[CSS Parser] Fix rx and ry parsing
[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     if (range.peek().type() != PercentageToken && range.peek().type() != NumberToken)
1208         return nullptr;
1209     RefPtr<CSSPrimitiveValue> clampValue = consumePercent(range, ValueRangeNonNegative);
1210     if (clampValue)
1211         return clampValue;
1212     // When specifying number of lines, don't allow 0 as a valid value.
1213     return consumePositiveInteger(range);
1214 }
1215
1216 static RefPtr<CSSValue> consumeLocale(CSSParserTokenRange& range)
1217 {
1218     if (range.peek().id() == CSSValueAuto)
1219         return consumeIdent(range);
1220     return consumeString(range);
1221 }
1222
1223 static RefPtr<CSSValue> consumeHyphenateLimit(CSSParserTokenRange& range, CSSValueID valueID)
1224 {
1225     if (range.peek().id() == valueID)
1226         return consumeIdent(range);
1227     return consumeNumber(range, ValueRangeNonNegative);
1228 }
1229
1230 static RefPtr<CSSValue> consumeColumnWidth(CSSParserTokenRange& range)
1231 {
1232     if (range.peek().id() == CSSValueAuto)
1233         return consumeIdent(range);
1234     // Always parse lengths in strict mode here, since it would be ambiguous otherwise when used in
1235     // the 'columns' shorthand property.
1236     RefPtr<CSSPrimitiveValue> columnWidth = consumeLength(range, HTMLStandardMode, ValueRangeNonNegative);
1237     if (!columnWidth || (!columnWidth->isCalculated() && columnWidth->doubleValue() == 0))
1238         return nullptr;
1239     return columnWidth;
1240 }
1241
1242 static RefPtr<CSSValue> consumeColumnCount(CSSParserTokenRange& range)
1243 {
1244     if (range.peek().id() == CSSValueAuto)
1245         return consumeIdent(range);
1246     return consumePositiveInteger(range);
1247 }
1248
1249 static RefPtr<CSSValue> consumeColumnGap(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1250 {
1251     if (range.peek().id() == CSSValueNormal)
1252         return consumeIdent(range);
1253     return consumeLength(range, cssParserMode, ValueRangeNonNegative);
1254 }
1255
1256 static RefPtr<CSSValue> consumeColumnSpan(CSSParserTokenRange& range)
1257 {
1258     return consumeIdent<CSSValueAll, CSSValueNone>(range);
1259 }
1260
1261 static RefPtr<CSSValue> consumeZoom(CSSParserTokenRange& range, const CSSParserContext& /*context*/)
1262 {
1263     const CSSParserToken& token = range.peek();
1264     RefPtr<CSSPrimitiveValue> zoom;
1265     if (token.type() == IdentToken)
1266         zoom = consumeIdent<CSSValueNormal, CSSValueReset, CSSValueDocument>(range);
1267     else {
1268         zoom = consumePercent(range, ValueRangeNonNegative);
1269         if (!zoom)
1270             zoom = consumeNumber(range, ValueRangeNonNegative);
1271     }
1272     return zoom;
1273 }
1274
1275 static RefPtr<CSSValue> consumeAnimationIterationCount(CSSParserTokenRange& range)
1276 {
1277     if (range.peek().id() == CSSValueInfinite)
1278         return consumeIdent(range);
1279     return consumeNumber(range, ValueRangeNonNegative);
1280 }
1281
1282 static RefPtr<CSSValue> consumeAnimationName(CSSParserTokenRange& range)
1283 {
1284     if (range.peek().id() == CSSValueNone)
1285         return consumeIdent(range);
1286
1287     if (range.peek().type() == StringToken) {
1288         const CSSParserToken& token = range.consumeIncludingWhitespace();
1289         if (equalIgnoringASCIICase(token.value(), "none"))
1290             return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
1291         // FIXME-NEWPARSER: Want to use a CSSCustomIdentValue here eventually.
1292         return CSSValuePool::singleton().createValue(token.value().toString(), CSSPrimitiveValue::UnitTypes::CSS_STRING);
1293     }
1294
1295     return consumeCustomIdent(range);
1296 }
1297
1298 static RefPtr<CSSValue> consumeTransitionProperty(CSSParserTokenRange& range)
1299 {
1300     const CSSParserToken& token = range.peek();
1301     if (token.type() != IdentToken)
1302         return nullptr;
1303     if (token.id() == CSSValueNone)
1304         return consumeIdent(range);
1305
1306     if (CSSPropertyID property = token.parseAsCSSPropertyID()) {
1307         range.consumeIncludingWhitespace();
1308         
1309         // FIXME-NEWPARSER: No reason why we can't use the "all" property now that it exists.
1310         // The old parser used a value keyword for "all", though, since it predated support for
1311         // the property.
1312         if (property == CSSPropertyAll)
1313             return CSSValuePool::singleton().createIdentifierValue(CSSValueAll);
1314
1315         // FIXME-NEWPARSER: Want to use a CSSCustomIdentValue here eventually.
1316         return CSSValuePool::singleton().createIdentifierValue(property);
1317     }
1318     return consumeCustomIdent(range);
1319 }
1320
1321     
1322 static RefPtr<CSSValue> consumeSteps(CSSParserTokenRange& range) {
1323     ASSERT(range.peek().functionId() == CSSValueSteps);
1324     CSSParserTokenRange rangeCopy = range;
1325     CSSParserTokenRange args = consumeFunction(rangeCopy);
1326     
1327     RefPtr<CSSPrimitiveValue> steps = consumePositiveInteger(args);
1328     if (!steps)
1329         return nullptr;
1330     
1331     // FIXME-NEWPARSER: Support the middle value and change from a boolean to an enum.
1332     bool stepAtStart = false;
1333     if (consumeCommaIncludingWhitespace(args)) {
1334         switch (args.consumeIncludingWhitespace().id()) {
1335             case CSSValueStart:
1336                 stepAtStart = true;
1337             break;
1338             case CSSValueEnd:
1339                 stepAtStart = false;
1340                 break;
1341             default:
1342                 return nullptr;
1343         }
1344     }
1345     
1346     if (!args.atEnd())
1347         return nullptr;
1348     
1349     range = rangeCopy;
1350     return CSSStepsTimingFunctionValue::create(steps->intValue(), stepAtStart);
1351 }
1352
1353 static RefPtr<CSSValue> consumeCubicBezier(CSSParserTokenRange& range)
1354 {
1355     ASSERT(range.peek().functionId() == CSSValueCubicBezier);
1356     CSSParserTokenRange rangeCopy = range;
1357     CSSParserTokenRange args = consumeFunction(rangeCopy);
1358
1359     double x1, y1, x2, y2;
1360     if (consumeNumberRaw(args, x1)
1361         && x1 >= 0 && x1 <= 1
1362         && consumeCommaIncludingWhitespace(args)
1363         && consumeNumberRaw(args, y1)
1364         && consumeCommaIncludingWhitespace(args)
1365         && consumeNumberRaw(args, x2)
1366         && x2 >= 0 && x2 <= 1
1367         && consumeCommaIncludingWhitespace(args)
1368         && consumeNumberRaw(args, y2)
1369         && args.atEnd()) {
1370         range = rangeCopy;
1371         return CSSCubicBezierTimingFunctionValue::create(x1, y1, x2, y2);
1372     }
1373
1374     return nullptr;
1375 }
1376
1377 static RefPtr<CSSValue> consumeSpringFunction(CSSParserTokenRange& range)
1378 {
1379     ASSERT(range.peek().functionId() == CSSValueSpring);
1380     CSSParserTokenRange rangeCopy = range;
1381     CSSParserTokenRange args = consumeFunction(rangeCopy);
1382
1383     // Mass must be greater than 0.
1384     double mass;
1385     if (!consumeNumberRaw(args, mass) || mass <= 0)
1386         return nullptr;
1387     
1388     // Stiffness must be greater than 0.
1389     double stiffness;
1390     if (!consumeNumberRaw(args, stiffness) || stiffness <= 0)
1391         return nullptr;
1392     
1393     // Damping coefficient must be greater than or equal to 0.
1394     double damping;
1395     if (!consumeNumberRaw(args, damping) || damping < 0)
1396         return nullptr;
1397     
1398     // Initial velocity may have any value.
1399     double initialVelocity;
1400     if (!consumeNumberRaw(args, initialVelocity))
1401         return nullptr;
1402
1403     if (!args.atEnd())
1404         return nullptr;
1405
1406     range = rangeCopy;
1407
1408     return CSSSpringTimingFunctionValue::create(mass, stiffness, damping, initialVelocity);
1409 }
1410
1411 static RefPtr<CSSValue> consumeAnimationTimingFunction(CSSParserTokenRange& range, const CSSParserContext& context)
1412 {
1413     CSSValueID id = range.peek().id();
1414     if (id == CSSValueEase || id == CSSValueLinear || id == CSSValueEaseIn
1415         || id == CSSValueEaseOut || id == CSSValueEaseInOut || id == CSSValueStepStart || id == CSSValueStepEnd)
1416         return consumeIdent(range);
1417
1418     CSSValueID function = range.peek().functionId();
1419     if (function == CSSValueCubicBezier)
1420         return consumeCubicBezier(range);
1421     if (function == CSSValueSteps)
1422         return consumeSteps(range);
1423     if (context.springTimingFunctionEnabled && function == CSSValueSpring)
1424         return consumeSpringFunction(range);
1425     return nullptr;
1426 }
1427
1428 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
1429 static RefPtr<CSSValue> consumeWebkitAnimationTrigger(CSSParserTokenRange& range, CSSParserMode mode)
1430 {
1431     if (range.peek().id() == CSSValueAuto)
1432         return consumeIdent(range);
1433     
1434     if (range.peek().functionId() != CSSValueContainerScroll)
1435         return nullptr;
1436     
1437     CSSParserTokenRange rangeCopy = range;
1438     CSSParserTokenRange args = consumeFunction(rangeCopy);
1439
1440     RefPtr<CSSPrimitiveValue> startValue = consumeLength(args, mode, ValueRangeAll, UnitlessQuirk::Forbid);
1441     if (!startValue)
1442         return nullptr;
1443     
1444     if (args.atEnd()) {
1445         range = rangeCopy;
1446         return CSSAnimationTriggerScrollValue::create(startValue.releaseNonNull());
1447     }
1448
1449     if (!consumeCommaIncludingWhitespace(args))
1450         return nullptr;
1451
1452     RefPtr<CSSPrimitiveValue> endValue = consumeLength(args, mode, ValueRangeAll, UnitlessQuirk::Forbid);
1453     if (!endValue || !args.atEnd())
1454         return nullptr;
1455
1456     range = rangeCopy;
1457
1458     return CSSAnimationTriggerScrollValue::create(startValue.releaseNonNull(), endValue.releaseNonNull());
1459 }
1460 #endif
1461     
1462 static RefPtr<CSSValue> consumeAnimationValue(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
1463 {
1464     switch (property) {
1465     case CSSPropertyAnimationDelay:
1466     case CSSPropertyTransitionDelay:
1467         return consumeTime(range, context.mode, ValueRangeAll, UnitlessQuirk::Forbid);
1468     case CSSPropertyAnimationDirection:
1469         return consumeIdent<CSSValueNormal, CSSValueAlternate, CSSValueReverse, CSSValueAlternateReverse>(range);
1470     case CSSPropertyAnimationDuration:
1471     case CSSPropertyTransitionDuration:
1472         return consumeTime(range, context.mode, ValueRangeNonNegative, UnitlessQuirk::Allow);
1473     case CSSPropertyAnimationFillMode:
1474         return consumeIdent<CSSValueNone, CSSValueForwards, CSSValueBackwards, CSSValueBoth>(range);
1475     case CSSPropertyAnimationIterationCount:
1476         return consumeAnimationIterationCount(range);
1477     case CSSPropertyAnimationName:
1478         return consumeAnimationName(range);
1479     case CSSPropertyAnimationPlayState:
1480         return consumeIdent<CSSValueRunning, CSSValuePaused>(range);
1481     case CSSPropertyTransitionProperty:
1482         return consumeTransitionProperty(range);
1483     case CSSPropertyAnimationTimingFunction:
1484     case CSSPropertyTransitionTimingFunction:
1485         return consumeAnimationTimingFunction(range, context);
1486 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
1487     case CSSPropertyWebkitAnimationTrigger:
1488         return consumeWebkitAnimationTrigger(range, context.mode);
1489 #endif
1490     default:
1491         ASSERT_NOT_REACHED();
1492         return nullptr;
1493     }
1494 }
1495
1496 static bool isValidAnimationPropertyList(CSSPropertyID property, const CSSValueList& valueList)
1497 {
1498     if (property != CSSPropertyTransitionProperty || valueList.length() < 2)
1499         return true;
1500     for (auto& value : valueList) {
1501         if (value->isPrimitiveValue() && downcast<CSSPrimitiveValue>(value.get()).isValueID()
1502             && downcast<CSSPrimitiveValue>(value.get()).valueID() == CSSValueNone)
1503             return false;
1504     }
1505     return true;
1506 }
1507
1508 static RefPtr<CSSValue> consumeAnimationPropertyList(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
1509 {
1510     RefPtr<CSSValueList> list;
1511     RefPtr<CSSValue> singleton;
1512     do {
1513         RefPtr<CSSValue> currentValue = consumeAnimationValue(property, range, context);
1514         if (!currentValue)
1515             return nullptr;
1516         
1517         if (singleton && !list) {
1518             list = CSSValueList::createCommaSeparated();
1519             list->append(singleton.releaseNonNull());
1520         }
1521         
1522         if (list)
1523             list->append(currentValue.releaseNonNull());
1524         else
1525             singleton = WTFMove(currentValue);
1526         
1527     } while (consumeCommaIncludingWhitespace(range));
1528
1529     if (list) {
1530         if (!isValidAnimationPropertyList(property, *list))
1531             return nullptr;
1532     
1533         ASSERT(list->length());
1534         return list;
1535     }
1536     
1537     return singleton;
1538 }
1539
1540 bool CSSPropertyParser::consumeAnimationShorthand(const StylePropertyShorthand& shorthand, bool important)
1541 {
1542     const unsigned longhandCount = shorthand.length();
1543     RefPtr<CSSValueList> longhands[8];
1544     ASSERT(longhandCount <= 8);
1545     for (size_t i = 0; i < longhandCount; ++i)
1546         longhands[i] = CSSValueList::createCommaSeparated();
1547
1548     do {
1549         bool parsedLonghand[8] = { false };
1550         do {
1551             bool foundProperty = false;
1552             for (size_t i = 0; i < longhandCount; ++i) {
1553                 if (parsedLonghand[i])
1554                     continue;
1555
1556                 if (RefPtr<CSSValue> value = consumeAnimationValue(shorthand.properties()[i], m_range, m_context)) {
1557                     parsedLonghand[i] = true;
1558                     foundProperty = true;
1559                     longhands[i]->append(*value);
1560                     break;
1561                 }
1562             }
1563             if (!foundProperty)
1564                 return false;
1565         } while (!m_range.atEnd() && m_range.peek().type() != CommaToken);
1566
1567         // FIXME: This will make invalid longhands, see crbug.com/386459
1568         for (size_t i = 0; i < longhandCount; ++i) {
1569             if (!parsedLonghand[i])
1570                 longhands[i]->append(CSSValuePool::singleton().createImplicitInitialValue());
1571             parsedLonghand[i] = false;
1572         }
1573     } while (consumeCommaIncludingWhitespace(m_range));
1574
1575     for (size_t i = 0; i < longhandCount; ++i) {
1576         if (!isValidAnimationPropertyList(shorthand.properties()[i], *longhands[i]))
1577             return false;
1578     }
1579
1580     for (size_t i = 0; i < longhandCount; ++i)
1581         addProperty(shorthand.properties()[i], shorthand.id(), *longhands[i], important);
1582
1583     return m_range.atEnd();
1584 }
1585
1586 static RefPtr<CSSValue> consumeZIndex(CSSParserTokenRange& range)
1587 {
1588     if (range.peek().id() == CSSValueAuto)
1589         return consumeIdent(range);
1590     return consumeInteger(range);
1591 }
1592
1593 static RefPtr<CSSValue> consumeShadow(CSSParserTokenRange& range, CSSParserMode cssParserMode, bool isBoxShadowProperty)
1594 {
1595     if (range.peek().id() == CSSValueNone)
1596         return consumeIdent(range);
1597
1598     RefPtr<CSSValueList> shadowValueList = CSSValueList::createCommaSeparated();
1599     do {
1600         if (RefPtr<CSSShadowValue> shadowValue = consumeSingleShadow(range, cssParserMode, isBoxShadowProperty, isBoxShadowProperty))
1601             shadowValueList->append(*shadowValue);
1602         else
1603             return nullptr;
1604     } while (consumeCommaIncludingWhitespace(range));
1605     return shadowValueList;
1606 }
1607
1608 static RefPtr<CSSValue> consumeTextDecorationLine(CSSParserTokenRange& range)
1609 {
1610     CSSValueID id = range.peek().id();
1611     if (id == CSSValueNone)
1612         return consumeIdent(range);
1613
1614     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1615     while (true) {
1616 #if ENABLE(LETTERPRESS)
1617         RefPtr<CSSPrimitiveValue> ident = consumeIdent<CSSValueBlink, CSSValueUnderline, CSSValueOverline, CSSValueLineThrough, CSSValueWebkitLetterpress>(range);
1618 #else
1619         RefPtr<CSSPrimitiveValue> ident = consumeIdent<CSSValueBlink, CSSValueUnderline, CSSValueOverline, CSSValueLineThrough>(range);
1620 #endif
1621         if (!ident)
1622             break;
1623         if (list->hasValue(ident.get()))
1624             return nullptr;
1625         list->append(ident.releaseNonNull());
1626     }
1627
1628     if (!list->length())
1629         return nullptr;
1630     return list;
1631 }
1632
1633 static RefPtr<CSSValue> consumeTextDecorationSkip(CSSParserTokenRange& range)
1634 {
1635     CSSValueID id = range.peek().id();
1636     if (id == CSSValueNone)
1637         return consumeIdent(range);
1638
1639     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1640     while (true) {
1641         auto ident = consumeIdent<CSSValueAuto, CSSValueInk, CSSValueObjects>(range);
1642         if (!ident)
1643             break;
1644         if (list->hasValue(ident.get()))
1645             return nullptr;
1646         list->append(ident.releaseNonNull());
1647     }
1648
1649     if (!list->length())
1650         return nullptr;
1651     return list;
1652 }
1653
1654 static RefPtr<CSSValue> consumeTextEmphasisStyle(CSSParserTokenRange& range)
1655 {
1656     CSSValueID id = range.peek().id();
1657     if (id == CSSValueNone)
1658         return consumeIdent(range);
1659
1660     if (RefPtr<CSSValue> textEmphasisStyle = consumeString(range))
1661         return textEmphasisStyle;
1662
1663     RefPtr<CSSPrimitiveValue> fill = consumeIdent<CSSValueFilled, CSSValueOpen>(range);
1664     RefPtr<CSSPrimitiveValue> shape = consumeIdent<CSSValueDot, CSSValueCircle, CSSValueDoubleCircle, CSSValueTriangle, CSSValueSesame>(range);
1665     if (!fill)
1666         fill = consumeIdent<CSSValueFilled, CSSValueOpen>(range);
1667     if (fill && shape) {
1668         RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
1669         parsedValues->append(fill.releaseNonNull());
1670         parsedValues->append(shape.releaseNonNull());
1671         return parsedValues;
1672     }
1673     if (fill)
1674         return fill;
1675     if (shape)
1676         return shape;
1677     return nullptr;
1678 }
1679
1680 static RefPtr<CSSValue> consumeOutlineColor(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1681 {
1682     // Allow the special focus color even in HTML Standard parsing mode.
1683     if (range.peek().id() == CSSValueWebkitFocusRingColor)
1684         return consumeIdent(range);
1685     return consumeColor(range, cssParserMode);
1686 }
1687
1688 static RefPtr<CSSPrimitiveValue> consumeLineWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
1689 {
1690     CSSValueID id = range.peek().id();
1691     if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
1692         return consumeIdent(range);
1693     return consumeLength(range, cssParserMode, ValueRangeNonNegative, unitless);
1694 }
1695
1696 static RefPtr<CSSPrimitiveValue> consumeBorderWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
1697 {
1698     return consumeLineWidth(range, cssParserMode, unitless);
1699 }
1700
1701 static RefPtr<CSSPrimitiveValue> consumeTextStrokeWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1702 {
1703     return consumeLineWidth(range, cssParserMode, UnitlessQuirk::Forbid);
1704 }
1705
1706 static RefPtr<CSSPrimitiveValue> consumeColumnRuleWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1707 {
1708     return consumeLineWidth(range, cssParserMode, UnitlessQuirk::Forbid);
1709 }
1710
1711 static bool consumeTranslate3d(CSSParserTokenRange& args, CSSParserMode cssParserMode, RefPtr<WebKitCSSTransformValue>& transformValue)
1712 {
1713     unsigned numberOfArguments = 2;
1714     RefPtr<CSSValue> parsedValue;
1715     do {
1716         parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll);
1717         if (!parsedValue)
1718             return false;
1719         transformValue->append(*parsedValue);
1720         if (!consumeCommaIncludingWhitespace(args))
1721             return false;
1722     } while (--numberOfArguments);
1723     parsedValue = consumeLength(args, cssParserMode, ValueRangeAll);
1724     if (!parsedValue)
1725         return false;
1726     transformValue->append(*parsedValue);
1727     return true;
1728 }
1729
1730 static bool consumeNumbers(CSSParserTokenRange& args, RefPtr<WebKitCSSTransformValue>& transformValue, unsigned numberOfArguments)
1731 {
1732     do {
1733         RefPtr<CSSPrimitiveValue> parsedValue = consumeNumber(args, ValueRangeAll);
1734         if (!parsedValue)
1735             return false;
1736         transformValue->append(parsedValue.releaseNonNull());
1737         if (--numberOfArguments && !consumeCommaIncludingWhitespace(args))
1738             return false;
1739     } while (numberOfArguments);
1740     return true;
1741 }
1742
1743 static bool consumePerspective(CSSParserTokenRange& args, CSSParserMode cssParserMode, RefPtr<WebKitCSSTransformValue>& transformValue)
1744 {
1745     RefPtr<CSSPrimitiveValue> parsedValue = consumeLength(args, cssParserMode, ValueRangeNonNegative);
1746     if (!parsedValue) {
1747         double perspective;
1748         if (!consumeNumberRaw(args, perspective) || perspective < 0)
1749             return false;
1750         parsedValue = CSSPrimitiveValue::create(perspective, CSSPrimitiveValue::UnitTypes::CSS_PX);
1751     }
1752     if (!parsedValue)
1753         return false;
1754     transformValue->append(parsedValue.releaseNonNull());
1755     return true;
1756 }
1757
1758 // FIXME-NEWPARSER: This has no reason to exist once we eliminate WebkitCSSTransformValue in favor
1759 // of CSSFunctionValue.
1760 static WebKitCSSTransformValue::TransformOperationType transformOperationForCSSValueID(CSSValueID functionId)
1761 {
1762     switch (functionId) {
1763     case CSSValueRotate:
1764         return WebKitCSSTransformValue::RotateTransformOperation;
1765     case CSSValueRotatex:
1766         return WebKitCSSTransformValue::RotateXTransformOperation;
1767     case CSSValueRotatey:
1768         return WebKitCSSTransformValue::RotateYTransformOperation;
1769     case CSSValueRotatez:
1770         return WebKitCSSTransformValue::RotateZTransformOperation;
1771     case CSSValueSkewx:
1772         return WebKitCSSTransformValue::SkewXTransformOperation;
1773     case CSSValueSkewy:
1774         return WebKitCSSTransformValue::SkewYTransformOperation;
1775     case CSSValueSkew:
1776         return WebKitCSSTransformValue::SkewTransformOperation;
1777     case CSSValueScalex:
1778         return WebKitCSSTransformValue::ScaleXTransformOperation;
1779     case CSSValueScaley:
1780         return WebKitCSSTransformValue::ScaleYTransformOperation;
1781     case CSSValueScalez:
1782         return WebKitCSSTransformValue::ScaleZTransformOperation;
1783     case CSSValueScale:
1784         return WebKitCSSTransformValue::ScaleTransformOperation;
1785     case CSSValuePerspective:
1786         return WebKitCSSTransformValue::PerspectiveTransformOperation;
1787     case CSSValueTranslatex:
1788         return WebKitCSSTransformValue::TranslateXTransformOperation;
1789     case CSSValueTranslatey:
1790         return WebKitCSSTransformValue::TranslateYTransformOperation;
1791     case CSSValueTranslate:
1792         return WebKitCSSTransformValue::TranslateTransformOperation;
1793     case CSSValueTranslatez:
1794         return WebKitCSSTransformValue::TranslateZTransformOperation;
1795     case CSSValueMatrix:
1796         return WebKitCSSTransformValue::MatrixTransformOperation;
1797     case CSSValueMatrix3d:
1798         return WebKitCSSTransformValue::Matrix3DTransformOperation;
1799     case CSSValueScale3d:
1800         return WebKitCSSTransformValue::Scale3DTransformOperation;
1801     case CSSValueRotate3d:
1802         return WebKitCSSTransformValue::Rotate3DTransformOperation;
1803     case CSSValueTranslate3d:
1804         return WebKitCSSTransformValue::Translate3DTransformOperation;
1805     default:
1806         return WebKitCSSTransformValue::UnknownTransformOperation;
1807     }
1808 }
1809
1810 static RefPtr<CSSValue> consumeTransformValue(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1811 {
1812     CSSValueID functionId = range.peek().functionId();
1813     if (functionId == CSSValueInvalid)
1814         return nullptr;
1815     CSSParserTokenRange args = consumeFunction(range);
1816     if (args.atEnd())
1817         return nullptr;
1818     
1819     // FIXME-NEWPARSER: Do we really need WebkitCSSTransformValue? A CSSFunctionValue is good
1820     // enough and has the CSSValueID as the operation type. Blink has eliminated it.
1821     RefPtr<WebKitCSSTransformValue> transformValue = WebKitCSSTransformValue::create(transformOperationForCSSValueID(functionId));
1822     RefPtr<CSSValue> parsedValue;
1823     switch (functionId) {
1824     case CSSValueRotate:
1825     case CSSValueRotatex:
1826     case CSSValueRotatey:
1827     case CSSValueRotatez:
1828     case CSSValueSkewx:
1829     case CSSValueSkewy:
1830     case CSSValueSkew:
1831         parsedValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid);
1832         if (!parsedValue)
1833             return nullptr;
1834         if (functionId == CSSValueSkew && consumeCommaIncludingWhitespace(args)) {
1835             transformValue->append(*parsedValue);
1836             parsedValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid);
1837             if (!parsedValue)
1838                 return nullptr;
1839         }
1840         break;
1841     case CSSValueScalex:
1842     case CSSValueScaley:
1843     case CSSValueScalez:
1844     case CSSValueScale:
1845         parsedValue = consumeNumber(args, ValueRangeAll);
1846         if (!parsedValue)
1847             return nullptr;
1848         if (functionId == CSSValueScale && consumeCommaIncludingWhitespace(args)) {
1849             transformValue->append(*parsedValue);
1850             parsedValue = consumeNumber(args, ValueRangeAll);
1851             if (!parsedValue)
1852                 return nullptr;
1853         }
1854         break;
1855     case CSSValuePerspective:
1856         if (!consumePerspective(args, cssParserMode, transformValue))
1857             return nullptr;
1858         break;
1859     case CSSValueTranslatex:
1860     case CSSValueTranslatey:
1861     case CSSValueTranslate:
1862         parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll);
1863         if (!parsedValue)
1864             return nullptr;
1865         if (functionId == CSSValueTranslate && consumeCommaIncludingWhitespace(args)) {
1866             transformValue->append(*parsedValue);
1867             parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll);
1868             if (!parsedValue)
1869                 return nullptr;
1870         }
1871         break;
1872     case CSSValueTranslatez:
1873         parsedValue = consumeLength(args, cssParserMode, ValueRangeAll);
1874         break;
1875     case CSSValueMatrix:
1876     case CSSValueMatrix3d:
1877         if (!consumeNumbers(args, transformValue, (functionId == CSSValueMatrix3d) ? 16 : 6))
1878             return nullptr;
1879         break;
1880     case CSSValueScale3d:
1881         if (!consumeNumbers(args, transformValue, 3))
1882             return nullptr;
1883         break;
1884     case CSSValueRotate3d:
1885         if (!consumeNumbers(args, transformValue, 3) || !consumeCommaIncludingWhitespace(args))
1886             return nullptr;
1887         parsedValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid);
1888         if (!parsedValue)
1889             return nullptr;
1890         break;
1891     case CSSValueTranslate3d:
1892         if (!consumeTranslate3d(args, cssParserMode, transformValue))
1893             return nullptr;
1894         break;
1895     default:
1896         return nullptr;
1897     }
1898     if (parsedValue)
1899         transformValue->append(*parsedValue);
1900     if (!args.atEnd())
1901         return nullptr;
1902     return transformValue;
1903 }
1904
1905 static RefPtr<CSSValue> consumeTransform(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1906 {
1907     if (range.peek().id() == CSSValueNone)
1908         return consumeIdent(range);
1909
1910     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1911     do {
1912         RefPtr<CSSValue> parsedTransformValue = consumeTransformValue(range, cssParserMode);
1913         if (!parsedTransformValue)
1914             return nullptr;
1915         list->append(parsedTransformValue.releaseNonNull());
1916     } while (!range.atEnd());
1917
1918     return list;
1919 }
1920
1921 template <CSSValueID start, CSSValueID end>
1922 static RefPtr<CSSPrimitiveValue> consumePositionLonghand(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1923 {
1924     if (range.peek().type() == IdentToken) {
1925         CSSValueID id = range.peek().id();
1926         int percent;
1927         if (id == start)
1928             percent = 0;
1929         else if (id == CSSValueCenter)
1930             percent = 50;
1931         else if (id == end)
1932             percent = 100;
1933         else
1934             return nullptr;
1935         range.consumeIncludingWhitespace();
1936         return CSSPrimitiveValue::create(percent, CSSPrimitiveValue::UnitTypes::CSS_PERCENTAGE);
1937     }
1938     return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll);
1939 }
1940
1941 static RefPtr<CSSPrimitiveValue> consumePositionX(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1942 {
1943     return consumePositionLonghand<CSSValueLeft, CSSValueRight>(range, cssParserMode);
1944 }
1945
1946 static RefPtr<CSSPrimitiveValue> consumePositionY(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1947 {
1948     return consumePositionLonghand<CSSValueTop, CSSValueBottom>(range, cssParserMode);
1949 }
1950
1951 static RefPtr<CSSValue> consumePaintStroke(CSSParserTokenRange& range, CSSParserMode cssParserMode)
1952 {
1953     if (range.peek().id() == CSSValueNone)
1954         return consumeIdent(range);
1955     RefPtr<CSSPrimitiveValue> url = consumeUrl(range);
1956     if (url) {
1957         RefPtr<CSSValue> parsedValue;
1958         if (range.peek().id() == CSSValueNone)
1959             parsedValue = consumeIdent(range);
1960         else
1961             parsedValue = consumeColor(range, cssParserMode);
1962         if (parsedValue) {
1963             RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
1964             values->append(url.releaseNonNull());
1965             values->append(parsedValue.releaseNonNull());
1966             return values;
1967         }
1968         return url;
1969     }
1970     return consumeColor(range, cssParserMode);
1971 }
1972
1973 static RefPtr<CSSValue> consumePaintOrder(CSSParserTokenRange& range)
1974 {
1975     if (range.peek().id() == CSSValueNormal)
1976         return consumeIdent(range);
1977
1978     Vector<CSSValueID, 3> paintTypeList;
1979     RefPtr<CSSPrimitiveValue> fill;
1980     RefPtr<CSSPrimitiveValue> stroke;
1981     RefPtr<CSSPrimitiveValue> markers;
1982     do {
1983         CSSValueID id = range.peek().id();
1984         if (id == CSSValueFill && !fill)
1985             fill = consumeIdent(range);
1986         else if (id == CSSValueStroke && !stroke)
1987             stroke = consumeIdent(range);
1988         else if (id == CSSValueMarkers && !markers)
1989             markers = consumeIdent(range);
1990         else
1991             return nullptr;
1992         paintTypeList.append(id);
1993     } while (!range.atEnd());
1994
1995     // After parsing we serialize the paint-order list. Since it is not possible to
1996     // pop a last list items from CSSValueList without bigger cost, we create the
1997     // list after parsing.
1998     CSSValueID firstPaintOrderType = paintTypeList.at(0);
1999     RefPtr<CSSValueList> paintOrderList = CSSValueList::createSpaceSeparated();
2000     switch (firstPaintOrderType) {
2001     case CSSValueFill:
2002     case CSSValueStroke:
2003         paintOrderList->append(firstPaintOrderType == CSSValueFill ? fill.releaseNonNull() : stroke.releaseNonNull());
2004         if (paintTypeList.size() > 1) {
2005             if (paintTypeList.at(1) == CSSValueMarkers)
2006                 paintOrderList->append(markers.releaseNonNull());
2007         }
2008         break;
2009     case CSSValueMarkers:
2010         paintOrderList->append(markers.releaseNonNull());
2011         if (paintTypeList.size() > 1) {
2012             if (paintTypeList.at(1) == CSSValueStroke)
2013                 paintOrderList->append(stroke.releaseNonNull());
2014         }
2015         break;
2016     default:
2017         ASSERT_NOT_REACHED();
2018     }
2019
2020     return paintOrderList;
2021 }
2022
2023 static RefPtr<CSSValue> consumeNoneOrURI(CSSParserTokenRange& range)
2024 {
2025     if (range.peek().id() == CSSValueNone)
2026         return consumeIdent(range);
2027     return consumeUrl(range);
2028 }
2029
2030 static RefPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2031 {
2032     // FIXME: Support intrinsic dimensions too.
2033     if (range.peek().id() == CSSValueAuto)
2034         return consumeIdent(range);
2035     return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2036 }
2037
2038 static RefPtr<CSSValue> consumeKerning(CSSParserTokenRange& range, CSSParserMode mode)
2039 {
2040     RefPtr<CSSValue> result = consumeIdent<CSSValueAuto, CSSValueNormal>(range);
2041     if (result)
2042         return result;
2043     return consumeLength(range, mode, ValueRangeAll, UnitlessQuirk::Allow);
2044 }
2045
2046 static RefPtr<CSSValue> consumeStrokeDasharray(CSSParserTokenRange& range)
2047 {
2048     CSSValueID id = range.peek().id();
2049     if (id == CSSValueNone)
2050         return consumeIdent(range);
2051
2052     RefPtr<CSSValueList> dashes = CSSValueList::createCommaSeparated();
2053     do {
2054         RefPtr<CSSPrimitiveValue> dash = consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeNonNegative);
2055         if (!dash || (consumeCommaIncludingWhitespace(range) && range.atEnd()))
2056             return nullptr;
2057         dashes->append(dash.releaseNonNull());
2058     } while (!range.atEnd());
2059     return dashes;
2060 }
2061
2062 static RefPtr<CSSPrimitiveValue> consumeBaselineShift(CSSParserTokenRange& range)
2063 {
2064     CSSValueID id = range.peek().id();
2065     if (id == CSSValueBaseline || id == CSSValueSub || id == CSSValueSuper)
2066         return consumeIdent(range);
2067     return consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeAll);
2068 }
2069
2070 static RefPtr<CSSPrimitiveValue> consumeRxOrRy(CSSParserTokenRange& range)
2071 {
2072     // FIXME-NEWPARSER: We don't support auto values when mapping, so for now turn this
2073     // off until we can figure out if we're even supposed to support it.
2074     // if (range.peek().id() == CSSValueAuto)
2075     //     return consumeIdent(range);
2076     return consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeAll, UnitlessQuirk::Forbid);
2077 }
2078
2079 static RefPtr<CSSValue> consumeCursor(CSSParserTokenRange& range, const CSSParserContext& context, bool inQuirksMode)
2080 {
2081     RefPtr<CSSValueList> list;
2082     while (RefPtr<CSSValue> image = consumeImage(range, context, ConsumeGeneratedImage::Forbid)) {
2083         double num;
2084         IntPoint hotSpot(-1, -1);
2085         bool hotSpotSpecified = false;
2086         if (consumeNumberRaw(range, num)) {
2087             hotSpot.setX(int(num));
2088             if (!consumeNumberRaw(range, num))
2089                 return nullptr;
2090             hotSpot.setY(int(num));
2091             hotSpotSpecified = true;
2092         }
2093
2094         if (!list)
2095             list = CSSValueList::createCommaSeparated();
2096
2097         list->append(CSSCursorImageValue::create(image.releaseNonNull(), hotSpotSpecified, hotSpot));
2098         if (!consumeCommaIncludingWhitespace(range))
2099             return nullptr;
2100     }
2101
2102     CSSValueID id = range.peek().id();
2103     RefPtr<CSSValue> cursorType;
2104     if (id == CSSValueHand) {
2105         if (!inQuirksMode) // Non-standard behavior
2106             return nullptr;
2107         cursorType = CSSValuePool::singleton().createIdentifierValue(CSSValuePointer);
2108         range.consumeIncludingWhitespace();
2109     } else if ((id >= CSSValueAuto && id <= CSSValueWebkitZoomOut) || id == CSSValueCopy || id == CSSValueNone) {
2110         cursorType = consumeIdent(range);
2111     } else {
2112         return nullptr;
2113     }
2114
2115     if (!list)
2116         return cursorType;
2117     list->append(cursorType.releaseNonNull());
2118     return list;
2119 }
2120
2121 static RefPtr<CSSValue> consumeAttr(CSSParserTokenRange args, CSSParserContext context)
2122 {
2123     if (args.peek().type() != IdentToken)
2124         return nullptr;
2125     
2126     CSSParserToken token = args.consumeIncludingWhitespace();
2127     auto attrName = token.value().toAtomicString();
2128     if (context.isHTMLDocument)
2129         attrName = attrName.convertToASCIILowercase();
2130
2131     if (!args.atEnd())
2132         return nullptr;
2133
2134     // FIXME-NEWPARSER: We want to use a CSSCustomIdentValue here eventually for the attrName.
2135     // FIXME-NEWPARSER: We want to use a CSSFunctionValue rather than relying on a custom
2136     // attr() primitive value.
2137     return CSSValuePool::singleton().createValue(attrName, CSSPrimitiveValue::CSS_ATTR);
2138 }
2139
2140 static RefPtr<CSSValue> consumeCounterContent(CSSParserTokenRange args, bool counters)
2141 {
2142     RefPtr<CSSPrimitiveValue> identifier = consumeCustomIdent(args);
2143     if (!identifier)
2144         return nullptr;
2145
2146     RefPtr<CSSPrimitiveValue> separator;
2147     if (!counters)
2148         separator = CSSPrimitiveValue::create(String(), CSSPrimitiveValue::UnitTypes::CSS_STRING);
2149     else {
2150         if (!consumeCommaIncludingWhitespace(args) || args.peek().type() != StringToken)
2151             return nullptr;
2152         separator = CSSPrimitiveValue::create(args.consumeIncludingWhitespace().value().toString(), CSSPrimitiveValue::UnitTypes::CSS_STRING);
2153     }
2154
2155     RefPtr<CSSPrimitiveValue> listStyle;
2156     if (consumeCommaIncludingWhitespace(args)) {
2157         CSSValueID id = args.peek().id();
2158         if ((id != CSSValueNone && (id < CSSValueDisc || id > CSSValueKatakanaIroha)))
2159             return nullptr;
2160         listStyle = consumeIdent(args);
2161     } else
2162         listStyle = CSSValuePool::singleton().createIdentifierValue(CSSValueDecimal);
2163
2164     if (!args.atEnd())
2165         return nullptr;
2166     
2167     // FIXME-NEWPARSER: Should just have a CSSCounterValue.
2168     return CSSValuePool::singleton().createValue(Counter::create(identifier.releaseNonNull(), listStyle.releaseNonNull(), separator.releaseNonNull()));
2169 }
2170
2171 static RefPtr<CSSValue> consumeContent(CSSParserTokenRange& range, CSSParserContext context)
2172 {
2173     if (identMatches<CSSValueNone, CSSValueNormal>(range.peek().id()))
2174         return consumeIdent(range);
2175
2176     RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
2177
2178     do {
2179         RefPtr<CSSValue> parsedValue = consumeImage(range, context);
2180         if (!parsedValue)
2181             parsedValue = consumeIdent<CSSValueOpenQuote, CSSValueCloseQuote, CSSValueNoOpenQuote, CSSValueNoCloseQuote>(range);
2182         if (!parsedValue)
2183             parsedValue = consumeString(range);
2184         if (!parsedValue) {
2185             if (range.peek().functionId() == CSSValueAttr)
2186                 parsedValue = consumeAttr(consumeFunction(range), context);
2187             else if (range.peek().functionId() == CSSValueCounter)
2188                 parsedValue = consumeCounterContent(consumeFunction(range), false);
2189             else if (range.peek().functionId() == CSSValueCounters)
2190                 parsedValue = consumeCounterContent(consumeFunction(range), true);
2191             if (!parsedValue)
2192                 return nullptr;
2193         }
2194         values->append(parsedValue.releaseNonNull());
2195     } while (!range.atEnd());
2196
2197     return values;
2198 }
2199
2200 static RefPtr<CSSPrimitiveValue> consumePerspective(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2201 {
2202     if (range.peek().id() == CSSValueNone)
2203         return consumeIdent(range);
2204     RefPtr<CSSPrimitiveValue> parsedValue = consumeLength(range, cssParserMode, ValueRangeAll);
2205     if (!parsedValue) {
2206         // FIXME: Make this quirk only apply to the webkit prefixed version of the property.
2207         double perspective;
2208         if (!consumeNumberRaw(range, perspective))
2209             return nullptr;
2210         parsedValue = CSSPrimitiveValue::create(perspective, CSSPrimitiveValue::UnitTypes::CSS_PX);
2211     }
2212     if (parsedValue && (parsedValue->isCalculated() || parsedValue->doubleValue() > 0))
2213         return parsedValue;
2214     return nullptr;
2215 }
2216
2217 #if ENABLE(CSS_SCROLL_SNAP)
2218
2219 static RefPtr<CSSValueList> consumeSnapPointCoordinateList(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2220 {
2221     RefPtr<CSSValueList> positions = CSSValueList::createSpaceSeparated();
2222     do {
2223         
2224         RefPtr<CSSPrimitiveValue> first = consumePositionX(range, cssParserMode);
2225         if (!first || range.atEnd())
2226             return nullptr;
2227         RefPtr<CSSPrimitiveValue> second = consumePositionY(range, cssParserMode);
2228         if (!second)
2229             return nullptr;
2230         RefPtr<CSSValue> position = createPrimitiveValuePair(first.releaseNonNull(), second.releaseNonNull(), Pair::IdenticalValueEncoding::DoNotCoalesce);
2231         positions->append(position.releaseNonNull());
2232     } while (!range.atEnd());
2233     return positions;
2234 }
2235
2236 static RefPtr<CSSValue> consumeScrollSnapCoordinate(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2237 {
2238     if (range.peek().id() == CSSValueNone)
2239         return consumeIdent(range);
2240     return consumeSnapPointCoordinateList(range, cssParserMode);
2241 }
2242
2243 static RefPtr<CSSValue> consumeScrollSnapDestination(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2244 {
2245     RefPtr<CSSPrimitiveValue> first = consumePositionX(range, cssParserMode);
2246     if (!first || range.atEnd())
2247         return nullptr;
2248     RefPtr<CSSPrimitiveValue> second = consumePositionY(range, cssParserMode);
2249     if (!second)
2250         return nullptr;
2251     return createPrimitiveValuePair(first.releaseNonNull(), second.releaseNonNull(), Pair::IdenticalValueEncoding::DoNotCoalesce);
2252 }
2253
2254 static RefPtr<CSSValue> consumeScrollSnapPoints(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2255 {
2256     if (range.peek().id() == CSSValueNone || range.peek().id() == CSSValueElements)
2257         return consumeIdent(range);
2258     
2259     RefPtr<CSSValueList> points = CSSValueList::createSpaceSeparated();
2260     do {
2261         if (range.peek().functionId() == CSSValueRepeat) {
2262             CSSParserTokenRange args = consumeFunction(range);
2263             RefPtr<CSSPrimitiveValue> parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative);
2264             if (args.atEnd() && parsedValue && (parsedValue->isCalculated() || parsedValue->doubleValue() > 0)) {
2265                 Ref<CSSFunctionValue> result = CSSFunctionValue::create(CSSValueRepeat);
2266                 result->append(parsedValue.releaseNonNull());
2267                 points->append(WTFMove(result));
2268             }
2269         } else {
2270             RefPtr<CSSValue> length = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Forbid);
2271             if (!length)
2272                 return nullptr;
2273             points->append(length.releaseNonNull());
2274         }
2275     } while (!range.atEnd());
2276     
2277     
2278     return points;
2279 }
2280
2281 #endif
2282
2283 static RefPtr<CSSValue> consumeBorderRadiusCorner(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2284 {
2285     RefPtr<CSSPrimitiveValue> parsedValue1 = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2286     if (!parsedValue1)
2287         return nullptr;
2288     RefPtr<CSSPrimitiveValue> parsedValue2 = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2289     if (!parsedValue2)
2290         parsedValue2 = parsedValue1;
2291     return createPrimitiveValuePair(parsedValue1.releaseNonNull(), parsedValue2.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
2292 }
2293
2294 static RefPtr<CSSPrimitiveValue> consumeVerticalAlign(CSSParserTokenRange& range, CSSParserMode cssParserMode)
2295 {
2296     RefPtr<CSSPrimitiveValue> parsedValue = consumeIdentRange(range, CSSValueBaseline, CSSValueWebkitBaselineMiddle);
2297     if (!parsedValue)
2298         parsedValue = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
2299     return parsedValue;
2300 }
2301
2302 static RefPtr<CSSPrimitiveValue> consumeShapeRadius(CSSParserTokenRange& args, CSSParserMode cssParserMode)
2303 {
2304     if (identMatches<CSSValueClosestSide, CSSValueFarthestSide>(args.peek().id()))
2305         return consumeIdent(args);
2306     return consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative);
2307 }
2308
2309 static RefPtr<CSSBasicShapeCircle> consumeBasicShapeCircle(CSSParserTokenRange& args, const CSSParserContext& context)
2310 {
2311     // spec: https://drafts.csswg.org/css-shapes/#supported-basic-shapes
2312     // circle( [<shape-radius>]? [at <position>]? )
2313     RefPtr<CSSBasicShapeCircle> shape = CSSBasicShapeCircle::create();
2314     if (RefPtr<CSSPrimitiveValue> radius = consumeShapeRadius(args, context.mode))
2315         shape->setRadius(radius.releaseNonNull());
2316     if (consumeIdent<CSSValueAt>(args)) {
2317         RefPtr<CSSPrimitiveValue> centerX;
2318         RefPtr<CSSPrimitiveValue> centerY;
2319         if (!consumePosition(args, context.mode, UnitlessQuirk::Forbid, centerX, centerY))
2320             return nullptr;
2321         shape->setCenterX(centerX.releaseNonNull());
2322         shape->setCenterY(centerY.releaseNonNull());
2323     }
2324     return shape;
2325 }
2326
2327 static RefPtr<CSSBasicShapeEllipse> consumeBasicShapeEllipse(CSSParserTokenRange& args, const CSSParserContext& context)
2328 {
2329     // spec: https://drafts.csswg.org/css-shapes/#supported-basic-shapes
2330     // ellipse( [<shape-radius>{2}]? [at <position>]? )
2331     RefPtr<CSSBasicShapeEllipse> shape = CSSBasicShapeEllipse::create();
2332     if (RefPtr<CSSPrimitiveValue> radiusX = consumeShapeRadius(args, context.mode)) {
2333         shape->setRadiusX(radiusX.releaseNonNull());
2334         if (RefPtr<CSSPrimitiveValue> radiusY = consumeShapeRadius(args, context.mode))
2335             shape->setRadiusY(radiusY.releaseNonNull());
2336     }
2337     if (consumeIdent<CSSValueAt>(args)) {
2338         RefPtr<CSSPrimitiveValue> centerX;
2339         RefPtr<CSSPrimitiveValue> centerY;
2340         if (!consumePosition(args, context.mode, UnitlessQuirk::Forbid, centerX, centerY))
2341             return nullptr;
2342         shape->setCenterX(centerX.releaseNonNull());
2343         shape->setCenterY(centerY.releaseNonNull());
2344     }
2345     return shape;
2346 }
2347
2348 static RefPtr<CSSBasicShapePolygon> consumeBasicShapePolygon(CSSParserTokenRange& args, const CSSParserContext& context)
2349 {
2350     RefPtr<CSSBasicShapePolygon> shape = CSSBasicShapePolygon::create();
2351     if (identMatches<CSSValueEvenodd, CSSValueNonzero>(args.peek().id())) {
2352         shape->setWindRule(args.consumeIncludingWhitespace().id() == CSSValueEvenodd ? RULE_EVENODD : RULE_NONZERO);
2353         if (!consumeCommaIncludingWhitespace(args))
2354             return nullptr;
2355     }
2356
2357     do {
2358         RefPtr<CSSPrimitiveValue> xLength = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2359         if (!xLength)
2360             return nullptr;
2361         RefPtr<CSSPrimitiveValue> yLength = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2362         if (!yLength)
2363             return nullptr;
2364         shape->appendPoint(xLength.releaseNonNull(), yLength.releaseNonNull());
2365     } while (consumeCommaIncludingWhitespace(args));
2366     return shape;
2367 }
2368
2369 static RefPtr<CSSBasicShapePath> consumeBasicShapePath(CSSParserTokenRange& args)
2370 {
2371     WindRule windRule = RULE_NONZERO;
2372     if (identMatches<CSSValueEvenodd, CSSValueNonzero>(args.peek().id())) {
2373         windRule = args.consumeIncludingWhitespace().id() == CSSValueEvenodd ? RULE_EVENODD : RULE_NONZERO;
2374         if (!consumeCommaIncludingWhitespace(args))
2375             return nullptr;
2376     }
2377
2378     if (args.peek().type() != StringToken)
2379         return nullptr;
2380     
2381     auto byteStream = std::make_unique<SVGPathByteStream>();
2382     if (!buildSVGPathByteStreamFromString(args.consumeIncludingWhitespace().value().toString(), *byteStream, UnalteredParsing))
2383         return nullptr;
2384     
2385     auto shape = CSSBasicShapePath::create(WTFMove(byteStream));
2386     shape->setWindRule(windRule);
2387     
2388     return WTFMove(shape);
2389 }
2390
2391 static void complete4Sides(RefPtr<CSSPrimitiveValue> side[4])
2392 {
2393     if (side[3])
2394         return;
2395     if (!side[2]) {
2396         if (!side[1])
2397             side[1] = side[0];
2398         side[2] = side[0];
2399     }
2400     side[3] = side[1];
2401 }
2402
2403 static bool consumeRadii(RefPtr<CSSPrimitiveValue> horizontalRadii[4], RefPtr<CSSPrimitiveValue> verticalRadii[4], CSSParserTokenRange& range, CSSParserMode cssParserMode, bool useLegacyParsing)
2404 {
2405     unsigned i = 0;
2406     for (; i < 4 && !range.atEnd() && range.peek().type() != DelimiterToken; ++i) {
2407         horizontalRadii[i] = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2408         if (!horizontalRadii[i])
2409             return false;
2410     }
2411     if (!horizontalRadii[0])
2412         return false;
2413     if (range.atEnd()) {
2414         // Legacy syntax: -webkit-border-radius: l1 l2; is equivalent to border-radius: l1 / l2;
2415         if (useLegacyParsing && i == 2) {
2416             verticalRadii[0] = horizontalRadii[1];
2417             horizontalRadii[1] = nullptr;
2418         } else {
2419             complete4Sides(horizontalRadii);
2420             for (unsigned i = 0; i < 4; ++i)
2421                 verticalRadii[i] = horizontalRadii[i];
2422             return true;
2423         }
2424     } else {
2425         if (!consumeSlashIncludingWhitespace(range))
2426             return false;
2427         for (i = 0; i < 4 && !range.atEnd(); ++i) {
2428             verticalRadii[i] = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
2429             if (!verticalRadii[i])
2430                 return false;
2431         }
2432         if (!verticalRadii[0] || !range.atEnd())
2433             return false;
2434     }
2435     complete4Sides(horizontalRadii);
2436     complete4Sides(verticalRadii);
2437     return true;
2438 }
2439
2440 static RefPtr<CSSBasicShapeInset> consumeBasicShapeInset(CSSParserTokenRange& args, const CSSParserContext& context)
2441 {
2442     RefPtr<CSSBasicShapeInset> shape = CSSBasicShapeInset::create();
2443     RefPtr<CSSPrimitiveValue> top = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2444     if (!top)
2445         return nullptr;
2446     RefPtr<CSSPrimitiveValue> right = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2447     RefPtr<CSSPrimitiveValue> bottom;
2448     RefPtr<CSSPrimitiveValue> left;
2449     if (right) {
2450         bottom = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2451         if (bottom)
2452             left = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
2453     }
2454     if (left)
2455         shape->updateShapeSize4Values(top.releaseNonNull(), right.releaseNonNull(), bottom.releaseNonNull(), left.releaseNonNull());
2456     else if (bottom)
2457         shape->updateShapeSize3Values(top.releaseNonNull(), right.releaseNonNull(), bottom.releaseNonNull());
2458     else if (right)
2459         shape->updateShapeSize2Values(top.releaseNonNull(), right.releaseNonNull());
2460     else
2461         shape->updateShapeSize1Value(top.releaseNonNull());
2462
2463     if (consumeIdent<CSSValueRound>(args)) {
2464         RefPtr<CSSPrimitiveValue> horizontalRadii[4] = { 0 };
2465         RefPtr<CSSPrimitiveValue> verticalRadii[4] = { 0 };
2466         if (!consumeRadii(horizontalRadii, verticalRadii, args, context.mode, false))
2467             return nullptr;
2468         shape->setTopLeftRadius(createPrimitiveValuePair(horizontalRadii[0].releaseNonNull(), verticalRadii[0].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
2469         shape->setTopRightRadius(createPrimitiveValuePair(horizontalRadii[1].releaseNonNull(), verticalRadii[1].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
2470         shape->setBottomRightRadius(createPrimitiveValuePair(horizontalRadii[2].releaseNonNull(), verticalRadii[2].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
2471         shape->setBottomLeftRadius(createPrimitiveValuePair(horizontalRadii[3].releaseNonNull(), verticalRadii[3].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
2472     }
2473     return shape;
2474 }
2475
2476 static RefPtr<CSSValue> consumeBasicShape(CSSParserTokenRange& range, const CSSParserContext& context)
2477 {
2478     RefPtr<CSSValue> result;
2479     if (range.peek().type() != FunctionToken)
2480         return nullptr;
2481     CSSValueID id = range.peek().functionId();
2482     CSSParserTokenRange rangeCopy = range;
2483     CSSParserTokenRange args = consumeFunction(rangeCopy);
2484     
2485     // FIXME-NEWPARSER: CSSBasicShape should be a CSSValue, and shapes should not be primitive values.
2486     RefPtr<CSSBasicShape> shape;
2487     if (id == CSSValueCircle)
2488         shape = consumeBasicShapeCircle(args, context);
2489     else if (id == CSSValueEllipse)
2490         shape = consumeBasicShapeEllipse(args, context);
2491     else if (id == CSSValuePolygon)
2492         shape = consumeBasicShapePolygon(args, context);
2493     else if (id == CSSValueInset)
2494         shape = consumeBasicShapeInset(args, context);
2495     else if (id == CSSValuePath)
2496         shape = consumeBasicShapePath(args);
2497     if (!shape)
2498         return nullptr;
2499     range = rangeCopy;
2500     
2501     if (!args.atEnd())
2502         return nullptr;
2503
2504     return CSSValuePool::singleton().createValue(shape.releaseNonNull());
2505 }
2506
2507 static RefPtr<CSSValue> consumeBasicShapeOrBox(CSSParserTokenRange& range, const CSSParserContext& context)
2508 {
2509     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2510     bool shapeFound = false;
2511     bool boxFound = false;
2512     while (!range.atEnd() && !(shapeFound && boxFound)) {
2513         RefPtr<CSSValue> componentValue;
2514         if (range.peek().type() == FunctionToken && !shapeFound) {
2515             componentValue = consumeBasicShape(range, context);
2516             shapeFound = true;
2517         } else if (range.peek().type() == IdentToken && !boxFound) {
2518             componentValue = consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, CSSValueMarginBox, CSSValueFill, CSSValueStroke, CSSValueViewBox>(range);
2519             boxFound = true;
2520         }
2521         if (!componentValue)
2522             return nullptr;
2523         list->append(componentValue.releaseNonNull());
2524     }
2525     
2526     if (!range.atEnd() || !list->length())
2527         return nullptr;
2528     
2529     return list;
2530 }
2531     
2532 static RefPtr<CSSValue> consumeWebkitClipPath(CSSParserTokenRange& range, const CSSParserContext& context)
2533 {
2534     if (range.peek().id() == CSSValueNone)
2535         return consumeIdent(range);
2536     if (RefPtr<CSSPrimitiveValue> url = consumeUrl(range))
2537         return url;
2538     return consumeBasicShapeOrBox(range, context);
2539 }
2540
2541 static RefPtr<CSSValue> consumeShapeOutside(CSSParserTokenRange& range, const CSSParserContext& context)
2542 {
2543     if (RefPtr<CSSValue> imageValue = consumeImageOrNone(range, context))
2544         return imageValue;
2545     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2546     if (RefPtr<CSSValue> boxValue = consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, CSSValueMarginBox>(range))
2547         list->append(boxValue.releaseNonNull());
2548     if (RefPtr<CSSValue> shapeValue = consumeBasicShape(range, context)) {
2549         list->append(shapeValue.releaseNonNull());
2550         if (list->length() < 2) {
2551             if (RefPtr<CSSValue> boxValue = consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, CSSValueMarginBox>(range))
2552                 list->append(boxValue.releaseNonNull());
2553         }
2554     }
2555     if (!list->length())
2556         return nullptr;
2557     return list;
2558 }
2559
2560 static RefPtr<CSSValue> consumeContentDistributionOverflowPosition(CSSParserTokenRange& range)
2561 {
2562     if (identMatches<CSSValueNormal, CSSValueBaseline, CSSValueLastBaseline>(range.peek().id()))
2563         return CSSContentDistributionValue::create(CSSValueInvalid, range.consumeIncludingWhitespace().id(), CSSValueInvalid);
2564
2565     CSSValueID distribution = CSSValueInvalid;
2566     CSSValueID position = CSSValueInvalid;
2567     CSSValueID overflow = CSSValueInvalid;
2568     do {
2569         CSSValueID id = range.peek().id();
2570         if (identMatches<CSSValueSpaceBetween, CSSValueSpaceAround, CSSValueSpaceEvenly, CSSValueStretch>(id)) {
2571             if (distribution != CSSValueInvalid)
2572                 return nullptr;
2573             distribution = id;
2574         } else if (identMatches<CSSValueStart, CSSValueEnd, CSSValueCenter, CSSValueFlexStart, CSSValueFlexEnd, CSSValueLeft, CSSValueRight>(id)) {
2575             if (position != CSSValueInvalid)
2576                 return nullptr;
2577             position = id;
2578         } else if (identMatches<CSSValueUnsafe, CSSValueSafe>(id)) {
2579             if (overflow != CSSValueInvalid)
2580                 return nullptr;
2581             overflow = id;
2582         } else {
2583             return nullptr;
2584         }
2585         range.consumeIncludingWhitespace();
2586     } while (!range.atEnd());
2587
2588     // The grammar states that we should have at least <content-distribution> or <content-position>.
2589     if (position == CSSValueInvalid && distribution == CSSValueInvalid)
2590         return nullptr;
2591
2592     // The grammar states that <overflow-position> must be associated to <content-position>.
2593     if (overflow != CSSValueInvalid && position == CSSValueInvalid)
2594         return nullptr;
2595
2596     return CSSContentDistributionValue::create(distribution, position, overflow);
2597 }
2598
2599 static RefPtr<CSSPrimitiveValue> consumeBorderImageRepeatKeyword(CSSParserTokenRange& range)
2600 {
2601     return consumeIdent<CSSValueStretch, CSSValueRepeat, CSSValueSpace, CSSValueRound>(range);
2602 }
2603
2604 static RefPtr<CSSValue> consumeBorderImageRepeat(CSSParserTokenRange& range)
2605 {
2606     RefPtr<CSSPrimitiveValue> horizontal = consumeBorderImageRepeatKeyword(range);
2607     if (!horizontal)
2608         return nullptr;
2609     RefPtr<CSSPrimitiveValue> vertical = consumeBorderImageRepeatKeyword(range);
2610     if (!vertical)
2611         vertical = horizontal;
2612     return createPrimitiveValuePair(horizontal.releaseNonNull(), vertical.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
2613 }
2614
2615 static RefPtr<CSSValue> consumeBorderImageSlice(CSSPropertyID property, CSSParserTokenRange& range)
2616 {
2617     bool fill = consumeIdent<CSSValueFill>(range);
2618     RefPtr<CSSPrimitiveValue> slices[4] = { 0 };
2619
2620     for (size_t index = 0; index < 4; ++index) {
2621         RefPtr<CSSPrimitiveValue> value = consumePercent(range, ValueRangeNonNegative);
2622         if (!value)
2623             value = consumeNumber(range, ValueRangeNonNegative);
2624         if (!value)
2625             break;
2626         slices[index] = value;
2627     }
2628     if (!slices[0])
2629         return nullptr;
2630     if (consumeIdent<CSSValueFill>(range)) {
2631         if (fill)
2632             return nullptr;
2633         fill = true;
2634     }
2635     complete4Sides(slices);
2636     // FIXME: For backwards compatibility, -webkit-border-image, -webkit-mask-box-image and -webkit-box-reflect have to do a fill by default.
2637     // FIXME: What do we do with -webkit-box-reflect and -webkit-mask-box-image? Probably just have to leave them filling...
2638     if (property == CSSPropertyWebkitBorderImage || property == CSSPropertyWebkitMaskBoxImage || property == CSSPropertyWebkitBoxReflect)
2639         fill = true;
2640     
2641     // Now build a rect value to hold all four of our primitive values.
2642     // FIXME-NEWPARSER: Should just have a CSSQuadValue.
2643     auto quad = Quad::create();
2644     quad->setTop(slices[0].releaseNonNull());
2645     quad->setRight(slices[1].releaseNonNull());
2646     quad->setBottom(slices[2].releaseNonNull());
2647     quad->setLeft(slices[3].releaseNonNull());
2648     
2649     // Make our new border image value now.
2650     return CSSBorderImageSliceValue::create(CSSValuePool::singleton().createValue(WTFMove(quad)), fill);
2651 }
2652
2653 static RefPtr<CSSValue> consumeBorderImageOutset(CSSParserTokenRange& range)
2654 {
2655     RefPtr<CSSPrimitiveValue> outsets[4] = { 0 };
2656
2657     RefPtr<CSSPrimitiveValue> value;
2658     for (size_t index = 0; index < 4; ++index) {
2659         value = consumeNumber(range, ValueRangeNonNegative);
2660         if (!value)
2661             value = consumeLength(range, HTMLStandardMode, ValueRangeNonNegative);
2662         if (!value)
2663             break;
2664         outsets[index] = value;
2665     }
2666     if (!outsets[0])
2667         return nullptr;
2668     complete4Sides(outsets);
2669     
2670     // FIXME-NEWPARSER: Should just have a CSSQuadValue.
2671     auto quad = Quad::create();
2672     quad->setTop(outsets[0].releaseNonNull());
2673     quad->setRight(outsets[1].releaseNonNull());
2674     quad->setBottom(outsets[2].releaseNonNull());
2675     quad->setLeft(outsets[3].releaseNonNull());
2676     
2677     return CSSValuePool::singleton().createValue(WTFMove(quad));
2678 }
2679
2680 static RefPtr<CSSValue> consumeBorderImageWidth(CSSParserTokenRange& range)
2681 {
2682     RefPtr<CSSPrimitiveValue> widths[4];
2683
2684     RefPtr<CSSPrimitiveValue> value;
2685     for (size_t index = 0; index < 4; ++index) {
2686         value = consumeNumber(range, ValueRangeNonNegative);
2687         if (!value)
2688             value = consumeLengthOrPercent(range, HTMLStandardMode, ValueRangeNonNegative, UnitlessQuirk::Forbid);
2689         if (!value)
2690             value = consumeIdent<CSSValueAuto>(range);
2691         if (!value)
2692             break;
2693         widths[index] = value;
2694     }
2695     if (!widths[0])
2696         return nullptr;
2697     complete4Sides(widths);
2698     
2699     // FIXME-NEWPARSER: Should just have a CSSQuadValue.
2700     auto quad = Quad::create();
2701     quad->setTop(widths[0].releaseNonNull());
2702     quad->setRight(widths[1].releaseNonNull());
2703     quad->setBottom(widths[2].releaseNonNull());
2704     quad->setLeft(widths[3].releaseNonNull());
2705     
2706     return CSSValuePool::singleton().createValue(WTFMove(quad));
2707 }
2708
2709 static bool consumeBorderImageComponents(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context, RefPtr<CSSValue>& source,
2710     RefPtr<CSSValue>& slice, RefPtr<CSSValue>& width, RefPtr<CSSValue>& outset, RefPtr<CSSValue>& repeat)
2711 {
2712     do {
2713         if (!source) {
2714             source = consumeImageOrNone(range, context);
2715             if (source)
2716                 continue;
2717         }
2718         if (!repeat) {
2719             repeat = consumeBorderImageRepeat(range);
2720             if (repeat)
2721                 continue;
2722         }
2723         if (!slice) {
2724             slice = consumeBorderImageSlice(property, range);
2725             if (slice) {
2726                 ASSERT(!width && !outset);
2727                 if (consumeSlashIncludingWhitespace(range)) {
2728                     width = consumeBorderImageWidth(range);
2729                     if (consumeSlashIncludingWhitespace(range)) {
2730                         outset = consumeBorderImageOutset(range);
2731                         if (!outset)
2732                             return false;
2733                     } else if (!width) {
2734                         return false;
2735                     }
2736                 }
2737             } else {
2738                 return false;
2739             }
2740         } else {
2741             return false;
2742         }
2743     } while (!range.atEnd());
2744     return true;
2745 }
2746
2747 static RefPtr<CSSValue> consumeWebkitBorderImage(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
2748 {
2749     RefPtr<CSSValue> source;
2750     RefPtr<CSSValue> slice;
2751     RefPtr<CSSValue> width;
2752     RefPtr<CSSValue> outset;
2753     RefPtr<CSSValue> repeat;
2754     if (consumeBorderImageComponents(property, range, context, source, slice, width, outset, repeat))
2755         return createBorderImageValue(WTFMove(source), WTFMove(slice), WTFMove(width), WTFMove(outset), WTFMove(repeat));
2756     return nullptr;
2757 }
2758
2759 static RefPtr<CSSValue> consumeReflect(CSSParserTokenRange& range, const CSSParserContext& context)
2760 {
2761     if (range.peek().id() == CSSValueNone)
2762         return consumeIdent(range);
2763     
2764     RefPtr<CSSPrimitiveValue> direction = consumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>(range);
2765     if (!direction)
2766         return nullptr;
2767
2768     RefPtr<CSSPrimitiveValue> offset;
2769     if (range.atEnd())
2770         offset = CSSValuePool::singleton().createValue(0, CSSPrimitiveValue::UnitTypes::CSS_PX);
2771     else {
2772         offset = consumeLengthOrPercent(range, context.mode, ValueRangeAll, UnitlessQuirk::Forbid);
2773         if (!offset)
2774             return nullptr;
2775     }
2776
2777     RefPtr<CSSValue> mask;
2778     if (!range.atEnd()) {
2779         mask = consumeWebkitBorderImage(CSSPropertyWebkitBoxReflect, range, context);
2780         if (!mask)
2781             return nullptr;
2782     }
2783     return CSSReflectValue::create(direction.releaseNonNull(), offset.releaseNonNull(), WTFMove(mask));
2784 }
2785
2786 #if ENABLE(CSS_IMAGE_ORIENTATION)
2787 static RefPtr<CSSValue> consumeImageOrientation(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless = UnitlessQuirk::Forbid)
2788 {
2789     if (range.peek().type() != NumberToken) {
2790         RefPtr<CSSPrimitiveValue> angle = consumeAngle(range, cssParserMode, unitless);
2791         if (angle && angle->doubleValue() == 0)
2792             return angle;
2793     }
2794     return nullptr;
2795 }
2796 #endif
2797
2798 static RefPtr<CSSPrimitiveValue> consumeBackgroundBlendMode(CSSParserTokenRange& range)
2799 {
2800     CSSValueID id = range.peek().id();
2801     if (id == CSSValueNormal || id == CSSValueOverlay || (id >= CSSValueMultiply && id <= CSSValueLuminosity))
2802         return consumeIdent(range);
2803     return nullptr;
2804 }
2805
2806 static RefPtr<CSSPrimitiveValue> consumeBackgroundAttachment(CSSParserTokenRange& range)
2807 {
2808     return consumeIdent<CSSValueScroll, CSSValueFixed, CSSValueLocal>(range);
2809 }
2810
2811 static RefPtr<CSSPrimitiveValue> consumeBackgroundBox(CSSParserTokenRange& range)
2812 {
2813     return consumeIdent<CSSValueBorderBox, CSSValuePaddingBox, CSSValueContentBox, CSSValueWebkitText>(range);
2814 }
2815
2816 static RefPtr<CSSPrimitiveValue> consumeBackgroundComposite(CSSParserTokenRange& range)
2817 {
2818     return consumeIdentRange(range, CSSValueClear, CSSValuePlusLighter);
2819 }
2820
2821 static RefPtr<CSSPrimitiveValue> consumeWebkitMaskSourceType(CSSParserTokenRange& range)
2822 {
2823     return consumeIdent<CSSValueAuto, CSSValueAlpha, CSSValueLuminance>(range);
2824 }
2825
2826 static RefPtr<CSSPrimitiveValue> consumePrefixedBackgroundBox(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& /*context*/)
2827 {
2828     // The values 'border', 'padding' and 'content' are deprecated and do not apply to the version of the property that has the -webkit- prefix removed.
2829     if (RefPtr<CSSPrimitiveValue> value = consumeIdentRange(range, CSSValueBorder, CSSValuePaddingBox))
2830         return value;
2831     if (range.peek().id() == CSSValueWebkitText || ((property == CSSPropertyWebkitBackgroundClip || property == CSSPropertyWebkitMaskClip) && range.peek().id() == CSSValueText))
2832         return consumeIdent(range);
2833     return nullptr;
2834 }
2835
2836 static RefPtr<CSSPrimitiveValue> consumeBackgroundSize(CSSPropertyID property, CSSParserTokenRange& range, CSSParserMode cssParserMode)
2837 {
2838     if (identMatches<CSSValueContain, CSSValueCover>(range.peek().id()))
2839         return consumeIdent(range);
2840
2841     // FIXME: We're allowing the unitless quirk on this property because our
2842     // tests assume that. Other browser engines don't allow it though.
2843     RefPtr<CSSPrimitiveValue> horizontal = consumeIdent<CSSValueAuto>(range);
2844     if (!horizontal)
2845         horizontal = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
2846
2847     RefPtr<CSSPrimitiveValue> vertical;
2848     if (!range.atEnd()) {
2849         if (range.peek().id() == CSSValueAuto) // `auto' is the default
2850             range.consumeIncludingWhitespace();
2851         else
2852             vertical = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
2853     } else if (!vertical && property == CSSPropertyWebkitBackgroundSize) {
2854         // Legacy syntax: "-webkit-background-size: 10px" is equivalent to "background-size: 10px 10px".
2855         vertical = horizontal;
2856     }
2857     if (!vertical)
2858         return horizontal;
2859     return createPrimitiveValuePair(horizontal.releaseNonNull(), vertical.releaseNonNull(), property == CSSPropertyWebkitBackgroundSize ? Pair::IdenticalValueEncoding::Coalesce : Pair::IdenticalValueEncoding::DoNotCoalesce);
2860 }
2861
2862 #if ENABLE(CSS_GRID_LAYOUT)
2863 static RefPtr<CSSValueList> consumeGridAutoFlow(CSSParserTokenRange& range)
2864 {
2865     RefPtr<CSSPrimitiveValue> rowOrColumnValue = consumeIdent<CSSValueRow, CSSValueColumn>(range);
2866     RefPtr<CSSPrimitiveValue> denseAlgorithm = consumeIdent<CSSValueDense>(range);
2867     if (!rowOrColumnValue) {
2868         rowOrColumnValue = consumeIdent<CSSValueRow, CSSValueColumn>(range);
2869         if (!rowOrColumnValue && !denseAlgorithm)
2870             return nullptr;
2871     }
2872     RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
2873     if (rowOrColumnValue)
2874         parsedValues->append(rowOrColumnValue.releaseNonNull());
2875     if (denseAlgorithm)
2876         parsedValues->append(denseAlgorithm.releaseNonNull());
2877     return parsedValues;
2878 }
2879 #endif
2880
2881 static RefPtr<CSSValue> consumeBackgroundComponent(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
2882 {
2883     switch (property) {
2884     case CSSPropertyBackgroundClip:
2885         return consumeBackgroundBox(range);
2886     case CSSPropertyBackgroundBlendMode:
2887         return consumeBackgroundBlendMode(range);
2888     case CSSPropertyBackgroundAttachment:
2889         return consumeBackgroundAttachment(range);
2890     case CSSPropertyBackgroundOrigin:
2891         return consumeBackgroundBox(range);
2892     case CSSPropertyWebkitMaskComposite:
2893     case CSSPropertyWebkitBackgroundComposite:
2894         return consumeBackgroundComposite(range);
2895     case CSSPropertyWebkitBackgroundClip:
2896     case CSSPropertyWebkitBackgroundOrigin:
2897     case CSSPropertyWebkitMaskClip:
2898     case CSSPropertyWebkitMaskOrigin:
2899         return consumePrefixedBackgroundBox(property, range, context);
2900     case CSSPropertyBackgroundImage:
2901     case CSSPropertyWebkitMaskImage:
2902         return consumeImageOrNone(range, context);
2903     case CSSPropertyWebkitMaskSourceType:
2904         return consumeWebkitMaskSourceType(range);
2905     case CSSPropertyBackgroundPositionX:
2906     case CSSPropertyWebkitMaskPositionX:
2907         return consumePositionX(range, context.mode);
2908     case CSSPropertyBackgroundPositionY:
2909     case CSSPropertyWebkitMaskPositionY:
2910         return consumePositionY(range, context.mode);
2911     case CSSPropertyBackgroundSize:
2912     case CSSPropertyWebkitBackgroundSize:
2913     case CSSPropertyWebkitMaskSize:
2914         return consumeBackgroundSize(property, range, context.mode);
2915     case CSSPropertyBackgroundColor:
2916         return consumeColor(range, context.mode);
2917     default:
2918         break;
2919     };
2920     return nullptr;
2921 }
2922
2923 static void addBackgroundValue(RefPtr<CSSValue>& list, Ref<CSSValue>&& value)
2924 {
2925     if (list) {
2926         if (!list->isBaseValueList()) {
2927             RefPtr<CSSValue> firstValue = list;
2928             list = CSSValueList::createCommaSeparated();
2929             downcast<CSSValueList>(*list).append(firstValue.releaseNonNull());
2930         }
2931         downcast<CSSValueList>(*list).append(WTFMove(value));
2932     } else {
2933         // To conserve memory we don't actually wrap a single value in a list.
2934         list = WTFMove(value);
2935     }
2936 }
2937
2938 static RefPtr<CSSValue> consumeCommaSeparatedBackgroundComponent(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
2939 {
2940     RefPtr<CSSValue> result;
2941     do {
2942         RefPtr<CSSValue> value = consumeBackgroundComponent(property, range, context);
2943         if (!value)
2944             return nullptr;
2945         addBackgroundValue(result, value.releaseNonNull());
2946     } while (consumeCommaIncludingWhitespace(range));
2947     return result;
2948 }
2949
2950 #if ENABLE(CSS_GRID_LAYOUT)
2951 static RefPtr<CSSPrimitiveValue> consumeSelfPositionKeyword(CSSParserTokenRange& range)
2952 {
2953     CSSValueID id = range.peek().id();
2954     if (id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
2955         || id == CSSValueSelfStart || id == CSSValueSelfEnd || id == CSSValueFlexStart
2956         || id == CSSValueFlexEnd || id == CSSValueLeft || id == CSSValueRight)
2957         return consumeIdent(range);
2958     return nullptr;
2959 }
2960
2961 static RefPtr<CSSValue> consumeSelfPositionOverflowPosition(CSSParserTokenRange& range)
2962 {
2963     if (identMatches<CSSValueAuto, CSSValueNormal, CSSValueStretch, CSSValueBaseline, CSSValueLastBaseline>(range.peek().id()))
2964         return consumeIdent(range);
2965
2966     RefPtr<CSSPrimitiveValue> overflowPosition = consumeIdent<CSSValueUnsafe, CSSValueSafe>(range);
2967     RefPtr<CSSPrimitiveValue> selfPosition = consumeSelfPositionKeyword(range);
2968     if (!selfPosition)
2969         return nullptr;
2970     if (!overflowPosition)
2971         overflowPosition = consumeIdent<CSSValueUnsafe, CSSValueSafe>(range);
2972     if (overflowPosition)
2973         return createPrimitiveValuePair(selfPosition.releaseNonNull(), overflowPosition.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
2974     return selfPosition;
2975 }
2976
2977 static RefPtr<CSSValue> consumeAlignItems(CSSParserTokenRange& range)
2978 {
2979     // align-items property does not allow the 'auto' value.
2980     if (identMatches<CSSValueAuto>(range.peek().id()))
2981         return nullptr;
2982     return consumeSelfPositionOverflowPosition(range);
2983 }
2984
2985 static RefPtr<CSSValue> consumeJustifyItems(CSSParserTokenRange& range)
2986 {
2987     CSSParserTokenRange rangeCopy = range;
2988     RefPtr<CSSPrimitiveValue> legacy = consumeIdent<CSSValueLegacy>(rangeCopy);
2989     RefPtr<CSSPrimitiveValue> positionKeyword = consumeIdent<CSSValueCenter, CSSValueLeft, CSSValueRight>(rangeCopy);
2990     if (!legacy)
2991         legacy = consumeIdent<CSSValueLegacy>(rangeCopy);
2992     if (legacy && positionKeyword) {
2993         range = rangeCopy;
2994         return createPrimitiveValuePair(legacy.releaseNonNull(), positionKeyword.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
2995     }
2996     return consumeSelfPositionOverflowPosition(range);
2997 }
2998
2999 static RefPtr<CSSValue> consumeFitContent(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3000 {
3001     CSSParserTokenRange rangeCopy = range;
3002     CSSParserTokenRange args = consumeFunction(rangeCopy);
3003     RefPtr<CSSPrimitiveValue> length = consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
3004     if (!length || !args.atEnd())
3005         return nullptr;
3006     range = rangeCopy;
3007     RefPtr<CSSFunctionValue> result = CSSFunctionValue::create(CSSValueFitContent);
3008     result->append(length.releaseNonNull());
3009     return result;
3010 }
3011
3012 static RefPtr<CSSPrimitiveValue> consumeCustomIdentForGridLine(CSSParserTokenRange& range)
3013 {
3014     if (range.peek().id() == CSSValueAuto || range.peek().id() == CSSValueSpan)
3015         return nullptr;
3016     return consumeCustomIdent(range);
3017 }
3018
3019 static RefPtr<CSSValue> consumeGridLine(CSSParserTokenRange& range)
3020 {
3021     if (range.peek().id() == CSSValueAuto)
3022         return consumeIdent(range);
3023
3024     RefPtr<CSSPrimitiveValue> spanValue;
3025     RefPtr<CSSPrimitiveValue> gridLineName;
3026     RefPtr<CSSPrimitiveValue> numericValue = consumeInteger(range);
3027     if (numericValue) {
3028         gridLineName = consumeCustomIdentForGridLine(range);
3029         spanValue = consumeIdent<CSSValueSpan>(range);
3030     } else {
3031         spanValue = consumeIdent<CSSValueSpan>(range);
3032         if (spanValue) {
3033             numericValue = consumeInteger(range);
3034             gridLineName = consumeCustomIdentForGridLine(range);
3035             if (!numericValue)
3036                 numericValue = consumeInteger(range);
3037         } else {
3038             gridLineName = consumeCustomIdentForGridLine(range);
3039             if (gridLineName) {
3040                 numericValue = consumeInteger(range);
3041                 spanValue = consumeIdent<CSSValueSpan>(range);
3042                 if (!spanValue && !numericValue)
3043                     return gridLineName;
3044             } else {
3045                 return nullptr;
3046             }
3047         }
3048     }
3049
3050     if (spanValue && !numericValue && !gridLineName)
3051         return nullptr; // "span" keyword alone is invalid.
3052     if (spanValue && numericValue && numericValue->intValue() < 0)
3053         return nullptr; // Negative numbers are not allowed for span.
3054     if (numericValue && numericValue->intValue() == 0)
3055         return nullptr; // An <integer> value of zero makes the declaration invalid.
3056
3057     RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
3058     if (spanValue)
3059         values->append(spanValue.releaseNonNull());
3060     if (numericValue)
3061         values->append(numericValue.releaseNonNull());
3062     if (gridLineName)
3063         values->append(gridLineName.releaseNonNull());
3064     ASSERT(values->length());
3065     return values;
3066 }
3067
3068 static bool isGridTrackFixedSized(const CSSPrimitiveValue& primitiveValue)
3069 {
3070     CSSValueID valueID = primitiveValue.valueID();
3071     if (valueID == CSSValueWebkitMinContent || valueID == CSSValueWebkitMaxContent || valueID == CSSValueAuto || primitiveValue.isFlex())
3072         return false;
3073
3074     return true;
3075 }
3076
3077 static bool isGridTrackFixedSized(const CSSValue& value)
3078 {
3079     if (value.isPrimitiveValue())
3080         return isGridTrackFixedSized(downcast<CSSPrimitiveValue>(value));
3081
3082     ASSERT(value.isFunctionValue());
3083     auto& function = downcast<CSSFunctionValue>(value);
3084     if (function.name() == CSSValueFitContent || function.arguments() == nullptr || function.arguments()->length() < 2)
3085         return false;
3086
3087     CSSValue* minPrimitiveValue = downcast<CSSPrimitiveValue>(function.arguments()->item(0));
3088     CSSValue* maxPrimitiveValue = downcast<CSSPrimitiveValue>(function.arguments()->item(1));
3089     return isGridTrackFixedSized(*minPrimitiveValue) || isGridTrackFixedSized(*maxPrimitiveValue);
3090 }
3091
3092 static Vector<String> parseGridTemplateAreasColumnNames(const String& gridRowNames)
3093 {
3094     ASSERT(!gridRowNames.isEmpty());
3095     Vector<String> columnNames;
3096     // Using StringImpl to avoid checks and indirection in every call to String::operator[].
3097     StringImpl& text = *gridRowNames.impl();
3098
3099     StringBuilder areaName;
3100     for (unsigned i = 0; i < text.length(); ++i) {
3101         if (isCSSSpace(text[i])) {
3102             if (!areaName.isEmpty()) {
3103                 columnNames.append(areaName.toString());
3104                 areaName.clear();
3105             }
3106             continue;
3107         }
3108         if (text[i] == '.') {
3109             if (areaName == ".")
3110                 continue;
3111             if (!areaName.isEmpty()) {
3112                 columnNames.append(areaName.toString());
3113                 areaName.clear();
3114             }
3115         } else {
3116             if (!isNameCodePoint(text[i]))
3117                 return Vector<String>();
3118             if (areaName == ".") {
3119                 columnNames.append(areaName.toString());
3120                 areaName.clear();
3121             }
3122         }
3123
3124         areaName.append(text[i]);
3125     }
3126
3127     if (!areaName.isEmpty())
3128         columnNames.append(areaName.toString());
3129
3130     return columnNames;
3131 }
3132
3133 static bool parseGridTemplateAreasRow(const String& gridRowNames, NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount)
3134 {
3135     if (gridRowNames.isEmpty() || gridRowNames.containsOnlyWhitespace())
3136         return false;
3137
3138     Vector<String> columnNames = parseGridTemplateAreasColumnNames(gridRowNames);
3139     if (rowCount == 0) {
3140         columnCount = columnNames.size();
3141         if (columnCount == 0)
3142             return false;
3143     } else if (columnCount != columnNames.size()) {
3144         // The declaration is invalid if all the rows don't have the number of columns.
3145         return false;
3146     }
3147
3148     for (size_t currentColumn = 0; currentColumn < columnCount; ++currentColumn) {
3149         const String& gridAreaName = columnNames[currentColumn];
3150
3151         // Unamed areas are always valid (we consider them to be 1x1).
3152         if (gridAreaName == ".")
3153             continue;
3154
3155         size_t lookAheadColumn = currentColumn + 1;
3156         while (lookAheadColumn < columnCount && columnNames[lookAheadColumn] == gridAreaName)
3157             lookAheadColumn++;
3158
3159         NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName);
3160         if (gridAreaIt == gridAreaMap.end()) {
3161             gridAreaMap.add(gridAreaName, GridArea(GridSpan::translatedDefiniteGridSpan(rowCount, rowCount + 1), GridSpan::translatedDefiniteGridSpan(currentColumn, lookAheadColumn)));
3162         } else {
3163             GridArea& gridArea = gridAreaIt->value;
3164
3165             // The following checks test that the grid area is a single filled-in rectangle.
3166             // 1. The new row is adjacent to the previously parsed row.
3167             if (rowCount != gridArea.rows.endLine())
3168                 return false;
3169
3170             // 2. The new area starts at the same position as the previously parsed area.
3171             if (currentColumn != gridArea.columns.startLine())
3172                 return false;
3173
3174             // 3. The new area ends at the same position as the previously parsed area.
3175             if (lookAheadColumn != gridArea.columns.endLine())
3176                 return false;
3177
3178             gridArea.rows = GridSpan::translatedDefiniteGridSpan(gridArea.rows.startLine(), gridArea.rows.endLine() + 1);
3179         }
3180         currentColumn = lookAheadColumn - 1;
3181     }
3182
3183     return true;
3184 }
3185
3186 static RefPtr<CSSPrimitiveValue> consumeGridBreadth(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3187 {
3188     const CSSParserToken& token = range.peek();
3189     if (identMatches<CSSValueWebkitMinContent, CSSValueWebkitMaxContent, CSSValueAuto>(token.id()))
3190         return consumeIdent(range);
3191     if (token.type() == DimensionToken && token.unitType() == CSSPrimitiveValue::UnitTypes::CSS_FR) {
3192         if (range.peek().numericValue() < 0)
3193             return nullptr;
3194         return CSSPrimitiveValue::create(range.consumeIncludingWhitespace().numericValue(), CSSPrimitiveValue::UnitTypes::CSS_FR);
3195     }
3196     return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
3197 }
3198
3199 static RefPtr<CSSValue> consumeGridTrackSize(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3200 {
3201     const CSSParserToken& token = range.peek();
3202     if (identMatches<CSSValueAuto>(token.id()))
3203         return consumeIdent(range);
3204
3205     if (token.functionId() == CSSValueMinmax) {
3206         CSSParserTokenRange rangeCopy = range;
3207         CSSParserTokenRange args = consumeFunction(rangeCopy);
3208         RefPtr<CSSPrimitiveValue> minTrackBreadth = consumeGridBreadth(args, cssParserMode);
3209         if (!minTrackBreadth || minTrackBreadth->isFlex() || !consumeCommaIncludingWhitespace(args))
3210             return nullptr;
3211         RefPtr<CSSPrimitiveValue> maxTrackBreadth = consumeGridBreadth(args, cssParserMode);
3212         if (!maxTrackBreadth || !args.atEnd())
3213             return nullptr;
3214         range = rangeCopy;
3215         RefPtr<CSSFunctionValue> result = CSSFunctionValue::create(CSSValueMinmax);
3216         result->append(minTrackBreadth.releaseNonNull());
3217         result->append(maxTrackBreadth.releaseNonNull());
3218         return result;
3219     }
3220
3221     if (token.functionId() == CSSValueFitContent)
3222         return consumeFitContent(range, cssParserMode);
3223
3224     return consumeGridBreadth(range, cssParserMode);
3225 }
3226
3227 // Appends to the passed in CSSGridLineNamesValue if any, otherwise creates a new one.
3228 static RefPtr<CSSGridLineNamesValue> consumeGridLineNames(CSSParserTokenRange& range, CSSGridLineNamesValue* lineNames = nullptr)
3229 {
3230     CSSParserTokenRange rangeCopy = range;
3231     if (rangeCopy.consumeIncludingWhitespace().type() != LeftBracketToken)
3232         return nullptr;
3233     
3234     RefPtr<CSSGridLineNamesValue> result = lineNames;
3235     if (!result)
3236         result = CSSGridLineNamesValue::create();
3237     while (RefPtr<CSSPrimitiveValue> lineName = consumeCustomIdentForGridLine(rangeCopy))
3238         result->append(lineName.releaseNonNull());
3239     if (rangeCopy.consumeIncludingWhitespace().type() != RightBracketToken)
3240         return nullptr;
3241     range = rangeCopy;
3242     return result;
3243 }
3244
3245 static bool consumeGridTrackRepeatFunction(CSSParserTokenRange& range, CSSParserMode cssParserMode, CSSValueList& list, bool& isAutoRepeat, bool& allTracksAreFixedSized)
3246 {
3247     CSSParserTokenRange args = consumeFunction(range);
3248     // The number of repetitions for <auto-repeat> is not important at parsing level
3249     // because it will be computed later, let's set it to 1.
3250     size_t repetitions = 1;
3251     isAutoRepeat = identMatches<CSSValueAutoFill, CSSValueAutoFit>(args.peek().id());
3252     RefPtr<CSSValueList> repeatedValues;
3253     if (isAutoRepeat)
3254         repeatedValues = CSSGridAutoRepeatValue::create(args.consumeIncludingWhitespace().id());
3255     else {
3256         // FIXME: a consumeIntegerRaw would be more efficient here.
3257         RefPtr<CSSPrimitiveValue> repetition = consumePositiveInteger(args);
3258         if (!repetition)
3259             return false;
3260         repetitions = clampTo<size_t>(repetition->doubleValue(), 0, kGridMaxTracks);
3261         repeatedValues = CSSValueList::createSpaceSeparated();
3262     }
3263     if (!consumeCommaIncludingWhitespace(args))
3264         return false;
3265     RefPtr<CSSGridLineNamesValue> lineNames = consumeGridLineNames(args);
3266     if (lineNames)
3267         repeatedValues->append(lineNames.releaseNonNull());
3268
3269     size_t numberOfTracks = 0;
3270     while (!args.atEnd()) {
3271         RefPtr<CSSValue> trackSize = consumeGridTrackSize(args, cssParserMode);
3272         if (!trackSize)
3273             return false;
3274         if (allTracksAreFixedSized)
3275             allTracksAreFixedSized = isGridTrackFixedSized(*trackSize);
3276         repeatedValues->append(trackSize.releaseNonNull());
3277         ++numberOfTracks;
3278         lineNames = consumeGridLineNames(args);
3279         if (lineNames)
3280             repeatedValues->append(lineNames.releaseNonNull());
3281     }
3282     // We should have found at least one <track-size> or else it is not a valid <track-list>.
3283     if (!numberOfTracks)
3284         return false;
3285
3286     if (isAutoRepeat)
3287         list.append(repeatedValues.releaseNonNull());
3288     else {
3289         // We clamp the repetitions to a multiple of the repeat() track list's size, while staying below the max grid size.
3290         repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks);
3291         for (size_t i = 0; i < repetitions; ++i) {
3292             for (size_t j = 0; j < repeatedValues->length(); ++j)
3293                 list.append(*repeatedValues->itemWithoutBoundsCheck(j));
3294         }
3295     }
3296     return true;
3297 }
3298
3299 enum TrackListType { GridTemplate, GridTemplateNoRepeat, GridAuto };
3300
3301 static RefPtr<CSSValue> consumeGridTrackList(CSSParserTokenRange& range, CSSParserMode cssParserMode, TrackListType trackListType)
3302 {
3303     bool allowGridLineNames = trackListType != GridAuto;
3304     RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
3305     RefPtr<CSSGridLineNamesValue> lineNames = consumeGridLineNames(range);
3306     if (lineNames) {
3307         if (!allowGridLineNames)
3308             return nullptr;
3309         values->append(lineNames.releaseNonNull());
3310     }
3311     
3312     bool allowRepeat = trackListType == GridTemplate;
3313     bool seenAutoRepeat = false;
3314     bool allTracksAreFixedSized = true;
3315     do {
3316         bool isAutoRepeat;
3317         if (range.peek().functionId() == CSSValueRepeat) {
3318             if (!allowRepeat)
3319                 return nullptr;
3320             if (!consumeGridTrackRepeatFunction(range, cssParserMode, *values, isAutoRepeat, allTracksAreFixedSized))
3321                 return nullptr;
3322             if (isAutoRepeat && seenAutoRepeat)
3323                 return nullptr;
3324             seenAutoRepeat = seenAutoRepeat || isAutoRepeat;
3325         } else if (RefPtr<CSSValue> value = consumeGridTrackSize(range, cssParserMode)) {
3326             if (allTracksAreFixedSized)
3327                 allTracksAreFixedSized = isGridTrackFixedSized(*value);
3328             values->append(value.releaseNonNull());
3329         } else {
3330             return nullptr;
3331         }
3332         if (seenAutoRepeat && !allTracksAreFixedSized)
3333             return nullptr;
3334         lineNames = consumeGridLineNames(range);
3335         if (lineNames) {
3336             if (!allowGridLineNames)
3337                 return nullptr;
3338             values->append(lineNames.releaseNonNull());
3339         }
3340     } while (!range.atEnd() && range.peek().type() != DelimiterToken);
3341     return values;
3342 }
3343
3344 static RefPtr<CSSValue> consumeGridTemplatesRowsOrColumns(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3345 {
3346     if (range.peek().id() == CSSValueNone)
3347         return consumeIdent(range);
3348     return consumeGridTrackList(range, cssParserMode, GridTemplate);
3349 }
3350
3351 static RefPtr<CSSValue> consumeGridTemplateAreas(CSSParserTokenRange& range)
3352 {
3353     if (range.peek().id() == CSSValueNone)
3354         return consumeIdent(range);
3355
3356     NamedGridAreaMap gridAreaMap;
3357     size_t rowCount = 0;
3358     size_t columnCount = 0;
3359
3360     while (range.peek().type() == StringToken) {
3361         if (!parseGridTemplateAreasRow(range.consumeIncludingWhitespace().value().toString(), gridAreaMap, rowCount, columnCount))
3362             return nullptr;
3363         ++rowCount;
3364     }
3365
3366     if (rowCount == 0)
3367         return nullptr;
3368     ASSERT(columnCount);
3369     return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount);
3370 }
3371 #endif
3372
3373 #if ENABLE(CSS_REGIONS)
3374 static RefPtr<CSSValue> consumeFlowProperty(CSSParserTokenRange& range)
3375 {
3376     RefPtr<CSSValue> result;
3377     if (range.peek().id() == CSSValueNone)
3378         result = consumeIdent(range);
3379     else
3380         result = consumeCustomIdent(range);
3381     return result;
3382 }
3383 #endif
3384
3385 static RefPtr<CSSValue> consumeLineBoxContain(CSSParserTokenRange& range)
3386 {
3387     if (range.peek().id() == CSSValueNone)
3388         return consumeIdent(range);
3389
3390     LineBoxContain lineBoxContain = LineBoxContainNone;
3391     
3392     while (range.peek().type() == IdentToken) {
3393         auto id = range.peek().id();
3394         if (id == CSSValueBlock) {
3395             if (lineBoxContain & LineBoxContainBlock)
3396                 return nullptr;
3397             lineBoxContain |= LineBoxContainBlock;
3398         } else if (id == CSSValueInline) {
3399             if (lineBoxContain & LineBoxContainInline)
3400                 return nullptr;
3401             lineBoxContain |= LineBoxContainInline;
3402         } else if (id == CSSValueFont) {
3403             if (lineBoxContain & LineBoxContainFont)
3404                 return nullptr;
3405             lineBoxContain |= LineBoxContainFont;
3406         } else if (id == CSSValueGlyphs) {
3407             if (lineBoxContain & LineBoxContainGlyphs)
3408                 return nullptr;
3409             lineBoxContain |= LineBoxContainGlyphs;
3410         } else if (id == CSSValueReplaced) {
3411             if (lineBoxContain & LineBoxContainReplaced)
3412                 return nullptr;
3413             lineBoxContain |= LineBoxContainReplaced;
3414         } else if (id == CSSValueInlineBox) {
3415             if (lineBoxContain & LineBoxContainInlineBox)
3416                 return nullptr;
3417             lineBoxContain |= LineBoxContainInlineBox;
3418         } else if (id == CSSValueInitialLetter) {
3419             if (lineBoxContain & LineBoxContainInitialLetter)
3420                 return nullptr;
3421             lineBoxContain |= LineBoxContainInitialLetter;
3422         } else
3423             return nullptr;
3424         range.consumeIncludingWhitespace();
3425     }
3426     
3427     if (!lineBoxContain)
3428         return nullptr;
3429     
3430     return CSSLineBoxContainValue::create(lineBoxContain);
3431 }
3432
3433 static RefPtr<CSSValue> consumeLineGrid(CSSParserTokenRange& range)
3434 {
3435     if (range.peek().id() == CSSValueNone)
3436         return consumeIdent(range);
3437     return consumeCustomIdent(range);
3438 }
3439
3440 static RefPtr<CSSValue> consumeInitialLetter(CSSParserTokenRange& range)
3441 {
3442     RefPtr<CSSValue> ident = consumeIdent<CSSValueNormal>(range);
3443     if (ident)
3444         return ident;
3445     
3446     RefPtr<CSSPrimitiveValue> height = consumeNumber(range, ValueRangeNonNegative);
3447     if (!height)
3448         return nullptr;
3449     
3450     RefPtr<CSSPrimitiveValue> position;
3451     if (!range.atEnd()) {
3452         position = consumeNumber(range, ValueRangeNonNegative);
3453         if (!position || !range.atEnd())
3454             return nullptr;
3455     } else
3456         position = height.copyRef();
3457     
3458     return createPrimitiveValuePair(position.releaseNonNull(), WTFMove(height));
3459 }
3460
3461 static RefPtr<CSSValue> consumeHangingPunctuation(CSSParserTokenRange& range)
3462 {
3463     if (range.peek().id() == CSSValueNone)
3464         return consumeIdent(range);
3465     
3466     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3467     std::bitset<numCSSValueKeywords> seenValues;
3468
3469     bool seenForceEnd = false;
3470     bool seenAllowEnd = false;
3471     bool seenFirst = false;
3472     bool seenLast = false;
3473
3474     while (!range.atEnd()) {
3475         CSSValueID valueID = range.peek().id();
3476         if ((valueID == CSSValueFirst && seenFirst)
3477             || (valueID == CSSValueLast && seenLast)
3478             || (valueID == CSSValueAllowEnd && (seenAllowEnd || seenForceEnd))
3479             || (valueID == CSSValueForceEnd && (seenAllowEnd || seenForceEnd)))
3480             return nullptr;
3481         RefPtr<CSSValue> ident = consumeIdent<CSSValueAllowEnd, CSSValueForceEnd, CSSValueFirst, CSSValueLast>(range);
3482         if (!ident)
3483             return nullptr;
3484         switch (valueID) {
3485         case CSSValueAllowEnd:
3486             seenAllowEnd = true;
3487             break;
3488         case CSSValueForceEnd:
3489             seenForceEnd = true;
3490             break;
3491         case CSSValueFirst:
3492             seenFirst = true;
3493             break;
3494         case CSSValueLast:
3495             seenLast = true;
3496             break;
3497         default:
3498             break;
3499         }
3500         list->append(ident.releaseNonNull());
3501     }
3502     
3503     return list->length() ? list : nullptr;
3504 }
3505
3506 static RefPtr<CSSValue> consumeWebkitMarqueeIncrement(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3507 {
3508     if (range.peek().type() == IdentToken)
3509         return consumeIdent<CSSValueSmall, CSSValueMedium, CSSValueLarge>(range);
3510     return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll);
3511 }
3512
3513 static RefPtr<CSSValue> consumeWebkitMarqueeRepetition(CSSParserTokenRange& range)
3514 {
3515     if (range.peek().type() == IdentToken)
3516         return consumeIdent<CSSValueInfinite>(range);
3517     return consumeNumber(range, ValueRangeNonNegative);
3518 }
3519
3520 static RefPtr<CSSValue> consumeWebkitMarqueeSpeed(CSSParserTokenRange& range, CSSParserMode cssParserMode)
3521 {
3522     if (range.peek().type() == IdentToken)
3523         return consumeIdent<CSSValueSlow, CSSValueNormal, CSSValueFast>(range);
3524     return consumeTime(range, cssParserMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
3525 }
3526
3527 static RefPtr<CSSValue> consumeAlt(CSSParserTokenRange& range, const CSSParserContext& context)
3528 {
3529     if (range.peek().type() == StringToken)
3530         return consumeString(range);
3531     
3532     if (range.peek().functionId() != CSSValueAttr)
3533         return nullptr;
3534     
3535     return consumeAttr(consumeFunction(range), context);
3536 }
3537
3538 static RefPtr<CSSValue> consumeWebkitAspectRatio(CSSParserTokenRange& range)
3539 {
3540     if (range.peek().type() == IdentToken)
3541         return consumeIdent<CSSValueAuto, CSSValueFromDimensions, CSSValueFromIntrinsic>(range);
3542     
3543     RefPtr<CSSPrimitiveValue> leftValue = consumeNumber(range, ValueRangeNonNegative);
3544     if (!leftValue || range.atEnd() || !consumeSlashIncludingWhitespace(range))
3545         return nullptr;
3546     RefPtr<CSSPrimitiveValue> rightValue = consumeNumber(range, ValueRangeNonNegative);
3547     if (!rightValue)
3548         return nullptr;
3549     
3550     return CSSAspectRatioValue::create(leftValue->floatValue(), rightValue->floatValue());
3551 }
3552
3553 static RefPtr<CSSValue> consumeTextEmphasisPosition(CSSParserTokenRange& range)
3554 {
3555     bool foundOverOrUnder = false;
3556     CSSValueID overUnderValueID = CSSValueOver;
3557     bool foundLeftOrRight = false;
3558     CSSValueID leftRightValueID = CSSValueRight;
3559     while (!range.atEnd()) {
3560         switch (range.peek().id()) {
3561         case CSSValueOver:
3562             if (foundOverOrUnder)
3563                 return nullptr;
3564             foundOverOrUnder = true;
3565             overUnderValueID = CSSValueOver;
3566             break;
3567         case CSSValueUnder:
3568             if (foundOverOrUnder)
3569                 return nullptr;
3570             foundOverOrUnder = true;
3571             overUnderValueID = CSSValueUnder;
3572             break;
3573         case CSSValueLeft:
3574             if (foundLeftOrRight)
3575                 return nullptr;
3576             foundLeftOrRight = true;
3577             leftRightValueID = CSSValueLeft;
3578             break;
3579         case CSSValueRight:
3580             if (foundLeftOrRight)
3581                 return nullptr;
3582             foundLeftOrRight = true;
3583             leftRightValueID = CSSValueRight;
3584             break;
3585         default:
3586             return nullptr;
3587         }
3588         
3589         range.consumeIncludingWhitespace();
3590     }
3591     if (!foundOverOrUnder)
3592         return nullptr;
3593     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3594     list->append(CSSValuePool::singleton().createIdentifierValue(overUnderValueID));
3595     if (foundLeftOrRight)
3596         list->append(CSSValuePool::singleton().createIdentifierValue(leftRightValueID));
3597     return list;
3598 }
3599     
3600 #if ENABLE(DASHBOARD_SUPPORT)
3601
3602 static RefPtr<CSSValue> consumeWebkitDashboardRegion(CSSParserTokenRange& range, CSSParserMode mode)
3603 {
3604     if (range.peek().id() == CSSValueNone)
3605         return consumeIdent(range);
3606     
3607     auto firstRegion = DashboardRegion::create();
3608     DashboardRegion* region = nullptr;
3609     
3610     bool requireCommas = false;
3611     
3612     while (!range.atEnd()) {
3613         if (!region)
3614             region = firstRegion.ptr();
3615         else {
3616             auto nextRegion = DashboardRegion::create();
3617             region->m_next = nextRegion.copyRef();
3618             region = nextRegion.ptr();
3619         }
3620         
3621         if (range.peek().functionId() != CSSValueDashboardRegion)
3622             return nullptr;
3623         
3624         CSSParserTokenRange rangeCopy = range;
3625         CSSParserTokenRange args = consumeFunction(rangeCopy);
3626         
3627         // First arg is a label.
3628         if (args.peek().type() != IdentToken)
3629             return nullptr;
3630         region->m_label = args.consumeIncludingWhitespace().value().toString();
3631         
3632         // Comma is optional, so don't fail if we can't consume one.
3633         requireCommas = consumeCommaIncludingWhitespace(args);
3634
3635         // Second arg is a type.
3636         if (args.peek().type() != IdentToken)
3637             return nullptr;
3638         region->m_geometryType = args.consumeIncludingWhitespace().value().toString();
3639         if (equalLettersIgnoringASCIICase(region->m_geometryType, "circle"))
3640             region->m_isCircle = true;
3641         else if (equalLettersIgnoringASCIICase(region->m_geometryType, "rectangle"))
3642             region->m_isRectangle = true;
3643         else
3644             return nullptr;
3645         
3646         if (args.atEnd()) {
3647             // This originally used CSSValueInvalid by accident. It might be more logical to use something else.
3648             RefPtr<CSSPrimitiveValue> amount = CSSValuePool::singleton().createIdentifierValue(CSSValueInvalid);
3649             region->setTop(amount.copyRef());
3650             region->setRight(amount.copyRef());
3651             region->setBottom(amount.copyRef());
3652             region->setLeft(WTFMove(amount));
3653             range = rangeCopy;
3654             continue;
3655         }
3656         
3657         // Next four arguments must be offset numbers or auto.
3658         for (int i = 0; i < 4; ++i) {
3659             if (args.atEnd() || (requireCommas && !consumeCommaIncludingWhitespace(args)))
3660                 return nullptr;
3661
3662             if (args.atEnd())
3663                 return nullptr;
3664             
3665             RefPtr<CSSPrimitiveValue> amount;
3666             if (args.peek().id() == CSSValueAuto)
3667                 amount = consumeIdent(args);
3668             else
3669                 amount = consumeLength(args, mode, ValueRangeAll);
3670         
3671             if (!i)
3672                 region->setTop(WTFMove(amount));
3673             else if (i == 1)
3674                 region->setRight(WTFMove(amount));
3675             else if (i == 2)
3676                 region->setBottom(WTFMove(amount));
3677             else
3678                 region->setLeft(WTFMove(amount));
3679         }
3680         
3681         if (!args.atEnd())
3682             return nullptr;
3683         
3684         range = rangeCopy;
3685     }
3686     
3687     return CSSValuePool::singleton().createValue(RefPtr<DashboardRegion>(WTFMove(firstRegion)));
3688 }
3689     
3690 #endif
3691
3692 RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, CSSPropertyID currentShorthand)
3693 {
3694     if (CSSParserFastPaths::isKeywordPropertyID(property)) {
3695         if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_range.peek().id(), m_context.mode, m_styleSheetContents))
3696             return nullptr;
3697         return consumeIdent(m_range);
3698     }
3699     switch (property) {
3700     case CSSPropertyWillChange:
3701         return consumeWillChange(m_range);
3702     case CSSPropertyPage:
3703         return consumePage(m_range);
3704     case CSSPropertyQuotes:
3705         return consumeQuotes(m_range);
3706     case CSSPropertyFontVariantCaps:
3707         return consumeFontVariantCaps(m_range);
3708     case CSSPropertyFontVariantLigatures:
3709         return consumeFontVariantLigatures(m_range);
3710     case CSSPropertyFontVariantNumeric:
3711         return consumeFontVariantNumeric(m_range);
3712     case CSSPropertyFontVariantEastAsian:
3713         return consumeFontVariantEastAsian(m_range);
3714     case CSSPropertyFontFeatureSettings:
3715         return consumeFontFeatureSettings(m_range);
3716     case CSSPropertyFontFamily:
3717         return consumeFontFamily(m_range);
3718     case CSSPropertyFontWeight:
3719         return consumeFontWeight(m_range);
3720     case CSSPropertyFontSynthesis:
3721         return consumeFontSynthesis(m_range);
3722 #if ENABLE(VARIATION_FONTS)
3723     case CSSPropertyFontVariationSettings:
3724         if (m_context.variationFontsEnabled)
3725             return consumeFontVariationSettings(m_range);
3726         return nullptr;
3727 #endif
3728     case CSSPropertyLetterSpacing:
3729         return consumeLetterSpacing(m_range, m_context.mode);
3730     case CSSPropertyWordSpacing:
3731         return consumeWordSpacing(m_range, m_context.mode);
3732     case CSSPropertyTabSize:
3733         return consumeTabSize(m_range, m_context.mode);
3734 #if ENABLE(TEXT_AUTOSIZING)
3735     case CSSPropertyWebkitTextSizeAdjust:
3736         // FIXME: Support toggling the validation of this property via a runtime setting that is independent of
3737         // whether isTextAutosizingEnabled() is true. We want to enable this property on iOS, when simulating
3738         // a iOS device in Safari's responsive design mode and when optionally enabled in DRT/WTR. Otherwise,
3739         // this property should be disabled by default.
3740 #if !PLATFORM(IOS)
3741         if (!m_context.textAutosizingEnabled)
3742             return nullptr;
3743 #endif
3744         return consumeTextSizeAdjust(m_range, m_context.mode);
3745 #endif
3746     case CSSPropertyFontSize:
3747         return consumeFontSize(m_range, m_context.mode, UnitlessQuirk::Allow);
3748     case CSSPropertyLineHeight:
3749         return consumeLineHeight(m_range, m_context.mode);
3750     case CSSPropertyWebkitBorderHorizontalSpacing:
3751     case CSSPropertyWebkitBorderVerticalSpacing:
3752         return consumeLength(m_range, m_context.mode, ValueRangeNonNegative);
3753     case CSSPropertyCounterIncrement:
3754     case CSSPropertyCounterReset:
3755         return consumeCounter(m_range, property == CSSPropertyCounterIncrement ? 1 : 0);
3756     case CSSPropertySize:
3757         return consumeSize(m_range, m_context.mode);
3758     case CSSPropertyTextIndent:
3759         return consumeTextIndent(m_range, m_context.mode);
3760     case CSSPropertyMaxWidth:
3761     case CSSPropertyMaxHeight:
3762         return consumeMaxWidthOrHeight(m_range, m_context, UnitlessQuirk::Allow);
3763     case CSSPropertyWebkitMaxLogicalWidth:
3764     case CSSPropertyWebkitMaxLogicalHeight:
3765         return consumeMaxWidthOrHeight(m_range, m_context);
3766     case CSSPropertyMinWidth:
3767     case CSSPropertyMinHeight:
3768     case CSSPropertyWidth:
3769     case CSSPropertyHeight:
3770         return consumeWidthOrHeight(m_range, m_context, UnitlessQuirk::Allow);
3771     case CSSPropertyWebkitMinLogicalWidth:
3772     case CSSPropertyWebkitMinLogicalHeight:
3773     case CSSPropertyWebkitLogicalWidth:
3774     case CSSPropertyWebkitLogicalHeight:
3775         return consumeWidthOrHeight(m_range, m_context);
3776     case CSSPropertyMarginTop:
3777     case CSSPropertyMarginRight:
3778     case CSSPropertyMarginBottom:
3779     case CSSPropertyMarginLeft:
3780     case CSSPropertyBottom:
3781     case CSSPropertyLeft:
3782     case CSSPropertyRight:
3783     case CSSPropertyTop:
3784         return consumeMarginOrOffset(m_range, m_context.mode, UnitlessQuirk::Allow);
3785     case CSSPropertyWebkitMarginStart:
3786     case CSSPropertyWebkitMarginEnd:
3787     case CSSPropertyWebkitMarginBefore:
3788     case CSSPropertyWebkitMarginAfter:
3789         return consumeMarginOrOffset(m_range, m_context.mode, UnitlessQuirk::Forbid);
3790     case CSSPropertyPaddingTop:
3791     case CSSPropertyPaddingRight:
3792     case CSSPropertyPaddingBottom:
3793     case CSSPropertyPaddingLeft:
3794         return consumeLengthOrPercent(m_range, m_context.mode, ValueRangeNonNegative, UnitlessQuirk::Allow);
3795     case CSSPropertyWebkitPaddingStart:
3796     case CSSPropertyWebkitPaddingEnd:
3797     case CSSPropertyWebkitPaddingBefore:
3798     case CSSPropertyWebkitPaddingAfter:
3799         return consumeLengthOrPercent(m_range, m_context.mode, ValueRangeNonNegative, UnitlessQuirk::Forbid);
3800     case CSSPropertyClip:
3801         return consumeClip(m_range, m_context.mode);
3802 #if ENABLE(TOUCH_EVENTS)
3803     case CSSPropertyTouchAction:
3804         return consumeTouchAction(m_range);
3805 #endif
3806     case CSSPropertyObjectPosition:
3807         return consumePosition(m_range, m_context.mode, UnitlessQuirk::Forbid);
3808     case CSSPropertyWebkitLineClamp:
3809         return consumeLineClamp(m_range);
3810     case CSSPropertyWebkitFontSizeDelta:
3811         return consumeLength(m_range, m_context.mode, ValueRangeAll, UnitlessQuirk::Allow);
3812     case CSSPropertyWebkitHyphenateCharacter:
3813     case CSSPropertyWebkitLocale:
3814         return consumeLocale(m_range);
3815     case CSSPropertyWebkitHyphenateLimitBefore:
3816     case CSSPropertyWebkitHyphenateLimitAfter:
3817         return consumeHyphenateLimit(m_range, CSSValueAuto);
3818     case CSSPropertyWebkitHyphenateLimitLines:
3819         return consumeHyphenateLimit(m_range, CSSValueNoLimit);
3820     case CSSPropertyColumnWidth:
3821         return consumeColumnWidth(m_range);
3822     case CSSPropertyColumnCount:
3823         return consumeColumnCount(m_range);
3824     case CSSPropertyColumnGap:
3825         return consumeColumnGap(m_range, m_context.mode);
3826     case CSSPropertyColumnSpan:
3827         return consumeColumnSpan(m_range);
3828     case CSSPropertyZoom:
3829         return consumeZoom(m_range, m_context);
3830     case CSSPropertyAnimationDelay:
3831     case CSSPropertyTransitionDelay:
3832     case CSSPropertyAnimationDirection:
3833     case CSSPropertyAnimationDuration:
3834     case CSSPropertyTransitionDuration:
3835     case CSSPropertyAnimationFillMode:
3836     case CSSPropertyAnimationIterationCount:
3837     case CSSPropertyAnimationName:
3838     case CSSPropertyAnimationPlayState:
3839     case CSSPropertyTransitionProperty:
3840     case CSSPropertyAnimationTimingFunction:
3841     case CSSPropertyTransitionTimingFunction:
3842 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
3843     case CSSPropertyWebkitAnimationTrigger:
3844 #endif
3845         return consumeAnimationPropertyList(property, m_range, m_context);
3846 #if ENABLE(CSS_GRID_LAYOUT)
3847     case CSSPropertyGridColumnGap:
3848     case CSSPropertyGridRowGap:
3849         return consumeLength(m_range, m_context.mode, ValueRangeNonNegative);
3850 #endif
3851     case CSSPropertyShapeMargin:
3852         return consumeLengthOrPercent(m_range, m_context.mode, ValueRangeNonNegative);
3853     case CSSPropertyShapeImageThreshold:
3854         return consumeNumber(m_range, ValueRangeAll);
3855     case CSSPropertyWebkitBoxOrdinalGroup:
3856  &nb