Bug 1286553 - HTMLTooltip: consume only left click events;r=bgrins

MozReview-Commit-ID: Hr0Lwv8Zx5C

--HG--
extra : rebase_source : 5464c3881db5ad0413cb3ca3a8103c88d970d851
This commit is contained in:
Julian Descottes 2016-07-14 16:13:11 +02:00
parent bd810d4350
commit 50dbb87670
2 changed files with 25 additions and 1 deletions

View File

@ -46,6 +46,7 @@ function* runTests(doc) {
yield testClickInTooltipContent(doc);
yield testConsumeOutsideClicksFalse(doc);
yield testConsumeOutsideClicksTrue(doc);
yield testConsumeWithRightClick(doc);
yield testClickInOuterIframe(doc);
yield testClickInInnerIframe(doc);
}
@ -106,6 +107,28 @@ function* testConsumeOutsideClicksTrue(doc) {
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");

View File

@ -491,7 +491,8 @@ HTMLTooltip.prototype = {
}
this.hide();
if (this.consumeOutsideClicks) {
if (this.consumeOutsideClicks && e.button === 0) {
// Consume only left click events (button === 0).
e.preventDefault();
e.stopPropagation();
}