Bug 991111 - Middle clicks on tiles are not counted [r=adw]
authorEd Lee <edilee@mozilla.com>
Tue, 15 Apr 2014 12:14:08 -0700
changeset 197264 578a88956f7d4816b8278bd3a9f33481ffe47cd7
parent 197087 661f96cbf4cef409e3805d3dc29a418d62b87204
child 197265 cd86975315178a1d0b473c6e7c9289e55afcf9ea
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs991111
milestone31.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 991111 - Middle clicks on tiles are not counted [r=adw] Move the click listener to the xul window to correctly get the click event to filter for site-related clicks.
browser/base/content/newtab/sites.js
browser/base/content/test/newtab/browser.ini
browser/base/content/test/newtab/browser_newtab_bug991111.js
--- a/browser/base/content/newtab/sites.js
+++ b/browser/base/content/newtab/sites.js
@@ -164,17 +164,20 @@ Site.prototype = {
   /**
    * Adds event handlers for the site and its buttons.
    */
   _addEventHandlers: function Site_addEventHandlers() {
     // Register drag-and-drop event handlers.
     this._node.addEventListener("dragstart", this, false);
     this._node.addEventListener("dragend", this, false);
     this._node.addEventListener("mouseover", this, false);
-    this._node.addEventListener("click", this, false);
+
+    // XXX bug 991111 - Not all click events are correctly triggered when
+    // listening from the xhtml node, so listen from the xul window and filter
+    addEventListener("click", this, false);
 
     // Specially treat the sponsored icon to prevent regular hover effects
     let sponsored = this._querySelector(".newtab-control-sponsored");
     sponsored.addEventListener("mouseover", () => {
       this.cell.node.setAttribute("ignorehover", "true");
     });
     sponsored.addEventListener("mouseout", () => {
       this.cell.node.removeAttribute("ignorehover");
@@ -235,17 +238,21 @@ Site.prototype = {
   },
 
   /**
    * Handles all site events.
    */
   handleEvent: function Site_handleEvent(aEvent) {
     switch (aEvent.type) {
       case "click":
-        this._onClick(aEvent);
+        // Check the bitmask if the click event is for the site's descendants
+        if (this._node.compareDocumentPosition(aEvent.target) &
+            this._node.DOCUMENT_POSITION_CONTAINED_BY) {
+          this._onClick(aEvent);
+        }
         break;
       case "mouseover":
         this._node.removeEventListener("mouseover", this, false);
         this._speculativeConnect();
         break;
       case "dragstart":
         gDrag.start(this, aEvent);
         break;
--- a/browser/base/content/test/newtab/browser.ini
+++ b/browser/base/content/test/newtab/browser.ini
@@ -10,16 +10,17 @@ skip-if = e10s # Bug ?????? - about:newt
 [browser_newtab_bug723121.js]
 [browser_newtab_bug725996.js]
 [browser_newtab_bug734043.js]
 [browser_newtab_bug735987.js]
 skip-if = os == "mac" # Intermittent failures, bug 898317
 [browser_newtab_bug752841.js]
 [browser_newtab_bug765628.js]
 [browser_newtab_bug876313.js]
+[browser_newtab_bug991111.js]
 [browser_newtab_disable.js]
 [browser_newtab_drag_drop.js]
 [browser_newtab_drag_drop_ext.js]
 [browser_newtab_drop_preview.js]
 [browser_newtab_focus.js]
 [browser_newtab_perwindow_private_browsing.js]
 [browser_newtab_reset.js]
 [browser_newtab_sponsored_icon_click.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/newtab/browser_newtab_bug991111.js
@@ -0,0 +1,19 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function runTests() {
+  yield setLinks("0");
+  yield addNewTabPageTab();
+
+  // Remember if the click handler was triggered
+  let cell = getCell(0);
+  let clicked = false;
+  cell.site._onClick = e => {
+    clicked = true;
+    executeSoon(TestRunner.next);
+  };
+
+  // Send a middle-click and make sure it happened
+  yield EventUtils.synthesizeMouseAtCenter(cell.node, {button: 1}, getContentWindow());
+  ok(clicked, "middle click triggered click listener");
+}