Bug 1451684 - Compute farthest-side / closest-side circle radius as pixels, then resolve to percentages according to formula defined in spec. r=gl draft
authorRazvan Caliman <rcaliman@mozilla.com>
Fri, 22 Jun 2018 17:40:45 +0200
changeset 809625 6814b1cf2242a9b37420e34487522c6b60c8d03f
parent 809559 6b6f3f6ecf142908b3e437d3bc3fac75540a9bcb
push id113736
push userbmo:rcaliman@mozilla.com
push dateFri, 22 Jun 2018 15:49:51 +0000
reviewersgl
bugs1451684
milestone62.0a1
Bug 1451684 - Compute farthest-side / closest-side circle radius as pixels, then resolve to percentages according to formula defined in spec. r=gl MozReview-Commit-ID: 5yE8Q88fZ78
devtools/server/actors/highlighters/shapes.js
--- a/devtools/server/actors/highlighters/shapes.js
+++ b/devtools/server/actors/highlighters/shapes.js
@@ -1878,22 +1878,28 @@ class ShapesHighlighter extends AutoRefr
     let radius = values[0];
     const { width, height } = this.currentDimensions;
     const center = splitCoords(values[1]).map(this.convertCoordsToPercent.bind(this));
 
     // Percentage values for circle() are resolved from the
     // used width and height of the reference box as sqrt(width^2+height^2)/sqrt(2).
     const computedSize = Math.sqrt((width ** 2) + (height ** 2)) / Math.sqrt(2);
 
+    // Position coordinates for circle center in pixels.
+    const cxPx = width * center[0] / 100;
+    const cyPx = height * center[1] / 100;
+
     if (radius === "closest-side") {
       // radius is the distance from center to closest side of reference box
-      radius = Math.min(center[0], center[1], 100 - center[0], 100 - center[1]);
+      radius = Math.min(cxPx, cyPx, width - cxPx, height - cyPx);
+      radius = coordToPercent(`${radius}px`, computedSize);
     } else if (radius === "farthest-side") {
       // radius is the distance from center to farthest side of reference box
-      radius = Math.max(center[0], center[1], 100 - center[0], 100 - center[1]);
+      radius = Math.max(cxPx, cyPx, width - cxPx, height - cyPx);
+      radius = coordToPercent(`${radius}px`, computedSize);
     } else if (radius.includes("calc(")) {
       radius = evalCalcExpression(radius.substring(5, radius.length - 1), computedSize);
     } else {
       radius = coordToPercent(radius, computedSize);
     }
 
     // Scale both radiusX and radiusY to match the radius computed
     // using the above equation.