From f66fc316264532c1dd409427590750994125767f Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Mon, 4 May 2009 10:55:47 -0400 Subject: [PATCH] Bug 374288, don't open tooltips on items in a menu when the listener is outside of it, r+sr=neil --- layout/xul/base/src/nsXULTooltipListener.cpp | 28 +++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/layout/xul/base/src/nsXULTooltipListener.cpp b/layout/xul/base/src/nsXULTooltipListener.cpp index 866e0c002551..bbe2d7d310c0 100644 --- a/layout/xul/base/src/nsXULTooltipListener.cpp +++ b/layout/xul/base/src/nsXULTooltipListener.cpp @@ -227,7 +227,7 @@ nsXULTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent) nsCOMPtr eventTarget; aMouseEvent->GetCurrentTarget(getter_AddRefs(eventTarget)); - + nsCOMPtr sourceContent = do_QueryInterface(eventTarget); mSourceNode = do_GetWeakReference(sourceContent); #ifdef MOZ_XUL @@ -240,17 +240,33 @@ nsXULTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent) // so that the delay is from when the mouse stops moving, not when it enters // the node. KillTooltipTimer(); - + // If the mouse moves while the tooltip is up, hide it. If nothing is // showing and the tooltip hasn't been displayed since the mouse entered // the node, then start the timer to show the tooltip. if (!currentTooltip && !mTooltipShownOnce) { + // don't show tooltips attached to elements outside of a menu popup + // when hovering over an element inside it. + nsCOMPtr eventTarget; + aMouseEvent->GetTarget(getter_AddRefs(eventTarget)); + nsCOMPtr targetContent = do_QueryInterface(eventTarget); + while (targetContent && targetContent != sourceContent) { + nsIAtom* tag = targetContent->Tag(); + if (targetContent->GetNameSpaceID() == kNameSpaceID_XUL && + (tag == nsGkAtoms::menupopup || + tag == nsGkAtoms::panel || + tag == nsGkAtoms::tooltip)) { + mSourceNode = nsnull; + return NS_OK; + } + + targetContent = targetContent->GetParent(); + } + mTooltipTimer = do_CreateInstance("@mozilla.org/timer;1"); if (mTooltipTimer) { - aMouseEvent->GetTarget(getter_AddRefs(eventTarget)); - nsCOMPtr targetNode = do_QueryInterface(eventTarget); - mTargetNode = do_GetWeakReference(targetNode); - if (targetNode) { + mTargetNode = do_GetWeakReference(eventTarget); + if (mTargetNode) { nsresult rv = mTooltipTimer->InitWithFuncCallback(sTooltipCallback, this, kTooltipShowTime, nsITimer::TYPE_ONE_SHOT); if (NS_FAILED(rv)) {