| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // a range for the selection, and the text including the selection which | 98 // a range for the selection, and the text including the selection which |
| 99 // might include several characters before and after it. | 99 // might include several characters before and after it. |
| 100 class TextSelection { | 100 class TextSelection { |
| 101 public: | 101 public: |
| 102 TextSelection(); | 102 TextSelection(); |
| 103 TextSelection(const TextSelection& other); | 103 TextSelection(const TextSelection& other); |
| 104 ~TextSelection(); | 104 ~TextSelection(); |
| 105 | 105 |
| 106 void SetSelection(const base::string16& text, | 106 void SetSelection(const base::string16& text, |
| 107 size_t offset, | 107 size_t offset, |
| 108 const gfx::Range& range, | 108 const gfx::Range& range); |
| 109 bool user_initiated); | |
| 110 | 109 |
| 111 const base::string16& selected_text() const { return selected_text_; } | 110 const base::string16& selected_text() const { return selected_text_; } |
| 112 size_t offset() const { return offset_; } | 111 size_t offset() const { return offset_; } |
| 113 const gfx::Range& range() const { return range_; } | 112 const gfx::Range& range() const { return range_; } |
| 114 const base::string16& text() const { return text_; } | 113 const base::string16& text() const { return text_; } |
| 115 bool user_initiated() const { return user_initiated_; } | |
| 116 | 114 |
| 117 private: | 115 private: |
| 118 // The offset of the text stored in |text| relative to the start of the web | 116 // The offset of the text stored in |text| relative to the start of the web |
| 119 // page. | 117 // page. |
| 120 size_t offset_ = 0; | 118 size_t offset_; |
| 121 | 119 |
| 122 // The range of the selection in the page (highlighted text). | 120 // The range of the selection in the page (highlighted text). |
| 123 gfx::Range range_ = gfx::Range::InvalidRange(); | 121 gfx::Range range_; |
| 124 | 122 |
| 125 // The highlighted text which is the portion of |text_| marked by |offset_| | 123 // The highlighted text which is the portion of |text_| marked by |offset_| |
| 126 // and |range_|. It will be an empty string if either |text_| or |range_| | 124 // and |range_|. It will be an empty string if either |text_| or |range_| |
| 127 // are empty of this selection information is invalid (i.e., |range_| does | 125 // are empty of this selection information is invalid (i.e., |range_| does |
| 128 // not cover any of |text_|. | 126 // not cover any of |text_|. |
| 129 base::string16 selected_text_; | 127 base::string16 selected_text_; |
| 130 | 128 |
| 131 // Part of the text on the page which includes the highlighted text plus | 129 // Part of the text on the page which includes the highlighted text plus |
| 132 // possibly several characters before and after it. | 130 // possibly several characters before and after it. |
| 133 base::string16 text_; | 131 base::string16 text_; |
| 134 | |
| 135 // True if text selection is triggered by user input. | |
| 136 bool user_initiated_ = false; | |
| 137 }; | 132 }; |
| 138 | 133 |
| 139 TextInputManager(); | 134 TextInputManager(); |
| 140 ~TextInputManager(); | 135 ~TextInputManager(); |
| 141 | 136 |
| 142 // Returns the currently active widget, i.e., the RWH which is associated with | 137 // Returns the currently active widget, i.e., the RWH which is associated with |
| 143 // |active_view_|. | 138 // |active_view_|. |
| 144 RenderWidgetHostImpl* GetActiveWidget() const; | 139 RenderWidgetHostImpl* GetActiveWidget() const; |
| 145 | 140 |
| 146 // --------------------------------------------------------------------------- | 141 // --------------------------------------------------------------------------- |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // Called when the composition range and/or character bounds have changed. | 187 // Called when the composition range and/or character bounds have changed. |
| 193 void ImeCompositionRangeChanged( | 188 void ImeCompositionRangeChanged( |
| 194 RenderWidgetHostViewBase* view, | 189 RenderWidgetHostViewBase* view, |
| 195 const gfx::Range& range, | 190 const gfx::Range& range, |
| 196 const std::vector<gfx::Rect>& character_bounds); | 191 const std::vector<gfx::Rect>& character_bounds); |
| 197 | 192 |
| 198 // Updates the new text selection information for the |view|. | 193 // Updates the new text selection information for the |view|. |
| 199 void SelectionChanged(RenderWidgetHostViewBase* view, | 194 void SelectionChanged(RenderWidgetHostViewBase* view, |
| 200 const base::string16& text, | 195 const base::string16& text, |
| 201 size_t offset, | 196 size_t offset, |
| 202 const gfx::Range& range, | 197 const gfx::Range& range); |
| 203 bool user_initiated); | |
| 204 | 198 |
| 205 // Registers the given |view| for tracking its TextInputState. This is called | 199 // Registers the given |view| for tracking its TextInputState. This is called |
| 206 // by any view which has updates in its TextInputState (whether tab's RWHV or | 200 // by any view which has updates in its TextInputState (whether tab's RWHV or |
| 207 // that of a child frame). The |view| must unregister itself before being | 201 // that of a child frame). The |view| must unregister itself before being |
| 208 // destroyed (i.e., call TextInputManager::Unregister). | 202 // destroyed (i.e., call TextInputManager::Unregister). |
| 209 void Register(RenderWidgetHostViewBase* view); | 203 void Register(RenderWidgetHostViewBase* view); |
| 210 | 204 |
| 211 // Clears the TextInputState from the |view|. If |view == active_view_|, this | 205 // Clears the TextInputState from the |view|. If |view == active_view_|, this |
| 212 // call will lead to a TextInputState update since the TextInputState.type | 206 // call will lead to a TextInputState update since the TextInputState.type |
| 213 // should be reset to none. | 207 // should be reset to none. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 ViewMap<CompositionRangeInfo> composition_range_info_map_; | 248 ViewMap<CompositionRangeInfo> composition_range_info_map_; |
| 255 ViewMap<TextSelection> text_selection_map_; | 249 ViewMap<TextSelection> text_selection_map_; |
| 256 | 250 |
| 257 base::ObserverList<Observer> observer_list_; | 251 base::ObserverList<Observer> observer_list_; |
| 258 | 252 |
| 259 DISALLOW_COPY_AND_ASSIGN(TextInputManager); | 253 DISALLOW_COPY_AND_ASSIGN(TextInputManager); |
| 260 }; | 254 }; |
| 261 } | 255 } |
| 262 | 256 |
| 263 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ | 257 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ |
| OLD | NEW |