| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "ui/gfx/screen.h" | 30 #include "ui/gfx/screen.h" |
| 31 #include "views/ime/text_input_type_tracker.h" | 31 #include "views/ime/text_input_type_tracker.h" |
| 32 #include "views/widget/widget.h" | 32 #include "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) |
| 40 #include "ui/aura/desktop.h" |
| 41 #include "ui/aura/desktop_observer.h" |
| 40 #include "ui/aura_shell/shell.h" | 42 #include "ui/aura_shell/shell.h" |
| 41 #include "ui/aura_shell/shell_window_ids.h" | 43 #include "ui/aura_shell/shell_window_ids.h" |
| 42 #endif | 44 #endif |
| 43 | 45 |
| 44 namespace { | 46 namespace { |
| 45 | 47 |
| 46 const int kDefaultKeyboardHeight = 300; | 48 const int kDefaultKeyboardHeight = 300; |
| 47 const int kKeyboardSlideDuration = 300; // In milliseconds | 49 const int kKeyboardSlideDuration = 300; // In milliseconds |
| 48 const char kOnTextInputTypeChanged[] = | 50 const char kOnTextInputTypeChanged[] = |
| 49 "experimental.input.onTextInputTypeChanged"; | 51 "experimental.input.onTextInputTypeChanged"; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 66 // TODO(sad): Is the default profile always going to be the one we want? | 68 // TODO(sad): Is the default profile always going to be the one we want? |
| 67 | 69 |
| 68 class KeyboardWidget | 70 class KeyboardWidget |
| 69 : public views::Widget, | 71 : public views::Widget, |
| 70 public ui::AnimationDelegate, | 72 public ui::AnimationDelegate, |
| 71 public TabContentsObserver, | 73 public TabContentsObserver, |
| 72 public ExtensionFunctionDispatcher::Delegate, | 74 public ExtensionFunctionDispatcher::Delegate, |
| 73 #if defined(OS_CHROMEOS) | 75 #if defined(OS_CHROMEOS) |
| 74 public chromeos::input_method::InputMethodManager::VirtualKeyboardObserver
, | 76 public chromeos::input_method::InputMethodManager::VirtualKeyboardObserver
, |
| 75 #endif | 77 #endif |
| 78 #if defined(USE_AURA) |
| 79 public aura::DesktopObserver, |
| 80 #endif |
| 76 public NotificationObserver, | 81 public NotificationObserver, |
| 77 public views::Widget::Observer, | 82 public views::Widget::Observer, |
| 78 public views::TextInputTypeObserver { | 83 public views::TextInputTypeObserver { |
| 79 public: | 84 public: |
| 80 KeyboardWidget(); | 85 KeyboardWidget(); |
| 81 virtual ~KeyboardWidget(); | 86 virtual ~KeyboardWidget(); |
| 82 | 87 |
| 83 // Show the keyboard for the target widget. The events from the keyboard will | 88 // Show the keyboard for the target widget. The events from the keyboard will |
| 84 // be sent to |widget|. | 89 // be sent to |widget|. |
| 85 void ShowKeyboardForWidget(views::Widget* widget); | 90 void ShowKeyboardForWidget(views::Widget* widget); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 virtual TabContents* GetAssociatedTabContents() const OVERRIDE; | 124 virtual TabContents* GetAssociatedTabContents() const OVERRIDE; |
| 120 | 125 |
| 121 #if defined(OS_CHROMEOS) | 126 #if defined(OS_CHROMEOS) |
| 122 // Overridden from input_method::InputMethodManager::VirtualKeyboardObserver. | 127 // Overridden from input_method::InputMethodManager::VirtualKeyboardObserver. |
| 123 virtual void VirtualKeyboardChanged( | 128 virtual void VirtualKeyboardChanged( |
| 124 chromeos::input_method::InputMethodManager* manager, | 129 chromeos::input_method::InputMethodManager* manager, |
| 125 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, | 130 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, |
| 126 const std::string& virtual_keyboard_layout); | 131 const std::string& virtual_keyboard_layout); |
| 127 #endif | 132 #endif |
| 128 | 133 |
| 134 #if defined(USE_AURA) |
| 135 // Overridden from aura::DesktopObserver. |
| 136 virtual void OnDesktopResized(const gfx::Size& new_size) OVERRIDE; |
| 137 #endif |
| 138 |
| 129 // Overridden from NotificationObserver. | 139 // Overridden from NotificationObserver. |
| 130 virtual void Observe(int type, | 140 virtual void Observe(int type, |
| 131 const NotificationSource& source, | 141 const NotificationSource& source, |
| 132 const NotificationDetails& details) OVERRIDE; | 142 const NotificationDetails& details) OVERRIDE; |
| 133 | 143 |
| 134 // Overridden from views::Widget::Observer. | 144 // Overridden from views::Widget::Observer. |
| 135 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; | 145 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; |
| 136 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE; | 146 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE; |
| 137 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE; | 147 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE; |
| 138 | 148 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 NotificationService::AllSources()); | 216 NotificationService::AllSources()); |
| 207 registrar_.Add(this, | 217 registrar_.Add(this, |
| 208 content::NOTIFICATION_APP_TERMINATING, | 218 content::NOTIFICATION_APP_TERMINATING, |
| 209 NotificationService::AllSources()); | 219 NotificationService::AllSources()); |
| 210 | 220 |
| 211 #if defined(OS_CHROMEOS) | 221 #if defined(OS_CHROMEOS) |
| 212 chromeos::input_method::InputMethodManager* manager = | 222 chromeos::input_method::InputMethodManager* manager = |
| 213 chromeos::input_method::InputMethodManager::GetInstance(); | 223 chromeos::input_method::InputMethodManager::GetInstance(); |
| 214 manager->AddVirtualKeyboardObserver(this); | 224 manager->AddVirtualKeyboardObserver(this); |
| 215 #endif | 225 #endif |
| 226 |
| 227 #if defined(USE_AURA) |
| 228 aura::Desktop::GetInstance()->AddObserver(this); |
| 229 #endif |
| 216 } | 230 } |
| 217 | 231 |
| 218 KeyboardWidget::~KeyboardWidget() { | 232 KeyboardWidget::~KeyboardWidget() { |
| 219 if (target_) | 233 if (target_) |
| 220 target_->RemoveObserver(this); | 234 target_->RemoveObserver(this); |
| 221 views::TextInputTypeTracker::GetInstance()->RemoveTextInputTypeObserver(this); | 235 views::TextInputTypeTracker::GetInstance()->RemoveTextInputTypeObserver(this); |
| 222 #if defined(OS_CHROMEOS) | 236 #if defined(OS_CHROMEOS) |
| 223 chromeos::input_method::InputMethodManager* manager = | 237 chromeos::input_method::InputMethodManager* manager = |
| 224 chromeos::input_method::InputMethodManager::GetInstance(); | 238 chromeos::input_method::InputMethodManager::GetInstance(); |
| 225 manager->RemoveVirtualKeyboardObserver(this); | 239 manager->RemoveVirtualKeyboardObserver(this); |
| 226 #endif | 240 #endif |
| 227 | 241 |
| 242 #if defined(USE_AURA) |
| 243 aura::Desktop::GetInstance()->RemoveObserver(this); |
| 244 #endif |
| 228 // TODO(sad): Do anything else? | 245 // TODO(sad): Do anything else? |
| 229 } | 246 } |
| 230 | 247 |
| 231 void KeyboardWidget::ShowKeyboardForWidget(views::Widget* widget) { | 248 void KeyboardWidget::ShowKeyboardForWidget(views::Widget* widget) { |
| 232 if (target_ == widget && IsVisible() && !animation_->is_animating()) | 249 if (target_ == widget && IsVisible() && !animation_->is_animating()) |
| 233 return; | 250 return; |
| 234 SetTarget(widget); | 251 SetTarget(widget); |
| 235 | 252 |
| 236 transform_.reset(new ui::InterpolatedTranslation( | 253 transform_.reset(new ui::InterpolatedTranslation( |
| 237 gfx::Point(0, keyboard_height_), gfx::Point())); | 254 gfx::Point(0, keyboard_height_), gfx::Point())); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 void KeyboardWidget::VirtualKeyboardChanged( | 419 void KeyboardWidget::VirtualKeyboardChanged( |
| 403 chromeos::input_method::InputMethodManager* manager, | 420 chromeos::input_method::InputMethodManager* manager, |
| 404 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, | 421 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, |
| 405 const std::string& virtual_keyboard_layout) { | 422 const std::string& virtual_keyboard_layout) { |
| 406 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); | 423 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); |
| 407 dom_view_->LoadURL(url); | 424 dom_view_->LoadURL(url); |
| 408 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); | 425 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); |
| 409 } | 426 } |
| 410 #endif | 427 #endif |
| 411 | 428 |
| 429 #if defined(USE_AURA) |
| 430 void KeyboardWidget::OnDesktopResized(const gfx::Size& new_size) { |
| 431 ResetBounds(); |
| 432 } |
| 433 #endif |
| 434 |
| 412 void KeyboardWidget::Observe(int type, | 435 void KeyboardWidget::Observe(int type, |
| 413 const NotificationSource& source, | 436 const NotificationSource& source, |
| 414 const NotificationDetails& details) { | 437 const NotificationDetails& details) { |
| 415 switch (type) { | 438 switch (type) { |
| 416 case chrome::NOTIFICATION_FOCUSED_EDITABLE_NODE_TOUCHED: { | 439 case chrome::NOTIFICATION_FOCUSED_EDITABLE_NODE_TOUCHED: { |
| 417 // In case the keyboard hid itself and the focus is still in an editable | 440 // In case the keyboard hid itself and the focus is still in an editable |
| 418 // field, and the user touches the field, then we want to show the | 441 // field, and the user touches the field, then we want to show the |
| 419 // keyboard again. | 442 // keyboard again. |
| 420 views::Widget* widget = GetBrowserWidget(); | 443 views::Widget* widget = GetBrowserWidget(); |
| 421 if (widget) | 444 if (widget) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 546 |
| 524 void VirtualKeyboardManager::OnDesktopBoundsChanged( | 547 void VirtualKeyboardManager::OnDesktopBoundsChanged( |
| 525 const gfx::Rect& prev_bounds) { | 548 const gfx::Rect& prev_bounds) { |
| 526 keyboard_->ResetBounds(); | 549 keyboard_->ResetBounds(); |
| 527 } | 550 } |
| 528 | 551 |
| 529 // static | 552 // static |
| 530 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { | 553 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { |
| 531 return Singleton<VirtualKeyboardManager>::get(); | 554 return Singleton<VirtualKeyboardManager>::get(); |
| 532 } | 555 } |
| OLD | NEW |