OLD | NEW |
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 "ash/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 return true; | 460 return true; |
461 } | 461 } |
462 | 462 |
463 bool HandleToggleAppList(ui::KeyboardCode key_code, | 463 bool HandleToggleAppList(ui::KeyboardCode key_code, |
464 ui::EventType previous_event_type, | 464 ui::EventType previous_event_type, |
465 ui::KeyboardCode previous_key_code, | 465 ui::KeyboardCode previous_key_code, |
466 const ui::Accelerator& accelerator) { | 466 const ui::Accelerator& accelerator) { |
467 // If something else was pressed between the Search key (LWIN) | 467 // If something else was pressed between the Search key (LWIN) |
468 // being pressed and released, then ignore the release of the | 468 // being pressed and released, then ignore the release of the |
469 // Search key. | 469 // Search key. |
470 if (key_code == ui::VKEY_LWIN && | 470 |
471 (previous_event_type == ui::ET_KEY_RELEASED || | 471 if ((key_code != ui::VKEY_BROWSER_SEARCH || |
472 previous_key_code != ui::VKEY_LWIN)) | 472 accelerator.type() != ui::ET_KEY_PRESSED) && |
| 473 (key_code != ui::VKEY_LWIN || |
| 474 previous_event_type != ui::ET_KEY_PRESSED || |
| 475 previous_key_code != ui::VKEY_LWIN || |
| 476 accelerator.type() != ui::ET_KEY_RELEASED)) { |
473 return false; | 477 return false; |
| 478 } |
| 479 |
474 if (key_code == ui::VKEY_LWIN) | 480 if (key_code == ui::VKEY_LWIN) |
475 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin")); | 481 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin")); |
| 482 |
476 // When spoken feedback is enabled, we should neither toggle the list nor | 483 // When spoken feedback is enabled, we should neither toggle the list nor |
477 // consume the key since Search+Shift is one of the shortcuts the a11y | 484 // consume the key since Search+Shift is one of the shortcuts the a11y |
478 // feature uses. crbug.com/132296 | 485 // feature uses. crbug.com/132296 |
479 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code()); | |
480 if (Shell::GetInstance()->accessibility_delegate()-> | 486 if (Shell::GetInstance()->accessibility_delegate()-> |
481 IsSpokenFeedbackEnabled()) | 487 IsSpokenFeedbackEnabled()) |
482 return false; | 488 return false; |
483 ash::Shell::GetInstance()->ToggleAppList(NULL); | 489 ash::Shell::GetInstance()->ToggleAppList(NULL); |
484 return true; | 490 return true; |
485 } | 491 } |
486 | 492 |
487 bool HandleToggleFullscreen(ui::KeyboardCode key_code) { | 493 bool HandleToggleFullscreen(ui::KeyboardCode key_code) { |
488 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP2) { | 494 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP2) { |
489 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4")); | 495 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4")); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 chromeos::input_method::InputMethodManager::Get(); | 656 chromeos::input_method::InputMethodManager::Get(); |
651 chromeos::input_method::ImeKeyboard* keyboard = | 657 chromeos::input_method::ImeKeyboard* keyboard = |
652 ime ? ime->GetImeKeyboard() : NULL; | 658 ime ? ime->GetImeKeyboard() : NULL; |
653 if (keyboard) | 659 if (keyboard) |
654 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled()); | 660 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled()); |
655 return true; | 661 return true; |
656 } | 662 } |
657 | 663 |
658 #endif // defined(OS_CHROMEOS) | 664 #endif // defined(OS_CHROMEOS) |
659 | 665 |
660 class AutoSet { | |
661 public: | |
662 AutoSet(ui::Accelerator* scoped, ui::Accelerator new_value) | |
663 : scoped_(scoped), new_value_(new_value) {} | |
664 ~AutoSet() { *scoped_ = new_value_; } | |
665 | |
666 private: | |
667 ui::Accelerator* scoped_; | |
668 const ui::Accelerator new_value_; | |
669 | |
670 DISALLOW_COPY_AND_ASSIGN(AutoSet); | |
671 }; | |
672 | |
673 } // namespace | 666 } // namespace |
674 | 667 |
675 //////////////////////////////////////////////////////////////////////////////// | 668 //////////////////////////////////////////////////////////////////////////////// |
676 // AcceleratorController, public: | 669 // AcceleratorController, public: |
677 | 670 |
678 AcceleratorController::AcceleratorController() | 671 AcceleratorController::AcceleratorController() |
679 : accelerator_manager_(new ui::AcceleratorManager) { | 672 : accelerator_manager_(new ui::AcceleratorManager), |
| 673 accelerator_history_(new ui::AcceleratorHistory) { |
680 Init(); | 674 Init(); |
681 } | 675 } |
682 | 676 |
683 AcceleratorController::~AcceleratorController() { | 677 AcceleratorController::~AcceleratorController() { |
684 } | 678 } |
685 | 679 |
686 void AcceleratorController::Init() { | 680 void AcceleratorController::Init() { |
687 previous_accelerator_.set_type(ui::ET_UNKNOWN); | |
688 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { | 681 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { |
689 actions_allowed_at_login_screen_.insert( | 682 actions_allowed_at_login_screen_.insert( |
690 kActionsAllowedAtLoginOrLockScreen[i]); | 683 kActionsAllowedAtLoginOrLockScreen[i]); |
691 actions_allowed_at_lock_screen_.insert( | 684 actions_allowed_at_lock_screen_.insert( |
692 kActionsAllowedAtLoginOrLockScreen[i]); | 685 kActionsAllowedAtLoginOrLockScreen[i]); |
693 } | 686 } |
694 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) | 687 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) |
695 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); | 688 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); |
696 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) | 689 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) |
697 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]); | 690 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, | 724 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, |
732 ui::AcceleratorTarget* target) { | 725 ui::AcceleratorTarget* target) { |
733 accelerator_manager_->Unregister(accelerator, target); | 726 accelerator_manager_->Unregister(accelerator, target); |
734 } | 727 } |
735 | 728 |
736 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) { | 729 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) { |
737 accelerator_manager_->UnregisterAll(target); | 730 accelerator_manager_->UnregisterAll(target); |
738 } | 731 } |
739 | 732 |
740 bool AcceleratorController::Process(const ui::Accelerator& accelerator) { | 733 bool AcceleratorController::Process(const ui::Accelerator& accelerator) { |
741 AutoSet auto_set(&previous_accelerator_, accelerator); | |
742 | |
743 if (ime_control_delegate_) { | 734 if (ime_control_delegate_) { |
744 return accelerator_manager_->Process( | 735 return accelerator_manager_->Process( |
745 ime_control_delegate_->RemapAccelerator(accelerator)); | 736 ime_control_delegate_->RemapAccelerator(accelerator)); |
746 } | 737 } |
747 return accelerator_manager_->Process(accelerator); | 738 return accelerator_manager_->Process(accelerator); |
748 } | 739 } |
749 | 740 |
750 bool AcceleratorController::IsRegistered( | 741 bool AcceleratorController::IsRegistered( |
751 const ui::Accelerator& accelerator) const { | 742 const ui::Accelerator& accelerator) const { |
752 return accelerator_manager_->GetCurrentTarget(accelerator) != NULL; | 743 return accelerator_manager_->GetCurrentTarget(accelerator) != NULL; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 // empty Accelerator() instance as the second argument. Such events | 782 // empty Accelerator() instance as the second argument. Such events |
792 // should never be suspended. | 783 // should never be suspended. |
793 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; | 784 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; |
794 // Ignore accelerators invoked as repeated (while holding a key for a long | 785 // Ignore accelerators invoked as repeated (while holding a key for a long |
795 // time, if their handling is nonrepeatable. | 786 // time, if their handling is nonrepeatable. |
796 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && | 787 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && |
797 accelerator.IsRepeat() && !gesture_event) { | 788 accelerator.IsRepeat() && !gesture_event) { |
798 return true; | 789 return true; |
799 } | 790 } |
800 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. | 791 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. |
801 const ui::EventType previous_event_type = previous_accelerator_.type(); | 792 const ui::Accelerator& previous_accelerator = |
802 const ui::KeyboardCode previous_key_code = previous_accelerator_.key_code(); | 793 accelerator_history_->GetPreviousAccelerator(); |
| 794 const ui::EventType previous_event_type = previous_accelerator.type(); |
| 795 const ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); |
803 | 796 |
804 // You *MUST* return true when some action is performed. Otherwise, this | 797 // You *MUST* return true when some action is performed. Otherwise, this |
805 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent | 798 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent |
806 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. | 799 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. |
807 // | 800 // |
808 // If your accelerator invokes more than one line of code, please either | 801 // If your accelerator invokes more than one line of code, please either |
809 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE | 802 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE |
810 // below) or pull it into a HandleFoo() function above. | 803 // below) or pull it into a HandleFoo() function above. |
811 switch (action) { | 804 switch (action) { |
812 case ACCESSIBLE_FOCUS_NEXT: | 805 case ACCESSIBLE_FOCUS_NEXT: |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 keyboard_brightness_control_delegate) { | 1100 keyboard_brightness_control_delegate) { |
1108 keyboard_brightness_control_delegate_ = | 1101 keyboard_brightness_control_delegate_ = |
1109 keyboard_brightness_control_delegate.Pass(); | 1102 keyboard_brightness_control_delegate.Pass(); |
1110 } | 1103 } |
1111 | 1104 |
1112 bool AcceleratorController::CanHandleAccelerators() const { | 1105 bool AcceleratorController::CanHandleAccelerators() const { |
1113 return true; | 1106 return true; |
1114 } | 1107 } |
1115 | 1108 |
1116 } // namespace ash | 1109 } // namespace ash |
OLD | NEW |