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..76832a94904966dbde966c6f67e00dca96fa9096 |
| --- /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 |
|
Yoyo Zhou
2013/10/04 18:12:07
What I meant is here, it's only called for keys th
Finnur
2013/10/11 10:59:22
Good point. Added that.
|
| + // is struck. |
| + 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_ |