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

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

Issue 350943003: Support global keyboard commands on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address various comments. 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 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 accelerators_.find(remapped_accelerator); 850 accelerators_.find(remapped_accelerator);
851 if (iter == accelerators_.end()) 851 if (iter == accelerators_.end())
852 return false; // not an accelerator. 852 return false; // not an accelerator.
853 853
854 return reserved_actions_.find(iter->second) != reserved_actions_.end(); 854 return reserved_actions_.find(iter->second) != reserved_actions_.end();
855 } 855 }
856 856
857 bool AcceleratorController::PerformAction(int action, 857 bool AcceleratorController::PerformAction(int action,
858 const ui::Accelerator& accelerator) { 858 const ui::Accelerator& accelerator) {
859 ash::Shell* shell = ash::Shell::GetInstance(); 859 ash::Shell* shell = ash::Shell::GetInstance();
860 if (!shell->session_state_delegate()->IsActiveUserSessionStarted() && 860 AcceleratorProcessingRestriction restriction =
861 actions_allowed_at_login_screen_.find(action) == 861 GetAcceleratorProcessingRestriction(action, accelerator);
862 actions_allowed_at_login_screen_.end()) { 862 if (restriction != RESTRICTION_NONE)
863 return false; 863 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
864 }
865 if (shell->session_state_delegate()->IsScreenLocked() &&
866 actions_allowed_at_lock_screen_.find(action) ==
867 actions_allowed_at_lock_screen_.end()) {
868 return false;
869 }
870 if (shell->IsSystemModalWindowOpen() &&
871 actions_allowed_at_modal_window_.find(action) ==
872 actions_allowed_at_modal_window_.end()) {
873 // Note: we return true. This indicates the shortcut is handled
874 // and will not be passed to the modal window. This is important
875 // for things like Alt+Tab that would cause an undesired effect
876 // in the modal window by cycling through its window elements.
877 return true;
878 }
879 if (shell->delegate()->IsRunningInForcedAppMode() &&
880 actions_allowed_in_app_mode_.find(action) ==
881 actions_allowed_in_app_mode_.end()) {
882 return false;
883 }
884 if (MruWindowTracker::BuildWindowList(false).empty() &&
885 actions_needing_window_.find(action) != actions_needing_window_.end()) {
886 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert(
887 A11Y_ALERT_WINDOW_NEEDED);
888 return true;
889 }
890 864
891 const ui::KeyboardCode key_code = accelerator.key_code(); 865 const ui::KeyboardCode key_code = accelerator.key_code();
892 // PerformAction() is performed from gesture controllers and passes 866 // PerformAction() is performed from gesture controllers and passes
893 // empty Accelerator() instance as the second argument. Such events 867 // empty Accelerator() instance as the second argument. Such events
894 // should never be suspended. 868 // should never be suspended.
895 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; 869 const bool gesture_event = key_code == ui::VKEY_UNKNOWN;
896 // Ignore accelerators invoked as repeated (while holding a key for a long 870 // Ignore accelerators invoked as repeated (while holding a key for a long
897 // time, if their handling is nonrepeatable. 871 // time, if their handling is nonrepeatable.
898 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && 872 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
899 accelerator.IsRepeat() && !gesture_event) { 873 accelerator.IsRepeat() && !gesture_event) {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 case PRINT_VIEW_HIERARCHY: 1107 case PRINT_VIEW_HIERARCHY:
1134 return HandlePrintViewHierarchy(); 1108 return HandlePrintViewHierarchy();
1135 case PRINT_WINDOW_HIERARCHY: 1109 case PRINT_WINDOW_HIERARCHY:
1136 return HandlePrintWindowHierarchy(); 1110 return HandlePrintWindowHierarchy();
1137 default: 1111 default:
1138 NOTREACHED() << "Unhandled action " << action; 1112 NOTREACHED() << "Unhandled action " << action;
1139 } 1113 }
1140 return false; 1114 return false;
1141 } 1115 }
1142 1116
1117 AcceleratorController::AcceleratorProcessingRestriction
1118 AcceleratorController::GetAcceleratorProcessingRestriction(
1119 int action,
1120 const ui::Accelerator& accelerator) {
oshima 2014/06/27 18:40:40 accelerator is not used here. Maybe this is what y
David Tseng 2014/06/27 21:47:16 I removed the accelerator parameter. Perhaps the
1121 ash::Shell* shell = ash::Shell::GetInstance();
1122 if (!shell->session_state_delegate()->IsActiveUserSessionStarted() &&
1123 actions_allowed_at_login_screen_.find(action) ==
1124 actions_allowed_at_login_screen_.end()) {
1125 return RESTRICTION_PREVENT_PROCESSING;
1126 }
1127 if (shell->session_state_delegate()->IsScreenLocked() &&
1128 actions_allowed_at_lock_screen_.find(action) ==
1129 actions_allowed_at_lock_screen_.end()) {
1130 return RESTRICTION_PREVENT_PROCESSING;
1131 }
1132 if (shell->IsSystemModalWindowOpen() &&
1133 actions_allowed_at_modal_window_.find(action) ==
1134 actions_allowed_at_modal_window_.end()) {
1135 // Note we prevent the shortcut from propagating so it will not
1136 // be passed to the modal window. This is important for things like
1137 // Alt+Tab that would cause an undesired effect in the modal window by
1138 // cycling through its window elements.
1139 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
1140 }
1141 if (shell->delegate()->IsRunningInForcedAppMode() &&
1142 actions_allowed_in_app_mode_.find(action) ==
1143 actions_allowed_in_app_mode_.end()) {
1144 return RESTRICTION_PREVENT_PROCESSING;
1145 }
1146 if (MruWindowTracker::BuildWindowList(false).empty() &&
1147 actions_needing_window_.find(action) != actions_needing_window_.end()) {
1148 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert(
1149 A11Y_ALERT_WINDOW_NEEDED);
1150 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
1151 }
1152 return RESTRICTION_NONE;
1153 }
1154
1143 void AcceleratorController::SetBrightnessControlDelegate( 1155 void AcceleratorController::SetBrightnessControlDelegate(
1144 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate) { 1156 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate) {
1145 brightness_control_delegate_ = brightness_control_delegate.Pass(); 1157 brightness_control_delegate_ = brightness_control_delegate.Pass();
1146 } 1158 }
1147 1159
1148 void AcceleratorController::SetImeControlDelegate( 1160 void AcceleratorController::SetImeControlDelegate(
1149 scoped_ptr<ImeControlDelegate> ime_control_delegate) { 1161 scoped_ptr<ImeControlDelegate> ime_control_delegate) {
1150 ime_control_delegate_ = ime_control_delegate.Pass(); 1162 ime_control_delegate_ = ime_control_delegate.Pass();
1151 } 1163 }
1152 1164
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 keyboard_brightness_control_delegate) { 1197 keyboard_brightness_control_delegate) {
1186 keyboard_brightness_control_delegate_ = 1198 keyboard_brightness_control_delegate_ =
1187 keyboard_brightness_control_delegate.Pass(); 1199 keyboard_brightness_control_delegate.Pass();
1188 } 1200 }
1189 1201
1190 bool AcceleratorController::CanHandleAccelerators() const { 1202 bool AcceleratorController::CanHandleAccelerators() const {
1191 return true; 1203 return true;
1192 } 1204 }
1193 1205
1194 } // namespace ash 1206 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698