diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 57e20072dc5..e735d7b99c7 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -2217,16 +2217,13 @@ nsXULElement::AddPopupListener(nsIAtom* aName) return NS_OK; } - nsresult rv = NS_NewXULPopupListener(this, isContext, - getter_AddRefs(popupListener)); - if (NS_FAILED(rv)) - return rv; + popupListener = new nsXULPopupListener(this, isContext); // Add the popup as a listener on this element. nsEventListenerManager* manager = GetListenerManager(PR_TRUE); NS_ENSURE_TRUE(manager, NS_ERROR_FAILURE); - rv = SetProperty(listenerAtom, popupListener, PopupListenerPropertyDtor, - PR_TRUE); + nsresult rv = SetProperty(listenerAtom, popupListener, + PopupListenerPropertyDtor, PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); // Want the property to have a reference to the listener. nsIDOMEventListener* listener = nsnull; diff --git a/content/xul/content/src/nsXULPopupListener.cpp b/content/xul/content/src/nsXULPopupListener.cpp index c6b7aaba01b..2f7b6937708 100644 --- a/content/xul/content/src/nsXULPopupListener.cpp +++ b/content/xul/content/src/nsXULPopupListener.cpp @@ -104,39 +104,26 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULPopupListener) NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULPopupListener) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULPopupListener) - NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener) - NS_INTERFACE_MAP_ENTRY(nsIDOMContextMenuListener) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMMouseListener) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) + NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END //////////////////////////////////////////////////////////////// -// nsIDOMMouseListener +// nsIDOMEventListener nsresult -nsXULPopupListener::MouseDown(nsIDOMEvent* aMouseEvent) +nsXULPopupListener::HandleEvent(nsIDOMEvent* aEvent) { - if(!mIsContext) - return PreLaunchPopup(aMouseEvent); - else + nsAutoString eventType; + aEvent->GetType(eventType); + + if(!((eventType.EqualsLiteral("mousedown") && !mIsContext) || + (eventType.EqualsLiteral("contextmenu") && mIsContext))) return NS_OK; -} -nsresult -nsXULPopupListener::ContextMenu(nsIDOMEvent* aMouseEvent) -{ - if(mIsContext) - return PreLaunchPopup(aMouseEvent); - else - return NS_OK; -} - -nsresult -nsXULPopupListener::PreLaunchPopup(nsIDOMEvent* aMouseEvent) -{ PRUint16 button; - nsCOMPtr mouseEvent; - mouseEvent = do_QueryInterface(aMouseEvent); + nsCOMPtr mouseEvent = do_QueryInterface(aEvent); if (!mouseEvent) { //non-ui event passed in. bad things. return NS_OK; @@ -223,7 +210,7 @@ nsXULPopupListener::PreLaunchPopup(nsIDOMEvent* aMouseEvent) return NS_OK; } - nsCOMPtr nsevent(do_QueryInterface(aMouseEvent)); + nsCOMPtr nsevent = do_QueryInterface(aEvent); if (mIsContext) { #ifndef NS_CONTEXT_MENU_IS_MOUSEUP @@ -240,9 +227,9 @@ nsXULPopupListener::PreLaunchPopup(nsIDOMEvent* aMouseEvent) } // Open the popup and cancel the default handling of the event. - LaunchPopup(aMouseEvent, targetContent); - aMouseEvent->StopPropagation(); - aMouseEvent->PreventDefault(); + LaunchPopup(aEvent, targetContent); + aEvent->StopPropagation(); + aEvent->PreventDefault(); return NS_OK; } @@ -474,17 +461,3 @@ nsXULPopupListener::LaunchPopup(nsIDOMEvent* aEvent, nsIContent* aTargetContent) return NS_OK; } - -//////////////////////////////////////////////////////////////// -nsresult -NS_NewXULPopupListener(nsIDOMElement* aElement, PRBool aIsContext, - nsIDOMEventListener** aListener) -{ - nsXULPopupListener* pl = new nsXULPopupListener(aElement, aIsContext); - if (!pl) - return NS_ERROR_OUT_OF_MEMORY; - - *aListener = static_cast(pl); - NS_ADDREF(*aListener); - return NS_OK; -} diff --git a/content/xul/content/src/nsXULPopupListener.h b/content/xul/content/src/nsXULPopupListener.h index 96876b8a605..82c198f2bd7 100644 --- a/content/xul/content/src/nsXULPopupListener.h +++ b/content/xul/content/src/nsXULPopupListener.h @@ -52,12 +52,10 @@ #include "nsIDOMElement.h" #include "nsIDOMMouseEvent.h" #include "nsIFrame.h" -#include "nsIDOMMouseListener.h" -#include "nsIDOMContextMenuListener.h" +#include "nsIDOMEventListener.h" #include "nsCycleCollectionParticipant.h" -class nsXULPopupListener : public nsIDOMMouseListener, - public nsIDOMContextMenuListener +class nsXULPopupListener : public nsIDOMEventListener { public: // aElement is the element that the popup is attached to. If aIsContext is @@ -69,25 +67,10 @@ public: // nsISupports NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULPopupListener, - nsIDOMMouseListener) - - // nsIDOMMouseListener - NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent); - NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent) { return NS_OK; } - NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; } - NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; } - NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; } - NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; } - - // nsIDOMContextMenuListener - NS_IMETHOD ContextMenu(nsIDOMEvent* aContextMenuEvent); - - // nsIDOMEventListener - NS_IMETHOD HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; } + NS_DECL_CYCLE_COLLECTION_CLASS(nsXULPopupListener) + NS_DECL_NSIDOMEVENTLISTENER protected: - // open the popup. aEvent is the event that triggered the popup such as // a mouse click and aTargetContent is the target of this event. virtual nsresult LaunchPopup(nsIDOMEvent* aEvent, nsIContent* aTargetContent); @@ -96,12 +79,6 @@ protected: virtual void ClosePopup(); private: - - // PreLaunchPopup is called before LaunchPopup to ensure that the event is - // suitable and to initialize the XUL document's popupNode to the event - // target. - nsresult PreLaunchPopup(nsIDOMEvent* aMouseEvent); - #ifndef NS_CONTEXT_MENU_IS_MOUSEUP // When a context menu is opened, focus the target of the contextmenu event. nsresult FireFocusOnTargetContent(nsIDOMNode* aTargetNode); @@ -117,11 +94,4 @@ private: PRBool mIsContext; }; -// Construct a new nsXULPopupListener and return in aListener. See the -// nsXULPopupListener constructor for details about the aElement and -// aIsContext arguments. -nsresult -NS_NewXULPopupListener(nsIDOMElement* aElement, PRBool aIsContext, - nsIDOMEventListener** aListener); - #endif // nsXULPopupListener_h___