| 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 AcceleratorControllerDelegate; |
| 30 class ExitWarningHandler; | 31 class ExitWarningHandler; |
| 31 class ImeControlDelegate; | 32 class ImeControlDelegate; |
| 32 class ScreenshotDelegate; | |
| 33 class VolumeControlDelegate; | 33 class VolumeControlDelegate; |
| 34 | 34 |
| 35 // AcceleratorController provides functions for registering or unregistering | 35 // AcceleratorController provides functions for registering or unregistering |
| 36 // global keyboard accelerators, which are handled earlier than any windows. It | 36 // global keyboard accelerators, which are handled earlier than any windows. It |
| 37 // also implements several handlers as an accelerator target. | 37 // also implements several handlers as an accelerator target. |
| 38 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { | 38 class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { |
| 39 public: | 39 public: |
| 40 AcceleratorController(); | 40 explicit AcceleratorController(AcceleratorControllerDelegate* delegate); |
| 41 ~AcceleratorController() override; | 41 ~AcceleratorController() override; |
| 42 | 42 |
| 43 // A list of possible ways in which an accelerator should be restricted before | 43 // A list of possible ways in which an accelerator should be restricted before |
| 44 // processing. Any target registered with this controller should respect | 44 // processing. Any target registered with this controller should respect |
| 45 // restrictions by calling |GetCurrentAcceleratorRestriction| during | 45 // restrictions by calling |GetCurrentAcceleratorRestriction| during |
| 46 // processing. | 46 // processing. |
| 47 enum AcceleratorProcessingRestriction { | 47 enum AcceleratorProcessingRestriction { |
| 48 // Process the accelerator normally. | 48 // Process the accelerator normally. |
| 49 RESTRICTION_NONE, | 49 RESTRICTION_NONE, |
| 50 | 50 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 // 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 |
| 96 // was performed successfully. | 96 // was performed successfully. |
| 97 bool PerformActionIfEnabled(AcceleratorAction action); | 97 bool PerformActionIfEnabled(AcceleratorAction action); |
| 98 | 98 |
| 99 // Returns the restriction for the current context. | 99 // Returns the restriction for the current context. |
| 100 AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction(); | 100 AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction(); |
| 101 | 101 |
| 102 void SetImeControlDelegate( | 102 void SetImeControlDelegate( |
| 103 std::unique_ptr<ImeControlDelegate> ime_control_delegate); | 103 std::unique_ptr<ImeControlDelegate> ime_control_delegate); |
| 104 void SetScreenshotDelegate( | |
| 105 std::unique_ptr<ScreenshotDelegate> screenshot_delegate); | |
| 106 ScreenshotDelegate* screenshot_delegate() { | |
| 107 return screenshot_delegate_.get(); | |
| 108 } | |
| 109 | 104 |
| 110 // Provides access to the ExitWarningHandler for testing. | 105 // Provides access to the ExitWarningHandler for testing. |
| 111 ExitWarningHandler* GetExitWarningHandlerForTest() { | 106 ExitWarningHandler* GetExitWarningHandlerForTest() { |
| 112 return &exit_warning_handler_; | 107 return &exit_warning_handler_; |
| 113 } | 108 } |
| 114 | 109 |
| 115 // Returns true if the menu should close in order to perform the accelerator. | 110 // Returns true if the menu should close in order to perform the accelerator. |
| 116 bool ShouldCloseMenuAndRepostAccelerator( | 111 bool ShouldCloseMenuAndRepostAccelerator( |
| 117 const ui::Accelerator& accelerator) const; | 112 const ui::Accelerator& accelerator) const; |
| 118 | 113 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 const ui::Accelerator& accelerator); | 147 const ui::Accelerator& accelerator); |
| 153 | 148 |
| 154 // Returns whether performing |action| should consume the key event. | 149 // Returns whether performing |action| should consume the key event. |
| 155 bool ShouldActionConsumeKeyEvent(AcceleratorAction action); | 150 bool ShouldActionConsumeKeyEvent(AcceleratorAction action); |
| 156 | 151 |
| 157 // Get the accelerator restriction for the given action. Supply an |action| | 152 // Get the accelerator restriction for the given action. Supply an |action| |
| 158 // of -1 to get restrictions that apply for the current context. | 153 // of -1 to get restrictions that apply for the current context. |
| 159 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction( | 154 AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction( |
| 160 int action); | 155 int action); |
| 161 | 156 |
| 157 AcceleratorControllerDelegate* delegate_; |
| 158 |
| 162 std::unique_ptr<ui::AcceleratorManager> accelerator_manager_; | 159 std::unique_ptr<ui::AcceleratorManager> accelerator_manager_; |
| 163 | 160 |
| 164 // A tracker for the current and previous accelerators. | 161 // A tracker for the current and previous accelerators. |
| 165 std::unique_ptr<ui::AcceleratorHistory> accelerator_history_; | 162 std::unique_ptr<ui::AcceleratorHistory> accelerator_history_; |
| 166 | 163 |
| 167 std::unique_ptr<ImeControlDelegate> ime_control_delegate_; | 164 std::unique_ptr<ImeControlDelegate> ime_control_delegate_; |
| 168 std::unique_ptr<ScreenshotDelegate> screenshot_delegate_; | |
| 169 | 165 |
| 170 // Handles the exit accelerator which requires a double press to exit and | 166 // Handles the exit accelerator which requires a double press to exit and |
| 171 // shows a popup with an explanation. | 167 // shows a popup with an explanation. |
| 172 ExitWarningHandler exit_warning_handler_; | 168 ExitWarningHandler exit_warning_handler_; |
| 173 | 169 |
| 174 // A map from accelerators to the AcceleratorAction values, which are used in | 170 // A map from accelerators to the AcceleratorAction values, which are used in |
| 175 // the implementation. | 171 // the implementation. |
| 176 std::map<ui::Accelerator, AcceleratorAction> accelerators_; | 172 std::map<ui::Accelerator, AcceleratorAction> accelerators_; |
| 177 | 173 |
| 178 std::map<AcceleratorAction, const DeprecatedAcceleratorData*> | 174 std::map<AcceleratorAction, const DeprecatedAcceleratorData*> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 199 std::set<int> actions_needing_window_; | 195 std::set<int> actions_needing_window_; |
| 200 // Actions that can be performed without closing the menu (if one is present). | 196 // Actions that can be performed without closing the menu (if one is present). |
| 201 std::set<int> actions_keeping_menu_open_; | 197 std::set<int> actions_keeping_menu_open_; |
| 202 | 198 |
| 203 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); | 199 DISALLOW_COPY_AND_ASSIGN(AcceleratorController); |
| 204 }; | 200 }; |
| 205 | 201 |
| 206 } // namespace ash | 202 } // namespace ash |
| 207 | 203 |
| 208 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ | 204 #endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_H_ |
| OLD | NEW |