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/. */
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
29 namespace mozilla::widget
{
31 class MOZ_RAII AutoProfilerMessageMarker
{
33 explicit AutoProfilerMessageMarker(Span
<const char> aMsgLoopName
, HWND hWnd
,
34 UINT msg
, WPARAM wParam
, LPARAM lParam
);
36 ~AutoProfilerMessageMarker();
39 Maybe
<MarkerOptions
> mOptions
;
40 Span
<const char> mMsgLoopName
;
46 // Windows message debugging data
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
,
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
{
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
) {
70 mResult
= mozilla::Some(result
);
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
;
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
{
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
,
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
,
116 void WindowEdgeParamInfo(nsCString
& str
, uint64_t value
, const char* name
,
118 void RectParamInfo(nsCString
& str
, uint64_t value
, const char* name
,
120 void UiActionParamInfo(nsCString
& str
, uint64_t value
, const char* name
,
122 void WideStringParamInfo(nsCString
& result
, uint64_t value
, const char* name
,
124 void MinMaxInfoParamInfo(nsCString
& result
, uint64_t value
, const char* name
,
126 nsAutoCString
WmNcCalcSizeParamInfo(uint64_t wParam
, uint64_t lParam
,
128 } // namespace mozilla::widget
130 #if defined(POPUP_ROLLUP_DEBUG_OUTPUT)
136 # define DISPLAY_NMM_PRT(_arg) \
137 MOZ_LOG(gWindowsLog, mozilla::LogLevel::Info, ((_arg)));
139 # define DISPLAY_NMM_PRT(_arg)
140 #endif // defined(POPUP_ROLLUP_DEBUG_OUTPUT)
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
150 # define IS_VK_DOWN(a) (GetKeyState(a) < 0)
151 #endif // defined(DEBUG_VK)
153 #endif /* WindowDbg_h__ */