summaryrefslogtreecommitdiffstats
path: root/xpfe
diff options
context:
space:
mode:
Diffstat (limited to 'xpfe')
-rw-r--r--xpfe/appshell/AppWindow.cpp61
1 files changed, 28 insertions, 33 deletions
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<nsIWidget> 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<LoadNativeMenusListener> 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<nsINodeList> 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<nsINode> menubarNode;
+ RefPtr<Element> menubar;
if (menubarElements) {
- menubarNode = menubarElements->Item(0);
+ menubar = Element::FromNodeOrNull(menubarElements->Item(0));
}
- using widget::NativeMenuSupport;
- if (menubarNode) {
- nsCOMPtr<Element> 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<DocumentL10n> l10n = aDoc->GetL10n();
- if (l10n) {
+ if (RefPtr<DocumentL10n> l10n = aDoc->GetL10n()) {
// Wait for l10n to be ready so the menus are localized.
RefPtr<Promise> promise = l10n->Ready();
MOZ_ASSERT(promise);
- RefPtr<L10nReadyPromiseHandler> 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<nsIDocumentViewer> viewer;
- mDocShell->GetDocViewer(getter_AddRefs(viewer));
- if (viewer) {
- RefPtr<Document> menubarDoc = viewer->GetDocument();
- if (menubarDoc) {
- if (mIsHiddenWindow || sHiddenWindowLoadedNativeMenus) {
- BeginLoadNativeMenus(menubarDoc, mWindow);
- } else {
- sLoadNativeMenusListeners.EmplaceBack(menubarDoc, mWindow);
- }
+ if (RefPtr<Document> menubarDoc = mDocShell->GetExtantDocument()) {
+ if (mIsHiddenWindow || !sWaitingForHiddenWindowToLoadNativeMenus) {
+ BeginLoadNativeMenus(menubarDoc, mWindow);
+ } else {
+ sLoadNativeMenusListeners.EmplaceBack(menubarDoc, mWindow);
}
}
}