blob: 703d2c48dce273ff60eb866e7af7eeaf55101b02 [file] [log] [blame]
[email protected]16d57d92011-11-15 02:27:261// Copyright (c) 2011 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.
4
5#ifndef UI_BASE_ACCELERATOR_MANAGER_H_
6#define UI_BASE_ACCELERATOR_MANAGER_H_
7#pragma once
8
9#include <list>
10#include <map>
11
12#include "base/basictypes.h"
13#include "ui/base/models/accelerator.h"
14#include "ui/base/ui_export.h"
15
16namespace ui {
17
18// The AcceleratorManger is used to handle keyboard accelerators.
19class UI_EXPORT AcceleratorManager {
20 public:
21 AcceleratorManager();
22 ~AcceleratorManager();
23
24 // Register a keyboard accelerator for the specified target. If multiple
25 // targets are registered for an accelerator, a target registered later has
26 // higher priority.
27 // Note that we are currently limited to accelerators that are either:
28 // - a key combination including Ctrl or Alt
29 // - the escape key
30 // - the enter key
31 // - any F key (F1, F2, F3 ...)
32 // - any browser specific keys (as available on special keyboards)
33 void Register(const Accelerator& accelerator, AcceleratorTarget* target);
34
35 // Unregister the specified keyboard accelerator for the specified target.
36 void Unregister(const Accelerator& accelerator, AcceleratorTarget* target);
37
38 // Unregister all keyboard accelerator for the specified target.
39 void UnregisterAll(AcceleratorTarget* target);
40
41 // Activate the target associated with the specified accelerator.
42 // First, AcceleratorPressed handler of the most recently registered target
43 // is called, and if that handler processes the event (i.e. returns true),
44 // this method immediately returns. If not, we do the same thing on the next
45 // target, and so on.
46 // Returns true if an accelerator was activated.
47 bool Process(const Accelerator& accelerator);
48
49 // Returns the AcceleratorTarget that should be activated for the specified
50 // keyboard accelerator, or NULL if no view is registered for that keyboard
51 // accelerator.
52 AcceleratorTarget* GetCurrentTarget(const Accelerator& accelertor) const;
53
54 private:
55 // The accelerators and associated targets.
56 typedef std::list<AcceleratorTarget*> AcceleratorTargetList;
57 typedef std::map<Accelerator, AcceleratorTargetList> AcceleratorMap;
58 AcceleratorMap accelerators_;
59
60 DISALLOW_COPY_AND_ASSIGN(AcceleratorManager);
61};
62
63} // namespace ui
64
65#endif // UI_BASE_ACCELERATOR_MANAGER_H_