Bug 1319911: Revert changeset 3d7142a4f06d from bug 1292527 due to reported regression. r=me
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Thu, 24 Nov 2016 09:20:39 -0500
changeset 324249 49228a69b071bc200360aa43845b42b996759479
parent 324248 900960e68528c73afb6cfb3d97400bb3311386cf
child 324250 19e3bf665a8e22adc47a900814fcb50153f199ec
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersme
bugs1319911, 1292527
milestone53.0a1
Bug 1319911: Revert changeset 3d7142a4f06d from bug 1292527 due to reported regression. r=me
widget/cocoa/nsMenuBarX.h
widget/cocoa/nsMenuBarX.mm
widget/cocoa/nsMenuX.mm
--- a/widget/cocoa/nsMenuBarX.h
+++ b/widget/cocoa/nsMenuBarX.h
@@ -10,29 +10,20 @@
 
 #include "mozilla/UniquePtr.h"
 #include "nsMenuBaseX.h"
 #include "nsMenuGroupOwnerX.h"
 #include "nsChangeObserver.h"
 #include "nsINativeMenuService.h"
 #include "nsString.h"
 
-class nsMenuBarX;
 class nsMenuX;
 class nsIWidget;
 class nsIContent;
 
-// ApplicationMenuDelegate is used to receive Cocoa notifications.
-@interface ApplicationMenuDelegate : NSObject<NSMenuDelegate>
-{
-  nsMenuBarX* mApplicationMenu; // weak ref
-}
-- (id)initWithApplicationMenu:(nsMenuBarX*)aApplicationMenu;
-@end
-
 // The native menu service for creating native menu bars.
 class nsNativeMenuServiceX : public nsINativeMenuService
 {
 public:
   NS_DECL_ISUPPORTS
 
   nsNativeMenuServiceX() {}
 
@@ -112,30 +103,26 @@ public:
   nsMenuX*          GetMenuAt(uint32_t aIndex);
   nsMenuX*          GetXULHelpMenu();
   void              SetSystemHelpMenu();
   nsresult          Paint();
   void              ForceUpdateNativeMenuAt(const nsAString& indexString);
   void              ForceNativeMenuReload(); // used for testing
   static char       GetLocalizedAccelKey(const char *shortcutID);
   static void       ResetNativeApplicationMenu();
-  void              SetNeedsRebuild();
-  void              ApplicationMenuOpened();
 
 protected:
   void              ConstructNativeMenus();
   void              ConstructFallbackNativeMenus();
   nsresult          InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex);
   void              RemoveMenuAtIndex(uint32_t aIndex);
   void              HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode);
   void              AquifyMenuBar();
   NSMenuItem*       CreateNativeAppMenuItem(nsMenuX* inMenu, const nsAString& nodeID, SEL action,
                                             int tag, NativeMenuItemTarget* target);
   nsresult          CreateApplicationMenu(nsMenuX* inMenu);
 
   nsTArray<mozilla::UniquePtr<nsMenuX>> mMenuArray;
   nsIWidget*         mParentWindow;        // [weak]
   GeckoNSMenu*       mNativeMenu;            // root menu, representing entire menu bar
-  bool               mNeedsRebuild;
-  ApplicationMenuDelegate* mApplicationMenuDelegate;
 };
 
 #endif // nsMenuBarX_h_
--- a/widget/cocoa/nsMenuBarX.mm
+++ b/widget/cocoa/nsMenuBarX.mm
@@ -50,53 +50,22 @@ NS_IMETHODIMP nsNativeMenuServiceX::Crea
 
   RefPtr<nsMenuBarX> mb = new nsMenuBarX();
   if (!mb)
     return NS_ERROR_OUT_OF_MEMORY;
 
   return mb->Create(aParent, aMenuBarNode);
 }
 
-//
-// ApplicationMenuDelegate Objective-C class
-//
-
-@implementation ApplicationMenuDelegate
-
-- (id)initWithApplicationMenu:(nsMenuBarX*)aApplicationMenu
-{
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
-
-  if ((self = [super init])) {
-    mApplicationMenu = aApplicationMenu;
-  }
-  return self;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
-}
-
-- (void)menuWillOpen:(NSMenu*)menu
-{
-  mApplicationMenu->ApplicationMenuOpened();
-}
-
-- (void)menuDidClose:(NSMenu*)menu
-{
-}
-
-@end
-
 nsMenuBarX::nsMenuBarX()
-: nsMenuGroupOwnerX(), mParentWindow(nullptr), mNeedsRebuild(false)
+: nsMenuGroupOwnerX(), mParentWindow(nullptr)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   mNativeMenu = [[GeckoNSMenu alloc] initWithTitle:@"MainMenuBar"];
-  mApplicationMenuDelegate =
-    [[ApplicationMenuDelegate alloc] initWithApplicationMenu:this];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 nsMenuBarX::~nsMenuBarX()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
@@ -118,21 +87,16 @@ nsMenuBarX::~nsMenuBarX()
   }
 
   // We have to manually clear the array here because clearing causes menu items
   // to call back into the menu bar to unregister themselves. We don't want to
   // depend on member variable ordering to ensure that the array gets cleared
   // before the registration hash table is destroyed.
   mMenuArray.Clear();
 
