Changeset 182270 in webkit


Ignore:
Timestamp:
Apr 2, 2015 1:51:23 AM (9 years ago)
Author:
commit-queue@webkit.org
Message:

[CSS MultiColumn] Parse "columns: auto <length>" shorthand property value properly
https://bugs.webkit.org/show_bug.cgi?id=143248

Patch by Joonghun Park <jh718.park@samsung.com> on 2015-04-02
Reviewed by Darin Adler.

Source/WebCore:

Test: fast/multicol/columns-shorthand-parsing-2.html

The two longhands for the 'columns' property ('column-count' and
'column-width') may both take 'auto' as a value. When we encounter
'auto' during parsing the value list of a declaration, we cannot just
make a guess at which property/properties that's meant for. Instead,
don't assign anything to 'auto' right away, but wait until all values
have been processed and at that point set the still unassigned
properties to 'auto'. If 'auto' isn't in the value list at all, set
unassigned properties to 'initial' for the 'columns' property, just
like we do for any other property.

  • css/CSSParser.cpp:

(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseColumnWidth):
(WebCore::CSSParser::parseColumnCount):
(WebCore::CSSParser::parseColumnsShorthand):

  • css/CSSParser.h:

LayoutTests:

  • fast/css/getPropertyValue-columns-expected.txt:
  • fast/css/getPropertyValue-columns.html:
  • fast/multicol/columns-shorthand-parsing-2-expected.txt: Added.
  • fast/multicol/columns-shorthand-parsing-2.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r182266 r182270  
     12015-04-02  Joonghun Park  <jh718.park@samsung.com>
     2
     3        [CSS MultiColumn] Parse "columns: auto <length>" shorthand property value properly
     4        https://bugs.webkit.org/show_bug.cgi?id=143248
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/css/getPropertyValue-columns-expected.txt:
     9        * fast/css/getPropertyValue-columns.html:
     10        * fast/multicol/columns-shorthand-parsing-2-expected.txt: Added.
     11        * fast/multicol/columns-shorthand-parsing-2.html: Added.
     12
    1132015-04-01  Commit Queue  <commit-queue@webkit.org>
    214
  • trunk/LayoutTests/fast/css/getPropertyValue-columns-expected.txt

    r144730 r182270  
    1 Bug 111011: getPropertyValue for -webkit-columns returns null, should compute the shorthand value
     1Bug 111011: getPropertyValue for columns returns null, should compute the shorthand value
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
    44
    55
    6 PASS webkitColumnsValue("columns1") is "10px"
    7 PASS webkitColumnsValue("columns2") is "10"
    8 PASS webkitColumnsValue("columns3") is "10px auto"
    9 PASS webkitColumnsValue("columns4") is "auto"
    10 PASS webkitColumnsValue("columns5") is "auto 2"
    11 PASS webkitColumnsValue("columns6") is "10px 2"
    12 PASS webkitColumnsValue("columns7") is "auto auto"
    13 NOTE: 'foo' is an illegal CSS value for '-webkit-columns'.
    14 PASS webkitColumnsValue("columns8") is null
     6PASS columnsValue("columns1") is "10px"
     7PASS columnsValue("columns2") is "10"
     8PASS columnsValue("columns3") is "10px auto"
     9PASS columnsValue("columns4") is "auto"
     10PASS columnsValue("columns5") is "auto 2"
     11PASS columnsValue("columns6") is "10px 2"
     12PASS columnsValue("columns7") is "auto auto"
     13NOTE: 'foo' is an illegal CSS value for 'columns'.
     14PASS columnsValue("columns8") is null
    1515NOTE: If only few longhand properties are specified, getPropertyValue for shorthand property returns null.
    16 PASS webkitColumnsValue("columns9") is null
     16PASS columnsValue("columns9") is null
    1717PASS successfullyParsed is true
    1818
  • trunk/LayoutTests/fast/css/getPropertyValue-columns.html

    r155263 r182270  
    22</html>
    33  <head>
    4     <title>-webkit-columns shorthand getPropertyValue test</title>
     4    <title>columns shorthand getPropertyValue test</title>
    55    <style>
    66      .test {
     
    1616  </head>
    1717  <body>
    18     <div id="columns1" class="test" style="-webkit-columns: 10px;"></div>
    19     <div id="columns2" class="test" style="-webkit-columns: 10;"></div>
    20     <div id="columns3" class="test" style="-webkit-columns: 10px auto;"></div>
    21     <div id="columns4" class="test" style="-webkit-columns: auto;"></div>
    22     <div id="columns5" class="test" style="-webkit-columns: auto 2;"></div>
    23     <div id="columns6" class="test" style="-webkit-column-width: 10px; -webkit-column-count: 2;"></div>
    24     <div id="columns7" class="test" style="-webkit-column-width: auto; -webkit-column-count: auto;"></div>
    25     <div id="columns8" class="test" style="-webkit-columns: foo;"></div>
    26     <div id="columns9" class="test" style="-webkit-column-width: 10px;"></div>
     18    <div id="columns1" class="test" style="columns: 10px;"></div>
     19    <div id="columns2" class="test" style="columns: 10;"></div>
     20    <div id="columns3" class="test" style="columns: 10px auto;"></div>
     21    <div id="columns4" class="test" style="columns: auto;"></div>
     22    <div id="columns5" class="test" style="columns: auto 2;"></div>
     23    <div id="columns6" class="test" style="column-width: 10px; column-count: 2;"></div>
     24    <div id="columns7" class="test" style="column-width: auto; column-count: auto;"></div>
     25    <div id="columns8" class="test" style="columns: foo;"></div>
     26    <div id="columns9" class="test" style="column-width: 10px;"></div>
    2727    <script>
    28       description("<a href=\"https://bugs.webkit.org/show_bug.cgi?id=111011\">Bug 111011: getPropertyValue for -webkit-columns returns null, should compute the shorthand value</a>");
     28      description("<a href=\"https://bugs.webkit.org/show_bug.cgi?id=111011\">Bug 111011: getPropertyValue for columns returns null, should compute the shorthand value</a>");
    2929
    30       function webkitColumnsValue(id) {
     30      function columnsValue(id) {
    3131        var element = document.getElementById(id);
    32         return element.style.getPropertyValue("-webkit-columns");
     32        return element.style.getPropertyValue("columns");
    3333      }
    3434
    35       shouldBeEqualToString('webkitColumnsValue("columns1")', '10px');
    36       shouldBeEqualToString('webkitColumnsValue("columns2")', '10');
    37       shouldBeEqualToString('webkitColumnsValue("columns3")', '10px auto');
    38       shouldBeEqualToString('webkitColumnsValue("columns4")', 'auto');
    39       shouldBeEqualToString('webkitColumnsValue("columns5")', 'auto 2');
    40       shouldBeEqualToString('webkitColumnsValue("columns6")', '10px 2');
    41       shouldBeEqualToString('webkitColumnsValue("columns7")', 'auto auto');
    42       debug("NOTE: 'foo' is an illegal CSS value for '-webkit-columns'.");
    43       shouldBe('webkitColumnsValue("columns8")', "null");
     35      shouldBeEqualToString('columnsValue("columns1")', '10px');
     36      shouldBeEqualToString('columnsValue("columns2")', '10');
     37      shouldBeEqualToString('columnsValue("columns3")', '10px auto');
     38      shouldBeEqualToString('columnsValue("columns4")', 'auto');
     39      shouldBeEqualToString('columnsValue("columns5")', 'auto 2');
     40      shouldBeEqualToString('columnsValue("columns6")', '10px 2');
     41      shouldBeEqualToString('columnsValue("columns7")', 'auto auto');
     42      debug("NOTE: 'foo' is an illegal CSS value for 'columns'.");
     43      shouldBe('columnsValue("columns8")', "null");
    4444      debug("NOTE: If only few longhand properties are specified, getPropertyValue for shorthand property returns null.")
    45       shouldBe('webkitColumnsValue("columns9")', "null");
     45      shouldBe('columnsValue("columns9")', "null");
    4646    </script>
    4747    <script src="../../resources/js-test-post.js"></script>
  • trunk/Source/WebCore/ChangeLog

    r182266 r182270  
     12015-04-02  Joonghun Park  <jh718.park@samsung.com>
     2
     3        [CSS MultiColumn] Parse "columns: auto <length>" shorthand property value properly
     4        https://bugs.webkit.org/show_bug.cgi?id=143248
     5
     6        Reviewed by Darin Adler.
     7
     8        Test: fast/multicol/columns-shorthand-parsing-2.html
     9
     10        The two longhands for the 'columns' property ('column-count' and
     11        'column-width') may both take 'auto' as a value. When we encounter
     12        'auto' during parsing the value list of a declaration, we cannot just
     13        make a guess at which property/properties that's meant for. Instead,
     14        don't assign anything to 'auto' right away, but wait until all values
     15        have been processed and at that point set the still unassigned
     16        properties to 'auto'. If 'auto' isn't in the value list at all, set
     17        unassigned properties to 'initial' for the 'columns' property, just
     18        like we do for any other property.
     19
     20        * css/CSSParser.cpp:
     21        (WebCore::CSSParser::parseValue):
     22        (WebCore::CSSParser::parseColumnWidth):
     23        (WebCore::CSSParser::parseColumnCount):
     24        (WebCore::CSSParser::parseColumnsShorthand):
     25        * css/CSSParser.h:
     26
    1272015-04-01  Commit Queue  <commit-queue@webkit.org>
    228
  • trunk/Source/WebCore/css/CSSParser.cpp

    r182147 r182270  
    27642764        break;
    27652765    case CSSPropertyColumnCount:
    2766         if (id == CSSValueAuto)
    2767             validPrimitive = true;
    2768         else
    2769             validPrimitive = !id && validateUnit(valueWithCalculation, FPositiveInteger, CSSQuirksMode);
     2766        parsedValue = parseColumnCount();
    27702767        break;
    27712768    case CSSPropertyColumnGap: // normal | <length>
     
    27922789        break;
    27932790    case CSSPropertyColumnWidth: // auto | <length>
    2794         if (id == CSSValueAuto)
    2795             validPrimitive = true;
    2796         else {
    2797             // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property.
    2798             validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg, CSSStrictMode) && parsedDouble(valueWithCalculation);
    2799         }
     2791        parsedValue = parseColumnWidth();
    28002792        break;
    28012793    // End of CSS3 properties
     
    29582950        return parseShorthand(propId, listStyleShorthand(), important);
    29592951    case CSSPropertyColumns:
    2960         return parseShorthand(propId, columnsShorthand(), important);
     2952        return parseColumnsShorthand(important);
    29612953    case CSSPropertyColumnRule:
    29622954        return parseShorthand(propId, columnRuleShorthand(), important);
     
    36083600        addProperty(shorthand.properties()[i], values[i].release(), important);
    36093601    }
     3602
     3603    return true;
     3604}
     3605
     3606RefPtr<CSSValue> CSSParser::parseColumnWidth()
     3607{
     3608    ValueWithCalculation valueWithCalculation(*m_valueList->current());
     3609    CSSValueID id = valueWithCalculation.value().id;
     3610    // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property.
     3611    if (id != CSSValueAuto && !(validateUnit(valueWithCalculation, FLength | FNonNeg, CSSStrictMode) && parsedDouble(valueWithCalculation)))
     3612        return nullptr;
     3613
     3614    RefPtr<CSSValue> parsedValue = parseValidPrimitive(id, valueWithCalculation);
     3615    m_valueList->next();
     3616    return parsedValue;
     3617}
     3618
     3619RefPtr<CSSValue> CSSParser::parseColumnCount()
     3620{
     3621    ValueWithCalculation valueWithCalculation(*m_valueList->current());
     3622    CSSValueID id = valueWithCalculation.value().id;
     3623
     3624    if (id != CSSValueAuto && !validateUnit(valueWithCalculation, FPositiveInteger, CSSQuirksMode))
     3625        return nullptr;
     3626
     3627    RefPtr<CSSValue> parsedValue = parseValidPrimitive(id, valueWithCalculation);
     3628    m_valueList->next();
     3629    return parsedValue;
     3630}
     3631
     3632bool CSSParser::parseColumnsShorthand(bool important)
     3633{
     3634    RefPtr<CSSValue> columnWidth;
     3635    RefPtr<CSSValue> columnCount;
     3636    bool hasPendingExplicitAuto = false;
     3637
     3638    for (unsigned propertiesParsed = 0; CSSParserValue* value = m_valueList->current(); propertiesParsed++) {
     3639        if (propertiesParsed >= 2)
     3640            return false; // Too many values for this shorthand. Invalid declaration.
     3641        if (!propertiesParsed && value->id == CSSValueAuto) {
     3642            // 'auto' is a valid value for any of the two longhands, and at this point
     3643            // we don't know which one(s) it is meant for. We need to see if there are other values first.
     3644            m_valueList->next();
     3645            hasPendingExplicitAuto = true;
     3646        } else {
     3647            if (!columnWidth) {
     3648                if ((columnWidth = parseColumnWidth()))
     3649                    continue;
     3650            }
     3651            if (!columnCount) {
     3652                if ((columnCount = parseColumnCount()))
     3653                    continue;
     3654            }
     3655            // If we didn't find at least one match, this is an invalid shorthand and we have to ignore it.
     3656            return false;
     3657        }
     3658    }
     3659
     3660    // Any unassigned property at this point will become implicit 'auto'.
     3661    if (columnWidth)
     3662        addProperty(CSSPropertyColumnWidth, columnWidth, important);
     3663    else {
     3664        addProperty(CSSPropertyColumnWidth, cssValuePool().createIdentifierValue(CSSValueAuto), important, !hasPendingExplicitAuto /* implicit */);
     3665        hasPendingExplicitAuto = false;
     3666    }
     3667
     3668    if (columnCount)
     3669        addProperty(CSSPropertyColumnCount, columnCount, important);
     3670    else
     3671        addProperty(CSSPropertyColumnCount, cssValuePool().createIdentifierValue(CSSValueAuto), important, !hasPendingExplicitAuto /* implicit */);
    36103672
    36113673    return true;
  • trunk/Source/WebCore/css/CSSParser.h

    r182147 r182270  
    193193    bool parseAnimationShorthand(CSSPropertyID, bool important);
    194194
     195    RefPtr<CSSValue> parseColumnWidth();
     196    RefPtr<CSSValue> parseColumnCount();
     197    bool parseColumnsShorthand(bool important);
     198
    195199#if ENABLE(CSS_GRID_LAYOUT)
    196200    PassRefPtr<CSSValue> parseGridPosition();
Note: See TracChangeset for help on using the changeset viewer.