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

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

Issue 1948343002: [reland] Browser Side Text Input State Tracking for OOPIF (Aura Only) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
(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
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
40 TextInputManager();
41 ~TextInputManager();
42
43 // 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
45 // |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE.
46 RenderWidgetHostViewBase* GetActiveView() const;
47
48 // Returns the TextInputState corresponding to |active_view_|.
49 // 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.
51 const TextInputState* GetTextInputState();
52
53 // Updates the TextInputState for |view|.
54 void UpdateTextInputState(RenderWidgetHostViewBase* view,
55 const TextInputState& state);
56
57 // Registers the given |view| for tracking its TextInputState.
58 // TextInputManager will observe the lifetime of the |view|.
Charlie Reis 2016/06/02 22:03:29 This is expected to be called for all views (inclu
EhsanK 2016/06/03 17:00:34 Done. Also modified a bit as TextInputManager is n
59 void Register(RenderWidgetHostViewBase* view);
60
61 // Clears the TextInputState from the |view|. If |view == active_view_|, this
62 // call will lead to a TextInputState update since the TextInputState.type
63 // should be reset to none.
64 void Unregister(RenderWidgetHostViewBase* view);
65
66 // Returns true if |view| is already registered.
67 bool IsRegistered(RenderWidgetHostViewBase* view) const;
68
69 // Add and remove observers for notifications regarding updates in the
70 // TextInputState. Clients must be sure to remove themselves before they go
71 // away.
72 void AddObserver(Observer* observer);
Charlie Reis 2016/06/02 22:03:29 In contrast, I think we only expect this to be cal
EhsanK 2016/06/03 17:00:34 At any point in time, we might have more than 2. T
73 void RemoveObserver(Observer* observer);
74
75 private:
76 friend bool GetTextInputTypeForView(WebContents* web_contents,
77 RenderWidgetHostView* view,
78 ui::TextInputType* type);
79
80 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
81 bool did_update_state);
82
83 // The view with active text input state.
84 RenderWidgetHostViewBase* active_view_;
85
86 std::unordered_map<RenderWidgetHostViewBase*, TextInputState>
87 text_input_state_map_;
88
89 base::ObserverList<Observer> observer_list_;
90
91 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
92 };
93 }
94
95 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698