| 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 "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) |
| 40 #include "ui/aura/desktop.h" | 40 #include "ui/aura/root_window.h" |
| 41 #include "ui/aura/desktop_observer.h" | 41 #include "ui/aura/root_window_observer.h" |
| 42 #include "ui/aura_shell/shell.h" | 42 #include "ui/aura_shell/shell.h" |
| 43 #include "ui/aura_shell/shell_window_ids.h" | 43 #include "ui/aura_shell/shell_window_ids.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 const int kDefaultKeyboardHeight = 300; | 48 const int kDefaultKeyboardHeight = 300; |
| 49 const int kKeyboardSlideDuration = 300; // In milliseconds | 49 const int kKeyboardSlideDuration = 300; // In milliseconds |
| 50 const char kOnTextInputTypeChanged[] = | 50 const char kOnTextInputTypeChanged[] = |
| 51 "experimental.input.virtualKeyboard.onTextInputTypeChanged"; | 51 "experimental.input.virtualKeyboard.onTextInputTypeChanged"; |
| 52 | 52 |
| 53 // The default position of the keyboard widget should be at the bottom, | 53 // The default position of the keyboard widget should be at the bottom, |
| 54 // spanning the entire width of the desktop. | 54 // spanning the entire width of the root window. |
| 55 gfx::Rect GetKeyboardPosition(int height) { | 55 gfx::Rect GetKeyboardPosition(int height) { |
| 56 gfx::Rect area = gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()); | 56 gfx::Rect area = gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()); |
| 57 return gfx::Rect(area.x(), area.y() + area.height() - height, | 57 return gfx::Rect(area.x(), area.y() + area.height() - height, |
| 58 area.width(), height); | 58 area.width(), height); |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 | 62 |
| 63 // TODO(sad): Is the default profile always going to be the one we want? | 63 // TODO(sad): Is the default profile always going to be the one we want? |
| 64 | 64 |
| 65 class KeyboardWidget | 65 class KeyboardWidget |
| 66 : public views::Widget, | 66 : public views::Widget, |
| 67 public ui::AnimationDelegate, | 67 public ui::AnimationDelegate, |
| 68 public TabContentsObserver, | 68 public TabContentsObserver, |
| 69 public ExtensionFunctionDispatcher::Delegate, | 69 public ExtensionFunctionDispatcher::Delegate, |
| 70 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
| 71 public chromeos::input_method::InputMethodManager::VirtualKeyboardObserver
, | 71 public chromeos::input_method::InputMethodManager::VirtualKeyboardObserver
, |
| 72 #endif | 72 #endif |
| 73 #if defined(USE_AURA) | 73 #if defined(USE_AURA) |
| 74 public aura::DesktopObserver, | 74 public aura::RootWindowObserver, |
| 75 #endif | 75 #endif |
| 76 public content::NotificationObserver, | 76 public content::NotificationObserver, |
| 77 public views::Widget::Observer, | 77 public views::Widget::Observer, |
| 78 public views::TextInputTypeObserver { | 78 public views::TextInputTypeObserver { |
| 79 public: | 79 public: |
| 80 KeyboardWidget(); | 80 KeyboardWidget(); |
| 81 virtual ~KeyboardWidget(); | 81 virtual ~KeyboardWidget(); |
| 82 | 82 |
| 83 // Show the keyboard for the target widget. The events from the keyboard will | 83 // Show the keyboard for the target widget. The events from the keyboard will |
| 84 // be sent to |widget|. | 84 // be sent to |widget|. |
| 85 void ShowKeyboardForWidget(views::Widget* widget); | 85 void ShowKeyboardForWidget(views::Widget* widget); |
| 86 | 86 |
| 87 // Updates the bounds to reflect the current screen/desktop bounds. | 87 // Updates the bounds to reflect the current screen/root window bounds. |
| 88 void ResetBounds(); | 88 void ResetBounds(); |
| 89 | 89 |
| 90 // Overridden from views::Widget | 90 // Overridden from views::Widget |
| 91 void Hide() OVERRIDE; | 91 void Hide() OVERRIDE; |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 // Sets the target widget, adds/removes Widget::Observer, reparents etc. | 94 // Sets the target widget, adds/removes Widget::Observer, reparents etc. |
| 95 void SetTarget(Widget* target); | 95 void SetTarget(Widget* target); |
| 96 | 96 |
| 97 // Returns the widget of the active browser, or NULL if there is no such | 97 // Returns the widget of the active browser, or NULL if there is no such |
| (...skipping 26 matching lines...) Expand all Loading... |
| 124 | 124 |
| 125 #if defined(OS_CHROMEOS) | 125 #if defined(OS_CHROMEOS) |
| 126 // Overridden from input_method::InputMethodManager::VirtualKeyboardObserver. | 126 // Overridden from input_method::InputMethodManager::VirtualKeyboardObserver. |
| 127 virtual void VirtualKeyboardChanged( | 127 virtual void VirtualKeyboardChanged( |
| 128 chromeos::input_method::InputMethodManager* manager, | 128 chromeos::input_method::InputMethodManager* manager, |
| 129 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, | 129 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, |
| 130 const std::string& virtual_keyboard_layout); | 130 const std::string& virtual_keyboard_layout); |
| 131 #endif | 131 #endif |
| 132 | 132 |
| 133 #if defined(USE_AURA) | 133 #if defined(USE_AURA) |
| 134 // Overridden from aura::DesktopObserver. | 134 // Overridden from aura::RootWindowObserver. |
| 135 virtual void OnDesktopResized(const gfx::Size& new_size) OVERRIDE; | 135 virtual void OnRootWindowResized(const gfx::Size& new_size) OVERRIDE; |
| 136 #endif | 136 #endif |
| 137 | 137 |
| 138 // Overridden from NotificationObserver. | 138 // Overridden from NotificationObserver. |
| 139 virtual void Observe(int type, | 139 virtual void Observe(int type, |
| 140 const content::NotificationSource& source, | 140 const content::NotificationSource& source, |
| 141 const content::NotificationDetails& details) OVERRIDE; | 141 const content::NotificationDetails& details) OVERRIDE; |
| 142 | 142 |
| 143 // Overridden from views::Widget::Observer. | 143 // Overridden from views::Widget::Observer. |
| 144 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; | 144 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; |
| 145 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE; | 145 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 content::NOTIFICATION_APP_TERMINATING, | 220 content::NOTIFICATION_APP_TERMINATING, |
| 221 content::NotificationService::AllSources()); | 221 content::NotificationService::AllSources()); |
| 222 | 222 |
| 223 #if defined(OS_CHROMEOS) | 223 #if defined(OS_CHROMEOS) |
| 224 chromeos::input_method::InputMethodManager* manager = | 224 chromeos::input_method::InputMethodManager* manager = |
| 225 chromeos::input_method::InputMethodManager::GetInstance(); | 225 chromeos::input_method::InputMethodManager::GetInstance(); |
| 226 manager->AddVirtualKeyboardObserver(this); | 226 manager->AddVirtualKeyboardObserver(this); |
| 227 #endif | 227 #endif |
| 228 | 228 |
| 229 #if defined(USE_AURA) | 229 #if defined(USE_AURA) |
| 230 aura::Desktop::GetInstance()->AddObserver(this); | 230 aura::RootWindow::GetInstance()->AddObserver(this); |
| 231 #endif | 231 #endif |
| 232 } | 232 } |
| 233 | 233 |
| 234 KeyboardWidget::~KeyboardWidget() { | 234 KeyboardWidget::~KeyboardWidget() { |
| 235 if (target_) | 235 if (target_) |
| 236 target_->RemoveObserver(this); | 236 target_->RemoveObserver(this); |
| 237 views::TextInputTypeTracker::GetInstance()->RemoveTextInputTypeObserver(this); | 237 views::TextInputTypeTracker::GetInstance()->RemoveTextInputTypeObserver(this); |
| 238 #if defined(OS_CHROMEOS) | 238 #if defined(OS_CHROMEOS) |
| 239 chromeos::input_method::InputMethodManager* manager = | 239 chromeos::input_method::InputMethodManager* manager = |
| 240 chromeos::input_method::InputMethodManager::GetInstance(); | 240 chromeos::input_method::InputMethodManager::GetInstance(); |
| 241 manager->RemoveVirtualKeyboardObserver(this); | 241 manager->RemoveVirtualKeyboardObserver(this); |
| 242 #endif | 242 #endif |
| 243 | 243 |
| 244 #if defined(USE_AURA) | 244 #if defined(USE_AURA) |
| 245 aura::Desktop::GetInstance()->RemoveObserver(this); | 245 aura::RootWindow::GetInstance()->RemoveObserver(this); |
| 246 #endif | 246 #endif |
| 247 // TODO(sad): Do anything else? | 247 // TODO(sad): Do anything else? |
| 248 } | 248 } |
| 249 | 249 |
| 250 void KeyboardWidget::ShowKeyboardForWidget(views::Widget* widget) { | 250 void KeyboardWidget::ShowKeyboardForWidget(views::Widget* widget) { |
| 251 if (target_ == widget && IsVisible() && !animation_->is_animating()) | 251 if (target_ == widget && IsVisible() && !animation_->is_animating()) |
| 252 return; | 252 return; |
| 253 SetTarget(widget); | 253 SetTarget(widget); |
| 254 | 254 |
| 255 transform_.reset(new ui::InterpolatedTranslation( | 255 transform_.reset(new ui::InterpolatedTranslation( |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 chromeos::input_method::InputMethodManager* manager, | 435 chromeos::input_method::InputMethodManager* manager, |
| 436 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, | 436 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, |
| 437 const std::string& virtual_keyboard_layout) { | 437 const std::string& virtual_keyboard_layout) { |
| 438 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); | 438 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); |
| 439 dom_view_->LoadURL(url); | 439 dom_view_->LoadURL(url); |
| 440 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); | 440 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); |
| 441 } | 441 } |
| 442 #endif | 442 #endif |
| 443 | 443 |
| 444 #if defined(USE_AURA) | 444 #if defined(USE_AURA) |
| 445 void KeyboardWidget::OnDesktopResized(const gfx::Size& new_size) { | 445 void KeyboardWidget::OnRootWindowResized(const gfx::Size& new_size) { |
| 446 ResetBounds(); | 446 ResetBounds(); |
| 447 } | 447 } |
| 448 #endif | 448 #endif |
| 449 | 449 |
| 450 void KeyboardWidget::Observe(int type, | 450 void KeyboardWidget::Observe(int type, |
| 451 const content::NotificationSource& source, | 451 const content::NotificationSource& source, |
| 452 const content::NotificationDetails& details) { | 452 const content::NotificationDetails& details) { |
| 453 switch (type) { | 453 switch (type) { |
| 454 case chrome::NOTIFICATION_FOCUSED_EDITABLE_NODE_TOUCHED: { | 454 case chrome::NOTIFICATION_FOCUSED_EDITABLE_NODE_TOUCHED: { |
| 455 // In case the keyboard hid itself and the focus is still in an editable | 455 // In case the keyboard hid itself and the focus is still in an editable |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 | 536 |
| 537 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { | 537 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { |
| 538 DCHECK_EQ(keyboard_, widget); | 538 DCHECK_EQ(keyboard_, widget); |
| 539 keyboard_ = NULL; | 539 keyboard_ = NULL; |
| 540 } | 540 } |
| 541 | 541 |
| 542 // static | 542 // static |
| 543 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { | 543 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { |
| 544 return Singleton<VirtualKeyboardManager>::get(); | 544 return Singleton<VirtualKeyboardManager>::get(); |
| 545 } | 545 } |
| OLD | NEW |