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

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

Issue 2057803002: Tracking SelectionBounds for all RenderWidgets on the Browser Side (Aura Only) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed an Error 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 10
10 #include "base/observer_list.h" 11 #include "base/observer_list.h"
11 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
12 #include "content/common/text_input_state.h" 13 #include "content/common/text_input_state.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/selection_bound.h"
16
17 struct ViewHostMsg_SelectionBounds_Params;
13 18
14 namespace content { 19 namespace content {
15 20
16 class RenderWidgetHostImpl; 21 class RenderWidgetHostImpl;
17 class RenderWidgetHostView; 22 class RenderWidgetHostView;
18 class RenderWidgetHostViewBase; 23 class RenderWidgetHostViewBase;
19 class WebContents; 24 class WebContents;
20 25
21 // A class which receives updates of TextInputState from multiple sources and 26 // A class which receives updates of TextInputState from multiple sources and
22 // decides what the new TextInputState is. It also notifies the observers when 27 // decides what the new TextInputState is. It also notifies the observers when
(...skipping 11 matching lines...) Expand all
34 // changed (e.g., Aura for updating IME). 39 // changed (e.g., Aura for updating IME).
35 virtual void OnUpdateTextInputStateCalled( 40 virtual void OnUpdateTextInputStateCalled(
36 TextInputManager* text_input_manager, 41 TextInputManager* text_input_manager,
37 RenderWidgetHostViewBase* updated_view, 42 RenderWidgetHostViewBase* updated_view,
38 bool did_update_state) {} 43 bool did_update_state) {}
39 // Called when |updated_view| has called ImeCancelComposition on 44 // Called when |updated_view| has called ImeCancelComposition on
40 // TextInputManager. 45 // TextInputManager.
41 virtual void OnImeCancelComposition( 46 virtual void OnImeCancelComposition(
42 TextInputManager* text_input_manager, 47 TextInputManager* text_input_manager,
43 RenderWidgetHostViewBase* updated_view) {} 48 RenderWidgetHostViewBase* updated_view) {}
49 // Called when the selection bounds for the |updated_view| has changed.
50 virtual void OnSelectionBoundsChanged(
51 TextInputManager* text_input_manager,
52 RenderWidgetHostViewBase* updated_view) {}
44 }; 53 };
45 54
46 TextInputManager(); 55 TextInputManager();
47 ~TextInputManager(); 56 ~TextInputManager();
48 57
49 // --------------------------------------------------------------------------- 58 // ---------------------------------------------------------------------------
50 // The following methods can be used to obtain information about IME-related 59 // The following methods can be used to obtain information about IME-related
51 // state for the active RenderWidget. 60 // state for the active RenderWidget.
52 61
53 // Returns the currently active widget, i.e., the RWH which is associated with 62 // Returns the currently active widget, i.e., the RWH which is associated with
54 // |active_view_|. 63 // |active_view_|.
55 RenderWidgetHostImpl* GetActiveWidget() const; 64 RenderWidgetHostImpl* GetActiveWidget() const;
56 65
57 // Returns the TextInputState corresponding to |active_view_|. 66 // Returns the TextInputState corresponding to |active_view_|.
58 // Users of this method should not hold on to the pointer as it might become 67 // Users of this method should not hold on to the pointer as it might become
59 // dangling if the TextInputManager or |active_view_| might go away. 68 // dangling if the TextInputManager or |active_view_| might go away.
60 const TextInputState* GetTextInputState(); 69 const TextInputState* GetTextInputState();
61 70
71 // Returns the rect between selection bounds for the |active_view_|.
72 gfx::Rect GetSelectionBoundsRect();
73
62 // --------------------------------------------------------------------------- 74 // ---------------------------------------------------------------------------
63 // The following methods are called by RWHVs on the tab to update their IME- 75 // The following methods are called by RWHVs on the tab to update their IME-
64 // related state. 76 // related state.
65 77
66 // Updates the TextInputState for |view|. 78 // Updates the TextInputState for |view|.
67 void UpdateTextInputState(RenderWidgetHostViewBase* view, 79 void UpdateTextInputState(RenderWidgetHostViewBase* view,
68 const TextInputState& state); 80 const TextInputState& state);
69 81
70 // The current IME composition has been cancelled on the renderer side for 82 // The current IME composition has been cancelled on the renderer side for
71 // the widget corresponding to |view|. 83 // the widget corresponding to |view|.
72 void ImeCancelComposition(RenderWidgetHostViewBase* view); 84 void ImeCancelComposition(RenderWidgetHostViewBase* view);
73 85
86 // Updates the selection bounds for the |view|. In Aura, selection bounds are
87 // used to provide the InputMethod with the position of the caret, e.g., in
88 // setting the position of the ui::ImeWindow.
89 void SelectionBoundsChanged(RenderWidgetHostViewBase* view,
90 const ViewHostMsg_SelectionBounds_Params& params);
91
74 // Registers the given |view| for tracking its TextInputState. This is called 92 // Registers the given |view| for tracking its TextInputState. This is called
75 // by any view which has updates in its TextInputState (whether tab's RWHV or 93 // by any view which has updates in its TextInputState (whether tab's RWHV or
76 // that of a child frame). The |view| must unregister itself before being 94 // that of a child frame). The |view| must unregister itself before being
77 // destroyed (i.e., call TextInputManager::Unregister). 95 // destroyed (i.e., call TextInputManager::Unregister).
78 void Register(RenderWidgetHostViewBase* view); 96 void Register(RenderWidgetHostViewBase* view);
79 97
80 // Clears the TextInputState from the |view|. If |view == active_view_|, this 98 // Clears the TextInputState from the |view|. If |view == active_view_|, this
81 // call will lead to a TextInputState update since the TextInputState.type 99 // call will lead to a TextInputState update since the TextInputState.type
82 // should be reset to none. 100 // should be reset to none.
83 void Unregister(RenderWidgetHostViewBase* view); 101 void Unregister(RenderWidgetHostViewBase* view);
84 102
85 // Returns true if |view| is already registered. 103 // Returns true if |view| is already registered.
86 bool IsRegistered(RenderWidgetHostViewBase* view) const; 104 bool IsRegistered(RenderWidgetHostViewBase* view) const;
87 105
88 // Add and remove observers for notifications regarding updates in the 106 // Add and remove observers for notifications regarding updates in the
89 // TextInputState. Clients must be sure to remove themselves before they go 107 // TextInputState. Clients must be sure to remove themselves before they go
90 // away. 108 // away.
91 // Only the tab's RWHV should observer TextInputManager. In tests, however, 109 // Only the tab's RWHV should observer TextInputManager. In tests, however,
92 // in addition to the tab's RWHV, one or more test observers might observe 110 // in addition to the tab's RWHV, one or more test observers might observe
93 // TextInputManager. 111 // TextInputManager.
94 void AddObserver(Observer* observer); 112 void AddObserver(Observer* observer);
95 void RemoveObserver(Observer* observer); 113 void RemoveObserver(Observer* observer);
96 114
97 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; } 115 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; }
98 size_t GetRegisteredViewsCountForTesting(); 116 size_t GetRegisteredViewsCountForTesting();
99 ui::TextInputType GetTextInputTypeForViewForTesting( 117 ui::TextInputType GetTextInputTypeForViewForTesting(
100 RenderWidgetHostViewBase* view); 118 RenderWidgetHostViewBase* view);
101 119
102 private: 120 private:
121 // Text selection bounds.
122 struct SelectionRegion {
123 SelectionRegion();
124 SelectionRegion(const SelectionRegion& other);
125
126 // The begining of the selection region.
127 gfx::SelectionBound anchor;
128 // The end of the selection region (caret position).
129 gfx::SelectionBound focus;
130 };
131
132 template <class Value>
133 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> {
134 };
135
103 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, 136 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
104 bool did_update_state); 137 bool did_update_state);
105 138
106 // The view with active text input state, i.e., a focused <input> element. 139 // The view with active text input state, i.e., a focused <input> element.
107 // It will be nullptr if no such view exists. Note that the active view 140 // It will be nullptr if no such view exists. Note that the active view
108 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. 141 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE.
109 RenderWidgetHostViewBase* active_view_; 142 RenderWidgetHostViewBase* active_view_;
110 143
111 std::unordered_map<RenderWidgetHostViewBase*, TextInputState> 144 ViewMap<TextInputState> text_input_state_map_;
112 text_input_state_map_; 145
146 // Maps a registered view to a pair of selection bounds where the first bound
147 // is selection anchor and the second is selection focus.
Charlie Reis 2016/06/30 20:27:21 nit: Stale comment.
EhsanK 2016/06/30 21:01:15 Acknowledged.
148 ViewMap<SelectionRegion> selection_region_map_;
113 149
114 base::ObserverList<Observer> observer_list_; 150 base::ObserverList<Observer> observer_list_;
115 151
116 DISALLOW_COPY_AND_ASSIGN(TextInputManager); 152 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
117 }; 153 };
118 } 154 }
119 155
120 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 156 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698