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 if (key_code != ui::VKEY_LWIN || |
471 (previous_event_type == ui::ET_KEY_RELEASED || | 471 previous_event_type != ui::ET_KEY_PRESSED || |
472 previous_key_code != ui::VKEY_LWIN)) | 472 previous_key_code != ui::VKEY_LWIN || |
473 accelerator.type() != ui::ET_KEY_RELEASED) | |
Jun Mukai
2014/11/15 01:56:33
This means accelerator is not handled at all if ke
Jun Mukai
2014/11/15 01:56:33
This was weird in the previous code. Multi-lined
afakhry
2014/11/15 02:40:30
Done.
afakhry
2014/11/15 02:40:31
I added a test for VKEY_BROWSER_SEARCH and pressed
| |
473 return false; | 474 return false; |
474 if (key_code == ui::VKEY_LWIN) | 475 |
475 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin")); | 476 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin")); |
477 | |
476 // When spoken feedback is enabled, we should neither toggle the list nor | 478 // 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 | 479 // consume the key since Search+Shift is one of the shortcuts the a11y |
478 // feature uses. crbug.com/132296 | 480 // feature uses. crbug.com/132296 |
479 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code()); | 481 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code()); |
afakhry
2014/11/15 03:04:58
I also removed this line as it doesn't take into c
| |
480 if (Shell::GetInstance()->accessibility_delegate()-> | 482 if (Shell::GetInstance()->accessibility_delegate()-> |
481 IsSpokenFeedbackEnabled()) | 483 IsSpokenFeedbackEnabled()) |
482 return false; | 484 return false; |
483 ash::Shell::GetInstance()->ToggleAppList(NULL); | 485 ash::Shell::GetInstance()->ToggleAppList(NULL); |
484 return true; | 486 return true; |
485 } | 487 } |
486 | 488 |
487 bool HandleToggleFullscreen(ui::KeyboardCode key_code) { | 489 bool HandleToggleFullscreen(ui::KeyboardCode key_code) { |
488 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP2) { | 490 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP2) { |
489 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4")); | 491 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(); | 652 chromeos::input_method::InputMethodManager::Get(); |
651 chromeos::input_method::ImeKeyboard* keyboard = | 653 chromeos::input_method::ImeKeyboard* keyboard = |
652 ime ? ime->GetImeKeyboard() : NULL; | 654 ime ? ime->GetImeKeyboard() : NULL; |
653 if (keyboard) | 655 if (keyboard) |
654 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled()); | 656 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled()); |
655 return true; | 657 return true; |
656 } | 658 } |
657 | 659 |
658 #endif // defined(OS_CHROMEOS) | 660 #endif // defined(OS_CHROMEOS) |
659 | 661 |
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 | 662 } // namespace |
674 | 663 |
675 //////////////////////////////////////////////////////////////////////////////// | 664 //////////////////////////////////////////////////////////////////////////////// |
676 // AcceleratorController, public: | 665 // AcceleratorController, public: |
677 | 666 |
678 AcceleratorController::AcceleratorController() | 667 AcceleratorController::AcceleratorController() |
679 : accelerator_manager_(new ui::AcceleratorManager) { | 668 : accelerator_manager_(new ui::AcceleratorManager) { |
680 Init(); | 669 Init(); |
681 } | 670 } |
682 | 671 |
683 AcceleratorController::~AcceleratorController() { | 672 AcceleratorController::~AcceleratorController() { |
684 } | 673 } |
685 | 674 |
686 void AcceleratorController::Init() { | 675 void AcceleratorController::Init() { |
687 previous_accelerator_.set_type(ui::ET_UNKNOWN); | |
688 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { | 676 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { |
689 actions_allowed_at_login_screen_.insert( | 677 actions_allowed_at_login_screen_.insert( |
690 kActionsAllowedAtLoginOrLockScreen[i]); | 678 kActionsAllowedAtLoginOrLockScreen[i]); |
691 actions_allowed_at_lock_screen_.insert( | 679 actions_allowed_at_lock_screen_.insert( |
692 kActionsAllowedAtLoginOrLockScreen[i]); | 680 kActionsAllowedAtLoginOrLockScreen[i]); |
693 } | 681 } |
694 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) | 682 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) |
695 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); | 683 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); |
696 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) | 684 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) |
697 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]); | 685 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, | 719 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, |
732 ui::AcceleratorTarget* target) { | 720 ui::AcceleratorTarget* target) { |
733 accelerator_manager_->Unregister(accelerator, target); | 721 accelerator_manager_->Unregister(accelerator, target); |
734 } | 722 } |
735 | 723 |
736 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) { | 724 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) { |
737 accelerator_manager_->UnregisterAll(target); | 725 accelerator_manager_->UnregisterAll(target); |
738 } | 726 } |
739 | 727 |
740 bool AcceleratorController::Process(const ui::Accelerator& accelerator) { | 728 bool AcceleratorController::Process(const ui::Accelerator& accelerator) { |
741 AutoSet auto_set(&previous_accelerator_, accelerator); | |
742 | |
743 if (ime_control_delegate_) { | 729 if (ime_control_delegate_) { |
744 return accelerator_manager_->Process( | 730 return accelerator_manager_->Process( |
745 ime_control_delegate_->RemapAccelerator(accelerator)); | 731 ime_control_delegate_->RemapAccelerator(accelerator)); |
746 } | 732 } |
747 return accelerator_manager_->Process(accelerator); | 733 return accelerator_manager_->Process(accelerator); |
748 } | 734 } |
749 | 735 |
750 bool AcceleratorController::IsRegistered( | 736 bool AcceleratorController::IsRegistered( |
751 const ui::Accelerator& accelerator) const { | 737 const ui::Accelerator& accelerator) const { |
752 return accelerator_manager_->GetCurrentTarget(accelerator) != NULL; | 738 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 | 777 // empty Accelerator() instance as the second argument. Such events |
792 // should never be suspended. | 778 // should never be suspended. |
793 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; | 779 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; |
794 // Ignore accelerators invoked as repeated (while holding a key for a long | 780 // Ignore accelerators invoked as repeated (while holding a key for a long |
795 // time, if their handling is nonrepeatable. | 781 // time, if their handling is nonrepeatable. |
796 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && | 782 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && |
797 accelerator.IsRepeat() && !gesture_event) { | 783 accelerator.IsRepeat() && !gesture_event) { |
798 return true; | 784 return true; |
799 } | 785 } |
800 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. | 786 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. |
801 const ui::EventType previous_event_type = previous_accelerator_.type(); | 787 const ui::Accelerator& previous_accelerator = |
802 const ui::KeyboardCode previous_key_code = previous_accelerator_.key_code(); | 788 ui::AcceleratorHistory::GetInstance()->GetPreviousAccelerator(); |
789 const ui::EventType previous_event_type = previous_accelerator.type(); | |
790 const ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); | |
803 | 791 |
804 // You *MUST* return true when some action is performed. Otherwise, this | 792 // You *MUST* return true when some action is performed. Otherwise, this |
805 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent | 793 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent |
806 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. | 794 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. |
807 // | 795 // |
808 // If your accelerator invokes more than one line of code, please either | 796 // 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 | 797 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE |
810 // below) or pull it into a HandleFoo() function above. | 798 // below) or pull it into a HandleFoo() function above. |
811 switch (action) { | 799 switch (action) { |
812 case ACCESSIBLE_FOCUS_NEXT: | 800 case ACCESSIBLE_FOCUS_NEXT: |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 keyboard_brightness_control_delegate) { | 1095 keyboard_brightness_control_delegate) { |
1108 keyboard_brightness_control_delegate_ = | 1096 keyboard_brightness_control_delegate_ = |
1109 keyboard_brightness_control_delegate.Pass(); | 1097 keyboard_brightness_control_delegate.Pass(); |
1110 } | 1098 } |
1111 | 1099 |
1112 bool AcceleratorController::CanHandleAccelerators() const { | 1100 bool AcceleratorController::CanHandleAccelerators() const { |
1113 return true; | 1101 return true; |
1114 } | 1102 } |
1115 | 1103 |
1116 } // namespace ash | 1104 } // namespace ash |
OLD | NEW |