Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: ui/keyboard/keyboard_controller.h

Issue 1392713002: Extract content dependency from keyboard code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/keyboard/keyboard_constants.cc ('k') | ui/keyboard/keyboard_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/event_types.h" 9 #include "base/event_types.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "ui/aura/window_observer.h" 12 #include "ui/aura/window_observer.h"
13 #include "ui/base/ime/input_method_observer.h" 13 #include "ui/base/ime/input_method_observer.h"
14 #include "ui/base/ime/text_input_type.h" 14 #include "ui/base/ime/text_input_type.h"
15 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/keyboard/keyboard_export.h" 16 #include "ui/keyboard/keyboard_export.h"
17 #include "url/gurl.h"
18 17
19 namespace aura { 18 namespace aura {
20 class Window; 19 class Window;
21 } 20 }
22 namespace ui { 21 namespace ui {
23 class InputMethod; 22 class InputMethod;
24 class TextInputClient; 23 class TextInputClient;
25 } 24 }
26 25
27 namespace keyboard { 26 namespace keyboard {
28 27
29 class CallbackAnimationObserver; 28 class CallbackAnimationObserver;
30 class WindowBoundsChangeObserver;
31 class KeyboardControllerObserver; 29 class KeyboardControllerObserver;
32 class KeyboardControllerProxy; 30 class KeyboardUI;
33 31
34 // Animation distance. 32 // Animation distance.
35 const int kAnimationDistance = 30; 33 const int kAnimationDistance = 30;
36 34
37 enum KeyboardMode { 35 enum KeyboardMode {
38 // Invalid mode. 36 // Invalid mode.
39 NONE, 37 NONE,
40 // Full width virtual keyboard. The virtual keyboard window has the same width 38 // Full width virtual keyboard. The virtual keyboard window has the same width
41 // as the display. 39 // as the display.
42 FULL_WIDTH, 40 FULL_WIDTH,
43 // Floating virtual keyboard. The virtual keyboard window has customizable 41 // Floating virtual keyboard. The virtual keyboard window has customizable
44 // width and is draggable. 42 // width and is draggable.
45 FLOATING, 43 FLOATING,
46 }; 44 };
47 45
48 // Provides control of the virtual keyboard, including providing a container 46 // Provides control of the virtual keyboard, including providing a container
49 // and controlling visibility. 47 // and controlling visibility.
50 class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver, 48 class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
51 public aura::WindowObserver { 49 public aura::WindowObserver {
52 public: 50 public:
53 // Different ways to hide the keyboard. 51 // Different ways to hide the keyboard.
54 enum HideReason { 52 enum HideReason {
55 // System initiated. 53 // System initiated.
56 HIDE_REASON_AUTOMATIC, 54 HIDE_REASON_AUTOMATIC,
57 // User initiated. 55 // User initiated.
58 HIDE_REASON_MANUAL, 56 HIDE_REASON_MANUAL,
59 }; 57 };
60 58
61 // Takes ownership of |proxy|. 59 // Takes ownership of |ui|.
62 explicit KeyboardController(KeyboardControllerProxy* proxy); 60 explicit KeyboardController(KeyboardUI* ui);
63 ~KeyboardController() override; 61 ~KeyboardController() override;
64 62
65 // Returns the container for the keyboard, which is owned by 63 // Returns the container for the keyboard, which is owned by
66 // KeyboardController. 64 // KeyboardController.
67 aura::Window* GetContainerWindow(); 65 aura::Window* GetContainerWindow();
68 66
69 // Whether the container window for the keyboard has been initialized. 67 // Whether the container window for the keyboard has been initialized.
70 bool keyboard_container_initialized() const { 68 bool keyboard_container_initialized() const {
71 return container_.get() != NULL; 69 return container_.get() != NULL;
72 } 70 }
73 71
74 // 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
75 // loaded yet. 73 // loaded yet.
76 void Reload(); 74 void Reload();
77 75
78 // Hides virtual keyboard and notifies observer bounds change. 76 // Hides virtual keyboard and notifies observer bounds change.
79 // 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
80 // 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
81 // 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.
82 void HideKeyboard(HideReason reason); 80 void HideKeyboard(HideReason reason);
83 81
84 // Notifies the keyboard observer for keyboard bounds changed. 82 // Notifies the keyboard observer for keyboard bounds changed.
85 void NotifyKeyboardBoundsChanging(const gfx::Rect& new_bounds); 83 void NotifyKeyboardBoundsChanging(const gfx::Rect& new_bounds);
86 84
87 // Management of the observer list. 85 // Management of the observer list.
88 virtual void AddObserver(KeyboardControllerObserver* observer); 86 virtual void AddObserver(KeyboardControllerObserver* observer);
89 virtual void RemoveObserver(KeyboardControllerObserver* observer); 87 virtual void RemoveObserver(KeyboardControllerObserver* observer);
90 88
91 KeyboardControllerProxy* proxy() { return proxy_.get(); } 89 KeyboardUI* ui() { return ui_.get(); }
92 90
93 void set_lock_keyboard(bool lock) { lock_keyboard_ = lock; } 91 void set_lock_keyboard(bool lock) { lock_keyboard_ = lock; }
94 92
95 KeyboardMode keyboard_mode() const { return keyboard_mode_; } 93 KeyboardMode keyboard_mode() const { return keyboard_mode_; }
96 94
97 void SetKeyboardMode(KeyboardMode mode); 95 void SetKeyboardMode(KeyboardMode mode);
98 96
99 // Force the keyboard to show up if not showing and lock the keyboard if 97 // Force the keyboard to show up if not showing and lock the keyboard if
100 // |lock| is true. 98 // |lock| is true.
101 void ShowKeyboard(bool lock); 99 void ShowKeyboard(bool lock);
(...skipping 10 matching lines...) Expand all
112 bool keyboard_visible() { return keyboard_visible_; } 110 bool keyboard_visible() { return keyboard_visible_; }
113 111
114 bool show_on_resize() { return show_on_resize_; } 112 bool show_on_resize() { return show_on_resize_; }
115 113
116 // Returns the current keyboard bounds. An empty rectangle will get returned 114 // Returns the current keyboard bounds. An empty rectangle will get returned
117 // when the keyboard is not shown or in FLOATING mode. 115 // when the keyboard is not shown or in FLOATING mode.
118 const gfx::Rect& current_keyboard_bounds() { 116 const gfx::Rect& current_keyboard_bounds() {
119 return current_keyboard_bounds_; 117 return current_keyboard_bounds_;
120 } 118 }
121 119
122 // Determines whether a particular window should have insets for overscroll.
123 bool ShouldEnableInsets(aura::Window* window);
124
125 // Updates insets on web content window
126 void UpdateWindowInsets(aura::Window* window);
127
128 private: 120 private:
129 // For access to Observer methods for simulation. 121 // For access to Observer methods for simulation.
130 friend class KeyboardControllerTest; 122 friend class KeyboardControllerTest;
131 123
132 // aura::WindowObserver overrides 124 // aura::WindowObserver overrides
133 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override; 125 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
134 void OnWindowAddedToRootWindow(aura::Window* window) override; 126 void OnWindowAddedToRootWindow(aura::Window* window) override;
135 void OnWindowRemovingFromRootWindow(aura::Window* window, 127 void OnWindowRemovingFromRootWindow(aura::Window* window,
136 aura::Window* new_root) override; 128 aura::Window* new_root) override;
137 void OnWindowBoundsChanged(aura::Window* window, 129 void OnWindowBoundsChanged(aura::Window* window,
138 const gfx::Rect& old_bounds, 130 const gfx::Rect& old_bounds,
139 const gfx::Rect& new_bounds) override; 131 const gfx::Rect& new_bounds) override;
140 132
141 // InputMethodObserver overrides 133 // InputMethodObserver overrides
142 void OnTextInputTypeChanged(const ui::TextInputClient* client) override {} 134 void OnTextInputTypeChanged(const ui::TextInputClient* client) override {}
143 void OnFocus() override {} 135 void OnFocus() override {}
144 void OnBlur() override {} 136 void OnBlur() override {}
145 void OnCaretBoundsChanged(const ui::TextInputClient* client) override {} 137 void OnCaretBoundsChanged(const ui::TextInputClient* client) override {}
146 void OnTextInputStateChanged(const ui::TextInputClient* client) override; 138 void OnTextInputStateChanged(const ui::TextInputClient* client) override;
147 void OnInputMethodDestroyed(const ui::InputMethod* input_method) override; 139 void OnInputMethodDestroyed(const ui::InputMethod* input_method) override;
148 void OnShowImeIfNeeded() override; 140 void OnShowImeIfNeeded() override;
149 141
150 // Show virtual keyboard immediately with animation. 142 // Show virtual keyboard immediately with animation.
151 void ShowKeyboardInternal(); 143 void ShowKeyboardInternal();
152 144
153 // Clears any insets on web content windows.
154 void ResetWindowInsets();
155
156 // Returns true if keyboard is scheduled to hide. 145 // Returns true if keyboard is scheduled to hide.
157 bool WillHideKeyboard() const; 146 bool WillHideKeyboard() const;
158 147
159 // Called when show and hide animation finished successfully. If the animation 148 // Called when show and hide animation finished successfully. If the animation
160 // is aborted, it won't be called. 149 // is aborted, it won't be called.
161 void ShowAnimationFinished(); 150 void ShowAnimationFinished();
162 void HideAnimationFinished(); 151 void HideAnimationFinished();
163 152
164 // Adds an observer for tracking changes to a window size or 153 scoped_ptr<KeyboardUI> ui_;
165 // position while the keyboard is displayed. Any window repositioning
166 // invalidates insets for overscrolling.
167 void AddBoundsChangedObserver(aura::Window* window);
168
169 scoped_ptr<KeyboardControllerProxy> proxy_;
170 scoped_ptr<aura::Window> container_; 154 scoped_ptr<aura::Window> container_;
171 // CallbackAnimationObserver should destructed before container_ because it 155 // CallbackAnimationObserver should destructed before container_ because it
172 // uses container_'s animator. 156 // uses container_'s animator.
173 scoped_ptr<CallbackAnimationObserver> animation_observer_; 157 scoped_ptr<CallbackAnimationObserver> animation_observer_;
174 158
175 scoped_ptr<WindowBoundsChangeObserver> window_bounds_observer_;
176
177 ui::InputMethod* input_method_; 159 ui::InputMethod* input_method_;
178 bool keyboard_visible_; 160 bool keyboard_visible_;
179 bool show_on_resize_; 161 bool show_on_resize_;
180 bool lock_keyboard_; 162 bool lock_keyboard_;
181 KeyboardMode keyboard_mode_; 163 KeyboardMode keyboard_mode_;
182 ui::TextInputType type_; 164 ui::TextInputType type_;
183 165
184 base::ObserverList<KeyboardControllerObserver> observer_list_; 166 base::ObserverList<KeyboardControllerObserver> observer_list_;
185 167
186 // The currently used keyboard position. 168 // The currently used keyboard position.
187 gfx::Rect current_keyboard_bounds_; 169 gfx::Rect current_keyboard_bounds_;
188 170
189 static KeyboardController* instance_; 171 static KeyboardController* instance_;
190 172
191 base::WeakPtrFactory<KeyboardController> weak_factory_; 173 base::WeakPtrFactory<KeyboardController> weak_factory_;
192 174
193 DISALLOW_COPY_AND_ASSIGN(KeyboardController); 175 DISALLOW_COPY_AND_ASSIGN(KeyboardController);
194 }; 176 };
195 177
196 } // namespace keyboard 178 } // namespace keyboard
197 179
198 #endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ 180 #endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_H_
OLDNEW
« no previous file with comments | « ui/keyboard/keyboard_constants.cc ('k') | ui/keyboard/keyboard_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698