Changeset 153752 in webkit


Ignore:
Timestamp:
Aug 6, 2013 8:08:21 AM (11 years ago)
Author:
sergio@webkit.org
Message:

[CSS Grid Layout] Allow defining named grid lines on the grid element
https://bugs.webkit.org/show_bug.cgi?id=118255

Reviewed by Andreas Kling.

From Blink r149798 by <jchaffraix@chromium.org>

Source/WebCore:

This change adds parsing, style resolution and getComputedStyle
support for named grid lines at the grid element level
(i.e. extends our <track-list> support). Per the specification, we
allow multiple grid lines with the same name.

To fully support resolving the grid lines to a position on our
grid, we need to add the parsing at the grid item's level (which
means extending our <grid-line> support). This will be done in a
follow-up change.

Test: fast/css-grid-layout/named-grid-line-get-set.html

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::addValuesForNamedGridLinesAtIndex):
(WebCore::valueForGridTrackList):
(WebCore::ComputedStyleExtractor::propertyValue):

  • css/CSSParser.cpp:

(WebCore::CSSParser::parseGridTrackList):

  • css/StyleResolver.cpp:

(WebCore::createGridTrackList):
(WebCore::StyleResolver::applyProperty):

  • rendering/style/RenderStyle.h:
  • rendering/style/StyleGridData.cpp:

(WebCore::StyleGridData::StyleGridData):

  • rendering/style/StyleGridData.h:

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

