| 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); |
| 130 | 102 |
| 131 // Initializes the accelerators this class handles as a target. | 103 // Initializes the accelerators this class handles as a target. |
| 132 void Init(); | 104 void Init(); |
| 133 | 105 |
| 134 // Registers the specified accelerators. | 106 // Registers the specified accelerators. |
| 135 void RegisterAccelerators(const AcceleratorData accelerators[], | 107 void RegisterAccelerators(const AcceleratorData accelerators[], |
| 136 size_t accelerators_length); | 108 size_t accelerators_length); |
| 137 | 109 |
| 138 void SetKeyboardBrightnessControlDelegate( | 110 void SetKeyboardBrightnessControlDelegate( |
| 139 scoped_ptr<KeyboardBrightnessControlDelegate> | 111 scoped_ptr<KeyboardBrightnessControlDelegate> |
| 140 keyboard_brightness_control_delegate); | 112 keyboard_brightness_control_delegate); |
| 141 | 113 |
| 142 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; | 114 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; |
| 143 | 115 |
| 144 // TODO(derat): BrightnessControlDelegate is also used by the system tray; | 116 // TODO(derat): BrightnessControlDelegate is also used by the system tray; |
| 145 // move it outside of this class. | 117 // move it outside of this class. |
| 146 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_; | 118 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_; |
| 147 scoped_ptr<ImeControlDelegate> ime_control_delegate_; | 119 scoped_ptr<ImeControlDelegate> ime_control_delegate_; |
| 148 scoped_ptr<KeyboardBrightnessControlDelegate> | 120 scoped_ptr<KeyboardBrightnessControlDelegate> |
| 149 keyboard_brightness_control_delegate_; | 121 keyboard_brightness_control_delegate_; |
| 150 scoped_ptr<ScreenshotDelegate> screenshot_delegate_; | 122 scoped_ptr<ScreenshotDelegate> screenshot_delegate_; |
| 151 | 123 |
| 152 // Contextual information, eg. if the current accelerator is repeated. | 124 // Remember previous accelerator as some accelerator needs to be fired |
| 153 AcceleratorControllerContext context_; | 125 // with a specific sequence. |
| 126 ui::Accelerator previous_accelerator_; |
| 154 | 127 |
| 155 // Handles the exit accelerator which requires a double press to exit and | 128 // Handles the exit accelerator which requires a double press to exit and |
| 156 // shows a popup with an explanation. | 129 // shows a popup with an explanation. |
| 157 ExitWarningHandler exit_warning_handler_; | 130 ExitWarningHandler exit_warning_handler_; |
| 158 | 131 |
| 159 // A map from accelerators to the AcceleratorAction values, which are used in | 132 // A map from accelerators to the AcceleratorAction values, which are used in |
| 160 // the implementation. | 133 // the implementation. |
| 161 std::map<ui::Accelerator, int> accelerators_; | 134 std::map<ui::Accelerator, int> accelerators_; |
| 162 | 135 |
| 163 // Actions allowed when the user is not signed in. | 136 // 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_; | 147 std::set<int> actions_allowed_in_app_mode_; |
| 175 // Actions disallowed if there are no windows. | 148 // Actions disallowed if there are no windows. |
| 176 std::set<int> actions_needing_window_; | 149 std::set<int> actions_needing_window_; |
| 177 | 150 |
| 178 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); | 151 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); |
| 179 }; | 152 }; |
| 180 | 153 |
| 181 } // namespace ash | 154 } // namespace ash |
| 182 | 155 |
| 183 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 156 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
| OLD | NEW |