Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / input / public / accelerator_manager.h
blobb572c50f753d501de7765fa0c0786b3b9cc74296
1 // Copyright 2014 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 ATHENA_INPUT_PUBLIC_ACCELERATOR_MANAGER_H_
6 #define ATHENA_INPUT_PUBLIC_ACCELERATOR_MANAGER_H_
8 #include "athena/athena_export.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/events/keycodes/keyboard_codes.h"
12 namespace ui {
13 class Accelerator;
16 namespace views {
17 class FocusManager;
20 namespace athena {
22 enum TriggerEvent {
23 TRIGGER_ON_PRESS,
24 TRIGGER_ON_RELEASE,
27 // Accelerator flags.
28 enum AcceleratorFlags {
29 AF_NONE = 0,
30 // Used for accelerators that should not be fired on auto repeated
31 // key event, such as toggling fullscrren.
32 AF_NON_AUTO_REPEATABLE = 1 << 0,
33 // Most key events are sent to applications first as they may
34 // want to consume them. Reserverd accelerators are reserved for OS
35 // and cannot be consumed by apps. (such as window cycling)
36 AF_RESERVED = 1 << 1,
37 // Used for accelerators that are useful only in debug mode.
38 AF_DEBUG = 1 << 2,
41 struct AcceleratorData {
42 // true if the accelerator should be triggered upon ui::ET_KEY_PRESSED
43 TriggerEvent trigger_event;
44 ui::KeyboardCode keycode; // KeyEvent event flags.
45 int keyevent_flags; // Combination of ui::KeyEventFlags
46 int command_id; // ID to distinguish
47 int accelerator_flags; // Combination of AcceleratorFlags;
50 // An interface that implements behavior for the set of
51 // accelerators.
52 class ATHENA_EXPORT AcceleratorHandler {
53 public:
54 virtual ~AcceleratorHandler() {}
56 virtual bool IsCommandEnabled(int command_id) const = 0;
57 virtual bool OnAcceleratorFired(int command_id,
58 const ui::Accelerator& accelerator) = 0;
61 class ATHENA_EXPORT AcceleratorManager {
62 public:
63 // Returns an AccelerarManager for global acelerators.
64 static AcceleratorManager* Get();
66 // Creates an AcceleratorManager for application windows that
67 // define their own accelerators.
68 static scoped_ptr<AcceleratorManager> CreateForFocusManager(
69 views::FocusManager* focus_manager);
71 virtual ~AcceleratorManager() {}
73 // Tells if the accelerator is registered with the given flag. If
74 // flags is AF_NONE, it simply tells if the accelerator is
75 // registered with any flags.
76 virtual bool IsRegistered(const ui::Accelerator& accelerator,
77 int flags) const = 0;
79 // Register accelerators and its handler that will be invoked when
80 // one of accelerator is fired.
81 virtual void RegisterAccelerators(const AcceleratorData accelerators[],
82 size_t num_accelerators,
83 AcceleratorHandler* handler) = 0;
85 // Enables/Disables accelerators that has a AF_DEBUG flag.
86 virtual void SetDebugAcceleratorsEnabled(bool enabled) = 0;
89 } // namespace athena
91 #endif // ATHENA_INPUT_PUBLIC_ACCELERATOR_MANAGER_H_