Chromium Code Reviews| 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..c14a502f22bd25a6a27b3e70eefd5eed058f6504 |
| --- /dev/null |
| +++ b/content/browser/renderer_host/text_input_manager.h |
| @@ -0,0 +1,95 @@ |
| +// 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_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ |
| +#define CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ |
| + |
| +#include <unordered_map> |
| + |
| +#include "base/observer_list.h" |
| +#include "content/common/content_export.h" |
| +#include "content/common/text_input_state.h" |
| + |
| +namespace content { |
| + |
| +class RenderWidgetHostView; |
| +class RenderWidgetHostViewBase; |
| +class WebContents; |
| + |
| +// A class which receives updates of TextInputState from multiple sources and |
| +// decides what the new TextInputState is. It also notifies the observers when |
| +// text input state is updated. |
| +class CONTENT_EXPORT TextInputManager { |
| + public: |
| + // The tab's top-level 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 a view has called UpdateTextInputState on TextInputManager. |
| + // If the call has led to a change in TextInputState, |did_update_state| is |
| + // true. In some plaforms, we need this update even when the state has not |
| + // changed (e.g., Aura for updating IME). |
| + virtual void OnUpdateTextInputStateCalled( |
| + TextInputManager* text_input_manager, |
| + RenderWidgetHostViewBase* updated_view, |
| + bool did_update_state) {} |
| + }; |
| + |
| + TextInputManager(); |
| + ~TextInputManager(); |
| + |
| + // Returns the currently active view (i.e., the RWHV with a focused <input> |
| + // element), or nullptr if none exist. The |active_view_| cannot have a |
| + // |TextInputState.type| of ui::TEXT_INPUT_TYPE_NONE. |
| + RenderWidgetHostViewBase* GetActiveView() const; |
| + |
| + // Returns the TextInputState corresponding to |active_view_|. |
| + // 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(); |
| + |
| + // Updates the TextInputState 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|. |
|
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
|
| + void Register(RenderWidgetHostViewBase* view); |
| + |
| + // Clears the TextInputState from the |view|. If |view == active_view_|, this |
| + // call will lead to a TextInputState update since the TextInputState.type |
| + // should be reset to none. |
| + void Unregister(RenderWidgetHostViewBase* view); |
| + |
| + // Returns true if |view| is already registered. |
| + bool IsRegistered(RenderWidgetHostViewBase* view) const; |
| + |
| + // Add and remove observers for notifications regarding updates in the |
| + // TextInputState. Clients must be sure to remove themselves before they go |
| + // away. |
| + 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
|
| + void RemoveObserver(Observer* observer); |
| + |
| + private: |
| + friend bool GetTextInputTypeForView(WebContents* web_contents, |
| + RenderWidgetHostView* view, |
| + ui::TextInputType* type); |
| + |
| + void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, |
| + bool did_update_state); |
| + |
| + // 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_RENDERER_HOST_TEXT_INPUT_MANAGER_H__ |