Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / base / accelerators / accelerator_manager.h
blob8398c8f7404c2253e76fdb8cb63eac1a28bf9c1e
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
3 // found in the LICENSE file.
5 #ifndef UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_
6 #define UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_
8 #include <list>
9 #include <map>
10 #include <utility>
12 #include "base/basictypes.h"
13 #include "ui/base/accelerators/accelerator.h"
14 #include "ui/base/ui_base_export.h"
15 #include "ui/events/event_constants.h"
17 namespace ui {
19 // The AcceleratorManger is used to handle keyboard accelerators.
20 class UI_BASE_EXPORT AcceleratorManager {
21 public:
22 enum HandlerPriority {
23 kNormalPriority,
24 kHighPriority,
27 AcceleratorManager();
28 ~AcceleratorManager();
30 // Register a keyboard accelerator for the specified target. If multiple
31 // targets are registered for an accelerator, a target registered later has
32 // higher priority.
33 // |accelerator| is the accelerator to register.
34 // |priority| denotes the priority of the handler.
35 // NOTE: In almost all cases, you should specify kNormalPriority for this
36 // 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 // except for very isolated cases.
39 // |target| is the AcceleratorTarget that handles the event once the
40 // accelerator is pressed.
41 // Note that we are currently limited to accelerators that are either:
42 // - a key combination including Ctrl or Alt
43 // - the escape key
44 // - the enter key
45 // - any F key (F1, F2, F3 ...)
46 // - any browser specific keys (as available on special keyboards)
47 void Register(const Accelerator& accelerator,
48 HandlerPriority priority,
49 AcceleratorTarget* target);
51 // Unregister the specified keyboard accelerator for the specified target.
52 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target);
54 // Unregister all keyboard accelerator for the specified target.
55 void UnregisterAll(AcceleratorTarget* target);
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);
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;
70 // Whether the given |accelerator| has a priority handler associated with it.
71 bool HasPriorityHandler(const Accelerator& accelerator) const;
73 private:
74 // The accelerators and associated targets.
75 typedef std::list<AcceleratorTarget*> AcceleratorTargetList;
76 // This construct pairs together a |bool| (denoting whether the list contains
77 // a priority_handler at the front) with the list of AcceleratorTargets.
78 typedef std::pair<bool, AcceleratorTargetList> AcceleratorTargets;
79 typedef std::map<Accelerator, AcceleratorTargets> AcceleratorMap;
80 AcceleratorMap accelerators_;
82 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager);
85 } // namespace ui
87 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_