Bug 1455535 - Add support for vmin/vmax units. Ensure vh/vw are computed against actual host window. r=pbro draft
authorRazvan Caliman <rcaliman@mozilla.com>
Fri, 20 Apr 2018 17:31:39 +0200
changeset 785641 92d64fecc011ed0216e4f7023d50e95bcf7478e4
parent 785586 cc0d7de218cb0c260c8ba0cf6637845ad2222f49
push id107290
push userbmo:rcaliman@mozilla.com
push dateFri, 20 Apr 2018 15:33:42 +0000
reviewerspbro
bugs1455535
milestone61.0a1
Bug 1455535 - Add support for vmin/vmax units. Ensure vh/vw are computed against actual host window. r=pbro MozReview-Commit-ID: 1ifVJu1OW5L
devtools/server/actors/highlighters/shapes.js
--- a/devtools/server/actors/highlighters/shapes.js
+++ b/devtools/server/actors/highlighters/shapes.js
@@ -2553,32 +2553,40 @@ class ShapesHighlighter extends AutoRefr
    * @param {String} unit
    *        One of: %, em, rem, vw, vh
    * @param {Number} size
    *        Size to which percentage values are relative to.
    * @return {Number}
    */
   getUnitToPixelRatio(unit, size) {
     let ratio;
+    const windowHeight = this.currentNode.ownerGlobal.innerHeight;
+    const windowWidth = this.currentNode.ownerGlobal.innerWidth;
     switch (unit) {
       case "%":
         ratio = 100 / size;
         break;
       case "em":
         ratio = 1 / parseFloat(getComputedStyle(this.currentNode).fontSize);
         break;
       case "rem":
         const root = this.currentNode.ownerDocument.documentElement;
         ratio = 1 / parseFloat(getComputedStyle(root).fontSize);
         break;
       case "vw":
-        ratio = 100 / this.win.innerWidth;
+        ratio = 100 / windowWidth;
         break;
       case "vh":
-        ratio = 100 / this.win.innerHeight;
+        ratio = 100 / windowHeight;
+        break;
+      case "vmin":
+        ratio = 100 / Math.min(windowHeight, windowWidth);
+        break;
+      case "vmax":
+        ratio = 100 / Math.max(windowHeight, windowWidth);
         break;
       default:
         // If unit is not recognized, peg ratio 1:1 to pixels.
         ratio = 1;
     }
 
     return ratio;
   }