From d59e2ac8dc5d8ea23cd347221a00b42318057fcf Mon Sep 17 00:00:00 2001 From: Steven Michaud Date: Mon, 24 Aug 2015 10:57:02 -0500 Subject: [PATCH] Bug 1181977 - Firefox app menu contains only "Quit" in certain edgecases. r=spohl --- widget/cocoa/nsAppShell.mm | 2 -- widget/cocoa/nsMenuBarX.mm | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/widget/cocoa/nsAppShell.mm b/widget/cocoa/nsAppShell.mm index 0f753530ca19..bd1e08365283 100644 --- a/widget/cocoa/nsAppShell.mm +++ b/widget/cocoa/nsAppShell.mm @@ -28,7 +28,6 @@ #include "nsCocoaFeatures.h" #include "nsCocoaUtils.h" #include "nsChildView.h" -#include "nsMenuBarX.h" #include "nsToolkit.h" #include "TextInputHandler.h" #include "mozilla/HangMonitor.h" @@ -658,7 +657,6 @@ nsAppShell::Run(void) mStarted = true; AddScreenWakeLockListener(); - nsMenuBarX::ResetNativeApplicationMenu(); NS_OBJC_TRY_ABORT([NSApp run]); diff --git a/widget/cocoa/nsMenuBarX.mm b/widget/cocoa/nsMenuBarX.mm index a58cb80630bf..e8187cb5d0fe 100644 --- a/widget/cocoa/nsMenuBarX.mm +++ b/widget/cocoa/nsMenuBarX.mm @@ -33,6 +33,7 @@ NativeMenuItemTarget* nsMenuBarX::sNativeEventTarget = nil; nsMenuBarX* nsMenuBarX::sLastGeckoMenuBarPainted = nullptr; // Weak nsMenuBarX* nsMenuBarX::sCurrentPaintDelayedMenuBar = nullptr; // Weak NSMenu* sApplicationMenu = nil; +BOOL sApplicationMenuIsFallback = NO; BOOL gSomeMenuBarPainted = NO; // We keep references to the first quit and pref item content nodes we find, which @@ -186,6 +187,7 @@ void nsMenuBarX::ConstructFallbackNativeMenus() [quitMenuItem setTarget:nsMenuBarX::sNativeEventTarget]; [quitMenuItem setTag:eCommand_ID_Quit]; [sApplicationMenu addItem:quitMenuItem]; + sApplicationMenuIsFallback = YES; } uint32_t nsMenuBarX::GetMenuCount() @@ -207,6 +209,11 @@ nsresult nsMenuBarX::InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; + // If we've only yet created a fallback global Application menu (using + // ContructFallbackNativeMenus()), destroy it before recreating it properly. + if (sApplicationMenu && sApplicationMenuIsFallback) { + ResetNativeApplicationMenu(); + } // If we haven't created a global Application menu yet, do it. if (!sApplicationMenu) { nsresult rv = NS_OK; // avoid warning about rv being unused @@ -506,6 +513,7 @@ void nsMenuBarX::ResetNativeApplicationMenu() [sApplicationMenu removeAllItems]; [sApplicationMenu release]; sApplicationMenu = nil; + sApplicationMenuIsFallback = NO; } // Hide the item in the menu by setting the 'hidden' attribute. Returns it in |outHiddenNode| so