[CSS Parser] Support glyph-orientation-horizontal and glyph-orientation-vertical
[WebKit-https.git] / Source / WebCore / css / parser / CSSPropertyParser.cpp
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Copyright (C) 2016 Apple Inc. All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //    * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //    * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //    * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 #include "config.h"
31 #include "CSSPropertyParser.h"
32
33 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
34 #include "CSSAnimationTriggerScrollValue.h"
35 #endif
36 #include "CSSAspectRatioValue.h"
37 #include "CSSBasicShapes.h"
38 #include "CSSBorderImage.h"
39 #include "CSSBorderImageSliceValue.h"
40 #include "CSSContentDistributionValue.h"
41 #include "CSSCursorImageValue.h"
42 #include "CSSCustomIdentValue.h"
43 #include "CSSFontFaceSrcValue.h"
44 #include "CSSFontFeatureValue.h"
45 #if ENABLE(VARIATION_FONTS)
46 #include "CSSFontVariationValue.h"
47 #endif
48 #include "CSSFunctionValue.h"
49 #include "CSSGridAutoRepeatValue.h"
50 #include "CSSGridLineNamesValue.h"
51 #include "CSSGridTemplateAreasValue.h"
52 #include "CSSInheritedValue.h"
53 #include "CSSInitialValue.h"
54 #include "CSSLineBoxContainValue.h"
55 #include "CSSParserFastPaths.h"
56 #include "CSSParserIdioms.h"
57 #include "CSSPendingSubstitutionValue.h"
58 #include "CSSPrimitiveValueMappings.h"
59 #include "CSSPropertyParserHelpers.h"
60 #include "CSSReflectValue.h"
61 #include "CSSRevertValue.h"
62 #include "CSSShadowValue.h"
63 #include "CSSTimingFunctionValue.h"
64 #include "CSSUnicodeRangeValue.h"
65 #include "CSSUnsetValue.h"
66 #include "CSSVariableParser.h"
67 #include "CSSVariableReferenceValue.h"
68 #include "Counter.h"
69 #if ENABLE(DASHBOARD_SUPPORT)
70 #include "DashboardRegion.h"
71 #endif
72 #include "FontFace.h"
73 #include "HashTools.h"
74 // FIXME-NEWPARSER: Replace Pair and Rect with actual CSSValue subclasses (CSSValuePair and CSSQuadValue).
75 #include "Pair.h"
76 #include "Rect.h"
77 #include "RenderTheme.h"
78 #include "RuntimeEnabledFeatures.h"
79 #include "SVGPathByteStream.h"
80 #include "SVGPathUtilities.h"
81 #include "StylePropertyShorthand.h"
82 #include "StylePropertyShorthandFunctions.h"
83 #include "WebKitCSSTransformValue.h"
84 #include <bitset>
85 #include <memory>
86 #include <wtf/text/StringBuilder.h>
87
88 using namespace WTF;
89
90 namespace WebCore {
91
92 static bool hasPrefix(const char* string, unsigned length, const char* prefix)
93 {
94     for (unsigned i = 0; i < length; ++i) {
95         if (!prefix[i])
96             return true;
97         if (string[i] != prefix[i])
98             return false;
99     }
100     return false;
101 }
102
103 #if PLATFORM(IOS)
104 static void cssPropertyNameIOSAliasing(const char* propertyName, const char*& propertyNameAlias, unsigned& newLength)
105 {
106     if (!strcmp(propertyName, "-webkit-hyphenate-locale")) {
107         // Worked in iOS 4.2.
108         static const char webkitLocale[] = "-webkit-locale";
109         propertyNameAlias = webkitLocale;
110         newLength = strlen(webkitLocale);
111     }
112 }
113 #endif
114
115 template <typename CharacterType>
116 static CSSPropertyID cssPropertyID(const CharacterType* propertyName, unsigned length)
117 {
118     char buffer[maxCSSPropertyNameLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
119     
120     for (unsigned i = 0; i != length; ++i) {
121         CharacterType c = propertyName[i];
122         if (!c || c >= 0x7F)
123             return CSSPropertyInvalid; // illegal character
124         buffer[i] = toASCIILower(c);
125     }
126     buffer[length] = '\0';
127     
128     const char* name = buffer;
129     if (buffer[0] == '-') {
130 #if ENABLE(LEGACY_CSS_VENDOR_PREFIXES)
131         // If the prefix is -apple- or -khtml-, change it to -webkit-.
132         // This makes the string one character longer.
133         if (RuntimeEnabledFeatures::sharedFeatures().legacyCSSVendorPrefixesEnabled()
134             && (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "-khtml-"))) {
135             memmove(buffer + 7, buffer + 6, length + 1 - 6);
136             memcpy(buffer, "-webkit", 7);
137             ++length;
138         }
139 #endif
140 #if PLATFORM(IOS)
141         cssPropertyNameIOSAliasing(buffer, name, length);
142 #endif
143     }
144     
145     const Property* hashTableEntry = findProperty(name, length);
146     return hashTableEntry ? static_cast<CSSPropertyID>(hashTableEntry->id) : CSSPropertyInvalid;
147 }
148
149 static bool isAppleLegacyCssValueKeyword(const char* valueKeyword, unsigned length)
150 {
151     static const char applePrefix[] = "-apple-";
152     static const char appleSystemPrefix[] = "-apple-system";
153     static const char* appleWirelessPlaybackTargetActive = getValueName(CSSValueAppleWirelessPlaybackTargetActive);
154     
155     return hasPrefix(valueKeyword, length, applePrefix)
156     && !hasPrefix(valueKeyword, length, appleSystemPrefix)
157     && !WTF::equal(reinterpret_cast<const LChar*>(valueKeyword), reinterpret_cast<const LChar*>(appleWirelessPlaybackTargetActive), length);
158 }
159
160 template <typename CharacterType>
161 static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
162 {
163     char buffer[maxCSSValueKeywordLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
164     
165     for (unsigned i = 0; i != length; ++i) {
166         CharacterType c = valueKeyword[i];
167         if (!c || c >= 0x7F)
168             return CSSValueInvalid; // illegal keyword.
169         buffer[i] = WTF::toASCIILower(c);
170     }
171     buffer[length] = '\0';
172     
173     if (buffer[0] == '-') {
174         // If the prefix is -apple- or -khtml-, change it to -webkit-.
175         // This makes the string one character longer.
176         // On iOS we don't want to change values starting with -apple-system to -webkit-system.
177         // FIXME: Remove this mangling without breaking the web.
178         if (isAppleLegacyCssValueKeyword(buffer, length) || hasPrefix(buffer, length, "-khtml-")) {
179             memmove(buffer + 7, buffer + 6, length + 1 - 6);
180             memcpy(buffer, "-webkit", 7);
181             ++length;
182         }
183     }
184     
185     const Value* hashTableEntry = findValue(buffer, length);
186     return hashTableEntry ? static_cast<CSSValueID>(hashTableEntry->id) : CSSValueInvalid;
187 }
188
189 CSSValueID cssValueKeywordID(StringView string)
190 {
191     unsigned length = string.length();
192     if (!length)
193         return CSSValueInvalid;
194     if (length > maxCSSValueKeywordLength)
195         return CSSValueInvalid;
196     
197     return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : cssValueKeywordID(string.characters16(), length);
198 }
199
200 CSSPropertyID cssPropertyID(StringView string)
201 {
202     unsigned length = string.length();
203     
204     if (!length)
205         return CSSPropertyInvalid;
206     if (length > maxCSSPropertyNameLength)
207         return CSSPropertyInvalid;
208     
209     return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPropertyID(string.characters16(), length);
210 }
211     
212 using namespace CSSPropertyParserHelpers;
213
214 CSSPropertyParser::CSSPropertyParser(const CSSParserTokenRange& range, const CSSParserContext& context, StyleSheetContents* styleSheetContents, Vector<CSSProperty, 256>* parsedProperties)
215     : m_range(range)
216     , m_context(context)
217     , m_styleSheetContents(styleSheetContents)
218     , m_parsedProperties(parsedProperties)
219 {
220     m_range.consumeWhitespace();
221 }
222
223 void CSSPropertyParser::addProperty(CSSPropertyID property, CSSPropertyID currentShorthand, Ref<CSSValue>&& value, bool important, bool implicit)
224 {
225     int shorthandIndex = 0;
226     bool setFromShorthand = false;
227
228     if (currentShorthand) {
229         auto shorthands = matchingShorthandsForLonghand(property);
230         setFromShorthand = true;
231         if (shorthands.size() > 1)
232             shorthandIndex = indexOfShorthandForLonghand(currentShorthand, shorthands);
233     }
234
235     m_parsedProperties->append(CSSProperty(property, WTFMove(value), important, setFromShorthand, shorthandIndex, implicit));
236 }
237
238 void CSSPropertyParser::addExpandedPropertyForValue(CSSPropertyID property, Ref<CSSValue>&& value, bool important)
239 {
240     const StylePropertyShorthand& shorthand = shorthandForProperty(property);
241     unsigned shorthandLength = shorthand.length();
242     ASSERT(shorthandLength);
243     const CSSPropertyID* longhands = shorthand.properties();
244     for (unsigned i = 0; i < shorthandLength; ++i)
245         addProperty(longhands[i], property, value.copyRef(), important);
246 }
247     
248 bool CSSPropertyParser::parseValue(CSSPropertyID propertyID, bool important, const CSSParserTokenRange& range, const CSSParserContext& context, StyleSheetContents* styleSheetContents, ParsedPropertyVector& parsedProperties, StyleRule::Type ruleType)
249 {
250     int parsedPropertiesSize = parsedProperties.size();
251
252     CSSPropertyParser parser(range, context, styleSheetContents, &parsedProperties);
253     bool parseSuccess;
254
255 #if ENABLE(CSS_DEVICE_ADAPTATION)
256     if (ruleType == StyleRule::Viewport)
257         parseSuccess = parser.parseViewportDescriptor(propertyID, important);
258     else
259 #endif
260     if (ruleType == StyleRule::FontFace)
261         parseSuccess = parser.parseFontFaceDescriptor(propertyID);
262     else
263         parseSuccess = parser.parseValueStart(propertyID, important);
264
265     if (!parseSuccess)
266         parsedProperties.shrink(parsedPropertiesSize);
267
268     return parseSuccess;
269 }
270
271 RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, const CSSParserTokenRange& range, const CSSParserContext& context, StyleSheetContents* styleSheetContents)
272 {
273     CSSPropertyParser parser(range, context, styleSheetContents, nullptr);
274     RefPtr<CSSValue> value = parser.parseSingleValue(property);
275     if (!value || !parser.m_range.atEnd())
276         return nullptr;
277     return value;
278 }
279
280 static bool isLegacyBreakProperty(CSSPropertyID propertyID)
281 {
282     switch (propertyID) {
283     case CSSPropertyPageBreakAfter:
284     case CSSPropertyPageBreakBefore:
285     case CSSPropertyPageBreakInside:
286     case CSSPropertyWebkitColumnBreakAfter:
287     case CSSPropertyWebkitColumnBreakBefore:
288     case CSSPropertyWebkitColumnBreakInside:
289 #if ENABLE(CSS_REGIONS)
290     case CSSPropertyWebkitRegionBreakAfter:
291     case CSSPropertyWebkitRegionBreakBefore:
292     case CSSPropertyWebkitRegionBreakInside:
293 #endif
294         return true;
295     default:
296         break;
297     }
298     return false;
299 }
300
301 bool CSSPropertyParser::parseValueStart(CSSPropertyID propertyID, bool important)
302 {
303     if (consumeCSSWideKeyword(propertyID, important))
304         return true;
305
306     CSSParserTokenRange originalRange = m_range;
307     bool isShorthand = isShorthandCSSProperty(propertyID);
308
309     if (isShorthand) {
310         // Variable references will fail to parse here and will fall out to the variable ref parser below.
311         if (parseShorthand(propertyID, important))
312             return true;
313     } else if (isLegacyBreakProperty(propertyID)) {
314         // FIXME-NEWPARSER: Can turn this into a shorthand once old parser is gone, and then
315         // we don't need the special case.
316         if (consumeLegacyBreakProperty(propertyID, important))
317             return true;
318     } else {
319         RefPtr<CSSValue> parsedValue = parseSingleValue(propertyID);
320         if (parsedValue && m_range.atEnd()) {
321             addProperty(propertyID, CSSPropertyInvalid, *parsedValue, important);
322             return true;
323         }
324     }
325
326     if (CSSVariableParser::containsValidVariableReferences(originalRange)) {
327         RefPtr<CSSVariableReferenceValue> variable = CSSVariableReferenceValue::create(CSSVariableData::create(originalRange));
328
329         if (isShorthand) {
330             RefPtr<CSSPendingSubstitutionValue> pendingValue = CSSPendingSubstitutionValue::create(propertyID, variable.releaseNonNull());
331             addExpandedPropertyForValue(propertyID, pendingValue.releaseNonNull(), important);
332         } else
333             addProperty(propertyID, CSSPropertyInvalid, variable.releaseNonNull(), important);
334         return true;
335     }
336
337     return false;
338 }
339  
340 bool CSSPropertyParser::consumeCSSWideKeyword(CSSPropertyID propertyID, bool important)
341 {
342     CSSParserTokenRange rangeCopy = m_range;
343     CSSValueID valueID = rangeCopy.consumeIncludingWhitespace().id();
344     if (!rangeCopy.atEnd())
345         return false;
346
347     RefPtr<CSSValue> value;
348     if (valueID == CSSValueInherit)
349         value = CSSValuePool::singleton().createInheritedValue();
350     else if (valueID == CSSValueInitial)
351         value = CSSValuePool::singleton().createExplicitInitialValue();
352     else if (valueID == CSSValueUnset)
353         value = CSSValuePool::singleton().createUnsetValue();
354     else if (valueID == CSSValueRevert)
355         value = CSSValuePool::singleton().createRevertValue();
356     else
357         return false;
358     
359     const StylePropertyShorthand& shorthand = shorthandForProperty(propertyID);
360     if (!shorthand.length()) {
361         if (CSSProperty::isDescriptorOnly(propertyID))
362             return false;
363         addProperty(propertyID, CSSPropertyInvalid, value.releaseNonNull(), important);
364     } else
365         addExpandedPropertyForValue(propertyID, value.releaseNonNull(), important);
366     m_range = rangeCopy;
367     return true;
368 }
369
370 bool CSSPropertyParser::consumeTransformOrigin(bool important)
371 {
372     RefPtr<CSSPrimitiveValue> resultX;
373     RefPtr<CSSPrimitiveValue> resultY;
374     if (consumeOneOrTwoValuedPosition(m_range, m_context.mode, UnitlessQuirk::Forbid, resultX, resultY)) {
375         m_range.consumeWhitespace();
376         bool atEnd = m_range.atEnd();
377         RefPtr<CSSPrimitiveValue> resultZ = consumeLength(m_range, m_context.mode, ValueRangeAll);
378         if (!resultZ && !atEnd)
379             return false;
380         addProperty(CSSPropertyTransformOriginX, CSSPropertyTransformOrigin, resultX.releaseNonNull(), important);
381         addProperty(CSSPropertyTransformOriginY, CSSPropertyTransformOrigin, resultY.releaseNonNull(), important);
382         addProperty(CSSPropertyTransformOriginZ, CSSPropertyTransformOrigin, resultZ ? resultZ.releaseNonNull() : CSSValuePool::singleton().createValue(0, CSSPrimitiveValue::UnitTypes::CSS_PX), important, !resultZ);
383         
384         return true;
385     }
386     return false;
387 }
388
389 bool CSSPropertyParser::consumePerspectiveOrigin(bool important)
390 {
391     RefPtr<CSSPrimitiveValue> resultX;
392     RefPtr<CSSPrimitiveValue> resultY;
393     if (consumePosition(m_range, m_context.mode, UnitlessQuirk::Forbid, resultX, resultY)) {
394         addProperty(CSSPropertyPerspectiveOriginX, CSSPropertyPerspectiveOrigin, resultX.releaseNonNull(), important);
395         addProperty(CSSPropertyPerspectiveOriginY, CSSPropertyPerspectiveOrigin, resultY.releaseNonNull(), important);
396         return true;
397     }
398     return false;
399 }
400
401 // Methods for consuming non-shorthand properties starts here.
402 static RefPtr<CSSValue> consumeWillChange(CSSParserTokenRange& range)
403 {
404     if (range.peek().id() == CSSValueAuto)
405         return consumeIdent(range);
406
407     RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
408     // Every comma-separated list of identifiers is a valid will-change value,
409     // unless the list includes an explicitly disallowed identifier.
410     while (true) {
411         if (range.peek().type() != IdentToken)
412             return nullptr;
413         CSSPropertyID propertyID = cssPropertyID(range.peek().value());
414         if (propertyID != CSSPropertyInvalid) {
415             // Now "all" is used by both CSSValue and CSSPropertyValue.
416             // Need to return nullptr when currentValue is CSSPropertyAll.
417             if (propertyID == CSSPropertyWillChange || propertyID == CSSPropertyAll)
418                 return nullptr;
419             // FIXME-NEWPARSER: Use CSSCustomIdentValue someday.
420             values->append(CSSValuePool::singleton().createIdentifierValue(propertyID));
421             range.consumeIncludingWhitespace();
422         } else {
423             switch (range.peek().id()) {
424             case CSSValueNone:
425             case CSSValueAll:
426             case CSSValueAuto:
427             case CSSValueDefault:
428             case CSSValueInitial:
429             case CSSValueInherit:
430                 return nullptr;
431             case CSSValueContents:
432             case CSSValueScrollPosition:
433                 values->append(consumeIdent(range).releaseNonNull());
434                 break;
435             default:
436                 // Append properties we don't recognize, but that are legal, as strings.
437                 values->append(consumeCustomIdent(range).releaseNonNull());
438                 break;
439             }
440         }
441
442         if (range.atEnd())
443             break;
444         if (!consumeCommaIncludingWhitespace(range))
445             return nullptr;
446     }
447
448     return values;
449 }
450
451 static RefPtr<CSSFontFeatureValue> consumeFontFeatureTag(CSSParserTokenRange& range)
452 {
453     // Feature tag name consists of 4-letter characters.
454     static const unsigned tagNameLength = 4;
455
456     const CSSParserToken& token = range.consumeIncludingWhitespace();
457     // Feature tag name comes first
458     if (token.type() != StringToken)
459         return nullptr;
460     if (token.value().length() != tagNameLength)
461         return nullptr;
462     
463     FontTag tag;
464     for (unsigned i = 0; i < tag.size(); ++i) {
465         // Limits the range of characters to 0x20-0x7E, following the tag name rules defiend in the OpenType specification.
466         UChar character = token.value()[i];
467         if (character < 0x20 || character > 0x7E)
468             return nullptr;
469         tag[i] = toASCIILower(character);
470     }
471
472     int tagValue = 1;
473     // Feature tag values could follow: <integer> | on | off
474     if (range.peek().type() == NumberToken && range.peek().numericValueType() == IntegerValueType && range.peek().numericValue() >= 0) {
475         tagValue = clampTo<int>(range.consumeIncludingWhitespace().numericValue());
476         if (tagValue < 0)
477             return nullptr;
478     } else if (range.peek().id() == CSSValueOn || range.peek().id() == CSSValueOff) {
479         tagValue = range.consumeIncludingWhitespace().id() == CSSValueOn;
480     }
481     return CSSFontFeatureValue::create(WTFMove(tag), tagValue);
482 }
483
484 static RefPtr<CSSValue> consumeFontFeatureSettings(CSSParserTokenRange& range)
485 {
486     if (range.peek().id() == CSSValueNormal)
487         return consumeIdent(range);
488     RefPtr<CSSValueList> settings = CSSValueList::createCommaSeparated();
489     do {
490         RefPtr<CSSFontFeatureValue> fontFeatureValue = consumeFontFeatureTag(range);
491         if (!fontFeatureValue)
492             return nullptr;
493         settings->append(fontFeatureValue.releaseNonNull());
494     } while (consumeCommaIncludingWhitespace(range));
495     return settings;
496 }
497
498 #if ENABLE(VARIATION_FONTS)
499 static RefPtr<CSSValue> consumeFontVariationTag(CSSParserTokenRange& range)
500 {
501     if (range.peek().type() != StringToken)
502         return nullptr;
503     
504     auto string = range.consumeIncludingWhitespace().value().toString();
505     
506     FontTag tag;
507     if (string.length() != tag.size())
508         return nullptr;
509     for (unsigned i = 0; i < tag.size(); ++i) {
510         // Limits the range of characters to 0x20-0x7E, following the tag name rules defiend in the OpenType specification.
511         UChar character = string[i];
512         if (character < 0x20 || character > 0x7E)
513             return nullptr;
514         tag[i] = character;
515     }
516     
517     if (range.atEnd() || range.peek().type() != NumberToken)
518         return nullptr;
519
520     float tagValue = range.consumeIncludingWhitespace().numericValue();
521     
522     return CSSFontVariationValue::create(tag, tagValue);
523 }
524     
525 static RefPtr<CSSValue> consumeFontVariationSettings(CSSParserTokenRange& range)
526 {
527     if (range.peek().id() == CSSValueNormal)
528         return consumeIdent(range);
529     
530     auto settings = CSSValueList::createCommaSeparated();
531     do {
532         RefPtr<CSSValue> variationValue = consumeFontVariationTag(range);
533         if (!variationValue)
534             return nullptr;
535         settings->append(variationValue.releaseNonNull());
536     } while (consumeCommaIncludingWhitespace(range));
537     
538     if (!settings->length())
539         return nullptr;
540
541     return WTFMove(settings);
542 }
543 #endif // ENABLE(VARIATION_FONTS)
544
545 static RefPtr<CSSValue> consumePage(CSSParserTokenRange& range)
546 {
547     if (range.peek().id() == CSSValueAuto)
548         return consumeIdent(range);
549     return consumeCustomIdent(range);
550 }
551
552 static RefPtr<CSSValue> consumeQuotes(CSSParserTokenRange& range)
553 {
554     if (range.peek().id() == CSSValueNone)
555         return consumeIdent(range);
556     RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
557     while (!range.atEnd()) {
558         RefPtr<CSSPrimitiveValue> parsedValue = consumeString(range);
559         if (!parsedValue)
560             return nullptr;
561         values->append(parsedValue.releaseNonNull());
562     }
563     if (values->length() && values->length() % 2 == 0)
564         return values;
565     return nullptr;
566 }
567
568 class FontVariantLigaturesParser {
569 public:
570     FontVariantLigaturesParser()
571         : m_sawCommonLigaturesValue(false)
572         , m_sawDiscretionaryLigaturesValue(false)
573         , m_sawHistoricalLigaturesValue(false)
574         , m_sawContextualLigaturesValue(false)
575         , m_result(CSSValueList::createSpaceSeparated())
576     {
577     }
578
579     enum class ParseResult {
580         ConsumedValue,
581         DisallowedValue,
582         UnknownValue
583     };
584
585     ParseResult consumeLigature(CSSParserTokenRange& range)
586     {
587         CSSValueID valueID = range.peek().id();
588         switch (valueID) {
589         case CSSValueNoCommonLigatures:
590         case CSSValueCommonLigatures:
591             if (m_sawCommonLigaturesValue)
592                 return ParseResult::DisallowedValue;
593             m_sawCommonLigaturesValue = true;
594             break;
595         case CSSValueNoDiscretionaryLigatures:
596         case CSSValueDiscretionaryLigatures:
597             if (m_sawDiscretionaryLigaturesValue)
598                 return ParseResult::DisallowedValue;
599             m_sawDiscretionaryLigaturesValue = true;
600             break;
601         case CSSValueNoHistoricalLigatures:
602         case CSSValueHistoricalLigatures:
603             if (m_sawHistoricalLigaturesValue)
604                 return ParseResult::DisallowedValue;
605             m_sawHistoricalLigaturesValue = true;
606             break;
607         case CSSValueNoContextual:
608         case CSSValueContextual:
609             if (m_sawContextualLigaturesValue)
610                 return ParseResult::DisallowedValue;
611             m_sawContextualLigaturesValue = true;
612             break;
613         default:
614             return ParseResult::UnknownValue;
615         }
616         m_result->append(consumeIdent(range).releaseNonNull());
617         return ParseResult::ConsumedValue;
618     }
619
620     RefPtr<CSSValue> finalizeValue()
621     {
622         if (!m_result->length())
623             return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
624         return m_result.release();
625     }
626
627 private:
628     bool m_sawCommonLigaturesValue;
629     bool m_sawDiscretionaryLigaturesValue;
630     bool m_sawHistoricalLigaturesValue;
631     bool m_sawContextualLigaturesValue;
632     RefPtr<CSSValueList> m_result;
633 };
634
635 static RefPtr<CSSValue> consumeFontVariantLigatures(CSSParserTokenRange& range)
636 {
637     if (range.peek().id() == CSSValueNormal || range.peek().id() == CSSValueNone)
638         return consumeIdent(range);
639
640     FontVariantLigaturesParser ligaturesParser;
641     do {
642         if (ligaturesParser.consumeLigature(range) !=
643             FontVariantLigaturesParser::ParseResult::ConsumedValue)
644             return nullptr;
645     } while (!range.atEnd());
646
647     return ligaturesParser.finalizeValue();
648 }
649
650 static RefPtr<CSSValue> consumeFontVariantEastAsian(CSSParserTokenRange& range)
651 {
652     if (range.peek().id() == CSSValueNormal)
653         return consumeIdent(range);
654     
655     RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
656     FontVariantEastAsianVariant variant = FontVariantEastAsianVariant::Normal;
657     FontVariantEastAsianWidth width = FontVariantEastAsianWidth::Normal;
658     FontVariantEastAsianRuby ruby = FontVariantEastAsianRuby::Normal;
659     
660     while (!range.atEnd()) {
661         if (range.peek().type() != IdentToken)
662             return nullptr;
663         
664         auto id = range.peek().id();
665         
666         switch (id) {
667         case CSSValueJis78:
668             variant = FontVariantEastAsianVariant::Jis78;
669             break;
670         case CSSValueJis83:
671             variant = FontVariantEastAsianVariant::Jis83;
672             break;
673         case CSSValueJis90:
674             variant = FontVariantEastAsianVariant::Jis90;
675             break;
676         case CSSValueJis04:
677             variant = FontVariantEastAsianVariant::Jis04;
678             break;
679         case CSSValueSimplified:
680             variant = FontVariantEastAsianVariant::Simplified;
681             break;
682         case CSSValueTraditional:
683             variant = FontVariantEastAsianVariant::Traditional;
684             break;
685         case CSSValueFullWidth:
686             width = FontVariantEastAsianWidth::Full;
687             break;
688         case CSSValueProportionalWidth:
689             width = FontVariantEastAsianWidth::Proportional;
690             break;
691         case CSSValueRuby:
692             ruby = FontVariantEastAsianRuby::Yes;
693             break;
694         default:
695             return nullptr;
696         }
697         
698         range.consumeIncludingWhitespace();
699     }
700         
701     switch (variant) {
702     case FontVariantEastAsianVariant::Normal:
703         break;
704     case FontVariantEastAsianVariant::Jis78:
705         values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis78));
706         break;
707     case FontVariantEastAsianVariant::Jis83:
708         values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis83));
709         break;
710     case FontVariantEastAsianVariant::Jis90:
711         values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis90));
712         break;
713     case FontVariantEastAsianVariant::Jis04:
714         values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis04));
715         break;
716     case FontVariantEastAsianVariant::Simplified:
717         values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueSimplified));
718         break;
719     case FontVariantEastAsianVariant::Traditional:
720         values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueTraditional));
721         break;
722     }
723         
724     switch (width) {
725     case FontVariantEastAsianWidth::Normal:
726         break;
727     case FontVariantEastAsianWidth::Full:
728         values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueFullWidth));
729         break;
730     case FontVariantEastAsianWidth::Proportional:
731         values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueProportionalWidth));
732         break;
733     }
734         
735     switch (ruby) {
736     case FontVariantEastAsianRuby::Normal:
737         break;
738     case FontVariantEastAsianRuby::Yes:
739         values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueRuby));
740     }
741
742     if (!values->length())
743         return nullptr;
744
745     return values;
746 }
747     
748 static RefPtr<CSSPrimitiveValue> consumeFontVariantCaps(CSSParserTokenRange& range)
749 {
750     return consumeIdent<CSSValueNormal, CSSValueSmallCaps, CSSValueAllSmallCaps,
751         CSSValuePetiteCaps, CSSValueAllPetiteCaps,
752         CSSValueUnicase, CSSValueTitlingCaps>(range);
753 }
754
755 static RefPtr<CSSPrimitiveValue> consumeFontVariantAlternates(CSSParserTokenRange& range)
756 {
757     return consumeIdent<CSSValueNormal, CSSValueHistoricalForms>(range);
758 }
759
760 static RefPtr<CSSPrimitiveValue> consumeFontVariantPosition(CSSParserTokenRange& range)
761 {
762     return consumeIdent<CSSValueNormal, CSSValueSub, CSSValueSuper>(range);
763 }
764
765 class FontVariantNumericParser {
766 public:
767     FontVariantNumericParser()
768         : m_sawNumericFigureValue(false)
769         , m_sawNumericSpacingValue(false)
770         , m_sawNumericFractionValue(false)
771         , m_sawOrdinalValue(false)
772         , m_sawSlashedZeroValue(false)
773         , m_result(CSSValueList::createSpaceSeparated())
774     {
775     }
776
777     enum class ParseResult {
778         ConsumedValue,
779         DisallowedValue,
780         UnknownValue
781     };
782
783     ParseResult consumeNumeric(CSSParserTokenRange& range)
784     {
785         CSSValueID valueID = range.peek().id();
786         switch (valueID) {
787         case CSSValueLiningNums:
788         case CSSValueOldstyleNums:
789             if (m_sawNumericFigureValue)
790                 return ParseResult::DisallowedValue;
791             m_sawNumericFigureValue = true;
792             break;
793         case CSSValueProportionalNums:
794         case CSSValueTabularNums:
795             if (m_sawNumericSpacingValue)
796                 return ParseResult::DisallowedValue;
797             m_sawNumericSpacingValue = true;
798             break;
799         case CSSValueDiagonalFractions:
800         case CSSValueStackedFractions:
801             if (m_sawNumericFractionValue)
802                 return ParseResult::DisallowedValue;
803             m_sawNumericFractionValue = true;
804             break;
805         case CSSValueOrdinal:
806             if (m_sawOrdinalValue)
807                 return ParseResult::DisallowedValue;
808             m_sawOrdinalValue = true;
809             break;
810         case CSSValueSlashedZero:
811             if (m_sawSlashedZeroValue)
812                 return ParseResult::DisallowedValue;
813             m_sawSlashedZeroValue = true;
814             break;
815         default:
816             return ParseResult::UnknownValue;
817         }
818         m_result->append(consumeIdent(range).releaseNonNull());
819         return ParseResult::ConsumedValue;
820     }
821
822     RefPtr<CSSValue> finalizeValue()
823     {
824         if (!m_result->length())
825             return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
826         return m_result.release();
827     }
828
829
830 private:
831     bool m_sawNumericFigureValue;
832     bool m_sawNumericSpacingValue;
833     bool m_sawNumericFractionValue;
834     bool m_sawOrdinalValue;
835     bool m_sawSlashedZeroValue;
836     RefPtr<CSSValueList> m_result;
837 };
838
839 static RefPtr<CSSValue> consumeFontVariantNumeric(CSSParserTokenRange& range)
840 {
841     if (range.peek().id() == CSSValueNormal)
842         return consumeIdent(range);
843
844     FontVariantNumericParser numericParser;
845     do {
846         if (numericParser.consumeNumeric(range) !=
847             FontVariantNumericParser::ParseResult::ConsumedValue)
848             return nullptr;
849     } while (!range.atEnd());
850
851     return numericParser.finalizeValue();
852 }
853
854 static RefPtr<CSSPrimitiveValue> consumeFontVariantCSS21(CSSParserTokenRange& range)
855 {
856     return consumeIdent<CSSValueNormal, CSSValueSmallCaps>(range);
857 }
858
859 static RefPtr<CSSPrimitiveValue> consumeFontWeight(CSSParserTokenRange& range)
860 {
861     const CSSParserToken& token = range.peek();
862     if (token.id() >= CSSValueNormal && token.id() <= CSSValueLighter)
863         return consumeIdent(range);
864     if (token.type() != NumberToken || token.numericValueType() != IntegerValueType)
865         return nullptr;
866     int weight = static_cast<int>(token.numericValue());
867     if ((weight % 100) || weight < 100 || weight > 900)
868         return nullptr;
869     range.consumeIncludingWhitespace();
870     return CSSValuePool::singleton().createIdentifierValue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1));
871 }
872
873 static String concatenateFamilyName(CSSParserTokenRange& range)
874 {
875     StringBuilder builder;
876     bool addedSpace = false;
877     const CSSParserToken& firstToken = range.peek();
878     while (range.peek().type() == IdentToken) {
879         if (!builder.isEmpty()) {
880             builder.append(' ');
881             addedSpace = true;
882         }
883         builder.append(range.consumeIncludingWhitespace().value());
884     }
885     if (!addedSpace && isCSSWideKeyword(firstToken.id()))
886         return String();
887     return builder.toString();
888 }
889
890 static RefPtr<CSSValue> consumeFamilyName(CSSParserTokenRange& range)
891 {
892     if (range.peek().type() == StringToken)
893         return CSSValuePool::singleton().createFontFamilyValue(range.consumeIncludingWhitespace().value().toString());
894     if (range.peek().type() != IdentToken)
895         return nullptr;
896     String familyName = concatenateFamilyName(range);
897     if (familyName.isNull())
898         return nullptr;
899     return CSSValuePool::singleton().createFontFamilyValue(familyName);
900 }
901
902 static RefPtr<CSSValue> consumeGenericFamily(CSSParserTokenRange& range)
903 {
904     return consumeIdentRange(range, CSSValueSerif, CSSValueWebkitBody);
905 }
906
907 static RefPtr<CSSValueList> consumeFontFamily(CSSParserTokenRange& range)
908 {
909     RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
910     do {
911         RefPtr<CSSValue> parsedValue = consumeGenericFamily(range);
912         if (parsedValue) {
913             list->append(parsedValue.releaseNonNull());
914         } else {
915             parsedValue = consumeFamilyName(range);
916             if (parsedValue) {
917                 list->append(parsedValue.releaseNonNull());
918             } else {
919                 return nullptr;
920             }
921         }
922     } while (consumeCommaIncludingWhitespace(range));
923     return list;
924 }
925
926 static RefPtr<CSSValueList> consumeFontFamilyDescriptor(CSSParserTokenRange& range)
927 {
928     // FIXME-NEWPARSER: For compatibility with the old parser, we have to make
929     // a list here, even though the list always contains only a single family name.
930     // Once the old parser is gone, we can delete this function, make the caller
931     // use consumeFamilyName instead, and then patch the @font-face code to
932     // not expect a list with a single name in it.
933     RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
934     RefPtr<CSSValue> parsedValue = consumeFamilyName(range);
935     if (parsedValue)
936         list->append(parsedValue.releaseNonNull());
937     
938     if (!range.atEnd() || !list->length())
939         return nullptr;
940
941     return list;
942 }
943
944 static RefPtr<CSSValue> consumeFontSynthesis(CSSParserTokenRange& range)
945 {
946     // none | [ weight || style ]
947     CSSValueID id = range.peek().id();
948     if (id == CSSValueNone)
949         return consumeIdent(range);
950     
951     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
952     while (true) {
953         auto ident = consumeIdent<CSSValueWeight, CSSValueStyle>(range);
954         if (!ident)
955             break;
956         if (list->hasValue(ident.get()))
957             return nullptr;
958         list->append(ident.releaseNonNull());
959     }
960     
961     if (!list->length())
962         return nullptr;
963     return list;
964 }
965
966 static RefPtr<CSSValue> consumeLetterSpacing(CSSParserTokenRange& range, CSSParserMode cssParserMode)
967 {
968     if (range.peek().id() == CSSValueNormal)
969         return consumeIdent(range);
970     
971     return consumeLength(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
972 }
973
974 static RefPtr<CSSValue> consumeWordSpacing(CSSParserTokenRange& range, CSSParserMode cssParserMode)
975 {
976     if (range.peek().id() == CSSValueNormal)
977         return consumeIdent(range);
978     
979     return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
980 }
981     
982 static RefPtr<CSSValue> consumeTabSize(CSSParserTokenRange& range, CSSParserMode cssParserMode)
983 {
984     RefPtr<CSSPrimitiveValue> parsedValue = consumeInteger(range, 0);
985     if (parsedValue)
986         return parsedValue;
987     return consumeLength(range, cssParserMode, ValueRangeNonNegative);
988 }
989
990 #if ENABLE(TEXT_AUTOSIZING)
991 static RefPtr<CSSValue> consumeTextSizeAdjust(CSSParserTokenRange& range, CSSParserMode /* cssParserMode */)
992 {
993     if (range.peek().id() == CSSValueAuto)
994         return consumeIdent(range);
995     if (range.peek().id() == CSSValueNone)
996         return consumeIdent(range);
997     return consumePercent(range, ValueRangeNonNegative);
998 }
999 #endif
1000
1001 static RefPtr<CSSValue> consumeFontSize(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless = UnitlessQuirk::Forbid)
1002 {
1003     if (range.peek().id() >= CSSValueXxSmall && range.peek().id() <= CSSValueLarger)
1004         return consumeIdent(range);
1005     return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, unitless);
1006 }
1007
1008 static RefPtr<CSSPrimitiveValue> consumeLineHeight(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1009 {
1010     if (range.peek().id() == CSSValueNormal)
1011         return consumeIdent(range);
1012
1013     RefPtr<CSSPrimitiveValue> lineHeight = consumeNumber(range, ValueRangeNonNegative);
1014     if (lineHeight)
1015         return lineHeight;
1016     return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
1017 }
1018
1019 template<typename... Args>
1020 static Ref<CSSPrimitiveValue> createPrimitiveValuePair(Args&&... args)
1021 {
1022     return CSSValuePool::singleton().createValue(Pair::create(std::forward<Args>(args)...));
1023 }
1024
1025 static RefPtr<CSSValue> consumeCounter(CSSParserTokenRange& range, int defaultValue)
1026 {
1027     if (range.peek().id() == CSSValueNone)
1028         return consumeIdent(range);
1029
1030     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1031     do {
1032         RefPtr<CSSPrimitiveValue> counterName = consumeCustomIdent(range);
1033         if (!counterName)
1034             return nullptr;
1035         int i = defaultValue;
1036         if (RefPtr<CSSPrimitiveValue> counterValue = consumeInteger(range))
1037             i = counterValue->intValue();
1038         list->append(createPrimitiveValuePair(counterName.releaseNonNull(), CSSPrimitiveValue::create(i, CSSPrimitiveValue::UnitTypes::CSS_NUMBER), Pair::IdenticalValueEncoding::Coalesce));
1039     } while (!range.atEnd());
1040     return list;
1041 }
1042
1043 static RefPtr<CSSValue> consumePageSize(CSSParserTokenRange& range)
1044 {
1045     return consumeIdent<CSSValueA3, CSSValueA4, CSSValueA5, CSSValueB4, CSSValueB5, CSSValueLedger, CSSValueLegal, CSSValueLetter>(range);
1046 }
1047
1048 static RefPtr<CSSValueList> consumeSize(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1049 {
1050     RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
1051
1052     if (range.peek().id() == CSSValueAuto) {
1053         result->append(consumeIdent(range).releaseNonNull());
1054         return result;
1055     }
1056
1057     if (RefPtr<CSSValue> width = consumeLength(range, cssParserMode, ValueRangeNonNegative)) {
1058         RefPtr<CSSValue> height = consumeLength(range, cssParserMode, ValueRangeNonNegative);
1059         result->append(width.releaseNonNull());
1060         if (height)
1061             result->append(height.releaseNonNull());
1062         return result;
1063     }
1064
1065     RefPtr<CSSValue> pageSize = consumePageSize(range);
1066     RefPtr<CSSValue> orientation = consumeIdent<CSSValuePortrait, CSSValueLandscape>(range);
1067     if (!pageSize)
1068         pageSize = consumePageSize(range);
1069
1070     if (!orientation && !pageSize)
1071         return nullptr;
1072     if (pageSize)
1073         result->append(pageSize.releaseNonNull());
1074     if (orientation)
1075         result->append(orientation.releaseNonNull());
1076     return result;
1077 }
1078
1079 static RefPtr<CSSValue> consumeTextIndent(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1080 {
1081     // [ <length> | <percentage> ] && hanging? && each-line?
1082     // Keywords only allowed when css3Text is enabled.
1083     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1084
1085     bool hasLengthOrPercentage = false;
1086 //    bool hasEachLine = false;
1087     bool hasHanging = false;
1088
1089     do {
1090         if (!hasLengthOrPercentage) {
1091             if (RefPtr<CSSValue> textIndent = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow)) {
1092                 list->append(*textIndent);
1093                 hasLengthOrPercentage = true;
1094                 continue;
1095             }
1096         }
1097
1098         CSSValueID id = range.peek().id();
1099  /* FIXME-NEWPARSER: We don't support this yet.
1100         if (!hasEachLine && id == CSSValueEachLine) {
1101             list->append(*consumeIdent(range));
1102             hasEachLine = true;
1103             continue;
1104         }
1105 */
1106         
1107         if (!hasHanging && id == CSSValueHanging) {
1108             list->append(consumeIdent(range).releaseNonNull());
1109             hasHanging = true;
1110             continue;
1111         }
1112         
1113         return nullptr;
1114     } while (!range.atEnd());
1115
1116     if (!hasLengthOrPercentage)
1117         return nullptr;
1118
1119     return list;
1120 }
1121
1122 // FIXME-NEWPARSER: Drop the prefix on min-content, max-content and fit-content.
1123 static bool validWidthOrHeightKeyword(CSSValueID id, const CSSParserContext& /*context*/)
1124 {
1125     if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent) {
1126         return true;
1127     }
1128     return false;
1129 }
1130
1131 static RefPtr<CSSValue> consumeMaxWidthOrHeight(CSSParserTokenRange& range, const CSSParserContext& context, UnitlessQuirk unitless = UnitlessQuirk::Forbid)
1132 {
1133     if (range.peek().id() == CSSValueNone || validWidthOrHeightKeyword(range.peek().id(), context))
1134         return consumeIdent(range);
1135     return consumeLengthOrPercent(range, context.mode, ValueRangeNonNegative, unitless);
1136 }
1137
1138 static RefPtr<CSSValue> consumeWidthOrHeight(CSSParserTokenRange& range, const CSSParserContext& context, UnitlessQuirk unitless = UnitlessQuirk::Forbid)
1139 {
1140     if (range.peek().id() == CSSValueAuto || validWidthOrHeightKeyword(range.peek().id(), context))
1141         return consumeIdent(range);
1142     return consumeLengthOrPercent(range, context.mode, ValueRangeNonNegative, unitless);
1143 }
1144
1145 static RefPtr<CSSValue> consumeMarginOrOffset(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
1146 {
1147     if (range.peek().id() == CSSValueAuto)
1148         return consumeIdent(range);
1149     return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, unitless);
1150 }
1151
1152 static RefPtr<CSSPrimitiveValue> consumeClipComponent(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1153 {
1154     if (range.peek().id() == CSSValueAuto)
1155         return consumeIdent(range);
1156     return consumeLength(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
1157 }
1158
1159 static RefPtr<CSSValue> consumeClip(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1160 {
1161     if (range.peek().id() == CSSValueAuto)
1162         return consumeIdent(range);
1163
1164     if (range.peek().functionId() != CSSValueRect)
1165         return nullptr;
1166
1167     CSSParserTokenRange args = consumeFunction(range);
1168     // rect(t, r, b, l) || rect(t r b l)
1169     RefPtr<CSSPrimitiveValue> top = consumeClipComponent(args, cssParserMode);
1170     if (!top)
1171         return nullptr;
1172     bool needsComma = consumeCommaIncludingWhitespace(args);
1173     RefPtr<CSSPrimitiveValue> right = consumeClipComponent(args, cssParserMode);
1174     if (!right || (needsComma && !consumeCommaIncludingWhitespace(args)))
1175         return nullptr;
1176     RefPtr<CSSPrimitiveValue> bottom = consumeClipComponent(args, cssParserMode);
1177     if (!bottom || (needsComma && !consumeCommaIncludingWhitespace(args)))
1178         return nullptr;
1179     RefPtr<CSSPrimitiveValue> left = consumeClipComponent(args, cssParserMode);
1180     if (!left || !args.atEnd())
1181         return nullptr;
1182     
1183     auto rect = Rect::create();
1184     rect->setLeft(left.releaseNonNull());
1185     rect->setTop(top.releaseNonNull());
1186     rect->setRight(right.releaseNonNull());
1187     rect->setBottom(bottom.releaseNonNull());
1188     return CSSValuePool::singleton().createValue(WTFMove(rect));
1189 }
1190
1191 #if ENABLE(TOUCH_EVENTS)
1192 static RefPtr<CSSValue> consumeTouchAction(CSSParserTokenRange& range)
1193 {
1194     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1195     CSSValueID id = range.peek().id();
1196     if (id == CSSValueAuto || id == CSSValueNone || id == CSSValueManipulation) {
1197         list->append(consumeIdent(range).releaseNonNull());
1198         return list;
1199     }
1200     // FIXME-NEWPARSER: Support pan.
1201     return nullptr;
1202 }
1203 #endif
1204
1205 static RefPtr<CSSPrimitiveValue> consumeLineClamp(CSSParserTokenRange& range)
1206 {
1207     RefPtr<CSSPrimitiveValue> clampValue = consumePercent(range, ValueRangeNonNegative);
1208     if (clampValue)
1209         return clampValue;
1210     // When specifying number of lines, don't allow 0 as a valid value.
1211     return consumePositiveInteger(range);
1212 }
1213
1214 static RefPtr<CSSValue> consumeLocale(CSSParserTokenRange& range)
1215 {
1216     if (range.peek().id() == CSSValueAuto)
1217         return consumeIdent(range);
1218     return consumeString(range);
1219 }
1220
1221 static RefPtr<CSSValue> consumeHyphenateLimit(CSSParserTokenRange& range, CSSValueID valueID)
1222 {
1223     if (range.peek().id() == valueID)
1224         return consumeIdent(range);
1225     return consumeNumber(range, ValueRangeNonNegative);
1226 }
1227
1228 static RefPtr<CSSValue> consumeColumnWidth(CSSParserTokenRange& range)
1229 {
1230     if (range.peek().id() == CSSValueAuto)
1231         return consumeIdent(range);
1232     // Always parse lengths in strict mode here, since it would be ambiguous otherwise when used in
1233     // the 'columns' shorthand property.
1234     RefPtr<CSSPrimitiveValue> columnWidth = consumeLength(range, HTMLStandardMode, ValueRangeNonNegative);
1235     if (!columnWidth || (!columnWidth->isCalculated() && columnWidth->doubleValue() == 0))
1236         return nullptr;
1237     return columnWidth;
1238 }
1239
1240 static RefPtr<CSSValue> consumeColumnCount(CSSParserTokenRange& range)
1241 {
1242     if (range.peek().id() == CSSValueAuto)
1243         return consumeIdent(range);
1244     return consumePositiveInteger(range);
1245 }
1246
1247 static RefPtr<CSSValue> consumeColumnGap(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1248 {
1249     if (range.peek().id() == CSSValueNormal)
1250         return consumeIdent(range);
1251     return consumeLength(range, cssParserMode, ValueRangeNonNegative);
1252 }
1253
1254 static RefPtr<CSSValue> consumeColumnSpan(CSSParserTokenRange& range)
1255 {
1256     return consumeIdent<CSSValueAll, CSSValueNone>(range);
1257 }
1258
1259 static RefPtr<CSSValue> consumeZoom(CSSParserTokenRange& range, const CSSParserContext& /*context*/)
1260 {
1261     const CSSParserToken& token = range.peek();
1262     RefPtr<CSSPrimitiveValue> zoom;
1263     if (token.type() == IdentToken)
1264         zoom = consumeIdent<CSSValueNormal, CSSValueReset, CSSValueDocument>(range);
1265     else {
1266         zoom = consumePercent(range, ValueRangeNonNegative);
1267         if (!zoom)
1268             zoom = consumeNumber(range, ValueRangeNonNegative);
1269     }
1270     return zoom;
1271 }
1272
1273 static RefPtr<CSSValue> consumeAnimationIterationCount(CSSParserTokenRange& range)
1274 {
1275     if (range.peek().id() == CSSValueInfinite)
1276         return consumeIdent(range);
1277     return consumeNumber(range, ValueRangeNonNegative);
1278 }
1279
1280 static RefPtr<CSSValue> consumeAnimationName(CSSParserTokenRange& range)
1281 {
1282     if (range.peek().id() == CSSValueNone)
1283         return consumeIdent(range);
1284
1285     if (range.peek().type() == StringToken) {
1286         const CSSParserToken& token = range.consumeIncludingWhitespace();
1287         if (equalIgnoringASCIICase(token.value(), "none"))
1288             return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
1289         // FIXME-NEWPARSER: Want to use a CSSCustomIdentValue here eventually.
1290         return CSSValuePool::singleton().createValue(token.value().toString(), CSSPrimitiveValue::UnitTypes::CSS_STRING);
1291     }
1292
1293     return consumeCustomIdent(range);
1294 }
1295
1296 static RefPtr<CSSValue> consumeTransitionProperty(CSSParserTokenRange& range)
1297 {
1298     const CSSParserToken& token = range.peek();
1299     if (token.type() != IdentToken)
1300         return nullptr;
1301     if (token.id() == CSSValueNone)
1302         return consumeIdent(range);
1303
1304     if (CSSPropertyID property = token.parseAsCSSPropertyID()) {
1305         range.consumeIncludingWhitespace();
1306         
1307         // FIXME-NEWPARSER: No reason why we can't use the "all" property now that it exists.
1308         // The old parser used a value keyword for "all", though, since it predated support for
1309         // the property.
1310         if (property == CSSPropertyAll)
1311             return CSSValuePool::singleton().createIdentifierValue(CSSValueAll);
1312
1313         // FIXME-NEWPARSER: Want to use a CSSCustomIdentValue here eventually.
1314         return CSSValuePool::singleton().createIdentifierValue(property);
1315     }
1316     return consumeCustomIdent(range);
1317 }
1318
1319     
1320 static RefPtr<CSSValue> consumeSteps(CSSParserTokenRange& range) {
1321     ASSERT(range.peek().functionId() == CSSValueSteps);
1322     CSSParserTokenRange rangeCopy = range;
1323     CSSParserTokenRange args = consumeFunction(rangeCopy);
1324     
1325     RefPtr<CSSPrimitiveValue> steps = consumePositiveInteger(args);
1326     if (!steps)
1327         return nullptr;
1328     
1329     // FIXME-NEWPARSER: Support the middle value and change from a boolean to an enum.
1330     bool stepAtStart = false;
1331     if (consumeCommaIncludingWhitespace(args)) {
1332         switch (args.consumeIncludingWhitespace().id()) {
1333             case CSSValueStart:
1334                 stepAtStart = true;
1335             break;
1336             case CSSValueEnd:
1337                 stepAtStart = false;
1338                 break;
1339             default:
1340                 return nullptr;
1341         }
1342     }
1343     
1344     if (!args.atEnd())
1345         return nullptr;
1346     
1347     range = rangeCopy;
1348     return CSSStepsTimingFunctionValue::create(steps->intValue(), stepAtStart);
1349 }
1350
1351 static RefPtr<CSSValue> consumeCubicBezier(CSSParserTokenRange& range)
1352 {
1353     ASSERT(range.peek().functionId() == CSSValueCubicBezier);
1354     CSSParserTokenRange rangeCopy = range;
1355     CSSParserTokenRange args = consumeFunction(rangeCopy);
1356
1357     double x1, y1, x2, y2;
1358     if (consumeNumberRaw(args, x1)
1359         && x1 >= 0 && x1 <= 1
1360         && consumeCommaIncludingWhitespace(args)
1361         && consumeNumberRaw(args, y1)
1362         && consumeCommaIncludingWhitespace(args)
1363         && consumeNumberRaw(args, x2)
1364         && x2 >= 0 && x2 <= 1
1365         && consumeCommaIncludingWhitespace(args)
1366         && consumeNumberRaw(args, y2)
1367         && args.atEnd()) {
1368         range = rangeCopy;
1369         return CSSCubicBezierTimingFunctionValue::create(x1, y1, x2, y2);
1370     }
1371
1372     return nullptr;
1373 }
1374
1375 static RefPtr<CSSValue> consumeSpringFunction(CSSParserTokenRange& range)
1376 {
1377     ASSERT(range.peek().functionId() == CSSValueSpring);
1378     CSSParserTokenRange rangeCopy = range;
1379     CSSParserTokenRange args = consumeFunction(rangeCopy);
1380
1381     // Mass must be greater than 0.
1382     double mass;
1383     if (!consumeNumberRaw(args, mass) || mass <= 0)
1384         return nullptr;
1385     
1386     // Stiffness must be greater than 0.
1387     double stiffness;
1388     if (!consumeNumberRaw(args, stiffness) || stiffness <= 0)
1389         return nullptr;
1390     
1391     // Damping coefficient must be greater than or equal to 0.
1392     double damping;
1393     if (!consumeNumberRaw(args, damping) || damping < 0)
1394         return nullptr;
1395     
1396     // Initial velocity may have any value.
1397     double initialVelocity;
1398     if (!consumeNumberRaw(args, initialVelocity))
1399         return nullptr;
1400
1401     if (!args.atEnd())
1402         return nullptr;
1403
1404     range = rangeCopy;
1405
1406     return CSSSpringTimingFunctionValue::create(mass, stiffness, damping, initialVelocity);
1407 }
1408
1409 static RefPtr<CSSValue> consumeAnimationTimingFunction(CSSParserTokenRange& range, const CSSParserContext& context)
1410 {
1411     CSSValueID id = range.peek().id();
1412     if (id == CSSValueEase || id == CSSValueLinear || id == CSSValueEaseIn
1413         || id == CSSValueEaseOut || id == CSSValueEaseInOut || id == CSSValueStepStart || id == CSSValueStepEnd)
1414         return consumeIdent(range);
1415
1416     CSSValueID function = range.peek().functionId();
1417     if (function == CSSValueCubicBezier)
1418         return consumeCubicBezier(range);
1419     if (function == CSSValueSteps)
1420         return consumeSteps(range);
1421     if (context.springTimingFunctionEnabled && function == CSSValueSpring)
1422         return consumeSpringFunction(range);
1423     return nullptr;
1424 }
1425
1426 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
1427 static RefPtr<CSSValue> consumeWebkitAnimationTrigger(CSSParserTokenRange& range, CSSParserMode mode)
1428 {
1429     if (range.peek().id() == CSSValueAuto)
1430         return consumeIdent(range);
1431     
1432     if (range.peek().functionId() != CSSValueContainerScroll)
1433         return nullptr;
1434     
1435     CSSParserTokenRange rangeCopy = range;
1436     CSSParserTokenRange args = consumeFunction(rangeCopy);
1437
1438     RefPtr<CSSPrimitiveValue> startValue = consumeLength(args, mode, ValueRangeAll, UnitlessQuirk::Forbid);
1439     if (!startValue)
1440         return nullptr;
1441     
1442     if (args.atEnd()) {
1443         range = rangeCopy;
1444         return CSSAnimationTriggerScrollValue::create(startValue.releaseNonNull());
1445     }
1446
1447     if (!consumeCommaIncludingWhitespace(args))
1448         return nullptr;
1449
1450     RefPtr<CSSPrimitiveValue> endValue = consumeLength(args, mode, ValueRangeAll, UnitlessQuirk::Forbid);
1451     if (!endValue || !args.atEnd())
1452         return nullptr;
1453
1454     range = rangeCopy;
1455
1456     return CSSAnimationTriggerScrollValue::create(startValue.releaseNonNull(), endValue.releaseNonNull());
1457 }
1458 #endif
1459     
1460 static RefPtr<CSSValue> consumeAnimationValue(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
1461 {
1462     switch (property) {
1463     case CSSPropertyAnimationDelay:
1464     case CSSPropertyTransitionDelay:
1465         return consumeTime(range, context.mode, ValueRangeAll, UnitlessQuirk::Forbid);
1466     case CSSPropertyAnimationDirection:
1467         return consumeIdent<CSSValueNormal, CSSValueAlternate, CSSValueReverse, CSSValueAlternateReverse>(range);
1468     case CSSPropertyAnimationDuration:
1469     case CSSPropertyTransitionDuration:
1470         return consumeTime(range, context.mode, ValueRangeNonNegative, UnitlessQuirk::Allow);
1471     case CSSPropertyAnimationFillMode:
1472         return consumeIdent<CSSValueNone, CSSValueForwards, CSSValueBackwards, CSSValueBoth>(range);
1473     case CSSPropertyAnimationIterationCount:
1474         return consumeAnimationIterationCount(range);
1475     case CSSPropertyAnimationName:
1476         return consumeAnimationName(range);
1477     case CSSPropertyAnimationPlayState:
1478         return consumeIdent<CSSValueRunning, CSSValuePaused>(range);
1479     case CSSPropertyTransitionProperty:
1480         return consumeTransitionProperty(range);
1481     case CSSPropertyAnimationTimingFunction:
1482     case CSSPropertyTransitionTimingFunction:
1483         return consumeAnimationTimingFunction(range, context);
1484 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
1485     case CSSPropertyWebkitAnimationTrigger:
1486         return consumeWebkitAnimationTrigger(range, context.mode);
1487 #endif
1488     default:
1489         ASSERT_NOT_REACHED();
1490         return nullptr;
1491     }
1492 }
1493
1494 static bool isValidAnimationPropertyList(CSSPropertyID property, const CSSValueList& valueList)
1495 {
1496     if (property != CSSPropertyTransitionProperty || valueList.length() < 2)
1497         return true;
1498     for (auto& value : valueList) {
1499         if (value->isPrimitiveValue() && downcast<CSSPrimitiveValue>(value.get()).isValueID()
1500             && downcast<CSSPrimitiveValue>(value.get()).valueID() == CSSValueNone)
1501             return false;
1502     }
1503     return true;
1504 }
1505
1506 static RefPtr<CSSValue> consumeAnimationPropertyList(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
1507 {
1508     RefPtr<CSSValueList> list;
1509     RefPtr<CSSValue> singleton;
1510     do {
1511         RefPtr<CSSValue> currentValue = consumeAnimationValue(property, range, context);
1512         if (!currentValue)
1513             return nullptr;
1514         
1515         if (singleton && !list) {
1516             list = CSSValueList::createCommaSeparated();
1517             list->append(singleton.releaseNonNull());
1518         }
1519         
1520         if (list)
1521             list->append(currentValue.releaseNonNull());
1522         else
1523             singleton = WTFMove(currentValue);
1524         
1525     } while (consumeCommaIncludingWhitespace(range));
1526
1527     if (list) {
1528         if (!isValidAnimationPropertyList(property, *list))
1529             return nullptr;
1530     
1531         ASSERT(list->length());
1532         return list;
1533     }
1534     
1535     return singleton;
1536 }
1537
1538 bool CSSPropertyParser::consumeAnimationShorthand(const StylePropertyShorthand& shorthand, bool important)
1539 {
1540     const unsigned longhandCount = shorthand.length();
1541     RefPtr<CSSValueList> longhands[8];
1542     ASSERT(longhandCount <= 8);
1543     for (size_t i = 0; i < longhandCount; ++i)
1544         longhands[i] = CSSValueList::createCommaSeparated();
1545
1546     do {
1547         bool parsedLonghand[8] = { false };
1548         do {
1549             bool foundProperty = false;
1550             for (size_t i = 0; i < longhandCount; ++i) {
1551                 if (parsedLonghand[i])
1552                     continue;
1553
1554                 if (RefPtr<CSSValue> value = consumeAnimationValue(shorthand.properties()[i], m_range, m_context)) {
1555                     parsedLonghand[i] = true;
1556                     foundProperty = true;
1557                     longhands[i]->append(*value);
1558                     break;
1559                 }
1560             }
1561             if (!foundProperty)
1562                 return false;
1563         } while (!m_range.atEnd() && m_range.peek().type() != CommaToken);
1564
1565         // FIXME: This will make invalid longhands, see crbug.com/386459
1566         for (size_t i = 0; i < longhandCount; ++i) {
1567             if (!parsedLonghand[i])
1568                 longhands[i]->append(CSSValuePool::singleton().createImplicitInitialValue());
1569             parsedLonghand[i] = false;
1570         }
1571     } while (consumeCommaIncludingWhitespace(m_range));
1572
1573     for (size_t i = 0; i < longhandCount; ++i) {
1574         if (!isValidAnimationPropertyList(shorthand.properties()[i], *longhands[i]))
1575             return false;
1576     }
1577
1578     for (size_t i = 0; i < longhandCount; ++i)
1579         addProperty(shorthand.properties()[i], shorthand.id(), *longhands[i], important);
1580
1581     return m_range.atEnd();
1582 }
1583
1584 static RefPtr<CSSValue> consumeZIndex(CSSParserTokenRange& range)
1585 {
1586     if (range.peek().id() == CSSValueAuto)
1587         return consumeIdent(range);
1588     return consumeInteger(range);
1589 }
1590
1591 static RefPtr<CSSValue> consumeShadow(CSSParserTokenRange& range, CSSParserMode cssParserMode, bool isBoxShadowProperty)
1592 {
1593     if (range.peek().id() == CSSValueNone)
1594         return consumeIdent(range);
1595
1596     RefPtr<CSSValueList> shadowValueList = CSSValueList::createCommaSeparated();
1597     do {
1598         if (RefPtr<CSSShadowValue> shadowValue = consumeSingleShadow(range, cssParserMode, isBoxShadowProperty, isBoxShadowProperty))
1599             shadowValueList->append(*shadowValue);
1600         else
1601             return nullptr;
1602     } while (consumeCommaIncludingWhitespace(range));
1603     return shadowValueList;
1604 }
1605
1606 static RefPtr<CSSValue> consumeTextDecorationLine(CSSParserTokenRange& range)
1607 {
1608     CSSValueID id = range.peek().id();
1609     if (id == CSSValueNone)
1610         return consumeIdent(range);
1611
1612     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1613     while (true) {
1614 #if ENABLE(LETTERPRESS)
1615         RefPtr<CSSPrimitiveValue> ident = consumeIdent<CSSValueBlink, CSSValueUnderline, CSSValueOverline, CSSValueLineThrough, CSSValueWebkitLetterpress>(range);
1616 #else
1617         RefPtr<CSSPrimitiveValue> ident = consumeIdent<CSSValueBlink, CSSValueUnderline, CSSValueOverline, CSSValueLineThrough>(range);
1618 #endif
1619         if (!ident)
1620             break;
1621         if (list->hasValue(ident.get()))
1622             return nullptr;
1623         list->append(ident.releaseNonNull());
1624     }
1625
1626     if (!list->length())
1627         return nullptr;
1628     return list;
1629 }
1630
1631 static RefPtr<CSSValue> consumeTextDecorationSkip(CSSParserTokenRange& range)
1632 {
1633     CSSValueID id = range.peek().id();
1634     if (id == CSSValueNone)
1635         return consumeIdent(range);
1636
1637     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1638     while (true) {
1639         auto ident = consumeIdent<CSSValueAuto, CSSValueInk, CSSValueObjects>(range);
1640         if (!ident)
1641             break;
1642         if (list->hasValue(ident.get()))
1643             return nullptr;
1644         list->append(ident.releaseNonNull());
1645     }
1646
1647     if (!list->length())
1648         return nullptr;
1649     return list;
1650 }
1651
1652 static RefPtr<CSSValue> consumeTextEmphasisStyle(CSSParserTokenRange& range)
1653 {
1654     CSSValueID id = range.peek().id();
1655     if (id == CSSValueNone)
1656         return consumeIdent(range);
1657
1658     if (RefPtr<CSSValue> textEmphasisStyle = consumeString(range))
1659         return textEmphasisStyle;
1660
1661     RefPtr<CSSPrimitiveValue> fill = consumeIdent<CSSValueFilled, CSSValueOpen>(range);
1662     RefPtr<CSSPrimitiveValue> shape = consumeIdent<CSSValueDot, CSSValueCircle, CSSValueDoubleCircle, CSSValueTriangle, CSSValueSesame>(range);
1663     if (!fill)
1664         fill = consumeIdent<CSSValueFilled, CSSValueOpen>(range);
1665     if (fill && shape) {
1666         RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
1667         parsedValues->append(fill.releaseNonNull());
1668         parsedValues->append(shape.releaseNonNull());
1669         return parsedValues;
1670     }
1671     if (fill)
1672         return fill;
1673     if (shape)
1674         return shape;
1675     return nullptr;
1676 }
1677
1678 static RefPtr<CSSValue> consumeOutlineColor(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1679 {
1680     // Allow the special focus color even in HTML Standard parsing mode.
1681     if (range.peek().id() == CSSValueWebkitFocusRingColor)
1682         return consumeIdent(range);
1683     return consumeColor(range, cssParserMode);
1684 }
1685
1686 static RefPtr<CSSPrimitiveValue> consumeLineWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
1687 {
1688     CSSValueID id = range.peek().id();
1689     if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
1690         return consumeIdent(range);
1691     return consumeLength(range, cssParserMode, ValueRangeNonNegative, unitless);
1692 }
1693
1694 static RefPtr<CSSPrimitiveValue> consumeBorderWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
1695 {
1696     return consumeLineWidth(range, cssParserMode, unitless);
1697 }
1698
1699 static RefPtr<CSSPrimitiveValue> consumeTextStrokeWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1700 {
1701     return consumeLineWidth(range, cssParserMode, UnitlessQuirk::Forbid);
1702 }
1703
1704 static RefPtr<CSSPrimitiveValue> consumeColumnRuleWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1705 {
1706     return consumeLineWidth(range, cssParserMode, UnitlessQuirk::Forbid);
1707 }
1708
1709 static bool consumeTranslate3d(CSSParserTokenRange& args, CSSParserMode cssParserMode, RefPtr<WebKitCSSTransformValue>& transformValue)
1710 {
1711     unsigned numberOfArguments = 2;
1712     RefPtr<CSSValue> parsedValue;
1713     do {
1714         parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll);
1715         if (!parsedValue)
1716             return false;
1717         transformValue->append(*parsedValue);
1718         if (!consumeCommaIncludingWhitespace(args))
1719             return false;
1720     } while (--numberOfArguments);
1721     parsedValue = consumeLength(args, cssParserMode, ValueRangeAll);
1722     if (!parsedValue)
1723         return false;
1724     transformValue->append(*parsedValue);
1725     return true;
1726 }
1727
1728 static bool consumeNumbers(CSSParserTokenRange& args, RefPtr<WebKitCSSTransformValue>& transformValue, unsigned numberOfArguments)
1729 {
1730     do {
1731         RefPtr<CSSPrimitiveValue> parsedValue = consumeNumber(args, ValueRangeAll);
1732         if (!parsedValue)
1733             return false;
1734         transformValue->append(parsedValue.releaseNonNull());
1735         if (--numberOfArguments && !consumeCommaIncludingWhitespace(args))
1736             return false;
1737     } while (numberOfArguments);
1738     return true;
1739 }
1740
1741 static bool consumePerspective(CSSParserTokenRange& args, CSSParserMode cssParserMode, RefPtr<WebKitCSSTransformValue>& transformValue)
1742 {
1743     RefPtr<CSSPrimitiveValue> parsedValue = consumeLength(args, cssParserMode, ValueRangeNonNegative);
1744     if (!parsedValue) {
1745         double perspective;
1746         if (!consumeNumberRaw(args, perspective) || perspective < 0)
1747             return false;
1748         parsedValue = CSSPrimitiveValue::create(perspective, CSSPrimitiveValue::UnitTypes::CSS_PX);
1749     }
1750     if (!parsedValue)
1751         return false;
1752     transformValue->append(parsedValue.releaseNonNull());
1753     return true;
1754 }
1755
1756 // FIXME-NEWPARSER: This has no reason to exist once we eliminate WebkitCSSTransformValue in favor
1757 // of CSSFunctionValue.
1758 static WebKitCSSTransformValue::TransformOperationType transformOperationForCSSValueID(CSSValueID functionId)
1759 {
1760     switch (functionId) {
1761     case CSSValueRotate:
1762         return WebKitCSSTransformValue::RotateTransformOperation;
1763     case CSSValueRotatex:
1764         return WebKitCSSTransformValue::RotateXTransformOperation;
1765     case CSSValueRotatey:
1766         return WebKitCSSTransformValue::RotateYTransformOperation;
1767     case CSSValueRotatez:
1768         return WebKitCSSTransformValue::RotateZTransformOperation;
1769     case CSSValueSkewx:
1770         return WebKitCSSTransformValue::SkewXTransformOperation;
1771     case CSSValueSkewy:
1772         return WebKitCSSTransformValue::SkewYTransformOperation;
1773     case CSSValueSkew:
1774         return WebKitCSSTransformValue::SkewTransformOperation;
1775     case CSSValueScalex:
1776         return WebKitCSSTransformValue::ScaleXTransformOperation;
1777     case CSSValueScaley:
1778         return WebKitCSSTransformValue::ScaleYTransformOperation;
1779     case CSSValueScalez:
1780         return WebKitCSSTransformValue::ScaleZTransformOperation;
1781     case CSSValueScale:
1782         return WebKitCSSTransformValue::ScaleTransformOperation;
1783     case CSSValuePerspective:
1784         return WebKitCSSTransformValue::PerspectiveTransformOperation;
1785     case CSSValueTranslatex:
1786         return WebKitCSSTransformValue::TranslateXTransformOperation;
1787     case CSSValueTranslatey:
1788         return WebKitCSSTransformValue::TranslateYTransformOperation;
1789     case CSSValueTranslate:
1790         return WebKitCSSTransformValue::TranslateTransformOperation;
1791     case CSSValueTranslatez:
1792         return WebKitCSSTransformValue::TranslateZTransformOperation;
1793     case CSSValueMatrix:
1794         return WebKitCSSTransformValue::MatrixTransformOperation;
1795     case CSSValueMatrix3d:
1796         return WebKitCSSTransformValue::Matrix3DTransformOperation;
1797     case CSSValueScale3d:
1798         return WebKitCSSTransformValue::Scale3DTransformOperation;
1799     case CSSValueRotate3d:
1800         return WebKitCSSTransformValue::Rotate3DTransformOperation;
1801     case CSSValueTranslate3d:
1802         return WebKitCSSTransformValue::Translate3DTransformOperation;
1803     default:
1804         return WebKitCSSTransformValue::UnknownTransformOperation;
1805     }
1806 }
1807
1808 static RefPtr<CSSValue> consumeTransformValue(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1809 {
1810     CSSValueID functionId = range.peek().functionId();
1811     if (functionId == CSSValueInvalid)
1812         return nullptr;
1813     CSSParserTokenRange args = consumeFunction(range);
1814     if (args.atEnd())
1815         return nullptr;
1816     
1817     // FIXME-NEWPARSER: Do we really need WebkitCSSTransformValue? A CSSFunctionValue is good
1818     // enough and has the CSSValueID as the operation type. Blink has eliminated it.
1819     RefPtr<WebKitCSSTransformValue> transformValue = WebKitCSSTransformValue::create(transformOperationForCSSValueID(functionId));
1820     RefPtr<CSSValue> parsedValue;
1821     switch (functionId) {
1822     case CSSValueRotate:
1823     case CSSValueRotatex:
1824     case CSSValueRotatey:
1825     case CSSValueRotatez:
1826     case CSSValueSkewx:
1827     case CSSValueSkewy:
1828     case CSSValueSkew:
1829         parsedValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid);
1830         if (!parsedValue)
1831             return nullptr;
1832         if (functionId == CSSValueSkew && consumeCommaIncludingWhitespace(args)) {
1833             transformValue->append(*parsedValue);
1834             parsedValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid);
1835             if (!parsedValue)
1836                 return nullptr;
1837         }
1838         break;
1839     case CSSValueScalex:
1840     case CSSValueScaley:
1841     case CSSValueScalez:
1842     case CSSValueScale:
1843         parsedValue = consumeNumber(args, ValueRangeAll);
1844         if (!parsedValue)
1845             return nullptr;
1846         if (functionId == CSSValueScale && consumeCommaIncludingWhitespace(args)) {
1847             transformValue->append(*parsedValue);
1848             parsedValue = consumeNumber(args, ValueRangeAll);
1849             if (!parsedValue)
1850                 return nullptr;
1851         }
1852         break;
1853     case CSSValuePerspective:
1854         if (!consumePerspective(args, cssParserMode, transformValue))
1855             return nullptr;
1856         break;
1857     case CSSValueTranslatex:
1858     case CSSValueTranslatey:
1859     case CSSValueTranslate:
1860         parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll);
1861         if (!parsedValue)
1862             return nullptr;
1863         if (functionId == CSSValueTranslate && consumeCommaIncludingWhitespace(args)) {
1864             transformValue->append(*parsedValue);
1865             parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll);
1866             if (!parsedValue)
1867                 return nullptr;
1868         }
1869         break;
1870     case CSSValueTranslatez:
1871         parsedValue = consumeLength(args, cssParserMode, ValueRangeAll);
1872         break;
1873     case CSSValueMatrix:
1874     case CSSValueMatrix3d:
1875         if (!consumeNumbers(args, transformValue, (functionId == CSSValueMatrix3d) ? 16 : 6))
1876             return nullptr;
1877         break;
1878     case CSSValueScale3d:
1879         if (!consumeNumbers(args, transformValue, 3))
1880             return nullptr;
1881         break;
1882     case CSSValueRotate3d:
1883         if (!consumeNumbers(args, transformValue, 3) || !consumeCommaIncludingWhitespace(args))
1884             return nullptr;
1885         parsedValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid);
1886         if (!parsedValue)
1887             return nullptr;
1888         break;
1889     case CSSValueTranslate3d:
1890         if (!consumeTranslate3d(args, cssParserMode, transformValue))
1891             return nullptr;
1892         break;
1893     default:
1894         return nullptr;
1895     }
1896     if (parsedValue)
1897         transformValue->append(*parsedValue);
1898     if (!args.atEnd())
1899         return nullptr;
1900     return transformValue;
1901 }
1902
1903 static RefPtr<CSSValue> consumeTransform(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1904 {
1905     if (range.peek().id() == CSSValueNone)
1906         return consumeIdent(range);
1907
1908     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1909     do {
1910         RefPtr<CSSValue> parsedTransformValue = consumeTransformValue(range, cssParserMode);
1911         if (!parsedTransformValue)
1912             return nullptr;
1913         list->append(parsedTransformValue.releaseNonNull());
1914     } while (!range.atEnd());
1915
1916     return list;
1917 }
1918
1919 template <CSSValueID start, CSSValueID end>
1920 static RefPtr<CSSPrimitiveValue> consumePositionLonghand(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1921 {
1922     if (range.peek().type() == IdentToken) {
1923         CSSValueID id = range.peek().id();
1924         int percent;
1925         if (id == start)
1926             percent = 0;
1927         else if (id == CSSValueCenter)
1928             percent = 50;
1929         else if (id == end)
1930             percent = 100;
1931         else
1932             return nullptr;
1933         range.consumeIncludingWhitespace();
1934         return CSSPrimitiveValue::create(percent, CSSPrimitiveValue::UnitTypes::CSS_PERCENTAGE);
1935     }
1936     return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll);
1937 }
1938
1939 static RefPtr<CSSPrimitiveValue> consumePositionX(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1940 {
1941     return consumePositionLonghand<CSSValueLeft, CSSValueRight>(range, cssParserMode);
1942 }
1943
1944 static RefPtr<CSSPrimitiveValue> consumePositionY(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1945 {
1946     return consumePositionLonghand<CSSValueTop, CSSValueBottom>(range, cssParserMode);
1947 }
1948
1949 static RefPtr<CSSValue> consumePaintStroke(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1950 {
1951     if (range.peek().id() == CSSValueNone)
1952         return consumeIdent(range);
1953     RefPtr<CSSPrimitiveValue> url = consumeUrl(range);
1954     if (url) {
1955         RefPtr<CSSValue> parsedValue;
1956         if (range.peek().id() == CSSValueNone)
1957             parsedValue = consumeIdent(range);
1958         else
1959             parsedValue = consumeColor(range, cssParserMode);
1960         if (parsedValue) {
1961             RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
1962             values->append(url.releaseNonNull());
1963             values->append(parsedValue.releaseNonNull());
1964             return values;
1965         }
1966         return url;
1967     }
1968     return consumeColor(range, cssParserMode);
1969 }
1970
1971 static RefPtr<CSSValue> consumeGlyphOrientation(CSSParserTokenRange& range, CSSParserMode mode, CSSPropertyID property)
1972 {
1973     if (range.peek().id() == CSSValueAuto) {
1974         if (property == CSSPropertyGlyphOrientationVertical)
1975             return consumeIdent(range);
1976         return nullptr;
1977     }
1978     
1979     return consumeAngle(range, mode, UnitlessQuirk::Allow);
1980 }
1981
1982 static RefPtr<CSSValue> consumePaintOrder(CSSParserTokenRange& range)
1983 {
1984     if (range.peek().id() == CSSValueNormal)
1985         return consumeIdent(range);
1986
1987     Vector<CSSValueID, 3> paintTypeList;
1988     RefPtr<CSSPrimitiveValue> fill;
1989     RefPtr<CSSPrimitiveValue> stroke;
1990     RefPtr<CSSPrimitiveValue> markers;
1991     do {
1992         CSSValueID id = range.peek().id();
1993         if (id == CSSValueFill && !fill)
1994             fill = consumeIdent(range);
1995         else if (id == CSSValueStroke && !stroke)
1996             stroke = consumeIdent(range);
1997         else if (id == CSSValueMarkers && !markers)
1998             markers = consumeIdent(range);
1999         else
2000             return nullptr;
2001         paintTypeList.append(id);
2002     } while (!range.atEnd());
2003
2004     // After parsing we serialize the paint-order list. Since it is not possible to
2005     // pop a last list items from CSSValueList without bigger cost, we create the
2006     // list after parsing.
2007     CSSValueID firstPaintOrderType = paintTypeList.at(0);
2008     RefPtr<CSSValueList> paintOrderList = CSSValueList::createSpaceSeparated();
2009     switch (firstPaintOrderType) {
2010     case CSSValueFill:
2011     case CSSValueStroke:
2012         paintOrderList->append(firstPaintOrderType == CSSValueFill ? fill.releaseNonNull() : stroke.releaseNonNull());
2013         if (paintTypeList.size() > 1) {
2014             if (paintTypeList.at(1) == CSSValueMarkers)
2015                 paintOrderList->append(markers.releaseNonNull());
2016         }
2017         break;
2018     case CSSValueMarkers:
2019         paintOrderList->append(markers.releaseNonNull());
2020         if (paintTypeList.size() > 1) {
2021             if (paintTypeList.at(1) == CSSValueStroke)
2022                 paintOrderList->append(stroke.releaseNonNull());
2023         }
2024         break;
2025     default:
2026         ASSERT_NOT_REACHED();
2027     }
2028
2029     return paintOrderList;
2030 }
2031
2032 static RefPtr<CSSValue> consumeNoneOrURI(CSSParserTokenRange& range)
2033 {
2034     if (range.peek().id() == CSSValueNone)
2035         return consumeIdent(range);
2036     return consumeUrl(range);
2037 }
2038
2039 static RefPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2040 {
2041     // FIXME: Support intrinsic dimensions too.
2042     if (range.peek().id() == CSSValueAuto)
2043         return consumeIdent(range);
2044     return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2045 }
2046
2047 static RefPtr<CSSValue> consumeKerning(CSSParserTokenRange& range, CSSParserMode mode)
2048 {
2049     RefPtr<CSSValue> result = consumeIdent<CSSValueAuto, CSSValueNormal>(range);
2050     if (result)
2051         return result;
2052     return consumeLength(range, mode, ValueRangeAll, UnitlessQuirk::Allow);
2053 }
2054
2055 static RefPtr<CSSValue> consumeStrokeDasharray(CSSParserTokenRange& range)
2056 {
2057     CSSValueID id = range.peek().id();
2058     if (id == CSSValueNone)
2059         return consumeIdent(range);
2060
2061     RefPtr<CSSValueList> dashes = CSSValueList::createCommaSeparated();
2062     do {
2063         RefPtr<CSSPrimitiveValue> dash = consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeNonNegative);
2064         if (!dash || (consumeCommaIncludingWhitespace(range) && range.atEnd()))
2065             return nullptr;
2066         dashes->append(dash.releaseNonNull());
2067     } while (!range.atEnd());
2068     return dashes;
2069 }
2070
2071 static RefPtr<CSSPrimitiveValue> consumeBaselineShift(CSSParserTokenRange& range)
2072 {
2073     CSSValueID id = range.peek().id();
2074     if (id == CSSValueBaseline || id == CSSValueSub || id == CSSValueSuper)
2075         return consumeIdent(range);
2076     return consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeAll);
2077 }
2078
2079 static RefPtr<CSSPrimitiveValue> consumeRxOrRy(CSSParserTokenRange& range)
2080 {
2081     // FIXME-NEWPARSER: We don't support auto values when mapping, so for now turn this
2082     // off until we can figure out if we're even supposed to support it.
2083     // if (range.peek().id() == CSSValueAuto)
2084     //     return consumeIdent(range);
2085     return consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeAll, UnitlessQuirk::Forbid);
2086 }
2087
2088 static RefPtr<CSSValue> consumeCursor(CSSParserTokenRange& range, const CSSParserContext& context, bool inQuirksMode)
2089 {
2090     RefPtr<CSSValueList> list;
2091     while (RefPtr<CSSValue> image = consumeImage(range, context, ConsumeGeneratedImage::Forbid)) {
2092         double num;
2093         IntPoint hotSpot(-1, -1);
2094         bool hotSpotSpecified = false;
2095         if (consumeNumberRaw(range, num)) {
2096             hotSpot.setX(int(num));
2097             if (!consumeNumberRaw(range, num))
2098                 return nullptr;
2099             hotSpot.setY(int(num));
2100             hotSpotSpecified = true;
2101         }
2102
2103         if (!list)
2104             list = CSSValueList::createCommaSeparated();
2105
2106         list->append(CSSCursorImageValue::create(image.releaseNonNull(), hotSpotSpecified, hotSpot));
2107         if (!consumeCommaIncludingWhitespace(range))
2108             return nullptr;
2109     }
2110
2111     CSSValueID id = range.peek().id();
2112     RefPtr<CSSValue> cursorType;
2113     if (id == CSSValueHand) {
2114         if (!inQuirksMode) // Non-standard behavior
2115             return nullptr;
2116         cursorType = CSSValuePool::singleton().createIdentifierValue(CSSValuePointer);
2117         range.consumeIncludingWhitespace();
2118     } else if ((id >= CSSValueAuto && id <= CSSValueWebkitZoomOut) || id == CSSValueCopy || id == CSSValueNone) {
2119         cursorType = consumeIdent(range);
2120     } else {
2121         return nullptr;
2122     }
2123
2124     if (!list)
2125         return cursorType;
2126     list->append(cursorType.releaseNonNull());
2127     return list;
2128 }
2129
2130 static RefPtr<CSSValue> consumeAttr(CSSParserTokenRange args, CSSParserContext context)
2131 {
2132     if (args.peek().type() != IdentToken)
2133         return nullptr;
2134     
2135     CSSParserToken token = args.consumeIncludingWhitespace();
2136     auto attrName = token.value().toAtomicString();
2137     if (context.isHTMLDocument)
2138         attrName = attrName.convertToASCIILowercase();
2139
2140     if (!args.atEnd())
2141         return nullptr;
2142
2143     // FIXME-NEWPARSER: We want to use a CSSCustomIdentValue here eventually for the attrName.
2144     // FIXME-NEWPARSER: We want to use a CSSFunctionValue rather than relying on a custom
2145     // attr() primitive value.
2146     return CSSValuePool::singleton().createValue(attrName, CSSPrimitiveValue::CSS_ATTR);
2147 }
2148
2149 static RefPtr<CSSValue> consumeCounterContent(CSSParserTokenRange args, bool counters)
2150 {
2151     RefPtr<CSSPrimitiveValue> identifier = consumeCustomIdent(args);
2152     if (!identifier)
2153         return nullptr;
2154
2155     RefPtr<CSSPrimitiveValue> separator;
2156     if (!counters)
2157         separator = CSSPrimitiveValue::create(String(), CSSPrimitiveValue::UnitTypes::CSS_STRING);
2158     else {
2159         if (!consumeCommaIncludingWhitespace(args) || args.peek().type() != StringToken)
2160             return nullptr;
2161         separator = CSSPrimitiveValue::create(args.consumeIncludingWhitespace().value().toString(), CSSPrimitiveValue::UnitTypes::CSS_STRING);
2162     }
2163
2164     RefPtr<CSSPrimitiveValue> listStyle;
2165     if (consumeCommaIncludingWhitespace(args)) {
2166         CSSValueID id = args.peek().id();
2167         if ((id != CSSValueNone && (id < CSSValueDisc || id > CSSValueKatakanaIroha)))
2168             return nullptr;
2169         listStyle = consumeIdent(args);
2170     } else
2171         listStyle = CSSValuePool::singleton().createIdentifierValue(CSSValueDecimal);
2172
2173     if (!args.atEnd())
2174         return nullptr;
2175     
2176     // FIXME-NEWPARSER: Should just have a CSSCounterValue.
2177     return CSSValuePool::singleton().createValue(Counter::create(identifier.releaseNonNull(), listStyle.releaseNonNull(), separator.releaseNonNull()));
2178 }
2179
2180 static RefPtr<CSSValue> consumeContent(CSSParserTokenRange& range, CSSParserContext context)
2181 {
2182     if (identMatches<CSSValueNone, CSSValueNormal>(range.peek().id()))
2183         return consumeIdent(range);
2184
2185     RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
2186
2187     do {
2188         RefPtr<CSSValue> parsedValue = consumeImage(range, context);
2189         if (!parsedValue)
2190             parsedValue = consumeIdent<CSSValueOpenQuote, CSSValueCloseQuote, CSSValueNoOpenQuote, CSSValueNoCloseQuote>(range);
2191         if (!parsedValue)
2192             parsedValue = consumeString(range);
2193         if (!parsedValue) {
2194             if (range.peek().functionId() == CSSValueAttr)
2195                 parsedValue = consumeAttr(consumeFunction(range), context);
2196             else if (range.peek().functionId() == CSSValueCounter)
2197                 parsedValue = consumeCounterContent(consumeFunction(range), false);
2198             else if (range.peek().functionId() == CSSValueCounters)
2199                 parsedValue = consumeCounterContent(consumeFunction(range), true);
2200             if (!parsedValue)
2201                 return nullptr;
2202         }
2203         values->append(parsedValue.releaseNonNull());
2204     } while (!range.atEnd());
2205
2206     return values;
2207 }
2208
2209 static RefPtr<CSSPrimitiveValue> consumePerspective(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2210 {
2211     if (range.peek().id() == CSSValueNone)
2212         return consumeIdent(range);
2213     RefPtr<CSSPrimitiveValue> parsedValue = consumeLength(range, cssParserMode, ValueRangeAll);
2214     if (!parsedValue) {
2215         // FIXME: Make this quirk only apply to the webkit prefixed version of the property.
2216         double perspective;
2217         if (!consumeNumberRaw(range, perspective))
2218             return nullptr;
2219         parsedValue = CSSPrimitiveValue::create(perspective, CSSPrimitiveValue::UnitTypes::CSS_PX);
2220     }
2221     if (parsedValue && (parsedValue->isCalculated() || parsedValue->doubleValue() > 0))
2222         return parsedValue;
2223     return nullptr;
2224 }
2225
2226 #if ENABLE(CSS_SCROLL_SNAP)
2227
2228 static RefPtr<CSSValueList> consumeSnapPointCoordinateList(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2229 {
2230     RefPtr<CSSValueList> positions = CSSValueList::createSpaceSeparated();
2231     do {
2232         
2233         RefPtr<CSSPrimitiveValue> first = consumePositionX(range, cssParserMode);
2234         if (!first || range.atEnd())
2235             return nullptr;
2236         RefPtr<CSSPrimitiveValue> second = consumePositionY(range, cssParserMode);
2237         if (!second)
2238             return nullptr;
2239         RefPtr<CSSValue> position = createPrimitiveValuePair(first.releaseNonNull(), second.releaseNonNull(), Pair::IdenticalValueEncoding::DoNotCoalesce);
2240         positions->append(position.releaseNonNull());
2241     } while (!range.atEnd());
2242     return positions;
2243 }
2244
2245 static RefPtr<CSSValue> consumeScrollSnapCoordinate(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2246 {
2247     if (range.peek().id() == CSSValueNone)
2248         return consumeIdent(range);
2249     return consumeSnapPointCoordinateList(range, cssParserMode);
2250 }
2251
2252 static RefPtr<CSSValue> consumeScrollSnapDestination(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2253 {
2254     RefPtr<CSSPrimitiveValue> first = consumePositionX(range, cssParserMode);
2255     if (!first || range.atEnd())
2256         return nullptr;
2257     RefPtr<CSSPrimitiveValue> second = consumePositionY(range, cssParserMode);
2258     if (!second)
2259         return nullptr;
2260     return createPrimitiveValuePair(first.releaseNonNull(), second.releaseNonNull(), Pair::IdenticalValueEncoding::DoNotCoalesce);
2261 }
2262
2263 static RefPtr<CSSValue> consumeScrollSnapPoints(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2264 {
2265     if (range.peek().id() == CSSValueNone || range.peek().id() == CSSValueElements)
2266         return consumeIdent(range);
2267     
2268     RefPtr<CSSValueList> points = CSSValueList::createSpaceSeparated();
2269     do {
2270         if (range.peek().functionId() == CSSValueRepeat) {
2271             CSSParserTokenRange args = consumeFunction(range);
2272             RefPtr<CSSPrimitiveValue> parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative);
2273             if (args.atEnd() && parsedValue && (parsedValue->isCalculated() || parsedValue->doubleValue() > 0)) {
2274                 Ref<CSSFunctionValue> result = CSSFunctionValue::create(CSSValueRepeat);
2275                 result->append(parsedValue.releaseNonNull());
2276                 points->append(WTFMove(result));
2277             }
2278         } else {
2279             RefPtr<CSSValue> length = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Forbid);
2280             if (!length)
2281                 return nullptr;
2282             points->append(length.releaseNonNull());
2283         }
2284     } while (!range.atEnd());
2285     
2286     
2287     return points;
2288 }
2289
2290 #endif
2291
2292 static RefPtr<CSSValue> consumeBorderRadiusCorner(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2293 {
2294     RefPtr<CSSPrimitiveValue> parsedValue1 = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2295     if (!parsedValue1)
2296         return nullptr;
2297     RefPtr<CSSPrimitiveValue> parsedValue2 = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2298     if (!parsedValue2)
2299         parsedValue2 = parsedValue1;
2300     return createPrimitiveValuePair(parsedValue1.releaseNonNull(), parsedValue2.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
2301 }
2302
2303 static RefPtr<CSSPrimitiveValue> consumeVerticalAlign(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2304 {
2305     RefPtr<CSSPrimitiveValue> parsedValue = consumeIdentRange(range, CSSValueBaseline, CSSValueWebkitBaselineMiddle);
2306     if (!parsedValue)
2307         parsedValue = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
2308     return parsedValue;
2309 }
2310
2311 static RefPtr<CSSPrimitiveValue> consumeShapeRadius(CSSParserTokenRange& args, CSSParserMode cssParserMode)
2312 {
2313     if (identMatches<CSSValueClosestSide, CSSValueFarthestSide>(args.peek().id()))
2314         return consumeIdent(args);
2315     return consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative);
2316 }
2317
2318 static RefPtr<CSSBasicShapeCircle> consumeBasicShapeCircle(CSSParserTokenRange& args, const CSSParserContext& context)
2319 {
2320     // spec: https://drafts.csswg.org/css-shapes/#supported-basic-shapes
2321     // circle( [<shape-radius>]? [at <position>]? )
2322     RefPtr<CSSBasicShapeCircle> shape = CSSBasicShapeCircle::create();
2323     if (RefPtr<CSSPrimitiveValue> radius = consumeShapeRadius(args, context.mode))
2324         shape->setRadius(radius.releaseNonNull());
2325     if (consumeIdent<CSSValueAt>(args)) {
2326         RefPtr<CSSPrimitiveValue> centerX;
2327         RefPtr<CSSPrimitiveValue> centerY;
2328         if (!consumePosition(args, context.mode, UnitlessQuirk::Forbid, centerX, centerY))
2329             return nullptr;
2330         shape->setCenterX(centerX.releaseNonNull());
2331         shape->setCenterY(centerY.releaseNonNull());
2332     }
2333     return shape;
2334 }
2335
2336 static RefPtr<CSSBasicShapeEllipse> consumeBasicShapeEllipse(CSSParserTokenRange& args, const CSSParserContext& context)
2337 {
2338     // spec: https://drafts.csswg.org/css-shapes/#supported-basic-shapes
2339     // ellipse( [<shape-radius>{2}]? [at <position>]? )
2340     RefPtr<CSSBasicShapeEllipse> shape = CSSBasicShapeEllipse::create();
2341     if (RefPtr<CSSPrimitiveValue> radiusX = consumeShapeRadius(args, context.mode)) {
2342         shape->setRadiusX(radiusX.releaseNonNull());
2343         if (RefPtr<CSSPrimitiveValue> radiusY = consumeShapeRadius(args, context.mode))
2344             shape->setRadiusY(radiusY.releaseNonNull());
2345     }
2346     if (consumeIdent<CSSValueAt>(args)) {
2347         RefPtr<CSSPrimitiveValue> centerX;
2348         RefPtr<CSSPrimitiveValue> centerY;
2349         if (!consumePosition(args, context.mode, UnitlessQuirk::Forbid, centerX, centerY))
2350             return nullptr;
2351         shape->setCenterX(centerX.releaseNonNull());
2352         shape->setCenterY(centerY.releaseNonNull());
2353     }
2354     return shape;
2355 }
2356
2357 static RefPtr<CSSBasicShapePolygon> consumeBasicShapePolygon(CSSParserTokenRange& args, const CSSParserContext& context)
2358 {
2359     RefPtr<CSSBasicShapePolygon> shape = CSSBasicShapePolygon::create();
2360     if (identMatches<CSSValueEvenodd, CSSValueNonzero>(args.peek().id())) {
2361         shape->setWindRule(args.consumeIncludingWhitespace().id() == CSSValueEvenodd ? RULE_EVENODD : RULE_NONZERO);
2362         if (!consumeCommaIncludingWhitespace(args))
2363             return nullptr;
2364     }
2365
2366     do {
2367         RefPtr<CSSPrimitiveValue> xLength = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2368         if (!xLength)
2369             return nullptr;
2370         RefPtr<CSSPrimitiveValue> yLength = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2371         if (!yLength)
2372             return nullptr;
2373         shape->appendPoint(xLength.releaseNonNull(), yLength.releaseNonNull());
2374     } while (consumeCommaIncludingWhitespace(args));
2375     return shape;
2376 }
2377
2378 static RefPtr<CSSBasicShapePath> consumeBasicShapePath(CSSParserTokenRange& args)
2379 {
2380     WindRule windRule = RULE_NONZERO;
2381     if (identMatches<CSSValueEvenodd, CSSValueNonzero>(args.peek().id())) {
2382         windRule = args.consumeIncludingWhitespace().id() == CSSValueEvenodd ? RULE_EVENODD : RULE_NONZERO;
2383         if (!consumeCommaIncludingWhitespace(args))
2384             return nullptr;
2385     }
2386
2387     if (args.peek().type() != StringToken)
2388         return nullptr;
2389     
2390     auto byteStream = std::make_unique<SVGPathByteStream>();
2391     if (!buildSVGPathByteStreamFromString(args.consumeIncludingWhitespace().value().toString(), *byteStream, UnalteredParsing))
2392         return nullptr;
2393     
2394     auto shape = CSSBasicShapePath::create(WTFMove(byteStream));
2395     shape->setWindRule(windRule);
2396     
2397     return WTFMove(shape);
2398 }
2399
2400 static void complete4Sides(RefPtr<CSSPrimitiveValue> side[4])
2401 {
2402     if (side[3])
2403         return;
2404     if (!side[2]) {
2405         if (!side[1])
2406             side[1] = side[0];
2407         side[2] = side[0];
2408     }
2409     side[3] = side[1];
2410 }
2411
2412 static bool consumeRadii(RefPtr<CSSPrimitiveValue> horizontalRadii[4], RefPtr<CSSPrimitiveValue> verticalRadii[4], CSSParserTokenRange& range, CSSParserMode cssParserMode, bool useLegacyParsing)
2413 {
2414     unsigned i = 0;
2415     for (; i < 4 && !range.atEnd() && range.peek().type() != DelimiterToken; ++i) {
2416         horizontalRadii[i] = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2417         if (!horizontalRadii[i])
2418             return false;
2419     }
2420     if (!horizontalRadii[0])
2421         return false;
2422     if (range.atEnd()) {
2423         // Legacy syntax: -webkit-border-radius: l1 l2; is equivalent to border-radius: l1 / l2;
2424         if (useLegacyParsing && i == 2) {
2425             verticalRadii[0] = horizontalRadii[1];
2426             horizontalRadii[1] = nullptr;
2427         } else {
2428             complete4Sides(horizontalRadii);
2429             for (unsigned i = 0; i < 4; ++i)
2430                 verticalRadii[i] = horizontalRadii[i];
2431             return true;
2432         }
2433     } else {
2434         if (!consumeSlashIncludingWhitespace(range))
2435             return false;
2436         for (i = 0; i < 4 && !range.atEnd(); ++i) {
2437             verticalRadii[i] = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2438             if (!verticalRadii[i])
2439                 return false;
2440         }
2441         if (!verticalRadii[0] || !range.atEnd())
2442             return false;
2443     }
2444     complete4Sides(horizontalRadii);
2445     complete4Sides(verticalRadii);
2446     return true;
2447 }
2448
2449 static RefPtr<CSSBasicShapeInset> consumeBasicShapeInset(CSSParserTokenRange& args, const CSSParserContext& context)
2450 {
2451     RefPtr<CSSBasicShapeInset> shape = CSSBasicShapeInset::create();
2452     RefPtr<CSSPrimitiveValue> top = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2453     if (!top)
2454         return nullptr;
2455     RefPtr<CSSPrimitiveValue> right = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2456     RefPtr<CSSPrimitiveValue> bottom;
2457     RefPtr<CSSPrimitiveValue> left;
2458     if (right) {
2459         bottom = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2460         if (bottom)
2461             left = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2462     }
2463     if (left)
2464         shape->updateShapeSize4Values(top.releaseNonNull(), right.releaseNonNull(), bottom.releaseNonNull(), left.releaseNonNull());
2465     else if (bottom)
2466         shape->updateShapeSize3Values(top.releaseNonNull(), right.releaseNonNull(), bottom.releaseNonNull());
2467     else if (right)
2468         shape->updateShapeSize2Values(top.releaseNonNull(), right.releaseNonNull());
2469     else
2470         shape->updateShapeSize1Value(top.releaseNonNull());
2471
2472     if (consumeIdent<CSSValueRound>(args)) {
2473         RefPtr<CSSPrimitiveValue> horizontalRadii[4] = { 0 };
2474         RefPtr<CSSPrimitiveValue> verticalRadii[4] = { 0 };
2475         if (!consumeRadii(horizontalRadii, verticalRadii, args, context.mode, false))
2476             return nullptr;
2477         shape->setTopLeftRadius(createPrimitiveValuePair(horizontalRadii[0].releaseNonNull(), verticalRadii[0].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
2478         shape->setTopRightRadius(createPrimitiveValuePair(horizontalRadii[1].releaseNonNull(), verticalRadii[1].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
2479         shape->setBottomRightRadius(createPrimitiveValuePair(horizontalRadii[2].releaseNonNull(), verticalRadii[2].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
2480         shape->setBottomLeftRadius(createPrimitiveValuePair(horizontalRadii[3].releaseNonNull(), verticalRadii[3].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
2481     }
2482     return shape;
2483 }
2484
2485 static RefPtr<CSSValue> consumeBasicShape(CSSParserTokenRange& range, const CSSParserContext& context)
2486 {
2487     RefPtr<CSSValue> result;
2488     if (range.peek().type() != FunctionToken)
2489         return nullptr;
2490     CSSValueID id = range.peek().functionId();
2491     CSSParserTokenRange rangeCopy = range;
2492     CSSParserTokenRange args = consumeFunction(rangeCopy);
2493     
2494     // FIXME-NEWPARSER: CSSBasicShape should be a CSSValue, and shapes should not be primitive values.
2495     RefPtr<CSSBasicShape> shape;
2496     if (id == CSSValueCircle)
2497         shape = consumeBasicShapeCircle(args, context);
2498     else if (id == CSSValueEllipse)
2499         shape = consumeBasicShapeEllipse(args, context);
2500     else if (id == CSSValuePolygon)
2501         shape = consumeBasicShapePolygon(args, context);
2502     else if (id == CSSValueInset)
2503         shape = consumeBasicShapeInset(args, context);
2504     else if (id == CSSValuePath)
2505         shape = consumeBasicShapePath(args);
2506     if (!shape)
2507         return nullptr;
2508     range = rangeCopy;
2509     
2510     if (!args.atEnd())
2511         return nullptr;
2512
2513     return CSSValuePool::singleton().createValue(shape.releaseNonNull());
2514 }
2515
2516 static RefPtr<CSSValue> consumeBasicShapeOrBox(CSSParserTokenRange& range, const CSSParserContext& context)
2517 {
2518     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2519     bool shapeFound = false;
2520     bool boxFound = false;
2521     while (!range.atEnd() && !(shapeFound && boxFound)) {
2522         RefPtr<CSSValue> componentValue;
2523         if (range.peek().type() == FunctionToken && !shapeFound) {
2524             componentValue = consumeBasicShape(range, context);
2525             shapeFound = true;
2526         } else if (range.peek().type() == IdentToken && !boxFound) {
2527             componentValue = consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, CSSValueMarginBox, CSSValueFill, CSSValueStroke, CSSValueViewBox>(range);
2528             boxFound = true;
2529         }
2530         if (!componentValue)
2531             return nullptr;
2532         list->append(componentValue.releaseNonNull());
2533     }
2534     
2535     if (!range.atEnd() || !list->length())
2536         return nullptr;
2537     
2538     return list;
2539 }
2540     
2541 static RefPtr<CSSValue> consumeWebkitClipPath(CSSParserTokenRange& range, const CSSParserContext& context)
2542 {
2543     if (range.peek().id() == CSSValueNone)
2544         return consumeIdent(range);
2545     if (RefPtr<CSSPrimitiveValue> url = consumeUrl(range))
2546         return url;
2547     return consumeBasicShapeOrBox(range, context);
2548 }
2549
2550 static RefPtr<CSSValue> consumeShapeOutside(CSSParserTokenRange& range, const CSSParserContext& context)
2551 {
2552     if (RefPtr<CSSValue> imageValue = consumeImageOrNone(range, context))
2553         return imageValue;
2554     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2555     if (RefPtr<CSSValue> boxValue = consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, CSSValueMarginBox>(range))
2556         list->append(boxValue.releaseNonNull());
2557     if (RefPtr<CSSValue> shapeValue = consumeBasicShape(range, context)) {
2558         list->append(shapeValue.releaseNonNull());
2559         if (list->length() < 2) {
2560             if (RefPtr<CSSValue> boxValue = consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, CSSValueMarginBox>(range))
2561                 list->append(boxValue.releaseNonNull());
2562         }
2563     }
2564     if (!list->length())
2565         return nullptr;
2566     return list;
2567 }
2568
2569 static RefPtr<CSSValue> consumeContentDistributionOverflowPosition(CSSParserTokenRange& range)
2570 {
2571     if (identMatches<CSSValueNormal, CSSValueBaseline, CSSValueLastBaseline>(range.peek().id()))
2572         return CSSContentDistributionValue::create(CSSValueInvalid, range.consumeIncludingWhitespace().id(), CSSValueInvalid);
2573
2574     CSSValueID distribution = CSSValueInvalid;
2575     CSSValueID position = CSSValueInvalid;
2576     CSSValueID overflow = CSSValueInvalid;
2577     do {
2578         CSSValueID id = range.peek().id();
2579         if (identMatches<CSSValueSpaceBetween, CSSValueSpaceAround, CSSValueSpaceEvenly, CSSValueStretch>(id)) {
2580             if (distribution != CSSValueInvalid)
2581                 return nullptr;
2582             distribution = id;
2583         } else if (identMatches<CSSValueStart, CSSValueEnd, CSSValueCenter, CSSValueFlexStart, CSSValueFlexEnd, CSSValueLeft, CSSValueRight>(id)) {
2584             if (position != CSSValueInvalid)
2585                 return nullptr;
2586             position = id;
2587         } else if (identMatches<CSSValueUnsafe, CSSValueSafe>(id)) {
2588             if (overflow != CSSValueInvalid)
2589                 return nullptr;
2590             overflow = id;
2591         } else {
2592             return nullptr;
2593         }
2594         range.consumeIncludingWhitespace();
2595     } while (!range.atEnd());
2596
2597     // The grammar states that we should have at least <content-distribution> or <content-position>.
2598     if (position == CSSValueInvalid && distribution == CSSValueInvalid)
2599         return nullptr;
2600
2601     // The grammar states that <overflow-position> must be associated to <content-position>.
2602     if (overflow != CSSValueInvalid && position == CSSValueInvalid)
2603         return nullptr;
2604
2605     return CSSContentDistributionValue::create(distribution, position, overflow);
2606 }
2607
2608 static RefPtr<CSSPrimitiveValue> consumeBorderImageRepeatKeyword(CSSParserTokenRange& range)
2609 {
2610     return consumeIdent<CSSValueStretch, CSSValueRepeat, CSSValueSpace, CSSValueRound>(range);
2611 }
2612
2613 static RefPtr<CSSValue> consumeBorderImageRepeat(CSSParserTokenRange& range)
2614 {
2615     RefPtr<CSSPrimitiveValue> horizontal = consumeBorderImageRepeatKeyword(range);
2616     if (!horizontal)
2617         return nullptr;
2618     RefPtr<CSSPrimitiveValue> vertical = consumeBorderImageRepeatKeyword(range);
2619     if (!vertical)
2620         vertical = horizontal;
2621     return createPrimitiveValuePair(horizontal.releaseNonNull(), vertical.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
2622 }
2623
2624 static RefPtr<CSSValue> consumeBorderImageSlice(CSSPropertyID property, CSSParserTokenRange& range)
2625 {
2626     bool fill = consumeIdent<CSSValueFill>(range);
2627     RefPtr<CSSPrimitiveValue> slices[4] = { 0 };
2628
2629     for (size_t index = 0; index < 4; ++index) {
2630         RefPtr<CSSPrimitiveValue> value = consumePercent(range, ValueRangeNonNegative);
2631         if (!value)
2632             value = consumeNumber(range, ValueRangeNonNegative);
2633         if (!value)
2634             break;
2635         slices[index] = value;
2636     }
2637     if (!slices[0])
2638         return nullptr;
2639     if (consumeIdent<CSSValueFill>(range)) {
2640         if (fill)
2641             return nullptr;
2642         fill = true;
2643     }
2644     complete4Sides(slices);
2645     // FIXME: For backwards compatibility, -webkit-border-image, -webkit-mask-box-image and -webkit-box-reflect have to do a fill by default.
2646     // FIXME: What do we do with -webkit-box-reflect and -webkit-mask-box-image? Probably just have to leave them filling...
2647     if (property == CSSPropertyWebkitBorderImage || property == CSSPropertyWebkitMaskBoxImage || property == CSSPropertyWebkitBoxReflect)
2648         fill = true;
2649     
2650     // Now build a rect value to hold all four of our primitive values.
2651     // FIXME-NEWPARSER: Should just have a CSSQuadValue.
2652     auto quad = Quad::create();
2653     quad->setTop(slices[0].releaseNonNull());
2654     quad->setRight(slices[1].releaseNonNull());
2655     quad->setBottom(slices[2].releaseNonNull());
2656     quad->setLeft(slices[3].releaseNonNull());
2657     
2658     // Make our new border image value now.
2659     return CSSBorderImageSliceValue::create(CSSValuePool::singleton().createValue(WTFMove(quad)), fill);
2660 }
2661
2662 static RefPtr<CSSValue> consumeBorderImageOutset(CSSParserTokenRange& range)
2663 {
2664     RefPtr<CSSPrimitiveValue> outsets[4] = { 0 };
2665
2666     RefPtr<CSSPrimitiveValue> value;
2667     for (size_t index = 0; index < 4; ++index) {
2668         value = consumeNumber(range, ValueRangeNonNegative);
2669         if (!value)
2670             value = consumeLength(range, HTMLStandardMode, ValueRangeNonNegative);
2671         if (!value)
2672             break;
2673         outsets[index] = value;
2674     }
2675     if (!outsets[0])
2676         return nullptr;
2677     complete4Sides(outsets);
2678     
2679     // FIXME-NEWPARSER: Should just have a CSSQuadValue.
2680     auto quad = Quad::create();
2681     quad->setTop(outsets[0].releaseNonNull());
2682     quad->setRight(outsets[1].releaseNonNull());
2683     quad->setBottom(outsets[2].releaseNonNull());
2684     quad->setLeft(outsets[3].releaseNonNull());
2685     
2686     return CSSValuePool::singleton().createValue(WTFMove(quad));
2687 }
2688
2689 static RefPtr<CSSValue> consumeBorderImageWidth(CSSParserTokenRange& range)
2690 {
2691     RefPtr<CSSPrimitiveValue> widths[4];
2692
2693     RefPtr<CSSPrimitiveValue> value;
2694     for (size_t index = 0; index < 4; ++index) {
2695         value = consumeNumber(range, ValueRangeNonNegative);
2696         if (!value)
2697             value = consumeLengthOrPercent(range, HTMLStandardMode, ValueRangeNonNegative, UnitlessQuirk::Forbid);
2698         if (!value)
2699             value = consumeIdent<CSSValueAuto>(range);
2700         if (!value)
2701             break;
2702         widths[index] = value;
2703     }
2704     if (!widths[0])
2705         return nullptr;
2706     complete4Sides(widths);
2707     
2708     // FIXME-NEWPARSER: Should just have a CSSQuadValue.
2709     auto quad = Quad::create();
2710     quad->setTop(widths[0].releaseNonNull());
2711     quad->setRight(widths[1].releaseNonNull());
2712     quad->setBottom(widths[2].releaseNonNull());
2713     quad->setLeft(widths[3].releaseNonNull());
2714     
2715     return CSSValuePool::singleton().createValue(WTFMove(quad));
2716 }
2717
2718 static bool consumeBorderImageComponents(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context, RefPtr<CSSValue>& source,
2719     RefPtr<CSSValue>& slice, RefPtr<CSSValue>& width, RefPtr<CSSValue>& outset, RefPtr<CSSValue>& repeat)
2720 {
2721     do {
2722         if (!source) {
2723             source = consumeImageOrNone(range, context);
2724             if (source)
2725                 continue;
2726         }
2727         if (!repeat) {
2728             repeat = consumeBorderImageRepeat(range);
2729             if (repeat)
2730                 continue;
2731         }
2732         if (!slice) {
2733             slice = consumeBorderImageSlice(property, range);
2734             if (slice) {
2735                 ASSERT(!width && !outset);
2736                 if (consumeSlashIncludingWhitespace(range)) {
2737                     width = consumeBorderImageWidth(range);
2738                     if (consumeSlashIncludingWhitespace(range)) {
2739                         outset = consumeBorderImageOutset(range);
2740                         if (!outset)
2741                             return false;
2742                     } else if (!width) {
2743                         return false;
2744                     }
2745                 }
2746             } else {
2747                 return false;
2748             }
2749         } else {
2750             return false;
2751         }
2752     } while (!range.atEnd());
2753     return true;
2754 }
2755
2756 static RefPtr<CSSValue> consumeWebkitBorderImage(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
2757 {
2758     RefPtr<CSSValue> source;
2759     RefPtr<CSSValue> slice;
2760     RefPtr<CSSValue> width;
2761     RefPtr<CSSValue> outset;
2762     RefPtr<CSSValue> repeat;
2763     if (consumeBorderImageComponents(property, range, context, source, slice, width, outset, repeat))
2764         return createBorderImageValue(WTFMove(source), WTFMove(slice), WTFMove(width), WTFMove(outset), WTFMove(repeat));
2765     return nullptr;
2766 }
2767
2768 static RefPtr<CSSValue> consumeReflect(CSSParserTokenRange& range, const CSSParserContext& context)
2769 {
2770     if (range.peek().id() == CSSValueNone)
2771         return consumeIdent(range);
2772     
2773     RefPtr<CSSPrimitiveValue> direction = consumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>(range);
2774     if (!direction)
2775         return nullptr;
2776
2777     RefPtr<CSSPrimitiveValue> offset;
2778     if (range.atEnd())
2779         offset = CSSValuePool::singleton().createValue(0, CSSPrimitiveValue::UnitTypes::CSS_PX);
2780     else {
2781         offset = consumeLengthOrPercent(range, context.mode, ValueRangeAll, UnitlessQuirk::Forbid);
2782         if (!offset)
2783             return nullptr;
2784     }
2785
2786     RefPtr<CSSValue> mask;
2787     if (!range.atEnd()) {
2788         mask = consumeWebkitBorderImage(CSSPropertyWebkitBoxReflect, range, context);
2789         if (!mask)
2790             return nullptr;
2791     }
2792     return CSSReflectValue::create(direction.releaseNonNull(), offset.releaseNonNull(), WTFMove(mask));
2793 }
2794
2795 #if ENABLE(CSS_IMAGE_ORIENTATION)
2796 static RefPtr<CSSValue> consumeImageOrientation(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless = UnitlessQuirk::Forbid)
2797 {
2798     if (range.peek().type() != NumberToken) {
2799         RefPtr<CSSPrimitiveValue> angle = consumeAngle(range, cssParserMode, unitless);
2800         if (angle && angle->doubleValue() == 0)
2801             return angle;
2802     }
2803     return nullptr;
2804 }
2805 #endif
2806
2807 static RefPtr<CSSPrimitiveValue> consumeBackgroundBlendMode(CSSParserTokenRange& range)
2808 {
2809     CSSValueID id = range.peek().id();
2810     if (id == CSSValueNormal || id == CSSValueOverlay || (id >= CSSValueMultiply && id <= CSSValueLuminosity))
2811         return consumeIdent(range);
2812     return nullptr;
2813 }
2814
2815 static RefPtr<CSSPrimitiveValue> consumeBackgroundAttachment(CSSParserTokenRange& range)
2816 {
2817     return consumeIdent<CSSValueScroll, CSSValueFixed, CSSValueLocal>(range);
2818 }
2819
2820 static RefPtr<CSSPrimitiveValue> consumeBackgroundBox(CSSParserTokenRange& range)
2821 {
2822     return consumeIdent<CSSValueBorderBox, CSSValuePaddingBox, CSSValueContentBox, CSSValueWebkitText>(range);
2823 }
2824
2825 static RefPtr<CSSPrimitiveValue> consumeBackgroundComposite(CSSParserTokenRange& range)
2826 {
2827     return consumeIdentRange(range, CSSValueClear, CSSValuePlusLighter);
2828 }
2829
2830 static RefPtr<CSSPrimitiveValue> consumeWebkitMaskSourceType(CSSParserTokenRange& range)
2831 {
2832     return consumeIdent<CSSValueAuto, CSSValueAlpha, CSSValueLuminance>(range);
2833 }
2834
2835 static RefPtr<CSSPrimitiveValue> consumePrefixedBackgroundBox(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& /*context*/)
2836 {
2837     // The values 'border', 'padding' and 'content' are deprecated and do not apply to the version of the property that has the -webkit- prefix removed.
2838     if (RefPtr<CSSPrimitiveValue> value = consumeIdentRange(range, CSSValueBorder, CSSValuePaddingBox))
2839         return value;
2840     if (range.peek().id() == CSSValueWebkitText || ((property == CSSPropertyWebkitBackgroundClip || property == CSSPropertyWebkitMaskClip) && range.peek().id() == CSSValueText))
2841         return consumeIdent(range);
2842     return nullptr;
2843 }
2844
2845 static RefPtr<CSSPrimitiveValue> consumeBackgroundSize(CSSPropertyID property, CSSParserTokenRange& range, CSSParserMode cssParserMode)
2846 {
2847     if (identMatches<CSSValueContain, CSSValueCover>(range.peek().id()))
2848         return consumeIdent(range);
2849
2850     // FIXME: We're allowing the unitless quirk on this property because our
2851     // tests assume that. Other browser engines don't allow it though.
2852     RefPtr<CSSPrimitiveValue> horizontal = consumeIdent<CSSValueAuto>(range);
2853     if (!horizontal)
2854         horizontal = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
2855
2856     RefPtr<CSSPrimitiveValue> vertical;
2857     if (!range.atEnd()) {
2858         if (range.peek().id() == CSSValueAuto) // `auto' is the default
2859             range.consumeIncludingWhitespace();
2860         else
2861             vertical = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
2862     } else if (!vertical && property == CSSPropertyWebkitBackgroundSize) {
2863         // Legacy syntax: "-webkit-background-size: 10px" is equivalent to "background-size: 10px 10px".
2864         vertical = horizontal;
2865     }
2866     if (!vertical)
2867         return horizontal;
2868     return createPrimitiveValuePair(horizontal.releaseNonNull(), vertical.releaseNonNull(), property == CSSPropertyWebkitBackgroundSize ? Pair::IdenticalValueEncoding::Coalesce : Pair::IdenticalValueEncoding::DoNotCoalesce);
2869 }
2870
2871 #if ENABLE(CSS_GRID_LAYOUT)
2872 static RefPtr<CSSValueList> consumeGridAutoFlow(CSSParserTokenRange& range)
2873 {
2874     RefPtr<CSSPrimitiveValue> rowOrColumnValue = consumeIdent<CSSValueRow, CSSValueColumn>(range);
2875     RefPtr<CSSPrimitiveValue> denseAlgorithm = consumeIdent<CSSValueDense>(range);
2876     if (!rowOrColumnValue) {
2877         rowOrColumnValue = consumeIdent<CSSValueRow, CSSValueColumn>(range);
2878         if (!rowOrColumnValue && !denseAlgorithm)
2879             return nullptr;
2880     }
2881     RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
2882     if (rowOrColumnValue)
2883         parsedValues->append(rowOrColumnValue.releaseNonNull());
2884     if (denseAlgorithm)
2885         parsedValues->append(denseAlgorithm.releaseNonNull());
2886     return parsedValues;
2887 }
2888 #endif
2889
2890 static RefPtr<CSSValue> consumeBackgroundComponent(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
2891 {
2892     switch (property) {
2893     case CSSPropertyBackgroundClip:
2894         return consumeBackgroundBox(range);
2895     case CSSPropertyBackgroundBlendMode:
2896         return consumeBackgroundBlendMode(range);
2897     case CSSPropertyBackgroundAttachment:
2898         return consumeBackgroundAttachment(range);
2899     case CSSPropertyBackgroundOrigin:
2900         return consumeBackgroundBox(range);
2901     case CSSPropertyWebkitMaskComposite:
2902     case CSSPropertyWebkitBackgroundComposite:
2903         return consumeBackgroundComposite(range);
2904     case CSSPropertyWebkitBackgroundClip:
2905     case CSSPropertyWebkitBackgroundOrigin:
2906     case CSSPropertyWebkitMaskClip:
2907     case CSSPropertyWebkitMaskOrigin:
2908         return consumePrefixedBackgroundBox(property, range, context);
2909     case CSSPropertyBackgroundImage:
2910     case CSSPropertyWebkitMaskImage:
2911         return consumeImageOrNone(range, context);
2912     case CSSPropertyWebkitMaskSourceType:
2913         return consumeWebkitMaskSourceType(range);
2914     case CSSPropertyBackgroundPositionX:
2915     case CSSPropertyWebkitMaskPositionX:
2916         return consumePositionX(range, context.mode);
2917     case CSSPropertyBackgroundPositionY:
2918     case CSSPropertyWebkitMaskPositionY:
2919         return consumePositionY(range, context.mode);
2920     case CSSPropertyBackgroundSize:
2921     case CSSPropertyWebkitBackgroundSize:
2922     case CSSPropertyWebkitMaskSize:
2923         return consumeBackgroundSize(property, range, context.mode);
2924     case CSSPropertyBackgroundColor:
2925         return consumeColor(range, context.mode);
2926     default:
2927         break;
2928     };
2929     return nullptr;
2930 }
2931
2932 static void addBackgroundValue(RefPtr<CSSValue>& list, Ref<CSSValue>&& value)
2933 {
2934     if (list) {
2935         if (!list->isBaseValueList()) {
2936             RefPtr<CSSValue> firstValue = list;
2937             list = CSSValueList::createCommaSeparated();
2938             downcast<CSSValueList>(*list).append(firstValue.releaseNonNull());
2939         }
2940         downcast<CSSValueList>(*list).append(WTFMove(value));
2941     } else {
2942         // To conserve memory we don't actually wrap a single value in a list.
2943         list = WTFMove(value);
2944     }
2945 }
2946
2947 static RefPtr<CSSValue> consumeCommaSeparatedBackgroundComponent(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
2948 {
2949     RefPtr<CSSValue> result;
2950     do {
2951         RefPtr<CSSValue> value = consumeBackgroundComponent(property, range, context);
2952         if (!value)
2953             return nullptr;
2954         addBackgroundValue(result, value.releaseNonNull());
2955     } while (consumeCommaIncludingWhitespace(range));
2956     return result;
2957 }
2958
2959 #if ENABLE(CSS_GRID_LAYOUT)
2960 static RefPtr<CSSPrimitiveValue> consumeSelfPositionKeyword(CSSParserTokenRange& range)
2961 {
2962     CSSValueID id = range.peek().id();
2963     if (id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
2964         || id == CSSValueSelfStart || id == CSSValueSelfEnd || id == CSSValueFlexStart
2965         || id == CSSValueFlexEnd || id == CSSValueLeft || id == CSSValueRight)
2966         return consumeIdent(range);
2967     return nullptr;
2968 }
2969
2970 static RefPtr<CSSValue> consumeSelfPositionOverflowPosition(CSSParserTokenRange& range)
2971 {
2972     if (identMatches<CSSValueAuto, CSSValueNormal, CSSValueStretch, CSSValueBaseline, CSSValueLastBaseline>(range.peek().id()))
2973         return consumeIdent(range);
2974
2975     RefPtr<CSSPrimitiveValue> overflowPosition = consumeIdent<CSSValueUnsafe, CSSValueSafe>(range);
2976     RefPtr<CSSPrimitiveValue> selfPosition = consumeSelfPositionKeyword(range);
2977     if (!selfPosition)
2978         return nullptr;
2979     if (!overflowPosition)
2980         overflowPosition = consumeIdent<CSSValueUnsafe, CSSValueSafe>(range);
2981     if (overflowPosition)
2982         return createPrimitiveValuePair(selfPosition.releaseNonNull(), overflowPosition.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
2983     return selfPosition;
2984 }
2985
2986 static RefPtr<CSSValue> consumeAlignItems(CSSParserTokenRange& range)
2987 {
2988     // align-items property does not allow the 'auto' value.
2989     if (identMatches<CSSValueAuto>(range.peek().id()))
2990         return nullptr;
2991     return consumeSelfPositionOverflowPosition(range);
2992 }
2993
2994 static RefPtr<CSSValue> consumeJustifyItems(CSSParserTokenRange& range)
2995 {
2996     CSSParserTokenRange rangeCopy = range;
2997     RefPtr<CSSPrimitiveValue> legacy = consumeIdent<CSSValueLegacy>(rangeCopy);
2998     RefPtr<CSSPrimitiveValue> positionKeyword = consumeIdent<CSSValueCenter, CSSValueLeft, CSSValueRight>(rangeCopy);
2999     if (!legacy)
3000         legacy = consumeIdent<CSSValueLegacy>(rangeCopy);
3001     if (legacy && positionKeyword) {
3002         range = rangeCopy;
3003         return createPrimitiveValuePair(legacy.releaseNonNull(), positionKeyword.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
3004     }
3005     return consumeSelfPositionOverflowPosition(range);
3006 }
3007
3008 static RefPtr<CSSValue> consumeFitContent(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3009 {
3010     CSSParserTokenRange rangeCopy = range;
3011     CSSParserTokenRange args = consumeFunction(rangeCopy);
3012     RefPtr<CSSPrimitiveValue> length = consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
3013     if (!length || !args.atEnd())
3014         return nullptr;
3015     range = rangeCopy;
3016     RefPtr<CSSFunctionValue> result = CSSFunctionValue::create(CSSValueFitContent);
3017     result->append(length.releaseNonNull());
3018     return result;
3019 }
3020
3021 static RefPtr<CSSPrimitiveValue> consumeCustomIdentForGridLine(CSSParserTokenRange& range)
3022 {
3023     if (range.peek().id() == CSSValueAuto || range.peek().id() == CSSValueSpan)
3024         return nullptr;
3025     return consumeCustomIdent(range);
3026 }
3027
3028 static RefPtr<CSSValue> consumeGridLine(CSSParserTokenRange& range)
3029 {
3030     if (range.peek().id() == CSSValueAuto)
3031         return consumeIdent(range);
3032
3033     RefPtr<CSSPrimitiveValue> spanValue;
3034     RefPtr<CSSPrimitiveValue> gridLineName;
3035     RefPtr<CSSPrimitiveValue> numericValue = consumeInteger(range);
3036     if (numericValue) {
3037         gridLineName = consumeCustomIdentForGridLine(range);
3038         spanValue = consumeIdent<CSSValueSpan>(range);
3039     } else {
3040         spanValue = consumeIdent<CSSValueSpan>(range);
3041         if (spanValue) {
3042             numericValue = consumeInteger(range);
3043             gridLineName = consumeCustomIdentForGridLine(range);
3044             if (!numericValue)
3045                 numericValue = consumeInteger(range);
3046         } else {
3047             gridLineName = consumeCustomIdentForGridLine(range);
3048             if (gridLineName) {
3049                 numericValue = consumeInteger(range);
3050                 spanValue = consumeIdent<CSSValueSpan>(range);
3051                 if (!spanValue && !numericValue)
3052                     return gridLineName;
3053             } else {
3054                 return nullptr;
3055             }
3056         }
3057     }
3058
3059     if (spanValue && !numericValue && !gridLineName)
3060         return nullptr; // "span" keyword alone is invalid.
3061     if (spanValue && numericValue && numericValue->intValue() < 0)
3062         return nullptr; // Negative numbers are not allowed for span.
3063     if (numericValue && numericValue->intValue() == 0)
3064         return nullptr; // An <integer> value of zero makes the declaration invalid.
3065
3066     RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
3067     if (spanValue)
3068         values->append(spanValue.releaseNonNull());
3069     if (numericValue)
3070         values->append(numericValue.releaseNonNull());
3071     if (gridLineName)
3072         values->append(gridLineName.releaseNonNull());
3073     ASSERT(values->length());
3074     return values;
3075 }
3076
3077 static bool isGridTrackFixedSized(const CSSPrimitiveValue& primitiveValue)
3078 {
3079     CSSValueID valueID = primitiveValue.valueID();
3080     if (valueID == CSSValueWebkitMinContent || valueID == CSSValueWebkitMaxContent || valueID == CSSValueAuto || primitiveValue.isFlex())
3081         return false;
3082
3083     return true;
3084 }
3085
3086 static bool isGridTrackFixedSized(const CSSValue& value)
3087 {
3088     if (value.isPrimitiveValue())
3089         return isGridTrackFixedSized(downcast<CSSPrimitiveValue>(value));
3090
3091     ASSERT(value.isFunctionValue());
3092     auto& function = downcast<CSSFunctionValue>(value);
3093     if (function.name() == CSSValueFitContent || function.arguments() == nullptr || function.arguments()->length() < 2)
3094         return false;
3095
3096     CSSValue* minPrimitiveValue = downcast<CSSPrimitiveValue>(function.arguments()->item(0));
3097     CSSValue* maxPrimitiveValue = downcast<CSSPrimitiveValue>(function.arguments()->item(1));
3098     return isGridTrackFixedSized(*minPrimitiveValue) || isGridTrackFixedSized(*maxPrimitiveValue);
3099 }
3100
3101 static Vector<String> parseGridTemplateAreasColumnNames(const String& gridRowNames)
3102 {
3103     ASSERT(!gridRowNames.isEmpty());
3104     Vector<String> columnNames;
3105     // Using StringImpl to avoid checks and indirection in every call to String::operator[].
3106     StringImpl& text = *gridRowNames.impl();
3107
3108     StringBuilder areaName;
3109     for (unsigned i = 0; i < text.length(); ++i) {
3110         if (isCSSSpace(text[i])) {
3111             if (!areaName.isEmpty()) {
3112                 columnNames.append(areaName.toString());
3113                 areaName.clear();
3114             }
3115             continue;
3116         }
3117         if (text[i] == '.') {
3118             if (areaName == ".")
3119                 continue;
3120             if (!areaName.isEmpty()) {
3121                 columnNames.append(areaName.toString());
3122                 areaName.clear();
3123             }
3124         } else {
3125             if (!isNameCodePoint(text[i]))
3126                 return Vector<String>();
3127             if (areaName == ".") {
3128                 columnNames.append(areaName.toString());
3129                 areaName.clear();
3130             }
3131         }
3132
3133         areaName.append(text[i]);
3134     }
3135
3136     if (!areaName.isEmpty())
3137         columnNames.append(areaName.toString());
3138
3139     return columnNames;
3140 }
3141
3142 static bool parseGridTemplateAreasRow(const String& gridRowNames, NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount)
3143 {
3144     if (gridRowNames.isEmpty() || gridRowNames.containsOnlyWhitespace())
3145         return false;
3146
3147     Vector<String> columnNames = parseGridTemplateAreasColumnNames(gridRowNames);
3148     if (rowCount == 0) {
3149         columnCount = columnNames.size();
3150         if (columnCount == 0)
3151             return false;
3152     } else if (columnCount != columnNames.size()) {
3153         // The declaration is invalid if all the rows don't have the number of columns.
3154         return false;
3155     }
3156
3157     for (size_t currentColumn = 0; currentColumn < columnCount; ++currentColumn) {
3158         const String& gridAreaName = columnNames[currentColumn];
3159
3160         // Unamed areas are always valid (we consider them to be 1x1).
3161         if (gridAreaName == ".")
3162             continue;
3163
3164         size_t lookAheadColumn = currentColumn + 1;
3165         while (lookAheadColumn < columnCount && columnNames[lookAheadColumn] == gridAreaName)
3166             lookAheadColumn++;
3167
3168         NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName);
3169         if (gridAreaIt == gridAreaMap.end()) {
3170             gridAreaMap.add(gridAreaName, GridArea(GridSpan::translatedDefiniteGridSpan(rowCount, rowCount + 1), GridSpan::translatedDefiniteGridSpan(currentColumn, lookAheadColumn)));
3171         } else {
3172             GridArea& gridArea = gridAreaIt->value;
3173
3174             // The following checks test that the grid area is a single filled-in rectangle.
3175             // 1. The new row is adjacent to the previously parsed row.
3176             if (rowCount != gridArea.rows.endLine())
3177                 return false;
3178
3179             // 2. The new area starts at the same position as the previously parsed area.
3180             if (currentColumn != gridArea.columns.startLine())
3181                 return false;
3182
3183             // 3. The new area ends at the same position as the previously parsed area.
3184             if (lookAheadColumn != gridArea.columns.endLine())
3185                 return false;
3186
3187             gridArea.rows = GridSpan::translatedDefiniteGridSpan(gridArea.rows.startLine(), gridArea.rows.endLine() + 1);
3188         }
3189         currentColumn = lookAheadColumn - 1;
3190     }
3191
3192     return true;
3193 }
3194
3195 static RefPtr<CSSPrimitiveValue> consumeGridBreadth(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3196 {
3197     const CSSParserToken& token = range.peek();
3198     if (identMatches<CSSValueWebkitMinContent, CSSValueWebkitMaxContent, CSSValueAuto>(token.id()))
3199         return consumeIdent(range);
3200     if (token.type() == DimensionToken && token.unitType() == CSSPrimitiveValue::UnitTypes::CSS_FR) {
3201         if (range.peek().numericValue() < 0)
3202             return nullptr;
3203         return CSSPrimitiveValue::create(range.consumeIncludingWhitespace().numericValue(), CSSPrimitiveValue::UnitTypes::CSS_FR);
3204     }
3205     return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
3206 }
3207
3208 static RefPtr<CSSValue> consumeGridTrackSize(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3209 {
3210     const CSSParserToken& token = range.peek();
3211     if (identMatches<CSSValueAuto>(token.id()))
3212         return consumeIdent(range);
3213
3214     if (token.functionId() == CSSValueMinmax) {
3215         CSSParserTokenRange rangeCopy = range;
3216         CSSParserTokenRange args = consumeFunction(rangeCopy);
3217         RefPtr<CSSPrimitiveValue> minTrackBreadth = consumeGridBreadth(args, cssParserMode);
3218         if (!minTrackBreadth || minTrackBreadth->isFlex() || !consumeCommaIncludingWhitespace(args))
3219             return nullptr;
3220         RefPtr<CSSPrimitiveValue> maxTrackBreadth = consumeGridBreadth(args, cssParserMode);
3221         if (!maxTrackBreadth || !args.atEnd())
3222             return nullptr;
3223         range = rangeCopy;
3224         RefPtr<CSSFunctionValue> result = CSSFunctionValue::create(CSSValueMinmax);
3225         result->append(minTrackBreadth.releaseNonNull());
3226         result->append(maxTrackBreadth.releaseNonNull());
3227         return result;
3228     }
3229
3230     if (token.functionId() == CSSValueFitContent)
3231         return consumeFitContent(range, cssParserMode);
3232
3233     return consumeGridBreadth(range, cssParserMode);
3234 }
3235
3236 // Appends to the passed in CSSGridLineNamesValue if any, otherwise creates a new one.
3237 static RefPtr<CSSGridLineNamesValue> consumeGridLineNames(CSSParserTokenRange& range, CSSGridLineNamesValue* lineNames = nullptr)
3238 {
3239     CSSParserTokenRange rangeCopy = range;
3240     if (rangeCopy.consumeIncludingWhitespace().type() != LeftBracketToken)
3241         return nullptr;
3242     
3243     RefPtr<CSSGridLineNamesValue> result = lineNames;
3244     if (!result)
3245         result = CSSGridLineNamesValue::create();
3246     while (RefPtr<CSSPrimitiveValue> lineName = consumeCustomIdentForGridLine(rangeCopy))
3247         result->append(lineName.releaseNonNull());
3248     if (rangeCopy.consumeIncludingWhitespace().type() != RightBracketToken)
3249         return nullptr;
3250     range = rangeCopy;
3251     return result;
3252 }
3253
3254 static bool consumeGridTrackRepeatFunction(CSSParserTokenRange& range, CSSParserMode cssParserMode, CSSValueList& list, bool& isAutoRepeat, bool& allTracksAreFixedSized)
3255 {
3256     CSSParserTokenRange args = consumeFunction(range);
3257     // The number of repetitions for <auto-repeat> is not important at parsing level
3258     // because it will be computed later, let's set it to 1.
3259     size_t repetitions = 1;
3260     isAutoRepeat = identMatches<CSSValueAutoFill, CSSValueAutoFit>(args.peek().id());
3261     RefPtr<CSSValueList> repeatedValues;
3262     if (isAutoRepeat)
3263         repeatedValues = CSSGridAutoRepeatValue::create(args.consumeIncludingWhitespace().id());
3264     else {
3265         // FIXME: a consumeIntegerRaw would be more efficient here.
3266         RefPtr<CSSPrimitiveValue> repetition = consumePositiveInteger(args);
3267         if (!repetition)
3268             return false;
3269         repetitions = clampTo<size_t>(repetition->doubleValue(), 0, kGridMaxTracks);
3270         repeatedValues = CSSValueList::createSpaceSeparated();
3271     }
3272     if (!consumeCommaIncludingWhitespace(args))
3273         return false;
3274     RefPtr<CSSGridLineNamesValue> lineNames = consumeGridLineNames(args);
3275     if (lineNames)
3276         repeatedValues->append(lineNames.releaseNonNull());
3277
3278     size_t numberOfTracks = 0;
3279     while (!args.atEnd()) {
3280         RefPtr<CSSValue> trackSize = consumeGridTrackSize(args, cssParserMode);
3281         if (!trackSize)
3282             return false;
3283         if (allTracksAreFixedSized)
3284             allTracksAreFixedSized = isGridTrackFixedSized(*trackSize);
3285         repeatedValues->append(trackSize.releaseNonNull());
3286         ++numberOfTracks;
3287         lineNames = consumeGridLineNames(args);
3288         if (lineNames)
3289             repeatedValues->append(lineNames.releaseNonNull());
3290     }
3291     // We should have found at least one <track-size> or else it is not a valid <track-list>.
3292     if (!numberOfTracks)
3293         return false;
3294
3295     if (isAutoRepeat)
3296         list.append(repeatedValues.releaseNonNull());
3297     else {
3298         // We clamp the repetitions to a multiple of the repeat() track list's size, while staying below the max grid size.
3299         repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks);
3300         for (size_t i = 0; i < repetitions; ++i) {
3301             for (size_t j = 0; j < repeatedValues->length(); ++j)
3302                 list.append(*repeatedValues->itemWithoutBoundsCheck(j));
3303         }
3304     }
3305     return true;
3306 }
3307
3308 enum TrackListType { GridTemplate, GridTemplateNoRepeat, GridAuto };
3309
3310 static RefPtr<CSSValue> consumeGridTrackList(CSSParserTokenRange& range, CSSParserMode cssParserMode, TrackListType trackListType)
3311 {
3312     bool allowGridLineNames = trackListType != GridAuto;
3313     RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
3314     RefPtr<CSSGridLineNamesValue> lineNames = consumeGridLineNames(range);
3315     if (lineNames) {
3316         if (!allowGridLineNames)
3317             return nullptr;
3318         values->append(lineNames.releaseNonNull());
3319     }
3320     
3321     bool allowRepeat = trackListType == GridTemplate;
3322     bool seenAutoRepeat = false;
3323     bool allTracksAreFixedSized = true;
3324     do {
3325         bool isAutoRepeat;
3326         if (range.peek().functionId() == CSSValueRepeat) {
3327             if (!allowRepeat)
3328                 return nullptr;
3329             if (!consumeGridTrackRepeatFunction(range, cssParserMode, *values, isAutoRepeat, allTracksAreFixedSized))
3330                 return nullptr;
3331             if (isAutoRepeat && seenAutoRepeat)
3332                 return nullptr;
3333             seenAutoRepeat = seenAutoRepeat || isAutoRepeat;
3334         } else if (RefPtr<CSSValue> value = consumeGridTrackSize(range, cssParserMode)) {
3335             if (allTracksAreFixedSized)
3336                 allTracksAreFixedSized = isGridTrackFixedSized(*value);
3337             values->append(value.releaseNonNull());
3338         } else {
3339             return nullptr;
3340         }
3341         if (seenAutoRepeat && !allTracksAreFixedSized)
3342             return nullptr;
3343         lineNames = consumeGridLineNames(range);
3344         if (lineNames) {
3345             if (!allowGridLineNames)
3346                 return nullptr;
3347             values->append(lineNames.releaseNonNull());
3348         }
3349     } while (!range.atEnd() && range.peek().type() != DelimiterToken);
3350     return values;
3351 }
3352
3353 static RefPtr<CSSValue> consumeGridTemplatesRowsOrColumns(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3354 {
3355     if (range.peek().id() == CSSValueNone)
3356         return consumeIdent(range);
3357     return consumeGridTrackList(range, cssParserMode, GridTemplate);
3358 }
3359
3360 static RefPtr<CSSValue> consumeGridTemplateAreas(CSSParserTokenRange& range)
3361 {
3362     if (range.peek().id() == CSSValueNone)
3363         return consumeIdent(range);
3364
3365     NamedGridAreaMap gridAreaMap;
3366     size_t rowCount = 0;
3367     size_t columnCount = 0;
3368
3369     while (range.peek().type() == StringToken) {
3370         if (!parseGridTemplateAreasRow(range.consumeIncludingWhitespace().value().toString(), gridAreaMap, rowCount, columnCount))
3371             return nullptr;
3372         ++rowCount;
3373     }
3374
3375     if (rowCount == 0)
3376         return nullptr;
3377     ASSERT(columnCount);
3378     return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount);
3379 }
3380 #endif
3381
3382 #if ENABLE(CSS_REGIONS)
3383 static RefPtr<CSSValue> consumeFlowProperty(CSSParserTokenRange& range)
3384 {
3385     RefPtr<CSSValue> result;
3386     if (range.peek().id() == CSSValueNone)
3387         result = consumeIdent(range);
3388     else
3389         result = consumeCustomIdent(range);
3390     return result;
3391 }
3392 #endif
3393
3394 static RefPtr<CSSValue> consumeLineBoxContain(CSSParserTokenRange& range)
3395 {
3396     if (range.peek().id() == CSSValueNone)
3397         return consumeIdent(range);
3398
3399     LineBoxContain lineBoxContain = LineBoxContainNone;
3400     
3401     while (range.peek().type() == IdentToken) {
3402         auto id = range.peek().id();
3403         if (id == CSSValueBlock) {
3404             if (lineBoxContain & LineBoxContainBlock)
3405                 return nullptr;
3406             lineBoxContain |= LineBoxContainBlock;
3407         } else if (id == CSSValueInline) {
3408             if (lineBoxContain & LineBoxContainInline)
3409                 return nullptr;
3410             lineBoxContain |= LineBoxContainInline;
3411         } else if (id == CSSValueFont) {
3412             if (lineBoxContain & LineBoxContainFont)
3413                 return nullptr;
3414             lineBoxContain |= LineBoxContainFont;
3415         } else if (id == CSSValueGlyphs) {
3416             if (lineBoxContain & LineBoxContainGlyphs)
3417                 return nullptr;
3418             lineBoxContain |= LineBoxContainGlyphs;
3419         } else if (id == CSSValueReplaced) {
3420             if (lineBoxContain & LineBoxContainReplaced)
3421                 return nullptr;
3422             lineBoxContain |= LineBoxContainReplaced;
3423         } else if (id == CSSValueInlineBox) {
3424             if (lineBoxContain & LineBoxContainInlineBox)
3425                 return nullptr;
3426             lineBoxContain |= LineBoxContainInlineBox;
3427         } else if (id == CSSValueInitialLetter) {
3428             if (lineBoxContain & LineBoxContainInitialLetter)
3429                 return nullptr;
3430             lineBoxContain |= LineBoxContainInitialLetter;
3431         } else
3432             return nullptr;
3433         range.consumeIncludingWhitespace();
3434     }
3435     
3436     if (!lineBoxContain)
3437         return nullptr;
3438     
3439     return CSSLineBoxContainValue::create(lineBoxContain);
3440 }
3441
3442 static RefPtr<CSSValue> consumeLineGrid(CSSParserTokenRange& range)
3443 {
3444     if (range.peek().id() == CSSValueNone)
3445         return consumeIdent(range);
3446     return consumeCustomIdent(range);
3447 }
3448
3449 static RefPtr<CSSValue> consumeInitialLetter(CSSParserTokenRange& range)
3450 {
3451     RefPtr<CSSValue> ident = consumeIdent<CSSValueNormal>(range);
3452     if (ident)
3453         return ident;
3454     
3455     RefPtr<CSSPrimitiveValue> height = consumeNumber(range, ValueRangeNonNegative);
3456     if (!height)
3457         return nullptr;
3458     
3459     RefPtr<CSSPrimitiveValue> position;
3460     if (!range.atEnd()) {
3461         position = consumeNumber(range, ValueRangeNonNegative);
3462         if (!position || !range.atEnd())
3463             return nullptr;
3464     } else
3465         position = height.copyRef();
3466     
3467     return createPrimitiveValuePair(position.releaseNonNull(), WTFMove(height));
3468 }
3469
3470 static RefPtr<CSSValue> consumeHangingPunctuation(CSSParserTokenRange& range)
3471 {
3472     if (range.peek().id() == CSSValueNone)
3473         return consumeIdent(range);
3474     
3475     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3476     std::bitset<numCSSValueKeywords> seenValues;
3477
3478     bool seenForceEnd = false;
3479     bool seenAllowEnd = false;
3480     bool seenFirst = false;
3481     bool seenLast = false;
3482
3483     while (!range.atEnd()) {
3484         CSSValueID valueID = range.peek().id();
3485         if ((valueID == CSSValueFirst && seenFirst)
3486             || (valueID == CSSValueLast && seenLast)
3487             || (valueID == CSSValueAllowEnd && (seenAllowEnd || seenForceEnd))
3488             || (valueID == CSSValueForceEnd && (seenAllowEnd || seenForceEnd)))
3489             return nullptr;
3490         RefPtr<CSSValue> ident = consumeIdent<CSSValueAllowEnd, CSSValueForceEnd, CSSValueFirst, CSSValueLast>(range);
3491         if (!ident)
3492             return nullptr;
3493         switch (valueID) {
3494         case CSSValueAllowEnd:
3495             seenAllowEnd = true;
3496             break;
3497         case CSSValueForceEnd:
3498             seenForceEnd = true;
3499             break;
3500         case CSSValueFirst:
3501             seenFirst = true;
3502             break;
3503         case CSSValueLast:
3504             seenLast = true;
3505             break;
3506         default:
3507             break;
3508         }
3509         list->append(ident.releaseNonNull());
3510     }
3511     
3512     return list->length() ? list : nullptr;
3513 }
3514
3515 static RefPtr<CSSValue> consumeWebkitMarqueeIncrement(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3516 {
3517     if (range.peek().type() == IdentToken)
3518         return consumeIdent<CSSValueSmall, CSSValueMedium, CSSValueLarge>(range);
3519     return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
3520 }
3521
3522 static RefPtr<CSSValue> consumeWebkitMarqueeRepetition(CSSParserTokenRange& range)
3523 {
3524     if (range.peek().type() == IdentToken)
3525         return consumeIdent<CSSValueInfinite>(range);
3526     return consumeNumber(range, ValueRangeNonNegative);
3527 }
3528
3529 static RefPtr<CSSValue> consumeWebkitMarqueeSpeed(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3530 {
3531     if (range.peek().type() == IdentToken)
3532         return consumeIdent<CSSValueSlow, CSSValueNormal, CSSValueFast>(range);
3533     return consumeTime(range, cssParserMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
3534 }
3535
3536 static RefPtr<CSSValue> consumeAlt(CSSParserTokenRange& range, const CSSParserContext& context)
3537 {
3538     if (range.peek().type() == StringToken)
3539         return consumeString(range);
3540     
3541     if (range.peek().functionId() != CSSValueAttr)
3542         return nullptr;
3543     
3544     return consumeAttr(consumeFunction(range), context);
3545 }
3546
3547 static RefPtr<CSSValue> consumeWebkitAspectRatio(CSSParserTokenRange& range)
3548 {
3549     if (range.peek().type() == IdentToken)
3550         return consumeIdent<CSSValueAuto, CSSValueFromDimensions, CSSValueFromIntrinsic>(range);
3551     
3552     RefPtr<CSSPrimitiveValue> leftValue = consumeNumber(range, ValueRangeNonNegative);
3553     if (!leftValue || range.atEnd() || !consumeSlashIncludingWhitespace(range))
3554         return nullptr;
3555     RefPtr<CSSPrimitiveValue> rightValue = consumeNumber(range, ValueRangeNonNegative);
3556     if (!rightValue)
3557         return nullptr;
3558     
3559     return CSSAspectRatioValue::create(leftValue->floatValue(), rightValue->floatValue());
3560 }
3561
3562 static RefPtr<CSSValue> consumeTextEmphasisPosition(CSSParserTokenRange& range)
3563 {
3564     bool foundOverOrUnder = false;
3565     CSSValueID overUnderValueID = CSSValueOver;
3566     bool foundLeftOrRight = false;
3567     CSSValueID leftRightValueID = CSSValueRight;
3568     while (!range.atEnd()) {
3569         switch (range.peek().id()) {
3570         case CSSValueOver:
3571             if (foundOverOrUnder)
3572                 return nullptr;
3573             foundOverOrUnder = true;
3574             overUnderValueID = CSSValueOver;
3575             break;
3576         case CSSValueUnder:
3577             if (foundOverOrUnder)
3578                 return nullptr;
3579             foundOverOrUnder = true;
3580             overUnderValueID = CSSValueUnder;
3581             break;
3582         case CSSValueLeft:
3583             if (foundLeftOrRight)
3584                 return nullptr;
3585             foundLeftOrRight = true;
3586             leftRightValueID = CSSValueLeft;
3587             break;
3588         case CSSValueRight:
3589             if (foundLeftOrRight)
3590                 return nullptr;
3591             foundLeftOrRight = true;
3592             leftRightValueID = CSSValueRight;
3593             break;
3594         default:
3595             return nullptr;
3596         }
3597         
3598         range.consumeIncludingWhitespace();
3599     }
3600     if (!foundOverOrUnder)
3601         return nullptr;
3602     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3603     list->append(CSSValuePool::singleton().createIdentifierValue(overUnderValueID));
3604     if (foundLeftOrRight)
3605         list->append(CSSValuePool::singleton().createIdentifierValue(leftRightValueID));
3606     return list;
3607 }
3608     
3609 #if ENABLE(DASHBOARD_SUPPORT)
3610
3611 static RefPtr<CSSValue> consumeWebkitDashboardRegion(CSSParserTokenRange& range, CSSParserMode mode)
3612 {
3613     if (range.peek().id() == CSSValueNone)
3614         return consumeIdent(range);
3615     
3616     auto firstRegion = DashboardRegion::create();
3617     DashboardRegion* region = nullptr;
3618     
3619     bool requireCommas = false;
3620     
3621     while (!range.atEnd()) {
3622         if (!region)
3623             region = firstRegion.ptr();
3624         else {
3625             auto nextRegion = DashboardRegion::create();
3626             region->m_next = nextRegion.copyRef();
3627             region = nextRegion.ptr();
3628         }
3629         
3630         if (range.peek().functionId() != CSSValueDashboardRegion)
3631             return nullptr;
3632         
3633         CSSParserTokenRange rangeCopy = range;
3634         CSSParserTokenRange args = consumeFunction(rangeCopy);
3635         
3636         // First arg is a label.
3637         if (args.peek().type() != IdentToken)
3638             return nullptr;
3639         region->m_label = args.consumeIncludingWhitespace().value().toString();
3640         
3641         // Comma is optional, so don't fail if we can't consume one.
3642         requireCommas = consumeCommaIncludingWhitespace(args);
3643
3644         // Second arg is a type.
3645         if (args.peek().type() != IdentToken)
3646             return nullptr;
3647         region->m_geometryType = args.consumeIncludingWhitespace().value().toString();
3648         if (equalLettersIgnoringASCIICase(region->m_geometryType, "circle"))
3649             region->m_isCircle = true;
3650         else if (equalLettersIgnoringASCIICase(region->m_geometryType, "rectangle"))
3651             region->m_isRectangle = true;
3652         else
3653             return nullptr;
3654         
3655         if (args.atEnd()) {
3656             // This originally used CSSValueInvalid by accident. It might be more logical to use something else.
3657             RefPtr<CSSPrimitiveValue> amount = CSSValuePool::singleton().createIdentifierValue(CSSValueInvalid);
3658             region->setTop(amount.copyRef());
3659             region->setRight(amount.copyRef());
3660             region->setBottom(amount.copyRef());
3661             region->setLeft(WTFMove(amount));
3662             range = rangeCopy;
3663             continue;
3664         }
3665         
3666         // Next four arguments must be offset numbers or auto.
3667         for (int i = 0; i < 4; ++i) {
3668             if (args.atEnd() || (requireCommas && !consumeCommaIncludingWhitespace(args)))
3669                 return nullptr;
3670
3671             if (args.atEnd())
3672                 return nullptr;
3673             
3674             RefPtr<CSSPrimitiveValue> amount;
3675             if (args.peek().id() == CSSValueAuto)
3676                 amount = consumeIdent(args);
3677             else
3678                 amount = consumeLength(args, mode, ValueRangeAll);
3679         
3680             if (!i)
3681                 region->setTop(WTFMove(amount));
3682             else if (i == 1)
3683                 region->setRight(WTFMove(amount));
3684             else if (i == 2)
3685                 region->setBottom(WTFMove(amount));
3686             else
3687                 region->setLeft(WTFMove(amount));
3688         }
3689         
3690         if (!args.atEnd())
3691             return nullptr;
3692         
3693         range = rangeCopy;
3694     }
3695     
3696     return CSSValuePool::singleton().createValue(RefPtr<DashboardRegion>(WTFMove(firstRegion)));
3697 }
3698     
3699 #endif
3700
3701 RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, CSSPropertyID currentShorthand)
3702 {
3703     if (CSSParserFastPaths::isKeywordPropertyID(property)) {
3704         if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_range.peek().id(), m_context.mode, m_styleSheetContents))
3705             return nullptr;
3706         return consumeIdent(m_range);
3707     }
3708     switch (property) {
3709     case CSSPropertyWillChange:
3710         return consumeWillChange(m_range);
3711     case CSSPropertyPage:
3712         return consumePage(m_range);
3713     case CSSPropertyQuotes:
3714         return consumeQuotes(m_range);
3715     case CSSPropertyFontVariantCaps:
3716         return consumeFontVariantCaps(m_range);
3717     case CSSPropertyFontVariantLigatures:
3718         return consumeFontVariantLigatures(m_range);
3719     case CSSPropertyFontVariantNumeric:
3720         return consumeFontVariantNumeric(m_range);
3721     case CSSPropertyFontVariantEastAsian:
3722         return consumeFontVariantEastAsian(m_range);
3723     case CSSPropertyFontFeatureSettings:
3724         return consumeFontFeatureSettings(m_range);
3725     case CSSPropertyFontFamily:
3726         return consumeFontFamily(m_range);
3727     case CSSPropertyFontWeight:
3728         return consumeFontWeight(m_range);
3729     case CSSPropertyFontSynthesis:
3730         return consumeFontSynthesis(m_range);
3731 #if ENABLE(VARIATION_FONTS)
3732     case CSSPropertyFontVariationSettings:
3733         if (m_context.variationFontsEnabled)
3734             return consumeFontVariationSettings(m_range);
3735         return nullptr;
3736 #endif
3737     case CSSPropertyLetterSpacing:
3738         return consumeLetterSpacing(m_range, m_context.mode);
3739     case CSSPropertyWordSpacing:
3740         return consumeWordSpacing(m_range, m_context.mode);
3741     case CSSPropertyTabSize:
3742         return consumeTabSize(m_range, m_context.mode);
3743 #if ENABLE(TEXT_AUTOSIZING)
3744     case CSSPropertyWebkitTextSizeAdjust:
3745         // FIXME: Support toggling the validation of this property via a runtime setting that is independent of
3746         // whether isTextAutosizingEnabled() is true. We want to enable this property on iOS, when simulating
3747         // a iOS device in Safari's responsive design mode and when optionally enabled in DRT/WTR. Otherwise,
3748         // this property should be disabled by default.
3749 #if !PLATFORM(IOS)
3750         if (!m_context.textAutosizingEnabled)
3751             return nullptr;
3752 #endif
3753         return consumeTextSizeAdjust(m_range, m_context.mode);
3754 #endif
3755     case CSSPropertyFontSize:
3756         return consumeFontSize(m_range, m_context.mode, UnitlessQuirk::Allow);
3757     case CSSPropertyLineHeight:
3758         return consumeLineHeight(m_range, m_context.mode);
3759     case CSSPropertyWebkitBorderHorizontalSpacing:
3760     case CSSPropertyWebkitBorderVerticalSpacing:
3761         return consumeLength(m_range, m_context.mode, ValueRangeNonNegative);
3762     case CSSPropertyCounterIncrement:
3763     case CSSPropertyCounterReset:
3764         return consumeCounter(m_range, property == CSSPropertyCounterIncrement ? 1 : 0);
3765     case CSSPropertySize:
3766         return consumeSize(m_range, m_context.mode);
3767     case CSSPropertyTextIndent:
3768         return consumeTextIndent(m_range, m_context.mode);
3769     case CSSPropertyMaxWidth:
3770     case CSSPropertyMaxHeight:
3771         return consumeMaxWidthOrHeight(m_range, m_context, UnitlessQuirk::Allow);
3772     case CSSPropertyWebkitMaxLogicalWidth:
3773     case CSSPropertyWebkitMaxLogicalHeight:
3774         return consumeMaxWidthOrHeight(m_range, m_context);
3775     case CSSPropertyMinWidth:
3776     case CSSPropertyMinHeight:
3777     case CSSPropertyWidth:
3778     case CSSPropertyHeight:
3779         return consumeWidthOrHeight(m_range, m_context, UnitlessQuirk::Allow);
3780     case CSSPropertyWebkitMinLogicalWidth:
3781     case CSSPropertyWebkitMinLogicalHeight:
3782     case CSSPropertyWebkitLogicalWidth:
3783     case CSSPropertyWebkitLogicalHeight:
3784         return consumeWidthOrHeight(m_range, m_context);
3785     case CSSPropertyMarginTop:
3786     case CSSPropertyMarginRight:
3787     case CSSPropertyMarginBottom:
3788     case CSSPropertyMarginLeft:
3789     case CSSPropertyBottom:
3790     case CSSPropertyLeft:
3791     case CSSPropertyRight:
3792     case CSSPropertyTop:
3793         return consumeMarginOrOffset(m_range, m_context.mode, UnitlessQuirk::Allow);
3794     case CSSPropertyWebkitMarginStart:
3795     case CSSPropertyWebkitMarginEnd:
3796     case CSSPropertyWebkitMarginBefore:
3797     case CSSPropertyWebkitMarginAfter:
3798         return consumeMarginOrOffset(m_range, m_context.mode, UnitlessQuirk::Forbid);
3799     case CSSPropertyPaddingTop:
3800     case CSSPropertyPaddingRight:
3801     case CSSPropertyPaddingBottom:
3802     case CSSPropertyPaddingLeft:
3803         return consumeLengthOrPercent(m_range, m_context.mode, ValueRangeNonNegative, UnitlessQuirk::Allow);
3804     case CSSPropertyWebkitPaddingStart:
3805     case CSSPropertyWebkitPaddingEnd:
3806     case CSSPropertyWebkitPaddingBefore:
3807     case CSSPropertyWebkitPaddingAfter:
3808         return consumeLengthOrPercent(m_range, m_context.mode, ValueRangeNonNegative, UnitlessQuirk::Forbid);
3809     case CSSPropertyClip:
3810         return consumeClip(m_range, m_context.mode);
3811 #if ENABLE(TOUCH_EVENTS)
3812     case CSSPropertyTouchAction:
3813         return consumeTouchAction(m_range);
3814 #endif
3815     case CSSPropertyObjectPosition:
3816         return consumePosition(m_range, m_context.mode, UnitlessQuirk::Forbid);
3817     case CSSPropertyWebkitLineClamp:
3818         return consumeLineClamp(m_range);
3819     case CSSPropertyWebkitFontSizeDelta:
3820         return consumeLength(m_range, m_context.mode, ValueRangeAll, UnitlessQuirk::Allow);
3821     case CSSPropertyWebkitHyphenateCharacter:
3822     case CSSPropertyWebkitLocale:
3823         return consumeLocale(m_range);
3824     case CSSPropertyWebkitHyphenateLimitBefore:
3825     case CSSPropertyWebkitHyphenateLimitAfter:
3826         return consumeHyphenateLimit(m_range, CSSValueAuto);
3827     case CSSPropertyWebkitHyphenateLimitLines:
3828         return consumeHyphenateLimit(m_range, CSSValueNoLimit);
3829     case CSSPropertyColumnWidth:
3830         return consumeColumnWidth(m_range);
3831     case CSSPropertyColumnCount:
3832         return consumeColumnCount(m_range);
3833     case CSSPropertyColumnGap:
3834         return consumeColumnGap(m_range, m_context.mode);
3835     case CSSPropertyColumnSpan:
3836         return consumeColumnSpan(m_range);
3837     case CSSPropertyZoom:
3838         return consumeZoom(m_range, m_context);
3839     case CSSPropertyAnimationDelay:
3840     case CSSPropertyTransitionDelay:
3841     case CSSPropertyAnimationDirection:
3842     case CSSPropertyAnimationDuration:
3843     case CSSPropertyTransitionDuration:
3844     case CSSPropertyAnimationFillMode:
3845     case CSSPropertyAnimationIterationCount:
3846     case CSSPropertyAnimationName:
3847     case CSSPropertyAnimationPlayState:
3848     case CSSPropertyTransitionProperty:
3849     case CSSPropertyAnimationTimingFunction:
3850     case CSSPropertyTransitionTimingFunction:
3851 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
3852     case CSSPropertyWebkitAnimationTrigger:
3853 #endif
3854         return consumeAnimationPropertyList(property, m_range, m_context);
3855 #if ENABLE(CSS_GRID_LAYOUT)
3856     case CSSPropertyGridColumnGap: