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