2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 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.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
28 #include "CSSParser.h"
30 #include "CSSAspectRatioValue.h"
31 #include "CSSBasicShapes.h"
32 #include "CSSBorderImage.h"
33 #include "CSSCanvasValue.h"
34 #include "CSSCrossfadeValue.h"
35 #include "CSSCursorImageValue.h"
36 #include "CSSFilterImageValue.h"
37 #include "CSSFontFaceRule.h"
38 #include "CSSFontFaceSrcValue.h"
39 #include "CSSFontFeatureValue.h"
40 #include "CSSFontValue.h"
41 #include "CSSFunctionValue.h"
42 #include "CSSGradientValue.h"
43 #include "CSSImageValue.h"
44 #include "CSSInheritedValue.h"
45 #include "CSSInitialValue.h"
46 #include "CSSLineBoxContainValue.h"
47 #include "CSSMediaRule.h"
48 #include "CSSPageRule.h"
49 #include "CSSPrimitiveValue.h"
50 #include "CSSPropertySourceData.h"
51 #include "CSSReflectValue.h"
52 #include "CSSSelector.h"
53 #include "CSSShadowValue.h"
54 #include "CSSStyleSheet.h"
55 #include "CSSTimingFunctionValue.h"
56 #include "CSSUnicodeRangeValue.h"
57 #include "CSSValueKeywords.h"
58 #include "CSSValueList.h"
59 #include "CSSValuePool.h"
62 #include "FloatConversion.h"
63 #include "HTMLParserIdioms.h"
64 #include "HashTools.h"
65 #include "HistogramSupport.h"
66 #include "MediaList.h"
67 #include "MediaQueryExp.h"
69 #include "PageConsole.h"
72 #include "RenderTheme.h"
73 #include "RuntimeEnabledFeatures.h"
74 #include "SVGParserUtilities.h"
76 #include "StyleProperties.h"
77 #include "StylePropertyShorthand.h"
78 #include "StyleRule.h"
79 #include "StyleRuleImport.h"
80 #include "StyleSheetContents.h"
81 #include "TextEncoding.h"
82 #include "WebKitCSSKeyframeRule.h"
83 #include "WebKitCSSKeyframesRule.h"
84 #include "WebKitCSSRegionRule.h"
85 #include "WebKitCSSTransformValue.h"
88 #include <wtf/HexNumber.h>
89 #include <wtf/NeverDestroyed.h>
90 #include <wtf/StdLibExtras.h>
92 #include <wtf/text/StringBuffer.h>
93 #include <wtf/text/StringBuilder.h>
94 #include <wtf/text/StringImpl.h>
96 #if ENABLE(CSS_GRID_LAYOUT)
97 #include "CSSGridLineNamesValue.h"
100 #if ENABLE(CSS_IMAGE_SET)
101 #include "CSSImageSetValue.h"
104 #if ENABLE(CSS_FILTERS)
105 #include "WebKitCSSFilterValue.h"
108 #if ENABLE(DASHBOARD_SUPPORT)
109 #include "DashboardRegion.h"
115 extern int cssyydebug;
118 extern int cssyyparse(WebCore::CSSParser*);
129 class ImplicitScope {
130 WTF_MAKE_NONCOPYABLE(ImplicitScope);
132 ImplicitScope(WebCore::CSSParser* parser, PropertyType propertyType)
135 m_parser->m_implicitShorthand = propertyType == PropertyImplicit;
140 m_parser->m_implicitShorthand = false;
144 WebCore::CSSParser* m_parser;
151 static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX;
152 static const double MAX_SCALE = 1000000;
154 template <unsigned N>
155 static bool equal(const CSSParserString& a, const char (&b)[N])
157 unsigned length = N - 1; // Ignore the trailing null character
158 if (a.length() != length)
161 return a.is8Bit() ? WTF::equal(a.characters8(), reinterpret_cast<const LChar*>(b), length) : WTF::equal(a.characters16(), reinterpret_cast<const LChar*>(b), length);
164 template <unsigned N>
165 static bool equalIgnoringCase(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::equalIgnoringCase(b, a.characters8(), length) : WTF::equalIgnoringCase(b, a.characters16(), length);
174 template <unsigned N>
175 static bool equalIgnoringCase(CSSParserValue* value, const char (&b)[N])
177 ASSERT(value->unit == CSSPrimitiveValue::CSS_IDENT || value->unit == CSSPrimitiveValue::CSS_STRING);
178 return equalIgnoringCase(value->string, b);
181 static bool hasPrefix(const char* string, unsigned length, const char* prefix)
183 for (unsigned i = 0; i < length; ++i) {
186 if (string[i] != prefix[i])
192 static PassRefPtr<CSSPrimitiveValue> createPrimitiveValuePair(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> second)
194 return cssValuePool().createValue(Pair::create(first, second));
197 class AnimationParseContext {
199 AnimationParseContext()
200 : m_animationPropertyKeywordAllowed(true)
201 , m_firstAnimationCommitted(false)
202 , m_hasSeenAnimationPropertyKeyword(false)
206 void commitFirstAnimation()
208 m_firstAnimationCommitted = true;
211 bool hasCommittedFirstAnimation() const
213 return m_firstAnimationCommitted;
216 void commitAnimationPropertyKeyword()
218 m_animationPropertyKeywordAllowed = false;
221 bool animationPropertyKeywordAllowed() const
223 return m_animationPropertyKeywordAllowed;
226 bool hasSeenAnimationPropertyKeyword() const
228 return m_hasSeenAnimationPropertyKeyword;
231 void sawAnimationPropertyKeyword()
233 m_hasSeenAnimationPropertyKeyword = true;
237 bool m_animationPropertyKeywordAllowed;
238 bool m_firstAnimationCommitted;
239 bool m_hasSeenAnimationPropertyKeyword;
242 const CSSParserContext& strictCSSParserContext()
244 static NeverDestroyed<CSSParserContext> strictContext(CSSStrictMode);
245 return strictContext;
248 CSSParserContext::CSSParserContext(CSSParserMode mode, const URL& baseURL)
251 , isHTMLDocument(false)
252 , isCSSRegionsEnabled(false)
253 , isCSSCompositingEnabled(false)
254 #if ENABLE(CSS_GRID_LAYOUT)
255 , isCSSGridLayoutEnabled(false)
257 , needsSiteSpecificQuirks(false)
258 , enforcesCSSMIMETypeInNoQuirksMode(true)
259 , useLegacyBackgroundSizeShorthandBehavior(false)
262 // FIXME: Force the site specific quirk below to work on iOS. Investigating other site specific quirks
263 // to see if we can enable the preference all together is to be handled by:
264 // <rdar://problem/8493309> Investigate Enabling Site Specific Quirks in MobileSafari and UIWebView
265 needsSiteSpecificQuirks = true;
269 CSSParserContext::CSSParserContext(Document& document, const URL& baseURL, const String& charset)
270 : baseURL(baseURL.isNull() ? document.baseURL() : baseURL)
272 , mode(document.inQuirksMode() ? CSSQuirksMode : CSSStrictMode)
273 , isHTMLDocument(document.isHTMLDocument())
274 , isCSSRegionsEnabled(document.cssRegionsEnabled())
275 , isCSSCompositingEnabled(document.cssCompositingEnabled())
276 #if ENABLE(CSS_GRID_LAYOUT)
277 , isCSSGridLayoutEnabled(document.cssGridLayoutEnabled())
279 , needsSiteSpecificQuirks(document.settings() ? document.settings()->needsSiteSpecificQuirks() : false)
280 , enforcesCSSMIMETypeInNoQuirksMode(!document.settings() || document.settings()->enforceCSSMIMETypeInNoQuirksMode())
281 , useLegacyBackgroundSizeShorthandBehavior(document.settings() ? document.settings()->useLegacyBackgroundSizeShorthandBehavior() : false)
284 // FIXME: Force the site specific quirk below to work on iOS. Investigating other site specific quirks
285 // to see if we can enable the preference all together is to be handled by:
286 // <rdar://problem/8493309> Investigate Enabling Site Specific Quirks in MobileSafari and UIWebView
287 needsSiteSpecificQuirks = true;
291 bool operator==(const CSSParserContext& a, const CSSParserContext& b)
293 return a.baseURL == b.baseURL
294 && a.charset == b.charset
296 && a.isHTMLDocument == b.isHTMLDocument
297 && a.isCSSRegionsEnabled == b.isCSSRegionsEnabled
298 && a.isCSSCompositingEnabled == b.isCSSCompositingEnabled
299 #if ENABLE(CSS_GRID_LAYOUT)
300 && a.isCSSGridLayoutEnabled == b.isCSSGridLayoutEnabled
302 && a.needsSiteSpecificQuirks == b.needsSiteSpecificQuirks
303 && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode
304 && a.useLegacyBackgroundSizeShorthandBehavior == b.useLegacyBackgroundSizeShorthandBehavior;
307 CSSParser::CSSParser(const CSSParserContext& context)
310 , m_id(CSSPropertyInvalid)
312 #if ENABLE(CSS3_CONDITIONAL_RULES)
313 , m_supportsCondition(false)
315 , m_selectorListForParseSelector(0)
316 , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES)
317 , m_inParseShorthand(0)
318 , m_currentShorthand(CSSPropertyInvalid)
319 , m_implicitShorthand(false)
320 , m_hasFontFaceOnlyValues(false)
321 , m_hadSyntacticallyValidCSSRule(false)
323 , m_ignoreErrorsInDeclaration(false)
324 , m_defaultNamespace(starAtom)
325 , m_parsedTextPrefixLength(0)
326 , m_propertyRange(UINT_MAX, UINT_MAX)
327 , m_ruleSourceDataResult(0)
328 , m_parsingMode(NormalMode)
329 , m_is8BitSource(false)
330 , m_currentCharacter8(0)
331 , m_currentCharacter16(0)
335 , m_tokenStartLineNumber(0)
336 , m_lastSelectorLineNumber(0)
337 , m_allowImportRules(true)
338 , m_allowNamespaceDeclarations(true)
339 #if ENABLE(CSS_DEVICE_ADAPTATION)
340 , m_inViewport(false)
346 m_tokenStart.ptr8 = 0;
349 CSSParser::~CSSParser()
354 template <typename CharacterType>
355 ALWAYS_INLINE static void makeLower(const CharacterType* input, CharacterType* output, unsigned length)
357 // FIXME: If we need Unicode lowercasing here, then we probably want the real kind
358 // that can potentially change the length of the string rather than the character
359 // by character kind. If we don't need Unicode lowercasing, it would be good to
360 // simplify this function.
362 if (charactersAreAllASCII(input, length)) {
363 // Fast case for all-ASCII.
364 for (unsigned i = 0; i < length; i++)
365 output[i] = toASCIILower(input[i]);
367 for (unsigned i = 0; i < length; i++) {
368 ASSERT(u_tolower(input[i]) <= 0xFFFF);
369 output[i] = u_tolower(input[i]);
374 void CSSParserString::lower()
377 makeLower(characters8(), characters8(), length());
381 makeLower(characters16(), characters16(), length());
384 void CSSParser::setupParser(const char* prefix, unsigned prefixLength, const String& string, const char* suffix, unsigned suffixLength)
386 m_parsedTextPrefixLength = prefixLength;
387 unsigned stringLength = string.length();
388 unsigned length = stringLength + m_parsedTextPrefixLength + suffixLength + 1;
391 if (!stringLength || string.is8Bit()) {
392 m_dataStart8 = std::make_unique<LChar[]>(length);
393 for (unsigned i = 0; i < m_parsedTextPrefixLength; i++)
394 m_dataStart8[i] = prefix[i];
397 memcpy(m_dataStart8.get() + m_parsedTextPrefixLength, string.characters8(), stringLength * sizeof(LChar));
399 unsigned start = m_parsedTextPrefixLength + stringLength;
400 unsigned end = start + suffixLength;
401 for (unsigned i = start; i < end; i++)
402 m_dataStart8[i] = suffix[i - start];
404 m_dataStart8[length - 1] = 0;
406 m_is8BitSource = true;
407 m_currentCharacter8 = m_dataStart8.get();
408 m_currentCharacter16 = 0;
409 setTokenStart<LChar>(m_currentCharacter8);
410 m_lexFunc = &CSSParser::realLex<LChar>;
414 m_dataStart16 = std::make_unique<UChar[]>(length);
415 for (unsigned i = 0; i < m_parsedTextPrefixLength; i++)
416 m_dataStart16[i] = prefix[i];
418 ASSERT(stringLength);
419 memcpy(m_dataStart16.get() + m_parsedTextPrefixLength, string.characters16(), stringLength * sizeof(UChar));
421 unsigned start = m_parsedTextPrefixLength + stringLength;
422 unsigned end = start + suffixLength;
423 for (unsigned i = start; i < end; i++)
424 m_dataStart16[i] = suffix[i - start];
426 m_dataStart16[length - 1] = 0;
428 m_is8BitSource = false;
429 m_currentCharacter8 = 0;
430 m_currentCharacter16 = m_dataStart16.get();
431 setTokenStart<UChar>(m_currentCharacter16);
432 m_lexFunc = &CSSParser::realLex<UChar>;
435 void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, RuleSourceDataList* ruleSourceDataResult, bool logErrors)
437 setStyleSheet(sheet);
438 m_defaultNamespace = starAtom; // Reset the default namespace.
439 if (ruleSourceDataResult)
440 m_currentRuleDataStack = std::make_unique<RuleSourceDataList>();
441 m_ruleSourceDataResult = ruleSourceDataResult;
443 m_logErrors = logErrors && sheet->singleOwnerDocument() && !sheet->baseURL().isEmpty() && sheet->singleOwnerDocument()->page();
444 m_ignoreErrorsInDeclaration = false;
445 m_lineNumber = startLineNumber;
446 setupParser("", string, "");
448 sheet->shrinkToFit();
449 m_currentRuleDataStack.reset();
450 m_ruleSourceDataResult = 0;
452 m_ignoreErrorsInDeclaration = false;
456 PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string)
458 setStyleSheet(sheet);
459 m_allowNamespaceDeclarations = false;
460 setupParser("@-webkit-rule{", string, "} ");
462 return m_rule.release();
465 PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet, const String& string)
467 setStyleSheet(sheet);
468 setupParser("@-webkit-keyframe-rule{ ", string, "} ");
470 return m_keyframe.release();
473 #if ENABLE(CSS3_CONDITIONAL_RULES)
474 bool CSSParser::parseSupportsCondition(const String& string)
476 m_supportsCondition = false;
477 setupParser("@-webkit-supports-condition{ ", string, "} ");
479 return m_supportsCondition;
483 static inline bool isColorPropertyID(CSSPropertyID propertyId)
485 switch (propertyId) {
486 case CSSPropertyColor:
487 case CSSPropertyBackgroundColor:
488 case CSSPropertyBorderBottomColor:
489 case CSSPropertyBorderLeftColor:
490 case CSSPropertyBorderRightColor:
491 case CSSPropertyBorderTopColor:
492 case CSSPropertyOutlineColor:
493 case CSSPropertyTextLineThroughColor:
494 case CSSPropertyTextOverlineColor:
495 case CSSPropertyTextUnderlineColor:
496 case CSSPropertyWebkitBorderAfterColor:
497 case CSSPropertyWebkitBorderBeforeColor:
498 case CSSPropertyWebkitBorderEndColor:
499 case CSSPropertyWebkitBorderStartColor:
500 case CSSPropertyWebkitColumnRuleColor:
501 case CSSPropertyWebkitTextDecorationColor:
502 case CSSPropertyWebkitTextEmphasisColor:
503 case CSSPropertyWebkitTextFillColor:
504 case CSSPropertyWebkitTextStrokeColor:
511 static bool parseColorValue(MutableStyleProperties* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
513 ASSERT(!string.isEmpty());
514 bool strict = isStrictParserMode(cssParserMode);
515 if (!isColorPropertyID(propertyId))
517 CSSParserString cssString;
518 cssString.init(string);
519 CSSValueID valueID = cssValueKeywordID(cssString);
520 bool validPrimitive = false;
521 if (valueID == CSSValueWebkitText)
522 validPrimitive = true;
523 else if (valueID == CSSValueCurrentcolor)
524 validPrimitive = true;
525 else if ((valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID == CSSValueMenu
526 || (valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWebkitText && !strict)) {
527 validPrimitive = true;
530 if (validPrimitive) {
531 RefPtr<CSSValue> value = cssValuePool().createIdentifierValue(valueID);
532 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
536 if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
538 RefPtr<CSSValue> value = cssValuePool().createColorValue(color);
539 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
543 static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acceptsNegativeNumbers)
545 switch (propertyId) {
546 case CSSPropertyFontSize:
547 case CSSPropertyHeight:
548 case CSSPropertyWidth:
549 case CSSPropertyMinHeight:
550 case CSSPropertyMinWidth:
551 case CSSPropertyPaddingBottom:
552 case CSSPropertyPaddingLeft:
553 case CSSPropertyPaddingRight:
554 case CSSPropertyPaddingTop:
555 case CSSPropertyWebkitLogicalWidth:
556 case CSSPropertyWebkitLogicalHeight:
557 case CSSPropertyWebkitMinLogicalWidth:
558 case CSSPropertyWebkitMinLogicalHeight:
559 case CSSPropertyWebkitPaddingAfter:
560 case CSSPropertyWebkitPaddingBefore:
561 case CSSPropertyWebkitPaddingEnd:
562 case CSSPropertyWebkitPaddingStart:
563 acceptsNegativeNumbers = false;
565 #if ENABLE(CSS_SHAPES)
566 case CSSPropertyWebkitShapeMargin:
567 acceptsNegativeNumbers = false;
568 return RuntimeEnabledFeatures::sharedFeatures().cssShapesEnabled();
570 case CSSPropertyBottom:
571 case CSSPropertyLeft:
572 case CSSPropertyMarginBottom:
573 case CSSPropertyMarginLeft:
574 case CSSPropertyMarginRight:
575 case CSSPropertyMarginTop:
576 case CSSPropertyRight:
578 case CSSPropertyWebkitMarginAfter:
579 case CSSPropertyWebkitMarginBefore:
580 case CSSPropertyWebkitMarginEnd:
581 case CSSPropertyWebkitMarginStart:
582 acceptsNegativeNumbers = true;
589 template <typename CharacterType>
590 static inline bool parseSimpleLength(const CharacterType* characters, unsigned& length, CSSPrimitiveValue::UnitTypes& unit, double& number)
592 if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') {
594 unit = CSSPrimitiveValue::CSS_PX;
595 } else if (length > 1 && characters[length - 1] == '%') {
597 unit = CSSPrimitiveValue::CSS_PERCENTAGE;
600 // We rely on charactersToDouble for validation as well. The function
601 // will set "ok" to "false" if the entire passed-in character range does
602 // not represent a double.
604 number = charactersToDouble(characters, length, &ok);
608 static bool parseSimpleLengthValue(MutableStyleProperties* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
610 ASSERT(!string.isEmpty());
611 bool acceptsNegativeNumbers;
612 if (!isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers))
615 unsigned length = string.length();
617 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
619 if (string.is8Bit()) {
620 if (!parseSimpleLength(string.characters8(), length, unit, number))
623 if (!parseSimpleLength(string.characters16(), length, unit, number))
627 if (unit == CSSPrimitiveValue::CSS_NUMBER) {
628 if (number && isStrictParserMode(cssParserMode))
630 unit = CSSPrimitiveValue::CSS_PX;
632 if (number < 0 && !acceptsNegativeNumbers)
635 RefPtr<CSSValue> value = cssValuePool().createValue(number, unit);
636 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
640 static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int valueID, const CSSParserContext& parserContext)
645 switch (propertyId) {
646 case CSSPropertyBorderCollapse: // collapse | separate | inherit
647 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate)
650 case CSSPropertyBorderTopStyle: // <border-style> | inherit
651 case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed |
652 case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset
653 case CSSPropertyBorderLeftStyle:
654 case CSSPropertyWebkitBorderAfterStyle:
655 case CSSPropertyWebkitBorderBeforeStyle:
656 case CSSPropertyWebkitBorderEndStyle:
657 case CSSPropertyWebkitBorderStartStyle:
658 case CSSPropertyWebkitColumnRuleStyle:
659 if (valueID >= CSSValueNone && valueID <= CSSValueDouble)
662 case CSSPropertyBoxSizing:
663 if (valueID == CSSValueBorderBox || valueID == CSSValueContentBox)
666 case CSSPropertyCaptionSide: // top | bottom | left | right | inherit
667 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueTop || valueID == CSSValueBottom)
670 case CSSPropertyClear: // none | left | right | both | inherit
671 if (valueID == CSSValueNone || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueBoth)
674 case CSSPropertyDirection: // ltr | rtl | inherit
675 if (valueID == CSSValueLtr || valueID == CSSValueRtl)
678 case CSSPropertyDisplay:
679 // inline | block | list-item | inline-block | table |
680 // inline-table | table-row-group | table-header-group | table-footer-group | table-row |
681 // table-column-group | table-column | table-cell | table-caption | -webkit-box | -webkit-inline-box | none | inherit
682 // -webkit-flex | -webkit-inline-flex | -webkit-grid | -webkit-inline-grid
683 if ((valueID >= CSSValueInline && valueID <= CSSValueWebkitInlineFlex) || valueID == CSSValueNone)
685 #if ENABLE(CSS_GRID_LAYOUT)
686 if (parserContext.isCSSGridLayoutEnabled && (valueID == CSSValueWebkitGrid || valueID == CSSValueWebkitInlineGrid))
691 case CSSPropertyEmptyCells: // show | hide | inherit
692 if (valueID == CSSValueShow || valueID == CSSValueHide)
695 case CSSPropertyFloat: // left | right | none | center (for buggy CSS, maps to none)
696 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueNone || valueID == CSSValueCenter)
699 case CSSPropertyFontStyle: // normal | italic | oblique | inherit
700 if (valueID == CSSValueNormal || valueID == CSSValueItalic || valueID == CSSValueOblique)
703 case CSSPropertyImageRendering: // auto | optimizeSpeed | optimizeQuality | -webkit-crisp-edges | -webkit-optimize-contrast
704 if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizequality
705 || valueID == CSSValueWebkitCrispEdges || valueID == CSSValueWebkitOptimizeContrast)
708 case CSSPropertyListStylePosition: // inside | outside | inherit
709 if (valueID == CSSValueInside || valueID == CSSValueOutside)
712 case CSSPropertyListStyleType:
713 // See section CSS_PROP_LIST_STYLE_TYPE of file CSSValueKeywords.in
714 // for the list of supported list-style-types.
715 if ((valueID >= CSSValueDisc && valueID <= CSSValueKatakanaIroha) || valueID == CSSValueNone)
718 case CSSPropertyObjectFit:
719 if (valueID == CSSValueFill || valueID == CSSValueContain || valueID == CSSValueCover || valueID == CSSValueNone || valueID == CSSValueScaleDown)
722 case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto | inherit
723 if (valueID == CSSValueAuto || valueID == CSSValueNone || (valueID >= CSSValueInset && valueID <= CSSValueDouble))
726 case CSSPropertyOverflowWrap: // normal | break-word
727 case CSSPropertyWordWrap:
728 if (valueID == CSSValueNormal || valueID == CSSValueBreakWord)
731 case CSSPropertyOverflowX: // visible | hidden | scroll | auto | marquee | overlay | inherit
732 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitMarquee)
735 case CSSPropertyOverflowY: // visible | hidden | scroll | auto | marquee | overlay | inherit | -webkit-paged-x | -webkit-paged-y
736 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitMarquee || valueID == CSSValueWebkitPagedX || valueID == CSSValueWebkitPagedY)
739 case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | inherit
740 case CSSPropertyPageBreakBefore:
741 case CSSPropertyWebkitColumnBreakAfter:
742 case CSSPropertyWebkitColumnBreakBefore:
743 if (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight)
746 case CSSPropertyPageBreakInside: // avoid | auto | inherit
747 case CSSPropertyWebkitColumnBreakInside:
748 if (valueID == CSSValueAuto || valueID == CSSValueAvoid)
751 case CSSPropertyPointerEvents:
752 // none | visiblePainted | visibleFill | visibleStroke | visible |
753 // painted | fill | stroke | auto | all | inherit
754 if (valueID == CSSValueVisible || valueID == CSSValueNone || valueID == CSSValueAll || valueID == CSSValueAuto || (valueID >= CSSValueVisiblepainted && valueID <= CSSValueStroke))
757 case CSSPropertyPosition: // static | relative | absolute | fixed | sticky | inherit
758 if (valueID == CSSValueStatic || valueID == CSSValueRelative || valueID == CSSValueAbsolute || valueID == CSSValueFixed
759 #if ENABLE(CSS_STICKY_POSITION)
760 || valueID == CSSValueWebkitSticky
765 case CSSPropertyResize: // none | both | horizontal | vertical | auto
766 if (valueID == CSSValueNone || valueID == CSSValueBoth || valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueAuto)
769 case CSSPropertySpeak: // none | normal | spell-out | digits | literal-punctuation | no-punctuation | inherit
770 if (valueID == CSSValueNone || valueID == CSSValueNormal || valueID == CSSValueSpellOut || valueID == CSSValueDigits || valueID == CSSValueLiteralPunctuation || valueID == CSSValueNoPunctuation)
773 case CSSPropertyTableLayout: // auto | fixed | inherit
774 if (valueID == CSSValueAuto || valueID == CSSValueFixed)
777 case CSSPropertyTextLineThroughMode:
778 case CSSPropertyTextOverlineMode:
779 case CSSPropertyTextUnderlineMode:
780 if (valueID == CSSValueContinuous || valueID == CSSValueSkipWhiteSpace)
783 case CSSPropertyTextLineThroughStyle:
784 case CSSPropertyTextOverlineStyle:
785 case CSSPropertyTextUnderlineStyle:
786 if (valueID == CSSValueNone || valueID == CSSValueSolid || valueID == CSSValueDouble || valueID == CSSValueDashed || valueID == CSSValueDotDash || valueID == CSSValueDotDotDash || valueID == CSSValueWave)
789 case CSSPropertyTextOverflow: // clip | ellipsis
790 if (valueID == CSSValueClip || valueID == CSSValueEllipsis)
793 case CSSPropertyTextRendering: // auto | optimizeSpeed | optimizeLegibility | geometricPrecision
794 if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizelegibility || valueID == CSSValueGeometricprecision)
797 case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none | inherit
798 if ((valueID >= CSSValueCapitalize && valueID <= CSSValueLowercase) || valueID == CSSValueNone)
801 case CSSPropertyVisibility: // visible | hidden | collapse | inherit
802 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueCollapse)
805 case CSSPropertyWebkitAppearance:
806 if ((valueID >= CSSValueCheckbox && valueID <= CSSValueTextarea) || valueID == CSSValueNone)
809 case CSSPropertyWebkitBackfaceVisibility:
810 if (valueID == CSSValueVisible || valueID == CSSValueHidden)
813 #if ENABLE(CSS_COMPOSITING)
814 case CSSPropertyMixBlendMode:
815 if (parserContext.isCSSCompositingEnabled && (valueID == CSSValueNormal || valueID == CSSValueMultiply || valueID == CSSValueScreen
816 || valueID == CSSValueOverlay || valueID == CSSValueDarken || valueID == CSSValueLighten || valueID == CSSValueColorDodge
817 || valueID == CSSValueColorBurn || valueID == CSSValueHardLight || valueID == CSSValueSoftLight || valueID == CSSValueDifference
818 || valueID == CSSValueExclusion))
821 case CSSPropertyIsolation:
822 if (parserContext.isCSSCompositingEnabled && (valueID == CSSValueAuto || valueID == CSSValueIsolate))
826 case CSSPropertyWebkitBorderFit:
827 if (valueID == CSSValueBorder || valueID == CSSValueLines)
830 case CSSPropertyWebkitBoxAlign:
831 if (valueID == CSSValueStretch || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline)
834 #if ENABLE(CSS_BOX_DECORATION_BREAK)
835 case CSSPropertyWebkitBoxDecorationBreak:
836 if (valueID == CSSValueClone || valueID == CSSValueSlice)
840 case CSSPropertyWebkitBoxDirection:
841 if (valueID == CSSValueNormal || valueID == CSSValueReverse)
844 case CSSPropertyWebkitBoxLines:
845 if (valueID == CSSValueSingle || valueID == CSSValueMultiple)
848 case CSSPropertyWebkitBoxOrient:
849 if (valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueInlineAxis || valueID == CSSValueBlockAxis)
852 case CSSPropertyWebkitBoxPack:
853 if (valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueJustify)
856 case CSSPropertyWebkitColorCorrection:
857 if (valueID == CSSValueSrgb || valueID == CSSValueDefault)
860 case CSSPropertyWebkitColumnFill:
861 if (valueID == CSSValueAuto || valueID == CSSValueBalance)
864 case CSSPropertyWebkitAlignContent:
865 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround || valueID == CSSValueStretch)
868 case CSSPropertyWebkitAlignItems:
869 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch)
872 case CSSPropertyWebkitAlignSelf:
873 if (valueID == CSSValueAuto || valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch)
876 case CSSPropertyWebkitFlexDirection:
877 if (valueID == CSSValueRow || valueID == CSSValueRowReverse || valueID == CSSValueColumn || valueID == CSSValueColumnReverse)
880 case CSSPropertyWebkitFlexWrap:
881 if (valueID == CSSValueNowrap || valueID == CSSValueWrap || valueID == CSSValueWrapReverse)
884 case CSSPropertyWebkitJustifyContent:
885 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround)
888 case CSSPropertyWebkitFontKerning:
889 if (valueID == CSSValueAuto || valueID == CSSValueNormal || valueID == CSSValueNone)
892 case CSSPropertyWebkitFontSmoothing:
893 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueAntialiased || valueID == CSSValueSubpixelAntialiased)
896 case CSSPropertyWebkitHyphens:
897 if (valueID == CSSValueNone || valueID == CSSValueManual || valueID == CSSValueAuto)
900 #if ENABLE(CSS_GRID_LAYOUT)
901 case CSSPropertyWebkitGridAutoFlow:
902 if (valueID == CSSValueNone || valueID == CSSValueRow || valueID == CSSValueColumn)
906 case CSSPropertyWebkitLineAlign:
907 if (valueID == CSSValueNone || valueID == CSSValueEdges)
910 case CSSPropertyWebkitLineBreak: // auto | loose | normal | strict | after-white-space
911 if (valueID == CSSValueAuto || valueID == CSSValueLoose || valueID == CSSValueNormal || valueID == CSSValueStrict || valueID == CSSValueAfterWhiteSpace)
914 case CSSPropertyWebkitLineSnap:
915 if (valueID == CSSValueNone || valueID == CSSValueBaseline || valueID == CSSValueContain)
918 case CSSPropertyWebkitMarginAfterCollapse:
919 case CSSPropertyWebkitMarginBeforeCollapse:
920 case CSSPropertyWebkitMarginBottomCollapse:
921 case CSSPropertyWebkitMarginTopCollapse:
922 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate || valueID == CSSValueDiscard)
925 case CSSPropertyWebkitMarqueeDirection:
926 if (valueID == CSSValueForwards || valueID == CSSValueBackwards || valueID == CSSValueAhead || valueID == CSSValueReverse || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueDown
927 || valueID == CSSValueUp || valueID == CSSValueAuto)
930 case CSSPropertyWebkitMarqueeStyle:
931 if (valueID == CSSValueNone || valueID == CSSValueSlide || valueID == CSSValueScroll || valueID == CSSValueAlternate)
934 case CSSPropertyWebkitNbspMode: // normal | space
935 if (valueID == CSSValueNormal || valueID == CSSValueSpace)
938 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
939 case CSSPropertyWebkitOverflowScrolling:
940 if (valueID == CSSValueAuto || valueID == CSSValueTouch)
944 case CSSPropertyWebkitPrintColorAdjust:
945 if (valueID == CSSValueExact || valueID == CSSValueEconomy)
948 #if ENABLE(CSS_REGIONS)
949 case CSSPropertyWebkitRegionBreakAfter:
950 case CSSPropertyWebkitRegionBreakBefore:
951 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight))
954 case CSSPropertyWebkitRegionBreakInside:
955 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAvoid))
958 case CSSPropertyWebkitRegionFragment:
959 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueBreak))
963 case CSSPropertyWebkitRtlOrdering:
964 if (valueID == CSSValueLogical || valueID == CSSValueVisual)
968 case CSSPropertyWebkitRubyPosition:
969 if (valueID == CSSValueBefore || valueID == CSSValueAfter)
973 #if ENABLE(CSS3_TEXT)
974 case CSSPropertyWebkitTextAlignLast:
975 // auto | start | end | left | right | center | justify
976 if ((valueID >= CSSValueLeft && valueID <= CSSValueJustify) || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueAuto)
980 case CSSPropertyWebkitTextCombine:
981 if (valueID == CSSValueNone || valueID == CSSValueHorizontal)
984 #if ENABLE(CSS3_TEXT)
985 case CSSPropertyWebkitTextJustify:
986 // auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida
987 if ((valueID >= CSSValueInterWord && valueID <= CSSValueKashida) || valueID == CSSValueAuto || valueID == CSSValueNone)
991 case CSSPropertyWebkitTextSecurity:
992 // disc | circle | square | none | inherit
993 if (valueID == CSSValueDisc || valueID == CSSValueCircle || valueID == CSSValueSquare || valueID == CSSValueNone)
996 #if ENABLE(IOS_TEXT_AUTOSIZING)
997 case CSSPropertyWebkitTextSizeAdjust:
998 if (valueID == CSSValueAuto || valueID == CSSValueNone)
1002 case CSSPropertyWebkitTransformStyle:
1003 if (valueID == CSSValueFlat || valueID == CSSValuePreserve3d)
1006 case CSSPropertyWebkitUserDrag: // auto | none | element
1007 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueElement)
1010 case CSSPropertyWebkitUserModify: // read-only | read-write
1011 if (valueID == CSSValueReadOnly || valueID == CSSValueReadWrite || valueID == CSSValueReadWritePlaintextOnly)
1014 case CSSPropertyWebkitUserSelect: // auto | none | text | all
1015 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueText || valueID == CSSValueAll)
1018 case CSSPropertyWebkitWritingMode:
1019 if (valueID >= CSSValueHorizontalTb && valueID <= CSSValueHorizontalBt)
1022 case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit
1023 if (valueID == CSSValueNormal || valueID == CSSValuePre || valueID == CSSValuePreWrap || valueID == CSSValuePreLine || valueID == CSSValueNowrap)
1026 case CSSPropertyWordBreak: // normal | break-all | break-word (this is a custom extension)
1027 if (valueID == CSSValueNormal || valueID == CSSValueBreakAll || valueID == CSSValueBreakWord)
1031 ASSERT_NOT_REACHED();
1037 static inline bool isKeywordPropertyID(CSSPropertyID propertyId)
1039 switch (propertyId) {
1040 case CSSPropertyBorderBottomStyle:
1041 case CSSPropertyBorderCollapse:
1042 case CSSPropertyBorderLeftStyle:
1043 case CSSPropertyBorderRightStyle:
1044 case CSSPropertyBorderTopStyle:
1045 case CSSPropertyBoxSizing:
1046 case CSSPropertyCaptionSide:
1047 case CSSPropertyClear:
1048 case CSSPropertyDirection:
1049 case CSSPropertyDisplay:
1050 case CSSPropertyEmptyCells:
1051 case CSSPropertyFloat:
1052 case CSSPropertyFontStyle:
1053 case CSSPropertyImageRendering:
1054 case CSSPropertyListStylePosition:
1055 case CSSPropertyListStyleType:
1056 case CSSPropertyObjectFit:
1057 case CSSPropertyOutlineStyle:
1058 case CSSPropertyOverflowWrap:
1059 case CSSPropertyOverflowX:
1060 case CSSPropertyOverflowY:
1061 case CSSPropertyPageBreakAfter:
1062 case CSSPropertyPageBreakBefore:
1063 case CSSPropertyPageBreakInside:
1064 case CSSPropertyPointerEvents:
1065 case CSSPropertyPosition:
1066 case CSSPropertyResize:
1067 case CSSPropertySpeak:
1068 case CSSPropertyTableLayout:
1069 case CSSPropertyTextLineThroughMode:
1070 case CSSPropertyTextLineThroughStyle:
1071 case CSSPropertyTextOverflow:
1072 case CSSPropertyTextOverlineMode:
1073 case CSSPropertyTextOverlineStyle:
1074 case CSSPropertyTextRendering:
1075 case CSSPropertyTextTransform:
1076 case CSSPropertyTextUnderlineMode:
1077 case CSSPropertyTextUnderlineStyle:
1078 case CSSPropertyVisibility:
1079 case CSSPropertyWebkitAppearance:
1080 #if ENABLE(CSS_COMPOSITING)
1081 case CSSPropertyMixBlendMode:
1082 case CSSPropertyIsolation:
1084 case CSSPropertyWebkitBackfaceVisibility:
1085 case CSSPropertyWebkitBorderAfterStyle:
1086 case CSSPropertyWebkitBorderBeforeStyle:
1087 case CSSPropertyWebkitBorderEndStyle:
1088 case CSSPropertyWebkitBorderFit:
1089 case CSSPropertyWebkitBorderStartStyle:
1090 case CSSPropertyWebkitBoxAlign:
1091 #if ENABLE(CSS_BOX_DECORATION_BREAK)
1092 case CSSPropertyWebkitBoxDecorationBreak:
1094 case CSSPropertyWebkitBoxDirection:
1095 case CSSPropertyWebkitBoxLines:
1096 case CSSPropertyWebkitBoxOrient:
1097 case CSSPropertyWebkitBoxPack:
1098 case CSSPropertyWebkitColorCorrection:
1099 case CSSPropertyWebkitColumnBreakAfter:
1100 case CSSPropertyWebkitColumnBreakBefore:
1101 case CSSPropertyWebkitColumnBreakInside:
1102 case CSSPropertyWebkitColumnFill:
1103 case CSSPropertyWebkitColumnRuleStyle:
1104 case CSSPropertyWebkitAlignContent:
1105 case CSSPropertyWebkitAlignItems:
1106 case CSSPropertyWebkitAlignSelf:
1107 case CSSPropertyWebkitFlexDirection:
1108 case CSSPropertyWebkitFlexWrap:
1109 case CSSPropertyWebkitJustifyContent:
1110 case CSSPropertyWebkitFontKerning:
1111 case CSSPropertyWebkitFontSmoothing:
1112 case CSSPropertyWebkitHyphens:
1113 #if ENABLE(CSS_GRID_LAYOUT)
1114 case CSSPropertyWebkitGridAutoFlow:
1116 case CSSPropertyWebkitLineAlign:
1117 case CSSPropertyWebkitLineBreak:
1118 case CSSPropertyWebkitLineSnap:
1119 case CSSPropertyWebkitMarginAfterCollapse:
1120 case CSSPropertyWebkitMarginBeforeCollapse:
1121 case CSSPropertyWebkitMarginBottomCollapse:
1122 case CSSPropertyWebkitMarginTopCollapse:
1123 case CSSPropertyWebkitMarqueeDirection:
1124 case CSSPropertyWebkitMarqueeStyle:
1125 case CSSPropertyWebkitNbspMode:
1126 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
1127 case CSSPropertyWebkitOverflowScrolling:
1129 case CSSPropertyWebkitPrintColorAdjust:
1130 #if ENABLE(CSS_REGIONS)
1131 case CSSPropertyWebkitRegionBreakAfter:
1132 case CSSPropertyWebkitRegionBreakBefore:
1133 case CSSPropertyWebkitRegionBreakInside:
1134 case CSSPropertyWebkitRegionFragment:
1136 case CSSPropertyWebkitRtlOrdering:
1137 case CSSPropertyWebkitRubyPosition:
1138 #if ENABLE(CSS3_TEXT)
1139 case CSSPropertyWebkitTextAlignLast:
1141 case CSSPropertyWebkitTextCombine:
1142 #if ENABLE(CSS3_TEXT)
1143 case CSSPropertyWebkitTextJustify:
1145 case CSSPropertyWebkitTextSecurity:
1146 case CSSPropertyWebkitTransformStyle:
1147 case CSSPropertyWebkitUserDrag:
1148 case CSSPropertyWebkitUserModify:
1149 case CSSPropertyWebkitUserSelect:
1150 case CSSPropertyWebkitWritingMode:
1151 case CSSPropertyWhiteSpace:
1152 case CSSPropertyWordBreak:
1153 case CSSPropertyWordWrap:
1160 static bool parseKeywordValue(MutableStyleProperties* declaration, CSSPropertyID propertyId, const String& string, bool important, const CSSParserContext& parserContext)
1162 ASSERT(!string.isEmpty());
1164 if (!isKeywordPropertyID(propertyId)) {
1165 // All properties accept the values of "initial" and "inherit".
1166 String lowerCaseString = string.lower();
1167 if (lowerCaseString != "initial" && lowerCaseString != "inherit")
1170 // Parse initial/inherit shorthands using the CSSParser.
1171 if (shorthandForProperty(propertyId).length())
1175 CSSParserString cssString;
1176 cssString.init(string);
1177 CSSValueID valueID = cssValueKeywordID(cssString);
1182 RefPtr<CSSValue> value;
1183 if (valueID == CSSValueInherit)
1184 value = cssValuePool().createInheritedValue();
1185 else if (valueID == CSSValueInitial)
1186 value = cssValuePool().createExplicitInitialValue();
1187 else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext))
1188 value = cssValuePool().createIdentifierValue(valueID);
1192 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
1196 template <typename CharacterType>
1197 static bool parseTransformArguments(WebKitCSSTransformValue* transformValue, CharacterType* characters, unsigned length, unsigned start, unsigned expectedCount)
1199 while (expectedCount) {
1200 size_t end = WTF::find(characters, length, expectedCount == 1 ? ')' : ',', start);
1201 if (end == notFound || (expectedCount == 1 && end != length - 1))
1203 unsigned argumentLength = end - start;
1204 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
1206 if (!parseSimpleLength(characters + start, argumentLength, unit, number))
1208 if (unit != CSSPrimitiveValue::CSS_PX && (number || unit != CSSPrimitiveValue::CSS_NUMBER))
1210 transformValue->append(cssValuePool().createValue(number, unit));
1217 static bool parseTranslateTransformValue(MutableStyleProperties* properties, CSSPropertyID propertyID, const String& string, bool important)
1219 if (propertyID != CSSPropertyWebkitTransform)
1221 static const unsigned shortestValidTransformStringLength = 12;
1222 static const unsigned likelyMultipartTransformStringLengthCutoff = 32;
1223 if (string.length() < shortestValidTransformStringLength || string.length() > likelyMultipartTransformStringLengthCutoff)
1225 if (!string.startsWith("translate", false))
1227 UChar c9 = toASCIILower(string[9]);
1228 UChar c10 = toASCIILower(string[10]);
1230 WebKitCSSTransformValue::TransformOperationType transformType;
1231 unsigned expectedArgumentCount = 1;
1232 unsigned argumentStart = 11;
1233 if (c9 == 'x' && c10 == '(')
1234 transformType = WebKitCSSTransformValue::TranslateXTransformOperation;
1235 else if (c9 == 'y' && c10 == '(')
1236 transformType = WebKitCSSTransformValue::TranslateYTransformOperation;
1237 else if (c9 == 'z' && c10 == '(')
1238 transformType = WebKitCSSTransformValue::TranslateZTransformOperation;
1239 else if (c9 == '(') {
1240 transformType = WebKitCSSTransformValue::TranslateTransformOperation;
1241 expectedArgumentCount = 2;
1243 } else if (c9 == '3' && c10 == 'd' && string[11] == '(') {
1244 transformType = WebKitCSSTransformValue::Translate3DTransformOperation;
1245 expectedArgumentCount = 3;
1250 RefPtr<WebKitCSSTransformValue> transformValue = WebKitCSSTransformValue::create(transformType);
1252 if (string.is8Bit())
1253 success = parseTransformArguments(transformValue.get(), string.characters8(), string.length(), argumentStart, expectedArgumentCount);
1255 success = parseTransformArguments(transformValue.get(), string.characters16(), string.length(), argumentStart, expectedArgumentCount);
1258 RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
1259 result->append(transformValue.release());
1260 properties->addParsedProperty(CSSProperty(CSSPropertyWebkitTransform, result.release(), important));
1264 PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& string)
1266 if (string.isEmpty())
1268 RefPtr<MutableStyleProperties> dummyStyle = MutableStyleProperties::create();
1269 if (!parseValue(dummyStyle.get(), CSSPropertyFontFamily, string, false, CSSQuirksMode, 0))
1272 RefPtr<CSSValue> fontFamily = dummyStyle->getPropertyCSSValue(CSSPropertyFontFamily);
1273 if (!fontFamily->isValueList())
1274 return 0; // FIXME: "initial" and "inherit" should be parsed as font names in the face attribute.
1275 return static_pointer_cast<CSSValueList>(fontFamily.release());
1278 bool CSSParser::parseValue(MutableStyleProperties* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
1280 ASSERT(!string.isEmpty());
1281 if (parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode))
1283 if (parseColorValue(declaration, propertyID, string, important, cssParserMode))
1286 CSSParserContext context(cssParserMode);
1287 if (contextStyleSheet) {
1288 context = contextStyleSheet->parserContext();
1289 context.mode = cssParserMode;
1292 if (parseKeywordValue(declaration, propertyID, string, important, context))
1294 if (parseTranslateTransformValue(declaration, propertyID, string, important))
1297 CSSParser parser(context);
1298 return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
1301 bool CSSParser::parseValue(MutableStyleProperties* declaration, CSSPropertyID propertyID, const String& string, bool important, StyleSheetContents* contextStyleSheet)
1303 setStyleSheet(contextStyleSheet);
1305 setupParser("@-webkit-value{", string, "} ");
1308 m_important = important;
1315 if (m_hasFontFaceOnlyValues)
1316 deleteFontFaceOnlyValues();
1317 if (!m_parsedProperties.isEmpty()) {
1319 declaration->addParsedProperties(m_parsedProperties);
1326 // The color will only be changed when string contains a valid CSS color, so callers
1327 // can set it to a default color and ignore the boolean result.
1328 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
1330 // First try creating a color specified by name, rgba(), rgb() or "#" syntax.
1331 if (fastParseColor(color, string, strict))
1334 CSSParser parser(CSSStrictMode);
1336 // In case the fast-path parser didn't understand the color, try the full parser.
1337 if (!parser.parseColor(string))
1340 CSSValue* value = parser.m_parsedProperties.first().value();
1341 if (!value->isPrimitiveValue())
1344 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
1345 if (!primitiveValue->isRGBColor())
1348 color = primitiveValue->getRGBA32Value();
1352 bool CSSParser::parseColor(const String& string)
1354 setupParser("@-webkit-decls{color:", string, "} ");
1358 return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
1361 bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
1363 if (!document || !document->page())
1366 CSSParserString cssColor;
1367 cssColor.init(string);
1368 CSSValueID id = cssValueKeywordID(cssColor);
1372 color = document->page()->theme().systemColor(id).rgb();
1376 void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
1378 m_selectorListForParseSelector = &selectorList;
1380 setupParser("@-webkit-selector{", string, "}");
1384 m_selectorListForParseSelector = 0;
1387 PassRef<ImmutableStyleProperties> CSSParser::parseInlineStyleDeclaration(const String& string, Element* element)
1389 CSSParserContext context = element->document().elementSheet().contents().parserContext();
1390 context.mode = strictToCSSParserMode(element->isHTMLElement() && !element->document().inQuirksMode());
1391 return CSSParser(context).parseDeclaration(string, &element->document().elementSheet().contents());
1394 PassRef<ImmutableStyleProperties> CSSParser::parseDeclaration(const String& string, StyleSheetContents* contextStyleSheet)
1396 setStyleSheet(contextStyleSheet);
1398 setupParser("@-webkit-decls{", string, "} ");
1402 if (m_hasFontFaceOnlyValues)
1403 deleteFontFaceOnlyValues();
1405 PassRef<ImmutableStyleProperties> style = createStyleProperties();
1411 bool CSSParser::parseDeclaration(MutableStyleProperties* declaration, const String& string, PassRefPtr<CSSRuleSourceData> prpRuleSourceData, StyleSheetContents* contextStyleSheet)
1413 // Length of the "@-webkit-decls{" prefix.
1414 static const unsigned prefixLength = 15;
1416 setStyleSheet(contextStyleSheet);
1418 RefPtr<CSSRuleSourceData> ruleSourceData = prpRuleSourceData;
1419 if (ruleSourceData) {
1420 m_currentRuleDataStack = std::make_unique<RuleSourceDataList>();
1421 m_currentRuleDataStack->append(ruleSourceData);
1424 setupParser("@-webkit-decls{", string, "} ");
1429 if (m_hasFontFaceOnlyValues)
1430 deleteFontFaceOnlyValues();
1431 if (!m_parsedProperties.isEmpty()) {
1433 declaration->addParsedProperties(m_parsedProperties);
1437 if (ruleSourceData) {
1438 ASSERT(m_currentRuleDataStack->size() == 1);
1439 ruleSourceData->ruleBodyRange.start = 0;
1440 ruleSourceData->ruleBodyRange.end = string.length();
1441 for (size_t i = 0, size = ruleSourceData->styleSourceData->propertyData.size(); i < size; ++i) {
1442 CSSPropertySourceData& propertyData = ruleSourceData->styleSourceData->propertyData.at(i);
1443 propertyData.range.start -= prefixLength;
1444 propertyData.range.end -= prefixLength;
1447 fixUnparsedPropertyRanges(ruleSourceData.get());
1448 m_currentRuleDataStack.reset();
1454 std::unique_ptr<MediaQuery> CSSParser::parseMediaQuery(const String& string)
1456 if (string.isEmpty())
1459 ASSERT(!m_mediaQuery);
1461 // can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
1462 // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
1463 setupParser("@-webkit-mediaquery ", string, "} ");
1466 return std::move(m_mediaQuery);
1469 static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, std::bitset<numCSSProperties>& seenProperties)
1471 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
1472 for (int i = input.size() - 1; i >= 0; --i) {
1473 const CSSProperty& property = input[i];
1474 if (property.isImportant() != important)
1476 const unsigned propertyIDIndex = property.id() - firstCSSProperty;
1477 if (seenProperties.test(propertyIDIndex))
1479 seenProperties.set(propertyIDIndex);
1480 output[--unusedEntries] = property;
1484 PassRef<ImmutableStyleProperties> CSSParser::createStyleProperties()
1486 std::bitset<numCSSProperties> seenProperties;
1487 size_t unusedEntries = m_parsedProperties.size();
1488 Vector<CSSProperty, 256> results(unusedEntries);
1490 // Important properties have higher priority, so add them first. Duplicate definitions can then be ignored when found.
1491 filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties);
1492 filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties);
1494 results.remove(0, unusedEntries);
1496 return ImmutableStyleProperties::create(results.data(), results.size(), m_context.mode);
1499 void CSSParser::addPropertyWithPrefixingVariant(CSSPropertyID propId, PassRefPtr<CSSValue> value, bool important, bool implicit)
1501 RefPtr<CSSValue> val = value.get();
1502 addProperty(propId, value, important, implicit);
1504 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propId);
1505 if (prefixingVariant == propId)
1508 if (m_currentShorthand) {
1509 // We can't use ShorthandScope here as we can already be inside one (e.g we are parsing CSSTransition).
1510 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
1511 addProperty(prefixingVariant, val.release(), important, implicit);
1512 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
1514 addProperty(prefixingVariant, val.release(), important, implicit);
1517 void CSSParser::addProperty(CSSPropertyID propId, PassRefPtr<CSSValue> value, bool important, bool implicit)
1519 // This property doesn't belong to a shorthand or is a CSS variable (which will be resolved later).
1520 if (!m_currentShorthand) {
1521 m_parsedProperties.append(CSSProperty(propId, value, important, false, CSSPropertyInvalid, m_implicitShorthand || implicit));
1525 Vector<StylePropertyShorthand> shorthands = matchingShorthandsForLonghand(propId);
1526 if (shorthands.size() == 1)
1527 m_parsedProperties.append(CSSProperty(propId, value, important, true, CSSPropertyInvalid, m_implicitShorthand || implicit));
1529 m_parsedProperties.append(CSSProperty(propId, value, important, true, indexOfShorthandForLonghand(m_currentShorthand, shorthands), m_implicitShorthand || implicit));
1532 void CSSParser::rollbackLastProperties(int num)
1535 ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num));
1536 m_parsedProperties.shrink(m_parsedProperties.size() - num);
1539 void CSSParser::clearProperties()
1541 m_parsedProperties.clear();
1542 m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
1543 m_hasFontFaceOnlyValues = false;
1546 URL CSSParser::completeURL(const CSSParserContext& context, const String& url)
1550 if (context.charset.isEmpty())
1551 return URL(context.baseURL, url);
1552 return URL(context.baseURL, url, context.charset);
1555 URL CSSParser::completeURL(const String& url) const
1557 return completeURL(m_context, url);
1560 bool CSSParser::validCalculationUnit(CSSParserValue* value, Units unitflags, ReleaseParsedCalcValueCondition releaseCalc)
1562 bool mustBeNonNegative = unitflags & FNonNeg;
1564 if (!parseCalculation(value, mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll))
1568 switch (m_parsedCalculation->category()) {
1570 b = (unitflags & FLength);
1573 b = (unitflags & FPercent);
1574 if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
1578 b = (unitflags & FNumber);
1579 if (!b && (unitflags & FInteger) && m_parsedCalculation->isInt())
1581 if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
1584 case CalcPercentLength:
1585 b = (unitflags & FPercent) && (unitflags & FLength);
1587 case CalcPercentNumber:
1588 b = (unitflags & FPercent) && (unitflags & FNumber);
1593 if (!b || releaseCalc == ReleaseParsedCalcValue)
1594 m_parsedCalculation.release();
1598 inline bool CSSParser::shouldAcceptUnitLessValues(CSSParserValue* value, Units unitflags, CSSParserMode cssParserMode)
1600 // Qirks mode and svg presentation attributes accept unit less values.
1601 return (unitflags & (FLength | FAngle | FTime)) && (!value->fValue || cssParserMode == CSSQuirksMode || cssParserMode == SVGAttributeMode);
1604 bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, CSSParserMode cssParserMode, ReleaseParsedCalcValueCondition releaseCalc)
1606 if (isCalculation(value))
1607 return validCalculationUnit(value, unitflags, releaseCalc);
1610 switch (value->unit) {
1611 case CSSPrimitiveValue::CSS_NUMBER:
1612 b = (unitflags & FNumber);
1613 if (!b && shouldAcceptUnitLessValues(value, unitflags, cssParserMode)) {
1614 value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX :
1615 ((unitflags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS);
1618 if (!b && (unitflags & FInteger) && value->isInt)
1620 if (!b && (unitflags & FPositiveInteger) && value->isInt && value->fValue > 0)
1623 case CSSPrimitiveValue::CSS_PERCENTAGE:
1624 b = (unitflags & FPercent);
1626 case CSSParserValue::Q_EMS:
1627 case CSSPrimitiveValue::CSS_EMS:
1628 case CSSPrimitiveValue::CSS_REMS:
1629 case CSSPrimitiveValue::CSS_CHS:
1630 case CSSPrimitiveValue::CSS_EXS:
1631 case CSSPrimitiveValue::CSS_PX:
1632 case CSSPrimitiveValue::CSS_CM:
1633 case CSSPrimitiveValue::CSS_MM:
1634 case CSSPrimitiveValue::CSS_IN:
1635 case CSSPrimitiveValue::CSS_PT:
1636 case CSSPrimitiveValue::CSS_PC:
1637 case CSSPrimitiveValue::CSS_VW:
1638 case CSSPrimitiveValue::CSS_VH:
1639 case CSSPrimitiveValue::CSS_VMIN:
1640 case CSSPrimitiveValue::CSS_VMAX:
1641 b = (unitflags & FLength);
1643 case CSSPrimitiveValue::CSS_MS:
1644 case CSSPrimitiveValue::CSS_S:
1645 b = (unitflags & FTime);
1647 case CSSPrimitiveValue::CSS_DEG:
1648 case CSSPrimitiveValue::CSS_RAD:
1649 case CSSPrimitiveValue::CSS_GRAD:
1650 case CSSPrimitiveValue::CSS_TURN:
1651 b = (unitflags & FAngle);
1653 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1654 case CSSPrimitiveValue::CSS_DPPX:
1655 case CSSPrimitiveValue::CSS_DPI:
1656 case CSSPrimitiveValue::CSS_DPCM:
1657 b = (unitflags & FResolution);
1660 case CSSPrimitiveValue::CSS_HZ:
1661 case CSSPrimitiveValue::CSS_KHZ:
1662 case CSSPrimitiveValue::CSS_DIMENSION:
1666 if (b && unitflags & FNonNeg && value->fValue < 0)
1671 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSParserValue* value)
1673 if (m_parsedCalculation) {
1674 ASSERT(isCalculation(value));
1675 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1678 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1679 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1680 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
1681 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
1682 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM));
1684 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1685 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
1686 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX));
1688 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value->unit));
1691 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSParserValue* value)
1693 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT);
1694 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRING);
1697 static inline bool isComma(CSSParserValue* value)
1699 return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
1702 static inline bool isForwardSlashOperator(CSSParserValue* value)
1705 return value->unit == CSSParserValue::Operator && value->iValue == '/';
1708 bool CSSParser::validWidth(CSSParserValue* value)
1711 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent)
1713 return !id && validUnit(value, FLength | FPercent | FNonNeg);
1716 // FIXME: Combine this with validWidth when we support fit-content, et al, for heights.
1717 bool CSSParser::validHeight(CSSParserValue* value)
1720 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic)
1722 return !id && validUnit(value, FLength | FPercent | FNonNeg);
1725 inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(CSSValueID identifier, CSSParserValue* value)
1728 return cssValuePool().createIdentifierValue(identifier);
1729 if (value->unit == CSSPrimitiveValue::CSS_STRING)
1730 return createPrimitiveStringValue(value);
1731 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1732 return createPrimitiveNumericValue(value);
1733 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
1734 return createPrimitiveNumericValue(value);
1735 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
1736 return createPrimitiveNumericValue(value);
1737 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1738 if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM)
1739 return createPrimitiveNumericValue(value);
1741 if (value->unit >= CSSParserValue::Q_EMS)
1742 return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
1743 if (isCalculation(value))
1744 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1749 void CSSParser::addExpandedPropertyForValue(CSSPropertyID propId, PassRefPtr<CSSValue> prpValue, bool important)
1751 const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
1752 unsigned shorthandLength = shorthand.length();
1753 if (!shorthandLength) {
1754 addProperty(propId, prpValue, important);
1758 RefPtr<CSSValue> value = prpValue;
1759 ShorthandScope scope(this, propId);
1760 const CSSPropertyID* longhands = shorthand.properties();
1761 for (unsigned i = 0; i < shorthandLength; ++i)
1762 addProperty(longhands[i], value, important);
1765 bool CSSParser::parseValue(CSSPropertyID propId, bool important)
1770 CSSParserValue* value = m_valueList->current();
1775 // Note: m_parsedCalculation is used to pass the calc value to validUnit and then cleared at the end of this function.
1776 // FIXME: This is to avoid having to pass parsedCalc to all validUnit callers.
1777 ASSERT(!m_parsedCalculation);
1779 CSSValueID id = value->id;
1781 unsigned num = inShorthand() ? 1 : m_valueList->size();
1783 if (id == CSSValueInherit) {
1786 addExpandedPropertyForValue(propId, cssValuePool().createInheritedValue(), important);
1789 else if (id == CSSValueInitial) {
1792 addExpandedPropertyForValue(propId, cssValuePool().createExplicitInitialValue(), important);
1796 if (isKeywordPropertyID(propId)) {
1797 if (!isValidKeywordPropertyAndValue(propId, id, m_context))
1799 if (m_valueList->next() && !inShorthand())
1801 addProperty(propId, cssValuePool().createIdentifierValue(id), important);
1805 #if ENABLE(CSS_DEVICE_ADAPTATION)
1807 return parseViewportProperty(propId, important);
1810 bool validPrimitive = false;
1811 RefPtr<CSSValue> parsedValue;
1814 case CSSPropertySize: // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
1815 return parseSize(propId, important);
1817 case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit
1819 validPrimitive = true;
1821 return parseQuotes(propId, important);
1823 case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | isolate | isolate-override | plaintext | inherit
1824 if (id == CSSValueNormal
1825 || id == CSSValueEmbed
1826 || id == CSSValueBidiOverride
1827 || id == CSSValueWebkitIsolate
1828 || id == CSSValueWebkitIsolateOverride
1829 || id == CSSValueWebkitPlaintext)
1830 validPrimitive = true;
1833 case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
1834 // close-quote | no-open-quote | no-close-quote ]+ | inherit
1835 return parseContent(propId, important);
1837 case CSSPropertyWebkitAlt: // [ <string> | attr(X) ]
1838 return parseAlt(propId, important);
1840 case CSSPropertyClip: // <shape> | auto | inherit
1841 if (id == CSSValueAuto)
1842 validPrimitive = true;
1843 else if (value->unit == CSSParserValue::Function)
1844 return parseClipShape(propId, important);
1847 /* Start of supported CSS properties with validation. This is needed for parseShorthand to work
1848 * correctly and allows optimization in WebCore::applyRule(..)
1850 case CSSPropertyOverflow: {
1851 ShorthandScope scope(this, propId);
1852 if (num != 1 || !parseValue(CSSPropertyOverflowY, important))
1855 RefPtr<CSSValue> overflowXValue;
1857 // FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. If this value has been
1858 // set using the shorthand, then for now overflow-x will default to auto, but once we implement
1859 // pagination controls, it should default to hidden. If the overflow-y value is anything but
1860 // paged-x or paged-y, then overflow-x and overflow-y should have the same value.
1861 if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
1862 overflowXValue = cssValuePool().createIdentifierValue(CSSValueAuto);
1864 overflowXValue = m_parsedProperties.last().value();
1865 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important);
1869 case CSSPropertyTextAlign:
1870 // left | right | center | justify | -webkit-left | -webkit-right | -webkit-center | -webkit-match-parent
1871 // | start | end | inherit | -webkit-auto (converted to start)
1872 // NOTE: <string> is not supported.
1873 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd)
1874 validPrimitive = true;
1877 case CSSPropertyFontWeight: { // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
1878 if (m_valueList->size() != 1)
1880 return parseFontWeight(important);
1882 case CSSPropertyBorderSpacing: {
1884 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1885 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
1887 CSSValue* value = m_parsedProperties.last().value();
1888 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important);
1891 else if (num == 2) {
1892 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1893 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important) || !parseValue(CSSPropertyWebkitBorderVerticalSpacing, important))
1899 case CSSPropertyWebkitBorderHorizontalSpacing:
1900 case CSSPropertyWebkitBorderVerticalSpacing:
1901 validPrimitive = validUnit(value, FLength | FNonNeg);
1903 case CSSPropertyOutlineColor: // <color> | invert | inherit
1904 // Outline color has "invert" as additional keyword.
1905 // Also, we want to allow the special focus color even in strict parsing mode.
1906 if (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor) {
1907 validPrimitive = true;
1911 case CSSPropertyBackgroundColor: // <color> | inherit
1912 case CSSPropertyBorderTopColor: // <color> | inherit
1913 case CSSPropertyBorderRightColor:
1914 case CSSPropertyBorderBottomColor:
1915 case CSSPropertyBorderLeftColor:
1916 case CSSPropertyWebkitBorderStartColor:
1917 case CSSPropertyWebkitBorderEndColor:
1918 case CSSPropertyWebkitBorderBeforeColor:
1919 case CSSPropertyWebkitBorderAfterColor:
1920 case CSSPropertyColor: // <color> | inherit
1921 case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors
1922 case CSSPropertyTextUnderlineColor:
1923 case CSSPropertyTextOverlineColor:
1924 case CSSPropertyWebkitColumnRuleColor:
1925 case CSSPropertyWebkitTextDecorationColor:
1926 case CSSPropertyWebkitTextEmphasisColor:
1927 case CSSPropertyWebkitTextFillColor:
1928 case CSSPropertyWebkitTextStrokeColor:
1929 if (id == CSSValueWebkitText)
1930 validPrimitive = true; // Always allow this, even when strict parsing is on,
1931 // since we use this in our UA sheets.
1932 else if (id == CSSValueCurrentcolor)
1933 validPrimitive = true;
1934 else if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu ||
1935 (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
1936 validPrimitive = true;
1938 parsedValue = parseColor();
1940 m_valueList->next();
1944 case CSSPropertyCursor: {
1945 // Grammar defined by CSS3 UI and modified by CSS4 images:
1946 // [ [<image> [<x> <y>]?,]*
1947 // [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |
1948 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize |
1949 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help |
1950 // vertical-text | cell | context-menu | alias | copy | no-drop | not-allowed | -webkit-zoom-in
1951 // -webkit-zoom-out | all-scroll | -webkit-grab | -webkit-grabbing ] ] | inherit
1952 RefPtr<CSSValueList> list;
1954 RefPtr<CSSValue> image = 0;
1955 if (value->unit == CSSPrimitiveValue::CSS_URI) {
1956 String uri = value->string;
1958 image = CSSImageValue::create(completeURL(uri));
1959 #if ENABLE(CSS_IMAGE_SET) && ENABLE(MOUSE_CURSOR_SCALE)
1960 } else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
1961 image = parseImageSet();
1969 value = m_valueList->next();
1970 while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
1971 coords.append(int(value->fValue));
1972 value = m_valueList->next();
1974 bool hasHotSpot = false;
1975 IntPoint hotSpot(-1, -1);
1976 int nrcoords = coords.size();
1977 if (nrcoords > 0 && nrcoords != 2)
1979 if (nrcoords == 2) {
1981 hotSpot = IntPoint(coords[0], coords[1]);
1985 list = CSSValueList::createCommaSeparated();
1988 list->append(CSSCursorImageValue::create(image.releaseNonNull(), hasHotSpot, hotSpot));
1990 if ((inStrictMode() && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ',')))
1992 value = m_valueList->next(); // comma
1995 if (!value) { // no value after url list (MSIE 5 compatibility)
1996 if (list->length() != 1)
1998 } else if (inQuirksMode() && value->id == CSSValueHand) // MSIE 5 compatibility :/
1999 list->append(cssValuePool().createIdentifierValue(CSSValuePointer));
2000 else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
2001 list->append(cssValuePool().createIdentifierValue(value->id));
2002 m_valueList->next();
2003 parsedValue = list.release();
2007 if (inQuirksMode() && value->id == CSSValueHand) { // MSIE 5 compatibility :/
2008 id = CSSValuePointer;
2009 validPrimitive = true;
2010 } else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
2011 validPrimitive = true;
2013 ASSERT_NOT_REACHED();
2019 #if ENABLE(CURSOR_VISIBILITY)
2020 case CSSPropertyWebkitCursorVisibility:
2021 if (id == CSSValueAuto || id == CSSValueAutoHide)
2022 validPrimitive = true;
2026 case CSSPropertyBackgroundAttachment:
2027 case CSSPropertyBackgroundBlendMode:
2028 case CSSPropertyBackgroundClip:
2029 case CSSPropertyWebkitBackgroundClip:
2030 case CSSPropertyWebkitBackgroundComposite:
2031 case CSSPropertyBackgroundImage:
2032 case CSSPropertyBackgroundOrigin:
2033 case CSSPropertyWebkitBackgroundOrigin:
2034 case CSSPropertyBackgroundPosition:
2035 case CSSPropertyBackgroundPositionX:
2036 case CSSPropertyBackgroundPositionY:
2037 case CSSPropertyBackgroundSize:
2038 case CSSPropertyWebkitBackgroundSize:
2039 case CSSPropertyBackgroundRepeat:
2040 case CSSPropertyBackgroundRepeatX:
2041 case CSSPropertyBackgroundRepeatY:
2042 case CSSPropertyWebkitMaskClip:
2043 case CSSPropertyWebkitMaskComposite:
2044 case CSSPropertyWebkitMaskImage:
2045 case CSSPropertyWebkitMaskOrigin:
2046 case CSSPropertyWebkitMaskPosition:
2047 case CSSPropertyWebkitMaskPositionX:
2048 case CSSPropertyWebkitMaskPositionY:
2049 case CSSPropertyWebkitMaskSize:
2050 case CSSPropertyWebkitMaskSourceType:
2051 case CSSPropertyWebkitMaskRepeat:
2052 case CSSPropertyWebkitMaskRepeatX:
2053 case CSSPropertyWebkitMaskRepeatY:
2055 RefPtr<CSSValue> val1;
2056 RefPtr<CSSValue> val2;
2057 CSSPropertyID propId1, propId2;
2058 bool result = false;
2059 if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
2060 std::unique_ptr<ShorthandScope> shorthandScope;
2061 if (propId == CSSPropertyBackgroundPosition ||
2062 propId == CSSPropertyBackgroundRepeat ||
2063 propId == CSSPropertyWebkitMaskPosition ||
2064 propId == CSSPropertyWebkitMaskRepeat) {
2065 shorthandScope = std::make_unique<ShorthandScope>(this, propId);
2067 addProperty(propId1, val1.release(), important);
2069 addProperty(propId2, val2.release(), important);
2072 m_implicitShorthand = false;
2075 case CSSPropertyListStyleImage: // <uri> | none | inherit
2076 case CSSPropertyBorderImageSource:
2077 case CSSPropertyWebkitMaskBoxImageSource:
2078 if (id == CSSValueNone) {
2079 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone);
2080 m_valueList->next();
2081 } else if (value->unit == CSSPrimitiveValue::CSS_URI) {
2082 parsedValue = CSSImageValue::create(completeURL(value->string));
2083 m_valueList->next();
2084 } else if (isGeneratedImageValue(value)) {
2085 if (parseGeneratedImage(m_valueList.get(), parsedValue))
2086 m_valueList->next();
2090 #if ENABLE(CSS_IMAGE_SET)
2091 else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
2092 parsedValue = parseImageSet();
2095 m_valueList->next();
2100 case CSSPropertyWebkitTextStrokeWidth:
2101 case CSSPropertyOutlineWidth: // <border-width> | inherit
2102 case CSSPropertyBorderTopWidth: //// <border-width> | inherit
2103 case CSSPropertyBorderRightWidth: // Which is defined as
2104 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
2105 case CSSPropertyBorderLeftWidth:
2106 case CSSPropertyWebkitBorderStartWidth:
2107 case CSSPropertyWebkitBorderEndWidth:
2108 case CSSPropertyWebkitBorderBeforeWidth:
2109 case CSSPropertyWebkitBorderAfterWidth:
2110 case CSSPropertyWebkitColumnRuleWidth:
2111 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
2112 validPrimitive = true;
2114 validPrimitive = validUnit(value, FLength | FNonNeg);
2117 case CSSPropertyLetterSpacing: // normal | <length> | inherit
2118 if (id == CSSValueNormal)
2119 validPrimitive = true;
2121 validPrimitive = validUnit(value, FLength);
2124 case CSSPropertyWordSpacing: // normal | <length> | <percentage> | inherit
2125 if (id == CSSValueNormal)
2126 validPrimitive = true;
2128 validPrimitive = validUnit(value, FLength | FPercent);
2131 case CSSPropertyTextIndent:
2132 parsedValue = parseTextIndent();
2135 case CSSPropertyPaddingTop: //// <padding-width> | inherit
2136 case CSSPropertyPaddingRight: // Which is defined as
2137 case CSSPropertyPaddingBottom: // <length> | <percentage>
2138 case CSSPropertyPaddingLeft: ////
2139 case CSSPropertyWebkitPaddingStart:
2140 case CSSPropertyWebkitPaddingEnd:
2141 case CSSPropertyWebkitPaddingBefore:
2142 case CSSPropertyWebkitPaddingAfter:
2143 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
2146 case CSSPropertyMaxWidth:
2147 case CSSPropertyWebkitMaxLogicalWidth:
2148 validPrimitive = (id == CSSValueNone || validWidth(value));
2151 case CSSPropertyMinWidth:
2152 case CSSPropertyWebkitMinLogicalWidth:
2153 validPrimitive = validWidth(value);
2156 case CSSPropertyWidth:
2157 case CSSPropertyWebkitLogicalWidth:
2158 validPrimitive = (id == CSSValueAuto || validWidth(value));
2161 case CSSPropertyMaxHeight:
2162 case CSSPropertyWebkitMaxLogicalHeight:
2163 validPrimitive = (id == CSSValueNone || validHeight(value));
2166 case CSSPropertyMinHeight:
2167 case CSSPropertyWebkitMinLogicalHeight:
2168 validPrimitive = validHeight(value);
2171 case CSSPropertyHeight:
2172 case CSSPropertyWebkitLogicalHeight:
2173 validPrimitive = (id == CSSValueAuto || validHeight(value));
2176 case CSSPropertyFontSize:
2177 return parseFontSize(important);
2179 case CSSPropertyFontVariant: // normal | small-caps | inherit
2180 return parseFontVariant(important);
2182 case CSSPropertyVerticalAlign:
2183 // baseline | sub | super | top | text-top | middle | bottom | text-bottom |
2184 // <percentage> | <length> | inherit
2186 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
2187 validPrimitive = true;
2189 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2192 case CSSPropertyBottom: // <length> | <percentage> | auto | inherit
2193 case CSSPropertyLeft: // <length> | <percentage> | auto | inherit
2194 case CSSPropertyRight: // <length> | <percentage> | auto | inherit
2195 case CSSPropertyTop: // <length> | <percentage> | auto | inherit
2196 case CSSPropertyMarginTop: //// <margin-width> | inherit
2197 case CSSPropertyMarginRight: // Which is defined as
2198 case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit
2199 case CSSPropertyMarginLeft: ////
2200 case CSSPropertyWebkitMarginStart:
2201 case CSSPropertyWebkitMarginEnd:
2202 case CSSPropertyWebkitMarginBefore:
2203 case CSSPropertyWebkitMarginAfter:
2204 if (id == CSSValueAuto)
2205 validPrimitive = true;
2207 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2210 case CSSPropertyZIndex: // auto | <integer> | inherit
2211 if (id == CSSValueAuto)
2212 validPrimitive = true;
2214 validPrimitive = (!id && validUnit(value, FInteger, CSSQuirksMode));
2217 case CSSPropertyOrphans: // <integer> | inherit | auto (We've added support for auto for backwards compatibility)
2218 case CSSPropertyWidows: // <integer> | inherit | auto (Ditto)
2219 if (id == CSSValueAuto)
2220 validPrimitive = true;
2222 validPrimitive = (!id && validUnit(value, FPositiveInteger, CSSQuirksMode));
2225 case CSSPropertyLineHeight:
2226 return parseLineHeight(important);
2227 case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit
2228 if (id != CSSValueNone)
2229 return parseCounter(propId, 1, important);
2230 validPrimitive = true;
2232 case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit
2233 if (id != CSSValueNone)
2234 return parseCounter(propId, 0, important);
2235 validPrimitive = true;
2237 case CSSPropertyFontFamily:
2238 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit
2240 parsedValue = parseFontFamily();
2244 case CSSPropertyWebkitTextDecoration:
2245 // [ <text-decoration-line> || <text-decoration-style> || <text-decoration-color> ] | inherit
2246 return parseShorthand(CSSPropertyWebkitTextDecoration, webkitTextDecorationShorthand(), important);
2248 case CSSPropertyTextDecoration:
2249 case CSSPropertyWebkitTextDecorationsInEffect:
2250 case CSSPropertyWebkitTextDecorationLine:
2251 // none | [ underline || overline || line-through || blink ] | inherit
2252 return parseTextDecoration(propId, important);
2254 case CSSPropertyWebkitTextDecorationStyle:
2255 // solid | double | dotted | dashed | wavy
2256 if (id == CSSValueSolid || id == CSSValueDouble || id == CSSValueDotted || id == CSSValueDashed || id == CSSValueWavy)
2257 validPrimitive = true;
2260 case CSSPropertyWebkitTextDecorationSkip:
2261 // none | [ objects || spaces || ink || edges || box-decoration ]
2262 return parseTextDecorationSkip(important);
2264 case CSSPropertyWebkitTextUnderlinePosition:
2265 // auto | alphabetic | under
2266 return parseTextUnderlinePosition(important);
2268 case CSSPropertyZoom: // normal | reset | document | <number> | <percentage> | inherit
2269 if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument)
2270 validPrimitive = true;
2272 validPrimitive = (!id && validUnit(value, FNumber | FPercent | FNonNeg, CSSStrictMode));
2275 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.
2276 return parseFontFaceSrc();
2278 case CSSPropertyUnicodeRange:
2279 return parseFontFaceUnicodeRange();
2281 /* CSS3 properties */
2283 case CSSPropertyBorderImage: {
2284 RefPtr<CSSValue> result;
2285 return parseBorderImage(propId, result, important);
2287 case CSSPropertyWebkitBorderImage:
2288 case CSSPropertyWebkitMaskBoxImage: {
2289 RefPtr<CSSValue> result;
2290 if (parseBorderImage(propId, result)) {
2291 addProperty(propId, result, important);
2296 case CSSPropertyBorderImageOutset:
2297 case CSSPropertyWebkitMaskBoxImageOutset: {
2298 RefPtr<CSSPrimitiveValue> result;
2299 if (parseBorderImageOutset(result)) {
2300 addProperty(propId, result, important);
2305 case CSSPropertyBorderImageRepeat:
2306 case CSSPropertyWebkitMaskBoxImageRepeat: {
2307 RefPtr<CSSValue> result;
2308 if (parseBorderImageRepeat(result)) {
2309 addProperty(propId, result, important);
2314 case CSSPropertyBorderImageSlice:
2315 case CSSPropertyWebkitMaskBoxImageSlice: {
2316 RefPtr<CSSBorderImageSliceValue> result;
2317 if (parseBorderImageSlice(propId, result)) {
2318 addProperty(propId, result, important);
2323 case CSSPropertyBorderImageWidth:
2324 case CSSPropertyWebkitMaskBoxImageWidth: {
2325 RefPtr<CSSPrimitiveValue> result;
2326 if (parseBorderImageWidth(result)) {
2327 addProperty(propId, result, important);
2332 case CSSPropertyBorderTopRightRadius:
2333 case CSSPropertyBorderTopLeftRadius:
2334 case CSSPropertyBorderBottomLeftRadius:
2335 case CSSPropertyBorderBottomRightRadius: {
2336 if (num != 1 && num != 2)
2338 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
2339 if (!validPrimitive)
2341 RefPtr<CSSPrimitiveValue> parsedValue1 = createPrimitiveNumericValue(value);
2342 RefPtr<CSSPrimitiveValue> parsedValue2;
2344 value = m_valueList->next();
2345 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
2346 if (!validPrimitive)
2348 parsedValue2 = createPrimitiveNumericValue(value);
2350 parsedValue2 = parsedValue1;
2352 addProperty(propId, createPrimitiveValuePair(parsedValue1.release(), parsedValue2.release()), important);
2355 case CSSPropertyTabSize:
2356 validPrimitive = validUnit(value, FInteger | FNonNeg);
2358 case CSSPropertyWebkitAspectRatio:
2359 return parseAspectRatio(important);
2360 case CSSPropertyBorderRadius:
2361 case CSSPropertyWebkitBorderRadius:
2362 return parseBorderRadius(propId, important);
2363 case CSSPropertyOutlineOffset:
2364 validPrimitive = validUnit(value, FLength);
2366 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
2367 case CSSPropertyBoxShadow:
2368 case CSSPropertyWebkitBoxShadow:
2369 if (id == CSSValueNone)
2370 validPrimitive = true;
2372 RefPtr<CSSValueList> shadowValueList = parseShadow(m_valueList.get(), propId);
2373 if (shadowValueList) {
2374 addProperty(propId, shadowValueList.release(), important);
2375 m_valueList->next();
2381 case CSSPropertyWebkitBoxReflect:
2382 if (id == CSSValueNone)
2383 validPrimitive = true;
2385 return parseReflect(propId, important);
2387 case CSSPropertyOpacity:
2388 validPrimitive = validUnit(value, FNumber);
2390 case CSSPropertyWebkitBoxFlex:
2391 validPrimitive = validUnit(value, FNumber);
2393 case CSSPropertyWebkitBoxFlexGroup:
2394 validPrimitive = validUnit(value, FInteger | FNonNeg, CSSStrictMode);
2396 case CSSPropertyWebkitBoxOrdinalGroup:
2397 validPrimitive = validUnit(value, FInteger | FNonNeg, CSSStrictMode) && value->fValue;
2399 #if ENABLE(CSS_FILTERS)
2400 case CSSPropertyWebkitFilter:
2401 if (id == CSSValueNone)
2402 validPrimitive = true;
2404 RefPtr<CSSValue> currValue;
2405 if (!parseFilter(m_valueList.get(), currValue))
2407 addProperty(propId, currValue, important);
2412 #if ENABLE(CSS_COMPOSITING)
2413 case CSSPropertyMixBlendMode:
2414 if (cssCompositingEnabled())
2415 validPrimitive = true;
2417 case CSSPropertyIsolation:
2418 if (cssCompositingEnabled())
2419 validPrimitive = true;
2422 case CSSPropertyWebkitFlex: {
2423 ShorthandScope scope(this, propId);
2424 if (id == CSSValueNone) {
2425 addProperty(CSSPropertyWebkitFlexGrow, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2426 addProperty(CSSPropertyWebkitFlexShrink, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2427 addProperty(CSSPropertyWebkitFlexBasis, cssValuePool().createIdentifierValue(CSSValueAuto), important);
2430 return parseFlex(m_valueList.get(), important);
2432 case CSSPropertyWebkitFlexBasis:
2433 // FIXME: Support intrinsic dimensions too.
2434 if (id == CSSValueAuto)
2435 validPrimitive = true;
2437 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
2439 case CSSPropertyWebkitFlexGrow:
2440 case CSSPropertyWebkitFlexShrink:
2441 validPrimitive = validUnit(value, FNumber | FNonNeg);
2443 case CSSPropertyWebkitOrder:
2444 if (validUnit(value, FInteger, CSSStrictMode)) {
2445 // 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.
2446 parsedValue = cssValuePool().createValue(std::max<double>(std::numeric_limits<int>::min() + 2, value->fValue), static_cast<CSSPrimitiveValue::UnitTypes>(value->unit));
2447 m_valueList->next();
2450 case CSSPropertyWebkitMarquee:
2451 return parseShorthand(propId, webkitMarqueeShorthand(), important);
2452 case CSSPropertyWebkitMarqueeIncrement:
2453 if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
2454 validPrimitive = true;
2456 validPrimitive = validUnit(value, FLength | FPercent);
2458 case CSSPropertyWebkitMarqueeRepetition:
2459 if (id == CSSValueInfinite)
2460 validPrimitive = true;
2462 validPrimitive = validUnit(value, FInteger | FNonNeg);
2464 case CSSPropertyWebkitMarqueeSpeed:
2465 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
2466 validPrimitive = true;
2468 validPrimitive = validUnit(value, FTime | FInteger | FNonNeg);
2470 #if ENABLE(CSS_REGIONS)
2471 case CSSPropertyWebkitFlowInto:
2472 if (!cssRegionsEnabled())
2474 return parseFlowThread(propId, important);
2475 case CSSPropertyWebkitFlowFrom:
2476 if (!cssRegionsEnabled())
2478 return parseRegionThread(propId, important);
2480 case CSSPropertyWebkitTransform:
2481 if (id == CSSValueNone)
2482 validPrimitive = true;
2484 RefPtr<CSSValue> transformValue = parseTransform();
2485 if (transformValue) {
2486 addProperty(propId, transformValue.release(), important);
2492 case CSSPropertyWebkitTransformOrigin:
2493 case CSSPropertyWebkitTransformOriginX:
2494 case CSSPropertyWebkitTransformOriginY:
2495 case CSSPropertyWebkitTransformOriginZ: {
2496 RefPtr<CSSValue> val1;
2497 RefPtr<CSSValue> val2;
2498 RefPtr<CSSValue> val3;
2499 CSSPropertyID propId1, propId2, propId3;
2500 if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
2501 addProperty(propId1, val1.release(), important);
2503 addProperty(propId2, val2.release(), important);
2505 addProperty(propId3, val3.release(), important);
2510 case CSSPropertyWebkitPerspective:
2511 if (id == CSSValueNone)
2512 validPrimitive = true;
2514 // Accepting valueless numbers is a quirk of the -webkit prefixed version of the property.
2515 if (validUnit(value, FNumber | FLength | FNonNeg)) {
2516 RefPtr<CSSValue> val = createPrimitiveNumericValue(value);
2518 addProperty(propId, val.release(), important);
2525 case CSSPropertyWebkitPerspectiveOrigin:
2526 case CSSPropertyWebkitPerspectiveOriginX:
2527 case CSSPropertyWebkitPerspectiveOriginY: {
2528 RefPtr<CSSValue> val1;
2529 RefPtr<CSSValue> val2;
2530 CSSPropertyID propId1, propId2;
2531 if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
2532 addProperty(propId1, val1.release(), important);
2534 addProperty(propId2, val2.release(), important);
2539 case CSSPropertyWebkitAnimationDelay:
2540 case CSSPropertyWebkitAnimationDirection:
2541 case CSSPropertyWebkitAnimationDuration:
2542 case CSSPropertyWebkitAnimationFillMode:
2543 case CSSPropertyWebkitAnimationName:
2544 case CSSPropertyWebkitAnimationPlayState:
2545 case CSSPropertyWebkitAnimationIterationCount:
2546 case CSSPropertyWebkitAnimationTimingFunction:
2547 case CSSPropertyTransitionDelay:
2548 case CSSPropertyTransitionDuration:
2549 case CSSPropertyTransitionTimingFunction:
2550 case CSSPropertyTransitionProperty:
2551 case CSSPropertyWebkitTransitionDelay:
2552 case CSSPropertyWebkitTransitionDuration:
2553 case CSSPropertyWebkitTransitionTimingFunction:
2554 case CSSPropertyWebkitTransitionProperty: {
2555 RefPtr<CSSValue> val;
2556 AnimationParseContext context;
2557 if (parseAnimationProperty(propId, val, context)) {
2558 addPropertyWithPrefixingVariant(propId, val.release(), important);
2563 #if ENABLE(CSS_GRID_LAYOUT)
2564 case CSSPropertyWebkitGridAutoColumns:
2565 case CSSPropertyWebkitGridAutoRows:
2566 if (!cssGridLayoutEnabled())
2568 parsedValue = parseGridTrackSize(*m_valueList);
2571 case CSSPropertyWebkitGridTemplateColumns:
2572 case CSSPropertyWebkitGridTemplateRows:
2573 if (!cssGridLayoutEnabled())
2575 parsedValue = parseGridTrackList();
2578 case CSSPropertyWebkitGridColumnStart:
2579 case CSSPropertyWebkitGridColumnEnd:
2580 case CSSPropertyWebkitGridRowStart:
2581 case CSSPropertyWebkitGridRowEnd:
2582 if (!cssGridLayoutEnabled())
2585 parsedValue = parseGridPosition();
2588 case CSSPropertyWebkitGridColumn:
2589 case CSSPropertyWebkitGridRow: {
2590 if (!cssGridLayoutEnabled())
2593 return parseGridItemPositionShorthand(propId, important);
2596 case CSSPropertyWebkitGridTemplate:
2597 if (!cssGridLayoutEnabled())
2599 return parseGridTemplateShorthand(important);
2601 case CSSPropertyWebkitGridArea:
2602 if (!cssGridLayoutEnabled())
2604 return parseGridAreaShorthand(important);
2606 case CSSPropertyWebkitGridTemplateAreas:
2607 if (!cssGridLayoutEnabled())
2610 parsedValue = parseGridTemplateAreas();
2612 #endif /* ENABLE(CSS_GRID_LAYOUT) */
2613 case CSSPropertyWebkitMarginCollapse: {
2615 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2616 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important))
2618 CSSValue* value = m_parsedProperties.last().value();
2619 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
2622 else if (num == 2) {
2623 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2624 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important) || !parseValue(webkitMarginCollapseShorthand().properties()[1], important))
2630 case CSSPropertyTextLineThroughWidth:
2631 case CSSPropertyTextOverlineWidth:
2632 case CSSPropertyTextUnderlineWidth:
2633 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
2634 id == CSSValueMedium || id == CSSValueThick)
2635 validPrimitive = true;
2637 validPrimitive = !id && validUnit(value, FNumber | FLength | FPercent);
2639 case CSSPropertyWebkitColumnCount:
2640 if (id == CSSValueAuto)
2641 validPrimitive = true;
2643 validPrimitive = !id && validUnit(value, FPositiveInteger, CSSQuirksMode);
2645 case CSSPropertyWebkitColumnGap: // normal | <length>
2646 if (id == CSSValueNormal)
2647 validPrimitive = true;
2649 validPrimitive = validUnit(value, FLength | FNonNeg);
2651 case CSSPropertyWebkitColumnAxis:
2652 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto)
2653 validPrimitive = true;
2655 case CSSPropertyWebkitColumnProgression:
2656 if (id == CSSValueNormal || id == CSSValueReverse)
2657 validPrimitive = true;
2659 case CSSPropertyWebkitColumnSpan: // none | all | 1 (will be dropped in the unprefixed property)
2660 if (id == CSSValueAll || id == CSSValueNone)
2661 validPrimitive = true;
2663 validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValue == 1;
2665 case CSSPropertyWebkitColumnWidth: // auto | <length>
2666 if (id == CSSValueAuto)
2667 validPrimitive = true;
2668 else // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property.
2669 validPrimitive = validUnit(value, FLength | FNonNeg, CSSStrictMode) && value->fValue;
2671 // End of CSS3 properties
2673 // Apple specific properties. These will never be standardized and are purely to
2674 // support custom WebKit-based Apple applications.
2675 case CSSPropertyWebkitLineClamp:
2676 // When specifying number of lines, don't allow 0 as a valid value
2677 // When specifying either type of unit, require non-negative integers
2678 validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTAGE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, CSSQuirksMode));
2680 #if ENABLE(IOS_TEXT_AUTOSIZING)
2681 case CSSPropertyWebkitTextSizeAdjust:
2682 if (id == CSSValueAuto || id == CSSValueNone)
2683 validPrimitive = true;
2685 // FIXME: Handle multilength case where we allow relative units.
2686 validPrimitive = (!id && validUnit(value, FPercent | FNonNeg, CSSStrictMode));
2691 case CSSPropertyWebkitFontSizeDelta: // <length>
2692 validPrimitive = validUnit(value, FLength);
2695 case CSSPropertyWebkitHyphenateCharacter:
2696 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
2697 validPrimitive = true;
2700 case CSSPropertyWebkitHyphenateLimitBefore:
2701 case CSSPropertyWebkitHyphenateLimitAfter:
2702 if (id == CSSValueAuto || validUnit(value, FInteger | FNonNeg, CSSStrictMode))
2703 validPrimitive = true;
2706 case CSSPropertyWebkitHyphenateLimitLines:
2707 if (id == CSSValueNoLimit || validUnit(value, FInteger | FNonNeg, CSSStrictMode))
2708 validPrimitive = true;
2711 case CSSPropertyWebkitLineGrid:
2712 if (id == CSSValueNone)
2713 validPrimitive = true;
2714 else if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
2715 String lineGridValue = String(value->string);
2716 if (!lineGridValue.isEmpty()) {
2717 addProperty(propId, cssValuePool().createValue(lineGridValue, CSSPrimitiveValue::CSS_STRING), important);
2722 case CSSPropertyWebkitLocale:
2723 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
2724 validPrimitive = true;
2727 #if ENABLE(DASHBOARD_SUPPORT)
2728 case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region>
2729 if (value->unit == CSSParserValue::Function || id == CSSValueNone)
2730 return parseDashboardRegions(propId, important);
2735 // FIXME: CSSPropertyWebkitCompositionFillColor shouldn't be iOS-specific. Once we fix up its usage in
2736 // InlineTextBox::paintCompositionBackground() we should move it outside the PLATFORM(IOS)-guard.
2737 // See <https://bugs.webkit.org/show_bug.cgi?id=126296>.
2738 case CSSPropertyWebkitCompositionFillColor:
2739 if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu
2740 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2741 validPrimitive = true;
2743 parsedValue = parseColor();
2745 m_valueList->next();
2748 case CSSPropertyWebkitTouchCallout:
2749 if (id == CSSValueDefault || id == CSSValueNone)
2750 validPrimitive = true;
2753 #if ENABLE(TOUCH_EVENTS)
2754 case CSSPropertyWebkitTapHighlightColor:
2755 if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu
2756 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2757 validPrimitive = true;
2759 parsedValue = parseColor();
2761 m_valueList->next();
2765 // End Apple-specific properties
2767 /* shorthand properties */
2768 case CSSPropertyBackground: {
2769 // Position must come before color in this array because a plain old "0" is a legal color
2770 // in quirks mode but it's usually the X coordinate of a position.
2771 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
2772 CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin,
2773 CSSPropertyBackgroundClip, CSSPropertyBackgroundColor, CSSPropertyBackgroundSize };
2774 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2776 case CSSPropertyWebkitMask: {
2777 const CSSPropertyID properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskSourceType, CSSPropertyWebkitMaskRepeat,
2778 CSSPropertyWebkitMaskPosition, CSSPropertyWebkitMaskOrigin, CSSPropertyWebkitMaskClip, CSSPropertyWebkitMaskSize };
2779 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2781 case CSSPropertyBorder:
2782 // [ 'border-width' || 'border-style' || <color> ] | inherit
2784 if (parseShorthand(propId, borderAbridgedShorthand(), important)) {
2785 // The CSS3 Borders and Backgrounds specification says that border also resets border-image. It's as
2786 // though a value of none was specified for the image.
2787 addExpandedPropertyForValue(CSSPropertyBorderImage, cssValuePool().createImplicitInitialValue(), important);
2792 case CSSPropertyBorderTop:
2793 // [ 'border-top-width' || 'border-style' || <color> ] | inherit
2794 return parseShorthand(propId, borderTopShorthand(), important);
2795 case CSSPropertyBorderRight:
2796 // [ 'border-right-width' || 'border-style' || <color> ] | inherit
2797 return parseShorthand(propId, borderRightShorthand(), important);
2798 case CSSPropertyBorderBottom:
2799 // [ 'border-bottom-width' || 'border-style' || <color> ] | inherit
2800 return parseShorthand(propId, borderBottomShorthand(), important);
2801 case CSSPropertyBorderLeft:
2802 // [ 'border-left-width' || 'border-style' || <color> ] | inherit
2803 return parseShorthand(propId, borderLeftShorthand(), important);
2804 case CSSPropertyWebkitBorderStart:
2805 return parseShorthand(propId, webkitBorderStartShorthand(), important);
2806 case CSSPropertyWebkitBorderEnd:
2807 return parseShorthand(propId, webkitBorderEndShorthand(), important);
2808 case CSSPropertyWebkitBorderBefore:
2809 return parseShorthand(propId, webkitBorderBeforeShorthand(), important);
2810 case CSSPropertyWebkitBorderAfter:
2811 return parseShorthand(propId, webkitBorderAfterShorthand(), important);
2812 case CSSPropertyOutline:
2813 // [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit
2814 return parseShorthand(propId, outlineShorthand(), important);
2815 case CSSPropertyBorderColor:
2816 // <color>{1,4} | inherit
2817 return parse4Values(propId, borderColorShorthand().properties(), important);
2818 case CSSPropertyBorderWidth:
2819 // <border-width>{1,4} | inherit
2820 return parse4Values(propId, borderWidthShorthand().properties(), important);
2821 case CSSPropertyBorderStyle:
2822 // <border-style>{1,4} | inherit
2823 return parse4Values(propId, borderStyleShorthand().properties(), important);
2824 case CSSPropertyMargin:
2825 // <margin-width>{1,4} | inherit
2826 return parse4Values(propId, marginShorthand().properties(), important);
2827 case CSSPropertyPadding:
2828 // <padding-width>{1,4} | inherit
2829 return parse4Values(propId, paddingShorthand().properties(), important);
2830 case CSSPropertyWebkitFlexFlow:
2831 return parseShorthand(propId, webkitFlexFlowShorthand(), important);
2832 case CSSPropertyFont:
2833 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
2834 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
2835 if (id >= CSSValueCaption && id <= CSSValueStatusBar)
2836 validPrimitive = true;
2838 return parseFont(important);
2840 case CSSPropertyListStyle:
2841 return parseShorthand(propId, listStyleShorthand(), important);
2842 case CSSPropertyWebkitColumns:
2843 return parseShorthand(propId, webkitColumnsShorthand(), important);
2844 case CSSPropertyWebkitColumnRule:
2845 return parseShorthand(propId, webkitColumnRuleShorthand(), important);
2846 case CSSPropertyWebkitTextStroke:
2847 return parseShorthand(propId, webkitTextStrokeShorthand(), important);
2848 case CSSPropertyWebkitAnimation:
2849 return parseAnimationShorthand(important);
2850 case CSSPropertyTransition:
2851 case CSSPropertyWebkitTransition:
2852 return parseTransitionShorthand(propId, important);
2853 case CSSPropertyInvalid:
2855 case CSSPropertyPage:
2856 return parsePage(propId, important);
2857 case CSSPropertyFontStretch:
2858 case CSSPropertyTextLineThrough:
2859 case CSSPropertyTextOverline:
2860 case CSSPropertyTextUnderline:
2862 // CSS Text Layout Module Level 3: Vertical writing support
2863 case CSSPropertyWebkitTextEmphasis:
2864 return parseShorthand(propId, webkitTextEmphasisShorthand(), important);
2866 case CSSPropertyWebkitTextEmphasisStyle:
2867 return parseTextEmphasisStyle(important);
2869 case CSSPropertyWebkitTextEmphasisPosition:
2870 return parseTextEmphasisPosition(important);
2872 case CSSPropertyWebkitTextOrientation:
2873 // FIXME: For now just support sideways, sideways-right, upright and vertical-right.
2874 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSValueVerticalRight || id == CSSValueUpright)
2875 validPrimitive = true;
2878 case CSSPropertyWebkitLineBoxContain:
2879 if (id == CSSValueNone)
2880 validPrimitive = true;
2882 return parseLineBoxContain(important);
2884 case CSSPropertyWebkitFontFeatureSettings:
2885 if (id == CSSValueNormal)
2886 validPrimitive = true;
2888 return parseFontFeatureSettings(important);
2891 case CSSPropertyWebkitFontVariantLigatures:
2892 if (id == CSSValueNormal)
2893 validPrimitive = true;
2895 return parseFontVariantLigatures(important);
2897 case CSSPropertyWebkitClipPath:
2898 parsedValue = parseClipPath();
2900 #if ENABLE(CSS_SHAPES)
2901 case CSSPropertyWebkitShapeOutside:
2902 parsedValue = parseShapeProperty(propId);
2904 case CSSPropertyWebkitShapeMargin:
2905 validPrimitive = (RuntimeEnabledFeatures::sharedFeatures().cssShapesEnabled() && !id && validUnit(value, FLength | FPercent | FNonNeg));
2907 case CSSPropertyWebkitShapeImageThreshold:
2908 validPrimitive = (RuntimeEnabledFeatures::sharedFeatures().cssShapesEnabled() && !id && validUnit(value, FNumber));
2911 #if ENABLE(CSS_IMAGE_ORIENTATION)
2912 case CSSPropertyImageOrientation:
2913 validPrimitive = !id && validUnit(value, FAngle);
2916 #if ENABLE(CSS_IMAGE_RESOLUTION)
2917 case CSSPropertyImageResolution:
2918 parsedValue = parseImageResolution();
2921 case CSSPropertyBorderBottomStyle:
2922 case CSSPropertyBorderCollapse:
2923 case CSSPropertyBorderLeftStyle:
2924 case CSSPropertyBorderRightStyle:
2925 case CSSPropertyBorderTopStyle:
2926 case CSSPropertyBoxSizing:
2927 case CSSPropertyCaptionSide:
2928 case CSSPropertyClear:
2929 case CSSPropertyDirection:
2930 case CSSPropertyDisplay:
2931 case CSSPropertyEmptyCells:
2932 case CSSPropertyFloat:
2933 case CSSPropertyFontStyle:
2934 case CSSPropertyImageRendering:
2935 case CSSPropertyListStylePosition:
2936 case CSSPropertyListStyleType:
2937 case CSSPropertyObjectFit:
2938 case CSSPropertyOutlineStyle:
2939 case CSSPropertyOverflowWrap:
2940 case CSSPropertyOverflowX:
2941 case CSSPropertyOverflowY:
2942 case CSSPropertyPageBreakAfter:
2943 case CSSPropertyPageBreakBefore:
2944 case CSSPropertyPageBreakInside:
2945 case CSSPropertyPointerEvents:
2946 case CSSPropertyPosition:
2947 case CSSPropertyResize:
2948 case CSSPropertySpeak:
2949 case CSSPropertyTableLayout:
2950 case CSSPropertyTextLineThroughMode:
2951 case CSSPropertyTextLineThroughStyle:
2952 case CSSPropertyTextOverflow:
2953 case CSSPropertyTextOverlineMode:
2954 case CSSPropertyTextOverlineStyle:
2955 case CSSPropertyTextRendering:
2956 case CSSPropertyTextTransform:
2957 case CSSPropertyTextUnderlineMode:
2958 case CSSPropertyTextUnderlineStyle:
2959 case CSSPropertyVisibility:
2960 case CSSPropertyWebkitAppearance:
2961 case CSSPropertyWebkitBackfaceVisibility:
2962 case CSSPropertyWebkitBorderAfterStyle:
2963 case CSSPropertyWebkitBorderBeforeStyle:
2964 case CSSPropertyWebkitBorderEndStyle:
2965 case CSSPropertyWebkitBorderFit:
2966 case CSSPropertyWebkitBorderStartStyle:
2967 case CSSPropertyWebkitBoxAlign:
2968 #if ENABLE(CSS_BOX_DECORATION_BREAK)
2969 case CSSPropertyWebkitBoxDecorationBreak:
2971 case CSSPropertyWebkitBoxDirection:
2972 case CSSPropertyWebkitBoxLines:
2973 case CSSPropertyWebkitBoxOrient:
2974 case CSSPropertyWebkitBoxPack:
2975 case CSSPropertyWebkitColorCorrection:
2976 case CSSPropertyWebkitColumnBreakAfter:
2977 case CSSPropertyWebkitColumnBreakBefore:
2978 case CSSPropertyWebkitColumnBreakInside:
2979 case CSSPropertyWebkitColumnFill:
2980 case CSSPropertyWebkitColumnRuleStyle:
2981 case CSSPropertyWebkitAlignContent:
2982 case CSSPropertyWebkitAlignItems:
2983 case CSSPropertyWebkitAlignSelf:
2984 case CSSPropertyWebkitFlexDirection:
2985 case CSSPropertyWebkitFlexWrap:
2986 case CSSPropertyWebkitJustifyContent:
2987 case CSSPropertyWebkitFontKerning:
2988 case CSSPropertyWebkitFontSmoothing:
2989 case CSSPropertyWebkitHyphens:
2990 #if ENABLE(CSS_GRID_LAYOUT)
2991 case CSSPropertyWebkitGridAutoFlow:
2993 case CSSPropertyWebkitLineAlign:
2994 case CSSPropertyWebkitLineBreak:
2995 case CSSPropertyWebkitLineSnap:
2996 case CSSPropertyWebkitMarginAfterCollapse:
2997 case CSSPropertyWebkitMarginBeforeCollapse:
2998 case CSSPropertyWebkitMarginBottomCollapse:
2999 case CSSPropertyWebkitMarginTopCollapse:
3000 case CSSPropertyWebkitMarqueeDirection:
3001 case CSSPropertyWebkitMarqueeStyle:
3002 case CSSPropertyWebkitNbspMode:
3003 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
3004 case CSSPropertyWebkitOverflowScrolling:
3006 case CSSPropertyWebkitPrintColorAdjust:
3007 #if ENABLE(CSS_REGIONS)
3008 case CSSPropertyWebkitRegionBreakAfter:
3009 case CSSPropertyWebkitRegionBreakBefore:
3010 case CSSPropertyWebkitRegionBreakInside:
3011 case CSSPropertyWebkitRegionFragment:
3013 case CSSPropertyWebkitRtlOrdering:
3014 case CSSPropertyWebkitRubyPosition:
3015 #if ENABLE(CSS3_TEXT)
3016 case CSSPropertyWebkitTextAlignLast:
3018 case CSSPropertyWebkitTextCombine:
3019 #if ENABLE(CSS3_TEXT)
3020 case CSSPropertyWebkitTextJustify:
3022 case CSSPropertyWebkitTextSecurity:
3023 case CSSPropertyWebkitTransformStyle:
3024 case CSSPropertyWebkitUserDrag:
3025 case CSSPropertyWebkitUserModify:
3026 case CSSPropertyWebkitUserSelect:
3027 case CSSPropertyWebkitWritingMode:
3028 case CSSPropertyWhiteSpace:
3029 case CSSPropertyWordBreak:
3030 case CSSPropertyWordWrap:
3031 // These properties should be handled before in isValidKeywordPropertyAndValue().
3032 ASSERT_NOT_REACHED();
3034 #if ENABLE(CSS_DEVICE_ADAPTATION)
3035 // Properties bellow are validated inside parseViewportProperty, because we
3036 // check for parser state inViewportScope. We need to invalidate if someone
3037 // adds them outside a @viewport rule.
3038 case CSSPropertyMaxZoom:
3039 case CSSPropertyMinZoom:
3040 case CSSPropertyOrientation:
3041 case CSSPropertyUserZoom:
3042 validPrimitive = false;
3046 return parseSVGValue(propId, important);
3049 if (validPrimitive) {
3050 parsedValue = parseValidPrimitive(id, value);
3051 m_valueList->next();
3053 ASSERT(!m_parsedCalculation);
3055 if (!m_valueList->current() || inShorthand()) {
3056 addProperty(propId, parsedValue.release(), important);
3063 void CSSParser::addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
3066 if (lval->isBaseValueList())
3067 toCSSValueList(lval.get())->append(rval);
3069 PassRefPtr<CSSValue> oldlVal(lval.release());
3070 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3071 list->append(oldlVal);
3080 static bool parseBackgroundClip(CSSParserValue* parserValue, RefPtr<CSSValue>& cssValue)
3082 if (parserValue->id == CSSValueBorderBox || parserValue->id == CSSValuePaddingBox
3083 || parserValue->id == CSSValueContentBox || parserValue->id == CSSValueWebkitText) {
3084 cssValue = cssValuePool().createIdentifierValue(parserValue->id);
3090 bool CSSParser::useLegacyBackgroundSizeShorthandBehavior() const
3092 return m_context.useLegacyBackgroundSizeShorthandBehavior;
3095 const int cMaxFillProperties = 9;
3097 bool CSSParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* properties, int numProperties, bool important)
3099 ASSERT(numProperties <= cMaxFillProperties);
3100 if (numProperties > cMaxFillProperties)
3103 ShorthandScope scope(this, propId);
3105 bool parsedProperty[cMaxFillProperties] = { false };
3106 RefPtr<CSSValue> values[cMaxFillProperties];
3107 RefPtr<CSSValue> clipValue;
3108 RefPtr<CSSValue> positionYValue;
3109 RefPtr<CSSValue> repeatYValue;
3110 bool foundClip = false;
3112 bool foundPositionCSSProperty = false;
3114 while (m_valueList->current()) {
3115 CSSParserValue* val = m_valueList->current();
3116 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3117 // We hit the end. Fill in all remaining values with the initial value.
3118 m_valueList->next();
3119 for (i = 0; i < numProperties; ++i) {
3120 if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i])
3121 // Color is not allowed except as the last item in a list for backgrounds.
3122 // Reject the entire property.
3125 if (!parsedProperty[i] && properties[i] != CSSPropertyBackgroundColor) {
3126 addFillValue(values[i], cssValuePool().createImplicitInitialValue());
3127 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3128 addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
3129 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3130 addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
3131 if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) {
3132 // If background-origin wasn't present, then reset background-clip also.
3133 addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
3136 parsedProperty[i] = false;
3138 if (!m_valueList->current())
3142 bool sizeCSSPropertyExpected = false;
3143 if (isForwardSlashOperator(val) && foundPositionCSSProperty) {
3144 sizeCSSPropertyExpected = true;
3145 m_valueList->next();
3148 foundPositionCSSProperty = false;
3150 for (i = 0; !found && i < numProperties; ++i) {
3152 if (sizeCSSPropertyExpected && (properties[i] != CSSPropertyBackgroundSize && properties[i] != CSSPropertyWebkitMaskSize))
3154 if (!sizeCSSPropertyExpected && (properties[i] == CSSPropertyBackgroundSize || properties[i] == CSSPropertyWebkitMaskSize))
3157 if (!parsedProperty[i]) {
3158 RefPtr<CSSValue> val1;
3159 RefPtr<CSSValue> val2;
3160 CSSPropertyID propId1, propId2;
3161 CSSParserValue* parserValue = m_valueList->current();
3162 if (parseFillProperty(properties[i], propId1, propId2, val1, val2)) {
3163 parsedProperty[i] = found = true;
3164 addFillValue(values[i], val1.release());
3165 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3166 addFillValue(positionYValue, val2.release());
3167 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3168 addFillValue(repeatYValue, val2.release());
3169 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
3170 // Reparse the value as a clip, and see if we succeed.
3171 if (parseBackgroundClip(parserValue, val1))
3172 addFillValue(clipValue, val1.release()); // The property parsed successfully.
3174 addFillValue(clipValue, cssValuePool().createImplicitInitialValue()); // Some value was used for origin that is not supported by clip. Just reset clip instead.
3176 if (properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip)
3178 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3179 foundPositionCSSProperty = true;
3184 // if we didn't find at least one match, this is an
3185 // invalid shorthand and we have to ignore it
3190 // Now add all of the properties we found.
3191 for (i = 0; i < numProperties; i++) {
3192 // Fill in any remaining properties with the initial value.
3193 if (!parsedProperty[i]) {
3194 addFillValue(values[i], cssValuePool().createImplicitInitialValue());
3195 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3196 addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
3197 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3198 addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
3199 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
3200 // If background-origin wasn't present, then reset background-clip also.
3201 addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
3204 if (properties[i] == CSSPropertyBackgroundPosition) {
3205 addProperty(CSSPropertyBackgroundPositionX, values[i].release(), important);
3206 // it's OK to call positionYValue.release() since we only see CSSPropertyBackgroundPosition once
3207 addProperty(CSSPropertyBackgroundPositionY, positionYValue.release(), important);
3208 } else if (properties[i] == CSSPropertyWebkitMaskPosition) {
3209 addProperty(CSSPropertyWebkitMaskPositionX, values[i].release(), important);
3210 // it's OK to call positionYValue.release() since we only see CSSPropertyWebkitMaskPosition once
3211 addProperty(CSSPropertyWebkitMaskPositionY, positionYValue.release(), important);
3212 } else if (properties[i] == CSSPropertyBackgroundRepeat) {
3213 addProperty(CSSPropertyBackgroundRepeatX, values[i].release(), important);
3214 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
3215 addProperty(CSSPropertyBackgroundRepeatY, repeatYValue.release(), important);
3216 } else if (properties[i] == CSSPropertyWebkitMaskRepeat) {
3217 addProperty(CSSPropertyWebkitMaskRepeatX, values[i].release(), important);
3218 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
3219 addProperty(CSSPropertyWebkitMaskRepeatY, repeatYValue.release(), important);
3220 } else if ((properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) && !foundClip)
3221 // Value is already set while updating origin
3223 else if (properties[i] == CSSPropertyBackgroundSize && !parsedProperty[i] && useLegacyBackgroundSizeShorthandBehavior())
3226 addProperty(properties[i], values[i].release(), important);
3228 // Add in clip values when we hit the corresponding origin property.
3229 if (properties[i] == CSSPropertyBackgroundOrigin && !foundClip)
3230 addProperty(CSSPropertyBackgroundClip, clipValue.release(), important);
3231 else if (properties[i] == CSSPropertyWebkitMaskOrigin && !foundClip)
3232 addProperty(CSSPropertyWebkitMaskClip, clipValue.release(), important);
3238 void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
3241 if (lval->isValueList())
3242 toCSSValueList(lval.get())->append(rval);
3244 PassRefPtr<CSSValue> oldVal(lval.release());
3245 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3246 list->append(oldVal);
3255 bool CSSParser::parseAnimationShorthand(bool important)
3257 const StylePropertyShorthand& animationProperties = webkitAnimationShorthandForParsing();
3258 const unsigned numProperties = 7;
3260 // The list of properties in the shorthand should be the same
3261 // length as the list with animation name in last position, even though they are
3262 // in a different order.
3263 ASSERT(numProperties == webkitAnimationShorthandForParsing().length());
3264 ASSERT(numProperties == webkitAnimationShorthand().length());
3266 ShorthandScope scope(this, CSSPropertyWebkitAnimation);
3268 bool parsedProperty[numProperties] = { false };
3269 AnimationParseContext context;
3270 RefPtr<CSSValue> values[numProperties];
3273 while (m_valueList->current()) {
3274 CSSParserValue* val = m_valueList->current();
3275 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3276 // We hit the end. Fill in all remaining values with the initial value.
3277 m_valueList->next();
3278 for (i = 0; i < numProperties; ++i) {
3279 if (!parsedProperty[i])
3280 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3281 parsedProperty[i] = false;
3283 if (!m_valueList->current())
3285 context.commitFirstAnimation();
3289 for (i = 0; i < numProperties; ++i) {
3290 if (!parsedProperty[i]) {
3291 RefPtr<CSSValue> val;
3292 if (parseAnimationProperty(animationProperties.properties()[i], val, context)) {
3293 parsedProperty[i] = found = true;
3294 addAnimationValue(values[i], val.release());
3299 // There are more values to process but 'none' or 'all' were already defined as the animation property, the declaration becomes invalid.
3300 if (!context.animationPropertyKeywordAllowed() && context.hasCommittedFirstAnimation())
3304 // if we didn't find at least one match, this is an
3305 // invalid shorthand and we have to ignore it
3310 for (i = 0; i < numProperties; ++i) {
3311 // If we didn't find the property, set an intial value.
3312 if (!parsedProperty[i])
3313 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3315 addProperty(animationProperties.properties()[i], values[i].release(), important);
3321 bool CSSParser::parseTransitionShorthand(CSSPropertyID propId, bool important)
3323 const unsigned numProperties = 4;
3324 const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
3325 ASSERT(numProperties == shorthand.length());
3327 ShorthandScope scope(this, propId);
3329 bool parsedProperty[numProperties] = { false };
3330 AnimationParseContext context;
3331 RefPtr<CSSValue> values[numProperties];
3334 while (m_valueList->current()) {
3335 CSSParserValue* val = m_valueList->current();
3336 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3337 // We hit the end. Fill in all remaining values with the initial value.
3338 m_valueList->next();
3339 for (i = 0; i < numProperties; ++i) {
3340 if (!parsedProperty[i])
3341 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3342 parsedProperty[i] = false;
3344 if (!m_valueList->current())
3346 context.commitFirstAnimation();
3350 for (i = 0; !found && i < numProperties; ++i) {
3351 if (!parsedProperty[i]) {
3352 RefPtr<CSSValue> val;
3353 if (parseAnimationProperty(shorthand.properties()[i], val, context)) {
3354 parsedProperty[i] = found = true;
3355 addAnimationValue(values[i], val.release());
3358 // There are more values to process but 'none' or 'all' were already defined as the animation property, the declaration becomes invalid.
3359 if (!context.animationPropertyKeywordAllowed() && context.hasCommittedFirstAnimation())
3364 // if we didn't find at least one match, this is an
3365 // invalid shorthand and we have to ignore it
3370 // Fill in any remaining properties with the initial value.
3371 for (i = 0; i < numProperties; ++i) {
3372 if (!parsedProperty[i])
3373 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3376 // Now add all of the properties we found.
3377 for (i = 0; i < numProperties; i++)
3378 addPropertyWithPrefixingVariant(shorthand.properties()[i], values[i].release(), important);
3383 bool CSSParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthand& shorthand, bool important)
3385 // We try to match as many properties as possible
3386 // We set up an array of booleans to mark which property has been found,
3387 // and we try to search for properties until it makes no longer any sense.
3388 ShorthandScope scope(this, propId);
3391 unsigned propertiesParsed = 0;
3392 bool propertyFound[6]= { false, false, false, false, false, false }; // 6 is enough size.
3394 while (m_valueList->current()) {
3396 for (unsigned propIndex = 0; !found && propIndex < shorthand.length(); ++propIndex) {
3397 if (!propertyFound[propIndex] && parseValue(shorthand.properties()[propIndex], important)) {
3398 propertyFound[propIndex] = found = true;
3403 // if we didn't find at least one match, this is an
3404 // invalid shorthand and we have to ignore it