Chromium Code Reviews| Index: ui/base/win/singleton_hwnd.h |
| =================================================================== |
| --- ui/base/win/singleton_hwnd.h (revision 0) |
| +++ ui/base/win/singleton_hwnd.h (revision 0) |
| @@ -0,0 +1,49 @@ |
| +// Copyright (c) 2012 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 UI_GFX_SINGLETON_HWND_H_ |
| +#define UI_GFX_SINGLETON_HWND_H_ |
|
tfarina
2012/02/08 20:34:55
nit: UI_BASE_WIN_SINGLETON_HWND_H_
asvitkine_google
2012/02/08 21:04:57
Done.
|
| +#pragma once |
| + |
| +#include <windows.h> |
| +#include <vector> |
|
tfarina
2012/02/08 20:34:55
nit: I'd put a blank line between windows.h and ve
asvitkine_google
2012/02/08 21:04:57
I've seen a different review go the other way - la
|
| + |
| +#include "base/callback_forward.h" |
| +#include "base/basictypes.h" |
|
tfarina
2012/02/08 20:34:55
sort.
asvitkine_google
2012/02/08 21:04:57
Done.
|
| +#include "base/memory/singleton.h" |
| + |
| +namespace gfx { |
|
tfarina
2012/02/08 20:34:55
nit: namespace ui instead?
asvitkine_google
2012/02/08 21:04:57
Done.
|
| + |
| +typedef base::Callback<void(HWND, UINT, WPARAM, LPARAM)> WndProcCallback; |
| + |
| +// Singleton HWND that allows interested clients to receive WM_* notifications. |
| +class SingletonHwnd { |
| + public: |
| + // Singleton getter. |
| + static SingletonHwnd* GetInstance(); |
| + |
| + // Registers a listener callback for WM_* notifications. |
| + void RegisterListener(WndProcCallback& callback); |
| + |
| + // Windows callback for WM_* notifications. |
| + void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
| + |
| + private: |
| + // Listener HWND for WM_* notifications. |
| + HWND listener_window_; |
| + |
| + // List of registers listener callbacks. |
| + std::vector<WndProcCallback> listeners_; |
| + |
| + SingletonHwnd(); |
| + ~SingletonHwnd(); |
| + |
| + friend struct DefaultSingletonTraits<SingletonHwnd>; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SingletonHwnd); |
| +}; |
| + |
| +} // namespace gfx |
| + |
| +#endif // UI_GFX_SINGLETON_HWND_H_ |