From 164ea2c10c12722a1e07b30261bfc6ec85c1fc4c Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Wed, 4 Feb 2015 22:48:45 -0500 Subject: [PATCH] Bug 1129066 - Ensure the click event is always dispatched to an element node. r=smaug --- dom/events/EventStateManager.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 32a14b9721b..12c93eb4ca2 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -4434,6 +4434,14 @@ EventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, nsCOMPtr presShell = mPresContext->GetPresShell(); if (presShell) { nsCOMPtr mouseContent = GetEventTargetContent(aEvent); + // Click events apply to *elements* not nodes. At this point the target + // content may have been reset to some non-element content, and so we need + // to walk up the closest ancestor element, just like we do in + // nsPresShell::HandlePositionedEvent. + while (mouseContent && !mouseContent->IsElement()) { + mouseContent = mouseContent->GetParent(); + } + if (!mouseContent && !mCurrentTarget) { return NS_OK; }