Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: content/browser/renderer_host/text_input_manager.h

Issue 2132633002: Tracking composition range on the browser side (Aura) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatting Fixes Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/common/content_export.h" 12 #include "content/common/content_export.h"
13 #include "content/common/text_input_state.h" 13 #include "content/common/text_input_state.h"
14 #include "ui/gfx/geometry/rect.h" 14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/selection_bound.h" 15 #include "ui/gfx/selection_bound.h"
16 16
17 struct ViewHostMsg_SelectionBounds_Params; 17 struct ViewHostMsg_SelectionBounds_Params;
18 18
19 namespace gfx {
EhsanK 2016/07/07 22:10:58 Not quite sure if space is needed.
kenrb 2016/07/08 18:13:42 It isn't.
EhsanK 2016/07/11 18:07:21 Acknowledged.
20 class Range;
21 }
22
19 namespace content { 23 namespace content {
EhsanK 2016/07/07 22:10:58 Same dilemma, but maybe a different case than abov
kenrb 2016/07/08 18:13:42 A blank line here is appropriate.
EhsanK 2016/07/11 18:07:21 Acknowledged.
20 class RenderWidgetHostImpl; 24 class RenderWidgetHostImpl;
21 class RenderWidgetHostView; 25 class RenderWidgetHostView;
22 class RenderWidgetHostViewBase; 26 class RenderWidgetHostViewBase;
23 class WebContents; 27 class WebContents;
24 28
25 // A class which receives updates of TextInputState from multiple sources and 29 // A class which receives updates of TextInputState from multiple sources and
26 // decides what the new TextInputState is. It also notifies the observers when 30 // decides what the new TextInputState is. It also notifies the observers when
27 // text input state is updated. 31 // text input state is updated.
28 class CONTENT_EXPORT TextInputManager { 32 class CONTENT_EXPORT TextInputManager {
29 public: 33 public:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 RenderWidgetHostImpl* GetActiveWidget() const; 67 RenderWidgetHostImpl* GetActiveWidget() const;
64 68
65 // Returns the TextInputState corresponding to |active_view_|. 69 // Returns the TextInputState corresponding to |active_view_|.
66 // Users of this method should not hold on to the pointer as it might become 70 // 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. 71 // dangling if the TextInputManager or |active_view_| might go away.
68 const TextInputState* GetTextInputState(); 72 const TextInputState* GetTextInputState();
69 73
70 // Returns the rect between selection bounds for the |active_view_|. 74 // Returns the rect between selection bounds for the |active_view_|.
71 gfx::Rect GetSelectionBoundsRect(); 75 gfx::Rect GetSelectionBoundsRect();
72 76
77 // Returns a vector of rects for the character bounds of the active widget.
78 const std::vector<gfx::Rect>* GetCompositionCharacterBounds();
kenrb 2016/07/08 18:13:42 In RenderWidgetHostViewAura you call this without
EhsanK 2016/07/11 18:07:21 In RWHVAura we check if there is an active widget
79
73 // --------------------------------------------------------------------------- 80 // ---------------------------------------------------------------------------
74 // The following methods are called by RWHVs on the tab to update their IME- 81 // The following methods are called by RWHVs on the tab to update their IME-
75 // related state. 82 // related state.
76 83
77 // Updates the TextInputState for |view|. 84 // Updates the TextInputState for |view|.
78 void UpdateTextInputState(RenderWidgetHostViewBase* view, 85 void UpdateTextInputState(RenderWidgetHostViewBase* view,
79 const TextInputState& state); 86 const TextInputState& state);
80 87
81 // The current IME composition has been cancelled on the renderer side for 88 // The current IME composition has been cancelled on the renderer side for
82 // the widget corresponding to |view|. 89 // the widget corresponding to |view|.
83 void ImeCancelComposition(RenderWidgetHostViewBase* view); 90 void ImeCancelComposition(RenderWidgetHostViewBase* view);
84 91
85 // Updates the selection bounds for the |view|. In Aura, selection bounds are 92 // 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 93 // used to provide the InputMethod with the position of the caret, e.g., in
87 // setting the position of the ui::ImeWindow. 94 // setting the position of the ui::ImeWindow.
88 void SelectionBoundsChanged(RenderWidgetHostViewBase* view, 95 void SelectionBoundsChanged(RenderWidgetHostViewBase* view,
89 const ViewHostMsg_SelectionBounds_Params& params); 96 const ViewHostMsg_SelectionBounds_Params& params);
90 97
98 // Called when the composition range and/or character bounds have changed.
99 void ImeCompositionRangeChanged(
100 RenderWidgetHostViewBase* view,
101 const gfx::Range& range,
102 const std::vector<gfx::Rect>& character_bounds);
103
91 // Registers the given |view| for tracking its TextInputState. This is called 104 // 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 105 // 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 106 // that of a child frame). The |view| must unregister itself before being
94 // destroyed (i.e., call TextInputManager::Unregister). 107 // destroyed (i.e., call TextInputManager::Unregister).
95 void Register(RenderWidgetHostViewBase* view); 108 void Register(RenderWidgetHostViewBase* view);
96 109
97 // Clears the TextInputState from the |view|. If |view == active_view_|, this 110 // Clears the TextInputState from the |view|. If |view == active_view_|, this
98 // call will lead to a TextInputState update since the TextInputState.type 111 // call will lead to a TextInputState update since the TextInputState.type
99 // should be reset to none. 112 // should be reset to none.
100 void Unregister(RenderWidgetHostViewBase* view); 113 void Unregister(RenderWidgetHostViewBase* view);
(...skipping 20 matching lines...) Expand all
121 struct SelectionRegion { 134 struct SelectionRegion {
122 SelectionRegion(); 135 SelectionRegion();
123 SelectionRegion(const SelectionRegion& other); 136 SelectionRegion(const SelectionRegion& other);
124 137
125 // The begining of the selection region. 138 // The begining of the selection region.
126 gfx::SelectionBound anchor; 139 gfx::SelectionBound anchor;
127 // The end of the selection region (caret position). 140 // The end of the selection region (caret position).
128 gfx::SelectionBound focus; 141 gfx::SelectionBound focus;
129 }; 142 };
130 143
144 // Ccomposition range information.
145 struct CompositionRangeInfo {
EhsanK 2016/07/07 22:10:58 We do not store gfx::Range for Aura since it was n
146 CompositionRangeInfo();
147 CompositionRangeInfo(const CompositionRangeInfo& other);
148 ~CompositionRangeInfo();
149
150 std::vector<gfx::Rect> character_bounds;
151 };
152
131 // This class is used to create maps which hold specific IME state for a 153 // This class is used to create maps which hold specific IME state for a
132 // view. 154 // view.
133 template <class Value> 155 template <class Value>
134 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> { 156 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> {
135 }; 157 };
136 158
137 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, 159 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
138 bool did_update_state); 160 bool did_update_state);
139 161
140 // The view with active text input state, i.e., a focused <input> element. 162 // 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 163 // 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. 164 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE.
143 RenderWidgetHostViewBase* active_view_; 165 RenderWidgetHostViewBase* active_view_;
144 166
145 ViewMap<TextInputState> text_input_state_map_; 167 ViewMap<TextInputState> text_input_state_map_;
146 168
147 // Text selection bounds information for registered views. 169 // Text selection bounds information for registered views.
148 ViewMap<SelectionRegion> selection_region_map_; 170 ViewMap<SelectionRegion> selection_region_map_;
171 ViewMap<CompositionRangeInfo> composition_range_info_map_;
149 172
150 base::ObserverList<Observer> observer_list_; 173 base::ObserverList<Observer> observer_list_;
151 174
152 DISALLOW_COPY_AND_ASSIGN(TextInputManager); 175 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
153 }; 176 };
154 } 177 }
155 178
156 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 179 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698