Bug 1321467 - display grid line numbers with extended grid lines;r=zer0 draft
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 21 Feb 2017 17:51:01 +0100
changeset 487518 a242af83e654cd3cf1e234ad63a4852b47e9f8fb
parent 486570 698de2db1b16a5ef3c6a39f0f72885e69aee4022
child 546471 251dd8768251074549aebf7baaeda0edbbd30fb2
push id46236
push userjdescottes@mozilla.com
push dateTue, 21 Feb 2017 17:17:16 +0000
reviewerszer0
bugs1321467
milestone54.0a1
Bug 1321467 - display grid line numbers with extended grid lines;r=zer0 Clamp the x and y positions for the grid line numbers to make sure they are always visible, even if extended grid lines is turned on. MozReview-Commit-ID: 3sxdWtKyXKN
devtools/server/actors/highlighters/css-grid.js
--- a/devtools/server/actors/highlighters/css-grid.js
+++ b/devtools/server/actors/highlighters/css-grid.js
@@ -626,21 +626,26 @@ CssGridHighlighter.prototype = extend(Au
    * @param  {Number} startPos
    *         The start position of the cross side of the grid line.
    * @param  {String} dimensionType
    *         The grid dimension type which is either the constant COLUMNS or ROWS.
    */
   renderGridLineNumber(lineNumber, linePos, startPos, dimensionType) {
     this.ctx.save();
 
+    let textWidth = this.ctx.measureText(lineNumber).width;
+    // Guess the font height based on the measured width
+    let textHeight = textWidth * 2;
+
     if (dimensionType === COLUMNS) {
-      this.ctx.fillText(lineNumber, linePos, startPos);
+      let yPos = Math.max(startPos, textHeight);
+      this.ctx.fillText(lineNumber, linePos, yPos);
     } else {
-      let textWidth = this.ctx.measureText(lineNumber).width;
-      this.ctx.fillText(lineNumber, startPos - textWidth, linePos);
+      let xPos = Math.max(startPos, textWidth);
+      this.ctx.fillText(lineNumber, xPos - textWidth, linePos);
     }
 
     this.ctx.restore();
   },
 
   /**
    * Render the grid gap area on the css grid highlighter canvas.
    *