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

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 Compile Errors 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 9
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "content/common/content_export.h" 11 #include "content/common/content_export.h"
12 #include "content/common/text_input_state.h" 12 #include "content/common/text_input_state.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/selection_bound.h"
15
16 struct ViewHostMsg_SelectionBounds_Params;
13 17
14 namespace content { 18 namespace content {
15 19
16 class RenderWidgetHostImpl; 20 class RenderWidgetHostImpl;
17 class RenderWidgetHostView; 21 class RenderWidgetHostView;
18 class RenderWidgetHostViewBase; 22 class RenderWidgetHostViewBase;
19 class WebContents; 23 class WebContents;
20 24
21 // A class which receives updates of TextInputState from multiple sources and 25 // A class which receives updates of TextInputState from multiple sources and
22 // decides what the new TextInputState is. It also notifies the observers when 26 // decides what the new TextInputState is. It also notifies the observers when
23 // text input state is updated. 27 // text input state is updated.
24 class CONTENT_EXPORT TextInputManager { 28 class CONTENT_EXPORT TextInputManager {
25 public: 29 public:
26 // The tab's top-level RWHV should be an observer of TextInputManager to get 30 // The tab's top-level RWHV should be an observer of TextInputManager to get
27 // notifications about changes in TextInputState or other IME related state 31 // notifications about changes in TextInputState or other IME related state
28 // for child frames. 32 // for child frames.
29 class CONTENT_EXPORT Observer { 33 class CONTENT_EXPORT Observer {
30 public: 34 public:
31 // Called when a view has called UpdateTextInputState on TextInputManager. 35 // Called when a view has called UpdateTextInputState on TextInputManager.
32 // If the call has led to a change in TextInputState, |did_update_state| is 36 // If the call has led to a change in TextInputState, |did_update_state| is
33 // true. In some plaforms, we need this update even when the state has not 37 // true. In some plaforms, we need this update even when the state has not
34 // changed (e.g., Aura for updating IME). 38 // changed (e.g., Aura for updating IME).
35 virtual void OnUpdateTextInputStateCalled( 39 virtual void OnUpdateTextInputStateCalled(
36 TextInputManager* text_input_manager, 40 TextInputManager* text_input_manager,
37 RenderWidgetHostViewBase* updated_view, 41 RenderWidgetHostViewBase* updated_view,
38 bool did_update_state) {} 42 bool did_update_state) {}
43 // Called when the selection bounds for the |updated_view| has changed.
44 virtual void OnSelectionBoundsChanged(
45 TextInputManager* text_input_manager,
46 RenderWidgetHostViewBase* updated_view) {}
39 }; 47 };
40 48
41 TextInputManager(); 49 TextInputManager();
42 ~TextInputManager(); 50 ~TextInputManager();
43 51
44 // --------------------------------------------------------------------------- 52 // ---------------------------------------------------------------------------
45 // The following methods can be used to obtain information about IME-related 53 // The following methods can be used to obtain information about IME-related
46 // state for the active RenderWidget. 54 // state for the active RenderWidget.
47 55
48 // Returns the currently active widget, i.e., the RWH which is associated with 56 // Returns the currently active widget, i.e., the RWH which is associated with
49 // |active_view_|. 57 // |active_view_|.
50 RenderWidgetHostImpl* GetActiveWidget() const; 58 RenderWidgetHostImpl* GetActiveWidget() const;
51 59
52 // Returns the TextInputState corresponding to |active_view_|. 60 // Returns the TextInputState corresponding to |active_view_|.
53 // Users of this method should not hold on to the pointer as it might become 61 // Users of this method should not hold on to the pointer as it might become
54 // dangling if the TextInputManager or |active_view_| might go away. 62 // dangling if the TextInputManager or |active_view_| might go away.
55 const TextInputState* GetTextInputState(); 63 const TextInputState* GetTextInputState();
56 64
65 // Returns the rect between selection bounds for the |active_view_|.
66 gfx::Rect GetSelectionBoundsRect();
67
57 // --------------------------------------------------------------------------- 68 // ---------------------------------------------------------------------------
58 // The following methods are called by RWHVs on the tab to update their IME- 69 // The following methods are called by RWHVs on the tab to update their IME-
59 // related state. 70 // related state.
60 71
61 // Updates the TextInputState for |view|. 72 // Updates the TextInputState for |view|.
62 void UpdateTextInputState(RenderWidgetHostViewBase* view, 73 void UpdateTextInputState(RenderWidgetHostViewBase* view,
63 const TextInputState& state); 74 const TextInputState& state);
64 75
76 void SelectionBoundsChanged(RenderWidgetHostViewBase* view,
77 const ViewHostMsg_SelectionBounds_Params& params);
78
65 // Registers the given |view| for tracking its TextInputState. This is called 79 // Registers the given |view| for tracking its TextInputState. This is called
66 // by any view which has updates in its TextInputState (whether tab's RWHV or 80 // by any view which has updates in its TextInputState (whether tab's RWHV or
67 // that of a child frame). The |view| must unregister itself before being 81 // that of a child frame). The |view| must unregister itself before being
68 // destroyed (i.e., call TextInputManager::Unregister). 82 // destroyed (i.e., call TextInputManager::Unregister).
69 void Register(RenderWidgetHostViewBase* view); 83 void Register(RenderWidgetHostViewBase* view);
70 84
71 // Clears the TextInputState from the |view|. If |view == active_view_|, this 85 // Clears the TextInputState from the |view|. If |view == active_view_|, this
72 // call will lead to a TextInputState update since the TextInputState.type 86 // call will lead to a TextInputState update since the TextInputState.type
73 // should be reset to none. 87 // should be reset to none.
74 void Unregister(RenderWidgetHostViewBase* view); 88 void Unregister(RenderWidgetHostViewBase* view);
(...skipping 10 matching lines...) Expand all
85 void AddObserver(Observer* observer); 99 void AddObserver(Observer* observer);
86 void RemoveObserver(Observer* observer); 100 void RemoveObserver(Observer* observer);
87 101
88 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; } 102 RenderWidgetHostViewBase* active_view_for_testing() { return active_view_; }
89 103
90 private: 104 private:
91 friend bool GetTextInputTypeForView(WebContents* web_contents, 105 friend bool GetTextInputTypeForView(WebContents* web_contents,
92 RenderWidgetHostView* view, 106 RenderWidgetHostView* view,
93 ui::TextInputType* type); 107 ui::TextInputType* type);
94 108
109 template <class Value>
110 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> {
111 };
112
95 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, 113 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
96 bool did_update_state); 114 bool did_update_state);
97 115
98 // The view with active text input state, i.e., a focused <input> element. 116 // The view with active text input state, i.e., a focused <input> element.
99 // It will be nullptr if no such view exists. Note that the active view 117 // It will be nullptr if no such view exists. Note that the active view
100 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. 118 // cannot have a |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE.
101 RenderWidgetHostViewBase* active_view_; 119 RenderWidgetHostViewBase* active_view_;
102 120
103 std::unordered_map<RenderWidgetHostViewBase*, TextInputState> 121 ViewMap<TextInputState> text_input_state_map_;
104 text_input_state_map_; 122 ViewMap<gfx::SelectionBound> selection_anchor_map_;
123 ViewMap<gfx::SelectionBound> selection_focus_map_;
kenrb 2016/06/28 19:15:23 I'm not sure about this, but is it better to do it
EhsanK 2016/06/29 17:09:58 I made the two selection related one a map into a
105 124
106 base::ObserverList<Observer> observer_list_; 125 base::ObserverList<Observer> observer_list_;
107 126
108 DISALLOW_COPY_AND_ASSIGN(TextInputManager); 127 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
109 }; 128 };
110 } 129 }
111 130
112 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 131 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698