From 5fe142be9a828ac8c893ec3b3642ed5d7e35eaa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 5 Aug 2025 09:12:04 +0000 Subject: [PATCH] Bug 1977581 - Keep activating the parent window on Windows when destroying a child. r=win-reviewers,handyman, a=dsmith Bug 1902315 removed a PlaceBehind call here, which in this case happened to also activate the window (via the aActivate = true parameter). Keep raising the window manually, but with simpler APIs. Differential Revision: https://phabricator.services.mozilla.com/D258743 --- xpfe/appshell/AppWindow.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp index 22dbf9028167..dcf954ba17fd 100644 --- a/xpfe/appshell/AppWindow.cpp +++ b/xpfe/appshell/AppWindow.cpp @@ -547,6 +547,19 @@ NS_IMETHODIMP AppWindow::Destroy() { if (mWindow) mWindow->Show(false); #endif + // Raise and focus our parent explicitly on Windows, if visible. Apparently + // Windows gets the z-order and focus wrong otherwise for nested modal + // windows, see bug 1977581. +#ifdef XP_WIN + if (nsCOMPtr parent = do_QueryReferent(mParentWindow)) { + nsCOMPtr parentWidget; + parent->GetMainWidget(getter_AddRefs(parentWidget)); + if (parentWidget && parentWidget->IsVisible()) { + parentWidget->SetFocus(nsIWidget::Raise::Yes, dom::CallerType::System); + } + } +#endif + RemoveTooltipSupport(); mDOMWindow = nullptr;