| 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
|
| + // 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.
|
| + 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
|
| + // 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__
|
|
|