| 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 UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ | 5 #ifndef UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ |
| 6 #define UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ | 6 #define UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "ui/base/accelerators/accelerator.h" | 13 #include "ui/base/accelerators/accelerator.h" |
| 14 #include "ui/base/ui_base_export.h" | 14 #include "ui/base/ui_base_export.h" |
| 15 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
| 16 | 16 |
| 17 namespace ui { | 17 namespace ui { |
| 18 | 18 |
| 19 // The AcceleratorManger is used to handle keyboard accelerators. | 19 class AcceleratorManagerDelegate; |
| 20 |
| 21 // AcceleratorManger handles processing of accelerators. A delegate may be |
| 22 // supplied which is notified as unique accelerators are added and removed. |
| 20 class UI_BASE_EXPORT AcceleratorManager { | 23 class UI_BASE_EXPORT AcceleratorManager { |
| 21 public: | 24 public: |
| 22 enum HandlerPriority { | 25 enum HandlerPriority { |
| 23 kNormalPriority, | 26 kNormalPriority, |
| 24 kHighPriority, | 27 kHighPriority, |
| 25 }; | 28 }; |
| 26 | 29 |
| 27 AcceleratorManager(); | 30 explicit AcceleratorManager(AcceleratorManagerDelegate* = nullptr); |
| 28 ~AcceleratorManager(); | 31 ~AcceleratorManager(); |
| 29 | 32 |
| 30 // Register a keyboard accelerator for the specified target. If multiple | 33 // Register a keyboard accelerator for the specified target. If multiple |
| 31 // targets are registered for an accelerator, a target registered later has | 34 // targets are registered for an accelerator, a target registered later has |
| 32 // higher priority. | 35 // higher priority. |
| 33 // |accelerator| is the accelerator to register. | 36 // |accelerator| is the accelerator to register. |
| 34 // |priority| denotes the priority of the handler. | 37 // |priority| denotes the priority of the handler. |
| 35 // NOTE: In almost all cases, you should specify kNormalPriority for this | 38 // NOTE: In almost all cases, you should specify kNormalPriority for this |
| 36 // parameter. Setting it to kHighPriority prevents Chrome from sending the | 39 // parameter. Setting it to kHighPriority prevents Chrome from sending the |
| 37 // shortcut to the webpage if the renderer has focus, which is not desirable | 40 // shortcut to the webpage if the renderer has focus, which is not desirable |
| (...skipping 25 matching lines...) Expand all Loading... |
| 63 // this method immediately returns. If not, we do the same thing on the next | 66 // this method immediately returns. If not, we do the same thing on the next |
| 64 // target, and so on. | 67 // target, and so on. |
| 65 // Returns true if an accelerator was activated. | 68 // Returns true if an accelerator was activated. |
| 66 bool Process(const Accelerator& accelerator); | 69 bool Process(const Accelerator& accelerator); |
| 67 | 70 |
| 68 // Whether the given |accelerator| has a priority handler associated with it. | 71 // Whether the given |accelerator| has a priority handler associated with it. |
| 69 bool HasPriorityHandler(const Accelerator& accelerator) const; | 72 bool HasPriorityHandler(const Accelerator& accelerator) const; |
| 70 | 73 |
| 71 private: | 74 private: |
| 72 // The accelerators and associated targets. | 75 // The accelerators and associated targets. |
| 73 typedef std::list<AcceleratorTarget*> AcceleratorTargetList; | 76 using AcceleratorTargetList = std::list<AcceleratorTarget*>; |
| 74 // This construct pairs together a |bool| (denoting whether the list contains | 77 // This construct pairs together a |bool| (denoting whether the list contains |
| 75 // a priority_handler at the front) with the list of AcceleratorTargets. | 78 // a priority_handler at the front) with the list of AcceleratorTargets. |
| 76 typedef std::pair<bool, AcceleratorTargetList> AcceleratorTargets; | 79 using AcceleratorTargets = std::pair<bool, AcceleratorTargetList>; |
| 77 typedef std::map<Accelerator, AcceleratorTargets> AcceleratorMap; | 80 using AcceleratorMap = std::map<Accelerator, AcceleratorTargets>; |
| 81 |
| 82 // Implementation of Unregister(). |map_iter| points to the accelerator to |
| 83 // remove, and |target| the AcceleratorTarget to remove. |
| 84 void UnregisterImpl(AcceleratorMap::iterator map_iter, |
| 85 AcceleratorTarget* target); |
| 86 |
| 87 AcceleratorManagerDelegate* delegate_; |
| 78 AcceleratorMap accelerators_; | 88 AcceleratorMap accelerators_; |
| 79 | 89 |
| 80 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager); | 90 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager); |
| 81 }; | 91 }; |
| 82 | 92 |
| 83 } // namespace ui | 93 } // namespace ui |
| 84 | 94 |
| 85 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ | 95 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ |
| OLD | NEW |