2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004-2015 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8 * Copyright (C) 2012, 2013 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * Copyright (C) 2014 Google Inc. All rights reserved.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public License
23 * along with this library; see the file COPYING.LIB. If not, write to
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
29 #include "CSSParser.h"
31 #include "CSSAnimationTriggerScrollValue.h"
32 #include "CSSAspectRatioValue.h"
33 #include "CSSBasicShapes.h"
34 #include "CSSBorderImage.h"
35 #include "CSSBorderImageSliceValue.h"
36 #include "CSSCanvasValue.h"
37 #include "CSSContentDistributionValue.h"
38 #include "CSSCrossfadeValue.h"
39 #include "CSSCursorImageValue.h"
40 #include "CSSCustomPropertyValue.h"
41 #include "CSSFilterImageValue.h"
42 #include "CSSFontFaceRule.h"
43 #include "CSSFontFaceSrcValue.h"
44 #include "CSSFontFeatureValue.h"
45 #include "CSSFontValue.h"
46 #include "CSSFunctionValue.h"
47 #include "CSSGradientValue.h"
48 #include "CSSImageValue.h"
49 #include "CSSInheritedValue.h"
50 #include "CSSInitialValue.h"
51 #include "CSSKeyframeRule.h"
52 #include "CSSKeyframesRule.h"
53 #include "CSSLineBoxContainValue.h"
54 #include "CSSMediaRule.h"
55 #include "CSSNamedImageValue.h"
56 #include "CSSPageRule.h"
57 #include "CSSPrimitiveValue.h"
58 #include "CSSPrimitiveValueMappings.h"
59 #include "CSSPropertySourceData.h"
60 #include "CSSReflectValue.h"
61 #include "CSSRevertValue.h"
62 #include "CSSSelector.h"
63 #include "CSSShadowValue.h"
64 #include "CSSStyleSheet.h"
65 #include "CSSTimingFunctionValue.h"
66 #include "CSSUnicodeRangeValue.h"
67 #include "CSSUnsetValue.h"
68 #include "CSSValueKeywords.h"
69 #include "CSSValueList.h"
70 #include "CSSValuePool.h"
71 #include "CSSVariableDependentValue.h"
74 #include "FloatConversion.h"
76 #include "HTMLOptGroupElement.h"
77 #include "HTMLParserIdioms.h"
78 #include "HashTools.h"
79 #include "MediaList.h"
80 #include "MediaQueryExp.h"
82 #include "PageConsoleClient.h"
85 #include "RenderTheme.h"
86 #include "RuntimeEnabledFeatures.h"
87 #include "SVGParserUtilities.h"
88 #include "SVGPathByteStream.h"
89 #include "SVGPathUtilities.h"
90 #include "SelectorChecker.h"
91 #include "SelectorCheckerTestFunctions.h"
93 #include "StyleProperties.h"
94 #include "StylePropertyShorthand.h"
95 #include "StylePropertyShorthandFunctions.h"
96 #include "StyleRule.h"
97 #include "StyleRuleImport.h"
98 #include "StyleSheetContents.h"
99 #include "TextEncoding.h"
100 #include "WebKitCSSFilterValue.h"
101 #include "WebKitCSSRegionRule.h"
102 #include "WebKitCSSTransformValue.h"
105 #include <wtf/HexNumber.h>
106 #include <wtf/NeverDestroyed.h>
107 #include <wtf/StdLibExtras.h>
108 #include <wtf/dtoa.h>
109 #include <wtf/text/StringBuffer.h>
110 #include <wtf/text/StringBuilder.h>
111 #include <wtf/text/StringImpl.h>
113 #if ENABLE(CSS_GRID_LAYOUT)
114 #include "CSSGridAutoRepeatValue.h"
115 #include "CSSGridLineNamesValue.h"
116 #include "CSSGridTemplateAreasValue.h"
119 #if ENABLE(CSS_IMAGE_SET)
120 #include "CSSImageSetValue.h"
123 #if ENABLE(CSS_SCROLL_SNAP)
124 #include "LengthRepeat.h"
127 #if ENABLE(DASHBOARD_SUPPORT)
128 #include "DashboardRegion.h"
134 extern int cssyydebug;
137 extern int cssyyparse(WebCore::CSSParser*);
148 class ImplicitScope {
149 WTF_MAKE_NONCOPYABLE(ImplicitScope);
151 ImplicitScope(WebCore::CSSParser& parser, PropertyType propertyType)
154 m_parser.m_implicitShorthand = propertyType == PropertyImplicit;
159 m_parser.m_implicitShorthand = false;
163 WebCore::CSSParser& m_parser;
170 const unsigned CSSParser::invalidParsedPropertiesCount = std::numeric_limits<unsigned>::max();
171 static const double MAX_SCALE = 1000000;
173 template<unsigned length> bool equalLettersIgnoringASCIICase(const CSSParserValue& value, const char (&lowercaseLetters)[length])
175 ASSERT(value.unit == CSSPrimitiveValue::CSS_IDENT || value.unit == CSSPrimitiveValue::CSS_STRING);
176 return equalLettersIgnoringASCIICase(value.string, lowercaseLetters);
179 static bool hasPrefix(const char* string, unsigned length, const char* prefix)
181 for (unsigned i = 0; i < length; ++i) {
184 if (string[i] != prefix[i])
190 template<typename... Args>
191 static Ref<CSSPrimitiveValue> createPrimitiveValuePair(Args&&... args)
193 return CSSValuePool::singleton().createValue(Pair::create(std::forward<Args>(args)...));
196 class AnimationParseContext {
198 AnimationParseContext() = default;
200 void commitFirstAnimation()
202 m_firstAnimationCommitted = true;
205 bool hasCommittedFirstAnimation() const
207 return m_firstAnimationCommitted;
210 void commitAnimationPropertyKeyword()
212 m_animationPropertyKeywordAllowed = false;
215 bool animationPropertyKeywordAllowed() const
217 return m_animationPropertyKeywordAllowed;
220 bool hasSeenAnimationPropertyKeyword() const
222 return m_hasSeenAnimationPropertyKeyword;
225 void sawAnimationPropertyKeyword()
227 m_hasSeenAnimationPropertyKeyword = true;
231 bool m_animationPropertyKeywordAllowed { true };
232 bool m_firstAnimationCommitted { false };
233 bool m_hasSeenAnimationPropertyKeyword { false };
236 const CSSParserContext& strictCSSParserContext()
238 static NeverDestroyed<CSSParserContext> strictContext(CSSStrictMode);
239 return strictContext;
242 CSSParserContext::CSSParserContext(CSSParserMode mode, const URL& baseURL)
245 #if ENABLE(CSS_GRID_LAYOUT)
246 , cssGridLayoutEnabled(RuntimeEnabledFeatures::sharedFeatures().isCSSGridLayoutEnabled())
250 // FIXME: Force the site specific quirk below to work on iOS. Investigating other site specific quirks
251 // to see if we can enable the preference all together is to be handled by:
252 // <rdar://problem/8493309> Investigate Enabling Site Specific Quirks in MobileSafari and UIWebView
253 needsSiteSpecificQuirks = true;
257 CSSParserContext::CSSParserContext(Document& document, const URL& baseURL, const String& charset)
258 : baseURL(baseURL.isNull() ? document.baseURL() : baseURL)
260 , mode(document.inQuirksMode() ? CSSQuirksMode : CSSStrictMode)
261 , isHTMLDocument(document.isHTMLDocument())
262 #if ENABLE(CSS_GRID_LAYOUT)
263 , cssGridLayoutEnabled(document.isCSSGridLayoutEnabled())
266 if (Settings* settings = document.settings()) {
267 needsSiteSpecificQuirks = settings->needsSiteSpecificQuirks();
268 enforcesCSSMIMETypeInNoQuirksMode = settings->enforceCSSMIMETypeInNoQuirksMode();
269 useLegacyBackgroundSizeShorthandBehavior = settings->useLegacyBackgroundSizeShorthandBehavior();
270 #if ENABLE(IOS_TEXT_AUTOSIZING)
271 textAutosizingEnabled = settings->textAutosizingEnabled();
273 springTimingFunctionEnabled = settings->springTimingFunctionEnabled();
277 // FIXME: Force the site specific quirk below to work on iOS. Investigating other site specific quirks
278 // to see if we can enable the preference all together is to be handled by:
279 // <rdar://problem/8493309> Investigate Enabling Site Specific Quirks in MobileSafari and UIWebView
280 needsSiteSpecificQuirks = true;
284 bool operator==(const CSSParserContext& a, const CSSParserContext& b)
286 return a.baseURL == b.baseURL
287 && a.charset == b.charset
289 && a.isHTMLDocument == b.isHTMLDocument
290 #if ENABLE(CSS_GRID_LAYOUT)
291 && a.cssGridLayoutEnabled == b.cssGridLayoutEnabled
293 && a.needsSiteSpecificQuirks == b.needsSiteSpecificQuirks
294 && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode
295 && a.useLegacyBackgroundSizeShorthandBehavior == b.useLegacyBackgroundSizeShorthandBehavior
296 && a.springTimingFunctionEnabled == b.springTimingFunctionEnabled;
299 CSSParser::CSSParser(const CSSParserContext& context)
307 CSSParser::~CSSParser()
311 template<typename CharacterType> ALWAYS_INLINE static void convertToASCIILowercaseInPlace(CharacterType* characters, unsigned length)
313 for (unsigned i = 0; i < length; ++i)
314 characters[i] = toASCIILower(characters[i]);
317 void CSSParserString::convertToASCIILowercaseInPlace()
320 WebCore::convertToASCIILowercaseInPlace(characters8(), length());
322 WebCore::convertToASCIILowercaseInPlace(characters16(), length());
325 void CSSParser::setupParser(const char* prefix, unsigned prefixLength, StringView string, const char* suffix, unsigned suffixLength)
327 m_parsedTextPrefixLength = prefixLength;
328 unsigned stringLength = string.length();
329 unsigned length = stringLength + m_parsedTextPrefixLength + suffixLength + 1;
332 if (!stringLength || string.is8Bit()) {
333 m_dataStart8 = std::make_unique<LChar[]>(length);
334 for (unsigned i = 0; i < m_parsedTextPrefixLength; ++i)
335 m_dataStart8[i] = prefix[i];
338 memcpy(m_dataStart8.get() + m_parsedTextPrefixLength, string.characters8(), stringLength * sizeof(LChar));
340 unsigned start = m_parsedTextPrefixLength + stringLength;
341 unsigned end = start + suffixLength;
342 for (unsigned i = start; i < end; i++)
343 m_dataStart8[i] = suffix[i - start];
345 m_dataStart8[length - 1] = '\0';
347 m_is8BitSource = true;
348 m_currentCharacter8 = m_dataStart8.get();
349 m_currentCharacter16 = nullptr;
350 setTokenStart<LChar>(m_currentCharacter8);
351 m_lexFunc = &CSSParser::realLex<LChar>;
355 m_dataStart16 = std::make_unique<UChar[]>(length);
356 for (unsigned i = 0; i < m_parsedTextPrefixLength; ++i)
357 m_dataStart16[i] = prefix[i];
359 ASSERT(stringLength);
360 memcpy(m_dataStart16.get() + m_parsedTextPrefixLength, string.characters16(), stringLength * sizeof(UChar));
362 unsigned start = m_parsedTextPrefixLength + stringLength;
363 unsigned end = start + suffixLength;
364 for (unsigned i = start; i < end; i++)
365 m_dataStart16[i] = suffix[i - start];
367 m_dataStart16[length - 1] = '\0';
369 m_is8BitSource = false;
370 m_currentCharacter8 = nullptr;
371 m_currentCharacter16 = m_dataStart16.get();
372 setTokenStart<UChar>(m_currentCharacter16);
373 m_lexFunc = &CSSParser::realLex<UChar>;
376 void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, const TextPosition& textPosition, RuleSourceDataList* ruleSourceDataResult, bool logErrors)
378 setStyleSheet(sheet);
379 m_defaultNamespace = starAtom; // Reset the default namespace.
380 if (ruleSourceDataResult)
381 m_currentRuleDataStack = std::make_unique<RuleSourceDataList>();
382 m_ruleSourceDataResult = ruleSourceDataResult;
384 m_logErrors = logErrors && sheet->singleOwnerDocument() && !sheet->baseURL().isEmpty() && sheet->singleOwnerDocument()->page();
385 m_ignoreErrorsInDeclaration = false;
386 m_sheetStartLineNumber = textPosition.m_line.zeroBasedInt();
387 m_sheetStartColumnNumber = textPosition.m_column.zeroBasedInt();
388 m_lineNumber = m_sheetStartLineNumber;
389 m_columnOffsetForLine = 0;
390 setupParser("", string, "");
392 sheet->shrinkToFit();
393 m_currentRuleDataStack.reset();
394 m_ruleSourceDataResult = nullptr;
396 m_ignoreErrorsInDeclaration = false;
400 RefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string)
402 setStyleSheet(sheet);
403 m_allowNamespaceDeclarations = false;
404 setupParser("@-webkit-rule{", string, "} ");
409 RefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet, const String& string)
411 setStyleSheet(sheet);
412 setupParser("@-webkit-keyframe-rule{ ", string, "} ");
417 bool CSSParser::parseSupportsCondition(const String& string)
419 m_supportsCondition = false;
420 // can't use { because tokenizer state switches from supports to initial state when it sees { token.
421 // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
422 setupParser("@-webkit-supports-condition ", string, "} ");
424 return m_supportsCondition;
427 static inline bool isColorPropertyID(CSSPropertyID propertyId)
429 switch (propertyId) {
430 case CSSPropertyColor:
431 case CSSPropertyBackgroundColor:
432 case CSSPropertyBorderBottomColor:
433 case CSSPropertyBorderLeftColor:
434 case CSSPropertyBorderRightColor:
435 case CSSPropertyBorderTopColor:
436 case CSSPropertyOutlineColor:
437 case CSSPropertyTextLineThroughColor:
438 case CSSPropertyTextOverlineColor:
439 case CSSPropertyTextUnderlineColor:
440 case CSSPropertyWebkitBorderAfterColor:
441 case CSSPropertyWebkitBorderBeforeColor:
442 case CSSPropertyWebkitBorderEndColor:
443 case CSSPropertyWebkitBorderStartColor:
444 case CSSPropertyColumnRuleColor:
445 case CSSPropertyWebkitTextDecorationColor:
446 case CSSPropertyWebkitTextEmphasisColor:
447 case CSSPropertyWebkitTextFillColor:
448 case CSSPropertyWebkitTextStrokeColor:
455 bool CSSParser::isValidSystemColorValue(CSSValueID valueID)
457 return valueID >= CSSValueAqua && valueID <= CSSValueAppleSystemYellow;
460 static bool validPrimitiveValueColor(CSSValueID valueID, bool strict = false)
462 return (valueID == CSSValueWebkitText || valueID == CSSValueCurrentcolor || valueID == CSSValueMenu
463 || CSSParser::isValidSystemColorValue(valueID) || valueID == CSSValueAlpha
464 || (valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWebkitText && !strict));
467 static CSSParser::ParseResult parseColorValue(MutableStyleProperties& declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
469 ASSERT(!string.isEmpty());
470 bool strict = isStrictParserMode(cssParserMode);
471 if (!isColorPropertyID(propertyId))
472 return CSSParser::ParseResult::Error;
474 CSSParserString cssString;
475 cssString.init(string);
476 CSSValueID valueID = cssValueKeywordID(cssString);
477 if (validPrimitiveValueColor(valueID, strict)) {
478 auto value = CSSValuePool::singleton().createIdentifierValue(valueID);
479 return declaration.addParsedProperty(CSSProperty(propertyId, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
482 if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
483 return CSSParser::ParseResult::Error;
485 auto value = CSSValuePool::singleton().createColorValue(color);
486 return declaration.addParsedProperty(CSSProperty(propertyId, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
489 static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acceptsNegativeNumbers)
491 switch (propertyId) {
492 case CSSPropertyFontSize:
493 case CSSPropertyHeight:
494 case CSSPropertyWidth:
495 case CSSPropertyMinHeight:
496 case CSSPropertyMinWidth:
497 case CSSPropertyPaddingBottom:
498 case CSSPropertyPaddingLeft:
499 case CSSPropertyPaddingRight:
500 case CSSPropertyPaddingTop:
501 case CSSPropertyWebkitLogicalWidth:
502 case CSSPropertyWebkitLogicalHeight:
503 case CSSPropertyWebkitMinLogicalWidth:
504 case CSSPropertyWebkitMinLogicalHeight:
505 case CSSPropertyWebkitPaddingAfter:
506 case CSSPropertyWebkitPaddingBefore:
507 case CSSPropertyWebkitPaddingEnd:
508 case CSSPropertyWebkitPaddingStart:
509 #if ENABLE(CSS_GRID_LAYOUT)
510 case CSSPropertyGridColumnGap:
511 case CSSPropertyGridRowGap:
513 #if ENABLE(CSS_SHAPES)
514 case CSSPropertyWebkitShapeMargin:
516 acceptsNegativeNumbers = false;
518 case CSSPropertyBottom:
521 case CSSPropertyLeft:
522 case CSSPropertyMarginBottom:
523 case CSSPropertyMarginLeft:
524 case CSSPropertyMarginRight:
525 case CSSPropertyMarginTop:
529 case CSSPropertyRight:
531 case CSSPropertyWebkitMarginAfter:
532 case CSSPropertyWebkitMarginBefore:
533 case CSSPropertyWebkitMarginEnd:
534 case CSSPropertyWebkitMarginStart:
537 acceptsNegativeNumbers = true;
544 template <typename CharacterType>
545 static inline bool parseSimpleLength(const CharacterType* characters, unsigned& length, CSSPrimitiveValue::UnitTypes& unit, double& number)
547 if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') {
549 unit = CSSPrimitiveValue::CSS_PX;
550 } else if (length > 1 && characters[length - 1] == '%') {
552 unit = CSSPrimitiveValue::CSS_PERCENTAGE;
555 // We rely on charactersToDouble for validation as well. The function
556 // will set "ok" to "false" if the entire passed-in character range does
557 // not represent a double.
559 number = charactersToDouble(characters, length, &ok);
563 static CSSParser::ParseResult parseSimpleLengthValue(MutableStyleProperties& declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
565 ASSERT(!string.isEmpty());
566 bool acceptsNegativeNumbers;
567 if (!isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers))
568 return CSSParser::ParseResult::Error;
570 unsigned length = string.length();
572 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
574 if (string.is8Bit()) {
575 if (!parseSimpleLength(string.characters8(), length, unit, number))
576 return CSSParser::ParseResult::Error;
578 if (!parseSimpleLength(string.characters16(), length, unit, number))
579 return CSSParser::ParseResult::Error;
582 if (unit == CSSPrimitiveValue::CSS_NUMBER) {
583 if (number && isStrictParserMode(cssParserMode))
584 return CSSParser::ParseResult::Error;
585 unit = CSSPrimitiveValue::CSS_PX;
587 if (number < 0 && !acceptsNegativeNumbers)
588 return CSSParser::ParseResult::Error;
589 if (std::isinf(number))
590 return CSSParser::ParseResult::Error;
592 auto value = CSSValuePool::singleton().createValue(number, unit);
593 return declaration.addParsedProperty(CSSProperty(propertyId, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
596 static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int valueID, const CSSParserContext& parserContext, StyleSheetContents* styleSheetContents)
601 switch (propertyId) {
602 case CSSPropertyBorderCollapse: // collapse | separate | inherit
603 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate)
606 case CSSPropertyBorderTopStyle: // <border-style> | inherit
607 case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed |
608 case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset
609 case CSSPropertyBorderLeftStyle:
610 case CSSPropertyWebkitBorderAfterStyle:
611 case CSSPropertyWebkitBorderBeforeStyle:
612 case CSSPropertyWebkitBorderEndStyle:
613 case CSSPropertyWebkitBorderStartStyle:
614 case CSSPropertyColumnRuleStyle:
615 if (valueID >= CSSValueNone && valueID <= CSSValueDouble)
618 case CSSPropertyBoxSizing:
619 if (valueID == CSSValueBorderBox || valueID == CSSValueContentBox)
622 case CSSPropertyCaptionSide: // top | bottom | left | right | inherit
623 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueTop || valueID == CSSValueBottom)
626 case CSSPropertyClear: // none | left | right | both | inherit
627 if (valueID == CSSValueNone || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueBoth)
630 case CSSPropertyDirection: // ltr | rtl | inherit
631 if (valueID == CSSValueLtr || valueID == CSSValueRtl)
634 case CSSPropertyDisplay:
635 // inline | block | list-item | inline-block | table |
636 // inline-table | table-row-group | table-header-group | table-footer-group | table-row |
637 // table-column-group | table-column | table-cell | table-caption | -webkit-box | -webkit-inline-box | none | inherit
638 // flex | -webkit-flex | inline-flex | -webkit-inline-flex | grid | inline-grid | contents
639 if ((valueID >= CSSValueInline && valueID <= CSSValueContents) || valueID == CSSValueNone)
641 #if ENABLE(CSS_GRID_LAYOUT)
642 if (parserContext.cssGridLayoutEnabled && (valueID == CSSValueGrid || valueID == CSSValueInlineGrid))
647 case CSSPropertyEmptyCells: // show | hide | inherit
648 if (valueID == CSSValueShow || valueID == CSSValueHide)
651 case CSSPropertyFloat: // left | right | none | center (for buggy CSS, maps to none)
652 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueNone || valueID == CSSValueCenter)
655 case CSSPropertyFontStyle: // normal | italic | oblique | inherit
656 if (valueID == CSSValueNormal || valueID == CSSValueItalic || valueID == CSSValueOblique)
659 case CSSPropertyImageRendering: // auto | optimizeSpeed | optimizeQuality | -webkit-crisp-edges | -webkit-optimize-contrast | crisp-edges | pixelated
660 // optimizeSpeed and optimizeQuality are deprecated; a user agent must accept them as valid values but must treat them as having the same behavior as pixelated and auto respectively.
661 if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizequality
662 || valueID == CSSValueWebkitCrispEdges || valueID == CSSValueWebkitOptimizeContrast || valueID == CSSValueCrispEdges || valueID == CSSValuePixelated)
665 case CSSPropertyListStylePosition: // inside | outside | inherit
666 if (valueID == CSSValueInside || valueID == CSSValueOutside)
669 case CSSPropertyListStyleType:
670 // See section CSS_PROP_LIST_STYLE_TYPE of file CSSValueKeywords.in
671 // for the list of supported list-style-types.
672 if ((valueID >= CSSValueDisc && valueID <= CSSValueKatakanaIroha) || valueID == CSSValueNone)
675 case CSSPropertyObjectFit:
676 if (valueID == CSSValueFill || valueID == CSSValueContain || valueID == CSSValueCover || valueID == CSSValueNone || valueID == CSSValueScaleDown)
679 case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto | inherit
680 if (valueID == CSSValueAuto || valueID == CSSValueNone || (valueID >= CSSValueInset && valueID <= CSSValueDouble))
683 case CSSPropertyOverflowWrap: // normal | break-word
684 case CSSPropertyWordWrap:
685 if (valueID == CSSValueNormal || valueID == CSSValueBreakWord)
688 #if ENABLE(TOUCH_EVENTS)
689 case CSSPropertyTouchAction: // auto | manipulation
690 if (valueID == CSSValueAuto || valueID == CSSValueManipulation)
694 #if ENABLE(CSS_SCROLL_SNAP)
695 case CSSPropertyWebkitScrollSnapType: // none | mandatory | proximity
696 if (valueID == CSSValueNone || valueID == CSSValueMandatory || valueID == CSSValueProximity)
700 case CSSPropertyOverflowX: // visible | hidden | scroll | auto | overlay | inherit
701 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay)
704 case CSSPropertyOverflowY: // visible | hidden | scroll | auto | overlay | inherit | -webkit-paged-x | -webkit-paged-y
705 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitPagedX || valueID == CSSValueWebkitPagedY)
708 case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | inherit
709 case CSSPropertyPageBreakBefore:
710 case CSSPropertyWebkitColumnBreakAfter:
711 case CSSPropertyWebkitColumnBreakBefore:
712 if (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight)
715 case CSSPropertyPageBreakInside: // avoid | auto | inherit
716 case CSSPropertyWebkitColumnBreakInside:
717 if (valueID == CSSValueAuto || valueID == CSSValueAvoid)
720 case CSSPropertyPointerEvents:
721 // none | visiblePainted | visibleFill | visibleStroke | visible |
722 // painted | fill | stroke | auto | all | inherit
723 if (valueID == CSSValueVisible || valueID == CSSValueNone || valueID == CSSValueAll || valueID == CSSValueAuto || (valueID >= CSSValueVisiblepainted && valueID <= CSSValueStroke))
726 case CSSPropertyPosition: // static | relative | absolute | fixed | sticky | inherit
727 if (valueID == CSSValueStatic || valueID == CSSValueRelative || valueID == CSSValueAbsolute || valueID == CSSValueFixed || valueID == CSSValueWebkitSticky)
730 case CSSPropertyResize: // none | both | horizontal | vertical | auto
731 if (valueID == CSSValueNone || valueID == CSSValueBoth || valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueAuto)
734 case CSSPropertySpeak: // none | normal | spell-out | digits | literal-punctuation | no-punctuation | inherit
735 if (valueID == CSSValueNone || valueID == CSSValueNormal || valueID == CSSValueSpellOut || valueID == CSSValueDigits || valueID == CSSValueLiteralPunctuation || valueID == CSSValueNoPunctuation)
738 case CSSPropertyTableLayout: // auto | fixed | inherit
739 if (valueID == CSSValueAuto || valueID == CSSValueFixed)
742 case CSSPropertyTextLineThroughMode:
743 case CSSPropertyTextOverlineMode:
744 case CSSPropertyTextUnderlineMode:
745 if (valueID == CSSValueContinuous || valueID == CSSValueSkipWhiteSpace)
748 case CSSPropertyTextLineThroughStyle:
749 case CSSPropertyTextOverlineStyle:
750 case CSSPropertyTextUnderlineStyle:
751 if (valueID == CSSValueNone || valueID == CSSValueSolid || valueID == CSSValueDouble || valueID == CSSValueDashed || valueID == CSSValueDotDash || valueID == CSSValueDotDotDash || valueID == CSSValueWave)
754 case CSSPropertyTextOverflow: // clip | ellipsis
755 if (valueID == CSSValueClip || valueID == CSSValueEllipsis)
758 case CSSPropertyTextRendering: // auto | optimizeSpeed | optimizeLegibility | geometricPrecision
759 if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizelegibility || valueID == CSSValueGeometricprecision)
762 case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none | inherit
763 if ((valueID >= CSSValueCapitalize && valueID <= CSSValueLowercase) || valueID == CSSValueNone)
766 case CSSPropertyVisibility: // visible | hidden | collapse | inherit
767 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueCollapse)
770 case CSSPropertyWebkitAppearance:
771 if ((valueID >= CSSValueCheckbox && valueID <= CSSValueCapsLockIndicator) || valueID == CSSValueNone)
774 case CSSPropertyWebkitBackfaceVisibility:
775 if (valueID == CSSValueVisible || valueID == CSSValueHidden)
778 #if ENABLE(CSS_COMPOSITING)
779 case CSSPropertyMixBlendMode:
780 if (valueID == CSSValueNormal || valueID == CSSValueMultiply || valueID == CSSValueScreen
781 || valueID == CSSValueOverlay || valueID == CSSValueDarken || valueID == CSSValueLighten || valueID == CSSValueColorDodge
782 || valueID == CSSValueColorBurn || valueID == CSSValueHardLight || valueID == CSSValueSoftLight || valueID == CSSValueDifference
783 || valueID == CSSValueExclusion || valueID == CSSValuePlusDarker || valueID == CSSValuePlusLighter)
786 case CSSPropertyIsolation:
787 if (valueID == CSSValueAuto || valueID == CSSValueIsolate)
791 case CSSPropertyWebkitBorderFit:
792 if (valueID == CSSValueBorder || valueID == CSSValueLines)
795 case CSSPropertyWebkitBoxAlign:
796 if (valueID == CSSValueStretch || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline)
799 #if ENABLE(CSS_BOX_DECORATION_BREAK)
800 case CSSPropertyWebkitBoxDecorationBreak:
801 if (valueID == CSSValueClone || valueID == CSSValueSlice)
805 case CSSPropertyWebkitBoxDirection:
806 if (valueID == CSSValueNormal || valueID == CSSValueReverse)
809 case CSSPropertyWebkitBoxLines:
810 if (valueID == CSSValueSingle || valueID == CSSValueMultiple)
813 case CSSPropertyWebkitBoxOrient:
814 if (valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueInlineAxis || valueID == CSSValueBlockAxis)
817 case CSSPropertyWebkitBoxPack:
818 if (valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueJustify)
821 case CSSPropertyColumnFill:
822 if (valueID == CSSValueAuto || valueID == CSSValueBalance)
825 case CSSPropertyFlexDirection:
826 if (valueID == CSSValueRow || valueID == CSSValueRowReverse || valueID == CSSValueColumn || valueID == CSSValueColumnReverse)
829 case CSSPropertyFlexWrap:
830 if (valueID == CSSValueNowrap || valueID == CSSValueWrap || valueID == CSSValueWrapReverse)
833 case CSSPropertyWebkitFontKerning:
834 if (valueID == CSSValueAuto || valueID == CSSValueNormal || valueID == CSSValueNone)
837 case CSSPropertyWebkitFontSmoothing:
838 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueAntialiased || valueID == CSSValueSubpixelAntialiased)
841 case CSSPropertyWebkitHyphens:
842 if (valueID == CSSValueNone || valueID == CSSValueManual || valueID == CSSValueAuto)
845 case CSSPropertyWebkitLineAlign:
846 if (valueID == CSSValueNone || valueID == CSSValueEdges)
849 case CSSPropertyWebkitLineBreak: // auto | loose | normal | strict | after-white-space
850 if (valueID == CSSValueAuto || valueID == CSSValueLoose || valueID == CSSValueNormal || valueID == CSSValueStrict || valueID == CSSValueAfterWhiteSpace)
853 case CSSPropertyWebkitLineSnap:
854 if (valueID == CSSValueNone || valueID == CSSValueBaseline || valueID == CSSValueContain)
857 case CSSPropertyWebkitMarginAfterCollapse:
858 case CSSPropertyWebkitMarginBeforeCollapse:
859 case CSSPropertyWebkitMarginBottomCollapse:
860 case CSSPropertyWebkitMarginTopCollapse:
861 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate || valueID == CSSValueDiscard)
864 case CSSPropertyWebkitMarqueeDirection:
865 if (valueID == CSSValueForwards || valueID == CSSValueBackwards || valueID == CSSValueAhead || valueID == CSSValueReverse || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueDown
866 || valueID == CSSValueUp || valueID == CSSValueAuto)
869 case CSSPropertyWebkitMarqueeStyle:
870 if (valueID == CSSValueNone || valueID == CSSValueSlide || valueID == CSSValueScroll || valueID == CSSValueAlternate)
873 case CSSPropertyWebkitNbspMode: // normal | space
874 if (valueID == CSSValueNormal || valueID == CSSValueSpace)
877 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
878 case CSSPropertyWebkitOverflowScrolling:
879 if (valueID == CSSValueAuto || valueID == CSSValueTouch)
883 case CSSPropertyWebkitPrintColorAdjust:
884 if (valueID == CSSValueExact || valueID == CSSValueEconomy)
887 #if ENABLE(CSS_REGIONS)
888 case CSSPropertyWebkitRegionBreakAfter:
889 case CSSPropertyWebkitRegionBreakBefore:
890 if (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight)
893 case CSSPropertyWebkitRegionBreakInside:
894 if (valueID == CSSValueAuto || valueID == CSSValueAvoid)
897 case CSSPropertyWebkitRegionFragment:
898 if (valueID == CSSValueAuto || valueID == CSSValueBreak)
902 case CSSPropertyWebkitRtlOrdering:
903 if (valueID == CSSValueLogical || valueID == CSSValueVisual)
907 case CSSPropertyWebkitRubyPosition:
908 if (valueID == CSSValueBefore || valueID == CSSValueAfter || valueID == CSSValueInterCharacter)
912 #if ENABLE(CSS3_TEXT)
913 case CSSPropertyWebkitTextAlignLast:
914 // auto | start | end | left | right | center | justify
915 if ((valueID >= CSSValueLeft && valueID <= CSSValueJustify) || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueAuto)
919 case CSSPropertyWebkitTextCombine:
920 if (valueID == CSSValueNone || valueID == CSSValueHorizontal)
923 #if ENABLE(CSS3_TEXT)
924 case CSSPropertyWebkitTextJustify:
925 // auto | none | inter-word | distribute
926 if (valueID == CSSValueInterWord || valueID == CSSValueDistribute || valueID == CSSValueAuto || valueID == CSSValueNone)
930 case CSSPropertyWebkitTextSecurity:
931 // disc | circle | square | none | inherit
932 if (valueID == CSSValueDisc || valueID == CSSValueCircle || valueID == CSSValueSquare || valueID == CSSValueNone)
935 #if ENABLE(IOS_TEXT_AUTOSIZING)
936 case CSSPropertyWebkitTextSizeAdjust:
937 if (!parserContext.textAutosizingEnabled)
940 if (valueID == CSSValueAuto || valueID == CSSValueNone)
944 case CSSPropertyTransformStyle:
945 case CSSPropertyWebkitTransformStyle:
946 if (valueID == CSSValueFlat || valueID == CSSValuePreserve3d)
949 case CSSPropertyWebkitUserDrag: // auto | none | element
950 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueElement)
953 case CSSPropertyWebkitUserModify: // read-only | read-write
954 if (valueID == CSSValueReadOnly || valueID == CSSValueReadWrite || valueID == CSSValueReadWritePlaintextOnly) {
955 if (styleSheetContents)
956 styleSheetContents->parserSetUsesStyleBasedEditability();
960 case CSSPropertyWebkitUserSelect: // auto | none | text | all
961 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueText)
963 if (valueID == CSSValueAll) {
964 if (styleSheetContents)
965 styleSheetContents->parserSetUsesStyleBasedEditability();
969 case CSSPropertyWebkitWritingMode:
970 if (valueID >= CSSValueHorizontalTb && valueID <= CSSValueHorizontalBt)
973 case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit
974 if (valueID == CSSValueNormal || valueID == CSSValuePre || valueID == CSSValuePreWrap || valueID == CSSValuePreLine || valueID == CSSValueNowrap)
977 case CSSPropertyWordBreak: // normal | break-all | keep-all | break-word (this is a custom extension)
978 if (valueID == CSSValueNormal || valueID == CSSValueBreakAll || valueID == CSSValueKeepAll || valueID == CSSValueBreakWord)
981 #if ENABLE(CSS_TRAILING_WORD)
982 case CSSPropertyAppleTrailingWord: // auto | -apple-partially-balanced
983 if (valueID == CSSValueAuto || valueID == CSSValueWebkitPartiallyBalanced)
987 case CSSPropertyFontVariantPosition: // normal | sub | super
988 if (valueID == CSSValueNormal || valueID == CSSValueSub || valueID == CSSValueSuper)
991 case CSSPropertyFontVariantCaps: // normal | small-caps | all-small-caps | petite-caps | all-petite-caps | unicase | titling-caps
992 if (valueID == CSSValueNormal || valueID == CSSValueSmallCaps || valueID == CSSValueAllSmallCaps || valueID == CSSValuePetiteCaps || valueID == CSSValueAllPetiteCaps || valueID == CSSValueUnicase || valueID == CSSValueTitlingCaps)
995 case CSSPropertyFontVariantAlternates: // We only support the normal and historical-forms values.
996 if (valueID == CSSValueNormal || valueID == CSSValueHistoricalForms)
1000 case CSSPropertyBreakAfter:
1001 case CSSPropertyBreakBefore:
1002 // auto | avoid | left | right | recto | verso | column | page | region | avoid-page | avoid-column | avoid-region
1003 if (valueID == CSSValueAuto || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight
1004 || valueID == CSSValueRecto || valueID == CSSValueVerso || valueID == CSSValueColumn || valueID == CSSValuePage
1005 || valueID == CSSValueRegion || valueID == CSSValueAvoidColumn || valueID == CSSValueAvoidPage || valueID == CSSValueAvoidRegion)
1008 case CSSPropertyBreakInside:
1009 // auto | avoid | avoid-page | avoid-column | avoid-region
1010 if (valueID == CSSValueAuto || valueID == CSSValueAvoid || valueID == CSSValueAvoidColumn || valueID == CSSValueAvoidPage || valueID == CSSValueAvoidRegion)
1014 ASSERT_NOT_REACHED();
1017 #if !ENABLE(CSS_GRID_LAYOUT)
1018 UNUSED_PARAM(parserContext);
1023 static inline bool isKeywordPropertyID(CSSPropertyID propertyId)
1025 switch (propertyId) {
1026 case CSSPropertyBorderBottomStyle:
1027 case CSSPropertyBorderCollapse:
1028 case CSSPropertyBorderLeftStyle:
1029 case CSSPropertyBorderRightStyle:
1030 case CSSPropertyBorderTopStyle:
1031 case CSSPropertyBoxSizing:
1032 case CSSPropertyBreakAfter:
1033 case CSSPropertyBreakBefore:
1034 case CSSPropertyBreakInside:
1035 case CSSPropertyCaptionSide:
1036 case CSSPropertyClear:
1037 case CSSPropertyDirection:
1038 case CSSPropertyDisplay:
1039 case CSSPropertyEmptyCells:
1040 case CSSPropertyFloat:
1041 case CSSPropertyFontStyle:
1042 case CSSPropertyImageRendering:
1043 case CSSPropertyListStylePosition:
1044 case CSSPropertyListStyleType:
1045 case CSSPropertyObjectFit:
1046 case CSSPropertyOutlineStyle:
1047 case CSSPropertyOverflowWrap:
1048 case CSSPropertyOverflowX:
1049 case CSSPropertyOverflowY:
1050 case CSSPropertyPageBreakAfter:
1051 case CSSPropertyPageBreakBefore:
1052 case CSSPropertyPageBreakInside:
1053 case CSSPropertyPointerEvents:
1054 case CSSPropertyPosition:
1055 case CSSPropertyResize:
1056 case CSSPropertySpeak:
1057 case CSSPropertyTableLayout:
1058 case CSSPropertyTextLineThroughMode:
1059 case CSSPropertyTextLineThroughStyle:
1060 case CSSPropertyTextOverflow:
1061 case CSSPropertyTextOverlineMode:
1062 case CSSPropertyTextOverlineStyle:
1063 case CSSPropertyTextRendering:
1064 case CSSPropertyTextTransform:
1065 case CSSPropertyTextUnderlineMode:
1066 case CSSPropertyTextUnderlineStyle:
1067 case CSSPropertyVisibility:
1068 case CSSPropertyWebkitAppearance:
1069 #if ENABLE(CSS_COMPOSITING)
1070 case CSSPropertyMixBlendMode:
1071 case CSSPropertyIsolation:
1073 case CSSPropertyWebkitBackfaceVisibility:
1074 case CSSPropertyWebkitBorderAfterStyle:
1075 case CSSPropertyWebkitBorderBeforeStyle:
1076 case CSSPropertyWebkitBorderEndStyle:
1077 case CSSPropertyWebkitBorderFit:
1078 case CSSPropertyWebkitBorderStartStyle:
1079 case CSSPropertyWebkitBoxAlign:
1080 #if ENABLE(CSS_BOX_DECORATION_BREAK)
1081 case CSSPropertyWebkitBoxDecorationBreak:
1083 case CSSPropertyWebkitBoxDirection:
1084 case CSSPropertyWebkitBoxLines:
1085 case CSSPropertyWebkitBoxOrient:
1086 case CSSPropertyWebkitBoxPack:
1087 case CSSPropertyWebkitColumnBreakAfter:
1088 case CSSPropertyWebkitColumnBreakBefore:
1089 case CSSPropertyWebkitColumnBreakInside:
1090 case CSSPropertyColumnFill:
1091 case CSSPropertyColumnRuleStyle:
1092 case CSSPropertyFlexDirection:
1093 case CSSPropertyFlexWrap:
1094 case CSSPropertyWebkitFontKerning:
1095 case CSSPropertyWebkitFontSmoothing:
1096 case CSSPropertyWebkitHyphens:
1097 case CSSPropertyWebkitLineAlign:
1098 case CSSPropertyWebkitLineBreak:
1099 case CSSPropertyWebkitLineSnap:
1100 case CSSPropertyWebkitMarginAfterCollapse:
1101 case CSSPropertyWebkitMarginBeforeCollapse:
1102 case CSSPropertyWebkitMarginBottomCollapse:
1103 case CSSPropertyWebkitMarginTopCollapse:
1104 case CSSPropertyWebkitMarqueeDirection:
1105 case CSSPropertyWebkitMarqueeStyle:
1106 case CSSPropertyWebkitNbspMode:
1107 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
1108 case CSSPropertyWebkitOverflowScrolling:
1110 case CSSPropertyWebkitPrintColorAdjust:
1111 #if ENABLE(CSS_REGIONS)
1112 case CSSPropertyWebkitRegionBreakAfter:
1113 case CSSPropertyWebkitRegionBreakBefore:
1114 case CSSPropertyWebkitRegionBreakInside:
1115 case CSSPropertyWebkitRegionFragment:
1117 case CSSPropertyWebkitRtlOrdering:
1118 case CSSPropertyWebkitRubyPosition:
1119 #if ENABLE(CSS3_TEXT)
1120 case CSSPropertyWebkitTextAlignLast:
1122 case CSSPropertyWebkitTextCombine:
1123 #if ENABLE(CSS3_TEXT)
1124 case CSSPropertyWebkitTextJustify:
1126 case CSSPropertyWebkitTextSecurity:
1127 case CSSPropertyTransformStyle:
1128 case CSSPropertyWebkitTransformStyle:
1129 case CSSPropertyWebkitUserDrag:
1130 case CSSPropertyWebkitUserModify:
1131 case CSSPropertyWebkitUserSelect:
1132 case CSSPropertyWebkitWritingMode:
1133 case CSSPropertyWhiteSpace:
1134 case CSSPropertyWordBreak:
1135 case CSSPropertyWordWrap:
1136 #if ENABLE(TOUCH_EVENTS)
1137 case CSSPropertyTouchAction:
1139 #if ENABLE(CSS_SCROLL_SNAP)
1140 case CSSPropertyWebkitScrollSnapType:
1142 #if ENABLE(CSS_TRAILING_WORD)
1143 case CSSPropertyAppleTrailingWord:
1145 case CSSPropertyFontVariantPosition:
1146 case CSSPropertyFontVariantCaps:
1147 case CSSPropertyFontVariantAlternates:
1154 static bool isUniversalKeyword(const String& string)
1156 // These keywords can be used for all properties.
1157 return equalLettersIgnoringASCIICase(string, "initial")
1158 || equalLettersIgnoringASCIICase(string, "inherit")
1159 || equalLettersIgnoringASCIICase(string, "unset")
1160 || equalLettersIgnoringASCIICase(string, "revert");
1163 static CSSParser::ParseResult parseKeywordValue(MutableStyleProperties& declaration, CSSPropertyID propertyId, const String& string, bool important, const CSSParserContext& parserContext, StyleSheetContents* styleSheetContents)
1165 ASSERT(!string.isEmpty());
1167 if (!isKeywordPropertyID(propertyId)) {
1168 if (!isUniversalKeyword(string))
1169 return CSSParser::ParseResult::Error;
1171 // Don't try to parse initial/inherit/unset/revert shorthands; return an error so the caller will use the full CSS parser.
1172 if (shorthandForProperty(propertyId).length())
1173 return CSSParser::ParseResult::Error;
1176 CSSParserString cssString;
1177 cssString.init(string);
1178 CSSValueID valueID = cssValueKeywordID(cssString);
1181 return CSSParser::ParseResult::Error;
1183 RefPtr<CSSValue> value;
1184 if (valueID == CSSValueInherit)
1185 value = CSSValuePool::singleton().createInheritedValue();
1186 else if (valueID == CSSValueInitial)
1187 value = CSSValuePool::singleton().createExplicitInitialValue();
1188 else if (valueID == CSSValueUnset)
1189 value = CSSValuePool::singleton().createUnsetValue();
1190 else if (valueID == CSSValueRevert)
1191 value = CSSValuePool::singleton().createRevertValue();
1192 else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext, styleSheetContents))
1193 value = CSSValuePool::singleton().createIdentifierValue(valueID);
1195 return CSSParser::ParseResult::Error;
1197 return declaration.addParsedProperty(CSSProperty(propertyId, value.releaseNonNull(), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
1200 template <typename CharacterType>
1201 static bool parseTransformTranslateArguments(WebKitCSSTransformValue& transformValue, CharacterType* characters, unsigned length, unsigned start, unsigned expectedCount)
1203 auto& cssValuePool = CSSValuePool::singleton();
1204 while (expectedCount) {
1205 size_t end = WTF::find(characters, length, expectedCount == 1 ? ')' : ',', start);
1206 if (end == notFound || (expectedCount == 1 && end != length - 1))
1208 unsigned argumentLength = end - start;
1209 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
1211 if (!parseSimpleLength(characters + start, argumentLength, unit, number))
1213 if (unit != CSSPrimitiveValue::CSS_PX && (number || unit != CSSPrimitiveValue::CSS_NUMBER))
1215 transformValue.append(cssValuePool.createValue(number, CSSPrimitiveValue::CSS_PX));
1222 static CSSParser::ParseResult parseTranslateTransformValue(MutableStyleProperties& properties, CSSPropertyID propertyID, const String& string, bool important)
1224 if (propertyID != CSSPropertyTransform)
1225 return CSSParser::ParseResult::Error;
1227 static const unsigned shortestValidTransformStringLength = 12;
1228 static const unsigned likelyMultipartTransformStringLengthCutoff = 32;
1229 if (string.length() < shortestValidTransformStringLength || string.length() > likelyMultipartTransformStringLengthCutoff)
1230 return CSSParser::ParseResult::Error;
1232 if (!string.startsWith("translate", false))
1233 return CSSParser::ParseResult::Error;
1235 UChar c9 = toASCIILower(string[9]);
1236 UChar c10 = toASCIILower(string[10]);
1238 WebKitCSSTransformValue::TransformOperationType transformType;
1239 unsigned expectedArgumentCount = 1;
1240 unsigned argumentStart = 11;
1241 if (c9 == 'x' && c10 == '(')
1242 transformType = WebKitCSSTransformValue::TranslateXTransformOperation;
1243 else if (c9 == 'y' && c10 == '(')
1244 transformType = WebKitCSSTransformValue::TranslateYTransformOperation;
1245 else if (c9 == 'z' && c10 == '(')
1246 transformType = WebKitCSSTransformValue::TranslateZTransformOperation;
1247 else if (c9 == '(') {
1248 transformType = WebKitCSSTransformValue::TranslateTransformOperation;
1249 expectedArgumentCount = 2;
1251 } else if (c9 == '3' && c10 == 'd' && string[11] == '(') {
1252 transformType = WebKitCSSTransformValue::Translate3DTransformOperation;
1253 expectedArgumentCount = 3;
1256 return CSSParser::ParseResult::Error;
1258 auto transformValue = WebKitCSSTransformValue::create(transformType);
1260 if (string.is8Bit())
1261 success = parseTransformTranslateArguments(transformValue, string.characters8(), string.length(), argumentStart, expectedArgumentCount);
1263 success = parseTransformTranslateArguments(transformValue, string.characters16(), string.length(), argumentStart, expectedArgumentCount);
1265 return CSSParser::ParseResult::Error;
1267 auto result = CSSValueList::createSpaceSeparated();
1268 result->append(WTFMove(transformValue));
1269 return properties.addParsedProperty(CSSProperty(CSSPropertyTransform, WTFMove(result), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
1272 RefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& string)
1274 if (string.isEmpty())
1277 auto valueList = CSSValueList::createCommaSeparated();
1279 Vector<String> familyNames;
1280 string.string().split(',', true, familyNames);
1282 auto& cssValuePool = CSSValuePool::singleton();
1283 for (auto& familyName : familyNames) {
1284 String stripped = stripLeadingAndTrailingHTMLSpaces(familyName);
1285 if (stripped.isEmpty())
1288 RefPtr<CSSValue> value;
1289 for (auto propertyID : { CSSValueSerif, CSSValueSansSerif, CSSValueCursive, CSSValueFantasy, CSSValueMonospace, CSSValueWebkitBody }) {
1290 if (equalIgnoringASCIICase(stripped, getValueName(propertyID))) {
1291 value = cssValuePool.createIdentifierValue(propertyID);
1296 value = cssValuePool.createFontFamilyValue(stripped);
1297 valueList->append(value.releaseNonNull());
1300 return WTFMove(valueList);
1303 CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
1305 ASSERT(!string.isEmpty());
1306 CSSParser::ParseResult result = parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode);
1307 if (result != ParseResult::Error)
1310 result = parseColorValue(declaration, propertyID, string, important, cssParserMode);
1311 if (result != ParseResult::Error)
1314 CSSParserContext context(cssParserMode);
1315 if (contextStyleSheet) {
1316 context = contextStyleSheet->parserContext();
1317 context.mode = cssParserMode;
1320 result = parseKeywordValue(declaration, propertyID, string, important, context, contextStyleSheet);
1321 if (result != ParseResult::Error)
1324 result = parseTranslateTransformValue(declaration, propertyID, string, important);
1325 if (result != ParseResult::Error)
1328 CSSParser parser(context);
1329 return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
1332 CSSParser::ParseResult CSSParser::parseCustomPropertyValue(MutableStyleProperties& declaration, const AtomicString& propertyName, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
1334 CSSParserContext context(cssParserMode);
1335 if (contextStyleSheet) {
1336 context = contextStyleSheet->parserContext();
1337 context.mode = cssParserMode;
1340 CSSParser parser(context);
1341 parser.setCustomPropertyName(propertyName);
1342 return parser.parseValue(declaration, CSSPropertyCustom, string, important, contextStyleSheet);
1345 CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, StyleSheetContents* contextStyleSheet)
1347 setStyleSheet(contextStyleSheet);
1349 setupParser("@-webkit-value{", string, "} ");
1352 m_important = important;
1358 ParseResult result = ParseResult::Error;
1360 if (!m_parsedProperties.isEmpty()) {
1361 result = declaration.addParsedProperties(m_parsedProperties) ? ParseResult::Changed : ParseResult::Unchanged;
1368 // The color will only be changed when string contains a valid CSS color, so callers
1369 // can set it to a default color and ignore the boolean result.
1370 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
1372 if (string.isEmpty())
1375 // First try creating a color specified by name, rgba(), rgb() or "#" syntax.
1376 if (fastParseColor(color, string, strict))
1379 CSSParser parser(CSSStrictMode);
1381 // In case the fast-path parser didn't understand the color, try the full parser.
1382 if (!parser.parseColor(string))
1385 CSSValue& value = *parser.m_parsedProperties.first().value();
1386 if (!is<CSSPrimitiveValue>(value))
1389 CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value);
1390 if (!primitiveValue.isRGBColor())
1393 color = primitiveValue.getRGBA32Value();
1397 bool CSSParser::parseColor(const String& string)
1399 setupParser("@-webkit-decls{color:", string, "} ");
1403 return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
1406 bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
1408 if (!document || !document->page())
1411 CSSParserString cssColor;
1412 cssColor.init(string);
1413 CSSValueID id = cssValueKeywordID(cssColor);
1414 if (!validPrimitiveValueColor(id))
1417 Color parsedColor = document->page()->theme().systemColor(id);
1418 if (!parsedColor.isValid())
1421 color = parsedColor.rgb();
1425 void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
1427 m_selectorListForParseSelector = &selectorList;
1429 setupParser("@-webkit-selector{", string, "}");
1433 m_selectorListForParseSelector = nullptr;
1436 Ref<ImmutableStyleProperties> CSSParser::parseInlineStyleDeclaration(const String& string, Element* element)
1438 CSSParserContext context = element->document().elementSheet().contents().parserContext();
1439 context.mode = strictToCSSParserMode(element->isHTMLElement() && !element->document().inQuirksMode());
1440 return CSSParser(context).parseDeclaration(string, &element->document().elementSheet().contents());
1443 Ref<ImmutableStyleProperties> CSSParser::parseDeclaration(const String& string, StyleSheetContents* contextStyleSheet)
1445 setStyleSheet(contextStyleSheet);
1447 setupParser("@-webkit-decls{", string, "} ");
1451 Ref<ImmutableStyleProperties> style = createStyleProperties();
1457 bool CSSParser::parseDeclaration(MutableStyleProperties& declaration, const String& string, RefPtr<CSSRuleSourceData>&& ruleSourceData, StyleSheetContents* contextStyleSheet)
1459 // Length of the "@-webkit-decls{" prefix.
1460 static const unsigned prefixLength = 15;
1462 setStyleSheet(contextStyleSheet);
1464 if (ruleSourceData) {
1465 m_currentRuleDataStack = std::make_unique<RuleSourceDataList>();
1466 m_currentRuleDataStack->append(*ruleSourceData);
1469 setupParser("@-webkit-decls{", string, "} ");
1474 if (!m_parsedProperties.isEmpty()) {
1476 declaration.addParsedProperties(m_parsedProperties);
1480 if (ruleSourceData) {
1481 ASSERT(m_currentRuleDataStack->size() == 1);
1482 ruleSourceData->ruleBodyRange.start = 0;
1483 ruleSourceData->ruleBodyRange.end = string.length();
1484 for (size_t i = 0, size = ruleSourceData->styleSourceData->propertyData.size(); i < size; ++i) {
1485 CSSPropertySourceData& propertyData = ruleSourceData->styleSourceData->propertyData.at(i);
1486 propertyData.range.start -= prefixLength;
1487 propertyData.range.end -= prefixLength;
1490 fixUnparsedPropertyRanges(*ruleSourceData);
1491 m_currentRuleDataStack.reset();
1497 std::unique_ptr<MediaQuery> CSSParser::parseMediaQuery(const String& string)
1499 if (string.isEmpty())
1502 ASSERT(!m_mediaQuery);
1504 // can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
1505 // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
1506 setupParser("@-webkit-mediaquery ", string, "} ");
1509 return WTFMove(m_mediaQuery);
1512 Vector<CSSParser::SourceSize> CSSParser::parseSizesAttribute(StringView string)
1514 Vector<SourceSize> result;
1516 if (string.isEmpty())
1519 ASSERT(!m_sourceSizeList);
1521 setupParser("@-webkit-sizesattr ", string, "}");
1524 if (!m_sourceSizeList)
1527 result = WTFMove(*m_sourceSizeList);
1528 m_sourceSizeList = nullptr;
1532 // FIXME(141289): The following two constructors are only needed because of a bug in MSVC 2013 (and prior).
1533 // We should remove this code as soon as a Visual Studio update that fixes this problem is released.
1535 CSSParser::SourceSize::SourceSize(CSSParser::SourceSize&& original)
1536 : expression(WTFMove(original.expression))
1537 , length(WTFMove(original.length))
1541 CSSParser::SourceSize::SourceSize(MediaQueryExpression&& expression, Ref<CSSValue>&& value)
1542 : expression(WTFMove(expression))
1543 , length(WTFMove(value))
1547 Optional<CSSParser::SourceSize> CSSParser::sourceSize(MediaQueryExpression&& expression, CSSParserValue& parserValue)
1549 RefPtr<CSSValue> value;
1550 if (isCalculation(parserValue)) {
1551 auto* args = parserValue.function->args.get();
1552 if (args && args->size())
1553 value = CSSCalcValue::create(parserValue.function->name, *args, CalculationRangeNonNegative);
1556 value = parserValue.createCSSValue();
1557 destroy(parserValue);
1560 // FIXME: Calling the constructor explicitly here to work around an MSVC bug.
1561 // For other compilers, we did not need to define the constructors and we could use aggregate initialization syntax.
1562 return SourceSize(WTFMove(expression), value.releaseNonNull());
1565 static inline void filterProperties(bool important, const ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, std::bitset<numCSSProperties>& seenProperties, HashSet<AtomicString>& seenCustomProperties)
1567 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
1568 for (int i = input.size() - 1; i >= 0; --i) {
1569 const CSSProperty& property = input[i];
1570 if (property.isImportant() != important)
1573 if (property.id() == CSSPropertyCustom) {
1574 if (property.value()) {
1575 auto& name = downcast<CSSCustomPropertyValue>(*property.value()).name();
1576 if (!seenCustomProperties.add(name).isNewEntry)
1578 output[--unusedEntries] = property;
1583 const unsigned propertyIDIndex = property.id() - firstCSSProperty;
1584 ASSERT(propertyIDIndex < seenProperties.size());
1585 if (seenProperties[propertyIDIndex])
1587 seenProperties.set(propertyIDIndex);
1588 output[--unusedEntries] = property;
1592 Ref<ImmutableStyleProperties> CSSParser::createStyleProperties()
1594 std::bitset<numCSSProperties> seenProperties;
1595 size_t unusedEntries = m_parsedProperties.size();
1596 Vector<CSSProperty, 256> results(unusedEntries);
1598 // Important properties have higher priority, so add them first. Duplicate definitions can then be ignored when found.
1599 HashSet<AtomicString> seenCustomProperties;
1600 filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties);
1601 filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties);
1603 results.remove(0, unusedEntries);
1605 return ImmutableStyleProperties::create(results.data(), results.size(), m_context.mode);
1608 void CSSParser::addProperty(CSSPropertyID propId, RefPtr<CSSValue>&& value, bool important, bool implicit)
1610 // This property doesn't belong to a shorthand or is a CSS variable (which will be resolved later).
1611 if (!m_currentShorthand) {
1612 m_parsedProperties.append(CSSProperty(propId, WTFMove(value), important, false, CSSPropertyInvalid, m_implicitShorthand || implicit));
1616 auto shorthands = matchingShorthandsForLonghand(propId);
1617 if (shorthands.size() == 1)
1618 m_parsedProperties.append(CSSProperty(propId, WTFMove(value), important, true, CSSPropertyInvalid, m_implicitShorthand || implicit));
1620 m_parsedProperties.append(CSSProperty(propId, WTFMove(value), important, true, indexOfShorthandForLonghand(m_currentShorthand, shorthands), m_implicitShorthand || implicit));
1623 void CSSParser::rollbackLastProperties(int num)
1626 ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num));
1627 m_parsedProperties.shrink(m_parsedProperties.size() - num);
1630 void CSSParser::clearProperties()
1632 m_parsedProperties.clear();
1633 m_numParsedPropertiesBeforeMarginBox = invalidParsedPropertiesCount;
1636 URL CSSParser::completeURL(const CSSParserContext& context, const String& url)
1640 if (context.charset.isEmpty())
1641 return URL(context.baseURL, url);
1642 return URL(context.baseURL, url, context.charset);
1645 URL CSSParser::completeURL(const String& url) const
1647 return completeURL(m_context, url);
1650 bool CSSParser::validateCalculationUnit(ValueWithCalculation& valueWithCalculation, Units unitFlags)
1652 bool mustBeNonNegative = unitFlags & FNonNeg;
1654 RefPtr<CSSCalcValue> calculation;
1655 if (valueWithCalculation.calculation()) {
1656 // The calculation value was already parsed so we reuse it. However, we may need to update its range.
1657 calculation = valueWithCalculation.calculation();
1658 calculation->setPermittedValueRange(mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll);
1660 valueWithCalculation.setCalculation(parseCalculation(valueWithCalculation, mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll));
1661 calculation = valueWithCalculation.calculation();
1666 bool isValid = false;
1667 switch (calculation->category()) {
1669 isValid = (unitFlags & FNumber);
1670 if (!isValid && (unitFlags & FInteger) && calculation->isInt())
1672 if (!isValid && (unitFlags & FPositiveInteger) && calculation->isInt() && calculation->isPositive())
1676 isValid = (unitFlags & FLength);
1679 isValid = (unitFlags & FPercent);
1681 case CalcPercentLength:
1682 isValid = (unitFlags & FPercent) && (unitFlags & FLength);
1684 case CalcPercentNumber:
1685 isValid = (unitFlags & FPercent) && (unitFlags & FNumber);
1688 isValid = (unitFlags & FAngle);
1691 isValid = (unitFlags & FTime);
1694 isValid = (unitFlags & FFrequency);
1703 inline bool CSSParser::shouldAcceptUnitLessValues(CSSParserValue& value, Units unitFlags, CSSParserMode cssParserMode)
1705 // Qirks mode and svg presentation attributes accept unit less values.
1706 return (unitFlags & (FLength | FAngle | FTime)) && (!value.fValue || cssParserMode == CSSQuirksMode || cssParserMode == SVGAttributeMode);
1709 bool CSSParser::validateUnit(ValueWithCalculation& valueWithCalculation, Units unitFlags, CSSParserMode cssParserMode)
1711 if (isCalculation(valueWithCalculation))
1712 return validateCalculationUnit(valueWithCalculation, unitFlags);
1715 switch (valueWithCalculation.value().unit) {
1716 case CSSPrimitiveValue::CSS_NUMBER:
1717 b = (unitFlags & FNumber);
1718 if (!b && shouldAcceptUnitLessValues(valueWithCalculation, unitFlags, cssParserMode)) {
1719 valueWithCalculation.value().unit = (unitFlags & FLength) ? CSSPrimitiveValue::CSS_PX :
1720 ((unitFlags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS);
1723 if (!b && (unitFlags & FInteger) && valueWithCalculation.value().isInt)
1725 if (!b && (unitFlags & FPositiveInteger) && valueWithCalculation.value().isInt && valueWithCalculation.value().fValue > 0)
1728 case CSSPrimitiveValue::CSS_PERCENTAGE:
1729 b = (unitFlags & FPercent);
1731 case CSSParserValue::Q_EMS:
1732 case CSSPrimitiveValue::CSS_EMS:
1733 case CSSPrimitiveValue::CSS_REMS:
1734 case CSSPrimitiveValue::CSS_CHS:
1735 case CSSPrimitiveValue::CSS_EXS:
1736 case CSSPrimitiveValue::CSS_PX:
1737 case CSSPrimitiveValue::CSS_CM:
1738 case CSSPrimitiveValue::CSS_MM:
1739 case CSSPrimitiveValue::CSS_IN:
1740 case CSSPrimitiveValue::CSS_PT:
1741 case CSSPrimitiveValue::CSS_PC:
1742 case CSSPrimitiveValue::CSS_VW:
1743 case CSSPrimitiveValue::CSS_VH:
1744 case CSSPrimitiveValue::CSS_VMIN:
1745 case CSSPrimitiveValue::CSS_VMAX:
1746 b = (unitFlags & FLength);
1748 case CSSPrimitiveValue::CSS_MS:
1749 case CSSPrimitiveValue::CSS_S:
1750 b = (unitFlags & FTime);
1752 case CSSPrimitiveValue::CSS_DEG:
1753 case CSSPrimitiveValue::CSS_RAD:
1754 case CSSPrimitiveValue::CSS_GRAD:
1755 case CSSPrimitiveValue::CSS_TURN:
1756 b = (unitFlags & FAngle);
1758 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1759 case CSSPrimitiveValue::CSS_DPPX:
1760 case CSSPrimitiveValue::CSS_DPI:
1761 case CSSPrimitiveValue::CSS_DPCM:
1762 b = (unitFlags & FResolution);
1765 case CSSPrimitiveValue::CSS_HZ:
1766 case CSSPrimitiveValue::CSS_KHZ:
1767 case CSSPrimitiveValue::CSS_DIMENSION:
1771 if (b && unitFlags & FNonNeg && valueWithCalculation.value().fValue < 0)
1773 if (b && std::isinf(valueWithCalculation.value().fValue))
1778 inline Ref<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(ValueWithCalculation& valueWithCalculation)
1780 if (valueWithCalculation.calculation())
1781 return CSSPrimitiveValue::create(valueWithCalculation.calculation());
1783 CSSParserValue& value = valueWithCalculation;
1784 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1785 ASSERT((value.unit >= CSSPrimitiveValue::CSS_NUMBER && value.unit <= CSSPrimitiveValue::CSS_KHZ)
1786 || (value.unit >= CSSPrimitiveValue::CSS_TURN && value.unit <= CSSPrimitiveValue::CSS_CHS)
1787 || (value.unit >= CSSPrimitiveValue::CSS_VW && value.unit <= CSSPrimitiveValue::CSS_VMAX)
1788 || (value.unit >= CSSPrimitiveValue::CSS_DPPX && value.unit <= CSSPrimitiveValue::CSS_DPCM));
1790 ASSERT((value.unit >= CSSPrimitiveValue::CSS_NUMBER && value.unit <= CSSPrimitiveValue::CSS_KHZ)
1791 || (value.unit >= CSSPrimitiveValue::CSS_TURN && value.unit <= CSSPrimitiveValue::CSS_CHS)
1792 || (value.unit >= CSSPrimitiveValue::CSS_VW && value.unit <= CSSPrimitiveValue::CSS_VMAX));
1794 return CSSValuePool::singleton().createValue(value.fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value.unit));
1797 inline Ref<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSParserValue& value)
1799 ASSERT(value.unit == CSSPrimitiveValue::CSS_STRING || value.unit == CSSPrimitiveValue::CSS_IDENT);
1800 return CSSValuePool::singleton().createValue(value.string, CSSPrimitiveValue::CSS_STRING);
1803 static inline bool isComma(CSSParserValue* value)
1805 return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
1808 static inline bool isForwardSlashOperator(CSSParserValue& value)
1810 return value.unit == CSSParserValue::Operator && value.iValue == '/';
1813 bool CSSParser::isValidSize(ValueWithCalculation& valueWithCalculation)
1815 int id = valueWithCalculation.value().id;
1816 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent)
1818 return !id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg);
1821 inline RefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(CSSValueID identifier, ValueWithCalculation& valueWithCalculation)
1824 return CSSValuePool::singleton().createIdentifierValue(identifier);
1826 if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
1827 return createPrimitiveStringValue(valueWithCalculation);
1828 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_NUMBER && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_KHZ)
1829 return createPrimitiveNumericValue(valueWithCalculation);
1830 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_TURN && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_CHS)
1831 return createPrimitiveNumericValue(valueWithCalculation);
1832 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_VW && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_VMAX)
1833 return createPrimitiveNumericValue(valueWithCalculation);
1834 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1835 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_DPPX && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_DPCM)
1836 return createPrimitiveNumericValue(valueWithCalculation);
1838 if (valueWithCalculation.value().unit >= CSSParserValue::Q_EMS)
1839 return CSSPrimitiveValue::createAllowingMarginQuirk(valueWithCalculation.value().fValue, CSSPrimitiveValue::CSS_EMS);
1840 if (valueWithCalculation.calculation())
1841 return CSSPrimitiveValue::create(valueWithCalculation.calculation());
1846 void CSSParser::addExpandedPropertyForValue(CSSPropertyID propId, Ref<CSSValue>&& value, bool important)
1848 const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
1849 unsigned shorthandLength = shorthand.length();
1850 if (!shorthandLength) {
1851 addProperty(propId, WTFMove(value), important);
1855 ShorthandScope scope(this, propId);
1856 const CSSPropertyID* longhands = shorthand.properties();
1857 for (unsigned i = 0; i < shorthandLength; ++i)
1858 addProperty(longhands[i], value.copyRef(), important);
1861 RefPtr<CSSValue> CSSParser::parseVariableDependentValue(CSSPropertyID propID, const CSSVariableDependentValue& dependentValue, const CustomPropertyValueMap& customProperties, TextDirection direction, WritingMode writingMode)
1863 m_valueList.reset(new CSSParserValueList());
1864 if (!dependentValue.valueList().buildParserValueListSubstitutingVariables(m_valueList.get(), customProperties))
1867 CSSPropertyID dependentValuePropertyID = dependentValue.propertyID();
1868 if (CSSProperty::isDirectionAwareProperty(dependentValuePropertyID))
1869 dependentValuePropertyID = CSSProperty::resolveDirectionAwareProperty(dependentValuePropertyID, direction, writingMode);
1871 if (!parseValue(dependentValuePropertyID, false))
1874 for (auto& property : m_parsedProperties) {
1875 if (property.id() == propID)
1876 return property.value();
1881 #if ENABLE(CSS_IMAGE_SET)
1882 static bool isImageSetFunctionValue(const CSSParserValue& value)
1884 return value.unit == CSSParserValue::Function && (equalLettersIgnoringASCIICase(value.function->name, "image-set(") || equalLettersIgnoringASCIICase(value.function->name, "-webkit-image-set("));
1888 bool CSSParser::parseValue(CSSPropertyID propId, bool important)
1890 if (!m_valueList || !m_valueList->current())
1893 ValueWithCalculation valueWithCalculation(*m_valueList->current());
1894 CSSValueID id = valueWithCalculation.value().id;
1896 if (propId == CSSPropertyCustom)
1897 return parseCustomPropertyDeclaration(important, id);
1899 if (m_valueList->containsVariables()) {
1900 auto valueList = CSSValueList::createFromParserValueList(*m_valueList);
1901 addExpandedPropertyForValue(propId, CSSVariableDependentValue::create(WTFMove(valueList), propId), important);
1905 auto& cssValuePool = CSSValuePool::singleton();
1906 unsigned num = inShorthand() ? 1 : m_valueList->size();
1908 if (id == CSSValueInherit) {
1911 addExpandedPropertyForValue(propId, cssValuePool.createInheritedValue(), important);
1914 else if (id == CSSValueInitial) {
1917 addExpandedPropertyForValue(propId, cssValuePool.createExplicitInitialValue(), important);
1919 } else if (id == CSSValueUnset) {
1922 addExpandedPropertyForValue(propId, cssValuePool.createUnsetValue(), important);
1924 } else if (id == CSSValueRevert) {
1927 addExpandedPropertyForValue(propId, cssValuePool.createRevertValue(), important);
1931 if (propId == CSSPropertyAll)
1932 return false; // "all" doesn't allow you to specify anything other than inherit/initial/unset.
1934 if (isKeywordPropertyID(propId)) {
1935 if (!isValidKeywordPropertyAndValue(propId, id, m_context, m_styleSheet))
1937 if (m_valueList->next() && !inShorthand())
1939 addProperty(propId, cssValuePool.createIdentifierValue(id), important);
1943 #if ENABLE(CSS_DEVICE_ADAPTATION)
1945 return parseViewportProperty(propId, important);
1948 bool validPrimitive = false;
1949 RefPtr<CSSValue> parsedValue;
1952 case CSSPropertySize: // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
1953 return parseSize(propId, important);
1955 case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit
1956 if (id == CSSValueNone)
1957 validPrimitive = true;
1959 return parseQuotes(propId, important);
1961 case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | isolate | isolate-override | plaintext | inherit
1962 if (id == CSSValueNormal
1963 || id == CSSValueEmbed
1964 || id == CSSValueBidiOverride
1965 || id == CSSValueWebkitIsolate
1966 || id == CSSValueWebkitIsolateOverride
1967 || id == CSSValueWebkitPlaintext)
1968 validPrimitive = true;
1971 case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
1972 // close-quote | no-open-quote | no-close-quote ]+ | inherit
1973 return parseContent(propId, important);
1975 case CSSPropertyAlt: // [ <string> | attr(X) ]
1976 return parseAlt(propId, important);
1978 case CSSPropertyClip: // <shape> | auto | inherit
1979 if (id == CSSValueAuto)
1980 validPrimitive = true;
1981 else if (valueWithCalculation.value().unit == CSSParserValue::Function)
1982 return parseClipShape(propId, important);
1985 /* Start of supported CSS properties with validation. This is needed for parseShorthand to work
1986 * correctly and allows optimization in WebCore::applyRule(..)
1988 case CSSPropertyOverflow: {
1989 ShorthandScope scope(this, propId);
1990 if (num != 1 || !parseValue(CSSPropertyOverflowY, important))
1993 RefPtr<CSSValue> overflowXValue;
1995 // FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. If this value has been
1996 // set using the shorthand, then for now overflow-x will default to auto, but once we implement
1997 // pagination controls, it should default to hidden. If the overflow-y value is anything but
1998 // paged-x or paged-y, then overflow-x and overflow-y should have the same value.
1999 if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
2000 overflowXValue = cssValuePool.createIdentifierValue(CSSValueAuto);
2002 overflowXValue = m_parsedProperties.last().value();
2003 addProperty(CSSPropertyOverflowX, WTFMove(overflowXValue), important);
2007 case CSSPropertyTextAlign:
2008 // left | right | center | justify | -webkit-left | -webkit-right | -webkit-center | -webkit-match-parent
2009 // | start | end | inherit | -webkit-auto (converted to start)
2010 // NOTE: <string> is not supported.
2011 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd)
2012 validPrimitive = true;
2015 case CSSPropertyFontWeight: { // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
2016 if (m_valueList->size() != 1)
2018 return parseFontWeight(important);
2021 case CSSPropertyFontSynthesis: // none | [ weight || style ]
2022 return parseFontSynthesis(important);
2024 case CSSPropertyBorderSpacing: {
2026 ShorthandScope scope(this, CSSPropertyBorderSpacing);
2027 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
2029 CSSValue* value = m_parsedProperties.last().value();
2030 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important);
2033 else if (num == 2) {
2034 ShorthandScope scope(this, CSSPropertyBorderSpacing);
2035 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important) || !parseValue(CSSPropertyWebkitBorderVerticalSpacing, important))
2041 case CSSPropertyWebkitBorderHorizontalSpacing:
2042 case CSSPropertyWebkitBorderVerticalSpacing:
2043 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2045 case CSSPropertyOutlineColor: // <color> | invert | inherit
2046 // Outline color has "invert" as additional keyword.
2047 // Also, we want to allow the special focus color even in strict parsing mode.
2048 if (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor) {
2049 validPrimitive = true;
2053 case CSSPropertyBackgroundColor: // <color> | inherit
2054 case CSSPropertyBorderTopColor: // <color> | inherit
2055 case CSSPropertyBorderRightColor:
2056 case CSSPropertyBorderBottomColor:
2057 case CSSPropertyBorderLeftColor:
2058 case CSSPropertyWebkitBorderStartColor:
2059 case CSSPropertyWebkitBorderEndColor:
2060 case CSSPropertyWebkitBorderBeforeColor:
2061 case CSSPropertyWebkitBorderAfterColor:
2062 case CSSPropertyColor: // <color> | inherit
2063 case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors
2064 case CSSPropertyTextUnderlineColor:
2065 case CSSPropertyTextOverlineColor:
2066 case CSSPropertyColumnRuleColor:
2067 case CSSPropertyWebkitTextDecorationColor:
2068 case CSSPropertyWebkitTextEmphasisColor:
2069 case CSSPropertyWebkitTextFillColor:
2070 case CSSPropertyWebkitTextStrokeColor:
2071 if (id == CSSValueWebkitText)
2072 validPrimitive = true; // Always allow this, even when strict parsing is on,
2073 // since we use this in our UA sheets.
2074 else if (id == CSSValueCurrentcolor)
2075 validPrimitive = true;
2076 else if (isValidSystemColorValue(id) || id == CSSValueMenu
2077 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2078 validPrimitive = true;
2080 parsedValue = parseColor();
2082 m_valueList->next();
2086 case CSSPropertyCursor: {
2087 // Grammar defined by CSS3 UI and modified by CSS4 images:
2088 // [ [<image> [<x> <y>]?,]*
2089 // [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |
2090 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize |
2091 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help |
2092 // vertical-text | cell | context-menu | alias | copy | no-drop | not-allowed |
2093 // zoom-in | zoom-out | all-scroll | -webkit-grab | -webkit-grabbing | -webkit-zoom-in |
2094 // -webkit-zoom-out ] ] | inherit
2095 RefPtr<CSSValueList> list;
2096 CSSParserValue* value = &valueWithCalculation.value();
2098 RefPtr<CSSValue> image;
2099 if (value->unit == CSSPrimitiveValue::CSS_URI) {
2100 String uri = value->string;
2102 image = CSSImageValue::create(completeURL(uri));
2103 #if ENABLE(CSS_IMAGE_SET) && ENABLE(MOUSE_CURSOR_SCALE)
2104 } else if (isImageSetFunctionValue(*value)) {
2105 image = parseImageSet();
2113 value = m_valueList->next();
2114 while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
2115 coords.append(int(value->fValue));
2116 value = m_valueList->next();
2118 bool hasHotSpot = false;
2119 IntPoint hotSpot(-1, -1);
2120 int nrcoords = coords.size();
2121 if (nrcoords > 0 && nrcoords != 2)
2123 if (nrcoords == 2) {
2125 hotSpot = IntPoint(coords[0], coords[1]);
2129 list = CSSValueList::createCommaSeparated();
2132 list->append(CSSCursorImageValue::create(image.releaseNonNull(), hasHotSpot, hotSpot));
2134 if ((inStrictMode() && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ',')))
2136 value = m_valueList->next(); // comma
2140 // no value after url list (MSIE 5 compatibility)
2141 if (list->length() != 1)
2143 } else if (inQuirksMode() && value->id == CSSValueHand) // MSIE 5 compatibility :/
2144 list->append(cssValuePool.createIdentifierValue(CSSValuePointer));
2145 else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitZoomOut) || value->id == CSSValueCopy || value->id == CSSValueNone)
2146 list->append(cssValuePool.createIdentifierValue(value->id));
2147 m_valueList->next();
2148 parsedValue = WTFMove(list);
2152 if (inQuirksMode() && value->id == CSSValueHand) {
2153 // MSIE 5 compatibility :/
2154 id = CSSValuePointer;
2155 validPrimitive = true;
2156 } else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitZoomOut) || value->id == CSSValueCopy || value->id == CSSValueNone)
2157 validPrimitive = true;
2159 ASSERT_NOT_REACHED();
2165 #if ENABLE(CURSOR_VISIBILITY)
2166 case CSSPropertyWebkitCursorVisibility:
2167 if (id == CSSValueAuto || id == CSSValueAutoHide)
2168 validPrimitive = true;
2172 case CSSPropertyBackgroundAttachment:
2173 case CSSPropertyBackgroundBlendMode:
2174 case CSSPropertyBackgroundClip:
2175 case CSSPropertyWebkitBackgroundClip:
2176 case CSSPropertyWebkitBackgroundComposite:
2177 case CSSPropertyBackgroundImage:
2178 case CSSPropertyBackgroundOrigin:
2179 case CSSPropertyWebkitBackgroundOrigin:
2180 case CSSPropertyBackgroundPosition:
2181 case CSSPropertyBackgroundPositionX:
2182 case CSSPropertyBackgroundPositionY:
2183 case CSSPropertyBackgroundSize:
2184 case CSSPropertyWebkitBackgroundSize:
2185 case CSSPropertyBackgroundRepeat:
2186 case CSSPropertyBackgroundRepeatX:
2187 case CSSPropertyBackgroundRepeatY:
2188 case CSSPropertyWebkitMaskClip:
2189 case CSSPropertyWebkitMaskComposite:
2190 case CSSPropertyWebkitMaskImage:
2191 case CSSPropertyWebkitMaskOrigin:
2192 case CSSPropertyWebkitMaskPosition:
2193 case CSSPropertyWebkitMaskPositionX:
2194 case CSSPropertyWebkitMaskPositionY:
2195 case CSSPropertyWebkitMaskSize:
2196 case CSSPropertyWebkitMaskSourceType:
2197 case CSSPropertyWebkitMaskRepeat:
2198 case CSSPropertyWebkitMaskRepeatX:
2199 case CSSPropertyWebkitMaskRepeatY:
2201 RefPtr<CSSValue> val1;
2202 RefPtr<CSSValue> val2;
2203 CSSPropertyID propId1, propId2;
2204 bool result = false;
2205 if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
2206 std::unique_ptr<ShorthandScope> shorthandScope;
2207 if (propId == CSSPropertyBackgroundPosition ||
2208 propId == CSSPropertyBackgroundRepeat ||
2209 propId == CSSPropertyWebkitMaskPosition ||
2210 propId == CSSPropertyWebkitMaskRepeat) {
2211 shorthandScope = std::make_unique<ShorthandScope>(this, propId);
2213 addProperty(propId1, val1.releaseNonNull(), important);
2215 addProperty(propId2, val2.releaseNonNull(), important);
2218 m_implicitShorthand = false;
2221 case CSSPropertyListStyleImage: // <uri> | none | inherit
2222 case CSSPropertyBorderImageSource:
2223 case CSSPropertyWebkitMaskBoxImageSource:
2224 if (id == CSSValueNone) {
2225 parsedValue = cssValuePool.createIdentifierValue(CSSValueNone);
2226 m_valueList->next();
2227 } else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_URI) {
2228 parsedValue = CSSImageValue::create(completeURL(valueWithCalculation.value().string));
2229 m_valueList->next();
2230 } else if (isGeneratedImageValue(valueWithCalculation)) {
2231 if (parseGeneratedImage(*m_valueList, parsedValue))
2232 m_valueList->next();
2236 #if ENABLE(CSS_IMAGE_SET)
2237 else if (isImageSetFunctionValue(valueWithCalculation.value())) {
2238 parsedValue = parseImageSet();
2241 m_valueList->next();
2246 case CSSPropertyWebkitTextStrokeWidth:
2247 case CSSPropertyOutlineWidth: // <border-width> | inherit
2248 case CSSPropertyBorderTopWidth: //// <border-width> | inherit
2249 case CSSPropertyBorderRightWidth: // Which is defined as
2250 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
2251 case CSSPropertyBorderLeftWidth:
2252 case CSSPropertyWebkitBorderStartWidth:
2253 case CSSPropertyWebkitBorderEndWidth:
2254 case CSSPropertyWebkitBorderBeforeWidth:
2255 case CSSPropertyWebkitBorderAfterWidth:
2256 case CSSPropertyColumnRuleWidth:
2257 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
2258 validPrimitive = true;
2260 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2263 case CSSPropertyLetterSpacing: // normal | <length> | inherit
2264 if (id == CSSValueNormal)
2265 validPrimitive = true;
2267 validPrimitive = validateUnit(valueWithCalculation, FLength);
2270 case CSSPropertyWordSpacing: // normal | <length> | <percentage> | inherit
2271 if (id == CSSValueNormal)
2272 validPrimitive = true;
2274 validPrimitive = validateUnit(valueWithCalculation, FLength | FPercent);
2277 case CSSPropertyTextIndent:
2278 parsedValue = parseTextIndent();
2281 case CSSPropertyPaddingTop: //// <padding-width> | inherit
2282 case CSSPropertyPaddingRight: // Which is defined as
2283 case CSSPropertyPaddingBottom: // <length> | <percentage>
2284 case CSSPropertyPaddingLeft: ////
2285 case CSSPropertyWebkitPaddingStart:
2286 case CSSPropertyWebkitPaddingEnd:
2287 case CSSPropertyWebkitPaddingBefore:
2288 case CSSPropertyWebkitPaddingAfter:
2289 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg));
2292 case CSSPropertyMaxWidth:
2293 case CSSPropertyWebkitMaxLogicalWidth:
2294 case CSSPropertyMaxHeight:
2295 case CSSPropertyWebkitMaxLogicalHeight:
2296 validPrimitive = (id == CSSValueNone || isValidSize(valueWithCalculation));
2299 case CSSPropertyMinWidth:
2300 case CSSPropertyWebkitMinLogicalWidth:
2301 case CSSPropertyMinHeight:
2302 case CSSPropertyWebkitMinLogicalHeight:
2303 validPrimitive = id == CSSValueAuto || isValidSize(valueWithCalculation);
2306 case CSSPropertyWidth:
2307 case CSSPropertyWebkitLogicalWidth:
2308 case CSSPropertyHeight:
2309 case CSSPropertyWebkitLogicalHeight:
2310 validPrimitive = (id == CSSValueAuto || isValidSize(valueWithCalculation));
2313 case CSSPropertyFontSize:
2314 return parseFontSize(important);
2316 case CSSPropertyVerticalAlign:
2317 // baseline | sub | super | top | text-top | middle | bottom | text-bottom |
2318 // <percentage> | <length> | inherit
2320 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
2321 validPrimitive = true;
2323 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent));
2326 case CSSPropertyBottom: // <length> | <percentage> | auto | inherit
2327 case CSSPropertyLeft: // <length> | <percentage> | auto | inherit
2328 case CSSPropertyRight: // <length> | <percentage> | auto | inherit
2329 case CSSPropertyTop: // <length> | <percentage> | auto | inherit
2330 case CSSPropertyMarginTop: //// <margin-width> | inherit
2331 case CSSPropertyMarginRight: // Which is defined as
2332 case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit
2333 case CSSPropertyMarginLeft: ////
2334 case CSSPropertyWebkitMarginStart:
2335 case CSSPropertyWebkitMarginEnd:
2336 case CSSPropertyWebkitMarginBefore:
2337 case CSSPropertyWebkitMarginAfter:
2338 if (id == CSSValueAuto)
2339 validPrimitive = true;
2341 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent));
2344 case CSSPropertyZIndex: // auto | <integer> | inherit
2345 if (id == CSSValueAuto)
2346 validPrimitive = true;
2348 validPrimitive = (!id && validateUnit(valueWithCalculation, FInteger, CSSQuirksMode));
2351 case CSSPropertyOrphans: // <integer> | inherit | auto (We've added support for auto for backwards compatibility)
2352 case CSSPropertyWidows: // <integer> | inherit | auto (Ditto)
2353 if (id == CSSValueAuto)
2354 validPrimitive = true;
2356 validPrimitive = (!id && validateUnit(valueWithCalculation, FPositiveInteger, CSSQuirksMode));
2359 case CSSPropertyLineHeight:
2360 return parseLineHeight(important);
2361 case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit
2362 if (id != CSSValueNone)
2363 return parseCounter(propId, 1, important);
2364 validPrimitive = true;
2366 case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit
2367 if (id != CSSValueNone)
2368 return parseCounter(propId, 0, important);
2369 validPrimitive = true;
2371 case CSSPropertyFontFamily:
2372 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit
2374 parsedValue = parseFontFamily();
2378 case CSSPropertyWebkitTextDecoration:
2379 // [ <text-decoration-line> || <text-decoration-style> || <text-decoration-color> ] | inherit
2380 return parseShorthand(CSSPropertyWebkitTextDecoration, webkitTextDecorationShorthand(), important);
2382 case CSSPropertyTextDecoration:
2383 case CSSPropertyWebkitTextDecorationsInEffect:
2384 case CSSPropertyWebkitTextDecorationLine:
2385 // none | [ underline || overline || line-through || blink ] | inherit
2386 return parseTextDecoration(propId, important);
2388 case CSSPropertyWebkitTextDecorationStyle:
2389 // solid | double | dotted | dashed | wavy
2390 if (id == CSSValueSolid || id == CSSValueDouble || id == CSSValueDotted || id == CSSValueDashed || id == CSSValueWavy)
2391 validPrimitive = true;
2394 case CSSPropertyWebkitTextDecorationSkip:
2395 // none | [ objects || spaces || ink || edges || box-decoration ]
2396 return parseTextDecorationSkip(important);
2398 case CSSPropertyWebkitTextUnderlinePosition:
2399 // auto | alphabetic | under
2400 return parseTextUnderlinePosition(important);
2402 case CSSPropertyZoom:
2403 // normal | reset | document | <number> | <percentage> | inherit
2404 if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument)
2405 validPrimitive = true;
2407 validPrimitive = (!id && validateUnit(valueWithCalculation, FNumber | FPercent | FNonNeg, CSSStrictMode));
2410 case CSSPropertyWebkitTextZoom:
2412 if (id == CSSValueNormal || id == CSSValueReset)
2413 validPrimitive = true;
2416 case CSSPropertySrc: // Only used within @font-face and @-webkit-filter, so cannot use inherit | initial or be !important. This is a list of urls or local references.
2417 return parseFontFaceSrc();
2419 case CSSPropertyUnicodeRange:
2420 return parseFontFaceUnicodeRange();
2422 /* CSS3 properties */
2424 case CSSPropertyBorderImage: {
2425 RefPtr<CSSValue> result;
2426 return parseBorderImage(propId, result, important);
2428 case CSSPropertyWebkitBorderImage:
2429 case CSSPropertyWebkitMaskBoxImage: {
2430 RefPtr<CSSValue> result;
2431 if (parseBorderImage(propId, result)) {
2432 addProperty(propId, WTFMove(result), important);
2437 case CSSPropertyBorderImageOutset:
2438 case CSSPropertyWebkitMaskBoxImageOutset: {
2439 RefPtr<CSSPrimitiveValue> result;
2440 if (parseBorderImageOutset(result)) {
2441 addProperty(propId, WTFMove(result), important);
2446 case CSSPropertyBorderImageRepeat:
2447 case CSSPropertyWebkitMaskBoxImageRepeat: {
2448 RefPtr<CSSValue> result;
2449 if (parseBorderImageRepeat(result)) {
2450 addProperty(propId, WTFMove(result), important);
2455 case CSSPropertyBorderImageSlice:
2456 case CSSPropertyWebkitMaskBoxImageSlice: {
2457 RefPtr<CSSBorderImageSliceValue> result;
2458 if (parseBorderImageSlice(propId, result)) {
2459 addProperty(propId, WTFMove(result), important);
2464 case CSSPropertyBorderImageWidth:
2465 case CSSPropertyWebkitMaskBoxImageWidth: {
2466 RefPtr<CSSPrimitiveValue> result;
2467 if (parseBorderImageWidth(result)) {
2468 addProperty(propId, WTFMove(result), important);
2473 case CSSPropertyBorderTopRightRadius:
2474 case CSSPropertyBorderTopLeftRadius:
2475 case CSSPropertyBorderBottomLeftRadius:
2476 case CSSPropertyBorderBottomRightRadius: {
2477 if (num != 1 && num != 2)
2479 validPrimitive = validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg);
2480 if (!validPrimitive)
2482 auto parsedValue1 = createPrimitiveNumericValue(valueWithCalculation);
2483 RefPtr<CSSPrimitiveValue> parsedValue2;
2485 ValueWithCalculation nextValueWithCalculation(*m_valueList->next());
2486 validPrimitive = validateUnit(nextValueWithCalculation, FLength | FPercent | FNonNeg);
2487 if (!validPrimitive)
2489 parsedValue2 = createPrimitiveNumericValue(nextValueWithCalculation);
2491 parsedValue2 = parsedValue1.ptr();
2493 addProperty(propId, createPrimitiveValuePair(WTFMove(parsedValue1), parsedValue2.releaseNonNull()), important);
2496 case CSSPropertyTabSize:
2497 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg);
2499 case CSSPropertyWebkitAspectRatio:
2500 return parseAspectRatio(important);
2501 case CSSPropertyBorderRadius:
2502 case CSSPropertyWebkitBorderRadius:
2503 return parseBorderRadius(propId, important);
2504 case CSSPropertyOutlineOffset:
2505 validPrimitive = validateUnit(valueWithCalculation, FLength);
2507 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
2508 case CSSPropertyBoxShadow:
2509 case CSSPropertyWebkitBoxShadow:
2510 if (id == CSSValueNone)
2511 validPrimitive = true;
2513 RefPtr<CSSValueList> shadowValueList = parseShadow(*m_valueList, propId);
2514 if (shadowValueList) {
2515 addProperty(propId, shadowValueList.releaseNonNull(), important);
2516 m_valueList->next();
2522 case CSSPropertyWebkitInitialLetter: {
2523 if (id == CSSValueNormal)
2524 validPrimitive = true;
2526 if (num != 1 && num != 2)
2528 validPrimitive = validateUnit(valueWithCalculation, FPositiveInteger);
2529 if (!validPrimitive)
2531 auto height = createPrimitiveNumericValue(valueWithCalculation);
2532 RefPtr<CSSPrimitiveValue> position;
2534 ValueWithCalculation nextValueWithCalculation(*m_valueList->next());
2535 validPrimitive = validateUnit(nextValueWithCalculation, FPositiveInteger);
2536 if (!validPrimitive)
2538 position = createPrimitiveNumericValue(nextValueWithCalculation);
2540 position = height.ptr();
2541 addProperty(propId, createPrimitiveValuePair(position.releaseNonNull(), WTFMove(height)), important);
2546 case CSSPropertyWebkitBoxReflect:
2547 if (id == CSSValueNone)
2548 validPrimitive = true;
2550 return parseReflect(propId, important);
2552 case CSSPropertyOpacity:
2553 validPrimitive = validateUnit(valueWithCalculation, FNumber);
2555 case CSSPropertyWebkitBoxFlex:
2556 validPrimitive = validateUnit(valueWithCalculation, FNumber);
2558 case CSSPropertyWebkitBoxFlexGroup:
2559 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode);
2561 case CSSPropertyWebkitBoxOrdinalGroup:
2562 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode) && valueWithCalculation.value().fValue;
2564 case CSSPropertyFilter:
2565 #if ENABLE(FILTERS_LEVEL_2)
2566 case CSSPropertyWebkitBackdropFilter:
2568 if (id == CSSValueNone)
2569 validPrimitive = true;
2571 RefPtr<CSSValueList> currValue;
2572 if (!parseFilter(*m_valueList, currValue))
2574 addProperty(propId, WTFMove(currValue), important);
2578 #if ENABLE(CSS_COMPOSITING)
2579 case CSSPropertyMixBlendMode:
2580 validPrimitive = true;
2582 case CSSPropertyIsolation:
2583 validPrimitive = true;
2586 case CSSPropertyFlex: {
2587 ShorthandScope scope(this, propId);
2588 if (id == CSSValueNone) {
2589 addProperty(CSSPropertyFlexGrow, cssValuePool.createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2590 addProperty(CSSPropertyFlexShrink, cssValuePool.createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2591 addProperty(CSSPropertyFlexBasis, cssValuePool.createIdentifierValue(CSSValueAuto), important);
2594 return parseFlex(*m_valueList, important);
2596 case CSSPropertyFlexBasis:
2597 // FIXME: Support intrinsic dimensions too.
2598 if (id == CSSValueAuto)
2599 validPrimitive = true;
2601 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg));
2603 case CSSPropertyFlexGrow:
2604 case CSSPropertyFlexShrink:
2605 validPrimitive = validateUnit(valueWithCalculation, FNumber | FNonNeg);
2607 case CSSPropertyOrder:
2608 if (validateUnit(valueWithCalculation, FInteger, CSSStrictMode)) {
2609 // We restrict the smallest value to int min + 2 because we use int min and int min + 1 as special values in a hash set.
2610 double result = std::max<double>(std::numeric_limits<int>::min() + 2, parsedDouble(valueWithCalculation));
2611 parsedValue = cssValuePool.createValue(result, CSSPrimitiveValue::CSS_NUMBER);
2612 m_valueList->next();
2615 case CSSPropertyWebkitMarquee:
2616 return parseShorthand(propId, webkitMarqueeShorthand(), important);
2617 case CSSPropertyWebkitMarqueeIncrement:
2618 if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
2619 validPrimitive = true;
2621 validPrimitive = validateUnit(valueWithCalculation, FLength | FPercent);
2623 case CSSPropertyWebkitMarqueeRepetition:
2624 if (id == CSSValueInfinite)
2625 validPrimitive = true;
2627 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg);
2629 case CSSPropertyWebkitMarqueeSpeed:
2630 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
2631 validPrimitive = true;
2633 validPrimitive = validateUnit(valueWithCalculation, FTime | FInteger | FNonNeg);
2635 #if ENABLE(CSS_REGIONS)
2636 case CSSPropertyWebkitFlowInto:
2637 return parseFlowThread(propId, important);
2638 case CSSPropertyWebkitFlowFrom:
2639 return parseRegionThread(propId, important);
2641 case CSSPropertyTransform:
2642 if (id == CSSValueNone)
2643 validPrimitive = true;
2645 if (RefPtr<CSSValue> transformValue = parseTransform()) {
2646 addProperty(propId, transformValue.releaseNonNull(), important);
2652 case CSSPropertyTransformOrigin:
2653 case CSSPropertyTransformOriginX:
2654 case CSSPropertyTransformOriginY:
2655 case CSSPropertyTransformOriginZ: {
2656 RefPtr<CSSPrimitiveValue> val1;
2657 RefPtr<CSSPrimitiveValue> val2;
2658 RefPtr<CSSValue> val3;
2659 CSSPropertyID propId1, propId2, propId3;
2660 if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
2661 addProperty(propId1, WTFMove(val1), important);
2663 addProperty(propId2, WTFMove(val2), important);
2665 addProperty(propId3, WTFMove(val3), important);
2670 case CSSPropertyPerspective:
2671 if (id == CSSValueNone)
2672 validPrimitive = true;
2674 // Accepting valueless numbers is a quirk of the -webkit prefixed version of the property.
2675 if (validateUnit(valueWithCalculation, FNumber | FLength | FNonNeg)) {
2676 addProperty(propId, createPrimitiveNumericValue(valueWithCalculation), important);
2681 case CSSPropertyPerspectiveOrigin:
2682 case CSSPropertyPerspectiveOriginX:
2683 case CSSPropertyPerspectiveOriginY: {
2684 RefPtr<CSSPrimitiveValue> val1;
2685 RefPtr<CSSPrimitiveValue> val2;
2686 CSSPropertyID propId1, propId2;
2687 if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
2688 addProperty(propId1, WTFMove(val1), important);
2690 addProperty(propId2, WTFMove(val2), important);
2695 case CSSPropertyAnimationDelay:
2696 case CSSPropertyAnimationDirection:
2697 case CSSPropertyAnimationDuration:
2698 case CSSPropertyAnimationFillMode:
2699 case CSSPropertyAnimationName:
2700 case CSSPropertyAnimationPlayState:
2701 case CSSPropertyAnimationIterationCount:
2702 case CSSPropertyAnimationTimingFunction:
2703 case CSSPropertyWebkitAnimationDelay:
2704 case CSSPropertyWebkitAnimationDirection:
2705 case CSSPropertyWebkitAnimationDuration:
2706 case CSSPropertyWebkitAnimationFillMode:
2707 case CSSPropertyWebkitAnimationName:
2708 case CSSPropertyWebkitAnimationPlayState:
2709 case CSSPropertyWebkitAnimationIterationCount:
2710 case CSSPropertyWebkitAnimationTimingFunction:
2711 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
2712 case CSSPropertyWebkitAnimationTrigger:
2714 case CSSPropertyTransitionDelay:
2715 case CSSPropertyTransitionDuration:
2716 case CSSPropertyTransitionTimingFunction:
2717 case CSSPropertyTransitionProperty:
2718 case CSSPropertyWebkitTransitionDelay:
2719 case CSSPropertyWebkitTransitionDuration:
2720 case CSSPropertyWebkitTransitionTimingFunction:
2721 case CSSPropertyWebkitTransitionProperty: {
2722 RefPtr<CSSValue> val;
2723 AnimationParseContext context;
2724 if (parseAnimationProperty(propId, val, context)) {
2725 addProperty(propId, WTFMove(val), important);
2730 case CSSPropertyJustifyContent:
2731 parsedValue = parseContentDistributionOverflowPosition();
2733 case CSSPropertyJustifySelf:
2734 return parseItemPositionOverflowPosition(propId, important);
2735 case CSSPropertyJustifyItems:
2736 if (parseLegacyPosition(propId, important))
2738 m_valueList->setCurrentIndex(0);
2739 return parseItemPositionOverflowPosition(propId, important);
2740 #if ENABLE(CSS_GRID_LAYOUT)
2741 case CSSPropertyGridAutoColumns:
2742 case CSSPropertyGridAutoRows:
2743 if (!isCSSGridLayoutEnabled())
2745 parsedValue = parseGridTrackSize(*m_valueList);
2748 case CSSPropertyGridTemplateColumns:
2749 case CSSPropertyGridTemplateRows:
2750 if (!isCSSGridLayoutEnabled())
2752 parsedValue = parseGridTrackList();
2755 case CSSPropertyGridColumnStart:
2756 case CSSPropertyGridColumnEnd:
2757 case CSSPropertyGridRowStart:
2758 case CSSPropertyGridRowEnd:
2759 if (!isCSSGridLayoutEnabled())
2761 parsedValue = parseGridPosition();
2764 case CSSPropertyGridColumnGap:
2765 case CSSPropertyGridRowGap:
2766 if (!isCSSGridLayoutEnabled())
2768 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2771 case CSSPropertyGridGap:
2772 if (!isCSSGridLayoutEnabled())
2774 return parseGridGapShorthand(important);
2776 case CSSPropertyGridColumn:
2777 case CSSPropertyGridRow:
2778 if (!isCSSGridLayoutEnabled())
2780 return parseGridItemPositionShorthand(propId, important);
2782 case CSSPropertyGridTemplate:
2783 if (!isCSSGridLayoutEnabled())
2785 return parseGridTemplateShorthand(important);
2787 case CSSPropertyGrid:
2788 if (!isCSSGridLayoutEnabled())
2790 return parseGridShorthand(important);
2792 case CSSPropertyGridArea:
2793 if (!isCSSGridLayoutEnabled())
2795 return parseGridAreaShorthand(important);
2797 case CSSPropertyGridTemplateAreas:
2798 if (!isCSSGridLayoutEnabled())
2800 parsedValue = parseGridTemplateAreas();
2802 case CSSPropertyGridAutoFlow:
2803 if (!isCSSGridLayoutEnabled())
2805 parsedValue = parseGridAutoFlow(*m_valueList);
2807 #endif /* ENABLE(CSS_GRID_LAYOUT) */
2808 case CSSPropertyWebkitMarginCollapse: {
2810 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2811 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important))
2813 CSSValue* value = m_parsedProperties.last().value();
2814 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
2817 else if (num == 2) {
2818 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2819 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important) || !parseValue(webkitMarginCollapseShorthand().properties()[1], important))
2825 case CSSPropertyTextLineThroughWidth:
2826 case CSSPropertyTextOverlineWidth:
2827 case CSSPropertyTextUnderlineWidth:
2828 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
2829 id == CSSValueMedium || id == CSSValueThick)
2830 validPrimitive = true;
2832 validPrimitive = !id && validateUnit(valueWithCalculation, FNumber | FLength | FPercent);
2834 case CSSPropertyColumnCount:
2835 parsedValue = parseColumnCount();
2837 case CSSPropertyColumnGap: // normal | <length>
2838 if (id == CSSValueNormal)
2839 validPrimitive = true;
2841 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2843 case CSSPropertyWebkitColumnAxis:
2844 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto)
2845 validPrimitive = true;
2847 case CSSPropertyColumnProgression:
2848 if (id == CSSValueNormal || id == CSSValueReverse)
2849 validPrimitive = true;
2851 case CSSPropertyColumnSpan: // none | all | 1 (will be dropped in the unprefixed property)
2852 if (id == CSSValueAll || id == CSSValueNone)
2853 validPrimitive = true;
2854 else if (validateUnit(valueWithCalculation, FNumber | FNonNeg) && parsedDouble(valueWithCalculation) == 1) {
2855 addProperty(CSSPropertyColumnSpan, cssValuePool.createValue(1, CSSPrimitiveValue::CSS_NUMBER), important);
2859 case CSSPropertyColumnWidth: // auto | <length>
2860 parsedValue = parseColumnWidth();
2862 case CSSPropertyObjectPosition: {
2863 RefPtr<CSSPrimitiveValue> val1;
2864 RefPtr<CSSPrimitiveValue> val2;
2865 parseFillPosition(*m_valueList, val1, val2);
2867 addProperty(CSSPropertyObjectPosition, createPrimitiveValuePair(val1.releaseNonNull(), WTFMove(val2)), important);
2872 // End of CSS3 properties
2874 case CSSPropertyWillChange: // auto | [scroll-position | contents | <custom-ident>]#
2875 if (id == CSSValueAuto)
2876 validPrimitive = true;
2878 return parseWillChange(important);
2881 // Apple specific properties. These will never be standardized and are purely to
2882 // support custom WebKit-based Apple applications.
2883 case CSSPropertyWebkitLineClamp:
2884 // When specifying number of lines, don't allow 0 as a valid value
2885 // When specifying either type of unit, require non-negative integers
2886 validPrimitive = (!id && (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_PERCENTAGE || valueWithCalculation.value().fValue) && validateUnit(valueWithCalculation, FInteger | FPercent | FNonNeg, CSSQuirksMode));
2888 #if ENABLE(IOS_TEXT_AUTOSIZING)
2889 case CSSPropertyWebkitTextSizeAdjust:
2890 if (!isTextAutosizingEnabled())
2893 if (id == CSSValueAuto || id == CSSValueNone)
2894 validPrimitive = true;
2896 // FIXME: Handle multilength case where we allow relative units.
2897 validPrimitive = (!id && validateUnit(valueWithCalculation, FPercent | FNonNeg, CSSStrictMode));
2902 case CSSPropertyWebkitFontSizeDelta: // <length>
2903 validPrimitive = validateUnit(valueWithCalculation, FLength);
2906 case CSSPropertyWebkitHyphenateCharacter:
2907 if (id == CSSValueAuto || valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
2908 validPrimitive = true;
2911 case CSSPropertyWebkitHyphenateLimitBefore:
2912 case CSSPropertyWebkitHyphenateLimitAfter:
2913 if (id == CSSValueAuto || validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode))
2914 validPrimitive = true;
2917 case CSSPropertyWebkitHyphenateLimitLines:
2918 if (id == CSSValueNoLimit || validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode))
2919 validPrimitive = true;
2922 case CSSPropertyWebkitLineGrid:
2923 if (id == CSSValueNone)
2924 validPrimitive = true;
2925 else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_IDENT) {
2926 String lineGridValue = String(valueWithCalculation.value().string);
2927 if (!lineGridValue.isEmpty()) {
2928 addProperty(propId, cssValuePool.createValue(lineGridValue, CSSPrimitiveValue::CSS_STRING), important);
2933 case CSSPropertyWebkitLocale:
2934 if (id == CSSValueAuto || valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
2935 validPrimitive = true;
2938 #if ENABLE(DASHBOARD_SUPPORT)
2939 case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region>
2940 if (valueWithCalculation.value().unit == CSSParserValue::Function || id == CSSValueNone)
2941 return parseDashboardRegions(propId, important);
2946 case CSSPropertyWebkitTouchCallout:
2947 if (id == CSSValueDefault || id == CSSValueNone)
2948 validPrimitive = true;
2951 #if ENABLE(TOUCH_EVENTS)
2952 case CSSPropertyWebkitTapHighlightColor:
2953 if (isValidSystemColorValue(id) || id == CSSValueMenu
2954 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2955 validPrimitive = true;
2957 parsedValue = parseColor();
2959 m_valueList->next();
2963 // End Apple-specific properties
2965 /* shorthand properties */
2966 case CSSPropertyBackground: {
2967 // Position must come before color in this array because a plain old "0" is a legal color
2968 // in quirks mode but it's usually the X coordinate of a position.
2969 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
2970 CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin,
2971 CSSPropertyBackgroundClip, CSSPropertyBackgroundColor, CSSPropertyBackgroundSize };
2972 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2974 case CSSPropertyWebkitMask: {
2975 const CSSPropertyID properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskSourceType, CSSPropertyWebkitMaskRepeat,
2976 CSSPropertyWebkitMaskPosition, CSSPropertyWebkitMaskOrigin, CSSPropertyWebkitMaskClip, CSSPropertyWebkitMaskSize };
2977 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2979 case CSSPropertyBorder:
2980 // [ 'border-width' || 'border-style' || <color> ] | inherit
2982 if (parseShorthand(propId, borderAbridgedShorthand(), important)) {
2983 // The CSS3 Borders and Backgrounds specification says that border also resets border-image. It's as
2984 // though a value of none was specified for the image.
2985 addExpandedPropertyForValue(CSSPropertyBorderImage, cssValuePool.createImplicitInitialValue(), important);
2990 case CSSPropertyBorderTop:
2991 // [ 'border-top-width' || 'border-style' || <color> ] | inherit
2992 return parseShorthand(propId, borderTopShorthand(), important);
2993 case CSSPropertyBorderRight:
2994 // [ 'border-right-width' || 'border-style' || <color> ] | inherit
2995 return parseShorthand(propId, borderRightShorthand(), important);
2996 case CSSPropertyBorderBottom:
2997 // [ 'border-bottom-width' || 'border-style' || <color> ] | inherit
2998 return parseShorthand(propId, borderBottomShorthand(), important);
2999 case CSSPropertyBorderLeft:
3000 // [ 'border-left-width' || 'border-style' || <color> ] | inherit
3001 return parseShorthand(propId, borderLeftShorthand(), important);
3002 case CSSPropertyWebkitBorderStart:
3003 return parseShorthand(propId, webkitBorderStartShorthand(), important);
3004 case CSSPropertyWebkitBorderEnd:
3005 return parseShorthand(propId, webkitBorderEndShorthand(), important);
3006 case CSSPropertyWebkitBorderBefore:
3007 return parseShorthand(propId, webkitBorderBeforeShorthand(), important);
3008 case CSSPropertyWebkitBorderAfter:
3009 return parseShorthand(propId, webkitBorderAfterShorthand(), important);
3010 case CSSPropertyOutline:
3011 // [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit
3012 return parseShorthand(propId, outlineShorthand(), important);
3013 case CSSPropertyBorderColor:
3014 // <color>{1,4} | inherit
3015 return parse4Values(propId, borderColorShorthand().properties(), important);
3016 case CSSPropertyBorderWidth:
3017 // <border-width>{1,4} | inherit
3018 return parse4Values(propId, borderWidthShorthand().properties(), important);
3019 case CSSPropertyBorderStyle:
3020 // <border-style>{1,4} | inherit
3021 return parse4Values(propId, borderStyleShorthand().properties(), important);
3022 case CSSPropertyMargin:
3023 // <margin-width>{1,4} | inherit
3024 return parse4Values(propId, marginShorthand().properties(), important);
3025 case CSSPropertyPadding:
3026 // <padding-width>{1,4} | inherit
3027 return parse4Values(propId, paddingShorthand().properties(), important);
3028 case CSSPropertyFlexFlow:
3029 return parseShorthand(propId, flexFlowShorthand(), important);
3030 case CSSPropertyFont:
3031 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
3032 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
3033 if (num == 1 && id >= CSSValueCaption && id <= CSSValueStatusBar) {
3034 parseSystemFont(important);
3037 return parseFont(important);
3038 case CSSPropertyListStyle:
3039 return parseShorthand(propId, listStyleShorthand(), important);
3040 case CSSPropertyColumns:
3041 return parseColumnsShorthand(important);
3042 case CSSPropertyColumnRule:
3043 return parseShorthand(propId, columnRuleShorthand(), important);
3044 case CSSPropertyWebkitTextStroke:
3045 return parseShorthand(propId, webkitTextStrokeShorthand(), important);
3046 case CSSPropertyAnimation:
3047 case CSSPropertyWebkitAnimation:
3048 return parseAnimationShorthand(propId, important);
3049 case CSSPropertyTransition:
3050 case CSSPropertyWebkitTransition:
3051 return parseTransitionShorthand(propId, important);
3052 case CSSPropertyInvalid:
3054 case CSSPropertyPage:
3055 return parsePage(propId, important);
3056 case CSSPropertyFontStretch:
3057 case CSSPropertyTextLineThrough:
3058 case CSSPropertyTextOverline:
3059 case CSSPropertyTextUnderline:
3061 // CSS Text Layout Module Level 3: Vertical writing support
3062 case CSSPropertyWebkitTextEmphasis:
3063 return parseShorthand(propId, webkitTextEmphasisShorthand(), important);
3065 case CSSPropertyWebkitTextEmphasisStyle:
3066 return parseTextEmphasisStyle(important);
3068 case CSSPropertyWebkitTextEmphasisPosition:
3069 return parseTextEmphasisPosition(important);
3071 case CSSPropertyWebkitTextOrientation:
3072 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSValueVerticalRight || id == CSSValueMixed || id == CSSValueUpright)
3073 validPrimitive = true;
3076 case CSSPropertyHangingPunctuation:
3077 return parseHangingPunctuation(important);
3078 case CSSPropertyWebkitLineBoxContain:
3079 if (id == CSSValueNone)
3080 validPrimitive = true;
3082 return parseLineBoxContain(important);
3084 case CSSPropertyFontFeatureSettings:
3085 if (id == CSSValueNormal)
3086 validPrimitive = true;
3088 return parseFontFeatureSettings(important);
3090 case CSSPropertyFontVariantLigatures:
3091 if (id == CSSValueNormal || id == CSSValueNone)
3092 validPrimitive = true;
3094 return parseFontVariantLigatures(important, true, false);
3096 case CSSPropertyFontVariantNumeric:
3097 if (id == CSSValueNormal)
3098 validPrimitive = true;
3100 return parseFontVariantNumeric(important, true, false);
3102 case CSSPropertyFontVariantEastAsian:
3103 if (id == CSSValueNormal)
3104 validPrimitive = true;
3106 return parseFontVariantEastAsian(important, true, false);
3108 case CSSPropertyFontVariant:
3109 if (id == CSSValueNormal) {
3110 ShorthandScope scope(this, CSSPropertyFontVariant);
3111 addProperty(CSSPropertyFontVariantLigatures, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3112 addProperty(CSSPropertyFontVariantPosition, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3113 addProperty(CSSPropertyFontVariantCaps, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3114 addProperty(CSSPropertyFontVariantNumeric, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3115 addProperty(CSSPropertyFontVariantAlternates, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3116 addProperty(CSSPropertyFontVariantEastAsian, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3119 if (id == CSSValueNone) {
3120 ShorthandScope scope(this, CSSPropertyFontVariant);
3121 addProperty(CSSPropertyFontVariantLigatures, CSSValuePool::singleton().createIdentifierValue(CSSValueNone), important, true);
3124 return parseFontVariant(important);
3126 case CSSPropertyWebkitClipPath:
3127 parsedValue = parseClipPath();
3129 #if ENABLE(CSS_SHAPES)
3130 case CSSPropertyWebkitShapeOutside:
3131 parsedValue = parseShapeProperty(propId);
3133 case CSSPropertyWebkitShapeMargin:
3134 validPrimitive = !id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg);
3136 case CSSPropertyWebkitShapeImageThreshold:
3137 validPrimitive = !id && validateUnit(valueWithCalculation, FNumber);
3140 #if ENABLE(CSS_IMAGE_ORIENTATION)
3141 case CSSPropertyImageOrientation:
3142 validPrimitive = !id && validateUnit(valueWithCalculation, FAngle);
3145 #if ENABLE(CSS_IMAGE_RESOLUTION)
3146 case CSSPropertyImageResolution:
3147 parsedValue = parseImageResolution();
3150 case CSSPropertyAlignContent:
3151 parsedValue = parseContentDistributionOverflowPosition();
3153 case CSSPropertyAlignSelf:
3154 return parseItemPositionOverflowPosition(propId, important);
3156 case CSSPropertyAlignItems:
3157 return parseItemPositionOverflowPosition(propId, important);
3158 case CSSPropertyBorderBottomStyle:
3159 case CSSPropertyBorderCollapse:
3160 case CSSPropertyBorderLeftStyle:
3161 case CSSPropertyBorderRightStyle:
3162 case CSSPropertyBorderTopStyle:
3163 case CSSPropertyBoxSizing:
3164 case CSSPropertyBreakAfter:
3165 case CSSPropertyBreakBefore:
3166 case CSSPropertyBreakInside:
3167 case CSSPropertyCaptionSide:
3168 case CSSPropertyClear:
3169 case CSSPropertyDirection:
3170 case CSSPropertyDisplay:
3171 case CSSPropertyEmptyCells:
3172 case CSSPropertyFloat:
3173 case CSSPropertyFontStyle:
3174 case CSSPropertyImageRendering:
3175 case CSSPropertyListStylePosition:
3176 case CSSPropertyListStyleType:
3177 case CSSPropertyObjectFit:
3178 case CSSPropertyOutlineStyle:
3179 case CSSPropertyOverflowWrap:
3180 case CSSPropertyOverflowX:
3181 case CSSPropertyOverflowY:
3182 case CSSPropertyPageBreakAfter:
3183 case CSSPropertyPageBreakBefore:
3184 case CSSPropertyPageBreakInside:
3185 case CSSPropertyPointerEvents:
3186 case CSSPropertyPosition:
3187 case CSSPropertyResize:
3188 case CSSPropertySpeak:
3189 case CSSPropertyTableLayout:
3190 case CSSPropertyTextLineThroughMode:
3191 case CSSPropertyTextLineThroughStyle:
3192 case CSSPropertyTextOverflow:
3193 case CSSPropertyTextOverlineMode:
3194 case CSSPropertyTextOverlineStyle:
3195 case CSSPropertyTextRendering:
3196 case CSSPropertyTextTransform:
3197 case CSSPropertyTextUnderlineMode:
3198 case CSSPropertyTextUnderlineStyle:
3199 case CSSPropertyVisibility:
3200 case CSSPropertyWebkitAppearance:
3201 case CSSPropertyWebkitBackfaceVisibility:
3202 case CSSPropertyWebkitBorderAfterStyle:
3203 case CSSPropertyWebkitBorderBeforeStyle:
3204 case CSSPropertyWebkitBorderEndStyle:
3205 case CSSPropertyWebkitBorderFit:
3206 case CSSPropertyWebkitBorderStartStyle:
3207 case CSSPropertyWebkitBoxAlign:
3208 #if ENABLE(CSS_BOX_DECORATION_BREAK)
3209 case CSSPropertyWebkitBoxDecorationBreak:
3211 case CSSPropertyWebkitBoxDirection:
3212 case CSSPropertyWebkitBoxLines:
3213 case CSSPropertyWebkitBoxOrient:
3214 case CSSPropertyWebkitBoxPack:
3215 case CSSPropertyWebkitColumnBreakAfter:
3216 case CSSPropertyWebkitColumnBreakBefore:
3217 case CSSPropertyWebkitColumnBreakInside:
3218 case CSSPropertyColumnFill:
3219 case CSSPropertyColumnRuleStyle:
3220 case CSSPropertyFlexDirection:
3221 case CSSPropertyFlexWrap:
3222 case CSSPropertyWebkitFontKerning:
3223 case CSSPropertyWebkitFontSmoothing:
3224 case CSSPropertyWebkitHyphens:
3225 case CSSPropertyWebkitLineAlign:
3226 case CSSPropertyWebkitLineBreak:
3227 case CSSPropertyWebkitLineSnap:
3228 case CSSPropertyWebkitMarginAfterCollapse:
3229 case CSSPropertyWebkitMarginBeforeCollapse:
3230 case CSSPropertyWebkitMarginBottomCollapse:
3231 case CSSPropertyWebkitMarginTopCollapse:
3232 case CSSPropertyWebkitMarqueeDirection:
3233 case CSSPropertyWebkitMarqueeStyle:
3234 case CSSPropertyWebkitNbspMode:
3235 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
3236 case CSSPropertyWebkitOverflowScrolling:
3238 case CSSPropertyWebkitPrintColorAdjust:
3239 #if ENABLE(CSS_REGIONS)
3240 case CSSPropertyWebkitRegionBreakAfter:
3241 case CSSPropertyWebkitRegionBreakBefore:
3242 case CSSPropertyWebkitRegionBreakInside:
3243 case CSSPropertyWebkitRegionFragment:
3245 case CSSPropertyWebkitRtlOrdering:
3246 case CSSPropertyWebkitRubyPosition:
3247 #if ENABLE(CSS3_TEXT)
3248 case CSSPropertyWebkitTextAlignLast:
3250 case CSSPropertyWebkitTextCombine:
3251 #if ENABLE(CSS3_TEXT)
3252 case CSSPropertyWebkitTextJustify:
3254 case CSSPropertyWebkitTextSecurity:
3255 case CSSPropertyTransformStyle:
3256 case CSSPropertyWebkitTransformStyle:
3257 case CSSPropertyWebkitUserDrag:
3258 case CSSPropertyWebkitUserModify:
3259 case CSSPropertyWebkitUserSelect:
3260 case CSSPropertyWebkitWritingMode:
3261 case CSSPropertyWhiteSpace:
3262 case CSSPropertyWordBreak:
3263 case CSSPropertyWordWrap:
3264 #if ENABLE(TOUCH_EVENTS)
3265 case CSSPropertyTouchAction:
3267 #if ENABLE(CSS_SCROLL_SNAP)
3268 case CSSPropertyWebkitScrollSnapType:
3270 #if ENABLE(CSS_TRAILING_WORD)
3271 case CSSPropertyAppleTrailingWord:
3273 // These properties should be handled before in isValidKeywordPropertyAndValue().
3274 ASSERT_NOT_REACHED();
3276 #if ENABLE(CSS_DEVICE_ADAPTATION)
3277 // Properties bellow are validated inside parseViewportProperty, because we
3278 // check for parser state inViewportScope. We need to invalidate if someone
3279 // adds them outside a @viewport rule.
3280 case CSSPropertyMaxZoom:
3281 case CSSPropertyMinZoom:
3282 case CSSPropertyOrientation:
3283 case CSSPropertyUserZoom:
3284 validPrimitive = false;
3287 #if ENABLE(CSS_SCROLL_SNAP)
3288 case CSSPropertyWebkitScrollSnapPointsX:
3289 case CSSPropertyWebkitScrollSnapPointsY:
3290 if (id == CSSValueElements) {
3291 validPrimitive = true;
3294 return parseNonElementSnapPoints(propId, important);
3295 case CSSPropertyWebkitScrollSnapDestination: // <length>{2}
3296 return parseScrollSnapDestination(propId, important);
3297 case CSSPropertyWebkitScrollSnapCoordinate:
3298 return parseScrollSnapCoordinate(propId, important);
3302 return parseSVGValue(propId, important);
3305 if (validPrimitive) {
3306 parsedValue = parseValidPrimitive(id, valueWithCalculation);
3307 m_valueList->next();
3310 if (parsedValue && (!m_valueList->current() || inShorthand())) {
3311 addProperty(propId, parsedValue.releaseNonNull(), important);
3317 void CSSParser::addFillValue(RefPtr<CSSValue>& lval, Ref<CSSValue>&& rval)
3320 lval = WTFMove(rval);
3324 if (lval->isBaseValueList()) {
3325 downcast<CSSValueList>(*lval).append(WTFMove(rval));
3329 auto list = CSSValueList::createCommaSeparated();
3330 list.get().append(lval.releaseNonNull());
3331 list.get().append(WTFMove(rval));
3332 lval = WTFMove(list);
3335 static bool isContentDistributionKeyword(CSSValueID id)
3337 return id == CSSValueSpaceBetween || id == CSSValueSpaceAround
3338 || id == CSSValueSpaceEvenly || id == CSSValueStretch;
3341 static bool isContentPositionKeyword(CSSValueID id)
3343 return id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
3344 || id == CSSValueFlexStart || id == CSSValueFlexEnd
3345 || id == CSSValueLeft || id == CSSValueRight;
3348 static inline bool isBaselinePositionKeyword(CSSValueID id)
3350 return id == CSSValueBaseline || id == CSSValueLastBaseline;
3353 static bool isAlignmentOverflowKeyword(CSSValueID id)
3355 return id == CSSValueUnsafe || id == CSSValueSafe;
3358 static bool isItemPositionKeyword(CSSValueID id)
3360 return id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
3361 || id == CSSValueSelfStart || id == CSSValueSelfEnd || id == CSSValueFlexStart
3362 || id == CSSValueFlexEnd || id == CSSValueLeft || id == CSSValueRight;
3365 bool CSSParser::parseLegacyPosition(CSSPropertyID propId, bool important)
3367 // [ legacy && [ left | right | center ]
3369 CSSParserValue* value = m_valueList->current();
3373 if (value->id == CSSValueLegacy) {
3374 value = m_valueList->next();
3377 if (value->id != CSSValueCenter && value->id != CSSValueLeft && value->id != CSSValueRight)
3379 } else if (value->id == CSSValueCenter || value->id == CSSValueLeft || value->id == CSSValueRight) {
3380 if (!m_valueList->next() || m_valueList->current()->id != CSSValueLegacy)
3385 auto& cssValuePool = CSSValuePool::singleton();
3386 addProperty(propId, createPrimitiveValuePair(cssValuePool.createIdentifierValue(CSSValueLegacy), cssValuePool.createIdentifierValue(value->id)), important);
3387 return !m_valueList->next();
3390 RefPtr<CSSContentDistributionValue> CSSParser::parseContentDistributionOverflowPosition()
3392 // normal | <baseline-position> | <content-distribution> || [ <overflow-position>? && <content-position> ]
3393 // <baseline-position> = baseline | last-baseline;
3394 // <content-distribution> = space-between | space-around | space-evenly | stretch;
3395 // <content-position> = center | start | end | flex-start | flex-end | left | right;
3396 // <overflow-position> = unsafe | safe
3398 CSSParserValue* value = m_valueList->current();
3402 // auto | <baseline-position>
3403 if (value->id == CSSValueNormal || isBaselinePositionKeyword(value->id)) {
3404 m_valueList->next();
3405 return CSSContentDistributionValue::create(CSSValueInvalid, value->id, CSSValueInvalid);
3408 CSSValueID distribution = CSSValueInvalid;
3409 CSSValueID position = CSSValueInvalid;
3410 CSSValueID overflow = CSSValueInvalid;
3412 if (isContentDistributionKeyword(value->id)) {
3413 if (distribution != CSSValueInvalid)
3415 distribution = value->id;
3416 } else if (isContentPositionKeyword(value->id)) {
3417 if (position != CSSValueInvalid)
3419 position = value->id;
3420 } else if (isAlignmentOverflowKeyword(value->id)) {
3421 if (overflow != CSSValueInvalid)
3423 overflow = value->id;
3426 value = m_valueList->next();
3429 // The grammar states that we should have at least <content-distribution> or
3430 // <content-position> ( <content-distribution> || <content-position> ).
3431 if (position == CSSValueInvalid && distribution == CSSValueInvalid)
3434 // The grammar states that <overflow-position> must be associated to <content-position>.
3435 if (overflow != CSSValueInvalid && position == CSSValueInvalid)
3438 return CSSContentDistributionValue::create(distribution, position, overflow);
3441 bool CSSParser::parseItemPositionOverflowPosition(CSSPropertyID propId, bool important)
3443 // auto | normal | stretch | <baseline-position> | [<item-position> && <overflow-position>? ]
3444 // <baseline-position> = baseline | last-baseline;
3445 // <item-position> = center | start | end | self-start | self-end | flex-start | flex-end | left | right;
3446 // <overflow-position> = unsafe | safe
3448 CSSParserValue* value = m_valueList->current();
3452 if (value->id == CSSValueAuto || value->id == CSSValueNormal || value->id == CSSValueStretch || isBaselinePositionKeyword(value->id)) {
3453 // align-items property does not allow the 'auto' value.
3454 if (value->id == CSSValueAuto && propId == CSSPropertyAlignItems)
3456 if (m_valueList->next())
3459 addProperty(propId, CSSValuePool::singleton().createIdentifierValue(value->id), important);
3463 RefPtr<CSSPrimitiveValue> position;
3464 RefPtr<CSSPrimitiveValue> overflowAlignmentKeyword;
3465 if (isItemPositionKeyword(value->id)) {
3466 position = CSSValuePool::singleton().createIdentifierValue(value->id);
3467 value = m_valueList->next();
3469 if (value->id != CSSValueUnsafe && value->id != CSSValueSafe)
3471 overflowAlignmentKeyword = CSSValuePool::singleton().createIdentifierValue(value->id);
3473 } else if (isAlignmentOverflowKeyword(value->id)) {
3474 overflowAlignmentKeyword = CSSValuePool::singleton().createIdentifierValue(value->id);
3475 value = m_valueList->next();
3476 if (value && isItemPositionKeyword(value->id))
3477 position = CSSValuePool::singleton().createIdentifierValue(value->id);
3483 if (m_valueList->next())
3487 if (overflowAlignmentKeyword)
3488 addProperty(propId, createPrimitiveValuePair(position.releaseNonNull(), overflowAlignmentKeyword.releaseNonNull()), important);
3490 addProperty(propId, position.releaseNonNull(), important);
3495 static bool parseBackgroundClip(CSSParserValue& parserValue, RefPtr<CSSValue>& cssValue)
3497 if (parserValue.id == CSSValueBorderBox || parserValue.id == CSSValuePaddingBox
3498 || parserValue.id == CSSValueContentBox || parserValue.id == CSSValueWebkitText) {
3499 cssValue = CSSValuePool::singleton().createIdentifierValue(parserValue.id);
3505 bool CSSParser::useLegacyBackgroundSizeShorthandBehavior() const
3507 return m_context.useLegacyBackgroundSizeShorthandBehavior;
3510 #if ENABLE(CSS_SCROLL_SNAP)
3511 bool CSSParser::parseNonElementSnapPoints(CSSPropertyID propId, bool important)
3513 auto values = CSSValueList::createSpaceSeparated();
3514 while (CSSParserValue* value = m_valueList->current()) {
3515 ValueWithCalculation valueWithCalculation(*value);
3516 if (validateUnit(valueWithCalculation, FPercent | FLength))
3517 values->append(createPrimitiveNumericValue(valueWithCalculation));
3518 else if (value->unit == CSSParserValue::Function
3519 && value->function->args
3520 && value->function->args->size() == 1
3521 && equalLettersIgnoringASCIICase(value->function->name, "repeat(")) {
3522 ValueWithCalculation argumentWithCalculation(*value->function->args.get()->current());
3523 if (validateUnit(argumentWithCalculation, FLength | FPercent | FNonNeg)) {
3524 values->append(CSSValuePool::singleton().createValue(LengthRepeat::create(createPrimitiveNumericValue(argumentWithCalculation))));
3525 m_valueList->next();
3526 if (m_valueList->current())
3532 m_valueList->next();
3534 if (values->length()) {
3535 addProperty(propId, WTFMove(values), important);
3536 m_valueList->next();
3542 bool CSSParser::parseScrollSnapPositions(RefPtr<CSSValue>& cssValueX, RefPtr<CSSValue>& cssValueY)
3544 cssValueX = parsePositionX(*m_valueList);
3548 // Don't accept odd-length lists of positions (must always have an X and a Y):
3549 if (!m_valueList->next())
3552 cssValueY = parsePositionY(*m_valueList);
3559 bool CSSParser::parseScrollSnapDestination(CSSPropertyID propId, bool important)
3561 auto position = CSSValueList::createSpaceSeparated();
3562 if (m_valueList->size() != 2)
3565 RefPtr<CSSValue> cssValueX, cssValueY;
3566 if (!parseScrollSnapPositions(cssValueX, cssValueY))
3569 position->append(cssValueX.releaseNonNull());
3570 position->append(cssValueY.releaseNonNull());
3571 addProperty(propId, WTFMove(position), important);
3572 m_valueList->next();
3576 bool CSSParser::parseScrollSnapCoordinate(CSSPropertyID propId, bool important)
3578 auto positions = CSSValueList::createSpaceSeparated();
3579 while (m_valueList->current()) {
3580 RefPtr<CSSValue> cssValueX, cssValueY;
3581 if (!parseScrollSnapPositions(cssValueX, cssValueY))
3584 positions->append(cssValueX.releaseNonNull());
3585 positions->append(cssValueY.releaseNonNull());
3586 m_valueList->next();
3589 if (positions->length()) {
3590 addProperty(propId, WTFMove(positions), important);
3597 const int cMaxFillProperties = 9;
3599 bool CSSParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* properties, int numProperties, bool important)
3601 ASSERT(numProperties <= cMaxFillProperties);
3602 if (numProperties > cMaxFillProperties)
3605 ShorthandScope scope(this, propId);
3607 bool parsedProperty[cMaxFillProperties] = { false };
3608 RefPtr<CSSValue> values[cMaxFillProperties];
3609 RefPtr<CSSValue> clipValue;
3610 RefPtr<CSSValue> positionYValue;
3611 RefPtr<CSSValue> repeatYValue;
3612 bool foundClip = false;
3614 bool foundPositionCSSProperty = false;
3616 auto& cssValuePool = CSSValuePool::singleton();
3617 while (m_valueList->current()) {
3618 CSSParserValue& currentValue = *m_valueList->current();
3619 if (currentValue.unit == CSSParserValue::Operator && currentValue.iValue == ',') {
3620 // We hit the end. Fill in all remaining values with the initial value.
3621 m_valueList->next();
3622 for (i = 0; i < numProperties; ++i) {
3623 if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i])
3624 // Color is not allowed except as the last item in a list for backgrounds.
3625 // Reject the entire property.
3628 if (!parsedProperty[i] && properties[i] != CSSPropertyBackgroundColor) {
3629 addFillValue(values[i], cssValuePool.createImplicitInitialValue());
3630 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3631 addFillValue(positionYValue, cssValuePool.createImplicitInitialValue());
3632 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3633 addFillValue(repeatYValue, cssValuePool.createImplicitInitialValue());
3634 if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) {
3635 // If background-origin wasn't present, then reset background-clip also.
3636 addFillValue(clipValue, cssValuePool.createImplicitInitialValue());
3639 parsedProperty[i] = false;
3641 if (!m_valueList->current())
3645 bool sizeCSSPropertyExpected = false;
3646 if (isForwardSlashOperator(currentValue) && foundPositionCSSProperty) {
3647 sizeCSSPropertyExpected = true;
3648 m_valueList->next();
3651 foundPositionCSSProperty = false;
3653 for (i = 0; !found && i < numProperties; ++i) {
3655 if (sizeCSSPropertyExpected && (properties[i] != CSSPropertyBackgroundSize && properties[i] != CSSPropertyWebkitMaskSize))
3657 if (!sizeCSSPropertyExpected && (properties[i] == CSSPropertyBackgroundSize || properties[i] == CSSPropertyWebkitMaskSize))
3660 if (!parsedProperty[i]) {
3661 RefPtr<CSSValue> val1;
3662 RefPtr<CSSValue> val2;
3663 CSSPropertyID propId1, propId2;
3664 CSSParserValue& parserValue = *m_valueList->current();
3666 if (parseFillProperty(properties[i], propId1, propId2, val1, val2)) {
3667 parsedProperty[i] = found = true;
3668 addFillValue(values[i], val1.releaseNonNull());
3669 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3670 addFillValue(positionYValue, val2.releaseNonNull());
3671 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3672 addFillValue(repeatYValue, val2.releaseNonNull());
3673 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
3674 // Reparse the value as a clip, and see if we succeed.
3675 if (parseBackgroundClip(parserValue, val1))
3676 addFillValue(clipValue, val1.releaseNonNull()); // The property parsed successfully.
3678 addFillValue(clipValue, cssValuePool.createImplicitInitialValue()); // Some value was used for origin that is not supported by clip. Just reset clip instead.
3680 if (properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip)
3682 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3683 foundPositionCSSProperty = true;
3688 // if we didn't find at least one match, this is an
3689 // invalid shorthand and we have to ignore it
3694 // Now add all of the properties we found.
3695 for (i = 0; i < numProperties; ++i) {
3696 // Fill in any remaining properties with the initial value.
3697 if (!parsedProperty[i]) {
3698 addFillValue(values[i], cssValuePool.createImplicitInitialValue());
3699 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3700 addFillValue(positionYValue, cssValuePool.createImplicitInitialValue());
3701 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3702 addFillValue(repeatYValue, cssValuePool.createImplicitInitialValue());
3703 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
3704 // If background-origin wasn't present, then reset background-clip also.
3705 addFillValue(clipValue, cssValuePool.createImplicitInitialValue());
3708 if (properties[i] == CSSPropertyBackgroundPosition) {
3709 addProperty(CSSPropertyBackgroundPositionX, WTFMove(values[i]), important);
3710 // it's OK to call WTFMove(positionYValue) since we only see CSSPropertyBackgroundPosition once
3711 addProperty(CSSPropertyBackgroundPositionY, WTFMove(positionYValue), important);
3712 } else if (properties[i] == CSSPropertyWebkitMaskPosition) {
3713 addProperty(CSSPropertyWebkitMaskPositionX, WTFMove(values[i]), important);
3714 // it's OK to call WTFMove(positionYValue) since we only see CSSPropertyWebkitMaskPosition once
3715 addProperty(CSSPropertyWebkitMaskPositionY, WTFMove(positionYValue), important);
3716 } else if (properties[i] == CSSPropertyBackgroundRepeat) {
3717 addProperty(CSSPropertyBackgroundRepeatX, WTFMove(values[i]), important);
3718 // it's OK to call WTFMove(repeatYValue) since we only see CSSPropertyBackgroundPosition once
3719 addProperty(CSSPropertyBackgroundRepeatY, WTFMove(repeatYValue), important);
3720 } else if (properties[i] == CSSPropertyWebkitMaskRepeat) {
3721 addProperty(CSSPropertyWebkitMaskRepeatX, WTFMove(values[i]), important);
3722 // it's OK to call WTFMove(repeatYValue) since we only see CSSPropertyBackgroundPosition once
3723 addProperty(CSSPropertyWebkitMaskRepeatY, WTFMove(repeatYValue), important);
3724 } else if ((properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) && !foundClip)
3725 // Value is already set while updating origin
3727 else if (properties[i] == CSSPropertyBackgroundSize && !parsedProperty[i] && useLegacyBackgroundSizeShorthandBehavior())
3730 addProperty(properties[i], WTFMove(values[i]), important);
3732 // Add in clip values when we hit the corresponding origin property.
3733 if (properties[i] == CSSPropertyBackgroundOrigin && !foundClip)
3734 addProperty(CSSPropertyBackgroundClip, WTFMove(clipValue), important);
3735 else if (properties[i] == CSSPropertyWebkitMaskOrigin && !foundClip)
3736 addProperty(CSSPropertyWebkitMaskClip, WTFMove(clipValue), important);
3742 void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, Ref<CSSValue>&& rval)
3745 lval = WTFMove(rval);
3749 if (is<CSSValueList>(*lval)) {
3750 downcast<CSSValueList>(*lval).append(WTFMove(rval));
3754 auto list = CSSValueList::createCommaSeparated();
3755 list->append(lval.releaseNonNull());
3756 list->append(WTFMove(rval));
3757 lval = WTFMove(list);
3760 bool CSSParser::parseAnimationShorthand(CSSPropertyID propId, bool important)
3762 ASSERT(propId == CSSPropertyAnimation || propId == CSSPropertyWebkitAnimation);
3764 const unsigned numProperties = 8;
3765 const StylePropertyShorthand& shorthand = animationShorthandForParsing(propId);
3767 // The list of properties in the shorthand should be the same
3768 // length as the list with animation name in last position, even though they are
3769 // in a different order.
3770 ASSERT(numProperties == shorthand.length());
3771 ASSERT(numProperties == animationShorthand().length());
3772 ASSERT(numProperties == webkitAnimationShorthand().length());
3774 ShorthandScope scope(this, propId);
3776 bool parsedProperty[numProperties] = { false };
3777 AnimationParseContext context;
3778 RefPtr<CSSValue> values[numProperties];
3780 auto& cssValuePool = CSSValuePool::singleton();
3782 while (m_valueList->current()) {
3783 CSSParserValue* val = m_valueList->current();
3784 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3785 // We hit the end. Fill in all remaining values with the initial value.
3786 m_valueList->next();
3787 for (i = 0; i < numProperties; ++i) {
3788 if (!parsedProperty[i])
3789 addAnimationValue(values[i], cssValuePool.createImplicitInitialValue());
3790 parsedProperty[i] = false;
3792 if (!m_valueList->current())
3794 context.commitFirstAnimation();
3798 for (i = 0; i < numProperties; ++i) {
3799 if (!parsedProperty[i]) {
3800 RefPtr<CSSValue> val;
3801 if (parseAnimationProperty(shorthand.properties()[i], val, context)) {
3802 parsedProperty[i] = found = true;
3803 addAnimationValue(values[i], val.releaseNonNull());
3808 // There are more values to process but 'none' or 'all' were already defined as the animation property, the declaration becomes invalid.
3809 if (!context.animationPropertyKeywordAllowed() && context.hasCommittedFirstAnimation())
3813 // if we didn't find at least one match, this is an
3814 // invalid shorthand and we have to ignore it
3819 // Fill in any remaining properties with the initial value.
3820 for (i = 0; i < numProperties; ++i) {
3821 if (!parsedProperty[i])
3822 addAnimationValue(values[i], cssValuePool.createImplicitInitialValue());
3825 // Now add all of the properties we found.
3826 // In this case we have to explicitly set the variant form as well,
3827 // to make sure that a shorthand clears all existing prefixed and
3828 // unprefixed values.
3829 for (i = 0; i < numProperties; ++i)
3830 addPropertyWithPrefixingVariant(shorthand.properties()[i], WTFMove(values[i]), important);
3835 void CSSParser::addPropertyWithPrefixingVariant(CSSPropertyID propId, RefPtr<CSSValue>&& value, bool important, bool implicit)
3837 addProperty(propId, value.copyRef(), important, implicit);
3839 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propId);
3840 if (prefixingVariant == propId)
3843 if (m_currentShorthand) {
3844 // We can't use ShorthandScope here as we can already be inside one (e.g we are parsing CSSTransition).
3845 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
3846 addProperty(prefixingVariant, WTFMove(value), important, implicit);
3847 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
3849 addProperty(prefixingVariant, WTFMove(value), important, implicit);
3853 RefPtr<CSSPrimitiveValue> CSSParser::parseColumnWidth()
3855 ValueWithCalculation valueWithCalculation(*m_valueList->current());
3856 CSSValueID id = valueWithCalculation.value().id;
3857 // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property.
3858 if (id != CSSValueAuto && !(validateUnit(valueWithCalculation, FLength | FNonNeg, CSSStrictMode) && parsedDouble(valueWithCalculation)))
3861 auto parsedValue = parseValidPrimitive(id, valueWithCalculation);
3862 m_valueList->next();
3866 RefPtr<CSSPrimitiveValue> CSSParser::parseColumnCount()
3868 ValueWithCalculation valueWithCalculation(*m_valueList->current());
3869 CSSValueID id = valueWithCalculation.value().id;
3871 if (id != CSSValueAuto && !validateUnit(valueWithCalculation, FPositiveInteger, CSSQuirksMode))
3874 auto parsedValue = parseValidPrimitive(id, valueWithCalculation);
3875 m_valueList->next();
3879 bool CSSParser::parseColumnsShorthand(bool important)
3881 RefPtr<CSSValue> columnWidth;
3882 RefPtr<CSSValue> columnCount;
3883 bool hasPendingExplicitAuto = false;
3885 for (unsigned propertiesParsed = 0; CSSParserValue* value = m_valueList->current(); ++propertiesParsed) {
3886 if (propertiesParsed >= 2)
3887 return false; // Too many values for this shorthand. Invalid declaration.
3888 if (!propertiesParsed && value->id == CSSValueAuto) {
3889 // 'auto' is a valid value for any of the two longhands, and at this point
3890 // we don't know which one(s) it is meant for. We need to see if there are other values first.
3891 m_valueList->next();
3892 hasPendingExplicitAuto = true;
3895 if ((columnWidth = parseColumnWidth()))
3899 if ((columnCount = parseColumnCount()))
3902 // If we didn't find at least one match, this is an invalid shorthand and we have to ignore it.
3907 // Any unassigned property at this point will become implicit 'auto'.
3909 addProperty(CSSPropertyColumnWidth, WTFMove(columnWidth), important);
3911 addProperty(CSSPropertyColumnWidth, CSSValuePool::singleton().createIdentifierValue(CSSValueAuto), important, !hasPendingExplicitAuto /* implicit */);
3912 hasPendingExplicitAuto = false;
3916 addProperty(CSSPropertyColumnCount, WTFMove(columnCount), important);
3918 addProperty(CSSPropertyColumnCount, CSSValuePool::singleton().createIdentifierValue(CSSValueAuto), important, !hasPendingExplicitAuto /* implicit */);
3923 bool CSSParser::parseTransitionShorthand(CSSPropertyID propId, bool important)
3925 const unsigned numProperties = 4;
3926 const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
3927 ASSERT(numProperties == shorthand.length());
3929 ShorthandScope scope(this, propId);
3931 bool parsedProperty[numProperties] = { false };
3932 AnimationParseContext context;
3933 RefPtr<CSSValue> values[numProperties];
3935 auto& cssValuePool = CSSValuePool::singleton();
3937 while (m_valueList->current()) {
3938 CSSParserValue* val = m_valueList->current();
3939 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3940 // We hit the end. Fill in all remaining values with the initial value.
3941 m_valueList->next();
3942 for (i = 0; i < numProperties; ++i) {
3943 if (!parsedProperty[i])
3944 addAnimationValue(values[i], cssValuePool.createImplicitInitialValue());
3945 parsedProperty[i] = false;
3947 if (!m_valueList->current())
3949 context.commitFirstAnimation();
3953 for (i = 0; !found && i < numProperties; ++i) {
3954 if (!parsedProperty[i]) {
3955 RefPtr<CSSValue> val;
3956 if (parseAnimationProperty(shorthand.properties()[i], val, context)) {
3957 parsedProperty[i] = found = true;
3958 addAnimationValue(values[i], val.releaseNonNull());
3961 // There are more values to process but 'none' or 'all' were already defined as the animation property, the declaration becomes invalid.
3962 if (!context.animationPropertyKeywordAllowed() && context.hasCommittedFirstAnimation())
3967 // if we didn't find at least one match, this is an
3968 // invalid shorthand and we have to ignore it
3973 // Fill in any remaining properties with the initial value.
3974 for (i = 0; i < numProperties; ++i) {
3975 if (!parsedProperty[i])
3976 addAnimationValue(values[i], cssValuePool.createImplicitInitialValue());
3979 // Now add all of the properties we found.
3980 // In this case we have to explicitly set the variant form as well,
3981 // to make sure that a shorthand clears all existing prefixed and
3982 // unprefixed values.
3983 for (i = 0; i < numProperties; ++i)
3984 addPropertyWithPrefixingVariant(shorthand.properties()[i], WTFMove(values[i]), important);