Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: ash/accelerators/accelerator_controller.cc

Issue 308023002: Add EF_IS_REPEAT flag to KeyEvent to handle repeated accelerators correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use ui::EF_IS_REPEAT in test instead Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 bool HandlePrintUIHierarchies() { 736 bool HandlePrintUIHierarchies() {
737 // This is a separate command so the user only has to hit one key to generate 737 // This is a separate command so the user only has to hit one key to generate
738 // all the logs. Developers use the individual dumps repeatedly, so keep 738 // all the logs. Developers use the individual dumps repeatedly, so keep
739 // those as separate commands to avoid spamming their logs. 739 // those as separate commands to avoid spamming their logs.
740 HandlePrintLayerHierarchy(); 740 HandlePrintLayerHierarchy();
741 HandlePrintWindowHierarchy(); 741 HandlePrintWindowHierarchy();
742 HandlePrintViewHierarchy(); 742 HandlePrintViewHierarchy();
743 return true; 743 return true;
744 } 744 }
745 745
746 class AutoSet {
747 public:
748 AutoSet(ui::Accelerator* scoped, ui::Accelerator new_value)
749 : scoped_(scoped), new_value_(new_value) {}
750 ~AutoSet() { *scoped_ = new_value_; }
751
752 private:
753 ui::Accelerator* scoped_;
754 const ui::Accelerator new_value_;
755
756 DISALLOW_COPY_AND_ASSIGN(AutoSet);
757 };
758
746 } // namespace 759 } // namespace
747 760
748 //////////////////////////////////////////////////////////////////////////////// 761 ////////////////////////////////////////////////////////////////////////////////
749 // AcceleratorControllerContext, public:
750
751 AcceleratorControllerContext::AcceleratorControllerContext() {
752 current_accelerator_.set_type(ui::ET_UNKNOWN);
753 previous_accelerator_.set_type(ui::ET_UNKNOWN);
754 }
755
756 void AcceleratorControllerContext::UpdateContext(
757 const ui::Accelerator& accelerator) {
758 previous_accelerator_ = current_accelerator_;
759 current_accelerator_ = accelerator;
760 }
761
762 ////////////////////////////////////////////////////////////////////////////////
763 // AcceleratorController, public: 762 // AcceleratorController, public:
764 763
765 AcceleratorController::AcceleratorController() 764 AcceleratorController::AcceleratorController()
766 : accelerator_manager_(new ui::AcceleratorManager) { 765 : accelerator_manager_(new ui::AcceleratorManager) {
767 Init(); 766 Init();
768 } 767 }
769 768
770 AcceleratorController::~AcceleratorController() { 769 AcceleratorController::~AcceleratorController() {
771 } 770 }
772 771
773 void AcceleratorController::Init() { 772 void AcceleratorController::Init() {
773 previous_accelerator_.set_type(ui::ET_UNKNOWN);
774 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { 774 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) {
775 actions_allowed_at_login_screen_.insert( 775 actions_allowed_at_login_screen_.insert(
776 kActionsAllowedAtLoginOrLockScreen[i]); 776 kActionsAllowedAtLoginOrLockScreen[i]);
777 actions_allowed_at_lock_screen_.insert( 777 actions_allowed_at_lock_screen_.insert(
778 kActionsAllowedAtLoginOrLockScreen[i]); 778 kActionsAllowedAtLoginOrLockScreen[i]);
779 } 779 }
780 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) 780 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i)
781 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); 781 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]);
782 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) 782 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i)
783 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]); 783 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, 818 void AcceleratorController::Unregister(const ui::Accelerator& accelerator,
819 ui::AcceleratorTarget* target) { 819 ui::AcceleratorTarget* target) {
820 accelerator_manager_->Unregister(accelerator, target); 820 accelerator_manager_->Unregister(accelerator, target);
821 } 821 }
822 822
823 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) { 823 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) {
824 accelerator_manager_->UnregisterAll(target); 824 accelerator_manager_->UnregisterAll(target);
825 } 825 }
826 826
827 bool AcceleratorController::Process(const ui::Accelerator& accelerator) { 827 bool AcceleratorController::Process(const ui::Accelerator& accelerator) {
828 AutoSet auto_set(&previous_accelerator_, accelerator);
829
828 if (ime_control_delegate_) { 830 if (ime_control_delegate_) {
829 return accelerator_manager_->Process( 831 return accelerator_manager_->Process(
830 ime_control_delegate_->RemapAccelerator(accelerator)); 832 ime_control_delegate_->RemapAccelerator(accelerator));
831 } 833 }
832 return accelerator_manager_->Process(accelerator); 834 return accelerator_manager_->Process(accelerator);
833 } 835 }
834 836
835 bool AcceleratorController::IsRegistered( 837 bool AcceleratorController::IsRegistered(
836 const ui::Accelerator& accelerator) const { 838 const ui::Accelerator& accelerator) const {
837 return accelerator_manager_->GetCurrentTarget(accelerator) != NULL; 839 return accelerator_manager_->GetCurrentTarget(accelerator) != NULL;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert( 884 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert(
883 A11Y_ALERT_WINDOW_NEEDED); 885 A11Y_ALERT_WINDOW_NEEDED);
884 return true; 886 return true;
885 } 887 }
886 888
887 const ui::KeyboardCode key_code = accelerator.key_code(); 889 const ui::KeyboardCode key_code = accelerator.key_code();
888 // PerformAction() is performed from gesture controllers and passes 890 // PerformAction() is performed from gesture controllers and passes
889 // empty Accelerator() instance as the second argument. Such events 891 // empty Accelerator() instance as the second argument. Such events
890 // should never be suspended. 892 // should never be suspended.
891 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; 893 const bool gesture_event = key_code == ui::VKEY_UNKNOWN;
892
893 // Ignore accelerators invoked as repeated (while holding a key for a long 894 // Ignore accelerators invoked as repeated (while holding a key for a long
894 // time, if their handling is nonrepeatable. 895 // time, if their handling is nonrepeatable.
895 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && 896 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
896 context_.repeated() && !gesture_event) { 897 accelerator.IsRepeat() && !gesture_event) {
897 return true; 898 return true;
898 } 899 }
899 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. 900 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK.
900 const ui::EventType previous_event_type = 901 const ui::EventType previous_event_type = previous_accelerator_.type();
901 context_.previous_accelerator().type(); 902 const ui::KeyboardCode previous_key_code = previous_accelerator_.key_code();
902 const ui::KeyboardCode previous_key_code =
903 context_.previous_accelerator().key_code();
904 903
905 // You *MUST* return true when some action is performed. Otherwise, this 904 // You *MUST* return true when some action is performed. Otherwise, this
906 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent 905 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent
907 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. 906 // and BrowserView::HandleKeyboardEvent, for a single accelerator press.
908 // 907 //
909 // If your accelerator invokes more than one line of code, please either 908 // If your accelerator invokes more than one line of code, please either
910 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE 909 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE
911 // below) or pull it into a HandleFoo() function above. 910 // below) or pull it into a HandleFoo() function above.
912 switch (action) { 911 switch (action) {
913 case ACCESSIBLE_FOCUS_NEXT: 912 case ACCESSIBLE_FOCUS_NEXT:
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 keyboard_brightness_control_delegate) { 1183 keyboard_brightness_control_delegate) {
1185 keyboard_brightness_control_delegate_ = 1184 keyboard_brightness_control_delegate_ =
1186 keyboard_brightness_control_delegate.Pass(); 1185 keyboard_brightness_control_delegate.Pass();
1187 } 1186 }
1188 1187
1189 bool AcceleratorController::CanHandleAccelerators() const { 1188 bool AcceleratorController::CanHandleAccelerators() const {
1190 return true; 1189 return true;
1191 } 1190 }
1192 1191
1193 } // namespace ash 1192 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller.h ('k') | ash/accelerators/accelerator_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698