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

Unified Diff: chrome/browser/extensions/global_shortcut_listener.h

Issue 23812010: Implement first part of supporting global extension commands. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gclient sync Created 7 years, 2 months 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.h
diff --git a/chrome/browser/extensions/global_shortcut_listener.h b/chrome/browser/extensions/global_shortcut_listener.h
new file mode 100644
index 0000000000000000000000000000000000000000..4ca692124c7f86990e97800eaf410a1ed1fddfb9
--- /dev/null
+++ b/chrome/browser/extensions/global_shortcut_listener.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_H_
+#define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_H_
+
+#include <map>
+
+#include "base/observer_list.h"
+#include "ui/events/keycodes/keyboard_codes.h"
+#include "ui/gfx/native_widget_types.h"
+
+namespace ui {
+class Accelerator;
+}
+
+namespace extensions {
+
+// Platform-neutral implementation of a class that keeps track of observers and
+// monitors keystrokes. It relays messages to the appropriate observers when a
+// global shortcut has been struck by the user.
+class GlobalShortcutListener {
+ public:
+ class Observer {
+ public:
+ // Called when your global shortcut (|accelerator|) is struck.
+ virtual void OnKeyPressed(const ui::Accelerator& accelerator) = 0;
+ };
+
+ virtual ~GlobalShortcutListener();
+
+ static GlobalShortcutListener* GetInstance();
+
+ // Implemented by platform-specific implementations of this class.
+ virtual void StartListening() = 0;
+ virtual void StopListening() = 0;
+
+ // Register an observer for when a certain |accelerator| is struck.
+ virtual void RegisterAccelerator(
+ const ui::Accelerator& accelerator, Observer* observer);
+ // Stop listening for the given |accelerator|.
+ virtual void UnregisterAccelerator(
+ const ui::Accelerator& accelerator, Observer* observer);
+
+ protected:
+ GlobalShortcutListener();
+
+ // Called by platform specific implementations of this class whenever a key
+ // is struck. Only called for keys that have observers registered.
+ void NotifyKeyPressed(const ui::Accelerator& accelerator);
+
+ // The map of accelerators that have been successfully registered as global
+ // shortcuts and their observer lists.
+ typedef ObserverList<Observer> Observers;
+ typedef std::map< ui::Accelerator, Observers* > AcceleratorMap;
+ AcceleratorMap accelerator_map_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListener);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_H_
« no previous file with comments | « chrome/browser/extensions/extension_keybinding_registry.cc ('k') | chrome/browser/extensions/global_shortcut_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698