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

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: Merged Created 4 years, 7 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_TEXT_INPUT_MANAGER_H__
6 #define CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__
7
8 #include <unordered_map>
9
10 #include "base/observer_list.h"
11 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h"
12 #include "content/common/content_export.h"
13 #include "content/common/text_input_state.h"
14
15 namespace content {
16
17 class RenderWidgetHostViewBase;
18 class TestTextInputManagerObserver;
19
20 // A class which receives updates of Text Input State from multiple sources and
21 // decides what the new text input state is. It also notifies the observers when
22 // text input state is updated.
23 class CONTENT_EXPORT TextInputManager
24 : public RenderWidgetHostViewBaseObserver {
25 public:
26 // The top-level tab RWHV should be an observer of TextInputManager to get
27 // notifications about changes in TextInputState or other IME related state
28 // for child frames.
29 class CONTENT_EXPORT Observer {
30 public:
31 // Called when the text input state for |view| has been updated. If the
kenrb 2016/05/12 16:16:37 nit: "If the the update"
EhsanK 2016/05/13 16:00:56 Changed the comment altogether since the method si
32 // the update leads to a change in the text input state for the view (which
33 // is defined differently for each platform), then |changed| will be true.
kenrb 2016/05/12 16:16:37 This could use some clarification. First, is it ne
EhsanK 2016/05/13 16:00:56 The issue, which as of now only exists in Aura, is
34 virtual void OnTextInputStateUpdated(TextInputManager* text_input_manager,
35 RenderWidgetHostViewBase* view,
36 bool changed) {}
37
38 // Notifies all the observers that |text_input_manager| has been destroyed.
39 // It is important for (tab-level) RWHV to update its reference to
40 // |text_input_manager|.
41 // TODO(ekaramad): This observer call is necessary for tab-level RWHV to be
42 // notified of TextInputManager going away in destruction paths where
43 // WebContentsImpl is destroyed sooner than RWHV (in Aura, this happens
44 // through deleting the window object). We should revise this later and
45 // perhaps turn the Observer into a Delegate.
46 virtual void OnTextInputManagerDestroyed(
47 TextInputManager* text_input_manager) {}
48 };
49
50 explicit TextInputManager();
51 ~TextInputManager() override;
52
53 // Returns the current text input state corresponding to |active_source_|.
54 // Users of this method should not hold on to the pointer as it might become
55 // dangling if the TextInputManager or |active_view_| might go away.
56 const TextInputState* GetTextInputState();
57
58 // Returns the currently active view. The active view is the last
59 // RenderWidgetHostViewBase which reported a |TextInputState.type| of other
60 // than ui::TEXT_INPUT_TYPE_NONE.
61 RenderWidgetHostViewBase* GetActiveView() const;
62
63 // Updates the text input state for |view|.
64 void UpdateTextInputState(RenderWidgetHostViewBase* view,
65 const TextInputState& state);
66
67 // Registers the given |view| for tracking its TextInputState.
68 // TextInputManager will observe the lifetime of the |view|.
69 void Register(RenderWidgetHostViewBase* view);
70
71 // Clear text input state of |view| and removes TextInputManager from its
72 // observer list. It is important to call this for any RWHV being tracked
73 // before
kenrb 2016/05/12 16:16:37 nit: Unneeded line break.
EhsanK 2016/05/13 16:00:56 I think git cl format did this somehow. Done!
kenrb 2016/05/13 20:37:41 Yes it wraps comments wrong.
74 // destruction of RWHV or TextInputManager.
75 void Unregister(RenderWidgetHostViewBase* view);
76
77 // Returns true if |view| is already registered.
78 bool IsRegisteredView(RenderWidgetHostViewBase* view) const;
79
80 void AddObserver(Observer* observer);
81 void RemoveObserver(Observer* observer);
82
83 private:
84 friend class TestTextInputManagerObserver;
85
86 // RenderWidgetHostViewObserver implementations.
87 void OnRenderWidgetHostViewBaseDestroyed(
88 RenderWidgetHostViewBase* view) override;
89
90 // Notifies all the observers about an update in TextInputState by some view.
91 void NotifyObserversAboutInputStateUpdate(
92 RenderWidgetHostViewBase* updated_view,
93 bool changed);
94
95 // The view with active text input state.
96 RenderWidgetHostViewBase* active_view_;
97
98 std::unordered_map<RenderWidgetHostViewBase*, TextInputState>
99 text_input_state_map_;
100
101 base::ObserverList<Observer> observer_list_;
102
103 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
104 };
105 }
106
107 #endif // CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698