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 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 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 "CSSFontFaceRule.h"
37 #include "CSSFontFaceSrcValue.h"
38 #include "CSSFunctionValue.h"
39 #include "CSSGradientValue.h"
40 #include "CSSImageValue.h"
41 #include "CSSInheritedValue.h"
42 #include "CSSInitialValue.h"
43 #include "CSSLineBoxContainValue.h"
44 #include "CSSMediaRule.h"
45 #include "CSSPageRule.h"
46 #include "CSSPrimitiveValue.h"
47 #include "CSSPropertySourceData.h"
48 #include "CSSReflectValue.h"
49 #include "CSSSelector.h"
50 #include "CSSStyleSheet.h"
51 #include "CSSTimingFunctionValue.h"
52 #include "CSSUnicodeRangeValue.h"
53 #include "CSSValueKeywords.h"
54 #include "CSSValueList.h"
55 #include "CSSValuePool.h"
56 #if ENABLE(CSS_VARIABLES)
57 #include "CSSVariableValue.h"
61 #include "FloatConversion.h"
62 #include "FontFeatureValue.h"
63 #include "FontValue.h"
64 #include "HTMLParserIdioms.h"
65 #include "HashTools.h"
66 #include "HistogramSupport.h"
67 #include "MediaList.h"
68 #include "MediaQueryExp.h"
72 #include "RenderTheme.h"
73 #include "RuntimeEnabledFeatures.h"
74 #include "SVGParserUtilities.h"
76 #include "ShadowValue.h"
77 #include "StylePropertySet.h"
78 #include "StylePropertyShorthand.h"
79 #include "StyleRule.h"
80 #include "StyleRuleImport.h"
81 #include "StyleSheetContents.h"
82 #include "TextEncoding.h"
83 #include "WebKitCSSKeyframeRule.h"
84 #include "WebKitCSSKeyframesRule.h"
85 #include "WebKitCSSRegionRule.h"
86 #include "WebKitCSSTransformValue.h"
88 #include <wtf/BitArray.h>
89 #include <wtf/HexNumber.h>
91 #include <wtf/text/StringBuffer.h>
92 #include <wtf/text/StringBuilder.h>
93 #include <wtf/text/StringImpl.h>
95 #if ENABLE(CSS_IMAGE_SET)
96 #include "CSSImageSetValue.h"
99 #if ENABLE(CSS_FILTERS)
100 #include "WebKitCSSFilterValue.h"
102 #include "WebKitCSSSVGDocumentValue.h"
106 #if ENABLE(CSS_SHADERS)
107 #include "WebKitCSSArrayFunctionValue.h"
108 #include "WebKitCSSMixFunctionValue.h"
109 #include "WebKitCSSShaderValue.h"
112 #if ENABLE(DASHBOARD_SUPPORT)
113 #include "DashboardRegion.h"
119 extern int cssyydebug;
122 extern int cssyyparse(WebCore::CSSParser*);
134 class ImplicitScope {
135 WTF_MAKE_NONCOPYABLE(ImplicitScope);
137 ImplicitScope(WebCore::CSSParser* parser, PropertyType propertyType)
140 m_parser->m_implicitShorthand = propertyType == PropertyImplicit;
145 m_parser->m_implicitShorthand = false;
149 WebCore::CSSParser* m_parser;
156 static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX;
157 static const double MAX_SCALE = 1000000;
159 template <unsigned N>
160 static bool equal(const CSSParserString& a, const char (&b)[N])
162 unsigned length = N - 1; // Ignore the trailing null character
163 if (a.length() != length)
166 return a.is8Bit() ? WTF::equal(a.characters8(), reinterpret_cast<const LChar*>(b), length) : WTF::equal(a.characters16(), reinterpret_cast<const LChar*>(b), length);
169 template <unsigned N>
170 static bool equalIgnoringCase(const CSSParserString& a, const char (&b)[N])
172 unsigned length = N - 1; // Ignore the trailing null character
173 if (a.length() != length)
176 return a.is8Bit() ? WTF::equalIgnoringCase(b, a.characters8(), length) : WTF::equalIgnoringCase(b, a.characters16(), length);
179 template <unsigned N>
180 static bool equalIgnoringCase(CSSParserValue* value, const char (&b)[N])
182 ASSERT(value->unit == CSSPrimitiveValue::CSS_IDENT || value->unit == CSSPrimitiveValue::CSS_STRING);
183 return equalIgnoringCase(value->string, b);
186 static bool hasPrefix(const char* string, unsigned length, const char* prefix)
188 for (unsigned i = 0; i < length; ++i) {
191 if (string[i] != prefix[i])
197 static PassRefPtr<CSSPrimitiveValue> createPrimitiveValuePair(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> second)
199 return cssValuePool().createValue(Pair::create(first, second));
202 const CSSParserContext& strictCSSParserContext()
204 DEFINE_STATIC_LOCAL(CSSParserContext, strictContext, (CSSStrictMode));
205 return strictContext;
208 CSSParserContext::CSSParserContext(CSSParserMode mode, const KURL& baseURL)
211 , isHTMLDocument(false)
212 , isCSSCustomFilterEnabled(false)
213 , isCSSStickyPositionEnabled(false)
214 , isCSSRegionsEnabled(false)
215 , isCSSGridLayoutEnabled(false)
216 #if ENABLE(CSS_VARIABLES)
217 , isCSSVariablesEnabled(false)
219 , needsSiteSpecificQuirks(false)
220 , enforcesCSSMIMETypeInNoQuirksMode(true)
224 CSSParserContext::CSSParserContext(Document* document, const KURL& baseURL, const String& charset)
225 : baseURL(baseURL.isNull() ? document->baseURL() : baseURL)
227 , mode(document->inQuirksMode() ? CSSQuirksMode : CSSStrictMode)
228 , isHTMLDocument(document->isHTMLDocument())
229 , isCSSCustomFilterEnabled(document->settings() ? document->settings()->isCSSCustomFilterEnabled() : false)
230 , isCSSStickyPositionEnabled(document->cssStickyPositionEnabled())
231 , isCSSRegionsEnabled(document->cssRegionsEnabled())
232 , isCSSGridLayoutEnabled(document->cssGridLayoutEnabled())
233 #if ENABLE(CSS_VARIABLES)
234 , isCSSVariablesEnabled(document->settings() ? document->settings()->cssVariablesEnabled() : false)
236 , needsSiteSpecificQuirks(document->settings() ? document->settings()->needsSiteSpecificQuirks() : false)
237 , enforcesCSSMIMETypeInNoQuirksMode(!document->settings() || document->settings()->enforceCSSMIMETypeInNoQuirksMode())
241 bool operator==(const CSSParserContext& a, const CSSParserContext& b)
243 return a.baseURL == b.baseURL
244 && a.charset == b.charset
246 && a.isHTMLDocument == b.isHTMLDocument
247 && a.isCSSCustomFilterEnabled == b.isCSSCustomFilterEnabled
248 && a.isCSSStickyPositionEnabled == b.isCSSStickyPositionEnabled
249 && a.isCSSRegionsEnabled == b.isCSSRegionsEnabled
250 && a.isCSSGridLayoutEnabled == b.isCSSGridLayoutEnabled
251 #if ENABLE(CSS_VARIABLES)
252 && a.isCSSVariablesEnabled == b.isCSSVariablesEnabled
254 && a.needsSiteSpecificQuirks == b.needsSiteSpecificQuirks
255 && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode;
258 CSSParser::CSSParser(const CSSParserContext& context)
261 , m_id(CSSPropertyInvalid)
263 #if ENABLE(CSS3_CONDITIONAL_RULES)
264 , m_supportsCondition(false)
266 , m_selectorListForParseSelector(0)
267 , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES)
268 , m_inParseShorthand(0)
269 , m_currentShorthand(CSSPropertyInvalid)
270 , m_implicitShorthand(false)
271 , m_hasFontFaceOnlyValues(false)
272 , m_hadSyntacticallyValidCSSRule(false)
273 , m_defaultNamespace(starAtom)
274 , m_parsedTextPrefixLength(0)
275 , m_propertyRange(UINT_MAX, UINT_MAX)
276 , m_ruleSourceDataResult(0)
277 , m_parsingMode(NormalMode)
278 , m_is8BitSource(false)
279 , m_currentCharacter8(0)
280 , m_currentCharacter16(0)
284 , m_lastSelectorLineNumber(0)
285 , m_allowImportRules(true)
286 , m_allowNamespaceDeclarations(true)
287 #if ENABLE(CSS_DEVICE_ADAPTATION)
288 , m_inViewport(false)
294 m_tokenStart.ptr8 = 0;
295 CSSPropertySourceData::init();
298 CSSParser::~CSSParser()
302 deleteAllValues(m_floatingSelectors);
303 deleteAllValues(m_floatingSelectorVectors);
304 deleteAllValues(m_floatingValueLists);
305 deleteAllValues(m_floatingFunctions);
308 template <typename CharacterType>
309 ALWAYS_INLINE static void makeLower(const CharacterType* input, CharacterType* output, unsigned length)
311 // FIXME: If we need Unicode lowercasing here, then we probably want the real kind
312 // that can potentially change the length of the string rather than the character
313 // by character kind. If we don't need Unicode lowercasing, it would be good to
314 // simplify this function.
316 if (charactersAreAllASCII(input, length)) {
317 // Fast case for all-ASCII.
318 for (unsigned i = 0; i < length; i++)
319 output[i] = toASCIILower(input[i]);
321 for (unsigned i = 0; i < length; i++)
322 output[i] = Unicode::toLower(input[i]);
326 void CSSParserString::lower()
329 makeLower(characters8(), characters8(), length());
333 makeLower(characters16(), characters16(), length());
336 AtomicString CSSParserString::lowerSubstring(unsigned position, unsigned length) const
338 ASSERT(m_length >= position + length);
340 RefPtr<StringImpl> result;
344 result = StringImpl::createUninitialized(length, buffer);
345 makeLower(characters8() + position, buffer, length);
348 result = StringImpl::createUninitialized(length, buffer);
349 makeLower(characters16() + position, buffer, length);
352 return AtomicString(result);
355 void CSSParser::setupParser(const char* prefix, unsigned prefixLength, const String& string, const char* suffix, unsigned suffixLength)
357 m_parsedTextPrefixLength = prefixLength;
358 unsigned stringLength = string.length();
359 unsigned length = stringLength + m_parsedTextPrefixLength + suffixLength + 1;
362 if (!stringLength || string.is8Bit()) {
363 m_dataStart8 = adoptArrayPtr(new LChar[length]);
364 for (unsigned i = 0; i < m_parsedTextPrefixLength; i++)
365 m_dataStart8[i] = prefix[i];
368 memcpy(m_dataStart8.get() + m_parsedTextPrefixLength, string.characters8(), stringLength * sizeof(LChar));
370 unsigned start = m_parsedTextPrefixLength + stringLength;
371 unsigned end = start + suffixLength;
372 for (unsigned i = start; i < end; i++)
373 m_dataStart8[i] = suffix[i - start];
375 m_dataStart8[length - 1] = 0;
377 m_is8BitSource = true;
378 m_currentCharacter8 = m_dataStart8.get();
379 m_currentCharacter16 = 0;
380 setTokenStart<LChar>(m_currentCharacter8);
381 m_lexFunc = &CSSParser::realLex<LChar>;
385 m_dataStart16 = adoptArrayPtr(new UChar[length]);
386 for (unsigned i = 0; i < m_parsedTextPrefixLength; i++)
387 m_dataStart16[i] = prefix[i];
389 memcpy(m_dataStart16.get() + m_parsedTextPrefixLength, string.characters(), stringLength * sizeof(UChar));
391 unsigned start = m_parsedTextPrefixLength + stringLength;
392 unsigned end = start + suffixLength;
393 for (unsigned i = start; i < end; i++)
394 m_dataStart16[i] = suffix[i - start];
396 m_dataStart16[length - 1] = 0;
398 m_is8BitSource = false;
399 m_currentCharacter8 = 0;
400 m_currentCharacter16 = m_dataStart16.get();
401 setTokenStart<UChar>(m_currentCharacter16);
402 m_lexFunc = &CSSParser::realLex<UChar>;
405 void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, RuleSourceDataList* ruleSourceDataResult)
407 setStyleSheet(sheet);
408 m_defaultNamespace = starAtom; // Reset the default namespace.
409 if (ruleSourceDataResult)
410 m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
411 m_ruleSourceDataResult = ruleSourceDataResult;
413 m_lineNumber = startLineNumber;
414 setupParser("", string, "");
416 sheet->shrinkToFit();
417 m_currentRuleDataStack.clear();
418 m_ruleSourceDataResult = 0;
422 PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string)
424 setStyleSheet(sheet);
425 m_allowNamespaceDeclarations = false;
426 setupParser("@-webkit-rule{", string, "} ");
428 return m_rule.release();
431 PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet, const String& string)
433 setStyleSheet(sheet);
434 setupParser("@-webkit-keyframe-rule{ ", string, "} ");
436 return m_keyframe.release();
439 #if ENABLE(CSS3_CONDITIONAL_RULES)
440 bool CSSParser::parseSupportsCondition(const String& string)
442 m_supportsCondition = false;
443 setupParser("@-webkit-supports-condition{ ", string, "} ");
445 return m_supportsCondition;
449 static inline bool isColorPropertyID(CSSPropertyID propertyId)
451 switch (propertyId) {
452 case CSSPropertyColor:
453 case CSSPropertyBackgroundColor:
454 case CSSPropertyBorderBottomColor:
455 case CSSPropertyBorderLeftColor:
456 case CSSPropertyBorderRightColor:
457 case CSSPropertyBorderTopColor:
458 case CSSPropertyOutlineColor:
459 case CSSPropertyTextLineThroughColor:
460 case CSSPropertyTextOverlineColor:
461 case CSSPropertyTextUnderlineColor:
462 case CSSPropertyWebkitBorderAfterColor:
463 case CSSPropertyWebkitBorderBeforeColor:
464 case CSSPropertyWebkitBorderEndColor:
465 case CSSPropertyWebkitBorderStartColor:
466 case CSSPropertyWebkitColumnRuleColor:
467 case CSSPropertyWebkitTextEmphasisColor:
468 case CSSPropertyWebkitTextFillColor:
469 case CSSPropertyWebkitTextStrokeColor:
476 static bool parseColorValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
478 ASSERT(!string.isEmpty());
479 bool strict = isStrictParserMode(cssParserMode);
480 if (!isColorPropertyID(propertyId))
482 CSSParserString cssString;
483 cssString.init(string);
484 int valueID = cssValueKeywordID(cssString);
485 bool validPrimitive = false;
486 if (valueID == CSSValueWebkitText)
487 validPrimitive = true;
488 else if (valueID == CSSValueCurrentcolor)
489 validPrimitive = true;
490 else if ((valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID == CSSValueMenu
491 || (valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWebkitText && !strict)) {
492 validPrimitive = true;
495 if (validPrimitive) {
496 RefPtr<CSSValue> value = cssValuePool().createIdentifierValue(valueID);
497 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
501 if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
503 RefPtr<CSSValue> value = cssValuePool().createColorValue(color);
504 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
508 static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acceptsNegativeNumbers)
510 switch (propertyId) {
511 case CSSPropertyFontSize:
512 case CSSPropertyHeight:
513 case CSSPropertyWidth:
514 case CSSPropertyMinHeight:
515 case CSSPropertyMinWidth:
516 case CSSPropertyPaddingBottom:
517 case CSSPropertyPaddingLeft:
518 case CSSPropertyPaddingRight:
519 case CSSPropertyPaddingTop:
520 case CSSPropertyWebkitLogicalWidth:
521 case CSSPropertyWebkitLogicalHeight:
522 case CSSPropertyWebkitMinLogicalWidth:
523 case CSSPropertyWebkitMinLogicalHeight:
524 case CSSPropertyWebkitPaddingAfter:
525 case CSSPropertyWebkitPaddingBefore:
526 case CSSPropertyWebkitPaddingEnd:
527 case CSSPropertyWebkitPaddingStart:
528 acceptsNegativeNumbers = false;
530 #if ENABLE(CSS_EXCLUSIONS)
531 case CSSPropertyWebkitShapeMargin:
532 case CSSPropertyWebkitShapePadding:
533 acceptsNegativeNumbers = false;
534 return RuntimeEnabledFeatures::cssExclusionsEnabled();
536 case CSSPropertyBottom:
537 case CSSPropertyLeft:
538 case CSSPropertyMarginBottom:
539 case CSSPropertyMarginLeft:
540 case CSSPropertyMarginRight:
541 case CSSPropertyMarginTop:
542 case CSSPropertyRight:
543 case CSSPropertyTextIndent:
545 case CSSPropertyWebkitMarginAfter:
546 case CSSPropertyWebkitMarginBefore:
547 case CSSPropertyWebkitMarginEnd:
548 case CSSPropertyWebkitMarginStart:
549 acceptsNegativeNumbers = true;
556 template <typename CharacterType>
557 static inline bool parseSimpleLength(const CharacterType* characters, unsigned& length, CSSPrimitiveValue::UnitTypes& unit, double& number)
559 if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') {
561 unit = CSSPrimitiveValue::CSS_PX;
562 } else if (length > 1 && characters[length - 1] == '%') {
564 unit = CSSPrimitiveValue::CSS_PERCENTAGE;
567 // We rely on charactersToDouble for validation as well. The function
568 // will set "ok" to "false" if the entire passed-in character range does
569 // not represent a double.
571 number = charactersToDouble(characters, length, &ok);
575 static bool parseSimpleLengthValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
577 ASSERT(!string.isEmpty());
578 bool acceptsNegativeNumbers;
579 if (!isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers))
582 unsigned length = string.length();
584 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
586 if (string.is8Bit()) {
587 if (!parseSimpleLength(string.characters8(), length, unit, number))
590 if (!parseSimpleLength(string.characters16(), length, unit, number))
594 if (unit == CSSPrimitiveValue::CSS_NUMBER) {
595 if (number && isStrictParserMode(cssParserMode))
597 unit = CSSPrimitiveValue::CSS_PX;
599 if (number < 0 && !acceptsNegativeNumbers)
602 RefPtr<CSSValue> value = cssValuePool().createValue(number, unit);
603 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
607 static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int valueID, const CSSParserContext& parserContext)
612 switch (propertyId) {
613 case CSSPropertyBorderCollapse: // collapse | separate | inherit
614 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate)
617 case CSSPropertyBorderTopStyle: // <border-style> | inherit
618 case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed |
619 case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset
620 case CSSPropertyBorderLeftStyle:
621 case CSSPropertyWebkitBorderAfterStyle:
622 case CSSPropertyWebkitBorderBeforeStyle:
623 case CSSPropertyWebkitBorderEndStyle:
624 case CSSPropertyWebkitBorderStartStyle:
625 case CSSPropertyWebkitColumnRuleStyle:
626 if (valueID >= CSSValueNone && valueID <= CSSValueDouble)
629 case CSSPropertyBoxSizing:
630 if (valueID == CSSValueBorderBox || valueID == CSSValueContentBox)
633 case CSSPropertyCaptionSide: // top | bottom | left | right | inherit
634 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueTop || valueID == CSSValueBottom)
637 case CSSPropertyClear: // none | left | right | both | inherit
638 if (valueID == CSSValueNone || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueBoth)
641 case CSSPropertyDirection: // ltr | rtl | inherit
642 if (valueID == CSSValueLtr || valueID == CSSValueRtl)
645 case CSSPropertyDisplay:
646 // inline | block | list-item | run-in | inline-block | table |
647 // inline-table | table-row-group | table-header-group | table-footer-group | table-row |
648 // table-column-group | table-column | table-cell | table-caption | -webkit-box | -webkit-inline-box | none | inherit
649 // -webkit-flex | -webkit-inline-flex | -webkit-grid | -webkit-inline-grid
650 if ((valueID >= CSSValueInline && valueID <= CSSValueWebkitInlineFlex) || valueID == CSSValueNone)
652 if (parserContext.isCSSGridLayoutEnabled && (valueID == CSSValueWebkitGrid || valueID == CSSValueWebkitInlineGrid))
656 case CSSPropertyEmptyCells: // show | hide | inherit
657 if (valueID == CSSValueShow || valueID == CSSValueHide)
660 case CSSPropertyFloat: // left | right | none | center (for buggy CSS, maps to none)
661 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueNone || valueID == CSSValueCenter)
664 case CSSPropertyFontStyle: // normal | italic | oblique | inherit
665 if (valueID == CSSValueNormal || valueID == CSSValueItalic || valueID == CSSValueOblique)
668 case CSSPropertyImageRendering: // auto | optimizeContrast
669 if (valueID == CSSValueAuto || valueID == CSSValueWebkitOptimizeContrast)
672 case CSSPropertyListStylePosition: // inside | outside | inherit
673 if (valueID == CSSValueInside || valueID == CSSValueOutside)
676 case CSSPropertyListStyleType:
677 // See section CSS_PROP_LIST_STYLE_TYPE of file CSSValueKeywords.in
678 // for the list of supported list-style-types.
679 if ((valueID >= CSSValueDisc && valueID <= CSSValueKatakanaIroha) || valueID == CSSValueNone)
682 case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto | inherit
683 if (valueID == CSSValueAuto || valueID == CSSValueNone || (valueID >= CSSValueInset && valueID <= CSSValueDouble))
686 case CSSPropertyOverflowWrap: // normal | break-word
687 case CSSPropertyWordWrap:
688 if (valueID == CSSValueNormal || valueID == CSSValueBreakWord)
691 case CSSPropertyOverflowX: // visible | hidden | scroll | auto | marquee | overlay | inherit
692 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitMarquee)
695 case CSSPropertyOverflowY: // visible | hidden | scroll | auto | marquee | overlay | inherit | -webkit-paged-x | -webkit-paged-y
696 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitMarquee || valueID == CSSValueWebkitPagedX || valueID == CSSValueWebkitPagedY)
699 case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | inherit
700 case CSSPropertyPageBreakBefore:
701 case CSSPropertyWebkitColumnBreakAfter:
702 case CSSPropertyWebkitColumnBreakBefore:
703 if (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight)
706 case CSSPropertyPageBreakInside: // avoid | auto | inherit
707 case CSSPropertyWebkitColumnBreakInside:
708 if (valueID == CSSValueAuto || valueID == CSSValueAvoid)
711 case CSSPropertyPointerEvents:
712 // none | visiblePainted | visibleFill | visibleStroke | visible |
713 // painted | fill | stroke | auto | all | inherit
714 if (valueID == CSSValueVisible || valueID == CSSValueNone || valueID == CSSValueAll || valueID == CSSValueAuto || (valueID >= CSSValueVisiblepainted && valueID <= CSSValueStroke))
717 case CSSPropertyPosition: // static | relative | absolute | fixed | sticky | inherit
718 if (valueID == CSSValueStatic || valueID == CSSValueRelative || valueID == CSSValueAbsolute || valueID == CSSValueFixed
719 #if ENABLE(CSS_STICKY_POSITION)
720 || (parserContext.isCSSStickyPositionEnabled && valueID == CSSValueWebkitSticky)
725 case CSSPropertyResize: // none | both | horizontal | vertical | auto
726 if (valueID == CSSValueNone || valueID == CSSValueBoth || valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueAuto)
729 case CSSPropertySpeak: // none | normal | spell-out | digits | literal-punctuation | no-punctuation | inherit
730 if (valueID == CSSValueNone || valueID == CSSValueNormal || valueID == CSSValueSpellOut || valueID == CSSValueDigits || valueID == CSSValueLiteralPunctuation || valueID == CSSValueNoPunctuation)
733 case CSSPropertyTableLayout: // auto | fixed | inherit
734 if (valueID == CSSValueAuto || valueID == CSSValueFixed)
737 case CSSPropertyTextLineThroughMode:
738 case CSSPropertyTextOverlineMode:
739 case CSSPropertyTextUnderlineMode:
740 if (valueID == CSSValueContinuous || valueID == CSSValueSkipWhiteSpace)
743 case CSSPropertyTextLineThroughStyle:
744 case CSSPropertyTextOverlineStyle:
745 case CSSPropertyTextUnderlineStyle:
746 if (valueID == CSSValueNone || valueID == CSSValueSolid || valueID == CSSValueDouble || valueID == CSSValueDashed || valueID == CSSValueDotDash || valueID == CSSValueDotDotDash || valueID == CSSValueWave)
749 case CSSPropertyTextOverflow: // clip | ellipsis
750 if (valueID == CSSValueClip || valueID == CSSValueEllipsis)
753 case CSSPropertyTextRendering: // auto | optimizeSpeed | optimizeLegibility | geometricPrecision
754 if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizelegibility || valueID == CSSValueGeometricprecision)
757 case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none | inherit
758 if ((valueID >= CSSValueCapitalize && valueID <= CSSValueLowercase) || valueID == CSSValueNone)
761 case CSSPropertyVisibility: // visible | hidden | collapse | inherit
762 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueCollapse)
765 case CSSPropertyWebkitAppearance:
766 if ((valueID >= CSSValueCheckbox && valueID <= CSSValueTextarea) || valueID == CSSValueNone)
769 case CSSPropertyWebkitBackfaceVisibility:
770 if (valueID == CSSValueVisible || valueID == CSSValueHidden)
773 #if ENABLE(CSS_COMPOSITING)
774 case CSSPropertyWebkitBlendMode:
775 if (valueID == CSSValueNormal || valueID == CSSValueMultiply || valueID == CSSValueScreen || valueID == CSSValueOverlay
776 || valueID == CSSValueDarken || valueID == CSSValueLighten || valueID == CSSValueColorDodge || valueID == CSSValueColorBurn
777 || valueID == CSSValueHardLight || valueID == CSSValueSoftLight || valueID == CSSValueDifference || valueID == CSSValueExclusion
778 || valueID == CSSValueHue || valueID == CSSValueSaturation || valueID == CSSValueColor || valueID == CSSValueLuminosity)
782 case CSSPropertyWebkitBorderFit:
783 if (valueID == CSSValueBorder || valueID == CSSValueLines)
786 case CSSPropertyWebkitBoxAlign:
787 if (valueID == CSSValueStretch || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline)
790 #if ENABLE(CSS_BOX_DECORATION_BREAK)
791 case CSSPropertyWebkitBoxDecorationBreak:
792 if (valueID == CSSValueClone || valueID == CSSValueSlice)
796 case CSSPropertyWebkitBoxDirection:
797 if (valueID == CSSValueNormal || valueID == CSSValueReverse)
800 case CSSPropertyWebkitBoxLines:
801 if (valueID == CSSValueSingle || valueID == CSSValueMultiple)
804 case CSSPropertyWebkitBoxOrient:
805 if (valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueInlineAxis || valueID == CSSValueBlockAxis)
808 case CSSPropertyWebkitBoxPack:
809 if (valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueJustify)
812 case CSSPropertyWebkitColorCorrection:
813 if (valueID == CSSValueSrgb || valueID == CSSValueDefault)
816 case CSSPropertyWebkitAlignContent:
817 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround || valueID == CSSValueStretch)
820 case CSSPropertyWebkitAlignItems:
821 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch)
824 case CSSPropertyWebkitAlignSelf:
825 if (valueID == CSSValueAuto || valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch)
828 case CSSPropertyWebkitFlexDirection:
829 if (valueID == CSSValueRow || valueID == CSSValueRowReverse || valueID == CSSValueColumn || valueID == CSSValueColumnReverse)
832 case CSSPropertyWebkitFlexWrap:
833 if (valueID == CSSValueNowrap || valueID == CSSValueWrap || valueID == CSSValueWrapReverse)
836 case CSSPropertyWebkitJustifyContent:
837 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround)
840 case CSSPropertyWebkitFontKerning:
841 if (valueID == CSSValueAuto || valueID == CSSValueNormal || valueID == CSSValueNone)
844 case CSSPropertyWebkitFontSmoothing:
845 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueAntialiased || valueID == CSSValueSubpixelAntialiased)
848 case CSSPropertyWebkitHyphens:
849 if (valueID == CSSValueNone || valueID == CSSValueManual || valueID == CSSValueAuto)
852 case CSSPropertyWebkitGridAutoFlow:
853 if (valueID == CSSValueNone || valueID == CSSValueRow || valueID == CSSValueColumn)
856 case CSSPropertyWebkitLineAlign:
857 if (valueID == CSSValueNone || valueID == CSSValueEdges)
860 case CSSPropertyWebkitLineBreak: // auto | loose | normal | strict | after-white-space
861 if (valueID == CSSValueAuto || valueID == CSSValueLoose || valueID == CSSValueNormal || valueID == CSSValueStrict || valueID == CSSValueAfterWhiteSpace)
864 case CSSPropertyWebkitLineSnap:
865 if (valueID == CSSValueNone || valueID == CSSValueBaseline || valueID == CSSValueContain)
868 case CSSPropertyWebkitMarginAfterCollapse:
869 case CSSPropertyWebkitMarginBeforeCollapse:
870 case CSSPropertyWebkitMarginBottomCollapse:
871 case CSSPropertyWebkitMarginTopCollapse:
872 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate || valueID == CSSValueDiscard)
875 case CSSPropertyWebkitMarqueeDirection:
876 if (valueID == CSSValueForwards || valueID == CSSValueBackwards || valueID == CSSValueAhead || valueID == CSSValueReverse || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueDown
877 || valueID == CSSValueUp || valueID == CSSValueAuto)
880 case CSSPropertyWebkitMarqueeStyle:
881 if (valueID == CSSValueNone || valueID == CSSValueSlide || valueID == CSSValueScroll || valueID == CSSValueAlternate)
884 case CSSPropertyWebkitNbspMode: // normal | space
885 if (valueID == CSSValueNormal || valueID == CSSValueSpace)
888 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
889 case CSSPropertyWebkitOverflowScrolling:
890 if (valueID == CSSValueAuto || valueID == CSSValueTouch)
894 case CSSPropertyWebkitPrintColorAdjust:
895 if (valueID == CSSValueExact || valueID == CSSValueEconomy)
898 #if ENABLE(CSS_REGIONS)
899 case CSSPropertyWebkitRegionBreakAfter:
900 case CSSPropertyWebkitRegionBreakBefore:
901 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight))
904 case CSSPropertyWebkitRegionBreakInside:
905 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAvoid))
908 case CSSPropertyWebkitRegionOverflow:
909 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueBreak))
913 case CSSPropertyWebkitRtlOrdering:
914 if (valueID == CSSValueLogical || valueID == CSSValueVisual)
918 case CSSPropertyWebkitRubyPosition:
919 if (valueID == CSSValueBefore || valueID == CSSValueAfter)
923 #if ENABLE(CSS3_TEXT)
924 case CSSPropertyWebkitTextAlignLast:
925 // auto | start | end | left | right | center | justify
926 if ((valueID >= CSSValueLeft && valueID <= CSSValueJustify) || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueAuto)
930 case CSSPropertyWebkitTextCombine:
931 if (valueID == CSSValueNone || valueID == CSSValueHorizontal)
934 case CSSPropertyWebkitTextEmphasisPosition:
935 if (valueID == CSSValueOver || valueID == CSSValueUnder)
938 case CSSPropertyWebkitTextSecurity:
939 // disc | circle | square | none | inherit
940 if (valueID == CSSValueDisc || valueID == CSSValueCircle || valueID == CSSValueSquare || valueID == CSSValueNone)
943 case CSSPropertyWebkitTextSizeAdjust:
944 if (valueID == CSSValueAuto || valueID == CSSValueNone)
947 case CSSPropertyWebkitTransformStyle:
948 if (valueID == CSSValueFlat || valueID == CSSValuePreserve3d)
951 case CSSPropertyWebkitUserDrag: // auto | none | element
952 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueElement)
955 case CSSPropertyWebkitUserModify: // read-only | read-write
956 if (valueID == CSSValueReadOnly || valueID == CSSValueReadWrite || valueID == CSSValueReadWritePlaintextOnly)
959 case CSSPropertyWebkitUserSelect: // auto | none | text | all
960 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueText || valueID == CSSValueAll)
963 #if ENABLE(CSS_EXCLUSIONS)
964 case CSSPropertyWebkitWrapFlow:
965 if (!RuntimeEnabledFeatures::cssExclusionsEnabled())
967 if (valueID == CSSValueAuto || valueID == CSSValueBoth || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueMaximum || valueID == CSSValueClear)
970 case CSSPropertyWebkitWrapThrough:
971 if (!RuntimeEnabledFeatures::cssExclusionsEnabled())
973 if (valueID == CSSValueWrap || valueID == CSSValueNone)
977 case CSSPropertyWebkitWritingMode:
978 if (valueID >= CSSValueHorizontalTb && valueID <= CSSValueHorizontalBt)
981 case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit
982 if (valueID == CSSValueNormal || valueID == CSSValuePre || valueID == CSSValuePreWrap || valueID == CSSValuePreLine || valueID == CSSValueNowrap)
985 case CSSPropertyWordBreak: // normal | break-all | break-word (this is a custom extension)
986 if (valueID == CSSValueNormal || valueID == CSSValueBreakAll || valueID == CSSValueBreakWord)
990 ASSERT_NOT_REACHED();
996 static inline bool isKeywordPropertyID(CSSPropertyID propertyId)
998 switch (propertyId) {
999 case CSSPropertyBorderBottomStyle:
1000 case CSSPropertyBorderCollapse:
1001 case CSSPropertyBorderLeftStyle:
1002 case CSSPropertyBorderRightStyle:
1003 case CSSPropertyBorderTopStyle:
1004 case CSSPropertyBoxSizing:
1005 case CSSPropertyCaptionSide:
1006 case CSSPropertyClear:
1007 case CSSPropertyDirection:
1008 case CSSPropertyDisplay:
1009 case CSSPropertyEmptyCells:
1010 case CSSPropertyFloat:
1011 case CSSPropertyFontStyle:
1012 case CSSPropertyImageRendering:
1013 case CSSPropertyListStylePosition:
1014 case CSSPropertyListStyleType:
1015 case CSSPropertyOutlineStyle:
1016 case CSSPropertyOverflowWrap:
1017 case CSSPropertyOverflowX:
1018 case CSSPropertyOverflowY:
1019 case CSSPropertyPageBreakAfter:
1020 case CSSPropertyPageBreakBefore:
1021 case CSSPropertyPageBreakInside:
1022 case CSSPropertyPointerEvents:
1023 case CSSPropertyPosition:
1024 case CSSPropertyResize:
1025 case CSSPropertySpeak:
1026 case CSSPropertyTableLayout:
1027 case CSSPropertyTextLineThroughMode:
1028 case CSSPropertyTextLineThroughStyle:
1029 case CSSPropertyTextOverflow:
1030 case CSSPropertyTextOverlineMode:
1031 case CSSPropertyTextOverlineStyle:
1032 case CSSPropertyTextRendering:
1033 case CSSPropertyTextTransform:
1034 case CSSPropertyTextUnderlineMode:
1035 case CSSPropertyTextUnderlineStyle:
1036 case CSSPropertyVisibility:
1037 case CSSPropertyWebkitAppearance:
1038 #if ENABLE(CSS_COMPOSITING)
1039 case CSSPropertyWebkitBlendMode:
1041 case CSSPropertyWebkitBackfaceVisibility:
1042 case CSSPropertyWebkitBorderAfterStyle:
1043 case CSSPropertyWebkitBorderBeforeStyle:
1044 case CSSPropertyWebkitBorderEndStyle:
1045 case CSSPropertyWebkitBorderFit:
1046 case CSSPropertyWebkitBorderStartStyle:
1047 case CSSPropertyWebkitBoxAlign:
1048 #if ENABLE(CSS_BOX_DECORATION_BREAK)
1049 case CSSPropertyWebkitBoxDecorationBreak:
1051 case CSSPropertyWebkitBoxDirection:
1052 case CSSPropertyWebkitBoxLines:
1053 case CSSPropertyWebkitBoxOrient:
1054 case CSSPropertyWebkitBoxPack:
1055 case CSSPropertyWebkitColorCorrection:
1056 case CSSPropertyWebkitColumnBreakAfter:
1057 case CSSPropertyWebkitColumnBreakBefore:
1058 case CSSPropertyWebkitColumnBreakInside:
1059 case CSSPropertyWebkitColumnRuleStyle:
1060 case CSSPropertyWebkitAlignContent:
1061 case CSSPropertyWebkitAlignItems:
1062 case CSSPropertyWebkitAlignSelf:
1063 case CSSPropertyWebkitFlexDirection:
1064 case CSSPropertyWebkitFlexWrap:
1065 case CSSPropertyWebkitJustifyContent:
1066 case CSSPropertyWebkitFontKerning:
1067 case CSSPropertyWebkitFontSmoothing:
1068 case CSSPropertyWebkitHyphens:
1069 case CSSPropertyWebkitGridAutoFlow:
1070 case CSSPropertyWebkitLineAlign:
1071 case CSSPropertyWebkitLineBreak:
1072 case CSSPropertyWebkitLineSnap:
1073 case CSSPropertyWebkitMarginAfterCollapse:
1074 case CSSPropertyWebkitMarginBeforeCollapse:
1075 case CSSPropertyWebkitMarginBottomCollapse:
1076 case CSSPropertyWebkitMarginTopCollapse:
1077 case CSSPropertyWebkitMarqueeDirection:
1078 case CSSPropertyWebkitMarqueeStyle:
1079 case CSSPropertyWebkitNbspMode:
1080 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
1081 case CSSPropertyWebkitOverflowScrolling:
1083 case CSSPropertyWebkitPrintColorAdjust:
1084 #if ENABLE(CSS_REGIONS)
1085 case CSSPropertyWebkitRegionBreakAfter:
1086 case CSSPropertyWebkitRegionBreakBefore:
1087 case CSSPropertyWebkitRegionBreakInside:
1088 case CSSPropertyWebkitRegionOverflow:
1090 case CSSPropertyWebkitRtlOrdering:
1091 case CSSPropertyWebkitRubyPosition:
1092 #if ENABLE(CSS3_TEXT)
1093 case CSSPropertyWebkitTextAlignLast:
1095 case CSSPropertyWebkitTextCombine:
1096 case CSSPropertyWebkitTextEmphasisPosition:
1097 case CSSPropertyWebkitTextSecurity:
1098 case CSSPropertyWebkitTextSizeAdjust:
1099 case CSSPropertyWebkitTransformStyle:
1100 case CSSPropertyWebkitUserDrag:
1101 case CSSPropertyWebkitUserModify:
1102 case CSSPropertyWebkitUserSelect:
1103 #if ENABLE(CSS_EXCLUSIONS)
1104 case CSSPropertyWebkitWrapFlow:
1105 case CSSPropertyWebkitWrapThrough:
1107 case CSSPropertyWebkitWritingMode:
1108 case CSSPropertyWhiteSpace:
1109 case CSSPropertyWordBreak:
1110 case CSSPropertyWordWrap:
1117 static bool parseKeywordValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, const CSSParserContext& parserContext)
1119 ASSERT(!string.isEmpty());
1121 if (!isKeywordPropertyID(propertyId)) {
1122 // All properties accept the values of "initial" and "inherit".
1123 String lowerCaseString = string.lower();
1124 if (lowerCaseString != "initial" && lowerCaseString != "inherit")
1127 // Parse initial/inherit shorthands using the CSSParser.
1128 if (shorthandForProperty(propertyId).length())
1132 CSSParserString cssString;
1133 cssString.init(string);
1134 int valueID = cssValueKeywordID(cssString);
1139 RefPtr<CSSValue> value;
1140 if (valueID == CSSValueInherit)
1141 value = cssValuePool().createInheritedValue();
1142 else if (valueID == CSSValueInitial)
1143 value = cssValuePool().createExplicitInitialValue();
1144 else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext))
1145 value = cssValuePool().createIdentifierValue(valueID);
1149 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
1153 template <typename CharacterType>
1154 static bool parseTransformArguments(WebKitCSSTransformValue* transformValue, CharacterType* characters, unsigned length, unsigned start, unsigned expectedCount)
1156 while (expectedCount) {
1157 size_t end = WTF::find(characters, length, expectedCount == 1 ? ')' : ',', start);
1158 if (end == notFound || (expectedCount == 1 && end != length - 1))
1160 unsigned argumentLength = end - start;
1161 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
1163 if (!parseSimpleLength(characters + start, argumentLength, unit, number))
1165 if (unit != CSSPrimitiveValue::CSS_PX && (number || unit != CSSPrimitiveValue::CSS_NUMBER))
1167 transformValue->append(cssValuePool().createValue(number, unit));
1174 static bool parseTranslateTransformValue(StylePropertySet* properties, CSSPropertyID propertyID, const String& string, bool important)
1176 if (propertyID != CSSPropertyWebkitTransform)
1178 static const unsigned shortestValidTransformStringLength = 12;
1179 static const unsigned likelyMultipartTransformStringLengthCutoff = 32;
1180 if (string.length() < shortestValidTransformStringLength || string.length() > likelyMultipartTransformStringLengthCutoff)
1182 if (!string.startsWith("translate", false))
1184 UChar c9 = toASCIILower(string[9]);
1185 UChar c10 = toASCIILower(string[10]);
1187 WebKitCSSTransformValue::TransformOperationType transformType;
1188 unsigned expectedArgumentCount = 1;
1189 unsigned argumentStart = 11;
1190 if (c9 == 'x' && c10 == '(')
1191 transformType = WebKitCSSTransformValue::TranslateXTransformOperation;
1192 else if (c9 == 'y' && c10 == '(')
1193 transformType = WebKitCSSTransformValue::TranslateYTransformOperation;
1194 else if (c9 == 'z' && c10 == '(')
1195 transformType = WebKitCSSTransformValue::TranslateZTransformOperation;
1196 else if (c9 == '(') {
1197 transformType = WebKitCSSTransformValue::TranslateTransformOperation;
1198 expectedArgumentCount = 2;
1200 } else if (c9 == '3' && c10 == 'd' && string[11] == '(') {
1201 transformType = WebKitCSSTransformValue::Translate3DTransformOperation;
1202 expectedArgumentCount = 3;
1207 RefPtr<WebKitCSSTransformValue> transformValue = WebKitCSSTransformValue::create(transformType);
1209 if (string.is8Bit())
1210 success = parseTransformArguments(transformValue.get(), string.characters8(), string.length(), argumentStart, expectedArgumentCount);
1212 success = parseTransformArguments(transformValue.get(), string.characters16(), string.length(), argumentStart, expectedArgumentCount);
1215 RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
1216 result->append(transformValue.release());
1217 properties->addParsedProperty(CSSProperty(CSSPropertyWebkitTransform, result.release(), important));
1221 PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& string)
1223 if (string.isEmpty())
1225 RefPtr<StylePropertySet> dummyStyle = StylePropertySet::create();
1226 if (!parseValue(dummyStyle.get(), CSSPropertyFontFamily, string, false, CSSQuirksMode, 0))
1228 return static_pointer_cast<CSSValueList>(dummyStyle->getPropertyCSSValue(CSSPropertyFontFamily));
1231 #if ENABLE(CSS_VARIABLES)
1232 bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, Document* document)
1234 ASSERT(!string.isEmpty());
1236 CSSParserContext context(document);
1238 if (parseSimpleLengthValue(declaration, propertyID, string, important, context.mode))
1240 if (parseColorValue(declaration, propertyID, string, important, context.mode))
1242 if (parseKeywordValue(declaration, propertyID, string, important, context))
1245 CSSParser parser(context);
1246 return parser.parseValue(declaration, propertyID, string, important, static_cast<StyleSheetContents*>(0));
1250 bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
1252 ASSERT(!string.isEmpty());
1253 if (parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode))
1255 if (parseColorValue(declaration, propertyID, string, important, cssParserMode))
1258 CSSParserContext context(cssParserMode);
1259 if (contextStyleSheet) {
1260 context = contextStyleSheet->parserContext();
1261 context.mode = cssParserMode;
1264 if (parseKeywordValue(declaration, propertyID, string, important, context))
1266 if (parseTranslateTransformValue(declaration, propertyID, string, important))
1269 CSSParser parser(context);
1270 return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
1273 bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, StyleSheetContents* contextStyleSheet)
1275 setStyleSheet(contextStyleSheet);
1277 setupParser("@-webkit-value{", string, "} ");
1280 m_important = important;
1287 if (m_hasFontFaceOnlyValues)
1288 deleteFontFaceOnlyValues();
1289 if (!m_parsedProperties.isEmpty()) {
1291 declaration->addParsedProperties(m_parsedProperties);
1298 // The color will only be changed when string contains a valid CSS color, so callers
1299 // can set it to a default color and ignore the boolean result.
1300 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
1302 // First try creating a color specified by name, rgba(), rgb() or "#" syntax.
1303 if (fastParseColor(color, string, strict))
1306 CSSParser parser(CSSStrictMode);
1308 // In case the fast-path parser didn't understand the color, try the full parser.
1309 if (!parser.parseColor(string))
1312 CSSValue* value = parser.m_parsedProperties.first().value();
1313 if (!value->isPrimitiveValue())
1316 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
1317 if (!primitiveValue->isRGBColor())
1320 color = primitiveValue->getRGBA32Value();
1324 bool CSSParser::parseColor(const String& string)
1326 setupParser("@-webkit-decls{color:", string, "} ");
1330 return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
1333 bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
1335 if (!document || !document->page())
1338 CSSParserString cssColor;
1339 cssColor.init(string);
1340 int id = cssValueKeywordID(cssColor);
1344 color = document->page()->theme()->systemColor(id).rgb();
1348 void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
1350 m_selectorListForParseSelector = &selectorList;
1352 setupParser("@-webkit-selector{", string, "}");
1356 m_selectorListForParseSelector = 0;
1359 PassRefPtr<StylePropertySet> CSSParser::parseInlineStyleDeclaration(const String& string, Element* element)
1361 CSSParserContext context = element->document()->elementSheet()->contents()->parserContext();
1362 context.mode = strictToCSSParserMode(element->isHTMLElement() && !element->document()->inQuirksMode());
1363 return CSSParser(context).parseDeclaration(string, element->document()->elementSheet()->contents());
1366 PassRefPtr<StylePropertySet> CSSParser::parseDeclaration(const String& string, StyleSheetContents* contextStyleSheet)
1368 setStyleSheet(contextStyleSheet);
1370 setupParser("@-webkit-decls{", string, "} ");
1374 if (m_hasFontFaceOnlyValues)
1375 deleteFontFaceOnlyValues();
1377 RefPtr<StylePropertySet> style = createStylePropertySet();
1379 return style.release();
1383 bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, PassRefPtr<CSSRuleSourceData> prpRuleSourceData, StyleSheetContents* contextStyleSheet)
1385 // Length of the "@-webkit-decls{" prefix.
1386 static const unsigned prefixLength = 15;
1388 setStyleSheet(contextStyleSheet);
1390 RefPtr<CSSRuleSourceData> ruleSourceData = prpRuleSourceData;
1391 if (ruleSourceData) {
1392 m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
1393 m_currentRuleDataStack->append(ruleSourceData);
1396 setupParser("@-webkit-decls{", string, "} ");
1401 if (m_hasFontFaceOnlyValues)
1402 deleteFontFaceOnlyValues();
1403 if (!m_parsedProperties.isEmpty()) {
1405 declaration->addParsedProperties(m_parsedProperties);
1409 if (ruleSourceData) {
1410 ASSERT(m_currentRuleDataStack->size() == 1);
1411 ruleSourceData->ruleBodyRange.start = 0;
1412 ruleSourceData->ruleBodyRange.end = string.length();
1413 for (size_t i = 0, size = ruleSourceData->styleSourceData->propertyData.size(); i < size; ++i) {
1414 CSSPropertySourceData& propertyData = ruleSourceData->styleSourceData->propertyData.at(i);
1415 propertyData.range.start -= prefixLength;
1416 propertyData.range.end -= prefixLength;
1419 fixUnparsedPropertyRanges(ruleSourceData.get());
1420 m_currentRuleDataStack.clear();
1426 PassOwnPtr<MediaQuery> CSSParser::parseMediaQuery(const String& string)
1428 if (string.isEmpty())
1431 ASSERT(!m_mediaQuery);
1433 // can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
1434 // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
1435 setupParser("@-webkit-mediaquery ", string, "} ");
1438 return m_mediaQuery.release();
1441 #if ENABLE(CSS_VARIABLES)
1442 static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties, HashSet<AtomicString>& seenVariables)
1444 static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties)
1447 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
1448 for (int i = input.size() - 1; i >= 0; --i) {
1449 const CSSProperty& property = input[i];
1450 if (property.isImportant() != important)
1452 #if ENABLE(CSS_VARIABLES)
1453 if (property.id() == CSSPropertyVariable) {
1454 const AtomicString& name = static_cast<CSSVariableValue*>(property.value())->name();
1455 if (seenVariables.contains(name))
1457 seenVariables.add(name);
1458 output[--unusedEntries] = property;
1462 const unsigned propertyIDIndex = property.id() - firstCSSProperty;
1463 if (seenProperties.get(propertyIDIndex))
1465 seenProperties.set(propertyIDIndex);
1466 output[--unusedEntries] = property;
1470 PassRefPtr<StylePropertySet> CSSParser::createStylePropertySet()
1472 BitArray<numCSSProperties> seenProperties;
1473 size_t unusedEntries = m_parsedProperties.size();
1474 Vector<CSSProperty, 256> results(unusedEntries);
1476 // Important properties have higher priority, so add them first. Duplicate definitions can then be ignored when found.
1477 #if ENABLE(CSS_VARIABLES)
1478 HashSet<AtomicString> seenVariables;
1479 filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties, seenVariables);
1480 filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties, seenVariables);
1482 filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties);
1483 filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties);
1486 results.remove(0, unusedEntries);
1488 return StylePropertySet::createImmutable(results.data(), results.size(), m_context.mode);
1491 void CSSParser::addProperty(CSSPropertyID propId, PassRefPtr<CSSValue> value, bool important, bool implicit)
1493 m_parsedProperties.append(CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand || implicit));
1496 void CSSParser::rollbackLastProperties(int num)
1499 ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num));
1500 m_parsedProperties.shrink(m_parsedProperties.size() - num);
1503 void CSSParser::clearProperties()
1505 m_parsedProperties.clear();
1506 m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
1507 m_hasFontFaceOnlyValues = false;
1510 KURL CSSParser::completeURL(const CSSParserContext& context, const String& url)
1514 if (context.charset.isEmpty())
1515 return KURL(context.baseURL, url);
1516 return KURL(context.baseURL, url, context.charset);
1519 KURL CSSParser::completeURL(const String& url) const
1521 return completeURL(m_context, url);
1524 bool CSSParser::validCalculationUnit(CSSParserValue* value, Units unitflags, ReleaseParsedCalcValueCondition releaseCalc)
1526 bool mustBeNonNegative = unitflags & FNonNeg;
1528 if (!parseCalculation(value, mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll))
1532 switch (m_parsedCalculation->category()) {
1534 b = (unitflags & FLength);
1537 b = (unitflags & FPercent);
1538 if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
1542 b = (unitflags & FNumber);
1543 if (!b && (unitflags & FInteger) && m_parsedCalculation->isInt())
1545 if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
1548 case CalcPercentLength:
1549 b = (unitflags & FPercent) && (unitflags & FLength);
1551 case CalcPercentNumber:
1552 b = (unitflags & FPercent) && (unitflags & FNumber);
1554 #if ENABLE(CSS_VARIABLES)
1562 if (!b || releaseCalc == ReleaseParsedCalcValue)
1563 m_parsedCalculation.release();
1567 inline bool CSSParser::shouldAcceptUnitLessValues(CSSParserValue* value, Units unitflags, CSSParserMode cssParserMode)
1569 // Qirks mode and svg presentation attributes accept unit less values.
1570 return (unitflags & (FLength | FAngle | FTime)) && (!value->fValue || cssParserMode == CSSQuirksMode || cssParserMode == SVGAttributeMode);
1573 bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, CSSParserMode cssParserMode, ReleaseParsedCalcValueCondition releaseCalc)
1575 if (isCalculation(value))
1576 return validCalculationUnit(value, unitflags, releaseCalc);
1579 switch (value->unit) {
1580 #if ENABLE(CSS_VARIABLES)
1581 case CSSPrimitiveValue::CSS_VARIABLE_NAME:
1582 // Variables are checked at the point they are dereferenced because unit type is not available here.
1586 case CSSPrimitiveValue::CSS_NUMBER:
1587 b = (unitflags & FNumber);
1588 if (!b && shouldAcceptUnitLessValues(value, unitflags, cssParserMode)) {
1589 value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX :
1590 ((unitflags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS);
1593 if (!b && (unitflags & FInteger) && value->isInt)
1595 if (!b && (unitflags & FPositiveInteger) && value->isInt && value->fValue > 0)
1598 case CSSPrimitiveValue::CSS_PERCENTAGE:
1599 b = (unitflags & FPercent);
1601 case CSSParserValue::Q_EMS:
1602 case CSSPrimitiveValue::CSS_EMS:
1603 case CSSPrimitiveValue::CSS_REMS:
1604 case CSSPrimitiveValue::CSS_CHS:
1605 case CSSPrimitiveValue::CSS_EXS:
1606 case CSSPrimitiveValue::CSS_PX:
1607 case CSSPrimitiveValue::CSS_CM:
1608 case CSSPrimitiveValue::CSS_MM:
1609 case CSSPrimitiveValue::CSS_IN:
1610 case CSSPrimitiveValue::CSS_PT:
1611 case CSSPrimitiveValue::CSS_PC:
1612 case CSSPrimitiveValue::CSS_VW:
1613 case CSSPrimitiveValue::CSS_VH:
1614 case CSSPrimitiveValue::CSS_VMIN:
1615 case CSSPrimitiveValue::CSS_VMAX:
1616 b = (unitflags & FLength);
1618 case CSSPrimitiveValue::CSS_MS:
1619 case CSSPrimitiveValue::CSS_S:
1620 b = (unitflags & FTime);
1622 case CSSPrimitiveValue::CSS_DEG:
1623 case CSSPrimitiveValue::CSS_RAD:
1624 case CSSPrimitiveValue::CSS_GRAD:
1625 case CSSPrimitiveValue::CSS_TURN:
1626 b = (unitflags & FAngle);
1628 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1629 case CSSPrimitiveValue::CSS_DPPX:
1630 case CSSPrimitiveValue::CSS_DPI:
1631 case CSSPrimitiveValue::CSS_DPCM:
1632 b = (unitflags & FResolution);
1635 case CSSPrimitiveValue::CSS_HZ:
1636 case CSSPrimitiveValue::CSS_KHZ:
1637 case CSSPrimitiveValue::CSS_DIMENSION:
1641 if (b && unitflags & FNonNeg && value->fValue < 0)
1646 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSParserValue* value)
1648 #if ENABLE(CSS_VARIABLES)
1649 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
1650 return createPrimitiveVariableNameValue(value);
1653 if (m_parsedCalculation) {
1654 ASSERT(isCalculation(value));
1655 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1658 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1659 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1660 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
1661 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
1662 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM));
1664 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1665 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
1666 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX));
1668 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value->unit));
1671 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSParserValue* value)
1673 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT);
1674 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRING);
1677 #if ENABLE(CSS_VARIABLES)
1678 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveVariableNameValue(CSSParserValue* value)
1680 ASSERT(value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME);
1681 AtomicString variableName = String(value->string).lower();
1682 return CSSPrimitiveValue::create(variableName, CSSPrimitiveValue::CSS_VARIABLE_NAME);
1686 static inline bool isComma(CSSParserValue* value)
1688 return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
1691 static inline bool isForwardSlashOperator(CSSParserValue* value)
1694 return value->unit == CSSParserValue::Operator && value->iValue == '/';
1697 bool CSSParser::validWidth(CSSParserValue* value)
1700 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent)
1702 return !id && validUnit(value, FLength | FPercent | FNonNeg);
1705 // FIXME: Combine this with validWidth when we support fit-content, et al, for heights.
1706 bool CSSParser::validHeight(CSSParserValue* value)
1709 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic)
1711 return !id && validUnit(value, FLength | FPercent | FNonNeg);
1714 inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(int identifier, CSSParserValue* value)
1717 return cssValuePool().createIdentifierValue(identifier);
1718 if (value->unit == CSSPrimitiveValue::CSS_STRING)
1719 return createPrimitiveStringValue(value);
1720 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1721 return createPrimitiveNumericValue(value);
1722 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
1723 return createPrimitiveNumericValue(value);
1724 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
1725 return createPrimitiveNumericValue(value);
1726 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1727 if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM)
1728 return createPrimitiveNumericValue(value);
1730 #if ENABLE(CSS_VARIABLES)
1731 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
1732 return createPrimitiveVariableNameValue(value);
1734 if (value->unit >= CSSParserValue::Q_EMS)
1735 return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
1736 if (isCalculation(value))
1737 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1742 void CSSParser::addExpandedPropertyForValue(CSSPropertyID propId, PassRefPtr<CSSValue> prpValue, bool important)
1744 const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
1745 unsigned shorthandLength = shorthand.length();
1746 if (!shorthandLength) {
1747 addProperty(propId, prpValue, important);
1751 RefPtr<CSSValue> value = prpValue;
1752 ShorthandScope scope(this, propId);
1753 const CSSPropertyID* longhands = shorthand.properties();
1754 for (unsigned i = 0; i < shorthandLength; ++i)
1755 addProperty(longhands[i], value, important);
1758 bool CSSParser::parseValue(CSSPropertyID propId, bool important)
1763 CSSParserValue* value = m_valueList->current();
1768 // Note: m_parsedCalculation is used to pass the calc value to validUnit and then cleared at the end of this function.
1769 // FIXME: This is to avoid having to pass parsedCalc to all validUnit callers.
1770 ASSERT(!m_parsedCalculation);
1774 int num = inShorthand() ? 1 : m_valueList->size();
1776 if (id == CSSValueInherit) {
1779 addExpandedPropertyForValue(propId, cssValuePool().createInheritedValue(), important);
1782 else if (id == CSSValueInitial) {
1785 addExpandedPropertyForValue(propId, cssValuePool().createExplicitInitialValue(), important);
1789 #if ENABLE(CSS_VARIABLES)
1790 if (!id && value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME && num == 1) {
1791 addProperty(propId, createPrimitiveVariableNameValue(value), important);
1792 m_valueList->next();
1795 ASSERT(propId != CSSPropertyVariable);
1798 if (isKeywordPropertyID(propId)) {
1799 if (!isValidKeywordPropertyAndValue(propId, id, m_context))
1801 if (m_valueList->next() && !inShorthand())
1803 addProperty(propId, cssValuePool().createIdentifierValue(id), important);
1807 #if ENABLE(CSS_DEVICE_ADAPTATION)
1809 return parseViewportProperty(propId, important);
1812 bool validPrimitive = false;
1813 RefPtr<CSSValue> parsedValue;
1816 case CSSPropertySize: // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
1817 return parseSize(propId, important);
1819 case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit
1821 validPrimitive = true;
1823 return parseQuotes(propId, important);
1825 case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | isolate | isolate-override | plaintext | inherit
1826 if (id == CSSValueNormal
1827 || id == CSSValueEmbed
1828 || id == CSSValueBidiOverride
1829 || id == CSSValueWebkitIsolate
1830 || id == CSSValueWebkitIsolateOverride
1831 || id == CSSValueWebkitPlaintext)
1832 validPrimitive = true;
1835 case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
1836 // close-quote | no-open-quote | no-close-quote ]+ | inherit
1837 return parseContent(propId, important);
1839 case CSSPropertyClip: // <shape> | auto | inherit
1840 if (id == CSSValueAuto)
1841 validPrimitive = true;
1842 else if (value->unit == CSSParserValue::Function)
1843 return parseClipShape(propId, important);
1846 /* Start of supported CSS properties with validation. This is needed for parseShorthand to work
1847 * correctly and allows optimization in WebCore::applyRule(..)
1849 case CSSPropertyOverflow: {
1850 ShorthandScope scope(this, propId);
1851 if (num != 1 || !parseValue(CSSPropertyOverflowY, important))
1854 RefPtr<CSSValue> overflowXValue;
1856 // FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. If this value has been
1857 // set using the shorthand, then for now overflow-x will default to auto, but once we implement
1858 // pagination controls, it should default to hidden. If the overflow-y value is anything but
1859 // paged-x or paged-y, then overflow-x and overflow-y should have the same value.
1860 if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
1861 overflowXValue = cssValuePool().createIdentifierValue(CSSValueAuto);
1863 overflowXValue = m_parsedProperties.last().value();
1864 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important);
1868 case CSSPropertyTextAlign:
1869 // left | right | center | justify | -webkit-left | -webkit-right | -webkit-center | -webkit-match-parent
1870 // | start | end | <string> | inherit | -webkit-auto (converted to start)
1871 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd
1872 || value->unit == CSSPrimitiveValue::CSS_STRING)
1873 validPrimitive = true;
1876 case CSSPropertyFontWeight: { // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
1877 if (m_valueList->size() != 1)
1879 return parseFontWeight(important);
1881 case CSSPropertyBorderSpacing: {
1883 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1884 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
1886 CSSValue* value = m_parsedProperties.last().value();
1887 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important);
1890 else if (num == 2) {
1891 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1892 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important) || !parseValue(CSSPropertyWebkitBorderVerticalSpacing, important))
1898 case CSSPropertyWebkitBorderHorizontalSpacing:
1899 case CSSPropertyWebkitBorderVerticalSpacing:
1900 validPrimitive = validUnit(value, FLength | FNonNeg);
1902 case CSSPropertyOutlineColor: // <color> | invert | inherit
1903 // Outline color has "invert" as additional keyword.
1904 // Also, we want to allow the special focus color even in strict parsing mode.
1905 if (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor) {
1906 validPrimitive = true;
1910 case CSSPropertyBackgroundColor: // <color> | inherit
1911 case CSSPropertyBorderTopColor: // <color> | inherit
1912 case CSSPropertyBorderRightColor:
1913 case CSSPropertyBorderBottomColor:
1914 case CSSPropertyBorderLeftColor:
1915 case CSSPropertyWebkitBorderStartColor:
1916 case CSSPropertyWebkitBorderEndColor:
1917 case CSSPropertyWebkitBorderBeforeColor:
1918 case CSSPropertyWebkitBorderAfterColor:
1919 case CSSPropertyColor: // <color> | inherit
1920 case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors
1921 case CSSPropertyTextUnderlineColor:
1922 case CSSPropertyTextOverlineColor:
1923 case CSSPropertyWebkitColumnRuleColor:
1924 case CSSPropertyWebkitTextEmphasisColor:
1925 case CSSPropertyWebkitTextFillColor:
1926 case CSSPropertyWebkitTextStrokeColor:
1927 if (id == CSSValueWebkitText)
1928 validPrimitive = true; // Always allow this, even when strict parsing is on,
1929 // since we use this in our UA sheets.
1930 else if (id == CSSValueCurrentcolor)
1931 validPrimitive = true;
1932 else if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu ||
1933 (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
1934 validPrimitive = true;
1936 parsedValue = parseColor();
1938 m_valueList->next();
1942 case CSSPropertyCursor: {
1943 // Grammar defined by CSS3 UI and modified by CSS4 images:
1944 // [ [<image> [<x> <y>]?,]*
1945 // [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |
1946 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize |
1947 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help |
1948 // vertical-text | cell | context-menu | alias | copy | no-drop | not-allowed | -webkit-zoom-in
1949 // -webkit-zoom-out | all-scroll | -webkit-grab | -webkit-grabbing ] ] | inherit
1950 RefPtr<CSSValueList> list;
1952 RefPtr<CSSValue> image = 0;
1953 if (value->unit == CSSPrimitiveValue::CSS_URI) {
1954 String uri = value->string;
1956 image = CSSImageValue::create(completeURL(uri));
1957 #if ENABLE(CSS_IMAGE_SET) && ENABLE(MOUSE_CURSOR_SCALE)
1958 } else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
1959 image = parseImageSet(m_valueList.get());
1967 value = m_valueList->next();
1968 while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
1969 coords.append(int(value->fValue));
1970 value = m_valueList->next();
1972 bool hasHotSpot = false;
1973 IntPoint hotSpot(-1, -1);
1974 int nrcoords = coords.size();
1975 if (nrcoords > 0 && nrcoords != 2)
1977 if (nrcoords == 2) {
1979 hotSpot = IntPoint(coords[0], coords[1]);
1983 list = CSSValueList::createCommaSeparated();
1986 list->append(CSSCursorImageValue::create(image, hasHotSpot, hotSpot));
1988 if ((inStrictMode() && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ',')))
1990 value = m_valueList->next(); // comma
1993 if (!value) { // no value after url list (MSIE 5 compatibility)
1994 if (list->length() != 1)
1996 } else if (inQuirksMode() && value->id == CSSValueHand) // MSIE 5 compatibility :/
1997 list->append(cssValuePool().createIdentifierValue(CSSValuePointer));
1998 else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
1999 list->append(cssValuePool().createIdentifierValue(value->id));
2000 m_valueList->next();
2001 parsedValue = list.release();
2005 if (inQuirksMode() && value->id == CSSValueHand) { // MSIE 5 compatibility :/
2006 id = CSSValuePointer;
2007 validPrimitive = true;
2008 } else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
2009 validPrimitive = true;
2011 ASSERT_NOT_REACHED();
2017 case CSSPropertyBackgroundAttachment:
2018 case CSSPropertyBackgroundClip:
2019 case CSSPropertyWebkitBackgroundClip:
2020 case CSSPropertyWebkitBackgroundComposite:
2021 case CSSPropertyBackgroundImage:
2022 case CSSPropertyBackgroundOrigin:
2023 case CSSPropertyWebkitBackgroundOrigin:
2024 case CSSPropertyBackgroundPosition:
2025 case CSSPropertyBackgroundPositionX:
2026 case CSSPropertyBackgroundPositionY:
2027 case CSSPropertyBackgroundSize:
2028 case CSSPropertyWebkitBackgroundSize:
2029 case CSSPropertyBackgroundRepeat:
2030 case CSSPropertyBackgroundRepeatX:
2031 case CSSPropertyBackgroundRepeatY:
2032 case CSSPropertyWebkitMaskClip:
2033 case CSSPropertyWebkitMaskComposite:
2034 case CSSPropertyWebkitMaskImage:
2035 case CSSPropertyWebkitMaskOrigin:
2036 case CSSPropertyWebkitMaskPosition:
2037 case CSSPropertyWebkitMaskPositionX:
2038 case CSSPropertyWebkitMaskPositionY:
2039 case CSSPropertyWebkitMaskSize:
2040 case CSSPropertyWebkitMaskRepeat:
2041 case CSSPropertyWebkitMaskRepeatX:
2042 case CSSPropertyWebkitMaskRepeatY:
2043 #if ENABLE(CSS_COMPOSITING)
2044 case CSSPropertyWebkitBackgroundBlendMode:
2047 RefPtr<CSSValue> val1;
2048 RefPtr<CSSValue> val2;
2049 CSSPropertyID propId1, propId2;
2050 bool result = false;
2051 if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
2052 OwnPtr<ShorthandScope> shorthandScope;
2053 if (propId == CSSPropertyBackgroundPosition ||
2054 propId == CSSPropertyBackgroundRepeat ||
2055 propId == CSSPropertyWebkitMaskPosition ||
2056 propId == CSSPropertyWebkitMaskRepeat) {
2057 shorthandScope = adoptPtr(new ShorthandScope(this, propId));
2059 addProperty(propId1, val1.release(), important);
2061 addProperty(propId2, val2.release(), important);
2064 m_implicitShorthand = false;
2067 case CSSPropertyListStyleImage: // <uri> | none | inherit
2068 case CSSPropertyBorderImageSource:
2069 case CSSPropertyWebkitMaskBoxImageSource:
2070 if (id == CSSValueNone) {
2071 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone);
2072 m_valueList->next();
2073 } else if (value->unit == CSSPrimitiveValue::CSS_URI) {
2074 parsedValue = CSSImageValue::create(completeURL(value->string));
2075 m_valueList->next();
2076 } else if (isGeneratedImageValue(value)) {
2077 if (parseGeneratedImage(m_valueList.get(), parsedValue))
2078 m_valueList->next();
2082 #if ENABLE(CSS_IMAGE_SET)
2083 else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
2084 parsedValue = parseImageSet(m_valueList.get());
2087 m_valueList->next();
2092 case CSSPropertyWebkitTextStrokeWidth:
2093 case CSSPropertyOutlineWidth: // <border-width> | inherit
2094 case CSSPropertyBorderTopWidth: //// <border-width> | inherit
2095 case CSSPropertyBorderRightWidth: // Which is defined as
2096 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
2097 case CSSPropertyBorderLeftWidth:
2098 case CSSPropertyWebkitBorderStartWidth:
2099 case CSSPropertyWebkitBorderEndWidth:
2100 case CSSPropertyWebkitBorderBeforeWidth:
2101 case CSSPropertyWebkitBorderAfterWidth:
2102 case CSSPropertyWebkitColumnRuleWidth:
2103 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
2104 validPrimitive = true;
2106 validPrimitive = validUnit(value, FLength | FNonNeg);
2109 case CSSPropertyLetterSpacing: // normal | <length> | inherit
2110 case CSSPropertyWordSpacing: // normal | <length> | inherit
2111 if (id == CSSValueNormal)
2112 validPrimitive = true;
2114 validPrimitive = validUnit(value, FLength);
2117 case CSSPropertyTextIndent: // <length> | <percentage> | inherit
2118 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2121 case CSSPropertyPaddingTop: //// <padding-width> | inherit
2122 case CSSPropertyPaddingRight: // Which is defined as
2123 case CSSPropertyPaddingBottom: // <length> | <percentage>
2124 case CSSPropertyPaddingLeft: ////
2125 case CSSPropertyWebkitPaddingStart:
2126 case CSSPropertyWebkitPaddingEnd:
2127 case CSSPropertyWebkitPaddingBefore:
2128 case CSSPropertyWebkitPaddingAfter:
2129 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
2132 case CSSPropertyMaxWidth:
2133 case CSSPropertyWebkitMaxLogicalWidth:
2134 validPrimitive = (id == CSSValueNone || validWidth(value));
2137 case CSSPropertyMinWidth:
2138 case CSSPropertyWebkitMinLogicalWidth:
2139 case CSSPropertyWidth:
2140 case CSSPropertyWebkitLogicalWidth:
2141 validPrimitive = (id == CSSValueAuto || validWidth(value));
2144 case CSSPropertyMaxHeight:
2145 case CSSPropertyWebkitMaxLogicalHeight:
2146 validPrimitive = (id == CSSValueNone || validHeight(value));
2149 case CSSPropertyMinHeight:
2150 case CSSPropertyWebkitMinLogicalHeight:
2151 case CSSPropertyHeight:
2152 case CSSPropertyWebkitLogicalHeight:
2153 validPrimitive = (id == CSSValueAuto || validHeight(value));
2156 case CSSPropertyFontSize:
2157 return parseFontSize(important);
2159 case CSSPropertyFontVariant: // normal | small-caps | inherit
2160 return parseFontVariant(important);
2162 case CSSPropertyVerticalAlign:
2163 // baseline | sub | super | top | text-top | middle | bottom | text-bottom |
2164 // <percentage> | <length> | inherit
2166 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
2167 validPrimitive = true;
2169 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2172 case CSSPropertyBottom: // <length> | <percentage> | auto | inherit
2173 case CSSPropertyLeft: // <length> | <percentage> | auto | inherit
2174 case CSSPropertyRight: // <length> | <percentage> | auto | inherit
2175 case CSSPropertyTop: // <length> | <percentage> | auto | inherit
2176 case CSSPropertyMarginTop: //// <margin-width> | inherit
2177 case CSSPropertyMarginRight: // Which is defined as
2178 case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit
2179 case CSSPropertyMarginLeft: ////
2180 case CSSPropertyWebkitMarginStart:
2181 case CSSPropertyWebkitMarginEnd:
2182 case CSSPropertyWebkitMarginBefore:
2183 case CSSPropertyWebkitMarginAfter:
2184 if (id == CSSValueAuto)
2185 validPrimitive = true;
2187 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2190 case CSSPropertyZIndex: // auto | <integer> | inherit
2191 if (id == CSSValueAuto) {
2192 validPrimitive = true;
2196 case CSSPropertyOrphans: // <integer> | inherit | auto (We've added support for auto for backwards compatibility)
2197 case CSSPropertyWidows: // <integer> | inherit | auto (Ditto)
2198 if (id == CSSValueAuto)
2199 validPrimitive = true;
2201 validPrimitive = (!id && validUnit(value, FInteger, CSSQuirksMode));
2204 case CSSPropertyLineHeight:
2205 return parseLineHeight(important);
2206 case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit
2207 if (id != CSSValueNone)
2208 return parseCounter(propId, 1, important);
2209 validPrimitive = true;
2211 case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit
2212 if (id != CSSValueNone)
2213 return parseCounter(propId, 0, important);
2214 validPrimitive = true;
2216 case CSSPropertyFontFamily:
2217 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit
2219 parsedValue = parseFontFamily();
2223 case CSSPropertyTextDecoration:
2224 case CSSPropertyWebkitTextDecorationsInEffect:
2225 // none | [ underline || overline || line-through || blink ] | inherit
2226 return parseTextDecoration(propId, important);
2228 #if ENABLE(CSS3_TEXT)
2229 case CSSPropertyWebkitTextDecorationLine:
2230 // none | [ underline || overline || line-through ] | inherit
2231 return parseTextDecoration(propId, important);
2233 case CSSPropertyWebkitTextDecorationStyle:
2234 // solid | double | dotted | dashed | wavy
2235 if (id == CSSValueSolid || id == CSSValueDouble || id == CSSValueDotted || id == CSSValueDashed || id == CSSValueWavy)
2236 validPrimitive = true;
2240 case CSSPropertyZoom: // normal | reset | document | <number> | <percentage> | inherit
2241 if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument)
2242 validPrimitive = true;
2244 validPrimitive = (!id && validUnit(value, FNumber | FPercent | FNonNeg, CSSStrictMode));
2247 case CSSPropertySrc: // Only used within @font-face, so cannot use inherit | initial or be !important. This is a list of urls or local references.
2248 return parseFontFaceSrc();
2250 case CSSPropertyUnicodeRange:
2251 return parseFontFaceUnicodeRange();
2253 /* CSS3 properties */
2255 case CSSPropertyBorderImage: {
2256 RefPtr<CSSValue> result;
2257 return parseBorderImage(propId, result, important);
2259 case CSSPropertyWebkitBorderImage:
2260 case CSSPropertyWebkitMaskBoxImage: {
2261 RefPtr<CSSValue> result;
2262 if (parseBorderImage(propId, result)) {
2263 addProperty(propId, result, important);
2268 case CSSPropertyBorderImageOutset:
2269 case CSSPropertyWebkitMaskBoxImageOutset: {
2270 RefPtr<CSSPrimitiveValue> result;
2271 if (parseBorderImageOutset(result)) {
2272 addProperty(propId, result, important);
2277 case CSSPropertyBorderImageRepeat:
2278 case CSSPropertyWebkitMaskBoxImageRepeat: {
2279 RefPtr<CSSValue> result;
2280 if (parseBorderImageRepeat(result)) {
2281 addProperty(propId, result, important);
2286 case CSSPropertyBorderImageSlice:
2287 case CSSPropertyWebkitMaskBoxImageSlice: {
2288 RefPtr<CSSBorderImageSliceValue> result;
2289 if (parseBorderImageSlice(propId, result)) {
2290 addProperty(propId, result, important);
2295 case CSSPropertyBorderImageWidth:
2296 case CSSPropertyWebkitMaskBoxImageWidth: {
2297 RefPtr<CSSPrimitiveValue> result;
2298 if (parseBorderImageWidth(result)) {
2299 addProperty(propId, result, important);
2304 case CSSPropertyBorderTopRightRadius:
2305 case CSSPropertyBorderTopLeftRadius:
2306 case CSSPropertyBorderBottomLeftRadius:
2307 case CSSPropertyBorderBottomRightRadius: {
2308 if (num != 1 && num != 2)
2310 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
2311 if (!validPrimitive)
2313 RefPtr<CSSPrimitiveValue> parsedValue1 = createPrimitiveNumericValue(value);
2314 RefPtr<CSSPrimitiveValue> parsedValue2;
2316 value = m_valueList->next();
2317 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
2318 if (!validPrimitive)
2320 parsedValue2 = createPrimitiveNumericValue(value);
2322 parsedValue2 = parsedValue1;
2324 addProperty(propId, createPrimitiveValuePair(parsedValue1.release(), parsedValue2.release()), important);
2327 case CSSPropertyTabSize:
2328 validPrimitive = validUnit(value, FInteger | FNonNeg);
2330 case CSSPropertyWebkitAspectRatio:
2331 return parseAspectRatio(important);
2332 case CSSPropertyBorderRadius:
2333 case CSSPropertyWebkitBorderRadius:
2334 return parseBorderRadius(propId, important);
2335 case CSSPropertyOutlineOffset:
2336 validPrimitive = validUnit(value, FLength | FPercent);
2338 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
2339 case CSSPropertyBoxShadow:
2340 case CSSPropertyWebkitBoxShadow:
2341 if (id == CSSValueNone)
2342 validPrimitive = true;
2344 RefPtr<CSSValueList> shadowValueList = parseShadow(m_valueList.get(), propId);
2345 if (shadowValueList) {
2346 addProperty(propId, shadowValueList.release(), important);
2347 m_valueList->next();
2353 case CSSPropertyWebkitBoxReflect:
2354 if (id == CSSValueNone)
2355 validPrimitive = true;
2357 return parseReflect(propId, important);
2359 case CSSPropertyOpacity:
2360 validPrimitive = validUnit(value, FNumber);
2362 case CSSPropertyWebkitBoxFlex:
2363 validPrimitive = validUnit(value, FNumber);
2365 case CSSPropertyWebkitBoxFlexGroup:
2366 validPrimitive = validUnit(value, FInteger | FNonNeg, CSSStrictMode);
2368 case CSSPropertyWebkitBoxOrdinalGroup:
2369 validPrimitive = validUnit(value, FInteger | FNonNeg, CSSStrictMode) && value->fValue;
2371 #if ENABLE(CSS_FILTERS)
2372 case CSSPropertyWebkitFilter:
2373 if (id == CSSValueNone)
2374 validPrimitive = true;
2376 RefPtr<CSSValue> val = parseFilter();
2378 addProperty(propId, val, important);
2385 #if ENABLE(CSS_COMPOSITING)
2386 case CSSPropertyWebkitBlendMode:
2387 validPrimitive = true;
2390 case CSSPropertyWebkitFlex: {
2391 ShorthandScope scope(this, propId);
2392 if (id == CSSValueNone) {
2393 addProperty(CSSPropertyWebkitFlexGrow, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2394 addProperty(CSSPropertyWebkitFlexShrink, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2395 addProperty(CSSPropertyWebkitFlexBasis, cssValuePool().createIdentifierValue(CSSValueAuto), important);
2398 return parseFlex(m_valueList.get(), important);
2400 case CSSPropertyWebkitFlexBasis:
2401 // FIXME: Support intrinsic dimensions too.
2402 if (id == CSSValueAuto)
2403 validPrimitive = true;
2405 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
2407 case CSSPropertyWebkitFlexGrow:
2408 case CSSPropertyWebkitFlexShrink:
2409 validPrimitive = validUnit(value, FNumber | FNonNeg);
2411 case CSSPropertyWebkitOrder:
2412 if (validUnit(value, FInteger, CSSStrictMode)) {
2413 // 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.
2414 parsedValue = cssValuePool().createValue(max(static_cast<double>(std::numeric_limits<int>::min() + 2), value->fValue),
2415 static_cast<CSSPrimitiveValue::UnitTypes>(value->unit));
2416 m_valueList->next();
2419 case CSSPropertyWebkitMarquee:
2420 return parseShorthand(propId, webkitMarqueeShorthand(), important);
2421 case CSSPropertyWebkitMarqueeIncrement:
2422 if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
2423 validPrimitive = true;
2425 validPrimitive = validUnit(value, FLength | FPercent);
2427 case CSSPropertyWebkitMarqueeRepetition:
2428 if (id == CSSValueInfinite)
2429 validPrimitive = true;
2431 validPrimitive = validUnit(value, FInteger | FNonNeg);
2433 case CSSPropertyWebkitMarqueeSpeed:
2434 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
2435 validPrimitive = true;
2437 validPrimitive = validUnit(value, FTime | FInteger | FNonNeg);
2439 #if ENABLE(CSS_REGIONS)
2440 case CSSPropertyWebkitFlowInto:
2441 if (!cssRegionsEnabled())
2443 return parseFlowThread(propId, important);
2444 case CSSPropertyWebkitFlowFrom:
2445 if (!cssRegionsEnabled())
2447 return parseRegionThread(propId, important);
2449 case CSSPropertyWebkitTransform:
2450 if (id == CSSValueNone)
2451 validPrimitive = true;
2453 RefPtr<CSSValue> transformValue = parseTransform();
2454 if (transformValue) {
2455 addProperty(propId, transformValue.release(), important);
2461 case CSSPropertyWebkitTransformOrigin:
2462 case CSSPropertyWebkitTransformOriginX:
2463 case CSSPropertyWebkitTransformOriginY:
2464 case CSSPropertyWebkitTransformOriginZ: {
2465 RefPtr<CSSValue> val1;
2466 RefPtr<CSSValue> val2;
2467 RefPtr<CSSValue> val3;
2468 CSSPropertyID propId1, propId2, propId3;
2469 if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
2470 addProperty(propId1, val1.release(), important);
2472 addProperty(propId2, val2.release(), important);
2474 addProperty(propId3, val3.release(), important);
2479 case CSSPropertyWebkitPerspective:
2480 if (id == CSSValueNone)
2481 validPrimitive = true;
2483 // Accepting valueless numbers is a quirk of the -webkit prefixed version of the property.
2484 if (validUnit(value, FNumber | FLength | FNonNeg)) {
2485 RefPtr<CSSValue> val = createPrimitiveNumericValue(value);
2487 addProperty(propId, val.release(), important);
2494 case CSSPropertyWebkitPerspectiveOrigin:
2495 case CSSPropertyWebkitPerspectiveOriginX:
2496 case CSSPropertyWebkitPerspectiveOriginY: {
2497 RefPtr<CSSValue> val1;
2498 RefPtr<CSSValue> val2;
2499 CSSPropertyID propId1, propId2;
2500 if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
2501 addProperty(propId1, val1.release(), important);
2503 addProperty(propId2, val2.release(), important);
2508 case CSSPropertyWebkitAnimationDelay:
2509 case CSSPropertyWebkitAnimationDirection:
2510 case CSSPropertyWebkitAnimationDuration:
2511 case CSSPropertyWebkitAnimationFillMode:
2512 case CSSPropertyWebkitAnimationName:
2513 case CSSPropertyWebkitAnimationPlayState:
2514 case CSSPropertyWebkitAnimationIterationCount:
2515 case CSSPropertyWebkitAnimationTimingFunction:
2516 case CSSPropertyWebkitTransitionDelay:
2517 case CSSPropertyWebkitTransitionDuration:
2518 case CSSPropertyWebkitTransitionTimingFunction:
2519 case CSSPropertyWebkitTransitionProperty: {
2520 RefPtr<CSSValue> val;
2521 if (parseAnimationProperty(propId, val)) {
2522 addProperty(propId, val.release(), important);
2528 case CSSPropertyWebkitGridColumns:
2529 case CSSPropertyWebkitGridRows:
2530 if (!cssGridLayoutEnabled())
2532 return parseGridTrackList(propId, important);
2534 case CSSPropertyWebkitGridColumn:
2535 case CSSPropertyWebkitGridRow:
2536 if (!cssGridLayoutEnabled())
2538 validPrimitive = id == CSSValueAuto || validUnit(value, FInteger);
2541 case CSSPropertyWebkitMarginCollapse: {
2543 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2544 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important))
2546 CSSValue* value = m_parsedProperties.last().value();
2547 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
2550 else if (num == 2) {
2551 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2552 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important) || !parseValue(webkitMarginCollapseShorthand().properties()[1], important))
2558 case CSSPropertyTextLineThroughWidth:
2559 case CSSPropertyTextOverlineWidth:
2560 case CSSPropertyTextUnderlineWidth:
2561 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
2562 id == CSSValueMedium || id == CSSValueThick)
2563 validPrimitive = true;
2565 validPrimitive = !id && validUnit(value, FNumber | FLength | FPercent);
2567 case CSSPropertyWebkitColumnCount:
2568 if (id == CSSValueAuto)
2569 validPrimitive = true;
2571 validPrimitive = !id && validUnit(value, FPositiveInteger, CSSQuirksMode);
2573 case CSSPropertyWebkitColumnGap: // normal | <length>
2574 if (id == CSSValueNormal)
2575 validPrimitive = true;
2577 validPrimitive = validUnit(value, FLength | FNonNeg);
2579 case CSSPropertyWebkitColumnAxis:
2580 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto)
2581 validPrimitive = true;
2583 case CSSPropertyWebkitColumnProgression:
2584 if (id == CSSValueNormal || id == CSSValueReverse)
2585 validPrimitive = true;
2587 case CSSPropertyWebkitColumnSpan: // none | all | 1 (will be dropped in the unprefixed property)
2588 if (id == CSSValueAll || id == CSSValueNone)
2589 validPrimitive = true;
2591 validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValue == 1;
2593 case CSSPropertyWebkitColumnWidth: // auto | <length>
2594 if (id == CSSValueAuto)
2595 validPrimitive = true;
2596 else // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property.
2597 validPrimitive = validUnit(value, FLength | FNonNeg, CSSStrictMode) && value->fValue;
2599 // End of CSS3 properties
2601 // Apple specific properties. These will never be standardized and are purely to
2602 // support custom WebKit-based Apple applications.
2603 case CSSPropertyWebkitLineClamp:
2604 // When specifying number of lines, don't allow 0 as a valid value
2605 // When specifying either type of unit, require non-negative integers
2606 validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTAGE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, CSSQuirksMode));
2609 case CSSPropertyWebkitFontSizeDelta: // <length>
2610 validPrimitive = validUnit(value, FLength);
2613 case CSSPropertyWebkitHighlight:
2614 if (id == CSSValueNone || value->unit == CSSPrimitiveValue::CSS_STRING)
2615 validPrimitive = true;
2618 case CSSPropertyWebkitHyphenateCharacter:
2619 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
2620 validPrimitive = true;
2623 case CSSPropertyWebkitHyphenateLimitBefore:
2624 case CSSPropertyWebkitHyphenateLimitAfter:
2625 if (id == CSSValueAuto || validUnit(value, FInteger | FNonNeg, CSSStrictMode))
2626 validPrimitive = true;
2629 case CSSPropertyWebkitHyphenateLimitLines:
2630 if (id == CSSValueNoLimit || validUnit(value, FInteger | FNonNeg, CSSStrictMode))
2631 validPrimitive = true;
2634 case CSSPropertyWebkitLineGrid:
2635 if (id == CSSValueNone)
2636 validPrimitive = true;
2637 else if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
2638 String lineGridValue = String(value->string);
2639 if (!lineGridValue.isEmpty()) {
2640 addProperty(propId, cssValuePool().createValue(lineGridValue, CSSPrimitiveValue::CSS_STRING), important);
2645 case CSSPropertyWebkitLocale:
2646 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
2647 validPrimitive = true;
2650 #if ENABLE(DASHBOARD_SUPPORT)
2651 case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region>
2652 if (value->unit == CSSParserValue::Function || id == CSSValueNone)
2653 return parseDashboardRegions(propId, important);
2656 // End Apple-specific properties
2658 #if ENABLE(DRAGGABLE_REGION)
2659 case CSSPropertyWebkitAppRegion:
2660 if (id >= CSSValueDrag && id <= CSSValueNoDrag)
2661 validPrimitive = true;
2665 #if ENABLE(TOUCH_EVENTS)
2666 case CSSPropertyWebkitTapHighlightColor:
2667 if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu
2668 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2669 validPrimitive = true;
2671 parsedValue = parseColor();
2673 m_valueList->next();
2678 /* shorthand properties */
2679 case CSSPropertyBackground: {
2680 // Position must come before color in this array because a plain old "0" is a legal color
2681 // in quirks mode but it's usually the X coordinate of a position.
2682 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
2683 CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin,
2684 CSSPropertyBackgroundClip, CSSPropertyBackgroundColor, CSSPropertyBackgroundSize };
2685 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2687 case CSSPropertyWebkitMask: {
2688 const CSSPropertyID properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskRepeat,
2689 CSSPropertyWebkitMaskPosition, CSSPropertyWebkitMaskOrigin, CSSPropertyWebkitMaskClip, CSSPropertyWebkitMaskSize };
2690 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2692 case CSSPropertyBorder:
2693 // [ 'border-width' || 'border-style' || <color> ] | inherit
2695 if (parseShorthand(propId, borderAbridgedShorthand(), important)) {
2696 // The CSS3 Borders and Backgrounds specification says that border also resets border-image. It's as
2697 // though a value of none was specified for the image.
2698 addProperty(CSSPropertyBorderImage, cssValuePool().createImplicitInitialValue(), important);
2703 case CSSPropertyBorderTop:
2704 // [ 'border-top-width' || 'border-style' || <color> ] | inherit
2705 return parseShorthand(propId, borderTopShorthand(), important);
2706 case CSSPropertyBorderRight:
2707 // [ 'border-right-width' || 'border-style' || <color> ] | inherit
2708 return parseShorthand(propId, borderRightShorthand(), important);
2709 case CSSPropertyBorderBottom:
2710 // [ 'border-bottom-width' || 'border-style' || <color> ] | inherit
2711 return parseShorthand(propId, borderBottomShorthand(), important);
2712 case CSSPropertyBorderLeft:
2713 // [ 'border-left-width' || 'border-style' || <color> ] | inherit
2714 return parseShorthand(propId, borderLeftShorthand(), important);
2715 case CSSPropertyWebkitBorderStart:
2716 return parseShorthand(propId, webkitBorderStartShorthand(), important);
2717 case CSSPropertyWebkitBorderEnd:
2718 return parseShorthand(propId, webkitBorderEndShorthand(), important);
2719 case CSSPropertyWebkitBorderBefore:
2720 return parseShorthand(propId, webkitBorderBeforeShorthand(), important);
2721 case CSSPropertyWebkitBorderAfter:
2722 return parseShorthand(propId, webkitBorderAfterShorthand(), important);
2723 case CSSPropertyOutline:
2724 // [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit
2725 return parseShorthand(propId, outlineShorthand(), important);
2726 case CSSPropertyBorderColor:
2727 // <color>{1,4} | inherit
2728 return parse4Values(propId, borderColorShorthand().properties(), important);
2729 case CSSPropertyBorderWidth:
2730 // <border-width>{1,4} | inherit
2731 return parse4Values(propId, borderWidthShorthand().properties(), important);
2732 case CSSPropertyBorderStyle:
2733 // <border-style>{1,4} | inherit
2734 return parse4Values(propId, borderStyleShorthand().properties(), important);
2735 case CSSPropertyMargin:
2736 // <margin-width>{1,4} | inherit
2737 return parse4Values(propId, marginShorthand().properties(), important);
2738 case CSSPropertyPadding:
2739 // <padding-width>{1,4} | inherit
2740 return parse4Values(propId, paddingShorthand().properties(), important);
2741 case CSSPropertyWebkitFlexFlow:
2742 return parseShorthand(propId, webkitFlexFlowShorthand(), important);
2743 case CSSPropertyFont:
2744 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
2745 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
2746 if (id >= CSSValueCaption && id <= CSSValueStatusBar)
2747 validPrimitive = true;
2749 return parseFont(important);
2751 case CSSPropertyListStyle:
2752 return parseShorthand(propId, listStyleShorthand(), important);
2753 case CSSPropertyWebkitColumns:
2754 return parseShorthand(propId, webkitColumnsShorthand(), important);
2755 case CSSPropertyWebkitColumnRule:
2756 return parseShorthand(propId, webkitColumnRuleShorthand(), important);
2757 case CSSPropertyWebkitTextStroke:
2758 return parseShorthand(propId, webkitTextStrokeShorthand(), important);
2759 case CSSPropertyWebkitAnimation:
2760 return parseAnimationShorthand(important);
2761 case CSSPropertyWebkitTransition:
2762 return parseTransitionShorthand(important);
2763 case CSSPropertyInvalid:
2765 case CSSPropertyPage:
2766 return parsePage(propId, important);
2767 case CSSPropertyFontStretch:
2768 case CSSPropertyTextLineThrough:
2769 case CSSPropertyTextOverline:
2770 case CSSPropertyTextUnderline:
2772 // CSS Text Layout Module Level 3: Vertical writing support
2773 case CSSPropertyWebkitTextEmphasis:
2774 return parseShorthand(propId, webkitTextEmphasisShorthand(), important);
2776 case CSSPropertyWebkitTextEmphasisStyle:
2777 return parseTextEmphasisStyle(important);
2779 case CSSPropertyWebkitTextOrientation:
2780 // FIXME: For now just support sideways, sideways-right, upright and vertical-right.
2781 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSValueVerticalRight || id == CSSValueUpright)
2782 validPrimitive = true;
2785 case CSSPropertyWebkitLineBoxContain:
2786 if (id == CSSValueNone)
2787 validPrimitive = true;
2789 return parseLineBoxContain(important);
2791 case CSSPropertyWebkitFontFeatureSettings:
2792 if (id == CSSValueNormal)
2793 validPrimitive = true;
2795 return parseFontFeatureSettings(important);
2798 case CSSPropertyWebkitFontVariantLigatures:
2799 if (id == CSSValueNormal)
2800 validPrimitive = true;
2802 return parseFontVariantLigatures(important);
2804 case CSSPropertyWebkitClipPath:
2805 if (id == CSSValueNone)
2806 validPrimitive = true;
2807 else if (value->unit == CSSParserValue::Function)
2808 return parseBasicShape(propId, important);
2810 else if (value->unit == CSSPrimitiveValue::CSS_URI) {
2811 parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_URI);
2812 addProperty(propId, parsedValue.release(), important);
2817 #if ENABLE(CSS_EXCLUSIONS)
2818 case CSSPropertyWebkitShapeInside:
2819 case CSSPropertyWebkitShapeOutside:
2820 if (!RuntimeEnabledFeatures::cssExclusionsEnabled())
2822 if (id == CSSValueAuto)
2823 validPrimitive = true;
2824 else if (propId == CSSPropertyWebkitShapeInside && id == CSSValueOutsideShape)
2825 validPrimitive = true;
2826 else if (value->unit == CSSParserValue::Function)
2827 return parseBasicShape(propId, important);
2829 case CSSPropertyWebkitShapeMargin:
2830 case CSSPropertyWebkitShapePadding:
2831 validPrimitive = (RuntimeEnabledFeatures::cssExclusionsEnabled() && !id && validUnit(value, FLength | FNonNeg));
2833 case CSSPropertyWebkitWrap:
2834 return RuntimeEnabledFeatures::cssExclusionsEnabled() && parseShorthand(propId, webkitWrapShorthand(), important);
2836 #if ENABLE(CSS_IMAGE_ORIENTATION)
2837 case CSSPropertyImageOrientation:
2838 validPrimitive = !id && validUnit(value, FAngle);
2841 #if ENABLE(CSS_IMAGE_RESOLUTION)
2842 case CSSPropertyImageResolution:
2843 parsedValue = parseImageResolution(m_valueList.get());
2846 m_valueList->next();
2849 case CSSPropertyBorderBottomStyle:
2850 case CSSPropertyBorderCollapse:
2851 case CSSPropertyBorderLeftStyle:
2852 case CSSPropertyBorderRightStyle:
2853 case CSSPropertyBorderTopStyle:
2854 case CSSPropertyBoxSizing:
2855 case CSSPropertyCaptionSide:
2856 case CSSPropertyClear:
2857 case CSSPropertyDirection:
2858 case CSSPropertyDisplay:
2859 case CSSPropertyEmptyCells:
2860 case CSSPropertyFloat:
2861 case CSSPropertyFontStyle:
2862 case CSSPropertyImageRendering:
2863 case CSSPropertyListStylePosition:
2864 case CSSPropertyListStyleType:
2865 case CSSPropertyOutlineStyle:
2866 case CSSPropertyOverflowWrap:
2867 case CSSPropertyOverflowX:
2868 case CSSPropertyOverflowY:
2869 case CSSPropertyPageBreakAfter:
2870 case CSSPropertyPageBreakBefore:
2871 case CSSPropertyPageBreakInside:
2872 case CSSPropertyPointerEvents:
2873 case CSSPropertyPosition:
2874 case CSSPropertyResize:
2875 case CSSPropertySpeak:
2876 case CSSPropertyTableLayout:
2877 case CSSPropertyTextLineThroughMode:
2878 case CSSPropertyTextLineThroughStyle:
2879 case CSSPropertyTextOverflow:
2880 case CSSPropertyTextOverlineMode:
2881 case CSSPropertyTextOverlineStyle:
2882 case CSSPropertyTextRendering:
2883 case CSSPropertyTextTransform:
2884 case CSSPropertyTextUnderlineMode:
2885 case CSSPropertyTextUnderlineStyle:
2886 #if ENABLE(CSS_VARIABLES)
2887 case CSSPropertyVariable:
2889 case CSSPropertyVisibility:
2890 case CSSPropertyWebkitAppearance:
2891 case CSSPropertyWebkitBackfaceVisibility:
2892 case CSSPropertyWebkitBorderAfterStyle:
2893 case CSSPropertyWebkitBorderBeforeStyle:
2894 case CSSPropertyWebkitBorderEndStyle:
2895 case CSSPropertyWebkitBorderFit:
2896 case CSSPropertyWebkitBorderStartStyle:
2897 case CSSPropertyWebkitBoxAlign:
2898 #if ENABLE(CSS_BOX_DECORATION_BREAK)
2899 case CSSPropertyWebkitBoxDecorationBreak:
2901 case CSSPropertyWebkitBoxDirection:
2902 case CSSPropertyWebkitBoxLines:
2903 case CSSPropertyWebkitBoxOrient:
2904 case CSSPropertyWebkitBoxPack:
2905 case CSSPropertyWebkitColorCorrection:
2906 case CSSPropertyWebkitColumnBreakAfter:
2907 case CSSPropertyWebkitColumnBreakBefore:
2908 case CSSPropertyWebkitColumnBreakInside:
2909 case CSSPropertyWebkitColumnRuleStyle:
2910 case CSSPropertyWebkitAlignContent:
2911 case CSSPropertyWebkitAlignItems:
2912 case CSSPropertyWebkitAlignSelf:
2913 case CSSPropertyWebkitFlexDirection:
2914 case CSSPropertyWebkitFlexWrap:
2915 case CSSPropertyWebkitJustifyContent:
2916 case CSSPropertyWebkitFontKerning:
2917 case CSSPropertyWebkitFontSmoothing:
2918 case CSSPropertyWebkitHyphens:
2919 case CSSPropertyWebkitGridAutoFlow:
2920 case CSSPropertyWebkitLineAlign:
2921 case CSSPropertyWebkitLineBreak:
2922 case CSSPropertyWebkitLineSnap:
2923 case CSSPropertyWebkitMarginAfterCollapse:
2924 case CSSPropertyWebkitMarginBeforeCollapse:
2925 case CSSPropertyWebkitMarginBottomCollapse:
2926 case CSSPropertyWebkitMarginTopCollapse:
2927 case CSSPropertyWebkitMarqueeDirection:
2928 case CSSPropertyWebkitMarqueeStyle:
2929 case CSSPropertyWebkitNbspMode:
2930 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
2931 case CSSPropertyWebkitOverflowScrolling:
2933 case CSSPropertyWebkitPrintColorAdjust:
2934 #if ENABLE(CSS_REGIONS)
2935 case CSSPropertyWebkitRegionBreakAfter:
2936 case CSSPropertyWebkitRegionBreakBefore:
2937 case CSSPropertyWebkitRegionBreakInside:
2938 case CSSPropertyWebkitRegionOverflow:
2940 case CSSPropertyWebkitRtlOrdering:
2941 case CSSPropertyWebkitRubyPosition:
2942 #if ENABLE(CSS3_TEXT)
2943 case CSSPropertyWebkitTextAlignLast:
2945 case CSSPropertyWebkitTextCombine:
2946 case CSSPropertyWebkitTextEmphasisPosition:
2947 case CSSPropertyWebkitTextSecurity:
2948 case CSSPropertyWebkitTextSizeAdjust:
2949 case CSSPropertyWebkitTransformStyle:
2950 case CSSPropertyWebkitUserDrag:
2951 case CSSPropertyWebkitUserModify:
2952 case CSSPropertyWebkitUserSelect:
2953 #if ENABLE(CSS_EXCLUSIONS)
2954 case CSSPropertyWebkitWrapFlow:
2955 case CSSPropertyWebkitWrapThrough:
2957 case CSSPropertyWebkitWritingMode:
2958 case CSSPropertyWhiteSpace:
2959 case CSSPropertyWordBreak:
2960 case CSSPropertyWordWrap:
2961 // These properties should be handled before in isValidKeywordPropertyAndValue().
2962 ASSERT_NOT_REACHED();
2964 #if ENABLE(CSS_DEVICE_ADAPTATION)
2965 // Properties bellow are validated inside parseViewportProperty, because we
2966 // check for parser state inViewportScope. We need to invalidate if someone
2967 // adds them outside a @viewport rule.
2968 case CSSPropertyMaxZoom:
2969 case CSSPropertyMinZoom:
2970 case CSSPropertyOrientation:
2971 case CSSPropertyUserZoom:
2972 validPrimitive = false;
2977 return parseSVGValue(propId, important);
2981 if (validPrimitive) {
2982 parsedValue = parseValidPrimitive(id, value);
2983 m_valueList->next();
2985 ASSERT(!m_parsedCalculation);
2987 if (!m_valueList->current() || inShorthand()) {
2988 addProperty(propId, parsedValue.release(), important);
2995 void CSSParser::addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
2998 if (lval->isBaseValueList())
2999 static_cast<CSSValueList*>(lval.get())->append(rval);
3001 PassRefPtr<CSSValue> oldlVal(lval.release());
3002 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3003 list->append(oldlVal);
3012 static bool parseBackgroundClip(CSSParserValue* parserValue, RefPtr<CSSValue>& cssValue)
3014 if (parserValue->id == CSSValueBorderBox || parserValue->id == CSSValuePaddingBox
3015 || parserValue->id == CSSValueContentBox || parserValue->id == CSSValueWebkitText) {
3016 cssValue = cssValuePool().createIdentifierValue(parserValue->id);
3022 const int cMaxFillProperties = 9;
3024 bool CSSParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* properties, int numProperties, bool important)
3026 ASSERT(numProperties <= cMaxFillProperties);
3027 if (numProperties > cMaxFillProperties)
3030 ShorthandScope scope(this, propId);
3032 bool parsedProperty[cMaxFillProperties] = { false };
3033 RefPtr<CSSValue> values[cMaxFillProperties];
3034 RefPtr<CSSValue> clipValue;
3035 RefPtr<CSSValue> positionYValue;
3036 RefPtr<CSSValue> repeatYValue;
3037 bool foundClip = false;
3039 bool foundPositionCSSProperty = false;
3041 while (m_valueList->current()) {
3042 CSSParserValue* val = m_valueList->current();
3043 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3044 // We hit the end. Fill in all remaining values with the initial value.
3045 m_valueList->next();
3046 for (i = 0; i < numProperties; ++i) {
3047 if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i])
3048 // Color is not allowed except as the last item in a list for backgrounds.
3049 // Reject the entire property.
3052 if (!parsedProperty[i] && properties[i] != CSSPropertyBackgroundColor) {
3053 addFillValue(values[i], cssValuePool().createImplicitInitialValue());
3054 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3055 addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
3056 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3057 addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
3058 if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) {
3059 // If background-origin wasn't present, then reset background-clip also.
3060 addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
3063 parsedProperty[i] = false;
3065 if (!m_valueList->current())
3069 bool sizeCSSPropertyExpected = false;
3070 if (isForwardSlashOperator(val) && foundPositionCSSProperty) {
3071 sizeCSSPropertyExpected = true;
3072 m_valueList->next();
3075 foundPositionCSSProperty = false;
3077 for (i = 0; !found && i < numProperties; ++i) {
3079 if (sizeCSSPropertyExpected && (properties[i] != CSSPropertyBackgroundSize && properties[i] != CSSPropertyWebkitMaskSize))
3081 if (!sizeCSSPropertyExpected && (properties[i] == CSSPropertyBackgroundSize || properties[i] == CSSPropertyWebkitMaskSize))
3084 if (!parsedProperty[i]) {
3085 RefPtr<CSSValue> val1;
3086 RefPtr<CSSValue> val2;
3087 CSSPropertyID propId1, propId2;
3088 CSSParserValue* parserValue = m_valueList->current();
3089 if (parseFillProperty(properties[i], propId1, propId2, val1, val2)) {
3090 parsedProperty[i] = found = true;
3091 addFillValue(values[i], val1.release());
3092 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3093 addFillValue(positionYValue, val2.release());
3094 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3095 addFillValue(repeatYValue, val2.release());
3096 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
3097 // Reparse the value as a clip, and see if we succeed.
3098 if (parseBackgroundClip(parserValue, val1))
3099 addFillValue(clipValue, val1.release()); // The property parsed successfully.
3101 addFillValue(clipValue, cssValuePool().createImplicitInitialValue()); // Some value was used for origin that is not supported by clip. Just reset clip instead.
3103 if (properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) {
3105 addFillValue(clipValue, val1.release());
3108 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3109 foundPositionCSSProperty = true;
3114 // if we didn't find at least one match, this is an
3115 // invalid shorthand and we have to ignore it
3120 // Now add all of the properties we found.
3121 for (i = 0; i < numProperties; i++) {
3122 // Fill in any remaining properties with the initial value.
3123 if (!parsedProperty[i]) {
3124 addFillValue(values[i], cssValuePool().createImplicitInitialValue());
3125 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3126 addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
3127 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3128 addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
3129 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
3130 // If background-origin wasn't present, then reset background-clip also.
3131 addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
3134 if (properties[i] == CSSPropertyBackgroundPosition) {
3135 addProperty(CSSPropertyBackgroundPositionX, values[i].release(), important);
3136 // it's OK to call positionYValue.release() since we only see CSSPropertyBackgroundPosition once
3137 addProperty(CSSPropertyBackgroundPositionY, positionYValue.release(), important);
3138 } else if (properties[i] == CSSPropertyWebkitMaskPosition) {
3139 addProperty(CSSPropertyWebkitMaskPositionX, values[i].release(), important);
3140 // it's OK to call positionYValue.release() since we only see CSSPropertyWebkitMaskPosition once
3141 addProperty(CSSPropertyWebkitMaskPositionY, positionYValue.release(), important);
3142 } else if (properties[i] == CSSPropertyBackgroundRepeat) {
3143 addProperty(CSSPropertyBackgroundRepeatX, values[i].release(), important);
3144 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
3145 addProperty(CSSPropertyBackgroundRepeatY, repeatYValue.release(), important);
3146 } else if (properties[i] == CSSPropertyWebkitMaskRepeat) {
3147 addProperty(CSSPropertyWebkitMaskRepeatX, values[i].release(), important);
3148 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
3149 addProperty(CSSPropertyWebkitMaskRepeatY, repeatYValue.release(), important);
3150 } else if ((properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) && !foundClip)
3151 // Value is already set while updating origin
3154 addProperty(properties[i], values[i].release(), important);
3156 // Add in clip values when we hit the corresponding origin property.
3157 if (properties[i] == CSSPropertyBackgroundOrigin && !foundClip)
3158 addProperty(CSSPropertyBackgroundClip, clipValue.release(), important);
3159 else if (properties[i] == CSSPropertyWebkitMaskOrigin && !foundClip)
3160 addProperty(CSSPropertyWebkitMaskClip, clipValue.release(), important);
3166 #if ENABLE(CSS_VARIABLES)
3167 bool CSSParser::cssVariablesEnabled() const
3169 return m_context.isCSSVariablesEnabled;
3172 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr<CSSParserValueList> value, bool important)
3174 // When CSSGrammar.y encounters an invalid declaration it passes null for the CSSParserValueList, just bail.
3178 static const unsigned prefixLength = sizeof("-webkit-var-") - 1;
3180 ASSERT(name.length() > prefixLength);
3181 AtomicString variableName = name.lowerSubstring(prefixLength, name.length() - prefixLength);
3183 StringBuilder builder;
3184 for (unsigned i = 0, size = value->size(); i < size; i++) {
3186 builder.append(' ');
3187 RefPtr<CSSValue> cssValue = value->valueAt(i)->createCSSValue();
3190 builder.append(cssValue->cssText());
3192 addProperty(CSSPropertyVariable, CSSVariableValue::create(variableName, builder.toString().lower()), important, false);
3196 void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
3199 if (lval->isValueList())
3200 static_cast<CSSValueList*>(lval.get())->append(rval);
3202 PassRefPtr<CSSValue> oldVal(lval.release());
3203 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3204 list->append(oldVal);
3213 bool CSSParser::parseAnimationShorthand(bool important)
3215 const StylePropertyShorthand& animationProperties = webkitAnimationShorthandForParsing();
3216 const unsigned numProperties = 7;
3218 // The list of properties in the shorthand should be the same
3219 // length as the list with animation name in last position, even though they are
3220 // in a different order.
3221 ASSERT(numProperties == webkitAnimationShorthandForParsing().length());
3222 ASSERT(numProperties == webkitAnimationShorthand().length());
3224 ShorthandScope scope(this, CSSPropertyWebkitAnimation);
3226 bool parsedProperty[numProperties] = { false };
3227 RefPtr<CSSValue> values[numProperties];
3230 while (m_valueList->current()) {
3231 CSSParserValue* val = m_valueList->current();
3232 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3233 // We hit the end. Fill in all remaining values with the initial value.
3234 m_valueList->next();
3235 for (i = 0; i < numProperties; ++i) {
3236 if (!parsedProperty[i])
3237 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3238 parsedProperty[i] = false;
3240 if (!m_valueList->current())
3245 for (i = 0; i < numProperties; ++i) {
3246 if (!parsedProperty[i]) {
3247 RefPtr<CSSValue> val;
3248 if (parseAnimationProperty(animationProperties.properties()[i], val)) {
3249 parsedProperty[i] = found = true;
3250 addAnimationValue(values[i], val.release());
3256 // if we didn't find at least one match, this is an
3257 // invalid shorthand and we have to ignore it
3262 for (i = 0; i < numProperties; ++i) {
3263 // If we didn't find the property, set an intial value.
3264 if (!parsedProperty[i])
3265 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3267 addProperty(animationProperties.properties()[i], values[i].release(), important);
3273 bool CSSParser::parseTransitionShorthand(bool important)
3275 const unsigned numProperties = 4;
3276 ASSERT(numProperties == webkitTransitionShorthand().length());
3278 ShorthandScope scope(this, CSSPropertyWebkitTransition);
3280 bool parsedProperty[numProperties] = { false };
3281 RefPtr<CSSValue> values[numProperties];
3284 while (m_valueList->current()) {
3285 CSSParserValue* val = m_valueList->current();
3286 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3287 // We hit the end. Fill in all remaining values with the initial value.
3288 m_valueList->next();
3289 for (i = 0; i < numProperties; ++i) {
3290 if (!parsedProperty[i])
3291 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3292 parsedProperty[i] = false;
3294 if (!m_valueList->current())
3299 for (i = 0; !found && i < numProperties; ++i) {
3300 if (!parsedProperty[i]) {
3301 RefPtr<CSSValue> val;
3302 if (parseAnimationProperty(webkitTransitionShorthand().properties()[i], val)) {
3303 parsedProperty[i] = found = true;
3304 addAnimationValue(values[i], val.release());
3309 // if we didn't find at least one match, this is an
3310 // invalid shorthand and we have to ignore it
3315 // Fill in any remaining properties with the initial value.
3316 for (i = 0; i < numProperties; ++i) {
3317 if (!parsedProperty[i])
3318 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3321 // Now add all of the properties we found.
3322 for (i = 0; i < numProperties; i++)
3323 addProperty(webkitTransitionShorthand().properties()[i], values[i].release(), important);
3328 bool CSSParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthand& shorthand, bool important)
3330 // We try to match as many properties as possible
3331 // We set up an array of booleans to mark which property has been found,
3332 // and we try to search for properties until it makes no longer any sense.
3333 ShorthandScope scope(this, propId);
3336 unsigned propertiesParsed = 0;
3337 bool propertyFound[6]= { false, false, false, false, false, false }; // 6 is enough size.
3339 while (m_valueList->current()) {
3341 for (unsigned propIndex = 0; !found && propIndex < shorthand.length(); ++propIndex) {
3342 if (!propertyFound[propIndex] && parseValue(shorthand.properties()[propIndex], important)) {
3343 propertyFound[propIndex] = found = true;
3348 // if we didn't find at least one match, this is an
3349 // invalid shorthand and we have to ignore it
3354 if (propertiesParsed == shorthand.length())
3357 // Fill in any remaining properties with the initial value.
3358 ImplicitScope implicitScope(this, PropertyImplicit);
3359 const StylePropertyShorthand* const* const propertiesForInitialization = shorthand.propertiesForInitialization();
3360 for (unsigned i = 0; i < shorthand.length(); ++i) {
3361 if (propertyFound[i])
3364 if (propertiesForInitialization) {
3365 const StylePropertyShorthand& initProperties = *(propertiesForInitialization[i]);
3366 for (unsigned propIndex = 0; propIndex < initProperties.length(); ++propIndex)
3367 addProperty(initProperties.properties()[propIndex], cssValuePool().createImplicitInitialValue(), important);
3369 addProperty(shorthand.properties()[i], cssValuePool().createImplicitInitialValue(), important);
3375 bool CSSParser::parse4Values(CSSPropertyID propId, const CSSPropertyID *properties, bool important)
3377 /* From the CSS 2 specs, 8.3
3378 * If there is only one value, it applies to all sides. If there are two values, the top and
3379 * bottom margins are set to the first value and the right and left margins are set to the second.
3380 * If there are three values, the top is set to the first value, the left and right are set to the
3381 * second, and the bottom is set to the third. If there are four values, they apply to the top,
3382 * right, bottom, and left, respectively.
3385 int num = inShorthand() ? 1 : m_valueList->size();
3387 ShorthandScope scope(this, propId);
3389 // the order is top, right, bottom, left
3392 if (!parseValue(properties[0], important))
3394 CSSValue* value = m_parsedProperties.last().value();
3395 ImplicitScope implicitScope(this, PropertyImplicit);
3396 addProperty(properties[1], value, important);
3397 addProperty(properties[2], value, important);
3398 addProperty(properties[3], value, important);
3402 if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
3404 CSSValue* value = m_parsedProperties[m_parsedProperties.size() - 2].value();
3405 ImplicitScope implicitScope(this, PropertyImplicit);