Ignore:
Timestamp:
Feb 13, 2022, 5:52:40 PM (3 years ago)
Author:
[email protected]
Message:

Add support for parsing 'subgrid' in grid-template-columns/row
https://bugs.webkit.org/show_bug.cgi?id=236054

Patch by Matt Woodrow <Matt Woodrow> on 2022-02-13
Reviewed by Manuel Rego Casasnovas.

LayoutTests/imported/w3c:

Imported lastest subgrid tests.

  • web-platform-tests/css/css-grid/subgrid/grid-template-computed-nogrid-expected.txt:
  • web-platform-tests/css/css-grid/subgrid/grid-template-computed-nogrid.html:
  • web-platform-tests/css/css-grid/subgrid/grid-template-invalid-expected.txt: Added.
  • web-platform-tests/css/css-grid/subgrid/grid-template-invalid.html:
  • web-platform-tests/css/css-grid/subgrid/grid-template-valid-expected.txt: Added.
  • web-platform-tests/css/css-grid/subgrid/grid-template-valid.html:

Source/WebCore:

Adds support for parsing the 'subgrid' keyword followed by a list of line names for
grid-template-columns/rows.
Adds a new CSSSubgridValue wrapper around CSSValueList to represent this.
Also adds support for converting this into style data in StyleBuilderConverter, and serializing
the specified value for computed value (used when the element specified subgrid but doesn't
have an appropriate grid parent).

Tests: imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-template-invalid.html

imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-template-valid.html

  • Headers.cmake:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::OrderedNamedLinesCollector::namedGridLineCount const):
(WebCore::addValuesForNamedGridLinesAtIndex):
(WebCore::populateSubgridLineNameList):
(WebCore::valueForGridTrackList):

  • css/CSSSubgridValue.cpp: Added.

(WebCore::CSSSubgridValue::customCSSText const):
(WebCore::CSSSubgridValue::CSSSubgridValue):

  • css/CSSSubgridValue.h: Added.
  • css/CSSValue.cpp:

(WebCore::CSSValue::equals const):
(WebCore::CSSValue::cssText const):
(WebCore::CSSValue::destroy):

  • css/CSSValue.h:

(WebCore::CSSValue::isSubgridValue const):

  • css/CSSValueKeywords.in:
  • css/parser/CSSParserContext.cpp:

(WebCore::operator==):
(WebCore::add):

  • css/parser/CSSParserContext.h:
  • css/parser/CSSPropertyParser.cpp:

(WebCore::consumeGridLineNames):
(WebCore::consumeSubgridNameRepeatFunction):
(WebCore::consumeGridTrackList):
(WebCore::consumeGridTemplatesRowsOrColumns):
(WebCore::CSSPropertyParser::parseSingleValue):
(WebCore::CSSPropertyParser::consumeGridTemplateRowsAndAreasAndColumns):
(WebCore::CSSPropertyParser::consumeGridTemplateShorthand):
(WebCore::CSSPropertyParser::consumeGridShorthand):

  • rendering/style/RenderStyle.h:

(WebCore::RenderStyle::gridSubgridRows const):
(WebCore::RenderStyle::gridSubgridColumns const):
(WebCore::RenderStyle::setGridSubgridRows):
(WebCore::RenderStyle::setGridSubgridColumns):

  • rendering/style/StyleGridData.cpp:

(WebCore::StyleGridData::StyleGridData):

  • rendering/style/StyleGridData.h:

(WebCore::StyleGridData::operator== const):

  • style/StyleBuilderConverter.h:

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

  • style/StyleBuilderCustom.h:

Source/WTF:

Adds a new experimental preference for subgrid support, disabled by default.

  • Scripts/Preferences/WebPreferencesExperimental.yaml:

LayoutTests:

Updated TestExpectations to list all the subgrid tests individually, now that we pass a few.

  • TestExpectations:
  • platform/gtk/imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-template-computed-nogrid-expected.txt: Removed.
  • platform/wpe/imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-template-computed-nogrid-expected.txt: Removed.
File:
1 edited

