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 20 matching lines...) Expand all Loading... |
31 class VolumeControlDelegate; | 31 class VolumeControlDelegate; |
32 | 32 |
33 // AcceleratorController provides functions for registering or unregistering | 33 // AcceleratorController provides functions for registering or unregistering |
34 // global keyboard accelerators, which are handled earlier than any windows. It | 34 // global keyboard accelerators, which are handled earlier than any windows. It |
35 // also implements several handlers as an accelerator target. | 35 // also implements several handlers as an accelerator target. |
36 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { | 36 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { |
37 public: | 37 public: |
38 AcceleratorController(); | 38 AcceleratorController(); |
39 virtual ~AcceleratorController(); | 39 virtual ~AcceleratorController(); |
40 | 40 |
| 41 // A list of possible ways in which an accelerator should be restricted before |
| 42 // processing. Any target registered with this controller should respect |
| 43 // restrictions by calling |GetCurrentAcceleratorRestriction| during |
| 44 // processing. |
| 45 enum AcceleratorProcessingRestriction { |
| 46 // Process the accelerator normally. |
| 47 RESTRICTION_NONE, |
| 48 |
| 49 // Don't process the accelerator. |
| 50 RESTRICTION_PREVENT_PROCESSING, |
| 51 |
| 52 // Don't process the accelerator and prevent propagation to other targets. |
| 53 RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION |
| 54 }; |
| 55 |
41 // Registers a global keyboard accelerator for the specified target. If | 56 // Registers a global keyboard accelerator for the specified target. If |
42 // multiple targets are registered for an accelerator, a target registered | 57 // multiple targets are registered for an accelerator, a target registered |
43 // later has higher priority. | 58 // later has higher priority. |
44 void Register(const ui::Accelerator& accelerator, | 59 void Register(const ui::Accelerator& accelerator, |
45 ui::AcceleratorTarget* target); | 60 ui::AcceleratorTarget* target); |
46 | 61 |
47 // Unregisters the specified keyboard accelerator for the specified target. | 62 // Unregisters the specified keyboard accelerator for the specified target. |
48 void Unregister(const ui::Accelerator& accelerator, | 63 void Unregister(const ui::Accelerator& accelerator, |
49 ui::AcceleratorTarget* target); | 64 ui::AcceleratorTarget* target); |
50 | 65 |
(...skipping 13 matching lines...) Expand all Loading... |
64 | 79 |
65 // Returns true if the |accelerator| is one of the |reserved_actions_|. | 80 // Returns true if the |accelerator| is one of the |reserved_actions_|. |
66 bool IsReservedAccelerator(const ui::Accelerator& accelerator) const; | 81 bool IsReservedAccelerator(const ui::Accelerator& accelerator) const; |
67 | 82 |
68 // Performs the specified action. The |accelerator| may provide additional | 83 // Performs the specified action. The |accelerator| may provide additional |
69 // data the action needs. Returns whether an action was performed | 84 // data the action needs. Returns whether an action was performed |
70 // successfully. | 85 // successfully. |
71 bool PerformAction(int action, | 86 bool PerformAction(int action, |
72 const ui::Accelerator& accelerator); | 87 const ui::Accelerator& accelerator); |
73 | 88 |
| 89 // Returns the restriction for the current context. |
| 90 AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction(); |
| 91 |
74 // Overridden from ui::AcceleratorTarget: | 92 // Overridden from ui::AcceleratorTarget: |
75 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 93 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
76 virtual bool CanHandleAccelerators() const OVERRIDE; | 94 virtual bool CanHandleAccelerators() const OVERRIDE; |
77 | 95 |
78 void SetBrightnessControlDelegate( | 96 void SetBrightnessControlDelegate( |
79 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate); | 97 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate); |
80 void SetImeControlDelegate( | 98 void SetImeControlDelegate( |
81 scoped_ptr<ImeControlDelegate> ime_control_delegate); | 99 scoped_ptr<ImeControlDelegate> ime_control_delegate); |
82 void SetScreenshotDelegate( | 100 void SetScreenshotDelegate( |
83 scoped_ptr<ScreenshotDelegate> screenshot_delegate); | 101 scoped_ptr<ScreenshotDelegate> screenshot_delegate); |
(...skipping 18 matching lines...) Expand all Loading... |
102 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, | 120 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, |
103 DontRepeatToggleFullscreen); | 121 DontRepeatToggleFullscreen); |
104 | 122 |
105 // Initializes the accelerators this class handles as a target. | 123 // Initializes the accelerators this class handles as a target. |
106 void Init(); | 124 void Init(); |
107 | 125 |
108 // Registers the specified accelerators. | 126 // Registers the specified accelerators. |
109 void RegisterAccelerators(const AcceleratorData accelerators[], | 127 void RegisterAccelerators(const AcceleratorData accelerators[], |
110 size_t accelerators_length); | 128 size_t accelerators_length); |
111 | 129 |
| 130 // Get the accelerator restriction for the given action. Supply an |action| |
| 131 // of -1 to get restrictions that apply for the current context. |
| 132 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction( |
| 133 int action); |
| 134 |
112 void SetKeyboardBrightnessControlDelegate( | 135 void SetKeyboardBrightnessControlDelegate( |
113 scoped_ptr<KeyboardBrightnessControlDelegate> | 136 scoped_ptr<KeyboardBrightnessControlDelegate> |
114 keyboard_brightness_control_delegate); | 137 keyboard_brightness_control_delegate); |
115 | 138 |
116 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; | 139 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; |
117 | 140 |
118 // TODO(derat): BrightnessControlDelegate is also used by the system tray; | 141 // TODO(derat): BrightnessControlDelegate is also used by the system tray; |
119 // move it outside of this class. | 142 // move it outside of this class. |
120 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_; | 143 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_; |
121 scoped_ptr<ImeControlDelegate> ime_control_delegate_; | 144 scoped_ptr<ImeControlDelegate> ime_control_delegate_; |
(...skipping 27 matching lines...) Expand all Loading... |
149 std::set<int> actions_allowed_in_app_mode_; | 172 std::set<int> actions_allowed_in_app_mode_; |
150 // Actions disallowed if there are no windows. | 173 // Actions disallowed if there are no windows. |
151 std::set<int> actions_needing_window_; | 174 std::set<int> actions_needing_window_; |
152 | 175 |
153 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); | 176 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); |
154 }; | 177 }; |
155 | 178 |
156 } // namespace ash | 179 } // namespace ash |
157 | 180 |
158 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 181 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
OLD | NEW |