Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 UI_BASE_WIN_SINGLETON_HWND_H_ | |
| 6 #define UI_BASE_WIN_SINGLETON_HWND_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <windows.h> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/callback_forward.h" | |
| 14 | |
| 15 template<typename T> struct DefaultSingletonTraits; | |
| 16 | |
| 17 namespace ui { | |
| 18 | |
| 19 typedef base::Callback<void(HWND, UINT, WPARAM, LPARAM)> WndProcCallback; | |
| 20 | |
| 21 // Singleton message-only HWND that allows interested clients to receive WM_* | |
| 22 // notifications. | |
|
msw
2012/02/15 00:33:16
Note that not all WM_* messages are supported; poi
asvitkine_google
2012/02/15 15:10:44
Done.
| |
| 23 class SingletonHwnd { | |
|
msw
2012/02/15 00:33:16
Why not use/extend existing code like MessagePumpO
asvitkine_google
2012/02/15 15:10:44
I'm not familiar with that class... from a quick g
msw
2012/02/15 19:23:28
You're creating an HWND to listen for arbitrary WM
| |
| 24 public: | |
| 25 // Singleton getter. | |
|
msw
2012/02/15 00:33:16
nit: remove obvious comment.
asvitkine_google
2012/02/15 15:10:44
Done.
| |
| 26 static SingletonHwnd* GetInstance(); | |
| 27 | |
| 28 // Registers a listener callback for WM_* notifications. | |
|
msw
2012/02/15 00:33:16
Did you consider using [Add|Remove]Observer termin
asvitkine_google
2012/02/15 15:10:44
You're right - I think base/observer_list.h is the
| |
| 29 void RegisterListener(const WndProcCallback& callback); | |
|
msw
2012/02/15 00:33:16
Is there no way to UnregisterListener?
asvitkine_google
2012/02/15 15:10:44
Added.
| |
| 30 | |
| 31 // Windows callback for WM_* notifications. | |
| 32 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | |
| 33 | |
| 34 private: | |
| 35 friend struct DefaultSingletonTraits<SingletonHwnd>; | |
| 36 | |
| 37 SingletonHwnd(); | |
| 38 ~SingletonHwnd(); | |
| 39 | |
| 40 // Listener HWND for WM_* notifications. | |
| 41 HWND listener_window_; | |
| 42 | |
| 43 // List of registered listener callbacks. | |
| 44 std::vector<WndProcCallback> listeners_; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(SingletonHwnd); | |
| 47 }; | |
| 48 | |
| 49 } // namespace ui | |
| 50 | |
| 51 #endif // UI_BASE_WIN_SINGLETON_HWND_H_ | |
| OLD | NEW |