OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_BASE_WIN_SINGLETON_HWND_H_ | 5 #ifndef UI_BASE_WIN_SINGLETON_HWND_H_ |
6 #define UI_BASE_WIN_SINGLETON_HWND_H_ | 6 #define UI_BASE_WIN_SINGLETON_HWND_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "ui/base/win/window_impl.h" |
15 | 16 |
16 template<typename T> struct DefaultSingletonTraits; | 17 template<typename T> struct DefaultSingletonTraits; |
17 | 18 |
18 namespace ui { | 19 namespace ui { |
19 | 20 |
20 // Singleton message-only HWND that allows interested clients to receive WM_* | 21 // Singleton message-only HWND that allows interested clients to receive WM_* |
21 // notifications. | 22 // notifications. |
22 class SingletonHwnd { | 23 class SingletonHwnd : public WindowImpl { |
23 public: | 24 public: |
24 static SingletonHwnd* GetInstance(); | 25 static SingletonHwnd* GetInstance(); |
25 | 26 |
26 // Observer interface for receiving Windows WM_* notifications. | 27 // Observer interface for receiving Windows WM_* notifications. |
27 class Observer { | 28 class Observer { |
28 public: | 29 public: |
29 virtual void OnWndProc(HWND hwnd, | 30 virtual void OnWndProc(HWND hwnd, |
30 UINT message, | 31 UINT message, |
31 WPARAM wparam, | 32 WPARAM wparam, |
32 LPARAM lparam) = 0; | 33 LPARAM lparam) = 0; |
33 }; | 34 }; |
34 | 35 |
35 // Add/remove observer to receive WM_* notifications. | 36 // Add/remove observer to receive WM_* notifications. |
36 void AddObserver(Observer* observer); | 37 void AddObserver(Observer* observer); |
37 void RemoveObserver(Observer* observer); | 38 void RemoveObserver(Observer* observer); |
38 | 39 |
39 // Windows callback for WM_* notifications. | 40 // Windows callback for WM_* notifications. |
40 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 41 virtual BOOL ProcessWindowMessage(HWND window, |
| 42 UINT message, |
| 43 WPARAM wparam, |
| 44 LPARAM lparam, |
| 45 LRESULT& result, |
| 46 DWORD msg_map_id) OVERRIDE; |
41 | 47 |
42 private: | 48 private: |
43 friend struct DefaultSingletonTraits<SingletonHwnd>; | 49 friend struct DefaultSingletonTraits<SingletonHwnd>; |
44 | 50 |
45 SingletonHwnd(); | 51 SingletonHwnd(); |
46 ~SingletonHwnd(); | 52 ~SingletonHwnd(); |
47 | 53 |
48 // Listener HWND for WM_* notifications. | |
49 HWND listener_window_; | |
50 | |
51 // List of registered observers. | 54 // List of registered observers. |
52 ObserverList<Observer> observer_list_; | 55 ObserverList<Observer> observer_list_; |
53 | 56 |
54 DISALLOW_COPY_AND_ASSIGN(SingletonHwnd); | 57 DISALLOW_COPY_AND_ASSIGN(SingletonHwnd); |
55 }; | 58 }; |
56 | 59 |
57 } // namespace ui | 60 } // namespace ui |
58 | 61 |
59 #endif // UI_BASE_WIN_SINGLETON_HWND_H_ | 62 #endif // UI_BASE_WIN_SINGLETON_HWND_H_ |
OLD | NEW |