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> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 void Register(const Accelerator& accelerator, | 47 void Register(const Accelerator& accelerator, |
48 HandlerPriority priority, | 48 HandlerPriority priority, |
49 AcceleratorTarget* target); | 49 AcceleratorTarget* target); |
50 | 50 |
51 // Unregister the specified keyboard accelerator for the specified target. | 51 // Unregister the specified keyboard accelerator for the specified target. |
52 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target); | 52 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target); |
53 | 53 |
54 // Unregister all keyboard accelerator for the specified target. | 54 // Unregister all keyboard accelerator for the specified target. |
55 void UnregisterAll(AcceleratorTarget* target); | 55 void UnregisterAll(AcceleratorTarget* target); |
56 | 56 |
| 57 // Returns whether |accelerator| is already registered. |
| 58 bool IsRegistered(const Accelerator& accelerator) const; |
| 59 |
57 // Activate the target associated with the specified accelerator. | 60 // Activate the target associated with the specified accelerator. |
58 // First, AcceleratorPressed handler of the most recently registered target | 61 // First, AcceleratorPressed handler of the most recently registered target |
59 // is called, and if that handler processes the event (i.e. returns true), | 62 // 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 | 63 // this method immediately returns. If not, we do the same thing on the next |
61 // target, and so on. | 64 // target, and so on. |
62 // Returns true if an accelerator was activated. | 65 // Returns true if an accelerator was activated. |
63 bool Process(const Accelerator& accelerator); | 66 bool Process(const Accelerator& accelerator); |
64 | 67 |
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. | 68 // Whether the given |accelerator| has a priority handler associated with it. |
71 bool HasPriorityHandler(const Accelerator& accelerator) const; | 69 bool HasPriorityHandler(const Accelerator& accelerator) const; |
72 | 70 |
73 private: | 71 private: |
74 // The accelerators and associated targets. | 72 // The accelerators and associated targets. |
75 typedef std::list<AcceleratorTarget*> AcceleratorTargetList; | 73 typedef std::list<AcceleratorTarget*> AcceleratorTargetList; |
76 // This construct pairs together a |bool| (denoting whether the list contains | 74 // This construct pairs together a |bool| (denoting whether the list contains |
77 // a priority_handler at the front) with the list of AcceleratorTargets. | 75 // a priority_handler at the front) with the list of AcceleratorTargets. |
78 typedef std::pair<bool, AcceleratorTargetList> AcceleratorTargets; | 76 typedef std::pair<bool, AcceleratorTargetList> AcceleratorTargets; |
79 typedef std::map<Accelerator, AcceleratorTargets> AcceleratorMap; | 77 typedef std::map<Accelerator, AcceleratorTargets> AcceleratorMap; |
80 AcceleratorMap accelerators_; | 78 AcceleratorMap accelerators_; |
81 | 79 |
82 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager); | 80 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager); |
83 }; | 81 }; |
84 | 82 |
85 } // namespace ui | 83 } // namespace ui |
86 | 84 |
87 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ | 85 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ |
OLD | NEW |