Bug 1455535 - Add support for vmin/vmax units. Ensure vh/vw are computed against actual host window. r=pbro
authorRazvan Caliman <rcaliman@mozilla.com>
Fri, 20 Apr 2018 17:31:39 +0200
changeset 468560 22a1e2529011da888c2878c3a85b4336dedadc44
parent 468548 f3ad6a992444517319141bee521e512ce4faa006
child 468561 813166385a612395178c5cb955c5072098ef6148
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1455535
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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;
   }