| 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 #include "ui/gfx/win/singleton_hwnd.h" | 5 #include "ui/gfx/win/singleton_hwnd.h" |
| 6 | 6 |
| 7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "ui/gfx/win/singleton_hwnd_observer.h" | 9 #include "ui/gfx/win/singleton_hwnd_observer.h" |
| 10 | 10 |
| 11 namespace gfx { | 11 namespace gfx { |
| 12 | 12 |
| 13 // static | 13 // static |
| 14 SingletonHwnd* SingletonHwnd::GetInstance() { | 14 SingletonHwnd* SingletonHwnd::GetInstance() { |
| 15 return base::Singleton<SingletonHwnd>::get(); | 15 return base::Singleton<SingletonHwnd>::get(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 BOOL SingletonHwnd::ProcessWindowMessage(HWND window, | 18 BOOL SingletonHwnd::ProcessWindowMessage(HWND window, |
| 19 UINT message, | 19 UINT message, |
| 20 WPARAM wparam, | 20 WPARAM wparam, |
| 21 LPARAM lparam, | 21 LPARAM lparam, |
| 22 LRESULT& result, | 22 LRESULT& result, |
| 23 DWORD msg_map_id) { | 23 DWORD msg_map_id) { |
| 24 FOR_EACH_OBSERVER(SingletonHwndObserver, | 24 for (SingletonHwndObserver& observer : observer_list_) |
| 25 observer_list_, | 25 observer.OnWndProc(window, message, wparam, lparam); |
| 26 OnWndProc(window, message, wparam, lparam)); | |
| 27 return false; | 26 return false; |
| 28 } | 27 } |
| 29 | 28 |
| 30 SingletonHwnd::SingletonHwnd() { | 29 SingletonHwnd::SingletonHwnd() { |
| 31 if (!base::MessageLoopForUI::IsCurrent()) { | 30 if (!base::MessageLoopForUI::IsCurrent()) { |
| 32 // Creating this window in (e.g.) a renderer inhibits shutdown on | 31 // Creating this window in (e.g.) a renderer inhibits shutdown on |
| 33 // Windows. See http://crbug.com/230122 and http://crbug.com/236039. | 32 // Windows. See http://crbug.com/230122 and http://crbug.com/236039. |
| 34 return; | 33 return; |
| 35 } | 34 } |
| 36 WindowImpl::Init(NULL, Rect()); | 35 WindowImpl::Init(NULL, Rect()); |
| 37 } | 36 } |
| 38 | 37 |
| 39 SingletonHwnd::~SingletonHwnd() { | 38 SingletonHwnd::~SingletonHwnd() { |
| 40 // WindowImpl will clean up the hwnd value on WM_NCDESTROY. | 39 // WindowImpl will clean up the hwnd value on WM_NCDESTROY. |
| 41 if (hwnd()) | 40 if (hwnd()) |
| 42 DestroyWindow(hwnd()); | 41 DestroyWindow(hwnd()); |
| 43 | 42 |
| 44 // Tell all of our current observers to clean themselves up. | 43 // Tell all of our current observers to clean themselves up. |
| 45 FOR_EACH_OBSERVER(SingletonHwndObserver, observer_list_, ClearWndProc()); | 44 for (SingletonHwndObserver& observer : observer_list_) |
| 45 observer.ClearWndProc(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void SingletonHwnd::AddObserver(SingletonHwndObserver* observer) { | 48 void SingletonHwnd::AddObserver(SingletonHwndObserver* observer) { |
| 49 observer_list_.AddObserver(observer); | 49 observer_list_.AddObserver(observer); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void SingletonHwnd::RemoveObserver(SingletonHwndObserver* observer) { | 52 void SingletonHwnd::RemoveObserver(SingletonHwndObserver* observer) { |
| 53 observer_list_.RemoveObserver(observer); | 53 observer_list_.RemoveObserver(observer); |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace gfx | 56 } // namespace gfx |
| OLD | NEW |