Chromium Code Reviews| 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 |
| 11 #include "ash/accelerators/exit_warning_handler.h" | 11 #include "ash/accelerators/exit_warning_handler.h" |
| 12 #include "ash/ash_export.h" | 12 #include "ash/ash_export.h" |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "ui/base/accelerators/accelerator.h" | 17 #include "ui/base/accelerators/accelerator.h" |
| 18 #include "ui/base/accelerators/accelerator_history.h" | |
| 18 | 19 |
| 19 namespace ui { | 20 namespace ui { |
| 20 class AcceleratorManager; | 21 class AcceleratorManager; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 | 25 |
| 25 struct AcceleratorData; | 26 struct AcceleratorData; |
| 26 class BrightnessControlDelegate; | 27 class BrightnessControlDelegate; |
| 27 class ExitWarningHandler; | 28 class ExitWarningHandler; |
| 28 class ImeControlDelegate; | 29 class ImeControlDelegate; |
| 29 class KeyboardBrightnessControlDelegate; | 30 class KeyboardBrightnessControlDelegate; |
| 30 class ScreenshotDelegate; | 31 class ScreenshotDelegate; |
| 31 class VolumeControlDelegate; | 32 class VolumeControlDelegate; |
| 32 | 33 |
| 33 // AcceleratorController provides functions for registering or unregistering | 34 // AcceleratorController provides functions for registering or unregistering |
| 34 // global keyboard accelerators, which are handled earlier than any windows. It | 35 // global keyboard accelerators, which are handled earlier than any windows. It |
| 35 // also implements several handlers as an accelerator target. | 36 // also implements several handlers as an accelerator target. |
| 36 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { | 37 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { |
| 37 public: | 38 public: |
| 38 AcceleratorController(); | 39 AcceleratorController(ui::AcceleratorHistory* accelerator_history); |
| 39 ~AcceleratorController() override; | 40 ~AcceleratorController() override; |
| 40 | 41 |
| 41 // A list of possible ways in which an accelerator should be restricted before | 42 // A list of possible ways in which an accelerator should be restricted before |
| 42 // processing. Any target registered with this controller should respect | 43 // processing. Any target registered with this controller should respect |
| 43 // restrictions by calling |GetCurrentAcceleratorRestriction| during | 44 // restrictions by calling |GetCurrentAcceleratorRestriction| during |
| 44 // processing. | 45 // processing. |
| 45 enum AcceleratorProcessingRestriction { | 46 enum AcceleratorProcessingRestriction { |
| 46 // Process the accelerator normally. | 47 // Process the accelerator normally. |
| 47 RESTRICTION_NONE, | 48 RESTRICTION_NONE, |
| 48 | 49 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 } | 111 } |
| 111 ScreenshotDelegate* screenshot_delegate() { | 112 ScreenshotDelegate* screenshot_delegate() { |
| 112 return screenshot_delegate_.get(); | 113 return screenshot_delegate_.get(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 // Provides access to the ExitWarningHandler for testing. | 116 // Provides access to the ExitWarningHandler for testing. |
| 116 ExitWarningHandler* GetExitWarningHandlerForTest() { | 117 ExitWarningHandler* GetExitWarningHandlerForTest() { |
| 117 return &exit_warning_handler_; | 118 return &exit_warning_handler_; |
| 118 } | 119 } |
| 119 | 120 |
| 120 const ui::Accelerator& previous_accelerator_for_test() const { | 121 ui::AcceleratorHistory* accelerator_history_for_test() { |
| 121 return previous_accelerator_; | 122 return accelerator_history_; |
| 122 } | 123 } |
| 123 | 124 |
| 124 private: | 125 private: |
| 125 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators); | 126 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators); |
| 126 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, | 127 FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, |
| 127 DontRepeatToggleFullscreen); | 128 DontRepeatToggleFullscreen); |
| 128 | 129 |
| 129 // Initializes the accelerators this class handles as a target. | 130 // Initializes the accelerators this class handles as a target. |
| 130 void Init(); | 131 void Init(); |
| 131 | 132 |
| 132 // Registers the specified accelerators. | 133 // Registers the specified accelerators. |
| 133 void RegisterAccelerators(const AcceleratorData accelerators[], | 134 void RegisterAccelerators(const AcceleratorData accelerators[], |
| 134 size_t accelerators_length); | 135 size_t accelerators_length); |
| 135 | 136 |
| 136 // Get the accelerator restriction for the given action. Supply an |action| | 137 // Get the accelerator restriction for the given action. Supply an |action| |
| 137 // of -1 to get restrictions that apply for the current context. | 138 // of -1 to get restrictions that apply for the current context. |
| 138 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction( | 139 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction( |
| 139 int action); | 140 int action); |
| 140 | 141 |
| 141 void SetKeyboardBrightnessControlDelegate( | 142 void SetKeyboardBrightnessControlDelegate( |
| 142 scoped_ptr<KeyboardBrightnessControlDelegate> | 143 scoped_ptr<KeyboardBrightnessControlDelegate> |
| 143 keyboard_brightness_control_delegate); | 144 keyboard_brightness_control_delegate); |
| 144 | 145 |
| 145 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; | 146 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; |
| 146 | 147 |
| 148 ui::AcceleratorHistory* accelerator_history_; | |
|
Jun Mukai
2014/11/18 17:33:44
It's better to be owned by this class (or let acce
afakhry
2014/11/18 19:23:51
Done.
| |
| 149 | |
| 147 // TODO(derat): BrightnessControlDelegate is also used by the system tray; | 150 // TODO(derat): BrightnessControlDelegate is also used by the system tray; |
| 148 // move it outside of this class. | 151 // move it outside of this class. |
| 149 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_; | 152 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_; |
| 150 scoped_ptr<ImeControlDelegate> ime_control_delegate_; | 153 scoped_ptr<ImeControlDelegate> ime_control_delegate_; |
| 151 scoped_ptr<KeyboardBrightnessControlDelegate> | 154 scoped_ptr<KeyboardBrightnessControlDelegate> |
| 152 keyboard_brightness_control_delegate_; | 155 keyboard_brightness_control_delegate_; |
| 153 scoped_ptr<ScreenshotDelegate> screenshot_delegate_; | 156 scoped_ptr<ScreenshotDelegate> screenshot_delegate_; |
| 154 | 157 |
| 155 // Remember previous accelerator as some accelerator needs to be fired | |
| 156 // with a specific sequence. | |
| 157 ui::Accelerator previous_accelerator_; | |
| 158 | |
| 159 // Handles the exit accelerator which requires a double press to exit and | 158 // Handles the exit accelerator which requires a double press to exit and |
| 160 // shows a popup with an explanation. | 159 // shows a popup with an explanation. |
| 161 ExitWarningHandler exit_warning_handler_; | 160 ExitWarningHandler exit_warning_handler_; |
| 162 | 161 |
| 163 // A map from accelerators to the AcceleratorAction values, which are used in | 162 // A map from accelerators to the AcceleratorAction values, which are used in |
| 164 // the implementation. | 163 // the implementation. |
| 165 std::map<ui::Accelerator, int> accelerators_; | 164 std::map<ui::Accelerator, int> accelerators_; |
| 166 | 165 |
| 167 // Actions allowed when the user is not signed in. | 166 // Actions allowed when the user is not signed in. |
| 168 std::set<int> actions_allowed_at_login_screen_; | 167 std::set<int> actions_allowed_at_login_screen_; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 180 std::set<int> actions_allowed_in_app_mode_; | 179 std::set<int> actions_allowed_in_app_mode_; |
| 181 // Actions disallowed if there are no windows. | 180 // Actions disallowed if there are no windows. |
| 182 std::set<int> actions_needing_window_; | 181 std::set<int> actions_needing_window_; |
| 183 | 182 |
| 184 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); | 183 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); |
| 185 }; | 184 }; |
| 186 | 185 |
| 187 } // namespace ash | 186 } // namespace ash |
| 188 | 187 |
| 189 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 188 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
| OLD | NEW |