Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/extensions/global_shortcut_listener.h" | |
| 9 | |
| 10 #include <map> | |
| 11 #include <Carbon/Carbon.h> | |
| 12 | |
| 8 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 9 #include "chrome/browser/extensions/global_shortcut_listener.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 | |
| 16 @class GlobalShortcutListenerTap; | |
| 10 | 17 |
| 11 namespace extensions { | 18 namespace extensions { |
| 12 | 19 |
| 13 // Mac-specific implementation of the GlobalShortcutListener class that | 20 // Mac-specific implementation of the GlobalShortcutListener class that |
| 14 // listens for global shortcuts. Handles basic keyboard intercepting and | 21 // listens for global shortcuts. Handles basic keyboard intercepting and |
| 15 // forwards its output to the base class for processing. | 22 // forwards its output to the base class for processing. |
| 16 // TODO(finnur/smus): Implement this class. | 23 // |
| 24 // Uses an event tap for intercepting media keys (PlayPause, NextTrack, | |
| 25 // PreviousTrack). Also uses the Carbon RegisterEventHotKey API for binding to | |
| 26 // global keyboard shortcuts. | |
|
Finnur
2013/11/19 13:10:05
nit: Add 'other' in front of 'global' or 'non-medi
smus
2013/11/20 04:28:51
Done.
| |
| 17 class GlobalShortcutListenerMac : public GlobalShortcutListener { | 27 class GlobalShortcutListenerMac : public GlobalShortcutListener { |
| 18 public: | 28 public: |
| 19 virtual ~GlobalShortcutListenerMac(); | 29 virtual ~GlobalShortcutListenerMac(); |
| 20 | 30 |
| 21 virtual void StartListening() OVERRIDE; | 31 virtual void StartListening() OVERRIDE; |
| 22 virtual void StopListening() OVERRIDE; | 32 virtual void StopListening() OVERRIDE; |
| 23 | 33 |
| 34 // Keyboard event callbacks. | |
| 35 bool OnKeyEvent(EventHotKeyID hotKeyID); | |
| 36 bool OnMediaKeyEvent(ui::KeyboardCode keyCode); | |
| 37 | |
| 24 private: | 38 private: |
| 25 friend struct base::DefaultLazyInstanceTraits<GlobalShortcutListenerMac>; | 39 friend struct base::DefaultLazyInstanceTraits<GlobalShortcutListenerMac>; |
| 26 | 40 |
| 27 GlobalShortcutListenerMac(); | 41 GlobalShortcutListenerMac(); |
| 28 | 42 |
| 29 // Register an |accelerator| with the particular |observer|. | 43 // Register an |accelerator| with the particular |observer|. |
| 30 virtual void RegisterAccelerator( | 44 virtual void RegisterAccelerator( |
| 31 const ui::Accelerator& accelerator, | 45 const ui::Accelerator& accelerator, |
| 32 GlobalShortcutListener::Observer* observer) OVERRIDE; | 46 GlobalShortcutListener::Observer* observer) OVERRIDE; |
| 33 // Unregister an |accelerator| with the particular |observer|. | 47 // Unregister an |accelerator| with the particular |observer|. |
| 34 virtual void UnregisterAccelerator( | 48 virtual void UnregisterAccelerator( |
| 35 const ui::Accelerator& accelerator, | 49 const ui::Accelerator& accelerator, |
| 36 GlobalShortcutListener::Observer* observer) OVERRIDE; | 50 GlobalShortcutListener::Observer* observer) OVERRIDE; |
| 37 | 51 |
| 52 // Mac-specific function for registering a hotkey. | |
| 53 void RegisterHotKey(const ui::Accelerator& accelerator); | |
| 54 void UnregisterHotKey(const ui::Accelerator& accelerator); | |
| 55 | |
| 56 // Determine if a key is a media key or not. | |
|
Finnur
2013/11/19 13:10:05
Add a TODO(smus): Use the one in CommandService.
.
smus
2013/11/20 04:28:51
Done.
| |
| 57 bool IsMediaKey(const ui::Accelerator& accelerator); | |
| 58 | |
| 38 // Whether this object is listening for global shortcuts. | 59 // Whether this object is listening for global shortcuts. |
| 39 bool is_listening_; | 60 bool is_listening_; |
| 40 | 61 |
| 62 // A counter representing the current hotkey identifier. | |
| 63 int hotkey_id_ = 0; | |
| 64 | |
| 65 // A map of all hotkeys (media keys and shortcuts) mapping to their | |
| 66 // corresponding hotkey IDs. For quickly finding if an accelerator is | |
| 67 // registered. | |
| 68 typedef std::map< ui::Accelerator, int > HotKeyIdMap; | |
|
Robert Sesek
2013/11/19 18:34:58
nit: no space inside <>
smus
2013/11/20 04:28:51
Done.
| |
| 69 HotKeyIdMap hotkey_ids_; | |
| 70 | |
| 71 // The inverse map for quickly looking up accelerators by hotkey id. | |
| 72 typedef std::map< int, ui::Accelerator > IdHotKeyMap; | |
| 73 IdHotKeyMap id_hotkeys_; | |
| 74 | |
| 75 // Keyboard shortcut IDs to hotkeys map for unregistration. | |
| 76 typedef std::map< int, EventHotKeyRef > IdHotKeyRefMap; | |
| 77 IdHotKeyRefMap id_hotkey_refs_; | |
| 78 | |
| 79 // Global shortcut listener tap used for intercepting mac media keys. | |
| 80 base::scoped_nsobject<GlobalShortcutListenerTap> tap_; | |
| 81 | |
| 41 DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerMac); | 82 DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerMac); |
| 42 }; | 83 }; |
| 43 | 84 |
| 44 } // namespace extensions | 85 } // namespace extensions |
| 45 | 86 |
| 46 #endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_ | 87 #endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_ |
| OLD | NEW |