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

Side by Side Diff: chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc

Issue 9200011: Fix virtual keyboard on aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.h" 5 #include "chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_event_router.h" 9 #include "chrome/browser/extensions/extension_event_router.h"
10 #include "chrome/browser/extensions/extension_function_dispatcher.h" 10 #include "chrome/browser/extensions/extension_function_dispatcher.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/tabs/tab_strip_model.h" 13 #include "chrome/browser/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
17 #include "chrome/browser/ui/views/dom_view.h" 17 #include "chrome/browser/ui/views/dom_view.h"
18 #include "chrome/browser/ui/views/frame/browser_view.h" 18 #include "chrome/browser/ui/views/frame/browser_view.h"
19 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/extensions/extension_messages.h" 20 #include "chrome/common/extensions/extension_messages.h"
21 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "content/browser/site_instance.h" 22 #include "content/browser/site_instance.h"
23 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_contents_observer.h" 25 #include "content/public/browser/web_contents_observer.h"
25 #include "ui/base/animation/animation_delegate.h" 26 #include "ui/base/animation/animation_delegate.h"
26 #include "ui/base/animation/slide_animation.h" 27 #include "ui/base/animation/slide_animation.h"
27 #include "ui/base/ime/text_input_type.h" 28 #include "ui/base/ime/text_input_type.h"
28 #include "ui/gfx/compositor/layer.h" 29 #include "ui/gfx/compositor/layer.h"
29 #include "ui/gfx/interpolated_transform.h"
30 #include "ui/gfx/screen.h" 30 #include "ui/gfx/screen.h"
31 #include "ui/views/ime/text_input_type_tracker.h" 31 #include "ui/views/ime/text_input_type_tracker.h"
32 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
33 33
34 #if defined(OS_CHROMEOS) 34 #if defined(OS_CHROMEOS)
35 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 35 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
36 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" 36 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h"
37 #endif 37 #endif
38 38
39 #if defined(USE_AURA) 39 #if defined(USE_AURA)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 void Hide() OVERRIDE; 93 void Hide() OVERRIDE;
94 94
95 private: 95 private:
96 // Sets the target widget, adds/removes Widget::Observer, reparents etc. 96 // Sets the target widget, adds/removes Widget::Observer, reparents etc.
97 void SetTarget(Widget* target); 97 void SetTarget(Widget* target);
98 98
99 // Returns the widget of the active browser, or NULL if there is no such 99 // Returns the widget of the active browser, or NULL if there is no such
100 // widget. 100 // widget.
101 views::Widget* GetBrowserWidget(); 101 views::Widget* GetBrowserWidget();
102 102
103 // Update layer opacity and transform with values in animation_. 103 // Update layer opacity and bounds with values in animation_.
104 void UpdateForAnimation(); 104 void UpdateForAnimation();
105 105
106 // Overridden from views::Widget. 106 // Overridden from views::Widget.
107 virtual bool OnKeyEvent(const views::KeyEvent& event) OVERRIDE; 107 virtual bool OnKeyEvent(const views::KeyEvent& event) OVERRIDE;
108 108
109 // Overridden from ui::AnimationDelegate. 109 // Overridden from ui::AnimationDelegate.
110 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; 110 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
111 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; 111 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
112 112
113 // Overridden from content::WebContentsObserver. 113 // Overridden from content::WebContentsObserver.
(...skipping 28 matching lines...) Expand all
142 const content::NotificationDetails& details) OVERRIDE; 142 const content::NotificationDetails& details) OVERRIDE;
143 143
144 // Overridden from views::Widget::Observer. 144 // Overridden from views::Widget::Observer.
145 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; 145 virtual void OnWidgetClosing(Widget* widget) OVERRIDE;
146 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE; 146 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE;
147 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE; 147 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE;
148 148
149 // The animation. 149 // The animation.
150 scoped_ptr<ui::SlideAnimation> animation_; 150 scoped_ptr<ui::SlideAnimation> animation_;
151 151
152 // Interpolated transform used during animation.
153 scoped_ptr<ui::InterpolatedTransform> transform_;
154
155 GURL keyboard_url_; 152 GURL keyboard_url_;
156 153
157 // The DOM view to host the keyboard. 154 // The DOM view to host the keyboard.
158 DOMView* dom_view_; 155 DOMView* dom_view_;
159 156
160 ExtensionFunctionDispatcher extension_dispatcher_; 157 ExtensionFunctionDispatcher extension_dispatcher_;
161 158
162 // The widget the events from the keyboard should be directed to. 159 // The widget the events from the keyboard should be directed to.
163 views::Widget* target_; 160 views::Widget* target_;
164 161
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 content::NOTIFICATION_APP_TERMINATING, 219 content::NOTIFICATION_APP_TERMINATING,
223 content::NotificationService::AllSources()); 220 content::NotificationService::AllSources());
224 221
225 #if defined(OS_CHROMEOS) 222 #if defined(OS_CHROMEOS)
226 chromeos::input_method::InputMethodManager* manager = 223 chromeos::input_method::InputMethodManager* manager =
227 chromeos::input_method::InputMethodManager::GetInstance(); 224 chromeos::input_method::InputMethodManager::GetInstance();
228 manager->AddVirtualKeyboardObserver(this); 225 manager->AddVirtualKeyboardObserver(this);
229 #endif 226 #endif
230 227
231 #if defined(USE_AURA) 228 #if defined(USE_AURA)
232 aura::RootWindow::GetInstance()->AddObserver(this); 229 aura::RootWindow::GetInstance()->AddRootWindowObserver(this);
233 #endif 230 #endif
234 } 231 }
235 232
236 KeyboardWidget::~KeyboardWidget() { 233 KeyboardWidget::~KeyboardWidget() {
237 if (target_) 234 if (target_)
238 target_->RemoveObserver(this); 235 target_->RemoveObserver(this);
239 views::TextInputTypeTracker::GetInstance()->RemoveTextInputTypeObserver(this); 236 views::TextInputTypeTracker::GetInstance()->RemoveTextInputTypeObserver(this);
240 #if defined(OS_CHROMEOS) 237 #if defined(OS_CHROMEOS)
241 chromeos::input_method::InputMethodManager* manager = 238 chromeos::input_method::InputMethodManager* manager =
242 chromeos::input_method::InputMethodManager::GetInstance(); 239 chromeos::input_method::InputMethodManager::GetInstance();
243 manager->RemoveVirtualKeyboardObserver(this); 240 manager->RemoveVirtualKeyboardObserver(this);
244 #endif 241 #endif
245 242
246 #if defined(USE_AURA) 243 #if defined(USE_AURA)
247 aura::RootWindow::GetInstance()->RemoveObserver(this); 244 aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this);
248 #endif 245 #endif
249 // TODO(sad): Do anything else? 246 // TODO(sad): Do anything else?
250 } 247 }
251 248
252 void KeyboardWidget::ShowKeyboardForWidget(views::Widget* widget) { 249 void KeyboardWidget::ShowKeyboardForWidget(views::Widget* widget) {
253 if (target_ == widget && IsVisible() && !animation_->is_animating()) 250 if (target_ == widget && IsVisible() && !animation_->is_animating())
254 return; 251 return;
255 SetTarget(widget); 252 SetTarget(widget);
256 253
257 transform_.reset(new ui::InterpolatedTranslation(
258 gfx::Point(0, keyboard_height_), gfx::Point()));
259
260 UpdateForAnimation(); 254 UpdateForAnimation();
261 animation_->Show(); 255 animation_->Show();
262 256
263 Show(); 257 Show();
264 258
265 bool visible = true; 259 bool visible = true;
266 content::NotificationService::current()->Notify( 260 content::NotificationService::current()->Notify(
267 chrome::NOTIFICATION_KEYBOARD_VISIBILITY_CHANGED, 261 chrome::NOTIFICATION_KEYBOARD_VISIBILITY_CHANGED,
268 content::Source<KeyboardWidget>(this), 262 content::Source<KeyboardWidget>(this),
269 content::Details<bool>(&visible)); 263 content::Details<bool>(&visible));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 return NULL; 300 return NULL;
307 return view->GetWidget(); 301 return view->GetWidget();
308 } 302 }
309 303
310 bool KeyboardWidget::OnKeyEvent(const views::KeyEvent& event) { 304 bool KeyboardWidget::OnKeyEvent(const views::KeyEvent& event) {
311 return target_ ? target_->OnKeyEvent(event) : false; 305 return target_ ? target_->OnKeyEvent(event) : false;
312 } 306 }
313 307
314 void KeyboardWidget::UpdateForAnimation() { 308 void KeyboardWidget::UpdateForAnimation() {
315 float t = static_cast<float>(animation_->GetCurrentValue()); 309 float t = static_cast<float>(animation_->GetCurrentValue());
316 GetRootView()->SetTransform(transform_->Interpolate(t)); 310 gfx::Rect bounds = GetKeyboardPosition(keyboard_height_);
311 bounds.Offset(0, keyboard_height_*(1 - t));
312 SetBounds(bounds);
hashimoto 2012/01/23 10:21:53 Replace SetTransform with SetBounds because virtua
sadrul 2012/01/23 22:47:57 I think this is a wrong thing to do. Changing the
hashimoto 2012/01/24 11:23:05 Unless |keyboard_height_| is changed, the size of
317 if (GetRootView()->layer()) 313 if (GetRootView()->layer())
318 GetRootView()->layer()->SetOpacity(t * t); 314 GetRootView()->layer()->SetOpacity(t * t);
319 } 315 }
320 316
321 void KeyboardWidget::AnimationProgressed(const ui::Animation* animation) { 317 void KeyboardWidget::AnimationProgressed(const ui::Animation* animation) {
322 UpdateForAnimation(); 318 UpdateForAnimation();
323 } 319 }
324 320
325 void KeyboardWidget::AnimationEnded(const ui::Animation* animation) { 321 void KeyboardWidget::AnimationEnded(const ui::Animation* animation) {
326 gfx::Rect keyboard_rect; 322 gfx::Rect keyboard_rect;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 530
535 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { 531 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) {
536 DCHECK_EQ(keyboard_, widget); 532 DCHECK_EQ(keyboard_, widget);
537 keyboard_ = NULL; 533 keyboard_ = NULL;
538 } 534 }
539 535
540 // static 536 // static
541 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { 537 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() {
542 return Singleton<VirtualKeyboardManager>::get(); 538 return Singleton<VirtualKeyboardManager>::get();
543 } 539 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698