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

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

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

Powered by Google App Engine
This is Rietveld 408576698