Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(655)

Side by Side Diff: ui/base/accelerators/accelerator_manager.h

Issue 2586333003: Make mash register initial batch of accelerators in single shot. (Closed)
Patch Set: Fix comments. Move inline function to .h Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/ws/event_dispatcher.cc ('k') | ui/base/accelerators/accelerator_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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| contains 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,
52 AcceleratorTarget* target); 53 AcceleratorTarget* target);
53 54
55 // Registers a keyboard accelerator for the specified target. This function
56 // calls the function Register() with vector argument above.
57 inline void RegisterAccelerator(const Accelerator& accelerator,
58 HandlerPriority priority,
59 AcceleratorTarget* target) {
60 Register({accelerator}, priority, target);
61 }
62
54 // Unregister the specified keyboard accelerator for the specified target. 63 // Unregister the specified keyboard accelerator for the specified target.
55 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target); 64 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target);
56 65
57 // Unregister all keyboard accelerator for the specified target. 66 // Unregister all keyboard accelerator for the specified target.
58 void UnregisterAll(AcceleratorTarget* target); 67 void UnregisterAll(AcceleratorTarget* target);
59 68
60 // Returns whether |accelerator| is already registered. 69 // Returns whether |accelerator| is already registered.
61 bool IsRegistered(const Accelerator& accelerator) const; 70 bool IsRegistered(const Accelerator& accelerator) const;
62 71
63 // Activate the target associated with the specified accelerator. 72 // Activate the target associated with the specified accelerator.
(...skipping 22 matching lines...) Expand all
86 95
87 AcceleratorManagerDelegate* delegate_; 96 AcceleratorManagerDelegate* delegate_;
88 AcceleratorMap accelerators_; 97 AcceleratorMap accelerators_;
89 98
90 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager); 99 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager);
91 }; 100 };
92 101
93 } // namespace ui 102 } // namespace ui
94 103
95 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_ 104 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_MANAGER_H_
OLDNEW
« no previous file with comments | « services/ui/ws/event_dispatcher.cc ('k') | ui/base/accelerators/accelerator_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698