Bug 1379466 - Stop dispatching click events for non-primary mouse clicks on the web. r=smaug
authorIan Moody <moz-ian@perix.co.uk>
Thu, 18 Apr 2019 12:57:37 +0000
changeset 470162 0e9fa06f3fd885525adaad2e9995e3077258c94c
parent 470161 273553e141f1188c807488a12e45ab12c9ccb8a8
child 470163 23ff9cd1a1a43d794dad766662530471b31a121f
push id112843
push useraiakab@mozilla.com
push dateFri, 19 Apr 2019 09:50:22 +0000
treeherdermozilla-inbound@c06f27cbfe40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1379466
milestone68.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 1379466 - Stop dispatching click events for non-primary mouse clicks on the web. r=smaug It's against spec, and the auxclick event is now available and easier to use (fired on all elements rather than just window/document and text fields) Can't stop dispatching them entirely since frontend code is too reliant on it. Don't fire dblclick for auxclick. Mark wpt uievents/click/auxclick_event.html as passing Update test_clipboard_events.html Differential Revision: https://phabricator.services.mozilla.com/D26793
dom/events/EventStateManager.cpp
dom/tests/mochitest/general/mochitest.ini
dom/tests/mochitest/general/test_clipboard_events.html
testing/web-platform/meta/uievents/click/auxclick_event.html.ini
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -4858,16 +4858,17 @@ nsresult EventStateManager::InitAndDispa
                          aMouseUpEvent->mWidget, WidgetMouseEvent::eReal);
 
   event.mRefPoint = aMouseUpEvent->mRefPoint;
   event.mClickCount = aMouseUpEvent->mClickCount;
   event.mModifiers = aMouseUpEvent->mModifiers;
   event.buttons = aMouseUpEvent->buttons;
   event.mTime = aMouseUpEvent->mTime;
   event.mTimeStamp = aMouseUpEvent->mTimeStamp;
