| 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..b029074589691bc84b7443030048d744c271b445
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/text_input_manager.h
|
| @@ -0,0 +1,89 @@
|
| +// 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:
|
| + 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) {}
|
| +
|
| + virtual void OnTextInputManagerDestroyed(
|
| + TextInputManager* text_input_manager) {}
|
| + };
|
| +
|
| + explicit TextInputManager();
|
| + ~TextInputManager() override;
|
| +
|
| + // Returns the current text input state corresponding to |active_source_|.
|
| + 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.
|
| + void Unregister(RenderWidgetHostViewBase* view);
|
| +
|
| + 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__
|
|
|