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

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: Addressing shuchen@ and kenrb@ comments 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 TextInputState for |view| has changed from its previous
32 // value. The change is determined on each platform differently by only
33 // considering the change in the value of a subset of fields in the
34 // TextInputState.
35 virtual void OnTextInputStateUpdated(TextInputManager* text_input_manager,
36 RenderWidgetHostViewBase* view) {}
37
38 // Called when a view has called UpdateTextInputState on TextInputManager,
39 // regardless the call having lead to change in TextInputState. In some
40 // platforms this is necessary as it gives the tab-level |view| the chance
41 // do some other task, e.g., show IME if needed in Aura.
42 virtual void OnTextInputStateUpdateCalled(
EhsanK 2016/05/13 16:00:56 shuchen@, kenrb@: To differentiate between a 'chan
43 TextInputManager* text_input_manager) {}
44
45 // Notifies all the observers that |text_input_manager| is being destroyed.
46 // TODO(ekaramad): All RWHV should get this call, but only the top-level
47 // RWHV for the outermost WebContents should be called on the other observer
48 // methods. We should separate the two classes of observers when resolving
49 // crbug.com/609846.
50 virtual void OnDestroyingTextInputManager(
51 TextInputManager* text_input_manager) {}
52 };
53
54 explicit TextInputManager();
55 ~TextInputManager() override;
56
57 // Returns the current text input state corresponding to |active_source_|.
58 // Users of this method should not hold on to the pointer as it might become
59 // dangling if the TextInputManager or |active_view_| might go away.
60 const TextInputState* GetTextInputState();
61
62 // Returns the currently active view. The active view is the last
63 // RenderWidgetHostViewBase which reported a |TextInputState.type| of other
64 // than ui::TEXT_INPUT_TYPE_NONE.
65 RenderWidgetHostViewBase* GetActiveView() const;
66
67 // Updates the text input state for |view|.
68 void UpdateTextInputState(RenderWidgetHostViewBase* view,
69 const TextInputState& state);
70
71 // Registers the given |view| for tracking its TextInputState.
72 // TextInputManager will observe the lifetime of the |view|.
73 void Register(RenderWidgetHostViewBase* view);
74
75 // Clear text input state of |view| and removes TextInputManager from its
76 // observer list. It is important to call this for any RWHV being tracked
77 // before destruction of RWHV or TextInputManager.
78 void Unregister(RenderWidgetHostViewBase* view);
79
80 // Returns true if |view| is already registered.
81 bool IsRegisteredView(RenderWidgetHostViewBase* view) const;
82
83 void AddObserver(Observer* observer);
84 void RemoveObserver(Observer* observer);
85
86 private:
87 friend class TestTextInputManagerObserver;
88
89 // RenderWidgetHostViewObserver implementation.
90 void OnRenderWidgetHostViewBaseDestroyed(
91 RenderWidgetHostViewBase* view) override;
92
93 void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
94 bool state_changed);
95
96 // The view with active text input state.
97 RenderWidgetHostViewBase* active_view_;
98
99 std::unordered_map<RenderWidgetHostViewBase*, TextInputState>
100 text_input_state_map_;
101
102 base::ObserverList<Observer> observer_list_;
103
104 DISALLOW_COPY_AND_ASSIGN(TextInputManager);
105 };
106 }
107
108 #endif // CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698