diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:50 +0000 |
commit | def92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch) | |
tree | 2ef34b9ad8bb9a9220e05d60352558b15f513894 /layout/inspector | |
parent | Adding debian version 125.0.3-1. (diff) | |
download | firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/inspector')
-rw-r--r-- | layout/inspector/InspectorUtils.cpp | 31 | ||||
-rw-r--r-- | layout/inspector/InspectorUtils.h | 15 | ||||
-rw-r--r-- | layout/inspector/ServoStyleRuleMap.cpp | 8 | ||||
-rw-r--r-- | layout/inspector/tests/mochitest.toml | 3 | ||||
-rw-r--r-- | layout/inspector/tests/test_bug877690.html | 7 | ||||
-rw-r--r-- | layout/inspector/tests/test_getCSSPseudoElementNames.html | 1 | ||||
-rw-r--r-- | layout/inspector/tests/test_replaceBlockRuleBodyTextInStylesheet.html | 209 |
7 files changed, 250 insertions, 24 deletions
diff --git a/layout/inspector/InspectorUtils.cpp b/layout/inspector/InspectorUtils.cpp index f1886a0dd0..d174c16424 100644 --- a/layout/inspector/InspectorUtils.cpp +++ b/layout/inspector/InspectorUtils.cpp @@ -415,6 +415,7 @@ static uint32_t CollectAtRules(ServoCSSRuleList& aRuleList, case StyleCssRuleType::Media: case StyleCssRuleType::Supports: case StyleCssRuleType::LayerBlock: + case StyleCssRuleType::Property: case StyleCssRuleType::Container: { Unused << aResult.AppendElement(OwningNonNull(*rule), fallible); break; @@ -425,7 +426,6 @@ static uint32_t CollectAtRules(ServoCSSRuleList& aRuleList, case StyleCssRuleType::LayerStatement: case StyleCssRuleType::FontFace: case StyleCssRuleType::Page: - case StyleCssRuleType::Property: case StyleCssRuleType::Keyframes: case StyleCssRuleType::Keyframe: case StyleCssRuleType::Margin: @@ -433,6 +433,8 @@ static uint32_t CollectAtRules(ServoCSSRuleList& aRuleList, case StyleCssRuleType::CounterStyle: case StyleCssRuleType::FontFeatureValues: case StyleCssRuleType::FontPaletteValues: + case StyleCssRuleType::Scope: + case StyleCssRuleType::StartingStyle: break; } @@ -1000,22 +1002,19 @@ void InspectorUtils::GetCSSRegisteredProperties( } /* static */ -void InspectorUtils::GetRuleBodyTextOffsets( - GlobalObject&, const nsACString& aInitialText, - Nullable<InspectorGetRuleBodyTextResult>& aResult) { - uint32_t resultStartOffset; - uint32_t resultEndOffset; - - if (!Servo_GetRuleBodyTextOffsets(&aInitialText, &resultStartOffset, - &resultEndOffset)) { - aResult.SetNull(); - return; - } - - InspectorGetRuleBodyTextResult& offsets = aResult.SetValue(); - offsets.mStartOffset = resultStartOffset; - offsets.mEndOffset = resultEndOffset; +void InspectorUtils::GetRuleBodyText(GlobalObject&, + const nsACString& aInitialText, + nsACString& aBodyText) { + Servo_GetRuleBodyText(&aInitialText, &aBodyText); } +/* static */ +void InspectorUtils::ReplaceBlockRuleBodyTextInStylesheet( + GlobalObject&, const nsACString& aStyleSheetText, uint32_t aLine, + uint32_t aColumn, const nsACString& aNewBodyText, + nsACString& aNewStyleSheetText) { + Servo_ReplaceBlockRuleBodyTextInStylesheetText( + &aStyleSheetText, aLine, aColumn, &aNewBodyText, &aNewStyleSheetText); +} } // namespace dom } // namespace mozilla diff --git a/layout/inspector/InspectorUtils.h b/layout/inspector/InspectorUtils.h index f375e51472..9d64823fc4 100644 --- a/layout/inspector/InspectorUtils.h +++ b/layout/inspector/InspectorUtils.h @@ -270,11 +270,18 @@ class InspectorUtils { nsTArray<InspectorCSSPropertyDefinition>& aResult); /** - * Get the rule body text start and end offsets within aInitialText + * Get the rule body text within aInitialText */ - static void GetRuleBodyTextOffsets( - GlobalObject&, const nsACString& aInitialText, - Nullable<InspectorGetRuleBodyTextResult>& aResult); + static void GetRuleBodyText(GlobalObject&, const nsACString& aInitialText, + nsACString& aBodyText); + + /** + * Replace the rule body text in aStyleSheetText at passed line and column + */ + static void ReplaceBlockRuleBodyTextInStylesheet( + GlobalObject&, const nsACString& aStyleSheetText, uint32_t aLine, + uint32_t aColumn, const nsACString& aNewBodyText, + nsACString& aNewStyleSheetText); }; } // namespace mozilla::dom diff --git a/layout/inspector/ServoStyleRuleMap.cpp b/layout/inspector/ServoStyleRuleMap.cpp index b67d0c98fc..188c4f5329 100644 --- a/layout/inspector/ServoStyleRuleMap.cpp +++ b/layout/inspector/ServoStyleRuleMap.cpp @@ -86,7 +86,9 @@ void ServoStyleRuleMap::RuleRemoved(StyleSheet& aStyleSheet, case StyleCssRuleType::Supports: case StyleCssRuleType::LayerBlock: case StyleCssRuleType::Container: - case StyleCssRuleType::Document: { + case StyleCssRuleType::Document: + case StyleCssRuleType::Scope: + case StyleCssRuleType::StartingStyle: { // See the comment in SheetRemoved. mTable.Clear(); break; @@ -124,7 +126,9 @@ void ServoStyleRuleMap::FillTableFromRule(css::Rule& aRule) { case StyleCssRuleType::Media: case StyleCssRuleType::Supports: case StyleCssRuleType::Container: - case StyleCssRuleType::Document: { + case StyleCssRuleType::Document: + case StyleCssRuleType::Scope: + case StyleCssRuleType::StartingStyle: { auto& rule = static_cast<css::GroupRule&>(aRule); FillTableFromRuleList(*rule.CssRules()); break; diff --git a/layout/inspector/tests/mochitest.toml b/layout/inspector/tests/mochitest.toml index e51941752b..b45742b727 100644 --- a/layout/inspector/tests/mochitest.toml +++ b/layout/inspector/tests/mochitest.toml @@ -1,6 +1,7 @@ [DEFAULT] prefs = [ "layout.css.basic-shape-rect.enabled=true", + "layout.css.basic-shape-shape.enabled=true", "layout.css.basic-shape-xywh.enabled=true", "layout.css.properties-and-values.enabled=true", "layout.css.transition-behavior.enabled=true", @@ -78,6 +79,8 @@ skip-if = ["os == 'android'"] ["test_parseStyleSheet_nested.html"] +["test_replaceBlockRuleBodyTextInStylesheet.html"] + ["test_rgba_to_color_name.html"] ["test_selectormatcheselement.html"] diff --git a/layout/inspector/tests/test_bug877690.html b/layout/inspector/tests/test_bug877690.html index 9e5efca0d3..668d18200e 100644 --- a/layout/inspector/tests/test_bug877690.html +++ b/layout/inspector/tests/test_bug877690.html @@ -217,10 +217,13 @@ function do_test() { ok(testValues(values, expected), "property box-shadow's values"); // Regression test for bug 1255379. + var shapeFunction = [ "close", "evenodd", "nonzero", "by", "to", "cw", "ccw", + "small", "large" ]; var expected = [ "inherit", "initial", "unset", "revert", "revert-layer", "none", "url", "polygon", "circle", "ellipse", "inset", - "path", "rect", "xywh", "fill-box", "stroke-box", "view-box", - "margin-box", "border-box", "padding-box", "content-box" ]; + "path", "rect", "xywh", "fill-box", "stroke-box", + "view-box", "margin-box", "border-box", "padding-box", + "content-box", ...shapeFunction ]; var values = InspectorUtils.getCSSValuesForProperty("clip-path"); ok(testValues(values, expected), "property clip-path's values"); diff --git a/layout/inspector/tests/test_getCSSPseudoElementNames.html b/layout/inspector/tests/test_getCSSPseudoElementNames.html index 255f58b889..356d4a89bc 100644 --- a/layout/inspector/tests/test_getCSSPseudoElementNames.html +++ b/layout/inspector/tests/test_getCSSPseudoElementNames.html @@ -22,6 +22,7 @@ "::highlight", "::placeholder", "::selection", + "::target-text", "::-moz-color-swatch", "::-moz-focus-inner", "::-moz-meter-bar", diff --git a/layout/inspector/tests/test_replaceBlockRuleBodyTextInStylesheet.html b/layout/inspector/tests/test_replaceBlockRuleBodyTextInStylesheet.html new file mode 100644 index 0000000000..e6385978ba --- /dev/null +++ b/layout/inspector/tests/test_replaceBlockRuleBodyTextInStylesheet.html @@ -0,0 +1,209 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Test InspectorUtils::replaceBlockRuleBodyTextInStylesheet</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> + <style> +#test-simple { + color: #f0c; +} +#test-unicode,[data-unicode="๐ฆ๐จโ๐ฉโ๐งโ๐ฆ"]::after { + content: /* test comment */ "๐จโ๐ฉโ๐งโ๐ฆ๐ฆ"; + outline: 2px solid salmon; +} +#test-empty {} /* ๐ ๏ธโ๏ธ๐ ๏ธ */ #test-same-line { font-size: 3em; } +#test-nested-parent { + color: tomato; + #test-nested-child { + background: gold; + } +}#test-after-closing-bracket{--modified:false} + </style> + <script>SimpleTest.waitForExplicitFinish();</script> + <script defer> + const InspectorUtils = SpecialPowers.InspectorUtils; + let stylesheet = document.styleSheets[1]; + let authoredStyleSheetText = document.querySelector("style").textContent; + + const existingRulesAuthoredText = [ +`#test-simple { + color: #f0c; +}`, +`#test-unicode,[data-unicode="๐ฆ๐จโ๐ฉโ๐งโ๐ฆ"]::after { + content: /* test comment */ "๐จโ๐ฉโ๐งโ๐ฆ๐ฆ"; + outline: 2px solid salmon; +}`, +`#test-empty {}`, +`#test-same-line { font-size: 3em; }`, +`#test-nested-parent { + color: tomato; + #test-nested-child { + background: gold; + } +}`, +`#test-nested-child { + background: gold; + }`, +`#test-after-closing-bracket{--modified:false}`, +]; + + const replaceBlockRuleBodyTextInStylesheet = (rule, newBodyText) => { + return InspectorUtils.replaceBlockRuleBodyTextInStylesheet( + authoredStyleSheetText, + InspectorUtils.getRelativeRuleLine(rule), + InspectorUtils.getRuleColumn(rule), + newBodyText + )}; + + info("Check a simple case"); + let newBodyText = `border-color: cyan;`; + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[0], newBodyText), + authoredStyleSheetText.replace( + existingRulesAuthoredText[0], + `#test-simple {${newBodyText}}`, + ), + "Got the expected result for #test-simple" + ); + + info("Check that the rule body can be emptied"); + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[0], ""), + authoredStyleSheetText.replace( + existingRulesAuthoredText[0], + `#test-simple {}`, + ), + "Successfuly removed rule content for #test-simple" + ); + + info("Check that it can handle unicode characters"); + newBodyText = `content: "o ๐ฆ o";`; + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[1], newBodyText), + authoredStyleSheetText.replace(existingRulesAuthoredText[1], + `#test-unicode,[data-unicode="๐ฆ๐จโ๐ฉโ๐งโ๐ฆ"]::after {${newBodyText}}`, + ), + "Got the expected result for #test-unicode" + ); + + info("Check that it can replace content of an empty rule"); + newBodyText = `font-family: "Zilla;"`; + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[2], newBodyText), + authoredStyleSheetText.replace( + existingRulesAuthoredText[2], + `#test-empty {${newBodyText}}`, + ), + "Got the expected result for #test-empty" + ); + + info("Check that it can handle a rule on a same line as another rule"); + newBodyText = `color: pink;`; + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[3], newBodyText), + authoredStyleSheetText.replace( + existingRulesAuthoredText[3], + `#test-same-line {${newBodyText}}`, + ), + "Got the expected result for #test-same-line" + ); + + info("Check that it can handle a rule with a child rule"); + newBodyText = `background: silver; + & > span { + color: white; + }`; + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[4], newBodyText), + authoredStyleSheetText.replace( + existingRulesAuthoredText[4], + `#test-nested-parent {${newBodyText}}`, + ), + "Got the expected result for #test-nested-parent" + ); + + info("Check that it can handle a nested rule"); + newBodyText = `color: white;height: 100%;`; + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[4].cssRules[0], newBodyText), + authoredStyleSheetText.replace( + existingRulesAuthoredText[5], + `#test-nested-child {${newBodyText}}`, + ), + "Got the expected result for #test-nested-child" + ); + + // Covering fix for Bug 1890775 + info("Check that it can handle rules whose declaration is directly after the } of the previous rule, without spaces"); + isnot( + InspectorUtils.getRelativeRuleLine(stylesheet.cssRules[5]), + 1, + "The rule should not be on the first line of the stylesheet to check the issue it covers" + ); + newBodyText = `--modified:true`; + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[5], newBodyText), + authoredStyleSheetText.replace( + existingRulesAuthoredText[6], + `#test-after-closing-bracket{${newBodyText}}`, + ), + "Got the expected result for #test-after-closing-bracket" + ); + + info("Checking fix for files with crlf EOL sequence"); + let styleEl = document.createElement("style"); + let ruleText = `#test-after-closing-bracket-crlf{--modified-crlf:false}` + authoredStyleSheetText = `\r\nhtml{}${ruleText}`; + styleEl.append(document.createTextNode(authoredStyleSheetText)); + document.head.append(styleEl); + stylesheet = document.styleSheets[2]; + isnot( + InspectorUtils.getRelativeRuleLine(stylesheet.cssRules[1]), + 1, + "The rule should not be on the first line of the stylesheet to check the issue it covers" + ); + newBodyText = `--modified-crlf:true`; + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[1], newBodyText), + authoredStyleSheetText.replace( + ruleText, + `#test-after-closing-bracket-crlf{${newBodyText}}`, + ), + "Got the expected result for #test-after-closing-bracket-crlf" + ); + + info("Checking fix for files with cr EOL sequence"); + ruleText = `#test-after-closing-bracket-cr{--modified-cr:false}` + authoredStyleSheetText = `\rhtml{}${ruleText}`; + styleEl.innerText = ""; + styleEl.append(document.createTextNode(authoredStyleSheetText)); + isnot( + InspectorUtils.getRelativeRuleLine(stylesheet.cssRules[1]), + 1, + "The rule should not be on the first line of the stylesheet to check the issue it covers" + ); + newBodyText = `--modified-cr:true`; + is( + replaceBlockRuleBodyTextInStylesheet(stylesheet.cssRules[1], newBodyText), + authoredStyleSheetText.replace( + ruleText, + `#test-after-closing-bracket-cr{${newBodyText}}`, + ), + "Got the expected result for #test-after-closing-bracket-cr" + ); + + SimpleTest.finish(); + </script> +</head> +<body> +<h1>Test InspectorUtils::replaceBlockRuleBodyTextInStylesheet</h1> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +</pre> +</body> +</html> |