OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/parser/CSSPropertyParser.h" | 5 #include "core/css/parser/CSSPropertyParser.h" |
6 | 6 |
7 #include "core/StylePropertyShorthand.h" | 7 #include "core/StylePropertyShorthand.h" |
8 #include "core/css/CSSBasicShapeValues.h" | 8 #include "core/css/CSSBasicShapeValues.h" |
9 #include "core/css/CSSBorderImage.h" | 9 #include "core/css/CSSBorderImage.h" |
10 #include "core/css/CSSContentDistributionValue.h" | 10 #include "core/css/CSSContentDistributionValue.h" |
11 #include "core/css/CSSCounterValue.h" | 11 #include "core/css/CSSCounterValue.h" |
12 #include "core/css/CSSCrossfadeValue.h" | 12 #include "core/css/CSSCrossfadeValue.h" |
13 #include "core/css/CSSCursorImageValue.h" | 13 #include "core/css/CSSCursorImageValue.h" |
14 #include "core/css/CSSCustomIdentValue.h" | 14 #include "core/css/CSSCustomIdentValue.h" |
15 #include "core/css/CSSFontFaceSrcValue.h" | 15 #include "core/css/CSSFontFaceSrcValue.h" |
16 #include "core/css/CSSFontFeatureValue.h" | 16 #include "core/css/CSSFontFeatureValue.h" |
17 #include "core/css/CSSFunctionValue.h" | 17 #include "core/css/CSSFunctionValue.h" |
18 #include "core/css/CSSGradientValue.h" | 18 #include "core/css/CSSGradientValue.h" |
| 19 #include "core/css/CSSGridAutoRepeatValue.h" |
| 20 #include "core/css/CSSGridLineNamesValue.h" |
19 #include "core/css/CSSImageSetValue.h" | 21 #include "core/css/CSSImageSetValue.h" |
20 #include "core/css/CSSPaintValue.h" | 22 #include "core/css/CSSPaintValue.h" |
21 #include "core/css/CSSPathValue.h" | 23 #include "core/css/CSSPathValue.h" |
22 #include "core/css/CSSPrimitiveValueMappings.h" | 24 #include "core/css/CSSPrimitiveValueMappings.h" |
23 #include "core/css/CSSQuadValue.h" | 25 #include "core/css/CSSQuadValue.h" |
24 #include "core/css/CSSReflectValue.h" | 26 #include "core/css/CSSReflectValue.h" |
25 #include "core/css/CSSSVGDocumentValue.h" | 27 #include "core/css/CSSSVGDocumentValue.h" |
26 #include "core/css/CSSShadowValue.h" | 28 #include "core/css/CSSShadowValue.h" |
27 #include "core/css/CSSStringValue.h" | 29 #include "core/css/CSSStringValue.h" |
28 #include "core/css/CSSTimingFunctionValue.h" | 30 #include "core/css/CSSTimingFunctionValue.h" |
(...skipping 3069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3098 return nullptr; | 3100 return nullptr; |
3099 range = rangeCopy; | 3101 range = rangeCopy; |
3100 RefPtrWillBeRawPtr<CSSFunctionValue> result = CSSFunctionValue::create(C
SSValueMinmax); | 3102 RefPtrWillBeRawPtr<CSSFunctionValue> result = CSSFunctionValue::create(C
SSValueMinmax); |
3101 result->append(minTrackBreadth.release()); | 3103 result->append(minTrackBreadth.release()); |
3102 result->append(maxTrackBreadth.release()); | 3104 result->append(maxTrackBreadth.release()); |
3103 return result.release(); | 3105 return result.release(); |
3104 } | 3106 } |
3105 return consumeGridBreadth(range, cssParserMode, restriction); | 3107 return consumeGridBreadth(range, cssParserMode, restriction); |
3106 } | 3108 } |
3107 | 3109 |
| 3110 static PassRefPtrWillBeRawPtr<CSSGridLineNamesValue> consumeGridLineNames(CSSPar
serTokenRange& range) |
| 3111 { |
| 3112 CSSParserTokenRange rangeCopy = range; |
| 3113 if (rangeCopy.consumeIncludingWhitespace().type() != LeftBracketToken) |
| 3114 return nullptr; |
| 3115 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue:
:create(); |
| 3116 while (RefPtrWillBeRawPtr<CSSCustomIdentValue> lineName = consumeCustomIdent
ForGridLine(rangeCopy)) |
| 3117 lineNames->append(lineName.release()); |
| 3118 if (rangeCopy.consumeIncludingWhitespace().type() != RightBracketToken) |
| 3119 return nullptr; |
| 3120 range = rangeCopy; |
| 3121 return lineNames.release(); |
| 3122 } |
| 3123 |
| 3124 static bool consumeGridTrackRepeatFunction(CSSParserTokenRange& range, CSSParser
Mode cssParserMode, CSSValueList& list, bool& isAutoRepeat) |
| 3125 { |
| 3126 CSSParserTokenRange args = consumeFunction(range); |
| 3127 // The number of repetitions for <auto-repeat> is not important at parsing l
evel |
| 3128 // because it will be computed later, let's set it to 1. |
| 3129 size_t repetitions = 1; |
| 3130 isAutoRepeat = identMatches<CSSValueAutoFill, CSSValueAutoFit>(args.peek().i
d()); |
| 3131 RefPtrWillBeRawPtr<CSSValueList> repeatedValues; |
| 3132 if (isAutoRepeat) { |
| 3133 repeatedValues = CSSGridAutoRepeatValue::create(args.consumeIncludingWhi
tespace().id()); |
| 3134 } else { |
| 3135 // TODO(rob.buis): a consumeIntegerRaw would be more efficient here. |
| 3136 RefPtrWillBeRawPtr<CSSPrimitiveValue> repetition = consumePositiveIntege
r(args); |
| 3137 if (!repetition) |
| 3138 return false; |
| 3139 repetitions = clampTo<size_t>(repetition->getDoubleValue(), 0, kGridMaxT
racks); |
| 3140 repeatedValues = CSSValueList::createSpaceSeparated(); |
| 3141 } |
| 3142 if (!consumeCommaIncludingWhitespace(args)) |
| 3143 return false; |
| 3144 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = consumeGridLineNames(a
rgs); |
| 3145 if (lineNames) |
| 3146 repeatedValues->append(lineNames.release()); |
| 3147 |
| 3148 size_t numberOfTracks = 0; |
| 3149 TrackSizeRestriction restriction = isAutoRepeat ? FixedSizeOnly : AllowAll; |
| 3150 while (!args.atEnd()) { |
| 3151 if (isAutoRepeat && numberOfTracks) |
| 3152 return false; |
| 3153 RefPtrWillBeRawPtr<CSSValue> trackSize = consumeGridTrackSize(args, cssP
arserMode, restriction); |
| 3154 if (!trackSize) |
| 3155 return false; |
| 3156 repeatedValues->append(trackSize.release()); |
| 3157 ++numberOfTracks; |
| 3158 lineNames = consumeGridLineNames(args); |
| 3159 if (lineNames) |
| 3160 repeatedValues->append(lineNames.release()); |
| 3161 } |
| 3162 // We should have found at least one <track-size> or else it is not a valid
<track-list>. |
| 3163 if (!numberOfTracks) |
| 3164 return false; |
| 3165 |
| 3166 if (isAutoRepeat) { |
| 3167 list.append(repeatedValues.release()); |
| 3168 } else { |
| 3169 // We clamp the repetitions to a multiple of the repeat() track list's s
ize, while staying below the max grid size. |
| 3170 repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks); |
| 3171 for (size_t i = 0; i < repetitions; ++i) { |
| 3172 for (size_t j = 0; j < repeatedValues->length(); ++j) |
| 3173 list.append(repeatedValues->item(j)); |
| 3174 } |
| 3175 } |
| 3176 return true; |
| 3177 } |
| 3178 |
| 3179 static PassRefPtrWillBeRawPtr<CSSValue> consumeGridTrackList(CSSParserTokenRange
& range, CSSParserMode cssParserMode) |
| 3180 { |
| 3181 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated
(); |
| 3182 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = consumeGridLineNames(r
ange); |
| 3183 if (lineNames) |
| 3184 values->append(lineNames.release()); |
| 3185 |
| 3186 bool seenAutoRepeat = false; |
| 3187 // TODO(rob.buis): <line-names> should not be able to directly precede <auto
-repeat>. |
| 3188 do { |
| 3189 bool isAutoRepeat; |
| 3190 if (range.peek().functionId() == CSSValueRepeat) { |
| 3191 if (!consumeGridTrackRepeatFunction(range, cssParserMode, *values, i
sAutoRepeat)) |
| 3192 return nullptr; |
| 3193 if (isAutoRepeat && seenAutoRepeat) |
| 3194 return nullptr; |
| 3195 seenAutoRepeat = seenAutoRepeat || isAutoRepeat; |
| 3196 } else if (RefPtrWillBeRawPtr<CSSValue> value = consumeGridTrackSize(ran
ge, cssParserMode, seenAutoRepeat ? FixedSizeOnly : AllowAll)) { |
| 3197 values->append(value.release()); |
| 3198 } else { |
| 3199 return nullptr; |
| 3200 } |
| 3201 lineNames = consumeGridLineNames(range); |
| 3202 if (lineNames) |
| 3203 values->append(lineNames.release()); |
| 3204 } while (!range.atEnd() && range.peek().type() != DelimiterToken); |
| 3205 // <auto-repeat> requires definite minimum track sizes in order to compute t
he number of repetitions. |
| 3206 // The above while loop detects those appearances after the <auto-repeat> bu
t not the ones before. |
| 3207 if (seenAutoRepeat && !allTracksAreFixedSized(*values)) |
| 3208 return nullptr; |
| 3209 return values.release(); |
| 3210 } |
| 3211 |
| 3212 static PassRefPtrWillBeRawPtr<CSSValue> consumeGridTemplatesRowsOrColumns(CSSPar
serTokenRange& range, CSSParserMode cssParserMode) |
| 3213 { |
| 3214 if (range.peek().id() == CSSValueNone) |
| 3215 return consumeIdent(range); |
| 3216 return consumeGridTrackList(range, cssParserMode); |
| 3217 } |
| 3218 |
3108 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
ID unresolvedProperty) | 3219 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
ID unresolvedProperty) |
3109 { | 3220 { |
3110 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 3221 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
3111 if (CSSParserFastPaths::isKeywordPropertyID(property)) { | 3222 if (CSSParserFastPaths::isKeywordPropertyID(property)) { |
3112 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang
e.peek().id())) | 3223 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang
e.peek().id())) |
3113 return nullptr; | 3224 return nullptr; |
3114 return consumeIdent(m_range); | 3225 return consumeIdent(m_range); |
3115 } | 3226 } |
3116 switch (property) { | 3227 switch (property) { |
3117 case CSSPropertyWillChange: | 3228 case CSSPropertyWillChange: |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3470 case CSSPropertyGridColumnEnd: | 3581 case CSSPropertyGridColumnEnd: |
3471 case CSSPropertyGridColumnStart: | 3582 case CSSPropertyGridColumnStart: |
3472 case CSSPropertyGridRowEnd: | 3583 case CSSPropertyGridRowEnd: |
3473 case CSSPropertyGridRowStart: | 3584 case CSSPropertyGridRowStart: |
3474 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | 3585 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
3475 return consumeGridLine(m_range); | 3586 return consumeGridLine(m_range); |
3476 case CSSPropertyGridAutoColumns: | 3587 case CSSPropertyGridAutoColumns: |
3477 case CSSPropertyGridAutoRows: | 3588 case CSSPropertyGridAutoRows: |
3478 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | 3589 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
3479 return consumeGridTrackSize(m_range, m_context.mode()); | 3590 return consumeGridTrackSize(m_range, m_context.mode()); |
| 3591 case CSSPropertyGridTemplateColumns: |
| 3592 case CSSPropertyGridTemplateRows: |
| 3593 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
| 3594 return consumeGridTemplatesRowsOrColumns(m_range, m_context.mode()); |
3480 default: | 3595 default: |
3481 CSSParserValueList valueList(m_range); | 3596 CSSParserValueList valueList(m_range); |
3482 if (valueList.size()) { | 3597 if (valueList.size()) { |
3483 m_valueList = &valueList; | 3598 m_valueList = &valueList; |
3484 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve
dProperty)) { | 3599 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve
dProperty)) { |
3485 while (!m_range.atEnd()) | 3600 while (!m_range.atEnd()) |
3486 m_range.consume(); | 3601 m_range.consume(); |
3487 return result.release(); | 3602 return result.release(); |
3488 } | 3603 } |
3489 } | 3604 } |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4483 m_currentShorthand = oldShorthand; | 4598 m_currentShorthand = oldShorthand; |
4484 CSSParserValueList valueList(m_range); | 4599 CSSParserValueList valueList(m_range); |
4485 if (!valueList.size()) | 4600 if (!valueList.size()) |
4486 return false; | 4601 return false; |
4487 m_valueList = &valueList; | 4602 m_valueList = &valueList; |
4488 return legacyParseShorthand(unresolvedProperty, important); | 4603 return legacyParseShorthand(unresolvedProperty, important); |
4489 } | 4604 } |
4490 } | 4605 } |
4491 | 4606 |
4492 } // namespace blink | 4607 } // namespace blink |
OLD | NEW |