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

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: Removing some #ifdefs 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 // The offset of the text stored in |text| relative to the start of the web 99 // The offset of the text stored in |text| relative to the start of the web
72 // page. 100 // page.
73 size_t offset; 101 size_t offset;
74 102
75 // The current selection range relative to the start of the web page. 103 // The current selection range relative to the start of the web page.
76 gfx::Range range; 104 gfx::Range range;
77 105
78 // The text inside and around the current selection range. 106 // The text inside and around the current selection range.
79 base::string16 text; 107 base::string16 text;
80 }; 108 };
81 109
82 // Composition range information.
83 struct CompositionRangeInfo {
84 CompositionRangeInfo();
85 CompositionRangeInfo(const CompositionRangeInfo& other);
86 ~CompositionRangeInfo();
87
88 std::vector<gfx::Rect> character_bounds;
89 gfx::Range range;
90 };
91
92 TextInputManager(); 110 TextInputManager();
93 ~TextInputManager(); 111 ~TextInputManager();
94 112
95 // Returns the currently active widget, i.e., the RWH which is associated with 113 // Returns the currently active widget, i.e., the RWH which is associated with
96 // |active_view_|. 114 // |active_view_|.
97 RenderWidgetHostImpl* GetActiveWidget() const; 115 RenderWidgetHostImpl* GetActiveWidget() const;
98 116
99 // --------------------------------------------------------------------------- 117 // ---------------------------------------------------------------------------
100 // The following methods can be used to obtain information about IME-related 118 // The following methods can be used to obtain information about IME-related
101 // state for the active RenderWidgetHost. If the active widget is nullptr, the 119 // state for the active RenderWidgetHost. If the active widget is nullptr, the
102 // methods below will return nullptr as well. 120 // methods below will return nullptr as well.
103 // Users of these methods should not hold on to the pointers as they become 121 // Users of these methods should not hold on to the pointers as they become
104 // dangling if the TextInputManager or |active_view_| are destroyed. 122 // dangling if the TextInputManager or |active_view_| are destroyed.
105 123
106 // Returns the currently stored TextInputState. An state of nullptr can be 124 // Returns the currently stored TextInputState. An state of nullptr can be
107 // interpreted as a ui::TextInputType of ui::TEXT_INPUT_TYPE_NONE. 125 // interpreted as a ui::TextInputType of ui::TEXT_INPUT_TYPE_NONE.
108 const TextInputState* GetTextInputState() const; 126 const TextInputState* GetTextInputState() const;
109 127
110 // Returns the rect between selection bounds. 128 // Returns the selection bounds information for |view|. If |view| == nullptr,
111 gfx::Rect GetSelectionBoundsRect() const; 129 // it will return the corresponding information for |active_view_| or nullptr
130 // if there are no active views.
131 const SelectionRegion* GetSelectionRegion(
132 RenderWidgetHostViewBase* view = nullptr) const;
112 133
113 // Returns the composition range and character bounds information for the 134 // Returns the composition range and character bounds information for the
114 // |view|. If |view| == nullptr, it will assume |active_view_| and return its 135 // |view|. If |view| == nullptr, it will assume |active_view_| and return its
115 // state. If |active_view_| == nullptr, this method will return nullptr. 136 // state. If |active_view_| == nullptr, this method will return nullptr.
116 const TextInputManager::CompositionRangeInfo* GetCompositionRangeInfo( 137 const TextInputManager::CompositionRangeInfo* GetCompositionRangeInfo(
117 RenderWidgetHostViewBase* view = nullptr) const; 138 RenderWidgetHostViewBase* view = nullptr) const;
118 139
119 // The following method returns the text selection state for the given |view|. 140 // The following method returns the text selection state for the given |view|.
120 // If |view| == nullptr, it will assume |active_view_| and return its state. 141 // If |view| == nullptr, it will assume |active_view_| and return its state.
121 // In the case of |active_view_| == nullptr, the method will return nullptr. 142 // In the case of |active_view_| == nullptr, the method will return nullptr.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 void AddObserver(Observer* observer); 196 void AddObserver(Observer* observer);
176 void RemoveObserver(Observer* observer); 197 void RemoveObserver(Observer* observer);
177 bool HasObserver(Observer* observer) const; 198 bool HasObserver(Observer* observer) const;
178 199
179 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; } 200 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; }
180 size_t GetRegisteredViewsCountForTesting(); 201 size_t GetRegisteredViewsCountForTesting();
181 ui::TextInputType GetTextInputTypeForViewForTesting( 202 ui::TextInputType GetTextInputTypeForViewForTesting(
182 RenderWidgetHostViewBase* view); 203 RenderWidgetHostViewBase* view);
183 204
184 private: 205 private:
185 // Text selection bounds.
186 struct SelectionRegion {
187 SelectionRegion();
188 SelectionRegion(const SelectionRegion& other);
189
190 // The begining of the selection region.
191 gfx::SelectionBound anchor;
192 // The end of the selection region (caret position).
193 gfx::SelectionBound focus;
194 };
195
196 // This class is used to create maps which hold specific IME state for a 206 // This class is used to create maps which hold specific IME state for a
197 // view. 207 // view.
198 template <class Value> 208 template <class Value>
199 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> { 209 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> {
200 }; 210 };
201 211
202 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, 212 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
203 bool did_update_state); 213 bool did_update_state);
204 214
205 // The view with active text input state, i.e., a focused <input> element. 215 // The view with active text input state, i.e., a focused <input> element.
206 // It will be nullptr if no such view exists. Note that the active view 216 // It will be nullptr if no such view exists. Note that the active view
207 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. 217 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE.
208 RenderWidgetHostViewBase* active_view_; 218 RenderWidgetHostViewBase* active_view_;
209 219
210 // The following maps track corresponding IME state for views. For each view, 220 // The following maps track corresponding IME state for views. For each view,
211 // the values in the map are initialized and cleared in Register and 221 // the values in the map are initialized and cleared in Register and
212 // Unregister methods, respectively. 222 // Unregister methods, respectively.
213 ViewMap<TextInputState> text_input_state_map_; 223 ViewMap<TextInputState> text_input_state_map_;
214 ViewMap<SelectionRegion> selection_region_map_; 224 ViewMap<SelectionRegion> selection_region_map_;
215 ViewMap<CompositionRangeInfo> composition_range_info_map_; 225 ViewMap<CompositionRangeInfo> composition_range_info_map_;
216 ViewMap<TextSelection> text_selection_map_; 226 ViewMap<TextSelection> text_selection_map_;
217 227
218 base::ObserverList<Observer> observer_list_; 228 base::ObserverList<Observer> observer_list_;
219 229
220 DISALLOW_COPY_AND_ASSIGN(TextInputManager); 230 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
221 }; 231 };
222 } 232 }
223 233
224 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 234 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698