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

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: Created 4 years, 6 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 RenderWidgetHostView; 20 class RenderWidgetHostView;
17 class RenderWidgetHostViewBase; 21 class RenderWidgetHostViewBase;
18 class WebContents; 22 class WebContents;
19 23
20 // A class which receives updates of TextInputState from multiple sources and 24 // A class which receives updates of TextInputState from multiple sources and
21 // decides what the new TextInputState is. It also notifies the observers when 25 // decides what the new TextInputState is. It also notifies the observers when
22 // text input state is updated. 26 // text input state is updated.
23 class CONTENT_EXPORT TextInputManager { 27 class CONTENT_EXPORT TextInputManager {
24 public: 28 public:
25 // The tab's top-level RWHV should be an observer of TextInputManager to get 29 // The tab's top-level RWHV should be an observer of TextInputManager to get
26 // notifications about changes in TextInputState or other IME related state 30 // notifications about changes in TextInputState or other IME related state
27 // for child frames. 31 // for child frames.
28 class CONTENT_EXPORT Observer { 32 class CONTENT_EXPORT Observer {
29 public: 33 public:
30 // Called when a view has called UpdateTextInputState on TextInputManager. 34 // Called when a view has called UpdateTextInputState on TextInputManager.
31 // If the call has led to a change in TextInputState, |did_update_state| is 35 // If the call has led to a change in TextInputState, |did_update_state| is
32 // true. In some plaforms, we need this update even when the state has not 36 // true. In some plaforms, we need this update even when the state has not
33 // changed (e.g., Aura for updating IME). 37 // changed (e.g., Aura for updating IME).
34 virtual void OnUpdateTextInputStateCalled( 38 virtual void OnUpdateTextInputStateCalled(
35 TextInputManager* text_input_manager, 39 TextInputManager* text_input_manager,
36 RenderWidgetHostViewBase* updated_view, 40 RenderWidgetHostViewBase* updated_view,
37 bool did_update_state) {} 41 bool did_update_state) {}
42 // Called when the selection bounds for the |updated_view| has changed.
43 virtual void OnSelectionBoundsChanged(
44 TextInputManager* text_input_manager,
45 RenderWidgetHostViewBase* updated_view) {}
38 }; 46 };
39 47
40 TextInputManager(); 48 TextInputManager();
41 ~TextInputManager(); 49 ~TextInputManager();
42 50
43 // Returns the currently active view (i.e., the RWHV with a focused <input> 51 // Returns the currently active view (i.e., the RWHV with a focused <input>
44 // element), or nullptr if none exist. The |active_view_| cannot have a 52 // element), or nullptr if none exist. The |active_view_| cannot have a
45 // |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. 53 // |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE.
46 RenderWidgetHostViewBase* GetActiveView() const; 54 RenderWidgetHostViewBase* GetActiveView() const;
47 55
48 // Returns the TextInputState corresponding to |active_view_|. 56 // Returns the TextInputState corresponding to |active_view_|.
49 // Users of this method should not hold on to the pointer as it might become 57 // Users of this method should not hold on to the pointer as it might become
50 // dangling if the TextInputManager or |active_view_| might go away. 58 // dangling if the TextInputManager or |active_view_| might go away.
51 const TextInputState* GetTextInputState(); 59 const TextInputState* GetTextInputState();
52 60
61 // Returns the rect between selection bounds for the |active_view_|.
62 gfx::Rect GetSelectionBoundsRect();
63
53 // Updates the TextInputState for |view|. 64 // Updates the TextInputState for |view|.
54 void UpdateTextInputState(RenderWidgetHostViewBase* view, 65 void UpdateTextInputState(RenderWidgetHostViewBase* view,
55 const TextInputState& state); 66 const TextInputState& state);
56 67
68 void SelectionBoundsChanged(RenderWidgetHostViewBase* view,
69 const ViewHostMsg_SelectionBounds_Params& params);
70
57 // Registers the given |view| for tracking its TextInputState. This is called 71 // Registers the given |view| for tracking its TextInputState. This is called
58 // by any view which has updates in its TextInputState (whether tab's RWHV or 72 // by any view which has updates in its TextInputState (whether tab's RWHV or
59 // that of a child frame). The |view| must unregister itself before being 73 // that of a child frame). The |view| must unregister itself before being
60 // destroyed (i.e., call TextInputManager::Unregister). 74 // destroyed (i.e., call TextInputManager::Unregister).
61 void Register(RenderWidgetHostViewBase* view); 75 void Register(RenderWidgetHostViewBase* view);
62 76
63 // Clears the TextInputState from the |view|. If |view == active_view_|, this 77 // Clears the TextInputState from the |view|. If |view == active_view_|, this
64 // call will lead to a TextInputState update since the TextInputState.type 78 // call will lead to a TextInputState update since the TextInputState.type
65 // should be reset to none. 79 // should be reset to none.
66 void Unregister(RenderWidgetHostViewBase* view); 80 void Unregister(RenderWidgetHostViewBase* view);
67 81
68 // Returns true if |view| is already registered. 82 // Returns true if |view| is already registered.
69 bool IsRegistered(RenderWidgetHostViewBase* view) const; 83 bool IsRegistered(RenderWidgetHostViewBase* view) const;
70 84
71 // Add and remove observers for notifications regarding updates in the 85 // Add and remove observers for notifications regarding updates in the
72 // TextInputState. Clients must be sure to remove themselves before they go 86 // TextInputState. Clients must be sure to remove themselves before they go
73 // away. 87 // away.
74 // Only the tab's RWHV should observer TextInputManager. In tests, however, 88 // Only the tab's RWHV should observer TextInputManager. In tests, however,
75 // in addition to the tab's RWHV, one or more test observers might observe 89 // in addition to the tab's RWHV, one or more test observers might observe
76 // TextInputManager. 90 // TextInputManager.
77 void AddObserver(Observer* observer); 91 void AddObserver(Observer* observer);
78 void RemoveObserver(Observer* observer); 92 void RemoveObserver(Observer* observer);
79 93
80 private: 94 private:
81 friend bool GetTextInputTypeForView(WebContents* web_contents, 95 friend bool GetTextInputTypeForView(WebContents* web_contents,
82 RenderWidgetHostView* view, 96 RenderWidgetHostView* view,
83 ui::TextInputType* type); 97 ui::TextInputType* type);
84 98
99 template <class Value>
100 class ViewMap : public std::unordered_map<RenderWidgetHostViewBase*, Value> {
101 };
102
85 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, 103 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
86 bool did_update_state); 104 bool did_update_state);
87 105
88 // The view with active text input state. 106 // The view with active text input state.
89 RenderWidgetHostViewBase* active_view_; 107 RenderWidgetHostViewBase* active_view_;
90 108
91 std::unordered_map<RenderWidgetHostViewBase*, TextInputState> 109 ViewMap<TextInputState> text_input_state_map_;
92 text_input_state_map_; 110 ViewMap<gfx::SelectionBound> selection_anchor_map_;
111 ViewMap<gfx::SelectionBound> selection_focus_map_;
93 112
94 base::ObserverList<Observer> observer_list_; 113 base::ObserverList<Observer> observer_list_;
95 114
96 DISALLOW_COPY_AND_ASSIGN(TextInputManager); 115 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
97 }; 116 };
98 } 117 }
99 118
100 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ 119 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698