Bug 1460795 - HTML tooltips should consider the content zoom value. r?jdescottes
This patch will multiply the HTML tooltip position to the zoom value in order to
display HTML tooltip in correct position.
MozReview-Commit-ID: GHVkB5hN44k
--- a/devtools/client/shared/test/browser.ini
+++ b/devtools/client/shared/test/browser.ini
@@ -141,16 +141,17 @@ skip-if = e10s # Bug 1221911, bug 122228
[browser_html_tooltip_arrow-02.js]
[browser_html_tooltip_consecutive-show.js]
[browser_html_tooltip_hover.js]
[browser_html_tooltip_offset.js]
[browser_html_tooltip_rtl.js]
[browser_html_tooltip_variable-height.js]
[browser_html_tooltip_width-auto.js]
[browser_html_tooltip_xul-wrapper.js]
+[browser_html_tooltip_zoom.js]
[browser_inplace-editor-01.js]
[browser_inplace-editor-02.js]
[browser_inplace-editor_autoclose_parentheses.js]
[browser_inplace-editor_autocomplete_01.js]
[browser_inplace-editor_autocomplete_02.js]
[browser_inplace-editor_autocomplete_offset.js]
[browser_inplace-editor_autocomplete_css_variable.js]
[browser_inplace-editor_maxwidth.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/shared/test/browser_html_tooltip_zoom.js
@@ -0,0 +1,64 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+/* import-globals-from helper_html_tooltip.js */
+
+"use strict";
+
+/**
+ * Test the HTMLTooltip is displayed correct position if content is zoomed in.
+ */
+
+const HTML_NS = "http://www.w3.org/1999/xhtml";
+const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip.xul";
+
+const {HTMLTooltip} = require("devtools/client/shared/widgets/tooltip/HTMLTooltip");
+
+function getTooltipContent(doc) {
+ let div = doc.createElementNS(HTML_NS, "div");
+ div.style.height = "50px";
+ div.style.boxSizing = "border-box";
+ div.style.backgroundColor = "red";
+ div.textContent = "tooltip";
+ return div;
+}
+
+add_task(async function() {
+ let [host,, doc] = await createHost("window", TEST_URI);
+ const zoom = 1.5;
+ await pushPref("devtools.toolbox.zoomValue", zoom.toString(10));
+
+ // Change this xul zoom to the x1.5 since this test doesn't use the toolbox preferences.
+ let contentViewer = host.frame.docShell.contentViewer;
+ contentViewer.fullZoom = zoom;
+ let tooltip = new HTMLTooltip(doc, {useXulWrapper: true});
+
+ info("Set tooltip content");
+ tooltip.setContent(getTooltipContent(doc), {width: 100, height: 50});
+
+ is(tooltip.isVisible(), false, "Tooltip is not visible");
+
+ info("Show the tooltip and check the expected events are fired.");
+ let onShown = tooltip.once("shown");
+ tooltip.show(doc.getElementById("box1"));
+ await onShown;
+
+ let menuRect =
+ doc.querySelector(".tooltip-xul-wrapper").getBoxQuads({relativeTo: doc})[0].bounds;
+ let anchorRect = doc.getElementById("box1").getBoxQuads({relativeTo: doc})[0].bounds;
+ let xDelta = Math.abs(menuRect.left - anchorRect.left);
+ let yDelta = Math.abs(menuRect.top - anchorRect.bottom);
+
+ // This test allow the rounded error and platform's offset.
+ // For detail, see the devtools/client/framework/test/browser_toolbox_zoom_popup.js
+ ok(xDelta < 2, "xDelta is lower than 2: " + xDelta + ".");
+ ok(yDelta < 6, "yDelta is lower than 6: " + yDelta + ".");
+
+ info("Hide the tooltip and check the expected events are fired.");
+
+ let onPopupHidden = tooltip.once("hidden");
+ tooltip.hide();
+ await onPopupHidden;
+
+ tooltip.destroy();
+ await host.destroy();
+});
--- a/devtools/client/shared/widgets/tooltip/HTMLTooltip.js
+++ b/devtools/client/shared/widgets/tooltip/HTMLTooltip.js
@@ -4,16 +4,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const EventEmitter = require("devtools/shared/event-emitter");
const {TooltipToggle} = require("devtools/client/shared/widgets/tooltip/TooltipToggle");
const {listenOnce} = require("devtools/shared/async-utils");
+const Services = require("Services");
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const POSITION = {
TOP: "top",
BOTTOM: "bottom",
};
@@ -593,17 +594,21 @@ HTMLTooltip.prototype = {
panel.setAttribute("class", "tooltip-xul-wrapper");
return panel;
},
_showXulWrapperAt: function(left, top) {
this.xulPanelWrapper.addEventListener("popuphidden", this._onXulPanelHidden);
let onPanelShown = listenOnce(this.xulPanelWrapper, "popupshown");
- this.xulPanelWrapper.openPopupAtScreen(left, top, false);
+ let zoom = parseFloat(Services.prefs.getCharPref("devtools.toolbox.zoomValue"));
+ if (!zoom || isNaN(zoom)) {
+ zoom = 1.0;
+ }
+ this.xulPanelWrapper.openPopupAtScreen(left * zoom, top * zoom, false);
return onPanelShown;
},
_hideXulWrapper: function() {
this.xulPanelWrapper.removeEventListener("popuphidden", this._onXulPanelHidden);
if (this.xulPanelWrapper.state === "closed") {
// XUL panel is already closed, resolve immediately.