Bug 665609: Remove Add/RemoveEventListenerByIID API usage from nsXULPopupListener. r=smaug. Also r=ms2ger on killing NS_NewXULPopupListener.

This commit is contained in:
Jonas Sicking 2011-06-27 12:25:55 -07:00
Родитель b32ddb068b
Коммит d6902ff885
3 изменённых файлов: 21 добавлений и 81 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<nsIDOMMouseEvent> mouseEvent;
mouseEvent = do_QueryInterface(aMouseEvent);
nsCOMPtr<nsIDOMMouseEvent> 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<nsIDOMNSEvent> nsevent(do_QueryInterface(aMouseEvent));
nsCOMPtr<nsIDOMNSEvent> 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<nsIDOMMouseListener *>(pl);
NS_ADDREF(*aListener);
return NS_OK;
}

Просмотреть файл

@ -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___