OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__ |
| 6 #define CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__ |
| 7 |
| 8 #include <unordered_map> |
| 9 |
| 10 #include "base/observer_list.h" |
| 11 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h" |
| 12 #include "content/common/content_export.h" |
| 13 #include "content/common/text_input_state.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class RenderWidgetHostViewBase; |
| 18 class TestTextInputManagerObserver; |
| 19 |
| 20 // A class which receives updates of Text Input State from multiple sources and |
| 21 // decides what the new text input state is. It also notifies the observers when |
| 22 // text input state is updated. |
| 23 class CONTENT_EXPORT TextInputManager |
| 24 : public RenderWidgetHostViewBaseObserver { |
| 25 public: |
| 26 class CONTENT_EXPORT Observer { |
| 27 public: |
| 28 // Called when the text input state for |view| has been updated. If the |
| 29 // the update leads to a change in the text input state for the view (which |
| 30 // is defined differently for each platform), then |changed| will be true. |
| 31 virtual void OnTextInputStateUpdated(TextInputManager* text_input_manager, |
| 32 RenderWidgetHostViewBase* view, |
| 33 bool changed) {} |
| 34 |
| 35 virtual void OnTextInputManagerDestroyed( |
| 36 TextInputManager* text_input_manager) {} |
| 37 }; |
| 38 |
| 39 explicit TextInputManager(); |
| 40 ~TextInputManager() override; |
| 41 |
| 42 // Returns the current text input state corresponding to |active_source_|. |
| 43 const TextInputState* GetTextInputState(); |
| 44 |
| 45 // Returns the currently active view. The active view is the last |
| 46 // RenderWidgetHostViewBase which reported a |TextInputState.type| of other |
| 47 // than ui::TEXT_INPUT_TYPE_NONE. |
| 48 RenderWidgetHostViewBase* GetActiveView() const; |
| 49 |
| 50 // Updates the text input state for |view|. |
| 51 void UpdateTextInputState(RenderWidgetHostViewBase* view, |
| 52 const TextInputState& state); |
| 53 |
| 54 // Registers the given |view| for tracking its TextInputState. |
| 55 // TextInputManager will observe the lifetime of the |view|. |
| 56 void Register(RenderWidgetHostViewBase* view); |
| 57 |
| 58 // Clear text input state of |view| and removes TextInputManager from |
| 59 // its observer list. |
| 60 void Unregister(RenderWidgetHostViewBase* view); |
| 61 |
| 62 void AddObserver(Observer* observer); |
| 63 void RemoveObserver(Observer* observer); |
| 64 |
| 65 private: |
| 66 friend class TestTextInputManagerObserver; |
| 67 |
| 68 // RenderWidgetHostViewObserver implementations. |
| 69 void OnRenderWidgetHostViewBaseDestroyed( |
| 70 RenderWidgetHostViewBase* view) override; |
| 71 |
| 72 // Notifies all the observers about an update in TextInputState by some view. |
| 73 void NotifyObserversAboutInputStateUpdate( |
| 74 RenderWidgetHostViewBase* updated_view, |
| 75 bool changed); |
| 76 |
| 77 // The view with active text input state. |
| 78 RenderWidgetHostViewBase* active_view_; |
| 79 |
| 80 std::unordered_map<RenderWidgetHostViewBase*, TextInputState> |
| 81 text_input_state_map_; |
| 82 |
| 83 base::ObserverList<Observer> observer_list_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(TextInputManager); |
| 86 }; |
| 87 } |
| 88 |
| 89 #endif // CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__ |
OLD | NEW |