| 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..b621cf688b813d62f501e8aab6802a43edcf8185
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/text_input_manager.h
|
| @@ -0,0 +1,98 @@
|
| +// 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) {}
|
| +
|
| + // Called when the |text_input_manager| is being destroyed.
|
| + virtual void OnDestroyingTextInputManager(
|
| + TextInputManager* text_input_manager) {}
|
| + };
|
| +
|
| + 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|.
|
| + 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 lifetime event notifications, as well as
|
| + // updates in the TextInputState. Clients must be sure to remove themselves
|
| + // before they go away.
|
| + void AddObserver(Observer* observer);
|
| + void RemoveObserver(Observer* observer);
|
| +
|
| + private:
|
| + friend std::unordered_map<RenderWidgetHostView*, ui::TextInputType>
|
| + GetTextInputTypeMapFromWebContents(WebContents* web_contents);
|
| +
|
| + 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__
|
|
|