+  event.mFlags.mOnlyChromeDispatch = aNoContentDispatch;
   event.mFlags.mNoContentDispatch = aNoContentDispatch;
   event.button = aMouseUpEvent->button;
   event.pointerId = aMouseUpEvent->pointerId;
   event.inputSource = aMouseUpEvent->inputSource;
   nsIContent* target = aMouseUpContent;
   nsIFrame* targetFrame = aCurrentTarget;
   if (aOverrideClickTarget) {
     target = aOverrideClickTarget;
@@ -4985,35 +4986,35 @@ nsresult EventStateManager::DispatchClic
   AutoWeakFrame currentTarget = aClickTarget->GetPrimaryFrame();
   nsresult rv = InitAndDispatchClickEvent(
       aMouseUpEvent, aStatus, eMouseClick, aPresShell, aClickTarget,
       currentTarget, notDispatchToContents, aOverrideClickTarget);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
+  // Fire auxclick event if necessary.
+  if (fireAuxClick && aClickTarget && aClickTarget->IsInComposedDoc()) {
+    rv = InitAndDispatchClickEvent(aMouseUpEvent, aStatus, eMouseAuxClick,
+                                   aPresShell, aClickTarget, currentTarget,
+                                   false, aOverrideClickTarget);
+    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to dispatch eMouseAuxClick");
+  }
+
   // Fire double click event if click count is 2.
-  if (aMouseUpEvent->mClickCount == 2 && aClickTarget &&
+  if (aMouseUpEvent->mClickCount == 2 && !fireAuxClick && aClickTarget &&
       aClickTarget->IsInComposedDoc()) {
     rv = InitAndDispatchClickEvent(aMouseUpEvent, aStatus, eMouseDoubleClick,
                                    aPresShell, aClickTarget, currentTarget,
                                    notDispatchToContents, aOverrideClickTarget);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
-  // Fire auxclick even if necessary.
-  if (fireAuxClick && aClickTarget && aClickTarget->IsInComposedDoc()) {
-    rv = InitAndDispatchClickEvent(aMouseUpEvent, aStatus, eMouseAuxClick,
-                                   aPresShell, aClickTarget, currentTarget,
-                                   false, aOverrideClickTarget);
-    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to dispatch eMouseAuxClick");
-  }
-
   return rv;
 }
 
 nsresult EventStateManager::HandleMiddleClickPaste(
     nsIPresShell* aPresShell, WidgetMouseEvent* aMouseEvent,
     nsEventStatus* aStatus, TextEditor* aTextEditor) {
   MOZ_ASSERT(aPresShell);
   MOZ_ASSERT(aMouseEvent);
--- a/dom/tests/mochitest/general/mochitest.ini
+++ b/dom/tests/mochitest/general/mochitest.ini
@@ -82,16 +82,17 @@ skip-if = (toolkit == 'android') # Disab
 subsuite = clipboard
 [test_bug1208217.html]
 [test_bug1313753.html]
 [test_bug1434273.html]
 [test_clientRects.html]
 [test_clipboard_disallowed.html]
 [test_clipboard_events.html]
 subsuite = clipboard
+skip-if = headless # bug 1403542
 [test_consoleAPI.html]
 [test_contentViewer_overrideDPPX.html]
 [test_CCW_optimization.html]
 [test_datatransfer_disallowed.html]
 [test_devicePixelRatio_with_zoom.html]
 [test_DOMMatrix.html]
 [test_domWindowUtils.html]
 [test_domWindowUtils_scrollbarSize.html]
--- a/dom/tests/mochitest/general/test_clipboard_events.html
+++ b/dom/tests/mochitest/general/test_clipboard_events.html
@@ -920,32 +920,35 @@ add_task(async function test_paste_event
   auxclickFired = false;
   document.addEventListener("mouseup", (event) => { event.preventDefault(); }, {once: true});
   synthesizeMouseAtCenter(noneditableDiv, {button: 1});
   is(pasteEventCount, 1,
      "Even if 'mouseup' event is consumed, 'paste' event should be fired");
 
   pasteEventCount = 0;
   auxclickFired = false;
-  document.addEventListener("click", (event) => { event.preventDefault(); }, {once: true, capture: true});
+  document.addEventListener("auxclick", (event) => { event.preventDefault(); }, {once: true, capture: true});
   synthesizeMouseAtCenter(noneditableDiv, {button: 1});
+  ok(auxclickFired, "'auxclickFired' fired");
   is(pasteEventCount, 0,
-     "If 'click' event is consumed at capturing phase at the document node, 'paste' event should be not be fired");
+     "If 'auxclick' event is consumed at capturing phase at the document node, 'paste' event should not be fired");
 
   pasteEventCount = 0;
   auxclickFired = false;
-  noneditableDiv.addEventListener("click", (event) => { event.preventDefault(); }, {once: true});
+  noneditableDiv.addEventListener("auxclick", (event) => { event.preventDefault(); }, {once: true});
   synthesizeMouseAtCenter(noneditableDiv, {button: 1});
-  is(pasteEventCount, 1,
-     "Even if 'click' event listener is added to the click event target, 'paste' event should be fired");
+  ok(auxclickFired, "'auxclick' fired");
+  is(pasteEventCount, 0,
+     "If 'auxclick' event listener is added to the click event target, 'paste' event should not be fired");
 
   pasteEventCount = 0;
   auxclickFired = false;
   document.addEventListener("auxclick", (event) => { event.preventDefault(); }, {once: true});
   synthesizeMouseAtCenter(noneditableDiv, {button: 1});
+  ok(auxclickFired, "'auxclick' fired");
   is(pasteEventCount, 0,
      "If 'auxclick' event is consumed, 'paste' event should be not be fired");
 
   document.removeEventListener("auxclick", onAuxClick);
   document.removeEventListener("paste", onPaste);
   contenteditableContainer.innerHTML = "";
 });
 
deleted file mode 100644
--- a/testing/web-platform/meta/uievents/click/auxclick_event.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[auxclick_event.html]
-  [auxclick event sequence received.]
-    expected: FAIL
-