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 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 accelerators_.find(remapped_accelerator); | 849 accelerators_.find(remapped_accelerator); |
850 if (iter == accelerators_.end()) | 850 if (iter == accelerators_.end()) |
851 return false; // not an accelerator. | 851 return false; // not an accelerator. |
852 | 852 |
853 return reserved_actions_.find(iter->second) != reserved_actions_.end(); | 853 return reserved_actions_.find(iter->second) != reserved_actions_.end(); |
854 } | 854 } |
855 | 855 |
856 bool AcceleratorController::PerformAction(int action, | 856 bool AcceleratorController::PerformAction(int action, |
857 const ui::Accelerator& accelerator) { | 857 const ui::Accelerator& accelerator) { |
858 ash::Shell* shell = ash::Shell::GetInstance(); | 858 ash::Shell* shell = ash::Shell::GetInstance(); |
859 if (!shell->session_state_delegate()->IsActiveUserSessionStarted() && | 859 AcceleratorProcessingRestriction restriction = |
860 actions_allowed_at_login_screen_.find(action) == | 860 GetAcceleratorProcessingRestriction(action); |
861 actions_allowed_at_login_screen_.end()) { | 861 if (restriction != RESTRICTION_NONE) |
862 return false; | 862 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
863 } | |
864 if (shell->session_state_delegate()->IsScreenLocked() && | |
865 actions_allowed_at_lock_screen_.find(action) == | |
866 actions_allowed_at_lock_screen_.end()) { | |
867 return false; | |
868 } | |
869 if (shell->IsSystemModalWindowOpen() && | |
870 actions_allowed_at_modal_window_.find(action) == | |
871 actions_allowed_at_modal_window_.end()) { | |
872 // Note: we return true. This indicates the shortcut is handled | |
873 // and will not be passed to the modal window. This is important | |
874 // for things like Alt+Tab that would cause an undesired effect | |
875 // in the modal window by cycling through its window elements. | |
876 return true; | |
877 } | |
878 if (shell->delegate()->IsRunningInForcedAppMode() && | |
879 actions_allowed_in_app_mode_.find(action) == | |
880 actions_allowed_in_app_mode_.end()) { | |
881 return false; | |
882 } | |
883 if (MruWindowTracker::BuildWindowList(false).empty() && | |
884 actions_needing_window_.find(action) != actions_needing_window_.end()) { | |
885 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert( | |
886 A11Y_ALERT_WINDOW_NEEDED); | |
887 return true; | |
888 } | |
889 | 863 |
890 const ui::KeyboardCode key_code = accelerator.key_code(); | 864 const ui::KeyboardCode key_code = accelerator.key_code(); |
891 // PerformAction() is performed from gesture controllers and passes | 865 // PerformAction() is performed from gesture controllers and passes |
892 // empty Accelerator() instance as the second argument. Such events | 866 // empty Accelerator() instance as the second argument. Such events |
893 // should never be suspended. | 867 // should never be suspended. |
894 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; | 868 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; |
895 // Ignore accelerators invoked as repeated (while holding a key for a long | 869 // Ignore accelerators invoked as repeated (while holding a key for a long |
896 // time, if their handling is nonrepeatable. | 870 // time, if their handling is nonrepeatable. |
897 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && | 871 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && |
898 accelerator.IsRepeat() && !gesture_event) { | 872 accelerator.IsRepeat() && !gesture_event) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 case PRINT_VIEW_HIERARCHY: | 1109 case PRINT_VIEW_HIERARCHY: |
1136 return HandlePrintViewHierarchy(); | 1110 return HandlePrintViewHierarchy(); |
1137 case PRINT_WINDOW_HIERARCHY: | 1111 case PRINT_WINDOW_HIERARCHY: |
1138 return HandlePrintWindowHierarchy(); | 1112 return HandlePrintWindowHierarchy(); |
1139 default: | 1113 default: |
1140 NOTREACHED() << "Unhandled action " << action; | 1114 NOTREACHED() << "Unhandled action " << action; |
1141 } | 1115 } |
1142 return false; | 1116 return false; |
1143 } | 1117 } |
1144 | 1118 |
| 1119 AcceleratorController::AcceleratorProcessingRestriction |
| 1120 AcceleratorController::GetCurrentAcceleratorRestriction() { |
| 1121 return GetAcceleratorProcessingRestriction(-1); |
| 1122 } |
| 1123 |
| 1124 AcceleratorController::AcceleratorProcessingRestriction |
| 1125 AcceleratorController::GetAcceleratorProcessingRestriction(int action) { |
| 1126 ash::Shell* shell = ash::Shell::GetInstance(); |
| 1127 if (!shell->session_state_delegate()->IsActiveUserSessionStarted() && |
| 1128 actions_allowed_at_login_screen_.find(action) == |
| 1129 actions_allowed_at_login_screen_.end()) { |
| 1130 return RESTRICTION_PREVENT_PROCESSING; |
| 1131 } |
| 1132 if (shell->session_state_delegate()->IsScreenLocked() && |
| 1133 actions_allowed_at_lock_screen_.find(action) == |
| 1134 actions_allowed_at_lock_screen_.end()) { |
| 1135 return RESTRICTION_PREVENT_PROCESSING; |
| 1136 } |
| 1137 if (shell->IsSystemModalWindowOpen() && |
| 1138 actions_allowed_at_modal_window_.find(action) == |
| 1139 actions_allowed_at_modal_window_.end()) { |
| 1140 // Note we prevent the shortcut from propagating so it will not |
| 1141 // be passed to the modal window. This is important for things like |
| 1142 // Alt+Tab that would cause an undesired effect in the modal window by |
| 1143 // cycling through its window elements. |
| 1144 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
| 1145 } |
| 1146 if (shell->delegate()->IsRunningInForcedAppMode() && |
| 1147 actions_allowed_in_app_mode_.find(action) == |
| 1148 actions_allowed_in_app_mode_.end()) { |
| 1149 return RESTRICTION_PREVENT_PROCESSING; |
| 1150 } |
| 1151 if (MruWindowTracker::BuildWindowList(false).empty() && |
| 1152 actions_needing_window_.find(action) != actions_needing_window_.end()) { |
| 1153 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert( |
| 1154 A11Y_ALERT_WINDOW_NEEDED); |
| 1155 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
| 1156 } |
| 1157 return RESTRICTION_NONE; |
| 1158 } |
| 1159 |
1145 void AcceleratorController::SetBrightnessControlDelegate( | 1160 void AcceleratorController::SetBrightnessControlDelegate( |
1146 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate) { | 1161 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate) { |
1147 brightness_control_delegate_ = brightness_control_delegate.Pass(); | 1162 brightness_control_delegate_ = brightness_control_delegate.Pass(); |
1148 } | 1163 } |
1149 | 1164 |
1150 void AcceleratorController::SetImeControlDelegate( | 1165 void AcceleratorController::SetImeControlDelegate( |
1151 scoped_ptr<ImeControlDelegate> ime_control_delegate) { | 1166 scoped_ptr<ImeControlDelegate> ime_control_delegate) { |
1152 ime_control_delegate_ = ime_control_delegate.Pass(); | 1167 ime_control_delegate_ = ime_control_delegate.Pass(); |
1153 } | 1168 } |
1154 | 1169 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 keyboard_brightness_control_delegate) { | 1202 keyboard_brightness_control_delegate) { |
1188 keyboard_brightness_control_delegate_ = | 1203 keyboard_brightness_control_delegate_ = |
1189 keyboard_brightness_control_delegate.Pass(); | 1204 keyboard_brightness_control_delegate.Pass(); |
1190 } | 1205 } |
1191 | 1206 |
1192 bool AcceleratorController::CanHandleAccelerators() const { | 1207 bool AcceleratorController::CanHandleAccelerators() const { |
1193 return true; | 1208 return true; |
1194 } | 1209 } |
1195 | 1210 |
1196 } // namespace ash | 1211 } // namespace ash |
OLD | NEW |