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_GFX_WIN_SINGLETON_HWND_H_ | 5 #ifndef UI_GFX_WIN_SINGLETON_HWND_H_ |
6 #define UI_GFX_WIN_SINGLETON_HWND_H_ | 6 #define UI_GFX_WIN_SINGLETON_HWND_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "ui/gfx/win/window_impl.h" | 14 #include "ui/gfx/win/window_impl.h" |
15 | 15 |
16 template<typename T> struct DefaultSingletonTraits; | 16 template<typename T> struct DefaultSingletonTraits; |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 | 19 |
20 // Singleton message-only HWND that allows interested clients to receive WM_* | 20 // Singleton message-only HWND that allows interested clients to receive WM_* |
21 // notifications. | 21 // notifications. |
22 class SingletonHwnd : public WindowImpl { | 22 class GFX_EXPORT SingletonHwnd : public WindowImpl { |
23 public: | 23 public: |
24 static SingletonHwnd* GetInstance(); | 24 static SingletonHwnd* GetInstance(); |
25 | 25 |
26 // Observer interface for receiving Windows WM_* notifications. | 26 // Observer interface for receiving Windows WM_* notifications. |
27 class Observer { | 27 class Observer { |
28 public: | 28 public: |
29 virtual void OnWndProc(HWND hwnd, | 29 virtual void OnWndProc(HWND hwnd, |
30 UINT message, | 30 UINT message, |
31 WPARAM wparam, | 31 WPARAM wparam, |
32 LPARAM lparam) = 0; | 32 LPARAM lparam) = 0; |
33 }; | 33 }; |
34 | 34 |
35 // Creates the window used to receive the messages. Also called implicitly by | |
36 // AddObserver if the window has not been created before then. | |
37 void Init(); | |
sky
2013/10/03 18:01:22
Is there a way not to expose this? Could we move t
Finnur
2013/10/03 21:57:58
Sure, we can create the window in the constructor.
sky
2013/10/03 23:30:10
The constructor is only run on the first call to G
Finnur
2013/10/04 17:57:02
Done.
| |
38 | |
35 // Add/remove observer to receive WM_* notifications. | 39 // Add/remove observer to receive WM_* notifications. |
36 void AddObserver(Observer* observer); | 40 void AddObserver(Observer* observer); |
37 void RemoveObserver(Observer* observer); | 41 void RemoveObserver(Observer* observer); |
38 | 42 |
39 // Windows callback for WM_* notifications. | 43 // Windows callback for WM_* notifications. |
40 virtual BOOL ProcessWindowMessage(HWND window, | 44 virtual BOOL ProcessWindowMessage(HWND window, |
41 UINT message, | 45 UINT message, |
42 WPARAM wparam, | 46 WPARAM wparam, |
43 LPARAM lparam, | 47 LPARAM lparam, |
44 LRESULT& result, | 48 LRESULT& result, |
45 DWORD msg_map_id) OVERRIDE; | 49 DWORD msg_map_id) OVERRIDE; |
46 | 50 |
47 private: | 51 private: |
48 friend struct DefaultSingletonTraits<SingletonHwnd>; | 52 friend struct DefaultSingletonTraits<SingletonHwnd>; |
49 | 53 |
50 SingletonHwnd(); | 54 SingletonHwnd(); |
51 ~SingletonHwnd(); | 55 ~SingletonHwnd(); |
52 | 56 |
53 // List of registered observers. | 57 // List of registered observers. |
54 ObserverList<Observer> observer_list_; | 58 ObserverList<Observer> observer_list_; |
55 | 59 |
56 DISALLOW_COPY_AND_ASSIGN(SingletonHwnd); | 60 DISALLOW_COPY_AND_ASSIGN(SingletonHwnd); |
57 }; | 61 }; |
58 | 62 |
59 } // namespace gfx | 63 } // namespace gfx |
60 | 64 |
61 #endif // UI_GFX_WIN_SINGLETON_HWND_H_ | 65 #endif // UI_GFX_WIN_SINGLETON_HWND_H_ |
OLD | NEW |