#include "chrome/browser/extensions/global_shortcut_listener_win.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/win/win_util.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
+#include "ui/gfx/win/singleton_hwnd.h"
using content::BrowserThread;
void GlobalShortcutListenerWin::StartListening() {
DCHECK(!is_listening_); // Don't start twice.
DCHECK(!hotkey_ids_.empty()); // Also don't start if no hotkey is registered.
- gfx::SingletonHwnd::GetInstance()->AddObserver(this);
+ singleton_hwnd_observer_.reset(new gfx::SingletonHwndObserver(
+ base::Bind(
+ &GlobalShortcutListenerWin::OnWndProc, base::Unretained(this))));
+
is_listening_ = true;
}
void GlobalShortcutListenerWin::StopListening() {
DCHECK(is_listening_); // No point if we are not already listening.
DCHECK(hotkey_ids_.empty()); // Make sure the map is clean before ending.
- gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
+ singleton_hwnd_observer_.reset(nullptr);
is_listening_ = false;
}
#include <windows.h>
+#include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/global_shortcut_listener.h"
#include "ui/gfx/win/singleton_hwnd.h"
+#include "ui/gfx/win/singleton_hwnd_observer.h"
namespace extensions {
// Windows-specific implementation of the GlobalShortcutListener class that
// listens for global shortcuts. Handles setting up a keyboard hook and
// forwarding its output to the base class for processing.
-class GlobalShortcutListenerWin : public GlobalShortcutListener,
- public gfx::SingletonHwnd::Observer {
+class GlobalShortcutListenerWin : public GlobalShortcutListener {
public:
GlobalShortcutListenerWin();
virtual ~GlobalShortcutListenerWin();
private:
- // The implementation of our Window Proc, called by SingletonHwnd.
- virtual void OnWndProc(HWND hwnd,
- UINT message,
- WPARAM wparam,
- LPARAM lparam) override;
+ // The implementation of our Window Proc, called by SingletonHwndObserver.
+ void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
// GlobalShortcutListener implementation.
virtual void StartListening() override;
typedef std::map<ui::Accelerator, int> HotkeyIdMap;
HotkeyIdMap hotkey_ids_;
+ scoped_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_;
+
DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerWin);
};