⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 136150 in webkit


Ignore:
Timestamp:
Nov 29, 2012, 12:26:29 PM (14 years ago)
Author:
jchaffraix@webkit.org
Message:

[CSS Grid Layout] track sizing functions should have their own type
​https://bugs.webkit.org/show_bug.cgi?id=103343

Reviewed by Tony Chang.

The current code uses a Length to represent the track sizing function. This is
fine as we only parse <length> | <percentage> but in order to support minmax
sizing, we have to store 2 Lengths. We could go with a pair but that would make
the code not very readable so this change introduces GridTrackSize.

Refactoring, covered by existing tests.

  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:

Added GridTrackSize.h to all our build systems.

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::valueForGridTrackBreadth):
(WebCore::valueForGridTrackList):

  • css/StyleResolver.cpp:

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

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::computePreferredLogicalWidths):
(WebCore::RenderGrid::computedUsedBreadthOfGridTracks):

  • rendering/style/RenderStyle.h:

Updated the above call sites to use GridTrackSize. While
touching them, changed the code to use an empty Vector to represent
'none' instead of Length(Undefined).

  • rendering/style/StyleGridData.h:

Updated #include, removed a comment as it would have gone stale after
adding more grammar support and added a FIXME to rename some variables.

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::layoutGridItems):
Implemented a work-around to avoid crashing due to implicit columns / rows.

  • rendering/style/GridTrackSize.h: Added.

(WebCore::GridTrackSize::GridTrackSize):
(WebCore::GridTrackSize::length):
(WebCore::GridTrackSize::setLength):
(WebCore::GridTrackSize::type):
(WebCore::GridTrackSize::operator==):
New class, it now only wraps a single Length.

