From 6d9aab9154688e1d7e018ecf81cbd8deab5617e6 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Fri, 31 May 2013 11:49:26 +0200 Subject: [PATCH] Bug 877669 - nsXULPopupListener shouldn't prevent default if there are no attributes, r=neil --- .../xul/content/src/nsXULPopupListener.cpp | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/content/xul/content/src/nsXULPopupListener.cpp b/content/xul/content/src/nsXULPopupListener.cpp index e6aeb0757c5..5368d5ed765 100644 --- a/content/xul/content/src/nsXULPopupListener.cpp +++ b/content/xul/content/src/nsXULPopupListener.cpp @@ -201,10 +201,9 @@ nsXULPopupListener::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } - // Open the popup and cancel the default handling of the event. + // Open the popup. LaunchPopup will call StopPropagation and PreventDefault + // in the right situations. LaunchPopup(aEvent, targetContent); - aEvent->StopPropagation(); - aEvent->PreventDefault(); return NS_OK; } @@ -328,21 +327,24 @@ nsXULPopupListener::LaunchPopup(nsIDOMEvent* aEvent, nsIContent* aTargetContent) { nsresult rv = NS_OK; - nsIAtom* type = mIsContext ? nsGkAtoms::context : nsGkAtoms::popup; - nsAutoString identifier; - mElement->GetAttr(kNameSpaceID_None, type, identifier); + nsIAtom* type = mIsContext ? nsGkAtoms::context : nsGkAtoms::popup; + bool hasPopupAttr = mElement->GetAttr(kNameSpaceID_None, type, identifier); if (identifier.IsEmpty()) { - if (type == nsGkAtoms::popup) { - mElement->GetAttr(kNameSpaceID_None, nsGkAtoms::menu, identifier); - } else { - mElement->GetAttr(kNameSpaceID_None, nsGkAtoms::contextmenu, identifier); - } - if (identifier.IsEmpty()) - return rv; + hasPopupAttr = mElement->GetAttr(kNameSpaceID_None, + mIsContext ? nsGkAtoms::contextmenu : nsGkAtoms::menu, + identifier) || hasPopupAttr; } + if (hasPopupAttr) { + aEvent->StopPropagation(); + aEvent->PreventDefault(); + } + + if (identifier.IsEmpty()) + return rv; + // Try to find the popup content and the document. nsCOMPtr document = mElement->GetDocument(); if (!document) {