| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef ATHENA_INPUT_PUBLIC_ACCELERATOR_MANAGER_H_ | |
| 6 #define ATHENA_INPUT_PUBLIC_ACCELERATOR_MANAGER_H_ | |
| 7 | |
| 8 #include "athena/athena_export.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "ui/events/keycodes/keyboard_codes.h" | |
| 11 | |
| 12 namespace ui { | |
| 13 class Accelerator; | |
| 14 } | |
| 15 | |
| 16 namespace views { | |
| 17 class FocusManager; | |
| 18 } | |
| 19 | |
| 20 namespace athena { | |
| 21 | |
| 22 enum TriggerEvent { | |
| 23 TRIGGER_ON_PRESS, | |
| 24 TRIGGER_ON_RELEASE, | |
| 25 }; | |
| 26 | |
| 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, | |
| 39 }; | |
| 40 | |
| 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; | |
| 48 }; | |
| 49 | |
| 50 // An interface that implements behavior for the set of | |
| 51 // accelerators. | |
| 52 class ATHENA_EXPORT AcceleratorHandler { | |
| 53 public: | |
| 54 virtual ~AcceleratorHandler() {} | |
| 55 | |
| 56 virtual bool IsCommandEnabled(int command_id) const = 0; | |
| 57 virtual bool OnAcceleratorFired(int command_id, | |
| 58 const ui::Accelerator& accelerator) = 0; | |
| 59 }; | |
| 60 | |
| 61 class ATHENA_EXPORT AcceleratorManager { | |
| 62 public: | |
| 63 // Returns an AcceleratorManager for global accelerators. | |
| 64 static AcceleratorManager* Get(); | |
| 65 | |
| 66 // Creates an AcceleratorManager for application windows that | |
| 67 // define their own accelerators. | |
| 68 static scoped_ptr<AcceleratorManager> CreateForFocusManager( | |
| 69 views::FocusManager* focus_manager); | |
| 70 | |
| 71 virtual ~AcceleratorManager() {} | |
| 72 | |
| 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; | |
| 78 | |
| 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; | |
| 84 | |
| 85 virtual void RegisterAccelerator(const AcceleratorData& accelerator_data, | |
| 86 AcceleratorHandler* handler) = 0; | |
| 87 virtual void UnregisterAccelerator(const AcceleratorData& accelerator_data, | |
| 88 AcceleratorHandler* handler) = 0; | |
| 89 | |
| 90 // Enables/Disables accelerators that has a AF_DEBUG flag. | |
| 91 virtual void SetDebugAcceleratorsEnabled(bool enabled) = 0; | |
| 92 }; | |
| 93 | |
| 94 } // namespace athena | |
| 95 | |
| 96 #endif // ATHENA_INPUT_PUBLIC_ACCELERATOR_MANAGER_H_ | |
| OLD | NEW |