Skip to content

Commit 4d3fd5c

Browse files
committed
Bug 1984365 - [devtools] Update boxmodel highlighter infobar element data even if info bar is hidden. r=devtools-reviewers,ochameau.
This should make it easier to test and debug such highlighter, so we know for which elements they're displayed. Depends on D261767 Differential Revision: https://phabricator.services.mozilla.com/D261960
1 parent acf0251 commit 4d3fd5c

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

devtools/server/actors/highlighters/box-model.js

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const nodeConstants = require("resource://devtools/shared/dom-node-constants.js"
2929
loader.lazyGetter(this, "HighlightersBundle", () => {
3030
return new Localization(["devtools/shared/highlighters.ftl"], true);
3131
});
32+
loader.lazyRequireGetter(this, "flags", "resource://devtools/shared/flags.js");
3233

3334
// Note that the order of items in this array is important because it is used
3435
// for drawing the BoxModelHighlighter's path elements correctly.
@@ -369,17 +370,24 @@ class BoxModelHighlighter extends AutoRefreshHighlighter {
369370
setIgnoreLayoutChanges(true);
370371

371372
if (this._updateBoxModel()) {
373+
const isElementOrTextNode =
374+
node.nodeType === node.ELEMENT_NODE || node.nodeType === node.TEXT_NODE;
372375
// Show the infobar only if configured to do so and the node is an element or a text
373376
// node.
374-
if (
375-
!this.options.hideInfoBar &&
376-
(node.nodeType === node.ELEMENT_NODE ||
377-
node.nodeType === node.TEXT_NODE)
378-
) {
379-
this._showInfobar();
377+
if (isElementOrTextNode) {
378+
if (!this.options.hideInfoBar) {
379+
this._showInfobar();
380+
} else if (flags.testing) {
381+
// Even if we don't want to show the info bar, update the infobar data (tag, id,
382+
// classes, …) anyway so it's easier to debug/test
383+
this._updateInfobarNodeData();
384+
} else {
385+
this._hideInfobar();
386+
}
380387
} else {
381388
this._hideInfobar();
382389
}
390+
383391
this._updateSimpleHighlighters();
384392
this._showBoxModel();
385393

@@ -783,24 +791,10 @@ class BoxModelHighlighter extends AutoRefreshHighlighter {
783791
return;
784792
}
785793

786-
const { bindingElement: node, pseudo } = getBindingElementAndPseudo(
794+
const { bindingElement: node } = getBindingElementAndPseudo(
787795
this.currentNode
788796
);
789797

790-
// Update the tag, id, classes, pseudo-classes and dimensions
791-
const displayName = getNodeDisplayName(node);
792-
793-
const id = node.id ? "#" + node.id : "";
794-
795-
const classList = (node.classList || []).length
796-
? "." + [...node.classList].join(".")
797-
: "";
798-
799-
let pseudos = this._getPseudoClasses(node).join("");
800-
if (pseudo) {
801-
pseudos += pseudo;
802-
}
803-
804798
// We want to display the original `width` and `height`, instead of the ones affected
805799
// by any zoom. Since the infobar can be displayed also for text nodes, we can't
806800
// access the computed style for that, and this is why we recalculate them here.
@@ -821,10 +815,8 @@ class BoxModelHighlighter extends AutoRefreshHighlighter {
821815
const gridLayoutTextType = this._getLayoutTextType("gridtype", gridType);
822816
const flexLayoutTextType = this._getLayoutTextType("flextype", flexType);
823817

824-
this.getElement("box-model-infobar-tagname").setTextContent(displayName);
825-
this.getElement("box-model-infobar-id").setTextContent(id);
826-
this.getElement("box-model-infobar-classes").setTextContent(classList);
827-
this.getElement("box-model-infobar-pseudo-classes").setTextContent(pseudos);
818+
// Update the tag, id, classes, pseudo-classes
819+
this._updateInfobarNodeData();
828820
this.getElement("box-model-infobar-dimensions").setTextContent(dim);
829821
this.getElement("box-model-infobar-grid-type").setTextContent(
830822
gridLayoutTextType
@@ -836,6 +828,35 @@ class BoxModelHighlighter extends AutoRefreshHighlighter {
836828
this._moveInfobar();
837829
}
838830

831+
_updateInfobarNodeData() {
832+
if (!this.currentNode) {
833+
return;
834+
}
835+
836+
const { bindingElement: node, pseudo } = getBindingElementAndPseudo(
837+
this.currentNode
838+
);
839+
840+
// Update the tag, id, classes, pseudo-classes and dimensions
841+
const displayName = getNodeDisplayName(node);
842+
843+
const id = node.id ? "#" + node.id : "";
844+
845+
const classList = node.classList?.length
846+
? "." + [...node.classList].join(".")
847+
: "";
848+
849+
let pseudos = this._getPseudoClasses(node).join("");
850+
if (pseudo) {
851+
pseudos += pseudo;
852+
}
853+
854+
this.getElement("box-model-infobar-tagname").setTextContent(displayName);
855+
this.getElement("box-model-infobar-id").setTextContent(id);
856+
this.getElement("box-model-infobar-classes").setTextContent(classList);
857+
this.getElement("box-model-infobar-pseudo-classes").setTextContent(pseudos);
858+
}
859+
839860
_getLayoutTextType(layoutTypeKey, { isContainer, isItem }) {
840861
if (!isContainer && !isItem) {
841862
return "";

0 commit comments

Comments
 (0)