Title: [286200] trunk
Revision
286200
Author
commit-qu...@webkit.org
Date
2021-11-28 14:24:05 -0800 (Sun, 28 Nov 2021)

Log Message

Serialize computed style of background shorthand with multiple layers correctly.
https://bugs.webkit.org/show_bug.cgi?id=111121

Patch by Matt Woodrow <matt.wood...@gmail.com> on 2021-11-28
Reviewed by Cameron McCormack.

Source/WebCore:

New subtests added to getComputedStyle-background-shorthand

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::getBackgroundShorthandValue):

LayoutTests:

* fast/css/getComputedStyle/getComputedStyle-background-shorthand-expected.txt:
* fast/css/getComputedStyle/getComputedStyle-background-shorthand.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (286199 => 286200)


--- trunk/LayoutTests/ChangeLog	2021-11-28 21:28:36 UTC (rev 286199)
+++ trunk/LayoutTests/ChangeLog	2021-11-28 22:24:05 UTC (rev 286200)
@@ -1,3 +1,13 @@
+2021-11-28  Matt Woodrow  <matt.wood...@gmail.com>
+
+        Serialize computed style of background shorthand with multiple layers correctly.
+        https://bugs.webkit.org/show_bug.cgi?id=111121
+
+        Reviewed by Cameron McCormack.
+
+        * fast/css/getComputedStyle/getComputedStyle-background-shorthand-expected.txt:
+        * fast/css/getComputedStyle/getComputedStyle-background-shorthand.html:
+
 2021-11-28  Sihui Liu  <sihui_...@apple.com>
 
         Convert error to string before passing to testFailed() in FileSystemAccess layout tests

Modified: trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-background-shorthand-expected.txt (286199 => 286200)


--- trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-background-shorthand-expected.txt	2021-11-28 21:28:36 UTC (rev 286199)
+++ trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-background-shorthand-expected.txt	2021-11-28 22:24:05 UTC (rev 286200)
@@ -174,6 +174,37 @@
 PASS computedStyle.getPropertyCSSValue('background').item(1).item(1).getStringValue() is 'border-box'
 PASS computedStyle.getPropertyCSSValue('background').item(1).item(2).getStringValue() is 'padding-box'
 PASS checkComputedStyleValue() is true
+PASS computedStyle.getPropertyValue('background') is 'url("dummy://test.png") repeat scroll 0% 0% / auto padding-box border-box, rgb(255, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box'
+PASS computedStyle.getPropertyCSSValue('background').toString() is '[object CSSValueList]'
+PASS computedStyle.getPropertyCSSValue('background').cssText is 'url("dummy://test.png") repeat scroll 0% 0% / auto padding-box border-box, rgb(255, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box'
+PASS computedStyle.getPropertyCSSValue('background').length is 2
+PASS computedStyle.getPropertyCSSValue('background').item(0).length is 2
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(0).length is 4
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(1).length is 3
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(0).item(0).getStringValue() is 'dummy://test.png'
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(0).item(1).getStringValue() is 'repeat'
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(0).item(2).getStringValue() is 'scroll'
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(0).item(3).toString() is '[object CSSValueList]'
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(0).item(3).item(0).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE) is 0
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(0).item(3).item(1).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE) is 0
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(1).item(0).getStringValue() is 'auto'
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(1).item(1).getStringValue() is 'padding-box'
+PASS computedStyle.getPropertyCSSValue('background').item(0).item(1).item(2).getStringValue() is 'border-box'
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).length is 5
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(1).length is 3
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).item(0).getRGBColorValue().red.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 255
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).item(0).getRGBColorValue().green.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).item(0).getRGBColorValue().blue.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).item(1).getStringValue() is 'none'
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).item(2).getStringValue() is 'repeat'
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).item(3).getStringValue() is 'scroll'
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).item(4).toString() is '[object CSSValueList]'
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).item(4).item(0).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE) is 0
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(0).item(4).item(1).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE) is 0
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(1).item(0).getStringValue() is 'auto'
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(1).item(1).getStringValue() is 'padding-box'
+PASS computedStyle.getPropertyCSSValue('background').item(1).item(1).item(2).getStringValue() is 'border-box'
+PASS checkComputedStyleValue() is true
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-background-shorthand.html (286199 => 286200)


--- trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-background-shorthand.html	2021-11-28 21:28:36 UTC (rev 286199)
+++ trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-background-shorthand.html	2021-11-28 22:24:05 UTC (rev 286200)
@@ -214,6 +214,40 @@
 shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(2).getStringValue()", "'padding-box'");
 shouldBe("checkComputedStyleValue()", "true");
 
+
+e.style.background = "" red";
+shouldBe("computedStyle.getPropertyValue('background')", "'url(\"dummy://test.png\") repeat scroll 0% 0% / auto padding-box border-box, rgb(255, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box'");
+shouldBe("computedStyle.getPropertyCSSValue('background').toString()", "'[object CSSValueList]'");
+shouldBe("computedStyle.getPropertyCSSValue('background').cssText", "'url(\"dummy://test.png\") repeat scroll 0% 0% / auto padding-box border-box, rgb(255, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box'");
+shouldBe("computedStyle.getPropertyCSSValue('background').length", "2");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).length", "2");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(0).length", "4");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(1).length", "3");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(0).item(0).getStringValue()", "'dummy://test.png'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(0).item(1).getStringValue()", "'repeat'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(0).item(2).getStringValue()", "'scroll'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(0).item(3).toString()", "'[object CSSValueList]'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(0).item(3).item(0).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE)", "0");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(0).item(3).item(1).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE)", "0");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(1).item(0).getStringValue()", "'auto'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(1).item(1).getStringValue()", "'padding-box'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(0).item(1).item(2).getStringValue()", "'border-box'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).length", "5");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(1).length", "3");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).item(0).getRGBColorValue().red.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "255");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).item(0).getRGBColorValue().green.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "0");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).item(0).getRGBColorValue().blue.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "0");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).item(1).getStringValue()", "'none'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).item(2).getStringValue()", "'repeat'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).item(3).getStringValue()", "'scroll'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).item(4).toString()", "'[object CSSValueList]'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).item(4).item(0).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE)", "0");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(0).item(4).item(1).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE)", "0");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(1).item(0).getStringValue()", "'auto'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(1).item(1).getStringValue()", "'padding-box'");
+shouldBe("computedStyle.getPropertyCSSValue('background').item(1).item(1).item(2).getStringValue()", "'border-box'");
+shouldBe("checkComputedStyleValue()", "true");
+
 document.body.removeChild(testContainer);
 
 </script>

Modified: trunk/Source/WebCore/ChangeLog (286199 => 286200)


--- trunk/Source/WebCore/ChangeLog	2021-11-28 21:28:36 UTC (rev 286199)
+++ trunk/Source/WebCore/ChangeLog	2021-11-28 22:24:05 UTC (rev 286200)
@@ -1,3 +1,15 @@
+2021-11-28  Matt Woodrow  <matt.wood...@gmail.com>
+
+        Serialize computed style of background shorthand with multiple layers correctly.
+        https://bugs.webkit.org/show_bug.cgi?id=111121
+
+        Reviewed by Cameron McCormack.
+
+        New subtests added to getComputedStyle-background-shorthand
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::getBackgroundShorthandValue):
+
 2021-11-28  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [WebGPU] Add derived sources to Xcode project

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (286199 => 286200)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2021-11-28 21:28:36 UTC (rev 286199)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2021-11-28 22:24:05 UTC (rev 286200)
@@ -4447,15 +4447,76 @@
     return Exception { NoModificationAllowedError };
 }
 
