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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/global_shortcut_listener_mac.h
===================================================================
--- chrome/browser/extensions/global_shortcut_listener_mac.h (revision 235137)
+++ chrome/browser/extensions/global_shortcut_listener_mac.h (working copy)
@@ -5,15 +5,25 @@
#ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_
#define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_MAC_H_
-#include "base/lazy_instance.h"
#include "chrome/browser/extensions/global_shortcut_listener.h"
+#include <map>
+#include <Carbon/Carbon.h>
+
+#include "base/lazy_instance.h"
+#include "base/mac/scoped_nsobject.h"
+
+@class GlobalShortcutListenerTap;
+
namespace extensions {
// Mac-specific implementation of the GlobalShortcutListener class that
// listens for global shortcuts. Handles basic keyboard intercepting and
// forwards its output to the base class for processing.
-// TODO(finnur/smus): Implement this class.
+//
+// Uses an event tap for intercepting media keys (PlayPause, NextTrack,
+// PreviousTrack). Also uses the Carbon RegisterEventHotKey API for binding to
+// 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.
class GlobalShortcutListenerMac : public GlobalShortcutListener {
public:
virtual ~GlobalShortcutListenerMac();
@@ -21,6 +31,10 @@
virtual void StartListening() OVERRIDE;
virtual void StopListening() OVERRIDE;
+ // Keyboard event callbacks.
+ bool OnKeyEvent(EventHotKeyID hotKeyID);
+ bool OnMediaKeyEvent(ui::KeyboardCode keyCode);
+
private:
friend struct base::DefaultLazyInstanceTraits<GlobalShortcutListenerMac>;
@@ -35,9 +49,36 @@
const ui::Accelerator& accelerator,
GlobalShortcutListener::Observer* observer) OVERRIDE;
+ // Mac-specific function for registering a hotkey.
+ void RegisterHotKey(const ui::Accelerator& accelerator);
+ void UnregisterHotKey(const ui::Accelerator& accelerator);
+
+ // 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.
+ bool IsMediaKey(const ui::Accelerator& accelerator);
+
// Whether this object is listening for global shortcuts.
bool is_listening_;
+ // A counter representing the current hotkey identifier.
+ int hotkey_id_ = 0;
+
+ // A map of all hotkeys (media keys and shortcuts) mapping to their
+ // corresponding hotkey IDs. For quickly finding if an accelerator is
+ // registered.
+ 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.
+ HotKeyIdMap hotkey_ids_;
+
+ // The inverse map for quickly looking up accelerators by hotkey id.
+ typedef std::map< int, ui::Accelerator > IdHotKeyMap;
+ IdHotKeyMap id_hotkeys_;
+
+ // Keyboard shortcut IDs to hotkeys map for unregistration.
+ typedef std::map< int, EventHotKeyRef > IdHotKeyRefMap;
+ IdHotKeyRefMap id_hotkey_refs_;
+
+ // Global shortcut listener tap used for intercepting mac media keys.
+ base::scoped_nsobject<GlobalShortcutListenerTap> tap_;
+
DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerMac);
};

Powered by Google App Engine
This is Rietveld 408576698