OLD | NEW |
---|---|
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 |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "base/strings/string16.h" | |
12 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
13 #include "content/common/text_input_state.h" | 14 #include "content/common/text_input_state.h" |
14 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
16 #include "ui/gfx/range/range.h" | |
15 #include "ui/gfx/selection_bound.h" | 17 #include "ui/gfx/selection_bound.h" |
16 | 18 |
17 struct ViewHostMsg_SelectionBounds_Params; | 19 struct ViewHostMsg_SelectionBounds_Params; |
18 | 20 |
19 namespace gfx { | |
20 class Range; | |
21 } | |
22 | |
23 namespace content { | 21 namespace content { |
24 | 22 |
25 class RenderWidgetHostImpl; | 23 class RenderWidgetHostImpl; |
26 class RenderWidgetHostView; | 24 class RenderWidgetHostView; |
27 class RenderWidgetHostViewBase; | 25 class RenderWidgetHostViewBase; |
28 class WebContents; | 26 class WebContents; |
29 | 27 |
30 // A class which receives updates of TextInputState from multiple sources and | 28 // A class which receives updates of TextInputState from multiple sources and |
31 // decides what the new TextInputState is. It also notifies the observers when | 29 // decides what the new TextInputState is. It also notifies the observers when |
32 // text input state is updated. | 30 // text input state is updated. |
(...skipping 18 matching lines...) Expand all Loading... | |
51 TextInputManager* text_input_manager, | 49 TextInputManager* text_input_manager, |
52 RenderWidgetHostViewBase* updated_view) {} | 50 RenderWidgetHostViewBase* updated_view) {} |
53 // Called when |updated_view| has changed its SelectionRegion. | 51 // Called when |updated_view| has changed its SelectionRegion. |
54 virtual void OnSelectionBoundsChanged( | 52 virtual void OnSelectionBoundsChanged( |
55 TextInputManager* text_input_manager, | 53 TextInputManager* text_input_manager, |
56 RenderWidgetHostViewBase* updated_view) {} | 54 RenderWidgetHostViewBase* updated_view) {} |
57 // Called when |updated_view| has changed its CompositionRangeInfo. | 55 // Called when |updated_view| has changed its CompositionRangeInfo. |
58 virtual void OnImeCompositionRangeChanged( | 56 virtual void OnImeCompositionRangeChanged( |
59 TextInputManager* text_input_manager, | 57 TextInputManager* text_input_manager, |
60 RenderWidgetHostViewBase* updated_view) {} | 58 RenderWidgetHostViewBase* updated_view) {} |
59 // Called when the text selection for the |updated_view_| has changed. | |
60 virtual void OnTextSelectionChanged( | |
61 TextInputManager* text_input_manager, | |
62 RenderWidgetHostViewBase* updated_view) {} | |
61 }; | 63 }; |
62 | 64 |
65 // This struct is used to store text selection related information for views. | |
66 struct TextSelection { | |
67 TextSelection(); | |
68 TextSelection(const TextSelection& other); | |
69 ~TextSelection(); | |
70 | |
71 // The offset of the text stored in |text| relative to the start of the web | |
72 // page. | |
73 size_t offset; | |
74 | |
75 // The current selection range relative to the start of the web page. | |
76 gfx::Range range; | |
77 | |
78 // The text inside and around the current selection range. | |
79 base::string16 text; | |
80 }; | |
81 | |
63 TextInputManager(); | 82 TextInputManager(); |
64 ~TextInputManager(); | 83 ~TextInputManager(); |
65 | 84 |
66 // Returns the currently active widget, i.e., the RWH which is associated with | 85 // Returns the currently active widget, i.e., the RWH which is associated with |
67 // |active_view_|. | 86 // |active_view_|. |
68 RenderWidgetHostImpl* GetActiveWidget() const; | 87 RenderWidgetHostImpl* GetActiveWidget() const; |
69 | 88 |
70 // --------------------------------------------------------------------------- | 89 // --------------------------------------------------------------------------- |
71 // The following methods can be used to obtain information about IME-related | 90 // The following methods can be used to obtain information about IME-related |
72 // state for the active RenderWidgetHost. If the active widget is nullptr, the | 91 // state for the active RenderWidgetHost. If the active widget is nullptr, the |
73 // methods below will return nullptr as well. | 92 // methods below will return nullptr as well. |
74 // Users of these methods should not hold on to the pointers as they become | 93 // Users of these methods should not hold on to the pointers as they become |
75 // dangling if the TextInputManager or |active_view_| are destroyed. | 94 // dangling if the TextInputManager or |active_view_| are destroyed. |
76 | 95 |
77 // Returns the currently stored TextInputState. An state of nullptr can be | 96 // Returns the currently stored TextInputState. An state of nullptr can be |
78 // interpreted as a ui::TextInputType of ui::TEXT_INPUT_TYPE_NONE. | 97 // interpreted as a ui::TextInputType of ui::TEXT_INPUT_TYPE_NONE. |
79 const TextInputState* GetTextInputState(); | 98 const TextInputState* GetTextInputState(); |
80 | 99 |
81 // Returns the rect between selection bounds. | 100 // Returns the rect between selection bounds. |
82 gfx::Rect GetSelectionBoundsRect(); | 101 gfx::Rect GetSelectionBoundsRect(); |
83 | 102 |
84 // Returns a vector of rects representing the character bounds. | 103 // Returns a vector of rects representing the character bounds. |
85 const std::vector<gfx::Rect>* GetCompositionCharacterBounds(); | 104 const std::vector<gfx::Rect>* GetCompositionCharacterBounds(); |
86 | 105 |
106 // The following method return the text selection state for the given |view|. | |
Charlie Reis
2016/07/20 23:00:30
nit: returns
EhsanK
2016/07/21 16:52:55
Done. Thanks!
| |
107 // If |view| == nullptr, it will assume |active_view_| and return its state. | |
108 // In the case of |active_view_| == nullptr, the method will return nullptr. | |
109 const TextSelection* GetTextSelection( | |
110 RenderWidgetHostViewBase* view = nullptr); | |
111 | |
87 // --------------------------------------------------------------------------- | 112 // --------------------------------------------------------------------------- |
88 // The following methods are called by RWHVs on the tab to update their IME- | 113 // The following methods are called by RWHVs on the tab to update their IME- |
89 // related state. | 114 // related state. |
90 | 115 |
91 // Updates the TextInputState for |view|. | 116 // Updates the TextInputState for |view|. |
92 void UpdateTextInputState(RenderWidgetHostViewBase* view, | 117 void UpdateTextInputState(RenderWidgetHostViewBase* view, |
93 const TextInputState& state); | 118 const TextInputState& state); |
94 | 119 |
95 // The current IME composition has been cancelled on the renderer side for | 120 // The current IME composition has been cancelled on the renderer side for |
96 // the widget corresponding to |view|. | 121 // the widget corresponding to |view|. |
97 void ImeCancelComposition(RenderWidgetHostViewBase* view); | 122 void ImeCancelComposition(RenderWidgetHostViewBase* view); |
98 | 123 |
99 // Updates the selection bounds for the |view|. In Aura, selection bounds are | 124 // Updates the selection bounds for the |view|. In Aura, selection bounds are |
100 // used to provide the InputMethod with the position of the caret, e.g., in | 125 // used to provide the InputMethod with the position of the caret, e.g., in |
101 // setting the position of the ui::ImeWindow. | 126 // setting the position of the ui::ImeWindow. |
102 void SelectionBoundsChanged(RenderWidgetHostViewBase* view, | 127 void SelectionBoundsChanged(RenderWidgetHostViewBase* view, |
103 const ViewHostMsg_SelectionBounds_Params& params); | 128 const ViewHostMsg_SelectionBounds_Params& params); |
104 | 129 |
105 // Called when the composition range and/or character bounds have changed. | 130 // Called when the composition range and/or character bounds have changed. |
106 void ImeCompositionRangeChanged( | 131 void ImeCompositionRangeChanged( |
107 RenderWidgetHostViewBase* view, | 132 RenderWidgetHostViewBase* view, |
108 const gfx::Range& range, | 133 const gfx::Range& range, |
109 const std::vector<gfx::Rect>& character_bounds); | 134 const std::vector<gfx::Rect>& character_bounds); |
110 | 135 |
136 // Updates the new text selection information for the |view|. | |
137 void SelectionChanged(RenderWidgetHostViewBase* view, | |
138 const base::string16& text, | |
139 size_t offset, | |
140 const gfx::Range& range); | |
141 | |
111 // Registers the given |view| for tracking its TextInputState. This is called | 142 // Registers the given |view| for tracking its TextInputState. This is called |
112 // by any view which has updates in its TextInputState (whether tab's RWHV or | 143 // by any view which has updates in its TextInputState (whether tab's RWHV or |
113 // that of a child frame). The |view| must unregister itself before being | 144 // that of a child frame). The |view| must unregister itself before being |
114 // destroyed (i.e., call TextInputManager::Unregister). | 145 // destroyed (i.e., call TextInputManager::Unregister). |
115 void Register(RenderWidgetHostViewBase* view); | 146 void Register(RenderWidgetHostViewBase* view); |
116 | 147 |
117 // Clears the TextInputState from the |view|. If |view == active_view_|, this | 148 // Clears the TextInputState from the |view|. If |view == active_view_|, this |
118 // call will lead to a TextInputState update since the TextInputState.type | 149 // call will lead to a TextInputState update since the TextInputState.type |
119 // should be reset to none. | 150 // should be reset to none. |
120 void Unregister(RenderWidgetHostViewBase* view); | 151 void Unregister(RenderWidgetHostViewBase* view); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // The view with active text input state, i.e., a focused <input> element. | 200 // The view with active text input state, i.e., a focused <input> element. |
170 // It will be nullptr if no such view exists. Note that the active view | 201 // It will be nullptr if no such view exists. Note that the active view |
171 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. | 202 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. |
172 RenderWidgetHostViewBase* active_view_; | 203 RenderWidgetHostViewBase* active_view_; |
173 | 204 |
174 ViewMap<TextInputState> text_input_state_map_; | 205 ViewMap<TextInputState> text_input_state_map_; |
175 | 206 |
176 // Text selection bounds information for registered views. | 207 // Text selection bounds information for registered views. |
177 ViewMap<SelectionRegion> selection_region_map_; | 208 ViewMap<SelectionRegion> selection_region_map_; |
178 ViewMap<CompositionRangeInfo> composition_range_info_map_; | 209 ViewMap<CompositionRangeInfo> composition_range_info_map_; |
210 ViewMap<TextSelection> text_selection_map_; | |
179 | 211 |
180 base::ObserverList<Observer> observer_list_; | 212 base::ObserverList<Observer> observer_list_; |
181 | 213 |
182 DISALLOW_COPY_AND_ASSIGN(TextInputManager); | 214 DISALLOW_COPY_AND_ASSIGN(TextInputManager); |
183 }; | 215 }; |
184 } | 216 } |
185 | 217 |
186 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ | 218 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ |
OLD | NEW |