Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ |
| 6 | #define CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ |
| 7 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 8 | #include <optional> |
Jan Wilken Dörrie | ad587c3 | 2021-03-11 14:09:27 | [diff] [blame] | 9 | #include <string> |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 10 | #include <unordered_map> |
ekaramad | fcce088 | 2016-07-07 02:44:51 | [diff] [blame] | 11 | #include <utility> |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 12 | |
Dave Tapuska | c135bf1 | 2020-06-19 17:37:53 | [diff] [blame] | 13 | #include "base/i18n/rtl.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 14 | #include "base/memory/raw_ptr.h" |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 15 | #include "base/observer_list.h" |
| 16 | #include "content/common/content_export.h" |
Adam Ettenberger | 23b345b | 2024-10-16 20:03:39 | [diff] [blame] | 17 | #include "third_party/blink/public/mojom/page/widget.mojom-forward.h" |
Dave Tapuska | c135bf1 | 2020-06-19 17:37:53 | [diff] [blame] | 18 | #include "ui/base/ime/mojom/text_input_state.mojom.h" |
Jing Wang | 6554c150 | 2021-05-05 02:04:00 | [diff] [blame] | 19 | #include "ui/base/ime/text_input_client.h" |
ekaramad | fcce088 | 2016-07-07 02:44:51 | [diff] [blame] | 20 | #include "ui/gfx/geometry/rect.h" |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 21 | #include "ui/gfx/range/range.h" |
ekaramad | fcce088 | 2016-07-07 02:44:51 | [diff] [blame] | 22 | #include "ui/gfx/selection_bound.h" |
| 23 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 24 | namespace content { |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 25 | |
ekaramad | 8cba7886 | 2016-06-24 19:42:31 | [diff] [blame] | 26 | class RenderWidgetHostImpl; |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 27 | class RenderWidgetHostViewBase; |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 28 | |
| 29 | // A class which receives updates of TextInputState from multiple sources and |
| 30 | // decides what the new TextInputState is. It also notifies the observers when |
| 31 | // text input state is updated. |
| 32 | class CONTENT_EXPORT TextInputManager { |
| 33 | public: |
| 34 | // The tab's top-level RWHV should be an observer of TextInputManager to get |
| 35 | // notifications about changes in TextInputState or other IME related state |
| 36 | // for child frames. |
| 37 | class CONTENT_EXPORT Observer { |
| 38 | public: |
| 39 | // Called when a view has called UpdateTextInputState on TextInputManager. |
| 40 | // If the call has led to a change in TextInputState, |did_update_state| is |
| 41 | // true. In some plaforms, we need this update even when the state has not |
ekaramad | db49e17 | 2016-11-30 08:44:40 | [diff] [blame] | 42 | // changed (e.g., Aura for updating IME). Also note that |updated_view| is |
| 43 | // the view which has most recently received an update in TextInputState. |
| 44 | // |updated_view| should not be used to obtain any IME state since this |
| 45 | // observer method might have been called in the process of unregistering |
| 46 | // |active_view_| from TextInputManager (which in turn is a result of either |
| 47 | // destroying |active_view_| or TextInputManager). |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 48 | virtual void OnUpdateTextInputStateCalled( |
| 49 | TextInputManager* text_input_manager, |
| 50 | RenderWidgetHostViewBase* updated_view, |
| 51 | bool did_update_state) {} |
ekaramad | 50ee203 | 2016-06-29 02:18:25 | [diff] [blame] | 52 | // Called when |updated_view| has called ImeCancelComposition on |
| 53 | // TextInputManager. |
| 54 | virtual void OnImeCancelComposition( |
| 55 | TextInputManager* text_input_manager, |
| 56 | RenderWidgetHostViewBase* updated_view) {} |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 57 | // Called when |updated_view| has changed its SelectionRegion. |
ekaramad | fcce088 | 2016-07-07 02:44:51 | [diff] [blame] | 58 | virtual void OnSelectionBoundsChanged( |
| 59 | TextInputManager* text_input_manager, |
| 60 | RenderWidgetHostViewBase* updated_view) {} |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 61 | // Called when |updated_view| has changed its CompositionRangeInfo. |
Alex Mitra | 08747df | 2023-08-08 17:04:10 | [diff] [blame] | 62 | // |character_bounds_changed| marks whether the current |
| 63 | // CompositionRangeInfo::character_bounds should be updated. |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 64 | virtual void OnImeCompositionRangeChanged( |
| 65 | TextInputManager* text_input_manager, |
Alex Mitra | 08747df | 2023-08-08 17:04:10 | [diff] [blame] | 66 | RenderWidgetHostViewBase* updated_view, |
Alex Mitra | 9b83bea9 | 2025-02-28 14:14:04 | [diff] [blame] | 67 | bool character_bounds_changed) {} |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 68 | // Called when the text selection for the |updated_view_| has changed. |
| 69 | virtual void OnTextSelectionChanged( |
| 70 | TextInputManager* text_input_manager, |
| 71 | RenderWidgetHostViewBase* updated_view) {} |
| 72 | }; |
| 73 | |
ekaramad | 2f52009 | 2016-08-22 23:10:24 | [diff] [blame] | 74 | // Text selection bounds. |
| 75 | struct SelectionRegion { |
| 76 | SelectionRegion(); |
| 77 | SelectionRegion(const SelectionRegion& other); |
Peter Kasting | c634073 | 2021-07-05 06:01:00 | [diff] [blame] | 78 | SelectionRegion& operator=(const SelectionRegion& other); |
ekaramad | 2f52009 | 2016-08-22 23:10:24 | [diff] [blame] | 79 | |
ekaramad | 2f52009 | 2016-08-22 23:10:24 | [diff] [blame] | 80 | // The begining of the selection region. |
| 81 | gfx::SelectionBound anchor; |
| 82 | // The end of the selection region (caret position). |
| 83 | gfx::SelectionBound focus; |
| 84 | |
Andrew Xu | a178f3a | 2021-04-13 00:54:15 | [diff] [blame] | 85 | // The bounding box of the selection region. |
| 86 | gfx::Rect bounding_box; |
| 87 | |
ekaramad | 2f52009 | 2016-08-22 23:10:24 | [diff] [blame] | 88 | // The following variables are only used on Mac platform. |
| 89 | // The current caret bounds. |
| 90 | gfx::Rect caret_rect; |
| 91 | // The current first selection bounds. |
| 92 | gfx::Rect first_selection_rect; |
| 93 | }; |
| 94 | |
| 95 | // Composition range information. |
| 96 | struct CompositionRangeInfo { |
| 97 | CompositionRangeInfo(); |
| 98 | CompositionRangeInfo(const CompositionRangeInfo& other); |
| 99 | ~CompositionRangeInfo(); |
| 100 | |
| 101 | std::vector<gfx::Rect> character_bounds; |
| 102 | gfx::Range range; |
| 103 | }; |
| 104 | |
ekaramad | 374b266 | 2017-03-02 20:44:52 | [diff] [blame] | 105 | // This class is used to store text selection information for views. The text |
| 106 | // selection information includes a range around the selected (highlighted) |
| 107 | // text which is defined by an offset from the beginning of the page/frame, |
| 108 | // a range for the selection, and the text including the selection which |
| 109 | // might include several characters before and after it. |
| 110 | class TextSelection { |
| 111 | public: |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 112 | TextSelection(); |
| 113 | TextSelection(const TextSelection& other); |
| 114 | ~TextSelection(); |
| 115 | |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 116 | void SetSelection(const std::u16string& text, |
ekaramad | 374b266 | 2017-03-02 20:44:52 | [diff] [blame] | 117 | size_t offset, |
changwan | 44664cd | 2017-05-23 19:14:34 | [diff] [blame] | 118 | const gfx::Range& range); |
ekaramad | 65cf559 | 2016-08-18 21:44:53 | [diff] [blame] | 119 | |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 120 | const std::u16string& selected_text() const { return selected_text_; } |
ekaramad | 374b266 | 2017-03-02 20:44:52 | [diff] [blame] | 121 | size_t offset() const { return offset_; } |
| 122 | const gfx::Range& range() const { return range_; } |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 123 | const std::u16string& text() const { return text_; } |
ekaramad | 374b266 | 2017-03-02 20:44:52 | [diff] [blame] | 124 | |
| 125 | private: |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 126 | // The offset of the text stored in |text| relative to the start of the web |
| 127 | // page. |
changwan | 44664cd | 2017-05-23 19:14:34 | [diff] [blame] | 128 | size_t offset_; |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 129 | |
ekaramad | 374b266 | 2017-03-02 20:44:52 | [diff] [blame] | 130 | // The range of the selection in the page (highlighted text). |
changwan | 44664cd | 2017-05-23 19:14:34 | [diff] [blame] | 131 | gfx::Range range_; |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 132 | |
ekaramad | 374b266 | 2017-03-02 20:44:52 | [diff] [blame] | 133 | // The highlighted text which is the portion of |text_| marked by |offset_| |
| 134 | // and |range_|. It will be an empty string if either |text_| or |range_| |
| 135 | // are empty of this selection information is invalid (i.e., |range_| does |
| 136 | // not cover any of |text_|. |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 137 | std::u16string selected_text_; |
ekaramad | 374b266 | 2017-03-02 20:44:52 | [diff] [blame] | 138 | |
| 139 | // Part of the text on the page which includes the highlighted text plus |
| 140 | // possibly several characters before and after it. |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 141 | std::u16string text_; |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 142 | }; |
| 143 | |
Anupam Snigdha | 915824a | 2024-03-05 17:55:30 | [diff] [blame] | 144 | TextInputManager(); |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 145 | |
| 146 | TextInputManager(const TextInputManager&) = delete; |
| 147 | TextInputManager& operator=(const TextInputManager&) = delete; |
| 148 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 149 | ~TextInputManager(); |
| 150 | |
ekaramad | 8cba7886 | 2016-06-24 19:42:31 | [diff] [blame] | 151 | // Returns the currently active widget, i.e., the RWH which is associated with |
| 152 | // |active_view_|. |
| 153 | RenderWidgetHostImpl* GetActiveWidget() const; |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 154 | |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 155 | // --------------------------------------------------------------------------- |
| 156 | // The following methods can be used to obtain information about IME-related |
| 157 | // state for the active RenderWidgetHost. If the active widget is nullptr, the |
| 158 | // methods below will return nullptr as well. |
| 159 | // Users of these methods should not hold on to the pointers as they become |
| 160 | // dangling if the TextInputManager or |active_view_| are destroyed. |
| 161 | |
ekaramad | db49e17 | 2016-11-30 08:44:40 | [diff] [blame] | 162 | // Returns the currently stored TextInputState for |active_view_|. A state of |
| 163 | // nullptr can be interpreted as a ui::TextInputType of |
| 164 | // ui::TEXT_INPUT_TYPE_NONE. |
Dave Tapuska | c135bf1 | 2020-06-19 17:37:53 | [diff] [blame] | 165 | const ui::mojom::TextInputState* GetTextInputState() const; |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 166 | |
John Palmer | 75ce6c7 | 2021-01-21 05:15:00 | [diff] [blame] | 167 | // Returns the current autocorrect range, or an empty range if no autocorrect |
| 168 | // range is currently present. |
| 169 | gfx::Range GetAutocorrectRange() const; |
| 170 | |
Jing Wang | 6554c150 | 2021-05-05 02:04:00 | [diff] [blame] | 171 | // Returns the grammar fragment which contains |range|. If non-existent, |
Jing Wang | a7c098c | 2022-05-24 01:28:20 | [diff] [blame] | 172 | // returns nullopt. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 173 | std::optional<ui::GrammarFragment> GetGrammarFragment(gfx::Range range) const; |
Jing Wang | 6554c150 | 2021-05-05 02:04:00 | [diff] [blame] | 174 | |
ekaramad | 2f52009 | 2016-08-22 23:10:24 | [diff] [blame] | 175 | // Returns the selection bounds information for |view|. If |view| == nullptr, |
| 176 | // it will return the corresponding information for |active_view_| or nullptr |
| 177 | // if there are no active views. |
| 178 | const SelectionRegion* GetSelectionRegion( |
| 179 | RenderWidgetHostViewBase* view = nullptr) const; |
ekaramad | fcce088 | 2016-07-07 02:44:51 | [diff] [blame] | 180 | |
ekaramad | d773ff4 | 2016-08-12 19:30:40 | [diff] [blame] | 181 | // Returns the composition range and character bounds information for the |
ekaramad | 79819af0 | 2017-04-10 21:10:26 | [diff] [blame] | 182 | // |active_view_|. Returns nullptr If |active_view_| == nullptr. |
| 183 | const TextInputManager::CompositionRangeInfo* GetCompositionRangeInfo() const; |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 184 | |
Adam Ettenberger | 23b345b | 2024-10-16 20:03:39 | [diff] [blame] | 185 | #if BUILDFLAG(IS_WIN) |
| 186 | // `ProximateCharacterRangeBounds` is provided by the renderer and contains a |
| 187 | // character offset range and associated character bounding boxes in widget |
| 188 | // coordinates for a subset of the actual character bounding boxes. This data |
| 189 | // enables StylusHandwritingWin gesture support for renderer content, but is |
| 190 | // a compromise since it only contains a limited subset of content for |
| 191 | // performance (CPU and memory) reasons, since computing and copying all of |
| 192 | // the character bounds from a renderer document may be costly and slow for |
| 193 | // large documents. |
| 194 | // |
| 195 | // For views content, since they exist in the browser process it's possible to |
| 196 | // retrieve accurate results without ProximateCharacterRangeBounds. |
| 197 | // ProximateCharacterRangeBounds will not be updated for views content, and |
| 198 | // shouldn't be relied upon for views use cases as it could be null or stale. |
| 199 | // Views that implement `ui::TextInputClient` should instead implement both |
| 200 | // `GetProximateCharacterBounds` and `GetProximateCharacterIndexFromPoint` to |
| 201 | // query their content directly. For example, `views::Textfield` could collect |
| 202 | // character bounds through `gfx::RenderText`, GetRenderText(). |
| 203 | const blink::mojom::ProximateCharacterRangeBounds* |
| 204 | GetProximateCharacterBoundsInfo(const RenderWidgetHostViewBase& view) const; |
| 205 | #endif // BUILDFLAG(IS_WIN) |
| 206 | |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 207 | // The following method returns the text selection state for the given |view|. |
| 208 | // If |view| == nullptr, it will assume |active_view_| and return its state. |
| 209 | // In the case of |active_view_| == nullptr, the method will return nullptr. |
| 210 | const TextSelection* GetTextSelection( |
| 211 | RenderWidgetHostViewBase* view = nullptr) const; |
| 212 | |
John Palmer | 2200b9a9 | 2021-10-27 04:39:02 | [diff] [blame] | 213 | // Returns the bounds of the text control in the root frame. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 214 | const std::optional<gfx::Rect> GetTextControlBounds() const; |
John Palmer | 2200b9a9 | 2021-10-27 04:39:02 | [diff] [blame] | 215 | |
| 216 | // Returns the bounds of the selected text in the root frame. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 217 | const std::optional<gfx::Rect> GetTextSelectionBounds() const; |
John Palmer | 2200b9a9 | 2021-10-27 04:39:02 | [diff] [blame] | 218 | |
ekaramad | 8cba7886 | 2016-06-24 19:42:31 | [diff] [blame] | 219 | // --------------------------------------------------------------------------- |
| 220 | // The following methods are called by RWHVs on the tab to update their IME- |
| 221 | // related state. |
| 222 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 223 | // Updates the TextInputState for |view|. |
| 224 | void UpdateTextInputState(RenderWidgetHostViewBase* view, |
Dave Tapuska | c135bf1 | 2020-06-19 17:37:53 | [diff] [blame] | 225 | const ui::mojom::TextInputState& state); |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 226 | |
Adam Ettenberger | 23b345b | 2024-10-16 20:03:39 | [diff] [blame] | 227 | #if BUILDFLAG(IS_WIN) |
| 228 | // Takes ownership of `proximate_bounds` so it can be retrieved later by |
| 229 | // GetProximateCharacterBoundsInfo(). When populated by the renderer process, |
| 230 | // enables StylusHandwritingWin gesture support for renderer content. |
| 231 | // If `proximate_bounds` is null, removes `view` from the cache. |
| 232 | void UpdateProximateCharacterBounds( |
| 233 | RenderWidgetHostViewBase& view, |
| 234 | blink::mojom::ProximateCharacterRangeBoundsPtr proximate_bounds); |
| 235 | #endif // BUILDFLAG(IS_WIN) |
| 236 | |
ekaramad | 50ee203 | 2016-06-29 02:18:25 | [diff] [blame] | 237 | // The current IME composition has been cancelled on the renderer side for |
| 238 | // the widget corresponding to |view|. |
| 239 | void ImeCancelComposition(RenderWidgetHostViewBase* view); |
| 240 | |
ekaramad | fcce088 | 2016-07-07 02:44:51 | [diff] [blame] | 241 | // Updates the selection bounds for the |view|. In Aura, selection bounds are |
| 242 | // used to provide the InputMethod with the position of the caret, e.g., in |
| 243 | // setting the position of the ui::ImeWindow. |
Dave Tapuska | c135bf1 | 2020-06-19 17:37:53 | [diff] [blame] | 244 | void SelectionBoundsChanged(RenderWidgetHostViewBase* view, |
| 245 | const gfx::Rect& anchor_rect, |
| 246 | base::i18n::TextDirection anchor_dir, |
| 247 | const gfx::Rect& focus_rect, |
| 248 | base::i18n::TextDirection focus_dir, |
Andrew Xu | a178f3a | 2021-04-13 00:54:15 | [diff] [blame] | 249 | const gfx::Rect& bounding_box, |
Dave Tapuska | c135bf1 | 2020-06-19 17:37:53 | [diff] [blame] | 250 | bool is_anchor_first); |
ekaramad | fcce088 | 2016-07-07 02:44:51 | [diff] [blame] | 251 | |
Aaron Leventhal | fe0c7ef | 2018-07-25 14:05:53 | [diff] [blame] | 252 | // Notify observers that the selection bounds have been updated. This is also |
| 253 | // called when a view with a selection is reactivated. |
| 254 | void NotifySelectionBoundsChanged(RenderWidgetHostViewBase* view); |
| 255 | |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 256 | // Called when the composition range and/or character bounds have changed. |
| 257 | void ImeCompositionRangeChanged( |
| 258 | RenderWidgetHostViewBase* view, |
| 259 | const gfx::Range& range, |
Alex Mitra | 9b83bea9 | 2025-02-28 14:14:04 | [diff] [blame] | 260 | const std::optional<std::vector<gfx::Rect>>& character_bounds); |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 261 | |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 262 | // Updates the new text selection information for the |view|. |
| 263 | void SelectionChanged(RenderWidgetHostViewBase* view, |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 264 | const std::u16string& text, |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 265 | size_t offset, |
changwan | 44664cd | 2017-05-23 19:14:34 | [diff] [blame] | 266 | const gfx::Range& range); |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 267 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 268 | // Registers the given |view| for tracking its TextInputState. This is called |
| 269 | // by any view which has updates in its TextInputState (whether tab's RWHV or |
| 270 | // that of a child frame). The |view| must unregister itself before being |
| 271 | // destroyed (i.e., call TextInputManager::Unregister). |
| 272 | void Register(RenderWidgetHostViewBase* view); |
| 273 | |
| 274 | // Clears the TextInputState from the |view|. If |view == active_view_|, this |
| 275 | // call will lead to a TextInputState update since the TextInputState.type |
| 276 | // should be reset to none. |
| 277 | void Unregister(RenderWidgetHostViewBase* view); |
| 278 | |
| 279 | // Returns true if |view| is already registered. |
| 280 | bool IsRegistered(RenderWidgetHostViewBase* view) const; |
| 281 | |
| 282 | // Add and remove observers for notifications regarding updates in the |
| 283 | // TextInputState. Clients must be sure to remove themselves before they go |
| 284 | // away. |
| 285 | // Only the tab's RWHV should observer TextInputManager. In tests, however, |
| 286 | // in addition to the tab's RWHV, one or more test observers might observe |
| 287 | // TextInputManager. |
| 288 | void AddObserver(Observer* observer); |
| 289 | void RemoveObserver(Observer* observer); |
ekaramad | fd5f5a89 | 2016-08-12 04:33:10 | [diff] [blame] | 290 | bool HasObserver(Observer* observer) const; |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 291 | |
ekaramad | 8cba7886 | 2016-06-24 19:42:31 | [diff] [blame] | 292 | RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; } |
ekaramad | 936536d | 2016-06-29 05:44:44 | [diff] [blame] | 293 | size_t GetRegisteredViewsCountForTesting(); |
| 294 | ui::TextInputType GetTextInputTypeForViewForTesting( |
| 295 | RenderWidgetHostViewBase* view); |
ekaramad | 2c3c487 | 2017-06-15 14:58:06 | [diff] [blame] | 296 | const gfx::Range* GetCompositionRangeForTesting() const; |
ekaramad | 8cba7886 | 2016-06-24 19:42:31 | [diff] [blame] | 297 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 298 | private: |
ekaramad | fcce088 | 2016-07-07 02:44:51 | [diff] [blame] | 299 | // This class is used to create maps which hold specific IME state for a |
| 300 | // view. |
| 301 | template <class Value> |
| 302 | class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> { |
| 303 | }; |
| 304 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 305 | void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, |
| 306 | bool did_update_state); |
| 307 | |
ekaramad | 8cba7886 | 2016-06-24 19:42:31 | [diff] [blame] | 308 | // The view with active text input state, i.e., a focused <input> element. |
| 309 | // It will be nullptr if no such view exists. Note that the active view |
| 310 | // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 311 | raw_ptr<RenderWidgetHostViewBase> active_view_; |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 312 | |
ekaramad | 4cfc03e | 2016-07-21 17:34:21 | [diff] [blame] | 313 | // The following maps track corresponding IME state for views. For each view, |
| 314 | // the values in the map are initialized and cleared in Register and |
| 315 | // Unregister methods, respectively. |
My Nguyen | ca19c6d | 2020-08-05 11:32:42 | [diff] [blame] | 316 | ViewMap<ui::mojom::TextInputStatePtr> text_input_state_map_; |
ekaramad | fcce088 | 2016-07-07 02:44:51 | [diff] [blame] | 317 | ViewMap<SelectionRegion> selection_region_map_; |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 318 | ViewMap<CompositionRangeInfo> composition_range_info_map_; |
ekaramad | 6f1786b | 2016-07-21 21:10:58 | [diff] [blame] | 319 | ViewMap<TextSelection> text_selection_map_; |
Adam Ettenberger | 23b345b | 2024-10-16 20:03:39 | [diff] [blame] | 320 | #if BUILDFLAG(IS_WIN) |
| 321 | ViewMap<blink::mojom::ProximateCharacterRangeBoundsPtr> |
| 322 | proximate_character_bounds_map_; |
| 323 | #endif // BUILDFLAG(IS_WIN) |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 324 | |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 325 | base::ObserverList<Observer>::Unchecked observer_list_; |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 326 | }; |
| 327 | } |
| 328 | |
ekaramad | b8e23a96c | 2016-07-13 01:21:15 | [diff] [blame] | 329 | #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ |