Ignore:
Timestamp:
Nov 28, 2021, 2:24:05 PM (3 years ago)
Author:
[email protected]
Message:

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

Patch by Matt Woodrow <[email protected]> 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:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r286086 r286200  
    44484448}
    44494449
     4450size_t ComputedStyleExtractor::getLayerCount(CSSPropertyID property)
     4451{
     4452    ASSERT(property == CSSPropertyBackground || property == CSSPropertyMask);
     4453    if (!styledElement())
     4454        return 0;
     4455
     4456    std::unique_ptr<RenderStyle> ownedStyle;
     4457    const RenderStyle* style = computeRenderStyleForProperty(*styledElement(), m_pseudoElementSpecifier, property, ownedStyle);
     4458    if (!style)
     4459        return 0;
     4460
     4461    auto& layers = property == CSSPropertyMask ? style->maskLayers() : style->backgroundLayers();
     4462
     4463    size_t layerCount = 0;
     4464    for (auto* currLayer = &layers; currLayer; currLayer = currLayer->next())
     4465        layerCount++;
     4466    return layerCount;
     4467}
     4468
     4469Ref<CSSValueList> ComputedStyleExtractor::getFillLayerPropertyShorthandValue(CSSPropertyID property, const StylePropertyShorthand& propertiesBeforeSlashSeparator, const StylePropertyShorthand& propertiesAfterSlashSeparator, CSSPropertyID lastLayerProperty)
     4470{
     4471    ASSERT(property == CSSPropertyBackground || property == CSSPropertyMask);
     4472    size_t layerCount = getLayerCount(property);
     4473    ASSERT(layerCount);
     4474
     4475    auto lastValue = lastLayerProperty != CSSPropertyInvalid ? propertyValue(lastLayerProperty, DoNotUpdateLayout) : nullptr;
     4476    auto before = getCSSPropertyValuesForShorthandProperties(propertiesBeforeSlashSeparator);
     4477    auto after = getCSSPropertyValuesForShorthandProperties(propertiesAfterSlashSeparator);
     4478
     4479    // The computed properties are returned as lists of properties, with a list of layers in each.
     4480    // We want to swap that around to have a list of layers, with a list of properties in each.
     4481
     4482    auto layers = CSSValueList::createCommaSeparated();
     4483
     4484    for (size_t i = 0; i < layerCount; i++) {
     4485        auto list = CSSValueList::createSlashSeparated();
     4486        auto beforeList = CSSValueList::createSpaceSeparated();
     4487
     4488        if (i == layerCount - 1 && lastValue)
     4489            beforeList->append(*lastValue);
     4490
     4491        for (size_t j = 0; j < propertiesBeforeSlashSeparator.length(); j++) {
     4492            auto& value = *before->item(j);
     4493            beforeList->append(layerCount == 1 ? value : *downcast<CSSValueList>(value).item(i));
     4494        }
     4495        list->append(beforeList);
     4496
     4497        auto afterList = CSSValueList::createSpaceSeparated();
     4498        for (size_t j = 0; j < propertiesAfterSlashSeparator.length(); j++) {
     4499            auto& value = *after->item(j);
     4500            afterList->append(layerCount == 1 ? value : *downcast<CSSValueList>(value).item(i));
     4501        }
     4502        list->append(afterList);
     4503
     4504        if (layerCount == 1)
     4505            return list;
     4506
     4507        layers->append(list);
     4508    }
     4509
     4510    return layers;
     4511}
     4512
     4513
    44504514Ref<CSSValueList> ComputedStyleExtractor::getBackgroundShorthandValue()
    44514515{
    4452     static const CSSPropertyID propertiesBeforeSlashSeperator[5] = { CSSPropertyBackgroundColor, CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat, CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition };
    4453     static const CSSPropertyID propertiesAfterSlashSeperator[3] = { CSSPropertyBackgroundSize, CSSPropertyBackgroundOrigin, CSSPropertyBackgroundClip };
    4454 
    4455     auto list = CSSValueList::createSlashSeparated();
    4456     list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShorthand(CSSPropertyBackground, propertiesBeforeSlashSeperator)));
    4457     list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShorthand(CSSPropertyBackground, propertiesAfterSlashSeperator)));
    4458     return list;
     4516    static const CSSPropertyID propertiesBeforeSlashSeparator[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat, CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition };
     4517    static const CSSPropertyID propertiesAfterSlashSeparator[] = { CSSPropertyBackgroundSize, CSSPropertyBackgroundOrigin, CSSPropertyBackgroundClip };
     4518
     4519    return getFillLayerPropertyShorthandValue(CSSPropertyBackground, StylePropertyShorthand(CSSPropertyBackground, propertiesBeforeSlashSeparator), StylePropertyShorthand(CSSPropertyBackground, propertiesAfterSlashSeparator), CSSPropertyBackgroundColor);
    44594520}
    44604521
Note: See TracChangeset for help on using the changeset viewer.