LayoutTests:

  • fast/css-grid-layout/named-grid-line-get-set-expected.txt: Added.
  • fast/css-grid-layout/named-grid-line-get-set.html: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r153748 r153752  
     12013-08-06  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [CSS Grid Layout] Allow defining named grid lines on the grid element
     4        https://bugs.webkit.org/show_bug.cgi?id=118255
     5
     6        Reviewed by Andreas Kling.
     7
     8        From Blink r149798 by <jchaffraix@chromium.org>
     9
     10        * fast/css-grid-layout/named-grid-line-get-set-expected.txt: Added.
     11        * fast/css-grid-layout/named-grid-line-get-set.html: Added.
     12
    1132013-06-26  Sergio Villar Senin  <svillar@igalia.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r153750 r153752  
     12013-08-06  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [CSS Grid Layout] Allow defining named grid lines on the grid element
     4        https://bugs.webkit.org/show_bug.cgi?id=118255
     5
     6        Reviewed by Andreas Kling.
     7
     8        From Blink r149798 by <jchaffraix@chromium.org>
     9
     10        This change adds parsing, style resolution and getComputedStyle
     11        support for named grid lines at the grid element level
     12        (i.e. extends our <track-list> support). Per the specification, we
     13        allow multiple grid lines with the same name.
     14
     15        To fully support resolving the grid lines to a position on our
     16        grid, we need to add the parsing at the grid item's level (which
     17        means extending our <grid-line> support). This will be done in a
     18        follow-up change.
     19
     20        Test: fast/css-grid-layout/named-grid-line-get-set.html
     21
     22        * css/CSSComputedStyleDeclaration.cpp:
     23        (WebCore::addValuesForNamedGridLinesAtIndex):
     24        (WebCore::valueForGridTrackList):
     25        (WebCore::ComputedStyleExtractor::propertyValue):
     26        * css/CSSParser.cpp:
     27        (WebCore::CSSParser::parseGridTrackList):
     28        * css/StyleResolver.cpp:
     29        (WebCore::createGridTrackList):
     30        (WebCore::StyleResolver::applyProperty):
     31        * rendering/style/RenderStyle.h:
     32        * rendering/style/StyleGridData.cpp:
     33        (WebCore::StyleGridData::StyleGridData):
     34        * rendering/style/StyleGridData.h:
     35        (WebCore::StyleGridData::operator==):
     36
    1372013-08-06  Allan Sandfeld Jensen  <allan.jensen@digia.com>
    238
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r153748 r153752  
    10841084}
    10851085
    1086 static PassRefPtr<CSSValue> valueForGridTrackList(const Vector<GridTrackSize>& trackSizes, const RenderStyle* style, RenderView *renderView)
     1086static void addValuesForNamedGridLinesAtIndex(const NamedGridLinesMap& namedGridLines, size_t i, CSSValueList& list)
     1087{
     1088    // Note that this won't return the results in the order specified in the style sheet,
     1089    // which is probably fine as we still *do* return all the expected values.
     1090    NamedGridLinesMap::const_iterator it = namedGridLines.begin();
     1091    NamedGridLinesMap::const_iterator end = namedGridLines.end();
     1092    for (; it != end; ++it) {
     1093        const Vector<size_t>& linesIndexes = it->value;
     1094        for (size_t j = 0; j < linesIndexes.size(); ++j) {
     1095            if (linesIndexes[j] != i)
     1096                continue;
     1097
     1098            list.append(cssValuePool().createValue(it->key, CSSPrimitiveValue::CSS_STRING));
     1099            break;
     1100        }
     1101    }
     1102}
     1103
     1104static PassRefPtr<CSSValue> valueForGridTrackList(const Vector<GridTrackSize>& trackSizes, const NamedGridLinesMap& namedGridLines, const RenderStyle* style, RenderView* renderView)
    10871105{
    10881106    // Handle the 'none' case here.
    1089     if (!trackSizes.size())
     1107    if (!trackSizes.size()) {
     1108        ASSERT(namedGridLines.isEmpty());
    10901109        return cssValuePool().createIdentifierValue(CSSValueNone);
     1110    }
    10911111
    10921112    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
    1093     for (size_t i = 0; i < trackSizes.size(); ++i)
     1113    for (size_t i = 0; i < trackSizes.size(); ++i) {
     1114        addValuesForNamedGridLinesAtIndex(namedGridLines, i, *list);
    10941115        list->append(valueForGridTrackSize(trackSizes[i], style, renderView));
     1116    }
     1117    // Those are the trailing <string>* allowed in the syntax.
     1118    addValuesForNamedGridLinesAtIndex(namedGridLines, trackSizes.size(), *list);
    10951119    return list.release();
    10961120}
     
    20452069            return valueForGridTrackSize(style->gridAutoRows(), style.get(), m_node->document()->renderView());
    20462070        case CSSPropertyWebkitGridDefinitionColumns:
    2047             return valueForGridTrackList(style->gridColumns(), style.get(), m_node->document()->renderView());
     2071            return valueForGridTrackList(style->gridColumns(), style->namedGridColumnLines(), style.get(), m_node->document()->renderView());
    20482072        case CSSPropertyWebkitGridDefinitionRows:
    2049             return valueForGridTrackList(style->gridRows(), style.get(), m_node->document()->renderView());
     2073            return valueForGridTrackList(style->gridRows(), style->namedGridRowLines(), style.get(), m_node->document()->renderView());
    20502074
    20512075        case CSSPropertyWebkitGridColumnStart:
  • trunk/Source/WebCore/css/CSSParser.cpp

    r153748 r153752  
    48544854    RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
    48554855    while (m_valueList->current()) {
     4856        while (m_valueList->current() && m_valueList->current()->unit == CSSPrimitiveValue::CSS_STRING) {
     4857            RefPtr<CSSPrimitiveValue> name = createPrimitiveStringValue(m_valueList->current());
     4858            values->append(name);
     4859            m_valueList->next();
     4860        }
     4861
     4862        // This allows trailing <string>* per the specification.
     4863        if (!m_valueList->current())
     4864            break;
     4865
    48564866        RefPtr<CSSPrimitiveValue> primitiveValue = parseGridTrackSize();
    48574867        if (!primitiveValue)
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r153748 r153752  
    21002100}
    21012101
    2102 static bool createGridTrackList(CSSValue* value, Vector<GridTrackSize>& trackSizes, const StyleResolver::State& state)
     2102static bool createGridTrackList(CSSValue* value, Vector<GridTrackSize>& trackSizes, NamedGridLinesMap& namedGridLines, const StyleResolver::State& state)
    21032103{
    21042104    // Handle 'none'.
     
    21112111        return false;
    21122112
     2113    size_t currentNamedGridLine = 0;
    21132114    for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
    21142115        CSSValue* currValue = i.value();
     2116        if (currValue->isPrimitiveValue()) {
     2117            CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(currValue);
     2118            if (primitiveValue->isString()) {
     2119                NamedGridLinesMap::AddResult result = namedGridLines.add(primitiveValue->getStringValue(), Vector<size_t>());
     2120                result.iterator->value.append(currentNamedGridLine);
     2121                continue;
     2122            }
     2123        }
     2124
     2125        ++currentNamedGridLine;
    21152126        GridTrackSize trackSize;
    21162127        if (!createGridTrackSize(currValue, trackSize, state))
     
    21192130        trackSizes.append(trackSize);
    21202131    }
     2132
     2133    if (trackSizes.isEmpty())
     2134        return false;
     2135
    21212136    return true;
    21222137}
     
    28392854    case CSSPropertyWebkitGridDefinitionColumns: {
    28402855        Vector<GridTrackSize> trackSizes;
    2841         if (!createGridTrackList(value, trackSizes, state))
     2856        NamedGridLinesMap namedGridLines;
     2857        if (!createGridTrackList(value, trackSizes, namedGridLines, state))
    28422858            return;
    28432859        state.style()->setGridColumns(trackSizes);
     2860        state.style()->setNamedGridColumnLines(namedGridLines);
    28442861        return;
    28452862    }
    28462863    case CSSPropertyWebkitGridDefinitionRows: {
    28472864        Vector<GridTrackSize> trackSizes;
    2848         if (!createGridTrackList(value, trackSizes, state))
     2865        NamedGridLinesMap namedGridLines;
     2866        if (!createGridTrackList(value, trackSizes, namedGridLines, state))
    28492867            return;
    28502868        state.style()->setGridRows(trackSizes);
     2869        state.style()->setNamedGridRowLines(namedGridLines);
    28512870        return;
    28522871    }
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r153746 r153752  
    777777    const Vector<GridTrackSize>& gridColumns() const { return rareNonInheritedData->m_grid->m_gridColumns; }
    778778    const Vector<GridTrackSize>& gridRows() const { return rareNonInheritedData->m_grid->m_gridRows; }
     779    const NamedGridLinesMap& namedGridColumnLines() const { return rareNonInheritedData->m_grid->m_namedGridColumnLines; }
     780    const NamedGridLinesMap& namedGridRowLines() const { return rareNonInheritedData->m_grid->m_namedGridRowLines; }
    779781    GridAutoFlow gridAutoFlow() const { return rareNonInheritedData->m_grid->m_gridAutoFlow; }
    780782    const GridTrackSize& gridAutoColumns() const { return rareNonInheritedData->m_grid->m_gridAutoColumns; }
     
    12991301    void setGridColumns(const Vector<GridTrackSize>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridColumns, lengths); }
    13001302    void setGridRows(const Vector<GridTrackSize>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridRows, lengths); }
     1303    void setNamedGridColumnLines(const NamedGridLinesMap& namedGridColumnLines) { SET_VAR(rareNonInheritedData.access()->m_grid, m_namedGridColumnLines, namedGridColumnLines); }
     1304    void setNamedGridRowLines(const NamedGridLinesMap& namedGridRowLines) { SET_VAR(rareNonInheritedData.access()->m_grid, m_namedGridRowLines, namedGridRowLines); }
    13011305    void setGridAutoFlow(GridAutoFlow flow) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridAutoFlow, flow); }
    13021306    void setGridItemColumnStart(const GridPosition& columnStartPosition) { SET_VAR(rareNonInheritedData.access()->m_gridItem, m_gridColumnStart, columnStartPosition); }
  • trunk/Source/WebCore/rendering/style/StyleGridData.cpp

    r146274 r153752  
    4444    , m_gridColumns(o.m_gridColumns)
    4545    , m_gridRows(o.m_gridRows)
     46    , m_namedGridColumnLines(o.m_namedGridColumnLines)
     47    , m_namedGridRowLines(o.m_namedGridRowLines)
    4648    , m_gridAutoFlow(o.m_gridAutoFlow)
    4749    , m_gridAutoRows(o.m_gridAutoRows)
  • trunk/Source/WebCore/rendering/style/StyleGridData.h

    r146274 r153752  
    3232#include <wtf/RefCounted.h>
    3333#include <wtf/Vector.h>
     34#include <wtf/text/WTFString.h>
    3435
    3536namespace WebCore {
     37
     38typedef HashMap<String, Vector<size_t> > NamedGridLinesMap;
    3639
    3740class StyleGridData : public RefCounted<StyleGridData> {
     
    4245    bool operator==(const StyleGridData& o) const
    4346    {
    44         return m_gridColumns == o.m_gridColumns && m_gridRows == o.m_gridRows && m_gridAutoFlow == o.m_gridAutoFlow && m_gridAutoRows == o.m_gridAutoRows && m_gridAutoColumns == o.m_gridAutoColumns;
     47        // FIXME: comparing two hashes doesn't look great for performance. Something to keep in mind going forward.
     48        return m_gridColumns == o.m_gridColumns && m_gridRows == o.m_gridRows && m_gridAutoFlow == o.m_gridAutoFlow && m_gridAutoRows == o.m_gridAutoRows && m_gridAutoColumns == o.m_gridAutoColumns && m_namedGridColumnLines == o.m_namedGridColumnLines && m_namedGridRowLines == o.m_namedGridRowLines;
    4549    }
    4650
     
    5357    Vector<GridTrackSize> m_gridColumns;
    5458    Vector<GridTrackSize> m_gridRows;
     59
     60    NamedGridLinesMap m_namedGridColumnLines;
     61    NamedGridLinesMap m_namedGridRowLines;
    5562
    5663    GridAutoFlow m_gridAutoFlow;
Note: See TracChangeset for help on using the changeset viewer.