OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ | |
7 | |
8 #include <unordered_map> | |
9 | |
10 #include "base/observer_list.h" | |
11 #include "content/common/content_export.h" | |
12 #include "content/common/text_input_state.h" | |
13 | |
14 namespace content { | |
15 | |
16 class RenderWidgetHostView; | |
17 class RenderWidgetHostViewBase; | |
18 class WebContents; | |
19 | |
20 // A class which receives updates of TextInputState from multiple sources and | |
Charlie Reis
2016/05/26 06:22:05
nit: Remove extra space between "from" and "multip
EhsanK
2016/05/30 15:06:08
Done.
| |
21 // decides what the new TextInputState is. It also notifies the observers when | |
22 // text input state is updated. | |
23 class CONTENT_EXPORT TextInputManager { | |
24 public: | |
25 // 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 | |
27 // for child frames. | |
28 class CONTENT_EXPORT Observer { | |
29 public: | |
30 // Called when a view has called UpdateTextInputState on TextInputManager. | |
31 // 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 | |
33 // changed (e.g., Aura for updating IME). | |
34 virtual void OnUpdateTextInputStateCalled( | |
35 TextInputManager* text_input_manager, | |
36 RenderWidgetHostViewBase* updated_view, | |
37 bool did_update_state) {} | |
38 | |
39 // Called when the |text_input_manager| is being destroyed. | |
40 virtual void OnDestroyingTextInputManager( | |
Charlie Reis
2016/05/26 06:22:05
Please remove this for now. We can add it later w
EhsanK
2016/05/30 15:06:08
Done.
I removed it, but there is something about
Charlie Reis
2016/06/02 22:03:29
I'm not sure I follow that in depth, but my intent
| |
41 TextInputManager* text_input_manager) {} | |
42 }; | |
43 | |
44 TextInputManager(); | |
45 ~TextInputManager(); | |
46 | |
47 // Returns the currently active view (,i.e., the RWHV with a focused <input> | |
Charlie Reis
2016/05/26 06:22:05
nit: No comma after open paren.
EhsanK
2016/05/30 15:06:08
Done.
| |
48 // element), or nullptr if none exist. The |active_view_| cannot have a | |
49 // |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. | |
50 RenderWidgetHostViewBase* GetActiveView() const; | |
51 | |
52 // Returns the TextInputState corresponding to |active_view_|. | |
53 // 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. | |
55 const TextInputState* GetTextInputState(); | |
56 | |
57 // Updates the TextInputState for |view|. | |
58 void UpdateTextInputState(RenderWidgetHostViewBase* view, | |
59 const TextInputState& state); | |
60 | |
61 // Registers the given |view| for tracking its TextInputState. | |
62 // TextInputManager will observe the lifetime of the |view|. | |
63 void Register(RenderWidgetHostViewBase* view); | |
64 | |
65 // Clears the TextInputState from the |view|. If |view == active_view_|, this | |
66 // call will lead to a TextInputState update since the TextInputState.type | |
67 // should be reset to none. | |
68 void Unregister(RenderWidgetHostViewBase* view); | |
69 | |
70 // Returns true if |view| is already registered. | |
71 bool IsRegistered(RenderWidgetHostViewBase* view) const; | |
72 | |
73 // Add and remove observers for lifetime event notifications, as well as | |
Charlie Reis
2016/05/26 06:22:05
nit: There's no lifetime event notifications in th
EhsanK
2016/05/30 15:06:08
Acknowledged.
| |
74 // updates in the TextInputState. Clients must be sure to remove themselves | |
75 // before they go away. | |
76 void AddObserver(Observer* observer); | |
77 void RemoveObserver(Observer* observer); | |
78 | |
79 private: | |
80 friend std::unordered_map<RenderWidgetHostView*, ui::TextInputType> | |
81 GetTextInputTypeMapFromWebContents(WebContents* web_contents); | |
Charlie Reis
2016/05/26 06:22:05
We won't need this if we expose a GetTextInputType
EhsanK
2016/05/30 15:06:08
I am not sure if we need a GetTextInputTypeForView
Charlie Reis
2016/06/02 22:03:29
Sorry, that's not what I meant. I just meant we w
| |
82 | |
83 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, | |
84 bool did_update_state); | |
85 | |
86 // The view with active text input state. | |
87 RenderWidgetHostViewBase* active_view_; | |
88 | |
89 std::unordered_map<RenderWidgetHostViewBase*, TextInputState> | |
90 text_input_state_map_; | |
91 | |
92 base::ObserverList<Observer> observer_list_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(TextInputManager); | |
95 }; | |
96 } | |
97 | |
98 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ | |
OLD | NEW |