Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 |
|
sky
2015/01/08 23:39:26
fix this.
Andre
2015/01/09 00:06:15
Done.
| |
| 2 // // 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 | 3 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 4 | 5 |
| 5 #ifndef UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ | 6 #ifndef UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ |
| 6 #define UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ | 7 #define UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ |
| 7 | 8 |
| 8 #include <list> | 9 #include <list> |
| 9 #include <map> | 10 #include <map> |
| 10 #include <utility> | 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 13 #include "ui/base/accelerators/accelerator.h" | 14 #include "ui/base/accelerators/accelerator.h" |
| 14 #include "ui/base/ui_base_export.h" | 15 #include "ui/base/ui_base_export.h" |
| 15 #include "ui/events/event_constants.h" | 16 #include "ui/events/event_constants.h" |
| 16 | 17 |
| 17 namespace ui { | 18 namespace ui { |
| 18 | 19 |
| 19 // The AcceleratorManger is used to handle keyboard accelerators. | 20 // The AcceleratorManger is used to handle keyboard accelerators. |
| 20 class UI_BASE_EXPORT AcceleratorManager { | 21 class UI_BASE_EXPORT AcceleratorManager : public AcceleratorProcessor { |
| 21 public: | 22 public: |
| 22 enum HandlerPriority { | 23 enum HandlerPriority { |
| 23 kNormalPriority, | 24 kNormalPriority, |
| 24 kHighPriority, | 25 kHighPriority, |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 AcceleratorManager(); | 28 AcceleratorManager(); |
| 28 ~AcceleratorManager(); | 29 ~AcceleratorManager() override; |
| 29 | 30 |
| 30 // Register a keyboard accelerator for the specified target. If multiple | 31 // Register a keyboard accelerator for the specified target. If multiple |
| 31 // targets are registered for an accelerator, a target registered later has | 32 // targets are registered for an accelerator, a target registered later has |
| 32 // higher priority. | 33 // higher priority. |
| 33 // |accelerator| is the accelerator to register. | 34 // |accelerator| is the accelerator to register. |
| 34 // |priority| denotes the priority of the handler. | 35 // |priority| denotes the priority of the handler. |
| 35 // NOTE: In almost all cases, you should specify kNormalPriority for this | 36 // NOTE: In almost all cases, you should specify kNormalPriority for this |
| 36 // parameter. Setting it to kHighPriority prevents Chrome from sending the | 37 // parameter. Setting it to kHighPriority prevents Chrome from sending the |
| 37 // shortcut to the webpage if the renderer has focus, which is not desirable | 38 // shortcut to the webpage if the renderer has focus, which is not desirable |
| 38 // except for very isolated cases. | 39 // except for very isolated cases. |
| 39 // |target| is the AcceleratorTarget that handles the event once the | 40 // |target| is the AcceleratorTarget that handles the event once the |
| 40 // accelerator is pressed. | 41 // accelerator is pressed. |
| 41 // Note that we are currently limited to accelerators that are either: | 42 // Note that we are currently limited to accelerators that are either: |
| 42 // - a key combination including Ctrl or Alt | 43 // - a key combination including Ctrl or Alt |
| 43 // - the escape key | 44 // - the escape key |
| 44 // - the enter key | 45 // - the enter key |
| 45 // - any F key (F1, F2, F3 ...) | 46 // - any F key (F1, F2, F3 ...) |
| 46 // - any browser specific keys (as available on special keyboards) | 47 // - any browser specific keys (as available on special keyboards) |
| 47 void Register(const Accelerator& accelerator, | 48 void Register(const Accelerator& accelerator, |
| 48 HandlerPriority priority, | 49 HandlerPriority priority, |
| 49 AcceleratorTarget* target); | 50 AcceleratorTarget* target); |
| 50 | 51 |
| 51 // Unregister the specified keyboard accelerator for the specified target. | 52 // Unregister the specified keyboard accelerator for the specified target. |
| 52 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target); | 53 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target); |
| 53 | 54 |
| 54 // Unregister all keyboard accelerator for the specified target. | 55 // Unregister all keyboard accelerator for the specified target. |
| 55 void UnregisterAll(AcceleratorTarget* target); | 56 void UnregisterAll(AcceleratorTarget* target); |
| 56 | 57 |
| 57 // Activate the target associated with the specified accelerator. | |
| 58 // First, AcceleratorPressed handler of the most recently registered target | |
| 59 // is called, and if that handler processes the event (i.e. returns true), | |
| 60 // this method immediately returns. If not, we do the same thing on the next | |
| 61 // target, and so on. | |
| 62 // Returns true if an accelerator was activated. | |
| 63 bool Process(const Accelerator& accelerator); | |
| 64 | |
| 65 // Returns the AcceleratorTarget that should be activated for the specified | |
| 66 // keyboard accelerator, or NULL if no view is registered for that keyboard | |
| 67 // accelerator. | |
| 68 AcceleratorTarget* GetCurrentTarget(const Accelerator& accelerator) const; | |
| 69 | |
| 70 // Whether the given |accelerator| has a priority handler associated with it. | 58 // Whether the given |accelerator| has a priority handler associated with it. |
| 71 bool HasPriorityHandler(const Accelerator& accelerator) const; | 59 bool HasPriorityHandler(const Accelerator& accelerator) const; |
| 72 | 60 |
| 61 // Overridden from AcceleratorProcessor: | |
| 62 bool ProcessAccelerator(const Accelerator& accelerator) override; | |
| 63 AcceleratorTarget* GetTargetForAccelerator( | |
| 64 const Accelerator& accelerator) const override; | |
| 65 | |
| 73 private: | 66 private: |
| 74 // The accelerators and associated targets. | 67 // The accelerators and associated targets. |
| 75 typedef std::list<AcceleratorTarget*> AcceleratorTargetList; | 68 typedef std::list<AcceleratorTarget*> AcceleratorTargetList; |
| 76 // This construct pairs together a |bool| (denoting whether the list contains | 69 // This construct pairs together a |bool| (denoting whether the list contains |
| 77 // a priority_handler at the front) with the list of AcceleratorTargets. | 70 // a priority_handler at the front) with the list of AcceleratorTargets. |
| 78 typedef std::pair<bool, AcceleratorTargetList> AcceleratorTargets; | 71 typedef std::pair<bool, AcceleratorTargetList> AcceleratorTargets; |
| 79 typedef std::map<Accelerator, AcceleratorTargets> AcceleratorMap; | 72 typedef std::map<Accelerator, AcceleratorTargets> AcceleratorMap; |
| 80 AcceleratorMap accelerators_; | 73 AcceleratorMap accelerators_; |
| 81 | 74 |
| 82 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager); | 75 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager); |
| 83 }; | 76 }; |
| 84 | 77 |
| 85 } // namespace ui | 78 } // namespace ui |
| 86 | 79 |
| 87 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ | 80 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ |
| OLD | NEW |