Ignore:
Timestamp:
Mar 27, 2022, 9:18:05 PM (3 years ago)
Author:
Matt Woodrow
Message:

Preserve repeat() notation for grid-templates
https://bugs.webkit.org/show_bug.cgi?id=202259

Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-grid/animation/grid-template-columns-interpolation-expected.txt:
  • web-platform-tests/css/css-grid/animation/grid-template-rows-interpolation-expected.txt:
  • web-platform-tests/css/css-grid/parsing/grid-template-columns-computed-nogrid-expected.txt:
  • web-platform-tests/css/css-grid/parsing/grid-template-rows-computed-nogrid-expected.txt:

Update expectations for existing WPT tests, now that we get the correct computed value for
grid-template-rows/columns.

Source/WebCore:

  • animation/CSSPropertyAnimation.cpp:

(WebCore::blendFunc):
(WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):
(WebCore::GridTemplateTracksWrapper<ForColumns>::GridTemplateTracksWrapper): Deleted.
(WebCore::GridTemplateTracksWrapper<ForRows>::GridTemplateTracksWrapper): Deleted.

Replaces GridTemplateTracksWrapper with a simpler GridTemplatePropertyWrapper that just compares the
track lists. In the future we can iterate the two tracks lists in parallel and interpolate per-item,
in order to get animation correct per-spec.

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::populateGridTrackList):
(WebCore::populateSubgridLineNameList):
(WebCore::valueForGridTrackList):
(WebCore::OrderedNamedLinesCollectorInsideRepeat::OrderedNamedLinesCollectorInsideRepeat): Deleted.
(WebCore::OrderedNamedLinesCollector::collectLineNamesForIndex const): Deleted.
(WebCore::OrderedNamedLinesCollectorInsideRepeat::collectLineNamesForIndex const): Deleted.

Implements getComputedStyle by iterating the track list and doing a 1:1 conversion to CSSValues, instead
of reconstructing from the processed hashtables.
This correctly preserves repeat() instances in the track list, which weren't retreivable from the processed
data.

  • rendering/style/RenderStyle.h:

(WebCore::RenderStyle::gridColumns const):
(WebCore::RenderStyle::gridRows const):
(WebCore::RenderStyle::gridColumnList const):
(WebCore::RenderStyle::gridRowList const):
(WebCore::RenderStyle::gridAutoRepeatColumns const):
(WebCore::RenderStyle::gridAutoRepeatRows const):
(WebCore::RenderStyle::gridAutoRepeatColumnsInsertionPoint const):
(WebCore::RenderStyle::gridAutoRepeatRowsInsertionPoint const):
(WebCore::RenderStyle::gridAutoRepeatColumnsType const):
(WebCore::RenderStyle::gridAutoRepeatRowsType const):
(WebCore::RenderStyle::namedGridColumnLines const):
(WebCore::RenderStyle::namedGridRowLines const):
(WebCore::RenderStyle::orderedNamedGridColumnLines const):
(WebCore::RenderStyle::orderedNamedGridRowLines const):
(WebCore::RenderStyle::autoRepeatNamedGridColumnLines const):
(WebCore::RenderStyle::autoRepeatNamedGridRowLines const):
(WebCore::RenderStyle::autoRepeatOrderedNamedGridColumnLines const):
(WebCore::RenderStyle::autoRepeatOrderedNamedGridRowLines const):
(WebCore::RenderStyle::gridSubgridRows const):
(WebCore::RenderStyle::gridSubgridColumns const):
(WebCore::RenderStyle::setGridColumnList):
(WebCore::RenderStyle::setGridRowList):
(WebCore::RenderStyle::setGridAutoRows):
(WebCore::RenderStyle::setGridAutoFlow):
(WebCore::RenderStyle::setGridColumns): Deleted.
(WebCore::RenderStyle::setGridRows): Deleted.
(WebCore::RenderStyle::setGridAutoRepeatColumns): Deleted.
(WebCore::RenderStyle::setGridAutoRepeatRows): Deleted.
(WebCore::RenderStyle::setGridAutoRepeatColumnsInsertionPoint): Deleted.
(WebCore::RenderStyle::setGridAutoRepeatRowsInsertionPoint): Deleted.
(WebCore::RenderStyle::setGridAutoRepeatColumnsType): Deleted.
(WebCore::RenderStyle::setGridAutoRepeatRowsType): Deleted.
(WebCore::RenderStyle::setNamedGridColumnLines): Deleted.
(WebCore::RenderStyle::setNamedGridRowLines): Deleted.
(WebCore::RenderStyle::setOrderedNamedGridColumnLines): Deleted.
(WebCore::RenderStyle::setOrderedNamedGridRowLines): Deleted.
(WebCore::RenderStyle::setAutoRepeatNamedGridColumnLines): Deleted.
(WebCore::RenderStyle::setAutoRepeatNamedGridRowLines): Deleted.
(WebCore::RenderStyle::setAutoRepeatOrderedNamedGridColumnLines): Deleted.
(WebCore::RenderStyle::setAutoRepeatOrderedNamedGridRowLines): Deleted.
(WebCore::RenderStyle::setGridSubgridRows): Deleted.
(WebCore::RenderStyle::setGridSubgridColumns): Deleted.

  • rendering/style/StyleGridData.cpp:

