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

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: Removed |selection_anchor_| and |selection_focus_| from RenderWidgetHostViewAura. 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 void SelectionBoundsChanged(RenderWidgetHostViewBase* view,
Charlie Reis 2016/06/29 20:18:37 Please add a comment about what selection bounds a
EhsanK 2016/06/30 00:24:45 Good point. This is not necessarily triggered by
87 const ViewHostMsg_SelectionBounds_Params& params);
88
74 // Registers the given |view| for tracking its TextInputState. This is called 89 // 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 90 // 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 91 // that of a child frame). The |view| must unregister itself before being
77 // destroyed (i.e., call TextInputManager::Unregister). 92 // destroyed (i.e., call TextInputManager::Unregister).
78 void Register(RenderWidgetHostViewBase* view); 93 void Register(RenderWidgetHostViewBase* view);
79 94
80 // Clears the TextInputState from the |view|. If |view == active_view_|, this 95 // Clears the TextInputState from the |view|. If |view == active_view_|, this
81 // call will lead to a TextInputState update since the TextInputState.type 96 // call will lead to a TextInputState update since the TextInputState.type
82 // should be reset to none. 97 // should be reset to none.
83 void Unregister(RenderWidgetHostViewBase* view); 98 void Unregister(RenderWidgetHostViewBase* view);
84 99
85 // Returns true if |view| is already registered. 100 // Returns true if |view| is already registered.
86 bool IsRegistered(RenderWidgetHostViewBase* view) const; 101 bool IsRegistered(RenderWidgetHostViewBase* view) const;
87 102
88 // Add and remove observers for notifications regarding updates in the 103 // Add and remove observers for notifications regarding updates in the
89 // TextInputState. Clients must be sure to remove themselves before they go 104 // TextInputState. Clients must be sure to remove themselves before they go
90 // away. 105 // away.
91 // Only the tab's RWHV should observer TextInputManager. In tests, however, 106 // 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 107 // in addition to the tab's RWHV, one or more test observers might observe
93 // TextInputManager. 108 // TextInputManager.
94 void AddObserver(Observer* observer); 109 void AddObserver(Observer* observer);
95 void RemoveObserver(Observer* observer); 110 void RemoveObserver(Observer* observer);
96 111
97 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; } 112 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; }
98 size_t GetRegisteredViewsCountForTesting(); 113 size_t GetRegisteredViewsCountForTesting();
99 ui::TextInputType GetTextInputTypeForViewForTesting( 114 ui::TextInputType GetTextInputTypeForViewForTesting(
100 RenderWidgetHostViewBase* view); 115 RenderWidgetHostViewBase* view);
101 116
102 private: 117 private:
118 template <class Value>
119 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> {
120 };
121
103 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, 122 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
104 bool did_update_state); 123 bool did_update_state);
105 124
106 // The view with active text input state, i.e., a focused <input> element. 125 // 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 126 // 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. 127 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE.
109 RenderWidgetHostViewBase* active_view_; 128 RenderWidgetHostViewBase* active_view_;
110 129
111 std::unordered_map<RenderWidgetHostViewBase*, TextInputState> 130 ViewMap<TextInputState> text_input_state_map_;
112 text_input_state_map_; 131
132 #if defined(USE_AURA)
133 // Maps a registered view to a pair of selection bounds where the first bound
134 // is selection anchor and the second is selection focus.
135 ViewMap<std::pair<gfx::SelectionBound, gfx::SelectionBound>>
Charlie Reis 2016/06/29 20:18:37 I'm not a fan of using a map of pairs. Can we hav
EhsanK 2016/06/30 00:24:45 Acknowledged.
136 selection_bound_map_;
137 #endif
113 138
114 base::ObserverList<Observer> observer_list_; 139 base::ObserverList<Observer> observer_list_;
115 140
116 DISALLOW_COPY_AND_ASSIGN(TextInputManager); 141 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
117 }; 142 };
118 } 143 }
119 144
120 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 145 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698