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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 desktop. |
55 gfx::Rect GetKeyboardPosition(int height) { | 55 gfx::Rect GetKeyboardPosition(int height) { |
56 views::View* desktop = views::desktop::DesktopWindowView::desktop_window_view; | 56 gfx::Rect area = gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()); |
57 gfx::Rect area; | |
58 if (desktop) | |
59 area = desktop->bounds(); | |
60 else | |
61 area = gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()); | |
62 return gfx::Rect(area.x(), area.y() + area.height() - height, | 57 return gfx::Rect(area.x(), area.y() + area.height() - height, |
63 area.width(), height); | 58 area.width(), height); |
64 } | 59 } |
65 | 60 |
66 } // namespace | 61 } // namespace |
67 | 62 |
68 // 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? |
69 | 64 |
70 class KeyboardWidget | 65 class KeyboardWidget |
71 : public views::Widget, | 66 : public views::Widget, |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 } | 507 } |
513 | 508 |
514 void KeyboardWidget::OnWidgetActivationChanged(Widget* widget, bool active) { | 509 void KeyboardWidget::OnWidgetActivationChanged(Widget* widget, bool active) { |
515 if (target_ == widget && !active) | 510 if (target_ == widget && !active) |
516 SetTarget(NULL); | 511 SetTarget(NULL); |
517 } | 512 } |
518 | 513 |
519 VirtualKeyboardManager::VirtualKeyboardManager() | 514 VirtualKeyboardManager::VirtualKeyboardManager() |
520 : keyboard_(new KeyboardWidget()) { | 515 : keyboard_(new KeyboardWidget()) { |
521 keyboard_->AddObserver(this); | 516 keyboard_->AddObserver(this); |
522 | |
523 views::desktop::DesktopWindowView* desktop = | |
524 views::desktop::DesktopWindowView::desktop_window_view; | |
525 | |
526 // We are either not in views desktop mode, or we are and we are not yet | |
527 // observing the desktop. | |
528 DCHECK(!desktop || !desktop->HasObserver(this)); | |
529 | |
530 if (desktop) | |
531 desktop->AddObserver(this); | |
532 } | 517 } |
533 | 518 |
534 VirtualKeyboardManager::~VirtualKeyboardManager() { | 519 VirtualKeyboardManager::~VirtualKeyboardManager() { |
535 DCHECK(!keyboard_); | 520 DCHECK(!keyboard_); |
536 | |
537 views::desktop::DesktopWindowView* desktop = | |
538 views::desktop::DesktopWindowView::desktop_window_view; | |
539 | |
540 // We are either not in views desktop mode, or we are and we have been | |
541 // observing the desktop | |
542 DCHECK(!desktop || desktop->HasObserver(this)); | |
543 | |
544 if (desktop) | |
545 desktop->RemoveObserver(this); | |
546 } | 521 } |
547 | 522 |
548 void VirtualKeyboardManager::ShowKeyboardForWidget(views::Widget* widget) { | 523 void VirtualKeyboardManager::ShowKeyboardForWidget(views::Widget* widget) { |
549 keyboard_->ShowKeyboardForWidget(widget); | 524 keyboard_->ShowKeyboardForWidget(widget); |
550 } | 525 } |
551 | 526 |
552 void VirtualKeyboardManager::Hide() { | 527 void VirtualKeyboardManager::Hide() { |
553 keyboard_->Hide(); | 528 keyboard_->Hide(); |
554 } | 529 } |
555 | 530 |
556 views::Widget* VirtualKeyboardManager::keyboard() { | 531 views::Widget* VirtualKeyboardManager::keyboard() { |
557 return keyboard_; | 532 return keyboard_; |
558 } | 533 } |
559 | 534 |
560 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { | 535 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { |
561 DCHECK_EQ(keyboard_, widget); | 536 DCHECK_EQ(keyboard_, widget); |
562 keyboard_ = NULL; | 537 keyboard_ = NULL; |
563 } | 538 } |
564 | 539 |
565 void VirtualKeyboardManager::OnDesktopBoundsChanged( | |
566 const gfx::Rect& prev_bounds) { | |
567 keyboard_->ResetBounds(); | |
568 } | |
569 | |
570 // static | 540 // static |
571 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { | 541 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { |
572 return Singleton<VirtualKeyboardManager>::get(); | 542 return Singleton<VirtualKeyboardManager>::get(); |
573 } | 543 } |
OLD | NEW |