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_EXS:
1605 case CSSPrimitiveValue::CSS_PX:
1606 case CSSPrimitiveValue::CSS_CM:
1607 case CSSPrimitiveValue::CSS_MM:
1608 case CSSPrimitiveValue::CSS_IN:
1609 case CSSPrimitiveValue::CSS_PT:
1610 case CSSPrimitiveValue::CSS_PC:
1611 case CSSPrimitiveValue::CSS_VW:
1612 case CSSPrimitiveValue::CSS_VH:
1613 case CSSPrimitiveValue::CSS_VMIN:
1614 case CSSPrimitiveValue::CSS_VMAX:
1615 b = (unitflags & FLength);
1617 case CSSPrimitiveValue::CSS_MS:
1618 case CSSPrimitiveValue::CSS_S:
1619 b = (unitflags & FTime);
1621 case CSSPrimitiveValue::CSS_DEG:
1622 case CSSPrimitiveValue::CSS_RAD:
1623 case CSSPrimitiveValue::CSS_GRAD:
1624 case CSSPrimitiveValue::CSS_TURN:
1625 b = (unitflags & FAngle);
1627 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1628 case CSSPrimitiveValue::CSS_DPPX:
1629 case CSSPrimitiveValue::CSS_DPI:
1630 case CSSPrimitiveValue::CSS_DPCM:
1631 b = (unitflags & FResolution);
1634 case CSSPrimitiveValue::CSS_HZ:
1635 case CSSPrimitiveValue::CSS_KHZ:
1636 case CSSPrimitiveValue::CSS_DIMENSION:
1640 if (b && unitflags & FNonNeg && value->fValue < 0)
1645 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSParserValue* value)
1647 #if ENABLE(CSS_VARIABLES)
1648 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
1649 return createPrimitiveVariableNameValue(value);
1652 if (m_parsedCalculation) {
1653 ASSERT(isCalculation(value));
1654 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1657 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1658 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1659 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
1660 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
1661 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM));
1663 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1664 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
1665 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX));
1667 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value->unit));
1670 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSParserValue* value)
1672 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT);
1673 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRING);
1676 #if ENABLE(CSS_VARIABLES)
1677 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveVariableNameValue(CSSParserValue* value)
1679 ASSERT(value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME);
1680 AtomicString variableName = String(value->string).lower();
1681 return CSSPrimitiveValue::create(variableName, CSSPrimitiveValue::CSS_VARIABLE_NAME);
1685 static inline bool isComma(CSSParserValue* value)
1687 return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
1690 static inline bool isForwardSlashOperator(CSSParserValue* value)
1693 return value->unit == CSSParserValue::Operator && value->iValue == '/';
1696 bool CSSParser::validWidth(CSSParserValue* value)
1699 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent)
1701 return !id && validUnit(value, FLength | FPercent | FNonNeg);
1704 // FIXME: Combine this with validWidth when we support fit-content, et al, for heights.
1705 bool CSSParser::validHeight(CSSParserValue* value)
1708 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic)
1710 return !id && validUnit(value, FLength | FPercent | FNonNeg);
1713 inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(int identifier, CSSParserValue* value)
1716 return cssValuePool().createIdentifierValue(identifier);
1717 if (value->unit == CSSPrimitiveValue::CSS_STRING)
1718 return createPrimitiveStringValue(value);
1719 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1720 return createPrimitiveNumericValue(value);
1721 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
1722 return createPrimitiveNumericValue(value);
1723 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
1724 return createPrimitiveNumericValue(value);
1725 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
1726 if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM)
1727 return createPrimitiveNumericValue(value);
1729 #if ENABLE(CSS_VARIABLES)
1730 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
1731 return createPrimitiveVariableNameValue(value);
1733 if (value->unit >= CSSParserValue::Q_EMS)
1734 return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
1735 if (isCalculation(value))
1736 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1741 void CSSParser::addExpandedPropertyForValue(CSSPropertyID propId, PassRefPtr<CSSValue> prpValue, bool important)
1743 const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
1744 unsigned shorthandLength = shorthand.length();
1745 if (!shorthandLength) {
1746 addProperty(propId, prpValue, important);
1750 RefPtr<CSSValue> value = prpValue;
1751 ShorthandScope scope(this, propId);
1752 const CSSPropertyID* longhands = shorthand.properties();
1753 for (unsigned i = 0; i < shorthandLength; ++i)
1754 addProperty(longhands[i], value, important);
1757 bool CSSParser::parseValue(CSSPropertyID propId, bool important)
1762 CSSParserValue* value = m_valueList->current();
1767 // Note: m_parsedCalculation is used to pass the calc value to validUnit and then cleared at the end of this function.
1768 // FIXME: This is to avoid having to pass parsedCalc to all validUnit callers.
1769 ASSERT(!m_parsedCalculation);
1773 int num = inShorthand() ? 1 : m_valueList->size();
1775 if (id == CSSValueInherit) {
1778 addExpandedPropertyForValue(propId, cssValuePool().createInheritedValue(), important);
1781 else if (id == CSSValueInitial) {
1784 addExpandedPropertyForValue(propId, cssValuePool().createExplicitInitialValue(), important);
1788 #if ENABLE(CSS_VARIABLES)
1789 if (!id && value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME && num == 1) {
1790 addProperty(propId, createPrimitiveVariableNameValue(value), important);
1791 m_valueList->next();
1794 ASSERT(propId != CSSPropertyVariable);
1797 if (isKeywordPropertyID(propId)) {
1798 if (!isValidKeywordPropertyAndValue(propId, id, m_context))
1800 if (m_valueList->next() && !inShorthand())
1802 addProperty(propId, cssValuePool().createIdentifierValue(id), important);
1806 #if ENABLE(CSS_DEVICE_ADAPTATION)
1808 return parseViewportProperty(propId, important);
1811 bool validPrimitive = false;
1812 RefPtr<CSSValue> parsedValue;
1815 case CSSPropertySize: // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
1816 return parseSize(propId, important);
1818 case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit
1820 validPrimitive = true;
1822 return parseQuotes(propId, important);
1824 case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | isolate | isolate-override | plaintext | inherit
1825 if (id == CSSValueNormal
1826 || id == CSSValueEmbed
1827 || id == CSSValueBidiOverride
1828 || id == CSSValueWebkitIsolate
1829 || id == CSSValueWebkitIsolateOverride
1830 || id == CSSValueWebkitPlaintext)
1831 validPrimitive = true;
1834 case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
1835 // close-quote | no-open-quote | no-close-quote ]+ | inherit
1836 return parseContent(propId, important);
1838 case CSSPropertyClip: // <shape> | auto | inherit
1839 if (id == CSSValueAuto)
1840 validPrimitive = true;
1841 else if (value->unit == CSSParserValue::Function)
1842 return parseClipShape(propId, important);
1845 /* Start of supported CSS properties with validation. This is needed for parseShorthand to work
1846 * correctly and allows optimization in WebCore::applyRule(..)
1848 case CSSPropertyOverflow: {
1849 ShorthandScope scope(this, propId);
1850 if (num != 1 || !parseValue(CSSPropertyOverflowY, important))
1853 RefPtr<CSSValue> overflowXValue;
1855 // FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. If this value has been
1856 // set using the shorthand, then for now overflow-x will default to auto, but once we implement
1857 // pagination controls, it should default to hidden. If the overflow-y value is anything but
1858 // paged-x or paged-y, then overflow-x and overflow-y should have the same value.
1859 if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
1860 overflowXValue = cssValuePool().createIdentifierValue(CSSValueAuto);
1862 overflowXValue = m_parsedProperties.last().value();
1863 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important);
1867 case CSSPropertyTextAlign:
1868 // left | right | center | justify | -webkit-left | -webkit-right | -webkit-center | -webkit-match-parent
1869 // | start | end | <string> | inherit | -webkit-auto (converted to start)
1870 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd
1871 || value->unit == CSSPrimitiveValue::CSS_STRING)
1872 validPrimitive = true;
1875 case CSSPropertyFontWeight: { // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
1876 if (m_valueList->size() != 1)
1878 return parseFontWeight(important);
1880 case CSSPropertyBorderSpacing: {
1882 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1883 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
1885 CSSValue* value = m_parsedProperties.last().value();
1886 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important);
1889 else if (num == 2) {
1890 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1891 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important) || !parseValue(CSSPropertyWebkitBorderVerticalSpacing, important))
1897 case CSSPropertyWebkitBorderHorizontalSpacing:
1898 case CSSPropertyWebkitBorderVerticalSpacing:
1899 validPrimitive = validUnit(value, FLength | FNonNeg);
1901 case CSSPropertyOutlineColor: // <color> | invert | inherit
1902 // Outline color has "invert" as additional keyword.
1903 // Also, we want to allow the special focus color even in strict parsing mode.
1904 if (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor) {
1905 validPrimitive = true;
1909 case CSSPropertyBackgroundColor: // <color> | inherit
1910 case CSSPropertyBorderTopColor: // <color> | inherit
1911 case CSSPropertyBorderRightColor:
1912 case CSSPropertyBorderBottomColor:
1913 case CSSPropertyBorderLeftColor:
1914 case CSSPropertyWebkitBorderStartColor:
1915 case CSSPropertyWebkitBorderEndColor:
1916 case CSSPropertyWebkitBorderBeforeColor:
1917 case CSSPropertyWebkitBorderAfterColor:
1918 case CSSPropertyColor: // <color> | inherit
1919 case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors
1920 case CSSPropertyTextUnderlineColor:
1921 case CSSPropertyTextOverlineColor:
1922 case CSSPropertyWebkitColumnRuleColor:
1923 case CSSPropertyWebkitTextEmphasisColor:
1924 case CSSPropertyWebkitTextFillColor:
1925 case CSSPropertyWebkitTextStrokeColor:
1926 if (id == CSSValueWebkitText)
1927 validPrimitive = true; // Always allow this, even when strict parsing is on,
1928 // since we use this in our UA sheets.
1929 else if (id == CSSValueCurrentcolor)
1930 validPrimitive = true;
1931 else if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu ||
1932 (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
1933 validPrimitive = true;
1935 parsedValue = parseColor();
1937 m_valueList->next();
1941 case CSSPropertyCursor: {
1942 // Grammar defined by CSS3 UI and modified by CSS4 images:
1943 // [ [<image> [<x> <y>]?,]*
1944 // [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |
1945 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize |
1946 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help |
1947 // vertical-text | cell | context-menu | alias | copy | no-drop | not-allowed | -webkit-zoom-in
1948 // -webkit-zoom-out | all-scroll | -webkit-grab | -webkit-grabbing ] ] | inherit
1949 RefPtr<CSSValueList> list;
1951 RefPtr<CSSValue> image = 0;
1952 if (value->unit == CSSPrimitiveValue::CSS_URI) {
1953 String uri = value->string;
1955 image = CSSImageValue::create(completeURL(uri));
1956 #if ENABLE(CSS_IMAGE_SET) && ENABLE(MOUSE_CURSOR_SCALE)
1957 } else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
1958 image = parseImageSet(m_valueList.get());
1966 value = m_valueList->next();
1967 while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
1968 coords.append(int(value->fValue));
1969 value = m_valueList->next();
1971 bool hasHotSpot = false;
1972 IntPoint hotSpot(-1, -1);
1973 int nrcoords = coords.size();
1974 if (nrcoords > 0 && nrcoords != 2)
1976 if (nrcoords == 2) {
1978 hotSpot = IntPoint(coords[0], coords[1]);
1982 list = CSSValueList::createCommaSeparated();
1985 list->append(CSSCursorImageValue::create(image, hasHotSpot, hotSpot));
1987 if ((inStrictMode() && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ',')))
1989 value = m_valueList->next(); // comma
1992 if (!value) { // no value after url list (MSIE 5 compatibility)
1993 if (list->length() != 1)
1995 } else if (inQuirksMode() && value->id == CSSValueHand) // MSIE 5 compatibility :/
1996 list->append(cssValuePool().createIdentifierValue(CSSValuePointer));
1997 else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
1998 list->append(cssValuePool().createIdentifierValue(value->id));
1999 m_valueList->next();
2000 parsedValue = list.release();
2004 if (inQuirksMode() && value->id == CSSValueHand) { // MSIE 5 compatibility :/
2005 id = CSSValuePointer;
2006 validPrimitive = true;
2007 } else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
2008 validPrimitive = true;
2010 ASSERT_NOT_REACHED();
2016 case CSSPropertyBackgroundAttachment:
2017 case CSSPropertyBackgroundClip:
2018 case CSSPropertyWebkitBackgroundClip:
2019 case CSSPropertyWebkitBackgroundComposite:
2020 case CSSPropertyBackgroundImage:
2021 case CSSPropertyBackgroundOrigin:
2022 case CSSPropertyWebkitBackgroundOrigin:
2023 case CSSPropertyBackgroundPosition:
2024 case CSSPropertyBackgroundPositionX:
2025 case CSSPropertyBackgroundPositionY:
2026 case CSSPropertyBackgroundSize:
2027 case CSSPropertyWebkitBackgroundSize:
2028 case CSSPropertyBackgroundRepeat:
2029 case CSSPropertyBackgroundRepeatX:
2030 case CSSPropertyBackgroundRepeatY:
2031 case CSSPropertyWebkitMaskClip:
2032 case CSSPropertyWebkitMaskComposite:
2033 case CSSPropertyWebkitMaskImage:
2034 case CSSPropertyWebkitMaskOrigin:
2035 case CSSPropertyWebkitMaskPosition:
2036 case CSSPropertyWebkitMaskPositionX:
2037 case CSSPropertyWebkitMaskPositionY:
2038 case CSSPropertyWebkitMaskSize:
2039 case CSSPropertyWebkitMaskRepeat:
2040 case CSSPropertyWebkitMaskRepeatX:
2041 case CSSPropertyWebkitMaskRepeatY:
2042 #if ENABLE(CSS_COMPOSITING)
2043 case CSSPropertyWebkitBackgroundBlendMode:
2046 RefPtr<CSSValue> val1;
2047 RefPtr<CSSValue> val2;
2048 CSSPropertyID propId1, propId2;
2049 bool result = false;
2050 if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
2051 OwnPtr<ShorthandScope> shorthandScope;
2052 if (propId == CSSPropertyBackgroundPosition ||
2053 propId == CSSPropertyBackgroundRepeat ||
2054 propId == CSSPropertyWebkitMaskPosition ||
2055 propId == CSSPropertyWebkitMaskRepeat) {
2056 shorthandScope = adoptPtr(new ShorthandScope(this, propId));
2058 addProperty(propId1, val1.release(), important);
2060 addProperty(propId2, val2.release(), important);
2063 m_implicitShorthand = false;
2066 case CSSPropertyListStyleImage: // <uri> | none | inherit
2067 case CSSPropertyBorderImageSource:
2068 case CSSPropertyWebkitMaskBoxImageSource:
2069 if (id == CSSValueNone) {
2070 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone);
2071 m_valueList->next();
2072 } else if (value->unit == CSSPrimitiveValue::CSS_URI) {
2073 parsedValue = CSSImageValue::create(completeURL(value->string));
2074 m_valueList->next();
2075 } else if (isGeneratedImageValue(value)) {
2076 if (parseGeneratedImage(m_valueList.get(), parsedValue))
2077 m_valueList->next();
2081 #if ENABLE(CSS_IMAGE_SET)
2082 else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
2083 parsedValue = parseImageSet(m_valueList.get());
2086 m_valueList->next();
2091 case CSSPropertyWebkitTextStrokeWidth:
2092 case CSSPropertyOutlineWidth: // <border-width> | inherit
2093 case CSSPropertyBorderTopWidth: //// <border-width> | inherit
2094 case CSSPropertyBorderRightWidth: // Which is defined as
2095 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
2096 case CSSPropertyBorderLeftWidth:
2097 case CSSPropertyWebkitBorderStartWidth:
2098 case CSSPropertyWebkitBorderEndWidth:
2099 case CSSPropertyWebkitBorderBeforeWidth:
2100 case CSSPropertyWebkitBorderAfterWidth:
2101 case CSSPropertyWebkitColumnRuleWidth:
2102 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
2103 validPrimitive = true;
2105 validPrimitive = validUnit(value, FLength | FNonNeg);
2108 case CSSPropertyLetterSpacing: // normal | <length> | inherit
2109 case CSSPropertyWordSpacing: // normal | <length> | inherit
2110 if (id == CSSValueNormal)
2111 validPrimitive = true;
2113 validPrimitive = validUnit(value, FLength);
2116 case CSSPropertyTextIndent: // <length> | <percentage> | inherit
2117 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2120 case CSSPropertyPaddingTop: //// <padding-width> | inherit
2121 case CSSPropertyPaddingRight: // Which is defined as
2122 case CSSPropertyPaddingBottom: // <length> | <percentage>
2123 case CSSPropertyPaddingLeft: ////
2124 case CSSPropertyWebkitPaddingStart:
2125 case CSSPropertyWebkitPaddingEnd:
2126 case CSSPropertyWebkitPaddingBefore:
2127 case CSSPropertyWebkitPaddingAfter:
2128 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
2131 case CSSPropertyMaxWidth:
2132 case CSSPropertyWebkitMaxLogicalWidth:
2133 validPrimitive = (id == CSSValueNone || validWidth(value));
2136 case CSSPropertyMinWidth:
2137 case CSSPropertyWebkitMinLogicalWidth:
2138 case CSSPropertyWidth:
2139 case CSSPropertyWebkitLogicalWidth:
2140 validPrimitive = (id == CSSValueAuto || validWidth(value));
2143 case CSSPropertyMaxHeight:
2144 case CSSPropertyWebkitMaxLogicalHeight:
2145 validPrimitive = (id == CSSValueNone || validHeight(value));
2148 case CSSPropertyMinHeight:
2149 case CSSPropertyWebkitMinLogicalHeight:
2150 case CSSPropertyHeight:
2151 case CSSPropertyWebkitLogicalHeight:
2152 validPrimitive = (id == CSSValueAuto || validHeight(value));
2155 case CSSPropertyFontSize:
2156 return parseFontSize(important);
2158 case CSSPropertyFontVariant: // normal | small-caps | inherit
2159 return parseFontVariant(important);
2161 case CSSPropertyVerticalAlign:
2162 // baseline | sub | super | top | text-top | middle | bottom | text-bottom |
2163 // <percentage> | <length> | inherit
2165 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
2166 validPrimitive = true;
2168 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2171 case CSSPropertyBottom: // <length> | <percentage> | auto | inherit
2172 case CSSPropertyLeft: // <length> | <percentage> | auto | inherit
2173 case CSSPropertyRight: // <length> | <percentage> | auto | inherit
2174 case CSSPropertyTop: // <length> | <percentage> | auto | inherit
2175 case CSSPropertyMarginTop: //// <margin-width> | inherit
2176 case CSSPropertyMarginRight: // Which is defined as
2177 case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit
2178 case CSSPropertyMarginLeft: ////
2179 case CSSPropertyWebkitMarginStart:
2180 case CSSPropertyWebkitMarginEnd:
2181 case CSSPropertyWebkitMarginBefore:
2182 case CSSPropertyWebkitMarginAfter:
2183 if (id == CSSValueAuto)
2184 validPrimitive = true;
2186 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2189 case CSSPropertyZIndex: // auto | <integer> | inherit
2190 if (id == CSSValueAuto) {
2191 validPrimitive = true;
2195 case CSSPropertyOrphans: // <integer> | inherit | auto (We've added support for auto for backwards compatibility)
2196 case CSSPropertyWidows: // <integer> | inherit | auto (Ditto)
2197 if (id == CSSValueAuto)
2198 validPrimitive = true;
2200 validPrimitive = (!id && validUnit(value, FInteger, CSSQuirksMode));
2203 case CSSPropertyLineHeight:
2204 return parseLineHeight(important);
2205 case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit
2206 if (id != CSSValueNone)
2207 return parseCounter(propId, 1, important);
2208 validPrimitive = true;
2210 case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit
2211 if (id != CSSValueNone)
2212 return parseCounter(propId, 0, important);
2213 validPrimitive = true;
2215 case CSSPropertyFontFamily:
2216 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit
2218 parsedValue = parseFontFamily();
2222 case CSSPropertyTextDecoration:
2223 case CSSPropertyWebkitTextDecorationsInEffect:
2224 // none | [ underline || overline || line-through || blink ] | inherit
2225 return parseTextDecoration(propId, important);
2227 #if ENABLE(CSS3_TEXT)
2228 case CSSPropertyWebkitTextDecorationLine:
2229 // none | [ underline || overline || line-through ] | inherit
2230 return parseTextDecoration(propId, important);
2232 case CSSPropertyWebkitTextDecorationStyle:
2233 // solid | double | dotted | dashed | wavy
2234 if (id == CSSValueSolid || id == CSSValueDouble || id == CSSValueDotted || id == CSSValueDashed || id == CSSValueWavy)
2235 validPrimitive = true;
2239 case CSSPropertyZoom: // normal | reset | document | <number> | <percentage> | inherit
2240 if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument)
2241 validPrimitive = true;
2243 validPrimitive = (!id && validUnit(value, FNumber | FPercent | FNonNeg, CSSStrictMode));
2246 case CSSPropertySrc: // Only used within @font-face, so cannot use inherit | initial or be !important. This is a list of urls or local references.
2247 return parseFontFaceSrc();
2249 case CSSPropertyUnicodeRange:
2250 return parseFontFaceUnicodeRange();
2252 /* CSS3 properties */
2254 case CSSPropertyBorderImage: {
2255 RefPtr<CSSValue> result;
2256 return parseBorderImage(propId, result, important);
2258 case CSSPropertyWebkitBorderImage:
2259 case CSSPropertyWebkitMaskBoxImage: {
2260 RefPtr<CSSValue> result;
2261 if (parseBorderImage(propId, result)) {
2262 addProperty(propId, result, important);
2267 case CSSPropertyBorderImageOutset:
2268 case CSSPropertyWebkitMaskBoxImageOutset: {
2269 RefPtr<CSSPrimitiveValue> result;
2270 if (parseBorderImageOutset(result)) {
2271 addProperty(propId, result, important);
2276 case CSSPropertyBorderImageRepeat:
2277 case CSSPropertyWebkitMaskBoxImageRepeat: {
2278 RefPtr<CSSValue> result;
2279 if (parseBorderImageRepeat(result)) {
2280 addProperty(propId, result, important);
2285 case CSSPropertyBorderImageSlice:
2286 case CSSPropertyWebkitMaskBoxImageSlice: {
2287 RefPtr<CSSBorderImageSliceValue> result;
2288 if (parseBorderImageSlice(propId, result)) {
2289 addProperty(propId, result, important);
2294 case CSSPropertyBorderImageWidth:
2295 case CSSPropertyWebkitMaskBoxImageWidth: {
2296 RefPtr<CSSPrimitiveValue> result;
2297 if (parseBorderImageWidth(result)) {
2298 addProperty(propId, result, important);
2303 case CSSPropertyBorderTopRightRadius:
2304 case CSSPropertyBorderTopLeftRadius:
2305 case CSSPropertyBorderBottomLeftRadius:
2306 case CSSPropertyBorderBottomRightRadius: {
2307 if (num != 1 && num != 2)
2309 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
2310 if (!validPrimitive)
2312 RefPtr<CSSPrimitiveValue> parsedValue1 = createPrimitiveNumericValue(value);
2313 RefPtr<CSSPrimitiveValue> parsedValue2;
2315 value = m_valueList->next();
2316 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
2317 if (!validPrimitive)
2319 parsedValue2 = createPrimitiveNumericValue(value);
2321 parsedValue2 = parsedValue1;
2323 addProperty(propId, createPrimitiveValuePair(parsedValue1.release(), parsedValue2.release()), important);
2326 case CSSPropertyTabSize:
2327 validPrimitive = validUnit(value, FInteger | FNonNeg);
2329 case CSSPropertyWebkitAspectRatio:
2330 return parseAspectRatio(important);
2331 case CSSPropertyBorderRadius:
2332 case CSSPropertyWebkitBorderRadius:
2333 return parseBorderRadius(propId, important);
2334 case CSSPropertyOutlineOffset:
2335 validPrimitive = validUnit(value, FLength | FPercent);
2337 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
2338 case CSSPropertyBoxShadow:
2339 case CSSPropertyWebkitBoxShadow:
2340 if (id == CSSValueNone)
2341 validPrimitive = true;
2343 RefPtr<CSSValueList> shadowValueList = parseShadow(m_valueList.get(), propId);
2344 if (shadowValueList) {
2345 addProperty(propId, shadowValueList.release(), important);
2346 m_valueList->next();
2352 case CSSPropertyWebkitBoxReflect:
2353 if (id == CSSValueNone)
2354 validPrimitive = true;
2356 return parseReflect(propId, important);
2358 case CSSPropertyOpacity:
2359 validPrimitive = validUnit(value, FNumber);
2361 case CSSPropertyWebkitBoxFlex:
2362 validPrimitive = validUnit(value, FNumber);
2364 case CSSPropertyWebkitBoxFlexGroup:
2365 validPrimitive = validUnit(value, FInteger | FNonNeg, CSSStrictMode);
2367 case CSSPropertyWebkitBoxOrdinalGroup:
2368 validPrimitive = validUnit(value, FInteger | FNonNeg, CSSStrictMode) && value->fValue;
2370 #if ENABLE(CSS_FILTERS)
2371 case CSSPropertyWebkitFilter:
2372 if (id == CSSValueNone)
2373 validPrimitive = true;
2375 RefPtr<CSSValue> val = parseFilter();
2377 addProperty(propId, val, important);
2384 #if ENABLE(CSS_COMPOSITING)
2385 case CSSPropertyWebkitBlendMode:
2386 validPrimitive = true;
2389 case CSSPropertyWebkitFlex: {
2390 ShorthandScope scope(this, propId);
2391 if (id == CSSValueNone) {
2392 addProperty(CSSPropertyWebkitFlexGrow, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2393 addProperty(CSSPropertyWebkitFlexShrink, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2394 addProperty(CSSPropertyWebkitFlexBasis, cssValuePool().createIdentifierValue(CSSValueAuto), important);
2397 return parseFlex(m_valueList.get(), important);
2399 case CSSPropertyWebkitFlexBasis:
2400 // FIXME: Support intrinsic dimensions too.
2401 if (id == CSSValueAuto)
2402 validPrimitive = true;
2404 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
2406 case CSSPropertyWebkitFlexGrow:
2407 case CSSPropertyWebkitFlexShrink:
2408 validPrimitive = validUnit(value, FNumber | FNonNeg);
2410 case CSSPropertyWebkitOrder:
2411 if (validUnit(value, FInteger, CSSStrictMode)) {
2412 // 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.
2413 parsedValue = cssValuePool().createValue(max(static_cast<double>(std::numeric_limits<int>::min() + 2), value->fValue),
2414 static_cast<CSSPrimitiveValue::UnitTypes>(value->unit));
2415 m_valueList->next();
2418 case CSSPropertyWebkitMarquee:
2419 return parseShorthand(propId, webkitMarqueeShorthand(), important);
2420 case CSSPropertyWebkitMarqueeIncrement:
2421 if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
2422 validPrimitive = true;
2424 validPrimitive = validUnit(value, FLength | FPercent);
2426 case CSSPropertyWebkitMarqueeRepetition:
2427 if (id == CSSValueInfinite)
2428 validPrimitive = true;
2430 validPrimitive = validUnit(value, FInteger | FNonNeg);
2432 case CSSPropertyWebkitMarqueeSpeed:
2433 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
2434 validPrimitive = true;
2436 validPrimitive = validUnit(value, FTime | FInteger | FNonNeg);
2438 #if ENABLE(CSS_REGIONS)
2439 case CSSPropertyWebkitFlowInto:
2440 if (!cssRegionsEnabled())
2442 return parseFlowThread(propId, important);
2443 case CSSPropertyWebkitFlowFrom:
2444 if (!cssRegionsEnabled())
2446 return parseRegionThread(propId, important);
2448 case CSSPropertyWebkitTransform:
2449 if (id == CSSValueNone)
2450 validPrimitive = true;
2452 RefPtr<CSSValue> transformValue = parseTransform();
2453 if (transformValue) {
2454 addProperty(propId, transformValue.release(), important);
2460 case CSSPropertyWebkitTransformOrigin:
2461 case CSSPropertyWebkitTransformOriginX:
2462 case CSSPropertyWebkitTransformOriginY:
2463 case CSSPropertyWebkitTransformOriginZ: {
2464 RefPtr<CSSValue> val1;
2465 RefPtr<CSSValue> val2;
2466 RefPtr<CSSValue> val3;
2467 CSSPropertyID propId1, propId2, propId3;
2468 if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
2469 addProperty(propId1, val1.release(), important);
2471 addProperty(propId2, val2.release(), important);
2473 addProperty(propId3, val3.release(), important);
2478 case CSSPropertyWebkitPerspective:
2479 if (id == CSSValueNone)
2480 validPrimitive = true;
2482 // Accepting valueless numbers is a quirk of the -webkit prefixed version of the property.
2483 if (validUnit(value, FNumber | FLength | FNonNeg)) {
2484 RefPtr<CSSValue> val = createPrimitiveNumericValue(value);
2486 addProperty(propId, val.release(), important);
2493 case CSSPropertyWebkitPerspectiveOrigin:
2494 case CSSPropertyWebkitPerspectiveOriginX:
2495 case CSSPropertyWebkitPerspectiveOriginY: {
2496 RefPtr<CSSValue> val1;
2497 RefPtr<CSSValue> val2;
2498 CSSPropertyID propId1, propId2;
2499 if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
2500 addProperty(propId1, val1.release(), important);
2502 addProperty(propId2, val2.release(), important);
2507 case CSSPropertyWebkitAnimationDelay:
2508 case CSSPropertyWebkitAnimationDirection:
2509 case CSSPropertyWebkitAnimationDuration:
2510 case CSSPropertyWebkitAnimationFillMode:
2511 case CSSPropertyWebkitAnimationName:
2512 case CSSPropertyWebkitAnimationPlayState:
2513 case CSSPropertyWebkitAnimationIterationCount:
2514 case CSSPropertyWebkitAnimationTimingFunction:
2515 case CSSPropertyWebkitTransitionDelay:
2516 case CSSPropertyWebkitTransitionDuration:
2517 case CSSPropertyWebkitTransitionTimingFunction:
2518 case CSSPropertyWebkitTransitionProperty: {
2519 RefPtr<CSSValue> val;
2520 if (parseAnimationProperty(propId, val)) {
2521 addProperty(propId, val.release(), important);
2527 case CSSPropertyWebkitGridColumns:
2528 case CSSPropertyWebkitGridRows:
2529 if (!cssGridLayoutEnabled())
2531 return parseGridTrackList(propId, important);
2533 case CSSPropertyWebkitGridColumn:
2534 case CSSPropertyWebkitGridRow:
2535 if (!cssGridLayoutEnabled())
2537 validPrimitive = id == CSSValueAuto || validUnit(value, FInteger);
2540 case CSSPropertyWebkitMarginCollapse: {
2542 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2543 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important))
2545 CSSValue* value = m_parsedProperties.last().value();
2546 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
2549 else if (num == 2) {
2550 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2551 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important) || !parseValue(webkitMarginCollapseShorthand().properties()[1], important))
2557 case CSSPropertyTextLineThroughWidth:
2558 case CSSPropertyTextOverlineWidth:
2559 case CSSPropertyTextUnderlineWidth:
2560 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
2561 id == CSSValueMedium || id == CSSValueThick)
2562 validPrimitive = true;
2564 validPrimitive = !id && validUnit(value, FNumber | FLength | FPercent);
2566 case CSSPropertyWebkitColumnCount:
2567 if (id == CSSValueAuto)
2568 validPrimitive = true;
2570 validPrimitive = !id && validUnit(value, FPositiveInteger, CSSQuirksMode);
2572 case CSSPropertyWebkitColumnGap: // normal | <length>
2573 if (id == CSSValueNormal)
2574 validPrimitive = true;
2576 validPrimitive = validUnit(value, FLength | FNonNeg);
2578 case CSSPropertyWebkitColumnAxis:
2579 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto)
2580 validPrimitive = true;
2582 case CSSPropertyWebkitColumnProgression:
2583 if (id == CSSValueNormal || id == CSSValueReverse)
2584 validPrimitive = true;
2586 case CSSPropertyWebkitColumnSpan: // none | all | 1 (will be dropped in the unprefixed property)
2587 if (id == CSSValueAll || id == CSSValueNone)
2588 validPrimitive = true;
2590 validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValue == 1;
2592 case CSSPropertyWebkitColumnWidth: // auto | <length>
2593 if (id == CSSValueAuto)
2594 validPrimitive = true;
2595 else // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property.
2596 validPrimitive = validUnit(value, FLength | FNonNeg, CSSStrictMode) && value->fValue;
2598 // End of CSS3 properties
2600 // Apple specific properties. These will never be standardized and are purely to
2601 // support custom WebKit-based Apple applications.
2602 case CSSPropertyWebkitLineClamp:
2603 // When specifying number of lines, don't allow 0 as a valid value
2604 // When specifying either type of unit, require non-negative integers
2605 validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTAGE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, CSSQuirksMode));
2608 case CSSPropertyWebkitFontSizeDelta: // <length>
2609 validPrimitive = validUnit(value, FLength);
2612 case CSSPropertyWebkitHighlight:
2613 if (id == CSSValueNone || value->unit == CSSPrimitiveValue::CSS_STRING)
2614 validPrimitive = true;
2617 case CSSPropertyWebkitHyphenateCharacter:
2618 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
2619 validPrimitive = true;
2622 case CSSPropertyWebkitHyphenateLimitBefore:
2623 case CSSPropertyWebkitHyphenateLimitAfter:
2624 if (id == CSSValueAuto || validUnit(value, FInteger | FNonNeg, CSSStrictMode))
2625 validPrimitive = true;
2628 case CSSPropertyWebkitHyphenateLimitLines:
2629 if (id == CSSValueNoLimit || validUnit(value, FInteger | FNonNeg, CSSStrictMode))
2630 validPrimitive = true;
2633 case CSSPropertyWebkitLineGrid:
2634 if (id == CSSValueNone)
2635 validPrimitive = true;
2636 else if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
2637 String lineGridValue = String(value->string);
2638 if (!lineGridValue.isEmpty()) {
2639 addProperty(propId, cssValuePool().createValue(lineGridValue, CSSPrimitiveValue::CSS_STRING), important);
2644 case CSSPropertyWebkitLocale:
2645 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
2646 validPrimitive = true;
2649 #if ENABLE(DASHBOARD_SUPPORT)
2650 case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region>
2651 if (value->unit == CSSParserValue::Function || id == CSSValueNone)
2652 return parseDashboardRegions(propId, important);
2655 // End Apple-specific properties
2657 #if ENABLE(DRAGGABLE_REGION)
2658 case CSSPropertyWebkitAppRegion:
2659 if (id >= CSSValueDrag && id <= CSSValueNoDrag)
2660 validPrimitive = true;
2664 #if ENABLE(TOUCH_EVENTS)
2665 case CSSPropertyWebkitTapHighlightColor:
2666 if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu
2667 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2668 validPrimitive = true;
2670 parsedValue = parseColor();
2672 m_valueList->next();
2677 /* shorthand properties */
2678 case CSSPropertyBackground: {
2679 // Position must come before color in this array because a plain old "0" is a legal color
2680 // in quirks mode but it's usually the X coordinate of a position.
2681 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
2682 CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin,
2683 CSSPropertyBackgroundClip, CSSPropertyBackgroundColor, CSSPropertyBackgroundSize };
2684 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2686 case CSSPropertyWebkitMask: {
2687 const CSSPropertyID properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskRepeat,
2688 CSSPropertyWebkitMaskPosition, CSSPropertyWebkitMaskOrigin, CSSPropertyWebkitMaskClip, CSSPropertyWebkitMaskSize };
2689 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2691 case CSSPropertyBorder:
2692 // [ 'border-width' || 'border-style' || <color> ] | inherit
2694 if (parseShorthand(propId, borderAbridgedShorthand(), important)) {
2695 // The CSS3 Borders and Backgrounds specification says that border also resets border-image. It's as
2696 // though a value of none was specified for the image.
2697 addProperty(CSSPropertyBorderImage, cssValuePool().createImplicitInitialValue(), important);
2702 case CSSPropertyBorderTop:
2703 // [ 'border-top-width' || 'border-style' || <color> ] | inherit
2704 return parseShorthand(propId, borderTopShorthand(), important);
2705 case CSSPropertyBorderRight:
2706 // [ 'border-right-width' || 'border-style' || <color> ] | inherit
2707 return parseShorthand(propId, borderRightShorthand(), important);
2708 case CSSPropertyBorderBottom:
2709 // [ 'border-bottom-width' || 'border-style' || <color> ] | inherit
2710 return parseShorthand(propId, borderBottomShorthand(), important);
2711 case CSSPropertyBorderLeft:
2712 // [ 'border-left-width' || 'border-style' || <color> ] | inherit
2713 return parseShorthand(propId, borderLeftShorthand(), important);
2714 case CSSPropertyWebkitBorderStart:
2715 return parseShorthand(propId, webkitBorderStartShorthand(), important);
2716 case CSSPropertyWebkitBorderEnd:
2717 return parseShorthand(propId, webkitBorderEndShorthand(), important);
2718 case CSSPropertyWebkitBorderBefore:
2719 return parseShorthand(propId, webkitBorderBeforeShorthand(), important);
2720 case CSSPropertyWebkitBorderAfter:
2721 return parseShorthand(propId, webkitBorderAfterShorthand(), important);
2722 case CSSPropertyOutline:
2723 // [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit
2724 return parseShorthand(propId, outlineShorthand(), important);
2725 case CSSPropertyBorderColor:
2726 // <color>{1,4} | inherit
2727 return parse4Values(propId, borderColorShorthand().properties(), important);
2728 case CSSPropertyBorderWidth:
2729 // <border-width>{1,4} | inherit
2730 return parse4Values(propId, borderWidthShorthand().properties(), important);
2731 case CSSPropertyBorderStyle:
2732 // <border-style>{1,4} | inherit
2733 return parse4Values(propId, borderStyleShorthand().properties(), important);
2734 case CSSPropertyMargin:
2735 // <margin-width>{1,4} | inherit
2736 return parse4Values(propId, marginShorthand().properties(), important);
2737 case CSSPropertyPadding:
2738 // <padding-width>{1,4} | inherit
2739 return parse4Values(propId, paddingShorthand().properties(), important);
2740 case CSSPropertyWebkitFlexFlow:
2741 return parseShorthand(propId, webkitFlexFlowShorthand(), important);
2742 case CSSPropertyFont:
2743 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
2744 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
2745 if (id >= CSSValueCaption && id <= CSSValueStatusBar)
2746 validPrimitive = true;
2748 return parseFont(important);
2750 case CSSPropertyListStyle:
2751 return parseShorthand(propId, listStyleShorthand(), important);
2752 case CSSPropertyWebkitColumns:
2753 return parseShorthand(propId, webkitColumnsShorthand(), important);
2754 case CSSPropertyWebkitColumnRule:
2755 return parseShorthand(propId, webkitColumnRuleShorthand(), important);
2756 case CSSPropertyWebkitTextStroke:
2757 return parseShorthand(propId, webkitTextStrokeShorthand(), important);
2758 case CSSPropertyWebkitAnimation:
2759 return parseAnimationShorthand(important);
2760 case CSSPropertyWebkitTransition:
2761 return parseTransitionShorthand(important);
2762 case CSSPropertyInvalid:
2764 case CSSPropertyPage:
2765 return parsePage(propId, important);
2766 case CSSPropertyFontStretch:
2767 case CSSPropertyTextLineThrough:
2768 case CSSPropertyTextOverline:
2769 case CSSPropertyTextUnderline:
2771 // CSS Text Layout Module Level 3: Vertical writing support
2772 case CSSPropertyWebkitTextEmphasis:
2773 return parseShorthand(propId, webkitTextEmphasisShorthand(), important);
2775 case CSSPropertyWebkitTextEmphasisStyle:
2776 return parseTextEmphasisStyle(important);
2778 case CSSPropertyWebkitTextOrientation:
2779 // FIXME: For now just support sideways, sideways-right, upright and vertical-right.
2780 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSValueVerticalRight || id == CSSValueUpright)
2781 validPrimitive = true;
2784 case CSSPropertyWebkitLineBoxContain:
2785 if (id == CSSValueNone)
2786 validPrimitive = true;
2788 return parseLineBoxContain(important);
2790 case CSSPropertyWebkitFontFeatureSettings:
2791 if (id == CSSValueNormal)
2792 validPrimitive = true;
2794 return parseFontFeatureSettings(important);
2797 case CSSPropertyWebkitFontVariantLigatures:
2798 if (id == CSSValueNormal)
2799 validPrimitive = true;
2801 return parseFontVariantLigatures(important);
2803 case CSSPropertyWebkitClipPath:
2804 if (id == CSSValueNone)
2805 validPrimitive = true;
2806 else if (value->unit == CSSParserValue::Function)
2807 return parseBasicShape(propId, important);
2809 else if (value->unit == CSSPrimitiveValue::CSS_URI) {
2810 parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_URI);
2811 addProperty(propId, parsedValue.release(), important);
2816 #if ENABLE(CSS_EXCLUSIONS)
2817 case CSSPropertyWebkitShapeInside:
2818 case CSSPropertyWebkitShapeOutside:
2819 if (!RuntimeEnabledFeatures::cssExclusionsEnabled())
2821 if (id == CSSValueAuto)
2822 validPrimitive = true;
2823 else if (propId == CSSPropertyWebkitShapeInside && id == CSSValueOutsideShape)
2824 validPrimitive = true;
2825 else if (value->unit == CSSParserValue::Function)
2826 return parseBasicShape(propId, important);
2828 case CSSPropertyWebkitShapeMargin:
2829 case CSSPropertyWebkitShapePadding:
2830 validPrimitive = (RuntimeEnabledFeatures::cssExclusionsEnabled() && !id && validUnit(value, FLength | FNonNeg));
2832 case CSSPropertyWebkitWrap:
2833 return RuntimeEnabledFeatures::cssExclusionsEnabled() && parseShorthand(propId, webkitWrapShorthand(), important);
2835 #if ENABLE(CSS_IMAGE_ORIENTATION)
2836 case CSSPropertyImageOrientation:
2837 validPrimitive = !id && validUnit(value, FAngle);
2840 #if ENABLE(CSS_IMAGE_RESOLUTION)
2841 case CSSPropertyImageResolution:
2842 parsedValue = parseImageResolution(m_valueList.get());
2845 m_valueList->next();
2848 case CSSPropertyBorderBottomStyle:
2849 case CSSPropertyBorderCollapse:
2850 case CSSPropertyBorderLeftStyle:
2851 case CSSPropertyBorderRightStyle:
2852 case CSSPropertyBorderTopStyle:
2853 case CSSPropertyBoxSizing:
2854 case CSSPropertyCaptionSide:
2855 case CSSPropertyClear:
2856 case CSSPropertyDirection:
2857 case CSSPropertyDisplay:
2858 case CSSPropertyEmptyCells:
2859 case CSSPropertyFloat:
2860 case CSSPropertyFontStyle:
2861 case CSSPropertyImageRendering:
2862 case CSSPropertyListStylePosition:
2863 case CSSPropertyListStyleType:
2864 case CSSPropertyOutlineStyle:
2865 case CSSPropertyOverflowWrap:
2866 case CSSPropertyOverflowX:
2867 case CSSPropertyOverflowY:
2868 case CSSPropertyPageBreakAfter:
2869 case CSSPropertyPageBreakBefore:
2870 case CSSPropertyPageBreakInside:
2871 case CSSPropertyPointerEvents:
2872 case CSSPropertyPosition:
2873 case CSSPropertyResize:
2874 case CSSPropertySpeak:
2875 case CSSPropertyTableLayout:
2876 case CSSPropertyTextLineThroughMode:
2877 case CSSPropertyTextLineThroughStyle:
2878 case CSSPropertyTextOverflow:
2879 case CSSPropertyTextOverlineMode:
2880 case CSSPropertyTextOverlineStyle:
2881 case CSSPropertyTextRendering:
2882 case CSSPropertyTextTransform:
2883 case CSSPropertyTextUnderlineMode:
2884 case CSSPropertyTextUnderlineStyle:
2885 #if ENABLE(CSS_VARIABLES)
2886 case CSSPropertyVariable:
2888 case CSSPropertyVisibility:
2889 case CSSPropertyWebkitAppearance:
2890 case CSSPropertyWebkitBackfaceVisibility:
2891 case CSSPropertyWebkitBorderAfterStyle:
2892 case CSSPropertyWebkitBorderBeforeStyle:
2893 case CSSPropertyWebkitBorderEndStyle:
2894 case CSSPropertyWebkitBorderFit:
2895 case CSSPropertyWebkitBorderStartStyle:
2896 case CSSPropertyWebkitBoxAlign:
2897 #if ENABLE(CSS_BOX_DECORATION_BREAK)
2898 case CSSPropertyWebkitBoxDecorationBreak:
2900 case CSSPropertyWebkitBoxDirection:
2901 case CSSPropertyWebkitBoxLines:
2902 case CSSPropertyWebkitBoxOrient:
2903 case CSSPropertyWebkitBoxPack:
2904 case CSSPropertyWebkitColorCorrection:
2905 case CSSPropertyWebkitColumnBreakAfter:
2906 case CSSPropertyWebkitColumnBreakBefore:
2907 case CSSPropertyWebkitColumnBreakInside:
2908 case CSSPropertyWebkitColumnRuleStyle:
2909 case CSSPropertyWebkitAlignContent:
2910 case CSSPropertyWebkitAlignItems:
2911 case CSSPropertyWebkitAlignSelf:
2912 case CSSPropertyWebkitFlexDirection:
2913 case CSSPropertyWebkitFlexWrap:
2914 case CSSPropertyWebkitJustifyContent:
2915 case CSSPropertyWebkitFontKerning:
2916 case CSSPropertyWebkitFontSmoothing:
2917 case CSSPropertyWebkitHyphens:
2918 case CSSPropertyWebkitGridAutoFlow:
2919 case CSSPropertyWebkitLineAlign:
2920 case CSSPropertyWebkitLineBreak:
2921 case CSSPropertyWebkitLineSnap:
2922 case CSSPropertyWebkitMarginAfterCollapse:
2923 case CSSPropertyWebkitMarginBeforeCollapse:
2924 case CSSPropertyWebkitMarginBottomCollapse:
2925 case CSSPropertyWebkitMarginTopCollapse:
2926 case CSSPropertyWebkitMarqueeDirection:
2927 case CSSPropertyWebkitMarqueeStyle:
2928 case CSSPropertyWebkitNbspMode:
2929 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
2930 case CSSPropertyWebkitOverflowScrolling:
2932 case CSSPropertyWebkitPrintColorAdjust:
2933 #if ENABLE(CSS_REGIONS)
2934 case CSSPropertyWebkitRegionBreakAfter:
2935 case CSSPropertyWebkitRegionBreakBefore:
2936 case CSSPropertyWebkitRegionBreakInside:
2937 case CSSPropertyWebkitRegionOverflow:
2939 case CSSPropertyWebkitRtlOrdering:
2940 case CSSPropertyWebkitRubyPosition:
2941 #if ENABLE(CSS3_TEXT)
2942 case CSSPropertyWebkitTextAlignLast:
2944 case CSSPropertyWebkitTextCombine:
2945 case CSSPropertyWebkitTextEmphasisPosition:
2946 case CSSPropertyWebkitTextSecurity:
2947 case CSSPropertyWebkitTextSizeAdjust:
2948 case CSSPropertyWebkitTransformStyle:
2949 case CSSPropertyWebkitUserDrag:
2950 case CSSPropertyWebkitUserModify:
2951 case CSSPropertyWebkitUserSelect:
2952 #if ENABLE(CSS_EXCLUSIONS)
2953 case CSSPropertyWebkitWrapFlow:
2954 case CSSPropertyWebkitWrapThrough:
2956 case CSSPropertyWebkitWritingMode:
2957 case CSSPropertyWhiteSpace:
2958 case CSSPropertyWordBreak:
2959 case CSSPropertyWordWrap:
2960 // These properties should be handled before in isValidKeywordPropertyAndValue().
2961 ASSERT_NOT_REACHED();
2963 #if ENABLE(CSS_DEVICE_ADAPTATION)
2964 // Properties bellow are validated inside parseViewportProperty, because we
2965 // check for parser state inViewportScope. We need to invalidate if someone
2966 // adds them outside a @viewport rule.
2967 case CSSPropertyMaxZoom:
2968 case CSSPropertyMinZoom:
2969 case CSSPropertyOrientation:
2970 case CSSPropertyUserZoom:
2971 validPrimitive = false;
2976 return parseSVGValue(propId, important);
2980 if (validPrimitive) {
2981 parsedValue = parseValidPrimitive(id, value);
2982 m_valueList->next();
2984 ASSERT(!m_parsedCalculation);
2986 if (!m_valueList->current() || inShorthand()) {
2987 addProperty(propId, parsedValue.release(), important);
2994 void CSSParser::addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
2997 if (lval->isBaseValueList())
2998 static_cast<CSSValueList*>(lval.get())->append(rval);
3000 PassRefPtr<CSSValue> oldlVal(lval.release());
3001 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3002 list->append(oldlVal);
3011 static bool parseBackgroundClip(CSSParserValue* parserValue, RefPtr<CSSValue>& cssValue)
3013 if (parserValue->id == CSSValueBorderBox || parserValue->id == CSSValuePaddingBox
3014 || parserValue->id == CSSValueContentBox || parserValue->id == CSSValueWebkitText) {
3015 cssValue = cssValuePool().createIdentifierValue(parserValue->id);
3021 const int cMaxFillProperties = 9;
3023 bool CSSParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* properties, int numProperties, bool important)
3025 ASSERT(numProperties <= cMaxFillProperties);
3026 if (numProperties > cMaxFillProperties)
3029 ShorthandScope scope(this, propId);
3031 bool parsedProperty[cMaxFillProperties] = { false };
3032 RefPtr<CSSValue> values[cMaxFillProperties];
3033 RefPtr<CSSValue> clipValue;
3034 RefPtr<CSSValue> positionYValue;
3035 RefPtr<CSSValue> repeatYValue;
3036 bool foundClip = false;
3038 bool foundPositionCSSProperty = false;
3040 while (m_valueList->current()) {
3041 CSSParserValue* val = m_valueList->current();
3042 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3043 // We hit the end. Fill in all remaining values with the initial value.
3044 m_valueList->next();
3045 for (i = 0; i < numProperties; ++i) {
3046 if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i])
3047 // Color is not allowed except as the last item in a list for backgrounds.
3048 // Reject the entire property.
3051 if (!parsedProperty[i] && properties[i] != CSSPropertyBackgroundColor) {
3052 addFillValue(values[i], cssValuePool().createImplicitInitialValue());
3053 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3054 addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
3055 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3056 addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
3057 if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) {
3058 // If background-origin wasn't present, then reset background-clip also.
3059 addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
3062 parsedProperty[i] = false;
3064 if (!m_valueList->current())
3068 bool sizeCSSPropertyExpected = false;
3069 if (isForwardSlashOperator(val) && foundPositionCSSProperty) {
3070 sizeCSSPropertyExpected = true;
3071 m_valueList->next();
3074 foundPositionCSSProperty = false;
3076 for (i = 0; !found && i < numProperties; ++i) {
3078 if (sizeCSSPropertyExpected && (properties[i] != CSSPropertyBackgroundSize && properties[i] != CSSPropertyWebkitMaskSize))
3080 if (!sizeCSSPropertyExpected && (properties[i] == CSSPropertyBackgroundSize || properties[i] == CSSPropertyWebkitMaskSize))
3083 if (!parsedProperty[i]) {
3084 RefPtr<CSSValue> val1;
3085 RefPtr<CSSValue> val2;
3086 CSSPropertyID propId1, propId2;
3087 CSSParserValue* parserValue = m_valueList->current();
3088 if (parseFillProperty(properties[i], propId1, propId2, val1, val2)) {
3089 parsedProperty[i] = found = true;
3090 addFillValue(values[i], val1.release());
3091 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3092 addFillValue(positionYValue, val2.release());
3093 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3094 addFillValue(repeatYValue, val2.release());
3095 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
3096 // Reparse the value as a clip, and see if we succeed.
3097 if (parseBackgroundClip(parserValue, val1))
3098 addFillValue(clipValue, val1.release()); // The property parsed successfully.
3100 addFillValue(clipValue, cssValuePool().createImplicitInitialValue()); // Some value was used for origin that is not supported by clip. Just reset clip instead.
3102 if (properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) {
3104 addFillValue(clipValue, val1.release());
3107 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3108 foundPositionCSSProperty = true;
3113 // if we didn't find at least one match, this is an
3114 // invalid shorthand and we have to ignore it
3119 // Now add all of the properties we found.
3120 for (i = 0; i < numProperties; i++) {
3121 // Fill in any remaining properties with the initial value.
3122 if (!parsedProperty[i]) {
3123 addFillValue(values[i], cssValuePool().createImplicitInitialValue());
3124 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
3125 addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
3126 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
3127 addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
3128 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
3129 // If background-origin wasn't present, then reset background-clip also.
3130 addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
3133 if (properties[i] == CSSPropertyBackgroundPosition) {
3134 addProperty(CSSPropertyBackgroundPositionX, values[i].release(), important);
3135 // it's OK to call positionYValue.release() since we only see CSSPropertyBackgroundPosition once
3136 addProperty(CSSPropertyBackgroundPositionY, positionYValue.release(), important);
3137 } else if (properties[i] == CSSPropertyWebkitMaskPosition) {
3138 addProperty(CSSPropertyWebkitMaskPositionX, values[i].release(), important);
3139 // it's OK to call positionYValue.release() since we only see CSSPropertyWebkitMaskPosition once
3140 addProperty(CSSPropertyWebkitMaskPositionY, positionYValue.release(), important);
3141 } else if (properties[i] == CSSPropertyBackgroundRepeat) {
3142 addProperty(CSSPropertyBackgroundRepeatX, values[i].release(), important);
3143 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
3144 addProperty(CSSPropertyBackgroundRepeatY, repeatYValue.release(), important);
3145 } else if (properties[i] == CSSPropertyWebkitMaskRepeat) {
3146 addProperty(CSSPropertyWebkitMaskRepeatX, values[i].release(), important);
3147 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
3148 addProperty(CSSPropertyWebkitMaskRepeatY, repeatYValue.release(), important);
3149 } else if ((properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) && !foundClip)
3150 // Value is already set while updating origin
3153 addProperty(properties[i], values[i].release(), important);
3155 // Add in clip values when we hit the corresponding origin property.
3156 if (properties[i] == CSSPropertyBackgroundOrigin && !foundClip)
3157 addProperty(CSSPropertyBackgroundClip, clipValue.release(), important);
3158 else if (properties[i] == CSSPropertyWebkitMaskOrigin && !foundClip)
3159 addProperty(CSSPropertyWebkitMaskClip, clipValue.release(), important);
3165 #if ENABLE(CSS_VARIABLES)
3166 bool CSSParser::cssVariablesEnabled() const
3168 return m_context.isCSSVariablesEnabled;
3171 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr<CSSParserValueList> value, bool important)
3173 // When CSSGrammar.y encounters an invalid declaration it passes null for the CSSParserValueList, just bail.
3177 static const unsigned prefixLength = sizeof("-webkit-var-") - 1;
3179 ASSERT(name.length() > prefixLength);
3180 AtomicString variableName = name.lowerSubstring(prefixLength, name.length() - prefixLength);
3182 StringBuilder builder;
3183 for (unsigned i = 0, size = value->size(); i < size; i++) {
3185 builder.append(' ');
3186 RefPtr<CSSValue> cssValue = value->valueAt(i)->createCSSValue();
3189 builder.append(cssValue->cssText());
3191 addProperty(CSSPropertyVariable, CSSVariableValue::create(variableName, builder.toString().lower()), important, false);
3195 void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
3198 if (lval->isValueList())
3199 static_cast<CSSValueList*>(lval.get())->append(rval);
3201 PassRefPtr<CSSValue> oldVal(lval.release());
3202 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3203 list->append(oldVal);
3212 bool CSSParser::parseAnimationShorthand(bool important)
3214 const StylePropertyShorthand& animationProperties = webkitAnimationShorthandForParsing();
3215 const unsigned numProperties = 7;
3217 // The list of properties in the shorthand should be the same
3218 // length as the list with animation name in last position, even though they are
3219 // in a different order.
3220 ASSERT(numProperties == webkitAnimationShorthandForParsing().length());
3221 ASSERT(numProperties == webkitAnimationShorthand().length());
3223 ShorthandScope scope(this, CSSPropertyWebkitAnimation);
3225 bool parsedProperty[numProperties] = { false };
3226 RefPtr<CSSValue> values[numProperties];
3229 while (m_valueList->current()) {
3230 CSSParserValue* val = m_valueList->current();
3231 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3232 // We hit the end. Fill in all remaining values with the initial value.
3233 m_valueList->next();
3234 for (i = 0; i < numProperties; ++i) {
3235 if (!parsedProperty[i])
3236 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3237 parsedProperty[i] = false;
3239 if (!m_valueList->current())
3244 for (i = 0; i < numProperties; ++i) {
3245 if (!parsedProperty[i]) {
3246 RefPtr<CSSValue> val;
3247 if (parseAnimationProperty(animationProperties.properties()[i], val)) {
3248 parsedProperty[i] = found = true;
3249 addAnimationValue(values[i], val.release());
3255 // if we didn't find at least one match, this is an
3256 // invalid shorthand and we have to ignore it
3261 for (i = 0; i < numProperties; ++i) {
3262 // If we didn't find the property, set an intial value.
3263 if (!parsedProperty[i])
3264 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3266 addProperty(animationProperties.properties()[i], values[i].release(), important);
3272 bool CSSParser::parseTransitionShorthand(bool important)
3274 const unsigned numProperties = 4;
3275 ASSERT(numProperties == webkitTransitionShorthand().length());
3277 ShorthandScope scope(this, CSSPropertyWebkitTransition);
3279 bool parsedProperty[numProperties] = { false };
3280 RefPtr<CSSValue> values[numProperties];
3283 while (m_valueList->current()) {
3284 CSSParserValue* val = m_valueList->current();
3285 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3286 // We hit the end. Fill in all remaining values with the initial value.
3287 m_valueList->next();
3288 for (i = 0; i < numProperties; ++i) {
3289 if (!parsedProperty[i])
3290 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3291 parsedProperty[i] = false;
3293 if (!m_valueList->current())
3298 for (i = 0; !found && i < numProperties; ++i) {
3299 if (!parsedProperty[i]) {
3300 RefPtr<CSSValue> val;
3301 if (parseAnimationProperty(webkitTransitionShorthand().properties()[i], val)) {
3302 parsedProperty[i] = found = true;
3303 addAnimationValue(values[i], val.release());
3308 // if we didn't find at least one match, this is an
3309 // invalid shorthand and we have to ignore it
3314 // Fill in any remaining properties with the initial value.
3315 for (i = 0; i < numProperties; ++i) {
3316 if (!parsedProperty[i])
3317 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3320 // Now add all of the properties we found.
3321 for (i = 0; i < numProperties; i++)
3322 addProperty(webkitTransitionShorthand().properties()[i], values[i].release(), important);
3327 bool CSSParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthand& shorthand, bool important)
3329 // We try to match as many properties as possible
3330 // We set up an array of booleans to mark which property has been found,
3331 // and we try to search for properties until it makes no longer any sense.
3332 ShorthandScope scope(this, propId);
3335 unsigned propertiesParsed = 0;
3336 bool propertyFound[6]= { false, false, false, false, false, false }; // 6 is enough size.
3338 while (m_valueList->current()) {
3340 for (unsigned propIndex = 0; !found && propIndex < shorthand.length(); ++propIndex) {
3341 if (!propertyFound[propIndex] && parseValue(shorthand.properties()[propIndex], important)) {
3342 propertyFound[propIndex] = found = true;
3347 // if we didn't find at least one match, this is an
3348 // invalid shorthand and we have to ignore it
3353 if (propertiesParsed == shorthand.length())
3356 // Fill in any remaining properties with the initial value.
3357 ImplicitScope implicitScope(this, PropertyImplicit);
3358 const StylePropertyShorthand* const* const propertiesForInitialization = shorthand.propertiesForInitialization();
3359 for (unsigned i = 0; i < shorthand.length(); ++i) {
3360 if (propertyFound[i])
3363 if (propertiesForInitialization) {
3364 const StylePropertyShorthand& initProperties = *(propertiesForInitialization[i]);
3365 for (unsigned propIndex = 0; propIndex < initProperties.length(); ++propIndex)
3366 addProperty(initProperties.properties()[propIndex], cssValuePool().createImplicitInitialValue(), important);
3368 addProperty(shorthand.properties()[i], cssValuePool().createImplicitInitialValue(), important);
3374 bool CSSParser::parse4Values(CSSPropertyID propId, const CSSPropertyID *properties, bool important)
3376 /* From the CSS 2 specs, 8.3
3377 * If there is only one value, it applies to all sides. If there are two values, the top and
3378 * bottom margins are set to the first value and the right and left margins are set to the second.
3379 * If there are three values, the top is set to the first value, the left and right are set to the
3380 * second, and the bottom is set to the third. If there are four values, they apply to the top,
3381 * right, bottom, and left, respectively.
3384 int num = inShorthand() ? 1 : m_valueList->size();
3386 ShorthandScope scope(this, propId);
3388 // the order is top, right, bottom, left
3391 if (!parseValue(properties[0], important))
3393 CSSValue* value = m_parsedProperties.last().value();
3394 ImplicitScope implicitScope(this, PropertyImplicit);
3395 addProperty(properties[1], value, important);
3396 addProperty(properties[2], value, important);
3397 addProperty(properties[3], value, important);
3401 if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
3403 CSSValue* value = m_parsedProperties[m_parsedProperties.size() - 2].value();
3404 ImplicitScope implicitScope(this, PropertyImplicit);
3405 addProperty(properties[2], value, important);
3406 value = m_parsedProperties[m_parsedProperties.size() - 2].value();
3407 addProperty(properties[3], value, important);
3411 if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || !parseValue(properties[2], important))
3413 CSSValue* value = m_parsedProperties[m_parsedProperties.size() - 2].value();
3414 ImplicitScope implicitScope(this, PropertyImplicit);
3415 addProperty(properties[3], value, important);
3419 if (!parseValue(properties[0], important) || !parseValue(properties[1], important) ||
3420 !parseValue(properties[2], important) || !parseValue(properties[3], important))
3432 // auto | <identifier>
3433 bool CSSParser::parsePage(CSSPropertyID propId, bool important)
3435 ASSERT(propId == CSSPropertyPage);
3437 if (m_valueList->size() != 1)
3440 CSSParserValue* value = m_valueList->current();
3444 if (value->id == CSSValueAuto) {
3445 addProperty(propId, cssValuePool().createIdentifierValue(value->id), important);
3447 } else if (value->id == 0 && value->unit == CSSPrimitiveValue::CSS_IDENT) {
3448 addProperty(propId, createPrimitiveStringValue(value), important);
3454 // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
3455 bool CSSParser::parseSize(CSSPropertyID propId, bool important)
3457 ASSERT(propId == CSSPropertySize);
3459 if (m_valueList->size() > 2)
3462 CSSParserValue* value = m_valueList->current();
3466 RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
3469 SizeParameterType paramType = parseSizeParameter(parsedValues.get(), value, None);
3470 if (paramType == None)
3473 // Second parameter, if any.
3474 value = m_valueList->next();
3476 paramType = parseSizeParameter(parsedValues.get(), value, paramType);
3477 if (paramType == None)
3481 addProperty(propId, parsedValues.release(), important);
3485 CSSParser::SizeParameterType CSSParser::parseSizeParameter(CSSValueList* parsedValues, CSSParserValue* value, SizeParameterType prevParamType)
3487 switch (value->id) {
3489 if (prevParamType == None) {
3490 parsedValues->append(cssValuePool().createIdentifierValue(value->id));
3494 case CSSValueLandscape:
3495 case CSSValuePortrait:
3496 if (prevParamType == None || prevParamType == PageSize) {
3497 parsedValues->append(cssValuePool().createIdentifierValue(value->id));
3506 case CSSValueLedger:
3508 case CSSValueLetter:
3509 if (prevParamType == None || prevParamType == Orientation) {
3510 // Normalize to Page Size then Orientation order by prepending.
3511 // This is not specified by the CSS3 Paged Media specification, but for simpler processing later (StyleResolver::applyPageSizeProperty).
3512 parsedValues->prepend(cssValuePool().createIdentifierValue(value->id));
3517 if (validUnit(value, FLength | FNonNeg) && (prevParamType == None || prevParamType == Length)) {
3518 parsedValues->append(createPrimitiveNumericValue(value));
3527 // [ <string> <string> ]+ | inherit | none
3528 // inherit and none are handled in parseValue.
3529 bool CSSParser::parseQuotes(CSSPropertyID propId, bool important)
3531 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
3532 while (CSSParserValue* val = m_valueList->current()) {
3533 RefPtr<CSSValue> parsedValue;
3534 if (val->unit == CSSPrimitiveValue::CSS_STRING)
3535 parsedValue = CSSPrimitiveValue::create(val->string, CSSPrimitiveValue::CSS_STRING);
3538 values->append(parsedValue.release());
3539 m_valueList->next();
3541 if (values->length()) {
3542 addProperty(propId, values.release(), important);
3543 m_valueList->next();
3549 // [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
3550 // in CSS 2.1 this got somewhat reduced:
3551 // [ <string> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
3552 bool CSSParser::parseContent(CSSPropertyID propId, bool important)
3554 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
3556 while (CSSParserValue* val = m_valueList->current()) {
3557 RefPtr<CSSValue> parsedValue;
3558 if (val->unit == CSSPrimitiveValue::CSS_URI) {
3560 parsedValue = CSSImageValue::create(completeURL(val->string));
3561 } else if (val->unit == CSSParserValue::Function) {
3562 // attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradient(...)
3563 CSSParserValueList* args = val->function->args.get();
3566 if (equalIgnoringCase(val->function->name, "attr(")) {
3567 parsedValue = parseAttr(args);
3570 } else if (equalIgnoringCase(val->function->name, "counter(")) {
3571 parsedValue = parseCounterContent(args, false);
3574 } else if (equalIgnoringCase(val->function->name, "counters(")) {
3575 parsedValue = parseCounterContent(args, true);
3578 #if ENABLE(CSS_IMAGE_SET)
3579 } else if (equalIgnoringCase(val->function->name, "-webkit-image-set(")) {
3580 parsedValue = parseImageSet(m_valueList.get());
3584 } else if (isGeneratedImageValue(val)) {
3585 if (!parseGeneratedImage(m_valueList.get(), parsedValue))
3589 } else if (val->unit == CSSPrimitiveValue::CSS_IDENT) {
3595 // FIXME: These are not yet implemented (http://bugs.webkit.org/show_bug.cgi?id=6503).
3599 case CSSValueOpenQuote:
3600 case CSSValueCloseQuote:
3601 case CSSValueNoOpenQuote:
3602 case CSSValueNoCloseQuote:
3604 case CSSValueNormal:
3605 parsedValue = cssValuePool().createIdentifierValue(val->id);
3607 } else if (val->unit == CSSPrimitiveValue::CSS_STRING) {
3608 parsedValue = createPrimitiveStringValue(val);
3612 values->append(parsedValue.release());
3613 m_valueList->next();
3616 if (values->length()) {
3617 addProperty(propId, values.release(), important);
3618 m_valueList->next();
3625 PassRefPtr<CSSValue> CSSParser::parseAttr(CSSParserValueList* args)
3627 if (args->size() != 1)
3630 CSSParserValue* a = args->current();
3632 if (a->unit != CSSPrimitiveValue::CSS_IDENT)
3635 String attrName = a->string;
3636 // CSS allows identifiers with "-" at the start, like "-webkit-mask-image".
3637 // But HTML attribute names can't have those characters, and we should not
3638 // even parse them inside attr().
3639 if (attrName[0] == '-')
3642 if (m_context.isHTMLDocument)
3643 attrName = attrName.lower();
3645 return cssValuePool().createValue(attrName, CSSPrimitiveValue::CSS_ATTR);
3648 PassRefPtr<CSSValue> CSSParser::parseBackgroundColor()
3650 int id = m_valueList->current()->id;
3651 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor ||
3652 (id >= CSSValueGrey && id < CSSValueWebkitText && inQuirksMode()))
3653 return cssValuePool().createIdentifierValue(id);
3654 return parseColor();
3657 bool CSSParser::parseFillImage(CSSParserValueList* valueList, RefPtr<CSSValue>& value)
3659 if (valueList->current()->id == CSSValueNone) {
3660 value = cssValuePool().createIdentifierValue(CSSValueNone);
3663 if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
3664 value = CSSImageValue::create(completeURL(valueList->current()->string));
3668 if (isGeneratedImageValue(valueList->current()))
3669 return parseGeneratedImage(valueList, value);
3671 #if ENABLE(CSS_IMAGE_SET)
3672 if (valueList->current()->unit == CSSParserValue::Function && equalIgnoringCase(valueList->current()->function->name, "-webkit-image-set(")) {
3673 value = parseImageSet(m_valueList.get());
3682 PassRefPtr<CSSValue> CSSParser::parseFillPositionX(CSSParserValueList* valueList)
3684 int id = valueList->current()->id;
3685 if (id == CSSValueLeft || id == CSSValueRight || id == CSSValueCenter) {
3687 if (id == CSSValueRight)
3689 else if (id == CSSValueCenter)
3691 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
3693 if (validUnit(valueList->current(), FPercent | FLength))
3694 return createPrimitiveNumericValue(valueList->current());
3698 PassRefPtr<CSSValue> CSSParser::parseFillPositionY(CSSParserValueList* valueList)
3700 int id = valueList->current()->id;
3701 if (id == CSSValueTop || id == CSSValueBottom || id == CSSValueCenter) {
3703 if (id == CSSValueBottom)
3705 else if (id == CSSValueCenter)
3707 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
3709 if (validUnit(valueList->current(), FPercent | FLength))
3710 return createPrimitiveNumericValue(valueList->current());
3714 PassRefPtr<CSSPrimitiveValue> CSSParser::parseFillPositionComponent(CSSParserValueList* valueList, unsigned& cumulativeFlags, FillPositionFlag& individualFlag, FillPositionParsingMode parsingMode)
3716 int id = valueList->current()->id;
3717 if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id == CSSValueBottom || id == CSSValueCenter) {
3719 if (id == CSSValueLeft || id == CSSValueRight) {
3720 if (cumulativeFlags & XFillPosition)
3722 cumulativeFlags |= XFillPosition;
3723 individualFlag = XFillPosition;
3724 if (id == CSSValueRight)
3727 else if (id == CSSValueTop || id == CSSValueBottom) {
3728 if (cumulativeFlags & YFillPosition)
3730 cumulativeFlags |= YFillPosition;
3731 individualFlag = YFillPosition;
3732 if (id == CSSValueBottom)
3734 } else if (id == CSSValueCenter) {
3735 // Center is ambiguous, so we're not sure which position we've found yet, an x or a y.
3737 cumulativeFlags |= AmbiguousFillPosition;
3738 individualFlag = AmbiguousFillPosition;
3741 if (parsingMode == ResolveValuesAsKeyword)
3742 return cssValuePool().createIdentifierValue(id);
3744 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
3746 if (validUnit(valueList->current(), FPercent | FLength)) {
3747 if (!cumulativeFlags) {
3748 cumulativeFlags |= XFillPosition;
3749 individualFlag = XFillPosition;
3750 } else if (cumulativeFlags & (XFillPosition | AmbiguousFillPosition)) {
3751 cumulativeFlags |= YFillPosition;
3752 individualFlag = YFillPosition;
3754 if (m_parsedCalculation)
3755 m_parsedCalculation.release();
3758 return createPrimitiveNumericValue(valueList->current());
3763 static bool isValueConflictingWithCurrentEdge(int value1, int value2)
3765 if ((value1 == CSSValueLeft || value1 == CSSValueRight) && (value2 == CSSValueLeft || value2 == CSSValueRight))
3768 if ((value1 == CSSValueTop || value1 == CSSValueBottom) && (value2 == CSSValueTop || value2 == CSSValueBottom))
3774 static bool isFillPositionKeyword(int value)
3776 return value == CSSValueLeft || value == CSSValueTop || value == CSSValueBottom || value == CSSValueRight || value == CSSValueCenter;
3779 void CSSParser::parse4ValuesFillPosition(CSSParserValueList* valueList, RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2, PassRefPtr<CSSPrimitiveValue> parsedValue1, PassRefPtr<CSSPrimitiveValue> parsedValue2)
3781 // [ left | right ] [ <percentage] | <length> ] && [ top | bottom ] [ <percentage> | <length> ]
3782 // In the case of 4 values <position> requires the second value to be a length or a percentage.
3783 if (isFillPositionKeyword(parsedValue2->getIdent()))
3786 unsigned cumulativeFlags = 0;
3787 FillPositionFlag value3Flag = InvalidFillPosition;
3788 RefPtr<CSSPrimitiveValue> value3 = parseFillPositionComponent(valueList, cumulativeFlags, value3Flag, ResolveValuesAsKeyword);
3792 int ident1 = parsedValue1->getIdent();
3793 int ident3 = value3->getIdent();
3795 if (ident1 == CSSValueCenter)
3798 if (!isFillPositionKeyword(ident3) || ident3 == CSSValueCenter)
3801 // We need to check if the values are not conflicting, e.g. they are not on the same edge. It is
3802 // needed as the second call to parseFillPositionComponent was on purpose not checking it. In the
3803 // case of two values top 20px is invalid but in the case of 4 values it becomes valid.
3804 if (isValueConflictingWithCurrentEdge(ident1, ident3))
3809 cumulativeFlags = 0;
3810 FillPositionFlag value4Flag = InvalidFillPosition;
3811 RefPtr<CSSPrimitiveValue> value4 = parseFillPositionComponent(valueList, cumulativeFlags, value4Flag, ResolveValuesAsKeyword);
3815 // 4th value must be a length or a percentage.
3816 if (isFillPositionKeyword(value4->getIdent()))
3819 value1 = createPrimitiveValuePair(parsedValue1, parsedValue2);
3820 value2 = createPrimitiveValuePair(value3, value4);
3822 if (ident1 == CSSValueTop || ident1 == CSSValueBottom)
3823 value1.swap(value2);
3827 void CSSParser::parse3ValuesFillPosition(CSSParserValueList* valueList, RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2, PassRefPtr<CSSPrimitiveValue> parsedValue1, PassRefPtr<CSSPrimitiveValue> parsedValue2)
3829 unsigned cumulativeFlags = 0;
3830 FillPositionFlag value3Flag = InvalidFillPosition;
3831 RefPtr<CSSPrimitiveValue> value3 = parseFillPositionComponent(valueList, cumulativeFlags, value3Flag, ResolveValuesAsKeyword);
3833 // value3 is not an expected value, we return.
3839 bool swapNeeded = false;
3840 int ident1 = parsedValue1->getIdent();
3841 int ident2 = parsedValue2->getIdent();
3842 int ident3 = value3->getIdent();
3844 int firstPositionKeyword;
3845 int secondPositionKeyword;
3847 if (ident1 == CSSValueCenter) {
3848 // <position> requires the first 'center' to be followed by a keyword.
3849 if (!isFillPositionKeyword(ident2))
3852 // If 'center' is the first keyword then the last one needs to be a length.
3853 if (isFillPositionKeyword(ident3))
3856 firstPositionKeyword = CSSValueLeft;
3857 if (ident2 == CSSValueLeft || ident2 == CSSValueRight) {
3858 firstPositionKeyword = CSSValueTop;
3861 value1 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(firstPositionKeyword), cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAGE));
3862 value2 = createPrimitiveValuePair(parsedValue2, value3);
3863 } else if (ident3 == CSSValueCenter) {
3864 if (isFillPositionKeyword(ident2))
3867 secondPositionKeyword = CSSValueTop;
3868 if (ident1 == CSSValueTop || ident1 == CSSValueBottom) {
3869 secondPositionKeyword = CSSValueLeft;
3872 value1 = createPrimitiveValuePair(parsedValue1, parsedValue2);
3873 value2 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(secondPositionKeyword), cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAGE));
3875 RefPtr<CSSPrimitiveValue> firstPositionValue;
3876 RefPtr<CSSPrimitiveValue> secondPositionValue;
3878 if (isFillPositionKeyword(ident2)) {
3879 // To match CSS grammar, we should only accept: [ center | left | right | bottom | top ] [ left | right | top | bottom ] [ <percentage> | <length> ].
3880 ASSERT(ident2 != CSSValueCenter);
3882 if (isFillPositionKeyword(ident3))
3885 secondPositionValue = value3;
3886 secondPositionKeyword = ident2;
3887 firstPositionValue = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PERCENTAGE);
3889 // Per CSS, we should only accept: [ right | left | top | bottom ] [ <percentage> | <length> ] [ center | left | right | bottom | top ].
3890 if (!isFillPositionKeyword(ident3))
3893 firstPositionValue = parsedValue2;
3894 secondPositionKeyword = ident3;
3895 secondPositionValue = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PERCENTAGE);
3898 if (isValueConflictingWithCurrentEdge(ident1, secondPositionKeyword))
3901 value1 = createPrimitiveValuePair(parsedValue1, firstPositionValue);
3902 value2 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(secondPositionKeyword), secondPositionValue);
3905 if (ident1 == CSSValueTop || ident1 == CSSValueBottom || swapNeeded)
3906 value1.swap(value2);
3909 CSSPrimitiveValue* first = static_cast<CSSPrimitiveValue*>(value1.get());
3910 CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(value2.get());
3911 ident1 = first->getPairValue()->first()->getIdent();
3912 ident2 = second->getPairValue()->first()->getIdent();
3913 ASSERT(ident1 == CSSValueLeft || ident1 == CSSValueRight);
3914 ASSERT(ident2 == CSSValueBottom || ident2 == CSSValueTop);
3918 inline bool CSSParser::isPotentialPositionValue(CSSParserValue* value)
3920 return isFillPositionKeyword(value->id) || validUnit(value, FPercent | FLength, ReleaseParsedCalcValue);
3923 void CSSParser::parseFillPosition(CSSParserValueList* valueList, RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2)
3925 unsigned numberOfValues = 0;
3926 for (unsigned i = valueList->currentIndex(); i < valueList->size(); ++i, ++numberOfValues) {
3927 CSSParserValue* current = valueList->valueAt(i);
3928 if (isComma(current) || !current || isForwardSlashOperator(current) || !isPotentialPositionValue(current))
3932 if (numberOfValues > 4)
3935 // If we are parsing two values, we can safely call the CSS 2.1 parsing function and return.
3936 if (numberOfValues <= 2) {
3937 parse2ValuesFillPosition(valueList, value1, value2);
3941 ASSERT(numberOfValues > 2 && numberOfValues <= 4);
3943 CSSParserValue* value = valueList->current();
3945 // <position> requires the first value to be a background keyword.
3946 if (!isFillPositionKeyword(value->id))
3949 // Parse the first value. We're just making sure that it is one of the valid keywords or a percentage/length.
3950 unsigned cumulativeFlags = 0;
3951 FillPositionFlag value1Flag = InvalidFillPosition;
3952 FillPositionFlag value2Flag = InvalidFillPosition;
3953 value1 = parseFillPositionComponent(valueList, cumulativeFlags, value1Flag, ResolveValuesAsKeyword);
3957 value = valueList->next();
3959 // In case we are parsing more than two values, relax the check inside of parseFillPositionComponent. top 20px is
3960 // a valid start for <position>.
3961 cumulativeFlags = AmbiguousFillPosition;
3962 value2 = parseFillPositionComponent(valueList, cumulativeFlags, value2Flag, ResolveValuesAsKeyword);
3970 RefPtr<CSSPrimitiveValue> parsedValue1 = static_cast<CSSPrimitiveValue*>(value1.get());
3971 RefPtr<CSSPrimitiveValue> parsedValue2 = static_cast<CSSPrimitiveValue*>(value2.get());
3976 // Per CSS3 syntax, <position> can't have 'center' as its second keyword as we have more arguments to follow.
3977 if (parsedValue2->getIdent() == CSSValueCenter)
3980 if (numberOfValues == 3)
3981 parse3ValuesFillPosition(valueList, value1, value2, parsedValue1.release(), parsedValue2.release());
3983 parse4ValuesFillPosition(valueList, value1, value2, parsedValue1.release