Bug 1874684 - Part 20: Tag stack classes with MOZ_STACK_CLASS. r=allstarschh
[gecko.git] / widget / windows / nsWindowDbg.h
blobc739966fd5c9d70a6a3ef11b635b88478ad11585
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"
14 #include "mozilla/BaseProfilerMarkersPrerequisites.h"
16 // Enables debug output for popup rollup hooks
17 // #define POPUP_ROLLUP_DEBUG_OUTPUT
19 // Enable window size and state debug output
20 // #define WINSTATE_DEBUG_OUTPUT
22 // nsIWidget defines a set of debug output statements
23 // that are called in various places within the code.
24 // #define WIDGET_DEBUG_OUTPUT
26 // Enable IS_VK_DOWN debug output
27 // #define DEBUG_VK
29 namespace mozilla::widget {
31 class MOZ_RAII AutoProfilerMessageMarker {
32 public:
33 explicit AutoProfilerMessageMarker(Span<const char> aMsgLoopName, HWND hWnd,
34 UINT msg, WPARAM wParam, LPARAM lParam);
36 ~AutoProfilerMessageMarker();
38 protected:
39 Maybe<MarkerOptions> mOptions;
40 Span<const char> mMsgLoopName;
41 UINT mMsg;
42 WPARAM mWParam;
43 LPARAM mLParam;
46 // Windows message debugging data
47 struct EventMsgInfo {
48 const char* mStr;
49 UINT mId;
50 std::function<nsAutoCString(WPARAM, LPARAM, bool)> mParamInfoFn;
51 std::function<void(nsCString&, WPARAM, const char*, bool)> mWParamInfoFn;
52 const char* mWParamName;
53 std::function<void(nsCString&, LPARAM, const char*, bool)> mLParamInfoFn;
54 const char* mLParamName;
55 void LogParameters(nsCString& str, WPARAM wParam, LPARAM lParam,
56 bool isPreCall);
58 extern std::unordered_map<UINT, EventMsgInfo> gAllEvents;
60 // RAII-style class to log before and after an event is handled.
61 class NativeEventLogger final {
62 public:
63 template <size_t N>
64 NativeEventLogger(const char (&aMsgLoopName)[N], HWND hwnd, UINT msg,
65 WPARAM wParam, LPARAM lParam)
66 : NativeEventLogger(Span(aMsgLoopName), hwnd, msg, wParam, lParam) {}
68 void SetResult(LRESULT lresult, bool result) {
69 mRetValue = lresult;
70 mResult = mozilla::Some(result);
72 ~NativeEventLogger();
74 private:
75 NativeEventLogger(Span<const char> aMsgLoopName, HWND hwnd, UINT msg,
76 WPARAM wParam, LPARAM lParam);
77 bool NativeEventLoggerInternal();
79 AutoProfilerMessageMarker mProfilerMarker;
80 const char* mMsgLoopName;
81 const HWND mHwnd;
82 const UINT mMsg;
83 const WPARAM mWParam;
84 const LPARAM mLParam;
85 mozilla::Maybe<long> mEventCounter;
86 // not const because these will be set after the event is handled
87 mozilla::Maybe<bool> mResult;
88 LRESULT mRetValue = 0;
90 bool mShouldLogPostCall;
93 struct EnumValueAndName {
94 uint64_t mFlag;
95 const char* mName;
98 // Appends to str a description of the flags passed in.
99 // flagsAndNames is a list of flag values with a string description
100 // for each one. These are processed in order, so if there are
101 // flag values that are combination of individual values (for example
102 // something like WS_OVERLAPPEDWINDOW) they need to come first
103 // in the flagsAndNames array.
104 // A 0 flag value will only be written if the flags input is exactly
105 // 0, and it must come last in the flagsAndNames array.
106 // Returns whether any info was appended to str.
107 bool AppendFlagsInfo(nsCString& str, uint64_t flags,
108 const nsTArray<EnumValueAndName>& flagsAndNames,
109 const char* name);
111 nsAutoCString WmSizeParamInfo(uint64_t wParam, uint64_t lParam, bool isPreCall);
112 void XLowWordYHighWordParamInfo(nsCString& str, uint64_t value,
113 const char* name, bool isPreCall);
114 void WindowPosParamInfo(nsCString& str, uint64_t value, const char* name,
115 bool isPreCall);
116 void WindowEdgeParamInfo(nsCString& str, uint64_t value, const char* name,
117 bool isPreCall);
118 void RectParamInfo(nsCString& str, uint64_t value, const char* name,
119 bool isPreCall);
120 void UiActionParamInfo(nsCString& str, uint64_t value, const char* name,
121 bool isPreCall);
122 void WideStringParamInfo(nsCString& result, uint64_t value, const char* name,
123 bool isPreCall);
124 void MinMaxInfoParamInfo(nsCString& result, uint64_t value, const char* name,
125 bool isPreCall);
126 nsAutoCString WmNcCalcSizeParamInfo(uint64_t wParam, uint64_t lParam,
127 bool isPreCall);
128 } // namespace mozilla::widget
130 #if defined(POPUP_ROLLUP_DEBUG_OUTPUT)
131 typedef struct {
132 char* mStr;
133 int mId;
134 } MSGFEventMsgInfo;
136 # define DISPLAY_NMM_PRT(_arg) \
137 MOZ_LOG(gWindowsLog, mozilla::LogLevel::Info, ((_arg)));
138 #else
139 # define DISPLAY_NMM_PRT(_arg)
140 #endif // defined(POPUP_ROLLUP_DEBUG_OUTPUT)
142 #if defined(DEBUG)
143 void DDError(const char* msg, HRESULT hr);
144 #endif // defined(DEBUG)
146 #if defined(DEBUG_VK)
147 bool is_vk_down(int vk);
148 # define IS_VK_DOWN is_vk_down
149 #else
150 # define IS_VK_DOWN(a) (GetKeyState(a) < 0)
151 #endif // defined(DEBUG_VK)
153 #endif /* WindowDbg_h__ */