Chromium Code Reviews| Index: ui/gfx/win/singleton_hwnd_observer.cc |
| diff --git a/ui/gfx/win/singleton_hwnd_observer.cc b/ui/gfx/win/singleton_hwnd_observer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3b3c3097c4d0b725be40fd5d4da6ebf15fc1026c |
| --- /dev/null |
| +++ b/ui/gfx/win/singleton_hwnd_observer.cc |
| @@ -0,0 +1,42 @@ |
| +// Copyright (c) 2015 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. |
| + |
| +#include "ui/gfx/win/singleton_hwnd_observer.h" |
| + |
| +#include "ui/gfx/win/singleton_hwnd.h" |
| + |
| +namespace gfx { |
| + |
| +SingletonHwndObserver::SingletonHwndObserver(const WndProc& wnd_proc) : |
| + wnd_proc_(wnd_proc) { |
| + DCHECK(!wnd_proc.is_null()); |
| + SingletonHwnd::GetInstance()->AddObserver(this); |
| +} |
| + |
| +SingletonHwndObserver::~SingletonHwndObserver() { |
| + ClearWndProc(); |
|
sky
2015/04/28 13:20:34
Why do you need the ClearWndProc? Won't evertyhing
robliao
2015/04/28 14:11:55
We need to unregister from the SingletonHwnd in tw
sky
2015/04/28 16:45:46
I see it. You're taking is_null() to know when you
|
| +} |
| + |
| +void SingletonHwndObserver::ClearWndProc() { |
| + if (!wnd_proc_.is_null()) |
| + SingletonHwnd::GetInstance()->RemoveObserver(this); |
| + |
| + wnd_proc_.Reset(); |
| +} |
| + |
| +void SingletonHwndObserver::OnWndProc(HWND hwnd, |
| + UINT message, |
| + WPARAM wparam, |
| + LPARAM lparam) { |
| + if (wnd_proc_.is_null()) |
|
sky
2015/04/28 16:45:46
Shouldn't this be a DCHECK?
robliao
2015/04/28 22:14:10
Actually, even a DCHECK isn't necessary, as it wou
|
| + return; |
| + |
| + wnd_proc_.Run(hwnd, message, wparam, lparam); |
| + |
| + if (message == WM_NCDESTROY) { |
|
sky
2015/04/28 13:20:34
nit: no {}
robliao
2015/04/28 14:11:55
Done.
|
| + ClearWndProc(); |
| + } |
| +} |
| + |
| +} // namespace gfx |