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 3 // found in the LICENSE file. 4 5 #include "ash/accelerators/accelerator_table.h" 6 7 #include "ash/strings/grit/ash_strings.h" 8 #include "base/stl_util.h" 9 10 namespace ash { 11 12 // Instructions for how to deprecate and replace an Accelerator: 13 // 14 // 1- Replace the old deprecated accelerator from the above list with the new 15 // accelerator that will take its place. 16 // 2- Add an entry for it in the following |kDeprecatedAccelerators| list. 17 // 3- Add another entry in the |kDeprecatedAcceleratorsData|. 18 // 4- That entry should contain the following: 19 // - The action that the deprecated accelerator maps to. 20 // - Define a histogram for this action in |histograms.xml| in the form 21 // "Ash.Accelerators.Deprecated.{ActionName}" and include the name of this 22 // histogram in this entry. This name will be used as the ID of the 23 // notification to be shown to the user. This is to prevent duplication of 24 // same notification. 25 // - The ID of the localized notification message to give the users telling 26 // them about the deprecation (Add one in |ash_strings.grd|. Search for 27 // the comment <!-- Deprecated Accelerators Messages -->). 28 // - The IDs of the localized old and new shortcut text to be used to fill 29 // the notification text. Also found in |ash_strings.grd|. 30 // - {true or false} whether the deprecated accelerator is still enabled (we 31 // don't disable a deprecated accelerator abruptly). 32 // 5- Don't forget to update the keyboard_shortcut_viewer_metadata.cc and 33 // shortcut_viewer_strings.grdp. 34 const AcceleratorData kDeprecatedAccelerators[] = { 35 {true, ui::VKEY_ESCAPE, ui::EF_SHIFT_DOWN, SHOW_TASK_MANAGER}, 36 37 // Deprecated in M59. 38 {true, ui::VKEY_K, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, 39 SHOW_IME_MENU_BUBBLE}, 40 41 // Deprecated in M61. 42 {true, ui::VKEY_H, ui::EF_COMMAND_DOWN | ui::EF_SHIFT_DOWN, 43 TOGGLE_HIGH_CONTRAST}}; 44 45 const size_t kDeprecatedAcceleratorsLength = 46 base::size(kDeprecatedAccelerators); 47 48 const DeprecatedAcceleratorData kDeprecatedAcceleratorsData[] = { 49 {SHOW_TASK_MANAGER, "Ash.Accelerators.Deprecated.ShowTaskManager", 50 IDS_DEPRECATED_SHOW_TASK_MANAGER_MSG, IDS_SHORTCUT_TASK_MANAGER_OLD, 51 IDS_SHORTCUT_TASK_MANAGER_NEW, true}, 52 {SHOW_IME_MENU_BUBBLE, "Ash.Accelerators.Deprecated.ShowImeMenuBubble", 53 IDS_DEPRECATED_SHOW_IME_BUBBLE_MSG, IDS_SHORTCUT_IME_BUBBLE_OLD, 54 IDS_SHORTCUT_IME_BUBBLE_NEW, true}, 55 { 56 TOGGLE_HIGH_CONTRAST, "Ash.Accelerators.Deprecated.ToggleHighContrast", 57 IDS_DEPRECATED_TOGGLE_HIGH_CONTRAST_MSG, 58 IDS_SHORTCUT_TOGGLE_HIGH_CONTRAST_OLD, 59 IDS_SHORTCUT_TOGGLE_HIGH_CONTRAST_NEW, 60 false // Old accelerator was disabled immediately upon deprecation. 61 }}; 62 63 const size_t kDeprecatedAcceleratorsDataLength = 64 base::size(kDeprecatedAcceleratorsData); 65 66 static_assert(kDeprecatedAcceleratorsLength == 67 kDeprecatedAcceleratorsDataLength, 68 "Deprecated accelerator tables must be kept in sync"); 69 70 const AcceleratorData kDebugAcceleratorData[] = { 71 {true, ui::VKEY_N, kDebugModifier, TOGGLE_WIFI}, 72 {true, ui::VKEY_O, kDebugModifier, DEBUG_SHOW_TOAST}, 73 {true, ui::VKEY_P, ui::EF_COMMAND_DOWN | ui::EF_SHIFT_DOWN, 74 DEBUG_TOGGLE_TOUCH_PAD}, 75 {true, ui::VKEY_T, ui::EF_COMMAND_DOWN | ui::EF_SHIFT_DOWN, 76 DEBUG_TOGGLE_TOUCH_SCREEN}, 77 {true, ui::VKEY_T, kDebugModifier, DEBUG_TOGGLE_TABLET_MODE}, 78 {true, ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, 79 DEBUG_TOGGLE_WALLPAPER_MODE}, 80 {true, ui::VKEY_L, kDebugModifier, DEBUG_PRINT_LAYER_HIERARCHY}, 81 {true, ui::VKEY_V, kDebugModifier, DEBUG_PRINT_VIEW_HIERARCHY}, 82 {true, ui::VKEY_W, kDebugModifier, DEBUG_PRINT_WINDOW_HIERARCHY}, 83 {true, ui::VKEY_D, kDebugModifier, DEBUG_TOGGLE_DEVICE_SCALE_FACTOR}, 84 {true, ui::VKEY_B, kDebugModifier, DEBUG_TOGGLE_SHOW_DEBUG_BORDERS}, 85 {true, ui::VKEY_F, kDebugModifier, DEBUG_TOGGLE_SHOW_FPS_COUNTER}, 86 {true, ui::VKEY_P, kDebugModifier, DEBUG_TOGGLE_SHOW_PAINT_RECTS}, 87 {true, ui::VKEY_K, kDebugModifier, DEBUG_TRIGGER_CRASH}, 88 {true, ui::VKEY_G, kDebugModifier, DEBUG_TOGGLE_HUD_DISPLAY}, 89 }; 90 91 const size_t kDebugAcceleratorDataLength = base::size(kDebugAcceleratorData); 92 93 const AcceleratorData kDeveloperAcceleratorData[] = { 94 // Extra shortcut for debug build to control magnifier on Linux desktop. 95 {true, ui::VKEY_BRIGHTNESS_DOWN, ui::EF_CONTROL_DOWN, MAGNIFIER_ZOOM_OUT}, 96 {true, ui::VKEY_BRIGHTNESS_UP, ui::EF_CONTROL_DOWN, MAGNIFIER_ZOOM_IN}, 97 // Extra shortcuts to lock the screen on Linux desktop. 98 {true, ui::VKEY_L, ui::EF_ALT_DOWN, LOCK_PRESSED}, 99 {false, ui::VKEY_L, ui::EF_ALT_DOWN, LOCK_RELEASED}, 100 {true, ui::VKEY_P, ui::EF_ALT_DOWN, POWER_PRESSED}, 101 {false, ui::VKEY_P, ui::EF_ALT_DOWN, POWER_RELEASED}, 102 {true, ui::VKEY_POWER, ui::EF_SHIFT_DOWN, LOCK_PRESSED}, 103 {false, ui::VKEY_POWER, ui::EF_SHIFT_DOWN, LOCK_RELEASED}, 104 {true, ui::VKEY_D, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, 105 DEV_ADD_REMOVE_DISPLAY}, 106 {true, ui::VKEY_J, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, 107 DEV_TOGGLE_UNIFIED_DESKTOP}, 108 {true, ui::VKEY_M, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, 109 TOGGLE_MIRROR_MODE}, 110 {true, ui::VKEY_W, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, TOGGLE_WIFI}, 111 // Extra shortcut for display swapping as Alt-F4 is taken on Linux desktop. 112 {true, ui::VKEY_S, kDebugModifier, SWAP_PRIMARY_DISPLAY}, 113 // Extra shortcut to rotate/scale up/down the screen on Linux desktop. 114 {true, ui::VKEY_R, kDebugModifier, ROTATE_SCREEN}, 115 // For testing on systems where Alt-Tab is already mapped. 116 {true, ui::VKEY_W, ui::EF_ALT_DOWN, CYCLE_FORWARD_MRU}, 117 {true, ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, CYCLE_BACKWARD_MRU}, 118 {true, ui::VKEY_F, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, 119 TOGGLE_FULLSCREEN}, 120 // TODO(wutao): Get a shortcut for the Ambient mode. 121 {true, ui::VKEY_A, ui::EF_COMMAND_DOWN | ui::EF_CONTROL_DOWN, 122 START_AMBIENT_MODE}, 123 }; 124 125 const size_t kDeveloperAcceleratorDataLength = 126 base::size(kDeveloperAcceleratorData); 127 128 const AcceleratorAction kPreferredActions[] = { 129 // Window cycling accelerators. 130 CYCLE_BACKWARD_MRU, // Shift+Alt+Tab 131 CYCLE_FORWARD_MRU, // Alt+Tab 132 }; 133 134 const size_t kPreferredActionsLength = base::size(kPreferredActions); 135 136 const AcceleratorAction kReservedActions[] = { 137 POWER_PRESSED, POWER_RELEASED, SUSPEND, 138 }; 139 140 const size_t kReservedActionsLength = base::size(kReservedActions); 141 142 const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = { 143 BRIGHTNESS_DOWN, 144 BRIGHTNESS_UP, 145 DEBUG_PRINT_LAYER_HIERARCHY, 146 DEBUG_PRINT_VIEW_HIERARCHY, 147 DEBUG_PRINT_WINDOW_HIERARCHY, 148 DEBUG_TOGGLE_HUD_DISPLAY, 149 DEBUG_TOGGLE_TOUCH_PAD, 150 DEBUG_TOGGLE_TOUCH_SCREEN, 151 DEBUG_TOGGLE_TABLET_MODE, 152 DEV_ADD_REMOVE_DISPLAY, 153 DISABLE_CAPS_LOCK, 154 KEYBOARD_BRIGHTNESS_DOWN, 155 KEYBOARD_BRIGHTNESS_UP, 156 MAGNIFIER_ZOOM_IN, // Control+F7 157 MAGNIFIER_ZOOM_OUT, // Control+F6 158 MEDIA_FAST_FORWARD, 159 MEDIA_NEXT_TRACK, 160 MEDIA_PAUSE, 161 MEDIA_PLAY, 162 MEDIA_PLAY_PAUSE, 163 MEDIA_PREV_TRACK, 164 MEDIA_REWIND, 165 MEDIA_STOP, 166 PRIVACY_SCREEN_TOGGLE, 167 PRINT_UI_HIERARCHIES, 168 ROTATE_SCREEN, 169 SCALE_UI_DOWN, 170 SCALE_UI_RESET, 171 SCALE_UI_UP, 172 SHOW_IME_MENU_BUBBLE, 173 START_AMBIENT_MODE, 174 SWITCH_TO_LAST_USED_IME, 175 SWITCH_TO_NEXT_IME, 176 TOGGLE_CAPS_LOCK, 177 TOGGLE_DICTATION, 178 TOGGLE_DOCKED_MAGNIFIER, 179 TOGGLE_FULLSCREEN_MAGNIFIER, 180 TOGGLE_HIGH_CONTRAST, 181 TOGGLE_MIRROR_MODE, 182 TOGGLE_SPOKEN_FEEDBACK, 183 TOGGLE_SYSTEM_TRAY_BUBBLE, 184 TOGGLE_WIFI, 185 TOUCH_HUD_CLEAR, 186 VOLUME_DOWN, 187 VOLUME_MUTE, 188 VOLUME_UP, 189 #if !defined(NDEBUG) 190 POWER_PRESSED, 191 POWER_RELEASED, 192 #endif // !defined(NDEBUG) 193 }; 194 195 const size_t kActionsAllowedAtLoginOrLockScreenLength = 196 base::size(kActionsAllowedAtLoginOrLockScreen); 197 198 const AcceleratorAction kActionsAllowedAtLockScreen[] = { 199 EXIT, 200 SUSPEND, 201 TAKE_PARTIAL_SCREENSHOT, 202 TAKE_SCREENSHOT, 203 TAKE_WINDOW_SCREENSHOT, 204 }; 205 206 const size_t kActionsAllowedAtLockScreenLength = 207 base::size(kActionsAllowedAtLockScreen); 208 209 const AcceleratorAction kActionsAllowedAtPowerMenu[] = { 210 BRIGHTNESS_DOWN, BRIGHTNESS_UP, VOLUME_DOWN, VOLUME_UP, VOLUME_MUTE, 211 }; 212 213 const size_t kActionsAllowedAtPowerMenuLength = 214 base::size(kActionsAllowedAtPowerMenu); 215 216 const AcceleratorAction kActionsAllowedAtModalWindow[] = { 217 BRIGHTNESS_DOWN, 218 BRIGHTNESS_UP, 219 DEBUG_TOGGLE_TOUCH_PAD, 220 DEBUG_TOGGLE_TOUCH_SCREEN, 221 DEV_ADD_REMOVE_DISPLAY, 222 DISABLE_CAPS_LOCK, 223 EXIT, 224 KEYBOARD_BRIGHTNESS_DOWN, 225 KEYBOARD_BRIGHTNESS_UP, 226 LOCK_SCREEN, 227 MAGNIFIER_ZOOM_IN, 228 MAGNIFIER_ZOOM_OUT, 229 MEDIA_FAST_FORWARD, 230 MEDIA_NEXT_TRACK, 231 MEDIA_PAUSE, 232 MEDIA_PLAY, 233 MEDIA_PLAY_PAUSE, 234 MEDIA_PREV_TRACK, 235 MEDIA_REWIND, 236 MEDIA_STOP, 237 OPEN_FEEDBACK_PAGE, 238 POWER_PRESSED, 239 POWER_RELEASED, 240 PRINT_UI_HIERARCHIES, 241 PRIVACY_SCREEN_TOGGLE, 242 ROTATE_SCREEN, 243 SCALE_UI_DOWN, 244 SCALE_UI_RESET, 245 SCALE_UI_UP, 246 SHOW_IME_MENU_BUBBLE, 247 SHOW_SHORTCUT_VIEWER, 248 START_AMBIENT_MODE, 249 SUSPEND, 250 SWAP_PRIMARY_DISPLAY, 251 SWITCH_TO_LAST_USED_IME, 252 SWITCH_TO_NEXT_IME, 253 TAKE_PARTIAL_SCREENSHOT, 254 TAKE_SCREENSHOT, 255 TAKE_WINDOW_SCREENSHOT, 256 TOGGLE_CAPS_LOCK, 257 TOGGLE_DICTATION, 258 TOGGLE_DOCKED_MAGNIFIER, 259 TOGGLE_FULLSCREEN_MAGNIFIER, 260 TOGGLE_HIGH_CONTRAST, 261 TOGGLE_MIRROR_MODE, 262 TOGGLE_SPOKEN_FEEDBACK, 263 TOGGLE_WIFI, 264 VOLUME_DOWN, 265 VOLUME_MUTE, 266 VOLUME_UP, 267 }; 268 269 const size_t kActionsAllowedAtModalWindowLength = 270 base::size(kActionsAllowedAtModalWindow); 271 272 const AcceleratorAction kRepeatableActions[] = { 273 BRIGHTNESS_DOWN, 274 BRIGHTNESS_UP, 275 FOCUS_NEXT_PANE, 276 FOCUS_PREVIOUS_PANE, 277 KEYBOARD_BRIGHTNESS_DOWN, 278 KEYBOARD_BRIGHTNESS_UP, 279 MAGNIFIER_ZOOM_IN, 280 MAGNIFIER_ZOOM_OUT, 281 MEDIA_FAST_FORWARD, 282 MEDIA_NEXT_TRACK, 283 MEDIA_PREV_TRACK, 284 MEDIA_REWIND, 285 RESTORE_TAB, 286 VOLUME_DOWN, 287 VOLUME_UP, 288 }; 289 290 const size_t kRepeatableActionsLength = base::size(kRepeatableActions); 291 292 const AcceleratorAction kActionsAllowedInAppModeOrPinnedMode[] = { 293 BRIGHTNESS_DOWN, 294 BRIGHTNESS_UP, 295 DEBUG_PRINT_LAYER_HIERARCHY, 296 DEBUG_PRINT_VIEW_HIERARCHY, 297 DEBUG_PRINT_WINDOW_HIERARCHY, 298 DEBUG_TOGGLE_TOUCH_PAD, 299 DEBUG_TOGGLE_TOUCH_SCREEN, 300 DEV_ADD_REMOVE_DISPLAY, 301 DISABLE_CAPS_LOCK, 302 KEYBOARD_BRIGHTNESS_DOWN, 303 KEYBOARD_BRIGHTNESS_UP, 304 MAGNIFIER_ZOOM_IN, // Control+F7 305 MAGNIFIER_ZOOM_OUT, // Control+F6 306 MEDIA_FAST_FORWARD, 307 MEDIA_NEXT_TRACK, 308 MEDIA_PAUSE, 309 MEDIA_PLAY, 310 MEDIA_PLAY_PAUSE, 311 MEDIA_PREV_TRACK, 312 MEDIA_REWIND, 313 MEDIA_STOP, 314 POWER_PRESSED, 315 POWER_RELEASED, 316 PRINT_UI_HIERARCHIES, 317 PRIVACY_SCREEN_TOGGLE, 318 ROTATE_SCREEN, 319 SCALE_UI_DOWN, 320 SCALE_UI_RESET, 321 SCALE_UI_UP, 322 SWAP_PRIMARY_DISPLAY, 323 SWITCH_TO_LAST_USED_IME, 324 SWITCH_TO_NEXT_IME, 325 TOGGLE_CAPS_LOCK, 326 TOGGLE_DICTATION, 327 TOGGLE_DOCKED_MAGNIFIER, 328 TOGGLE_FULLSCREEN_MAGNIFIER, 329 TOGGLE_HIGH_CONTRAST, 330 TOGGLE_MIRROR_MODE, 331 TOGGLE_SPOKEN_FEEDBACK, 332 TOGGLE_WIFI, 333 TOUCH_HUD_CLEAR, 334 VOLUME_DOWN, 335 VOLUME_MUTE, 336 VOLUME_UP, 337 }; 338 339 const size_t kActionsAllowedInAppModeOrPinnedModeLength = 340 base::size(kActionsAllowedInAppModeOrPinnedMode); 341 342 const AcceleratorAction kActionsAllowedInPinnedMode[] = { 343 LOCK_SCREEN, 344 SUSPEND, 345 TAKE_PARTIAL_SCREENSHOT, 346 TAKE_SCREENSHOT, 347 TAKE_WINDOW_SCREENSHOT, 348 UNPIN, 349 }; 350 351 const size_t kActionsAllowedInPinnedModeLength = 352 base::size(kActionsAllowedInPinnedMode); 353 354 const AcceleratorAction kActionsAllowedInAppMode[] = { 355 FOCUS_SHELF, 356 }; 357 358 const size_t kActionsAllowedInAppModeLength = 359 base::size(kActionsAllowedInAppMode); 360 361 const AcceleratorAction kActionsNeedingWindow[] = { 362 // clang-format off 363 DESKS_MOVE_ACTIVE_ITEM, 364 MOVE_ACTIVE_WINDOW_BETWEEN_DISPLAYS, 365 ROTATE_WINDOW, 366 TOGGLE_FULLSCREEN, 367 TOGGLE_MAXIMIZED, 368 WINDOW_CYCLE_SNAP_LEFT, 369 WINDOW_CYCLE_SNAP_RIGHT, 370 WINDOW_MINIMIZE, 371 // clang-format on 372 }; 373 374 const size_t kActionsNeedingWindowLength = base::size(kActionsNeedingWindow); 375 376 const AcceleratorAction kActionsKeepingMenuOpen[] = { 377 BRIGHTNESS_DOWN, 378 BRIGHTNESS_UP, 379 DEBUG_TOGGLE_TOUCH_PAD, 380 DEBUG_TOGGLE_TOUCH_SCREEN, 381 DISABLE_CAPS_LOCK, 382 KEYBOARD_BRIGHTNESS_DOWN, 383 KEYBOARD_BRIGHTNESS_UP, 384 MEDIA_FAST_FORWARD, 385 MEDIA_NEXT_TRACK, 386 MEDIA_PAUSE, 387 MEDIA_PLAY, 388 MEDIA_PLAY_PAUSE, 389 MEDIA_PREV_TRACK, 390 MEDIA_REWIND, 391 MEDIA_STOP, 392 PRINT_UI_HIERARCHIES, 393 PRIVACY_SCREEN_TOGGLE, 394 SWITCH_TO_LAST_USED_IME, 395 SWITCH_TO_NEXT_IME, 396 TAKE_PARTIAL_SCREENSHOT, 397 TAKE_SCREENSHOT, 398 TAKE_WINDOW_SCREENSHOT, 399 TOGGLE_APP_LIST, 400 TOGGLE_APP_LIST_FULLSCREEN, 401 TOGGLE_CAPS_LOCK, 402 TOGGLE_DICTATION, 403 TOGGLE_DOCKED_MAGNIFIER, 404 TOGGLE_FULLSCREEN_MAGNIFIER, 405 TOGGLE_HIGH_CONTRAST, 406 TOGGLE_SPOKEN_FEEDBACK, 407 TOGGLE_WIFI, 408 VOLUME_DOWN, 409 VOLUME_MUTE, 410 VOLUME_UP, 411 }; 412 413 const size_t kActionsKeepingMenuOpenLength = 414 base::size(kActionsKeepingMenuOpen); 415 416 } // namespace ash 417