blob: 229b98aa6ed40eb552272340fd6395019779de2f [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2015 The Chromium Authors
robliao305070a072015-05-01 23:47:192// 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
9namespace gfx {
10
11SingletonHwndObserver::SingletonHwndObserver(const WndProc& wnd_proc)
12 : wnd_proc_(wnd_proc) {
13 DCHECK(!wnd_proc.is_null());
14 SingletonHwnd::GetInstance()->AddObserver(this);
15}
16
17SingletonHwndObserver::~SingletonHwndObserver() {
18 ClearWndProc();
19}
20
21void SingletonHwndObserver::ClearWndProc() {
22 if (!wnd_proc_.is_null()) {
23 SingletonHwnd::GetInstance()->RemoveObserver(this);
24 wnd_proc_.Reset();
25 }
26}
27
28void 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