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_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 5 #ifndef ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
6 #define ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 6 #define ASH_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/accelerators/accelerator_table.h" | 14 #include "ash/accelerators/accelerator_table.h" |
15 #include "ash/accelerators/exit_warning_handler.h" | 15 #include "ash/accelerators/exit_warning_handler.h" |
16 #include "ash/ash_export.h" | 16 #include "ash/ash_export.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "ui/base/accelerators/accelerator.h" | 20 #include "ui/base/accelerators/accelerator.h" |
21 #include "ui/base/accelerators/accelerator_history.h" | 21 #include "ui/base/accelerators/accelerator_history.h" |
22 | 22 |
23 namespace ui { | 23 namespace ui { |
24 class AcceleratorManager; | 24 class AcceleratorManager; |
25 } | 25 } |
26 | 26 |
27 namespace ash { | 27 namespace ash { |
28 | 28 |
29 struct AcceleratorData; | 29 struct AcceleratorData; |
30 class BrightnessControlDelegate; | |
31 class ExitWarningHandler; | 30 class ExitWarningHandler; |
32 class ImeControlDelegate; | 31 class ImeControlDelegate; |
33 class KeyboardBrightnessControlDelegate; | |
34 class ScreenshotDelegate; | 32 class ScreenshotDelegate; |
35 class VolumeControlDelegate; | 33 class VolumeControlDelegate; |
36 | 34 |
37 // AcceleratorController provides functions for registering or unregistering | 35 // AcceleratorController provides functions for registering or unregistering |
38 // global keyboard accelerators, which are handled earlier than any windows. It | 36 // global keyboard accelerators, which are handled earlier than any windows. It |
39 // also implements several handlers as an accelerator target. | 37 // also implements several handlers as an accelerator target. |
40 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { | 38 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { |
41 public: | 39 public: |
42 AcceleratorController(); | 40 AcceleratorController(); |
43 ~AcceleratorController() override; | 41 ~AcceleratorController() override; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // can be consumed by web contents if needed. | 92 // can be consumed by web contents if needed. |
95 bool IsDeprecated(const ui::Accelerator& accelerator) const; | 93 bool IsDeprecated(const ui::Accelerator& accelerator) const; |
96 | 94 |
97 // Performs the specified action if it is enabled. Returns whether the action | 95 // Performs the specified action if it is enabled. Returns whether the action |
98 // was performed successfully. | 96 // was performed successfully. |
99 bool PerformActionIfEnabled(AcceleratorAction action); | 97 bool PerformActionIfEnabled(AcceleratorAction action); |
100 | 98 |
101 // Returns the restriction for the current context. | 99 // Returns the restriction for the current context. |
102 AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction(); | 100 AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction(); |
103 | 101 |
104 void SetBrightnessControlDelegate( | |
105 std::unique_ptr<BrightnessControlDelegate> brightness_control_delegate); | |
106 void SetImeControlDelegate( | 102 void SetImeControlDelegate( |
107 std::unique_ptr<ImeControlDelegate> ime_control_delegate); | 103 std::unique_ptr<ImeControlDelegate> ime_control_delegate); |
108 void SetScreenshotDelegate( | 104 void SetScreenshotDelegate( |
109 std::unique_ptr<ScreenshotDelegate> screenshot_delegate); | 105 std::unique_ptr<ScreenshotDelegate> screenshot_delegate); |
110 BrightnessControlDelegate* brightness_control_delegate() const { | |
111 return brightness_control_delegate_.get(); | |
112 } | |
113 ScreenshotDelegate* screenshot_delegate() { | 106 ScreenshotDelegate* screenshot_delegate() { |
114 return screenshot_delegate_.get(); | 107 return screenshot_delegate_.get(); |
115 } | 108 } |
116 | 109 |
117 // Provides access to the ExitWarningHandler for testing. | 110 // Provides access to the ExitWarningHandler for testing. |
118 ExitWarningHandler* GetExitWarningHandlerForTest() { | 111 ExitWarningHandler* GetExitWarningHandlerForTest() { |
119 return &exit_warning_handler_; | 112 return &exit_warning_handler_; |
120 } | 113 } |
121 | 114 |
122 // Returns true if the menu should close in order to perform the accelerator. | 115 // Returns true if the menu should close in order to perform the accelerator. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 const ui::Accelerator& accelerator); | 152 const ui::Accelerator& accelerator); |
160 | 153 |
161 // Returns whether performing |action| should consume the key event. | 154 // Returns whether performing |action| should consume the key event. |
162 bool ShouldActionConsumeKeyEvent(AcceleratorAction action); | 155 bool ShouldActionConsumeKeyEvent(AcceleratorAction action); |
163 | 156 |
164 // Get the accelerator restriction for the given action. Supply an |action| | 157 // Get the accelerator restriction for the given action. Supply an |action| |
165 // of -1 to get restrictions that apply for the current context. | 158 // of -1 to get restrictions that apply for the current context. |
166 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction( | 159 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction( |
167 int action); | 160 int action); |
168 | 161 |
169 void SetKeyboardBrightnessControlDelegate( | |
170 std::unique_ptr<KeyboardBrightnessControlDelegate> | |
171 keyboard_brightness_control_delegate); | |
172 | |
173 std::unique_ptr<ui::AcceleratorManager> accelerator_manager_; | 162 std::unique_ptr<ui::AcceleratorManager> accelerator_manager_; |
174 | 163 |
175 // A tracker for the current and previous accelerators. | 164 // A tracker for the current and previous accelerators. |
176 std::unique_ptr<ui::AcceleratorHistory> accelerator_history_; | 165 std::unique_ptr<ui::AcceleratorHistory> accelerator_history_; |
177 | 166 |
178 // TODO(derat): BrightnessControlDelegate is also used by the system tray; | |
179 // move it outside of this class. | |
180 std::unique_ptr<BrightnessControlDelegate> brightness_control_delegate_; | |
181 std::unique_ptr<ImeControlDelegate> ime_control_delegate_; | 167 std::unique_ptr<ImeControlDelegate> ime_control_delegate_; |
182 std::unique_ptr<KeyboardBrightnessControlDelegate> | |
183 keyboard_brightness_control_delegate_; | |
184 std::unique_ptr<ScreenshotDelegate> screenshot_delegate_; | 168 std::unique_ptr<ScreenshotDelegate> screenshot_delegate_; |
185 | 169 |
186 // Handles the exit accelerator which requires a double press to exit and | 170 // Handles the exit accelerator which requires a double press to exit and |
187 // shows a popup with an explanation. | 171 // shows a popup with an explanation. |
188 ExitWarningHandler exit_warning_handler_; | 172 ExitWarningHandler exit_warning_handler_; |
189 | 173 |
190 // A map from accelerators to the AcceleratorAction values, which are used in | 174 // A map from accelerators to the AcceleratorAction values, which are used in |
191 // the implementation. | 175 // the implementation. |
192 std::map<ui::Accelerator, AcceleratorAction> accelerators_; | 176 std::map<ui::Accelerator, AcceleratorAction> accelerators_; |
193 | 177 |
(...skipping 21 matching lines...) Expand all Loading... |
215 std::set<int> actions_needing_window_; | 199 std::set<int> actions_needing_window_; |
216 // Actions that can be performed without closing the menu (if one is present). | 200 // Actions that can be performed without closing the menu (if one is present). |
217 std::set<int> actions_keeping_menu_open_; | 201 std::set<int> actions_keeping_menu_open_; |
218 | 202 |
219 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); | 203 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); |
220 }; | 204 }; |
221 | 205 |
222 } // namespace ash | 206 } // namespace ash |
223 | 207 |
224 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 208 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
OLD | NEW |