From 41b4dabe304c2a30af4f696a6b4427be5fd330ff Mon Sep 17 00:00:00 2001 From: "joshmoz%gmail.com" Date: Fri, 9 Nov 2007 17:38:34 +0000 Subject: [PATCH] remove nsIMenuListener interface and its usage, cuts some memory usage, faster without it, and code is much cleaner. b=400259 r=smorgan sr=roc a=pav git-svn-id: svn://10.0.0.236/trunk@239070 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/public/Makefile.in | 1 - mozilla/widget/public/nsIMenu.h | 54 +++++++--- mozilla/widget/public/nsIMenuBar.h | 13 ++- mozilla/widget/public/nsIMenuItem.h | 19 +--- mozilla/widget/public/nsIMenuListener.h | 95 ---------------- mozilla/widget/public/nsIWidget.h | 19 +--- mozilla/widget/src/cocoa/nsMenuBarX.h | 18 +--- mozilla/widget/src/cocoa/nsMenuBarX.mm | 64 ++--------- mozilla/widget/src/cocoa/nsMenuItemX.h | 16 --- mozilla/widget/src/cocoa/nsMenuItemX.mm | 88 ++------------- mozilla/widget/src/cocoa/nsMenuX.h | 23 ++-- mozilla/widget/src/cocoa/nsMenuX.mm | 102 ++++++------------ mozilla/widget/src/xpwidgets/nsBaseWidget.cpp | 21 ---- mozilla/widget/src/xpwidgets/nsBaseWidget.h | 3 - .../xpfe/appshell/src/nsWebShellWindow.cpp | 6 +- 15 files changed, 111 insertions(+), 431 deletions(-) delete mode 100644 mozilla/widget/public/nsIMenuListener.h diff --git a/mozilla/widget/public/Makefile.in b/mozilla/widget/public/Makefile.in index e7185f4f647..d1369702109 100644 --- a/mozilla/widget/public/Makefile.in +++ b/mozilla/widget/public/Makefile.in @@ -55,7 +55,6 @@ EXPORTS = \ nsEvent.h \ nsIMouseListener.h \ nsIEventListener.h \ - nsIMenuListener.h \ nsWidgetsCID.h \ nsILookAndFeel.h \ nsIPluginWidget.h \ diff --git a/mozilla/widget/public/nsIMenu.h b/mozilla/widget/public/nsIMenu.h index 8cbb617a582..5ac0c86e48d 100644 --- a/mozilla/widget/public/nsIMenu.h +++ b/mozilla/widget/public/nsIMenu.h @@ -40,20 +40,21 @@ #include "nsISupports.h" #include "nsStringFwd.h" +#include "nsEvent.h" class nsIMenuBar; class nsIMenu; class nsIMenuItem; -class nsIMenuListener; class nsIChangeManager; class nsIContent; class nsIMenuCommandDispatcher; +class nsIWidget; -// 9188038F-D392-43BD-AEE7-730C3723643F +// 9225136B-3F56-4CA3-92E0-623D5FB8356B #define NS_IMENU_IID \ -{ 0x9188038F, 0xD392, 0x43BD, \ - { 0xAE, 0xE7, 0x73, 0x0C, 0x37, 0x23, 0x64, 0x3F } } +{ 0x9225136B, 0x3F56, 0x4CA3, \ + { 0x92, 0xE0, 0x62, 0x3D, 0x5F, 0xB8, 0x35, 0x6B } } /** * Menu widget @@ -176,21 +177,9 @@ class nsIMenu : public nsISupports { * */ NS_IMETHOD SetNativeData(void* aData) = 0; - - /** - * Adds menu listener for dynamic construction - * - */ - NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener) = 0; /** - * Removes menu listener for dynamic construction - * - */ - NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener) = 0; - - /** - * Get GetMenuContent + * Get menu content * */ NS_IMETHOD GetMenuContent(nsIContent ** aMenuContent) = 0; @@ -212,8 +201,39 @@ class nsIMenu : public nsISupports { /** * Sets an appropriate icon for the menu. + * */ NS_IMETHOD SetupIcon() = 0; + + /** + * Menu has been selected + * + */ + virtual nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent) = 0; + + /** + * Menu has been deselected + * + */ + virtual void MenuDeselected(const nsMenuEvent & aMenuEvent) = 0; + + /** + * Construct menu + * + */ + virtual void MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, void * aMenuNode) = 0; + + /** + * Destruct menu + * + */ + virtual void MenuDestruct(const nsMenuEvent & aMenuEvent) = 0; + + /** + * Set rebuild + * + */ + virtual void SetRebuild(PRBool aMenuEvent) = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIMenu, NS_IMENU_IID) diff --git a/mozilla/widget/public/nsIMenuBar.h b/mozilla/widget/public/nsIMenuBar.h index 3b39d0b332d..8bbcb1e6fc1 100644 --- a/mozilla/widget/public/nsIMenuBar.h +++ b/mozilla/widget/public/nsIMenuBar.h @@ -44,10 +44,10 @@ class nsIWidget; -// {f2e79601-1700-11d5-bb6f-90f240fe493c} +// F81C6D64-B260-44ED-9289-2E410A130E35 #define NS_IMENUBAR_IID \ -{ 0xf2e79601, 0x1700, 0x11d5, \ - { 0xbb, 0x6f, 0x90, 0xf2, 0x40, 0xfe, 0x49, 0x3c } } +{ 0xF81C6D64, 0xB260, 0x44ED, \ + { 0x92, 0x89, 0x2E, 0x41, 0x0A, 0x13, 0x0E, 0x35 } } /** * MenuBar widget @@ -128,7 +128,12 @@ class nsIMenuBar : public nsISupports { * */ NS_IMETHOD Paint() = 0; - + + /** + * Construct the menubar + * + */ + NS_IMETHOD MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, void * aMenuNode) = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIMenuBar, NS_IMENUBAR_IID) diff --git a/mozilla/widget/public/nsIMenuItem.h b/mozilla/widget/public/nsIMenuItem.h index 530a34872df..a590b2e7e62 100644 --- a/mozilla/widget/public/nsIMenuItem.h +++ b/mozilla/widget/public/nsIMenuItem.h @@ -44,14 +44,13 @@ #include "nsIDOMElement.h" -// 7DF81BE2-51F4-4CAA-9FD7-3F974A7AEA51 +// CC986E81-9F46-4AA2-B809-C544789E6F06 #define NS_IMENUITEM_IID \ -{ 0x7DF81BE2, 0x51F4, 0x4CAA, \ - { 0x9F, 0xD7, 0x3F, 0x97, 0x4A, 0x7A, 0xEA, 0x51 } } +{ 0xCC986E81, 0x9F46, 0x4AA2, \ + { 0xB8, 0x09, 0xC5, 0x44, 0x78, 0x9E, 0x6F, 0x06 } } class nsIMenu; class nsIWidget; -class nsIMenuListener; class nsIChangeManager; class nsIContent; @@ -128,18 +127,6 @@ class nsIMenuItem : public nsISupports { */ NS_IMETHOD GetNativeData(void*& aData) = 0; - /** - * Adds menu listener - * - */ - NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener) = 0; - - /** - * Removes menu listener - * - */ - NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener) = 0; - /** * Indicates whether it is a separator * diff --git a/mozilla/widget/public/nsIMenuListener.h b/mozilla/widget/public/nsIMenuListener.h deleted file mode 100644 index d19e9bef3bc..00000000000 --- a/mozilla/widget/public/nsIMenuListener.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * 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 - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIMenuListener_h__ -#define nsIMenuListener_h__ - -#include "nsISupports.h" -#include "nsEvent.h" - -class nsIWidget; - -// F463E22A-C5A9-4443-9407-2A7CD6634AE1 -#define NS_IMENULISTENER_IID \ -{ 0xF463E22A, 0xC5A9, 0x4443, \ - { 0x94, 0x07, 0x2A, 0x7C, 0xD6, 0x63, 0x4A, 0xE1 } } - -/** - * - * Menu event listener - * This interface should only be implemented by the menu manager - * These are registered with nsWindows to receive menu events - */ - -class nsIMenuListener : public nsISupports { - - public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMENULISTENER_IID) - - /** - * Processes a menu item selected event - * @param aMenuEvent See nsGUIEvent.h - * @return whether the event was consumed or ignored. See nsEventStatus - */ - virtual nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent) = 0; - - /** - * Processes a menu selected event - * @param aMenuEvent See nsGUIEvent.h - * @return whether the event was consumed or ignored. See nsEventStatus - */ - virtual nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent) = 0; - - /** - * Processes a menu deselect event - * @param aMenuEvent See nsGUIEvent.h - * @return whether the event was consumed or ignored. See nsEventStatus - */ - virtual nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent) = 0; - - virtual nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, - nsIWidget* aParentWindow, void* aNode) = 0; - - virtual nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent) = 0; - - virtual nsEventStatus CheckRebuild(PRBool & aMenuEvent) = 0; - virtual nsEventStatus SetRebuild(PRBool aMenuEvent) = 0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIMenuListener, NS_IMENULISTENER_IID) - -#endif // nsIMenuListener_h__ diff --git a/mozilla/widget/public/nsIWidget.h b/mozilla/widget/public/nsIWidget.h index 5a32ebd1268..a90bd95faf7 100644 --- a/mozilla/widget/public/nsIWidget.h +++ b/mozilla/widget/public/nsIWidget.h @@ -40,8 +40,6 @@ #include "nsISupports.h" #include "nsColor.h" -#include "nsIMouseListener.h" -#include "nsIMenuListener.h" #include "nsCoord.h" #include "prthread.h" @@ -64,6 +62,7 @@ class nsGUIEvent; struct nsColorMap; class imgIContainer; class gfxASurface; +class nsIMouseListener; /** * Callback function that processes events. @@ -95,11 +94,10 @@ typedef nsEventStatus (*PR_CALLBACK EVENT_CALLBACK)(nsGUIEvent *event); #define NS_NATIVE_PLUGIN_PORT_CG 101 #endif -// d9d02313-6a10-4b6d-9f15-18177e94047a - +// 3B4E560A-11E6-4EBD-B987-35385624970D #define NS_IWIDGET_IID \ -{ 0xd9d02313, 0x6a10, 0x4b6d, \ - { 0x9f, 0x15, 0x18, 0x17, 0x7e, 0x94, 0x04, 0x7a } } +{ 0x3B4E560A, 0x11E6, 0x4EBD, \ + { 0xB9, 0x87, 0x35, 0x38, 0x56, 0x24, 0x97, 0x0D } } // Hide the native window systems real window type so as to avoid // including native window system types and api's. This is necessary @@ -765,15 +763,6 @@ class nsIWidget : public nsISupports { NS_IMETHOD AddEventListener(nsIEventListener * aListener) = 0; - /** - * Adds a menu listener to this widget - * Any existing menu listener is replaced - * - * @param aListener menu listener to add to this widget. - */ - - NS_IMETHOD AddMenuListener(nsIMenuListener * aListener) = 0; - /** * Return the widget's toolkit * diff --git a/mozilla/widget/src/cocoa/nsMenuBarX.h b/mozilla/widget/src/cocoa/nsMenuBarX.h index 46e3d84f3b1..a390a4e3216 100644 --- a/mozilla/widget/src/cocoa/nsMenuBarX.h +++ b/mozilla/widget/src/cocoa/nsMenuBarX.h @@ -40,7 +40,6 @@ #define nsMenuBarX_h_ #include "nsIMenuBar.h" -#include "nsIMenuListener.h" #include "nsIMutationObserver.h" #include "nsIChangeManager.h" #include "nsIMenuCommandDispatcher.h" @@ -82,7 +81,6 @@ namespace MenuHelpersX // class nsMenuBarX : public nsIMenuBar, - public nsIMenuListener, public nsIMutationObserver, public nsIChangeManager, public nsIMenuCommandDispatcher, @@ -101,22 +99,11 @@ public: NS_DECL_NSICHANGEMANAGER NS_DECL_NSIMENUCOMMANDDISPATCHER - // nsIMenuListener interface - nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, - void * aMenuNode); - nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); - nsEventStatus CheckRebuild(PRBool & aMenuEvent); - nsEventStatus SetRebuild(PRBool aMenuEvent); - // nsIMutationObserver NS_DECL_NSIMUTATIONOBSERVER - NS_IMETHOD Create(nsIWidget * aParent); - // nsIMenuBar Methods + NS_IMETHOD Create(nsIWidget * aParent); NS_IMETHOD GetParent(nsIWidget *&aParent); NS_IMETHOD SetParent(nsIWidget * aParent); NS_IMETHOD AddMenu(nsIMenu * aMenu); @@ -128,7 +115,8 @@ public: NS_IMETHOD GetNativeData(void*& aData); NS_IMETHOD Paint(); NS_IMETHOD SetNativeData(void* aData); - + NS_IMETHOD MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, void * aMenuNode); + protected: // Make our menubar conform to Aqua UI guidelines diff --git a/mozilla/widget/src/cocoa/nsMenuBarX.mm b/mozilla/widget/src/cocoa/nsMenuBarX.mm index 68ff9e8d95d..6993e2f3219 100644 --- a/mozilla/widget/src/cocoa/nsMenuBarX.mm +++ b/mozilla/widget/src/cocoa/nsMenuBarX.mm @@ -64,7 +64,7 @@ #include "nsWidgetsCID.h" static NS_DEFINE_CID(kMenuCID, NS_MENU_CID); -NS_IMPL_ISUPPORTS6(nsMenuBarX, nsIMenuBar, nsIMenuListener, nsIMutationObserver, +NS_IMPL_ISUPPORTS5(nsMenuBarX, nsIMenuBar, nsIMutationObserver, nsIChangeManager, nsIMenuCommandDispatcher, nsISupportsWeakReference) EventHandlerUPP nsMenuBarX::sCommandEventHandler = nsnull; @@ -133,42 +133,6 @@ nsMenuBarX::~nsMenuBarX() } -nsEventStatus -nsMenuBarX::MenuItemSelected(const nsMenuEvent &aMenuEvent) -{ - return nsEventStatus_eIgnore; -} - - -nsEventStatus -nsMenuBarX::MenuSelected(const nsMenuEvent &aMenuEvent) -{ - return nsEventStatus_eIgnore; -} - - -nsEventStatus -nsMenuBarX::MenuDeselected(const nsMenuEvent & aMenuEvent) -{ - return nsEventStatus_eIgnore; -} - - -nsEventStatus -nsMenuBarX::CheckRebuild(PRBool & aNeedsRebuild) -{ - aNeedsRebuild = PR_TRUE; - return nsEventStatus_eIgnore; -} - - -nsEventStatus -nsMenuBarX::SetRebuild(PRBool aNeedsRebuild) -{ - return nsEventStatus_eIgnore; -} - - // Do what's necessary to conform to the Aqua guidelines for menus. void nsMenuBarX::AquifyMenuBar() @@ -332,29 +296,28 @@ nsMenuBarX::HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** } -nsEventStatus -nsMenuBarX::MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow, - void * aMenubarNode) +NS_IMETHODIMP +nsMenuBarX::MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow, void * aMenubarNode) { 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; - + return NS_ERROR_FAILURE; + SetParent(aParentWindow); - + AquifyMenuBar(); - + OSStatus err = InstallCommandEventHandler(); if (err) - return nsEventStatus_eIgnore; + return NS_ERROR_FAILURE; nsCOMPtr domDoc; domNode->GetOwnerDocument(getter_AddRefs(domDoc)); nsCOMPtr doc(do_QueryInterface(domDoc)); if (!doc) - return nsEventStatus_eIgnore; + return NS_ERROR_FAILURE; doc->AddMutationObserver(this); mDocument = doc; @@ -384,14 +347,7 @@ nsMenuBarX::MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWind // The parent takes ownership. aParentWindow->SetMenuBar(this); - return nsEventStatus_eIgnore; -} - - -nsEventStatus -nsMenuBarX::MenuDestruct(const nsMenuEvent & aMenuEvent) -{ - return nsEventStatus_eIgnore; + return NS_OK; } diff --git a/mozilla/widget/src/cocoa/nsMenuItemX.h b/mozilla/widget/src/cocoa/nsMenuItemX.h index b0762677a05..38fec6c6d91 100644 --- a/mozilla/widget/src/cocoa/nsMenuItemX.h +++ b/mozilla/widget/src/cocoa/nsMenuItemX.h @@ -41,7 +41,6 @@ #include "nsIMenuItem.h" #include "nsString.h" -#include "nsIMenuListener.h" #include "nsIChangeManager.h" #include "nsWeakReference.h" #include "nsIWidget.h" @@ -57,7 +56,6 @@ class nsMenuItemIconX; */ class nsMenuItemX : public nsIMenuItem, - public nsIMenuListener, public nsIChangeObserver, public nsSupportsWeakReference { @@ -80,8 +78,6 @@ public: NS_IMETHOD GetChecked(PRBool *aIsEnabled); NS_IMETHOD GetMenuItemType(EMenuItemType *aIsCheckbox); NS_IMETHOD GetNativeData(void*& aData); - NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener); - NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener); NS_IMETHOD IsSeparator(PRBool & aIsSep); NS_IMETHOD DoCommand(); @@ -90,16 +86,6 @@ public: NS_IMETHOD GetModifiers(PRUint8 * aModifiers); NS_IMETHOD SetupIcon(); NS_IMETHOD GetMenuItemContent(nsIContent ** aMenuItemContent); - - // nsIMenuListener interface - nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, - void * aMenuNode); - nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); - nsEventStatus CheckRebuild(PRBool & aMenuEvent); - nsEventStatus SetRebuild(PRBool aMenuEvent); protected: @@ -112,8 +98,6 @@ protected: nsIMenu* mMenuParent; // weak, parent owns us nsIChangeManager* mManager; // weak - - nsCOMPtr mXULCommandListener; nsCOMPtr mContent; nsCOMPtr mCommandContent; diff --git a/mozilla/widget/src/cocoa/nsMenuItemX.mm b/mozilla/widget/src/cocoa/nsMenuItemX.mm index 5012b7c4364..949c713ab44 100644 --- a/mozilla/widget/src/cocoa/nsMenuItemX.mm +++ b/mozilla/widget/src/cocoa/nsMenuItemX.mm @@ -44,7 +44,6 @@ #include "nsIMenu.h" #include "nsIMenuBar.h" #include "nsIWidget.h" -#include "nsIMenuListener.h" #include "nsINameSpaceManager.h" #include "nsWidgetAtoms.h" #include "nsIServiceManager.h" @@ -58,7 +57,7 @@ #include "nsGUIEvent.h" -NS_IMPL_ISUPPORTS4(nsMenuItemX, nsIMenuItem, nsIMenuListener, nsIChangeObserver, nsISupportsWeakReference) +NS_IMPL_ISUPPORTS3(nsMenuItemX, nsIMenuItem, nsIChangeObserver, nsISupportsWeakReference) nsMenuItemX::nsMenuItemX() @@ -226,21 +225,6 @@ NS_METHOD nsMenuItemX::GetNativeData(void *& aData) } -NS_METHOD nsMenuItemX::AddMenuListener(nsIMenuListener * aMenuListener) -{ - mXULCommandListener = aMenuListener; // addref - return NS_OK; -} - - -NS_METHOD nsMenuItemX::RemoveMenuListener(nsIMenuListener * aMenuListener) -{ - if (mXULCommandListener.get() == aMenuListener) - mXULCommandListener = nsnull; - return NS_OK; -} - - NS_METHOD nsMenuItemX::IsSeparator(PRBool & aIsSep) { aIsSep = (mType == nsIMenuItem::eSeparator); @@ -248,62 +232,6 @@ NS_METHOD nsMenuItemX::IsSeparator(PRBool & aIsSep) } -// -// nsIMenuListener interface -// - - -nsEventStatus nsMenuItemX::MenuItemSelected(const nsMenuEvent & aMenuEvent) -{ - return nsEventStatus_eIgnore; -} - - -nsEventStatus nsMenuItemX::MenuSelected(const nsMenuEvent & aMenuEvent) -{ - return nsEventStatus_eIgnore; -} - - -// -// nsIMenuListener interface -// - - -nsEventStatus nsMenuItemX::MenuDeselected(const nsMenuEvent & aMenuEvent) -{ - return nsEventStatus_eIgnore; -} - - -nsEventStatus nsMenuItemX::MenuConstruct( - const nsMenuEvent & aMenuEvent, - nsIWidget * aParentWindow, - void * aMenuNode) -{ - return nsEventStatus_eIgnore; -} - - -nsEventStatus nsMenuItemX::MenuDestruct(const nsMenuEvent & aMenuEvent) -{ - return nsEventStatus_eIgnore; -} - - -nsEventStatus nsMenuItemX::CheckRebuild(PRBool & aNeedsRebuild) -{ - aNeedsRebuild = PR_TRUE; - return nsEventStatus_eIgnore; -} - - -nsEventStatus nsMenuItemX::SetRebuild(PRBool aNeedsRebuild) -{ - return nsEventStatus_eIgnore; -} - - // Executes the "cached" javaScript command. // Returns NS_OK if the command was executed properly, otherwise an error code. NS_IMETHODIMP nsMenuItemX::DoCommand() @@ -459,14 +387,12 @@ nsMenuItemX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIC nsWidgetAtoms::_true, eCaseMatters)) UncheckRadioSiblings(mContent); } - nsCOMPtr listener = do_QueryInterface(mMenuParent); - listener->SetRebuild(PR_TRUE); + mMenuParent->SetRebuild(PR_TRUE); } else if (aAttribute == nsWidgetAtoms::hidden || aAttribute == nsWidgetAtoms::collapsed || aAttribute == nsWidgetAtoms::label) { - nsCOMPtr listener = do_QueryInterface(mMenuParent); - listener->SetRebuild(PR_TRUE); + mMenuParent->SetRebuild(PR_TRUE); } else if (aAttribute == nsWidgetAtoms::image) { SetupIcon(); @@ -513,9 +439,8 @@ nsMenuItemX::ContentRemoved(nsIDocument *aDocument, nsIContent *aChild, PRInt32 mManager->Unregister(mCommandContent); mCommandContent = nsnull; } - - nsCOMPtr listener = do_QueryInterface(mMenuParent); - listener->SetRebuild(PR_TRUE); + + mMenuParent->SetRebuild(PR_TRUE); return NS_OK; } @@ -523,8 +448,7 @@ nsMenuItemX::ContentRemoved(nsIDocument *aDocument, nsIContent *aChild, PRInt32 NS_IMETHODIMP nsMenuItemX::ContentInserted(nsIDocument *aDocument, nsIContent *aChild, PRInt32 aIndexInContainer) { - nsCOMPtr listener = do_QueryInterface(mMenuParent); - listener->SetRebuild(PR_TRUE); + mMenuParent->SetRebuild(PR_TRUE); return NS_OK; } diff --git a/mozilla/widget/src/cocoa/nsMenuX.h b/mozilla/widget/src/cocoa/nsMenuX.h index d4b6034d2fb..84fa7dbddde 100644 --- a/mozilla/widget/src/cocoa/nsMenuX.h +++ b/mozilla/widget/src/cocoa/nsMenuX.h @@ -42,7 +42,6 @@ #include "nsCOMPtr.h" #include "nsAutoPtr.h" #include "nsIMenu.h" -#include "nsIMenuListener.h" #include "nsIChangeManager.h" #include "nsWeakReference.h" #include "nsMenuBarX.h" @@ -52,7 +51,6 @@ class nsIMenuBar; -class nsIMenuListener; class nsMenuX; class nsMenuItemIconX; @@ -70,7 +68,6 @@ class nsMenuItemIconX; class nsMenuX : public nsIMenu, - public nsIMenuListener, public nsIChangeObserver, public nsSupportsWeakReference { @@ -84,16 +81,6 @@ public: id GetNativeMenuItem(); - // nsIMenuListener methods - nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, - void * aMenuNode); - 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, nsIContent* aNode); @@ -112,8 +99,6 @@ public: NS_IMETHOD RemoveAll(); NS_IMETHOD GetNativeData(void** aData); NS_IMETHOD SetNativeData(void* aData); - NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener); - NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener); NS_IMETHOD GetMenuContent(nsIContent ** aMenuNode); NS_IMETHOD SetEnabled(PRBool aIsEnabled); NS_IMETHOD GetEnabled(PRBool* aIsEnabled); @@ -123,7 +108,12 @@ public: void** aMenuRef, PRUint16* aMenuItemIndex); NS_IMETHOD SetupIcon(); - + nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); + void MenuDeselected(const nsMenuEvent & aMenuEvent); + void MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, void * aMenuNode); + void MenuDestruct(const nsMenuEvent & aMenuEvent); + void SetRebuild(PRBool aMenuEvent); + protected: // Determines how many menus are visible among the siblings that are before me. // It doesn't matter if I am visible. @@ -154,7 +144,6 @@ protected: nsISupports* mParent; // weak, my parent owns me nsIChangeManager* mManager; // weak ref, it will outlive us [menubar] nsCOMPtr mMenuContent; // the |menu| tag, strong ref - nsCOMPtr mListener; // strong ref nsRefPtr mIcon; // Mac specific diff --git a/mozilla/widget/src/cocoa/nsMenuX.mm b/mozilla/widget/src/cocoa/nsMenuX.mm index cdd70057b68..4ed4093e9dc 100644 --- a/mozilla/widget/src/cocoa/nsMenuX.mm +++ b/mozilla/widget/src/cocoa/nsMenuX.mm @@ -50,7 +50,6 @@ #include "nsIMenu.h" #include "nsIMenuBar.h" #include "nsIMenuItem.h" -#include "nsIMenuListener.h" #include "nsIMenuCommandDispatcher.h" #include "nsToolkit.h" @@ -84,7 +83,7 @@ static PRBool gConstructingMenu = PR_FALSE; static NS_DEFINE_CID(kMenuCID, NS_MENU_CID); static NS_DEFINE_CID(kMenuItemCID, NS_MENUITEM_CID); -NS_IMPL_ISUPPORTS4(nsMenuX, nsIMenu, nsIMenuListener, nsIChangeObserver, nsISupportsWeakReference) +NS_IMPL_ISUPPORTS3(nsMenuX, nsIMenu, nsIChangeObserver, nsISupportsWeakReference) nsMenuX::nsMenuX() @@ -422,32 +421,6 @@ NS_IMETHODIMP nsMenuX::SetNativeData(void * aData) } -NS_IMETHODIMP nsMenuX::AddMenuListener(nsIMenuListener * aMenuListener) -{ - mListener = aMenuListener; // strong ref - return NS_OK; -} - - -NS_IMETHODIMP nsMenuX::RemoveMenuListener(nsIMenuListener * aMenuListener) -{ - if (aMenuListener == mListener) - mListener = nsnull; - return NS_OK; -} - - -// -// nsIMenuListener interface -// - - -nsEventStatus nsMenuX::MenuItemSelected(const nsMenuEvent & aMenuEvent) -{ - return nsEventStatus_eIgnore; -} - - nsEventStatus nsMenuX::MenuSelected(const nsMenuEvent & aMenuEvent) { // printf("JOSH: MenuSelected called for %s \n", NS_LossyConvertUTF16toASCII(mLabel).get()); @@ -482,12 +455,12 @@ nsEventStatus nsMenuX::MenuSelected(const nsMenuEvent & aMenuEvent) else { // Make sure none of our submenus are the ones that should be handling this for (PRUint32 i = mMenuItemsArray.Count() - 1; i >= 0; i--) { - nsISupports* menuSupports = mMenuItemsArray.ObjectAt(i); - nsCOMPtr menuListener = do_QueryInterface(menuSupports); - if (menuListener) { - nsEventStatus eventStatus = menuListener->MenuSelected(aMenuEvent); - if (eventStatus != nsEventStatus_eIgnore) - return eventStatus; + nsISupports* menuSupports = mMenuItemsArray.ObjectAt(i); + nsCOMPtr menu = do_QueryInterface(menuSupports); + if (menu) { + nsEventStatus status = menu->MenuSelected(aMenuEvent); + if (status != nsEventStatus_eIgnore) + return status; } } } @@ -496,18 +469,17 @@ nsEventStatus nsMenuX::MenuSelected(const nsMenuEvent & aMenuEvent) } -nsEventStatus nsMenuX::MenuDeselected(const nsMenuEvent & aMenuEvent) +void nsMenuX::MenuDeselected(const nsMenuEvent & aMenuEvent) { // Destroy the menu if (mConstructed) { MenuDestruct(aMenuEvent); mConstructed = false; } - return nsEventStatus_eIgnore; } -nsEventStatus nsMenuX::MenuConstruct( +void nsMenuX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow, void * aMenuNode) @@ -525,7 +497,7 @@ nsEventStatus nsMenuX::MenuConstruct( GetMenuPopupContent(getter_AddRefs(menuPopup)); if (!menuPopup) { gConstructingMenu = PR_FALSE; - return nsEventStatus_eIgnore; + return; } // bug 365405: Manually wrap the menupopup node to make sure it's bounded @@ -570,41 +542,29 @@ nsEventStatus nsMenuX::MenuConstruct( gConstructingMenu = PR_FALSE; mNeedsRebuild = PR_FALSE; // printf("Done building, mMenuItemsArray.Count() = %d \n", mMenuItemsArray.Count()); - - return nsEventStatus_eIgnore; } -nsEventStatus nsMenuX::MenuDestruct(const nsMenuEvent & aMenuEvent) +void nsMenuX::MenuDestruct(const nsMenuEvent & aMenuEvent) { // printf("nsMenuX::MenuDestruct() called for %s \n", NS_LossyConvertUTF16toASCII(mLabel).get()); - - // Fire our ondestroy handler. If we're told to stop, don't destroy the menu - PRBool keepProcessing = OnDestroy(); - if (keepProcessing) { - if (mNeedsRebuild) - mConstructed = false; - // Close the node. - mMenuContent->UnsetAttr(kNameSpaceID_None, nsWidgetAtoms::open, PR_TRUE); - OnDestroyed(); - } - return nsEventStatus_eIgnore; + + // Fire our ondestroy handler. If we're told to stop, don't destroy the menu. + if (!OnDestroy()) + return; + + if (mNeedsRebuild) + mConstructed = false; + // Close the node. + mMenuContent->UnsetAttr(kNameSpaceID_None, nsWidgetAtoms::open, PR_TRUE); + OnDestroyed(); } -nsEventStatus nsMenuX::CheckRebuild(PRBool & aNeedsRebuild) -{ - aNeedsRebuild = PR_TRUE; - return nsEventStatus_eIgnore; -} - - -nsEventStatus nsMenuX::SetRebuild(PRBool aNeedsRebuild) +void nsMenuX::SetRebuild(PRBool aNeedsRebuild) { if (!gConstructingMenu) mNeedsRebuild = aNeedsRebuild; - - return nsEventStatus_eIgnore; } @@ -1026,8 +986,8 @@ NS_IMETHODIMP nsMenuX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpa // the parent menu in order for the changes to be picked up. If we're // a regular menu, just change the title and redraw the menubar. if (!menubarParent) { - nsCOMPtr parentListener(do_QueryInterface(mParent)); - parentListener->SetRebuild(PR_TRUE); + nsCOMPtr parentMenu(do_QueryInterface(mParent)); + parentMenu->SetRebuild(PR_TRUE); } else { // reuse the existing menu, to avoid rebuilding the root menu bar. @@ -1163,17 +1123,19 @@ static pascal OSStatus MyMenuEventHandler(EventHandlerCallRef myHandler, EventRe } nsISupports* supports = reinterpret_cast(userData); - nsCOMPtr listener(do_QueryInterface(supports)); - if (listener) { + nsCOMPtr menu(do_QueryInterface(supports)); + if (menu) { MenuRef menuRef; ::GetEventParameter(event, kEventParamDirectObject, typeMenuRef, NULL, sizeof(menuRef), NULL, &menuRef); nsMenuEvent menuEvent(PR_TRUE, NS_MENU_SELECTED, nsnull); menuEvent.time = PR_IntervalNow(); menuEvent.mCommand = (PRUint32)menuRef; - if (kind == kEventMenuOpening) - listener->MenuSelected(menuEvent); - else - listener->MenuDeselected(menuEvent); + if (kind == kEventMenuOpening) { + menu->MenuSelected(menuEvent); + } + else { + menu->MenuDeselected(menuEvent); + } return noErr; } } diff --git a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp index be48a62d89d..4b9418a2d55 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp +++ b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp @@ -39,7 +39,6 @@ #include "nsBaseWidget.h" #include "nsIDeviceContext.h" #include "nsCOMPtr.h" -#include "nsIMenuListener.h" #include "nsGfxCIID.h" #include "nsWidgetsCID.h" #include "nsIFullScreen.h" @@ -80,7 +79,6 @@ nsBaseWidget::nsBaseWidget() , mToolkit(nsnull) , mMouseListener(nsnull) , mEventListener(nsnull) -, mMenuListener(nsnull) , mCursor(eCursor_standard) , mWindowType(eWindowType_child) , mBorderStyle(eBorderStyle_none) @@ -117,7 +115,6 @@ nsBaseWidget::~nsBaseWidget() printf("WIDGETS- = %d\n", gNumWidgets); #endif - NS_IF_RELEASE(mMenuListener); NS_IF_RELEASE(mToolkit); NS_IF_RELEASE(mContext); if (mOriginalBounds) @@ -250,7 +247,6 @@ NS_METHOD nsBaseWidget::Destroy() // disconnect listeners. NS_IF_RELEASE(mMouseListener); NS_IF_RELEASE(mEventListener); - NS_IF_RELEASE(mMenuListener); return NS_OK; } @@ -718,23 +714,6 @@ NS_METHOD nsBaseWidget::AddEventListener(nsIEventListener * aListener) return NS_OK; } -/** -* Add a menu listener -* This interface should only be called by the menu services manager -* This will AddRef() the menu listener -* This will Release() a previously set menu listener -* -**/ - -NS_METHOD nsBaseWidget::AddMenuListener(nsIMenuListener * aListener) -{ - NS_IF_RELEASE(mMenuListener); - NS_IF_ADDREF(aListener); - mMenuListener = aListener; - return NS_OK; -} - - /** * If the implementation of nsWindow supports borders this method MUST be overridden * diff --git a/mozilla/widget/src/xpwidgets/nsBaseWidget.h b/mozilla/widget/src/xpwidgets/nsBaseWidget.h index e73bae54da8..f75db6efcf7 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseWidget.h +++ b/mozilla/widget/src/xpwidgets/nsBaseWidget.h @@ -41,7 +41,6 @@ #include "nsIWidget.h" #include "nsIMouseListener.h" #include "nsIEventListener.h" -#include "nsIMenuListener.h" #include "nsIToolkit.h" #include "nsIAppShell.h" #include "nsILocalFile.h" @@ -119,7 +118,6 @@ public: NS_IMETHOD SetBorderStyle(nsBorderStyle aBorderStyle); NS_IMETHOD AddMouseListener(nsIMouseListener * aListener); NS_IMETHOD AddEventListener(nsIEventListener * aListener); - NS_IMETHOD AddMenuListener(nsIMenuListener * aListener); NS_IMETHOD SetBounds(const nsRect &aRect); NS_IMETHOD GetBounds(nsRect &aRect); NS_IMETHOD GetClientBounds(nsRect &aRect); @@ -158,7 +156,6 @@ protected: nsIToolkit *mToolkit; nsIMouseListener *mMouseListener; nsIEventListener *mEventListener; - nsIMenuListener *mMenuListener; nscolor mBackground; nscolor mForeground; nsCursor mCursor; diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index edc558d1b1e..3cbfa8028c7 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -109,7 +109,6 @@ #include "nsIMarkupDocumentViewer.h" #if defined(XP_MACOSX) -#include "nsIMenuListener.h" #include "nsIMenuBar.h" #define USE_NATIVE_MENUS #endif @@ -514,12 +513,9 @@ static void LoadNativeMenus(nsIDOMDocument *aDOMDoc, nsIWidget *aParentWindow) if (!pnsMenuBar) return; - // set pnsMenuBar as a nsMenuListener on aParentWindow - nsCOMPtr menuListener = do_QueryInterface(pnsMenuBar); - // fake event nsMenuEvent fake(PR_TRUE, 0, nsnull); - menuListener->MenuConstruct(fake, aParentWindow, menubarNode); + pnsMenuBar->MenuConstruct(fake, aParentWindow, menubarNode); } #endif