Changeset 102183 in webkit


Ignore:
Timestamp:
Dec 6, 2011 3:11:05 PM (12 years ago)
Author:
jchaffraix@webkit.org
Message:

CSS Grid Layout: Add support for parsing multiple grid-columns or grid-rows
https://bugs.webkit.org/show_bug.cgi?id=73272

Reviewed by Tony Chang.

Source/WebCore:

Test: fast/css-grid-layout/grid-columns-rows-get-set-multiple.html

Updated our supported syntax to match the following:
<track-list> := [ <track-breadth> ]+ | 'none'
<track-breadth> := <length> | <percentage> | 'auto'
(the naming loosely matches the specification)

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::valueForGridTrackBreadth): Added function to handle a breadth
(extended with 'auto' that the spec puts in <track-minmax>).

(WebCore::valueForGridTrackList): Create a space seperated list of
track breadth or none.

(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Updated
to use the new functions.

  • css/CSSParser.cpp:

(WebCore::CSSParser::parseGridTrackList): Extended the function to
match the new syntax.

  • css/CSSStyleApplyProperty.cpp:

(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty): Removed our
simple implementation. Replaced by the CSSStyleSelector functions.

  • css/CSSStyleSelector.cpp:

(WebCore::createGridTrackBreadth):
(WebCore::createGridTrackList):
Added those 2 functions to convert the CSSPrimitiveValue to a Vector
as expected by RenderStyle.

(WebCore::CSSStyleSelector::applyProperty): Added our 2 properties
now that it is not handled by CSSStyleApplyProperty.

  • rendering/style/RenderStyle.h:

(WebCore::InheritedFlags::gridColumns):
(WebCore::InheritedFlags::gridRows):
(WebCore::InheritedFlags::setGridColumns):
(WebCore::InheritedFlags::setGridRows):
(WebCore::InheritedFlags::initialGridColumns):
(WebCore::InheritedFlags::initialGridRows):
Updated the previous methods to take a Vector of Length.

(WebCore::InheritedFlags::initialGridTrackValue):
Needed function to return a Vector with one 'none' Length (the initial
value per the specification).

  • rendering/style/StyleGridData.h: Updated to use a Vector.

LayoutTests:

  • fast/css-grid-layout/grid-columns-rows-get-set-expected.txt:
  • fast/css-grid-layout/resources/grid-columns-rows-get-set.js:

Added more testing for the single case.

  • fast/css-grid-layout/grid-columns-rows-get-set-multiple-expected.txt: Added.
  • fast/css-grid-layout/grid-columns-rows-get-set-multiple.html: Added.
  • fast/css-grid-layout/resources/grid-columns-rows-get-set-multiple.js: Added.
Location:
trunk
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r102155 r102183  
     12011-12-06  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        CSS Grid Layout: Add support for parsing multiple grid-columns or grid-rows
     4        https://bugs.webkit.org/show_bug.cgi?id=73272
     5
     6        Reviewed by Tony Chang.
     7
     8        * fast/css-grid-layout/grid-columns-rows-get-set-expected.txt:
     9        * fast/css-grid-layout/resources/grid-columns-rows-get-set.js:
     10        Added more testing for the single case.
     11
     12        * fast/css-grid-layout/grid-columns-rows-get-set-multiple-expected.txt: Added.
     13        * fast/css-grid-layout/grid-columns-rows-get-set-multiple.html: Added.
     14        * fast/css-grid-layout/resources/grid-columns-rows-get-set-multiple.js: Added.
     15
    1162011-12-06  Darin Adler  <darin@apple.com>
    217
  • trunk/LayoutTests/fast/css-grid-layout/grid-columns-rows-get-set-expected.txt

    r101288 r102183  
    2727PASS getComputedStyle(element, '').getPropertyValue('-webkit-grid-columns') is 'auto'
    2828PASS getComputedStyle(element, '').getPropertyValue('-webkit-grid-rows') is 'auto'
     29
     30Test setting grid-columns and grid-rows back to 'none' through JS
     31PASS getComputedStyle(element, '').getPropertyValue('-webkit-grid-columns') is '18px'
     32PASS getComputedStyle(element, '').getPropertyValue('-webkit-grid-rows') is '66px'
     33PASS getComputedStyle(element, '').getPropertyValue('-webkit-grid-columns') is 'none'
     34PASS getComputedStyle(element, '').getPropertyValue('-webkit-grid-rows') is 'none'
    2935PASS successfullyParsed is true
    3036
  • trunk/LayoutTests/fast/css-grid-layout/resources/grid-columns-rows-get-set.js

    r101288 r102183  
    4949shouldBe("getComputedStyle(element, '').getPropertyValue('-webkit-grid-columns')", "'auto'");
    5050shouldBe("getComputedStyle(element, '').getPropertyValue('-webkit-grid-rows')", "'auto'");
     51
     52debug("");
     53debug("Test setting grid-columns and grid-rows back to 'none' through JS");
     54element.style.webkitGridColumns = "18px";
     55element.style.webkitGridRows = "66px";
     56shouldBe("getComputedStyle(element, '').getPropertyValue('-webkit-grid-columns')", "'18px'");
     57shouldBe("getComputedStyle(element, '').getPropertyValue('-webkit-grid-rows')", "'66px'");
     58element.style.webkitGridColumns = "none";
     59element.style.webkitGridRows = "none";
     60shouldBe("getComputedStyle(element, '').getPropertyValue('-webkit-grid-columns')", "'none'");
     61shouldBe("getComputedStyle(element, '').getPropertyValue('-webkit-grid-rows')", "'none'");
  • trunk/Source/WebCore/ChangeLog

    r102181 r102183  
     12011-12-06  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        CSS Grid Layout: Add support for parsing multiple grid-columns or grid-rows
     4        https://bugs.webkit.org/show_bug.cgi?id=73272
     5
     6        Reviewed by Tony Chang.
     7
     8        Test: fast/css-grid-layout/grid-columns-rows-get-set-multiple.html
     9
     10        Updated our supported syntax to match the following:
     11        <track-list> := [ <track-breadth> ]+ | 'none'
     12        <track-breadth> := <length> | <percentage> | 'auto'
     13        (the naming loosely matches the specification)
     14
     15        * css/CSSComputedStyleDeclaration.cpp:
     16        (WebCore::valueForGridTrackBreadth): Added function to handle a breadth
     17        (extended with 'auto' that the spec puts in <track-minmax>).
     18
     19        (WebCore::valueForGridTrackList): Create a space seperated list of
     20        track breadth or none.
     21
     22        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Updated
     23        to use the new functions.
     24
     25        * css/CSSParser.cpp:
     26        (WebCore::CSSParser::parseGridTrackList): Extended the function to
     27        match the new syntax.
     28
     29        * css/CSSStyleApplyProperty.cpp:
     30        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty): Removed our
     31        simple implementation. Replaced by the CSSStyleSelector functions.
     32
     33        * css/CSSStyleSelector.cpp:
     34        (WebCore::createGridTrackBreadth):
     35        (WebCore::createGridTrackList):
     36        Added those 2 functions to convert the CSSPrimitiveValue to a Vector
     37        as expected by RenderStyle.
     38
     39        (WebCore::CSSStyleSelector::applyProperty): Added our 2 properties
     40        now that it is not handled by CSSStyleApplyProperty.
     41
     42        * rendering/style/RenderStyle.h:
     43        (WebCore::InheritedFlags::gridColumns):
     44        (WebCore::InheritedFlags::gridRows):
     45        (WebCore::InheritedFlags::setGridColumns):
     46        (WebCore::InheritedFlags::setGridRows):
     47        (WebCore::InheritedFlags::initialGridColumns):
     48        (WebCore::InheritedFlags::initialGridRows):
     49        Updated the previous methods to take a Vector of Length.
     50
     51        (WebCore::InheritedFlags::initialGridTrackValue):
     52        Needed function to return a Vector with one 'none' Length (the initial
     53        value per the specification).
     54
     55        * rendering/style/StyleGridData.h: Updated to use a Vector.
     56
    1572011-12-06  David Reveman  <reveman@chromium.org>
    258
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r102149 r102183  
    795795
    796796#if ENABLE(CSS_GRID_LAYOUT)
    797 static PassRefPtr<CSSValue> valueForGridTrackList(const Length& trackLength, const RenderStyle* style, CSSValuePool* cssValuePool)
     797static PassRefPtr<CSSValue> valueForGridTrackBreadth(const Length& trackLength, const RenderStyle* style, CSSValuePool* cssValuePool)
    798798{
    799799    if (trackLength.isPercent())
     
    801801    if (trackLength.isAuto())
    802802        return cssValuePool->createIdentifierValue(CSSValueAuto);
    803     if (trackLength.isUndefined())
     803    return zoomAdjustedPixelValue(trackLength.value(), style, cssValuePool);
     804}
     805
     806static PassRefPtr<CSSValue> valueForGridTrackList(const Vector<Length>& trackLengths, const RenderStyle* style, CSSValuePool* cssValuePool)
     807{
     808    // We should have at least an element!
     809    ASSERT(trackLengths.size());
     810
     811    // Handle the 'none' case here.
     812    if (trackLengths.size() == 1 && trackLengths[0].isUndefined())
    804813        return cssValuePool->createIdentifierValue(CSSValueNone);
    805     return zoomAdjustedPixelValue(trackLength.value(), style, cssValuePool);
     814
     815    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
     816    for (size_t i = 0; i < trackLengths.size(); ++i)
     817        list->append(valueForGridTrackBreadth(trackLengths[i], style, cssValuePool));
     818    return list.release();
    806819}
    807820#endif
     
    15161529#if ENABLE(CSS_GRID_LAYOUT)
    15171530        case CSSPropertyWebkitGridColumns: {
    1518             Length gridColumns = style->gridColumns();
    1519             return valueForGridTrackList(gridColumns, style.get(), cssValuePool);
     1531            return valueForGridTrackList(style->gridColumns(), style.get(), cssValuePool);
    15201532        }
    15211533        case CSSPropertyWebkitGridRows: {
    1522             Length gridRows = style->gridRows();
    1523             return valueForGridTrackList(gridRows, style.get(), cssValuePool);
     1534            return valueForGridTrackList(style->gridRows(), style.get(), cssValuePool);
    15241535        }
    15251536#endif
  • trunk/Source/WebCore/css/CSSParser.cpp

    r101998 r102183  
    35273527{
    35283528    CSSParserValue* value = m_valueList->current();
    3529     if (value->id == CSSValueNone || value->id == CSSValueAuto) {
     3529    if (value->id == CSSValueNone) {
     3530        if (m_valueList->next())
     3531            return false;
     3532
    35303533        addProperty(propId, cssValuePool()->createIdentifierValue(value->id), important);
    35313534        return true;
    35323535    }
    35333536
    3534     if (validUnit(value, FLength | FPercent, m_strict)) {
    3535         addProperty(propId, createPrimitiveNumericValue(value), important);
    3536         return true;
    3537     }
    3538     return false;
     3537    RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
     3538    while (value) {
     3539        bool valid = validUnit(value, FLength | FPercent, m_strict) || value->id == CSSValueAuto;
     3540        if (!valid)
     3541            return false;
     3542
     3543        RefPtr<CSSPrimitiveValue> primitiveValue = value->id == CSSValueAuto ? cssValuePool()->createIdentifierValue(CSSValueAuto) : createPrimitiveNumericValue(value);
     3544        values->append(primitiveValue.release());
     3545        value = m_valueList->next();
     3546    }
     3547    addProperty(propId, values.release(), important);
     3548    return true;
    35393549}
    35403550#endif
  • trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp

    r101499 r102183  
    13321332    setPropertyHandler(CSSPropertyLeft, ApplyPropertyLength<&RenderStyle::left, &RenderStyle::setLeft, &RenderStyle::initialOffset, AutoEnabled>::createHandler());
    13331333
    1334 #if ENABLE(CSS_GRID_LAYOUT)
    1335     setPropertyHandler(CSSPropertyWebkitGridColumns, ApplyPropertyLength<&RenderStyle::gridColumns, &RenderStyle::setGridColumns, &RenderStyle::initialGridColumns, AutoEnabled, IntrinsicDisabled, MinIntrinsicDisabled, NoneEnabled, UndefinedEnabled>::createHandler());
    1336     setPropertyHandler(CSSPropertyWebkitGridRows, ApplyPropertyLength<&RenderStyle::gridRows, &RenderStyle::setGridRows, &RenderStyle::initialGridRows, AutoEnabled, IntrinsicDisabled, MinIntrinsicDisabled, NoneEnabled, UndefinedEnabled>::createHandler());
    1337 #endif
    1338 
    13391334    setPropertyHandler(CSSPropertyWidth, ApplyPropertyLength<&RenderStyle::width, &RenderStyle::setWidth, &RenderStyle::initialSize, AutoEnabled, IntrinsicEnabled, MinIntrinsicEnabled, NoneDisabled, UndefinedDisabled, FlexWidth>::createHandler());
    13401335    setPropertyHandler(CSSPropertyHeight, ApplyPropertyLength<&RenderStyle::height, &RenderStyle::setHeight, &RenderStyle::initialSize, AutoEnabled, IntrinsicEnabled, MinIntrinsicEnabled, NoneDisabled, UndefinedDisabled, FlexHeight>::createHandler());
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r102063 r102183  
    25072507}
    25082508
     2509#if ENABLE(CSS_GRID_LAYOUT)
     2510
     2511static bool createGridTrackBreadth(CSSPrimitiveValue* primitiveValue, CSSStyleSelector* selector, Length& length)
     2512{
     2513    if (primitiveValue->getIdent() == CSSValueAuto) {
     2514        length = Length();
     2515        return true;
     2516    }
     2517
     2518    int type = primitiveValue->primitiveType();
     2519    if (CSSPrimitiveValue::isUnitTypeLength(type)) {
     2520        length = primitiveValue->computeLength<Length>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
     2521        length.setQuirk(primitiveValue->isQuirkValue());
     2522        return true;
     2523    }
     2524
     2525    if (type == CSSPrimitiveValue::CSS_PERCENTAGE) {
     2526        length = Length(primitiveValue->getDoubleValue(), Percent);
     2527        return true;
     2528    }
     2529
     2530    return false;
     2531}
     2532
     2533static bool createGridTrackList(CSSValue* value, Vector<Length>& lengths, CSSStyleSelector* selector)
     2534{
     2535    // Handle 'none'.
     2536    if (value->isPrimitiveValue()) {
     2537        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
     2538        if (primitiveValue->getIdent() == CSSValueNone) {
     2539            lengths.append(Length(Undefined));
     2540            return true;
     2541        }
     2542        return false;
     2543    }
     2544
     2545    if (value->isValueList()) {
     2546        for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
     2547            CSSValue* currValue = i.value();
     2548            if (!currValue->isPrimitiveValue())
     2549                return false;
     2550
     2551            Length length;
     2552            if (!createGridTrackBreadth(static_cast<CSSPrimitiveValue*>(currValue), selector, length))
     2553                return false;
     2554
     2555            lengths.append(length);
     2556        }
     2557        return true;
     2558    }
     2559
     2560    return false;
     2561}
     2562#endif
     2563
    25092564void CSSStyleSelector::applyProperty(int id, CSSValue *value)
    25102565{
     
    37593814        createFilterOperations(value, style(), m_rootElementStyle, operations);
    37603815        m_style->setFilter(operations);
     3816        return;
     3817    }
     3818#endif
     3819#if ENABLE(CSS_GRID_LAYOUT)
     3820    case CSSPropertyWebkitGridColumns: {
     3821        Vector<Length> lengths;
     3822        if (!createGridTrackList(value, lengths, this))
     3823            return;
     3824        m_style->setGridColumns(lengths);
     3825        return;
     3826    }
     3827    case CSSPropertyWebkitGridRows: {
     3828        Vector<Length> lengths;
     3829        if (!createGridTrackList(value, lengths, this))
     3830            return;
     3831        m_style->setGridRows(lengths);
    37613832        return;
    37623833    }
     
    38253896    case CSSPropertyFontStyle:
    38263897    case CSSPropertyFontVariant:
    3827 #if ENABLE(CSS_GRID_LAYOUT)
    3828     case CSSPropertyWebkitGridColumns:
    3829     case CSSPropertyWebkitGridRows:
    3830 #endif
    38313898    case CSSPropertyTextRendering:
    38323899    case CSSPropertyWebkitTextOrientation:
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r101524 r102183  
    730730
    731731#if ENABLE(CSS_GRID_LAYOUT)
    732     Length gridColumns() const { return rareNonInheritedData->m_grid->m_gridColumns; }
    733     Length gridRows() const { return rareNonInheritedData->m_grid->m_gridRows; }
     732    const Vector<Length>& gridColumns() const { return rareNonInheritedData->m_grid->m_gridColumns; }
     733    const Vector<Length>& gridRows() const { return rareNonInheritedData->m_grid->m_gridRows; }
    734734#endif
    735735
     
    11471147    void setFlexFlow(EFlexFlow flow) { SET_VAR(rareNonInheritedData.access()->m_flexibleBox, m_flexFlow, flow); }
    11481148#if ENABLE(CSS_GRID_LAYOUT)
    1149     void setGridColumns(Length length) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridColumns, length); }
    1150     void setGridRows(Length length) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridRows, length); }
     1149    void setGridColumns(const Vector<Length>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridColumns, lengths); }
     1150    void setGridRows(const Vector<Length>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridRows, lengths); }
    11511151#endif
    11521152
     
    15261526
    15271527#if ENABLE(CSS_GRID_LAYOUT)
    1528     static Length initialGridColumns() { return Length(Undefined); }
    1529     static Length initialGridRows() { return Length(Undefined); }
     1528    // The initial value is 'none' for grid tracks.
     1529    static Vector<Length> initialGridTrackValue()
     1530    {
     1531        static Vector<Length> defaultLength;
     1532        // We need to manually add the Length here as the Length(0) is 'auto'.
     1533        if (!defaultLength.size())
     1534            defaultLength.append(Length(Undefined));
     1535        return defaultLength;
     1536    }
     1537    static Vector<Length> initialGridColumns() { return initialGridTrackValue(); }
     1538    static Vector<Length> initialGridRows() { return initialGridTrackValue(); }
    15301539#endif
    15311540
  • trunk/Source/WebCore/rendering/style/StyleGridData.h

    r101288 r102183  
    3232#include <wtf/PassRefPtr.h>
    3333#include <wtf/RefCounted.h>
     34#include <wtf/Vector.h>
    3435
    3536namespace WebCore {
     
    5253    // FIXME: For the moment, we only support a subset of the grammar which correspond to:
    5354    // 'auto' | <length> | <percentage> | 'none'
    54     Length m_gridColumns;
    55     Length m_gridRows;
     55    Vector<Length> m_gridColumns;
     56    Vector<Length> m_gridRows;
    5657
    5758private:
Note: See TracChangeset for help on using the changeset viewer.