From fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:14:29 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- xpfe/appshell/AppWindow.cpp | 61 +++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'xpfe') diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp index 6356acd764..e172f9340e 100644 --- a/xpfe/appshell/AppWindow.cpp +++ b/xpfe/appshell/AppWindow.cpp @@ -78,7 +78,7 @@ #include "mozilla/dom/DocumentL10n.h" -#ifdef XP_MACOSX +#if defined(XP_MACOSX) || defined(MOZ_WIDGET_GTK) # include "mozilla/widget/NativeMenuSupport.h" # define USE_NATIVE_MENUS #endif @@ -491,10 +491,10 @@ NS_IMETHODIMP AppWindow::ShowModal() { #ifdef USE_NATIVE_MENUS if (!gfxPlatform::IsHeadless()) { - // macOS only: For modals created early in startup. - // (e.g. ProfileManager/ProfileDowngrade) this creates a fallback menu for - // the menu bar which only contains a "Quit" menu item. - // This allows the user to quit the application in a regular way with cmd+Q. + // On macOS, for modals created early in startup. (e.g. + // ProfileManager/ProfileDowngrade) this creates a fallback menu for the + // menu bar which only contains a "Quit" menu item. This allows the user to + // quit the application in a regular way with cmd+Q. widget::NativeMenuSupport::CreateNativeMenuBar(mWindow, nullptr); } #endif @@ -3129,7 +3129,16 @@ struct LoadNativeMenusListener { nsCOMPtr mParentWindow; }; -static bool sHiddenWindowLoadedNativeMenus = false; +// On macOS the hidden window is created eagerly, and we want to wait for it to +// load the native menus. +static bool sWaitingForHiddenWindowToLoadNativeMenus = +# ifdef XP_MACOSX + true +# else + false +# endif + ; + static nsTArray sLoadNativeMenusListeners; static void BeginLoadNativeMenus(Document* aDoc, nsIWidget* aParentWindow); @@ -3140,25 +3149,18 @@ static void LoadNativeMenus(Document* aDoc, nsIWidget* aParentWindow) { // Find the menubar tag (if there is more than one, we ignore all but // the first). nsCOMPtr menubarElements = aDoc->GetElementsByTagNameNS( - nsLiteralString( - u"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"), + u"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"_ns, u"menubar"_ns); - nsCOMPtr menubarNode; + RefPtr menubar; if (menubarElements) { - menubarNode = menubarElements->Item(0); + menubar = Element::FromNodeOrNull(menubarElements->Item(0)); } - using widget::NativeMenuSupport; - if (menubarNode) { - nsCOMPtr menubarContent(do_QueryInterface(menubarNode)); - NativeMenuSupport::CreateNativeMenuBar(aParentWindow, menubarContent); - } else { - NativeMenuSupport::CreateNativeMenuBar(aParentWindow, nullptr); - } + widget::NativeMenuSupport::CreateNativeMenuBar(aParentWindow, menubar); - if (!sHiddenWindowLoadedNativeMenus) { - sHiddenWindowLoadedNativeMenus = true; + if (sWaitingForHiddenWindowToLoadNativeMenus) { + sWaitingForHiddenWindowToLoadNativeMenus = false; for (auto& listener : sLoadNativeMenusListeners) { BeginLoadNativeMenus(listener.mDocument, listener.mParentWindow); } @@ -3197,13 +3199,11 @@ class L10nReadyPromiseHandler final : public dom::PromiseNativeHandler { NS_IMPL_ISUPPORTS0(L10nReadyPromiseHandler) static void BeginLoadNativeMenus(Document* aDoc, nsIWidget* aParentWindow) { - RefPtr l10n = aDoc->GetL10n(); - if (l10n) { + if (RefPtr l10n = aDoc->GetL10n()) { // Wait for l10n to be ready so the menus are localized. RefPtr promise = l10n->Ready(); MOZ_ASSERT(promise); - RefPtr handler = - new L10nReadyPromiseHandler(aDoc, aParentWindow); + RefPtr handler = new L10nReadyPromiseHandler(aDoc, aParentWindow); promise->AppendNativeHandler(handler); } else { // Something went wrong loading the doc and l10n wasn't created. This @@ -3314,16 +3314,11 @@ AppWindow::OnStateChange(nsIWebProgress* aProgress, nsIRequest* aRequest, // commands /////////////////////////////// if (!gfxPlatform::IsHeadless()) { - nsCOMPtr viewer; - mDocShell->GetDocViewer(getter_AddRefs(viewer)); - if (viewer) { - RefPtr menubarDoc = viewer->GetDocument(); - if (menubarDoc) { - if (mIsHiddenWindow || sHiddenWindowLoadedNativeMenus) { - BeginLoadNativeMenus(menubarDoc, mWindow); - } else { - sLoadNativeMenusListeners.EmplaceBack(menubarDoc, mWindow); - } + if (RefPtr menubarDoc = mDocShell->GetExtantDocument()) { + if (mIsHiddenWindow || !sWaitingForHiddenWindowToLoadNativeMenus) { + BeginLoadNativeMenus(menubarDoc, mWindow); + } else { + sLoadNativeMenusListeners.EmplaceBack(menubarDoc, mWindow); } } } -- cgit v1.2.3