Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: ash/common/accelerators/accelerator_controller.h

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_COMMON_ACCELERATORS_ACCELERATOR_CONTROLLER_H_
6 #define ASH_COMMON_ACCELERATORS_ACCELERATOR_CONTROLLER_H_
7
8 #include <stddef.h>
9
10 #include <map>
11 #include <memory>
12 #include <set>
13 #include <vector>
14
15 #include "ash/ash_export.h"
16 #include "ash/common/accelerators/accelerator_table.h"
17 #include "ash/common/accelerators/exit_warning_handler.h"
18 #include "ash/public/interfaces/accelerator_controller.mojom.h"
19 #include "base/compiler_specific.h"
20 #include "base/gtest_prod_util.h"
21 #include "base/macros.h"
22 #include "mojo/public/cpp/bindings/binding_set.h"
23 #include "ui/base/accelerators/accelerator.h"
24 #include "ui/base/accelerators/accelerator_history.h"
25
26 namespace ui {
27 class AcceleratorManager;
28 class AcceleratorManagerDelegate;
29 }
30
31 namespace ash {
32
33 struct AcceleratorData;
34 class AcceleratorControllerDelegate;
35 class ExitWarningHandler;
36 class ImeControlDelegate;
37
38 // AcceleratorController provides functions for registering or unregistering
39 // global keyboard accelerators, which are handled earlier than any windows. It
40 // also implements several handlers as an accelerator target.
41 class ASH_EXPORT AcceleratorController
42 : public ui::AcceleratorTarget,
43 NON_EXPORTED_BASE(public mojom::AcceleratorController) {
44 public:
45 AcceleratorController(AcceleratorControllerDelegate* delegate,
46 ui::AcceleratorManagerDelegate* manager_delegate);
47 ~AcceleratorController() override;
48
49 // A list of possible ways in which an accelerator should be restricted before
50 // processing. Any target registered with this controller should respect
51 // restrictions by calling |GetCurrentAcceleratorRestriction| during
52 // processing.
53 enum AcceleratorProcessingRestriction {
54 // Process the accelerator normally.
55 RESTRICTION_NONE,
56
57 // Don't process the accelerator.
58 RESTRICTION_PREVENT_PROCESSING,
59
60 // Don't process the accelerator and prevent propagation to other targets.
61 RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
62 };
63
64 // Registers global keyboard accelerators for the specified target. If
65 // multiple targets are registered for any given accelerator, a target
66 // registered later has higher priority.
67 void Register(const std::vector<ui::Accelerator>& accelerators,
68 ui::AcceleratorTarget* target);
69
70 // Unregisters the specified keyboard accelerator for the specified target.
71 void Unregister(const ui::Accelerator& accelerator,
72 ui::AcceleratorTarget* target);
73
74 // Unregisters all keyboard accelerators for the specified target.
75 void UnregisterAll(ui::AcceleratorTarget* target);
76
77 // Activates the target associated with the specified accelerator.
78 // First, AcceleratorPressed handler of the most recently registered target
79 // is called, and if that handler processes the event (i.e. returns true),
80 // this method immediately returns. If not, we do the same thing on the next
81 // target, and so on.
82 // Returns true if an accelerator was activated.
83 bool Process(const ui::Accelerator& accelerator);
84
85 // Returns true if the |accelerator| is registered.
86 bool IsRegistered(const ui::Accelerator& accelerator) const;
87
88 // Returns true if the |accelerator| is preferred. A preferred accelerator
89 // is handled before being passed to an window/web contents, unless
90 // the window is in fullscreen state.
91 bool IsPreferred(const ui::Accelerator& accelerator) const;
92
93 // Returns true if the |accelerator| is reserved. A reserved accelerator
94 // is always handled and will never be passed to an window/web contents.
95 bool IsReserved(const ui::Accelerator& accelerator) const;
96
97 // Returns true if the |accelerator| is deprecated. Deprecated accelerators
98 // can be consumed by web contents if needed.
99 bool IsDeprecated(const ui::Accelerator& accelerator) const;
100
101 // Performs the specified action if it is enabled. Returns whether the action
102 // was performed successfully.
103 bool PerformActionIfEnabled(AcceleratorAction action);
104
105 // Returns the restriction for the current context.
106 AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction();
107
108 void SetImeControlDelegate(
109 std::unique_ptr<ImeControlDelegate> ime_control_delegate);
110
111 // Provides access to the ExitWarningHandler for testing.
112 ExitWarningHandler* GetExitWarningHandlerForTest() {
113 return &exit_warning_handler_;
114 }
115
116 // Returns true if the menu should close in order to perform the accelerator.
117 bool ShouldCloseMenuAndRepostAccelerator(
118 const ui::Accelerator& accelerator) const;
119
120 ui::AcceleratorHistory* accelerator_history() {
121 return accelerator_history_.get();
122 }
123
124 // Overridden from ui::AcceleratorTarget:
125 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
126 bool CanHandleAccelerators() const override;
127
128 // Binds the mojom::AcceleratorController interface to this object.
129 void BindRequest(mojom::AcceleratorControllerRequest request);
130
131 // mojom::AcceleratorController:
132 void SetVolumeController(mojom::VolumeControllerPtr controller) override;
133
134 private:
135 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators);
136 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest,
137 DontRepeatToggleFullscreen);
138 FRIEND_TEST_ALL_PREFIXES(DeprecatedAcceleratorTester,
139 TestDeprecatedAcceleratorsBehavior);
140
141 // Initializes the accelerators this class handles as a target.
142 void Init();
143
144 // Registers the specified accelerators.
145 void RegisterAccelerators(const AcceleratorData accelerators[],
146 size_t accelerators_length);
147
148 // Registers the deprecated accelerators and their replacing new ones.
149 void RegisterDeprecatedAccelerators();
150
151 // Returns whether |action| can be performed. The |accelerator| may provide
152 // additional data the action needs.
153 bool CanPerformAction(AcceleratorAction action,
154 const ui::Accelerator& accelerator);
155
156 // Performs the specified action. The |accelerator| may provide additional
157 // data the action needs.
158 void PerformAction(AcceleratorAction action,
159 const ui::Accelerator& accelerator);
160
161 // Returns whether performing |action| should consume the key event.
162 bool ShouldActionConsumeKeyEvent(AcceleratorAction action);
163
164 // Get the accelerator restriction for the given action. Supply an |action|
165 // of -1 to get restrictions that apply for the current context.
166 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction(
167 int action);
168
169 // If |accelerator| is a deprecated accelerator, it performs the appropriate
170 // deprecated accelerator pre-handling.
171 // Returns PROCEED if the accelerator's action should be performed (i.e. if
172 // |accelerator| is not a deprecated accelerator, or it's an enabled
173 // deprecated accelerator), and STOP otherwise (if the accelerator is a
174 // disabled deprecated accelerator).
175 enum class AcceleratorProcessingStatus { PROCEED, STOP };
176 AcceleratorProcessingStatus MaybeDeprecatedAcceleratorPressed(
177 AcceleratorAction action,
178 const ui::Accelerator& accelerator) const;
179
180 AcceleratorControllerDelegate* delegate_;
181
182 std::unique_ptr<ui::AcceleratorManager> accelerator_manager_;
183
184 // A tracker for the current and previous accelerators.
185 std::unique_ptr<ui::AcceleratorHistory> accelerator_history_;
186
187 std::unique_ptr<ImeControlDelegate> ime_control_delegate_;
188
189 // Handles the exit accelerator which requires a double press to exit and
190 // shows a popup with an explanation.
191 ExitWarningHandler exit_warning_handler_;
192
193 // A map from accelerators to the AcceleratorAction values, which are used in
194 // the implementation.
195 std::map<ui::Accelerator, AcceleratorAction> accelerators_;
196
197 std::map<AcceleratorAction, const DeprecatedAcceleratorData*>
198 actions_with_deprecations_;
199 std::set<ui::Accelerator> deprecated_accelerators_;
200
201 // Bindings for the mojom::AcceleratorController interface.
202 mojo::BindingSet<mojom::AcceleratorController> bindings_;
203
204 // Volume controller interface in chrome browser. May be null in tests. Exists
205 // because chrome owns the CrasAudioHandler dbus communication.
206 mojom::VolumeControllerPtr volume_controller_;
207
208 // Actions allowed when the user is not signed in.
209 std::set<int> actions_allowed_at_login_screen_;
210 // Actions allowed when the screen is locked.
211 std::set<int> actions_allowed_at_lock_screen_;
212 // Actions allowed when a modal window is up.
213 std::set<int> actions_allowed_at_modal_window_;
214 // Preferred actions. See accelerator_table.h for details.
215 std::set<int> preferred_actions_;
216 // Reserved actions. See accelerator_table.h for details.
217 std::set<int> reserved_actions_;
218 // Actions which will be repeated while holding the accelerator key.
219 std::set<int> repeatable_actions_;
220 // Actions allowed in app mode.
221 std::set<int> actions_allowed_in_app_mode_;
222 // Actions allowed in pinned mode.
223 std::set<int> actions_allowed_in_pinned_mode_;
224 // Actions disallowed if there are no windows.
225 std::set<int> actions_needing_window_;
226 // Actions that can be performed without closing the menu (if one is present).
227 std::set<int> actions_keeping_menu_open_;
228
229 DISALLOW_COPY_AND_ASSIGN(AcceleratorController);
230 };
231
232 } // namespace ash
233
234 #endif // ASH_COMMON_ACCELERATORS_ACCELERATOR_CONTROLLER_H_
OLDNEW
« no previous file with comments | « ash/common/accelerators/accelerator_commands.cc ('k') | ash/common/accelerators/accelerator_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698