Bug 1286553 - HTMLTooltip: consume only left click events;r=bgrins
MozReview-Commit-ID: Hr0Lwv8Zx5C
--- a/devtools/client/shared/test/browser_html_tooltip-02.js
+++ b/devtools/client/shared/test/browser_html_tooltip-02.js
@@ -41,16 +41,17 @@ add_task(function* () {
useXulWrapper = true;
yield runTests(doc);
});
function* runTests(doc) {
yield testClickInTooltipContent(doc);
yield testConsumeOutsideClicksFalse(doc);
yield testConsumeOutsideClicksTrue(doc);
+ yield testConsumeWithRightClick(doc);
yield testClickInOuterIframe(doc);
yield testClickInInnerIframe(doc);
}
function* testClickInTooltipContent(doc) {
info("Test a tooltip is not closed when clicking inside itself");
let tooltip = new HTMLTooltip({doc}, {useXulWrapper});
@@ -101,16 +102,38 @@ function* testConsumeOutsideClicksTrue(d
yield onHidden;
is(box4clicks, 0, "box4 catched no click event");
is(tooltip.isVisible(), false, "Tooltip is hidden");
tooltip.destroy();
}
+function* testConsumeWithRightClick(doc) {
+ info("Test closing a tooltip with a right-click, with consumeOutsideClicks: true");
+ let box4 = doc.getElementById("box4");
+
+ let tooltip = new HTMLTooltip({doc}, {consumeOutsideClicks: true, useXulWrapper});
+ tooltip.setContent(getTooltipContent(doc), {width: 100, height: 50});
+ yield showTooltip(tooltip, doc.getElementById("box1"));
+
+ // Only left-click events should be consumed, so we expect to catch a click when using
+ // {button: 2}, which simulates a right-click.
+ info("Right click on box4, expect tooltip to be hidden, event should not be consumed");
+ let onBox4Clicked = once(box4, "click");
+ let onHidden = once(tooltip, "hidden");
+ EventUtils.synthesizeMouseAtCenter(box4, {button: 2}, doc.defaultView);
+ yield onHidden;
+ yield onBox4Clicked;
+
+ is(tooltip.isVisible(), false, "Tooltip is hidden");
+
+ tooltip.destroy();
+}
+
function* testClickInOuterIframe(doc) {
info("Test clicking an iframe outside of the tooltip closes the tooltip");
let frame = doc.getElementById("frame");
let tooltip = new HTMLTooltip({doc}, {useXulWrapper});
tooltip.setContent(getTooltipContent(doc), {width: 100, height: 50});
yield showTooltip(tooltip, doc.getElementById("box1"));
--- a/devtools/client/shared/widgets/HTMLTooltip.js
+++ b/devtools/client/shared/widgets/HTMLTooltip.js
@@ -486,17 +486,18 @@ HTMLTooltip.prototype = {
},
_onClick: function (e) {
if (this._isInTooltipContainer(e.target)) {
return;
}
this.hide();
- if (this.consumeOutsideClicks) {
+ if (this.consumeOutsideClicks && e.button === 0) {
+ // Consume only left click events (button === 0).
e.preventDefault();
e.stopPropagation();
}
},
_isInTooltipContainer: function (node) {
// Check if the target is the tooltip arrow.
if (this.arrow && this.arrow === node) {