Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
robliao | 305070a07 | 2015-05-01 23:47:19 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ui/gfx/win/singleton_hwnd_observer.h" |
| 6 | |
| 7 | #include "ui/gfx/win/singleton_hwnd.h" |
| 8 | |
| 9 | namespace gfx { |
| 10 | |
| 11 | SingletonHwndObserver::SingletonHwndObserver(const WndProc& wnd_proc) |
| 12 | : wnd_proc_(wnd_proc) { |
| 13 | DCHECK(!wnd_proc.is_null()); |
| 14 | SingletonHwnd::GetInstance()->AddObserver(this); |
| 15 | } |
| 16 | |
| 17 | SingletonHwndObserver::~SingletonHwndObserver() { |
| 18 | ClearWndProc(); |
| 19 | } |
| 20 | |
| 21 | void SingletonHwndObserver::ClearWndProc() { |
| 22 | if (!wnd_proc_.is_null()) { |
| 23 | SingletonHwnd::GetInstance()->RemoveObserver(this); |
| 24 | wnd_proc_.Reset(); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | void SingletonHwndObserver::OnWndProc(HWND hwnd, |
| 29 | UINT message, |
| 30 | WPARAM wparam, |
| 31 | LPARAM lparam) { |
| 32 | wnd_proc_.Run(hwnd, message, wparam, lparam); |
| 33 | } |
| 34 | |
| 35 | } // namespace gfx |