Bug 1369942 - Display Negative Line Numbers in CSS Grid Inspector. r=zer0
MozReview-Commit-ID: FmOj7jVT3Ll
--- a/devtools/client/preferences/devtools.js
+++ b/devtools/client/preferences/devtools.js
@@ -78,16 +78,17 @@ pref("devtools.promote.layoutview", 1);
pref("devtools.promote.layoutview.showPromoteBar", true);
// Grid highlighter preferences
pref("devtools.gridinspector.gridOutlineMaxColumns", 50);
pref("devtools.gridinspector.gridOutlineMaxRows", 50);
pref("devtools.gridinspector.showGridAreas", false);
pref("devtools.gridinspector.showGridLineNumbers", false);
pref("devtools.gridinspector.showInfiniteLines", false);
+pref("devtools.gridinspector.showNegativeLineNumbers", false);
// Whether or not the box model panel is opened in the computed view
pref("devtools.computed.boxmodel.opened", true);
// Whether or not the box model panel is opened in the layout view
pref("devtools.layout.boxmodel.opened", true);
// Whether or not the grid inspector panel is opened in the layout view
pref("devtools.layout.grid.opened", true);
--- a/devtools/server/actors/highlighters/css-grid.js
+++ b/devtools/server/actors/highlighters/css-grid.js
@@ -29,16 +29,17 @@ const {
} = require("devtools/shared/layout/dom-matrix-2d");
const { stringifyGridFragments } = require("devtools/server/actors/utils/css-grid-utils");
const { LocalizationHelper } = require("devtools/shared/l10n");
const LAYOUT_STRINGS_URI = "devtools/client/locales/layout.properties";
const LAYOUT_L10N = new LocalizationHelper(LAYOUT_STRINGS_URI);
const CSS_GRID_ENABLED_PREF = "layout.css.grid.enabled";
+const NEGATIVE_LINE_NUMBERS_PREF = "devtools.gridinspector.showNegativeLineNumbers";
const DEFAULT_GRID_COLOR = "#4B0082";
const COLUMNS = "cols";
const ROWS = "rows";
const GRID_FONT_SIZE = 10;
const GRID_FONT_FAMILY = "sans-serif";
@@ -1140,16 +1141,45 @@ class CssGridHighlighter extends AutoRef
}
// Line numbers are rendered in a 2nd step to avoid overlapping with existing lines.
if (this.options.showGridLineNumbers) {
this.renderLineNumbers(fragment.cols, COLUMNS, "left", "top",
this.getFirstRowLinePos(fragment));
this.renderLineNumbers(fragment.rows, ROWS, "top", "left",
this.getFirstColLinePos(fragment));
+
+ if (Services.prefs.getBoolPref(NEGATIVE_LINE_NUMBERS_PREF)) {
+ this.renderNegativeLineNumbers(fragment.cols, COLUMNS, "left", "top",
+ this.getLastRowLinePos(fragment));
+ this.renderNegativeLineNumbers(fragment.rows, ROWS, "top", "left",
+ this.getLastColLinePos(fragment));
+ }
+ }
+ }
+
+ /**
+ * Render the negative grid lines given the grid dimension information of the
+ * column or row lines.
+ *
+ * See @param for renderLines.
+ */
+ renderNegativeLineNumbers(gridDimension, dimensionType, mainSide, crossSide,
+ startPos) {
+ let lineStartPos = startPos;
+
+ const { lines } = gridDimension;
+
+ for (let i = 0, line = lines[i]; i < lines.length; line = lines[++i]) {
+ let linePos = line.start;
+
+ const negativeLineNumber = i - lines.length;
+
+ this.renderGridLineNumber(negativeLineNumber, linePos, lineStartPos, line.breadth,
+ dimensionType);
}
}
/**
* Renders the grid area overlay on the css grid highlighter canvas.
*/
renderGridAreaOverlay() {
let padding = 1;
@@ -1458,16 +1488,28 @@ class CssGridHighlighter extends AutoRef
let boxWidth = textWidth + 2 * padding;
let boxHeight = textHeight + 2 * padding;
// Calculate the x & y coordinates for the line number container, so that it is
// centered on the line, and in the middle of the gap if there is any.
let x, y;
+ let startOffset = (boxHeight + 2) / devicePixelRatio;
+
+ if (Services.prefs.getBoolPref(NEGATIVE_LINE_NUMBERS_PREF)) {
+ // If the line number is negative, offset it from the grid container edge,
+ // (downwards if its a column, rightwards if its a row).
+ if (lineNumber < 0) {
+ startPos += startOffset;
+ } else {
+ startPos -= startOffset;
+ }
+ }
+
if (dimensionType === COLUMNS) {
x = linePos + breadth / 2;
y = startPos;
} else {
x = startPos;
y = linePos + breadth / 2;
}