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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_WIN_H_
6#define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_WIN_H_
7
8#include <windows.h>
9
10#include "chrome/browser/extensions/global_shortcut_listener.h"
11#include "ui/gfx/win/singleton_hwnd.h"
12
13namespace extensions {
14
15// Windows-specific implementation of the GlobalShortcutListener class that
16// listens for global shortcuts. Handles setting up a keyboard hook and
17// forwarding its output to the base class for processing.
18class GlobalShortcutListenerWin : public GlobalShortcutListener,
19                                  public gfx::SingletonHwnd::Observer {
20 public:
21  GlobalShortcutListenerWin();
22  virtual ~GlobalShortcutListenerWin();
23
24 private:
25  // The implementation of our Window Proc, called by SingletonHwnd.
26  virtual void OnWndProc(HWND hwnd,
27                         UINT message,
28                         WPARAM wparam,
29                         LPARAM lparam) OVERRIDE;
30
31  // GlobalShortcutListener implementation.
32  virtual void StartListening() OVERRIDE;
33  virtual void StopListening() OVERRIDE;
34  virtual bool RegisterAcceleratorImpl(
35      const ui::Accelerator& accelerator) OVERRIDE;
36  virtual void UnregisterAcceleratorImpl(
37      const ui::Accelerator& accelerator) OVERRIDE;
38
39  // Whether this object is listening for global shortcuts.
40  bool is_listening_;
41
42  // A map of registered accelerators and their registration ids.
43  typedef std::map<ui::Accelerator, int> HotkeyIdMap;
44  HotkeyIdMap hotkey_ids_;
45
46  DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerWin);
47};
48
49}  // namespace extensions
50
51#endif  // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_WIN_H_
52