Bug 1861709 replace AudioCallbackDriver::ThreadRunning() assertions that mean to...
[gecko.git] / widget / windows / WindowHook.h
blob1d1f4b02da0482fcdbdced785529f5d186c387b2
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef __mozilla_WindowHook_h__
8 #define __mozilla_WindowHook_h__
10 #include <windows.h>
12 #include <nsHashKeys.h>
13 #include <nsClassHashtable.h>
14 #include <nsTArray.h>
16 #include "nsAppShell.h"
18 class nsWindow;
20 namespace mozilla {
21 namespace widget {
23 struct MSGResult;
25 class WindowHook {
26 public:
27 // It is expected that most callbacks will return false
28 typedef bool (*Callback)(void* aContext, HWND hWnd, UINT nMsg, WPARAM wParam,
29 LPARAM lParam, LRESULT* aResult);
31 nsresult AddHook(UINT nMsg, Callback callback, void* context);
32 nsresult RemoveHook(UINT nMsg, Callback callback, void* context);
33 nsresult AddMonitor(UINT nMsg, Callback callback, void* context);
34 nsresult RemoveMonitor(UINT nMsg, Callback callback, void* context);
36 private:
37 struct CallbackData {
38 Callback cb;
39 void* context;
41 CallbackData() : cb(nullptr), context(nullptr) {}
42 CallbackData(Callback cb, void* ctx) : cb(cb), context(ctx) {}
43 bool Invoke(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam,
44 LRESULT* aResult);
45 bool operator==(const CallbackData& rhs) const {
46 return cb == rhs.cb && context == rhs.context;
48 bool operator!=(const CallbackData& rhs) const { return !(*this == rhs); }
49 explicit operator bool() const { return !!cb; }
52 typedef nsTArray<CallbackData> CallbackDataArray;
53 struct MessageData {
54 UINT nMsg;
55 CallbackData hook;
56 CallbackDataArray monitors;
59 bool Notify(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
60 MSGResult& aResult);
62 MessageData* Lookup(UINT nMsg);
63 MessageData* LookupOrCreate(UINT nMsg);
64 void DeleteIfEmpty(MessageData* data);
66 typedef nsTArray<MessageData> MessageDataArray;
67 MessageDataArray mMessageData;
69 // For Notify
70 friend class ::nsWindow;
73 } // namespace widget
74 } // namespace mozilla
76 #endif // __mozilla_WindowHook_h__