Changeset 214852 in webkit


Ignore:
Timestamp:
Apr 3, 2017 4:08:42 PM (7 years ago)
Author:
jfernandez@igalia.com
Message:

[css-align] Adapt place-content alignment shorthand to the new baseline syntax
https://bugs.webkit.org/show_bug.cgi?id=170340

Reviewed by David Hyatt.

Source/WebCore:

Now that the align-content and justify-content CSS properties are
adapted to the new baseline-position CSS values syntax we can adapt the
shorthand that controls such properties to the new syntax as well.

No new tests, just adding some additional cases to the tests we already have.

  • css/StyleProperties.cpp:

(WebCore::StyleProperties::getPropertyValue):
(WebCore::StyleProperties::placeContentPropertyValue):

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

(WebCore::isContentDistributionKeyword):
(WebCore::isContentPositionKeyword):
(WebCore::isOverflowKeyword):
(WebCore::getBaselineKeyword):
(WebCore::consumeContentDistributionOverflowPosition):
(WebCore::consumeSimplifiedContentPosition):

LayoutTests:

Added additional test cases to evaluate the new baseline-alignment syntax.

  • css3/parse-place-content-expected.txt:
  • css3/parse-place-content.html:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r214851 r214852  
     12017-04-03  Javier Fernandez  <jfernandez@igalia.com>
     2
     3        [css-align] Adapt place-content alignment shorthand to the new baseline syntax
     4        https://bugs.webkit.org/show_bug.cgi?id=170340
     5
     6        Reviewed by David Hyatt.
     7
     8        Added additional test cases to evaluate the new baseline-alignment syntax.
     9
     10        * css3/parse-place-content-expected.txt:
     11        * css3/parse-place-content.html:
     12
    1132017-04-03  Nan Wang  <n_wang@apple.com>
    214
  • trunk/LayoutTests/css3/parse-place-content-expected.txt

    r213230 r214852  
    44PASS Test getting the Computed Value of place-content's longhand properties when setting 'normal' value through CSS.
    55PASS Test getting the Computed Value of place-content's longhand properties when setting 'baseline' value through CSS.
     6PASS Test getting the Computed Value of place-content's longhand properties when setting 'first baseline' value through CSS.
     7PASS Test getting the Computed Value of place-content's longhand properties when setting 'last baseline' value through CSS.
    68PASS Test getting the Computed Value of place-content's longhand properties when setting 'start' value through CSS.
    79PASS Test getting the Computed Value of place-content's longhand properties when setting 'flex-start' value through CSS.
     
    1921PASS Test setting 'baseline safe' as incorrect value through CSS.
    2022PASS Test setting 'start end left' as incorrect value through CSS.
    21 FAIL Test setting values through JS. assert_equals: placeContent specified value is not what it should. expected "center" but got "center center"
     23PASS Test setting values through JS.
    2224PASS Test setting incorrect values through JS.
    2325PASS Test the 'initial' value of the place-content shorthand and its longhand properties' Computed value
  • trunk/LayoutTests/css3/parse-place-content.html

    r213230 r214852  
    88#placeContentBaseline {
    99    place-content: baseline;
     10}
     11#placeContentFirstBaseline {
     12    place-content: first baseline;
     13}
     14#placeContentLastBaseline {
     15    place-content: last baseline;
    1016}
    1117#placeContentStart {
     
    6470    <div id="placeContentNormal"></div>
    6571    <div id="placeContentBaseline"></div>
     72    <div id="placeContentFirstBaseline"></div>
     73    <div id="placeContentLastBaseline"></div>
    6674    <div id="placeContentStart"></div>
    6775    <div id="placeContentFlexStart"></div>
     
    8391function checkPlaceContentValues(element, value, alignValue, justifyValue)
    8492{
    85      var res = value.split(" ");
    86      if (res.length < 2)
    87          res[1] = res[0];
    88      checkValues(element, "alignContent", "align-content", res[0], alignValue);
    89      checkValues(element, "justifyContent", "justify-content", res[1], justifyValue);
     93    var res = value.split(" ");
     94    var alignContentSpecified = res[0];
     95    var justifyContentSpecified = "";
     96    if (res[0] === "first" || res[0] === "last") {
     97        alignContentSpecified = res[0] + " " + res[1];
     98        if (res.length > 2)
     99            justifyContentSpecified = res.slice(2).join(" ");
     100    } else {
     101        justifyContentSpecified = res.slice(1).join(" ");
     102    }
     103
     104    if (justifyContentSpecified === "")
     105         justifyContentSpecified = alignContentSpecified;
     106     checkValues(element, "alignContent", "align-content", alignContentSpecified, alignValue);
     107     checkValues(element, "justifyContent", "justify-content", justifyContentSpecified, justifyValue);
    90108}
    91109
    92110function checkPlaceContentValuesJS(value, alignValue, justifyValue)
    93111{
    94    element = document.createElement("div");
    95    document.body.appendChild(element);
    96    element.style.placeContent = value;
    97    checkValues(element, "placeContent", "place-content", value, alignValue + ' ' + justifyValue)
    98    checkPlaceContentValues(element, value, alignValue, justifyValue)
     112    element = document.createElement("div");
     113    document.body.appendChild(element);
     114    element.style.placeContent = value;
     115    checkValues(element, "placeContent", "place-content", value, alignValue + ' ' + justifyValue)
     116    checkPlaceContentValues(element, value, alignValue, justifyValue)
    99117}
    100118
     
    140158
    141159test(function() {
     160    checkValues(placeContentFirstBaseline, "placeContent", "place-content", "", "baseline baseline");
     161    checkPlaceContentValues(placeContentFirstBaseline, "", "baseline", "baseline");
     162}, "Test getting the Computed Value of place-content's longhand properties when setting 'first baseline' value through CSS.");
     163
     164test(function() {
     165    checkValues(placeContentLastBaseline, "placeContent", "place-content", "", "last baseline last baseline");
     166    checkPlaceContentValues(placeContentLastBaseline, "", "last baseline", "last baseline");
     167}, "Test getting the Computed Value of place-content's longhand properties when setting 'last baseline' value through CSS.");
     168
     169test(function() {
    142170    checkValues(placeContentStart, "placeContent", "place-content", "", "start start");
    143171    checkPlaceContentValues(placeContentStart, "", "start", "start");
     
    215243
    216244test(function() {
    217     // FIXME: We will get FAIL for placeContent specified values tests because we still don't know how to serialize this shortand.
    218     // https://github.com/w3c/csswg-drafts/issues/1041
    219245    checkPlaceContentValuesJS("center", "center", "center");
    220     checkPlaceContentValuesJS("start start", "start", "start");
    221246    checkPlaceContentValuesJS("center start", "center", "start");
    222247    checkPlaceContentValuesJS("space-between end", "space-between", "end");
     
    232257    checkPlaceContentValuesBadJS("stretch safe", "normal", "normal");
    233258    checkPlaceContentValuesBadJS("space-between start end", "normal", "normal");
     259    checkPlaceContentValuesBadJS("", "normal", "normal");
    234260}, "Test setting incorrect values through JS.");
    235261
  • trunk/Source/WebCore/ChangeLog

    r214851 r214852  
     12017-04-03  Javier Fernandez  <jfernandez@igalia.com>
     2
     3        [css-align] Adapt place-content alignment shorthand to the new baseline syntax
     4        https://bugs.webkit.org/show_bug.cgi?id=170340
     5
     6        Reviewed by David Hyatt.
     7
     8        Now that the align-content and justify-content CSS properties are
     9        adapted to the new baseline-position CSS values syntax we can adapt the
     10        shorthand that controls such properties to the new syntax as well.
     11
     12        No new tests, just adding some additional cases to the tests we already have.
     13
     14        * css/StyleProperties.cpp:
     15        (WebCore::StyleProperties::getPropertyValue):
     16        (WebCore::StyleProperties::placeContentPropertyValue):
     17        * css/StyleProperties.h:
     18        * css/parser/CSSPropertyParser.cpp:
     19        (WebCore::isContentDistributionKeyword):
     20        (WebCore::isContentPositionKeyword):
     21        (WebCore::isOverflowKeyword):
     22        (WebCore::getBaselineKeyword):
     23        (WebCore::consumeContentDistributionOverflowPosition):
     24        (WebCore::consumeSimplifiedContentPosition):
     25
    1262017-04-03  Nan Wang  <n_wang@apple.com>
    227
  • trunk/Source/WebCore/css/StyleProperties.cpp

    r214383 r214852  
    187187        return getShorthandValue(gridRowShorthand());
    188188    case CSSPropertyPlaceContent:
    189         return getShorthandValue(placeContentShorthand());
     189        return placeContentPropertyValue();
    190190    case CSSPropertyFont:
    191191        return fontValue();
     
    584584}
    585585
     586String StyleProperties::placeContentPropertyValue() const
     587{
     588    String value = getCommonValue(placeContentShorthand());
     589    if (value.isNull() || value.isEmpty())
     590        return getShorthandValue(placeContentShorthand());
     591    return value;
     592}
     593
    586594String StyleProperties::borderPropertyValue(CommonValueMode valueMode) const
    587595{
  • trunk/Source/WebCore/css/StyleProperties.h

    r209826 r214852  
    158158    String getShorthandValue(const StylePropertyShorthand&) const;
    159159    String getCommonValue(const StylePropertyShorthand&) const;
     160    String placeContentPropertyValue() const;
    160161    enum CommonValueMode { OmitUncommonValues, ReturnNullOnUncommonValues };
    161162    String borderPropertyValue(CommonValueMode) const;
  • trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp

    r214624 r214852  
    26202620}
    26212621
     2622static bool isContentDistributionKeyword(CSSValueID id)
     2623{
     2624    return identMatches<CSSValueSpaceBetween, CSSValueSpaceAround, CSSValueSpaceEvenly, CSSValueStretch>(id);
     2625}
     2626
     2627static bool isContentPositionKeyword(CSSValueID id)
     2628{
     2629    return identMatches<CSSValueStart, CSSValueEnd, CSSValueCenter, CSSValueFlexStart, CSSValueFlexEnd, CSSValueLeft, CSSValueRight>(id);
     2630}
     2631
     2632static bool isOverflowKeyword(CSSValueID id)
     2633{
     2634    return CSSPropertyParserHelpers::identMatches<CSSValueUnsafe, CSSValueSafe>(id);
     2635}
     2636
    26222637static bool isBaselineKeyword(CSSValueID id)
    26232638{
    26242639    return identMatches<CSSValueFirst, CSSValueLast, CSSValueBaseline>(id);
     2640}
     2641
     2642static CSSValueID getBaselineKeyword(RefPtr<CSSValue> value)
     2643{
     2644    auto& primitiveValue = downcast<CSSPrimitiveValue>(*value);
     2645    if (auto* pairValue = primitiveValue.pairValue()) {
     2646        ASSERT(pairValue->second()->valueID() == CSSValueBaseline);
     2647        if (pairValue->first()->valueID() == CSSValueLast)
     2648            return CSSValueLastBaseline;
     2649        return CSSValueFirstBaseline;
     2650    }
     2651    ASSERT(primitiveValue.valueID() == CSSValueBaseline);
     2652    return CSSValueBaseline;
    26252653}
    26262654
     
    26492677        if (!baseline)
    26502678            return nullptr;
    2651         CSSValueID baselineID = CSSValueBaseline;
    2652         auto& primitiveValue = downcast<CSSPrimitiveValue>(*baseline);
    2653         if (auto* pairValue = primitiveValue.pairValue()) {
    2654             if (pairValue->first()->valueID() == CSSValueLast)
    2655                 baselineID = CSSValueLastBaseline;
    2656             else
    2657                 baselineID = CSSValueFirstBaseline;
    2658         }
    2659         return CSSContentDistributionValue::create(CSSValueInvalid, baselineID, CSSValueInvalid);
     2679        return CSSContentDistributionValue::create(CSSValueInvalid, getBaselineKeyword(baseline), CSSValueInvalid);
    26602680    }
    26612681
     
    26652685    do {
    26662686        CSSValueID id = range.peek().id();
    2667         if (identMatches<CSSValueSpaceBetween, CSSValueSpaceAround, CSSValueSpaceEvenly, CSSValueStretch>(id)) {
     2687        if (isContentDistributionKeyword(id)) {
    26682688            if (distribution != CSSValueInvalid)
    26692689                return nullptr;
    26702690            distribution = id;
    2671         } else if (identMatches<CSSValueStart, CSSValueEnd, CSSValueCenter, CSSValueFlexStart, CSSValueFlexEnd, CSSValueLeft, CSSValueRight>(id)) {
     2691        } else if (isContentPositionKeyword(id)) {
    26722692            if (position != CSSValueInvalid)
    26732693                return nullptr;
    26742694            position = id;
    2675         } else if (identMatches<CSSValueUnsafe, CSSValueSafe>(id)) {
     2695        } else if (isOverflowKeyword(id)) {
    26762696            if (overflow != CSSValueInvalid)
    26772697                return nullptr;
     
    54525472{
    54535473    CSSValueID id = range.peek().id();
    5454     if (identMatches<CSSValueNormal, CSSValueBaseline, CSSValueLastBaseline>(id))
     5474    if (identMatches<CSSValueNormal>(id) || isContentPositionKeyword(id))
    54555475        return CSSContentDistributionValue::create(CSSValueInvalid, range.consumeIncludingWhitespace().id(), CSSValueInvalid);
    5456     if (identMatches<CSSValueSpaceBetween, CSSValueSpaceAround, CSSValueSpaceEvenly, CSSValueStretch>(id))
     5476    if (isBaselineKeyword(id)) {
     5477        RefPtr<CSSValue> baseline = consumeBaselineKeyword(range);
     5478        if (!baseline)
     5479            return nullptr;
     5480        return CSSContentDistributionValue::create(CSSValueInvalid, getBaselineKeyword(baseline.releaseNonNull()), CSSValueInvalid);
     5481    }
     5482    if (isContentDistributionKeyword(id))
    54575483        return CSSContentDistributionValue::create(range.consumeIncludingWhitespace().id(), CSSValueInvalid, CSSValueInvalid);
    5458     if (identMatches<CSSValueStart, CSSValueEnd, CSSValueCenter, CSSValueFlexStart, CSSValueFlexEnd, CSSValueLeft, CSSValueRight>(id))
    5459         return CSSContentDistributionValue::create(CSSValueInvalid, range.consumeIncludingWhitespace().id(), CSSValueInvalid);
    54605484    return nullptr;
    54615485}
Note: See TracChangeset for help on using the changeset viewer.