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 "CSSCanvasValue.h"
36 #include "CSSContentDistributionValue.h"
37 #include "CSSCrossfadeValue.h"
38 #include "CSSCursorImageValue.h"
39 #include "CSSFilterImageValue.h"
40 #include "CSSFontFaceRule.h"
41 #include "CSSFontFaceSrcValue.h"
42 #include "CSSFontFeatureValue.h"
43 #include "CSSFontValue.h"
44 #include "CSSFunctionValue.h"
45 #include "CSSGradientValue.h"
46 #include "CSSImageValue.h"
47 #include "CSSInheritedValue.h"
48 #include "CSSInitialValue.h"
49 #include "CSSKeyframeRule.h"
50 #include "CSSKeyframesRule.h"
51 #include "CSSLineBoxContainValue.h"
52 #include "CSSMediaRule.h"
53 #include "CSSPageRule.h"
54 #include "CSSPrimitiveValue.h"
55 #include "CSSPrimitiveValueMappings.h"
56 #include "CSSPropertySourceData.h"
57 #include "CSSReflectValue.h"
58 #include "CSSSelector.h"
59 #include "CSSShadowValue.h"
60 #include "CSSStyleSheet.h"
61 #include "CSSTimingFunctionValue.h"
62 #include "CSSUnicodeRangeValue.h"
63 #include "CSSValueKeywords.h"
64 #include "CSSValueList.h"
65 #include "CSSValuePool.h"
68 #include "FloatConversion.h"
69 #include "GridCoordinate.h"
70 #include "HTMLParserIdioms.h"
71 #include "HashTools.h"
72 #include "MediaList.h"
73 #include "MediaQueryExp.h"
75 #include "PageConsoleClient.h"
78 #include "RenderTheme.h"
79 #include "RuntimeEnabledFeatures.h"
80 #include "SVGParserUtilities.h"
81 #include "SelectorChecker.h"
82 #include "SelectorCheckerTestFunctions.h"
84 #include "StyleProperties.h"
85 #include "StylePropertyShorthand.h"
86 #include "StyleRule.h"
87 #include "StyleRuleImport.h"
88 #include "StyleSheetContents.h"
89 #include "TextEncoding.h"
90 #include "WebKitCSSFilterValue.h"
91 #include "WebKitCSSRegionRule.h"
92 #include "WebKitCSSResourceValue.h"
93 #include "WebKitCSSTransformValue.h"
94 #include <JavaScriptCore/Profile.h>
97 #include <wtf/HexNumber.h>
98 #include <wtf/NeverDestroyed.h>
99 #include <wtf/StdLibExtras.h>
100 #include <wtf/dtoa.h>
101 #include <wtf/text/StringBuffer.h>
102 #include <wtf/text/StringBuilder.h>
103 #include <wtf/text/StringImpl.h>
105 #if ENABLE(CSS_GRID_LAYOUT)
106 #include "CSSGridLineNamesValue.h"
107 #include "CSSGridTemplateAreasValue.h"
110 #if ENABLE(CSS_IMAGE_SET)
111 #include "CSSImageSetValue.h"
114 #if ENABLE(CSS_SCROLL_SNAP)
115 #include "LengthRepeat.h"
118 #if ENABLE(DASHBOARD_SUPPORT)
119 #include "DashboardRegion.h"
125 extern int cssyydebug;
128 extern int cssyyparse(WebCore::CSSParser*);
139 class ImplicitScope {
140 WTF_MAKE_NONCOPYABLE(ImplicitScope);
142 ImplicitScope(WebCore::CSSParser& parser, PropertyType propertyType)
145 m_parser.m_implicitShorthand = propertyType == PropertyImplicit;
150 m_parser.m_implicitShorthand = false;
154 WebCore::CSSParser& m_parser;
161 static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX;
162 static const double MAX_SCALE = 1000000;
164 template <unsigned N>
165 static bool equal(const CSSParserString& a, const char (&b)[N])
167 unsigned length = N - 1; // Ignore the trailing null character
168 if (a.length() != length)
171 return a.is8Bit() ? WTF::equal(a.characters8(), reinterpret_cast<const LChar*>(b), length) : WTF::equal(a.characters16(), reinterpret_cast<const LChar*>(b), length);
174 template <unsigned N>
175 static bool equalIgnoringCase(const CSSParserString& a, const char (&b)[N])
177 unsigned length = N - 1; // Ignore the trailing null character
178 if (a.length() != length)
181 return a.is8Bit() ? WTF::equalIgnoringCase(b, a.characters8(), length) : WTF::equalIgnoringCase(b, a.characters16(), length);
184 template <unsigned N>
185 static bool equalIgnoringCase(CSSParserValue& value, const char (&b)[N])
187 ASSERT(value.unit == CSSPrimitiveValue::CSS_IDENT || value.unit == CSSPrimitiveValue::CSS_STRING);
188 return equalIgnoringCase(value.string, b);
191 static bool hasPrefix(const char* string, unsigned length, const char* prefix)
193 for (unsigned i = 0; i < length; ++i) {
196 if (string[i] != prefix[i])
202 static Ref<CSSPrimitiveValue> createPrimitiveValuePair(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> second)
204 return cssValuePool().createValue(Pair::create(first, second));
207 class AnimationParseContext {
209 AnimationParseContext()
210 : m_animationPropertyKeywordAllowed(true)
211 , m_firstAnimationCommitted(false)
212 , m_hasSeenAnimationPropertyKeyword(false)
216 void commitFirstAnimation()
218 m_firstAnimationCommitted = true;
221 bool hasCommittedFirstAnimation() const
223 return m_firstAnimationCommitted;
226 void commitAnimationPropertyKeyword()
228 m_animationPropertyKeywordAllowed = false;
231 bool animationPropertyKeywordAllowed() const
233 return m_animationPropertyKeywordAllowed;
236 bool hasSeenAnimationPropertyKeyword() const
238 return m_hasSeenAnimationPropertyKeyword;
241 void sawAnimationPropertyKeyword()
243 m_hasSeenAnimationPropertyKeyword = true;
247 bool m_animationPropertyKeywordAllowed;
248 bool m_firstAnimationCommitted;
249 bool m_hasSeenAnimationPropertyKeyword;
252 const CSSParserContext& strictCSSParserContext()
254 static NeverDestroyed<CSSParserContext> strictContext(CSSStrictMode);
255 return strictContext;
258 CSSParserContext::CSSParserContext(CSSParserMode mode, const URL& baseURL)
261 , isHTMLDocument(false)
262 , isCSSRegionsEnabled(RuntimeEnabledFeatures::sharedFeatures().cssRegionsEnabled())
263 , isCSSCompositingEnabled(RuntimeEnabledFeatures::sharedFeatures().cssCompositingEnabled())
264 , needsSiteSpecificQuirks(false)
265 , enforcesCSSMIMETypeInNoQuirksMode(true)
266 , useLegacyBackgroundSizeShorthandBehavior(false)
269 // FIXME: Force the site specific quirk below to work on iOS. Investigating other site specific quirks
270 // to see if we can enable the preference all together is to be handled by:
271 // <rdar://problem/8493309> Investigate Enabling Site Specific Quirks in MobileSafari and UIWebView
272 needsSiteSpecificQuirks = true;
276 CSSParserContext::CSSParserContext(Document& document, const URL& baseURL, const String& charset)
277 : baseURL(baseURL.isNull() ? document.baseURL() : baseURL)
279 , mode(document.inQuirksMode() ? CSSQuirksMode : CSSStrictMode)
280 , isHTMLDocument(document.isHTMLDocument())
281 , isCSSRegionsEnabled(document.cssRegionsEnabled())
282 , isCSSCompositingEnabled(document.cssCompositingEnabled())
283 , needsSiteSpecificQuirks(document.settings() ? document.settings()->needsSiteSpecificQuirks() : false)
284 , enforcesCSSMIMETypeInNoQuirksMode(!document.settings() || document.settings()->enforceCSSMIMETypeInNoQuirksMode())
285 , useLegacyBackgroundSizeShorthandBehavior(document.settings() ? document.settings()->useLegacyBackgroundSizeShorthandBehavior() : false)
288 // FIXME: Force the site specific quirk below to work on iOS. Investigating other site specific quirks
289 // to see if we can enable the preference all together is to be handled by:
290 // <rdar://problem/8493309> Investigate Enabling Site Specific Quirks in MobileSafari and UIWebView
291 needsSiteSpecificQuirks = true;
295 bool operator==(const CSSParserContext& a, const CSSParserContext& b)
297 return a.baseURL == b.baseURL
298 && a.charset == b.charset
300 && a.isHTMLDocument == b.isHTMLDocument
301 && a.isCSSRegionsEnabled == b.isCSSRegionsEnabled
302 && a.isCSSCompositingEnabled == b.isCSSCompositingEnabled
303 && a.needsSiteSpecificQuirks == b.needsSiteSpecificQuirks
304 && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode
305 && a.useLegacyBackgroundSizeShorthandBehavior == b.useLegacyBackgroundSizeShorthandBehavior;
308 CSSParser::CSSParser(const CSSParserContext& context)
311 , m_id(CSSPropertyInvalid)
312 , m_styleSheet(nullptr)
313 , m_supportsCondition(false)
314 , m_selectorListForParseSelector(nullptr)
315 , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES)
316 , m_inParseShorthand(0)
317 , m_currentShorthand(CSSPropertyInvalid)
318 , m_implicitShorthand(false)
319 , m_hasFontFaceOnlyValues(false)
320 , m_hadSyntacticallyValidCSSRule(false)
322 , m_ignoreErrorsInDeclaration(false)
323 , m_defaultNamespace(starAtom)
324 , m_parsedTextPrefixLength(0)
325 , m_nestedSelectorLevel(0)
326 , m_propertyRange(UINT_MAX, UINT_MAX)
327 , m_ruleSourceDataResult(nullptr)
328 , m_parsingMode(NormalMode)
329 , m_is8BitSource(false)
330 , m_currentCharacter8(nullptr)
331 , m_currentCharacter16(nullptr)
335 , m_tokenStartLineNumber(0)
336 , m_tokenStartColumnNumber(0)
337 , m_lastSelectorLineNumber(0)
338 , m_columnOffsetForLine(0)
339 , m_sheetStartLineNumber(0)
340 , m_sheetStartColumnNumber(0)
341 , m_allowImportRules(true)
342 , m_allowNamespaceDeclarations(true)
343 #if ENABLE(CSS_DEVICE_ADAPTATION)
344 , m_inViewport(false)
350 m_tokenStart.ptr8 = nullptr;
353 CSSParser::~CSSParser()
358 template <typename CharacterType>
359 ALWAYS_INLINE static void makeLower(const CharacterType* input, CharacterType* output, unsigned length)
361 // FIXME: If we need Unicode lowercasing here, then we probably want the real kind
362 // that can potentially change the length of the string rather than the character
363 // by character kind. If we don't need Unicode lowercasing, it would be good to
364 // simplify this function.
366 if (charactersAreAllASCII(input, length)) {
367 // Fast case for all-ASCII.
368 for (unsigned i = 0; i < length; ++i)
369 output[i] = toASCIILower(input[i]);
371 for (unsigned i = 0; i < length; ++i) {
372 ASSERT(u_tolower(input[i]) <= 0xFFFF);
373 output[i] = u_tolower(input[i]);
378 void CSSParserString::lower()
381 makeLower(characters8(), characters8(), length());
385 makeLower(characters16(), characters16(), length());
388 void CSSParser::setupParser(const char* prefix, unsigned prefixLength, StringView string, const char* suffix, unsigned suffixLength)
390 m_parsedTextPrefixLength = prefixLength;
391 unsigned stringLength = string.length();
392 unsigned length = stringLength + m_parsedTextPrefixLength + suffixLength + 1;
395 if (!stringLength || string.is8Bit()) {
396 m_dataStart8 = std::make_unique<LChar[]>(length);
397 for (unsigned i = 0; i < m_parsedTextPrefixLength; ++i)
398 m_dataStart8[i] = prefix[i];
401 memcpy(m_dataStart8.get() + m_parsedTextPrefixLength, string.characters8(), stringLength * sizeof(LChar));
403 unsigned start = m_parsedTextPrefixLength + stringLength;
404 unsigned end = start + suffixLength;
405 for (unsigned i = start; i < end; i++)
406 m_dataStart8[i] = suffix[i - start];
408 m_dataStart8[length - 1] = '\0';
410 m_is8BitSource = true;
411 m_currentCharacter8 = m_dataStart8.get();
412 m_currentCharacter16 = nullptr;
413 setTokenStart<LChar>(m_currentCharacter8);
414 m_lexFunc = &CSSParser::realLex<LChar>;
418 m_dataStart16 = std::make_unique<UChar[]>(length);
419 for (unsigned i = 0; i < m_parsedTextPrefixLength; ++i)
420 m_dataStart16[i] = prefix[i];
422 ASSERT(stringLength);
423 memcpy(m_dataStart16.get() + m_parsedTextPrefixLength, string.characters16(), stringLength * sizeof(UChar));
425 unsigned start = m_parsedTextPrefixLength + stringLength;
426 unsigned end = start + suffixLength;
427 for (unsigned i = start; i < end; i++)
428 m_dataStart16[i] = suffix[i - start];
430 m_dataStart16[length - 1] = '\0';
432 m_is8BitSource = false;
433 m_currentCharacter8 = nullptr;
434 m_currentCharacter16 = m_dataStart16.get();
435 setTokenStart<UChar>(m_currentCharacter16);
436 m_lexFunc = &CSSParser::realLex<UChar>;
439 void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, const TextPosition& textPosition, RuleSourceDataList* ruleSourceDataResult, bool logErrors)
441 setStyleSheet(sheet);
442 m_defaultNamespace = starAtom; // Reset the default namespace.
443 if (ruleSourceDataResult)
444 m_currentRuleDataStack = std::make_unique<RuleSourceDataList>();
445 m_ruleSourceDataResult = ruleSourceDataResult;
447 m_logErrors = logErrors && sheet->singleOwnerDocument() && !sheet->baseURL().isEmpty() && sheet->singleOwnerDocument()->page();
448 m_ignoreErrorsInDeclaration = false;
449 m_sheetStartLineNumber = textPosition.m_line.zeroBasedInt();
450 m_sheetStartColumnNumber = textPosition.m_column.zeroBasedInt();
451 m_lineNumber = m_sheetStartLineNumber;
452 m_columnOffsetForLine = 0;
453 setupParser("", string, "");
455 sheet->shrinkToFit();
456 m_currentRuleDataStack.reset();
457 m_ruleSourceDataResult = nullptr;
459 m_ignoreErrorsInDeclaration = false;
463 PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string)
465 setStyleSheet(sheet);
466 m_allowNamespaceDeclarations = false;
467 setupParser("@-webkit-rule{", string, "} ");
469 return m_rule.release();
472 PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet, const String& string)
474 setStyleSheet(sheet);
475 setupParser("@-webkit-keyframe-rule{ ", string, "} ");
477 return m_keyframe.release();
480 bool CSSParser::parseSupportsCondition(const String& string)
482 m_supportsCondition = false;
483 // can't use { because tokenizer state switches from supports to initial state when it sees { token.
484 // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
485 setupParser("@-webkit-supports-condition ", string, "} ");
487 return m_supportsCondition;
490 static inline bool isColorPropertyID(CSSPropertyID propertyId)
492 switch (propertyId) {
493 case CSSPropertyColor:
494 case CSSPropertyBackgroundColor:
495 case CSSPropertyBorderBottomColor:
496 case CSSPropertyBorderLeftColor:
497 case CSSPropertyBorderRightColor:
498 case CSSPropertyBorderTopColor:
499 case CSSPropertyOutlineColor:
500 case CSSPropertyTextLineThroughColor:
501 case CSSPropertyTextOverlineColor:
502 case CSSPropertyTextUnderlineColor:
503 case CSSPropertyWebkitBorderAfterColor:
504 case CSSPropertyWebkitBorderBeforeColor:
505 case CSSPropertyWebkitBorderEndColor:
506 case CSSPropertyWebkitBorderStartColor:
507 case CSSPropertyColumnRuleColor:
508 case CSSPropertyWebkitTextDecorationColor:
509 case CSSPropertyWebkitTextEmphasisColor:
510 case CSSPropertyWebkitTextFillColor:
511 case CSSPropertyWebkitTextStrokeColor:
518 bool CSSParser::isValidSystemColorValue(CSSValueID valueID)
520 return valueID >= CSSValueAqua && valueID <= CSSValueAppleSystemYellow;
523 static bool validPrimitiveValueColor(CSSValueID valueID, bool strict = false)
525 return (valueID == CSSValueWebkitText || valueID == CSSValueCurrentcolor || valueID == CSSValueMenu
526 || CSSParser::isValidSystemColorValue(valueID) || valueID == CSSValueAlpha
527 || (valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWebkitText && !strict));
530 static CSSParser::ParseResult parseColorValue(MutableStyleProperties* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
532 ASSERT(!string.isEmpty());
533 bool strict = isStrictParserMode(cssParserMode);
534 if (!isColorPropertyID(propertyId))
535 return CSSParser::ParseResult::Error;
537 CSSParserString cssString;
538 cssString.init(string);
539 CSSValueID valueID = cssValueKeywordID(cssString);
540 if (validPrimitiveValueColor(valueID, strict)) {
541 RefPtr<CSSValue> value = cssValuePool().createIdentifierValue(valueID);
542 return declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
545 if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
546 return CSSParser::ParseResult::Error;
548 RefPtr<CSSValue> value = cssValuePool().createColorValue(color);
549 return declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
552 static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acceptsNegativeNumbers)
554 switch (propertyId) {
555 case CSSPropertyFontSize:
556 case CSSPropertyHeight:
557 case CSSPropertyWidth:
558 case CSSPropertyMinHeight:
559 case CSSPropertyMinWidth:
560 case CSSPropertyPaddingBottom:
561 case CSSPropertyPaddingLeft:
562 case CSSPropertyPaddingRight:
563 case CSSPropertyPaddingTop:
564 case CSSPropertyWebkitLogicalWidth:
565 case CSSPropertyWebkitLogicalHeight:
566 case CSSPropertyWebkitMinLogicalWidth:
567 case CSSPropertyWebkitMinLogicalHeight:
568 case CSSPropertyWebkitPaddingAfter:
569 case CSSPropertyWebkitPaddingBefore:
570 case CSSPropertyWebkitPaddingEnd:
571 case CSSPropertyWebkitPaddingStart:
572 acceptsNegativeNumbers = false;
574 #if ENABLE(CSS_SHAPES)
575 case CSSPropertyWebkitShapeMargin:
576 acceptsNegativeNumbers = false;
577 return RuntimeEnabledFeatures::sharedFeatures().cssShapesEnabled();
579 case CSSPropertyBottom:
582 case CSSPropertyLeft:
583 case CSSPropertyMarginBottom:
584 case CSSPropertyMarginLeft:
585 case CSSPropertyMarginRight:
586 case CSSPropertyMarginTop:
590 case CSSPropertyRight:
592 case CSSPropertyWebkitMarginAfter:
593 case CSSPropertyWebkitMarginBefore:
594 case CSSPropertyWebkitMarginEnd:
595 case CSSPropertyWebkitMarginStart:
598 acceptsNegativeNumbers = true;
605 template <typename CharacterType>
606 static inline bool parseSimpleLength(const CharacterType* characters, unsigned& length, CSSPrimitiveValue::UnitTypes& unit, double& number)
608 if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') {
610 unit = CSSPrimitiveValue::CSS_PX;
611 } else if (length > 1 && characters[length - 1] == '%') {
613 unit = CSSPrimitiveValue::CSS_PERCENTAGE;
616 // We rely on charactersToDouble for validation as well. The function
617 // will set "ok" to "false" if the entire passed-in character range does
618 // not represent a double.
620 number = charactersToDouble(characters, length, &ok);
624 static CSSParser::ParseResult parseSimpleLengthValue(MutableStyleProperties* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
626 ASSERT(!string.isEmpty());
627 bool acceptsNegativeNumbers;
628 if (!isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers))
629 return CSSParser::ParseResult::Error;
631 unsigned length = string.length();
633 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
635 if (string.is8Bit()) {
636 if (!parseSimpleLength(string.characters8(), length, unit, number))
637 return CSSParser::ParseResult::Error;
639 if (!parseSimpleLength(string.characters16(), length, unit, number))
640 return CSSParser::ParseResult::Error;
643 if (unit == CSSPrimitiveValue::CSS_NUMBER) {
644 if (number && isStrictParserMode(cssParserMode))
645 return CSSParser::ParseResult::Error;
646 unit = CSSPrimitiveValue::CSS_PX;
648 if (number < 0 && !acceptsNegativeNumbers)
649 return CSSParser::ParseResult::Error;
650 if (std::isinf(number))
651 return CSSParser::ParseResult::Error;
653 RefPtr<CSSValue> value = cssValuePool().createValue(number, unit);
654 return declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
657 static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int valueID, const CSSParserContext& parserContext, StyleSheetContents* styleSheetContents)
662 switch (propertyId) {
663 case CSSPropertyBorderCollapse: // collapse | separate | inherit
664 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate)
667 case CSSPropertyBorderTopStyle: // <border-style> | inherit
668 case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed |
669 case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset
670 case CSSPropertyBorderLeftStyle:
671 case CSSPropertyWebkitBorderAfterStyle:
672 case CSSPropertyWebkitBorderBeforeStyle:
673 case CSSPropertyWebkitBorderEndStyle:
674 case CSSPropertyWebkitBorderStartStyle:
675 case CSSPropertyColumnRuleStyle:
676 if (valueID >= CSSValueNone && valueID <= CSSValueDouble)
679 case CSSPropertyBoxSizing:
680 if (valueID == CSSValueBorderBox || valueID == CSSValueContentBox)
683 case CSSPropertyCaptionSide: // top | bottom | left | right | inherit
684 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueTop || valueID == CSSValueBottom)
687 case CSSPropertyClear: // none | left | right | both | inherit
688 if (valueID == CSSValueNone || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueBoth)
691 case CSSPropertyDirection: // ltr | rtl | inherit
692 if (valueID == CSSValueLtr || valueID == CSSValueRtl)
695 case CSSPropertyDisplay:
696 // inline | block | list-item | inline-block | table |
697 // inline-table | table-row-group | table-header-group | table-footer-group | table-row |
698 // table-column-group | table-column | table-cell | table-caption | -webkit-box | -webkit-inline-box | none | inherit
699 // flex | -webkit-flex | inline-flex | -webkit-inline-flex | -webkit-grid | -webkit-inline-grid
700 if ((valueID >= CSSValueInline && valueID <= CSSValueWebkitInlineFlex) || valueID == CSSValueNone)
702 #if ENABLE(CSS_GRID_LAYOUT)
703 if (valueID == CSSValueWebkitGrid || valueID == CSSValueWebkitInlineGrid)
708 case CSSPropertyEmptyCells: // show | hide | inherit
709 if (valueID == CSSValueShow || valueID == CSSValueHide)
712 case CSSPropertyFloat: // left | right | none | center (for buggy CSS, maps to none)
713 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueNone || valueID == CSSValueCenter)
716 case CSSPropertyFontStyle: // normal | italic | oblique | inherit
717 if (valueID == CSSValueNormal || valueID == CSSValueItalic || valueID == CSSValueOblique)
720 case CSSPropertyImageRendering: // auto | optimizeSpeed | optimizeQuality | -webkit-crisp-edges | -webkit-optimize-contrast
721 if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizequality
722 || valueID == CSSValueWebkitCrispEdges || valueID == CSSValueWebkitOptimizeContrast)
725 case CSSPropertyListStylePosition: // inside | outside | inherit
726 if (valueID == CSSValueInside || valueID == CSSValueOutside)
729 case CSSPropertyListStyleType:
730 // See section CSS_PROP_LIST_STYLE_TYPE of file CSSValueKeywords.in
731 // for the list of supported list-style-types.
732 if ((valueID >= CSSValueDisc && valueID <= CSSValueKatakanaIroha) || valueID == CSSValueNone)
735 case CSSPropertyObjectFit:
736 if (valueID == CSSValueFill || valueID == CSSValueContain || valueID == CSSValueCover || valueID == CSSValueNone || valueID == CSSValueScaleDown)
739 case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto | inherit
740 if (valueID == CSSValueAuto || valueID == CSSValueNone || (valueID >= CSSValueInset && valueID <= CSSValueDouble))
743 case CSSPropertyOverflowWrap: // normal | break-word
744 case CSSPropertyWordWrap:
745 if (valueID == CSSValueNormal || valueID == CSSValueBreakWord)
748 #if ENABLE(CSS_SCROLL_SNAP)
749 case CSSPropertyWebkitScrollSnapType: // none | mandatory | proximity
750 if (valueID == CSSValueNone || valueID == CSSValueMandatory || valueID == CSSValueProximity)
754 case CSSPropertyOverflowX: // visible | hidden | scroll | auto | marquee | overlay | inherit
755 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitMarquee)
758 case CSSPropertyOverflowY: // visible | hidden | scroll | auto | marquee | overlay | inherit | -webkit-paged-x | -webkit-paged-y
759 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitMarquee || valueID == CSSValueWebkitPagedX || valueID == CSSValueWebkitPagedY)
762 case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | inherit
763 case CSSPropertyPageBreakBefore:
764 case CSSPropertyWebkitColumnBreakAfter:
765 case CSSPropertyWebkitColumnBreakBefore:
766 if (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight)
769 case CSSPropertyPageBreakInside: // avoid | auto | inherit
770 case CSSPropertyWebkitColumnBreakInside:
771 if (valueID == CSSValueAuto || valueID == CSSValueAvoid)
774 case CSSPropertyPointerEvents:
775 // none | visiblePainted | visibleFill | visibleStroke | visible |
776 // painted | fill | stroke | auto | all | inherit
777 if (valueID == CSSValueVisible || valueID == CSSValueNone || valueID == CSSValueAll || valueID == CSSValueAuto || (valueID >= CSSValueVisiblepainted && valueID <= CSSValueStroke))
780 case CSSPropertyPosition: // static | relative | absolute | fixed | sticky | inherit
781 if (valueID == CSSValueStatic || valueID == CSSValueRelative || valueID == CSSValueAbsolute || valueID == CSSValueFixed || valueID == CSSValueWebkitSticky)
784 case CSSPropertyResize: // none | both | horizontal | vertical | auto
785 if (valueID == CSSValueNone || valueID == CSSValueBoth || valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueAuto)
788 case CSSPropertySpeak: // none | normal | spell-out | digits | literal-punctuation | no-punctuation | inherit
789 if (valueID == CSSValueNone || valueID == CSSValueNormal || valueID == CSSValueSpellOut || valueID == CSSValueDigits || valueID == CSSValueLiteralPunctuation || valueID == CSSValueNoPunctuation)
792 case CSSPropertyTableLayout: // auto | fixed | inherit
793 if (valueID == CSSValueAuto || valueID == CSSValueFixed)
796 case CSSPropertyTextLineThroughMode:
797 case CSSPropertyTextOverlineMode:
798 case CSSPropertyTextUnderlineMode:
799 if (valueID == CSSValueContinuous || valueID == CSSValueSkipWhiteSpace)
802 case CSSPropertyTextLineThroughStyle:
803 case CSSPropertyTextOverlineStyle:
804 case CSSPropertyTextUnderlineStyle:
805 if (valueID == CSSValueNone || valueID == CSSValueSolid || valueID == CSSValueDouble || valueID == CSSValueDashed || valueID == CSSValueDotDash || valueID == CSSValueDotDotDash || valueID == CSSValueWave)
808 case CSSPropertyTextOverflow: // clip | ellipsis
809 if (valueID == CSSValueClip || valueID == CSSValueEllipsis)
812 case CSSPropertyTextRendering: // auto | optimizeSpeed | optimizeLegibility | geometricPrecision
813 if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizelegibility || valueID == CSSValueGeometricprecision)
816 case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none | inherit
817 if ((valueID >= CSSValueCapitalize && valueID <= CSSValueLowercase) || valueID == CSSValueNone)
820 case CSSPropertyVisibility: // visible | hidden | collapse | inherit
821 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueCollapse)
824 case CSSPropertyWebkitAppearance:
825 if ((valueID >= CSSValueCheckbox && valueID <= CSSValueCapsLockIndicator) || valueID == CSSValueNone)
828 case CSSPropertyWebkitBackfaceVisibility:
829 if (valueID == CSSValueVisible || valueID == CSSValueHidden)
832 #if ENABLE(CSS_COMPOSITING)
833 case CSSPropertyMixBlendMode:
834 if (parserContext.isCSSCompositingEnabled && (valueID == CSSValueNormal || valueID == CSSValueMultiply || valueID == CSSValueScreen
835 || valueID == CSSValueOverlay || valueID == CSSValueDarken || valueID == CSSValueLighten || valueID == CSSValueColorDodge
836 || valueID == CSSValueColorBurn || valueID == CSSValueHardLight || valueID == CSSValueSoftLight || valueID == CSSValueDifference
837 || valueID == CSSValueExclusion || valueID == CSSValuePlusDarker || valueID == CSSValuePlusLighter))
840 case CSSPropertyIsolation:
841 if (parserContext.isCSSCompositingEnabled && (valueID == CSSValueAuto || valueID == CSSValueIsolate))
845 case CSSPropertyWebkitBorderFit:
846 if (valueID == CSSValueBorder || valueID == CSSValueLines)
849 case CSSPropertyWebkitBoxAlign:
850 if (valueID == CSSValueStretch || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline)
853 #if ENABLE(CSS_BOX_DECORATION_BREAK)
854 case CSSPropertyWebkitBoxDecorationBreak:
855 if (valueID == CSSValueClone || valueID == CSSValueSlice)
859 case CSSPropertyWebkitBoxDirection:
860 if (valueID == CSSValueNormal || valueID == CSSValueReverse)
863 case CSSPropertyWebkitBoxLines:
864 if (valueID == CSSValueSingle || valueID == CSSValueMultiple)
867 case CSSPropertyWebkitBoxOrient:
868 if (valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueInlineAxis || valueID == CSSValueBlockAxis)
871 case CSSPropertyWebkitBoxPack:
872 if (valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueJustify)
875 case CSSPropertyWebkitColorCorrection:
876 if (valueID == CSSValueSrgb || valueID == CSSValueDefault)
879 case CSSPropertyColumnFill:
880 if (valueID == CSSValueAuto || valueID == CSSValueBalance)
883 case CSSPropertyFlexDirection:
884 if (valueID == CSSValueRow || valueID == CSSValueRowReverse || valueID == CSSValueColumn || valueID == CSSValueColumnReverse)
887 case CSSPropertyFlexWrap:
888 if (valueID == CSSValueNowrap || valueID == CSSValueWrap || valueID == CSSValueWrapReverse)
891 case CSSPropertyWebkitFontKerning:
892 if (valueID == CSSValueAuto || valueID == CSSValueNormal || valueID == CSSValueNone)
895 case CSSPropertyWebkitFontSmoothing:
896 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueAntialiased || valueID == CSSValueSubpixelAntialiased)
899 case CSSPropertyWebkitHyphens:
900 if (valueID == CSSValueNone || valueID == CSSValueManual || valueID == CSSValueAuto)
903 case CSSPropertyWebkitLineAlign:
904 if (valueID == CSSValueNone || valueID == CSSValueEdges)
907 case CSSPropertyWebkitLineBreak: // auto | loose | normal | strict | after-white-space
908 if (valueID == CSSValueAuto || valueID == CSSValueLoose || valueID == CSSValueNormal || valueID == CSSValueStrict || valueID == CSSValueAfterWhiteSpace)
911 case CSSPropertyWebkitLineSnap:
912 if (valueID == CSSValueNone || valueID == CSSValueBaseline || valueID == CSSValueContain)
915 case CSSPropertyWebkitMarginAfterCollapse:
916 case CSSPropertyWebkitMarginBeforeCollapse:
917 case CSSPropertyWebkitMarginBottomCollapse:
918 case CSSPropertyWebkitMarginTopCollapse:
919 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate || valueID == CSSValueDiscard)
922 case CSSPropertyWebkitMarqueeDirection:
923 if (valueID == CSSValueForwards || valueID == CSSValueBackwards || valueID == CSSValueAhead || valueID == CSSValueReverse || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueDown
924 || valueID == CSSValueUp || valueID == CSSValueAuto)
927 case CSSPropertyWebkitMarqueeStyle:
928 if (valueID == CSSValueNone || valueID == CSSValueSlide || valueID == CSSValueScroll || valueID == CSSValueAlternate)
931 case CSSPropertyWebkitNbspMode: // normal | space
932 if (valueID == CSSValueNormal || valueID == CSSValueSpace)
935 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
936 case CSSPropertyWebkitOverflowScrolling:
937 if (valueID == CSSValueAuto || valueID == CSSValueTouch)
941 case CSSPropertyWebkitPrintColorAdjust:
942 if (valueID == CSSValueExact || valueID == CSSValueEconomy)
945 #if ENABLE(CSS_REGIONS)
946 case CSSPropertyWebkitRegionBreakAfter:
947 case CSSPropertyWebkitRegionBreakBefore:
948 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight))
951 case CSSPropertyWebkitRegionBreakInside:
952 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAvoid))
955 case CSSPropertyWebkitRegionFragment:
956 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueBreak))
960 case CSSPropertyWebkitRtlOrdering:
961 if (valueID == CSSValueLogical || valueID == CSSValueVisual)
965 case CSSPropertyWebkitRubyPosition:
966 if (valueID == CSSValueBefore || valueID == CSSValueAfter || valueID == CSSValueInterCharacter)
970 #if ENABLE(CSS3_TEXT)
971 case CSSPropertyWebkitTextAlignLast:
972 // auto | start | end | left | right | center | justify
973 if ((valueID >= CSSValueLeft && valueID <= CSSValueJustify) || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueAuto)
977 case CSSPropertyWebkitTextCombine:
978 if (valueID == CSSValueNone || valueID == CSSValueHorizontal)
981 #if ENABLE(CSS3_TEXT)
982 case CSSPropertyWebkitTextJustify:
983 // auto | none | inter-word | distribute
984 if (valueID == CSSValueInterWord || valueID == CSSValueDistribute || valueID == CSSValueAuto || valueID == CSSValueNone)
988 case CSSPropertyWebkitTextSecurity:
989 // disc | circle | square | none | inherit
990 if (valueID == CSSValueDisc || valueID == CSSValueCircle || valueID == CSSValueSquare || valueID == CSSValueNone)
993 #if ENABLE(IOS_TEXT_AUTOSIZING)
994 case CSSPropertyWebkitTextSizeAdjust:
995 if (valueID == CSSValueAuto || valueID == CSSValueNone)
999 case CSSPropertyTransformStyle:
1000 case CSSPropertyWebkitTransformStyle:
1001 if (valueID == CSSValueFlat || valueID == CSSValuePreserve3d)
1004 case CSSPropertyWebkitUserDrag: // auto | none | element
1005 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueElement)
1008 case CSSPropertyWebkitUserModify: // read-only | read-write
1009 if (valueID == CSSValueReadOnly || valueID == CSSValueReadWrite || valueID == CSSValueReadWritePlaintextOnly) {
1010 if (styleSheetContents)
1011 styleSheetContents->parserSetUsesStyleBasedEditability();
1015 case CSSPropertyWebkitUserSelect: // auto | none | text | all
1016 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueText)
1018 if (valueID == CSSValueAll) {
1019 if (styleSheetContents)
1020 styleSheetContents->parserSetUsesStyleBasedEditability();
1024 case CSSPropertyWebkitWritingMode:
1025 if (valueID >= CSSValueHorizontalTb && valueID <= CSSValueHorizontalBt)
1028 case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit
1029 if (valueID == CSSValueNormal || valueID == CSSValuePre || valueID == CSSValuePreWrap || valueID == CSSValuePreLine || valueID == CSSValueNowrap)
1032 case CSSPropertyWordBreak: // normal | break-all | break-word (this is a custom extension)
1033 if (valueID == CSSValueNormal || valueID == CSSValueBreakAll || valueID == CSSValueBreakWord)
1036 #if ENABLE(CSS_TRAILING_WORD)
1037 case CSSPropertyAppleTrailingWord: // auto | -apple-partially-balanced
1038 if (valueID == CSSValueAuto || valueID == CSSValueWebkitPartiallyBalanced)
1043 ASSERT_NOT_REACHED();
1046 #if !ENABLE(CSS_COMPOSITING) && !ENABLE(CSS_REGIONS)
1047 UNUSED_PARAM(parserContext);
1052 static inline bool isKeywordPropertyID(CSSPropertyID propertyId)
1054 switch (propertyId) {
1055 case CSSPropertyBorderBottomStyle:
1056 case CSSPropertyBorderCollapse:
1057 case CSSPropertyBorderLeftStyle:
1058 case CSSPropertyBorderRightStyle:
1059 case CSSPropertyBorderTopStyle:
1060 case CSSPropertyBoxSizing:
1061 case CSSPropertyCaptionSide:
1062 case CSSPropertyClear:
1063 case CSSPropertyDirection:
1064 case CSSPropertyDisplay:
1065 case CSSPropertyEmptyCells:
1066 case CSSPropertyFloat:
1067 case CSSPropertyFontStyle:
1068 case CSSPropertyImageRendering:
1069 case CSSPropertyListStylePosition:
1070 case CSSPropertyListStyleType:
1071 case CSSPropertyObjectFit:
1072 case CSSPropertyOutlineStyle:
1073 case CSSPropertyOverflowWrap:
1074 case CSSPropertyOverflowX:
1075 case CSSPropertyOverflowY:
1076 case CSSPropertyPageBreakAfter:
1077 case CSSPropertyPageBreakBefore:
1078 case CSSPropertyPageBreakInside:
1079 case CSSPropertyPointerEvents:
1080 case CSSPropertyPosition:
1081 case CSSPropertyResize:
1082 case CSSPropertySpeak:
1083 case CSSPropertyTableLayout:
1084 case CSSPropertyTextLineThroughMode:
1085 case CSSPropertyTextLineThroughStyle:
1086 case CSSPropertyTextOverflow:
1087 case CSSPropertyTextOverlineMode:
1088 case CSSPropertyTextOverlineStyle:
1089 case CSSPropertyTextRendering:
1090 case CSSPropertyTextTransform:
1091 case CSSPropertyTextUnderlineMode:
1092 case CSSPropertyTextUnderlineStyle:
1093 case CSSPropertyVisibility:
1094 case CSSPropertyWebkitAppearance:
1095 #if ENABLE(CSS_COMPOSITING)
1096 case CSSPropertyMixBlendMode:
1097 case CSSPropertyIsolation:
1099 case CSSPropertyWebkitBackfaceVisibility:
1100 case CSSPropertyWebkitBorderAfterStyle:
1101 case CSSPropertyWebkitBorderBeforeStyle:
1102 case CSSPropertyWebkitBorderEndStyle:
1103 case CSSPropertyWebkitBorderFit:
1104 case CSSPropertyWebkitBorderStartStyle:
1105 case CSSPropertyWebkitBoxAlign:
1106 #if ENABLE(CSS_BOX_DECORATION_BREAK)
1107 case CSSPropertyWebkitBoxDecorationBreak:
1109 case CSSPropertyWebkitBoxDirection:
1110 case CSSPropertyWebkitBoxLines:
1111 case CSSPropertyWebkitBoxOrient:
1112 case CSSPropertyWebkitBoxPack:
1113 case CSSPropertyWebkitColorCorrection:
1114 case CSSPropertyWebkitColumnBreakAfter:
1115 case CSSPropertyWebkitColumnBreakBefore:
1116 case CSSPropertyWebkitColumnBreakInside:
1117 case CSSPropertyColumnFill:
1118 case CSSPropertyColumnRuleStyle:
1119 case CSSPropertyFlexDirection:
1120 case CSSPropertyFlexWrap:
1121 case CSSPropertyWebkitFontKerning:
1122 case CSSPropertyWebkitFontSmoothing:
1123 case CSSPropertyWebkitHyphens:
1124 case CSSPropertyWebkitLineAlign:
1125 case CSSPropertyWebkitLineBreak:
1126 case CSSPropertyWebkitLineSnap:
1127 case CSSPropertyWebkitMarginAfterCollapse:
1128 case CSSPropertyWebkitMarginBeforeCollapse:
1129 case CSSPropertyWebkitMarginBottomCollapse:
1130 case CSSPropertyWebkitMarginTopCollapse:
1131 case CSSPropertyWebkitMarqueeDirection:
1132 case CSSPropertyWebkitMarqueeStyle:
1133 case CSSPropertyWebkitNbspMode:
1134 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
1135 case CSSPropertyWebkitOverflowScrolling:
1137 case CSSPropertyWebkitPrintColorAdjust:
1138 #if ENABLE(CSS_REGIONS)
1139 case CSSPropertyWebkitRegionBreakAfter:
1140 case CSSPropertyWebkitRegionBreakBefore:
1141 case CSSPropertyWebkitRegionBreakInside:
1142 case CSSPropertyWebkitRegionFragment:
1144 case CSSPropertyWebkitRtlOrdering:
1145 case CSSPropertyWebkitRubyPosition:
1146 #if ENABLE(CSS3_TEXT)
1147 case CSSPropertyWebkitTextAlignLast:
1149 case CSSPropertyWebkitTextCombine:
1150 #if ENABLE(CSS3_TEXT)
1151 case CSSPropertyWebkitTextJustify:
1153 case CSSPropertyWebkitTextSecurity:
1154 case CSSPropertyTransformStyle:
1155 case CSSPropertyWebkitTransformStyle:
1156 case CSSPropertyWebkitUserDrag:
1157 case CSSPropertyWebkitUserModify:
1158 case CSSPropertyWebkitUserSelect:
1159 case CSSPropertyWebkitWritingMode:
1160 case CSSPropertyWhiteSpace:
1161 case CSSPropertyWordBreak:
1162 case CSSPropertyWordWrap:
1163 #if ENABLE(CSS_SCROLL_SNAP)
1164 case CSSPropertyWebkitScrollSnapType:
1166 #if ENABLE(CSS_TRAILING_WORD)
1167 case CSSPropertyAppleTrailingWord:
1175 static CSSParser::ParseResult parseKeywordValue(MutableStyleProperties* declaration, CSSPropertyID propertyId, const String& string, bool important, const CSSParserContext& parserContext, StyleSheetContents* styleSheetContents)
1177 ASSERT(!string.isEmpty());
1179 if (!isKeywordPropertyID(propertyId)) {
1180 // All properties accept the values of "initial" and "inherit".
1181 String lowerCaseString = string.lower();
1182 if (lowerCaseString != "initial" && lowerCaseString != "inherit")
1183 return CSSParser::ParseResult::Error;
1185 // Parse initial/inherit shorthands using the CSSParser.
1186 if (shorthandForProperty(propertyId).length())
1187 return CSSParser::ParseResult::Error;
1190 CSSParserString cssString;
1191 cssString.init(string);
1192 CSSValueID valueID = cssValueKeywordID(cssString);
1195 return CSSParser::ParseResult::Error;
1197 RefPtr<CSSValue> value;
1198 if (valueID == CSSValueInherit)
1199 value = cssValuePool().createInheritedValue();
1200 else if (valueID == CSSValueInitial)
1201 value = cssValuePool().createExplicitInitialValue();
1202 else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext, styleSheetContents))
1203 value = cssValuePool().createIdentifierValue(valueID);
1205 return CSSParser::ParseResult::Error;
1207 return declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
1210 template <typename CharacterType>
1211 static bool parseTransformTranslateArguments(WebKitCSSTransformValue& transformValue, CharacterType* characters, unsigned length, unsigned start, unsigned expectedCount)
1213 while (expectedCount) {
1214 size_t end = WTF::find(characters, length, expectedCount == 1 ? ')' : ',', start);
1215 if (end == notFound || (expectedCount == 1 && end != length - 1))
1217 unsigned argumentLength = end - start;
1218 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
1220 if (!parseSimpleLength(characters + start, argumentLength, unit, number))
1222 if (unit != CSSPrimitiveValue::CSS_PX && (number || unit != CSSPrimitiveValue::CSS_NUMBER))
1224 transformValue.append(cssValuePool().createValue(number, CSSPrimitiveValue::CSS_PX));
1231 static CSSParser::ParseResult parseTranslateTransformValue(MutableStyleProperties* properties, CSSPropertyID propertyID, const String& string, bool important)
1233 if (propertyID != CSSPropertyTransform)
1234 return CSSParser::ParseResult::Error;
1236 static const unsigned shortestValidTransformStringLength = 12;
1237 static const unsigned likelyMultipartTransformStringLengthCutoff = 32;
1238 if (string.length() < shortestValidTransformStringLength || string.length() > likelyMultipartTransformStringLengthCutoff)
1239 return CSSParser::ParseResult::Error;
1241 if (!string.startsWith("translate", false))
1242 return CSSParser::ParseResult::Error;
1244 UChar c9 = toASCIILower(string[9]);
1245 UChar c10 = toASCIILower(string[10]);
1247 WebKitCSSTransformValue::TransformOperationType transformType;
1248 unsigned expectedArgumentCount = 1;
1249 unsigned argumentStart = 11;
1250 if (c9 == 'x' && c10 == '(')
1251 transformType = WebKitCSSTransformValue::TranslateXTransformOperation;
1252 else if (c9 == 'y' && c10 == '(')
1253 transformType = WebKitCSSTransformValue::TranslateYTransformOperation;
1254 else if (c9 == 'z' && c10 == '(')
1255 transformType = WebKitCSSTransformValue::TranslateZTransformOperation;
1256 else if (c9 == '(') {
1257 transformType = WebKitCSSTransformValue::TranslateTransformOperation;
1258 expectedArgumentCount = 2;
1260 } else if (c9 == '3' && c10 == 'd' && string[11] == '(') {
1261 transformType = WebKitCSSTransformValue::Translate3DTransformOperation;
1262 expectedArgumentCount = 3;
1265 return CSSParser::ParseResult::Error;
1267 RefPtr<WebKitCSSTransformValue> transformValue = WebKitCSSTransformValue::create(transformType);
1269 if (string.is8Bit())
1270 success = parseTransformTranslateArguments(*transformValue, string.characters8(), string.length(), argumentStart, expectedArgumentCount);
1272 success = parseTransformTranslateArguments(*transformValue, string.characters16(), string.length(), argumentStart, expectedArgumentCount);
1274 return CSSParser::ParseResult::Error;
1276 RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
1277 result->append(transformValue.releaseNonNull());
1278 return properties->addParsedProperty(CSSProperty(CSSPropertyTransform, result.release(), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
1281 PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& string)
1283 if (string.isEmpty())
1286 Ref<CSSValueList> valueList = CSSValueList::createCommaSeparated();
1288 Vector<String> familyNames;
1289 string.string().split(',', true, familyNames);
1291 for (auto& familyName : familyNames) {
1292 String stripped = stripLeadingAndTrailingHTMLSpaces(familyName);
1293 if (stripped.isEmpty())
1296 RefPtr<CSSValue> value;
1297 for (auto propertyID : { CSSValueSerif, CSSValueSansSerif, CSSValueCursive, CSSValueFantasy, CSSValueMonospace, CSSValueWebkitBody }) {
1298 if (equalIgnoringCase(stripped, getValueName(propertyID))) {
1299 value = cssValuePool().createIdentifierValue(propertyID);
1304 value = cssValuePool().createFontFamilyValue(stripped);
1305 valueList->append(value.releaseNonNull());
1308 return WTF::move(valueList);
1311 CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
1313 ASSERT(!string.isEmpty());
1314 CSSParser::ParseResult result = parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode);
1315 if (result != ParseResult::Error)
1318 result = parseColorValue(declaration, propertyID, string, important, cssParserMode);
1319 if (result != ParseResult::Error)
1322 CSSParserContext context(cssParserMode);
1323 if (contextStyleSheet) {
1324 context = contextStyleSheet->parserContext();
1325 context.mode = cssParserMode;
1328 result = parseKeywordValue(declaration, propertyID, string, important, context, contextStyleSheet);
1329 if (result != ParseResult::Error)
1332 result = parseTranslateTransformValue(declaration, propertyID, string, important);
1333 if (result != ParseResult::Error)
1336 CSSParser parser(context);
1337 return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
1340 CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties* declaration, CSSPropertyID propertyID, const String& string, bool important, StyleSheetContents* contextStyleSheet)
1342 setStyleSheet(contextStyleSheet);
1344 setupParser("@-webkit-value{", string, "} ");
1347 m_important = important;
1353 ParseResult result = ParseResult::Error;
1354 if (m_hasFontFaceOnlyValues)
1355 deleteFontFaceOnlyValues();
1357 if (!m_parsedProperties.isEmpty()) {
1358 result = declaration->addParsedProperties(m_parsedProperties) ? ParseResult::Changed : ParseResult::Unchanged;
1365 // The color will only be changed when string contains a valid CSS color, so callers
1366 // can set it to a default color and ignore the boolean result.
1367 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
1369 // First try creating a color specified by name, rgba(), rgb() or "#" syntax.
1370 if (fastParseColor(color, string, strict))
1373 CSSParser parser(CSSStrictMode);
1375 // In case the fast-path parser didn't understand the color, try the full parser.
1376 if (!parser.parseColor(string))
1379 CSSValue& value = *parser.m_parsedProperties.first().value();
1380 if (!is<CSSPrimitiveValue>(value))
1383 CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value);
1384 if (!primitiveValue.isRGBColor())
1387 color = primitiveValue.getRGBA32Value();
1391 bool CSSParser::parseColor(const String& string)
1393 setupParser("@-webkit-decls{color:", string, "} ");
1397 return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
1400 bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
1402 if (!document || !document->page())
1405 CSSParserString cssColor;
1406 cssColor.init(string);
1407 CSSValueID id = cssValueKeywordID(cssColor);
1408 if (!validPrimitiveValueColor(id))
1411 Color parsedColor = document->page()->theme().systemColor(id);
1412 if (!parsedColor.isValid())
1415 color = parsedColor.rgb();
1419 void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
1421 m_selectorListForParseSelector = &selectorList;
1423 setupParser("@-webkit-selector{", string, "}");
1427 m_selectorListForParseSelector = nullptr;
1430 Ref<ImmutableStyleProperties> CSSParser::parseInlineStyleDeclaration(const String& string, Element* element)
1432 CSSParserContext context = element->document().elementSheet().contents().parserContext();
1433 context.mode = strictToCSSParserMode(element->isHTMLElement() && !element->document().inQuirksMode());
1434 return CSSParser(context).parseDeclaration(string, &element->document().elementSheet().contents());
1437 Ref<ImmutableStyleProperties> CSSParser::parseDeclaration(const String& string, StyleSheetContents* contextStyleSheet)
1439 setStyleSheet(contextStyleSheet);
1441 setupParser("@-webkit-decls{", string, "} ");
1445 if (m_hasFontFaceOnlyValues)
1446 deleteFontFaceOnlyValues();
1448 Ref<ImmutableStyleProperties> style = createStyleProperties();
1454 bool CSSParser::parseDeclaration(MutableStyleProperties* declaration, const String& string, PassRefPtr<CSSRuleSourceData> prpRuleSourceData, StyleSheetContents* contextStyleSheet)
1456 // Length of the "@-webkit-decls{" prefix.
1457 static const unsigned prefixLength = 15;
1459 setStyleSheet(contextStyleSheet);
1461 RefPtr<CSSRuleSourceData> ruleSourceData = prpRuleSourceData;
1462 if (ruleSourceData) {
1463 m_currentRuleDataStack = std::make_unique<RuleSourceDataList>();
1464 m_currentRuleDataStack->append(ruleSourceData);
1467 setupParser("@-webkit-decls{", string, "} ");
1472 if (m_hasFontFaceOnlyValues)
1473 deleteFontFaceOnlyValues();
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.get());
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 WTF::move(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 = WTF::move(*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.
1534 CSSParser::SourceSize::SourceSize(CSSParser::SourceSize&& original)
1535 : expression(WTF::move(original.expression))
1536 , length(original.length)
1540 CSSParser::SourceSize::SourceSize(std::unique_ptr<MediaQueryExp>&& origExp, RefPtr<CSSValue> value)
1541 : expression(WTF::move(origExp))
1546 CSSParser::SourceSize CSSParser::sourceSize(std::unique_ptr<MediaQueryExp>&& expression, CSSParserValue& parserValue)
1548 RefPtr<CSSValue> value;
1549 if (isCalculation(parserValue)) {
1550 auto* args = parserValue.function->args.get();
1551 if (args && args->size())
1552 value = CSSCalcValue::create(parserValue.function->name, *args, CalculationRangeNonNegative);
1555 value = parserValue.createCSSValue();
1556 destroy(parserValue);
1557 // FIXME: Calling the constructor explicitly here to work around an MSVC bug.
1558 // For other compilers, we did not need to define the constructors and we could use aggregate initialization syntax.
1559 return SourceSize(WTF::move(expression), WTF::move(value));
1562 static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, std::bitset<numCSSProperties>& seenProperties)
1564 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
1565 for (int i = input.size() - 1; i >= 0; --i) {
1566 const CSSProperty& property = input[i];
1567 if (property.isImportant() != important)
1569 const unsigned propertyIDIndex = property.id() - firstCSSProperty;
1570 ASSERT(propertyIDIndex < seenProperties.size());
1571 if (seenProperties[propertyIDIndex])
1573 seenProperties.set(propertyIDIndex);
1574 output[--unusedEntries] = property;
1578 Ref<ImmutableStyleProperties> CSSParser::createStyleProperties()
1580 std::bitset<numCSSProperties> seenProperties;
1581 size_t unusedEntries = m_parsedProperties.size();
1582 Vector<CSSProperty, 256> results(unusedEntries);
1584 // Important properties have higher priority, so add them first. Duplicate definitions can then be ignored when found.
1585 filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties);
1586 filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties);
1588 results.remove(0, unusedEntries);
1590 return ImmutableStyleProperties::create(results.data(), results.size(), m_context.mode);
1593 void CSSParser::addPropertyWithPrefixingVariant(CSSPropertyID propId, PassRefPtr<CSSValue> value, bool important, bool implicit)
1595 RefPtr<CSSValue> val = value.get();
1596 addProperty(propId, value, important, implicit);
1598 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propId);
1599 if (prefixingVariant == propId)
1602 if (m_currentShorthand) {
1603 // We can't use ShorthandScope here as we can already be inside one (e.g we are parsing CSSTransition).
1604 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
1605 addProperty(prefixingVariant, val.release(), important, implicit);
1606 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
1608 addProperty(prefixingVariant, val.release(), important, implicit);
1611 void CSSParser::addProperty(CSSPropertyID propId, PassRefPtr<CSSValue> value, bool important, bool implicit)
1613 // This property doesn't belong to a shorthand or is a CSS variable (which will be resolved later).
1614 if (!m_currentShorthand) {
1615 m_parsedProperties.append(CSSProperty(propId, value, important, false, CSSPropertyInvalid, m_implicitShorthand || implicit));
1619 Vector<StylePropertyShorthand> shorthands = matchingShorthandsForLonghand(propId);
1620 if (shorthands.size() == 1)
1621 m_parsedProperties.append(CSSProperty(propId, value, important, true, CSSPropertyInvalid, m_implicitShorthand || implicit));
1623 m_parsedProperties.append(CSSProperty(propId, value, important, true, indexOfShorthandForLonghand(m_currentShorthand, shorthands), m_implicitShorthand || implicit));
1626 void CSSParser::rollbackLastProperties(int num)
1629 ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num));
1630 m_parsedProperties.shrink(m_parsedProperties.size() - num);
1633 void CSSParser::clearProperties()
1635 m_parsedProperties.clear();
1636 m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
1637 m_hasFontFaceOnlyValues = false;
1640 URL CSSParser::completeURL(const CSSParserContext& context, const String& url)
1644 if (context.charset.isEmpty())
1645 return URL(context.baseURL, url);
1646 return URL(context.baseURL, url, context.charset);
1649 URL CSSParser::completeURL(const String& url) const
1651 return completeURL(m_context, url);
1654 bool CSSParser::validateCalculationUnit(ValueWithCalculation& valueWithCalculation, Units unitFlags)
1656 bool mustBeNonNegative = unitFlags & FNonNeg;
1658 RefPtr<CSSCalcValue> calculation;
1659 if (valueWithCalculation.calculation()) {
1660 // The calculation value was already parsed so we reuse it. However, we may need to update its range.
1661 calculation = valueWithCalculation.calculation();
1662 calculation->setPermittedValueRange(mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll);
1664 valueWithCalculation.setCalculation(parseCalculation(valueWithCalculation, mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll));
1665 calculation = valueWithCalculation.calculation();
1670 bool isValid = false;
1671 switch (calculation->category()) {
1673 isValid = (unitFlags & FNumber);
1674 if (!isValid && (unitFlags & FInteger) && calculation->isInt())
1676 if (!isValid && (unitFlags & FPositiveInteger) && calculation->isInt() && calculation->isPositive())
1680 isValid = (unitFlags & FLength);
1683 isValid = (unitFlags & FPercent);
1685 case CalcPercentLength:
1686 isValid = (unitFlags & FPercent) && (unitFlags & FLength);
1688 case CalcPercentNumber:
1689 isValid = (unitFlags & FPercent) && (unitFlags & FNumber);
1692 isValid = (unitFlags & FAngle);
1695 isValid = (unitFlags & FTime);
1698 isValid = (unitFlags & FFrequency);
1707 inline bool CSSParser::shouldAcceptUnitLessValues(CSSParserValue& value, Units unitFlags, CSSParserMode cssParserMode)
1709 // Qirks mode and svg presentation attributes accept unit less values.
1710 return (unitFlags & (FLength | FAngle | FTime)) && (!value.fValue || cssParserMode == CSSQuirksMode || cssParserMode == SVGAttributeMode);
1713 bool CSSParser::validateUnit(ValueWithCalculation& valueWithCalculation, Units unitFlags, CSSParserMode cssParserMode)
1715 if (isCalculation(valueWithCalculation))
1716 return validateCalculationUnit(valueWithCalculation, unitFlags);
1719 switch (valueWithCalculation.value().unit) {
1720 case CSSPrimitiveValue::CSS_NUMBER:
1721 b = (unitFlags & FNumber);
1722 if (!b && shouldAcceptUnitLessValues(valueWithCalculation, unitFlags, cssParserMode)) {
1723 valueWithCalculation.value().unit = (unitFlags & FLength) ? CSSPrimitiveValue::CSS_PX :
1724 ((unitFlags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS);
1727 if (!b && (unitFlags & FInteger) && valueWithCalculation.value().isInt)
1729 if (!b && (unitFlags & FPositiveInteger) && valueWithCalculation.value().isInt && valueWithCalculation.value().fValue > 0)
1732 case CSSPrimitiveValue::CSS_PERCENTAGE:
1733 b = (unitFlags & FPercent);
1735 case CSSParserValue::Q_EMS:
1736 case CSSPrimitiveValue::CSS_EMS:
1737 case CSSPrimitiveValue::CSS_REMS:
1738 case CSSPrimitiveValue::CSS_CHS:
1739 case CSSPrimitiveValue::CSS_EXS:
1740 case CSSPrimitiveValue::CSS_PX:
1741 case CSSPrimitiveValue::CSS_CM:
1742 case CSSPrimitiveValue::CSS_MM:
1743 case CSSPrimitiveValue::CSS_IN:
1744 case CSSPrimitiveValue::CSS_PT:
1745 case CSSPrimitiveValue::CSS_PC:
1746 case CSSPrimitiveValue::CSS_VW:
1747 case CSSPrimitiveValue::CSS_VH:
1748 case CSSPrimitiveValue::CSS_VMIN:
1749 case CSSPrimitiveValue::CSS_VMAX:
1750 b = (unitFlags & FLength);
1752 case CSSPrimitiveValue::CSS_MS:
1753 case CSSPrimitiveValue::CSS_S:
1754 b = (unitFlags & FTime);
1756 case CSSPrimitiveValue::CSS_DEG:
1757 case CSSPrimitiveValue::CSS_RAD:
1758 case CSSPrimitiveValue::CSS_GRAD:
1759 case CSSPrimitiveValue::CSS_TURN:
1760 b = (unitFlags & FAngle);
1762 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1763 case CSSPrimitiveValue::CSS_DPPX:
1764 case CSSPrimitiveValue::CSS_DPI:
1765 case CSSPrimitiveValue::CSS_DPCM:
1766 b = (unitFlags & FResolution);
1769 case CSSPrimitiveValue::CSS_HZ:
1770 case CSSPrimitiveValue::CSS_KHZ:
1771 case CSSPrimitiveValue::CSS_DIMENSION:
1775 if (b && unitFlags & FNonNeg && valueWithCalculation.value().fValue < 0)
1777 if (b && std::isinf(valueWithCalculation.value().fValue))
1782 inline Ref<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(ValueWithCalculation& valueWithCalculation)
1784 if (valueWithCalculation.calculation())
1785 return CSSPrimitiveValue::create(valueWithCalculation.calculation());
1787 CSSParserValue& value = valueWithCalculation;
1788 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1789 ASSERT((value.unit >= CSSPrimitiveValue::CSS_NUMBER && value.unit <= CSSPrimitiveValue::CSS_KHZ)
1790 || (value.unit >= CSSPrimitiveValue::CSS_TURN && value.unit <= CSSPrimitiveValue::CSS_CHS)
1791 || (value.unit >= CSSPrimitiveValue::CSS_VW && value.unit <= CSSPrimitiveValue::CSS_VMAX)
1792 || (value.unit >= CSSPrimitiveValue::CSS_DPPX && value.unit <= CSSPrimitiveValue::CSS_DPCM));
1794 ASSERT((value.unit >= CSSPrimitiveValue::CSS_NUMBER && value.unit <= CSSPrimitiveValue::CSS_KHZ)
1795 || (value.unit >= CSSPrimitiveValue::CSS_TURN && value.unit <= CSSPrimitiveValue::CSS_CHS)
1796 || (value.unit >= CSSPrimitiveValue::CSS_VW && value.unit <= CSSPrimitiveValue::CSS_VMAX));
1798 return cssValuePool().createValue(value.fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value.unit));
1801 inline Ref<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSParserValue& value)
1803 ASSERT(value.unit == CSSPrimitiveValue::CSS_STRING || value.unit == CSSPrimitiveValue::CSS_IDENT);
1804 return cssValuePool().createValue(value.string, CSSPrimitiveValue::CSS_STRING);
1807 static inline bool isComma(CSSParserValue* value)
1809 return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
1812 static inline bool isForwardSlashOperator(CSSParserValue& value)
1814 return value.unit == CSSParserValue::Operator && value.iValue == '/';
1817 bool CSSParser::validateWidth(ValueWithCalculation& valueWithCalculation)
1819 int id = valueWithCalculation.value().id;
1820 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent)
1822 return !id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg);
1825 // FIXME: Combine this with validWidth when we support fit-content, et al, for heights.
1826 bool CSSParser::validateHeight(ValueWithCalculation& valueWithCalculation)
1828 int id = valueWithCalculation.value().id;
1829 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic)
1831 return !id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg);
1834 inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(CSSValueID identifier, ValueWithCalculation& valueWithCalculation)
1837 return cssValuePool().createIdentifierValue(identifier);
1839 if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
1840 return createPrimitiveStringValue(valueWithCalculation);
1841 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_NUMBER && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_KHZ)
1842 return createPrimitiveNumericValue(valueWithCalculation);
1843 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_TURN && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_CHS)
1844 return createPrimitiveNumericValue(valueWithCalculation);
1845 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_VW && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_VMAX)
1846 return createPrimitiveNumericValue(valueWithCalculation);
1847 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1848 if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_DPPX && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_DPCM)
1849 return createPrimitiveNumericValue(valueWithCalculation);
1851 if (valueWithCalculation.value().unit >= CSSParserValue::Q_EMS)
1852 return CSSPrimitiveValue::createAllowingMarginQuirk(valueWithCalculation.value().fValue, CSSPrimitiveValue::CSS_EMS);
1853 if (valueWithCalculation.calculation())
1854 return CSSPrimitiveValue::create(valueWithCalculation.calculation());
1859 void CSSParser::addExpandedPropertyForValue(CSSPropertyID propId, PassRefPtr<CSSValue> prpValue, bool important)
1861 const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
1862 unsigned shorthandLength = shorthand.length();
1863 if (!shorthandLength) {
1864 addProperty(propId, prpValue, important);
1868 RefPtr<CSSValue> value = prpValue;
1869 ShorthandScope scope(this, propId);
1870 const CSSPropertyID* longhands = shorthand.properties();
1871 for (unsigned i = 0; i < shorthandLength; ++i)
1872 addProperty(longhands[i], value, important);
1875 bool CSSParser::parseValue(CSSPropertyID propId, bool important)
1877 if (!m_valueList || !m_valueList->current())
1880 ValueWithCalculation valueWithCalculation(*m_valueList->current());
1881 CSSValueID id = valueWithCalculation.value().id;
1883 unsigned num = inShorthand() ? 1 : m_valueList->size();
1885 if (id == CSSValueInherit) {
1888 addExpandedPropertyForValue(propId, cssValuePool().createInheritedValue(), important);
1891 else if (id == CSSValueInitial) {
1894 addExpandedPropertyForValue(propId, cssValuePool().createExplicitInitialValue(), important);
1898 if (isKeywordPropertyID(propId)) {
1899 if (!isValidKeywordPropertyAndValue(propId, id, m_context, m_styleSheet))
1901 if (m_valueList->next() && !inShorthand())
1903 addProperty(propId, cssValuePool().createIdentifierValue(id), important);
1907 #if ENABLE(CSS_DEVICE_ADAPTATION)
1909 return parseViewportProperty(propId, important);
1912 bool validPrimitive = false;
1913 RefPtr<CSSValue> parsedValue;
1916 case CSSPropertySize: // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
1917 return parseSize(propId, important);
1919 case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit
1920 if (id == CSSValueNone)
1921 validPrimitive = true;
1923 return parseQuotes(propId, important);
1925 case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | isolate | isolate-override | plaintext | inherit
1926 if (id == CSSValueNormal
1927 || id == CSSValueEmbed
1928 || id == CSSValueBidiOverride
1929 || id == CSSValueWebkitIsolate
1930 || id == CSSValueWebkitIsolateOverride
1931 || id == CSSValueWebkitPlaintext)
1932 validPrimitive = true;
1935 case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
1936 // close-quote | no-open-quote | no-close-quote ]+ | inherit
1937 return parseContent(propId, important);
1939 case CSSPropertyAlt: // [ <string> | attr(X) ]
1940 return parseAlt(propId, important);
1942 case CSSPropertyClip: // <shape> | auto | inherit
1943 if (id == CSSValueAuto)
1944 validPrimitive = true;
1945 else if (valueWithCalculation.value().unit == CSSParserValue::Function)
1946 return parseClipShape(propId, important);
1949 /* Start of supported CSS properties with validation. This is needed for parseShorthand to work
1950 * correctly and allows optimization in WebCore::applyRule(..)
1952 case CSSPropertyOverflow: {
1953 ShorthandScope scope(this, propId);
1954 if (num != 1 || !parseValue(CSSPropertyOverflowY, important))
1957 RefPtr<CSSValue> overflowXValue;
1959 // FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. If this value has been
1960 // set using the shorthand, then for now overflow-x will default to auto, but once we implement
1961 // pagination controls, it should default to hidden. If the overflow-y value is anything but
1962 // paged-x or paged-y, then overflow-x and overflow-y should have the same value.
1963 if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
1964 overflowXValue = cssValuePool().createIdentifierValue(CSSValueAuto);
1966 overflowXValue = m_parsedProperties.last().value();
1967 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important);
1971 case CSSPropertyTextAlign:
1972 // left | right | center | justify | -webkit-left | -webkit-right | -webkit-center | -webkit-match-parent
1973 // | start | end | inherit | -webkit-auto (converted to start)
1974 // NOTE: <string> is not supported.
1975 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd)
1976 validPrimitive = true;
1979 case CSSPropertyFontWeight: { // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
1980 if (m_valueList->size() != 1)
1982 return parseFontWeight(important);
1985 case CSSPropertyFontSynthesis: // none | [ weight || style ]
1986 return parseFontSynthesis(important);
1988 case CSSPropertyBorderSpacing: {
1990 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1991 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
1993 CSSValue* value = m_parsedProperties.last().value();
1994 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important);
1997 else if (num == 2) {
1998 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1999 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important) || !parseValue(CSSPropertyWebkitBorderVerticalSpacing, important))
2005 case CSSPropertyWebkitBorderHorizontalSpacing:
2006 case CSSPropertyWebkitBorderVerticalSpacing:
2007 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2009 case CSSPropertyOutlineColor: // <color> | invert | inherit
2010 // Outline color has "invert" as additional keyword.
2011 // Also, we want to allow the special focus color even in strict parsing mode.
2012 if (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor) {
2013 validPrimitive = true;
2017 case CSSPropertyBackgroundColor: // <color> | inherit
2018 case CSSPropertyBorderTopColor: // <color> | inherit
2019 case CSSPropertyBorderRightColor:
2020 case CSSPropertyBorderBottomColor:
2021 case CSSPropertyBorderLeftColor:
2022 case CSSPropertyWebkitBorderStartColor:
2023 case CSSPropertyWebkitBorderEndColor:
2024 case CSSPropertyWebkitBorderBeforeColor:
2025 case CSSPropertyWebkitBorderAfterColor:
2026 case CSSPropertyColor: // <color> | inherit
2027 case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors
2028 case CSSPropertyTextUnderlineColor:
2029 case CSSPropertyTextOverlineColor:
2030 case CSSPropertyColumnRuleColor:
2031 case CSSPropertyWebkitTextDecorationColor:
2032 case CSSPropertyWebkitTextEmphasisColor:
2033 case CSSPropertyWebkitTextFillColor:
2034 case CSSPropertyWebkitTextStrokeColor:
2035 if (id == CSSValueWebkitText)
2036 validPrimitive = true; // Always allow this, even when strict parsing is on,
2037 // since we use this in our UA sheets.
2038 else if (id == CSSValueCurrentcolor)
2039 validPrimitive = true;
2040 else if (isValidSystemColorValue(id) || id == CSSValueMenu
2041 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2042 validPrimitive = true;
2044 parsedValue = parseColor();
2046 m_valueList->next();
2050 case CSSPropertyCursor: {
2051 // Grammar defined by CSS3 UI and modified by CSS4 images:
2052 // [ [<image> [<x> <y>]?,]*
2053 // [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |
2054 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize |
2055 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help |
2056 // vertical-text | cell | context-menu | alias | copy | no-drop | not-allowed |
2057 // zoom-in | zoom-out | all-scroll | -webkit-grab | -webkit-grabbing | -webkit-zoom-in |
2058 // -webkit-zoom-out ] ] | inherit
2059 RefPtr<CSSValueList> list;
2060 CSSParserValue* value = &valueWithCalculation.value();
2062 RefPtr<CSSValue> image;
2063 if (value->unit == CSSPrimitiveValue::CSS_URI) {
2064 String uri = value->string;
2066 image = CSSImageValue::create(completeURL(uri));
2067 #if ENABLE(CSS_IMAGE_SET) && ENABLE(MOUSE_CURSOR_SCALE)
2068 } else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
2069 image = parseImageSet();
2077 value = m_valueList->next();
2078 while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
2079 coords.append(int(value->fValue));
2080 value = m_valueList->next();
2082 bool hasHotSpot = false;
2083 IntPoint hotSpot(-1, -1);
2084 int nrcoords = coords.size();
2085 if (nrcoords > 0 && nrcoords != 2)
2087 if (nrcoords == 2) {
2089 hotSpot = IntPoint(coords[0], coords[1]);
2093 list = CSSValueList::createCommaSeparated();
2096 list->append(CSSCursorImageValue::create(image.releaseNonNull(), hasHotSpot, hotSpot));
2098 if ((inStrictMode() && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ',')))
2100 value = m_valueList->next(); // comma
2104 // no value after url list (MSIE 5 compatibility)
2105 if (list->length() != 1)
2107 } else if (inQuirksMode() && value->id == CSSValueHand) // MSIE 5 compatibility :/
2108 list->append(cssValuePool().createIdentifierValue(CSSValuePointer));
2109 else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitZoomOut) || value->id == CSSValueCopy || value->id == CSSValueNone)
2110 list->append(cssValuePool().createIdentifierValue(value->id));
2111 m_valueList->next();
2112 parsedValue = list.release();
2116 if (inQuirksMode() && value->id == CSSValueHand) {
2117 // MSIE 5 compatibility :/
2118 id = CSSValuePointer;
2119 validPrimitive = true;
2120 } else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitZoomOut) || value->id == CSSValueCopy || value->id == CSSValueNone)
2121 validPrimitive = true;
2123 ASSERT_NOT_REACHED();
2129 #if ENABLE(CURSOR_VISIBILITY)
2130 case CSSPropertyWebkitCursorVisibility:
2131 if (id == CSSValueAuto || id == CSSValueAutoHide)
2132 validPrimitive = true;
2136 case CSSPropertyBackgroundAttachment:
2137 case CSSPropertyBackgroundBlendMode:
2138 case CSSPropertyBackgroundClip:
2139 case CSSPropertyWebkitBackgroundClip:
2140 case CSSPropertyWebkitBackgroundComposite:
2141 case CSSPropertyBackgroundImage:
2142 case CSSPropertyBackgroundOrigin:
2143 case CSSPropertyWebkitBackgroundOrigin:
2144 case CSSPropertyBackgroundPosition:
2145 case CSSPropertyBackgroundPositionX:
2146 case CSSPropertyBackgroundPositionY:
2147 case CSSPropertyBackgroundSize:
2148 case CSSPropertyWebkitBackgroundSize:
2149 case CSSPropertyBackgroundRepeat:
2150 case CSSPropertyBackgroundRepeatX:
2151 case CSSPropertyBackgroundRepeatY:
2152 case CSSPropertyWebkitMaskClip:
2153 case CSSPropertyWebkitMaskComposite:
2154 case CSSPropertyWebkitMaskImage:
2155 case CSSPropertyWebkitMaskOrigin:
2156 case CSSPropertyWebkitMaskPosition:
2157 case CSSPropertyWebkitMaskPositionX:
2158 case CSSPropertyWebkitMaskPositionY:
2159 case CSSPropertyWebkitMaskSize:
2160 case CSSPropertyWebkitMaskSourceType:
2161 case CSSPropertyWebkitMaskRepeat:
2162 case CSSPropertyWebkitMaskRepeatX:
2163 case CSSPropertyWebkitMaskRepeatY:
2165 RefPtr<CSSValue> val1;
2166 RefPtr<CSSValue> val2;
2167 CSSPropertyID propId1, propId2;
2168 bool result = false;
2169 if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
2170 std::unique_ptr<ShorthandScope> shorthandScope;
2171 if (propId == CSSPropertyBackgroundPosition ||
2172 propId == CSSPropertyBackgroundRepeat ||
2173 propId == CSSPropertyWebkitMaskPosition ||
2174 propId == CSSPropertyWebkitMaskRepeat) {
2175 shorthandScope = std::make_unique<ShorthandScope>(this, propId);
2177 addProperty(propId1, val1.release(), important);
2179 addProperty(propId2, val2.release(), important);
2182 m_implicitShorthand = false;
2185 case CSSPropertyListStyleImage: // <uri> | none | inherit
2186 case CSSPropertyBorderImageSource:
2187 case CSSPropertyWebkitMaskBoxImageSource:
2188 if (id == CSSValueNone) {
2189 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone);
2190 m_valueList->next();
2191 } else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_URI) {
2192 parsedValue = CSSImageValue::create(completeURL(valueWithCalculation.value().string));
2193 m_valueList->next();
2194 } else if (isGeneratedImageValue(valueWithCalculation)) {
2195 if (parseGeneratedImage(*m_valueList, parsedValue))
2196 m_valueList->next();
2200 #if ENABLE(CSS_IMAGE_SET)
2201 else if (valueWithCalculation.value().unit == CSSParserValue::Function && equalIgnoringCase(valueWithCalculation.value().function->name, "-webkit-image-set(")) {
2202 parsedValue = parseImageSet();
2205 m_valueList->next();
2210 case CSSPropertyWebkitTextStrokeWidth:
2211 case CSSPropertyOutlineWidth: // <border-width> | inherit
2212 case CSSPropertyBorderTopWidth: //// <border-width> | inherit
2213 case CSSPropertyBorderRightWidth: // Which is defined as
2214 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
2215 case CSSPropertyBorderLeftWidth:
2216 case CSSPropertyWebkitBorderStartWidth:
2217 case CSSPropertyWebkitBorderEndWidth:
2218 case CSSPropertyWebkitBorderBeforeWidth:
2219 case CSSPropertyWebkitBorderAfterWidth:
2220 case CSSPropertyColumnRuleWidth:
2221 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
2222 validPrimitive = true;
2224 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2227 case CSSPropertyLetterSpacing: // normal | <length> | inherit
2228 if (id == CSSValueNormal)
2229 validPrimitive = true;
2231 validPrimitive = validateUnit(valueWithCalculation, FLength);
2234 case CSSPropertyWordSpacing: // normal | <length> | <percentage> | inherit
2235 if (id == CSSValueNormal)
2236 validPrimitive = true;
2238 validPrimitive = validateUnit(valueWithCalculation, FLength | FPercent);
2241 case CSSPropertyTextIndent:
2242 parsedValue = parseTextIndent();
2245 case CSSPropertyPaddingTop: //// <padding-width> | inherit
2246 case CSSPropertyPaddingRight: // Which is defined as
2247 case CSSPropertyPaddingBottom: // <length> | <percentage>
2248 case CSSPropertyPaddingLeft: ////
2249 case CSSPropertyWebkitPaddingStart:
2250 case CSSPropertyWebkitPaddingEnd:
2251 case CSSPropertyWebkitPaddingBefore:
2252 case CSSPropertyWebkitPaddingAfter:
2253 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg));
2256 case CSSPropertyMaxWidth:
2257 case CSSPropertyWebkitMaxLogicalWidth:
2258 validPrimitive = (id == CSSValueNone || validateWidth(valueWithCalculation));
2261 case CSSPropertyMinWidth:
2262 case CSSPropertyWebkitMinLogicalWidth:
2263 validPrimitive = validateWidth(valueWithCalculation);
2266 case CSSPropertyWidth:
2267 case CSSPropertyWebkitLogicalWidth:
2268 validPrimitive = (id == CSSValueAuto || validateWidth(valueWithCalculation));
2271 case CSSPropertyMaxHeight:
2272 case CSSPropertyWebkitMaxLogicalHeight:
2273 validPrimitive = (id == CSSValueNone || validateHeight(valueWithCalculation));
2276 case CSSPropertyMinHeight:
2277 case CSSPropertyWebkitMinLogicalHeight:
2278 validPrimitive = validateHeight(valueWithCalculation);
2281 case CSSPropertyHeight:
2282 case CSSPropertyWebkitLogicalHeight:
2283 validPrimitive = (id == CSSValueAuto || validateHeight(valueWithCalculation));
2286 case CSSPropertyFontSize:
2287 return parseFontSize(important);
2289 case CSSPropertyFontVariant: // normal | small-caps | inherit
2290 return parseFontVariant(important);
2292 case CSSPropertyVerticalAlign:
2293 // baseline | sub | super | top | text-top | middle | bottom | text-bottom |
2294 // <percentage> | <length> | inherit
2296 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
2297 validPrimitive = true;
2299 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent));
2302 case CSSPropertyBottom: // <length> | <percentage> | auto | inherit
2303 case CSSPropertyLeft: // <length> | <percentage> | auto | inherit
2304 case CSSPropertyRight: // <length> | <percentage> | auto | inherit
2305 case CSSPropertyTop: // <length> | <percentage> | auto | inherit
2306 case CSSPropertyMarginTop: //// <margin-width> | inherit
2307 case CSSPropertyMarginRight: // Which is defined as
2308 case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit
2309 case CSSPropertyMarginLeft: ////
2310 case CSSPropertyWebkitMarginStart:
2311 case CSSPropertyWebkitMarginEnd:
2312 case CSSPropertyWebkitMarginBefore:
2313 case CSSPropertyWebkitMarginAfter:
2314 if (id == CSSValueAuto)
2315 validPrimitive = true;
2317 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent));
2320 case CSSPropertyZIndex: // auto | <integer> | inherit
2321 if (id == CSSValueAuto)
2322 validPrimitive = true;
2324 validPrimitive = (!id && validateUnit(valueWithCalculation, FInteger, CSSQuirksMode));
2327 case CSSPropertyOrphans: // <integer> | inherit | auto (We've added support for auto for backwards compatibility)
2328 case CSSPropertyWidows: // <integer> | inherit | auto (Ditto)
2329 if (id == CSSValueAuto)
2330 validPrimitive = true;
2332 validPrimitive = (!id && validateUnit(valueWithCalculation, FPositiveInteger, CSSQuirksMode));
2335 case CSSPropertyLineHeight:
2336 return parseLineHeight(important);
2337 case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit
2338 if (id != CSSValueNone)
2339 return parseCounter(propId, 1, important);
2340 validPrimitive = true;
2342 case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit
2343 if (id != CSSValueNone)
2344 return parseCounter(propId, 0, important);
2345 validPrimitive = true;
2347 case CSSPropertyFontFamily:
2348 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit
2350 parsedValue = parseFontFamily();
2354 case CSSPropertyWebkitTextDecoration:
2355 // [ <text-decoration-line> || <text-decoration-style> || <text-decoration-color> ] | inherit
2356 return parseShorthand(CSSPropertyWebkitTextDecoration, webkitTextDecorationShorthand(), important);
2358 case CSSPropertyTextDecoration:
2359 case CSSPropertyWebkitTextDecorationsInEffect:
2360 case CSSPropertyWebkitTextDecorationLine:
2361 // none | [ underline || overline || line-through || blink ] | inherit
2362 return parseTextDecoration(propId, important);
2364 case CSSPropertyWebkitTextDecorationStyle:
2365 // solid | double | dotted | dashed | wavy
2366 if (id == CSSValueSolid || id == CSSValueDouble || id == CSSValueDotted || id == CSSValueDashed || id == CSSValueWavy)
2367 validPrimitive = true;
2370 case CSSPropertyWebkitTextDecorationSkip:
2371 // none | [ objects || spaces || ink || edges || box-decoration ]
2372 return parseTextDecorationSkip(important);
2374 case CSSPropertyWebkitTextUnderlinePosition:
2375 // auto | alphabetic | under
2376 return parseTextUnderlinePosition(important);
2378 case CSSPropertyZoom: // normal | reset | document | <number> | <percentage> | inherit
2379 if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument)
2380 validPrimitive = true;
2382 validPrimitive = (!id && validateUnit(valueWithCalculation, FNumber | FPercent | FNonNeg, CSSStrictMode));
2385 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.
2386 return parseFontFaceSrc();
2388 case CSSPropertyUnicodeRange:
2389 return parseFontFaceUnicodeRange();
2391 /* CSS3 properties */
2393 case CSSPropertyBorderImage: {
2394 RefPtr<CSSValue> result;
2395 return parseBorderImage(propId, result, important);
2397 case CSSPropertyWebkitBorderImage:
2398 case CSSPropertyWebkitMaskBoxImage: {
2399 RefPtr<CSSValue> result;
2400 if (parseBorderImage(propId, result)) {
2401 addProperty(propId, result, important);
2406 case CSSPropertyBorderImageOutset:
2407 case CSSPropertyWebkitMaskBoxImageOutset: {
2408 RefPtr<CSSPrimitiveValue> result;
2409 if (parseBorderImageOutset(result)) {
2410 addProperty(propId, result, important);
2415 case CSSPropertyBorderImageRepeat:
2416 case CSSPropertyWebkitMaskBoxImageRepeat: {
2417 RefPtr<CSSValue> result;
2418 if (parseBorderImageRepeat(result)) {
2419 addProperty(propId, result, important);
2424 case CSSPropertyBorderImageSlice:
2425 case CSSPropertyWebkitMaskBoxImageSlice: {
2426 RefPtr<CSSBorderImageSliceValue> result;
2427 if (parseBorderImageSlice(propId, result)) {
2428 addProperty(propId, result, important);
2433 case CSSPropertyBorderImageWidth:
2434 case CSSPropertyWebkitMaskBoxImageWidth: {
2435 RefPtr<CSSPrimitiveValue> result;
2436 if (parseBorderImageWidth(result)) {
2437 addProperty(propId, result, important);
2442 case CSSPropertyBorderTopRightRadius:
2443 case CSSPropertyBorderTopLeftRadius:
2444 case CSSPropertyBorderBottomLeftRadius:
2445 case CSSPropertyBorderBottomRightRadius: {
2446 if (num != 1 && num != 2)
2448 validPrimitive = validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg);
2449 if (!validPrimitive)
2451 RefPtr<CSSPrimitiveValue> parsedValue1 = createPrimitiveNumericValue(valueWithCalculation);
2452 RefPtr<CSSPrimitiveValue> parsedValue2;
2454 ValueWithCalculation nextValueWithCalculation(*m_valueList->next());
2455 validPrimitive = validateUnit(nextValueWithCalculation, FLength | FPercent | FNonNeg);
2456 if (!validPrimitive)
2458 parsedValue2 = createPrimitiveNumericValue(nextValueWithCalculation);
2460 parsedValue2 = parsedValue1;
2462 addProperty(propId, createPrimitiveValuePair(parsedValue1.release(), parsedValue2.release()), important);
2465 case CSSPropertyTabSize:
2466 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg);
2468 case CSSPropertyWebkitAspectRatio:
2469 return parseAspectRatio(important);
2470 case CSSPropertyBorderRadius:
2471 case CSSPropertyWebkitBorderRadius:
2472 return parseBorderRadius(propId, important);
2473 case CSSPropertyOutlineOffset:
2474 validPrimitive = validateUnit(valueWithCalculation, FLength);
2476 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
2477 case CSSPropertyBoxShadow:
2478 case CSSPropertyWebkitBoxShadow:
2479 if (id == CSSValueNone)
2480 validPrimitive = true;
2482 RefPtr<CSSValueList> shadowValueList = parseShadow(*m_valueList, propId);
2483 if (shadowValueList) {
2484 addProperty(propId, shadowValueList.release(), important);
2485 m_valueList->next();
2491 case CSSPropertyWebkitInitialLetter: {
2492 if (id == CSSValueNormal)
2493 validPrimitive = true;
2495 if (num != 1 && num != 2)
2497 validPrimitive = validateUnit(valueWithCalculation, FPositiveInteger);
2498 if (!validPrimitive)
2500 RefPtr<CSSPrimitiveValue> parsedValue1 = createPrimitiveNumericValue(valueWithCalculation);
2501 RefPtr<CSSPrimitiveValue> parsedValue2;
2503 ValueWithCalculation nextValueWithCalculation(*m_valueList->next());
2504 validPrimitive = validateUnit(nextValueWithCalculation, FPositiveInteger);
2505 if (!validPrimitive)
2507 parsedValue2 = createPrimitiveNumericValue(nextValueWithCalculation);
2509 parsedValue2 = parsedValue1;
2510 addProperty(propId, createPrimitiveValuePair(parsedValue1.release(), parsedValue2.release()), important);
2515 case CSSPropertyWebkitBoxReflect:
2516 if (id == CSSValueNone)
2517 validPrimitive = true;
2519 return parseReflect(propId, important);
2521 case CSSPropertyOpacity:
2522 validPrimitive = validateUnit(valueWithCalculation, FNumber);
2524 case CSSPropertyWebkitBoxFlex:
2525 validPrimitive = validateUnit(valueWithCalculation, FNumber);
2527 case CSSPropertyWebkitBoxFlexGroup:
2528 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode);
2530 case CSSPropertyWebkitBoxOrdinalGroup:
2531 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode) && valueWithCalculation.value().fValue;
2533 case CSSPropertyWebkitFilter:
2534 #if ENABLE(FILTERS_LEVEL_2)
2535 case CSSPropertyWebkitBackdropFilter:
2537 if (id == CSSValueNone)
2538 validPrimitive = true;
2540 RefPtr<CSSValue> currValue;
2541 if (!parseFilter(*m_valueList, currValue))
2543 addProperty(propId, currValue, important);
2547 #if ENABLE(CSS_COMPOSITING)
2548 case CSSPropertyMixBlendMode:
2549 if (cssCompositingEnabled())
2550 validPrimitive = true;
2552 case CSSPropertyIsolation:
2553 if (cssCompositingEnabled())
2554 validPrimitive = true;
2557 case CSSPropertyFlex: {
2558 ShorthandScope scope(this, propId);
2559 if (id == CSSValueNone) {
2560 addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2561 addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2562 addProperty(CSSPropertyFlexBasis, cssValuePool().createIdentifierValue(CSSValueAuto), important);
2565 return parseFlex(*m_valueList, important);
2567 case CSSPropertyFlexBasis:
2568 // FIXME: Support intrinsic dimensions too.
2569 if (id == CSSValueAuto)
2570 validPrimitive = true;
2572 validPrimitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg));
2574 case CSSPropertyFlexGrow:
2575 case CSSPropertyFlexShrink:
2576 validPrimitive = validateUnit(valueWithCalculation, FNumber | FNonNeg);
2578 case CSSPropertyOrder:
2579 if (validateUnit(valueWithCalculation, FInteger, CSSStrictMode)) {
2580 // 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.
2581 double result = std::max<double>(std::numeric_limits<int>::min() + 2, parsedDouble(valueWithCalculation));
2582 parsedValue = cssValuePool().createValue(result, CSSPrimitiveValue::CSS_NUMBER);
2583 m_valueList->next();
2586 case CSSPropertyWebkitMarquee:
2587 return parseShorthand(propId, webkitMarqueeShorthand(), important);
2588 case CSSPropertyWebkitMarqueeIncrement:
2589 if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
2590 validPrimitive = true;
2592 validPrimitive = validateUnit(valueWithCalculation, FLength | FPercent);
2594 case CSSPropertyWebkitMarqueeRepetition:
2595 if (id == CSSValueInfinite)
2596 validPrimitive = true;
2598 validPrimitive = validateUnit(valueWithCalculation, FInteger | FNonNeg);
2600 case CSSPropertyWebkitMarqueeSpeed:
2601 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
2602 validPrimitive = true;
2604 validPrimitive = validateUnit(valueWithCalculation, FTime | FInteger | FNonNeg);
2606 #if ENABLE(CSS_REGIONS)
2607 case CSSPropertyWebkitFlowInto:
2608 if (!cssRegionsEnabled())
2610 return parseFlowThread(propId, important);
2611 case CSSPropertyWebkitFlowFrom:
2612 if (!cssRegionsEnabled())
2614 return parseRegionThread(propId, important);
2616 case CSSPropertyTransform:
2617 if (id == CSSValueNone)
2618 validPrimitive = true;
2620 RefPtr<CSSValue> transformValue = parseTransform();
2621 if (transformValue) {
2622 addProperty(propId, transformValue.release(), important);
2628 case CSSPropertyTransformOrigin:
2629 case CSSPropertyTransformOriginX:
2630 case CSSPropertyTransformOriginY:
2631 case CSSPropertyTransformOriginZ: {
2632 RefPtr<CSSValue> val1;
2633 RefPtr<CSSValue> val2;
2634 RefPtr<CSSValue> val3;
2635 CSSPropertyID propId1, propId2, propId3;
2636 if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
2637 addProperty(propId1, val1.release(), important);
2639 addProperty(propId2, val2.release(), important);
2641 addProperty(propId3, val3.release(), important);
2646 case CSSPropertyPerspective:
2647 if (id == CSSValueNone)
2648 validPrimitive = true;
2650 // Accepting valueless numbers is a quirk of the -webkit prefixed version of the property.
2651 if (validateUnit(valueWithCalculation, FNumber | FLength | FNonNeg)) {
2652 RefPtr<CSSValue> val = createPrimitiveNumericValue(valueWithCalculation);
2654 addProperty(propId, val.release(), important);
2661 case CSSPropertyPerspectiveOrigin:
2662 case CSSPropertyPerspectiveOriginX:
2663 case CSSPropertyPerspectiveOriginY: {
2664 RefPtr<CSSValue> val1;
2665 RefPtr<CSSValue> val2;
2666 CSSPropertyID propId1, propId2;
2667 if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
2668 addProperty(propId1, val1.release(), important);
2670 addProperty(propId2, val2.release(), important);
2675 case CSSPropertyAnimationDelay:
2676 case CSSPropertyAnimationDirection:
2677 case CSSPropertyAnimationDuration:
2678 case CSSPropertyAnimationFillMode:
2679 case CSSPropertyAnimationName:
2680 case CSSPropertyAnimationPlayState:
2681 case CSSPropertyAnimationIterationCount:
2682 case CSSPropertyAnimationTimingFunction:
2683 case CSSPropertyWebkitAnimationDelay:
2684 case CSSPropertyWebkitAnimationDirection:
2685 case CSSPropertyWebkitAnimationDuration:
2686 case CSSPropertyWebkitAnimationFillMode:
2687 case CSSPropertyWebkitAnimationName:
2688 case CSSPropertyWebkitAnimationPlayState:
2689 case CSSPropertyWebkitAnimationIterationCount:
2690 case CSSPropertyWebkitAnimationTimingFunction:
2691 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
2692 case CSSPropertyWebkitAnimationTrigger:
2694 case CSSPropertyTransitionDelay:
2695 case CSSPropertyTransitionDuration:
2696 case CSSPropertyTransitionTimingFunction:
2697 case CSSPropertyTransitionProperty:
2698 case CSSPropertyWebkitTransitionDelay:
2699 case CSSPropertyWebkitTransitionDuration:
2700 case CSSPropertyWebkitTransitionTimingFunction:
2701 case CSSPropertyWebkitTransitionProperty: {
2702 RefPtr<CSSValue> val;
2703 AnimationParseContext context;
2704 if (parseAnimationProperty(propId, val, context)) {
2705 addPropertyWithPrefixingVariant(propId, val.release(), important);
2710 case CSSPropertyJustifyContent:
2711 parsedValue = parseContentDistributionOverflowPosition();
2713 case CSSPropertyJustifySelf:
2714 return parseItemPositionOverflowPosition(propId, important);
2715 case CSSPropertyJustifyItems:
2716 if (parseLegacyPosition(propId, important))
2718 m_valueList->setCurrentIndex(0);
2719 return parseItemPositionOverflowPosition(propId, important);
2720 #if ENABLE(CSS_GRID_LAYOUT)
2721 case CSSPropertyWebkitGridAutoColumns:
2722 case CSSPropertyWebkitGridAutoRows:
2723 parsedValue = parseGridTrackSize(*m_valueList);
2726 case CSSPropertyWebkitGridTemplateColumns:
2727 case CSSPropertyWebkitGridTemplateRows:
2728 parsedValue = parseGridTrackList();
2731 case CSSPropertyWebkitGridColumnStart:
2732 case CSSPropertyWebkitGridColumnEnd:
2733 case CSSPropertyWebkitGridRowStart:
2734 case CSSPropertyWebkitGridRowEnd:
2735 parsedValue = parseGridPosition();
2738 case CSSPropertyWebkitGridColumn:
2739 case CSSPropertyWebkitGridRow: {
2740 return parseGridItemPositionShorthand(propId, important);
2743 case CSSPropertyWebkitGridTemplate:
2744 return parseGridTemplateShorthand(important);
2746 case CSSPropertyWebkitGrid:
2747 return parseGridShorthand(important);
2749 case CSSPropertyWebkitGridArea:
2750 return parseGridAreaShorthand(important);
2752 case CSSPropertyWebkitGridTemplateAreas:
2753 parsedValue = parseGridTemplateAreas();
2755 case CSSPropertyWebkitGridAutoFlow:
2756 parsedValue = parseGridAutoFlow(*m_valueList);
2758 #endif /* ENABLE(CSS_GRID_LAYOUT) */
2759 case CSSPropertyWebkitMarginCollapse: {
2761 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2762 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important))
2764 CSSValue* value = m_parsedProperties.last().value();
2765 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
2768 else if (num == 2) {
2769 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2770 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important) || !parseValue(webkitMarginCollapseShorthand().properties()[1], important))
2776 case CSSPropertyTextLineThroughWidth:
2777 case CSSPropertyTextOverlineWidth:
2778 case CSSPropertyTextUnderlineWidth:
2779 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
2780 id == CSSValueMedium || id == CSSValueThick)
2781 validPrimitive = true;
2783 validPrimitive = !id && validateUnit(valueWithCalculation, FNumber | FLength | FPercent);
2785 case CSSPropertyColumnCount:
2786 parsedValue = parseColumnCount();
2788 case CSSPropertyColumnGap: // normal | <length>
2789 if (id == CSSValueNormal)
2790 validPrimitive = true;
2792 validPrimitive = validateUnit(valueWithCalculation, FLength | FNonNeg);
2794 case CSSPropertyWebkitColumnAxis:
2795 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto)
2796 validPrimitive = true;
2798 case CSSPropertyColumnProgression:
2799 if (id == CSSValueNormal || id == CSSValueReverse)
2800 validPrimitive = true;
2802 case CSSPropertyColumnSpan: // none | all | 1 (will be dropped in the unprefixed property)
2803 if (id == CSSValueAll || id == CSSValueNone)
2804 validPrimitive = true;
2805 else if (validateUnit(valueWithCalculation, FNumber | FNonNeg) && parsedDouble(valueWithCalculation) == 1) {
2806 addProperty(CSSPropertyColumnSpan, cssValuePool().createValue(1, CSSPrimitiveValue::CSS_NUMBER), important);
2810 case CSSPropertyColumnWidth: // auto | <length>
2811 parsedValue = parseColumnWidth();
2813 // End of CSS3 properties
2815 // Apple specific properties. These will never be standardized and are purely to
2816 // support custom WebKit-based Apple applications.
2817 case CSSPropertyWebkitLineClamp:
2818 // When specifying number of lines, don't allow 0 as a valid value
2819 // When specifying either type of unit, require non-negative integers
2820 validPrimitive = (!id && (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_PERCENTAGE || valueWithCalculation.value().fValue) && validateUnit(valueWithCalculation, FInteger | FPercent | FNonNeg, CSSQuirksMode));
2822 #if ENABLE(IOS_TEXT_AUTOSIZING)
2823 case CSSPropertyWebkitTextSizeAdjust:
2824 if (id == CSSValueAuto || id == CSSValueNone)
2825 validPrimitive = true;
2827 // FIXME: Handle multilength case where we allow relative units.
2828 validPrimitive = (!id && validateUnit(valueWithCalculation, FPercent | FNonNeg, CSSStrictMode));
2833 case CSSPropertyWebkitFontSizeDelta: // <length>
2834 validPrimitive = validateUnit(valueWithCalculation, FLength);
2837 case CSSPropertyWebkitHyphenateCharacter:
2838 if (id == CSSValueAuto || valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
2839 validPrimitive = true;
2842 case CSSPropertyWebkitHyphenateLimitBefore:
2843 case CSSPropertyWebkitHyphenateLimitAfter:
2844 if (id == CSSValueAuto || validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode))
2845 validPrimitive = true;
2848 case CSSPropertyWebkitHyphenateLimitLines:
2849 if (id == CSSValueNoLimit || validateUnit(valueWithCalculation, FInteger | FNonNeg, CSSStrictMode))
2850 validPrimitive = true;
2853 case CSSPropertyWebkitLineGrid:
2854 if (id == CSSValueNone)
2855 validPrimitive = true;
2856 else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_IDENT) {
2857 String lineGridValue = String(valueWithCalculation.value().string);
2858 if (!lineGridValue.isEmpty()) {
2859 addProperty(propId, cssValuePool().createValue(lineGridValue, CSSPrimitiveValue::CSS_STRING), important);
2864 case CSSPropertyWebkitLocale:
2865 if (id == CSSValueAuto || valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
2866 validPrimitive = true;
2869 #if ENABLE(DASHBOARD_SUPPORT)
2870 case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region>
2871 if (valueWithCalculation.value().unit == CSSParserValue::Function || id == CSSValueNone)
2872 return parseDashboardRegions(propId, important);
2877 case CSSPropertyWebkitTouchCallout:
2878 if (id == CSSValueDefault || id == CSSValueNone)
2879 validPrimitive = true;
2882 #if ENABLE(TOUCH_EVENTS)
2883 case CSSPropertyWebkitTapHighlightColor:
2884 if (isValidSystemColorValue(id) || id == CSSValueMenu
2885 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2886 validPrimitive = true;
2888 parsedValue = parseColor();
2890 m_valueList->next();
2894 // End Apple-specific properties
2896 /* shorthand properties */
2897 case CSSPropertyBackground: {
2898 // Position must come before color in this array because a plain old "0" is a legal color
2899 // in quirks mode but it's usually the X coordinate of a position.
2900 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
2901 CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin,
2902 CSSPropertyBackgroundClip, CSSPropertyBackgroundColor, CSSPropertyBackgroundSize };
2903 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2905 case CSSPropertyWebkitMask: {
2906 const CSSPropertyID properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskSourceType, CSSPropertyWebkitMaskRepeat,
2907 CSSPropertyWebkitMaskPosition, CSSPropertyWebkitMaskOrigin, CSSPropertyWebkitMaskClip, CSSPropertyWebkitMaskSize };
2908 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2910 case CSSPropertyBorder:
2911 // [ 'border-width' || 'border-style' || <color> ] | inherit
2913 if (parseShorthand(propId, borderAbridgedShorthand(), important)) {
2914 // The CSS3 Borders and Backgrounds specification says that border also resets border-image. It's as
2915 // though a value of none was specified for the image.
2916 addExpandedPropertyForValue(CSSPropertyBorderImage, cssValuePool().createImplicitInitialValue(), important);
2921 case CSSPropertyBorderTop:
2922 // [ 'border-top-width' || 'border-style' || <color> ] | inherit
2923 return parseShorthand(propId, borderTopShorthand(), important);
2924 case CSSPropertyBorderRight:
2925 // [ 'border-right-width' || 'border-style' || <color> ] | inherit
2926 return parseShorthand(propId, borderRightShorthand(), important);
2927 case CSSPropertyBorderBottom:
2928 // [ 'border-bottom-width' || 'border-style' || <color> ] | inherit
2929 return parseShorthand(propId, borderBottomShorthand(), important);
2930 case CSSPropertyBorderLeft:
2931 // [ 'border-left-width' || 'border-style' || <color> ] | inherit
2932 return parseShorthand(propId, borderLeftShorthand(), important);
2933 case CSSPropertyWebkitBorderStart:
2934 return parseShorthand(propId, webkitBorderStartShorthand(), important);
2935 case CSSPropertyWebkitBorderEnd:
2936 return parseShorthand(propId, webkitBorderEndShorthand(), important);
2937 case CSSPropertyWebkitBorderBefore:
2938 return parseShorthand(propId, webkitBorderBeforeShorthand(), important);
2939 case CSSPropertyWebkitBorderAfter:
2940 return parseShorthand(propId, webkitBorderAfterShorthand(), important);
2941 case CSSPropertyOutline:
2942 // [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit
2943 return parseShorthand(propId, outlineShorthand(), important);
2944 case CSSPropertyBorderColor:
2945 // <color>{1,4} | inherit
2946 return parse4Values(propId, borderColorShorthand().properties(), important);
2947 case CSSPropertyBorderWidth:
2948 // <border-width>{1,4} | inherit
2949 return parse4Values(propId, borderWidthShorthand().properties(), important);
2950 case CSSPropertyBorderStyle:
2951 // <border-style>{1,4} | inherit
2952 return parse4Values(propId, borderStyleShorthand().properties(), important);
2953 case CSSPropertyMargin:
2954 // <margin-width>{1,4} | inherit
2955 return parse4Values(propId, marginShorthand().properties(), important);
2956 case CSSPropertyPadding:
2957 // <padding-width>{1,4} | inherit
2958 return parse4Values(propId, paddingShorthand().properties(), important);
2959 case CSSPropertyFlexFlow:
2960 return parseShorthand(propId, flexFlowShorthand(), important);
2961 case CSSPropertyFont:
2962 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
2963 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
2964 if (num == 1 && id >= CSSValueCaption && id <= CSSValueStatusBar) {
2965 parseSystemFont(important);
2968 return parseFont(important);
2969 case CSSPropertyListStyle:
2970 return parseShorthand(propId, listStyleShorthand(), important);
2971 case CSSPropertyColumns:
2972 return parseColumnsShorthand(important);
2973 case CSSPropertyColumnRule:
2974 return parseShorthand(propId, columnRuleShorthand(), important);
2975 case CSSPropertyWebkitTextStroke:
2976 return parseShorthand(propId, webkitTextStrokeShorthand(), important);
2977 case CSSPropertyAnimation:
2978 case CSSPropertyWebkitAnimation:
2979 return parseAnimationShorthand(propId, important);
2980 case CSSPropertyTransition:
2981 case CSSPropertyWebkitTransition:
2982 return parseTransitionShorthand(propId, important);
2983 case CSSPropertyInvalid:
2985 case CSSPropertyPage:
2986 return parsePage(propId, important);
2987 case CSSPropertyFontStretch:
2988 case CSSPropertyTextLineThrough:
2989 case CSSPropertyTextOverline:
2990 case CSSPropertyTextUnderline:
2992 // CSS Text Layout Module Level 3: Vertical writing support
2993 case CSSPropertyWebkitTextEmphasis:
2994 return parseShorthand(propId, webkitTextEmphasisShorthand(), important);
2996 case CSSPropertyWebkitTextEmphasisStyle:
2997 return parseTextEmphasisStyle(important);
2999 case CSSPropertyWebkitTextEmphasisPosition:
3000 return parseTextEmphasisPosition(important);
3002 case CSSPropertyWebkitTextOrientation:
3003 // FIXME: For now just support sideways, sideways-right, upright and vertical-right.
3004 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSValueVerticalRight || id == CSSValueUpright)
3005 validPrimitive = true;
3008 case CSSPropertyWebkitLineBoxContain:
3009 if (id == CSSValueNone)
3010 validPrimitive = true;
3012 return parseLineBoxContain(important);
3014 case CSSPropertyWebkitFontFeatureSettings:
3015 if (id == CSSValueNormal)
3016 validPrimitive = true;
3018 return parseFontFeatureSettings(important);
3021 case CSSPropertyWebkitFontVariantLigatures:
3022 if (id == CSSValueNormal)
3023 validPrimitive = true;
3025 return parseFontVariantLigatures(important);
3027 case CSSPropertyWebkitClipPath:
3028 parsedValue = parseClipPath();
3030 #if ENABLE(CSS_SHAPES)
3031 case CSSPropertyWebkitShapeOutside:
3032 parsedValue = parseShapeProperty(propId);
3034 case CSSPropertyWebkitShapeMargin:
3035 validPrimitive = (RuntimeEnabledFeatures::sharedFeatures().cssShapesEnabled() && !id && validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg));
3037 case CSSPropertyWebkitShapeImageThreshold:
3038 validPrimitive = (RuntimeEnabledFeatures::sharedFeatures().cssShapesEnabled() && !id && validateUnit(valueWithCalculation, FNumber));
3041 #if ENABLE(CSS_IMAGE_ORIENTATION)
3042 case CSSPropertyImageOrientation:
3043 validPrimitive = !id && validateUnit(valueWithCalculation, FAngle);
3046 #if ENABLE(CSS_IMAGE_RESOLUTION)
3047 case CSSPropertyImageResolution:
3048 parsedValue = parseImageResolution();
3051 case CSSPropertyAlignContent:
3052 parsedValue = parseContentDistributionOverflowPosition();
3054 case CSSPropertyAlignSelf:
3055 return parseItemPositionOverflowPosition(propId, important);
3057 case CSSPropertyAlignItems:
3058 return parseItemPositionOverflowPosition(propId, important);
3059 case CSSPropertyBorderBottomStyle:
3060 case CSSPropertyBorderCollapse:
3061 case CSSPropertyBorderLeftStyle:
3062 case CSSPropertyBorderRightStyle:
3063 case CSSPropertyBorderTopStyle:
3064 case CSSPropertyBoxSizing:
3065 case CSSPropertyCaptionSide:
3066 case CSSPropertyClear:
3067 case CSSPropertyDirection:
3068 case CSSPropertyDisplay:
3069 case CSSPropertyEmptyCells:
3070 case CSSPropertyFloat:
3071 case CSSPropertyFontStyle:
3072 case CSSPropertyImageRendering:
3073 case CSSPropertyListStylePosition:
3074 case CSSPropertyListStyleType:
3075 case CSSPropertyObjectFit:
3076 case CSSPropertyOutlineStyle:
3077 case CSSPropertyOverflowWrap:
3078 case CSSPropertyOverflowX:
3079 case CSSPropertyOverflowY:
3080 case CSSPropertyPageBreakAfter:
3081 case CSSPropertyPageBreakBefore:
3082 case CSSPropertyPageBreakInside:
3083 case CSSPropertyPointerEvents:
3084 case CSSPropertyPosition:
3085 case CSSPropertyResize:
3086 case CSSPropertySpeak:
3087 case CSSPropertyTableLayout:
3088 case CSSPropertyTextLineThroughMode:
3089 case CSSPropertyTextLineThroughStyle:
3090 case CSSPropertyTextOverflow:
3091 case CSSPropertyTextOverlineMode:
3092 case CSSPropertyTextOverlineStyle:
3093 case CSSPropertyTextRendering:
3094 case CSSPropertyTextTransform:
3095 case CSSPropertyTextUnderlineMode:
3096 case CSSPropertyTextUnderlineStyle:
3097 case CSSPropertyVisibility:
3098 case CSSPropertyWebkitAppearance:
3099 case CSSPropertyWebkitBackfaceVisibility:
3100 case CSSPropertyWebkitBorderAfterStyle:
3101 case CSSPropertyWebkitBorderBeforeStyle:
3102 case CSSPropertyWebkitBorderEndStyle:
3103 case CSSPropertyWebkitBorderFit:
3104 case CSSPropertyWebkitBorderStartStyle:
3105 case CSSPropertyWebkitBoxAlign:
3106 #if ENABLE(CSS_BOX_DECORATION_BREAK)
3107 case CSSPropertyWebkitBoxDecorationBreak:
3109 case CSSPropertyWebkitBoxDirection:
3110 case CSSPropertyWebkitBoxLines:
3111 case CSSPropertyWebkitBoxOrient:
3112 case CSSPropertyWebkitBoxPack:
3113 case CSSPropertyWebkitColorCorrection:
3114 case CSSPropertyWebkitColumnBreakAfter:
3115 case CSSPropertyWebkitColumnBreakBefore:
3116 case CSSPropertyWebkitColumnBreakInside:
3117 case CSSPropertyColumnFill:
3118 case CSSPropertyColumnRuleStyle:
3119 case CSSPropertyFlexDirection:
3120 case CSSPropertyFlexWrap:
3121 case CSSPropertyWebkitFontKerning:
3122 case CSSPropertyWebkitFontSmoothing:
3123 case CSSPropertyWebkitHyphens:
3124 case CSSPropertyWebkitLineAlign:
3125 case CSSPropertyWebkitLineBreak:
3126 case CSSPropertyWebkitLineSnap:
3127 case CSSPropertyWebkitMarginAfterCollapse:
3128 case CSSPropertyWebkitMarginBeforeCollapse:
3129 case CSSPropertyWebkitMarginBottomCollapse:
3130 case CSSPropertyWebkitMarginTopCollapse:
3131 case CSSPropertyWebkitMarqueeDirection:
3132 case CSSPropertyWebkitMarqueeStyle:
3133 case CSSPropertyWebkitNbspMode:
3134 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
3135 case CSSPropertyWebkitOverflowScrolling:
3137 case CSSPropertyWebkitPrintColorAdjust:
3138 #if ENABLE(CSS_REGIONS)
3139 case CSSPropertyWebkitRegionBreakAfter:
3140 case CSSPropertyWebkitRegionBreakBefore:
3141 case CSSPropertyWebkitRegionBreakInside:
3142 case CSSPropertyWebkitRegionFragment:
3144 case CSSPropertyWebkitRtlOrdering:
3145 case CSSPropertyWebkitRubyPosition:
3146 #if ENABLE(CSS3_TEXT)
3147 case CSSPropertyWebkitTextAlignLast:
3149 case CSSPropertyWebkitTextCombine:
3150 #if ENABLE(CSS3_TEXT)
3151 case CSSPropertyWebkitTextJustify:
3153 case CSSPropertyWebkitTextSecurity:
3154 case CSSPropertyTransformStyle:
3155 case CSSPropertyWebkitTransformStyle:
3156 case CSSPropertyWebkitUserDrag:
3157 case CSSPropertyWebkitUserModify:
3158 case CSSPropertyWebkitUserSelect:
3159 case CSSPropertyWebkitWritingMode:
3160 case CSSPropertyWhiteSpace:
3161 case CSSPropertyWordBreak:
3162 case CSSPropertyWordWrap:
3163 #if ENABLE(CSS_SCROLL_SNAP)
3164 case CSSPropertyWebkitScrollSnapType:
3166 #if ENABLE(CSS_TRAILING_WORD)
3167 case CSSPropertyAppleTrailingWord:
3169 // These properties should be handled before in isValidKeywordPropertyAndValue().
3170 ASSERT_NOT_REACHED();
3172 #if ENABLE(CSS_DEVICE_ADAPTATION)
3173 // Properties bellow are validated inside parseViewportProperty, because we
3174 // check for parser state inViewportScope. We need to invalidate if someone
3175 // adds them outside a @viewport rule.
3176 case CSSPropertyMaxZoom:
3177 case CSSPropertyMinZoom:
3178 case CSSPropertyOrientation:
3179 case CSSPropertyUserZoom:
3180 validPrimitive = false;
3183 #if ENABLE(CSS_SCROLL_SNAP)
3184 case CSSPropertyWebkitScrollSnapPointsX:
3185 case CSSPropertyWebkitScrollSnapPointsY:
3186 if (id == CSSValueElements) {
3187 validPrimitive = true;
3190 return parseNonElementSnapPoints(propId, important);
3191 case CSSPropertyWebkitScrollSnapDestination: // <length>{2}
3192 return parseScrollSnapDestination(propId, important);
3193 case CSSPropertyWebkitScrollSnapCoordinate:
3194 return parseScrollSnapCoordinate(propId, important);
3198 return parseSVGValue(propId, important);
3201 if (validPrimitive) {
3202 parsedValue = parseValidPrimitive(id, valueWithCalculation);
3203 m_valueList->next();
3207 if (!m_valueList->current() || inShorthand()) {
3208 addProperty(propId, parsedValue.release(), important);
3215 void CSSParser::addFillValue(RefPtr<CSSValue>& lval, Ref<CSSValue>&& rval)
3218 lval = WTF::move(rval);
3222 if (lval->isBaseValueList()) {
3223 downcast<CSSValueList>(*lval).append(WTF::move(rval));
3227 auto list = CSSValueList::createCommaSeparated();
3228 list.get().append(lval.releaseNonNull());
3229 list.get().append(WTF::move(rval));
3230 lval = WTF::move(list);
3233 static bool isContentDistributionKeyword(CSSValueID id)
3235 return id == CSSValueSpaceBetween || id == CSSValueSpaceAround
3236 || id == CSSValueSpaceEvenly || id == CSSValueStretch;
3239 static bool isContentPositionKeyword(CSSValueID id)
3241 return id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
3242 || id == CSSValueFlexStart || id == CSSValueFlexEnd
3243 || id == CSSValueLeft || id == CSSValueRight;
3246 static inline bool isBaselinePositionKeyword(CSSValueID id)
3248 return id == CSSValueBaseline || id == CSSValueLastBaseline;
3251 static bool isAlignmentOverflowKeyword(CSSValueID id)
3253 return id == CSSValueTrue || id == CSSValueSafe;
3256 static bool isItemPositionKeyword(CSSValueID id)
3258 return id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
3259 || id == CSSValueSelfStart || id == CSSValueSelfEnd || id == CSSValueFlexStart
3260 || id == CSSValueFlexEnd || id == CSSValueLeft || id == CSSValueRight;
3263 bool CSSParser::parseLegacyPosition(CSSPropertyID propId, bool important)
3265 // [ legacy && [ left | right | center ]
3267 CSSParserValue* value = m_valueList->current();
3271 if (value->id == CSSValueLegacy) {
3272 value = m_valueList->next();
3275 if (value->id != CSSValueCenter && value->id != CSSValueLeft && value->id != CSSValueRight)
3277 } else if (value->id == CSSValueCenter || value->id == CSSValueLeft || value->id == CSSValueRight) {
3278 if (!m_valueList->next() || m_valueList->current()->id != CSSValueLegacy)
3283 addProperty(propId, createPrimitiveValuePair(cssValuePool().createIdentifierValue(CSSValueLegacy), cssValuePool().createIdentifierValue(value->id)), important);
3284 return !m_valueList->next();
3287 PassRefPtr<CSSValue> CSSParser::parseContentDistributionOverflowPosition()
3289 // auto | <baseline-position> | <content-distribution> || [ <overflow-position>? && <content-position> ]
3290 // <baseline-position> = baseline | last-baseline;
3291 // <content-distribution> = space-between | space-around | space-evenly | stretch;
3292 // <content-position> = center | start | end | flex-start | flex-end | left | right;
3293 // <overflow-position> = true | safe
3295 CSSParserValue* value = m_valueList->current();
3299 // auto | <baseline-position>
3300 if (value->id == CSSValueAuto || isBaselinePositionKeyword(value->id)) {
3301 m_valueList->next();
3302 return CSSContentDistributionValue::create(CSSValueInvalid, value->id, CSSValueInvalid);
3305 CSSValueID distribution = CSSValueInvalid;
3306 CSSValueID position = CSSValueInvalid;
3307 CSSValueID overflow = CSSValueInvalid;
3309 if (isContentDistributionKeyword(value->id)) {
3310 if (distribution != CSSValueInvalid)
3312 distribution = value->id;
3313 } else if (isContentPositionKeyword(value->id)) {
3314 if (position != CSSValueInvalid)
3316 position = value->id;
3317 } else if (isAlignmentOverflowKeyword(value->id)) {
3318 if (overflow != CSSValueInvalid)
3320 overflow = value->id;
3323 value = m_valueList->next();
3326 // The grammar states that we should have at least <content-distribution> or
3327 // <content-position> ( <content-distribution> || <content-position> ).
3328 if (position == CSSValueInvalid && distribution == CSSValueInvalid)
3331 // The grammar states that <overflow-position> must be associated to <content-position>.
3332 if (overflow != CSSValueInvalid && position == CSSValueInvalid)
3335 return CSSContentDistributionValue::create(distribution, position, overflow);
3338 bool CSSParser::parseItemPositionOverflowPosition(CSSPropertyID propId, bool important)
3340 // auto | stretch | <baseline-position> | [<item-position> && <overflow-position>? ]
3341 // <baseline-position> = baseline | last-baseline;
3342 // <item-position> = center | start | end | self-start | self-end | flex-start | flex-end | left | right;
3343 // <overflow-position> = true | safe
3345 CSSParserValue* value = m_valueList->current();
3349 if (value->id == CSSValueAuto || value->id == CSSValueStretch || isBaselinePositionKeyword(value->id)) {
3350 if (m_valueList->next())
3353 addProperty(propId, cssValuePool().createIdentifierValue(value->id), important);
3357 RefPtr<CSSPrimitiveValue> position;
3358 RefPtr<CSSPrimitiveValue> overflowAlignmentKeyword;
3359 if (isItemPositionKeyword(value->id)) {
3360 position = cssValuePool().createIdentifierValue(value->id);
3361 value = m_valueList->next();
3363 if (value->id != CSSValueTrue && value->id != CSSValueSafe)
3365 overflowAlignmentKeyword = cssValuePool().createIdentifierValue(value->id);
3367 } else if (isAlignmentOverflowKeyword(value->id)) {
3368 overflowAlignmentKeyword = cssValuePool().createIdentifierValue(value->id);
3369 value = m_valueList->next();
3370 if (value && isItemPositionKeyword(value->id))
3371 position = cssValuePool().createIdentifierValue(value->id);
3377 if (m_valueList->next())
3381 if (overflowAlignmentKeyword)
3382 addProperty(propId, createPrimitiveValuePair(position.release(), overflowAlignmentKeyword.release()), important);
3384 addProperty(propId, position.release(), important);
3389 static bool parseBackgroundClip(CSSParserValue& parserValue, RefPtr<CSSValue>& cssValue)
3391 if (parserValue.id == CSSValueBorderBox || parserValue.id == CSSValuePaddingBox
3392 || parserValue.id == CSSValueContentBox || parserValue.id == CSSValueWebkitText) {
3393 cssValue = cssValuePool().createIdentifierValue(parserValue.id);
3399 bool CSSParser::useLegacyBackgroundSizeShorthandBehavior() const
3401 return m_context.useLegacyBackgroundSizeShorthandBehavior;
3404 #if ENABLE(CSS_SCROLL_SNAP)
3405 bool CSSParser::parseNonElementSnapPoints(CSSPropertyID propId, bool important)
3407 RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
3408 while (CSSParserValue* value = m_valueList->current()) {
3409 ValueWithCalculation valueWithCalculation(*value);
3410 if (validateUnit(valueWithCalculation, FPercent | FLength))
3411 values->append(createPrimitiveNumericValue(valueWithCalculation));
3412 else if (value->unit == CSSParserValue::Function
3413 && value->function->args
3414 && value->function->args->size() == 1
3415 && equalIgnoringCase(value->function->name, "repeat(")) {
3416 ValueWithCalculation argumentWithCalculation(*value->function->args.get()->current());
3417 if (validateUnit(argumentWithCalculation, FLength | FPercent)) {
3418 values->append(cssValuePool().createValue(LengthRepeat::create(createPrimitiveNumericValue(argumentWithCalculation))));
3419 m_valueList->next();
3420 if (m_valueList->current())
3426 m_valueList->next();
3428 if (values->length()) {
3429 addProperty(propId, values.release(), important);
3430 m_valueList->next();
3436 bool CSSParser::parseScrollSnapPositions(RefPtr<CSSValue>& cssValueX, RefPtr<CSSValue>& cssValueY)