-  if (sApplicationMenu) {
-    ResetNativeApplicationMenu();
-  }
-  [mApplicationMenuDelegate release];
-
   [mNativeMenu release];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 nsresult nsMenuBarX::Create(nsIWidget* aParent, nsIContent* aContent)
 {
   if (!aParent)
@@ -209,17 +173,16 @@ void nsMenuBarX::ConstructFallbackNative
   NSString* keyStr= [NSString stringWithUTF8String:
                      NS_ConvertUTF16toUTF8(keyUTF16).get()];
 
   if (!nsMenuBarX::sNativeEventTarget) {
     nsMenuBarX::sNativeEventTarget = [[NativeMenuItemTarget alloc] init];
   }
 
   sApplicationMenu = [[[[NSApp mainMenu] itemAtIndex:0] submenu] retain];
-  [sApplicationMenu setDelegate:mApplicationMenuDelegate];
   NSMenuItem* quitMenuItem = [[[NSMenuItem alloc] initWithTitle:labelStr
                                                   action:@selector(menuItemHit:)
                                                   keyEquivalent:keyStr] autorelease];
   [quitMenuItem setTarget:nsMenuBarX::sNativeEventTarget];
   [quitMenuItem setTag:eCommand_ID_Quit];
   [sApplicationMenu addItem:quitMenuItem];
   sApplicationMenuIsFallback = YES;
 }
@@ -504,32 +467,16 @@ char nsMenuBarX::GetLocalizedAccelKey(co
 void nsMenuBarX::ResetNativeApplicationMenu()
 {
   [sApplicationMenu removeAllItems];
   [sApplicationMenu release];
   sApplicationMenu = nil;
   sApplicationMenuIsFallback = NO;
 }
 
-void nsMenuBarX::SetNeedsRebuild()
-{
-  mNeedsRebuild = true;
-}
-
-void nsMenuBarX::ApplicationMenuOpened()
-{
-  if (mNeedsRebuild) {
-    if (!mMenuArray.IsEmpty()) {
-      ResetNativeApplicationMenu();
-      CreateApplicationMenu(mMenuArray[0].get());
-    }
-    mNeedsRebuild = false;
-  }
-}
-
 // Hide the item in the menu by setting the 'hidden' attribute. Returns it in |outHiddenNode| so
 // the caller can hang onto it if they so choose. It is acceptable to pass nsull
 // for |outHiddenNode| if the caller doesn't care about the hidden node.
 void nsMenuBarX::HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode)
 {
   nsCOMPtr<nsIDOMElement> menuItem;
   inDoc->GetElementById(inID, getter_AddRefs(menuItem));
   nsCOMPtr<nsIContent> menuContent(do_QueryInterface(menuItem));
@@ -692,18 +639,16 @@ nsresult nsMenuBarX::CreateApplicationMe
          label="&preferencesCmdMac.label;"
            key="open_prefs_key"/>
 
   We need to use this system for localization purposes, until we have a better way
   to define the Application menu to be used on Mac OS X.
 */
 
   if (sApplicationMenu) {
-    [sApplicationMenu setDelegate:mApplicationMenuDelegate];
-
     // This code reads attributes we are going to care about from the DOM elements
 
     NSMenuItem *itemBeingAdded = nil;
     BOOL addAboutSeparator = FALSE;
 
     // Add the About menu item
     itemBeingAdded = CreateNativeAppMenuItem(inMenu, NS_LITERAL_STRING("aboutName"), @selector(menuItemHit:),
                                              eCommand_ID_About, nsMenuBarX::sNativeEventTarget);
--- a/widget/cocoa/nsMenuX.mm
+++ b/widget/cocoa/nsMenuX.mm
@@ -445,23 +445,18 @@ void nsMenuX::MenuConstruct()
 
   gConstructingMenu = false;
   mNeedsRebuild = false;
   // printf("Done building, mMenuObjectsArray.Count() = %d \n", mMenuObjectsArray.Count());
 }
 
 void nsMenuX::SetRebuild(bool aNeedsRebuild)
 {
-  if (!gConstructingMenu) {
+  if (!gConstructingMenu)
     mNeedsRebuild = aNeedsRebuild;
-    if (mParent->MenuObjectType() == eMenuBarObjectType) {
-      nsMenuBarX* mb = static_cast<nsMenuBarX*>(mParent);
-      mb->SetNeedsRebuild();
-    }
-  }
 }
 
 nsresult nsMenuX::SetEnabled(bool aIsEnabled)
 {
   if (aIsEnabled != mIsEnabled) {
     // we always want to rebuild when this changes
     mIsEnabled = aIsEnabled;
     [mNativeMenuItem setEnabled:(BOOL)mIsEnabled];