Bug 1455535 - Add support for vmin/vmax units. Ensure vh/vw are computed against actual host window. r=pbro
MozReview-Commit-ID: 1ifVJu1OW5L
--- 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;
}