summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /devtools/client/inspector/rules
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/inspector/rules')
-rw-r--r--devtools/client/inspector/rules/models/element-style.js122
-rw-r--r--devtools/client/inspector/rules/test/browser_rules_content_01.js2
-rw-r--r--devtools/client/inspector/rules/test/browser_rules_nested_rules.js6
-rw-r--r--devtools/client/inspector/rules/test/browser_rules_search-filter_context-menu.js12
-rw-r--r--devtools/client/inspector/rules/test/browser_rules_select-and-copy-styles.js4
-rw-r--r--devtools/client/inspector/rules/test/browser_rules_selector-highlighter-nested-rules.js4
-rw-r--r--devtools/client/inspector/rules/test/browser_rules_variables_02.js9
7 files changed, 83 insertions, 76 deletions
diff --git a/devtools/client/inspector/rules/models/element-style.js b/devtools/client/inspector/rules/models/element-style.js
index e280a5e4a0..368a8ae953 100644
--- a/devtools/client/inspector/rules/models/element-style.js
+++ b/devtools/client/inspector/rules/models/element-style.js
@@ -57,7 +57,7 @@ class ElementStyle {
this.ruleView = ruleView;
this.store = store || {};
this.pageStyle = pageStyle;
- this.pseudoElements = [];
+ this.pseudoElementTypes = new Set();
this.showUserAgentStyles = showUserAgentStyles;
this.rules = [];
this.cssProperties = this.ruleView.cssProperties;
@@ -90,7 +90,7 @@ class ElementStyle {
}
this.destroyed = true;
- this.pseudoElements = [];
+ this.pseudoElementTypes.clear();
for (const rule of this.rules) {
if (rule.editor) {
@@ -141,9 +141,12 @@ class ElementStyle {
}
// Store a list of all pseudo-element types found in the matching rules.
- this.pseudoElements = this.rules
- .filter(r => r.pseudoElement)
- .map(r => r.pseudoElement);
+ this.pseudoElementTypes = new Set();
+ for (const rule of this.rules) {
+ if (rule.pseudoElement) {
+ this.pseudoElementTypes.add(rule.pseudoElement);
+ }
+ }
// Mark overridden computed styles.
this.onRuleUpdated();
@@ -275,7 +278,7 @@ class ElementStyle {
this.updateDeclarations();
// Update declarations for matching rules for pseudo-elements.
- for (const pseudo of this.pseudoElements) {
+ for (const pseudo of this.pseudoElementTypes) {
this.updateDeclarations(pseudo);
}
}
@@ -299,11 +302,6 @@ class ElementStyle {
updateDeclarations(pseudo = "") {
// Gather all text properties applicable to the selected element or pseudo-element.
const textProps = this._getDeclarations(pseudo);
- // Gather all the computed properties applied by those text properties.
- let computedProps = [];
- for (const textProp of textProps) {
- computedProps = computedProps.concat(textProp.computed);
- }
// CSS Variables inherits from the normal element in case of pseudo element.
const variables = new Map(pseudo ? this.variablesMap.get("") : null);
@@ -332,58 +330,62 @@ class ElementStyle {
// _overriddenDirty will be set on each prop, indicating whether its
// dirty status changed during this pass.
const taken = new Map();
- for (const computedProp of computedProps) {
- const earlier = taken.get(computedProp.name);
-
- // Prevent -webkit-gradient from being selected after unchecking
- // linear-gradient in this case:
- // -moz-linear-gradient: ...;
- // -webkit-linear-gradient: ...;
- // linear-gradient: ...;
- if (!computedProp.textProp.isValid()) {
- computedProp.overridden = true;
- continue;
- }
-
- let overridden;
- if (
- earlier &&
- computedProp.priority === "important" &&
- (earlier.priority !== "important" ||
- // Even if the earlier property was important, if the current rule is in a layer
- // it will take precedence, unless the earlier property rule was in the same layer.
- (computedProp.textProp.rule?.isInLayer() &&
- computedProp.textProp.rule.isInDifferentLayer(
- earlier.textProp.rule
- ))) &&
- // For !important only consider rules applying to the same parent node.
- computedProp.textProp.rule.inherited == earlier.textProp.rule.inherited
- ) {
- // New property is higher priority. Mark the earlier property
- // overridden (which will reverse its dirty state).
- earlier._overriddenDirty = !earlier._overriddenDirty;
- earlier.overridden = true;
- overridden = false;
- } else {
- overridden = !!earlier;
- }
-
- computedProp._overriddenDirty = !!computedProp.overridden !== overridden;
- computedProp.overridden = overridden;
-
- if (!computedProp.overridden && computedProp.textProp.enabled) {
- taken.set(computedProp.name, computedProp);
+ for (const textProp of textProps) {
+ for (const computedProp of textProp.computed) {
+ const earlier = taken.get(computedProp.name);
+
+ // Prevent -webkit-gradient from being selected after unchecking
+ // linear-gradient in this case:
+ // -moz-linear-gradient: ...;
+ // -webkit-linear-gradient: ...;
+ // linear-gradient: ...;
+ if (!computedProp.textProp.isValid()) {
+ computedProp.overridden = true;
+ continue;
+ }
- // At this point, we can get CSS variable from "inherited" rules.
- // When this is a registered custom property with `inherits` set to false,
- // the text prop is "invisible" (i.e. not shown in the rule view).
- // In such case, we don't want to get the value in the Map, and we'll rather
- // get the initial value from the registered property definition.
+ let overridden;
if (
- isCssVariable(computedProp.name) &&
- !computedProp.textProp.invisible
+ earlier &&
+ computedProp.priority === "important" &&
+ (earlier.priority !== "important" ||
+ // Even if the earlier property was important, if the current rule is in a layer
+ // it will take precedence, unless the earlier property rule was in the same layer.
+ (computedProp.textProp.rule?.isInLayer() &&
+ computedProp.textProp.rule.isInDifferentLayer(
+ earlier.textProp.rule
+ ))) &&
+ // For !important only consider rules applying to the same parent node.
+ computedProp.textProp.rule.inherited ==
+ earlier.textProp.rule.inherited
) {
- variables.set(computedProp.name, computedProp.value);
+ // New property is higher priority. Mark the earlier property
+ // overridden (which will reverse its dirty state).
+ earlier._overriddenDirty = !earlier._overriddenDirty;
+ earlier.overridden = true;
+ overridden = false;
+ } else {
+ overridden = !!earlier;
+ }
+
+ computedProp._overriddenDirty =
+ !!computedProp.overridden !== overridden;
+ computedProp.overridden = overridden;
+
+ if (!computedProp.overridden && computedProp.textProp.enabled) {
+ taken.set(computedProp.name, computedProp);
+
+ // At this point, we can get CSS variable from "inherited" rules.
+ // When this is a registered custom property with `inherits` set to false,
+ // the text prop is "invisible" (i.e. not shown in the rule view).
+ // In such case, we don't want to get the value in the Map, and we'll rather
+ // get the initial value from the registered property definition.
+ if (
+ isCssVariable(computedProp.name) &&
+ !computedProp.textProp.invisible
+ ) {
+ variables.set(computedProp.name, computedProp.value);
+ }
}
}
}
diff --git a/devtools/client/inspector/rules/test/browser_rules_content_01.js b/devtools/client/inspector/rules/test/browser_rules_content_01.js
index b92ec47db0..1985f07f5f 100644
--- a/devtools/client/inspector/rules/test/browser_rules_content_01.js
+++ b/devtools/client/inspector/rules/test/browser_rules_content_01.js
@@ -103,7 +103,7 @@ add_task(async function () {
matches: true,
},
{
- selector: ".unmatched",
+ selector: "& .unmatched",
matches: false,
},
]);
diff --git a/devtools/client/inspector/rules/test/browser_rules_nested_rules.js b/devtools/client/inspector/rules/test/browser_rules_nested_rules.js
index 925f36a0e6..0dc068232b 100644
--- a/devtools/client/inspector/rules/test/browser_rules_nested_rules.js
+++ b/devtools/client/inspector/rules/test/browser_rules_nested_rules.js
@@ -93,7 +93,7 @@ add_task(async function () {
checkRuleViewContent(view, [
{ selector: "element", ancestorRulesData: null, declarations: [] },
{
- selector: `.foo`,
+ selector: `& .foo`,
// prettier-ignore
ancestorRulesData: [
`body {`,
@@ -108,7 +108,7 @@ add_task(async function () {
checkRuleViewContent(view, [
{ selector: "element", ancestorRulesData: null, declarations: [] },
{
- selector: `#bar`,
+ selector: `& #bar`,
// prettier-ignore
ancestorRulesData: [
`body {`,
@@ -138,7 +138,7 @@ add_task(async function () {
checkRuleViewContent(view, [
{ selector: "element", ancestorRulesData: null, declarations: [] },
{
- selector: `[href]`,
+ selector: `& [href]`,
ancestorRulesData: [
`body {`,
` @media screen {`,
diff --git a/devtools/client/inspector/rules/test/browser_rules_search-filter_context-menu.js b/devtools/client/inspector/rules/test/browser_rules_search-filter_context-menu.js
index 881b5274ee..009c67cd70 100644
--- a/devtools/client/inspector/rules/test/browser_rules_search-filter_context-menu.js
+++ b/devtools/client/inspector/rules/test/browser_rules_search-filter_context-menu.js
@@ -86,12 +86,12 @@ add_task(async function () {
cmdCopy = searchContextMenu.querySelector("#editmenu-copy");
cmdPaste = searchContextMenu.querySelector("#editmenu-paste");
- is(cmdUndo.getAttribute("disabled"), "", "cmdUndo is enabled");
- is(cmdDelete.getAttribute("disabled"), "", "cmdDelete is enabled");
- is(cmdSelectAll.getAttribute("disabled"), "", "cmdSelectAll is enabled");
- is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
- is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
- is(cmdPaste.getAttribute("disabled"), "", "cmdPaste is enabled");
+ is(cmdUndo.getAttribute("disabled"), null, "cmdUndo is enabled");
+ is(cmdDelete.getAttribute("disabled"), null, "cmdDelete is enabled");
+ is(cmdSelectAll.getAttribute("disabled"), null, "cmdSelectAll is enabled");
+ is(cmdCut.getAttribute("disabled"), null, "cmdCut is enabled");
+ is(cmdCopy.getAttribute("disabled"), null, "cmdCopy is enabled");
+ is(cmdPaste.getAttribute("disabled"), null, "cmdPaste is enabled");
const onContextMenuHidden = toolbox.once("menu-close");
searchContextMenu.hidePopup();
diff --git a/devtools/client/inspector/rules/test/browser_rules_select-and-copy-styles.js b/devtools/client/inspector/rules/test/browser_rules_select-and-copy-styles.js
index f9d245828e..c6d4f29a4d 100644
--- a/devtools/client/inspector/rules/test/browser_rules_select-and-copy-styles.js
+++ b/devtools/client/inspector/rules/test/browser_rules_select-and-copy-styles.js
@@ -209,9 +209,9 @@ async function checkCopyNestedRule(view) {
const copyEvent = new win.Event("copy", { bubbles: true });
const expectedNested = `html {
- body {
+ & body {
@container (1px < width) {
- #nested {
+ & #nested {
background: tomato;
color: gold;
}
diff --git a/devtools/client/inspector/rules/test/browser_rules_selector-highlighter-nested-rules.js b/devtools/client/inspector/rules/test/browser_rules_selector-highlighter-nested-rules.js
index 4a5e8bcd0c..ecf41fb920 100644
--- a/devtools/client/inspector/rules/test/browser_rules_selector-highlighter-nested-rules.js
+++ b/devtools/client/inspector/rules/test/browser_rules_selector-highlighter-nested-rules.js
@@ -88,8 +88,8 @@ add_task(async function () {
);
ok(highlighterData.isShown, "The selector highlighter was shown");
- info(`Clicking on ".title" selector icon`);
- highlighterData = await clickSelectorIcon(view, ".title");
+ info(`Clicking on "& .title" selector icon`);
+ highlighterData = await clickSelectorIcon(view, "& .title");
is(
highlighterData.nodeFront.nodeName.toLowerCase(),
"h1",
diff --git a/devtools/client/inspector/rules/test/browser_rules_variables_02.js b/devtools/client/inspector/rules/test/browser_rules_variables_02.js
index 4100859fb9..ee37a7b07a 100644
--- a/devtools/client/inspector/rules/test/browser_rules_variables_02.js
+++ b/devtools/client/inspector/rules/test/browser_rules_variables_02.js
@@ -119,9 +119,14 @@ async function testBorderShorthandAndInheritance(inspector, view) {
// var(x) is the next sibling of the parent of M
const setVarXParent = setVarMParent.parentNode.nextElementSibling;
- // var(r) is the next sibling of var(x), and var(g) is the next sibling of var(r), etc.
- const setVarRParent = setVarXParent.nextElementSibling;
+ // var(x) next sibling is the element that wraps the color
+ const colorParent =
+ setVarXParent.nextElementSibling.querySelector(".ruleview-color");
+ // var(r) is the first childElement of the ruleview-color element
+ const setVarRParent = colorParent.firstElementChild;
+ // var(g) is the next sibling of var(r),
const setVarGParent = setVarRParent.nextElementSibling;
+ // and var(b) is the next sibling of var(g),
const setVarBParent = setVarGParent.nextElementSibling;
const setVarM = getVarFromParent(setVarMParent);