Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: content/browser/renderer_host/text_input_manager.h

Issue 2903833002: Reland: Update TextSelection for non-user initiated events
Patch Set: Add test for JS cursor movement Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
6 #define CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 6 #define CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
7 7
8 #include <unordered_map> 8 #include <unordered_map>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // a range for the selection, and the text including the selection which 98 // a range for the selection, and the text including the selection which
99 // might include several characters before and after it. 99 // might include several characters before and after it.
100 class TextSelection { 100 class TextSelection {
101 public: 101 public:
102 TextSelection(); 102 TextSelection();
103 TextSelection(const TextSelection& other); 103 TextSelection(const TextSelection& other);
104 ~TextSelection(); 104 ~TextSelection();
105 105
106 void SetSelection(const base::string16& text, 106 void SetSelection(const base::string16& text,
107 size_t offset, 107 size_t offset,
108 const gfx::Range& range); 108 const gfx::Range& range,
109 bool user_initiated);
109 110
110 const base::string16& selected_text() const { return selected_text_; } 111 const base::string16& selected_text() const { return selected_text_; }
111 size_t offset() const { return offset_; } 112 size_t offset() const { return offset_; }
112 const gfx::Range& range() const { return range_; } 113 const gfx::Range& range() const { return range_; }
113 const base::string16& text() const { return text_; } 114 const base::string16& text() const { return text_; }
115 bool user_initiated() const { return user_initiated_; }
114 116
115 private: 117 private:
116 // The offset of the text stored in |text| relative to the start of the web 118 // The offset of the text stored in |text| relative to the start of the web
117 // page. 119 // page.
118 size_t offset_; 120 size_t offset_ = 0;
119 121
120 // The range of the selection in the page (highlighted text). 122 // The range of the selection in the page (highlighted text).
121 gfx::Range range_; 123 gfx::Range range_ = gfx::Range::InvalidRange();
122 124
123 // The highlighted text which is the portion of |text_| marked by |offset_| 125 // The highlighted text which is the portion of |text_| marked by |offset_|
124 // and |range_|. It will be an empty string if either |text_| or |range_| 126 // and |range_|. It will be an empty string if either |text_| or |range_|
125 // are empty of this selection information is invalid (i.e., |range_| does 127 // are empty of this selection information is invalid (i.e., |range_| does
126 // not cover any of |text_|. 128 // not cover any of |text_|.
127 base::string16 selected_text_; 129 base::string16 selected_text_;
128 130
129 // Part of the text on the page which includes the highlighted text plus 131 // Part of the text on the page which includes the highlighted text plus
130 // possibly several characters before and after it. 132 // possibly several characters before and after it.
131 base::string16 text_; 133 base::string16 text_;
134
135 // True if text selection is triggered by user input.
136 bool user_initiated_ = false;
132 }; 137 };
133 138
134 TextInputManager(); 139 TextInputManager();
135 ~TextInputManager(); 140 ~TextInputManager();
136 141
137 // Returns the currently active widget, i.e., the RWH which is associated with 142 // Returns the currently active widget, i.e., the RWH which is associated with
138 // |active_view_|. 143 // |active_view_|.
139 RenderWidgetHostImpl* GetActiveWidget() const; 144 RenderWidgetHostImpl* GetActiveWidget() const;
140 145
141 // --------------------------------------------------------------------------- 146 // ---------------------------------------------------------------------------
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // Called when the composition range and/or character bounds have changed. 192 // Called when the composition range and/or character bounds have changed.
188 void ImeCompositionRangeChanged( 193 void ImeCompositionRangeChanged(
189 RenderWidgetHostViewBase* view, 194 RenderWidgetHostViewBase* view,
190 const gfx::Range& range, 195 const gfx::Range& range,
191 const std::vector<gfx::Rect>& character_bounds); 196 const std::vector<gfx::Rect>& character_bounds);
192 197
193 // Updates the new text selection information for the |view|. 198 // Updates the new text selection information for the |view|.
194 void SelectionChanged(RenderWidgetHostViewBase* view, 199 void SelectionChanged(RenderWidgetHostViewBase* view,
195 const base::string16& text, 200 const base::string16& text,
196 size_t offset, 201 size_t offset,
197 const gfx::Range& range); 202 const gfx::Range& range,
203 bool user_initiated);
198 204
199 // Registers the given |view| for tracking its TextInputState. This is called 205 // Registers the given |view| for tracking its TextInputState. This is called
200 // by any view which has updates in its TextInputState (whether tab's RWHV or 206 // by any view which has updates in its TextInputState (whether tab's RWHV or
201 // that of a child frame). The |view| must unregister itself before being 207 // that of a child frame). The |view| must unregister itself before being
202 // destroyed (i.e., call TextInputManager::Unregister). 208 // destroyed (i.e., call TextInputManager::Unregister).
203 void Register(RenderWidgetHostViewBase* view); 209 void Register(RenderWidgetHostViewBase* view);
204 210
205 // Clears the TextInputState from the |view|. If |view == active_view_|, this 211 // Clears the TextInputState from the |view|. If |view == active_view_|, this
206 // call will lead to a TextInputState update since the TextInputState.type 212 // call will lead to a TextInputState update since the TextInputState.type
207 // should be reset to none. 213 // should be reset to none.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 ViewMap<CompositionRangeInfo> composition_range_info_map_; 255 ViewMap<CompositionRangeInfo> composition_range_info_map_;
250 ViewMap<TextSelection> text_selection_map_; 256 ViewMap<TextSelection> text_selection_map_;
251 257
252 base::ObserverList<Observer> observer_list_; 258 base::ObserverList<Observer> observer_list_;
253 259
254 DISALLOW_COPY_AND_ASSIGN(TextInputManager); 260 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
255 }; 261 };
256 } 262 }
257 263
258 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 264 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698