diff --git a/widget/src/cocoa/Makefile.in b/widget/src/cocoa/Makefile.in index bcefa59fbe43..64c04f88e01f 100644 --- a/widget/src/cocoa/Makefile.in +++ b/widget/src/cocoa/Makefile.in @@ -99,14 +99,14 @@ MAC_LCPPSRCS = \ CPPSRCS = \ - nsMenuX.cpp \ - nsMenuBarX.cpp \ - nsMenuItemX.cpp \ $(MAC_LCPPSRCS) \ $(GFX_LCPPSRCS) \ $(NULL) CMMSRCS = \ + nsMenuX.mm \ + nsMenuBarX.mm \ + nsMenuItemX.mm \ nsFilePicker.mm \ nsToolkit.mm \ nsAppShellCocoa.mm \ diff --git a/widget/src/cocoa/nsMenuBarX.h b/widget/src/cocoa/nsMenuBarX.h index 24358c953b6c..b3953c4a8de6 100644 --- a/widget/src/cocoa/nsMenuBarX.h +++ b/widget/src/cocoa/nsMenuBarX.h @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Josh Aas * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -49,12 +50,8 @@ #include "nsWeakReference.h" #include "nsIContent.h" -#include -#include -#include -#include - -extern nsWeakPtr gMacMenubarX; +#import +#import class nsIWidget; class nsIDocument; @@ -62,28 +59,29 @@ class nsIDOMNode; namespace MenuHelpersX { - // utility routine for getting a PresContext out of a docShell - nsresult DocShellToPresContext ( nsIDocShell* inDocShell, nsPresContext** outContext ) ; - + // utility routine for getting a PresContext out of a docShell + nsresult DocShellToPresContext(nsIDocShell* inDocShell, nsPresContext** outContext); + nsEventStatus DispatchCommandTo(nsIWeakReference* aDocShellWeakRef, + nsIContent* aTargetContent); } -/** - * Native Mac MenuBar wrapper - */ +// +// Native Mac menu bar wrapper +// -class nsMenuBarX : public nsIMenuBar, - public nsIMenuListener, - public nsIDocumentObserver, - public nsIChangeManager, - public nsIMenuCommandDispatcher, - public nsSupportsWeakReference +class nsMenuBarX : public nsIMenuBar, + public nsIMenuListener, + public nsIDocumentObserver, + public nsIChangeManager, + public nsIMenuCommandDispatcher, + public nsSupportsWeakReference { public: nsMenuBarX(); virtual ~nsMenuBarX(); - - enum { kAppleMenuID = 1 } ; + + enum {kApplicationMenuID = 1}; NS_DECL_ISUPPORTS NS_DECL_NSICHANGEMANAGER @@ -119,44 +117,44 @@ public: protected: - void GetDocument ( nsIDocShell* inDocShell, nsIDocument** outDocument ) ; - void RegisterAsDocumentObserver ( nsIDocShell* inDocShell ) ; + void GetDocument(nsIDocShell* inDocShell, nsIDocument** outDocument) ; + void RegisterAsDocumentObserver(nsIDocShell* inDocShell); - // Make our menubar conform to Aqua UI guidelines - void AquifyMenuBar ( ) ; - void HideItem ( nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode ) ; - OSStatus InstallCommandEventHandler ( ) ; + // Make our menubar conform to Aqua UI guidelines + void AquifyMenuBar(); + void HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode); + OSStatus InstallCommandEventHandler(); - // command handler for some special menu items (prefs/quit/etc) - pascal static OSStatus CommandEventHandler ( EventHandlerCallRef inHandlerChain, - EventRef inEvent, void* userData ) ; - nsEventStatus ExecuteCommand ( nsIContent* inDispatchTo ) ; + // command handler for some special menu items (prefs/quit/etc) + pascal static OSStatus CommandEventHandler(EventHandlerCallRef inHandlerChain, + EventRef inEvent, void* userData); + nsEventStatus ExecuteCommand(nsIContent* inDispatchTo); - // build the Apple menu shared by all menu bars. - nsresult CreateAppleMenu ( nsIMenu* inMenu ) ; + // build the Application menu shared by all menu bars. + nsresult CreateApplicationMenu(nsIMenu* inMenu); - nsHashtable mObserverTable; // stores observers for content change notification - nsHashtable mCommandMapTable; // maps CommandIDs to content nodes for CarbonEvent item selection - PRUint32 mCurrentCommandID; // unique command id (per menu-bar) to give to next item that asks + nsHashtable mObserverTable; // stores observers for content change notification + nsHashtable mCommandMapTable; // maps CommandIDs to content nodes for CarbonEvent item selection PRUint32 mNumMenus; - nsSupportsArray mMenusArray; // holds refs - nsCOMPtr mMenuBarContent; // menubar content node, strong ref - nsCOMPtr mPrefItemContent; // on X, holds the content node for the prefs item that has - // been removed from the menubar - nsCOMPtr mQuitItemContent; // as above, but for quit - nsIWidget* mParent; // weak ref - + nsSupportsArray mMenusArray; // holds refs + nsCOMPtr mMenuBarContent; // menubar content node, strong ref + nsCOMPtr mPrefItemContent; // on X, holds the content node for the prefs item that has + // been removed from the menubar + nsCOMPtr mQuitItemContent; // as above, but for quit + nsIWidget* mParent; // weak ref PRBool mIsMenuBarAdded; + PRUint32 mCurrentCommandID; // unique command id (per menu-bar) to give to next item that asks - nsWeakPtr mDocShellWeakRef; // weak ref to docshell - nsIDocument* mDocument; // pointer to document - MenuRef mRootMenu; // root menu, representing entire menu bar. + nsWeakPtr mDocShellWeakRef; // weak ref to docshell + nsIDocument* mDocument; // pointer to document + + NSMenu* mRootMenu; // root menu, representing entire menu bar. - static MenuRef sAppleMenu; // AppleMenu shared by all menubars + static NSMenu* sApplicationMenu; // Application menu shared by all menubars - static EventHandlerUPP sCommandEventHandler; // carbon event handler for commands, shared + static EventHandlerUPP sCommandEventHandler; // carbon event handler for commands, shared }; #endif // nsMenuBarX_h__ diff --git a/widget/src/cocoa/nsMenuX.h b/widget/src/cocoa/nsMenuX.h index 5ea7d83878a4..d7028df63334 100644 --- a/widget/src/cocoa/nsMenuX.h +++ b/widget/src/cocoa/nsMenuX.h @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Josh Aas * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -45,17 +46,23 @@ #include "nsIChangeManager.h" #include "nsWeakReference.h" -#include -#include -#include +#import +#import class nsIMenuBar; class nsIMenuListener; +class nsMenuX; -//static PRInt16 mMacMenuIDCount; // use GetUniqueMenuID() -extern PRInt16 mMacMenuIDCount;// = kMacMenuID; +// This class simply receives events from menus as a proxy for a gecko menu +@interface MenuDelegate : NSObject +{ + nsMenuX* mGeckoMenu; // weak ref + BOOL mHaveInstalledCarbonEvents; +} +- (id)initWithGeckoMenu:(nsMenuX*)geckoMenu; +@end class nsMenuX : public nsIMenu, @@ -75,15 +82,15 @@ public: nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, + nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, void * menuNode, void * aDocShell); nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); nsEventStatus CheckRebuild(PRBool & aMenuEvent); nsEventStatus SetRebuild(PRBool aMenuEvent); // nsIMenu Methods - NS_IMETHOD Create ( nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey, - nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) ; + NS_IMETHOD Create (nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey, + nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode); NS_IMETHOD GetParent(nsISupports *&aParent); NS_IMETHOD GetLabel(nsString &aText); NS_IMETHOD SetLabel(const nsAString &aText); @@ -105,37 +112,36 @@ public: NS_IMETHOD GetEnabled(PRBool* aIsEnabled); NS_IMETHOD IsHelpMenu(PRBool* aIsEnabled); - // NS_IMETHOD AddMenuItem(nsIMenuItem * aMenuItem); NS_IMETHOD AddMenu(nsIMenu * aMenu); - + protected: - // Determines how many menus are visible among the siblings that are before me. - // It doesn't matter if I am visible. - nsresult CountVisibleBefore ( PRUint32* outVisibleBefore ) ; + // Determines how many menus are visible among the siblings that are before me. + // It doesn't matter if I am visible. + nsresult CountVisibleBefore(PRUint32* outVisibleBefore); // fetch the content node associated with the menupopup item - void GetMenuPopupContent ( nsIContent** aResult ) ; + void GetMenuPopupContent(nsIContent** aResult); - // Insert a new item in this menu with index |inItemIndex| with the text |inItemLabel|, - // middle-truncated to a certain pixel width with an elipsis. - void InsertMenuItemWithTruncation ( nsAutoString & inItemLabel, - PRUint32 inItemIndex ) ; + // Insert a new item in this menu with index |inItemIndex| with the text |inItemLabel|, + // middle-truncated to a certain pixel width with an elipsis. + void InsertMenuItemWithTruncation(nsAutoString & inItemLabel, + PRUint32 inItemIndex); // fire handlers for oncreate/ondestroy - PRBool OnDestroy() ; - PRBool OnCreate() ; - PRBool OnDestroyed() ; - PRBool OnCreated() ; + PRBool OnDestroy(); + PRBool OnCreate(); + PRBool OnDestroyed(); + PRBool OnCreated(); - void LoadMenuItem ( nsIMenu* pParentMenu, nsIContent* menuitemContent ); - void LoadSubMenu ( nsIMenu * pParentMenu, nsIContent* menuitemContent ); - void LoadSeparator ( nsIContent* menuitemContent ); + void LoadMenuItem(nsIMenu* pParentMenu, nsIContent* menuitemContent); + void LoadSubMenu(nsIMenu * pParentMenu, nsIContent* menuitemContent); + void LoadSeparator(nsIContent* menuitemContent); - nsEventStatus HelpMenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow, - void* unused, void* aDocShell); + nsEventStatus HelpMenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow, + void* unused, void* aDocShell); - MenuHandle NSStringNewMenu(short menuID, nsString& menuTitle); + NSMenu* CreateMenuWithGeckoString(nsString& menuTitle); protected: nsString mLabel; @@ -148,9 +154,10 @@ protected: nsCOMPtr mMenuContent; // the |menu| tag, strong ref nsCOMPtr mListener; // strong ref - // MacSpecific + // Mac specific PRInt16 mMacMenuID; - MenuHandle mMacMenuHandle; + NSMenu* mMacMenu; // strong ref, we own it + MenuDelegate* mMenuDelegate; // strong ref, we keep this around to get events for us PRInt16 mHelpMenuOSItemsCount; PRPackedBool mIsHelpMenu; PRPackedBool mIsEnabled;