From 188f4d813adc29c264517ca570ed5dcc3ee13fe6 Mon Sep 17 00:00:00 2001 From: "joshmoz%gmail.com" Date: Mon, 17 Sep 2007 15:07:00 +0000 Subject: [PATCH] remove all docshell and webshell usage from cocoa widgets. b=273812 r=cbarrett sr=bz a=roc git-svn-id: svn://10.0.0.236/trunk@236097 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/public/nsIMenuListener.h | 11 ++-- mozilla/widget/src/cocoa/Makefile.in | 2 - mozilla/widget/src/cocoa/nsMenuBarX.h | 11 +--- mozilla/widget/src/cocoa/nsMenuBarX.mm | 65 +++++-------------- mozilla/widget/src/cocoa/nsMenuItemX.h | 3 +- mozilla/widget/src/cocoa/nsMenuItemX.mm | 4 +- mozilla/widget/src/cocoa/nsMenuX.h | 3 +- mozilla/widget/src/cocoa/nsMenuX.mm | 9 +-- .../xpfe/appshell/src/nsWebShellWindow.cpp | 8 +-- 9 files changed, 31 insertions(+), 85 deletions(-) diff --git a/mozilla/widget/public/nsIMenuListener.h b/mozilla/widget/public/nsIMenuListener.h index 8de37c6d1d0..d19e9bef3bc 100644 --- a/mozilla/widget/public/nsIMenuListener.h +++ b/mozilla/widget/public/nsIMenuListener.h @@ -43,10 +43,10 @@ class nsIWidget; -// {f2e79602-1700-11d5-bb6f-90f240fe493c} +// F463E22A-C5A9-4443-9407-2A7CD6634AE1 #define NS_IMENULISTENER_IID \ -{ 0xf2e79602, 0x1700, 0x11d5, \ - { 0xbb, 0x6f, 0x90, 0xf2, 0x40, 0xfe, 0x49, 0x3c } } +{ 0xF463E22A, 0xC5A9, 0x4443, \ + { 0x94, 0x07, 0x2A, 0x7C, 0xD6, 0x63, 0x4A, 0xE1 } } /** * @@ -81,9 +81,8 @@ class nsIMenuListener : public nsISupports { */ virtual nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent) = 0; - virtual nsEventStatus MenuConstruct( const nsMenuEvent & aMenuEvent, - nsIWidget* aParentWindow, void* aNode, - void* aDocShell) = 0; + virtual nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, + nsIWidget* aParentWindow, void* aNode) = 0; virtual nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent) = 0; diff --git a/mozilla/widget/src/cocoa/Makefile.in b/mozilla/widget/src/cocoa/Makefile.in index d05063cc786..ddf759ed9de 100644 --- a/mozilla/widget/src/cocoa/Makefile.in +++ b/mozilla/widget/src/cocoa/Makefile.in @@ -56,8 +56,6 @@ REQUIRES = xpcom \ string \ uconv \ dom \ - webshell \ - docshell \ plugin \ content \ layout \ diff --git a/mozilla/widget/src/cocoa/nsMenuBarX.h b/mozilla/widget/src/cocoa/nsMenuBarX.h index 74408a3fb47..72505b58f41 100644 --- a/mozilla/widget/src/cocoa/nsMenuBarX.h +++ b/mozilla/widget/src/cocoa/nsMenuBarX.h @@ -55,7 +55,6 @@ class nsIWidget; class nsIDocument; class nsIDOMNode; -class nsIDocShell; extern "C" MenuRef _NSGetCarbonMenu(NSMenu* aMenu); @@ -63,8 +62,7 @@ PRBool NodeIsHiddenOrCollapsed(nsIContent* inContent); namespace MenuHelpersX { - nsEventStatus DispatchCommandTo(nsIWeakReference* aDocShellWeakRef, - nsIContent* aTargetContent); + nsEventStatus DispatchCommandTo(nsIContent* aTargetContent); NSString* CreateTruncatedCocoaLabel(const nsString& itemLabel); PRUint8 GeckoModifiersForNodeAttribute(const nsString& modifiersAttribute); unsigned int MacModifiersForGeckoModifiers(PRUint8 geckoModifiers); @@ -110,7 +108,7 @@ public: nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, - void * menuNode, void * aDocShell); + void * aMenuNode); nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); nsEventStatus CheckRebuild(PRBool & aMenuEvent); nsEventStatus SetRebuild(PRBool aMenuEvent); @@ -134,9 +132,6 @@ public: NS_IMETHOD SetNativeData(void* aData); protected: - - void GetDocument(nsIDocShell* inDocShell, nsIDocument** outDocument) ; - void RegisterAsDocumentObserver(nsIDocShell* inDocShell); // Make our menubar conform to Aqua UI guidelines void AquifyMenuBar(); @@ -165,8 +160,6 @@ protected: 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 NSMenu* mRootMenu; // root menu, representing entire menu bar diff --git a/mozilla/widget/src/cocoa/nsMenuBarX.mm b/mozilla/widget/src/cocoa/nsMenuBarX.mm index 71ef1dcc8b0..b69b62368ee 100644 --- a/mozilla/widget/src/cocoa/nsMenuBarX.mm +++ b/mozilla/widget/src/cocoa/nsMenuBarX.mm @@ -53,8 +53,6 @@ #include "nsString.h" #include "nsIStringBundle.h" #include "nsIDocument.h" -#include "nsIDocShell.h" -#include "nsIDocumentViewer.h" #include "nsIMutationObserver.h" #include "nsIDOMDocument.h" @@ -207,41 +205,6 @@ nsMenuBarX::SetRebuild(PRBool aNeedsRebuild) } -void -nsMenuBarX::GetDocument(nsIDocShell* inDocShell, nsIDocument** outDocument) -{ - *outDocument = nsnull; - - if (inDocShell) { - nsCOMPtr cv; - inDocShell->GetContentViewer(getter_AddRefs(cv)); - if (cv) { - // get the document - nsCOMPtr docv(do_QueryInterface(cv)); - if (!docv) - return; - docv->GetDocument(outDocument); // addrefs - } - } -} - - -void -nsMenuBarX::RegisterAsDocumentObserver(nsIDocShell* inDocShell) -{ - nsCOMPtr doc; - GetDocument(inDocShell, getter_AddRefs(doc)); - if (!doc) - return; - - // register ourselves - doc->AddMutationObserver(this); - // also get pointer to doc, just in case docshell goes away - // we can still remove ourself as doc observer directly from doc - mDocument = doc; -} - - // 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). @@ -384,8 +347,8 @@ nsMenuBarX::ExecuteCommand(nsIContent* inDispatchTo) if (!inDispatchTo) return nsEventStatus_eIgnore; - return MenuHelpersX::DispatchCommandTo(mDocShellWeakRef, inDispatchTo); -} // ExecuteCommand + return MenuHelpersX::DispatchCommandTo(inDispatchTo); +} // Hide the item in the menu by setting the 'hidden' attribute. Returns it in |outHiddenNode| so @@ -409,11 +372,10 @@ nsMenuBarX::HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** nsEventStatus nsMenuBarX::MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow, - void * menubarNode, void * aDocShell) + void * aMenubarNode) { - mDocShellWeakRef = do_GetWeakReference(static_cast(aDocShell)); - nsIDOMNode* aDOMNode = static_cast(menubarNode); - mMenuBarContent = do_QueryInterface(aDOMNode); // strong ref + nsIDOMNode* domNode = static_cast(aMenubarNode); + mMenuBarContent = do_QueryInterface(domNode); // strong ref NS_ASSERTION(mMenuBarContent, "No content specified for this menubar"); if (!mMenuBarContent) return nsEventStatus_eIgnore; @@ -425,11 +387,15 @@ nsMenuBarX::MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWind OSStatus err = InstallCommandEventHandler(); if (err) return nsEventStatus_eIgnore; - - nsCOMPtr docShell = do_QueryReferent(mDocShellWeakRef); - if (docShell) - RegisterAsDocumentObserver(docShell); - + + nsCOMPtr domDoc; + domNode->GetOwnerDocument(getter_AddRefs(domDoc)); + nsCOMPtr doc(do_QueryInterface(domDoc)); + if (!doc) + return nsEventStatus_eIgnore; + doc->AddMutationObserver(this); + mDocument = doc; + // set this as a nsMenuListener on aParentWindow aParentWindow->AddMenuListener((nsIMenuListener *)this); @@ -1031,8 +997,7 @@ nsMenuBarX::Unregister(PRUint32 inCommandID) nsEventStatus -MenuHelpersX::DispatchCommandTo(nsIWeakReference* aDocShellWeakRef, - nsIContent* aTargetContent) +MenuHelpersX::DispatchCommandTo(nsIContent* aTargetContent) { NS_PRECONDITION(aTargetContent, "null ptr"); diff --git a/mozilla/widget/src/cocoa/nsMenuItemX.h b/mozilla/widget/src/cocoa/nsMenuItemX.h index ff83676c37b..b0762677a05 100644 --- a/mozilla/widget/src/cocoa/nsMenuItemX.h +++ b/mozilla/widget/src/cocoa/nsMenuItemX.h @@ -50,7 +50,6 @@ #import class nsIMenu; -class nsIDocShell; class nsMenuItemIconX; /** @@ -97,7 +96,7 @@ public: nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, - void * menuNode, void * aDocShell); + void * aMenuNode); nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); nsEventStatus CheckRebuild(PRBool & aMenuEvent); nsEventStatus SetRebuild(PRBool aMenuEvent); diff --git a/mozilla/widget/src/cocoa/nsMenuItemX.mm b/mozilla/widget/src/cocoa/nsMenuItemX.mm index 1ca20ee68a4..c7fd9025f6a 100644 --- a/mozilla/widget/src/cocoa/nsMenuItemX.mm +++ b/mozilla/widget/src/cocoa/nsMenuItemX.mm @@ -53,7 +53,6 @@ #include "nsIPrivateDOMEvent.h" #include "nsIDOMEventTarget.h" #include "nsIDOMDocumentEvent.h" -#include "nsIDocShell.h" #include "nsMenuItemIconX.h" #include "nsGUIEvent.h" @@ -281,8 +280,7 @@ nsEventStatus nsMenuItemX::MenuDeselected(const nsMenuEvent & aMenuEvent) nsEventStatus nsMenuItemX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, - void * menuNode, - void * aDocShell) + void * aMenuNode) { return nsEventStatus_eIgnore; } diff --git a/mozilla/widget/src/cocoa/nsMenuX.h b/mozilla/widget/src/cocoa/nsMenuX.h index b4cd55c8905..d4b6034d2fb 100644 --- a/mozilla/widget/src/cocoa/nsMenuX.h +++ b/mozilla/widget/src/cocoa/nsMenuX.h @@ -53,7 +53,6 @@ class nsIMenuBar; class nsIMenuListener; -class nsIDocShell; class nsMenuX; class nsMenuItemIconX; @@ -90,7 +89,7 @@ public: nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, - void * menuNode, void * aDocShell); + void * aMenuNode); nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); nsEventStatus CheckRebuild(PRBool & aMenuEvent); nsEventStatus SetRebuild(PRBool aMenuEvent); diff --git a/mozilla/widget/src/cocoa/nsMenuX.mm b/mozilla/widget/src/cocoa/nsMenuX.mm index 1e5162d4f5a..4bd25d6217b 100644 --- a/mozilla/widget/src/cocoa/nsMenuX.mm +++ b/mozilla/widget/src/cocoa/nsMenuX.mm @@ -40,10 +40,8 @@ #include "nsIDocument.h" #include "nsIContent.h" #include "nsIDOMDocument.h" -#include "nsIDocumentViewer.h" #include "nsIDocumentObserver.h" #include "nsIComponentManager.h" -#include "nsIDocShell.h" #include "prinrval.h" #include "nsIRollupListener.h" @@ -159,7 +157,7 @@ nsMenuX::Create(nsISupports * aParent, const nsAString &aLabel, const nsAString // is actually selected, then we can't access keyboard commands until the // menu gets selected, which is bad. nsMenuEvent fake(PR_TRUE, 0, nsnull); - MenuConstruct(fake, nsnull, nsnull, nsnull); + MenuConstruct(fake, nsnull, nsnull); if (menu) mIcon = new nsMenuItemIconX(static_cast(this), menu, mMenuContent, mNativeMenuItem); @@ -476,7 +474,7 @@ nsEventStatus nsMenuX::MenuSelected(const nsMenuEvent & aMenuEvent) if (mNeedsRebuild) RemoveAll(); - MenuConstruct(aMenuEvent, nsnull, nsnull, nsnull); + MenuConstruct(aMenuEvent, nsnull, nsnull); mConstructed = true; } @@ -515,8 +513,7 @@ nsEventStatus nsMenuX::MenuDeselected(const nsMenuEvent & aMenuEvent) nsEventStatus nsMenuX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, - void * /* menuNode */, - void * aDocShell) + void * aMenuNode) { mConstructed = false; gConstructingMenu = PR_TRUE; diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 9ab19cc1353..086dd66f95f 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -494,7 +494,7 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) } #ifdef USE_NATIVE_MENUS -static void LoadNativeMenus(nsIDOMDocument *aDOMDoc, nsIWidget *aParentWindow, nsIDocShell *aDocShell) +static void LoadNativeMenus(nsIDOMDocument *aDOMDoc, nsIWidget *aParentWindow) { // Find the menubar tag (if there is more than one, we ignore all but // the first). @@ -519,7 +519,7 @@ static void LoadNativeMenus(nsIDOMDocument *aDOMDoc, nsIWidget *aParentWindow, n // fake event nsMenuEvent fake(PR_TRUE, 0, nsnull); - menuListener->MenuConstruct(fake, aParentWindow, menubarNode, aDocShell); + menuListener->MenuConstruct(fake, aParentWindow, menubarNode); } #endif @@ -608,9 +608,7 @@ nsWebShellWindow::OnStateChange(nsIWebProgress *aProgress, /////////////////////////////// nsCOMPtr menubarDOMDoc(GetNamedDOMDoc(NS_LITERAL_STRING("this"))); // XXX "this" is a small kludge for code reused if (menubarDOMDoc) - { - LoadNativeMenus(menubarDOMDoc, mWindow, mDocShell); - } + LoadNativeMenus(menubarDOMDoc, mWindow); #endif // USE_NATIVE_MENUS OnChromeLoaded();