/* 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("resource://devtools/server/actors/highlighters/auto-refresh.js");
const { apply } = require("resource://devtools/shared/layout/dom-matrix-2d.js");
const {
CANVAS_SIZE,
DEFAULT_COLOR,
clearRect,
drawLine,
drawRect,
getCurrentMatrix,
updateCanvasElement,
updateCanvasPosition,
} = require("resource://devtools/server/actors/highlighters/utils/canvas.js");
const {
CanvasFrameAnonymousContentHelper,
getComputedStyle,
} = require("resource://devtools/server/actors/highlighters/utils/markup.js");
const {
getAbsoluteScrollOffsetsForNode,
getCurrentZoom,
getDisplayPixelRatio,
getUntransformedQuad,
getWindowDimensions,
setIgnoreLayoutChanges,
} = require("resource://devtools/shared/layout/utils.js");
const FLEXBOX_LINES_PROPERTIES = {
edge: {
lineDash: [5, 3],
},
item: {
lineDash: [0, 0],
},
alignItems: {
lineDash: [0, 0],
},
};
const FLEXBOX_CONTAINER_PATTERN_LINE_DASH = [5, 3]; // px
const FLEXBOX_CONTAINER_PATTERN_WIDTH = 14; // px
const FLEXBOX_CONTAINER_PATTERN_HEIGHT = 14; // px
const FLEXBOX_JUSTIFY_CONTENT_PATTERN_WIDTH = 7; // px
const FLEXBOX_JUSTIFY_CONTENT_PATTERN_HEIGHT = 7; // px
/**
* Cached used by `FlexboxHighlighter.getFlexContainerPattern`.
*/
const gCachedFlexboxPattern = new Map();
const FLEXBOX = "flexbox";
const JUSTIFY_CONTENT = "justify-content";
/**
* The FlexboxHighlighter is the class that overlays a visual canvas on top of
* display: [inline-]flex elements.
*
* @param {String} options.color
* The color that should be used to draw the highlighter for this flexbox.
* Structure:
*
*/
class FlexboxHighlighter extends AutoRefreshHighlighter {
constructor(highlighterEnv) {
super(highlighterEnv);
this.ID_CLASS_PREFIX = "flexbox-";
this.markup = new CanvasFrameAnonymousContentHelper(
this.highlighterEnv,
this._buildMarkup.bind(this)
);
this.isReady = this.markup.initialize();
this.onPageHide = this.onPageHide.bind(this);
this.onWillNavigate = this.onWillNavigate.bind(this);
this.highlighterEnv.on("will-navigate", this.onWillNavigate);
const { pageListenerTarget } = highlighterEnv;
pageListenerTarget.addEventListener("pagehide", this.onPageHide);
// Initialize the