(WebCore::StyleGridData::StyleGridData):
(WebCore::StyleGridData::setRows):
(WebCore::StyleGridData::setColumns):
(WebCore::createGridLineNamesList):
(WebCore::StyleGridData::computeCachedTrackData):
(WebCore::operator<<):

  • rendering/style/StyleGridData.h:

(WebCore::StyleGridData::operator== const):
(WebCore::StyleGridData::gridColumns const):
(WebCore::StyleGridData::gridRows const):
(WebCore::StyleGridData::namedGridColumnLines const):
(WebCore::StyleGridData::namedGridRowLines const):
(WebCore::StyleGridData::orderedNamedGridColumnLines const):
(WebCore::StyleGridData::orderedNamedGridRowLines const):
(WebCore::StyleGridData::autoRepeatNamedGridColumnLines const):
(WebCore::StyleGridData::autoRepeatNamedGridRowLines const):
(WebCore::StyleGridData::autoRepeatOrderedNamedGridColumnLines const):
(WebCore::StyleGridData::autoRepeatOrderedNamedGridRowLines const):
(WebCore::StyleGridData::gridAutoRepeatColumns const):
(WebCore::StyleGridData::gridAutoRepeatRows const):
(WebCore::StyleGridData::autoRepeatColumnsInsertionPoint const):
(WebCore::StyleGridData::autoRepeatRowsInsertionPoint const):
(WebCore::StyleGridData::autoRepeatColumnsType const):
(WebCore::StyleGridData::autoRepeatRowsType const):
(WebCore::StyleGridData::subgridRows const):
(WebCore::StyleGridData::subgridColumns const):
(WebCore::StyleGridData::columns const):
(WebCore::StyleGridData::rows const):

Stores the computed track lists directly on RenderGrid, while retaining storage of the processed data.
computeCachedTrackData should be logically identical to the old BuilderConverter::createGridTrackList, but
happens when we modify the StyleGridData so that we can run it during animations.

  • style/StyleBuilderConverter.h:

(WebCore::Style::BuilderConverter::createGridTrackList):
(WebCore::Style::createGridLineNamesList): Deleted.
(): Deleted.

  • style/StyleBuilderCustom.h:

(WebCore::Style::BuilderCustom::applyInitialGridTemplateColumns):
(WebCore::Style::BuilderCustom::applyValueGridTemplateColumns):
(WebCore::Style::BuilderCustom::applyInitialGridTemplateRows):
(WebCore::Style::BuilderCustom::applyValueGridTemplateRows):

Rather than converting the track list into processed hashtables, just copies the data in the track list
format so that the StyleGridData can access the original data.

LayoutTests:

  • fast/css-grid-layout/grid-repeat-calc-expected.txt:
  • fast/css-grid-layout/grid-repeat-calc.html:
  • fast/css-grid-layout/non-grid-element-repeat-get-set-expected.txt:
  • fast/css-grid-layout/non-grid-element-repeat-get-set.html:

Update expected results to use repeat() notation.

File:
1 edited

