OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_COMMON_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 5 #ifndef ASH_COMMON_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
6 #define ASH_COMMON_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 6 #define ASH_COMMON_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "ash/ash_export.h" | 14 #include "ash/ash_export.h" |
15 #include "ash/common/accelerators/accelerator_table.h" | 15 #include "ash/common/accelerators/accelerator_table.h" |
16 #include "ash/common/accelerators/exit_warning_handler.h" | 16 #include "ash/common/accelerators/exit_warning_handler.h" |
17 #include "ash/public/interfaces/volume.mojom.h" | 17 #include "ash/public/interfaces/volume.mojom.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 #include "mojo/public/cpp/bindings/binding_set.h" | |
21 #include "ui/base/accelerators/accelerator.h" | 22 #include "ui/base/accelerators/accelerator.h" |
22 #include "ui/base/accelerators/accelerator_history.h" | 23 #include "ui/base/accelerators/accelerator_history.h" |
23 | 24 |
24 namespace ui { | 25 namespace ui { |
25 class AcceleratorManager; | 26 class AcceleratorManager; |
26 class AcceleratorManagerDelegate; | 27 class AcceleratorManagerDelegate; |
27 } | 28 } |
28 | 29 |
29 namespace ash { | 30 namespace ash { |
30 | 31 |
31 struct AcceleratorData; | 32 struct AcceleratorData; |
32 class AcceleratorControllerDelegate; | 33 class AcceleratorControllerDelegate; |
33 class ExitWarningHandler; | 34 class ExitWarningHandler; |
34 class ImeControlDelegate; | 35 class ImeControlDelegate; |
35 | 36 |
36 // AcceleratorController provides functions for registering or unregistering | 37 // AcceleratorController provides functions for registering or unregistering |
37 // global keyboard accelerators, which are handled earlier than any windows. It | 38 // global keyboard accelerators, which are handled earlier than any windows. It |
38 // also implements several handlers as an accelerator target. | 39 // also implements several handlers as an accelerator target. Implements |
39 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { | 40 // mojom::Volume so that Chrome can set itself as the mojom::VolumeClient, |
41 // which is only used by accelerator keys. | |
42 class ASH_EXPORT AcceleratorController | |
43 : public ui::AcceleratorTarget, | |
44 NON_EXPORTED_BASE(public mojom::Volume) { | |
msw
2016/12/03 00:26:43
Inheriting a Volume-specific interface here is som
James Cook
2016/12/06 19:23:57
Done.
| |
40 public: | 45 public: |
41 AcceleratorController(AcceleratorControllerDelegate* delegate, | 46 AcceleratorController(AcceleratorControllerDelegate* delegate, |
42 ui::AcceleratorManagerDelegate* manager_delegate); | 47 ui::AcceleratorManagerDelegate* manager_delegate); |
43 ~AcceleratorController() override; | 48 ~AcceleratorController() override; |
44 | 49 |
45 // A list of possible ways in which an accelerator should be restricted before | 50 // A list of possible ways in which an accelerator should be restricted before |
46 // processing. Any target registered with this controller should respect | 51 // processing. Any target registered with this controller should respect |
47 // restrictions by calling |GetCurrentAcceleratorRestriction| during | 52 // restrictions by calling |GetCurrentAcceleratorRestriction| during |
48 // processing. | 53 // processing. |
49 enum AcceleratorProcessingRestriction { | 54 enum AcceleratorProcessingRestriction { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 const ui::Accelerator& accelerator) const; | 119 const ui::Accelerator& accelerator) const; |
115 | 120 |
116 ui::AcceleratorHistory* accelerator_history() { | 121 ui::AcceleratorHistory* accelerator_history() { |
117 return accelerator_history_.get(); | 122 return accelerator_history_.get(); |
118 } | 123 } |
119 | 124 |
120 // Overridden from ui::AcceleratorTarget: | 125 // Overridden from ui::AcceleratorTarget: |
121 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 126 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
122 bool CanHandleAccelerators() const override; | 127 bool CanHandleAccelerators() const override; |
123 | 128 |
129 // Binds the mojom::Volume interface to this object. | |
130 void BindRequest(mojom::VolumeRequest request); | |
131 | |
132 // mojom::Volume: | |
133 void SetClient(mojom::VolumeClientPtr client) override; | |
134 | |
124 private: | 135 private: |
125 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators); | 136 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators); |
126 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, | 137 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, |
127 DontRepeatToggleFullscreen); | 138 DontRepeatToggleFullscreen); |
128 FRIEND_TEST_ALL_PREFIXES(DeprecatedAcceleratorTester, | 139 FRIEND_TEST_ALL_PREFIXES(DeprecatedAcceleratorTester, |
129 TestDeprecatedAcceleratorsBehavior); | 140 TestDeprecatedAcceleratorsBehavior); |
130 | 141 |
131 // Initializes the accelerators this class handles as a target. | 142 // Initializes the accelerators this class handles as a target. |
132 void Init(); | 143 void Init(); |
133 | 144 |
(...skipping 15 matching lines...) Expand all Loading... | |
149 const ui::Accelerator& accelerator); | 160 const ui::Accelerator& accelerator); |
150 | 161 |
151 // Returns whether performing |action| should consume the key event. | 162 // Returns whether performing |action| should consume the key event. |
152 bool ShouldActionConsumeKeyEvent(AcceleratorAction action); | 163 bool ShouldActionConsumeKeyEvent(AcceleratorAction action); |
153 | 164 |
154 // Get the accelerator restriction for the given action. Supply an |action| | 165 // Get the accelerator restriction for the given action. Supply an |action| |
155 // of -1 to get restrictions that apply for the current context. | 166 // of -1 to get restrictions that apply for the current context. |
156 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction( | 167 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction( |
157 int action); | 168 int action); |
158 | 169 |
159 // Returns the volume controller interface raw pointer, may be null in tests. | |
160 mojom::VolumeController* GetVolumeController(); | |
161 void OnVolumeControllerConnectionError(); | |
162 | |
163 AcceleratorControllerDelegate* delegate_; | 170 AcceleratorControllerDelegate* delegate_; |
164 | 171 |
165 std::unique_ptr<ui::AcceleratorManager> accelerator_manager_; | 172 std::unique_ptr<ui::AcceleratorManager> accelerator_manager_; |
166 | 173 |
167 // A tracker for the current and previous accelerators. | 174 // A tracker for the current and previous accelerators. |
168 std::unique_ptr<ui::AcceleratorHistory> accelerator_history_; | 175 std::unique_ptr<ui::AcceleratorHistory> accelerator_history_; |
169 | 176 |
170 std::unique_ptr<ImeControlDelegate> ime_control_delegate_; | 177 std::unique_ptr<ImeControlDelegate> ime_control_delegate_; |
171 | 178 |
172 // Handles the exit accelerator which requires a double press to exit and | 179 // Handles the exit accelerator which requires a double press to exit and |
173 // shows a popup with an explanation. | 180 // shows a popup with an explanation. |
174 ExitWarningHandler exit_warning_handler_; | 181 ExitWarningHandler exit_warning_handler_; |
175 | 182 |
176 // A map from accelerators to the AcceleratorAction values, which are used in | 183 // A map from accelerators to the AcceleratorAction values, which are used in |
177 // the implementation. | 184 // the implementation. |
178 std::map<ui::Accelerator, AcceleratorAction> accelerators_; | 185 std::map<ui::Accelerator, AcceleratorAction> accelerators_; |
179 | 186 |
180 std::map<AcceleratorAction, const DeprecatedAcceleratorData*> | 187 std::map<AcceleratorAction, const DeprecatedAcceleratorData*> |
181 actions_with_deprecations_; | 188 actions_with_deprecations_; |
182 std::set<ui::Accelerator> deprecated_accelerators_; | 189 std::set<ui::Accelerator> deprecated_accelerators_; |
183 | 190 |
184 // The cached volume controller interface pointer. | 191 // Bindings for the mojom::Volume interface. |
185 mojom::VolumeControllerPtr volume_controller_; | 192 mojo::BindingSet<mojom::Volume> bindings_; |
193 | |
194 // Client interface in chrome browser. May be null in tests. | |
msw
2016/12/05 20:15:09
optional nit: Mention here that it's used for [Cra
James Cook
2016/12/06 19:23:57
Done.
| |
195 mojom::VolumeClientPtr volume_client_; | |
186 | 196 |
187 // Actions allowed when the user is not signed in. | 197 // Actions allowed when the user is not signed in. |
188 std::set<int> actions_allowed_at_login_screen_; | 198 std::set<int> actions_allowed_at_login_screen_; |
189 // Actions allowed when the screen is locked. | 199 // Actions allowed when the screen is locked. |
190 std::set<int> actions_allowed_at_lock_screen_; | 200 std::set<int> actions_allowed_at_lock_screen_; |
191 // Actions allowed when a modal window is up. | 201 // Actions allowed when a modal window is up. |
192 std::set<int> actions_allowed_at_modal_window_; | 202 std::set<int> actions_allowed_at_modal_window_; |
193 // Preferred actions. See accelerator_table.h for details. | 203 // Preferred actions. See accelerator_table.h for details. |
194 std::set<int> preferred_actions_; | 204 std::set<int> preferred_actions_; |
195 // Reserved actions. See accelerator_table.h for details. | 205 // Reserved actions. See accelerator_table.h for details. |
196 std::set<int> reserved_actions_; | 206 std::set<int> reserved_actions_; |
197 // Actions which will be repeated while holding the accelerator key. | 207 // Actions which will be repeated while holding the accelerator key. |
198 std::set<int> repeatable_actions_; | 208 std::set<int> repeatable_actions_; |
199 // Actions allowed in app mode. | 209 // Actions allowed in app mode. |
200 std::set<int> actions_allowed_in_app_mode_; | 210 std::set<int> actions_allowed_in_app_mode_; |
201 // Actions allowed in pinned mode. | 211 // Actions allowed in pinned mode. |
202 std::set<int> actions_allowed_in_pinned_mode_; | 212 std::set<int> actions_allowed_in_pinned_mode_; |
203 // Actions disallowed if there are no windows. | 213 // Actions disallowed if there are no windows. |
204 std::set<int> actions_needing_window_; | 214 std::set<int> actions_needing_window_; |
205 // Actions that can be performed without closing the menu (if one is present). | 215 // Actions that can be performed without closing the menu (if one is present). |
206 std::set<int> actions_keeping_menu_open_; | 216 std::set<int> actions_keeping_menu_open_; |
207 | 217 |
208 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); | 218 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); |
209 }; | 219 }; |
210 | 220 |
211 } // namespace ash | 221 } // namespace ash |
212 | 222 |
213 #endif // ASH_COMMON_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 223 #endif // ASH_COMMON_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
OLD | NEW |