diff --git a/devtools/server/actors/highlighters/shapes.js b/devtools/server/actors/highlighters/shapes.js index dce775e78b44..2be7968f23da 100644 --- a/devtools/server/actors/highlighters/shapes.js +++ b/devtools/server/actors/highlighters/shapes.js @@ -841,8 +841,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter { return `${newX}${unitX} ${newY}${unitY}`; }).join(", "); - polygonDef = (this.geometryBox) ? `polygon(${polygonDef}) ${this.geometryBox}` : - `polygon(${polygonDef})`; + polygonDef = `polygon(${polygonDef}) ${this.geometryBox}`.trim(); this.currentNode.style.setProperty(this.property, polygonDef, "important"); } @@ -865,11 +864,9 @@ class ShapesHighlighter extends AutoRefreshHighlighter { radius = `${Math.abs((newCx - transX) * ratioRad)}${unitRad}`; } - let circleDef = (this.geometryBox) ? - `circle(${radius} at ${newCx * ratioX}${unitX} ` + - `${newCy * ratioY}${unitY} ${this.geometryBox}` : - `circle(${radius} at ${newCx * ratioX}${unitX} ${newCy * ratioY}${unitY}`; - this.currentNode.style.setProperty(this.property, circleDef, "important"); + let circleDef = `circle(${radius} at ${newCx * ratioX}${unitX} ` + + `${newCy * ratioY}${unitY}) ${this.geometryBox}`.trim(); + this.emit("highlighter-event", { type: "shape-change", value: circleDef }); } /** @@ -893,12 +890,9 @@ class ShapesHighlighter extends AutoRefreshHighlighter { ry = `${Math.abs((newCy - transY) * ratioRY)}${unitRY}`; } - let ellipseDef = (this.geometryBox) ? - `ellipse(${rx} ${ry} at ${newCx * ratioX}${unitX} ` + - `${newCy * ratioY}${unitY}) ${this.geometryBox}` : - `ellipse(${rx} ${ry} at ${newCx * ratioX}${unitX} ` + - `${newCy * ratioY}${unitY})`; - this.currentNode.style.setProperty(this.property, ellipseDef, "important"); + let ellipseDef = `ellipse(${rx} ${ry} at ${newCx * ratioX}${unitX} ` + + `${newCy * ratioY}${unitY}) ${this.geometryBox}`.trim(); + this.emit("highlighter-event", { type: "shape-change", value: ellipseDef }); } /** @@ -980,8 +974,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter { return (i === point) ? `${newX}${unitX} ${newY}${unitY}` : `${coords[0]} ${coords[1]}`; }).join(", "); - polygonDef = (this.geometryBox) ? `polygon(${polygonDef}) ${this.geometryBox}` : - `polygon(${polygonDef})`; + polygonDef = `polygon(${polygonDef}) ${this.geometryBox}`.trim(); this.currentNode.style.setProperty(this.property, polygonDef, "important"); } @@ -1001,8 +994,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter { return (i === after) ? `${coords[0]} ${coords[1]}, ${x}% ${y}%` : `${coords[0]} ${coords[1]}`; }).join(", "); - polygonDef = (this.geometryBox) ? `polygon(${polygonDef}) ${this.geometryBox}` : - `polygon(${polygonDef})`; + polygonDef = `polygon(${polygonDef}) ${this.geometryBox}`.trim(); this.hoveredPoint = after + 1; this._emitHoverEvent(this.hoveredPoint); @@ -1020,8 +1012,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter { polygonDef += coordinates.map((coords, i) => { return `${coords[0]} ${coords[1]}`; }).join(", "); - polygonDef = (this.geometryBox) ? `polygon(${polygonDef}) ${this.geometryBox}` : - `polygon(${polygonDef})`; + polygonDef = `polygon(${polygonDef}) ${this.geometryBox}`.trim(); this.hoveredPoint = null; this._emitHoverEvent(this.hoveredPoint); @@ -1086,9 +1077,8 @@ class ShapesHighlighter extends AutoRefreshHighlighter { let deltaY = (pageY - y) * ratioY; let newCx = `${valueX + deltaX}${unitX}`; let newCy = `${valueY + deltaY}${unitY}`; - let circleDef = (this.geometryBox) ? - `circle(${radius} at ${newCx} ${newCy}) ${this.geometryBox}` : - `circle(${radius} at ${newCx} ${newCy})`; + // if not defined by the user, geometryBox will be an empty string; trim() cleans up + let circleDef = `circle(${radius} at ${newCx} ${newCy}) ${this.geometryBox}`.trim(); this.currentNode.style.setProperty(this.property, circleDef, "important"); } else if (point === "radius") { @@ -1101,9 +1091,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter { let delta = (newRadiusPx - origRadius) * ratio; let newRadius = `${value + delta}${unit}`; - let circleDef = (this.geometryBox) ? - `circle(${newRadius} at ${cx} ${cy} ${this.geometryBox}` : - `circle(${newRadius} at ${cx} ${cy}`; + let circleDef = `circle(${newRadius} at ${cx} ${cy}) ${this.geometryBox}`.trim(); this.currentNode.style.setProperty(this.property, circleDef, "important"); } @@ -1177,9 +1165,8 @@ class ShapesHighlighter extends AutoRefreshHighlighter { let deltaY = (pageY - y) * ratioY; let newCx = `${valueX + deltaX}${unitX}`; let newCy = `${valueY + deltaY}${unitY}`; - let ellipseDef = (this.geometryBox) ? - `ellipse(${rx} ${ry} at ${newCx} ${newCy}) ${this.geometryBox}` : - `ellipse(${rx} ${ry} at ${newCx} ${newCy})`; + let ellipseDef = + `ellipse(${rx} ${ry} at ${newCx} ${newCy}) ${this.geometryBox}`.trim(); this.currentNode.style.setProperty(this.property, ellipseDef, "important"); } else if (point === "rx") { @@ -1189,9 +1176,8 @@ class ShapesHighlighter extends AutoRefreshHighlighter { let delta = ((newRadiusPercent / 100 * width) - origRadius) * ratio; let newRadius = `${value + delta}${unit}`; - let ellipseDef = (this.geometryBox) ? - `ellipse(${newRadius} ${ry} at ${cx} ${cy}) ${this.geometryBox}` : - `ellipse(${newRadius} ${ry} at ${cx} ${cy})`; + let ellipseDef = + `ellipse(${newRadius} ${ry} at ${cx} ${cy}) ${this.geometryBox}`.trim(); this.currentNode.style.setProperty(this.property, ellipseDef, "important"); } else if (point === "ry") { @@ -1201,9 +1187,8 @@ class ShapesHighlighter extends AutoRefreshHighlighter { let delta = ((newRadiusPercent / 100 * height) - origRadius) * ratio; let newRadius = `${value + delta}${unit}`; - let ellipseDef = (this.geometryBox) ? - `ellipse(${rx} ${newRadius} at ${cx} ${cy}) ${this.geometryBox}` : - `ellipse(${rx} ${newRadius} at ${cx} ${cy})`; + let ellipseDef = + `ellipse(${rx} ${newRadius} at ${cx} ${cy}) ${this.geometryBox}`.trim(); this.currentNode.style.setProperty(this.property, ellipseDef, "important"); } diff --git a/devtools/server/actors/utils/shapes-utils.js b/devtools/server/actors/utils/shapes-utils.js index 74a4bf034139..ad1cb2bd1113 100644 --- a/devtools/server/actors/utils/shapes-utils.js +++ b/devtools/server/actors/utils/shapes-utils.js @@ -9,7 +9,7 @@ * @returns {Number} the distance between the two points */ const getDistance = (x1, y1, x2, y2) => { - return Math.hypot(x2 - x1, y2 - y1); + return Math.round(Math.hypot(x2 - x1, y2 - y1)); }; /**