Ignore:
Timestamp:
May 25, 2016, 7:44:48 AM (10 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSParser.cpp

    r201378 r201382  
    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() || primitiveValue.isPercentage() || primitiveValue.isCalculated());
    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
     5868            allTracksAreFixedSized = 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;
    59335925
     5926        allTracksAreFixedSized = allTracksAreFixedSized && isGridTrackFixedSized(*trackSize);
    59345927        repeatedValues->append(trackSize.releaseNonNull());
    59355928        ++numberOfTracks;
     
    59625955}
    59635956
    5964 RefPtr<CSSValue> CSSParser::parseGridTrackSize(CSSParserValueList& inputList, TrackSizeRestriction restriction)
     5957RefPtr<CSSValue> CSSParser::parseGridTrackSize(CSSParserValueList& inputList)
    59655958{
    59665959    ASSERT(isCSSGridLayoutEnabled());
     
    59785971            return nullptr;
    59795972
    5980         TrackSizeRestriction minTrackBreadthRestriction = restriction == AllowAll ? InflexibleSizeOnly : restriction;
    5981         RefPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth(*arguments->valueAt(0), minTrackBreadthRestriction);
    5982         if (!minTrackBreadth)
     5973        RefPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth(*arguments->valueAt(0));
     5974        if (!minTrackBreadth || minTrackBreadth->isFlex())
    59835975            return nullptr;
    59845976
     
    59935985    }
    59945986
    5995     return parseGridBreadth(currentValue, restriction);
    5996 }
    5997 
    5998 RefPtr<CSSPrimitiveValue> CSSParser::parseGridBreadth(CSSParserValue& value, TrackSizeRestriction restriction)
     5987    return parseGridBreadth(currentValue);
     5988}
     5989
     5990RefPtr<CSSPrimitiveValue> CSSParser::parseGridBreadth(CSSParserValue& value)
    59995991{
    60005992    ASSERT(isCSSGridLayoutEnabled());
    60015993
    6002     if (value.id == CSSValueWebkitMinContent || value.id == CSSValueWebkitMaxContent || value.id == CSSValueAuto) {
    6003         if (restriction == FixedSizeOnly)
    6004             return nullptr;
     5994    if (value.id == CSSValueWebkitMinContent || value.id == CSSValueWebkitMaxContent || value.id == CSSValueAuto)
    60055995        return CSSValuePool::singleton().createIdentifierValue(value.id);
    6006     }
    60075996
    60085997    if (value.unit == CSSPrimitiveValue::CSS_FR) {
    6009         if (restriction == FixedSizeOnly || restriction == InflexibleSizeOnly)
    6010             return nullptr;
    6011 
    60125998        double flexValue = value.fValue;
    60135999
Note: See TracChangeset for help on using the changeset viewer.