diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /layout/inspector | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/inspector')
-rw-r--r-- | layout/inspector/InspectorUtils.cpp | 93 | ||||
-rw-r--r-- | layout/inspector/InspectorUtils.h | 16 | ||||
-rw-r--r-- | layout/inspector/tests/mochitest.toml | 3 | ||||
-rw-r--r-- | layout/inspector/tests/test_bug877690.html | 2 | ||||
-rw-r--r-- | layout/inspector/tests/test_color_to.html | 116 |
5 files changed, 216 insertions, 14 deletions
diff --git a/layout/inspector/InspectorUtils.cpp b/layout/inspector/InspectorUtils.cpp index e2111aa9bd..f1886a0dd0 100644 --- a/layout/inspector/InspectorUtils.cpp +++ b/layout/inspector/InspectorUtils.cpp @@ -351,9 +351,7 @@ uint32_t InspectorUtils::GetRelativeRuleLine(GlobalObject& aGlobal, return aRule.GetLineNumber() + 1; } - -void InspectorUtils::GetRuleIndex(GlobalObject& aGlobal, - css::Rule& aRule, +void InspectorUtils::GetRuleIndex(GlobalObject& aGlobal, css::Rule& aRule, nsTArray<uint32_t>& aResult) { css::Rule* currentRule = &aRule; @@ -401,21 +399,56 @@ bool InspectorUtils::HasRulesModifiedByCSSOM(GlobalObject& aGlobal, return aSheet.HasModifiedRulesForDevtools(); } -static void CollectRules(ServoCSSRuleList& aRuleList, - nsTArray<RefPtr<css::Rule>>& aResult) { - for (uint32_t i = 0, len = aRuleList.Length(); i < len; ++i) { +static uint32_t CollectAtRules(ServoCSSRuleList& aRuleList, + Sequence<OwningNonNull<css::Rule>>& aResult) { + uint32_t len = aRuleList.Length(); + uint32_t ruleCount = len; + for (uint32_t i = 0; i < len; ++i) { css::Rule* rule = aRuleList.GetRule(i); - aResult.AppendElement(rule); + // This collect rules we want to display in Devtools Style Editor toolbar. + // When adding a new StyleCssRuleType, put it in the "default" list, and + // file a new bug with + // https://bugzilla.mozilla.org/enter_bug.cgi?product=DevTools&component=Style%20Editor&short_desc=Consider%20displaying%20new%20XXX%20rule%20type%20in%20at-rules%20sidebar + // so the DevTools team gets notified and can decide if it should be + // displayed. + switch (rule->Type()) { + case StyleCssRuleType::Media: + case StyleCssRuleType::Supports: + case StyleCssRuleType::LayerBlock: + case StyleCssRuleType::Container: { + Unused << aResult.AppendElement(OwningNonNull(*rule), fallible); + break; + } + case StyleCssRuleType::Style: + case StyleCssRuleType::Import: + case StyleCssRuleType::Document: + case StyleCssRuleType::LayerStatement: + case StyleCssRuleType::FontFace: + case StyleCssRuleType::Page: + case StyleCssRuleType::Property: + case StyleCssRuleType::Keyframes: + case StyleCssRuleType::Keyframe: + case StyleCssRuleType::Margin: + case StyleCssRuleType::Namespace: + case StyleCssRuleType::CounterStyle: + case StyleCssRuleType::FontFeatureValues: + case StyleCssRuleType::FontPaletteValues: + break; + } + if (rule->IsGroupRule()) { - CollectRules(*static_cast<css::GroupRule*>(rule)->CssRules(), aResult); + ruleCount += CollectAtRules( + *static_cast<css::GroupRule*>(rule)->CssRules(), aResult); } } + return ruleCount; } -void InspectorUtils::GetAllStyleSheetCSSStyleRules( +void InspectorUtils::GetStyleSheetRuleCountAndAtRules( GlobalObject& aGlobal, StyleSheet& aSheet, - nsTArray<RefPtr<css::Rule>>& aResult) { - CollectRules(*aSheet.GetCssRulesInternal(), aResult); + InspectorStyleSheetRuleCountAndAtRulesResult& aResult) { + aResult.mRuleCount = + CollectAtRules(*aSheet.GetCssRulesInternal(), aResult.mAtRules); } /* static */ @@ -602,6 +635,26 @@ void InspectorUtils::ColorToRGBA(GlobalObject&, const nsACString& aColorString, } /* static */ +void InspectorUtils::ColorTo(GlobalObject&, const nsACString& aFromColor, + const nsACString& aToColorSpace, + Nullable<InspectorColorToResult>& aResult) { + nsCString resultColor; + nsTArray<float> resultComponents; + bool resultAdjusted = false; + + if (!ServoCSSParser::ColorTo(aFromColor, aToColorSpace, &resultColor, + &resultComponents, &resultAdjusted)) { + aResult.SetNull(); + return; + } + + auto& result = aResult.SetValue(); + result.mColor.AssignASCII(resultColor); + result.mComponents = std::move(resultComponents); + result.mAdjusted = resultAdjusted; +} + +/* static */ bool InspectorUtils::IsValidCSSColor(GlobalObject& aGlobalObject, const nsACString& aColorString) { return ServoCSSParser::IsValidCSSColor(aColorString); @@ -946,5 +999,23 @@ 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; +} + } // namespace dom } // namespace mozilla diff --git a/layout/inspector/InspectorUtils.h b/layout/inspector/InspectorUtils.h index 06bc0ff5fc..f375e51472 100644 --- a/layout/inspector/InspectorUtils.h +++ b/layout/inspector/InspectorUtils.h @@ -78,9 +78,9 @@ class InspectorUtils { static bool HasRulesModifiedByCSSOM(GlobalObject& aGlobal, StyleSheet& aSheet); - static void GetAllStyleSheetCSSStyleRules( + static void GetStyleSheetRuleCountAndAtRules( GlobalObject& aGlobal, StyleSheet& aSheet, - nsTArray<RefPtr<css::Rule>>& aResult); + InspectorStyleSheetRuleCountAndAtRulesResult& aResult); // Utilities for working with CSS properties // @@ -118,6 +118,11 @@ class InspectorUtils { const Document*, Nullable<InspectorRGBATuple>& aResult); + // Convert a given CSS color string to another color space. + static void ColorTo(GlobalObject&, const nsACString& aFromColor, + const nsACString& aToColorSpace, + Nullable<InspectorColorToResult>& aResult); + // Check whether a given color is a valid CSS color. static bool IsValidCSSColor(GlobalObject& aGlobal, const nsACString& aColorString); @@ -263,6 +268,13 @@ class InspectorUtils { static void GetCSSRegisteredProperties( GlobalObject& aGlobal, Document& aDocument, nsTArray<InspectorCSSPropertyDefinition>& aResult); + + /** + * Get the rule body text start and end offsets within aInitialText + */ + static void GetRuleBodyTextOffsets( + GlobalObject&, const nsACString& aInitialText, + Nullable<InspectorGetRuleBodyTextResult>& aResult); }; } // namespace mozilla::dom diff --git a/layout/inspector/tests/mochitest.toml b/layout/inspector/tests/mochitest.toml index 3db9693c20..e51941752b 100644 --- a/layout/inspector/tests/mochitest.toml +++ b/layout/inspector/tests/mochitest.toml @@ -3,6 +3,7 @@ prefs = [ "layout.css.basic-shape-rect.enabled=true", "layout.css.basic-shape-xywh.enabled=true", "layout.css.properties-and-values.enabled=true", + "layout.css.transition-behavior.enabled=true", "dom.customHighlightAPI.enabled=true", ] support-files = [ @@ -32,6 +33,8 @@ support-files = [ ["test_bug1006595.html"] +["test_color_to.html"] + ["test_color_to_rgba.html"] ["test_containing_block_of.html"] diff --git a/layout/inspector/tests/test_bug877690.html b/layout/inspector/tests/test_bug877690.html index 0c01428176..9e5efca0d3 100644 --- a/layout/inspector/tests/test_bug877690.html +++ b/layout/inspector/tests/test_bug877690.html @@ -145,7 +145,7 @@ function do_test() { var values = InspectorUtils.getCSSValuesForProperty(prop); var expected = [ "initial", "all", "unset", "cubic-bezier", "ease", "ease-in", "ease-in-out", "ease-out", "inherit", "revert", "revert-layer", "linear", "none", "step-end", "step-start", - "steps" ]; + "steps", "normal", "allow-discrete" ]; ok(testValues(values, expected), "property transition's values."); // test invalid property diff --git a/layout/inspector/tests/test_color_to.html b/layout/inspector/tests/test_color_to.html new file mode 100644 index 0000000000..b2c14e68c1 --- /dev/null +++ b/layout/inspector/tests/test_color_to.html @@ -0,0 +1,116 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Test InspectorUtils::ColorTo</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> + <script> + const InspectorUtils = SpecialPowers.InspectorUtils; + + const kEpsilon = 0.001; + + const chocolate = "color(srgb 0.8235294117647058 0.4117647058823529 0.11764705882352941)"; + const chocolateAlpha = "color(srgb 0.8235294117647058 0.4117647058823529 0.11764705882352941 / 0.4)"; + const noneColor = "color(srgb none none none / none)"; + + testColor(chocolate, "srgb", "rgb(82.35% 41.18% 11.76%)", [0.8235, 0.4118, 0.1176, 1], false); + testColor(chocolateAlpha, "srgb", "rgb(82.35% 41.18% 11.76% / 0.4)", [0.8235, 0.4118, 0.1176, 0.4], false); + testColor(noneColor, "srgb", "rgb(none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "hsl", "hsl(25deg 75% 47.06%)", [25, 75, 47.0588, 1], false); + testColor(chocolateAlpha, "hsl", "hsl(25deg 75% 47.06% / 0.4)", [25, 75, 47.0588, 0.4], false); + testColor(noneColor, "hsl", "hsl(none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "hwb", "hwb(25deg 11.76% 17.65%)", [25, 11.7647, 17.6471, 1], false); + testColor(chocolateAlpha, "hwb", "hwb(25deg 11.76% 17.65% / 0.4)", [25, 11.7647, 17.6471, 0.4], false); + testColor(noneColor, "hwb", "hwb(none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "lab", "lab(56.63% 39.24 57.55)", [56.6293, 39.2371, 57.5538, 1], false); + testColor(chocolateAlpha, "lab", "lab(56.63% 39.24 57.55 / 0.4)", [56.6293, 39.2371, 57.5538, 0.4], false); + testColor(noneColor, "lab", "lab(none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "lch", "lch(56.63 69.66 55.72deg)", [56.6293, 69.6562, 55.7159, 1], false); + testColor(chocolateAlpha, "lch", "lch(56.63 69.66 55.72deg / 0.4)", [56.6293, 69.6562, 55.7159, 0.4], false); + testColor(noneColor, "lch", "lch(none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "oklab", "oklab(63.44% 0.1 0.12)", [0.6344, 0.0991, 0.1192, 1], false); + testColor(chocolateAlpha, "oklab", "oklab(63.44% 0.1 0.12 / 0.4)", [0.6344, 0.0991, 0.1192, 0.4], false); + testColor(noneColor, "oklab", "oklab(none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "oklch", "oklch(0.63 0.15 50.27deg)", [0.6344, 0.1550, 50.2665, 1], false); + testColor(chocolateAlpha, "oklch", "oklch(0.63 0.15 50.27deg / 0.4)", [0.6344, 0.1550, 50.2665, 0.4], false); + testColor(noneColor, "oklch", "oklch(none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "srgb-linear", "color(srgb-linear 0.64 0.14 0.01)", [0.6445, 0.1413, 0.0130, 1], false); + testColor(chocolateAlpha, "srgb-linear", "color(srgb-linear 0.64 0.14 0.01 / 0.4)", [0.6445, 0.1413, 0.0130, 0.4], false); + testColor(noneColor, "srgb-linear", "color(srgb-linear none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "display-p3", "color(display-p3 0.77 0.43 0.2)", [0.7706, 0.434, 0.1998, 1], false); + testColor(chocolateAlpha, "display-p3", "color(display-p3 0.77 0.43 0.2 / 0.4)", [0.7706, 0.434, 0.1998, 0.4], false); + testColor(noneColor, "display-p3", "color(display-p3 none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "a98-rgb", "color(a98-rgb 0.73 0.41 0.16)", [0.7304, 0.4107, 0.162, 1], false); + testColor(chocolateAlpha, "a98-rgb", "color(a98-rgb 0.73 0.41 0.16 / 0.4)", [0.7304, 0.4107, 0.162, 0.4], false); + testColor(noneColor, "a98-rgb", "color(a98-rgb none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "prophoto-rgb", "color(prophoto-rgb 0.59 0.39 0.16)", [0.5923, 0.3941, 0.1643, 1], false); + testColor(chocolateAlpha, "prophoto-rgb", "color(prophoto-rgb 0.59 0.39 0.16 / 0.4)", [0.5923, 0.3941, 0.1643, 0.4], false); + testColor(noneColor, "prophoto-rgb", "color(prophoto-rgb none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "rec2020", "color(rec2020 0.67 0.4 0.14)", [0.6693, 0.4019, 0.1427, 1], false); + testColor(chocolateAlpha, "rec2020", "color(rec2020 0.67 0.4 0.14 / 0.4)", [0.6693, 0.4019, 0.1427, 0.4], false); + testColor(noneColor, "rec2020", "color(rec2020 none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "xyz-d50", "color(xyz-d50 0.34 0.25 0.03)", [0.3373, 0.2454, 0.032, 1], false); + testColor(chocolateAlpha, "xyz-d50", "color(xyz-d50 0.34 0.25 0.03 / 0.4)", [0.3373, 0.2454, 0.032, 0.4], false); + testColor(noneColor, "xyz-d50", "color(xyz-d50 none none none / none)", [0, 0, 0, 0], false); + + testColor(chocolate, "xyz-d65", "color(xyz-d65 0.32 0.24 0.04)", [0.3186, 0.239, 0.0416, 1], false); + testColor(chocolateAlpha, "xyz-d65", "color(xyz-d65 0.32 0.24 0.04 / 0.4)", [0.3186, 0.239, 0.0416, 0.4], false); + testColor(noneColor, "xyz-d65", "color(xyz-d65 none none none / none)", [0, 0, 0, 0], false); + + testColor("color(srgb calc(NaN) calc(NaN) calc(NaN) / calc(NaN))", "srgb", "rgb(0% 0% 0% / 0)", [NaN, NaN, NaN, 0], false); + + // Invalid color. + testColor("darkblueorange", "srgb", null, null, null); + testColor("rgb(none, none, none)", "lab", null, null, null); + testColor(null, "lab", null, null, null); + + // Invalid color spaces. + testColor(chocolate, "something", null, null, null); + testColor(chocolate, "", null, null, null); + testColor(chocolate, null, null, null, null); + + function testColor(color, colorSpace, expected, expectedComponents, expectedAdjust) { + let actual = InspectorUtils.colorTo(color, colorSpace); + + // If we only get 3 elements for the expected components, we just add the + // default alpha. + if (expectedComponents && expectedComponents.length === 3) { + expectedComponents.push(1); + } + + if (actual === null) { + is(expected, null, "color: converting \"" + color + "\" to \"" + colorSpace + "\" returns null"); + return; + } + + is(actual.color, expected, "color is correctly converted to \"" + colorSpace + "\""); + for (let i = 0; i < 4; i++) { + if (isNaN(expectedComponents[i])) { + is(isNaN(actual.components[i]), true, "component " + i + " is NaN when converting to \"" + colorSpace + "\""); + } else { + isfuzzy(actual.components[i], expectedComponents[i], kEpsilon, "component " + i + " when converting to \"" + colorSpace + "\""); + } + } + is(actual.adjusted, expectedAdjust, "color adjusted status currect"); + } + </script> +</head> +<body> +<p id="display"></p> +<div id="content" style="display: none"></div> +<pre id="test"></pre> +</body> +</html> |