Location:
trunk/Source/WebCore
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r136149 r136150  
     12012-11-29  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        [CSS Grid Layout] track sizing functions should have their own type
     4        https://bugs.webkit.org/show_bug.cgi?id=103343
     5
     6        Reviewed by Tony Chang.
     7
     8        The current code uses a Length to represent the track sizing function. This is
     9        fine as we only parse <length> | <percentage> but in order to support minmax
     10        sizing, we have to store 2 Lengths. We could go with a pair but that would make
     11        the code not very readable so this change introduces GridTrackSize.
     12
     13        Refactoring, covered by existing tests.
     14
     15        * GNUmakefile.list.am:
     16        * Target.pri:
     17        * WebCore.gypi:
     18        * WebCore.vcproj/WebCore.vcproj:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        Added GridTrackSize.h to all our build systems.
     21
     22        * css/CSSComputedStyleDeclaration.cpp:
     23        (WebCore::valueForGridTrackBreadth):
     24        (WebCore::valueForGridTrackList):
     25        * css/StyleResolver.cpp:
     26        (WebCore::createGridTrackBreadth):
     27        (WebCore::createGridTrackList):
     28        (WebCore::StyleResolver::applyProperty):
     29        * rendering/RenderGrid.cpp:
     30        (WebCore::RenderGrid::computePreferredLogicalWidths):
     31        (WebCore::RenderGrid::computedUsedBreadthOfGridTracks):
     32        * rendering/style/RenderStyle.h:
     33        Updated the above call sites to use GridTrackSize. While
     34        touching them, changed the code to use an empty Vector to represent
     35        'none' instead of Length(Undefined).
     36
     37        * rendering/style/StyleGridData.h:
     38        Updated #include, removed a comment as it would have gone stale after
     39        adding more grammar support and added a FIXME to rename some variables.
     40
     41        * rendering/RenderGrid.cpp:
     42        (WebCore::RenderGrid::layoutGridItems):
     43        Implemented a work-around to avoid crashing due to implicit columns / rows.
     44
     45        * rendering/style/GridTrackSize.h: Added.
     46        (WebCore::GridTrackSize::GridTrackSize):
     47        (WebCore::GridTrackSize::length):
     48        (WebCore::GridTrackSize::setLength):
     49        (WebCore::GridTrackSize::type):
     50        (WebCore::GridTrackSize::operator==):
     51        New class, it now only wraps a single Length.
     52
    1532012-11-29  Helder Correia  <helder.correia@nokia.com>
    254
  • trunk/Source/WebCore/GNUmakefile.list.am

    r136113 r136150  
    45054505        Source/WebCore/rendering/style/StyleVisualData.cpp \
    45064506        Source/WebCore/rendering/style/StyleVisualData.h \
     4507        Source/WebCore/rendering/style/GridTrackSize.h \
    45074508        Source/WebCore/rendering/TableLayout.h \
    45084509        Source/WebCore/rendering/TrailingFloatsRootInlineBox.h \
  • trunk/Source/WebCore/Target.pri

    r136113 r136150  
    24772477    rendering/style/StyleVariableData.h \
    24782478    rendering/style/StyleVisualData.h \
     2479    rendering/style/GridTrackSize.h \
    24792480    rendering/style/SVGRenderStyleDefs.h \
    24802481    rendering/style/SVGRenderStyle.h \
  • trunk/Source/WebCore/WebCore.gypi

    r136113 r136150  
    629629            'rendering/style/StyleVariableData.h',
    630630            'rendering/style/StyleVisualData.h',
     631            'rendering/style/GridTrackSizes.h',
    631632            'rendering/svg/SVGResourcesCache.h',
    632633            'workers/SharedWorkerStrategy.h',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r136113 r136150  
    4685246852                                </File>
    4685346853                                <File
     46854                                        RelativePath="..\rendering\style\GridTrackSize.h"
     46855                                        >
     46856                                </File>
     46857                                <File
    4685446858                                        RelativePath="..\rendering\style\SVGRenderStyle.cpp"
    4685546859                                        >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r136113 r136150  
    38223822                A12538D413F9B60A00024754 /* LayoutRepainter.h in Headers */ = {isa = PBXBuildFile; fileRef = A120ACA013F9983700FE4AC7 /* LayoutRepainter.h */; settings = {ATTRIBUTES = (Private, ); }; };
    38233823                A12705C31656BD6500C2E27C /* GridPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = A12705C21656BD6500C2E27C /* GridPosition.h */; settings = {ATTRIBUTES = (Private, ); }; };
     3824                A12A1050166444FD008FA311 /* GridTrackSize.h in Headers */ = {isa = PBXBuildFile; fileRef = A12A104E166444DC008FA311 /* GridTrackSize.h */; settings = {ATTRIBUTES = (Private, ); }; };
    38243825                A136A00C1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A136A00A1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp */; };
    38253826                A136A00D1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.h in Headers */ = {isa = PBXBuildFile; fileRef = A136A00B1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.h */; };
    … …  
    1113711138                A120ACA113F9984600FE4AC7 /* LayoutRepainter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutRepainter.cpp; sourceTree = "<group>"; };
    1113811139                A12705C21656BD6500C2E27C /* GridPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GridPosition.h; path = style/GridPosition.h; sourceTree = "<group>"; };
     11140                A12A104E166444DC008FA311 /* GridTrackSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GridTrackSize.h; path = style/GridTrackSize.h; sourceTree = "<group>"; };
    1113911141                A136A00A1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLHttpRequestProgressEventThrottle.cpp; sourceTree = "<group>"; };
    1114011142                A136A00B1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLHttpRequestProgressEventThrottle.h; sourceTree = "<group>"; };
    … …  
    2074320745                                BC2274760E8366E200E7F975 /* SVGRenderStyleDefs.cpp */,
    2074420746                                BC2274770E8366E200E7F975 /* SVGRenderStyleDefs.h */,
     20747                                A12A104E166444DC008FA311 /* GridTrackSize.h */,
    2074520748                        );
    2074620749                        name = style;
    … …  
    2560525608                                49E912AE0EFAC906009D0CAF /* TimingFunction.h in Headers */,
    2560625609                                070334D71459FFD5008D8D45 /* TrackBase.h in Headers */,
     25610                                A12A1050166444FD008FA311 /* GridTrackSize.h in Headers */,
    2560725611                                49E911C40EF86D47009D0CAF /* TransformationMatrix.h in Headers */,
    2560825612                                49E911CE0EF86D47009D0CAF /* TransformOperation.h in Headers */,
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r136142 r136150  
    984984#endif
    985985
    986 static PassRefPtr<CSSValue> valueForGridTrackBreadth(const Length& trackLength, const RenderStyle* style)
    987 {
    988     if (trackLength.isPercent())
    989         return cssValuePool().createValue(trackLength);
    990     if (trackLength.isAuto())
     986static PassRefPtr<CSSValue> valueForGridTrackBreadth(const GridTrackSize& trackSize, const RenderStyle* style)
     987{
     988    if (trackSize.length().isPercent())
     989        return cssValuePool().createValue(trackSize.length());
     990    if (trackSize.length().isAuto())
    991991        return cssValuePool().createIdentifierValue(CSSValueAuto);
    992     return zoomAdjustedPixelValue(trackLength.value(), style);
    993 }
    994 
    995 static PassRefPtr<CSSValue> valueForGridTrackList(const Vector<Length>& trackLengths, const RenderStyle* style)
    996 {
    997     // We should have at least an element!
    998     ASSERT(trackLengths.size());
    999 
     992    return zoomAdjustedPixelValue(trackSize.length().value(), style);
     993}
     994
     995static PassRefPtr<CSSValue> valueForGridTrackList(const Vector<GridTrackSize>& trackSizes, const RenderStyle* style)
     996{
    1000997    // Handle the 'none' case here.
    1001     if (trackLengths.size() == 1 && trackLengths[0].isUndefined())
     998    if (!trackSizes.size())
    1002999        return cssValuePool().createIdentifierValue(CSSValueNone);
    10031000
    10041001    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
    1005     for (size_t i = 0; i < trackLengths.size(); ++i)
    1006         list->append(valueForGridTrackBreadth(trackLengths[i], style));
     1002    for (size_t i = 0; i < trackSizes.size(); ++i)
     1003        list->append(valueForGridTrackBreadth(trackSizes[i], style));
    10071004    return list.release();
    10081005}
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r136142 r136150  
    26602660}
    26612661
    2662 static bool createGridTrackBreadth(CSSPrimitiveValue* primitiveValue, StyleResolver* selector, Length& length)
     2662static bool createGridTrackBreadth(CSSPrimitiveValue* primitiveValue, StyleResolver* selector, GridTrackSize& trackSize)
    26632663{
    26642664    Length workingLength = primitiveValue->convertToLength<FixedIntegerConversion | PercentConversion | ViewportPercentageConversion | AutoConversion>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
    … …  
    26692669        workingLength.setQuirk(primitiveValue->isQuirkValue());
    26702670
    2671     length = workingLength;
     2671    trackSize.setLength(workingLength);
    26722672    return true;
    26732673}
    26742674
    2675 static bool createGridTrackList(CSSValue* value, Vector<Length>& lengths, StyleResolver* selector)
     2675static bool createGridTrackList(CSSValue* value, Vector<GridTrackSize>& trackSizes, StyleResolver* selector)
    26762676{
    26772677    // Handle 'none'.
    26782678    if (value->isPrimitiveValue()) {
    26792679        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    2680         if (primitiveValue->getIdent() == CSSValueNone) {
    2681             lengths.append(Length(Undefined));
    2682             return true;
    2683         }
    2684         return false;
     2680        return primitiveValue->getIdent() == CSSValueNone;
    26852681    }
    26862682
    … …  
    26912687                return false;
    26922688
    2693             Length length;
    2694             if (!createGridTrackBreadth(static_cast<CSSPrimitiveValue*>(currValue), selector, length))
     2689            GridTrackSize trackSize;
     2690            if (!createGridTrackBreadth(static_cast<CSSPrimitiveValue*>(currValue), selector, trackSize))
    26952691                return false;
    26962692
    2697             lengths.append(length);
     2693            trackSizes.append(trackSize);
    26982694        }
    26992695        return true;
    … …  
    35453541#endif
    35463542    case CSSPropertyWebkitGridColumns: {
    3547         Vector<Length> lengths;
    3548         if (!createGridTrackList(value, lengths, this))
     3543        Vector<GridTrackSize> trackSizes;
     3544        if (!createGridTrackList(value, trackSizes, this))
    35493545            return;
    3550         m_style->setGridColumns(lengths);
     3546        m_style->setGridColumns(trackSizes);
    35513547        return;
    35523548    }
    35533549    case CSSPropertyWebkitGridRows: {
    3554         Vector<Length> lengths;
    3555         if (!createGridTrackList(value, lengths, this))
     3550        Vector<GridTrackSize> trackSizes;
     3551        if (!createGridTrackList(value, trackSizes, this))
    35563552            return;
    3557         m_style->setGridRows(lengths);
     3553        m_style->setGridRows(trackSizes);
    35583554        return;
    35593555    }
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r135965 r136150  
    117117    // FIXME: We don't take our own logical width into account.
    118118
    119     const Vector<Length>& trackStyles = style()->gridColumns();
     119    const Vector<GridTrackSize>& trackStyles = style()->gridColumns();
    120120
    121121    for (size_t i = 0; i < trackStyles.size(); ++i) {
    122         Length trackLength = trackStyles[i];
     122        Length trackLength = trackStyles[i].length();
    123123        if (!trackLength.isFixed()) {
    124124            notImplemented();
    … …  
    139139void RenderGrid::computedUsedBreadthOfGridTracks(TrackSizingDirection direction, Vector<GridTrack>& tracks)
    140140{
    141     const Vector<Length>& trackStyles = (direction == ForColumns) ? style()->gridColumns() : style()->gridRows();
     141    const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style()->gridColumns() : style()->gridRows();
    142142    for (size_t i = 0; i < trackStyles.size(); ++i) {
    143143        GridTrack track;
    144         if (trackStyles[i].isFixed())
    145             track.m_usedBreadth = trackStyles[i].getFloatValue();
     144        if (trackStyles[i].length().isFixed())
     145            track.m_usedBreadth = trackStyles[i].length().getFloatValue();
    146146        else
    147147            notImplemented();
    … …  
    166166        size_t rowTrack = resolveGridPosition(child->style()->gridItemRow());
    167167
    168         // Because the grid area cannot be styled, we don't need to adjust
    169         // the grid breadth to account for 'box-sizing'.
    170         child->setOverrideContainingBlockContentLogicalWidth(columnTracks[columnTrack].m_usedBreadth);
    171         child->setOverrideContainingBlockContentLogicalHeight(rowTracks[rowTrack].m_usedBreadth);
     168        // FIXME: Properly support implicit rows and columns (bug 103573).
     169        if (columnTrack < columnTracks.size() && rowTrack < rowTracks.size()) {
     170            // Because the grid area cannot be styled, we don't need to adjust
     171            // the grid breadth to account for 'box-sizing'.
     172            child->setOverrideContainingBlockContentLogicalWidth(columnTracks[columnTrack].m_usedBreadth);
     173            child->setOverrideContainingBlockContentLogicalHeight(rowTracks[rowTrack].m_usedBreadth);
     174        }
    172175
    173176        // FIXME: Grid items should stretch to fill their cells. Once we
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r136142 r136150  
    759759    EJustifyContent justifyContent() const { return static_cast<EJustifyContent>(rareNonInheritedData->m_justifyContent); }
    760760
    761     const Vector<Length>& gridColumns() const { return rareNonInheritedData->m_grid->m_gridColumns; }
    762     const Vector<Length>& gridRows() const { return rareNonInheritedData->m_grid->m_gridRows; }
     761    const Vector<GridTrackSize>& gridColumns() const { return rareNonInheritedData->m_grid->m_gridColumns; }
     762    const Vector<GridTrackSize>& gridRows() const { return rareNonInheritedData->m_grid->m_gridRows; }
    763763
    764764    const GridPosition& gridItemColumn() const { return rareNonInheritedData->m_gridItem->m_gridColumn; }
    … …  
    12411241    void setFlexWrap(EFlexWrap w) { SET_VAR(rareNonInheritedData.access()->m_flexibleBox, m_flexWrap, w); }
    12421242    void setJustifyContent(EJustifyContent p) { SET_VAR(rareNonInheritedData, m_justifyContent, p); }
    1243     void setGridColumns(const Vector<Length>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridColumns, lengths); }
    1244     void setGridRows(const Vector<Length>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridRows, lengths); }
     1243    void setGridColumns(const Vector<GridTrackSize>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridColumns, lengths); }
     1244    void setGridRows(const Vector<GridTrackSize>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridRows, lengths); }
    12451245    void setGridItemColumn(const GridPosition& columnPosition) { SET_VAR(rareNonInheritedData.access()->m_gridItem, m_gridColumn, columnPosition); }
    12461246    void setGridItemRow(const GridPosition& rowPosition) { SET_VAR(rareNonInheritedData.access()->m_gridItem, m_gridRow, rowPosition); }
    … …  
    16331633
    16341634    // The initial value is 'none' for grid tracks.
    1635     static Vector<Length> initialGridTrackValue()
    1636     {
    1637         DEFINE_STATIC_LOCAL(Vector<Length>, defaultLength, ());
    1638         // We need to manually add the Length here as the Length(0) is 'auto'.
    1639         if (!defaultLength.size())
    1640             defaultLength.append(Length(Undefined));
    1641         return defaultLength;
    1642     }
    1643     static Vector<Length> initialGridColumns() { return initialGridTrackValue(); }
    1644     static Vector<Length> initialGridRows() { return initialGridTrackValue(); }
     1635    static Vector<GridTrackSize> initialGridColumns() { return Vector<GridTrackSize>(); }
     1636    static Vector<GridTrackSize> initialGridRows() { return Vector<GridTrackSize>(); }
    16451637
    16461638    // 'auto' is the default.
  • trunk/Source/WebCore/rendering/style/StyleGridData.h

    r117613 r136150  
    2727#define StyleGridData_h
    2828
    29 #include "Length.h"
     29#include "GridTrackSize.h"
    3030#include <wtf/PassRefPtr.h>
    3131#include <wtf/RefCounted.h>
    … …  
    4949    }
    5050
    51     // FIXME: For the moment, we only support a subset of the grammar which correspond to:
    52     // 'auto' | <length> | <percentage> | 'none'
    53     Vector<Length> m_gridColumns;
    54     Vector<Length> m_gridRows;
     51    // FIXME: Update the naming of the following variables.
     52    Vector<GridTrackSize> m_gridColumns;
     53    Vector<GridTrackSize> m_gridRows;
    5554
    5655private:
Note: See TracChangeset for help on using the changeset viewer.