Changeset 201373 in webkit


Ignore:
Timestamp:
May 25, 2016 2:22:37 AM (8 years ago)
Author:
Manuel Rego Casasnovas
Message:

[css-grid] Simplify grid track sizes parsing
https://bugs.webkit.org/show_bug.cgi?id=158021

Reviewed by Sergio Villar Senin.

Previously once we saw an auto-repeat function,
we passed the "FixedSizeOnly" restriction to the rest of methods.
That way we were sure that all the tracks after the auto-repeat
had fixed sizes.
But we needed to call allTracksAreFixedSized() to be sure that
the tracks before the auto-repeat had fixed sizes too.

Now we're introducing a new boolean |allTracksAreFixedSized|,
to check in advance if the declaration contains any track not fixed.
If that's the case and we found an auto-repeat method,
we consider it invalid.
With this approach we avoid the loop to verify
that all the tracks (before and after the auto-repeat) are fixed.
It also allows us to simplify the code and avoid passing
the restriction to all the methods parsing the track size.

No new tests, no change of behavior.

  • css/CSSParser.cpp:

(WebCore::isGridTrackFixedSized): New method to check if a grid track
size is fixed or not (based on old allTracksAreFixedSized()).
(WebCore::CSSParser::parseGridTrackList): Add new boolean to detect
if any track has not a fixed size.
(WebCore::CSSParser::parseGridTrackRepeatFunction): Ditto.
(WebCore::CSSParser::parseGridTrackSize): Remove usage of
TrackSizeRestriction enum.
Check here if |minTrackBreadth| is a flexible size.
(WebCore::CSSParser::parseGridBreadth): Remove usage of
TrackSizeRestriction enum.
(WebCore::allTracksAreFixedSized): Deleted.

  • css/CSSParser.h: Remove TrackSizeRestriction enum and update headers.
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r201358 r201373  
     12016-05-25  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [css-grid] Simplify grid track sizes parsing
     4        https://bugs.webkit.org/show_bug.cgi?id=158021
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        Previously once we saw an auto-repeat function,
     9        we passed the "FixedSizeOnly" restriction to the rest of methods.
     10        That way we were sure that all the tracks after the auto-repeat
     11        had fixed sizes.
     12        But we needed to call allTracksAreFixedSized() to be sure that
     13        the tracks before the auto-repeat had fixed sizes too.
     14
     15        Now we're introducing a new boolean |allTracksAreFixedSized|,
     16        to check in advance if the declaration contains any track not fixed.
     17        If that's the case and we found an auto-repeat method,
     18        we consider it invalid.
     19        With this approach we avoid the loop to verify
     20        that all the tracks (before and after the auto-repeat) are fixed.
     21        It also allows us to simplify the code and avoid passing
     22        the restriction to all the methods parsing the track size.
     23
     24        No new tests, no change of behavior.
     25
     26        * css/CSSParser.cpp:
     27        (WebCore::isGridTrackFixedSized): New method to check if a grid track
     28        size is fixed or not (based on old allTracksAreFixedSized()).
     29        (WebCore::CSSParser::parseGridTrackList): Add new boolean to detect
     30        if any track has not a fixed size.
     31        (WebCore::CSSParser::parseGridTrackRepeatFunction): Ditto.
     32        (WebCore::CSSParser::parseGridTrackSize): Remove usage of
     33        TrackSizeRestriction enum.
     34        Check here if |minTrackBreadth| is a flexible size.
     35        (WebCore::CSSParser::parseGridBreadth): Remove usage of
     36        TrackSizeRestriction enum.
     37        (WebCore::allTracksAreFixedSized): Deleted.
     38        * css/CSSParser.h: Remove TrackSizeRestriction enum and update headers.
     39
    1402016-05-24  Myles C. Maxfield  <mmaxfield@apple.com>
    241
  • trunk/Source/WebCore/css/CSSParser.cpp

    r201325 r201373  
    58185818}
    58195819
    5820 static bool allTracksAreFixedSized(CSSValueList& valueList)
    5821 {
    5822     for (auto& value : valueList) {
    5823         if (is<CSSGridLineNamesValue>(value))
    5824             continue;
    5825         // The auto-repeat value holds a <fixed-size> = <fixed-breadth> | minmax( <fixed-breadth>, <track-breadth> )
    5826         if (is<CSSGridAutoRepeatValue>(value)) {
    5827             if (!allTracksAreFixedSized(downcast<CSSValueList>(value.get())))
    5828                 return false;
    5829             continue;
    5830         }
    5831         ASSERT(value->isPrimitiveValue() || (value->isFunctionValue() && downcast<CSSFunctionValue>(value.get()).arguments()));
    5832         const CSSPrimitiveValue& primitiveValue = value->isPrimitiveValue()
    5833             ? downcast<CSSPrimitiveValue>(value.get())
    5834             : downcast<CSSPrimitiveValue>(*downcast<CSSFunctionValue>(value.get()).arguments()->item(0));
    5835         CSSValueID valueID = primitiveValue.getValueID();
    5836         if (valueID == CSSValueWebkitMinContent || valueID == CSSValueWebkitMaxContent || valueID == CSSValueAuto || primitiveValue.isFlex())
    5837             return false;
    5838     }
     5820static bool isGridTrackFixedSized(const CSSValue& value)
     5821{
     5822    ASSERT(value.isPrimitiveValue() || (value.isFunctionValue() && downcast<CSSFunctionValue>(value).arguments()));
     5823    const auto& primitiveValue = value.isPrimitiveValue()
     5824        ? downcast<CSSPrimitiveValue>(value)
     5825        : downcast<CSSPrimitiveValue>(*downcast<CSSFunctionValue>(value).arguments()->item(0));
     5826    CSSValueID valueID = primitiveValue.getValueID();
     5827    if (valueID == CSSValueWebkitMinContent || valueID == CSSValueWebkitMaxContent || valueID == CSSValueAuto || primitiveValue.isFlex())
     5828        return false;
     5829
     5830    ASSERT(primitiveValue.isLength());
    58395831    return true;
    58405832}
     
    58585850    bool seenTrackSizeOrRepeatFunction = false;
    58595851    bool seenAutoRepeat = false;
     5852    bool allTracksAreFixedSized = true;
    58605853    while (CSSParserValue* currentValue = m_valueList->current()) {
    58615854        if (isForwardSlashOperator(*currentValue))
     
    58635856        if (currentValue->unit == CSSParserValue::Function && equalLettersIgnoringASCIICase(currentValue->function->name, "repeat(")) {
    58645857            bool isAutoRepeat;
    5865             if (!parseGridTrackRepeatFunction(values, isAutoRepeat))
     5858            if (!parseGridTrackRepeatFunction(values, isAutoRepeat, allTracksAreFixedSized))
    58665859                return nullptr;
    58675860            if (isAutoRepeat && seenAutoRepeat)
     
    58695862            seenAutoRepeat = seenAutoRepeat || isAutoRepeat;
    58705863        } else {
    5871             RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList, seenAutoRepeat ? FixedSizeOnly : AllowAll);
     5864            RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList);
    58725865            if (!value)
    58735866                return nullptr;
     5867            if (allTracksAreFixedSized)
     5868                allTracksAreFixedSized = isGridTrackFixedSized(*value);
    58745869            values->append(value.releaseNonNull());
    58755870        }
    58765871        seenTrackSizeOrRepeatFunction = true;
     5872
     5873        if (seenAutoRepeat && !allTracksAreFixedSized)
     5874            return nullptr;
    58775875
    58785876        // This will handle the trailing <custom-ident>* in the grammar.
     
    58855883        return nullptr;
    58865884
    5887     // <auto-repeat> requires definite minimum track sizes in order to compute the number of repetitions.
    5888     // The above while loop detects those appearances after the <auto-repeat> but not the ones before.
    5889     if (seenAutoRepeat && !allTracksAreFixedSized(values))
    5890         return nullptr;
    5891 
    58925885    return WTFMove(values);
    58935886}
    58945887
    5895 bool CSSParser::parseGridTrackRepeatFunction(CSSValueList& list, bool& isAutoRepeat)
     5888bool CSSParser::parseGridTrackRepeatFunction(CSSValueList& list, bool& isAutoRepeat, bool& allTracksAreFixedSized)
    58965889{
    58975890    ASSERT(isCSSGridLayoutEnabled());
     
    59235916
    59245917    unsigned numberOfTracks = 0;
    5925     TrackSizeRestriction restriction = isAutoRepeat ? FixedSizeOnly : AllowAll;
    59265918    while (arguments->current()) {
    59275919        if (isAutoRepeat && numberOfTracks)
    59285920            return false;
    59295921
    5930         RefPtr<CSSValue> trackSize = parseGridTrackSize(*arguments, restriction);
     5922        RefPtr<CSSValue> trackSize = parseGridTrackSize(*arguments);
    59315923        if (!trackSize)
    59325924            return false;
     5925        if (allTracksAreFixedSized)
     5926            allTracksAreFixedSized = isGridTrackFixedSized(*trackSize);
    59335927
    59345928        repeatedValues->append(trackSize.releaseNonNull());
     
    59625956}
    59635957
    5964 RefPtr<CSSValue> CSSParser::parseGridTrackSize(CSSParserValueList& inputList, TrackSizeRestriction restriction)
     5958RefPtr<CSSValue> CSSParser::parseGridTrackSize(CSSParserValueList& inputList)
    59655959{
    59665960    ASSERT(isCSSGridLayoutEnabled());
     
    59785972            return nullptr;
    59795973
    5980         TrackSizeRestriction minTrackBreadthRestriction = restriction == AllowAll ? InflexibleSizeOnly : restriction;
    5981         RefPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth(*arguments->valueAt(0), minTrackBreadthRestriction);
    5982         if (!minTrackBreadth)
     5974        RefPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth(*arguments->valueAt(0));
     5975        if (!minTrackBreadth || minTrackBreadth->isFlex())
    59835976            return nullptr;
    59845977
     
    59935986    }
    59945987
    5995     return parseGridBreadth(currentValue, restriction);
    5996 }
    5997 
    5998 RefPtr<CSSPrimitiveValue> CSSParser::parseGridBreadth(CSSParserValue& value, TrackSizeRestriction restriction)
     5988    return parseGridBreadth(currentValue);
     5989}
     5990
     5991RefPtr<CSSPrimitiveValue> CSSParser::parseGridBreadth(CSSParserValue& value)
    59995992{
    60005993    ASSERT(isCSSGridLayoutEnabled());
    60015994
    6002     if (value.id == CSSValueWebkitMinContent || value.id == CSSValueWebkitMaxContent || value.id == CSSValueAuto) {
    6003         if (restriction == FixedSizeOnly)
    6004             return nullptr;
     5995    if (value.id == CSSValueWebkitMinContent || value.id == CSSValueWebkitMaxContent || value.id == CSSValueAuto)
    60055996        return CSSValuePool::singleton().createIdentifierValue(value.id);
    6006     }
    60075997
    60085998    if (value.unit == CSSPrimitiveValue::CSS_FR) {
    6009         if (restriction == FixedSizeOnly || restriction == InflexibleSizeOnly)
    6010             return nullptr;
    6011 
    60125999        double flexValue = value.fValue;
    60136000
  • trunk/Source/WebCore/css/CSSParser.h

    r201325 r201373  
    240240    bool parseSingleGridAreaLonghand(RefPtr<CSSValue>&);
    241241    RefPtr<CSSValue> parseGridTrackList();
    242     bool parseGridTrackRepeatFunction(CSSValueList&, bool& isAutoRepeat);
    243     enum TrackSizeRestriction { FixedSizeOnly, InflexibleSizeOnly, AllowAll };
    244     RefPtr<CSSValue> parseGridTrackSize(CSSParserValueList& inputList, TrackSizeRestriction = AllowAll);
    245     RefPtr<CSSPrimitiveValue> parseGridBreadth(CSSParserValue&, TrackSizeRestriction = AllowAll);
     242    bool parseGridTrackRepeatFunction(CSSValueList&, bool& isAutoRepeat, bool& allTracksAreFixedSized);
     243    RefPtr<CSSValue> parseGridTrackSize(CSSParserValueList& inputList);
     244    RefPtr<CSSPrimitiveValue> parseGridBreadth(CSSParserValue&);
    246245    bool parseGridTemplateAreasRow(NamedGridAreaMap&, const unsigned, unsigned&);
    247246    RefPtr<CSSValue> parseGridTemplateAreas();
Note: See TracChangeset for help on using the changeset viewer.