Legend:

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

    r291690 r291956  
    3636#include "CSSFunctionValue.h"
    3737#include "CSSGridAutoRepeatValue.h"
     38#include "CSSGridIntegerRepeatValue.h"
    3839#include "CSSLineBoxContainValue.h"
    3940#include "CSSPrimitiveValue.h"
     
    856857
    857858    bool isEmpty() const { return m_orderedNamedGridLines.isEmpty() && m_orderedNamedAutoRepeatGridLines.isEmpty(); }
    858     virtual void collectLineNamesForIndex(CSSGridLineNamesValue&, unsigned index) const;
     859    virtual void collectLineNamesForIndex(CSSGridLineNamesValue&, unsigned index) const = 0;
    859860
    860861    virtual int namedGridLineCount() const { return m_orderedNamedGridLines.size(); }
     
    867868    const OrderedNamedGridLinesMap& m_orderedNamedGridLines;
    868869    const OrderedNamedGridLinesMap& m_orderedNamedAutoRepeatGridLines;
    869 };
    870 
    871 class OrderedNamedLinesCollectorInsideRepeat : public OrderedNamedLinesCollector {
    872 public:
    873     OrderedNamedLinesCollectorInsideRepeat(const RenderStyle& style, bool isRowAxis)
    874         : OrderedNamedLinesCollector(style, isRowAxis)
    875     {
    876     }
    877 
    878     void collectLineNamesForIndex(CSSGridLineNamesValue&, unsigned index) const override;
    879 
    880     int namedGridLineCount() const override { return m_orderedNamedAutoRepeatGridLines.size(); }
    881870};
    882871
     
    942931}
    943932
    944 void OrderedNamedLinesCollector::collectLineNamesForIndex(CSSGridLineNamesValue& lineNamesValue, unsigned i) const
    945 {
    946     ASSERT(!isEmpty());
    947     appendLines(lineNamesValue, i, NamedLines);
    948 }
    949 
    950 void OrderedNamedLinesCollectorInsideRepeat::collectLineNamesForIndex(CSSGridLineNamesValue& lineNamesValue, unsigned i) const
    951 {
    952     ASSERT(!isEmpty());
    953     appendLines(lineNamesValue, i, AutoRepeatNamedLines);
    954 }
    955 
    956933void OrderedNamedLinesCollectorInGridLayout::collectLineNamesForIndex(CSSGridLineNamesValue& lineNamesValue, unsigned i) const
    957934{
     
    10251002
    10261003template <typename T, typename F>
    1027 void populateGridTrackList(CSSValueList& list, OrderedNamedLinesCollector& collector, const Vector<T>& tracks, F getTrackSize, int start, int end, int offset = 0)
    1028 {
    1029     ASSERT(0 <= start);
     1004void populateGridTrackList(CSSValueList& list, OrderedNamedLinesCollector& collector, const Vector<T>& tracks, F getTrackSize, int offset = 0)
     1005{
     1006    int start = 0;
     1007    int end = tracks.size();
    10301008    ASSERT(start <= end);
    10311009    ASSERT(static_cast<unsigned>(end) <= tracks.size());
     
    10391017}
    10401018
    1041 template <typename T, typename F>
    1042 void populateGridTrackList(CSSValueList& list, OrderedNamedLinesCollector& collector, const Vector<T>& tracks, F getTrackSize, int offset = 0)
    1043 {
    1044     populateGridTrackList<T>(list, collector, tracks, getTrackSize, 0, tracks.size(), offset);
    1045 }
    1046 
    1047 static void populateSubgridLineNameList(CSSValueList& list, OrderedNamedLinesCollector& collector, int start, int end)
    1048 {
    1049     for (int i = start; i < end; i++)
     1019static void populateSubgridLineNameList(CSSValueList& list, OrderedNamedLinesCollector& collector)
     1020{
     1021    for (int i = 0; i < collector.namedGridLineCount(); i++)
    10501022        addValuesForNamedGridLinesAtIndex(collector, i, list, true);
    1051 }
    1052 
    1053 static void populateSubgridLineNameList(CSSValueList& list, OrderedNamedLinesCollector& collector)
    1054 {
    1055     populateSubgridLineNameList(list, collector, 0, collector.namedGridLineCount());
    10561023}
    10571024
     
    10781045
    10791046    auto list = CSSValueList::createSpaceSeparated();
    1080     if (isSubgrid)
    1081         list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueSubgrid));
    10821047
    10831048    // If the element is a grid container, the resolved value is the used value,
     
    10881053        auto* grid = downcast<RenderGrid>(renderer);
    10891054        if (isSubgrid) {
     1055            list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueSubgrid));
     1056
    10901057            OrderedNamedLinesCollectorInSubgridLayout collector(style, isRowAxis, grid->numTracks(direction));
    10911058            populateSubgridLineNameList(list.get(), collector);
     
    11031070
    11041071    // Otherwise, the resolved value is the computed value, preserving repeat().
    1105     OrderedNamedLinesCollector collector(style, isRowAxis);
    1106     auto getTrackSize = [&](const GridTrackSize& v) {
    1107         return specifiedValueForGridTrackSize(v, style);
     1072    const GridTrackList& computedTracks = isRowAxis ? style.gridColumnList() : style.gridRowList();
     1073
     1074    auto repeatVisitor = [&](CSSValueList& dest, const RepeatEntry& entry) {
     1075        if (std::holds_alternative<Vector<String>>(entry)) {
     1076            auto lineNamesValue = CSSGridLineNamesValue::create();
     1077            for (const auto& name : std::get<Vector<String>>(entry))
     1078                lineNamesValue->append(CSSValuePool::singleton().createCustomIdent(name));
     1079            dest.append(lineNamesValue);
     1080        } else {
     1081            dest.append(specifiedValueForGridTrackSize(std::get<GridTrackSize>(entry), style));
     1082        }
    11081083    };
    11091084
    1110     OrderedNamedLinesCollectorInsideRepeat repeatCollector(style, isRowAxis);
    1111     if (isSubgrid) {
    1112         if (!repeatCollector.namedGridLineCount()) {
    1113             populateSubgridLineNameList(list.get(), collector);
    1114             return list;
    1115         }
    1116 
    1117         // Add the line names that precede the auto repeat().
    1118         int autoRepeatInsertionPoint = isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint() : style.gridAutoRepeatRowsInsertionPoint();
    1119         autoRepeatInsertionPoint = std::clamp<int>(autoRepeatInsertionPoint, 0, collector.namedGridLineCount());
    1120         populateSubgridLineNameList(list.get(), collector, 0, autoRepeatInsertionPoint);
    1121 
    1122         // Add a CSSGridAutoRepeatValue with the contents of the auto repeat().
    1123         ASSERT((isRowAxis ? style.gridAutoRepeatColumnsType() : style.gridAutoRepeatRowsType()) == AutoRepeatType::Fill);
    1124         auto repeatedValues = CSSGridAutoRepeatValue::create(CSSValueAutoFill);
    1125         populateSubgridLineNameList(repeatedValues.get(), repeatCollector);
    1126         list->append(repeatedValues.get());
    1127 
    1128         // Add the line names that follow the auto repeat().
    1129         populateSubgridLineNameList(list.get(), collector, autoRepeatInsertionPoint, collector.namedGridLineCount());
    1130         return list;
    1131     }
    1132 
    1133     if (autoRepeatTrackSizes.isEmpty()) {
    1134         // If there's no auto repeat(), just add all the line names and track sizes.
    1135         populateGridTrackList(list.get(), collector, trackSizes, getTrackSize);
    1136         return list;
    1137     }
    1138 
    1139     // Add the line names and track sizes that precede the auto repeat().
    1140     int autoRepeatInsertionPoint = isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint() : style.gridAutoRepeatRowsInsertionPoint();
    1141     autoRepeatInsertionPoint = std::clamp<int>(autoRepeatInsertionPoint, 0, trackSizes.size());
    1142     populateGridTrackList(list.get(), collector, trackSizes, getTrackSize, 0, autoRepeatInsertionPoint);
    1143 
    1144     // Add a CSSGridAutoRepeatValue with the contents of the auto repeat().
    1145     AutoRepeatType autoRepeatType = isRowAxis ? style.gridAutoRepeatColumnsType() : style.gridAutoRepeatRowsType();
    1146     auto repeatedValues = CSSGridAutoRepeatValue::create(autoRepeatType == AutoRepeatType::Fill ? CSSValueAutoFill : CSSValueAutoFit);
    1147 
    1148     populateGridTrackList(repeatedValues.get(), repeatCollector, autoRepeatTrackSizes, getTrackSize);
    1149     list->append(repeatedValues.get());
    1150 
    1151     // Add the line names and track sizes that follow the auto repeat().
    1152     populateGridTrackList(list.get(), collector, trackSizes, getTrackSize, autoRepeatInsertionPoint, trackSizes.size(), 1);
     1085    auto trackEntryVisitor = WTF::makeVisitor([&](const GridTrackSize& size) {
     1086        list->append(specifiedValueForGridTrackSize(size, style));
     1087    }, [&](const Vector<String>& names) {
     1088        auto lineNamesValue = CSSGridLineNamesValue::create();
     1089        for (const auto& name : names)
     1090            lineNamesValue->append(CSSValuePool::singleton().createCustomIdent(name));
     1091        list->append(lineNamesValue);
     1092    }, [&](const GridTrackEntryRepeat& repeat) {
     1093        auto repeatedValues = CSSGridIntegerRepeatValue::create(repeat.repeats);
     1094        for (const auto& entry : repeat.list)
     1095            repeatVisitor(repeatedValues, entry);
     1096        list->append(repeatedValues);
     1097    }, [&](const GridTrackEntryAutoRepeat& repeat) {
     1098        auto repeatedValues = CSSGridAutoRepeatValue::create(repeat.type == AutoRepeatType::Fill ? CSSValueAutoFill : CSSValueAutoFit);
     1099        for (const auto& entry : repeat.list)
     1100            repeatVisitor(repeatedValues, entry);
     1101        list->append(repeatedValues);
     1102    }, [&](const GridTrackEntrySubgrid&) {
     1103        list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueSubgrid));
     1104    });
     1105
     1106    for (const auto& entry : computedTracks)
     1107        std::visit(trackEntryVisitor, entry);
     1108
    11531109    return list;
    11541110}
Note: See TracChangeset for help on using the changeset viewer.