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 "base/observer_list.h" | |
| 9 #include "ui/base/keycodes/keyboard_codes.h" | |
|
zhchbin
2013/09/20 07:49:23
This file has been moved from base to events. s/ba
| |
| 10 | |
| 11 namespace ui { | |
| 12 class Accelerator; | |
| 13 } | |
| 14 | |
| 15 namespace extensions { | |
| 16 | |
| 17 // Platform-neutral implementation of a class that keeps track of observers and | |
| 18 // monitors keystrokes. It relays messages to the appropriate observers when a | |
| 19 // global shortcut has been struck by the user. | |
| 20 class GlobalShortcutListener { | |
| 21 public: | |
| 22 class Observer { | |
| 23 public: | |
| 24 // Called when your global shortcut (|accelerator|) is struck. | |
| 25 virtual void OnKeyPressed(const ui::Accelerator& accelerator) = 0; | |
| 26 }; | |
| 27 | |
| 28 virtual ~GlobalShortcutListener(); | |
| 29 | |
| 30 static GlobalShortcutListener* GetInstance(); | |
| 31 | |
| 32 // Implemented by platform-specific implementations of this class. | |
| 33 virtual void StartHooking() = 0; | |
| 34 virtual void StopHooking() = 0; | |
|
zhchbin
2013/09/20 07:49:23
Hooking seems a little window-specific. How about
Finnur
2013/09/20 13:01:12
Good point.
On 2013/09/20 07:49:23, zhchbin wrote
| |
| 35 | |
| 36 // Register an observer for when a certain |accelerator| is struck. | |
| 37 void RegisterAccelerator( | |
| 38 const ui::Accelerator& accelerator, Observer* observer); | |
| 39 // Stop listening for the given |accelerator|. | |
| 40 void UnregisterAccelerator( | |
| 41 const ui::Accelerator& accelerator, Observer* observer); | |
| 42 | |
| 43 protected: | |
| 44 GlobalShortcutListener(); | |
| 45 | |
| 46 // Called by platform specific implementations of this class whenever a key | |
| 47 // is struck. Returns true if there are observers listening for the given | |
| 48 // |accelerator|, false otherwise. | |
| 49 bool NotifyKeyPressed(const ui::Accelerator& accelerator); | |
| 50 | |
| 51 private: | |
| 52 typedef ObserverList<Observer> Observers; | |
| 53 typedef std::map< ui::Accelerator, Observers* > AcceleratorMap; | |
| 54 AcceleratorMap accelerator_map_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListener); | |
| 57 }; | |
| 58 | |
| 59 } // namespace extensions | |
| 60 | |
| 61 #endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_H_ | |
| OLD | NEW |