Bug 1936325 - Miscellaneous windows widget clean-ups. r=win-reviewers,rkraesig

Did these while debugging bug 1936164. No behavior change intended.

Differential Revision: https://phabricator.services.mozilla.com/D231706
This commit is contained in:
Emilio Cobos Álvarez
2024-12-10 18:31:43 +00:00
parent faab93bf15
commit 450f3b396e
2 changed files with 109 additions and 107 deletions

View File

@@ -306,7 +306,7 @@ class WinUtils {
* | | TRUE | FALSE |
+ +-----------------+-------+-----------------------+-----------------------+
* | | | * an independent top level window |
* | | TRUE | * a pupup window (WS_POPUP) |
* | | TRUE | * a popup window (WS_POPUP) |
* | | | * an owned top level window (like dialog) |
* | aStopIfNotChild +-------+-----------------------+-----------------------+
* | | | * independent window | * only an independent |

View File

@@ -515,75 +515,73 @@ class TIPMessageHandler {
}
}
class MOZ_RAII A11yInstantiationBlocker {
public:
A11yInstantiationBlocker() {
if (!TIPMessageHandler::sInstance) {
return;
}
++TIPMessageHandler::sInstance->mA11yBlockCount;
}
class MOZ_RAII A11yInstantiationBlocker{public : A11yInstantiationBlocker(){
if (!TIPMessageHandler::sInstance){return;
} ++TIPMessageHandler::sInstance->mA11yBlockCount;
} // namespace mozilla
~A11yInstantiationBlocker() {
if (!TIPMessageHandler::sInstance) {
return;
}
MOZ_ASSERT(TIPMessageHandler::sInstance->mA11yBlockCount > 0);
--TIPMessageHandler::sInstance->mA11yBlockCount;
}
};
~A11yInstantiationBlocker() {
if (!TIPMessageHandler::sInstance) {
return;
}
MOZ_ASSERT(TIPMessageHandler::sInstance->mA11yBlockCount > 0);
--TIPMessageHandler::sInstance->mA11yBlockCount;
}
}
;
friend class A11yInstantiationBlocker;
static LRESULT CALLBACK TIPHook(int aCode, WPARAM aWParam, LPARAM aLParam) {
if (aCode < 0 || !sInstance) {
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
}
MSG* msg = reinterpret_cast<MSG*>(aLParam);
UINT& msgCode = msg->message;
for (uint32_t i = 0; i < std::size(sInstance->mMessages); ++i) {
if (msgCode == sInstance->mMessages[i]) {
A11yInstantiationBlocker block;
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
}
}
friend class A11yInstantiationBlocker;
static LRESULT CALLBACK TIPHook(int aCode, WPARAM aWParam, LPARAM aLParam) {
if (aCode < 0 || !sInstance) {
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
}
static LRESULT WINAPI SendMessageTimeoutWHook(HWND aHwnd, UINT aMsgCode,
WPARAM aWParam, LPARAM aLParam,
UINT aFlags, UINT aTimeout,
PDWORD_PTR aMsgResult) {
// We don't want to handle this unless the message is a WM_GETOBJECT that we
// want to block, and the aHwnd is a nsWindow that belongs to the current
// (i.e., main) thread.
if (!aMsgResult || aMsgCode != WM_GETOBJECT ||
static_cast<LONG>(aLParam) != OBJID_CLIENT || !::NS_IsMainThread() ||
!WinUtils::GetNSWindowPtr(aHwnd) || !IsA11yBlocked()) {
return sSendMessageTimeoutWStub(aHwnd, aMsgCode, aWParam, aLParam, aFlags,
aTimeout, aMsgResult);
MSG* msg = reinterpret_cast<MSG*>(aLParam);
UINT& msgCode = msg->message;
for (uint32_t i = 0; i < std::size(sInstance->mMessages); ++i) {
if (msgCode == sInstance->mMessages[i]) {
A11yInstantiationBlocker block;
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
}
// In this case we want to fake the result that would happen if we had
// decided not to handle WM_GETOBJECT in our WndProc. We hand the message
// off to DefWindowProc to accomplish this.
*aMsgResult = static_cast<DWORD_PTR>(
::DefWindowProcW(aHwnd, aMsgCode, aWParam, aLParam));
return static_cast<LRESULT>(TRUE);
}
static WindowsDllInterceptor::FuncHookType<decltype(&SendMessageTimeoutW)>
sSendMessageTimeoutWStub;
static StaticAutoPtr<TIPMessageHandler> sInstance;
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
}
HHOOK mHook;
UINT mMessages[7];
uint32_t mA11yBlockCount;
};
static LRESULT WINAPI SendMessageTimeoutWHook(HWND aHwnd, UINT aMsgCode,
WPARAM aWParam, LPARAM aLParam,
UINT aFlags, UINT aTimeout,
PDWORD_PTR aMsgResult) {
// We don't want to handle this unless the message is a WM_GETOBJECT that we
// want to block, and the aHwnd is a nsWindow that belongs to the current
// (i.e., main) thread.
if (!aMsgResult || aMsgCode != WM_GETOBJECT ||
static_cast<LONG>(aLParam) != OBJID_CLIENT || !::NS_IsMainThread() ||
!WinUtils::GetNSWindowPtr(aHwnd) || !IsA11yBlocked()) {
return sSendMessageTimeoutWStub(aHwnd, aMsgCode, aWParam, aLParam, aFlags,
aTimeout, aMsgResult);
}
// In this case we want to fake the result that would happen if we had
// decided not to handle WM_GETOBJECT in our WndProc. We hand the message
// off to DefWindowProc to accomplish this.
*aMsgResult = static_cast<DWORD_PTR>(
::DefWindowProcW(aHwnd, aMsgCode, aWParam, aLParam));
return static_cast<LRESULT>(TRUE);
}
static WindowsDllInterceptor::FuncHookType<decltype(&SendMessageTimeoutW)>
sSendMessageTimeoutWStub;
static StaticAutoPtr<TIPMessageHandler> sInstance;
HHOOK mHook;
UINT mMessages[7];
uint32_t mA11yBlockCount;
}
;
WindowsDllInterceptor::FuncHookType<decltype(&SendMessageTimeoutW)>
TIPMessageHandler::sSendMessageTimeoutWStub;
@@ -1202,7 +1200,7 @@ void nsWindow::Destroy() {
// Our windows can be subclassed which may prevent us receiving WM_DESTROY. If
// OnDestroy() didn't get called, call it now.
if (false == mOnDestroyCalled) {
if (!mOnDestroyCalled) {
MSGResult msgResult;
mWindowHook.Notify(mWnd, WM_DESTROY, 0, 0, msgResult);
OnDestroy();
@@ -2324,23 +2322,24 @@ bool nsWindow::IsEnabled() const {
**************************************************************/
void nsWindow::SetFocus(Raise aRaise, mozilla::dom::CallerType aCallerType) {
if (mWnd) {
#ifdef WINSTATE_DEBUG_OUTPUT
if (mWnd == WinUtils::GetTopLevelHWND(mWnd)) {
MOZ_LOG(gWindowsLog, LogLevel::Info,
("*** SetFocus: [ top] raise=%d\n", aRaise == Raise::Yes));
} else {
MOZ_LOG(gWindowsLog, LogLevel::Info,
("*** SetFocus: [child] raise=%d\n", aRaise == Raise::Yes));
}
#endif
// Uniconify, if necessary
HWND toplevelWnd = WinUtils::GetTopLevelHWND(mWnd);
if (aRaise == Raise::Yes && ::IsIconic(toplevelWnd)) {
::ShowWindow(toplevelWnd, SW_RESTORE);
}
::SetFocus(mWnd);
if (!mWnd) {
return;
}
#ifdef WINSTATE_DEBUG_OUTPUT
if (mWnd == WinUtils::GetTopLevelHWND(mWnd)) {
MOZ_LOG(gWindowsLog, LogLevel::Info,
("*** SetFocus: [ top] raise=%d\n", aRaise == Raise::Yes));
} else {
MOZ_LOG(gWindowsLog, LogLevel::Info,
("*** SetFocus: [child] raise=%d\n", aRaise == Raise::Yes));
}
#endif
// Uniconify, if necessary
HWND toplevelWnd = WinUtils::GetTopLevelHWND(mWnd);
if (aRaise == Raise::Yes && ::IsIconic(toplevelWnd)) {
::ShowWindow(toplevelWnd, SW_RESTORE);
}
::SetFocus(mWnd);
}
/**************************************************************
@@ -4631,8 +4630,9 @@ LRESULT CALLBACK nsWindow::WindowProcInternal(HWND hWnd, UINT msg,
nsAutoRollup autoRollup;
LRESULT popupHandlingResult;
if (DealWithPopups(hWnd, msg, wParam, lParam, &popupHandlingResult))
if (DealWithPopups(hWnd, msg, wParam, lParam, &popupHandlingResult)) {
return popupHandlingResult;
}
// Call ProcessMessage
LRESULT retValue;
@@ -5559,40 +5559,42 @@ bool nsWindow::ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
// events arrive.
case WM_ACTIVATE: {
int32_t fActive = LOWORD(wParam);
if (mWidgetListener) {
if (WA_INACTIVE == fActive) {
// when minimizing a window, the deactivation and focus events will
// be fired in the reverse order. Instead, just deactivate right away.
// This can also happen when a modal system dialog is opened, so check
// if the last window to receive the WM_KILLFOCUS message was this one
// or a child of this one.
if (HIWORD(wParam) ||
(mLastKillFocusWindow &&
(GetTopLevelForFocus(mLastKillFocusWindow) == mWnd))) {
DispatchFocusToTopLevelWindow(false);
} else {
sJustGotDeactivate = true;
}
if (IsTopLevelWidget()) {
mLastKeyboardLayout = KeyboardLayout::GetLayout();
}
if (!mWidgetListener) {
break;
}
if (WA_INACTIVE == fActive) {
// when minimizing a window, the deactivation and focus events will
// be fired in the reverse order. Instead, just deactivate right away.
// This can also happen when a modal system dialog is opened, so check
// if the last window to receive the WM_KILLFOCUS message was this one
// or a child of this one.
if (HIWORD(wParam) ||
(mLastKillFocusWindow &&
(GetTopLevelForFocus(mLastKillFocusWindow) == mWnd))) {
DispatchFocusToTopLevelWindow(false);
} else {
StopFlashing();
sJustGotDeactivate = true;
}
if (IsTopLevelWidget()) {
mLastKeyboardLayout = KeyboardLayout::GetLayout();
}
} else {
StopFlashing();
sJustGotActivate = true;
WidgetMouseEvent event(true, eMouseActivate, this,
WidgetMouseEvent::eReal);
InitEvent(event);
ModifierKeyState modifierKeyState;
modifierKeyState.InitInputEvent(event);
DispatchInputEvent(&event);
if (sSwitchKeyboardLayout && mLastKeyboardLayout)
ActivateKeyboardLayout(mLastKeyboardLayout, 0);
sJustGotActivate = true;
WidgetMouseEvent event(true, eMouseActivate, this,
WidgetMouseEvent::eReal);
InitEvent(event);
ModifierKeyState modifierKeyState;
modifierKeyState.InitInputEvent(event);
DispatchInputEvent(&event);
if (sSwitchKeyboardLayout && mLastKeyboardLayout) {
ActivateKeyboardLayout(mLastKeyboardLayout, 0);
}
#ifdef ACCESSIBILITY
a11y::LazyInstantiator::ResetUiaDetectionCache();
a11y::LazyInstantiator::ResetUiaDetectionCache();
#endif
}
}
} break;