Bug 1386047 - Grid and Flexbox inspector cross hash that fills the grid gap and flex container stays 45deg to the bounding lines on rotations. r?pbro
MozReview-Commit-ID: 1tDTGHEixCS
--- a/devtools/server/actors/highlighters/css-grid.js
+++ b/devtools/server/actors/highlighters/css-grid.js
@@ -1062,16 +1062,23 @@ class CssGridHighlighter extends AutoRef
} else {
endPos = this._winDimensions.width;
startPos = -endPos;
}
drawRect(this.ctx, startPos, linePos, endPos, linePos + breadth,
this.currentMatrix);
}
+ // Find current angle of grid by measuring the angle of two arbitrary points,
+ // then rotate canvas, so the hash pattern stays 45deg to the gridlines.
+ let p1 = apply(this.currentMatrix, [0, 0]);
+ let p2 = apply(this.currentMatrix, [1, 0]);
+ let angleRad = Math.atan2(p2[1] - p1[1], p2[0] - p1[0]);
+ this.ctx.rotate(angleRad);
+
this.ctx.fill();
this.ctx.restore();
}
/**
* Render the grid line name highlight for the given grid fragment index, lineNumber,
* and dimensionType.
*
--- a/devtools/server/actors/highlighters/flexbox.js
+++ b/devtools/server/actors/highlighters/flexbox.js
@@ -1,15 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { AutoRefreshHighlighter } = require("./auto-refresh");
+const { apply } = require("devtools/shared/layout/dom-matrix-2d");
const {
CANVAS_SIZE,
DEFAULT_COLOR,
clearRect,
drawLine,
drawRect,
getCurrentMatrix,
updateCanvasElement,
@@ -359,16 +360,23 @@ class FlexboxHighlighter extends AutoRef
this.ctx.setLineDash(FLEXBOX_LINES_PROPERTIES.edge.lineDash);
this.ctx.lineWidth = 0;
this.ctx.strokeStyle = DEFAULT_COLOR;
this.ctx.fillStyle = this.getFlexContainerPattern(devicePixelRatio);
let { bounds } = this.currentQuads.content[0];
drawRect(this.ctx, 0, 0, bounds.width, bounds.height, this.currentMatrix);
+ // Find current angle of outer flex element by measuring the angle of two arbitrary
+ // points, then rotate canvas, so the hash pattern stays 45deg to the boundary.
+ let p1 = apply(this.currentMatrix, [0, 0]);
+ let p2 = apply(this.currentMatrix, [1, 0]);
+ let angleRad = Math.atan2(p2[1] - p1[1], p2[0] - p1[0]);
+ this.ctx.rotate(angleRad);
+
this.ctx.fill();
this.ctx.stroke();
this.ctx.restore();
}
/**
* Renders the flex basis for a given flex item.
*/