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 draft
authorErica Wright <ewright@mozilla.com>
Wed, 21 Mar 2018 14:53:08 -0400
changeset 770818 7da45ca92690f2dcc608ab31046d83b70cde83fe
parent 768775 c488b8d0e074efb490ebca32db68eb77871bfd2f
push id103506
push userbmo:ewright@mozilla.com
push dateWed, 21 Mar 2018 20:59:02 +0000
reviewerspbro
bugs1386047
milestone61.0a1
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
devtools/server/actors/highlighters/css-grid.js
devtools/server/actors/highlighters/flexbox.js
--- 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.
    */