From ac847ef39ebbcb7b628772e43c09b1a03330ac83 Mon Sep 17 00:00:00 2001 From: Ed Lee Date: Tue, 15 Apr 2014 12:14:08 -0700 Subject: [PATCH] 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. --HG-- extra : rebase_source : 3fd8b2c658a695fbc9aa79d09f461acaeef2078f --- browser/base/content/newtab/sites.js | 11 +++++++++-- browser/base/content/test/newtab/browser.ini | 1 + .../test/newtab/browser_newtab_bug991111.js | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 browser/base/content/test/newtab/browser_newtab_bug991111.js diff --git a/browser/base/content/newtab/sites.js b/browser/base/content/newtab/sites.js index 00f48f7ab90..5fdc50729f0 100644 --- a/browser/base/content/newtab/sites.js +++ b/browser/base/content/newtab/sites.js @@ -169,7 +169,10 @@ Site.prototype = { 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"); @@ -240,7 +243,11 @@ Site.prototype = { 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); diff --git a/browser/base/content/test/newtab/browser.ini b/browser/base/content/test/newtab/browser.ini index 30440638db1..c07f872ebdb 100644 --- a/browser/base/content/test/newtab/browser.ini +++ b/browser/base/content/test/newtab/browser.ini @@ -15,6 +15,7 @@ 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] diff --git a/browser/base/content/test/newtab/browser_newtab_bug991111.js b/browser/base/content/test/newtab/browser_newtab_bug991111.js new file mode 100644 index 00000000000..4a597ae221e --- /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"); +}