Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/observer_list.h" | |
| 11 #include "ui/events/keycodes/keyboard_codes.h" | |
| 12 #include "ui/gfx/native_widget_types.h" | |
| 13 | |
| 14 namespace ui { | |
| 15 class Accelerator; | |
| 16 } | |
| 17 | |
| 18 namespace extensions { | |
| 19 | |
| 20 // Platform-neutral implementation of a class that keeps track of observers and | |
| 21 // monitors keystrokes. It relays messages to the appropriate observers when a | |
| 22 // global shortcut has been struck by the user. | |
| 23 class GlobalShortcutListener { | |
| 24 public: | |
| 25 class Observer { | |
| 26 public: | |
| 27 // Called when your global shortcut (|accelerator|) is struck. | |
| 28 virtual void OnKeyPressed(const ui::Accelerator& accelerator) = 0; | |
| 29 }; | |
| 30 | |
| 31 virtual ~GlobalShortcutListener(); | |
| 32 | |
| 33 static GlobalShortcutListener* GetInstance(); | |
| 34 | |
| 35 // Implemented by platform-specific implementations of this class. | |
| 36 virtual void StartListening() = 0; | |
| 37 virtual void StopListening() = 0; | |
| 38 | |
| 39 // Register an observer for when a certain |accelerator| is struck. | |
| 40 virtual void RegisterAccelerator( | |
| 41 const ui::Accelerator& accelerator, Observer* observer); | |
| 42 // Stop listening for the given |accelerator|. | |
| 43 virtual void UnregisterAccelerator( | |
| 44 const ui::Accelerator& accelerator, Observer* observer); | |
| 45 | |
| 46 protected: | |
| 47 GlobalShortcutListener(); | |
| 48 | |
| 49 // Called by platform specific implementations of this class whenever a key | |
|
Yoyo Zhou
2013/10/04 18:12:07
What I meant is here, it's only called for keys th
Finnur
2013/10/11 10:59:22
Good point. Added that.
| |
| 50 // is struck. | |
| 51 void NotifyKeyPressed(const ui::Accelerator& accelerator); | |
| 52 | |
| 53 // The map of accelerators that have been successfully registered as global | |
| 54 // shortcuts and their observer lists. | |
| 55 typedef ObserverList<Observer> Observers; | |
| 56 typedef std::map< ui::Accelerator, Observers* > AcceleratorMap; | |
| 57 AcceleratorMap accelerator_map_; | |
| 58 | |
| 59 private: | |
| 60 DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListener); | |
| 61 }; | |
| 62 | |
| 63 } // namespace extensions | |
| 64 | |
| 65 #endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_H_ | |
| OLD | NEW |