Chromium Code Reviews| 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 #include <vector> | |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.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 class AcceleratorManagerDelegate; | 20 class AcceleratorManagerDelegate; |
| 20 | 21 |
| 21 // AcceleratorManger handles processing of accelerators. A delegate may be | 22 // AcceleratorManger handles processing of accelerators. A delegate may be |
| 22 // supplied which is notified as unique accelerators are added and removed. | 23 // supplied which is notified as unique accelerators are added and removed. |
| 23 class UI_BASE_EXPORT AcceleratorManager { | 24 class UI_BASE_EXPORT AcceleratorManager { |
| 24 public: | 25 public: |
| 25 enum HandlerPriority { | 26 enum HandlerPriority { |
| 26 kNormalPriority, | 27 kNormalPriority, |
| 27 kHighPriority, | 28 kHighPriority, |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 explicit AcceleratorManager(AcceleratorManagerDelegate* = nullptr); | 31 explicit AcceleratorManager(AcceleratorManagerDelegate* = nullptr); |
| 31 ~AcceleratorManager(); | 32 ~AcceleratorManager(); |
| 32 | 33 |
| 33 // Register a keyboard accelerator for the specified target. If multiple | 34 // Register keyboard accelerators for the specified target. If multiple |
| 34 // targets are registered for an accelerator, a target registered later has | 35 // targets are registered for an accelerator, a target registered later has |
| 35 // higher priority. | 36 // higher priority. |
| 36 // |accelerator| is the accelerator to register. | 37 // |accelerators| contain accelerators to register. |
| 37 // |priority| denotes the priority of the handler. | 38 // |priority| denotes the priority of the handler. |
| 38 // NOTE: In almost all cases, you should specify kNormalPriority for this | 39 // NOTE: In almost all cases, you should specify kNormalPriority for this |
| 39 // parameter. Setting it to kHighPriority prevents Chrome from sending the | 40 // parameter. Setting it to kHighPriority prevents Chrome from sending the |
| 40 // shortcut to the webpage if the renderer has focus, which is not desirable | 41 // shortcut to the webpage if the renderer has focus, which is not desirable |
| 41 // except for very isolated cases. | 42 // except for very isolated cases. |
| 42 // |target| is the AcceleratorTarget that handles the event once the | 43 // |target| is the AcceleratorTarget that handles the event once the |
| 43 // accelerator is pressed. | 44 // accelerator is pressed. |
| 44 // Note that we are currently limited to accelerators that are either: | 45 // Note that we are currently limited to accelerators that are either: |
| 45 // - a key combination including Ctrl or Alt | 46 // - a key combination including Ctrl or Alt |
| 46 // - the escape key | 47 // - the escape key |
| 47 // - the enter key | 48 // - the enter key |
| 48 // - any F key (F1, F2, F3 ...) | 49 // - any F key (F1, F2, F3 ...) |
| 49 // - any browser specific keys (as available on special keyboards) | 50 // - any browser specific keys (as available on special keyboards) |
| 50 void Register(const Accelerator& accelerator, | 51 void Register(const std::vector<ui::Accelerator>& accelerators, |
| 51 HandlerPriority priority, | 52 HandlerPriority priority, |
|
sky
2017/01/27 19:11:14
Each accelerator may want a different priority, so
mfomitchev
2017/01/27 23:12:01
We don't currently have a use case for registering
sky
2017/01/28 00:09:15
Given we don't have a need for it now, I'm ok with
thanhph1
2017/01/30 16:37:54
I can't use the same name Register for inline func
| |
| 52 AcceleratorTarget* target); | 53 AcceleratorTarget* target); |
| 53 | 54 |
| 54 // Unregister the specified keyboard accelerator for the specified target. | 55 // Unregister the specified keyboard accelerator for the specified target. |
| 55 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target); | 56 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target); |
| 56 | 57 |
| 57 // Unregister all keyboard accelerator for the specified target. | 58 // Unregister all keyboard accelerator for the specified target. |
| 58 void UnregisterAll(AcceleratorTarget* target); | 59 void UnregisterAll(AcceleratorTarget* target); |
| 59 | 60 |
| 60 // Returns whether |accelerator| is already registered. | 61 // Returns whether |accelerator| is already registered. |
| 61 bool IsRegistered(const Accelerator& accelerator) const; | 62 bool IsRegistered(const Accelerator& accelerator) const; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 86 | 87 |
| 87 AcceleratorManagerDelegate* delegate_; | 88 AcceleratorManagerDelegate* delegate_; |
| 88 AcceleratorMap accelerators_; | 89 AcceleratorMap accelerators_; |
| 89 | 90 |
| 90 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager); | 91 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 } // namespace ui | 94 } // namespace ui |
| 94 | 95 |
| 95 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ | 96 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ |
| OLD | NEW |