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::addPropertyWithPrefixingVariant(CSSPropertyID propId, RefPtr<CSSValue>&& value, bool important, bool implicit)
1610 addProperty(propId, value.copyRef(), important, implicit);
1612 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propId);
1613 if (prefixingVariant == propId)
1616 if (m_currentShorthand) {
1617 // We can't use ShorthandScope here as we can already be inside one (e.g we are parsing CSSTransition).
1618 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
1619 addProperty(prefixingVariant, WTFMove(value), important, implicit);
1620 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
1622 addProperty(prefixingVariant, WTFMove(value), important, implicit);
1625 void CSSParser::addProperty(CSSPropertyID propId, RefPtr<CSSValue>&& value, bool important, bool implicit)
1627 // This property doesn't belong to a shorthand or is a CSS variable (which will be resolved later).
1628 if (!m_currentShorthand) {
1629 m_parsedProperties.append(CSSProperty(propId, WTFMove(value), important, false, CSSPropertyInvalid, m_implicitShorthand || implicit));
1633 auto shorthands = matchingShorthandsForLonghand(propId);
1634 if (shorthands.size() == 1)
1635 m_parsedProperties.append(CSSProperty(propId, WTFMove(value), important, true, CSSPropertyInvalid, m_implicitShorthand || implicit));
1637 m_parsedProperties.append(CSSProperty(propId, WTFMove(value), important, true, indexOfShorthandForLonghand(m_currentShorthand, shorthands), m_implicitShorthand || implicit));
1640 void CSSParser::rollbackLastProperties(int num)
1643 ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num));
1644 m_parsedProperties.shrink(m_parsedProperties.size() - num);
1647 void CSSParser::clearProperties()
1649 m_parsedProperties.clear();
1650 m_numParsedPropertiesBeforeMarginBox = invalidParsedPropertiesCount;
1653 URL CSSParser::completeURL(const CSSParserContext& context, const String& url)
1657 if (context.charset.isEmpty())
1658 return URL(context.baseURL, url);
1659 return URL(context.baseURL, url, context.charset);
1662 URL CSSParser::completeURL(const String& url) const
1664 return completeURL(m_context, url);
1667 bool CSSParser::validateCalculationUnit(ValueWithCalculation& valueWithCalculation, Units unitFlags)
1669 bool mustBeNonNegative = unitFlags & FNonNeg;
1671 RefPtr<CSSCalcValue> calculation;
1672 if (valueWithCalculation.calculation()) {
1673 // The calculation value was already parsed so we reuse it. However, we may need to update its range.
1674 calculation = valueWithCalculation.calculation();
1675 calculation->setPermittedValueRange(mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll);
1677 valueWithCalculation.setCalculation(parseCalculation(valueWithCalculation, mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll));
1678 calculation = valueWithCalculation.calculation();
1683 bool isValid = false;
1684 switch (calculation->category()) {
1686 isValid = (unitFlags & FNumber);
1687 if (!isValid && (unitFlags & FInteger) && calculation->isInt())
1689 if (!isValid && (unitFlags & FPositiveInteger) && calculation->isInt() && calculation->isPositive())
1693 isValid = (unitFlags & FLength);
1696 isValid = (unitFlags & FPercent);
1698 case CalcPercentLength:
1699 isValid = (unitFlags & FPercent) && (unitFlags & FLength);
1701 case CalcPercentNumber:
1702 isValid = (unitFlags & FPercent) && (unitFlags & FNumber);
1705 isValid = (unitFlags & FAngle);
1708 isValid = (unitFlags & FTime);
1711 isValid = (unitFlags & FFrequency);
1720 inline bool CSSParser::shouldAcceptUnitLessValues(CSSParserValue& value, Units unitFlags, CSSParserMode cssParserMode)
1722 // Qirks mode and svg presentation attributes accept unit less values.
1723 return (unitFlags & (FLength | FAngle | FTime)) && (!value.fValue || cssParserMode == CSSQuirksMode || cssParserMode == SVGAttributeMode);
1726 bool CSSParser::validateUnit(ValueWithCalculation& valueWithCalculation, Units unitFlags, CSSParserMode cssParserMode)
1728 if (isCalculation(valueWithCalculation))
1729 return validateCalculationUnit(valueWithCalculation, unitFlags);
1732 switch (valueWithCalculation.value().unit) {
1733 case CSSPrimitiveValue::CSS_NUMBER:
1734 b = (unitFlags & FNumber);
1735 if (!b && shouldAcceptUnitLessValues(valueWithCalculation, unitFlags, cssParserMode)) {
1736 valueWithCalculation.value().unit = (unitFlags & FLength) ? CSSPrimitiveValue::CSS_PX :
1737 ((unitFlags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS);
1740 if (!b && (unitFlags & FInteger) && valueWithCalculation.value().isInt)
1742 if (!b && (unitFlags & FPositiveInteger) && valueWithCalculation.value().isInt && valueWithCalculation.value().fValue > 0)
1745 case CSSPrimitiveValue::CSS_PERCENTAGE:
1746 b = (unitFlags & FPercent);
1748 case CSSParserValue::Q_EMS:
1749 case CSSPrimitiveValue::CSS_EMS:
1750 case CSSPrimitiveValue::CSS_REMS:
1751 case CSSPrimitiveValue::CSS_CHS:
1752 case CSSPrimitiveValue::CSS_EXS:
1753 case CSSPrimitiveValue::CSS_PX:
1754 case CSSPrimitiveValue::CSS_CM:
1755 case CSSPrimitiveValue::CSS_MM:
1756 case CSSPrimitiveValue::CSS_IN:
1757 case CSSPrimitiveValue::CSS_PT:
1758 case CSSPrimitiveValue::CSS_PC:
1759 case CSSPrimitiveValue::CSS_VW:
1760 case CSSPrimitiveValue::CSS_VH:
1761 case CSSPrimitiveValue::CSS_VMIN:
1762 case CSSPrimitiveValue::CSS_VMAX:
1763 b = (unitFlags & FLength);
1765 case CSSPrimitiveValue::CSS_MS:
1766 case CSSPrimitiveValue::CSS_S:
1767 b = (unitFlags & FTime);
1769 case CSSPrimitiveValue::CSS_DEG:
1770 case CSSPrimitiveValue::CSS_RAD:
1771 case CSSPrimitiveValue::CSS_GRAD:
1772 case CSSPrimitiveValue::CSS_TURN:
1773 b = (unitFlags & FAngle);
1775 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1776 case CSSPrimitiveValue::CSS_DPPX:
1777 case CSSPrimitiveValue::CSS_DPI:
1778 case CSSPrimitiveValue::CSS_DPCM:
1779 b = (unitFlags & FResolution);
1782 case CSSPrimitiveValue::CSS_HZ:
1783 case CSSPrimitiveValue::CSS_KHZ:
1784 case CSSPrimitiveValue::CSS_DIMENSION:
1788 if (b && unitFlags & FNonNeg && valueWithCalculation.value().fValue < 0)
1790 if (b && std::isinf(valueWithCalculation.value().fValue))
1795 inline Ref<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(ValueWithCalculation& valueWithCalculation)
1797 if (valueWithCalculation.calculation())
1798 return CSSPrimitiveValue::create(valueWithCalculation.calculation());
1800 CSSParserValue& value = valueWithCalculation;
1801 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1802 ASSERT((value.unit >= CSSPrimitiveValue::CSS_NUMBER && value.unit <= CSSPrimitiveValue::CSS_KHZ)
1803 || (value.unit >= CSSPrimitiveValue::CSS_TURN && value.unit <= CSSPrimitiveValue::CSS_CHS)
1804 || (value.unit >= CSSPrimitiveValue::CSS_VW && value.unit <= CSSPrimitiveValue::CSS_VMAX)
1805 || (value.unit >= CSSPrimitiveValue::CSS_DPPX && value.unit <= CSSPrimitiveValue::CSS_DPCM));
1807 ASSERT((value.unit >= CSSPrimitiveValue::CSS_NUMBER && value.unit <= CSSPrimitiveValue::CSS_KHZ)
1808 || (value.unit >= CSSPrimitiveValue::CSS_TURN && value.unit <= CSSPrimitiveValue::CSS_CHS)
1809 || (value.unit >= CSSPrimitiveValue::CSS_VW && value.unit <= CSSPrimitiveValue::CSS_VMAX));
1811 return CSSValuePool::singleton().createValue(value.fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value.unit));
1814 inline Ref<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSParserValue& value)
1816 ASSERT(value.unit == CSSPrimitiveValue::CSS_STRING || value.unit == CSSPrimitiveValue::CSS_IDENT);
1817 return CSSValuePool::singleton().createValue(value.string, CSSPrimitiveValue::CSS_STRING);
1820 static inline bool isComma(CSSParserValue* value)
1822 return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
1825 static inline bool isForwardSlashOperator(CSSParserValue& value)
1827 return value.unit == CSSParserValue::Operator && value.iValue == '/';
1830 bool CSSParser::isValidSize(ValueWithCalculation& valueWithCalculation)
1832 int id = valueWithCalculation.value().id;
1833 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent)
1835 return !id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg);
1838 inline RefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(CSSValueID identifier, ValueWithCalculation& valueWithCalculation)
1841 return CSSValuePool::singleton().createIdentifierValue(identifier);
1843 if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
1844 return createPrimitiveStringValue(valueWithCalculation);
1845 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_NUMBER && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_KHZ)
1846 return createPrimitiveNumericValue(valueWithCalculation);
1847 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_TURN && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_CHS)
1848 return createPrimitiveNumericValue(valueWithCalculation);
1849 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_VW && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_VMAX)
1850 return createPrimitiveNumericValue(valueWithCalculation);
1851 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1852 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_DPPX && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_DPCM)
1853 return createPrimitiveNumericValue(valueWithCalculation);
1855 if (valueWithCalculation.value().unit >= CSSParserValue::Q_EMS)
1856 return CSSPrimitiveValue::createAllowingMarginQuirk(valueWithCalculation.value().fValue, CSSPrimitiveValue::CSS_EMS);
1857 if (valueWithCalculation.calculation())
1858 return CSSPrimitiveValue::create(valueWithCalculation.calculation());
1863 void CSSParser::addExpandedPropertyForValue(CSSPropertyID propId, Ref<CSSValue>&& value, bool important)
1865 const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
1866 unsigned shorthandLength = shorthand.length();
1867 if (!shorthandLength) {
1868 addProperty(propId, WTFMove(value), important);
1872 ShorthandScope scope(this, propId);
1873 const CSSPropertyID* longhands = shorthand.properties();
1874 for (unsigned i = 0; i < shorthandLength; ++i)
1875 addProperty(longhands[i], value.copyRef(), important);
1878 RefPtr<CSSValue> CSSParser::parseVariableDependentValue(CSSPropertyID propID, const CSSVariableDependentValue& dependentValue, const CustomPropertyValueMap& customProperties, TextDirection direction, WritingMode writingMode)
1880 m_valueList.reset(new CSSParserValueList());
1881 if (!dependentValue.valueList().buildParserValueListSubstitutingVariables(m_valueList.get(), customProperties))
1884 CSSPropertyID dependentValuePropertyID = dependentValue.propertyID();
1885 if (CSSProperty::isDirectionAwareProperty(dependentValuePropertyID))
1886 dependentValuePropertyID = CSSProperty::resolveDirectionAwareProperty(dependentValuePropertyID, direction, writingMode);
1888 if (!parseValue(dependentValuePropertyID, false))
1891 for (auto& property : m_parsedProperties) {
1892 if (property.id() == propID)
1893 return property.value();
1898 #if ENABLE(CSS_IMAGE_SET)
1899 static bool isImageSetFunctionValue(const CSSParserValue& value)
1901 return value.unit == CSSParserValue::Function && (equalLettersIgnoringASCIICase(value.function->name, "image-set(") || equalLettersIgnoringASCIICase(value.function->name, "-webkit-image-set("));
1905 bool CSSParser::parseValue(CSSPropertyID propId, bool important)
1907 if (!m_valueList || !m_valueList->current())
1910 ValueWithCalculation valueWithCalculation(*m_valueList->current());
1911 CSSValueID id = valueWithCalculation.value().id;
1913 if (propId == CSSPropertyCustom)
1914 return parseCustomPropertyDeclaration(important, id);
1916 if (m_valueList->containsVariables()) {
1917 auto valueList = CSSValueList::createFromParserValueList(*m_valueList);
1918 addExpandedPropertyForValue(propId, CSSVariableDependentValue::create(WTFMove(valueList), propId), important);
1922 auto& cssValuePool = CSSValuePool::singleton();
1923 unsigned num = inShorthand() ? 1 : m_valueList->size();
1925 if (id == CSSValueInherit) {
1928 addExpandedPropertyForValue(propId, cssValuePool.createInheritedValue(), important);
1931 else if (id == CSSValueInitial) {
1934 addExpandedPropertyForValue(propId, cssValuePool.createExplicitInitialValue(), important);
1936 } else if (id == CSSValueUnset) {
1939 addExpandedPropertyForValue(propId, cssValuePool.createUnsetValue(), important);
1941 } else if (id == CSSValueRevert) {
1944 addExpandedPropertyForValue(propId, cssValuePool.createRevertValue(), important);
1948 if (propId == CSSPropertyAll)
1949 return false; // "all" doesn't allow you to specify anything other than inherit/initial/unset.
1951 if (isKeywordPropertyID(propId)) {
1952 if (!isValidKeywordPropertyAndValue(propId, id, m_context, m_styleSheet))
1954 if (m_valueList->next() && !inShorthand())
1956 addProperty(propId, cssValuePool.createIdentifierValue(id), important);
1960 #if ENABLE(CSS_DEVICE_ADAPTATION)
1962 return parseViewportProperty(propId, important);
1965 bool validPrimitive = false;
1966 RefPtr<CSSValue> parsedValue;
1969 case CSSPropertySize: // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
1970 return parseSize(propId, important);
1972 case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit
1973 if (id == CSSValueNone)
1974 validPrimitive = true;
1976 return parseQuotes(propId, important);
1978 case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | isolate | isolate-override | plaintext | inherit
1979 if (id == CSSValueNormal
1980 || id == CSSValueEmbed
1981 || id == CSSValueBidiOverride
1982 || id == CSSValueWebkitIsolate
1983 || id == CSSValueWebkitIsolateOverride
1984 || id == CSSValueWebkitPlaintext)
1985 validPrimitive = true;
1988 case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
1989 // close-quote | no-open-quote | no-close-quote ]+ | inherit
1990 return parseContent(propId, important);
1992 case CSSPropertyAlt: // [ <string> | attr(X) ]
1993 return parseAlt(propId, important);
1995 case CSSPropertyClip: // <shape> | auto | inherit
1996 if (id == CSSValueAuto)
1997 validPrimitive = true;
1998 else if (valueWithCalculation.value().unit == CSSParserValue::Function)
1999 return parseClipShape(propId, important);
2002 /* Start of supported CSS properties with validation. This is needed for parseShorthand to work
2003 * correctly and allows optimization in WebCore::applyRule(..)
2005 case CSSPropertyOverflow: {
2006 ShorthandScope scope(this, propId);
2007 if (num != 1 || !parseValue(CSSPropertyOverflowY, important))
2010 RefPtr<CSSValue> overflowXValue;
2012 // FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. If this value has been
2013 // set using the shorthand, then for now overflow-x will default to auto, but once we implement
2014 // pagination controls, it should default to hidden. If the overflow-y value is anything but
2015 // paged-x or paged-y, then overflow-x and overflow-y should have the same value.
2016 if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
2017 overflowXValue = cssValuePool.createIdentifierValue(CSSValueAuto);
2019 overflowXValue = m_parsedProperties.last().value();
2020 addProperty(CSSPropertyOverflowX, WTFMove(overflowXValue), important);
2024 case CSSPropertyTextAlign:
2025 // left | right | center | justify | -webkit-left | -webkit-right | -webkit-center | -webkit-match-parent
2026 // | start | end | inherit | -webkit-auto (converted to start)
2027 // NOTE: <string> is not supported.
2028 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd)
2029 validPrimitive = true;
2032 case CSSPropertyFontWeight: { // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
2033 if (m_valueList->size() != 1)
2035 return parseFontWeight(important);
2038 case CSSPropertyFontSynthesis: // none | [ weight || style ]
2039 return parseFontSynthesis(important);
2041 case CSSPropertyBorderSpacing: {
2043 ShorthandScope scope(this, CSSPropertyBorderSpacing);
2044 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
2046 CSSValue* value = m_parsedProperties.last().value();
2047 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important);
2050 else if (num == 2) {
2051 ShorthandScope scope(this, CSSPropertyBorderSpacing);
2052 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important) || !parseValue(CSSPropertyWebkitBorderVerticalSpacing, important))
2058 case CSSPropertyWebkitBorderHorizontalSpacing:
2059 case CSSPropertyWebkitBorderVerticalSpacing:
2060 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2062 case CSSPropertyOutlineColor: // <color> | invert | inherit
2063 // Outline color has "invert" as additional keyword.
2064 // Also, we want to allow the special focus color even in strict parsing mode.
2065 if (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor) {
2066 validPrimitive = true;
2070 case CSSPropertyBackgroundColor: // <color> | inherit
2071 case CSSPropertyBorderTopColor: // <color> | inherit
2072 case CSSPropertyBorderRightColor:
2073 case CSSPropertyBorderBottomColor:
2074 case CSSPropertyBorderLeftColor:
2075 case CSSPropertyWebkitBorderStartColor:
2076 case CSSPropertyWebkitBorderEndColor:
2077 case CSSPropertyWebkitBorderBeforeColor:
2078 case CSSPropertyWebkitBorderAfterColor:
2079 case CSSPropertyColor: // <color> | inherit
2080 case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors
2081 case CSSPropertyTextUnderlineColor:
2082 case CSSPropertyTextOverlineColor:
2083 case CSSPropertyColumnRuleColor:
2084 case CSSPropertyWebkitTextDecorationColor:
2085 case CSSPropertyWebkitTextEmphasisColor:
2086 case CSSPropertyWebkitTextFillColor:
2087 case CSSPropertyWebkitTextStrokeColor:
2088 if (id == CSSValueWebkitText)
2089 validPrimitive = true; // Always allow this, even when strict parsing is on,
2090 // since we use this in our UA sheets.
2091 else if (id == CSSValueCurrentcolor)
2092 validPrimitive = true;
2093 else if (isValidSystemColorValue(id) || id == CSSValueMenu
2094 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2095 validPrimitive = true;
2097 parsedValue = parseColor();
2099 m_valueList->next();
2103 case CSSPropertyCursor: {
2104 // Grammar defined by CSS3 UI and modified by CSS4 images:
2105 // [ [<image> [<x> <y>]?,]*
2106 // [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |
2107 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize |
2108 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help |
2109 // vertical-text | cell | context-menu | alias | copy | no-drop | not-allowed |
2110 // zoom-in | zoom-out | all-scroll | -webkit-grab | -webkit-grabbing | -webkit-zoom-in |
2111 // -webkit-zoom-out ] ] | inherit
2112 RefPtr<CSSValueList> list;
2113 CSSParserValue* value = &valueWithCalculation.value();
2115 RefPtr<CSSValue> image;
2116 if (value->unit == CSSPrimitiveValue::CSS_URI) {
2117 String uri = value->string;
2119 image = CSSImageValue::create(completeURL(uri));
2120 #if ENABLE(CSS_IMAGE_SET) && ENABLE(MOUSE_CURSOR_SCALE)
2121 } else if (isImageSetFunctionValue(*value)) {
2122 image = parseImageSet();
2130 value = m_valueList->next();
2131 while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
2132 coords.append(int(value->fValue));
2133 value = m_valueList->next();
2135 bool hasHotSpot = false;
2136 IntPoint hotSpot(-1, -1);
2137 int nrcoords = coords.size();
2138 if (nrcoords > 0 && nrcoords != 2)
2140 if (nrcoords == 2) {
2142 hotSpot = IntPoint(coords[0], coords[1]);
2146 list = CSSValueList::createCommaSeparated();
2149 list->append(CSSCursorImageValue::create(image.releaseNonNull(), hasHotSpot, hotSpot));
2151 if ((inStrictMode() && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ',')))
2153 value = m_valueList->next(); // comma
2157 // no value after url list (MSIE 5 compatibility)
2158 if (list->length() != 1)
2160 } else if (inQuirksMode() && value->id == CSSValueHand) // MSIE 5 compatibility :/
2161 list->append(cssValuePool.createIdentifierValue(CSSValuePointer));
2162 else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitZoomOut) || value->id == CSSValueCopy || value->id == CSSValueNone)
2163 list->append(cssValuePool.createIdentifierValue(value->id));
2164 m_valueList->next();
2165 parsedValue = WTFMove(list);
2169 if (inQuirksMode() && value->id == CSSValueHand) {
2170 // MSIE 5 compatibility :/
2171 id = CSSValuePointer;
2172 validPrimitive = true;
2173 } else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitZoomOut) || value->id == CSSValueCopy || value->id == CSSValueNone)
2174 validPrimitive = true;
2176 ASSERT_NOT_REACHED();
2182 #if ENABLE(CURSOR_VISIBILITY)
2183 case CSSPropertyWebkitCursorVisibility:
2184 if (id == CSSValueAuto || id == CSSValueAutoHide)
2185 validPrimitive = true;
2189 case CSSPropertyBackgroundAttachment:
2190 case CSSPropertyBackgroundBlendMode:
2191 case CSSPropertyBackgroundClip:
2192 case CSSPropertyWebkitBackgroundClip:
2193 case CSSPropertyWebkitBackgroundComposite:
2194 case CSSPropertyBackgroundImage:
2195 case CSSPropertyBackgroundOrigin:
2196 case CSSPropertyWebkitBackgroundOrigin:
2197 case CSSPropertyBackgroundPosition:
2198 case CSSPropertyBackgroundPositionX:
2199 case CSSPropertyBackgroundPositionY:
2200 case CSSPropertyBackgroundSize:
2201 case CSSPropertyWebkitBackgroundSize:
2202 case CSSPropertyBackgroundRepeat:
2203 case CSSPropertyBackgroundRepeatX:
2204 case CSSPropertyBackgroundRepeatY:
2205 case CSSPropertyWebkitMaskClip:
2206 case CSSPropertyWebkitMaskComposite:
2207 case CSSPropertyWebkitMaskImage:
2208 case CSSPropertyWebkitMaskOrigin:
2209 case CSSPropertyWebkitMaskPosition:
2210 case CSSPropertyWebkitMaskPositionX:
2211 case CSSPropertyWebkitMaskPositionY:
2212 case CSSPropertyWebkitMaskSize:
2213 case CSSPropertyWebkitMaskSourceType:
2214 case CSSPropertyWebkitMaskRepeat:
2215 case CSSPropertyWebkitMaskRepeatX:
2216 case CSSPropertyWebkitMaskRepeatY:
2218 RefPtr<CSSValue> val1;
2219 RefPtr<CSSValue> val2;
2220 CSSPropertyID propId1, propId2;
2221 bool result = false;
2222 if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
2223 std::unique_ptr<ShorthandScope> shorthandScope;
2224 if (propId == CSSPropertyBackgroundPosition ||
2225 propId == CSSPropertyBackgroundRepeat ||
2226 propId == CSSPropertyWebkitMaskPosition ||
2227 propId == CSSPropertyWebkitMaskRepeat) {
2228 shorthandScope = std::make_unique<ShorthandScope>(this, propId);
2230 addProperty(propId1, val1.releaseNonNull(), important);
2232 addProperty(propId2, val2.releaseNonNull(), important);
2235 m_implicitShorthand = false;
2238 case CSSPropertyListStyleImage: // <uri> | none | inherit
2239 case CSSPropertyBorderImageSource:
2240 case CSSPropertyWebkitMaskBoxImageSource:
2241 if (id == CSSValueNone) {
2242 parsedValue = cssValuePool.createIdentifierValue(CSSValueNone);
2243 m_valueList->next();
2244 } else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_URI) {
2245 parsedValue = CSSImageValue::create(completeURL(valueWithCalculation.value().string));
2246 m_valueList->next();
2247 } else if (isGeneratedImageValue(valueWithCalculation)) {
2248 if (parseGeneratedImage(*m_valueList, parsedValue))
2249 m_valueList->next();
2253 #if ENABLE(CSS_IMAGE_SET)
2254 else if (isImageSetFunctionValue(valueWithCalculation.value())) {
2255 parsedValue = parseImageSet();
2258 m_valueList->next();
2263 case CSSPropertyWebkitTextStrokeWidth:
2264 case CSSPropertyOutlineWidth: // <border-width> | inherit
2265 case CSSPropertyBorderTopWidth: //// <border-width> | inherit
2266 case CSSPropertyBorderRightWidth: // Which is defined as
2267 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
2268 case CSSPropertyBorderLeftWidth:
2269 case CSSPropertyWebkitBorderStartWidth:
2270 case CSSPropertyWebkitBorderEndWidth:
2271 case CSSPropertyWebkitBorderBeforeWidth:
2272 case CSSPropertyWebkitBorderAfterWidth:
2273 case CSSPropertyColumnRuleWidth:
2274 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
2275 validPrimitive = true;
2277 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2280 case CSSPropertyLetterSpacing: // normal | <length> | inherit
2281 if (id == CSSValueNormal)
2282 validPrimitive = true;
2284 validPrimitive = validateUnit(valueWithCalculation, FLength);
2287 case CSSPropertyWordSpacing: // normal | <length> | <percentage> | inherit
2288 if (id == CSSValueNormal)
2289 validPrimitive = true;
2291 validPrimitive = validateUnit(valueWithCalculation, FLength | FPercent);
2294 case CSSPropertyTextIndent:
2295 parsedValue = parseTextIndent();
2298 case CSSPropertyPaddingTop: //// <padding-width> | inherit
2299 case CSSPropertyPaddingRight: // Which is defined as
2300 case CSSPropertyPaddingBottom: // <length> | <percentage>
2301 case CSSPropertyPaddingLeft: ////
2302 case CSSPropertyWebkitPaddingStart:
2303 case CSSPropertyWebkitPaddingEnd:
2304 case CSSPropertyWebkitPaddingBefore:
2305 case CSSPropertyWebkitPaddingAfter:
2306 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg));
2309 case CSSPropertyMaxWidth:
2310 case CSSPropertyWebkitMaxLogicalWidth:
2311 case CSSPropertyMaxHeight:
2312 case CSSPropertyWebkitMaxLogicalHeight:
2313 validPrimitive = (id == CSSValueNone || isValidSize(valueWithCalculation));
2316 case CSSPropertyMinWidth:
2317 case CSSPropertyWebkitMinLogicalWidth:
2318 case CSSPropertyMinHeight:
2319 case CSSPropertyWebkitMinLogicalHeight:
2320 validPrimitive = id == CSSValueAuto || isValidSize(valueWithCalculation);
2323 case CSSPropertyWidth:
2324 case CSSPropertyWebkitLogicalWidth:
2325 case CSSPropertyHeight:
2326 case CSSPropertyWebkitLogicalHeight:
2327 validPrimitive = (id == CSSValueAuto || isValidSize(valueWithCalculation));
2330 case CSSPropertyFontSize:
2331 return parseFontSize(important);
2333 case CSSPropertyVerticalAlign:
2334 // baseline | sub | super | top | text-top | middle | bottom | text-bottom |
2335 // <percentage> | <length> | inherit
2337 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
2338 validPrimitive = true;
2340 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent));
2343 case CSSPropertyBottom: // <length> | <percentage> | auto | inherit
2344 case CSSPropertyLeft: // <length> | <percentage> | auto | inherit
2345 case CSSPropertyRight: // <length> | <percentage> | auto | inherit
2346 case CSSPropertyTop: // <length> | <percentage> | auto | inherit
2347 case CSSPropertyMarginTop: //// <margin-width> | inherit
2348 case CSSPropertyMarginRight: // Which is defined as
2349 case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit
2350 case CSSPropertyMarginLeft: ////
2351 case CSSPropertyWebkitMarginStart:
2352 case CSSPropertyWebkitMarginEnd:
2353 case CSSPropertyWebkitMarginBefore:
2354 case CSSPropertyWebkitMarginAfter:
2355 if (id == CSSValueAuto)
2356 validPrimitive = true;
2358 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent));
2361 case CSSPropertyZIndex: // auto | <integer> | inherit
2362 if (id == CSSValueAuto)
2363 validPrimitive = true;
2365 validPrimitive = (!id && validateUnit(valueWithCalculation, FInteger, CSSQuirksMode));
2368 case CSSPropertyOrphans: // <integer> | inherit | auto (We've added support for auto for backwards compatibility)
2369 case CSSPropertyWidows: // <integer> | inherit | auto (Ditto)
2370 if (id == CSSValueAuto)
2371 validPrimitive = true;
2373 validPrimitive = (!id && validateUnit(valueWithCalculation, FPositiveInteger, CSSQuirksMode));
2376 case CSSPropertyLineHeight:
2377 return parseLineHeight(important);
2378 case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit
2379 if (id != CSSValueNone)
2380 return parseCounter(propId, 1, important);
2381 validPrimitive = true;
2383 case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit
2384 if (id != CSSValueNone)
2385 return parseCounter(propId, 0, important);
2386 validPrimitive = true;
2388 case CSSPropertyFontFamily:
2389 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit
2391 parsedValue = parseFontFamily();
2395 case CSSPropertyWebkitTextDecoration:
2396 // [ <text-decoration-line> || <text-decoration-style> || <text-decoration-color> ] | inherit
2397 return parseShorthand(CSSPropertyWebkitTextDecoration, webkitTextDecorationShorthand(), important);
2399 case CSSPropertyTextDecoration:
2400 case CSSPropertyWebkitTextDecorationsInEffect:
2401 case CSSPropertyWebkitTextDecorationLine:
2402 // none | [ underline || overline || line-through || blink ] | inherit
2403 return parseTextDecoration(propId, important);
2405 case CSSPropertyWebkitTextDecorationStyle:
2406 // solid | double | dotted | dashed | wavy
2407 if (id == CSSValueSolid || id == CSSValueDouble || id == CSSValueDotted || id == CSSValueDashed || id == CSSValueWavy)
2408 validPrimitive = true;
2411 case CSSPropertyWebkitTextDecorationSkip:
2412 // none | [ objects || spaces || ink || edges || box-decoration ]
2413 return parseTextDecorationSkip(important);
2415 case CSSPropertyWebkitTextUnderlinePosition:
2416 // auto | alphabetic | under
2417 return parseTextUnderlinePosition(important);
2419 case CSSPropertyZoom:
2420 // normal | reset | document | <number> | <percentage> | inherit
2421 if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument)
2422 validPrimitive = true;
2424 validPrimitive = (!id && validateUnit(valueWithCalculation, FNumber | FPercent | FNonNeg, CSSStrictMode));
2427 case CSSPropertyWebkitTextZoom:
2429 if (id == CSSValueNormal || id == CSSValueReset)
2430 validPrimitive = true;
2433 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.
2434 return parseFontFaceSrc();
2436 case CSSPropertyUnicodeRange:
2437 return parseFontFaceUnicodeRange();
2439 /* CSS3 properties */
2441 case CSSPropertyBorderImage: {
2442 RefPtr<CSSValue> result;
2443 return parseBorderImage(propId, result, important);
2445 case CSSPropertyWebkitBorderImage:
2446 case CSSPropertyWebkitMaskBoxImage: {
2447 RefPtr<CSSValue> result;
2448 if (parseBorderImage(propId, result)) {
2449 addProperty(propId, WTFMove(result), important);
2454 case CSSPropertyBorderImageOutset:
2455 case CSSPropertyWebkitMaskBoxImageOutset: {
2456 RefPtr<CSSPrimitiveValue> result;
2457 if (parseBorderImageOutset(result)) {
2458 addProperty(propId, WTFMove(result), important);
2463 case CSSPropertyBorderImageRepeat:
2464 case CSSPropertyWebkitMaskBoxImageRepeat: {
2465 RefPtr<CSSValue> result;
2466 if (parseBorderImageRepeat(result)) {
2467 addProperty(propId, WTFMove(result), important);
2472 case CSSPropertyBorderImageSlice:
2473 case CSSPropertyWebkitMaskBoxImageSlice: {
2474 RefPtr<CSSBorderImageSliceValue> result;
2475 if (parseBorderImageSlice(propId, result)) {
2476 addProperty(propId, WTFMove(result), important);
2481 case CSSPropertyBorderImageWidth:
2482 case CSSPropertyWebkitMaskBoxImageWidth: {
2483 RefPtr<CSSPrimitiveValue> result;
2484 if (parseBorderImageWidth(result)) {
2485 addProperty(propId, WTFMove(result), important);
2490 case CSSPropertyBorderTopRightRadius:
2491 case CSSPropertyBorderTopLeftRadius:
2492 case CSSPropertyBorderBottomLeftRadius:
2493 case CSSPropertyBorderBottomRightRadius: {
2494 if (num != 1 && num != 2)
2496 validPrimitive = validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg);
2497 if (!validPrimitive)
2499 auto parsedValue1 = createPrimitiveNumericValue(valueWithCalculation);
2500 RefPtr<CSSPrimitiveValue> parsedValue2;
2502 ValueWithCalculation nextValueWithCalculation(*m_valueList->next());
2503 validPrimitive = validateUnit(nextValueWithCalculation, FLength | FPercent | FNonNeg);
2504 if (!validPrimitive)
2506 parsedValue2 = createPrimitiveNumericValue(nextValueWithCalculation);
2508 parsedValue2 = parsedValue1.ptr();
2510 addProperty(propId, createPrimitiveValuePair(WTFMove(parsedValue1), parsedValue2.releaseNonNull()), important);
2513 case CSSPropertyTabSize:
2514 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg);
2516 case CSSPropertyWebkitAspectRatio:
2517 return parseAspectRatio(important);
2518 case CSSPropertyBorderRadius:
2519 case CSSPropertyWebkitBorderRadius:
2520 return parseBorderRadius(propId, important);
2521 case CSSPropertyOutlineOffset:
2522 validPrimitive = validateUnit(valueWithCalculation, FLength);
2524 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
2525 case CSSPropertyBoxShadow:
2526 case CSSPropertyWebkitBoxShadow:
2527 if (id == CSSValueNone)
2528 validPrimitive = true;
2530 RefPtr<CSSValueList> shadowValueList = parseShadow(*m_valueList, propId);
2531 if (shadowValueList) {
2532 addProperty(propId, shadowValueList.releaseNonNull(), important);
2533 m_valueList->next();
2539 case CSSPropertyWebkitInitialLetter: {
2540 if (id == CSSValueNormal)
2541 validPrimitive = true;
2543 if (num != 1 && num != 2)
2545 validPrimitive = validateUnit(valueWithCalculation, FPositiveInteger);
2546 if (!validPrimitive)
2548 auto height = createPrimitiveNumericValue(valueWithCalculation);
2549 RefPtr<CSSPrimitiveValue> position;
2551 ValueWithCalculation nextValueWithCalculation(*m_valueList->next());
2552 validPrimitive = validateUnit(nextValueWithCalculation, FPositiveInteger);
2553 if (!validPrimitive)
2555 position = createPrimitiveNumericValue(nextValueWithCalculation);
2557 position = height.ptr();
2558 addProperty(propId, createPrimitiveValuePair(position.releaseNonNull(), WTFMove(height)), important);
2563 case CSSPropertyWebkitBoxReflect:
2564 if (id == CSSValueNone)
2565 validPrimitive = true;
2567 return parseReflect(propId, important);
2569 case CSSPropertyOpacity:
2570 validPrimitive = validateUnit(valueWithCalculation, FNumber);
2572 case CSSPropertyWebkitBoxFlex:
2573 validPrimitive = validateUnit(valueWithCalculation, FNumber);
2575 case CSSPropertyWebkitBoxFlexGroup:
2576 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode);
2578 case CSSPropertyWebkitBoxOrdinalGroup:
2579 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode) && valueWithCalculation.value().fValue;
2581 case CSSPropertyFilter:
2582 #if ENABLE(FILTERS_LEVEL_2)
2583 case CSSPropertyWebkitBackdropFilter:
2585 if (id == CSSValueNone)
2586 validPrimitive = true;
2588 RefPtr<CSSValueList> currValue;
2589 if (!parseFilter(*m_valueList, currValue))
2591 addProperty(propId, WTFMove(currValue), important);
2595 #if ENABLE(CSS_COMPOSITING)
2596 case CSSPropertyMixBlendMode:
2597 validPrimitive = true;
2599 case CSSPropertyIsolation:
2600 validPrimitive = true;
2603 case CSSPropertyFlex: {
2604 ShorthandScope scope(this, propId);
2605 if (id == CSSValueNone) {
2606 addProperty(CSSPropertyFlexGrow, cssValuePool.createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2607 addProperty(CSSPropertyFlexShrink, cssValuePool.createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2608 addProperty(CSSPropertyFlexBasis, cssValuePool.createIdentifierValue(CSSValueAuto), important);
2611 return parseFlex(*m_valueList, important);
2613 case CSSPropertyFlexBasis:
2614 // FIXME: Support intrinsic dimensions too.
2615 if (id == CSSValueAuto)
2616 validPrimitive = true;
2618 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg));
2620 case CSSPropertyFlexGrow:
2621 case CSSPropertyFlexShrink:
2622 validPrimitive = validateUnit(valueWithCalculation, FNumber | FNonNeg);
2624 case CSSPropertyOrder:
2625 if (validateUnit(valueWithCalculation, FInteger, CSSStrictMode)) {
2626 // 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.
2627 double result = std::max<double>(std::numeric_limits<int>::min() + 2, parsedDouble(valueWithCalculation));
2628 parsedValue = cssValuePool.createValue(result, CSSPrimitiveValue::CSS_NUMBER);
2629 m_valueList->next();
2632 case CSSPropertyWebkitMarquee:
2633 return parseShorthand(propId, webkitMarqueeShorthand(), important);
2634 case CSSPropertyWebkitMarqueeIncrement:
2635 if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
2636 validPrimitive = true;
2638 validPrimitive = validateUnit(valueWithCalculation, FLength | FPercent);
2640 case CSSPropertyWebkitMarqueeRepetition:
2641 if (id == CSSValueInfinite)
2642 validPrimitive = true;
2644 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg);
2646 case CSSPropertyWebkitMarqueeSpeed:
2647 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
2648 validPrimitive = true;
2650 validPrimitive = validateUnit(valueWithCalculation, FTime | FInteger | FNonNeg);
2652 #if ENABLE(CSS_REGIONS)
2653 case CSSPropertyWebkitFlowInto:
2654 return parseFlowThread(propId, important);
2655 case CSSPropertyWebkitFlowFrom:
2656 return parseRegionThread(propId, important);
2658 case CSSPropertyTransform:
2659 if (id == CSSValueNone)
2660 validPrimitive = true;
2662 if (RefPtr<CSSValue> transformValue = parseTransform()) {
2663 addProperty(propId, transformValue.releaseNonNull(), important);
2669 case CSSPropertyTransformOrigin:
2670 case CSSPropertyTransformOriginX:
2671 case CSSPropertyTransformOriginY:
2672 case CSSPropertyTransformOriginZ: {
2673 RefPtr<CSSPrimitiveValue> val1;
2674 RefPtr<CSSPrimitiveValue> val2;
2675 RefPtr<CSSValue> val3;
2676 CSSPropertyID propId1, propId2, propId3;
2677 if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
2678 addProperty(propId1, WTFMove(val1), important);
2680 addProperty(propId2, WTFMove(val2), important);
2682 addProperty(propId3, WTFMove(val3), important);
2687 case CSSPropertyPerspective:
2688 if (id == CSSValueNone)
2689 validPrimitive = true;
2691 // Accepting valueless numbers is a quirk of the -webkit prefixed version of the property.
2692 if (validateUnit(valueWithCalculation, FNumber | FLength | FNonNeg)) {
2693 addProperty(propId, createPrimitiveNumericValue(valueWithCalculation), important);
2698 case CSSPropertyPerspectiveOrigin:
2699 case CSSPropertyPerspectiveOriginX:
2700 case CSSPropertyPerspectiveOriginY: {
2701 RefPtr<CSSPrimitiveValue> val1;
2702 RefPtr<CSSPrimitiveValue> val2;
2703 CSSPropertyID propId1, propId2;
2704 if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
2705 addProperty(propId1, WTFMove(val1), important);
2707 addProperty(propId2, WTFMove(val2), important);
2712 case CSSPropertyAnimationDelay:
2713 case CSSPropertyAnimationDirection:
2714 case CSSPropertyAnimationDuration:
2715 case CSSPropertyAnimationFillMode:
2716 case CSSPropertyAnimationName:
2717 case CSSPropertyAnimationPlayState:
2718 case CSSPropertyAnimationIterationCount:
2719 case CSSPropertyAnimationTimingFunction:
2720 case CSSPropertyWebkitAnimationDelay:
2721 case CSSPropertyWebkitAnimationDirection:
2722 case CSSPropertyWebkitAnimationDuration:
2723 case CSSPropertyWebkitAnimationFillMode:
2724 case CSSPropertyWebkitAnimationName:
2725 case CSSPropertyWebkitAnimationPlayState:
2726 case CSSPropertyWebkitAnimationIterationCount:
2727 case CSSPropertyWebkitAnimationTimingFunction:
2728 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
2729 case CSSPropertyWebkitAnimationTrigger:
2731 case CSSPropertyTransitionDelay:
2732 case CSSPropertyTransitionDuration:
2733 case CSSPropertyTransitionTimingFunction:
2734 case CSSPropertyTransitionProperty:
2735 case CSSPropertyWebkitTransitionDelay:
2736 case CSSPropertyWebkitTransitionDuration:
2737 case CSSPropertyWebkitTransitionTimingFunction:
2738 case CSSPropertyWebkitTransitionProperty: {
2739 RefPtr<CSSValue> val;
2740 AnimationParseContext context;
2741 if (parseAnimationProperty(propId, val, context)) {
2742 addPropertyWithPrefixingVariant(propId, WTFMove(val), important);
2747 case CSSPropertyJustifyContent:
2748 parsedValue = parseContentDistributionOverflowPosition();
2750 case CSSPropertyJustifySelf:
2751 return parseItemPositionOverflowPosition(propId, important);
2752 case CSSPropertyJustifyItems:
2753 if (parseLegacyPosition(propId, important))
2755 m_valueList->setCurrentIndex(0);
2756 return parseItemPositionOverflowPosition(propId, important);
2757 #if ENABLE(CSS_GRID_LAYOUT)
2758 case CSSPropertyGridAutoColumns:
2759 case CSSPropertyGridAutoRows:
2760 if (!isCSSGridLayoutEnabled())
2762 parsedValue = parseGridTrackSize(*m_valueList);
2765 case CSSPropertyGridTemplateColumns:
2766 case CSSPropertyGridTemplateRows:
2767 if (!isCSSGridLayoutEnabled())
2769 parsedValue = parseGridTrackList();
2772 case CSSPropertyGridColumnStart:
2773 case CSSPropertyGridColumnEnd:
2774 case CSSPropertyGridRowStart:
2775 case CSSPropertyGridRowEnd:
2776 if (!isCSSGridLayoutEnabled())
2778 parsedValue = parseGridPosition();
2781 case CSSPropertyGridColumnGap:
2782 case CSSPropertyGridRowGap:
2783 if (!isCSSGridLayoutEnabled())
2785 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2788 case CSSPropertyGridGap:
2789 if (!isCSSGridLayoutEnabled())
2791 return parseGridGapShorthand(important);
2793 case CSSPropertyGridColumn:
2794 case CSSPropertyGridRow:
2795 if (!isCSSGridLayoutEnabled())
2797 return parseGridItemPositionShorthand(propId, important);
2799 case CSSPropertyGridTemplate:
2800 if (!isCSSGridLayoutEnabled())
2802 return parseGridTemplateShorthand(important);
2804 case CSSPropertyGrid:
2805 if (!isCSSGridLayoutEnabled())
2807 return parseGridShorthand(important);
2809 case CSSPropertyGridArea:
2810 if (!isCSSGridLayoutEnabled())
2812 return parseGridAreaShorthand(important);
2814 case CSSPropertyGridTemplateAreas:
2815 if (!isCSSGridLayoutEnabled())
2817 parsedValue = parseGridTemplateAreas();
2819 case CSSPropertyGridAutoFlow:
2820 if (!isCSSGridLayoutEnabled())
2822 parsedValue = parseGridAutoFlow(*m_valueList);
2824 #endif /* ENABLE(CSS_GRID_LAYOUT) */
2825 case CSSPropertyWebkitMarginCollapse: {
2827 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2828 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important))
2830 CSSValue* value = m_parsedProperties.last().value();
2831 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
2834 else if (num == 2) {
2835 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2836 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important) || !parseValue(webkitMarginCollapseShorthand().properties()[1], important))
2842 case CSSPropertyTextLineThroughWidth:
2843 case CSSPropertyTextOverlineWidth:
2844 case CSSPropertyTextUnderlineWidth:
2845 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
2846 id == CSSValueMedium || id == CSSValueThick)
2847 validPrimitive = true;
2849 validPrimitive = !id && validateUnit(valueWithCalculation, FNumber | FLength | FPercent);
2851 case CSSPropertyColumnCount:
2852 parsedValue = parseColumnCount();
2854 case CSSPropertyColumnGap: // normal | <length>
2855 if (id == CSSValueNormal)
2856 validPrimitive = true;
2858 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2860 case CSSPropertyWebkitColumnAxis:
2861 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto)
2862 validPrimitive = true;
2864 case CSSPropertyColumnProgression:
2865 if (id == CSSValueNormal || id == CSSValueReverse)
2866 validPrimitive = true;
2868 case CSSPropertyColumnSpan: // none | all | 1 (will be dropped in the unprefixed property)
2869 if (id == CSSValueAll || id == CSSValueNone)
2870 validPrimitive = true;
2871 else if (validateUnit(valueWithCalculation, FNumber | FNonNeg) && parsedDouble(valueWithCalculation) == 1) {
2872 addProperty(CSSPropertyColumnSpan, cssValuePool.createValue(1, CSSPrimitiveValue::CSS_NUMBER), important);
2876 case CSSPropertyColumnWidth: // auto | <length>
2877 parsedValue = parseColumnWidth();
2879 case CSSPropertyObjectPosition: {
2880 RefPtr<CSSPrimitiveValue> val1;
2881 RefPtr<CSSPrimitiveValue> val2;
2882 parseFillPosition(*m_valueList, val1, val2);
2884 addProperty(CSSPropertyObjectPosition, createPrimitiveValuePair(val1.releaseNonNull(), WTFMove(val2)), important);
2889 // End of CSS3 properties
2891 case CSSPropertyWillChange: // auto | [scroll-position | contents | <custom-ident>]#
2892 if (id == CSSValueAuto)
2893 validPrimitive = true;
2895 return parseWillChange(important);
2898 // Apple specific properties. These will never be standardized and are purely to
2899 // support custom WebKit-based Apple applications.
2900 case CSSPropertyWebkitLineClamp:
2901 // When specifying number of lines, don't allow 0 as a valid value
2902 // When specifying either type of unit, require non-negative integers
2903 validPrimitive = (!id && (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_PERCENTAGE || valueWithCalculation.value().fValue) && validateUnit(valueWithCalculation, FInteger | FPercent | FNonNeg, CSSQuirksMode));
2905 #if ENABLE(IOS_TEXT_AUTOSIZING)
2906 case CSSPropertyWebkitTextSizeAdjust:
2907 if (!isTextAutosizingEnabled())
2910 if (id == CSSValueAuto || id == CSSValueNone)
2911 validPrimitive = true;
2913 // FIXME: Handle multilength case where we allow relative units.
2914 validPrimitive = (!id && validateUnit(valueWithCalculation, FPercent | FNonNeg, CSSStrictMode));
2919 case CSSPropertyWebkitFontSizeDelta: // <length>
2920 validPrimitive = validateUnit(valueWithCalculation, FLength);
2923 case CSSPropertyWebkitHyphenateCharacter:
2924 if (id == CSSValueAuto || valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
2925 validPrimitive = true;
2928 case CSSPropertyWebkitHyphenateLimitBefore:
2929 case CSSPropertyWebkitHyphenateLimitAfter:
2930 if (id == CSSValueAuto || validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode))
2931 validPrimitive = true;
2934 case CSSPropertyWebkitHyphenateLimitLines:
2935 if (id == CSSValueNoLimit || validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode))
2936 validPrimitive = true;
2939 case CSSPropertyWebkitLineGrid:
2940 if (id == CSSValueNone)
2941 validPrimitive = true;
2942 else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_IDENT) {
2943 String lineGridValue = String(valueWithCalculation.value().string);
2944 if (!lineGridValue.isEmpty()) {
2945 addProperty(propId, cssValuePool.createValue(lineGridValue, CSSPrimitiveValue::CSS_STRING), important);
2950 case CSSPropertyWebkitLocale:
2951 if (id == CSSValueAuto || valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
2952 validPrimitive = true;
2955 #if ENABLE(DASHBOARD_SUPPORT)
2956 case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region>
2957 if (valueWithCalculation.value().unit == CSSParserValue::Function || id == CSSValueNone)
2958 return parseDashboardRegions(propId, important);
2963 case CSSPropertyWebkitTouchCallout:
2964 if (id == CSSValueDefault || id == CSSValueNone)
2965 validPrimitive = true;
2968 #if ENABLE(TOUCH_EVENTS)
2969 case CSSPropertyWebkitTapHighlightColor:
2970 if (isValidSystemColorValue(id) || id == CSSValueMenu
2971 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2972 validPrimitive = true;
2974 parsedValue = parseColor();
2976 m_valueList->next();
2980 // End Apple-specific properties
2982 /* shorthand properties */
2983 case CSSPropertyBackground: {
2984 // Position must come before color in this array because a plain old "0" is a legal color
2985 // in quirks mode but it's usually the X coordinate of a position.
2986 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
2987 CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin,
2988 CSSPropertyBackgroundClip, CSSPropertyBackgroundColor, CSSPropertyBackgroundSize };
2989 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2991 case CSSPropertyWebkitMask: {
2992 const CSSPropertyID properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskSourceType, CSSPropertyWebkitMaskRepeat,
2993 CSSPropertyWebkitMaskPosition, CSSPropertyWebkitMaskOrigin, CSSPropertyWebkitMaskClip, CSSPropertyWebkitMaskSize };
2994 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2996 case CSSPropertyBorder:
2997 // [ 'border-width' || 'border-style' || <color> ] | inherit
2999 if (parseShorthand(propId, borderAbridgedShorthand(), important)) {
3000 // The CSS3 Borders and Backgrounds specification says that border also resets border-image. It's as
3001 // though a value of none was specified for the image.
3002 addExpandedPropertyForValue(CSSPropertyBorderImage, cssValuePool.createImplicitInitialValue(), important);
3007 case CSSPropertyBorderTop:
3008 // [ 'border-top-width' || 'border-style' || <color> ] | inherit
3009 return parseShorthand(propId, borderTopShorthand(), important);
3010 case CSSPropertyBorderRight:
3011 // [ 'border-right-width' || 'border-style' || <color> ] | inherit
3012 return parseShorthand(propId, borderRightShorthand(), important);
3013 case CSSPropertyBorderBottom:
3014 // [ 'border-bottom-width' || 'border-style' || <color> ] | inherit
3015 return parseShorthand(propId, borderBottomShorthand(), important);
3016 case CSSPropertyBorderLeft:
3017 // [ 'border-left-width' || 'border-style' || <color> ] | inherit
3018 return parseShorthand(propId, borderLeftShorthand(), important);
3019 case CSSPropertyWebkitBorderStart:
3020 return parseShorthand(propId, webkitBorderStartShorthand(), important);
3021 case CSSPropertyWebkitBorderEnd:
3022 return parseShorthand(propId, webkitBorderEndShorthand(), important);
3023 case CSSPropertyWebkitBorderBefore:
3024 return parseShorthand(propId, webkitBorderBeforeShorthand(), important);
3025 case CSSPropertyWebkitBorderAfter:
3026 return parseShorthand(propId, webkitBorderAfterShorthand(), important);
3027 case CSSPropertyOutline:
3028 // [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit
3029 return parseShorthand(propId, outlineShorthand(), important);
3030 case CSSPropertyBorderColor:
3031 // <color>{1,4} | inherit
3032 return parse4Values(propId, borderColorShorthand().properties(), important);
3033 case CSSPropertyBorderWidth:
3034 // <border-width>{1,4} | inherit
3035 return parse4Values(propId, borderWidthShorthand().properties(), important);
3036 case CSSPropertyBorderStyle:
3037 // <border-style>{1,4} | inherit
3038 return parse4Values(propId, borderStyleShorthand().properties(), important);
3039 case CSSPropertyMargin:
3040 // <margin-width>{1,4} | inherit
3041 return parse4Values(propId, marginShorthand().properties(), important);
3042 case CSSPropertyPadding:
3043 // <padding-width>{1,4} | inherit
3044 return parse4Values(propId, paddingShorthand().properties(), important);
3045 case CSSPropertyFlexFlow:
3046 return parseShorthand(propId, flexFlowShorthand(), important);
3047 case CSSPropertyFont:
3048 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
3049 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
3050 if (num == 1 && id >= CSSValueCaption && id <= CSSValueStatusBar) {
3051 parseSystemFont(important);
3054 return parseFont(important);
3055 case CSSPropertyListStyle:
3056 return parseShorthand(propId, listStyleShorthand(), important);
3057 case CSSPropertyColumns:
3058 return parseColumnsShorthand(important);
3059 case CSSPropertyColumnRule:
3060 return parseShorthand(propId, columnRuleShorthand(), important);
3061 case CSSPropertyWebkitTextStroke:
3062 return parseShorthand(propId, webkitTextStrokeShorthand(), important);
3063 case CSSPropertyAnimation:
3064 case CSSPropertyWebkitAnimation:
3065 return parseAnimationShorthand(propId, important);
3066 case CSSPropertyTransition:
3067 case CSSPropertyWebkitTransition:
3068 return parseTransitionShorthand(propId, important);
3069 case CSSPropertyInvalid:
3071 case CSSPropertyPage:
3072 return parsePage(propId, important);
3073 case CSSPropertyFontStretch:
3074 case CSSPropertyTextLineThrough:
3075 case CSSPropertyTextOverline:
3076 case CSSPropertyTextUnderline:
3078 // CSS Text Layout Module Level 3: Vertical writing support
3079 case CSSPropertyWebkitTextEmphasis:
3080 return parseShorthand(propId, webkitTextEmphasisShorthand(), important);
3082 case CSSPropertyWebkitTextEmphasisStyle:
3083 return parseTextEmphasisStyle(important);
3085 case CSSPropertyWebkitTextEmphasisPosition:
3086 return parseTextEmphasisPosition(important);
3088 case CSSPropertyWebkitTextOrientation:
3089 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSValueVerticalRight || id == CSSValueMixed || id == CSSValueUpright)
3090 validPrimitive = true;
3093 case CSSPropertyHangingPunctuation:
3094 return parseHangingPunctuation(important);
3095 case CSSPropertyWebkitLineBoxContain:
3096 if (id == CSSValueNone)
3097 validPrimitive = true;
3099 return parseLineBoxContain(important);
3101 case CSSPropertyFontFeatureSettings:
3102 if (id == CSSValueNormal)
3103 validPrimitive = true;
3105 return parseFontFeatureSettings(important);
3107 case CSSPropertyFontVariantLigatures:
3108 if (id == CSSValueNormal || id == CSSValueNone)
3109 validPrimitive = true;
3111 return parseFontVariantLigatures(important, true, false);
3113 case CSSPropertyFontVariantNumeric:
3114 if (id == CSSValueNormal)
3115 validPrimitive = true;
3117 return parseFontVariantNumeric(important, true, false);
3119 case CSSPropertyFontVariantEastAsian:
3120 if (id == CSSValueNormal)
3121 validPrimitive = true;
3123 return parseFontVariantEastAsian(important, true, false);
3125 case CSSPropertyFontVariant:
3126 if (id == CSSValueNormal) {
3127 ShorthandScope scope(this, CSSPropertyFontVariant);
3128 addProperty(CSSPropertyFontVariantLigatures, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3129 addProperty(CSSPropertyFontVariantPosition, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3130 addProperty(CSSPropertyFontVariantCaps, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3131 addProperty(CSSPropertyFontVariantNumeric, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3132 addProperty(CSSPropertyFontVariantAlternates, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3133 addProperty(CSSPropertyFontVariantEastAsian, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
3136 if (id == CSSValueNone) {
3137 ShorthandScope scope(this, CSSPropertyFontVariant);
3138 addProperty(CSSPropertyFontVariantLigatures, CSSValuePool::singleton().createIdentifierValue(CSSValueNone), important, true);
3141 return parseFontVariant(important);
3143 case CSSPropertyWebkitClipPath:
3144 parsedValue = parseClipPath();
3146 #if ENABLE(CSS_SHAPES)
3147 case CSSPropertyWebkitShapeOutside:
3148 parsedValue = parseShapeProperty(propId);
3150 case CSSPropertyWebkitShapeMargin:
3151 validPrimitive = !id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg);
3153 case CSSPropertyWebkitShapeImageThreshold:
3154 validPrimitive = !id && validateUnit(valueWithCalculation, FNumber);
3157 #if ENABLE(CSS_IMAGE_ORIENTATION)
3158 case CSSPropertyImageOrientation:
3159 validPrimitive = !id && validateUnit(valueWithCalculation, FAngle);
3162 #if ENABLE(CSS_IMAGE_RESOLUTION)
3163 case CSSPropertyImageResolution:
3164 parsedValue = parseImageResolution();
3167 case CSSPropertyAlignContent:
3168 parsedValue = parseContentDistributionOverflowPosition();
3170 case CSSPropertyAlignSelf:
3171 return parseItemPositionOverflowPosition(propId, important);
3173 case CSSPropertyAlignItems:
3174 return parseItemPositionOverflowPosition(propId, important);
3175 case CSSPropertyBorderBottomStyle:
3176 case CSSPropertyBorderCollapse:
3177 case CSSPropertyBorderLeftStyle:
3178 case CSSPropertyBorderRightStyle:
3179 case CSSPropertyBorderTopStyle:
3180 case CSSPropertyBoxSizing:
3181 case CSSPropertyBreakAfter:
3182 case CSSPropertyBreakBefore:
3183 case CSSPropertyBreakInside:
3184 case CSSPropertyCaptionSide:
3185 case CSSPropertyClear:
3186 case CSSPropertyDirection:
3187 case CSSPropertyDisplay:
3188 case CSSPropertyEmptyCells:
3189 case CSSPropertyFloat:
3190 case CSSPropertyFontStyle:
3191 case CSSPropertyImageRendering:
3192 case CSSPropertyListStylePosition:
3193 case CSSPropertyListStyleType:
3194 case CSSPropertyObjectFit:
3195 case CSSPropertyOutlineStyle:
3196 case CSSPropertyOverflowWrap:
3197 case CSSPropertyOverflowX:
3198 case CSSPropertyOverflowY:
3199 case CSSPropertyPageBreakAfter:
3200 case CSSPropertyPageBreakBefore:
3201 case CSSPropertyPageBreakInside:
3202 case CSSPropertyPointerEvents:
3203 case CSSPropertyPosition:
3204 case CSSPropertyResize:
3205 case CSSPropertySpeak:
3206 case CSSPropertyTableLayout:
3207 case CSSPropertyTextLineThroughMode:
3208 case CSSPropertyTextLineThroughStyle:
3209 case CSSPropertyTextOverflow:
3210 case CSSPropertyTextOverlineMode:
3211 case CSSPropertyTextOverlineStyle:
3212 case CSSPropertyTextRendering:
3213 case CSSPropertyTextTransform:
3214 case CSSPropertyTextUnderlineMode:
3215 case CSSPropertyTextUnderlineStyle:
3216 case CSSPropertyVisibility:
3217 case CSSPropertyWebkitAppearance:
3218 case CSSPropertyWebkitBackfaceVisibility:
3219 case CSSPropertyWebkitBorderAfterStyle:
3220 case CSSPropertyWebkitBorderBeforeStyle:
3221 case CSSPropertyWebkitBorderEndStyle:
3222 case CSSPropertyWebkitBorderFit:
3223 case CSSPropertyWebkitBorderStartStyle:
3224 case CSSPropertyWebkitBoxAlign:
3225 #if ENABLE(CSS_BOX_DECORATION_BREAK)
3226 case CSSPropertyWebkitBoxDecorationBreak:
3228 case CSSPropertyWebkitBoxDirection:
3229 case CSSPropertyWebkitBoxLines:
3230 case CSSPropertyWebkitBoxOrient:
3231 case CSSPropertyWebkitBoxPack:
3232 case CSSPropertyWebkitColumnBreakAfter:
3233 case CSSPropertyWebkitColumnBreakBefore:
3234 case CSSPropertyWebkitColumnBreakInside:
3235 case CSSPropertyColumnFill:
3236 case CSSPropertyColumnRuleStyle:
3237 case CSSPropertyFlexDirection:
3238 case CSSPropertyFlexWrap:
3239 case CSSPropertyWebkitFontKerning:
3240 case CSSPropertyWebkitFontSmoothing:
3241 case CSSPropertyWebkitHyphens:
3242 case CSSPropertyWebkitLineAlign:
3243 case CSSPropertyWebkitLineBreak:
3244 case CSSPropertyWebkitLineSnap:
3245 case CSSPropertyWebkitMarginAfterCollapse:
3246 case CSSPropertyWebkitMarginBeforeCollapse:
3247 case CSSPropertyWebkitMarginBottomCollapse:
3248 case CSSPropertyWebkitMarginTopCollapse:
3249 case CSSPropertyWebkitMarqueeDirection:
3250 case CSSPropertyWebkitMarqueeStyle:
3251 case CSSPropertyWebkitNbspMode:
3252 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
3253 case CSSPropertyWebkitOverflowScrolling:
3255 case CSSPropertyWebkitPrintColorAdjust:
3256 #if ENABLE(CSS_REGIONS)
3257 case CSSPropertyWebkitRegionBreakAfter:
3258 case CSSPropertyWebkitRegionBreakBefore:
3259 case CSSPropertyWebkitRegionBreakInside:
3260 case CSSPropertyWebkitRegionFragment:
3262 case CSSPropertyWebkitRtlOrdering:
3263 case CSSPropertyWebkitRubyPosition:
3264 #if ENABLE(CSS3_TEXT)
3265 case CSSPropertyWebkitTextAlignLast:
3267 case CSSPropertyWebkitTextCombine:
3268 #if ENABLE(CSS3_TEXT)
3269 case CSSPropertyWebkitTextJustify:
3271 case CSSPropertyWebkitTextSecurity:
3272 case CSSPropertyTransformStyle:
3273 case CSSPropertyWebkitTransformStyle:
3274 case CSSPropertyWebkitUserDrag:
3275 case CSSPropertyWebkitUserModify:
3276 case CSSPropertyWebkitUserSelect:
3277 case CSSPropertyWebkitWritingMode:
3278 case CSSPropertyWhiteSpace:
3279 case CSSPropertyWordBreak:
3280 case CSSPropertyWordWrap:
3281 #if ENABLE(TOUCH_EVENTS)
3282 case CSSPropertyTouchAction:
3284 #if ENABLE(CSS_SCROLL_SNAP)
3285 case CSSPropertyWebkitScrollSnapType:
3287 #if ENABLE(CSS_TRAILING_WORD)
3288 case CSSPropertyAppleTrailingWord:
3290 // These properties should be handled before in isValidKeywordPropertyAndValue().
3291 ASSERT_NOT_REACHED();
3293 #if ENABLE(CSS_DEVICE_ADAPTATION)
3294 // Properties bellow are validated inside parseViewportProperty, because we
3295 // check for parser state inViewportScope. We need to invalidate if someone
3296 // adds them outside a @viewport rule.
3297 case CSSPropertyMaxZoom:
3298 case CSSPropertyMinZoom:
3299 case CSSPropertyOrientation:
3300 case CSSPropertyUserZoom:
3301 validPrimitive = false;
3304 #if ENABLE(CSS_SCROLL_SNAP)
3305 case CSSPropertyWebkitScrollSnapPointsX:
3306 case CSSPropertyWebkitScrollSnapPointsY:
3307 if (id == CSSValueElements) {
3308 validPrimitive = true;
3311 return parseNonElementSnapPoints(propId, important);
3312 case CSSPropertyWebkitScrollSnapDestination: // <length>{2}
3313 return parseScrollSnapDestination(propId, important);
3314 case CSSPropertyWebkitScrollSnapCoordinate:
3315 return parseScrollSnapCoordinate(propId, important);
3319 return parseSVGValue(propId, important);
3322 if (validPrimitive) {
3323 parsedValue = parseValidPrimitive(id, valueWithCalculation);
3324 m_valueList->next();
3327 if (parsedValue && (!m_valueList->current() || inShorthand())) {
3328 addProperty(propId, parsedValue.releaseNonNull(), important);
3334 void CSSParser::addFillValue(RefPtr<CSSValue>& lval, Ref<CSSValue>&& rval)
3337 lval = WTFMove(rval);
3341 if (lval->isBaseValueList()) {
3342 downcast<CSSValueList>(*lval).append(WTFMove(rval));
3346 auto list = CSSValueList::createCommaSeparated();
3347 list.get().append(lval.releaseNonNull());
3348 list.get().append(WTFMove(rval));
3349 lval = WTFMove(list);
3352 static bool isContentDistributionKeyword(CSSValueID id)
3354 return id == CSSValueSpaceBetween || id == CSSValueSpaceAround
3355 || id == CSSValueSpaceEvenly || id == CSSValueStretch;
3358 static bool isContentPositionKeyword(CSSValueID id)
3360 return id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
3361 || id == CSSValueFlexStart || id == CSSValueFlexEnd
3362 || id == CSSValueLeft || id == CSSValueRight;
3365 static inline bool isBaselinePositionKeyword(CSSValueID id)
3367 return id == CSSValueBaseline || id == CSSValueLastBaseline;
3370 static bool isAlignmentOverflowKeyword(CSSValueID id)
3372 return id == CSSValueUnsafe || id == CSSValueSafe;
3375 static bool isItemPositionKeyword(CSSValueID id)
3377 return id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
3378 || id == CSSValueSelfStart || id == CSSValueSelfEnd || id == CSSValueFlexStart
3379 || id == CSSValueFlexEnd || id == CSSValueLeft || id == CSSValueRight;
3382 bool CSSParser::parseLegacyPosition(CSSPropertyID propId, bool important)
3384 // [ legacy && [ left | right | center ]
3386 CSSParserValue* value = m_valueList->current();
3390 if (value->id == CSSValueLegacy) {
3391 value = m_valueList->next();
3394 if (value->id != CSSValueCenter && value->id != CSSValueLeft && value->id != CSSValueRight)
3396 } else if (value->id == CSSValueCenter || value->id == CSSValueLeft || value->id == CSSValueRight) {
3397 if (!m_valueList->next() || m_valueList->current()->id != CSSValueLegacy)
3402 auto& cssValuePool = CSSValuePool::singleton();
3403 addProperty(propId, createPrimitiveValuePair(cssValuePool.createIdentifierValue(CSSValueLegacy), cssValuePool.createIdentifierValue(value->id)), important);
3404 return !m_valueList->next();
3407 RefPtr<CSSContentDistributionValue> CSSParser::parseContentDistributionOverflowPosition()
3409 // normal | <baseline-position> | <content-distribution> || [ <overflow-position>? && <content-position> ]
3410 // <baseline-position> = baseline | last-baseline;
3411 // <content-distribution> = space-between | space-around | space-evenly | stretch;
3412 // <content-position> = center | start | end | flex-start | flex-end | left | right;
3413 // <overflow-position> = unsafe | safe
3415 CSSParserValue* value = m_valueList->current();
3419 // auto | <baseline-position>
3420 if (value->id == CSSValueNormal || isBaselinePositionKeyword(value->id)) {
3421 m_valueList->next();
3422 return CSSContentDistributionValue::create(CSSValueInvalid, value->id, CSSValueInvalid);
3425 CSSValueID distribution = CSSValueInvalid;
3426 CSSValueID position = CSSValueInvalid;
3427 CSSValueID overflow = CSSValueInvalid;
3429 if (isContentDistributionKeyword(value->id)) {
3430 if (distribution != CSSValueInvalid)
3432 distribution = value->id;