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

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

Issue 2213503002: Tracking SelectionBounds for all RenderWidgets on the Browser Side (Mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // Called when |updated_view| has changed its CompositionRangeInfo. 55 // Called when |updated_view| has changed its CompositionRangeInfo.
56 virtual void OnImeCompositionRangeChanged( 56 virtual void OnImeCompositionRangeChanged(
57 TextInputManager* text_input_manager, 57 TextInputManager* text_input_manager,
58 RenderWidgetHostViewBase* updated_view) {} 58 RenderWidgetHostViewBase* updated_view) {}
59 // Called when the text selection for the |updated_view_| has changed. 59 // Called when the text selection for the |updated_view_| has changed.
60 virtual void OnTextSelectionChanged( 60 virtual void OnTextSelectionChanged(
61 TextInputManager* text_input_manager, 61 TextInputManager* text_input_manager,
62 RenderWidgetHostViewBase* updated_view) {} 62 RenderWidgetHostViewBase* updated_view) {}
63 }; 63 };
64 64
65 // Text selection bounds.
66 struct SelectionRegion {
67 SelectionRegion();
68 SelectionRegion(const SelectionRegion& other);
69
70 // The following variables are only used on Aura platforms.
71 // The begining of the selection region.
72 gfx::SelectionBound anchor;
73 // The end of the selection region (caret position).
74 gfx::SelectionBound focus;
75
76 // The following variables are only used on Mac platform.
77 // The current caret bounds.
78 gfx::Rect caret_rect;
79 // The current first selection bounds.
80 gfx::Rect first_selection_rect;
81 };
82
83 // Composition range information.
84 struct CompositionRangeInfo {
85 CompositionRangeInfo();
86 CompositionRangeInfo(const CompositionRangeInfo& other);
87 ~CompositionRangeInfo();
88
89 std::vector<gfx::Rect> character_bounds;
90 gfx::Range range;
91 };
92
65 // This struct is used to store text selection related information for views. 93 // This struct is used to store text selection related information for views.
66 struct TextSelection { 94 struct TextSelection {
67 TextSelection(); 95 TextSelection();
68 TextSelection(const TextSelection& other); 96 TextSelection(const TextSelection& other);
69 ~TextSelection(); 97 ~TextSelection();
70 98
71 // If text selection is valid, |text| will be populated with the selected 99 // If text selection is valid, |text| will be populated with the selected
72 // text and the method will return true. Otherwise, it will return false. 100 // text and the method will return true. Otherwise, it will return false.
73 bool GetSelectedText(base::string16* text) const; 101 bool GetSelectedText(base::string16* text) const;
74 102
75 // The offset of the text stored in |text| relative to the start of the web 103 // The offset of the text stored in |text| relative to the start of the web
76 // page. 104 // page.
77 size_t offset; 105 size_t offset;
78 106
79 // The current selection range relative to the start of the web page. 107 // The current selection range relative to the start of the web page.
80 gfx::Range range; 108 gfx::Range range;
81 109
82 // The text inside and around the current selection range. 110 // The text inside and around the current selection range.
83 base::string16 text; 111 base::string16 text;
84 }; 112 };
85 113
86 // Composition range information.
87 struct CompositionRangeInfo {
88 CompositionRangeInfo();
89 CompositionRangeInfo(const CompositionRangeInfo& other);
90 ~CompositionRangeInfo();
91
92 std::vector<gfx::Rect> character_bounds;
93 gfx::Range range;
94 };
95
96 TextInputManager(); 114 TextInputManager();
97 ~TextInputManager(); 115 ~TextInputManager();
98 116
99 // Returns the currently active widget, i.e., the RWH which is associated with 117 // Returns the currently active widget, i.e., the RWH which is associated with
100 // |active_view_|. 118 // |active_view_|.
101 RenderWidgetHostImpl* GetActiveWidget() const; 119 RenderWidgetHostImpl* GetActiveWidget() const;
102 120
103 // --------------------------------------------------------------------------- 121 // ---------------------------------------------------------------------------
104 // The following methods can be used to obtain information about IME-related 122 // The following methods can be used to obtain information about IME-related
105 // state for the active RenderWidgetHost. If the active widget is nullptr, the 123 // state for the active RenderWidgetHost. If the active widget is nullptr, the
106 // methods below will return nullptr as well. 124 // methods below will return nullptr as well.
107 // Users of these methods should not hold on to the pointers as they become 125 // Users of these methods should not hold on to the pointers as they become
108 // dangling if the TextInputManager or |active_view_| are destroyed. 126 // dangling if the TextInputManager or |active_view_| are destroyed.
109 127
110 // Returns the currently stored TextInputState. An state of nullptr can be 128 // Returns the currently stored TextInputState. An state of nullptr can be
111 // interpreted as a ui::TextInputType of ui::TEXT_INPUT_TYPE_NONE. 129 // interpreted as a ui::TextInputType of ui::TEXT_INPUT_TYPE_NONE.
112 const TextInputState* GetTextInputState() const; 130 const TextInputState* GetTextInputState() const;
113 131
114 // Returns the rect between selection bounds. 132 // Returns the selection bounds information for |view|. If |view| == nullptr,
115 gfx::Rect GetSelectionBoundsRect() const; 133 // it will return the corresponding information for |active_view_| or nullptr
134 // if there are no active views.
135 const SelectionRegion* GetSelectionRegion(
136 RenderWidgetHostViewBase* view = nullptr) const;
116 137
117 // Returns the composition range and character bounds information for the 138 // Returns the composition range and character bounds information for the
118 // |view|. If |view| == nullptr, it will assume |active_view_| and return its 139 // |view|. If |view| == nullptr, it will assume |active_view_| and return its
119 // state. If |active_view_| == nullptr, this method will return nullptr. 140 // state. If |active_view_| == nullptr, this method will return nullptr.
120 const TextInputManager::CompositionRangeInfo* GetCompositionRangeInfo( 141 const TextInputManager::CompositionRangeInfo* GetCompositionRangeInfo(
121 RenderWidgetHostViewBase* view = nullptr) const; 142 RenderWidgetHostViewBase* view = nullptr) const;
122 143
123 // The following method returns the text selection state for the given |view|. 144 // The following method returns the text selection state for the given |view|.
124 // If |view| == nullptr, it will assume |active_view_| and return its state. 145 // If |view| == nullptr, it will assume |active_view_| and return its state.
125 // In the case of |active_view_| == nullptr, the method will return nullptr. 146 // In the case of |active_view_| == nullptr, the method will return nullptr.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 void AddObserver(Observer* observer); 200 void AddObserver(Observer* observer);
180 void RemoveObserver(Observer* observer); 201 void RemoveObserver(Observer* observer);
181 bool HasObserver(Observer* observer) const; 202 bool HasObserver(Observer* observer) const;
182 203
183 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; } 204 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; }
184 size_t GetRegisteredViewsCountForTesting(); 205 size_t GetRegisteredViewsCountForTesting();
185 ui::TextInputType GetTextInputTypeForViewForTesting( 206 ui::TextInputType GetTextInputTypeForViewForTesting(
186 RenderWidgetHostViewBase* view); 207 RenderWidgetHostViewBase* view);
187 208
188 private: 209 private:
189 // Text selection bounds.
190 struct SelectionRegion {
191 SelectionRegion();
192 SelectionRegion(const SelectionRegion& other);
193
194 // The begining of the selection region.
195 gfx::SelectionBound anchor;
196 // The end of the selection region (caret position).
197 gfx::SelectionBound focus;
198 };
199
200 // This class is used to create maps which hold specific IME state for a 210 // This class is used to create maps which hold specific IME state for a
201 // view. 211 // view.
202 template <class Value> 212 template <class Value>
203 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> { 213 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> {
204 }; 214 };
205 215
206 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, 216 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
207 bool did_update_state); 217 bool did_update_state);
208 218
209 // The view with active text input state, i.e., a focused <input> element. 219 // The view with active text input state, i.e., a focused <input> element.
210 // It will be nullptr if no such view exists. Note that the active view 220 // It will be nullptr if no such view exists. Note that the active view
211 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. 221 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE.
212 RenderWidgetHostViewBase* active_view_; 222 RenderWidgetHostViewBase* active_view_;
213 223
214 // The following maps track corresponding IME state for views. For each view, 224 // The following maps track corresponding IME state for views. For each view,
215 // the values in the map are initialized and cleared in Register and 225 // the values in the map are initialized and cleared in Register and
216 // Unregister methods, respectively. 226 // Unregister methods, respectively.
217 ViewMap<TextInputState> text_input_state_map_; 227 ViewMap<TextInputState> text_input_state_map_;
218 ViewMap<SelectionRegion> selection_region_map_; 228 ViewMap<SelectionRegion> selection_region_map_;
219 ViewMap<CompositionRangeInfo> composition_range_info_map_; 229 ViewMap<CompositionRangeInfo> composition_range_info_map_;
220 ViewMap<TextSelection> text_selection_map_; 230 ViewMap<TextSelection> text_selection_map_;
221 231
222 base::ObserverList<Observer> observer_list_; 232 base::ObserverList<Observer> observer_list_;
223 233
224 DISALLOW_COPY_AND_ASSIGN(TextInputManager); 234 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
225 }; 235 };
226 } 236 }
227 237
228 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 238 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698