Bug 1777519 [wpt PR 34660] - Avoid OSError from --kill-safari stat'ing random paths...
[gecko.git] / widget / windows / nsWindowDbg.h
blob9e2ed15384fd66b0a41bbf509a840d0fa85c860e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WindowDbg_h__
7 #define WindowDbg_h__
9 /*
10 * nsWindowDbg - Debug related utilities for nsWindow.
13 #include "nsWindowDefs.h"
15 // Enables debug output for popup rollup hooks
16 // #define POPUP_ROLLUP_DEBUG_OUTPUT
18 // Enable window size and state debug output
19 // #define WINSTATE_DEBUG_OUTPUT
21 // nsIWidget defines a set of debug output statements
22 // that are called in various places within the code.
23 // #define WIDGET_DEBUG_OUTPUT
25 // Enable IS_VK_DOWN debug output
26 // #define DEBUG_VK
28 namespace mozilla::widget {
29 // Windows message debugging data
30 struct EventMsgInfo {
31 const char* mStr;
32 UINT mId;
33 std::function<nsAutoCString(WPARAM, LPARAM, bool)> mParamInfoFn;
34 std::function<void(nsCString&, WPARAM, const char*, bool)> mWParamInfoFn;
35 const char* mWParamName;
36 std::function<void(nsCString&, LPARAM, const char*, bool)> mLParamInfoFn;
37 const char* mLParamName;
38 void LogParameters(nsCString& str, WPARAM wParam, LPARAM lParam,
39 bool isPreCall);
41 extern std::unordered_map<UINT, EventMsgInfo> gAllEvents;
43 // RAII-style class to log before and after an event is handled.
44 class PrintEvent final {
45 public:
46 PrintEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
47 void SetResult(LRESULT lresult, bool result) {
48 mRetValue = lresult;
49 mResult = mozilla::Some(result);
51 ~PrintEvent();
53 private:
54 bool PrintEventInternal();
56 const HWND mHwnd;
57 const UINT mMsg;
58 const WPARAM mWParam;
59 const LPARAM mLParam;
60 mozilla::Maybe<long> mEventCounter;
61 // not const because these will be set after the event is handled
62 mozilla::Maybe<bool> mResult;
63 LRESULT mRetValue = 0;
65 bool mShouldLogPostCall;
68 struct EnumValueAndName {
69 uint64_t mFlag;
70 const char* mName;
73 // Appends to str a description of the flags passed in.
74 // flagsAndNames is a list of flag values with a string description
75 // for each one. These are processed in order, so if there are
76 // flag values that are combination of individual values (for example
77 // something like WS_OVERLAPPEDWINDOW) they need to come first
78 // in the flagsAndNames array.
79 // A 0 flag value will only be written if the flags input is exactly
80 // 0, and it must come last in the flagsAndNames array.
81 // Returns whether any info was appended to str.
82 bool AppendFlagsInfo(nsCString& str, uint64_t flags,
83 const nsTArray<EnumValueAndName>& flagsAndNames,
84 const char* name);
86 nsAutoCString WmSizeParamInfo(uint64_t wParam, uint64_t lParam, bool isPreCall);
87 void XLowWordYHighWordParamInfo(nsCString& str, uint64_t value,
88 const char* name, bool isPreCall);
89 void WindowPosParamInfo(nsCString& str, uint64_t value, const char* name,
90 bool isPreCall);
91 void WindowEdgeParamInfo(nsCString& str, uint64_t value, const char* name,
92 bool isPreCall);
93 void RectParamInfo(nsCString& str, uint64_t value, const char* name,
94 bool isPreCall);
95 void UiActionParamInfo(nsCString& str, uint64_t value, const char* name,
96 bool isPreCall);
97 void WideStringParamInfo(nsCString& result, uint64_t value, const char* name,
98 bool isPreCall);
99 void MinMaxInfoParamInfo(nsCString& result, uint64_t value, const char* name,
100 bool isPreCall);
101 nsAutoCString WmNcCalcSizeParamInfo(uint64_t wParam, uint64_t lParam,
102 bool isPreCall);
103 } // namespace mozilla::widget
105 #if defined(POPUP_ROLLUP_DEBUG_OUTPUT)
106 typedef struct {
107 char* mStr;
108 int mId;
109 } MSGFEventMsgInfo;
111 # define DISPLAY_NMM_PRT(_arg) \
112 MOZ_LOG(gWindowsLog, mozilla::LogLevel::Info, ((_arg)));
113 #else
114 # define DISPLAY_NMM_PRT(_arg)
115 #endif // defined(POPUP_ROLLUP_DEBUG_OUTPUT)
117 #if defined(DEBUG)
118 void DDError(const char* msg, HRESULT hr);
119 #endif // defined(DEBUG)
121 #if defined(DEBUG_VK)
122 bool is_vk_down(int vk);
123 # define IS_VK_DOWN is_vk_down
124 #else
125 # define IS_VK_DOWN(a) (GetKeyState(a) < 0)
126 #endif // defined(DEBUG_VK)
128 #endif /* WindowDbg_h__ */