Chromium Code Reviews| 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..1e1a4ad2628c361f4c28910edaa62d800b6af82a |
| --- /dev/null |
| +++ b/chrome/browser/extensions/global_shortcut_listener.h |
| @@ -0,0 +1,61 @@ |
| +// 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 "base/observer_list.h" |
| +#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
|
| + |
| +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 StartHooking() = 0; |
| + 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
|
| + |
| + // Register an observer for when a certain |accelerator| is struck. |
| + void RegisterAccelerator( |
| + const ui::Accelerator& accelerator, Observer* observer); |
| + // Stop listening for the given |accelerator|. |
| + void UnregisterAccelerator( |
| + const ui::Accelerator& accelerator, Observer* observer); |
| + |
| + protected: |
| + GlobalShortcutListener(); |
| + |
| + // Called by platform specific implementations of this class whenever a key |
| + // is struck. Returns true if there are observers listening for the given |
| + // |accelerator|, false otherwise. |
| + bool NotifyKeyPressed(const ui::Accelerator& accelerator); |
| + |
| + private: |
| + typedef ObserverList<Observer> Observers; |
| + typedef std::map< ui::Accelerator, Observers* > AcceleratorMap; |
| + AcceleratorMap accelerator_map_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListener); |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_H_ |