[go: nahoru, domu]

blob: 7342102211c5362baa0031b1aa6c55e352c28a9c [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#ifndef UI_GFX_WIN_SINGLETON_HWND_OBSERVER_H_
6#define UI_GFX_WIN_SINGLETON_HWND_OBSERVER_H_
7
8#include <windows.h>
9
Avi Drissmanc149c162023-01-12 02:16:5910#include "base/functional/callback.h"
robliao305070a072015-05-01 23:47:1911#include "ui/gfx/gfx_export.h"
12
13namespace gfx {
14
15class SingletonHwnd;
16
17// Singleton lifetime management is tricky. This observer handles the correct
18// cleanup if either the SingletonHwnd or forwarded object is destroyed first.
Tommy Steimel2d655f62019-01-11 06:25:4419// Note that if you want to register a hot key on the SingletonHwnd, you need to
20// use a SingletonHwndHotKeyObserver instead for each hot key.
robliao305070a072015-05-01 23:47:1921class GFX_EXPORT SingletonHwndObserver {
22 public:
Sylvain Defresne13616442019-10-01 17:12:2623 using WndProc = base::RepeatingCallback<void(HWND, UINT, WPARAM, LPARAM)>;
robliao305070a072015-05-01 23:47:1924
25 explicit SingletonHwndObserver(const WndProc& wnd_proc);
Peter Boströmc8c12352021-09-21 23:37:1526
27 SingletonHwndObserver(const SingletonHwndObserver&) = delete;
28 SingletonHwndObserver& operator=(const SingletonHwndObserver&) = delete;
29
robliao305070a072015-05-01 23:47:1930 ~SingletonHwndObserver();
31
32 private:
33 friend class SingletonHwnd;
34
35 void ClearWndProc();
36 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
37
38 WndProc wnd_proc_;
robliao305070a072015-05-01 23:47:1939};
40
41} // namespace gfx
42
43#endif // UI_GFX_WIN_SINGLETON_HWND_OBSERVER_H_