| 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 return true; | 422 return true; |
| 423 } | 423 } |
| 424 | 424 |
| 425 bool HandleToggleAppList(ui::KeyboardCode key_code, | 425 bool HandleToggleAppList(ui::KeyboardCode key_code, |
| 426 ui::EventType previous_event_type, | 426 ui::EventType previous_event_type, |
| 427 ui::KeyboardCode previous_key_code, | 427 ui::KeyboardCode previous_key_code, |
| 428 const ui::Accelerator& accelerator) { | 428 const ui::Accelerator& accelerator) { |
| 429 // If something else was pressed between the Search key (LWIN) | 429 // If something else was pressed between the Search key (LWIN) |
| 430 // being pressed and released, then ignore the release of the | 430 // being pressed and released, then ignore the release of the |
| 431 // Search key. | 431 // Search key. |
| 432 if (key_code == ui::VKEY_LWIN && | 432 |
| 433 (previous_event_type == ui::ET_KEY_RELEASED || | 433 if ((key_code != ui::VKEY_BROWSER_SEARCH || |
| 434 previous_key_code != ui::VKEY_LWIN)) | 434 accelerator.type() != ui::ET_KEY_PRESSED) && |
| 435 (key_code != ui::VKEY_LWIN || |
| 436 previous_event_type != ui::ET_KEY_PRESSED || |
| 437 previous_key_code != ui::VKEY_LWIN || |
| 438 accelerator.type() != ui::ET_KEY_RELEASED)) { |
| 435 return false; | 439 return false; |
| 440 } |
| 441 |
| 436 if (key_code == ui::VKEY_LWIN) | 442 if (key_code == ui::VKEY_LWIN) |
| 437 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin")); | 443 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin")); |
| 444 |
| 438 // When spoken feedback is enabled, we should neither toggle the list nor | 445 // When spoken feedback is enabled, we should neither toggle the list nor |
| 439 // consume the key since Search+Shift is one of the shortcuts the a11y | 446 // consume the key since Search+Shift is one of the shortcuts the a11y |
| 440 // feature uses. crbug.com/132296 | 447 // feature uses. crbug.com/132296 |
| 441 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code()); | |
| 442 if (Shell::GetInstance()->accessibility_delegate()-> | 448 if (Shell::GetInstance()->accessibility_delegate()-> |
| 443 IsSpokenFeedbackEnabled()) | 449 IsSpokenFeedbackEnabled()) |
| 444 return false; | 450 return false; |
| 445 ash::Shell::GetInstance()->ToggleAppList(NULL); | 451 ash::Shell::GetInstance()->ToggleAppList(NULL); |
| 446 return true; | 452 return true; |
| 447 } | 453 } |
| 448 | 454 |
| 449 bool HandleToggleFullscreen(ui::KeyboardCode key_code) { | 455 bool HandleToggleFullscreen(ui::KeyboardCode key_code) { |
| 450 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP2) { | 456 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP2) { |
| 451 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4")); | 457 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4")); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 bool HandleVolumeUp(const ui::Accelerator& accelerator) { | 703 bool HandleVolumeUp(const ui::Accelerator& accelerator) { |
| 698 VolumeControlDelegate* volume_delegate = | 704 VolumeControlDelegate* volume_delegate = |
| 699 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate(); | 705 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate(); |
| 700 if (volume_delegate) | 706 if (volume_delegate) |
| 701 volume_delegate->HandleVolumeUp(accelerator); | 707 volume_delegate->HandleVolumeUp(accelerator); |
| 702 return true; | 708 return true; |
| 703 } | 709 } |
| 704 | 710 |
| 705 #endif // defined(OS_CHROMEOS) | 711 #endif // defined(OS_CHROMEOS) |
| 706 | 712 |
| 707 class AutoSet { | |
| 708 public: | |
| 709 AutoSet(ui::Accelerator* scoped, ui::Accelerator new_value) | |
| 710 : scoped_(scoped), new_value_(new_value) {} | |
| 711 ~AutoSet() { *scoped_ = new_value_; } | |
| 712 | |
| 713 private: | |
| 714 ui::Accelerator* scoped_; | |
| 715 const ui::Accelerator new_value_; | |
| 716 | |
| 717 DISALLOW_COPY_AND_ASSIGN(AutoSet); | |
| 718 }; | |
| 719 | |
| 720 } // namespace | 713 } // namespace |
| 721 | 714 |
| 722 //////////////////////////////////////////////////////////////////////////////// | 715 //////////////////////////////////////////////////////////////////////////////// |
| 723 // AcceleratorController, public: | 716 // AcceleratorController, public: |
| 724 | 717 |
| 725 AcceleratorController::AcceleratorController() | 718 AcceleratorController::AcceleratorController() |
| 726 : accelerator_manager_(new ui::AcceleratorManager) { | 719 : accelerator_manager_(new ui::AcceleratorManager), |
| 720 accelerator_history_(new ui::AcceleratorHistory) { |
| 727 Init(); | 721 Init(); |
| 728 } | 722 } |
| 729 | 723 |
| 730 AcceleratorController::~AcceleratorController() { | 724 AcceleratorController::~AcceleratorController() { |
| 731 } | 725 } |
| 732 | 726 |
| 733 void AcceleratorController::Register(const ui::Accelerator& accelerator, | 727 void AcceleratorController::Register(const ui::Accelerator& accelerator, |
| 734 ui::AcceleratorTarget* target) { | 728 ui::AcceleratorTarget* target) { |
| 735 accelerator_manager_->Register(accelerator, | 729 accelerator_manager_->Register(accelerator, |
| 736 ui::AcceleratorManager::kNormalPriority, | 730 ui::AcceleratorManager::kNormalPriority, |
| 737 target); | 731 target); |
| 738 } | 732 } |
| 739 | 733 |
| 740 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, | 734 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, |
| 741 ui::AcceleratorTarget* target) { | 735 ui::AcceleratorTarget* target) { |
| 742 accelerator_manager_->Unregister(accelerator, target); | 736 accelerator_manager_->Unregister(accelerator, target); |
| 743 } | 737 } |
| 744 | 738 |
| 745 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) { | 739 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) { |
| 746 accelerator_manager_->UnregisterAll(target); | 740 accelerator_manager_->UnregisterAll(target); |
| 747 } | 741 } |
| 748 | 742 |
| 749 bool AcceleratorController::Process(const ui::Accelerator& accelerator) { | 743 bool AcceleratorController::Process(const ui::Accelerator& accelerator) { |
| 750 AutoSet auto_set(&previous_accelerator_, accelerator); | |
| 751 | |
| 752 if (ime_control_delegate_) { | 744 if (ime_control_delegate_) { |
| 753 return accelerator_manager_->Process( | 745 return accelerator_manager_->Process( |
| 754 ime_control_delegate_->RemapAccelerator(accelerator)); | 746 ime_control_delegate_->RemapAccelerator(accelerator)); |
| 755 } | 747 } |
| 756 return accelerator_manager_->Process(accelerator); | 748 return accelerator_manager_->Process(accelerator); |
| 757 } | 749 } |
| 758 | 750 |
| 759 bool AcceleratorController::IsRegistered( | 751 bool AcceleratorController::IsRegistered( |
| 760 const ui::Accelerator& accelerator) const { | 752 const ui::Accelerator& accelerator) const { |
| 761 return accelerator_manager_->GetCurrentTarget(accelerator) != NULL; | 753 return accelerator_manager_->GetCurrentTarget(accelerator) != NULL; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 } | 815 } |
| 824 | 816 |
| 825 bool AcceleratorController::CanHandleAccelerators() const { | 817 bool AcceleratorController::CanHandleAccelerators() const { |
| 826 return true; | 818 return true; |
| 827 } | 819 } |
| 828 | 820 |
| 829 /////////////////////////////////////////////////////////////////////////////// | 821 /////////////////////////////////////////////////////////////////////////////// |
| 830 // AcceleratorController, private: | 822 // AcceleratorController, private: |
| 831 | 823 |
| 832 void AcceleratorController::Init() { | 824 void AcceleratorController::Init() { |
| 833 previous_accelerator_.set_type(ui::ET_UNKNOWN); | |
| 834 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { | 825 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { |
| 835 actions_allowed_at_login_screen_.insert( | 826 actions_allowed_at_login_screen_.insert( |
| 836 kActionsAllowedAtLoginOrLockScreen[i]); | 827 kActionsAllowedAtLoginOrLockScreen[i]); |
| 837 actions_allowed_at_lock_screen_.insert( | 828 actions_allowed_at_lock_screen_.insert( |
| 838 kActionsAllowedAtLoginOrLockScreen[i]); | 829 kActionsAllowedAtLoginOrLockScreen[i]); |
| 839 } | 830 } |
| 840 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) | 831 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) |
| 841 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); | 832 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); |
| 842 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) | 833 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) |
| 843 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]); | 834 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | 880 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
| 890 | 881 |
| 891 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && | 882 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && |
| 892 accelerator.IsRepeat()) { | 883 accelerator.IsRepeat()) { |
| 893 return true; | 884 return true; |
| 894 } | 885 } |
| 895 | 886 |
| 896 const ui::KeyboardCode key_code = accelerator.key_code(); | 887 const ui::KeyboardCode key_code = accelerator.key_code(); |
| 897 | 888 |
| 898 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. | 889 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. |
| 899 const ui::EventType previous_event_type = previous_accelerator_.type(); | 890 const ui::Accelerator& previous_accelerator = |
| 900 const ui::KeyboardCode previous_key_code = previous_accelerator_.key_code(); | 891 accelerator_history_->previous_accelerator(); |
| 892 const ui::EventType previous_event_type = previous_accelerator.type(); |
| 893 const ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); |
| 901 | 894 |
| 902 // You *MUST* return true when some action is performed. Otherwise, this | 895 // You *MUST* return true when some action is performed. Otherwise, this |
| 903 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent | 896 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent |
| 904 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. | 897 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. |
| 905 // | 898 // |
| 906 // If your accelerator invokes more than one line of code, please either | 899 // If your accelerator invokes more than one line of code, please either |
| 907 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE | 900 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE |
| 908 // below) or pull it into a HandleFoo() function above. | 901 // below) or pull it into a HandleFoo() function above. |
| 909 switch (action) { | 902 switch (action) { |
| 910 case ACCESSIBLE_FOCUS_NEXT: | 903 case ACCESSIBLE_FOCUS_NEXT: |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 } | 1143 } |
| 1151 | 1144 |
| 1152 void AcceleratorController::SetKeyboardBrightnessControlDelegate( | 1145 void AcceleratorController::SetKeyboardBrightnessControlDelegate( |
| 1153 scoped_ptr<KeyboardBrightnessControlDelegate> | 1146 scoped_ptr<KeyboardBrightnessControlDelegate> |
| 1154 keyboard_brightness_control_delegate) { | 1147 keyboard_brightness_control_delegate) { |
| 1155 keyboard_brightness_control_delegate_ = | 1148 keyboard_brightness_control_delegate_ = |
| 1156 keyboard_brightness_control_delegate.Pass(); | 1149 keyboard_brightness_control_delegate.Pass(); |
| 1157 } | 1150 } |
| 1158 | 1151 |
| 1159 } // namespace ash | 1152 } // namespace ash |
| OLD | NEW |