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 <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 namespace ash { | 23 namespace ash { |
24 | 24 |
25 struct AcceleratorData; | 25 struct AcceleratorData; |
26 class BrightnessControlDelegate; | 26 class BrightnessControlDelegate; |
27 class ExitWarningHandler; | 27 class ExitWarningHandler; |
28 class ImeControlDelegate; | 28 class ImeControlDelegate; |
29 class KeyboardBrightnessControlDelegate; | 29 class KeyboardBrightnessControlDelegate; |
30 class ScreenshotDelegate; | 30 class ScreenshotDelegate; |
31 class VolumeControlDelegate; | 31 class VolumeControlDelegate; |
32 | 32 |
33 // Stores information about accelerator context, eg. previous accelerator | |
34 // or if the current accelerator is repeated or not. | |
35 class ASH_EXPORT AcceleratorControllerContext { | |
36 public: | |
37 AcceleratorControllerContext(); | |
38 ~AcceleratorControllerContext() {} | |
39 | |
40 // Updates context - determines if the accelerator is repeated, as well as | |
41 // event type of the previous accelerator. | |
42 void UpdateContext(const ui::Accelerator& accelerator); | |
43 | |
44 const ui::Accelerator& previous_accelerator() const { | |
45 return previous_accelerator_; | |
46 } | |
47 bool repeated() const { | |
48 return current_accelerator_ == previous_accelerator_ && | |
49 current_accelerator_.type() != ui::ET_UNKNOWN; | |
50 } | |
51 | |
52 private: | |
53 ui::Accelerator current_accelerator_; | |
54 // Used for NEXT_IME and DISABLE_CAPS_LOCK accelerator actions. | |
55 ui::Accelerator previous_accelerator_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerContext); | |
58 }; | |
59 | |
60 // AcceleratorController provides functions for registering or unregistering | 33 // AcceleratorController provides functions for registering or unregistering |
61 // global keyboard accelerators, which are handled earlier than any windows. It | 34 // global keyboard accelerators, which are handled earlier than any windows. It |
62 // also implements several handlers as an accelerator target. | 35 // also implements several handlers as an accelerator target. |
63 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { | 36 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { |
64 public: | 37 public: |
65 AcceleratorController(); | 38 AcceleratorController(); |
66 virtual ~AcceleratorController(); | 39 virtual ~AcceleratorController(); |
67 | 40 |
68 // Registers a global keyboard accelerator for the specified target. If | 41 // Registers a global keyboard accelerator for the specified target. If |
69 // multiple targets are registered for an accelerator, a target registered | 42 // multiple targets are registered for an accelerator, a target registered |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 scoped_ptr<ImeControlDelegate> ime_control_delegate); | 81 scoped_ptr<ImeControlDelegate> ime_control_delegate); |
109 void SetScreenshotDelegate( | 82 void SetScreenshotDelegate( |
110 scoped_ptr<ScreenshotDelegate> screenshot_delegate); | 83 scoped_ptr<ScreenshotDelegate> screenshot_delegate); |
111 BrightnessControlDelegate* brightness_control_delegate() const { | 84 BrightnessControlDelegate* brightness_control_delegate() const { |
112 return brightness_control_delegate_.get(); | 85 return brightness_control_delegate_.get(); |
113 } | 86 } |
114 ScreenshotDelegate* screenshot_delegate() { | 87 ScreenshotDelegate* screenshot_delegate() { |
115 return screenshot_delegate_.get(); | 88 return screenshot_delegate_.get(); |
116 } | 89 } |
117 | 90 |
118 // Provides access to an object holding contextual information. | |
119 AcceleratorControllerContext* context() { | |
120 return &context_; | |
121 } | |
122 | |
123 // Provides access to the ExitWarningHandler for testing. | 91 // Provides access to the ExitWarningHandler for testing. |
124 ExitWarningHandler* GetExitWarningHandlerForTest() { | 92 ExitWarningHandler* GetExitWarningHandlerForTest() { |
125 return &exit_warning_handler_; | 93 return &exit_warning_handler_; |
126 } | 94 } |
127 | 95 |
| 96 const ui::Accelerator& previous_accelerator_for_test() const { |
| 97 return previous_accelerator_; |
| 98 } |
| 99 |
128 private: | 100 private: |
129 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators); | 101 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators); |
| 102 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, |
| 103 DontRepeatToggleFullscreen); |
130 | 104 |
131 // Initializes the accelerators this class handles as a target. | 105 // Initializes the accelerators this class handles as a target. |
132 void Init(); | 106 void Init(); |
133 | 107 |
134 // Registers the specified accelerators. | 108 // Registers the specified accelerators. |
135 void RegisterAccelerators(const AcceleratorData accelerators[], | 109 void RegisterAccelerators(const AcceleratorData accelerators[], |
136 size_t accelerators_length); | 110 size_t accelerators_length); |
137 | 111 |
138 void SetKeyboardBrightnessControlDelegate( | 112 void SetKeyboardBrightnessControlDelegate( |
139 scoped_ptr<KeyboardBrightnessControlDelegate> | 113 scoped_ptr<KeyboardBrightnessControlDelegate> |
140 keyboard_brightness_control_delegate); | 114 keyboard_brightness_control_delegate); |
141 | 115 |
142 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; | 116 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; |
143 | 117 |
144 // TODO(derat): BrightnessControlDelegate is also used by the system tray; | 118 // TODO(derat): BrightnessControlDelegate is also used by the system tray; |
145 // move it outside of this class. | 119 // move it outside of this class. |
146 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_; | 120 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_; |
147 scoped_ptr<ImeControlDelegate> ime_control_delegate_; | 121 scoped_ptr<ImeControlDelegate> ime_control_delegate_; |
148 scoped_ptr<KeyboardBrightnessControlDelegate> | 122 scoped_ptr<KeyboardBrightnessControlDelegate> |
149 keyboard_brightness_control_delegate_; | 123 keyboard_brightness_control_delegate_; |
150 scoped_ptr<ScreenshotDelegate> screenshot_delegate_; | 124 scoped_ptr<ScreenshotDelegate> screenshot_delegate_; |
151 | 125 |
152 // Contextual information, eg. if the current accelerator is repeated. | 126 // Remember previous accelerator as some accelerator needs to be fired |
153 AcceleratorControllerContext context_; | 127 // with a specific sequence. |
| 128 ui::Accelerator previous_accelerator_; |
154 | 129 |
155 // Handles the exit accelerator which requires a double press to exit and | 130 // Handles the exit accelerator which requires a double press to exit and |
156 // shows a popup with an explanation. | 131 // shows a popup with an explanation. |
157 ExitWarningHandler exit_warning_handler_; | 132 ExitWarningHandler exit_warning_handler_; |
158 | 133 |
159 // A map from accelerators to the AcceleratorAction values, which are used in | 134 // A map from accelerators to the AcceleratorAction values, which are used in |
160 // the implementation. | 135 // the implementation. |
161 std::map<ui::Accelerator, int> accelerators_; | 136 std::map<ui::Accelerator, int> accelerators_; |
162 | 137 |
163 // Actions allowed when the user is not signed in. | 138 // Actions allowed when the user is not signed in. |
(...skipping 10 matching lines...) Expand all Loading... |
174 std::set<int> actions_allowed_in_app_mode_; | 149 std::set<int> actions_allowed_in_app_mode_; |
175 // Actions disallowed if there are no windows. | 150 // Actions disallowed if there are no windows. |
176 std::set<int> actions_needing_window_; | 151 std::set<int> actions_needing_window_; |
177 | 152 |
178 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); | 153 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); |
179 }; | 154 }; |
180 | 155 |
181 } // namespace ash | 156 } // namespace ash |
182 | 157 |
183 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 158 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
OLD | NEW |