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

Unified 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 side-by-side diff with in-line comments
Download patch
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..a4b702890ccc1fdd4aa1e349ce6b4790a4fdf3f6
--- /dev/null
+++ b/content/browser/renderer_host/text_input_manager.h
@@ -0,0 +1,107 @@
+// 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 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
+ // the update leads to a change in the text input state for the view (which
+ // 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
+ virtual void OnTextInputStateUpdated(TextInputManager* text_input_manager,
+ RenderWidgetHostViewBase* view,
+ bool changed) {}
+
+ // Notifies all the observers that |text_input_manager| has been destroyed.
+ // It is important for (tab-level) RWHV to update its reference to
+ // |text_input_manager|.
+ // TODO(ekaramad): This observer call is necessary for tab-level RWHV to be
+ // notified of TextInputManager going away in destruction paths where
+ // WebContentsImpl is destroyed sooner than RWHV (in Aura, this happens
+ // through deleting the window object). We should revise this later and
+ // perhaps turn the Observer into a Delegate.
+ virtual void OnTextInputManagerDestroyed(
+ 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
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.
+ // 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 implementations.
+ void OnRenderWidgetHostViewBaseDestroyed(
+ RenderWidgetHostViewBase* view) override;
+
+ // Notifies all the observers about an update in TextInputState by some view.
+ void NotifyObserversAboutInputStateUpdate(
+ RenderWidgetHostViewBase* updated_view,
+ bool 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__

Powered by Google App Engine
This is Rietveld 408576698