OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ | 5 #ifndef UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ |
6 #define UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ | 6 #define UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/event_types.h" | 10 #include "base/event_types.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "ui/aura/window_observer.h" | 13 #include "ui/aura/window_observer.h" |
14 #include "ui/base/ime/input_method_observer.h" | 14 #include "ui/base/ime/input_method_observer.h" |
15 #include "ui/base/ime/text_input_type.h" | 15 #include "ui/base/ime/text_input_type.h" |
16 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/keyboard/keyboard_export.h" | 17 #include "ui/keyboard/keyboard_export.h" |
| 18 #include "ui/keyboard/keyboard_layout_delegate.h" |
18 | 19 |
19 namespace aura { | 20 namespace aura { |
20 class Window; | 21 class Window; |
21 } | 22 } |
22 namespace ui { | 23 namespace ui { |
23 class InputMethod; | 24 class InputMethod; |
24 class TextInputClient; | 25 class TextInputClient; |
25 } | 26 } |
26 | 27 |
27 namespace keyboard { | 28 namespace keyboard { |
(...skipping 23 matching lines...) Expand all Loading... |
51 public: | 52 public: |
52 // Different ways to hide the keyboard. | 53 // Different ways to hide the keyboard. |
53 enum HideReason { | 54 enum HideReason { |
54 // System initiated. | 55 // System initiated. |
55 HIDE_REASON_AUTOMATIC, | 56 HIDE_REASON_AUTOMATIC, |
56 // User initiated. | 57 // User initiated. |
57 HIDE_REASON_MANUAL, | 58 HIDE_REASON_MANUAL, |
58 }; | 59 }; |
59 | 60 |
60 // Takes ownership of |ui|. | 61 // Takes ownership of |ui|. |
61 explicit KeyboardController(KeyboardUI* ui); | 62 explicit KeyboardController(KeyboardUI* ui, KeyboardLayoutDelegate* delegate); |
62 ~KeyboardController() override; | 63 ~KeyboardController() override; |
63 | 64 |
64 // Returns the container for the keyboard, which is owned by | 65 // Returns the container for the keyboard, which is owned by |
65 // KeyboardController. | 66 // KeyboardController. |
66 aura::Window* GetContainerWindow(); | 67 aura::Window* GetContainerWindow(); |
67 | 68 |
68 // Whether the container window for the keyboard has been initialized. | 69 // Whether the container window for the keyboard has been initialized. |
69 bool keyboard_container_initialized() const { return container_ != nullptr; } | 70 bool keyboard_container_initialized() const { return container_ != nullptr; } |
70 | 71 |
71 // Reloads the content of the keyboard. No-op if the keyboard content is not | 72 // Reloads the content of the keyboard. No-op if the keyboard content is not |
72 // loaded yet. | 73 // loaded yet. |
73 void Reload(); | 74 void Reload(); |
74 | 75 |
75 // Hides virtual keyboard and notifies observer bounds change. | 76 // Hides virtual keyboard and notifies observer bounds change. |
76 // This function should be called with a delay to avoid layout flicker | 77 // This function should be called with a delay to avoid layout flicker |
77 // when the focus of input field quickly change. |automatic| is true when the | 78 // when the focus of input field quickly change. |automatic| is true when the |
78 // call is made by the system rather than initiated by the user. | 79 // call is made by the system rather than initiated by the user. |
79 void HideKeyboard(HideReason reason); | 80 void HideKeyboard(HideReason reason); |
80 | 81 |
81 // Notifies the keyboard observer for keyboard bounds changed. | 82 // Notifies the keyboard observer for keyboard bounds changed. |
82 void NotifyKeyboardBoundsChanging(const gfx::Rect& new_bounds); | 83 void NotifyKeyboardBoundsChanging(const gfx::Rect& new_bounds); |
83 | 84 |
84 // Management of the observer list. | 85 // Management of the observer list. |
85 virtual void AddObserver(KeyboardControllerObserver* observer); | 86 virtual void AddObserver(KeyboardControllerObserver* observer); |
86 virtual void RemoveObserver(KeyboardControllerObserver* observer); | 87 virtual void RemoveObserver(KeyboardControllerObserver* observer); |
87 | 88 |
88 KeyboardUI* ui() { return ui_.get(); } | 89 KeyboardUI* ui() { return ui_.get(); } |
89 | 90 |
90 void set_lock_keyboard(bool lock) { lock_keyboard_ = lock; } | 91 void set_keyboard_locked(bool lock) { keyboard_locked_ = lock; } |
91 | 92 |
92 bool get_lock_keyboard() const { return lock_keyboard_; } | 93 bool keyboard_locked() const { return keyboard_locked_; } |
93 | 94 |
94 KeyboardMode keyboard_mode() const { return keyboard_mode_; } | 95 KeyboardMode keyboard_mode() const { return keyboard_mode_; } |
95 | 96 |
96 void SetKeyboardMode(KeyboardMode mode); | 97 void SetKeyboardMode(KeyboardMode mode); |
97 | 98 |
98 // Force the keyboard to show up if not showing and lock the keyboard if | 99 // Force the keyboard to show up if not showing and lock the keyboard if |
99 // |lock| is true. | 100 // |lock| is true. |
100 void ShowKeyboard(bool lock); | 101 void ShowKeyboard(bool lock); |
101 | 102 |
| 103 // Force the keyboard to show up in the specific display if not showing and |
| 104 // lock the keyboard |
| 105 void ShowKeyboardInDisplay(const int64_t display_id); |
| 106 |
102 // Sets the active keyboard controller. KeyboardController takes ownership of | 107 // Sets the active keyboard controller. KeyboardController takes ownership of |
103 // the instance. Calling ResetIntance with a new instance destroys the | 108 // the instance. Calling ResetIntance with a new instance destroys the |
104 // previous one. May be called with NULL to clear the instance. | 109 // previous one. May be called with NULL to clear the instance. |
105 static void ResetInstance(KeyboardController* controller); | 110 static void ResetInstance(KeyboardController* controller); |
106 | 111 |
107 // Retrieve the active keyboard controller. | 112 // Retrieve the active keyboard controller. |
108 static KeyboardController* GetInstance(); | 113 static KeyboardController* GetInstance(); |
109 | 114 |
110 // Returns true if keyboard is currently visible. | 115 // Returns true if keyboard is currently visible. |
111 bool keyboard_visible() { return keyboard_visible_; } | 116 bool keyboard_visible() { return keyboard_visible_; } |
(...skipping 22 matching lines...) Expand all Loading... |
134 // InputMethodObserver overrides | 139 // InputMethodObserver overrides |
135 void OnTextInputTypeChanged(const ui::TextInputClient* client) override {} | 140 void OnTextInputTypeChanged(const ui::TextInputClient* client) override {} |
136 void OnFocus() override {} | 141 void OnFocus() override {} |
137 void OnBlur() override {} | 142 void OnBlur() override {} |
138 void OnCaretBoundsChanged(const ui::TextInputClient* client) override {} | 143 void OnCaretBoundsChanged(const ui::TextInputClient* client) override {} |
139 void OnTextInputStateChanged(const ui::TextInputClient* client) override; | 144 void OnTextInputStateChanged(const ui::TextInputClient* client) override; |
140 void OnInputMethodDestroyed(const ui::InputMethod* input_method) override; | 145 void OnInputMethodDestroyed(const ui::InputMethod* input_method) override; |
141 void OnShowImeIfNeeded() override; | 146 void OnShowImeIfNeeded() override; |
142 | 147 |
143 // Show virtual keyboard immediately with animation. | 148 // Show virtual keyboard immediately with animation. |
144 void ShowKeyboardInternal(); | 149 void ShowKeyboardInternal(int64_t display_id); |
145 | 150 |
146 // Returns true if keyboard is scheduled to hide. | 151 // Returns true if keyboard is scheduled to hide. |
147 bool WillHideKeyboard() const; | 152 bool WillHideKeyboard() const; |
148 | 153 |
149 // Called when show and hide animation finished successfully. If the animation | 154 // Called when show and hide animation finished successfully. If the animation |
150 // is aborted, it won't be called. | 155 // is aborted, it won't be called. |
151 void ShowAnimationFinished(); | 156 void ShowAnimationFinished(); |
152 void HideAnimationFinished(); | 157 void HideAnimationFinished(); |
153 | 158 |
154 std::unique_ptr<KeyboardUI> ui_; | 159 std::unique_ptr<KeyboardUI> ui_; |
| 160 KeyboardLayoutDelegate* layout_delegate_; |
155 std::unique_ptr<aura::Window> container_; | 161 std::unique_ptr<aura::Window> container_; |
156 // CallbackAnimationObserver should destructed before container_ because it | 162 // CallbackAnimationObserver should destructed before container_ because it |
157 // uses container_'s animator. | 163 // uses container_'s animator. |
158 std::unique_ptr<CallbackAnimationObserver> animation_observer_; | 164 std::unique_ptr<CallbackAnimationObserver> animation_observer_; |
159 | 165 |
160 ui::InputMethod* input_method_; | 166 ui::InputMethod* input_method_; |
161 bool keyboard_visible_; | 167 bool keyboard_visible_; |
162 bool show_on_resize_; | 168 bool show_on_resize_; |
163 bool lock_keyboard_; | 169 // If true, the keyboard is always visible even if no window has input focus. |
| 170 bool keyboard_locked_; |
164 KeyboardMode keyboard_mode_; | 171 KeyboardMode keyboard_mode_; |
165 ui::TextInputType type_; | 172 ui::TextInputType type_; |
166 | 173 |
167 base::ObserverList<KeyboardControllerObserver> observer_list_; | 174 base::ObserverList<KeyboardControllerObserver> observer_list_; |
168 | 175 |
169 // The currently used keyboard position. | 176 // The currently used keyboard position. |
170 gfx::Rect current_keyboard_bounds_; | 177 gfx::Rect current_keyboard_bounds_; |
171 | 178 |
172 static KeyboardController* instance_; | 179 static KeyboardController* instance_; |
173 | 180 |
174 base::WeakPtrFactory<KeyboardController> weak_factory_; | 181 base::WeakPtrFactory<KeyboardController> weak_factory_; |
175 | 182 |
176 DISALLOW_COPY_AND_ASSIGN(KeyboardController); | 183 DISALLOW_COPY_AND_ASSIGN(KeyboardController); |
177 }; | 184 }; |
178 | 185 |
179 } // namespace keyboard | 186 } // namespace keyboard |
180 | 187 |
181 #endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ | 188 #endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ |
OLD | NEW |