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 #ifndef ASH_ACCELERATORS_ACCELERATOR_TABLE_H_
6 #define ASH_ACCELERATORS_ACCELERATOR_TABLE_H_
7 
8 #include <stddef.h>
9 
10 #include "ash/ash_export.h"
11 #include "ash/public/cpp/accelerators.h"
12 #include "ui/events/event_constants.h"
13 #include "ui/events/keycodes/keyboard_codes.h"
14 
15 namespace ash {
16 
17 // The complete list of Ash accelerators is in ash/public/cpp/accelerators.h.
18 // This file mainly keeps track of special categories of accelerator.
19 //
20 // There are five classes of accelerators in Ash:
21 //
22 // Ash (OS) reserved:
23 // * Neither packaged apps nor web pages can cancel.
24 // * For example, power button.
25 // * See kReservedActions below.
26 //
27 // Ash (OS) preferred:
28 // * Fullscreen window can consume, but normal window can't.
29 // * For example, Alt-Tab window cycling.
30 // * See kPreferredActions below.
31 //
32 // Chrome OS system keys:
33 // * For legacy reasons, v1 apps can process and cancel. Otherwise handled
34 //   directly by Ash.
35 // * Brightness, volume control, etc.
36 // * See IsSystemKey() in ash/accelerators/accelerator_filter.cc.
37 //
38 // Browser reserved:
39 // * Packaged apps can cancel but web pages cannot.
40 // * For example, browser back and forward from first-row function keys.
41 // * See IsReservedCommandOrKey() in
42 //   chrome/browser/ui/browser_command_controller.cc.
43 //
44 // Browser non-reserved:
45 // * Both packaged apps and web pages can cancel.
46 // * For example, selecting tabs by number with Ctrl-1 to Ctrl-9.
47 // * See kAcceleratorMap in chrome/browser/ui/views/accelerator_table.cc.
48 //
49 // In particular, there is not an accelerator processing pass for Ash after
50 // the browser gets the accelerator.  See crbug.com/285308 for details.
51 //
52 // There are also various restrictions on accelerators allowed at the login
53 // screen, when running in "forced app mode" (like a kiosk), etc. See the
54 // various kActionsAllowed* below.
55 
56 // Gathers the needed data to handle deprecated accelerators.
57 struct DeprecatedAcceleratorData {
58   // The action that has deprecated accelerators.
59   AcceleratorAction action;
60 
61   // The name of the UMA histogram that will be used to measure the deprecated
62   // v.s. new accelerator usage.
63   const char* uma_histogram_name;
64 
65   // The ID of the localized notification message to show to users informing
66   // them about the deprecation.
67   int notification_message_id;
68 
69   // The ID of the localized old deprecated shortcut key.
70   int old_shortcut_id;
71 
72   // The ID of the localized new shortcut key.
73   int new_shortcut_id;
74 
75   // Specifies whether the deprecated accelerator is still enabled to do its
76   // associated action.
77   bool deprecated_enabled;
78 };
79 
80 // This will be used for the UMA stats to measure the how many users are using
81 // the old v.s. new accelerators.
82 enum DeprecatedAcceleratorUsage {
83   DEPRECATED_USED = 0,     // The deprecated accelerator is used.
84   NEW_USED,                // The new accelerator is used.
85   DEPRECATED_USAGE_COUNT,  // Maximum value of this enum for histogram use.
86 };
87 
88 // The list of the deprecated accelerators.
89 ASH_EXPORT extern const AcceleratorData kDeprecatedAccelerators[];
90 ASH_EXPORT extern const size_t kDeprecatedAcceleratorsLength;
91 
92 // The list of the actions with deprecated accelerators and the needed data to
93 // handle them.
94 ASH_EXPORT extern const DeprecatedAcceleratorData kDeprecatedAcceleratorsData[];
95 ASH_EXPORT extern const size_t kDeprecatedAcceleratorsDataLength;
96 
97 // Debug accelerators. Debug accelerators are only enabled when the "Debugging
98 // keyboard shortcuts" flag (--ash-debug-shortcuts) is enabled. Debug actions
99 // are always run (similar to reserved actions). Debug accelerators can be
100 // enabled in about:flags.
101 ASH_EXPORT extern const AcceleratorData kDebugAcceleratorData[];
102 ASH_EXPORT extern const size_t kDebugAcceleratorDataLength;
103 
104 // Developer accelerators that are enabled only with the command-line switch
105 // --ash-dev-shortcuts. They are always run similar to reserved actions.
106 ASH_EXPORT extern const AcceleratorData kDeveloperAcceleratorData[];
107 ASH_EXPORT extern const size_t kDeveloperAcceleratorDataLength;
108 
109 // Actions that should be handled very early in Ash unless the current target
110 // window is full-screen.
111 ASH_EXPORT extern const AcceleratorAction kPreferredActions[];
112 ASH_EXPORT extern const size_t kPreferredActionsLength;
113 
114 // Actions that are always handled in Ash.
115 ASH_EXPORT extern const AcceleratorAction kReservedActions[];
116 ASH_EXPORT extern const size_t kReservedActionsLength;
117 
118 // Actions allowed while user is not signed in or screen is locked.
119 ASH_EXPORT extern const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[];
120 ASH_EXPORT extern const size_t kActionsAllowedAtLoginOrLockScreenLength;
121 
122 // Actions allowed while screen is locked (in addition to
123 // kActionsAllowedAtLoginOrLockScreen).
124 ASH_EXPORT extern const AcceleratorAction kActionsAllowedAtLockScreen[];
125 ASH_EXPORT extern const size_t kActionsAllowedAtLockScreenLength;
126 
127 // Actions allowed while power menu is opened.
128 ASH_EXPORT extern const AcceleratorAction kActionsAllowedAtPowerMenu[];
129 ASH_EXPORT extern const size_t kActionsAllowedAtPowerMenuLength;
130 
131 // Actions allowed while a modal window is up.
132 ASH_EXPORT extern const AcceleratorAction kActionsAllowedAtModalWindow[];
133 ASH_EXPORT extern const size_t kActionsAllowedAtModalWindowLength;
134 
135 // Actions which may be repeated by holding an accelerator key.
136 ASH_EXPORT extern const AcceleratorAction kRepeatableActions[];
137 ASH_EXPORT extern const size_t kRepeatableActionsLength;
138 
139 // Actions allowed in app mode or pinned mode.
140 ASH_EXPORT extern const AcceleratorAction
141     kActionsAllowedInAppModeOrPinnedMode[];
142 ASH_EXPORT extern const size_t kActionsAllowedInAppModeOrPinnedModeLength;
143 
144 // Actions that can be performed in pinned mode.
145 // In pinned mode, the action listed in this or "in app mode or pinned mode"
146 // table can be performed.
147 ASH_EXPORT extern const AcceleratorAction kActionsAllowedInPinnedMode[];
148 ASH_EXPORT extern const size_t kActionsAllowedInPinnedModeLength;
149 
150 // Actions that can be performed in app mode.
151 // In app mode, the action listed in this or "in app mode or pinned mode" table
152 // can be performed.
153 ASH_EXPORT extern const AcceleratorAction kActionsAllowedInAppMode[];
154 ASH_EXPORT extern const size_t kActionsAllowedInAppModeLength;
155 
156 // Actions that require at least 1 window.
157 ASH_EXPORT extern const AcceleratorAction kActionsNeedingWindow[];
158 ASH_EXPORT extern const size_t kActionsNeedingWindowLength;
159 
160 // Actions that can be performed while keeping the menu open.
161 ASH_EXPORT extern const AcceleratorAction kActionsKeepingMenuOpen[];
162 ASH_EXPORT extern const size_t kActionsKeepingMenuOpenLength;
163 
164 }  // namespace ash
165 
166 #endif  // ASH_ACCELERATORS_ACCELERATOR_TABLE_H_
167