/* 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 Services = require("Services");
const { extend } = require("sdk/core/heritage");
const { AutoRefreshHighlighter } = require("./auto-refresh");
const {
CanvasFrameAnonymousContentHelper,
createNode,
createSVGNode,
moveInfobar,
} = require("./utils/markup");
const {
getCurrentZoom,
setIgnoreLayoutChanges
} = require("devtools/shared/layout/utils");
const { stringifyGridFragments } = require("devtools/server/actors/utils/css-grid-utils");
const CSS_GRID_ENABLED_PREF = "layout.css.grid.enabled";
const ROWS = "rows";
const COLUMNS = "cols";
const GRID_LINES_PROPERTIES = {
"edge": {
lineDash: [0, 0],
strokeStyle: "#4B0082"
},
"explicit": {
lineDash: [5, 3],
strokeStyle: "#8A2BE2"
},
"implicit": {
lineDash: [2, 2],
strokeStyle: "#9370DB"
}
};
// px
const GRID_GAP_PATTERN_WIDTH = 14;
const GRID_GAP_PATTERN_HEIGHT = 14;
const GRID_GAP_PATTERN_LINE_DASH = [5, 3];
const GRID_GAP_PATTERN_STROKE_STYLE = "#9370DB";
/**
* Cached used by `CssGridHighlighter.getGridGapPattern`.
*/
const gCachedGridPattern = new WeakMap();
// WeakMap key for the Row grid pattern.
const ROW_KEY = {};
// WeakMap key for the Column grid pattern.
const COLUMN_KEY = {};
/**
* The CssGridHighlighter is the class that overlays a visual grid on top of
* display:grid elements.
*
* Usage example:
* let h = new CssGridHighlighter(env);
* h.show(node, options);
* h.hide();
* h.destroy();
*
* Available Options:
* - showGridArea(areaName)
* @param {String} areaName
* Shows the grid area highlight for the given area name.
* - showAllGridAreas
* Shows all the grid area highlights for the current grid.
* - showGridLineNumbers(isShown)
* @param {Boolean}
* Displays the grid line numbers on the grid lines if isShown is true.
* - showInfiniteLines(isShown)
* @param {Boolean} isShown
* Displays an infinite line to represent the grid lines if isShown is true.
*
* Structure:
*
*/
function CssGridHighlighter(highlighterEnv) {
AutoRefreshHighlighter.call(this, highlighterEnv);
this.markup = new CanvasFrameAnonymousContentHelper(this.highlighterEnv,
this._buildMarkup.bind(this));
this.onNavigate = this.onNavigate.bind(this);
this.onWillNavigate = this.onWillNavigate.bind(this);
this.highlighterEnv.on("navigate", this.onNavigate);
this.highlighterEnv.on("will-navigate", this.onWillNavigate);
}
CssGridHighlighter.prototype = extend(AutoRefreshHighlighter.prototype, {
typeName: "CssGridHighlighter",
ID_CLASS_PREFIX: "css-grid-",
_buildMarkup() {
let container = createNode(this.win, {
attributes: {
"class": "highlighter-container"
}
});
// We use a