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"
28 enum AcceleratorFlags
{
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)
37 // Used for accelerators that are useful only in debug mode.
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
52 class ATHENA_EXPORT AcceleratorHandler
{
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
{
63 // Returns an AcceleratorManager for global accelerators.
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
,
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 virtual void RegisterAccelerator(const AcceleratorData
& accelerator_data
,
86 AcceleratorHandler
* handler
) = 0;
87 virtual void UnregisterAccelerator(const AcceleratorData
& accelerator_data
,
88 AcceleratorHandler
* handler
) = 0;
90 // Enables/Disables accelerators that has a AF_DEBUG flag.
91 virtual void SetDebugAcceleratorsEnabled(bool enabled
) = 0;
96 #endif // ATHENA_INPUT_PUBLIC_ACCELERATOR_MANAGER_H_