Bug 1129066 - Ensure the click event is always dispatched to an element node. r=smaug
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 04 Feb 2015 22:48:45 -0500
changeset 227597 4ceae3faa925a47962b5008a089639f7449c26f8
parent 227596 6aa2335b0f0ff3f2e1e9f07dc9dd046e1d7d5820
child 227598 929ab8b8c789f4cdedeff3228386de96e7100269
push id55164
push userkgupta@mozilla.com
push dateThu, 05 Feb 2015 03:49:05 +0000
treeherdermozilla-inbound@4ceae3faa925 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1129066
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1129066 - Ensure the click event is always dispatched to an element node. r=smaug
dom/events/EventStateManager.cpp
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -4429,16 +4429,24 @@ EventStateManager::CheckForAndDispatchCl
     event.timeStamp = aEvent->timeStamp;
     event.mFlags.mNoContentDispatch = notDispatchToContents;
     event.button = aEvent->button;
     event.inputSource = aEvent->inputSource;
 
     nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
     if (presShell) {
       nsCOMPtr<nsIContent> 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;
       }
 
       // HandleEvent clears out mCurrentTarget which we might need again
       nsWeakFrame currentTarget = mCurrentTarget;
       ret = presShell->HandleEventWithTarget(&event, currentTarget,
                                              mouseContent, aStatus);