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