Bug 664058: Remove Add/RemoveEventListenerByIID from nsXULTooltipListener. r=smaug

This commit is contained in:
Jonas Sicking 2011-06-30 14:19:40 -07:00
Родитель 5cb18d8d10
Коммит 166dbc4efd
2 изменённых файлов: 50 добавлений и 109 удалений

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

@ -103,38 +103,10 @@ nsXULTooltipListener::~nsXULTooltipListener()
}
}
NS_INTERFACE_MAP_BEGIN(nsXULTooltipListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMMouseMotionListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMMouseListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMouseMotionListener)
NS_INTERFACE_MAP_END
NS_IMPL_ISUPPORTS1(nsXULTooltipListener, nsIDOMEventListener)
NS_IMPL_ADDREF(nsXULTooltipListener)
NS_IMPL_RELEASE(nsXULTooltipListener)
//////////////////////////////////////////////////////////////////////////
//// nsIDOMMouseListener
NS_IMETHODIMP
nsXULTooltipListener::MouseDown(nsIDOMEvent* aMouseEvent)
{
HideTooltip();
return NS_OK;
}
NS_IMETHODIMP
nsXULTooltipListener::MouseUp(nsIDOMEvent* aMouseEvent)
{
HideTooltip();
return NS_OK;
}
NS_IMETHODIMP
nsXULTooltipListener::MouseOut(nsIDOMEvent* aMouseEvent)
void
nsXULTooltipListener::MouseOut(nsIDOMEvent* aEvent)
{
// reset flag so that tooltip will display on the next MouseMove
mTooltipShownOnce = PR_FALSE;
@ -146,12 +118,12 @@ nsXULTooltipListener::MouseOut(nsIDOMEvent* aMouseEvent)
if (mTooltipTimer && !currentTooltip) {
mTooltipTimer->Cancel();
mTooltipTimer = nsnull;
return NS_OK;
return;
}
#ifdef DEBUG_crap
if (mNeedTitletip)
return NS_OK;
return;
#endif
#ifdef MOZ_XUL
@ -160,7 +132,7 @@ nsXULTooltipListener::MouseOut(nsIDOMEvent* aMouseEvent)
if (currentTooltip) {
// which node did the mouse leave?
nsCOMPtr<nsIDOMEventTarget> eventTarget;
aMouseEvent->GetTarget(getter_AddRefs(eventTarget));
aEvent->GetTarget(getter_AddRefs(eventTarget));
nsCOMPtr<nsIDOMNode> targetNode(do_QueryInterface(eventTarget));
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
@ -180,31 +152,28 @@ nsXULTooltipListener::MouseOut(nsIDOMEvent* aMouseEvent)
}
}
#endif
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////
//// nsIDOMMouseMotionListener
NS_IMETHODIMP
nsXULTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent)
void
nsXULTooltipListener::MouseMove(nsIDOMEvent* aEvent)
{
if (!sShowTooltips)
return NS_OK;
return;
// stash the coordinates of the event so that we can still get back to it from within the
// timer callback. On win32, we'll get a MouseMove event even when a popup goes away --
// even when the mouse doesn't change position! To get around this, we make sure the
// mouse has really moved before proceeding.
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aMouseEvent));
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent));
if (!mouseEvent)
return;
PRInt32 newMouseX, newMouseY;
mouseEvent->GetScreenX(&newMouseX);
mouseEvent->GetScreenY(&newMouseY);
// filter out false win32 MouseMove event
if (mMouseScreenX == newMouseX && mMouseScreenY == newMouseY)
return NS_OK;
return;
// filter out minor movements due to crappy optical mice and shaky hands
// to prevent tooltips from hiding prematurely.
@ -213,12 +182,12 @@ nsXULTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent)
if ((currentTooltip) &&
(abs(mMouseScreenX - newMouseX) <= kTooltipMouseMoveTolerance) &&
(abs(mMouseScreenY - newMouseY) <= kTooltipMouseMoveTolerance))
return NS_OK;
return;
mMouseScreenX = newMouseX;
mMouseScreenY = newMouseY;
nsCOMPtr<nsIDOMEventTarget> currentTarget;
aMouseEvent->GetCurrentTarget(getter_AddRefs(currentTarget));
aEvent->GetCurrentTarget(getter_AddRefs(currentTarget));
nsCOMPtr<nsIContent> sourceContent = do_QueryInterface(currentTarget);
mSourceNode = do_GetWeakReference(sourceContent);
@ -238,7 +207,7 @@ nsXULTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent)
// the node, then start the timer to show the tooltip.
if (!currentTooltip && !mTooltipShownOnce) {
nsCOMPtr<nsIDOMEventTarget> eventTarget;
aMouseEvent->GetTarget(getter_AddRefs(eventTarget));
aEvent->GetTarget(getter_AddRefs(eventTarget));
// don't show tooltips attached to elements outside of a menu popup
// when hovering over an element inside it. The popupsinherittooltip
@ -254,7 +223,7 @@ nsXULTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent)
tag == nsGkAtoms::panel ||
tag == nsGkAtoms::tooltip)) {
mSourceNode = nsnull;
return NS_OK;
return;
}
targetContent = targetContent->GetParent();
@ -273,43 +242,35 @@ nsXULTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent)
}
}
}
return NS_OK;
return;
}
#ifdef MOZ_XUL
if (mIsSourceTree)
return NS_OK;
return;
#endif
HideTooltip();
// set a flag so that the tooltip is only displayed once until the mouse
// leaves the node
mTooltipShownOnce = PR_TRUE;
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////
//// nsIDOMKeyListener
NS_IMETHODIMP
nsXULTooltipListener::KeyDown(nsIDOMEvent* aKeyEvent)
{
HideTooltip();
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////
//// nsIDOMEventListener
NS_IMETHODIMP
nsXULTooltipListener::HandleEvent(nsIDOMEvent* aEvent)
{
nsAutoString type;
aEvent->GetType(type);
if (type.EqualsLiteral("DOMMouseScroll") || type.EqualsLiteral("dragstart"))
if (type.EqualsLiteral("DOMMouseScroll") ||
type.EqualsLiteral("keydown") ||
type.EqualsLiteral("mousedown") ||
type.EqualsLiteral("mouseup") ||
type.EqualsLiteral("dragstart"))
HideTooltip();
else if (type.EqualsLiteral("mousemove"))
MouseMove(aEvent);
else if (type.EqualsLiteral("mouseout"))
MouseOut(aEvent);
else if (type.EqualsLiteral("popuphiding"))
DestroyTooltip();
@ -343,9 +304,9 @@ nsXULTooltipListener::AddTooltipSupport(nsIContent* aNode)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(aNode));
evtTarget->AddEventListener(NS_LITERAL_STRING("mouseout"), static_cast<nsIDOMMouseListener*>(this), PR_FALSE);
evtTarget->AddEventListener(NS_LITERAL_STRING("mousemove"), static_cast<nsIDOMMouseListener*>(this), PR_FALSE);
evtTarget->AddEventListener(NS_LITERAL_STRING("dragstart"), static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
evtTarget->AddEventListener(NS_LITERAL_STRING("mouseout"), this, PR_FALSE);
evtTarget->AddEventListener(NS_LITERAL_STRING("mousemove"), this, PR_FALSE);
evtTarget->AddEventListener(NS_LITERAL_STRING("dragstart"), this, PR_TRUE);
return NS_OK;
}
@ -357,9 +318,9 @@ nsXULTooltipListener::RemoveTooltipSupport(nsIContent* aNode)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(aNode));
evtTarget->RemoveEventListener(NS_LITERAL_STRING("mouseout"), static_cast<nsIDOMMouseListener*>(this), PR_FALSE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"), static_cast<nsIDOMMouseListener*>(this), PR_FALSE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("dragstart"), static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("mouseout"), this, PR_FALSE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"), this, PR_FALSE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("dragstart"), this, PR_TRUE);
return NS_OK;
}
@ -456,20 +417,20 @@ nsXULTooltipListener::ShowTooltip()
// be sure DestroyPopup is called even if someone else closes the tooltip
nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(currentTooltip));
evtTarget->AddEventListener(NS_LITERAL_STRING("popuphiding"),
static_cast<nsIDOMMouseListener*>(this), PR_FALSE);
this, PR_FALSE);
// listen for mousedown, mouseup, keydown, and DOMMouseScroll events at document level
nsIDocument* doc = sourceNode->GetDocument();
if (doc) {
evtTarget = do_QueryInterface(doc);
evtTarget->AddEventListener(NS_LITERAL_STRING("DOMMouseScroll"),
static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
this, PR_TRUE);
evtTarget->AddEventListener(NS_LITERAL_STRING("mousedown"),
static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
this, PR_TRUE);
evtTarget->AddEventListener(NS_LITERAL_STRING("mouseup"),
static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
this, PR_TRUE);
evtTarget->AddEventListener(NS_LITERAL_STRING("keydown"),
static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
this, PR_TRUE);
}
mSourceNode = nsnull;
}
@ -690,7 +651,7 @@ nsXULTooltipListener::GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip)
nsresult
nsXULTooltipListener::DestroyTooltip()
{
nsCOMPtr<nsIDOMMouseListener> kungFuDeathGrip(this);
nsCOMPtr<nsIDOMEventListener> kungFuDeathGrip(this);
nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
if (currentTooltip) {
// clear out the tooltip node on the document
@ -698,10 +659,10 @@ nsXULTooltipListener::DestroyTooltip()
if (doc) {
// remove the mousedown and keydown listener from document
nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(doc));
evtTarget->RemoveEventListener(NS_LITERAL_STRING("DOMMouseScroll"), static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("mousedown"), static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("mouseup"), static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("keydown"), static_cast<nsIDOMMouseListener*>(this), PR_TRUE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("DOMMouseScroll"), this, PR_TRUE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, PR_TRUE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("mouseup"), this, PR_TRUE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("keydown"), this, PR_TRUE);
}
// remove the popuphidden listener from tooltip
@ -711,7 +672,7 @@ nsXULTooltipListener::DestroyTooltip()
// being called recursively (bug 120863)
mCurrentTooltip = nsnull;
evtTarget->RemoveEventListener(NS_LITERAL_STRING("popuphiding"), static_cast<nsIDOMMouseListener*>(this), PR_FALSE);
evtTarget->RemoveEventListener(NS_LITERAL_STRING("popuphiding"), this, PR_FALSE);
}
// kill any ongoing timers

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

@ -38,9 +38,7 @@
#ifndef nsXULTooltipListener_h__
#define nsXULTooltipListener_h__
#include "nsIDOMMouseListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMMouseEvent.h"
#include "nsIContent.h"
#include "nsIDOMElement.h"
@ -53,32 +51,14 @@
#endif
#include "nsWeakPtr.h"
class nsXULTooltipListener : public nsIDOMMouseListener,
public nsIDOMMouseMotionListener,
public nsIDOMKeyListener
class nsXULTooltipListener : public nsIDOMEventListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMEVENTLISTENER
// nsIDOMMouseListener
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
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);
// nsIDOMMouseMotionListener
NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; }
NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent);
// nsIDOMKeyListener
NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent);
NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent) { return NS_OK; }
NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent) { return NS_OK; }
// nsIDOMEventListener
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
void MouseOut(nsIDOMEvent* aEvent);
void MouseMove(nsIDOMEvent* aEvent);
nsresult AddTooltipSupport(nsIContent* aNode);
nsresult RemoveTooltipSupport(nsIContent* aNode);