Index: content/browser/renderer_host/text_input_manager.h |
diff --git a/content/browser/renderer_host/text_input_manager.h b/content/browser/renderer_host/text_input_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c90d9a540a1eefdfbed39afbf94a6c59a2ad1f3f |
--- /dev/null |
+++ b/content/browser/renderer_host/text_input_manager.h |
@@ -0,0 +1,108 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__ |
+#define CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__ |
+ |
+#include <unordered_map> |
+ |
+#include "base/observer_list.h" |
+#include "content/browser/renderer_host/render_widget_host_view_base_observer.h" |
+#include "content/common/content_export.h" |
+#include "content/common/text_input_state.h" |
+ |
+namespace content { |
+ |
+class RenderWidgetHostViewBase; |
+class TestTextInputManagerObserver; |
+ |
+// A class which receives updates of Text Input State from multiple sources and |
+// decides what the new text input state is. It also notifies the observers when |
+// text input state is updated. |
+class CONTENT_EXPORT TextInputManager |
+ : public RenderWidgetHostViewBaseObserver { |
+ public: |
+ // The top-level tab RWHV should be an observer of TextInputManager to get |
+ // notifications about changes in TextInputState or other IME related state |
+ // for child frames. |
+ class CONTENT_EXPORT Observer { |
+ public: |
+ // Called when the TextInputState for |view| has changed from its previous |
+ // value. The change is determined on each platform differently by only |
+ // considering the change in the value of a subset of fields in the |
+ // TextInputState. |
+ virtual void OnTextInputStateUpdated(TextInputManager* text_input_manager, |
+ RenderWidgetHostViewBase* view) {} |
+ |
+ // Called when a view has called UpdateTextInputState on TextInputManager, |
+ // regardless the call having lead to change in TextInputState. In some |
+ // platforms this is necessary as it gives the tab-level |view| the chance |
+ // do some other task, e.g., show IME if needed in Aura. |
+ virtual void OnTextInputStateUpdateCalled( |
EhsanK
2016/05/13 16:00:56
shuchen@, kenrb@:
To differentiate between a 'chan
|
+ TextInputManager* text_input_manager) {} |
+ |
+ // Notifies all the observers that |text_input_manager| is being destroyed. |
+ // TODO(ekaramad): All RWHV should get this call, but only the top-level |
+ // RWHV for the outermost WebContents should be called on the other observer |
+ // methods. We should separate the two classes of observers when resolving |
+ // crbug.com/609846. |
+ virtual void OnDestroyingTextInputManager( |
+ TextInputManager* text_input_manager) {} |
+ }; |
+ |
+ explicit TextInputManager(); |
+ ~TextInputManager() override; |
+ |
+ // Returns the current text input state corresponding to |active_source_|. |
+ // Users of this method should not hold on to the pointer as it might become |
+ // dangling if the TextInputManager or |active_view_| might go away. |
+ const TextInputState* GetTextInputState(); |
+ |
+ // Returns the currently active view. The active view is the last |
+ // RenderWidgetHostViewBase which reported a |TextInputState.type| of other |
+ // than ui::TEXT_INPUT_TYPE_NONE. |
+ RenderWidgetHostViewBase* GetActiveView() const; |
+ |
+ // Updates the text input state for |view|. |
+ void UpdateTextInputState(RenderWidgetHostViewBase* view, |
+ const TextInputState& state); |
+ |
+ // Registers the given |view| for tracking its TextInputState. |
+ // TextInputManager will observe the lifetime of the |view|. |
+ void Register(RenderWidgetHostViewBase* view); |
+ |
+ // Clear text input state of |view| and removes TextInputManager from its |
+ // observer list. It is important to call this for any RWHV being tracked |
+ // before destruction of RWHV or TextInputManager. |
+ void Unregister(RenderWidgetHostViewBase* view); |
+ |
+ // Returns true if |view| is already registered. |
+ bool IsRegisteredView(RenderWidgetHostViewBase* view) const; |
+ |
+ void AddObserver(Observer* observer); |
+ void RemoveObserver(Observer* observer); |
+ |
+ private: |
+ friend class TestTextInputManagerObserver; |
+ |
+ // RenderWidgetHostViewObserver implementation. |
+ void OnRenderWidgetHostViewBaseDestroyed( |
+ RenderWidgetHostViewBase* view) override; |
+ |
+ void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, |
+ bool state_changed); |
+ |
+ // The view with active text input state. |
+ RenderWidgetHostViewBase* active_view_; |
+ |
+ std::unordered_map<RenderWidgetHostViewBase*, TextInputState> |
+ text_input_state_map_; |
+ |
+ base::ObserverList<Observer> observer_list_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TextInputManager); |
+}; |
+} |
+ |
+#endif // CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__ |