diff --git a/widget/src/cocoa/nsMenuBarX.h b/widget/src/cocoa/nsMenuBarX.h index 72505b58f41f..46e3d84f3b17 100644 --- a/widget/src/cocoa/nsMenuBarX.h +++ b/widget/src/cocoa/nsMenuBarX.h @@ -91,9 +91,7 @@ class nsMenuBarX : public nsIMenuBar, public: nsMenuBarX(); virtual ~nsMenuBarX(); - - enum {kApplicationMenuID = 1}; - + // |NSMenuItem|s target Objective-C objects static NativeMenuItemTarget* sNativeEventTarget; diff --git a/widget/src/cocoa/nsMenuBarX.mm b/widget/src/cocoa/nsMenuBarX.mm index b69b62368ee8..f09a613d7e35 100644 --- a/widget/src/cocoa/nsMenuBarX.mm +++ b/widget/src/cocoa/nsMenuBarX.mm @@ -136,50 +136,34 @@ nsMenuBarX::~nsMenuBarX() nsEventStatus nsMenuBarX::MenuItemSelected(const nsMenuEvent &aMenuEvent) { - // Dispatch menu event - nsEventStatus eventStatus = nsEventStatus_eIgnore; - for (PRInt32 i = mMenusArray.Count() - 1; i >= 0; i--) { nsCOMPtr menu = mMenusArray.ObjectAt(i); nsCOMPtr menuListener = do_QueryInterface(menu); if (menuListener) { - eventStatus = menuListener->MenuItemSelected(aMenuEvent); - if (nsEventStatus_eIgnore != eventStatus) + nsEventStatus eventStatus = menuListener->MenuItemSelected(aMenuEvent); + if (eventStatus != nsEventStatus_eIgnore) return eventStatus; } } - return eventStatus; + return nsEventStatus_eIgnore; } nsEventStatus nsMenuBarX::MenuSelected(const nsMenuEvent &aMenuEvent) { - // Dispatch event - nsEventStatus eventStatus = nsEventStatus_eIgnore; - - nsCOMPtr menuListener; - if (menuListener) { - //TODO: MenuSelected is the right thing to call... - //eventStatus = menuListener->MenuSelected(aMenuEvent); - eventStatus = menuListener->MenuItemSelected(aMenuEvent); - if (nsEventStatus_eIgnore != eventStatus) - return eventStatus; - } - else { - for (PRInt32 i = mMenusArray.Count() - 1; i >= 0; i--) { - nsCOMPtr menu = mMenusArray.ObjectAt(i); - nsCOMPtr thisListener = do_QueryInterface(menu); - if (thisListener) { - //TODO: MenuSelected is the right thing to call... - //eventStatus = menuListener->MenuSelected(aMenuEvent); - eventStatus = thisListener->MenuItemSelected(aMenuEvent); - if (nsEventStatus_eIgnore != eventStatus) - return eventStatus; - } + for (PRInt32 i = mMenusArray.Count() - 1; i >= 0; i--) { + nsCOMPtr menu = mMenusArray.ObjectAt(i); + nsCOMPtr thisListener = do_QueryInterface(menu); + if (thisListener) { + //TODO: MenuSelected is the right thing to call... + //eventStatus = menuListener->MenuSelected(aMenuEvent); + nsEventStatus eventStatus = thisListener->MenuItemSelected(aMenuEvent); + if (eventStatus != nsEventStatus_eIgnore) + return eventStatus; } } - return eventStatus; + return nsEventStatus_eIgnore; } @@ -205,9 +189,7 @@ nsMenuBarX::SetRebuild(PRBool aNeedsRebuild) } -// Do what's necessary to conform to the Aqua guidelines for menus. Initially, this -// means removing 'Quit' from the file menu and 'Preferences' from the edit menu, along -// with their various separators (if present). +// Do what's necessary to conform to the Aqua guidelines for menus. void nsMenuBarX::AquifyMenuBar() { @@ -380,7 +362,7 @@ nsMenuBarX::MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWind if (!mMenuBarContent) return nsEventStatus_eIgnore; - Create(aParentWindow); + SetParent(aParentWindow); AquifyMenuBar(); @@ -396,9 +378,8 @@ nsMenuBarX::MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWind doc->AddMutationObserver(this); mDocument = doc; - // set this as a nsMenuListener on aParentWindow aParentWindow->AddMenuListener((nsIMenuListener *)this); - + PRUint32 count = mMenuBarContent->GetChildCount(); for (PRUint32 i = 0; i < count; i++) { nsIContent *menu = mMenuBarContent->GetChildAt(i); @@ -410,31 +391,19 @@ nsMenuBarX::MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWind menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuName); menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::accesskey, menuAccessKey); - // Don't create the whole menu yet, just add in the top level names - // Create nsMenu, the menubar will own it nsCOMPtr pnsMenu(do_CreateInstance(kMenuCID)); if (pnsMenu) { pnsMenu->Create(static_cast(this), menuName, menuAccessKey, static_cast(this), menu); - - // Make nsMenu a child of nsMenuBar. nsMenuBar takes ownership. AddMenu(pnsMenu); - - if (menu->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::id, - NS_LITERAL_STRING("menu_Help"), eCaseMatters)) { - nsMenuEvent event(PR_TRUE, 0, nsnull); - event.mCommand = (unsigned int)nsnull; - nsCOMPtr listener(do_QueryInterface(pnsMenu)); - listener->MenuSelected(event); - } } } } - } // for each menu + } // Give the aParentWindow this nsMenuBarX to hold onto. - // The parent takes ownership + // The parent takes ownership. aParentWindow->SetMenuBar(this); return nsEventStatus_eIgnore; @@ -768,7 +737,7 @@ NS_IMETHODIMP nsMenuBarX::RemoveAll() NS_IMETHODIMP nsMenuBarX::GetNativeData(void *& aData) { - aData = (void *) mRootMenu; + aData = (void*)mRootMenu; return NS_OK; } diff --git a/widget/src/cocoa/nsMenuX.mm b/widget/src/cocoa/nsMenuX.mm index 15feee96174f..8446faf05810 100644 --- a/widget/src/cocoa/nsMenuX.mm +++ b/widget/src/cocoa/nsMenuX.mm @@ -1159,7 +1159,7 @@ static pascal OSStatus MyMenuEventHandler(EventHandlerCallRef myHandler, EventRe } } else if (kind == kEventMenuOpening || kind == kEventMenuClosed) { - if (kind == kEventMenuOpening && gRollupListener != nsnull && gRollupWidget != nsnull) { + if (kind == kEventMenuOpening && gRollupListener && gRollupWidget) { gRollupListener->Rollup(); return userCanceledErr; }