Legend:

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

    r289588 r289722  
    858858    virtual void collectLineNamesForIndex(CSSGridLineNamesValue&, unsigned index) const;
    859859
     860    virtual int namedGridLineCount() const { return m_orderedNamedGridLines.size(); }
     861
    860862protected:
    861863
     
    875877
    876878    void collectLineNamesForIndex(CSSGridLineNamesValue&, unsigned index) const override;
     879
     880    int namedGridLineCount() const override { return m_orderedNamedAutoRepeatGridLines.size(); }
    877881};
    878882
     
    952956}
    953957
    954 static void addValuesForNamedGridLinesAtIndex(OrderedNamedLinesCollector& collector, unsigned i, CSSValueList& list)
     958static void addValuesForNamedGridLinesAtIndex(OrderedNamedLinesCollector& collector, unsigned i, CSSValueList& list, bool renderEmpty = false)
    955959{
    956960    if (collector.isEmpty())
     
    959963    auto lineNames = CSSGridLineNamesValue::create();
    960964    collector.collectLineNamesForIndex(lineNames.get(), i);
    961     if (lineNames->length())
     965    if (lineNames->length() || renderEmpty)
    962966        list.append(WTFMove(lineNames));
    963967}
     
    994998}
    995999
     1000static void populateSubgridLineNameList(CSSValueList& list, OrderedNamedLinesCollector& collector, int start, int end)
     1001{
     1002    for (int i = start; i < end; i++)
     1003        addValuesForNamedGridLinesAtIndex(collector, i, list, true);
     1004}
     1005
     1006static void populateSubgridLineNameList(CSSValueList& list, OrderedNamedLinesCollector& collector)
     1007{
     1008    populateSubgridLineNameList(list, collector, 0, collector.namedGridLineCount());
     1009}
     1010
    9961011static Ref<CSSValue> valueForGridTrackList(GridTrackSizingDirection direction, RenderObject* renderer, const RenderStyle& style)
    9971012{
    9981013    bool isRowAxis = direction == ForColumns;
    9991014    bool isRenderGrid = is<RenderGrid>(renderer);
     1015    bool isSubgrid = isRowAxis ? style.gridSubgridColumns() : style.gridSubgridRows();
    10001016    auto& trackSizes = isRowAxis ? style.gridColumns() : style.gridRows();
    10011017    auto& autoRepeatTrackSizes = isRowAxis ? style.gridAutoRepeatColumns() : style.gridAutoRepeatRows();
     
    10111027    }
    10121028
    1013     if (trackListIsEmpty)
     1029    if (trackListIsEmpty && !isSubgrid)
    10141030        return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
    10151031
    10161032    auto list = CSSValueList::createSpaceSeparated();
     1033    if (isSubgrid)
     1034        list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueSubgrid));
    10171035
    10181036    // If the element is a grid container, the resolved value is the used value,
    10191037    // specifying track sizes in pixels and expanding the repeat() notation.
    10201038    if (isRenderGrid) {
     1039        // FIXME: We need to handle computed subgrid here.
    10211040        auto* grid = downcast<RenderGrid>(renderer);
    10221041        OrderedNamedLinesCollectorInGridLayout collector(style, isRowAxis, grid->autoRepeatCountForDirection(direction), autoRepeatTrackSizes.size());
     
    10361055    };
    10371056
     1057    OrderedNamedLinesCollectorInsideRepeat repeatCollector(style, isRowAxis);
     1058    if (isSubgrid) {
     1059        if (!repeatCollector.namedGridLineCount()) {
     1060            populateSubgridLineNameList(list.get(), collector);
     1061            return list;
     1062        }
     1063
     1064        // Add the line names that precede the auto repeat().
     1065        int autoRepeatInsertionPoint = isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint() : style.gridAutoRepeatRowsInsertionPoint();
     1066        autoRepeatInsertionPoint = std::clamp<int>(autoRepeatInsertionPoint, 0, collector.namedGridLineCount());
     1067        populateSubgridLineNameList(list.get(), collector, 0, autoRepeatInsertionPoint);
     1068
     1069        // Add a CSSGridAutoRepeatValue with the contents of the auto repeat().
     1070        ASSERT((isRowAxis ? style.gridAutoRepeatColumnsType() : style.gridAutoRepeatRowsType()) == AutoRepeatType::Fill);
     1071        auto repeatedValues = CSSGridAutoRepeatValue::create(CSSValueAutoFill);
     1072        populateSubgridLineNameList(repeatedValues.get(), repeatCollector);
     1073        list->append(repeatedValues.get());
     1074
     1075        // Add the line names that follow the auto repeat().
     1076        populateSubgridLineNameList(list.get(), collector, autoRepeatInsertionPoint, collector.namedGridLineCount());
     1077        return list;
     1078    }
     1079
    10381080    if (autoRepeatTrackSizes.isEmpty()) {
    10391081        // If there's no auto repeat(), just add all the line names and track sizes.
     
    10431085
    10441086    // Add the line names and track sizes that precede the auto repeat().
    1045     int autoRepeatInsertionPoint = std::clamp<int>(isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint() : style.gridAutoRepeatRowsInsertionPoint(), 0, trackSizes.size());
     1087    int autoRepeatInsertionPoint = isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint() : style.gridAutoRepeatRowsInsertionPoint();
     1088    autoRepeatInsertionPoint = std::clamp<int>(autoRepeatInsertionPoint, 0, trackSizes.size());
    10461089    populateGridTrackList(list.get(), collector, trackSizes, getTrackSize, 0, autoRepeatInsertionPoint);
    10471090
     
    10491092    AutoRepeatType autoRepeatType = isRowAxis ? style.gridAutoRepeatColumnsType() : style.gridAutoRepeatRowsType();
    10501093    auto repeatedValues = CSSGridAutoRepeatValue::create(autoRepeatType == AutoRepeatType::Fill ? CSSValueAutoFill : CSSValueAutoFit);
    1051     OrderedNamedLinesCollectorInsideRepeat repeatCollector(style, isRowAxis);
     1094
    10521095    populateGridTrackList(repeatedValues.get(), repeatCollector, autoRepeatTrackSizes, getTrackSize);
    10531096    list->append(repeatedValues.get());
Note: See TracChangeset for help on using the changeset viewer.