Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: chrome/browser/extensions/global_shortcut_listener_mac.h

Issue 60353008: Mac global keybindings (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <Carbon/Carbon.h>
11 #include <map>
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 // non-media key global keyboard shortcuts (eg. Command-Shift-1).
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.
57 // TODO(smus): Use the one in CommandService.
58 bool IsMediaKey(const ui::Accelerator& accelerator);
59
60 // Whether or not any media keys are currently registered.
61 bool AreMediaKeysRegistered();
62
38 // Whether this object is listening for global shortcuts. 63 // Whether this object is listening for global shortcuts.
39 bool is_listening_; 64 bool is_listening_;
40 65
66 // A counter representing the current hotkey identifier.
67 int hotkey_id_ = 0;
68
69 // A map of all hotkeys (media keys and shortcuts) mapping to their
70 // corresponding hotkey IDs. For quickly finding if an accelerator is
71 // registered.
72 typedef std::map<ui::Accelerator, int> HotKeyIdMap;
73 HotKeyIdMap hotkey_ids_;
74
75 // The inverse map for quickly looking up accelerators by hotkey id.
76 typedef std::map<int, ui::Accelerator> IdHotKeyMap;
77 IdHotKeyMap id_hotkeys_;
78
79 // Keyboard shortcut IDs to hotkeys map for unregistration.
80 typedef std::map<int, EventHotKeyRef> IdHotKeyRefMap;
81 IdHotKeyRefMap id_hotkey_refs_;
82
83 // Global shortcut listener tap used for intercepting mac media keys.
84 base::scoped_nsobject<GlobalShortcutListenerTap> tap_;
85
41 DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerMac); 86 DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerMac);
42 }; 87 };
43 88
44 } // namespace extensions 89 } // namespace extensions
45 90
46 #endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_ 91 #endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698