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 3066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3095 return nullptr; | 3097 return nullptr; |
3096 range = rangeCopy; | 3098 range = rangeCopy; |
3097 RefPtrWillBeRawPtr<CSSFunctionValue> result = CSSFunctionValue::create(C SSValueMinmax); | 3099 RefPtrWillBeRawPtr<CSSFunctionValue> result = CSSFunctionValue::create(C SSValueMinmax); |
3098 result->append(minTrackBreadth.release()); | 3100 result->append(minTrackBreadth.release()); |
3099 result->append(maxTrackBreadth.release()); | 3101 result->append(maxTrackBreadth.release()); |
3100 return result.release(); | 3102 return result.release(); |
3101 } | 3103 } |
3102 return consumeGridBreadth(range, cssParserMode, restriction); | 3104 return consumeGridBreadth(range, cssParserMode, restriction); |
3103 } | 3105 } |
3104 | 3106 |
3107 static bool consumeGridLineNames(CSSParserTokenRange& range, CSSValueList& value List) | |
Timothy Loh
2016/03/24 04:29:31
I think this would be clearer it returned a CSSGri
rwlbuis
2016/03/24 20:40:32
Done.
| |
3108 { | |
3109 if (range.peek().type() != LeftBracketToken) | |
3110 return true; | |
3111 range.consumeIncludingWhitespace(); // Skip '['. | |
3112 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue: :create(); | |
3113 while (RefPtrWillBeRawPtr<CSSCustomIdentValue> lineName = consumeCustomIdent ForGridLine(range)) | |
3114 lineNames->append(lineName.release()); | |
3115 if (range.peek().type() != RightBracketToken) | |
3116 return false; | |
3117 range.consumeIncludingWhitespace(); // Consume ']'. | |
3118 valueList.append(lineNames.release()); | |
3119 return true; | |
3120 } | |
3121 | |
3122 static bool consumeGridTrackRepeatFunction(CSSParserTokenRange& range, CSSParser Mode cssParserMode, CSSValueList& list, bool& isAutoRepeat) | |
Timothy Loh
2016/03/24 04:29:31
Maybe better / more consistent with everything els
rwlbuis
2016/03/24 20:40:32
Done.
| |
3123 { | |
3124 if (range.peek().functionId() != CSSValueRepeat) | |
3125 return false; | |
3126 | |
3127 CSSParserTokenRange args = consumeFunction(range); | |
3128 // The number of repetitions for <auto-repeat> is not important at parsing l evel | |
3129 // because it will be computed later, let's set it to 1. | |
3130 size_t repetitions = 1; | |
3131 isAutoRepeat = identMatches<CSSValueAutoFill, CSSValueAutoFit>(args.peek().i d()); | |
3132 RefPtrWillBeRawPtr<CSSValueList> repeatedValues; | |
3133 if (!isAutoRepeat) { | |
Timothy Loh
2016/03/24 04:29:31
clearer to not negate here and swap the blocks aro
rwlbuis
2016/03/24 20:40:32
Done.
| |
3134 if (args.peek().type() != NumberToken || args.peek().numericValueType() != IntegerValueType) | |
Timothy Loh
2016/03/24 04:29:31
consumePositiveInteger??
rwlbuis
2016/03/24 20:40:32
That would work, but it will create a CSSValue for
Timothy Loh
2016/03/29 02:47:39
We need to use it to handle calc() correctly. Mayb
| |
3135 return false; | |
3136 double repetition = args.consumeIncludingWhitespace().numericValue(); | |
3137 if (repetition < 1) | |
3138 return false; | |
3139 repetitions = clampTo<size_t>(repetition, 0, kGridMaxTracks); | |
3140 repeatedValues = CSSValueList::createSpaceSeparated(); | |
3141 } else { | |
3142 repeatedValues = CSSGridAutoRepeatValue::create(args.consumeIncludingWhi tespace().id()); | |
3143 } | |
3144 if (!consumeCommaIncludingWhitespace(args) || !consumeGridLineNames(args, *r epeatedValues)) | |
3145 return false; | |
3146 | |
3147 size_t numberOfTracks = 0; | |
3148 TrackSizeRestriction restriction = isAutoRepeat ? FixedSizeOnly : AllowAll; | |
3149 while (!args.atEnd()) { | |
Timothy Loh
2016/03/24 04:29:31
I think you can do:
do {
..
} while (!args.at
rwlbuis
2016/03/24 20:40:32
I don't think this will work since then it would i
Timothy Loh
2016/03/29 02:47:39
Not sure what you mean exactly :/
rwlbuis
2016/03/29 21:15:50
Sorry, I meant I think we still need numberOfTrack
| |
3150 if (isAutoRepeat && numberOfTracks) | |
3151 return false; | |
3152 RefPtrWillBeRawPtr<CSSValue> trackSize = consumeGridTrackSize(args, cssP arserMode, restriction); | |
3153 if (!trackSize) | |
3154 return false; | |
3155 repeatedValues->append(trackSize.release()); | |
3156 ++numberOfTracks; | |
3157 if (!consumeGridLineNames(args, *repeatedValues)) | |
3158 return false; | |
3159 } | |
3160 // We should have found at least one <track-size> or else it is not a valid <track-list>. | |
3161 if (!numberOfTracks) | |
3162 return false; | |
3163 | |
3164 if (isAutoRepeat) { | |
3165 list.append(repeatedValues.release()); | |
3166 } else { | |
3167 // We clamp the repetitions to a multiple of the repeat() track list's s ize, while staying below the max grid size. | |
3168 repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks); | |
3169 for (size_t i = 0; i < repetitions; ++i) { | |
3170 for (size_t j = 0; j < repeatedValues->length(); ++j) | |
3171 list.append(repeatedValues->item(j)); | |
3172 } | |
3173 } | |
3174 return true; | |
3175 } | |
3176 | |
3177 static PassRefPtrWillBeRawPtr<CSSValue> consumeGridTrackList(CSSParserTokenRange & range, CSSParserMode cssParserMode) | |
3178 { | |
3179 if (range.peek().id() == CSSValueNone) | |
Timothy Loh
2016/03/24 04:29:31
I think consumeGridTrackList (or just consumeTrack
rwlbuis
2016/03/24 20:40:32
Agreed, good point, done.
| |
3180 return consumeIdent(range); | |
3181 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated (); | |
3182 if (!consumeGridLineNames(range, *values)) | |
3183 return nullptr; | |
3184 | |
3185 bool seenTrackSizeOrRepeatFunction = false; | |
3186 bool seenAutoRepeat = false; | |
3187 while (!range.atEnd()) { | |
Timothy Loh
2016/03/24 04:29:31
Maybe like this, and then you don't need seenTrack
rwlbuis
2016/03/24 20:40:32
Done.
| |
3188 if (range.peek().type() == DelimiterToken && range.peek().delimiter() == '/') | |
3189 break; | |
3190 bool isAutoRepeat; | |
3191 if (consumeGridTrackRepeatFunction(range, cssParserMode, *values, isAuto Repeat)) { | |
3192 if (isAutoRepeat && seenAutoRepeat) | |
3193 return nullptr; | |
3194 seenAutoRepeat = seenAutoRepeat || isAutoRepeat; | |
3195 } else if (RefPtrWillBeRawPtr<CSSValue> value = consumeGridTrackSize(ran ge, cssParserMode, seenAutoRepeat ? FixedSizeOnly : AllowAll)) { | |
3196 values->append(value.release()); | |
3197 } else { | |
3198 return nullptr; | |
3199 } | |
3200 seenTrackSizeOrRepeatFunction = true; | |
3201 if (!consumeGridLineNames(range, *values)) | |
3202 return nullptr; | |
3203 } | |
3204 // We should have found a <track-size> or else it is not a valid <track-list >. | |
3205 if (!seenTrackSizeOrRepeatFunction) | |
3206 return nullptr; | |
3207 // <auto-repeat> requires definite minimum track sizes in order to compute t he number of repetitions. | |
3208 // The above while loop detects those appearances after the <auto-repeat> bu t not the ones before. | |
3209 if (seenAutoRepeat && !allTracksAreFixedSized(*values)) | |
3210 return nullptr; | |
3211 return values.release(); | |
3212 } | |
3213 | |
3105 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) | 3214 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) |
3106 { | 3215 { |
3107 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 3216 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
3108 if (CSSParserFastPaths::isKeywordPropertyID(property)) { | 3217 if (CSSParserFastPaths::isKeywordPropertyID(property)) { |
3109 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang e.peek().id())) | 3218 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang e.peek().id())) |
3110 return nullptr; | 3219 return nullptr; |
3111 return consumeIdent(m_range); | 3220 return consumeIdent(m_range); |
3112 } | 3221 } |
3113 switch (property) { | 3222 switch (property) { |
3114 case CSSPropertyWillChange: | 3223 case CSSPropertyWillChange: |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3467 case CSSPropertyGridColumnEnd: | 3576 case CSSPropertyGridColumnEnd: |
3468 case CSSPropertyGridColumnStart: | 3577 case CSSPropertyGridColumnStart: |
3469 case CSSPropertyGridRowEnd: | 3578 case CSSPropertyGridRowEnd: |
3470 case CSSPropertyGridRowStart: | 3579 case CSSPropertyGridRowStart: |
3471 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | 3580 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
3472 return consumeGridLine(m_range); | 3581 return consumeGridLine(m_range); |
3473 case CSSPropertyGridAutoColumns: | 3582 case CSSPropertyGridAutoColumns: |
3474 case CSSPropertyGridAutoRows: | 3583 case CSSPropertyGridAutoRows: |
3475 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | 3584 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
3476 return consumeGridTrackSize(m_range, m_context.mode()); | 3585 return consumeGridTrackSize(m_range, m_context.mode()); |
3586 case CSSPropertyGridTemplateColumns: | |
3587 case CSSPropertyGridTemplateRows: | |
3588 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | |
3589 return consumeGridTrackList(m_range, m_context.mode()); | |
3477 default: | 3590 default: |
3478 CSSParserValueList valueList(m_range); | 3591 CSSParserValueList valueList(m_range); |
3479 if (valueList.size()) { | 3592 if (valueList.size()) { |
3480 m_valueList = &valueList; | 3593 m_valueList = &valueList; |
3481 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve dProperty)) { | 3594 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve dProperty)) { |
3482 while (!m_range.atEnd()) | 3595 while (!m_range.atEnd()) |
3483 m_range.consume(); | 3596 m_range.consume(); |
3484 return result.release(); | 3597 return result.release(); |
3485 } | 3598 } |
3486 } | 3599 } |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4480 m_currentShorthand = oldShorthand; | 4593 m_currentShorthand = oldShorthand; |
4481 CSSParserValueList valueList(m_range); | 4594 CSSParserValueList valueList(m_range); |
4482 if (!valueList.size()) | 4595 if (!valueList.size()) |
4483 return false; | 4596 return false; |
4484 m_valueList = &valueList; | 4597 m_valueList = &valueList; |
4485 return legacyParseShorthand(unresolvedProperty, important); | 4598 return legacyParseShorthand(unresolvedProperty, important); |
4486 } | 4599 } |
4487 } | 4600 } |
4488 | 4601 |
4489 } // namespace blink | 4602 } // namespace blink |
OLD | NEW |