accelerators.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. // Copyright 2018 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. #ifndef ASH_PUBLIC_CPP_ACCELERATORS_H_
  5. #define ASH_PUBLIC_CPP_ACCELERATORS_H_
  6. #include <stddef.h>
  7. #include "ash/public/cpp/ash_public_export.h"
  8. #include "base/callback_forward.h"
  9. #include "base/observer_list.h"
  10. #include "ui/events/event_constants.h"
  11. #include "ui/events/keycodes/keyboard_codes.h"
  12. namespace ui {
  13. class Accelerator;
  14. }
  15. namespace ash {
  16. class AcceleratorHistory;
  17. // See documentation in ash/accelerators/accelerator_table.h.
  18. enum AcceleratorAction {
  19. BRIGHTNESS_DOWN,
  20. BRIGHTNESS_UP,
  21. CYCLE_BACKWARD_MRU,
  22. CYCLE_FORWARD_MRU,
  23. DESKS_ACTIVATE_DESK_LEFT,
  24. DESKS_ACTIVATE_DESK_RIGHT,
  25. DESKS_MOVE_ACTIVE_ITEM_LEFT,
  26. DESKS_MOVE_ACTIVE_ITEM_RIGHT,
  27. DESKS_NEW_DESK,
  28. DESKS_REMOVE_CURRENT_DESK,
  29. DESKS_ACTIVATE_0,
  30. DESKS_ACTIVATE_1,
  31. DESKS_ACTIVATE_2,
  32. DESKS_ACTIVATE_3,
  33. DESKS_ACTIVATE_4,
  34. DESKS_ACTIVATE_5,
  35. DESKS_ACTIVATE_6,
  36. DESKS_ACTIVATE_7,
  37. DESKS_TOGGLE_ASSIGN_TO_ALL_DESKS,
  38. DISABLE_CAPS_LOCK,
  39. EXIT,
  40. FOCUS_CAMERA_PREVIEW,
  41. FOCUS_NEXT_PANE,
  42. FOCUS_PREVIOUS_PANE,
  43. FOCUS_SHELF,
  44. FOCUS_PIP,
  45. KEYBOARD_BACKLIGHT_TOGGLE,
  46. KEYBOARD_BRIGHTNESS_DOWN,
  47. KEYBOARD_BRIGHTNESS_UP,
  48. LAUNCH_APP_0,
  49. LAUNCH_APP_1,
  50. LAUNCH_APP_2,
  51. LAUNCH_APP_3,
  52. LAUNCH_APP_4,
  53. LAUNCH_APP_5,
  54. LAUNCH_APP_6,
  55. LAUNCH_APP_7,
  56. LAUNCH_LAST_APP,
  57. LOCK_PRESSED,
  58. LOCK_RELEASED,
  59. LOCK_SCREEN,
  60. MAGNIFIER_ZOOM_IN,
  61. MAGNIFIER_ZOOM_OUT,
  62. MEDIA_FAST_FORWARD,
  63. MEDIA_NEXT_TRACK,
  64. MEDIA_PAUSE,
  65. MEDIA_PLAY,
  66. MEDIA_PLAY_PAUSE,
  67. MEDIA_PREV_TRACK,
  68. MEDIA_REWIND,
  69. MEDIA_STOP,
  70. MICROPHONE_MUTE_TOGGLE,
  71. MOVE_ACTIVE_WINDOW_BETWEEN_DISPLAYS,
  72. NEW_INCOGNITO_WINDOW,
  73. NEW_TAB,
  74. NEW_WINDOW,
  75. OPEN_CALCULATOR,
  76. OPEN_CROSH,
  77. OPEN_DIAGNOSTICS,
  78. OPEN_FEEDBACK_PAGE,
  79. OPEN_FILE_MANAGER,
  80. OPEN_GET_HELP,
  81. POWER_PRESSED,
  82. POWER_RELEASED,
  83. PRINT_UI_HIERARCHIES,
  84. PRIVACY_SCREEN_TOGGLE,
  85. RESTORE_TAB,
  86. ROTATE_SCREEN,
  87. ROTATE_WINDOW,
  88. SCALE_UI_DOWN,
  89. SCALE_UI_RESET,
  90. SCALE_UI_UP,
  91. SHOW_EMOJI_PICKER,
  92. TOGGLE_IME_MENU_BUBBLE,
  93. SHOW_SHORTCUT_VIEWER,
  94. SHOW_STYLUS_TOOLS,
  95. SHOW_TASK_MANAGER,
  96. START_AMBIENT_MODE,
  97. START_ASSISTANT,
  98. SUSPEND,
  99. SWAP_PRIMARY_DISPLAY,
  100. SWITCH_IME, // Switch to another IME depending on the accelerator.
  101. SWITCH_TO_LAST_USED_IME,
  102. SWITCH_TO_NEXT_IME,
  103. SWITCH_TO_NEXT_USER,
  104. SWITCH_TO_PREVIOUS_USER,
  105. TAKE_PARTIAL_SCREENSHOT,
  106. TAKE_SCREENSHOT,
  107. TAKE_WINDOW_SCREENSHOT,
  108. TOGGLE_APP_LIST,
  109. TOGGLE_APP_LIST_FULLSCREEN,
  110. TOGGLE_CALENDAR,
  111. TOGGLE_CAPS_LOCK,
  112. TOGGLE_CLIPBOARD_HISTORY,
  113. TOGGLE_DICTATION,
  114. TOGGLE_DOCKED_MAGNIFIER,
  115. TOGGLE_FLOATING,
  116. TOGGLE_FULLSCREEN,
  117. TOGGLE_FULLSCREEN_MAGNIFIER,
  118. TOGGLE_HIGH_CONTRAST,
  119. TOGGLE_MAXIMIZED,
  120. TOGGLE_MESSAGE_CENTER_BUBBLE,
  121. TOGGLE_MIRROR_MODE,
  122. TOGGLE_OVERVIEW,
  123. TOGGLE_PROJECTOR_MARKER,
  124. TOGGLE_RESIZE_LOCK_MENU,
  125. TOGGLE_SPOKEN_FEEDBACK,
  126. TOGGLE_SYSTEM_TRAY_BUBBLE,
  127. TOGGLE_WIFI,
  128. TOUCH_HUD_CLEAR,
  129. TOUCH_HUD_MODE_CHANGE,
  130. UNPIN,
  131. VOLUME_DOWN,
  132. VOLUME_MUTE,
  133. VOLUME_UP,
  134. WINDOW_CYCLE_SNAP_LEFT,
  135. WINDOW_CYCLE_SNAP_RIGHT,
  136. WINDOW_MINIMIZE,
  137. MINIMIZE_TOP_WINDOW_ON_BACK,
  138. // Debug accelerators are intentionally at the end, so that if you remove one
  139. // you don't need to update tests which check hashes of the ids.
  140. DEBUG_DUMP_CALENDAR_MODEL,
  141. DEBUG_KEYBOARD_BACKLIGHT_TOGGLE,
  142. DEBUG_MICROPHONE_MUTE_TOGGLE,
  143. DEBUG_PRINT_LAYER_HIERARCHY,
  144. DEBUG_PRINT_VIEW_HIERARCHY,
  145. DEBUG_PRINT_WINDOW_HIERARCHY,
  146. DEBUG_SHOW_TOAST,
  147. DEBUG_TOGGLE_SHOW_DEBUG_BORDERS,
  148. DEBUG_TOGGLE_SHOW_FPS_COUNTER,
  149. DEBUG_TOGGLE_SHOW_PAINT_RECTS,
  150. DEBUG_TOGGLE_TOUCH_PAD,
  151. DEBUG_TOGGLE_TOUCH_SCREEN,
  152. DEBUG_TOGGLE_TABLET_MODE,
  153. DEBUG_TOGGLE_WALLPAPER_MODE,
  154. DEBUG_TRIGGER_CRASH, // Intentionally crash the ash process.
  155. DEBUG_TOGGLE_HUD_DISPLAY,
  156. DEV_ADD_REMOVE_DISPLAY,
  157. // Different than TOGGLE_APP_LIST to ignore search-as-modifier-key rules for
  158. // enabling the accelerator.
  159. DEV_TOGGLE_APP_LIST,
  160. DEV_TOGGLE_UNIFIED_DESKTOP,
  161. };
  162. struct AcceleratorData {
  163. bool trigger_on_press;
  164. ui::KeyboardCode keycode;
  165. int modifiers;
  166. AcceleratorAction action;
  167. };
  168. // A mask of all the modifiers used for debug accelerators.
  169. ASH_PUBLIC_EXPORT constexpr int kDebugModifier =
  170. ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN;
  171. // Accelerators handled by AcceleratorController.
  172. ASH_PUBLIC_EXPORT extern const AcceleratorData kAcceleratorData[];
  173. ASH_PUBLIC_EXPORT extern const size_t kAcceleratorDataLength;
  174. // Accelerators that are enabled/disabled with new accelerator mapping.
  175. // crbug.com/1067269
  176. ASH_PUBLIC_EXPORT extern const AcceleratorData
  177. kEnableWithNewMappingAcceleratorData[];
  178. ASH_PUBLIC_EXPORT extern const size_t
  179. kEnableWithNewMappingAcceleratorDataLength;
  180. ASH_PUBLIC_EXPORT extern const AcceleratorData
  181. kDisableWithNewMappingAcceleratorData[];
  182. ASH_PUBLIC_EXPORT extern const size_t
  183. kDisableWithNewMappingAcceleratorDataLength;
  184. // Accelerators that are enabled with positional shortcut mapping.
  185. ASH_PUBLIC_EXPORT extern const AcceleratorData
  186. kEnableWithPositionalAcceleratorsData[];
  187. ASH_PUBLIC_EXPORT extern const size_t
  188. kEnableWithPositionalAcceleratorsDataLength;
  189. // Accelerators that are enabled with improved desks keyboards shortcuts.
  190. ASH_PUBLIC_EXPORT extern const AcceleratorData
  191. kEnabledWithImprovedDesksKeyboardShortcutsAcceleratorData[];
  192. ASH_PUBLIC_EXPORT extern const size_t
  193. kEnabledWithImprovedDesksKeyboardShortcutsAcceleratorDataLength;
  194. // The public-facing interface for accelerator handling, which is Ash's duty to
  195. // implement.
  196. class ASH_PUBLIC_EXPORT AcceleratorController {
  197. public:
  198. class Observer : public base::CheckedObserver {
  199. public:
  200. // Invoked when `action` is performed.
  201. virtual void OnActionPerformed(AcceleratorAction action) = 0;
  202. // Invoked when `controller` is destroyed.
  203. virtual void OnAcceleratorControllerWillBeDestroyed(
  204. AcceleratorController* controller) {}
  205. };
  206. // Returns the singleton instance.
  207. static AcceleratorController* Get();
  208. // Called by Chrome to set the closure that should be run when the volume has
  209. // been adjusted (playing an audible tone when spoken feedback is enabled).
  210. static void SetVolumeAdjustmentSoundCallback(
  211. const base::RepeatingClosure& closure);
  212. // Called by Ash to run the closure from SetVolumeAdjustmentSoundCallback.
  213. static void PlayVolumeAdjustmentSound();
  214. // Activates the target associated with the specified accelerator.
  215. // First, AcceleratorPressed handler of the most recently registered target
  216. // is called, and if that handler processes the event (i.e. returns true),
  217. // this method immediately returns. If not, we do the same thing on the next
  218. // target, and so on.
  219. // Returns true if an accelerator was activated.
  220. virtual bool Process(const ui::Accelerator& accelerator) = 0;
  221. // Returns true if the |accelerator| is deprecated. Deprecated accelerators
  222. // can be consumed by web contents if needed.
  223. virtual bool IsDeprecated(const ui::Accelerator& accelerator) const = 0;
  224. // Performs the specified action if it is enabled. Returns whether the action
  225. // was performed successfully.
  226. virtual bool PerformActionIfEnabled(AcceleratorAction action,
  227. const ui::Accelerator& accelerator) = 0;
  228. // Called by Chrome when a menu item accelerator has been triggered. Returns
  229. // true if the menu should close.
  230. virtual bool OnMenuAccelerator(const ui::Accelerator& accelerator) = 0;
  231. // Returns true if the |accelerator| is registered.
  232. virtual bool IsRegistered(const ui::Accelerator& accelerator) const = 0;
  233. // Returns the accelerator histotry.
  234. virtual AcceleratorHistory* GetAcceleratorHistory() = 0;
  235. // Returns true if the provided accelerator matches the provided accelerator
  236. // action.
  237. virtual bool DoesAcceleratorMatchAction(const ui::Accelerator& accelerator,
  238. const AcceleratorAction action) = 0;
  239. void AddObserver(Observer* observer);
  240. void RemoveObserver(Observer* observer);
  241. protected:
  242. AcceleratorController();
  243. virtual ~AcceleratorController();
  244. void NotifyActionPerformed(AcceleratorAction action);
  245. base::ObserverList<Observer, /*check_empty=*/true> observers_;
  246. };
  247. // The public facing interface for AcceleratorHistory, which is implemented in
  248. // ash.
  249. class ASH_PUBLIC_EXPORT AcceleratorHistory {
  250. public:
  251. // Stores |accelerator| if it's different than the currently stored one.
  252. virtual void StoreCurrentAccelerator(const ui::Accelerator& accelerator) = 0;
  253. };
  254. } // namespace ash
  255. #endif // ASH_PUBLIC_CPP_ACCELERATORS_H_