Bug 1286553 - HTMLTooltip: consume only left click events;r=bgrins draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 14 Jul 2016 16:13:11 +0200
changeset 388624 5464c3881db5ad0413cb3ca3a8103c88d970d851
parent 387862 b6e311c419b5f15680b3fa56fd197c0e93dc40a5
child 525579 211549ff655df2b9e4a92dc91a3eb3546061ff55
push id23209
push userjdescottes@mozilla.com
push dateSat, 16 Jul 2016 09:39:07 +0000
reviewersbgrins
bugs1286553
milestone50.0a1
Bug 1286553 - HTMLTooltip: consume only left click events;r=bgrins MozReview-Commit-ID: Hr0Lwv8Zx5C
devtools/client/shared/test/browser_html_tooltip-02.js
devtools/client/shared/widgets/HTMLTooltip.js
--- 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) {