Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp

Issue 1816253002: Move grid-template-columns/grid-template-rows into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address final issue Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 PassRefPtrWillBeRawPtr<CSSGridLineNamesValue> consumeGridLineNames(CSSPar serTokenRange& range)
3108 {
3109 if (range.peek().type() != LeftBracketToken)
3110 return nullptr;
3111 CSSParserTokenRange rangeCopy = range;
3112 rangeCopy.consumeIncludingWhitespace(); // Skip '['.
Timothy Loh 2016/03/29 02:47:39 Not a fan of the two comments here, at least becau
rwlbuis 2016/03/29 21:15:51 Done.
3113 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue: :create();
3114 while (RefPtrWillBeRawPtr<CSSCustomIdentValue> lineName = consumeCustomIdent ForGridLine(rangeCopy))
3115 lineNames->append(lineName.release());
3116 if (rangeCopy.peek().type() != RightBracketToken)
3117 return nullptr;
3118 rangeCopy.consumeIncludingWhitespace(); // Consume ']'.
3119 range = rangeCopy;
3120 return lineNames.release();
3121 }
3122
3123 static bool consumeGridTrackRepeatFunction(CSSParserTokenRange& range, CSSParser Mode cssParserMode, CSSValueList& list, bool& isAutoRepeat)
3124 {
3125 CSSParserTokenRange args = consumeFunction(range);
3126 // The number of repetitions for <auto-repeat> is not important at parsing l evel
3127 // because it will be computed later, let's set it to 1.
3128 size_t repetitions = 1;
3129 isAutoRepeat = identMatches<CSSValueAutoFill, CSSValueAutoFit>(args.peek().i d());
3130 RefPtrWillBeRawPtr<CSSValueList> repeatedValues;
3131 if (isAutoRepeat) {
3132 repeatedValues = CSSGridAutoRepeatValue::create(args.consumeIncludingWhi tespace().id());
3133 } else {
3134 if (args.peek().type() != NumberToken || args.peek().numericValueType() != IntegerValueType)
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 }
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 if (range.peek().id() == CSSValueNone)
Timothy Loh 2016/03/29 02:47:39 I think you forgot to remove this from here since
rwlbuis 2016/03/29 21:15:50 Done.
3182 return consumeIdent(range);
3183 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated ();
3184 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = consumeGridLineNames(r ange);
3185 if (lineNames)
3186 values->append(lineNames.release());
3187
3188 bool seenAutoRepeat = false;
3189 do {
Timothy Loh 2016/03/29 02:47:39 This allows <line-names> directly before <auto-rep
svillar 2016/03/29 08:27:36 That's right. If we specify <line-names> then ther
rwlbuis 2016/03/29 21:15:51 Done.
Timothy Loh 2016/03/30 00:15:39 Not sure the TODO is accurate, or I'm misunderstan
3190 bool isAutoRepeat;
3191 if (range.peek().functionId() == CSSValueRepeat) {
3192 if (!consumeGridTrackRepeatFunction(range, cssParserMode, *values, i sAutoRepeat) || (isAutoRepeat && seenAutoRepeat))
svillar 2016/03/29 08:27:36 I would prefer this to be in two different conditi
rwlbuis 2016/03/29 21:15:50 Done.
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 lineNames = consumeGridLineNames(range);
3201 if (lineNames)
3202 values->append(lineNames.release());
3203 } while (!range.atEnd() && range.peek().type() != DelimiterToken);
3204 // <auto-repeat> requires definite minimum track sizes in order to compute t he number of repetitions.
3205 // The above while loop detects those appearances after the <auto-repeat> bu t not the ones before.
3206 if (seenAutoRepeat && !allTracksAreFixedSized(*values))
3207 return nullptr;
3208 return values.release();
3209 }
3210
3211 static PassRefPtrWillBeRawPtr<CSSValue> consumeGridTemplatesRowsOrColumns(CSSPar serTokenRange& range, CSSParserMode cssParserMode)
3212 {
3213 if (range.peek().id() == CSSValueNone)
3214 return consumeIdent(range);
3215 return consumeGridTrackList(range, cssParserMode);
3216 }
3217
3105 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) 3218 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty)
3106 { 3219 {
3107 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 3220 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
3108 if (CSSParserFastPaths::isKeywordPropertyID(property)) { 3221 if (CSSParserFastPaths::isKeywordPropertyID(property)) {
3109 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang e.peek().id())) 3222 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang e.peek().id()))
3110 return nullptr; 3223 return nullptr;
3111 return consumeIdent(m_range); 3224 return consumeIdent(m_range);
3112 } 3225 }
3113 switch (property) { 3226 switch (property) {
3114 case CSSPropertyWillChange: 3227 case CSSPropertyWillChange:
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
3467 case CSSPropertyGridColumnEnd: 3580 case CSSPropertyGridColumnEnd:
3468 case CSSPropertyGridColumnStart: 3581 case CSSPropertyGridColumnStart:
3469 case CSSPropertyGridRowEnd: 3582 case CSSPropertyGridRowEnd:
3470 case CSSPropertyGridRowStart: 3583 case CSSPropertyGridRowStart:
3471 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 3584 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3472 return consumeGridLine(m_range); 3585 return consumeGridLine(m_range);
3473 case CSSPropertyGridAutoColumns: 3586 case CSSPropertyGridAutoColumns:
3474 case CSSPropertyGridAutoRows: 3587 case CSSPropertyGridAutoRows:
3475 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 3588 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3476 return consumeGridTrackSize(m_range, m_context.mode()); 3589 return consumeGridTrackSize(m_range, m_context.mode());
3590 case CSSPropertyGridTemplateColumns:
3591 case CSSPropertyGridTemplateRows:
3592 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3593 return consumeGridTemplatesRowsOrColumns(m_range, m_context.mode());
3477 default: 3594 default:
3478 CSSParserValueList valueList(m_range); 3595 CSSParserValueList valueList(m_range);
3479 if (valueList.size()) { 3596 if (valueList.size()) {
3480 m_valueList = &valueList; 3597 m_valueList = &valueList;
3481 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve dProperty)) { 3598 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve dProperty)) {
3482 while (!m_range.atEnd()) 3599 while (!m_range.atEnd())
3483 m_range.consume(); 3600 m_range.consume();
3484 return result.release(); 3601 return result.release();
3485 } 3602 }
3486 } 3603 }
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
4480 m_currentShorthand = oldShorthand; 4597 m_currentShorthand = oldShorthand;
4481 CSSParserValueList valueList(m_range); 4598 CSSParserValueList valueList(m_range);
4482 if (!valueList.size()) 4599 if (!valueList.size())
4483 return false; 4600 return false;
4484 m_valueList = &valueList; 4601 m_valueList = &valueList;
4485 return legacyParseShorthand(unresolvedProperty, important); 4602 return legacyParseShorthand(unresolvedProperty, important);
4486 } 4603 }
4487 } 4604 }
4488 4605
4489 } // namespace blink 4606 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698