[tor-commits] [torbutton/maint-1.9.4] Bug 18144: about:tor update arrow position is wrong (Retina and zoom)

gk at torproject.org gk at torproject.org
Mon Feb 8 19:05:40 UTC 2016


commit 3ccbfe38c767fb5d85ea37168ae08c297997b5ac
Author: Kathy Brade <brade at pearlcrescent.com>
Date:   Mon Feb 1 14:48:22 2016 -0500

    Bug 18144: about:tor update arrow position is wrong (Retina and zoom)
    
    For the about:tor content window, use
    nsIDOMWindowUtils.screenPixelsPerCSSPixel instead of
    window.devicePixelRatio to compensate for a retina display and for
    content zoom (devicePixelRatio always returns 1.0 for content windows
    due to the fix for bug 13875).
---
 src/chrome/content/aboutTor/aboutTor.xhtml |  7 +------
 src/chrome/content/torbutton.js            | 22 +++++++++++++++-------
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/chrome/content/aboutTor/aboutTor.xhtml b/src/chrome/content/aboutTor/aboutTor.xhtml
index 6fdbe50..dbb8a89 100644
--- a/src/chrome/content/aboutTor/aboutTor.xhtml
+++ b/src/chrome/content/aboutTor/aboutTor.xhtml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-   - Copyright (c) 2015, The Tor Project, Inc.
+   - Copyright (c) 2016, The Tor Project, Inc.
    - See LICENSE for licensing information.
    - vim: set sw=2 sts=2 ts=8 et syntax=xml:
   -->
@@ -59,11 +59,6 @@ function adjustToolbarIconArrow()
     return;
   }
 
-  // Account for content zoom and retina displays by converting to device
-  // independent units.
-  if ("devicePixelRatio" in window)  // FF18+
-    tbXpos /= window.devicePixelRatio;
-
   const kArrowMargin = 6;          // Horizontal margin between line and text.
   const kArrowHeadExtraWidth = 9;  // Horizontal margin to the line.
   const kArrowLineThickness = 11;
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index 0d1cfe8..25b61fb 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -1023,7 +1023,8 @@ function torbutton_adjust_abouttor_fontsizes(aDoc, aContainerName)
 }
 
 // Determine X position of torbutton toolbar item and pass it through
-// to the xhtml document.
+// to the xhtml document by setting a torbutton-xpos attribute on the body.
+// The value that is set takes retina displays and content zoom into account.
 function torbutton_update_abouttor_arrow(aDoc) {
   try {
     let tbXpos = -1;
@@ -1033,15 +1034,22 @@ function torbutton_update_abouttor_arrow(aDoc) {
       let contentElem = document.getElementById("content");
       let contentRect = contentElem.getBoundingClientRect();
       if (tbItemRect.top < contentRect.top) {
-        tbXpos = tbItemRect.left + (tbItemRect.width / 2.0) -
-                    contentElem.getBoundingClientRect().left;
+        tbXpos = tbItemRect.left + (tbItemRect.width / 2.0) - contentRect.left;
       }
     }
-    if (tbXpos >= 0) {
-     if ("devicePixelRatio" in window)     // FF18+
-       tbXpos *= window.devicePixelRatio;  // Convert to device pixels.
 
-      tbXpos = Math.round(tbXpos);
+    if (tbXpos >= 0) {
+      // Convert to device-independent units, compensating for retina display
+      // and content zoom that may be in effect on the about:tor page.
+      // Because window.devicePixelRatio always returns 1.0 for non-Chrome
+      // windows (see bug 13875), we use screenPixelsPerCSSPixel for the
+      // content window.
+      tbXpos *= window.devicePixelRatio;
+      let pixRatio = gBrowser.contentWindow
+                             .QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsIDOMWindowUtils)
+                             .screenPixelsPerCSSPixel;
+      tbXpos = Math.round(tbXpos / pixRatio);
       aDoc.body.setAttribute("torbutton-xpos", tbXpos);
     } else {
       aDoc.body.removeAttribute("torbutton-xpos");



More information about the tor-commits mailing list