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 content { | 21 namespace content { |
20 class RenderWidgetHostImpl; | 22 class RenderWidgetHostImpl; |
21 class RenderWidgetHostView; | 23 class RenderWidgetHostView; |
22 class RenderWidgetHostViewBase; | 24 class RenderWidgetHostViewBase; |
23 class WebContents; | 25 class WebContents; |
24 | 26 |
(...skipping 17 matching lines...) Expand all Loading... |
42 bool did_update_state) {} | 44 bool did_update_state) {} |
43 // Called when |updated_view| has called ImeCancelComposition on | 45 // Called when |updated_view| has called ImeCancelComposition on |
44 // TextInputManager. | 46 // TextInputManager. |
45 virtual void OnImeCancelComposition( | 47 virtual void OnImeCancelComposition( |
46 TextInputManager* text_input_manager, | 48 TextInputManager* text_input_manager, |
47 RenderWidgetHostViewBase* updated_view) {} | 49 RenderWidgetHostViewBase* updated_view) {} |
48 // Called when the selection bounds for the |updated_view| has changed. | 50 // Called when the selection bounds for the |updated_view| has changed. |
49 virtual void OnSelectionBoundsChanged( | 51 virtual void OnSelectionBoundsChanged( |
50 TextInputManager* text_input_manager, | 52 TextInputManager* text_input_manager, |
51 RenderWidgetHostViewBase* updated_view) {} | 53 RenderWidgetHostViewBase* updated_view) {} |
| 54 // Called when the text selection for the |updated_view_| has changed. |
| 55 virtual void OnTextSelectionChanged( |
| 56 TextInputManager* text_input_manager, |
| 57 RenderWidgetHostViewBase* updated_view) {} |
52 }; | 58 }; |
53 | 59 |
| 60 // This struct is used to store text selection related information for views. |
| 61 struct TextSelection { |
| 62 TextSelection(); |
| 63 TextSelection(const TextSelection& other); |
| 64 ~TextSelection(); |
| 65 |
| 66 // The offset of the text stored in |text| relative to the start of the web |
| 67 // page. |
| 68 size_t offset; |
| 69 |
| 70 // The current selection range relative to the start of the web page. |
| 71 gfx::Range range; |
| 72 |
| 73 // The text inside and around the current selection range. |
| 74 base::string16 text; |
| 75 }; |
| 76 |
54 TextInputManager(); | 77 TextInputManager(); |
55 ~TextInputManager(); | 78 ~TextInputManager(); |
56 | 79 |
57 // --------------------------------------------------------------------------- | 80 // --------------------------------------------------------------------------- |
58 // The following methods can be used to obtain information about IME-related | 81 // The following methods can be used to obtain information about IME-related |
59 // state for the active RenderWidget. | 82 // state for the active RenderWidget. |
60 | 83 |
61 // Returns the currently active widget, i.e., the RWH which is associated with | 84 // Returns the currently active widget, i.e., the RWH which is associated with |
62 // |active_view_|. | 85 // |active_view_|. |
63 RenderWidgetHostImpl* GetActiveWidget() const; | 86 RenderWidgetHostImpl* GetActiveWidget() const; |
64 | 87 |
65 // Returns the TextInputState corresponding to |active_view_|. | 88 // Returns the TextInputState corresponding to |active_view_|. |
66 // Users of this method should not hold on to the pointer as it might become | 89 // Users of this method should not hold on to the pointer as it might become |
67 // dangling if the TextInputManager or |active_view_| might go away. | 90 // dangling if the TextInputManager or |active_view_| might go away. |
68 const TextInputState* GetTextInputState(); | 91 const TextInputState* GetTextInputState(); |
69 | 92 |
70 // Returns the rect between selection bounds for the |active_view_|. | 93 // Returns the rect between selection bounds for the |active_view_|. |
71 gfx::Rect GetSelectionBoundsRect(); | 94 gfx::Rect GetSelectionBoundsRect(); |
72 | 95 |
73 // --------------------------------------------------------------------------- | 96 // --------------------------------------------------------------------------- |
| 97 // The following method return the text selection state for the given |view|. |
| 98 // If |view| == nullptr, it will assume |active_view_| and return its state. |
| 99 // In the case of |active_view_| == nullptr, the method will return nullptr. |
| 100 const TextSelection* GetTextSelection( |
| 101 RenderWidgetHostViewBase* view = nullptr); |
| 102 |
| 103 // --------------------------------------------------------------------------- |
74 // The following methods are called by RWHVs on the tab to update their IME- | 104 // The following methods are called by RWHVs on the tab to update their IME- |
75 // related state. | 105 // related state. |
76 | 106 |
77 // Updates the TextInputState for |view|. | 107 // Updates the TextInputState for |view|. |
78 void UpdateTextInputState(RenderWidgetHostViewBase* view, | 108 void UpdateTextInputState(RenderWidgetHostViewBase* view, |
79 const TextInputState& state); | 109 const TextInputState& state); |
80 | 110 |
81 // The current IME composition has been cancelled on the renderer side for | 111 // The current IME composition has been cancelled on the renderer side for |
82 // the widget corresponding to |view|. | 112 // the widget corresponding to |view|. |
83 void ImeCancelComposition(RenderWidgetHostViewBase* view); | 113 void ImeCancelComposition(RenderWidgetHostViewBase* view); |
84 | 114 |
85 // Updates the selection bounds for the |view|. In Aura, selection bounds are | 115 // Updates the selection bounds for the |view|. In Aura, selection bounds are |
86 // used to provide the InputMethod with the position of the caret, e.g., in | 116 // used to provide the InputMethod with the position of the caret, e.g., in |
87 // setting the position of the ui::ImeWindow. | 117 // setting the position of the ui::ImeWindow. |
88 void SelectionBoundsChanged(RenderWidgetHostViewBase* view, | 118 void SelectionBoundsChanged(RenderWidgetHostViewBase* view, |
89 const ViewHostMsg_SelectionBounds_Params& params); | 119 const ViewHostMsg_SelectionBounds_Params& params); |
90 | 120 |
| 121 // Updates the new text selection information for the |view|. |
| 122 void SelectionChanged(RenderWidgetHostViewBase* view, |
| 123 const base::string16& text, |
| 124 size_t offset, |
| 125 const gfx::Range& range); |
| 126 |
91 // Registers the given |view| for tracking its TextInputState. This is called | 127 // Registers the given |view| for tracking its TextInputState. This is called |
92 // by any view which has updates in its TextInputState (whether tab's RWHV or | 128 // by any view which has updates in its TextInputState (whether tab's RWHV or |
93 // that of a child frame). The |view| must unregister itself before being | 129 // that of a child frame). The |view| must unregister itself before being |
94 // destroyed (i.e., call TextInputManager::Unregister). | 130 // destroyed (i.e., call TextInputManager::Unregister). |
95 void Register(RenderWidgetHostViewBase* view); | 131 void Register(RenderWidgetHostViewBase* view); |
96 | 132 |
97 // Clears the TextInputState from the |view|. If |view == active_view_|, this | 133 // Clears the TextInputState from the |view|. If |view == active_view_|, this |
98 // call will lead to a TextInputState update since the TextInputState.type | 134 // call will lead to a TextInputState update since the TextInputState.type |
99 // should be reset to none. | 135 // should be reset to none. |
100 void Unregister(RenderWidgetHostViewBase* view); | 136 void Unregister(RenderWidgetHostViewBase* view); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // The view with active text input state, i.e., a focused <input> element. | 176 // The view with active text input state, i.e., a focused <input> element. |
141 // It will be nullptr if no such view exists. Note that the active view | 177 // It will be nullptr if no such view exists. Note that the active view |
142 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. | 178 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. |
143 RenderWidgetHostViewBase* active_view_; | 179 RenderWidgetHostViewBase* active_view_; |
144 | 180 |
145 ViewMap<TextInputState> text_input_state_map_; | 181 ViewMap<TextInputState> text_input_state_map_; |
146 | 182 |
147 // Text selection bounds information for registered views. | 183 // Text selection bounds information for registered views. |
148 ViewMap<SelectionRegion> selection_region_map_; | 184 ViewMap<SelectionRegion> selection_region_map_; |
149 | 185 |
| 186 ViewMap<TextSelection> text_selection_map_; |
| 187 |
150 base::ObserverList<Observer> observer_list_; | 188 base::ObserverList<Observer> observer_list_; |
151 | 189 |
152 DISALLOW_COPY_AND_ASSIGN(TextInputManager); | 190 DISALLOW_COPY_AND_ASSIGN(TextInputManager); |
153 }; | 191 }; |
154 } | 192 } |
155 | 193 |
156 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ | 194 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ |
OLD | NEW |