+size_t ComputedStyleExtractor::getLayerCount(CSSPropertyID property)
+{
+    ASSERT(property == CSSPropertyBackground || property == CSSPropertyMask);
+    if (!styledElement())
+        return 0;
+
+    std::unique_ptr<RenderStyle> ownedStyle;
+    const RenderStyle* style = computeRenderStyleForProperty(*styledElement(), m_pseudoElementSpecifier, property, ownedStyle);
+    if (!style)
+        return 0;
+
+    auto& layers = property == CSSPropertyMask ? style->maskLayers() : style->backgroundLayers();
+
+    size_t layerCount = 0;
+    for (auto* currLayer = &layers; currLayer; currLayer = currLayer->next())
+        layerCount++;
+    return layerCount;
+}
+
+Ref<CSSValueList> ComputedStyleExtractor::getFillLayerPropertyShorthandValue(CSSPropertyID property, const StylePropertyShorthand& propertiesBeforeSlashSeparator, const StylePropertyShorthand& propertiesAfterSlashSeparator, CSSPropertyID lastLayerProperty)
+{
+    ASSERT(property == CSSPropertyBackground || property == CSSPropertyMask);
+    size_t layerCount = getLayerCount(property);
+    ASSERT(layerCount);
+
+    auto lastValue = lastLayerProperty != CSSPropertyInvalid ? propertyValue(lastLayerProperty, DoNotUpdateLayout) : nullptr;
+    auto before = getCSSPropertyValuesForShorthandProperties(propertiesBeforeSlashSeparator);
+    auto after = getCSSPropertyValuesForShorthandProperties(propertiesAfterSlashSeparator);
+
+    // The computed properties are returned as lists of properties, with a list of layers in each.
+    // We want to swap that around to have a list of layers, with a list of properties in each.
+
+    auto layers = CSSValueList::createCommaSeparated();
+
+    for (size_t i = 0; i < layerCount; i++) {
+        auto list = CSSValueList::createSlashSeparated();
+        auto beforeList = CSSValueList::createSpaceSeparated();
+
+        if (i == layerCount - 1 && lastValue)
+            beforeList->append(*lastValue);
+
+        for (size_t j = 0; j < propertiesBeforeSlashSeparator.length(); j++) {
+            auto& value = *before->item(j);
+            beforeList->append(layerCount == 1 ? value : *downcast<CSSValueList>(value).item(i));
+        }
+        list->append(beforeList);
+
+        auto afterList = CSSValueList::createSpaceSeparated();
+        for (size_t j = 0; j < propertiesAfterSlashSeparator.length(); j++) {
+            auto& value = *after->item(j);
+            afterList->append(layerCount == 1 ? value : *downcast<CSSValueList>(value).item(i));
+        }
+        list->append(afterList);
+
+        if (layerCount == 1)
+            return list;
+
+        layers->append(list);
+    }
+
+    return layers;
+}
+
+
 Ref<CSSValueList> ComputedStyleExtractor::getBackgroundShorthandValue()
 {
-    static const CSSPropertyID propertiesBeforeSlashSeperator[5] = { CSSPropertyBackgroundColor, CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat, CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition };
-    static const CSSPropertyID propertiesAfterSlashSeperator[3] = { CSSPropertyBackgroundSize, CSSPropertyBackgroundOrigin, CSSPropertyBackgroundClip };
+    static const CSSPropertyID propertiesBeforeSlashSeparator[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat, CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition };
+    static const CSSPropertyID propertiesAfterSlashSeparator[] = { CSSPropertyBackgroundSize, CSSPropertyBackgroundOrigin, CSSPropertyBackgroundClip };
 
-    auto list = CSSValueList::createSlashSeparated();
-    list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShorthand(CSSPropertyBackground, propertiesBeforeSlashSeperator)));
-    list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShorthand(CSSPropertyBackground, propertiesAfterSlashSeperator)));
-    return list;
+    return getFillLayerPropertyShorthandValue(CSSPropertyBackground, StylePropertyShorthand(CSSPropertyBackground, propertiesBeforeSlashSeparator), StylePropertyShorthand(CSSPropertyBackground, propertiesAfterSlashSeparator), CSSPropertyBackgroundColor);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h (286199 => 286200)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h	2021-11-28 21:28:36 UTC (rev 286199)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h	2021-11-28 22:24:05 UTC (rev 286200)
@@ -96,6 +96,9 @@
     Ref<CSSValueList> getCSSPropertyValuesForShorthandProperties(const StylePropertyShorthand&);
     RefPtr<CSSValueList> getCSSPropertyValuesFor2SidesShorthand(const StylePropertyShorthand&);
     RefPtr<CSSValueList> getCSSPropertyValuesFor4SidesShorthand(const StylePropertyShorthand&);
+
+    size_t getLayerCount(CSSPropertyID);
+    Ref<CSSValueList> getFillLayerPropertyShorthandValue(CSSPropertyID, const StylePropertyShorthand& propertiesBeforeSlashSeparator, const StylePropertyShorthand& propertiesAfterSlashSeparator, CSSPropertyID lastLayerProperty);
     Ref<CSSValueList> getBackgroundShorthandValue();
     Ref<CSSValueList> getCSSPropertyValuesForGridShorthand(const StylePropertyShorthand&);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to