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.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
27 #include "CSSParser.h"
29 #include "CSSAspectRatioValue.h"
30 #include "CSSBorderImage.h"
31 #include "CSSCanvasValue.h"
32 #include "CSSCrossfadeValue.h"
33 #include "CSSCursorImageValue.h"
34 #include "CSSFontFaceRule.h"
35 #include "CSSFontFaceSrcValue.h"
36 #include "CSSFunctionValue.h"
37 #include "CSSGradientValue.h"
38 #include "CSSImageValue.h"
39 #include "CSSInheritedValue.h"
40 #include "CSSInitialValue.h"
41 #include "CSSLineBoxContainValue.h"
42 #include "CSSMediaRule.h"
43 #include "CSSPageRule.h"
44 #include "CSSPrimitiveValue.h"
45 #include "CSSProperty.h"
46 #include "CSSPropertySourceData.h"
47 #include "CSSReflectValue.h"
48 #include "CSSSelector.h"
49 #include "CSSTimingFunctionValue.h"
50 #include "CSSUnicodeRangeValue.h"
51 #include "CSSValueKeywords.h"
52 #include "CSSValueList.h"
53 #include "CSSValuePool.h"
54 #if ENABLE(CSS_VARIABLES)
55 #include "CSSVariableValue.h"
57 #include "CSSWrapShapes.h"
60 #include "FloatConversion.h"
61 #include "FontFeatureValue.h"
62 #include "FontValue.h"
63 #include "HTMLParserIdioms.h"
64 #include "HashTools.h"
65 #include "MediaList.h"
66 #include "MediaQueryExp.h"
70 #include "RenderTheme.h"
71 #include "RuntimeEnabledFeatures.h"
72 #include "SVGParserUtilities.h"
74 #include "ShadowValue.h"
75 #include "StylePropertySet.h"
76 #include "StylePropertyShorthand.h"
77 #include "StyleRule.h"
78 #include "StyleRuleImport.h"
79 #include "StyleSheetContents.h"
80 #include "TextEncoding.h"
81 #include "WebKitCSSKeyframeRule.h"
82 #include "WebKitCSSKeyframesRule.h"
83 #include "WebKitCSSRegionRule.h"
84 #include "WebKitCSSTransformValue.h"
86 #include <wtf/BitArray.h>
87 #include <wtf/HexNumber.h>
89 #include <wtf/text/StringBuffer.h>
90 #include <wtf/text/StringBuilder.h>
92 #if ENABLE(CSS_IMAGE_SET)
93 #include "CSSImageSetValue.h"
96 #if ENABLE(CSS_FILTERS)
97 #include "WebKitCSSFilterValue.h"
99 #include "WebKitCSSSVGDocumentValue.h"
103 #if ENABLE(CSS_SHADERS)
104 #include "WebKitCSSShaderValue.h"
107 #if ENABLE(DASHBOARD_SUPPORT)
108 #include "DashboardRegion.h"
114 extern int cssyydebug;
117 extern int cssyyparse(void* parser);
129 class ImplicitScope {
130 WTF_MAKE_NONCOPYABLE(ImplicitScope);
132 ImplicitScope(WebCore::CSSParser* parser, PropertyType propertyType)
135 m_parser->m_implicitShorthand = propertyType == PropertyImplicit;
140 m_parser->m_implicitShorthand = false;
144 WebCore::CSSParser* m_parser;
151 static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX;
152 static const double MAX_SCALE = 1000000;
154 static bool equal(const CSSParserString& a, const char* b)
156 for (int i = 0; i < a.length; ++i) {
159 if (a.characters[i] != b[i])
165 static bool equalIgnoringCase(const CSSParserString& a, const char* b)
167 for (int i = 0; i < a.length; ++i) {
170 ASSERT(!isASCIIUpper(b[i]));
171 if (toASCIILower(a.characters[i]) != b[i])
177 static bool hasPrefix(const char* string, unsigned length, const char* prefix)
179 for (unsigned i = 0; i < length; ++i) {
182 if (string[i] != prefix[i])
188 const CSSParserContext& strictCSSParserContext()
190 DEFINE_STATIC_LOCAL(CSSParserContext, strictContext, (CSSStrictMode));
191 return strictContext;
194 CSSParserContext::CSSParserContext(CSSParserMode mode, const KURL& baseURL)
197 , isHTMLDocument(false)
198 , isCSSCustomFilterEnabled(false)
199 , isCSSRegionsEnabled(false)
200 , isCSSGridLayoutEnabled(false)
201 #if ENABLE(CSS_VARIABLES)
202 , isCSSVariablesEnabled(false)
204 , needsSiteSpecificQuirks(false)
205 , enforcesCSSMIMETypeInNoQuirksMode(true)
209 CSSParserContext::CSSParserContext(Document* document, const KURL& baseURL, const String& charset)
210 : baseURL(baseURL.isNull() ? document->baseURL() : baseURL)
212 , mode(document->inQuirksMode() ? CSSQuirksMode : CSSStrictMode)
213 , isHTMLDocument(document->isHTMLDocument())
214 , isCSSCustomFilterEnabled(document->settings() ? document->settings()->isCSSCustomFilterEnabled() : false)
215 , isCSSRegionsEnabled(document->cssRegionsEnabled())
216 , isCSSGridLayoutEnabled(document->cssGridLayoutEnabled())
217 #if ENABLE(CSS_VARIABLES)
218 , isCSSVariablesEnabled(document->settings() ? document->settings()->cssVariablesEnabled() : false)
220 , needsSiteSpecificQuirks(document->settings() ? document->settings()->needsSiteSpecificQuirks() : false)
221 , enforcesCSSMIMETypeInNoQuirksMode(!document->settings() || document->settings()->enforceCSSMIMETypeInNoQuirksMode())
225 bool operator==(const CSSParserContext& a, const CSSParserContext& b)
227 return a.baseURL == b.baseURL
228 && a.charset == b.charset
230 && a.isHTMLDocument == b.isHTMLDocument
231 && a.isCSSCustomFilterEnabled == b.isCSSCustomFilterEnabled
232 && a.isCSSRegionsEnabled == b.isCSSRegionsEnabled
233 && a.isCSSGridLayoutEnabled == b.isCSSGridLayoutEnabled
234 #if ENABLE(CSS_VARIABLES)
235 && a.isCSSVariablesEnabled == b.isCSSVariablesEnabled
237 && a.needsSiteSpecificQuirks == b.needsSiteSpecificQuirks
238 && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode;
241 CSSParser::CSSParser(const CSSParserContext& context)
244 , m_id(CSSPropertyInvalid)
246 , m_selectorListForParseSelector(0)
247 , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES)
248 , m_inParseShorthand(0)
249 , m_currentShorthand(CSSPropertyInvalid)
250 , m_implicitShorthand(false)
251 , m_hasFontFaceOnlyValues(false)
252 , m_hadSyntacticallyValidCSSRule(false)
253 , m_defaultNamespace(starAtom)
254 , m_parsedTextPrefixLength(0)
255 , m_propertyRange(UINT_MAX, UINT_MAX)
256 , m_ruleSourceDataResult(0)
257 , m_parsingMode(NormalMode)
258 , m_currentCharacter(0)
262 , m_lastSelectorLineNumber(0)
263 , m_allowImportRules(true)
264 , m_allowNamespaceDeclarations(true)
269 CSSPropertySourceData::init();
272 CSSParser::~CSSParser()
276 fastDeleteAllValues(m_floatingSelectors);
277 deleteAllValues(m_floatingSelectorVectors);
278 deleteAllValues(m_floatingValueLists);
279 deleteAllValues(m_floatingFunctions);
282 void CSSParserString::lower()
284 // FIXME: If we need Unicode lowercasing here, then we probably want the real kind
285 // that can potentially change the length of the string rather than the character
286 // by character kind. If we don't need Unicode lowercasing, it would be good to
287 // simplify this function.
289 if (charactersAreAllASCII(characters, length)) {
290 // Fast case for all-ASCII.
291 for (int i = 0; i < length; i++)
292 characters[i] = toASCIILower(characters[i]);
294 for (int i = 0; i < length; i++)
295 characters[i] = Unicode::toLower(characters[i]);
299 void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
301 m_parsedTextPrefixLength = strlen(prefix);
302 int length = string.length() + m_parsedTextPrefixLength + strlen(suffix) + 1;
304 m_dataStart = adoptArrayPtr(new UChar[length]);
305 for (unsigned i = 0; i < m_parsedTextPrefixLength; i++)
306 m_dataStart[i] = prefix[i];
308 memcpy(m_dataStart.get() + m_parsedTextPrefixLength, string.characters(), string.length() * sizeof(UChar));
310 unsigned start = m_parsedTextPrefixLength + string.length();
311 unsigned end = start + strlen(suffix);
312 for (unsigned i = start; i < end; i++)
313 m_dataStart[i] = suffix[i - start];
315 m_dataStart[length - 1] = 0;
317 m_currentCharacter = m_tokenStart = m_dataStart.get();
320 void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, RuleSourceDataList* ruleSourceDataResult)
322 setStyleSheet(sheet);
323 m_defaultNamespace = starAtom; // Reset the default namespace.
324 if (ruleSourceDataResult)
325 m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
326 m_ruleSourceDataResult = ruleSourceDataResult;
328 m_lineNumber = startLineNumber;
329 setupParser("", string, "");
331 m_currentRuleDataStack.clear();
332 m_ruleSourceDataResult = 0;
336 PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string)
338 setStyleSheet(sheet);
339 m_allowNamespaceDeclarations = false;
340 setupParser("@-webkit-rule{", string, "} ");
342 return m_rule.release();
345 PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet, const String& string)
347 setStyleSheet(sheet);
348 setupParser("@-webkit-keyframe-rule{ ", string, "} ");
350 return m_keyframe.release();
353 static inline bool isColorPropertyID(CSSPropertyID propertyId)
355 switch (propertyId) {
356 case CSSPropertyColor:
357 case CSSPropertyBackgroundColor:
358 case CSSPropertyBorderBottomColor:
359 case CSSPropertyBorderLeftColor:
360 case CSSPropertyBorderRightColor:
361 case CSSPropertyBorderTopColor:
362 case CSSPropertyOutlineColor:
363 case CSSPropertyTextLineThroughColor:
364 case CSSPropertyTextOverlineColor:
365 case CSSPropertyTextUnderlineColor:
366 case CSSPropertyWebkitBorderAfterColor:
367 case CSSPropertyWebkitBorderBeforeColor:
368 case CSSPropertyWebkitBorderEndColor:
369 case CSSPropertyWebkitBorderStartColor:
370 case CSSPropertyWebkitColumnRuleColor:
371 case CSSPropertyWebkitTextEmphasisColor:
372 case CSSPropertyWebkitTextFillColor:
373 case CSSPropertyWebkitTextStrokeColor:
380 static bool parseColorValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
382 ASSERT(!string.isEmpty());
383 bool strict = isStrictParserMode(cssParserMode);
384 if (!isColorPropertyID(propertyId))
386 CSSParserString cssString;
387 cssString.characters = const_cast<UChar*>(string.characters());
388 cssString.length = string.length();
389 int valueID = cssValueKeywordID(cssString);
390 bool validPrimitive = false;
391 if (valueID == CSSValueWebkitText)
392 validPrimitive = true;
393 else if (valueID == CSSValueCurrentcolor)
394 validPrimitive = true;
395 else if ((valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID == CSSValueMenu
396 || (valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWebkitText && !strict)) {
397 validPrimitive = true;
400 if (validPrimitive) {
401 RefPtr<CSSValue> value = cssValuePool().createIdentifierValue(valueID);
402 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
406 if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
408 RefPtr<CSSValue> value = cssValuePool().createColorValue(color);
409 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
413 static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acceptsNegativeNumbers)
415 switch (propertyId) {
416 case CSSPropertyFontSize:
417 case CSSPropertyHeight:
418 case CSSPropertyWidth:
419 case CSSPropertyMinHeight:
420 case CSSPropertyMinWidth:
421 case CSSPropertyPaddingBottom:
422 case CSSPropertyPaddingLeft:
423 case CSSPropertyPaddingRight:
424 case CSSPropertyPaddingTop:
425 case CSSPropertyWebkitLogicalWidth:
426 case CSSPropertyWebkitLogicalHeight:
427 case CSSPropertyWebkitMinLogicalWidth:
428 case CSSPropertyWebkitMinLogicalHeight:
429 case CSSPropertyWebkitPaddingAfter:
430 case CSSPropertyWebkitPaddingBefore:
431 case CSSPropertyWebkitPaddingEnd:
432 case CSSPropertyWebkitPaddingStart:
433 acceptsNegativeNumbers = false;
435 #if ENABLE(CSS_EXCLUSIONS)
436 case CSSPropertyWebkitWrapMargin:
437 case CSSPropertyWebkitWrapPadding:
438 acceptsNegativeNumbers = false;
439 return RuntimeEnabledFeatures::cssExclusionsEnabled();
441 case CSSPropertyBottom:
442 case CSSPropertyLeft:
443 case CSSPropertyMarginBottom:
444 case CSSPropertyMarginLeft:
445 case CSSPropertyMarginRight:
446 case CSSPropertyMarginTop:
447 case CSSPropertyRight:
448 case CSSPropertyTextIndent:
450 case CSSPropertyWebkitMarginAfter:
451 case CSSPropertyWebkitMarginBefore:
452 case CSSPropertyWebkitMarginEnd:
453 case CSSPropertyWebkitMarginStart:
454 acceptsNegativeNumbers = true;
461 template <typename CharType>
462 static inline bool parseSimpleLength(const CharType* characters, unsigned& length, CSSPrimitiveValue::UnitTypes& unit, double& number)
464 if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') {
466 unit = CSSPrimitiveValue::CSS_PX;
467 } else if (length > 1 && characters[length - 1] == '%') {
469 unit = CSSPrimitiveValue::CSS_PERCENTAGE;
472 // We rely on charactersToDouble for validation as well. The function
473 // will set "ok" to "false" if the entire passed-in character range does
474 // not represent a double.
476 number = charactersToDouble(characters, length, &ok);
480 static bool parseSimpleLengthValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
482 ASSERT(!string.isEmpty());
483 bool acceptsNegativeNumbers;
484 if (!isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers))
487 unsigned length = string.length();
489 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
491 if (string.is8Bit()) {
492 if (!parseSimpleLength(string.characters8(), length, unit, number))
495 if (!parseSimpleLength(string.characters16(), length, unit, number))
499 if (unit == CSSPrimitiveValue::CSS_NUMBER) {
500 if (number && isStrictParserMode(cssParserMode))
502 unit = CSSPrimitiveValue::CSS_PX;
504 if (number < 0 && !acceptsNegativeNumbers)
507 RefPtr<CSSValue> value = cssValuePool().createValue(number, unit);
508 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
512 static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int valueID, const CSSParserContext& parserContext)
517 switch (propertyId) {
518 case CSSPropertyBorderCollapse: // collapse | separate | inherit
519 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate)
522 case CSSPropertyBorderTopStyle: // <border-style> | inherit
523 case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed |
524 case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset
525 case CSSPropertyBorderLeftStyle:
526 case CSSPropertyWebkitBorderAfterStyle:
527 case CSSPropertyWebkitBorderBeforeStyle:
528 case CSSPropertyWebkitBorderEndStyle:
529 case CSSPropertyWebkitBorderStartStyle:
530 case CSSPropertyWebkitColumnRuleStyle:
531 if (valueID >= CSSValueNone && valueID <= CSSValueDouble)
534 case CSSPropertyBoxSizing:
535 if (valueID == CSSValueBorderBox || valueID == CSSValueContentBox)
538 case CSSPropertyCaptionSide: // top | bottom | left | right | inherit
539 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueTop || valueID == CSSValueBottom)
542 case CSSPropertyClear: // none | left | right | both | inherit
543 if (valueID == CSSValueNone || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueBoth)
546 case CSSPropertyDirection: // ltr | rtl | inherit
547 if (valueID == CSSValueLtr || valueID == CSSValueRtl)
550 case CSSPropertyDisplay:
551 // inline | block | list-item | run-in | inline-block | table |
552 // inline-table | table-row-group | table-header-group | table-footer-group | table-row |
553 // table-column-group | table-column | table-cell | table-caption | -webkit-box | -webkit-inline-box | none | inherit
554 // -webkit-flex | -webkit-inline-flex | -webkit-grid | -webkit-inline-grid
555 if ((valueID >= CSSValueInline && valueID <= CSSValueWebkitInlineBox) || valueID == CSSValueNone)
557 #if ENABLE(CSS3_FLEXBOX)
558 if (valueID == CSSValueWebkitFlex || valueID == CSSValueWebkitInlineFlex)
561 if (parserContext.isCSSGridLayoutEnabled && (valueID == CSSValueWebkitGrid || valueID == CSSValueWebkitInlineGrid))
565 case CSSPropertyEmptyCells: // show | hide | inherit
566 if (valueID == CSSValueShow || valueID == CSSValueHide)
569 case CSSPropertyFloat: // left | right | none | center (for buggy CSS, maps to none)
570 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueNone || valueID == CSSValueCenter)
573 case CSSPropertyFontStyle: // normal | italic | oblique | inherit
574 if (valueID == CSSValueNormal || valueID == CSSValueItalic || valueID == CSSValueOblique)
577 case CSSPropertyImageRendering: // auto | optimizeContrast
578 if (valueID == CSSValueAuto || valueID == CSSValueWebkitOptimizeContrast)
581 case CSSPropertyListStylePosition: // inside | outside | inherit
582 if (valueID == CSSValueInside || valueID == CSSValueOutside)
585 case CSSPropertyListStyleType:
586 // See section CSS_PROP_LIST_STYLE_TYPE of file CSSValueKeywords.in
587 // for the list of supported list-style-types.
588 if ((valueID >= CSSValueDisc && valueID <= CSSValueKatakanaIroha) || valueID == CSSValueNone)
591 case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto | inherit
592 if (valueID == CSSValueAuto || valueID == CSSValueNone || (valueID >= CSSValueInset && valueID <= CSSValueDouble))
595 case CSSPropertyOverflowX:
596 case CSSPropertyOverflowY: // visible | hidden | scroll | auto | marquee | overlay | inherit
597 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitMarquee)
600 case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | inherit
601 case CSSPropertyPageBreakBefore:
602 case CSSPropertyWebkitColumnBreakAfter:
603 case CSSPropertyWebkitColumnBreakBefore:
604 if (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight)
607 case CSSPropertyPageBreakInside: // avoid | auto | inherit
608 case CSSPropertyWebkitColumnBreakInside:
609 if (valueID == CSSValueAuto || valueID == CSSValueAvoid)
612 case CSSPropertyPointerEvents:
613 // none | visiblePainted | visibleFill | visibleStroke | visible |
614 // painted | fill | stroke | auto | all | inherit
615 if (valueID == CSSValueVisible || valueID == CSSValueNone || valueID == CSSValueAll || valueID == CSSValueAuto || (valueID >= CSSValueVisiblepainted && valueID <= CSSValueStroke))
618 case CSSPropertyPosition: // static | relative | absolute | fixed | sticky | inherit
619 if (valueID == CSSValueStatic || valueID == CSSValueRelative || valueID == CSSValueAbsolute || valueID == CSSValueFixed
620 #if ENABLE(CSS_STICKY_POSITION)
621 || valueID == CSSValueWebkitSticky
626 case CSSPropertyResize: // none | both | horizontal | vertical | auto
627 if (valueID == CSSValueNone || valueID == CSSValueBoth || valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueAuto)
630 case CSSPropertySpeak: // none | normal | spell-out | digits | literal-punctuation | no-punctuation | inherit
631 if (valueID == CSSValueNone || valueID == CSSValueNormal || valueID == CSSValueSpellOut || valueID == CSSValueDigits || valueID == CSSValueLiteralPunctuation || valueID == CSSValueNoPunctuation)
634 case CSSPropertyTableLayout: // auto | fixed | inherit
635 if (valueID == CSSValueAuto || valueID == CSSValueFixed)
638 case CSSPropertyTextLineThroughMode:
639 case CSSPropertyTextOverlineMode:
640 case CSSPropertyTextUnderlineMode:
641 if (valueID == CSSValueContinuous || valueID == CSSValueSkipWhiteSpace)
644 case CSSPropertyTextLineThroughStyle:
645 case CSSPropertyTextOverlineStyle:
646 case CSSPropertyTextUnderlineStyle:
647 if (valueID == CSSValueNone || valueID == CSSValueSolid || valueID == CSSValueDouble || valueID == CSSValueDashed || valueID == CSSValueDotDash || valueID == CSSValueDotDotDash || valueID == CSSValueWave)
650 case CSSPropertyTextOverflow: // clip | ellipsis
651 if (valueID == CSSValueClip || valueID == CSSValueEllipsis)
654 case CSSPropertyTextRendering: // auto | optimizeSpeed | optimizeLegibility | geometricPrecision
655 if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizelegibility || valueID == CSSValueGeometricprecision)
658 case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none | inherit
659 if ((valueID >= CSSValueCapitalize && valueID <= CSSValueLowercase) || valueID == CSSValueNone)
662 case CSSPropertyVisibility: // visible | hidden | collapse | inherit
663 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueCollapse)
666 case CSSPropertyWebkitAppearance:
667 if ((valueID >= CSSValueCheckbox && valueID <= CSSValueTextarea) || valueID == CSSValueNone)
670 case CSSPropertyWebkitBackfaceVisibility:
671 if (valueID == CSSValueVisible || valueID == CSSValueHidden)
674 case CSSPropertyWebkitBorderFit:
675 if (valueID == CSSValueBorder || valueID == CSSValueLines)
678 case CSSPropertyWebkitBoxAlign:
679 if (valueID == CSSValueStretch || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline)
682 #if ENABLE(CSS_BOX_DECORATION_BREAK)
683 case CSSPropertyWebkitBoxDecorationBreak:
684 if (valueID == CSSValueClone || valueID == CSSValueSlice)
688 case CSSPropertyWebkitBoxDirection:
689 if (valueID == CSSValueNormal || valueID == CSSValueReverse)
692 case CSSPropertyWebkitBoxLines:
693 if (valueID == CSSValueSingle || valueID == CSSValueMultiple)
696 case CSSPropertyWebkitBoxOrient:
697 if (valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueInlineAxis || valueID == CSSValueBlockAxis)
700 case CSSPropertyWebkitBoxPack:
701 if (valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueJustify)
704 case CSSPropertyWebkitColorCorrection:
705 if (valueID == CSSValueSrgb || valueID == CSSValueDefault)
708 #if ENABLE(CSS3_FLEXBOX)
709 case CSSPropertyWebkitAlignContent:
710 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround || valueID == CSSValueStretch)
713 case CSSPropertyWebkitAlignItems:
714 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch)
717 case CSSPropertyWebkitAlignSelf:
718 if (valueID == CSSValueAuto || valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch)
721 case CSSPropertyWebkitFlexDirection:
722 if (valueID == CSSValueRow || valueID == CSSValueRowReverse || valueID == CSSValueColumn || valueID == CSSValueColumnReverse)
725 case CSSPropertyWebkitFlexWrap:
726 if (valueID == CSSValueNone || valueID == CSSValueWrap || valueID == CSSValueWrapReverse)
729 case CSSPropertyWebkitJustifyContent:
730 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround)
734 case CSSPropertyWebkitFontKerning:
735 if (valueID == CSSValueAuto || valueID == CSSValueNormal || valueID == CSSValueNone)
738 case CSSPropertyWebkitFontSmoothing:
739 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueAntialiased || valueID == CSSValueSubpixelAntialiased)
742 case CSSPropertyWebkitHyphens:
743 if (valueID == CSSValueNone || valueID == CSSValueManual || valueID == CSSValueAuto)
746 case CSSPropertyWebkitLineAlign:
747 if (valueID == CSSValueNone || valueID == CSSValueEdges)
750 case CSSPropertyWebkitLineBreak: // normal | after-white-space
751 if (valueID == CSSValueNormal || valueID == CSSValueAfterWhiteSpace)
754 case CSSPropertyWebkitLineSnap:
755 if (valueID == CSSValueNone || valueID == CSSValueBaseline || valueID == CSSValueContain)
758 case CSSPropertyWebkitMarginAfterCollapse:
759 case CSSPropertyWebkitMarginBeforeCollapse:
760 case CSSPropertyWebkitMarginBottomCollapse:
761 case CSSPropertyWebkitMarginTopCollapse:
762 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate || valueID == CSSValueDiscard)
765 case CSSPropertyWebkitMarqueeDirection:
766 if (valueID == CSSValueForwards || valueID == CSSValueBackwards || valueID == CSSValueAhead || valueID == CSSValueReverse || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueDown
767 || valueID == CSSValueUp || valueID == CSSValueAuto)
770 case CSSPropertyWebkitMarqueeStyle:
771 if (valueID == CSSValueNone || valueID == CSSValueSlide || valueID == CSSValueScroll || valueID == CSSValueAlternate)
774 case CSSPropertyWebkitNbspMode: // normal | space
775 if (valueID == CSSValueNormal || valueID == CSSValueSpace)
778 #if ENABLE(OVERFLOW_SCROLLING)
779 case CSSPropertyWebkitOverflowScrolling:
780 if (valueID == CSSValueAuto || valueID == CSSValueTouch)
784 case CSSPropertyWebkitPrintColorAdjust:
785 if (valueID == CSSValueExact || valueID == CSSValueEconomy)
788 #if ENABLE(CSS_REGIONS)
789 case CSSPropertyWebkitRegionBreakAfter:
790 case CSSPropertyWebkitRegionBreakBefore:
791 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight))
794 case CSSPropertyWebkitRegionBreakInside:
795 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAvoid))
798 case CSSPropertyWebkitRegionOverflow:
799 if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueBreak))
803 case CSSPropertyWebkitRtlOrdering:
804 if (valueID == CSSValueLogical || valueID == CSSValueVisual)
807 case CSSPropertyWebkitTextCombine:
808 if (valueID == CSSValueNone || valueID == CSSValueHorizontal)
811 case CSSPropertyWebkitTextEmphasisPosition:
812 if (valueID == CSSValueOver || valueID == CSSValueUnder)
815 case CSSPropertyWebkitTextSecurity:
816 // disc | circle | square | none | inherit
817 if (valueID == CSSValueDisc || valueID == CSSValueCircle || valueID == CSSValueSquare || valueID == CSSValueNone)
820 case CSSPropertyWebkitTextSizeAdjust:
821 if (valueID == CSSValueAuto || valueID == CSSValueNone)
824 case CSSPropertyWebkitTransformStyle:
825 if (valueID == CSSValueFlat || valueID == CSSValuePreserve3d)
828 case CSSPropertyWebkitUserDrag: // auto | none | element
829 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueElement)
832 case CSSPropertyWebkitUserModify: // read-only | read-write
833 if (valueID == CSSValueReadOnly || valueID == CSSValueReadWrite || valueID == CSSValueReadWritePlaintextOnly)
836 case CSSPropertyWebkitUserSelect: // auto | none | text
837 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueText)
840 #if ENABLE(CSS_EXCLUSIONS)
841 case CSSPropertyWebkitWrapFlow:
842 if (!RuntimeEnabledFeatures::cssExclusionsEnabled())
844 if (valueID == CSSValueAuto || valueID == CSSValueBoth || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueMaximum || valueID == CSSValueClear)
847 case CSSPropertyWebkitWrapThrough:
848 if (!RuntimeEnabledFeatures::cssExclusionsEnabled())
850 if (valueID == CSSValueWrap || valueID == CSSValueNone)
854 case CSSPropertyWebkitWritingMode:
855 if (valueID >= CSSValueHorizontalTb && valueID <= CSSValueHorizontalBt)
858 case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit
859 if (valueID == CSSValueNormal || valueID == CSSValuePre || valueID == CSSValuePreWrap || valueID == CSSValuePreLine || valueID == CSSValueNowrap)
862 case CSSPropertyWordBreak: // normal | break-all | break-word (this is a custom extension)
863 if (valueID == CSSValueNormal || valueID == CSSValueBreakAll || valueID == CSSValueBreakWord)
866 case CSSPropertyWordWrap: // normal | break-word
867 if (valueID == CSSValueNormal || valueID == CSSValueBreakWord)
871 ASSERT_NOT_REACHED();
877 static inline bool isKeywordPropertyID(CSSPropertyID propertyId)
879 switch (propertyId) {
880 case CSSPropertyBorderBottomStyle:
881 case CSSPropertyBorderCollapse:
882 case CSSPropertyBorderLeftStyle:
883 case CSSPropertyBorderRightStyle:
884 case CSSPropertyBorderTopStyle:
885 case CSSPropertyBoxSizing:
886 case CSSPropertyCaptionSide:
887 case CSSPropertyClear:
888 case CSSPropertyDirection:
889 case CSSPropertyDisplay:
890 case CSSPropertyEmptyCells:
891 case CSSPropertyFloat:
892 case CSSPropertyFontStyle:
893 case CSSPropertyImageRendering:
894 case CSSPropertyListStylePosition:
895 case CSSPropertyListStyleType:
896 case CSSPropertyOutlineStyle:
897 case CSSPropertyOverflowX:
898 case CSSPropertyOverflowY:
899 case CSSPropertyPageBreakAfter:
900 case CSSPropertyPageBreakBefore:
901 case CSSPropertyPageBreakInside:
902 case CSSPropertyPointerEvents:
903 case CSSPropertyPosition:
904 case CSSPropertyResize:
905 case CSSPropertySpeak:
906 case CSSPropertyTableLayout:
907 case CSSPropertyTextLineThroughMode:
908 case CSSPropertyTextLineThroughStyle:
909 case CSSPropertyTextOverflow:
910 case CSSPropertyTextOverlineMode:
911 case CSSPropertyTextOverlineStyle:
912 case CSSPropertyTextRendering:
913 case CSSPropertyTextTransform:
914 case CSSPropertyTextUnderlineMode:
915 case CSSPropertyTextUnderlineStyle:
916 case CSSPropertyVisibility:
917 case CSSPropertyWebkitAppearance:
918 case CSSPropertyWebkitBackfaceVisibility:
919 case CSSPropertyWebkitBorderAfterStyle:
920 case CSSPropertyWebkitBorderBeforeStyle:
921 case CSSPropertyWebkitBorderEndStyle:
922 case CSSPropertyWebkitBorderFit:
923 case CSSPropertyWebkitBorderStartStyle:
924 case CSSPropertyWebkitBoxAlign:
925 #if ENABLE(CSS_BOX_DECORATION_BREAK)
926 case CSSPropertyWebkitBoxDecorationBreak:
928 case CSSPropertyWebkitBoxDirection:
929 case CSSPropertyWebkitBoxLines:
930 case CSSPropertyWebkitBoxOrient:
931 case CSSPropertyWebkitBoxPack:
932 case CSSPropertyWebkitColorCorrection:
933 case CSSPropertyWebkitColumnBreakAfter:
934 case CSSPropertyWebkitColumnBreakBefore:
935 case CSSPropertyWebkitColumnBreakInside:
936 case CSSPropertyWebkitColumnRuleStyle:
937 #if ENABLE(CSS3_FLEXBOX)
938 case CSSPropertyWebkitAlignContent:
939 case CSSPropertyWebkitAlignItems:
940 case CSSPropertyWebkitAlignSelf:
941 case CSSPropertyWebkitFlexDirection:
942 case CSSPropertyWebkitFlexWrap:
943 case CSSPropertyWebkitJustifyContent:
945 case CSSPropertyWebkitFontKerning:
946 case CSSPropertyWebkitFontSmoothing:
947 case CSSPropertyWebkitHyphens:
948 case CSSPropertyWebkitLineAlign:
949 case CSSPropertyWebkitLineBreak:
950 case CSSPropertyWebkitLineSnap:
951 case CSSPropertyWebkitMarginAfterCollapse:
952 case CSSPropertyWebkitMarginBeforeCollapse:
953 case CSSPropertyWebkitMarginBottomCollapse:
954 case CSSPropertyWebkitMarginTopCollapse:
955 case CSSPropertyWebkitMarqueeDirection:
956 case CSSPropertyWebkitMarqueeStyle:
957 case CSSPropertyWebkitNbspMode:
958 #if ENABLE(OVERFLOW_SCROLLING)
959 case CSSPropertyWebkitOverflowScrolling:
961 case CSSPropertyWebkitPrintColorAdjust:
962 #if ENABLE(CSS_REGIONS)
963 case CSSPropertyWebkitRegionBreakAfter:
964 case CSSPropertyWebkitRegionBreakBefore:
965 case CSSPropertyWebkitRegionBreakInside:
966 case CSSPropertyWebkitRegionOverflow:
968 case CSSPropertyWebkitRtlOrdering:
969 case CSSPropertyWebkitTextCombine:
970 case CSSPropertyWebkitTextEmphasisPosition:
971 case CSSPropertyWebkitTextSecurity:
972 case CSSPropertyWebkitTextSizeAdjust:
973 case CSSPropertyWebkitTransformStyle:
974 case CSSPropertyWebkitUserDrag:
975 case CSSPropertyWebkitUserModify:
976 case CSSPropertyWebkitUserSelect:
977 #if ENABLE(CSS_EXCLUSIONS)
978 case CSSPropertyWebkitWrapFlow:
979 case CSSPropertyWebkitWrapThrough:
981 case CSSPropertyWebkitWritingMode:
982 case CSSPropertyWhiteSpace:
983 case CSSPropertyWordBreak:
984 case CSSPropertyWordWrap:
991 static bool parseKeywordValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, const CSSParserContext& parserContext)
993 ASSERT(!string.isEmpty());
995 if (!isKeywordPropertyID(propertyId))
998 CSSParserString cssString;
999 cssString.characters = const_cast<UChar*>(string.characters());
1000 cssString.length = string.length();
1001 int valueID = cssValueKeywordID(cssString);
1006 RefPtr<CSSValue> value;
1007 if (valueID == CSSValueInherit)
1008 value = cssValuePool().createInheritedValue();
1009 else if (valueID == CSSValueInitial)
1010 value = cssValuePool().createExplicitInitialValue();
1011 else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext))
1012 value = cssValuePool().createIdentifierValue(valueID);
1016 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
1020 template <typename CharType>
1021 static bool parseTransformArguments(WebKitCSSTransformValue* transformValue, CharType* characters, unsigned length, unsigned start, unsigned expectedCount)
1023 while (expectedCount) {
1024 size_t end = WTF::find(characters, length, expectedCount == 1 ? ')' : ',', start);
1025 if (end == notFound || (expectedCount == 1 && end != length - 1))
1027 unsigned argumentLength = end - start;
1028 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
1030 if (!parseSimpleLength(characters + start, argumentLength, unit, number))
1032 if (unit != CSSPrimitiveValue::CSS_PX && (number || unit != CSSPrimitiveValue::CSS_NUMBER))
1034 transformValue->append(cssValuePool().createValue(number, unit));
1041 static bool parseTransformValue(StylePropertySet* properties, CSSPropertyID propertyID, const String& string, bool important)
1043 if (propertyID != CSSPropertyWebkitTransform)
1045 static const unsigned shortestValidTransformStringLength = 12;
1046 static const unsigned likelyMultipartTransformStringLengthCutoff = 32;
1047 if (string.length() < shortestValidTransformStringLength || string.length() > likelyMultipartTransformStringLengthCutoff)
1049 if (!string.startsWith("translate", false))
1051 UChar c9 = toASCIILower(string[9]);
1052 UChar c10 = toASCIILower(string[10]);
1054 WebKitCSSTransformValue::TransformOperationType transformType;
1055 unsigned expectedArgumentCount = 1;
1056 unsigned argumentStart = 11;
1057 if (c9 == 'x' && c10 == '(')
1058 transformType = WebKitCSSTransformValue::TranslateXTransformOperation;
1059 else if (c9 == 'y' && c10 == '(')
1060 transformType = WebKitCSSTransformValue::TranslateYTransformOperation;
1061 else if (c9 == 'z' && c10 == '(')
1062 transformType = WebKitCSSTransformValue::TranslateZTransformOperation;
1063 else if (c9 == '(') {
1064 transformType = WebKitCSSTransformValue::TranslateTransformOperation;
1065 expectedArgumentCount = 2;
1067 } else if (c9 == '3' && c10 == 'd' && string[11] == '(') {
1068 transformType = WebKitCSSTransformValue::Translate3DTransformOperation;
1069 expectedArgumentCount = 3;
1074 RefPtr<WebKitCSSTransformValue> transformValue = WebKitCSSTransformValue::create(transformType);
1076 if (string.is8Bit())
1077 success = parseTransformArguments(transformValue.get(), string.characters8(), string.length(), argumentStart, expectedArgumentCount);
1079 success = parseTransformArguments(transformValue.get(), string.characters16(), string.length(), argumentStart, expectedArgumentCount);
1082 RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
1083 result->append(transformValue.release());
1084 properties->addParsedProperty(CSSProperty(CSSPropertyWebkitTransform, result.release(), important));
1088 PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& string)
1090 if (string.isEmpty())
1092 RefPtr<StylePropertySet> dummyStyle = StylePropertySet::create();
1093 if (!parseValue(dummyStyle.get(), CSSPropertyFontFamily, string, false, CSSQuirksMode, 0))
1095 return static_pointer_cast<CSSValueList>(dummyStyle->getPropertyCSSValue(CSSPropertyFontFamily));
1098 #if ENABLE(CSS_VARIABLES)
1099 bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, Document* document)
1101 ASSERT(!string.isEmpty());
1103 CSSParserContext context(document);
1105 if (parseSimpleLengthValue(declaration, propertyID, string, important, context.mode))
1107 if (parseColorValue(declaration, propertyID, string, important, context.mode))
1109 if (parseKeywordValue(declaration, propertyID, string, important, context))
1112 CSSParser parser(context);
1113 return parser.parseValue(declaration, propertyID, string, important, static_cast<StyleSheetContents*>(0));
1117 bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
1119 ASSERT(!string.isEmpty());
1120 if (parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode))
1122 if (parseColorValue(declaration, propertyID, string, important, cssParserMode))
1124 if (parseKeywordValue(declaration, propertyID, string, important, contextStyleSheet->parserContext()))
1126 if (parseTransformValue(declaration, propertyID, string, important))
1129 CSSParserContext context(cssParserMode);
1130 if (contextStyleSheet) {
1131 context = contextStyleSheet->parserContext();
1132 context.mode = cssParserMode;
1134 CSSParser parser(context);
1135 return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
1138 bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, StyleSheetContents* contextStyleSheet)
1140 setStyleSheet(contextStyleSheet);
1142 setupParser("@-webkit-value{", string, "} ");
1145 m_important = important;
1152 if (m_hasFontFaceOnlyValues)
1153 deleteFontFaceOnlyValues();
1154 if (!m_parsedProperties.isEmpty()) {
1156 declaration->addParsedProperties(m_parsedProperties);
1163 // The color will only be changed when string contains a valid CSS color, so callers
1164 // can set it to a default color and ignore the boolean result.
1165 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
1167 // First try creating a color specified by name, rgba(), rgb() or "#" syntax.
1168 if (fastParseColor(color, string, strict))
1171 CSSParser parser(CSSStrictMode);
1173 // In case the fast-path parser didn't understand the color, try the full parser.
1174 if (!parser.parseColor(string))
1177 CSSValue* value = parser.m_parsedProperties.first().value();
1178 if (!value->isPrimitiveValue())
1181 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
1182 if (!primitiveValue->isRGBColor())
1185 color = primitiveValue->getRGBA32Value();
1189 bool CSSParser::parseColor(const String& string)
1191 setupParser("@-webkit-decls{color:", string, "} ");
1195 return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
1198 bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
1200 if (!document || !document->page())
1203 CSSParserString cssColor;
1204 cssColor.characters = const_cast<UChar*>(string.characters());
1205 cssColor.length = string.length();
1206 int id = cssValueKeywordID(cssColor);
1210 color = document->page()->theme()->systemColor(id).rgb();
1214 void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
1216 m_selectorListForParseSelector = &selectorList;
1218 setupParser("@-webkit-selector{", string, "}");
1222 m_selectorListForParseSelector = 0;
1225 bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, PassRefPtr<CSSRuleSourceData> prpRuleSourceData, StyleSheetContents* contextStyleSheet)
1227 // Length of the "@-webkit-decls{" prefix.
1228 static const unsigned prefixLength = 15;
1230 setStyleSheet(contextStyleSheet);
1232 RefPtr<CSSRuleSourceData> ruleSourceData = prpRuleSourceData;
1233 if (ruleSourceData) {
1234 m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
1235 m_currentRuleDataStack->append(ruleSourceData);
1238 setupParser("@-webkit-decls{", string, "} ");
1243 if (m_hasFontFaceOnlyValues)
1244 deleteFontFaceOnlyValues();
1245 if (!m_parsedProperties.isEmpty()) {
1247 declaration->addParsedProperties(m_parsedProperties);
1251 if (ruleSourceData) {
1252 ASSERT(m_currentRuleDataStack->size() == 1);
1253 ruleSourceData->ruleBodyRange.start = 0;
1254 ruleSourceData->ruleBodyRange.end = string.length();
1255 for (size_t i = 0, size = ruleSourceData->styleSourceData->propertyData.size(); i < size; ++i) {
1256 CSSPropertySourceData& propertyData = ruleSourceData->styleSourceData->propertyData.at(i);
1257 propertyData.range.start -= prefixLength;
1258 propertyData.range.end -= prefixLength;
1261 fixUnparsedPropertyRanges(ruleSourceData.get());
1262 m_currentRuleDataStack.clear();
1268 PassOwnPtr<MediaQuery> CSSParser::parseMediaQuery(const String& string)
1270 if (string.isEmpty())
1273 ASSERT(!m_mediaQuery);
1275 // can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
1276 // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
1277 setupParser("@-webkit-mediaquery ", string, "} ");
1280 return m_mediaQuery.release();
1283 #if ENABLE(CSS_VARIABLES)
1284 static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties, HashSet<AtomicString>& seenVariables)
1286 static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties)
1289 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
1290 for (int i = input.size() - 1; i >= 0; --i) {
1291 const CSSProperty& property = input[i];
1292 if (property.isImportant() != important)
1294 #if ENABLE(CSS_VARIABLES)
1295 if (property.id() == CSSPropertyVariable) {
1296 const AtomicString& name = static_cast<CSSVariableValue*>(property.value())->name();
1297 if (seenVariables.contains(name))
1299 seenVariables.add(name);
1300 output[--unusedEntries] = property;
1304 const unsigned propertyIDIndex = property.id() - firstCSSProperty;
1305 if (seenProperties.get(propertyIDIndex))
1307 seenProperties.set(propertyIDIndex);
1308 output[--unusedEntries] = property;
1312 PassRefPtr<StylePropertySet> CSSParser::createStylePropertySet()
1314 BitArray<numCSSProperties> seenProperties;
1315 size_t unusedEntries = m_parsedProperties.size();
1316 Vector<CSSProperty, 256> results(unusedEntries);
1318 // Important properties have higher priority, so add them first. Duplicate definitions can then be ignored when found.
1319 #if ENABLE(CSS_VARIABLES)
1320 HashSet<AtomicString> seenVariables;
1321 filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties, seenVariables);
1322 filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties, seenVariables);
1324 filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties);
1325 filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties);
1328 results.remove(0, unusedEntries);
1330 return StylePropertySet::createImmutable(results.data(), results.size(), m_context.mode);
1333 void CSSParser::addProperty(CSSPropertyID propId, PassRefPtr<CSSValue> value, bool important, bool implicit)
1335 m_parsedProperties.append(CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand || implicit));
1338 void CSSParser::rollbackLastProperties(int num)
1341 ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num));
1342 m_parsedProperties.shrink(m_parsedProperties.size() - num);
1345 void CSSParser::clearProperties()
1347 m_parsedProperties.clear();
1348 m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
1349 m_hasFontFaceOnlyValues = false;
1352 void CSSParser::setStyleSheet(StyleSheetContents* styleSheet)
1354 m_styleSheet = styleSheet;
1357 KURL CSSParser::completeURL(const CSSParserContext& context, const String& url)
1361 if (context.charset.isEmpty())
1362 return KURL(context.baseURL, url);
1363 return KURL(context.baseURL, url, context.charset);
1366 KURL CSSParser::completeURL(const String& url) const
1368 return completeURL(m_context, url);
1371 bool CSSParser::validCalculationUnit(CSSParserValue* value, Units unitflags)
1373 bool mustBeNonNegative = unitflags & FNonNeg;
1375 if (!parseCalculation(value, mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll))
1379 switch (m_parsedCalculation->category()) {
1381 b = (unitflags & FLength);
1384 b = (unitflags & FPercent);
1385 if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
1389 b = (unitflags & FNumber);
1390 if (!b && (unitflags & FInteger) && m_parsedCalculation->isInt())
1392 if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
1395 case CalcPercentLength:
1396 b = (unitflags & FPercent) && (unitflags & FLength);
1398 case CalcPercentNumber:
1399 b = (unitflags & FPercent) && (unitflags & FNumber);
1405 m_parsedCalculation.release();
1409 inline bool CSSParser::shouldAcceptUnitLessValues(CSSParserValue* value, Units unitflags, CSSParserMode cssParserMode)
1411 // Qirks mode and svg presentation attributes accept unit less values.
1412 return (unitflags & (FLength | FAngle | FTime)) && (!value->fValue || cssParserMode == CSSQuirksMode || cssParserMode == SVGAttributeMode);
1415 bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, CSSParserMode cssParserMode)
1417 if (isCalculation(value))
1418 return validCalculationUnit(value, unitflags);
1421 switch (value->unit) {
1422 #if ENABLE(CSS_VARIABLES)
1423 case CSSPrimitiveValue::CSS_VARIABLE_NAME:
1424 // Variables are checked at the point they are dereferenced because unit type is not available here.
1428 case CSSPrimitiveValue::CSS_NUMBER:
1429 b = (unitflags & FNumber);
1430 if (!b && shouldAcceptUnitLessValues(value, unitflags, cssParserMode)) {
1431 value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX :
1432 ((unitflags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS);
1435 if (!b && (unitflags & FInteger) && value->isInt)
1438 case CSSPrimitiveValue::CSS_PERCENTAGE:
1439 b = (unitflags & FPercent);
1441 case CSSParserValue::Q_EMS:
1442 case CSSPrimitiveValue::CSS_EMS:
1443 case CSSPrimitiveValue::CSS_REMS:
1444 case CSSPrimitiveValue::CSS_EXS:
1445 case CSSPrimitiveValue::CSS_PX:
1446 case CSSPrimitiveValue::CSS_CM:
1447 case CSSPrimitiveValue::CSS_MM:
1448 case CSSPrimitiveValue::CSS_IN:
1449 case CSSPrimitiveValue::CSS_PT:
1450 case CSSPrimitiveValue::CSS_PC:
1451 case CSSPrimitiveValue::CSS_VW:
1452 case CSSPrimitiveValue::CSS_VH:
1453 case CSSPrimitiveValue::CSS_VMIN:
1454 b = (unitflags & FLength);
1456 case CSSPrimitiveValue::CSS_MS:
1457 case CSSPrimitiveValue::CSS_S:
1458 b = (unitflags & FTime);
1460 case CSSPrimitiveValue::CSS_DEG:
1461 case CSSPrimitiveValue::CSS_RAD:
1462 case CSSPrimitiveValue::CSS_GRAD:
1463 case CSSPrimitiveValue::CSS_TURN:
1464 b = (unitflags & FAngle);
1466 #if ENABLE(CSS_IMAGE_RESOLUTION)
1467 case CSSPrimitiveValue::CSS_DPPX:
1468 case CSSPrimitiveValue::CSS_DPI:
1469 case CSSPrimitiveValue::CSS_DPCM:
1470 b = (unitflags & FResolution);
1473 case CSSPrimitiveValue::CSS_HZ:
1474 case CSSPrimitiveValue::CSS_KHZ:
1475 case CSSPrimitiveValue::CSS_DIMENSION:
1479 if (b && unitflags & FNonNeg && value->fValue < 0)
1484 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSParserValue* value)
1486 #if ENABLE(CSS_VARIABLES)
1487 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
1488 return CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_VARIABLE_NAME);
1491 if (m_parsedCalculation) {
1492 ASSERT(isCalculation(value));
1493 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1496 #if ENABLE(CSS_IMAGE_RESOLUTION)
1497 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1498 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
1499 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMIN)
1500 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM));
1502 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1503 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
1504 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMIN));
1506 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value->unit));
1509 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSParserValue* value)
1511 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT);
1512 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRING);
1515 static int unitFromString(CSSParserValue* value)
1517 if (value->unit != CSSPrimitiveValue::CSS_IDENT || value->id)
1520 if (equal(value->string, "em"))
1521 return CSSPrimitiveValue::CSS_EMS;
1522 if (equal(value->string, "rem"))
1523 return CSSPrimitiveValue::CSS_REMS;
1524 if (equal(value->string, "ex"))
1525 return CSSPrimitiveValue::CSS_EXS;
1526 if (equal(value->string, "px"))
1527 return CSSPrimitiveValue::CSS_PX;
1528 if (equal(value->string, "cm"))
1529 return CSSPrimitiveValue::CSS_CM;
1530 if (equal(value->string, "mm"))
1531 return CSSPrimitiveValue::CSS_MM;
1532 if (equal(value->string, "in"))
1533 return CSSPrimitiveValue::CSS_IN;
1534 if (equal(value->string, "pt"))
1535 return CSSPrimitiveValue::CSS_PT;
1536 if (equal(value->string, "pc"))
1537 return CSSPrimitiveValue::CSS_PC;
1538 if (equal(value->string, "deg"))
1539 return CSSPrimitiveValue::CSS_DEG;
1540 if (equal(value->string, "rad"))
1541 return CSSPrimitiveValue::CSS_RAD;
1542 if (equal(value->string, "grad"))
1543 return CSSPrimitiveValue::CSS_GRAD;
1544 if (equal(value->string, "turn"))
1545 return CSSPrimitiveValue::CSS_TURN;
1546 if (equal(value->string, "ms"))
1547 return CSSPrimitiveValue::CSS_MS;
1548 if (equal(value->string, "s"))
1549 return CSSPrimitiveValue::CSS_S;
1550 if (equal(value->string, "Hz"))
1551 return CSSPrimitiveValue::CSS_HZ;
1552 if (equal(value->string, "kHz"))
1553 return CSSPrimitiveValue::CSS_KHZ;
1554 if (equal(value->string, "vw"))
1555 return CSSPrimitiveValue::CSS_VW;
1556 if (equal(value->string, "vh"))
1557 return CSSPrimitiveValue::CSS_VH;
1558 if (equal(value->string, "vmin"))
1559 return CSSPrimitiveValue::CSS_VMIN;
1560 #if ENABLE(CSS_IMAGE_RESOLUTION)
1561 if (equal(value->string, "dppx"))
1562 return CSSPrimitiveValue::CSS_DPPX;
1563 if (equal(value->string, "dpi"))
1564 return CSSPrimitiveValue::CSS_DPI;
1565 if (equal(value->string, "dpcm"))
1566 return CSSPrimitiveValue::CSS_DPCM;
1572 static inline bool isComma(CSSParserValue* value)
1574 return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
1577 bool CSSParser::validWidth(CSSParserValue* value)
1580 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent)
1582 return !id && validUnit(value, FLength | FPercent | FNonNeg);
1585 // FIXME: Combine this with validWidth when we support fit-content, et al, for heights.
1586 bool CSSParser::validHeight(CSSParserValue* value)
1589 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic)
1591 return !id && validUnit(value, FLength | FPercent | FNonNeg);
1594 void CSSParser::checkForOrphanedUnits()
1596 if (inStrictMode() || inShorthand())
1599 // The purpose of this code is to implement the WinIE quirk that allows unit types to be separated from their numeric values
1600 // by whitespace, so e.g., width: 20 px instead of width:20px. This is invalid CSS, so we don't do this in strict mode.
1601 CSSParserValue* numericVal = 0;
1602 unsigned size = m_valueList->size();
1603 for (unsigned i = 0; i < size; i++) {
1604 CSSParserValue* value = m_valueList->valueAt(i);
1607 // Change the unit type of the numeric val to match.
1608 int unit = unitFromString(value);
1610 numericVal->unit = unit;
1613 // Now delete the bogus unit value.
1614 m_valueList->deleteValueAt(i);
1615 i--; // We're safe even though |i| is unsigned, since we only hit this code if we had a previous numeric value (so |i| is always > 0 here).
1621 numericVal = (value->unit == CSSPrimitiveValue::CSS_NUMBER) ? value : 0;
1625 inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(int identifier, CSSParserValue* value)
1628 return cssValuePool().createIdentifierValue(identifier);
1629 if (value->unit == CSSPrimitiveValue::CSS_STRING)
1630 return createPrimitiveStringValue(value);
1631 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1632 return createPrimitiveNumericValue(value);
1633 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
1634 return createPrimitiveNumericValue(value);
1635 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMIN)
1636 return createPrimitiveNumericValue(value);
1637 #if ENABLE(CSS_IMAGE_RESOLUTION)
1638 if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM)
1639 return createPrimitiveNumericValue(value);
1641 if (value->unit >= CSSParserValue::Q_EMS)
1642 return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
1643 if (isCalculation(value))
1644 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1649 bool CSSParser::parseValue(CSSPropertyID propId, bool important)
1654 CSSParserValue* value = m_valueList->current();
1659 // Note: m_parsedCalculation is used to pass the calc value to validUnit and then cleared at the end of this function.
1660 // FIXME: This is to avoid having to pass parsedCalc to all validUnit callers.
1661 ASSERT(!m_parsedCalculation);
1665 // In quirks mode, we will look for units that have been incorrectly separated from the number they belong to
1666 // by a space. We go ahead and associate the unit with the number even though it is invalid CSS.
1667 checkForOrphanedUnits();
1669 int num = inShorthand() ? 1 : m_valueList->size();
1671 if (id == CSSValueInherit) {
1674 addProperty(propId, cssValuePool().createInheritedValue(), important);
1677 else if (id == CSSValueInitial) {
1680 addProperty(propId, cssValuePool().createExplicitInitialValue(), important);
1684 #if ENABLE(CSS_VARIABLES)
1685 if (!id && value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME && num == 1) {
1686 addProperty(propId, CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_VARIABLE_NAME), important);
1687 m_valueList->next();
1690 ASSERT(propId != CSSPropertyVariable);
1693 if (isKeywordPropertyID(propId)) {
1694 if (!isValidKeywordPropertyAndValue(propId, id, m_context))
1696 if (m_valueList->next() && !inShorthand())
1698 addProperty(propId, cssValuePool().createIdentifierValue(id), important);
1702 bool validPrimitive = false;
1703 RefPtr<CSSValue> parsedValue;
1706 case CSSPropertySize: // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
1707 return parseSize(propId, important);
1709 case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit
1711 validPrimitive = true;
1713 return parseQuotes(propId, important);
1715 case CSSPropertyUnicodeBidi: // normal | embed | (bidi-override || isolate) | plaintext | inherit
1716 if (id == CSSValueNormal
1717 || id == CSSValueEmbed
1718 || id == CSSValueWebkitPlaintext)
1719 validPrimitive = true;
1721 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1722 bool isValid = true;
1723 while (isValid && value) {
1724 switch (value->id) {
1725 case CSSValueBidiOverride:
1726 case CSSValueWebkitIsolate:
1727 list->append(cssValuePool().createIdentifierValue(value->id));
1732 value = m_valueList->next();
1734 if (list->length() && isValid) {
1735 parsedValue = list.release();
1736 m_valueList->next();
1741 case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
1742 // close-quote | no-open-quote | no-close-quote ]+ | inherit
1743 return parseContent(propId, important);
1745 case CSSPropertyClip: // <shape> | auto | inherit
1746 if (id == CSSValueAuto)
1747 validPrimitive = true;
1748 else if (value->unit == CSSParserValue::Function)
1749 return parseClipShape(propId, important);
1752 /* Start of supported CSS properties with validation. This is needed for parseShorthand to work
1753 * correctly and allows optimization in WebCore::applyRule(..)
1755 case CSSPropertyOverflow: {
1756 ShorthandScope scope(this, propId);
1757 if (num != 1 || !parseValue(CSSPropertyOverflowX, important))
1759 CSSValue* value = m_parsedProperties.last().value();
1760 addProperty(CSSPropertyOverflowY, value, important);
1764 case CSSPropertyTextAlign:
1765 // left | right | center | justify | -webkit-left | -webkit-right | -webkit-center | -webkit-match-parent
1766 // | start | end | <string> | inherit | -webkit-auto (converted to start)
1767 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd
1768 || value->unit == CSSPrimitiveValue::CSS_STRING)
1769 validPrimitive = true;
1772 case CSSPropertyFontWeight: { // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
1773 if (m_valueList->size() != 1)
1775 return parseFontWeight(important);
1777 case CSSPropertyBorderSpacing: {
1779 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1780 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
1782 CSSValue* value = m_parsedProperties.last().value();
1783 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important);
1786 else if (num == 2) {
1787 ShorthandScope scope(this, CSSPropertyBorderSpacing);
1788 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important) || !parseValue(CSSPropertyWebkitBorderVerticalSpacing, important))
1794 case CSSPropertyWebkitBorderHorizontalSpacing:
1795 case CSSPropertyWebkitBorderVerticalSpacing:
1796 validPrimitive = validUnit(value, FLength | FNonNeg);
1798 case CSSPropertyOutlineColor: // <color> | invert | inherit
1799 // Outline color has "invert" as additional keyword.
1800 // Also, we want to allow the special focus color even in strict parsing mode.
1801 if (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor) {
1802 validPrimitive = true;
1806 case CSSPropertyBackgroundColor: // <color> | inherit
1807 case CSSPropertyBorderTopColor: // <color> | inherit
1808 case CSSPropertyBorderRightColor:
1809 case CSSPropertyBorderBottomColor:
1810 case CSSPropertyBorderLeftColor:
1811 case CSSPropertyWebkitBorderStartColor:
1812 case CSSPropertyWebkitBorderEndColor:
1813 case CSSPropertyWebkitBorderBeforeColor:
1814 case CSSPropertyWebkitBorderAfterColor:
1815 case CSSPropertyColor: // <color> | inherit
1816 case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors
1817 case CSSPropertyTextUnderlineColor:
1818 case CSSPropertyTextOverlineColor:
1819 case CSSPropertyWebkitColumnRuleColor:
1820 case CSSPropertyWebkitTextEmphasisColor:
1821 case CSSPropertyWebkitTextFillColor:
1822 case CSSPropertyWebkitTextStrokeColor:
1823 if (id == CSSValueWebkitText)
1824 validPrimitive = true; // Always allow this, even when strict parsing is on,
1825 // since we use this in our UA sheets.
1826 else if (id == CSSValueCurrentcolor)
1827 validPrimitive = true;
1828 else if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu ||
1829 (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
1830 validPrimitive = true;
1832 parsedValue = parseColor();
1834 m_valueList->next();
1838 case CSSPropertyCursor: {
1839 // [<uri>,]* [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |
1840 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize |
1841 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help |
1842 // vertical-text | cell | context-menu | alias | copy | no-drop | not-allowed | -webkit-zoom-in
1843 // -webkit-zoom-out | all-scroll | -webkit-grab | -webkit-grabbing ] ] | inherit
1844 RefPtr<CSSValueList> list;
1845 while (value && value->unit == CSSPrimitiveValue::CSS_URI) {
1847 list = CSSValueList::createCommaSeparated();
1848 String uri = value->string;
1850 value = m_valueList->next();
1851 while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
1852 coords.append(int(value->fValue));
1853 value = m_valueList->next();
1855 IntPoint hotSpot(-1, -1);
1856 int nrcoords = coords.size();
1857 if (nrcoords > 0 && nrcoords != 2)
1860 hotSpot = IntPoint(coords[0], coords[1]);
1863 list->append(CSSCursorImageValue::create(completeURL(uri), hotSpot));
1865 if ((inStrictMode() && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ',')))
1867 value = m_valueList->next(); // comma
1870 if (!value) { // no value after url list (MSIE 5 compatibility)
1871 if (list->length() != 1)
1873 } else if (inQuirksMode() && value->id == CSSValueHand) // MSIE 5 compatibility :/
1874 list->append(cssValuePool().createIdentifierValue(CSSValuePointer));
1875 else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
1876 list->append(cssValuePool().createIdentifierValue(value->id));
1877 m_valueList->next();
1878 parsedValue = list.release();
1882 if (inQuirksMode() && value->id == CSSValueHand) { // MSIE 5 compatibility :/
1883 id = CSSValuePointer;
1884 validPrimitive = true;
1885 } else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
1886 validPrimitive = true;
1888 ASSERT_NOT_REACHED();
1894 case CSSPropertyBackgroundAttachment:
1895 case CSSPropertyBackgroundClip:
1896 case CSSPropertyWebkitBackgroundClip:
1897 case CSSPropertyWebkitBackgroundComposite:
1898 case CSSPropertyBackgroundImage:
1899 case CSSPropertyBackgroundOrigin:
1900 case CSSPropertyWebkitBackgroundOrigin:
1901 case CSSPropertyBackgroundPosition:
1902 case CSSPropertyBackgroundPositionX:
1903 case CSSPropertyBackgroundPositionY:
1904 case CSSPropertyBackgroundSize:
1905 case CSSPropertyWebkitBackgroundSize:
1906 case CSSPropertyBackgroundRepeat:
1907 case CSSPropertyBackgroundRepeatX:
1908 case CSSPropertyBackgroundRepeatY:
1909 case CSSPropertyWebkitMaskAttachment:
1910 case CSSPropertyWebkitMaskClip:
1911 case CSSPropertyWebkitMaskComposite:
1912 case CSSPropertyWebkitMaskImage:
1913 case CSSPropertyWebkitMaskOrigin:
1914 case CSSPropertyWebkitMaskPosition:
1915 case CSSPropertyWebkitMaskPositionX:
1916 case CSSPropertyWebkitMaskPositionY:
1917 case CSSPropertyWebkitMaskSize:
1918 case CSSPropertyWebkitMaskRepeat:
1919 case CSSPropertyWebkitMaskRepeatX:
1920 case CSSPropertyWebkitMaskRepeatY: {
1921 RefPtr<CSSValue> val1;
1922 RefPtr<CSSValue> val2;
1923 CSSPropertyID propId1, propId2;
1924 bool result = false;
1925 if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
1926 OwnPtr<ShorthandScope> shorthandScope;
1927 if (propId == CSSPropertyBackgroundPosition ||
1928 propId == CSSPropertyBackgroundRepeat ||
1929 propId == CSSPropertyWebkitMaskPosition ||
1930 propId == CSSPropertyWebkitMaskRepeat) {
1931 shorthandScope = adoptPtr(new ShorthandScope(this, propId));
1933 addProperty(propId1, val1.release(), important);
1935 addProperty(propId2, val2.release(), important);
1938 m_implicitShorthand = false;
1941 case CSSPropertyListStyleImage: // <uri> | none | inherit
1942 case CSSPropertyBorderImageSource:
1943 case CSSPropertyWebkitMaskBoxImageSource:
1944 if (id == CSSValueNone) {
1945 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone);
1946 m_valueList->next();
1947 } else if (value->unit == CSSPrimitiveValue::CSS_URI) {
1948 parsedValue = CSSImageValue::create(completeURL(value->string));
1949 m_valueList->next();
1950 } else if (isGeneratedImageValue(value)) {
1951 if (parseGeneratedImage(m_valueList.get(), parsedValue))
1952 m_valueList->next();
1956 #if ENABLE(CSS_IMAGE_SET)
1957 else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
1958 parsedValue = parseImageSet(m_valueList.get());
1961 m_valueList->next();
1966 case CSSPropertyWebkitTextStrokeWidth:
1967 case CSSPropertyOutlineWidth: // <border-width> | inherit
1968 case CSSPropertyBorderTopWidth: //// <border-width> | inherit
1969 case CSSPropertyBorderRightWidth: // Which is defined as
1970 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
1971 case CSSPropertyBorderLeftWidth:
1972 case CSSPropertyWebkitBorderStartWidth:
1973 case CSSPropertyWebkitBorderEndWidth:
1974 case CSSPropertyWebkitBorderBeforeWidth:
1975 case CSSPropertyWebkitBorderAfterWidth:
1976 case CSSPropertyWebkitColumnRuleWidth:
1977 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
1978 validPrimitive = true;
1980 validPrimitive = validUnit(value, FLength | FNonNeg);
1983 case CSSPropertyLetterSpacing: // normal | <length> | inherit
1984 case CSSPropertyWordSpacing: // normal | <length> | inherit
1985 if (id == CSSValueNormal)
1986 validPrimitive = true;
1988 validPrimitive = validUnit(value, FLength);
1991 case CSSPropertyTextIndent: // <length> | <percentage> | inherit
1992 validPrimitive = (!id && validUnit(value, FLength | FPercent));
1995 case CSSPropertyPaddingTop: //// <padding-width> | inherit
1996 case CSSPropertyPaddingRight: // Which is defined as
1997 case CSSPropertyPaddingBottom: // <length> | <percentage>
1998 case CSSPropertyPaddingLeft: ////
1999 case CSSPropertyWebkitPaddingStart:
2000 case CSSPropertyWebkitPaddingEnd:
2001 case CSSPropertyWebkitPaddingBefore:
2002 case CSSPropertyWebkitPaddingAfter:
2003 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
2006 case CSSPropertyMaxWidth:
2007 case CSSPropertyWebkitMaxLogicalWidth:
2008 validPrimitive = (id == CSSValueNone || validWidth(value));
2011 case CSSPropertyMinWidth:
2012 case CSSPropertyWebkitMinLogicalWidth:
2013 case CSSPropertyWidth:
2014 case CSSPropertyWebkitLogicalWidth:
2015 validPrimitive = (id == CSSValueAuto || validWidth(value));
2018 case CSSPropertyMaxHeight:
2019 case CSSPropertyWebkitMaxLogicalHeight:
2020 validPrimitive = (id == CSSValueNone || validHeight(value));
2023 case CSSPropertyMinHeight:
2024 case CSSPropertyWebkitMinLogicalHeight:
2025 case CSSPropertyHeight:
2026 case CSSPropertyWebkitLogicalHeight:
2027 validPrimitive = (id == CSSValueAuto || validHeight(value));
2030 case CSSPropertyFontSize:
2031 return parseFontSize(important);
2033 case CSSPropertyFontVariant: // normal | small-caps | inherit
2034 return parseFontVariant(important);
2036 case CSSPropertyVerticalAlign:
2037 // baseline | sub | super | top | text-top | middle | bottom | text-bottom |
2038 // <percentage> | <length> | inherit
2040 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
2041 validPrimitive = true;
2043 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2046 case CSSPropertyBottom: // <length> | <percentage> | auto | inherit
2047 case CSSPropertyLeft: // <length> | <percentage> | auto | inherit
2048 case CSSPropertyRight: // <length> | <percentage> | auto | inherit
2049 case CSSPropertyTop: // <length> | <percentage> | auto | inherit
2050 case CSSPropertyMarginTop: //// <margin-width> | inherit
2051 case CSSPropertyMarginRight: // Which is defined as
2052 case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit
2053 case CSSPropertyMarginLeft: ////
2054 case CSSPropertyWebkitMarginStart:
2055 case CSSPropertyWebkitMarginEnd:
2056 case CSSPropertyWebkitMarginBefore:
2057 case CSSPropertyWebkitMarginAfter:
2058 if (id == CSSValueAuto)
2059 validPrimitive = true;
2061 validPrimitive = (!id && validUnit(value, FLength | FPercent));
2064 case CSSPropertyZIndex: // auto | <integer> | inherit
2065 if (id == CSSValueAuto) {
2066 validPrimitive = true;
2070 case CSSPropertyOrphans: // <integer> | inherit
2071 case CSSPropertyWidows: // <integer> | inherit
2072 // ### not supported later on
2073 validPrimitive = (!id && validUnit(value, FInteger, CSSQuirksMode));
2076 case CSSPropertyLineHeight:
2077 return parseLineHeight(important);
2078 case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit
2079 if (id != CSSValueNone)
2080 return parseCounter(propId, 1, important);
2081 validPrimitive = true;
2083 case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit
2084 if (id != CSSValueNone)
2085 return parseCounter(propId, 0, important);
2086 validPrimitive = true;
2088 case CSSPropertyFontFamily:
2089 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit
2091 parsedValue = parseFontFamily();
2095 case CSSPropertyTextDecoration:
2096 case CSSPropertyWebkitTextDecorationsInEffect:
2097 // none | [ underline || overline || line-through || blink ] | inherit
2098 if (id == CSSValueNone) {
2099 validPrimitive = true;
2101 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2102 bool isValid = true;
2103 while (isValid && value) {
2104 switch (value->id) {
2107 case CSSValueUnderline:
2108 case CSSValueOverline:
2109 case CSSValueLineThrough:
2110 list->append(cssValuePool().createIdentifierValue(value->id));
2115 value = m_valueList->next();
2117 if (list->length() && isValid) {
2118 parsedValue = list.release();
2119 m_valueList->next();
2124 case CSSPropertyZoom: // normal | reset | document | <number> | <percentage> | inherit
2125 if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument)
2126 validPrimitive = true;
2128 validPrimitive = (!id && validUnit(value, FNumber | FPercent | FNonNeg, CSSStrictMode));
2131 case CSSPropertySrc: // Only used within @font-face, so cannot use inherit | initial or be !important. This is a list of urls or local references.
2132 return parseFontFaceSrc();
2134 case CSSPropertyUnicodeRange:
2135 return parseFontFaceUnicodeRange();
2137 /* CSS3 properties */
2139 case CSSPropertyBorderImage: {
2140 RefPtr<CSSValue> result;
2141 return parseBorderImage(propId, result, important);
2143 case CSSPropertyWebkitBorderImage:
2144 case CSSPropertyWebkitMaskBoxImage: {
2145 RefPtr<CSSValue> result;
2146 if (parseBorderImage(propId, result)) {
2147 addProperty(propId, result, important);
2152 case CSSPropertyBorderImageOutset:
2153 case CSSPropertyWebkitMaskBoxImageOutset: {
2154 RefPtr<CSSPrimitiveValue> result;
2155 if (parseBorderImageOutset(result)) {
2156 addProperty(propId, result, important);
2161 case CSSPropertyBorderImageRepeat:
2162 case CSSPropertyWebkitMaskBoxImageRepeat: {
2163 RefPtr<CSSValue> result;
2164 if (parseBorderImageRepeat(result)) {
2165 addProperty(propId, result, important);
2170 case CSSPropertyBorderImageSlice:
2171 case CSSPropertyWebkitMaskBoxImageSlice: {
2172 RefPtr<CSSBorderImageSliceValue> result;
2173 if (parseBorderImageSlice(propId, result)) {
2174 addProperty(propId, result, important);
2179 case CSSPropertyBorderImageWidth:
2180 case CSSPropertyWebkitMaskBoxImageWidth: {
2181 RefPtr<CSSPrimitiveValue> result;
2182 if (parseBorderImageWidth(result)) {
2183 addProperty(propId, result, important);
2188 case CSSPropertyBorderTopRightRadius:
2189 case CSSPropertyBorderTopLeftRadius:
2190 case CSSPropertyBorderBottomLeftRadius:
2191 case CSSPropertyBorderBottomRightRadius: {
2192 if (num != 1 && num != 2)
2194 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
2195 if (!validPrimitive)
2197 RefPtr<CSSPrimitiveValue> parsedValue1 = createPrimitiveNumericValue(value);
2198 RefPtr<CSSPrimitiveValue> parsedValue2;
2200 value = m_valueList->next();
2201 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
2202 if (!validPrimitive)
2204 parsedValue2 = createPrimitiveNumericValue(value);
2206 parsedValue2 = parsedValue1;
2208 RefPtr<Pair> pair = Pair::create(parsedValue1.release(), parsedValue2.release());
2209 RefPtr<CSSPrimitiveValue> val = cssValuePool().createValue(pair.release());
2210 addProperty(propId, val.release(), important);
2213 case CSSPropertyTabSize:
2214 validPrimitive = validUnit(value, FInteger | FNonNeg);
2216 case CSSPropertyWebkitAspectRatio:
2217 return parseAspectRatio(important);
2218 case CSSPropertyBorderRadius:
2219 case CSSPropertyWebkitBorderRadius:
2220 return parseBorderRadius(propId, important);
2221 case CSSPropertyOutlineOffset:
2222 validPrimitive = validUnit(value, FLength | FPercent);
2224 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
2225 case CSSPropertyBoxShadow:
2226 case CSSPropertyWebkitBoxShadow:
2227 if (id == CSSValueNone)
2228 validPrimitive = true;
2230 RefPtr<CSSValueList> shadowValueList = parseShadow(m_valueList.get(), propId);
2231 if (shadowValueList) {
2232 addProperty(propId, shadowValueList.release(), important);
2233 m_valueList->next();
2239 case CSSPropertyWebkitBoxReflect:
2240 if (id == CSSValueNone)
2241 validPrimitive = true;
2243 return parseReflect(propId, important);
2245 case CSSPropertyOpacity:
2246 validPrimitive = validUnit(value, FNumber);
2248 case CSSPropertyWebkitBoxFlex:
2249 validPrimitive = validUnit(value, FNumber);
2251 case CSSPropertyWebkitBoxFlexGroup:
2252 validPrimitive = validUnit(value, FInteger | FNonNeg, CSSStrictMode);
2254 case CSSPropertyWebkitBoxOrdinalGroup:
2255 validPrimitive = validUnit(value, FInteger | FNonNeg, CSSStrictMode) && value->fValue;
2257 #if ENABLE(CSS_FILTERS)
2258 case CSSPropertyWebkitFilter:
2259 if (id == CSSValueNone)
2260 validPrimitive = true;
2262 RefPtr<CSSValue> val = parseFilter();
2264 addProperty(propId, val, important);
2271 #if ENABLE(CSS3_FLEXBOX)
2272 case CSSPropertyWebkitFlex: {
2273 ShorthandScope scope(this, propId);
2274 if (id == CSSValueNone) {
2275 addProperty(CSSPropertyWebkitFlexGrow, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2276 addProperty(CSSPropertyWebkitFlexShrink, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
2277 addProperty(CSSPropertyWebkitFlexBasis, cssValuePool().createIdentifierValue(CSSValueAuto), important);
2280 return parseFlex(m_valueList.get(), important);
2282 case CSSPropertyWebkitFlexBasis:
2283 // FIXME: Support intrinsic dimensions too.
2284 if (id == CSSValueAuto)
2285 validPrimitive = true;
2287 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
2289 case CSSPropertyWebkitFlexGrow:
2290 case CSSPropertyWebkitFlexShrink:
2291 validPrimitive = validUnit(value, FNumber | FNonNeg);
2293 case CSSPropertyWebkitOrder:
2294 validPrimitive = validUnit(value, FNumber);
2297 case CSSPropertyWebkitMarquee:
2298 return parseShorthand(propId, webkitMarqueeShorthand(), important);
2299 case CSSPropertyWebkitMarqueeIncrement:
2300 if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
2301 validPrimitive = true;
2303 validPrimitive = validUnit(value, FLength | FPercent);
2305 case CSSPropertyWebkitMarqueeRepetition:
2306 if (id == CSSValueInfinite)
2307 validPrimitive = true;
2309 validPrimitive = validUnit(value, FInteger | FNonNeg);
2311 case CSSPropertyWebkitMarqueeSpeed:
2312 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
2313 validPrimitive = true;
2315 validPrimitive = validUnit(value, FTime | FInteger | FNonNeg);
2317 #if ENABLE(CSS_REGIONS)
2318 case CSSPropertyWebkitFlowInto:
2319 if (!cssRegionsEnabled())
2321 return parseFlowThread(propId, important);
2322 case CSSPropertyWebkitFlowFrom:
2323 if (!cssRegionsEnabled())
2325 return parseRegionThread(propId, important);
2327 case CSSPropertyWebkitTransform:
2328 if (id == CSSValueNone)
2329 validPrimitive = true;
2331 PassRefPtr<CSSValue> val = parseTransform();
2333 addProperty(propId, val, important);
2339 case CSSPropertyWebkitTransformOrigin:
2340 case CSSPropertyWebkitTransformOriginX:
2341 case CSSPropertyWebkitTransformOriginY:
2342 case CSSPropertyWebkitTransformOriginZ: {
2343 RefPtr<CSSValue> val1;
2344 RefPtr<CSSValue> val2;
2345 RefPtr<CSSValue> val3;
2346 CSSPropertyID propId1, propId2, propId3;
2347 if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
2348 addProperty(propId1, val1.release(), important);
2350 addProperty(propId2, val2.release(), important);
2352 addProperty(propId3, val3.release(), important);
2357 case CSSPropertyWebkitPerspective:
2358 if (id == CSSValueNone)
2359 validPrimitive = true;
2361 // Accepting valueless numbers is a quirk of the -webkit prefixed version of the property.
2362 if (validUnit(value, FNumber | FLength | FNonNeg)) {
2363 RefPtr<CSSValue> val = createPrimitiveNumericValue(value);
2365 addProperty(propId, val.release(), important);
2372 case CSSPropertyWebkitPerspectiveOrigin:
2373 case CSSPropertyWebkitPerspectiveOriginX:
2374 case CSSPropertyWebkitPerspectiveOriginY: {
2375 RefPtr<CSSValue> val1;
2376 RefPtr<CSSValue> val2;
2377 CSSPropertyID propId1, propId2;
2378 if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
2379 addProperty(propId1, val1.release(), important);
2381 addProperty(propId2, val2.release(), important);
2386 case CSSPropertyWebkitAnimationDelay:
2387 case CSSPropertyWebkitAnimationDirection:
2388 case CSSPropertyWebkitAnimationDuration:
2389 case CSSPropertyWebkitAnimationFillMode:
2390 case CSSPropertyWebkitAnimationName:
2391 case CSSPropertyWebkitAnimationPlayState:
2392 case CSSPropertyWebkitAnimationIterationCount:
2393 case CSSPropertyWebkitAnimationTimingFunction:
2394 case CSSPropertyWebkitTransitionDelay:
2395 case CSSPropertyWebkitTransitionDuration:
2396 case CSSPropertyWebkitTransitionTimingFunction:
2397 case CSSPropertyWebkitTransitionProperty: {
2398 RefPtr<CSSValue> val;
2399 if (parseAnimationProperty(propId, val)) {
2400 addProperty(propId, val.release(), important);
2406 case CSSPropertyWebkitGridColumns:
2407 case CSSPropertyWebkitGridRows:
2408 if (!cssGridLayoutEnabled())
2410 return parseGridTrackList(propId, important);
2412 case CSSPropertyWebkitGridColumn:
2413 case CSSPropertyWebkitGridRow:
2414 if (!cssGridLayoutEnabled())
2416 validPrimitive = id == CSSValueAuto || validUnit(value, FInteger);
2419 case CSSPropertyWebkitMarginCollapse: {
2421 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2422 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important))
2424 CSSValue* value = m_parsedProperties.last().value();
2425 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
2428 else if (num == 2) {
2429 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2430 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important) || !parseValue(webkitMarginCollapseShorthand().properties()[1], important))
2436 case CSSPropertyTextLineThroughWidth:
2437 case CSSPropertyTextOverlineWidth:
2438 case CSSPropertyTextUnderlineWidth:
2439 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
2440 id == CSSValueMedium || id == CSSValueThick)
2441 validPrimitive = true;
2443 validPrimitive = !id && validUnit(value, FNumber | FLength | FPercent);
2445 case CSSPropertyWebkitColumnCount:
2446 if (id == CSSValueAuto)
2447 validPrimitive = true;
2449 validPrimitive = !id && validUnit(value, FInteger | FNonNeg, CSSQuirksMode);
2451 case CSSPropertyWebkitColumnGap: // normal | <length>
2452 if (id == CSSValueNormal)
2453 validPrimitive = true;
2455 validPrimitive = validUnit(value, FLength | FNonNeg);
2457 case CSSPropertyWebkitColumnAxis:
2458 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto)
2459 validPrimitive = true;
2461 case CSSPropertyWebkitColumnProgression:
2462 if (id == CSSValueNormal || id == CSSValueReverse)
2463 validPrimitive = true;
2465 case CSSPropertyWebkitColumnSpan: // all | 1
2466 if (id == CSSValueAll)
2467 validPrimitive = true;
2469 validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValue == 1;
2471 case CSSPropertyWebkitColumnWidth: // auto | <length>
2472 if (id == CSSValueAuto)
2473 validPrimitive = true;
2474 else // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property.
2475 validPrimitive = validUnit(value, FLength, CSSStrictMode);
2477 // End of CSS3 properties
2479 // Apple specific properties. These will never be standardized and are purely to
2480 // support custom WebKit-based Apple applications.
2481 case CSSPropertyWebkitLineClamp:
2482 // When specifying number of lines, don't allow 0 as a valid value
2483 // When specifying either type of unit, require non-negative integers
2484 validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTAGE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, CSSQuirksMode));
2487 case CSSPropertyWebkitFontSizeDelta: // <length>
2488 validPrimitive = validUnit(value, FLength);
2491 case CSSPropertyWebkitHighlight:
2492 if (id == CSSValueNone || value->unit == CSSPrimitiveValue::CSS_STRING)
2493 validPrimitive = true;
2496 case CSSPropertyWebkitHyphenateCharacter:
2497 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
2498 validPrimitive = true;
2501 case CSSPropertyWebkitHyphenateLimitBefore:
2502 case CSSPropertyWebkitHyphenateLimitAfter:
2503 if (id == CSSValueAuto || validUnit(value, FInteger | FNonNeg, CSSStrictMode))
2504 validPrimitive = true;
2507 case CSSPropertyWebkitHyphenateLimitLines:
2508 if (id == CSSValueNoLimit || validUnit(value, FInteger | FNonNeg, CSSStrictMode))
2509 validPrimitive = true;
2512 case CSSPropertyWebkitLineGrid:
2513 if (id == CSSValueNone)
2514 validPrimitive = true;
2515 else if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
2516 String lineGridValue = String(value->string);
2517 if (!lineGridValue.isEmpty()) {
2518 addProperty(propId, cssValuePool().createValue(lineGridValue, CSSPrimitiveValue::CSS_STRING), important);
2523 case CSSPropertyWebkitLocale:
2524 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
2525 validPrimitive = true;
2528 #if ENABLE(DASHBOARD_SUPPORT)
2529 case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region>
2530 if (value->unit == CSSParserValue::Function || id == CSSValueNone)
2531 return parseDashboardRegions(propId, important);
2534 // End Apple-specific properties
2536 #if ENABLE(TOUCH_EVENTS)
2537 case CSSPropertyWebkitTapHighlightColor:
2538 if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu
2539 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
2540 validPrimitive = true;
2542 parsedValue = parseColor();
2544 m_valueList->next();
2549 /* shorthand properties */
2550 case CSSPropertyBackground: {
2551 // Position must come before color in this array because a plain old "0" is a legal color
2552 // in quirks mode but it's usually the X coordinate of a position.
2553 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
2554 CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin,
2555 CSSPropertyBackgroundClip, CSSPropertyBackgroundColor, CSSPropertyBackgroundSize };
2556 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
2558 case CSSPropertyWebkitMask: {
2559 const CSSPropertyID properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskRepeat,
2560 CSSPropertyWebkitMaskAttachment, CSSPropertyWebkitMaskPosition,
2561 CSSPropertyWebkitMaskOrigin, CSSPropertyWebkitMaskClip };
2562 return parseFillShorthand(propId, properties, 6, important);
2564 case CSSPropertyBorder:
2565 // [ 'border-width' || 'border-style' || <color> ] | inherit
2567 if (parseShorthand(propId, borderAbridgedShorthand(), important)) {
2568 // The CSS3 Borders and Backgrounds specification says that border also resets border-image. It's as
2569 // though a value of none was specified for the image.
2570 addProperty(CSSPropertyBorderImage, cssValuePool().createImplicitInitialValue(), important);
2575 case CSSPropertyBorderTop:
2576 // [ 'border-top-width' || 'border-style' || <color> ] | inherit
2577 return parseShorthand(propId, borderTopShorthand(), important);
2578 case CSSPropertyBorderRight:
2579 // [ 'border-right-width' || 'border-style' || <color> ] | inherit
2580 return parseShorthand(propId, borderRightShorthand(), important);
2581 case CSSPropertyBorderBottom:
2582 // [ 'border-bottom-width' || 'border-style' || <color> ] | inherit
2583 return parseShorthand(propId, borderBottomShorthand(), important);
2584 case CSSPropertyBorderLeft:
2585 // [ 'border-left-width' || 'border-style' || <color> ] | inherit
2586 return parseShorthand(propId, borderLeftShorthand(), important);
2587 case CSSPropertyWebkitBorderStart:
2588 return parseShorthand(propId, webkitBorderStartShorthand(), important);
2589 case CSSPropertyWebkitBorderEnd:
2590 return parseShorthand(propId, webkitBorderEndShorthand(), important);
2591 case CSSPropertyWebkitBorderBefore:
2592 return parseShorthand(propId, webkitBorderBeforeShorthand(), important);
2593 case CSSPropertyWebkitBorderAfter:
2594 return parseShorthand(propId, webkitBorderAfterShorthand(), important);
2595 case CSSPropertyOutline:
2596 // [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit
2597 return parseShorthand(propId, outlineShorthand(), important);
2598 case CSSPropertyBorderColor:
2599 // <color>{1,4} | inherit
2600 return parse4Values(propId, borderColorShorthand().properties(), important);
2601 case CSSPropertyBorderWidth:
2602 // <border-width>{1,4} | inherit
2603 return parse4Values(propId, borderWidthShorthand().properties(), important);
2604 case CSSPropertyBorderStyle:
2605 // <border-style>{1,4} | inherit
2606 return parse4Values(propId, borderStyleShorthand().properties(), important);
2607 case CSSPropertyMargin:
2608 // <margin-width>{1,4} | inherit
2609 return parse4Values(propId, marginShorthand().properties(), important);
2610 case CSSPropertyPadding:
2611 // <padding-width>{1,4} | inherit
2612 return parse4Values(propId, paddingShorthand().properties(), important);
2613 #if ENABLE(CSS3_FLEXBOX)
2614 case CSSPropertyWebkitFlexFlow:
2615 return parseShorthand(propId, webkitFlexFlowShorthand(), important);
2617 case CSSPropertyFont:
2618 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
2619 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
2620 if (id >= CSSValueCaption && id <= CSSValueStatusBar)
2621 validPrimitive = true;
2623 return parseFont(important);
2625 case CSSPropertyListStyle:
2626 return parseShorthand(propId, listStyleShorthand(), important);
2627 case CSSPropertyWebkitColumns:
2628 return parseShorthand(propId, webkitColumnsShorthand(), important);
2629 case CSSPropertyWebkitColumnRule:
2630 return parseShorthand(propId, webkitColumnRuleShorthand(), important);
2631 case CSSPropertyWebkitTextStroke:
2632 return parseShorthand(propId, webkitTextStrokeShorthand(), important);
2633 case CSSPropertyWebkitAnimation:
2634 return parseAnimationShorthand(important);
2635 case CSSPropertyWebkitTransition:
2636 return parseTransitionShorthand(important);
2637 case CSSPropertyInvalid:
2639 case CSSPropertyPage:
2640 return parsePage(propId, important);
2641 case CSSPropertyFontStretch:
2642 case CSSPropertyTextLineThrough:
2643 case CSSPropertyTextOverline:
2644 case CSSPropertyTextUnderline:
2646 // CSS Text Layout Module Level 3: Vertical writing support
2647 case CSSPropertyWebkitTextEmphasis:
2648 return parseShorthand(propId, webkitTextEmphasisShorthand(), important);
2650 case CSSPropertyWebkitTextEmphasisStyle:
2651 return parseTextEmphasisStyle(important);
2653 case CSSPropertyWebkitTextOrientation:
2654 // FIXME: For now just support upright and vertical-right.
2655 if (id == CSSValueVerticalRight || id == CSSValueUpright)
2656 validPrimitive = true;
2659 case CSSPropertyWebkitLineBoxContain:
2660 if (id == CSSValueNone)
2661 validPrimitive = true;
2663 return parseLineBoxContain(important);
2665 case CSSPropertyWebkitFontFeatureSettings:
2666 if (id == CSSValueNormal)
2667 validPrimitive = true;
2669 return parseFontFeatureSettings(important);
2672 case CSSPropertyWebkitFontVariantLigatures:
2673 if (id == CSSValueNormal)
2674 validPrimitive = true;
2676 return parseFontVariantLigatures(important);
2678 #if ENABLE(CSS_EXCLUSIONS)
2679 case CSSPropertyWebkitShapeInside:
2680 case CSSPropertyWebkitShapeOutside:
2681 if (!RuntimeEnabledFeatures::cssExclusionsEnabled())
2683 if (id == CSSValueAuto)
2684 validPrimitive = true;
2685 else if (value->unit == CSSParserValue::Function)
2686 return parseExclusionShape((propId == CSSPropertyWebkitShapeInside), important);
2688 case CSSPropertyWebkitWrapMargin:
2689 case CSSPropertyWebkitWrapPadding:
2690 validPrimitive = (RuntimeEnabledFeatures::cssExclusionsEnabled() && !id && validUnit(value, FLength | FNonNeg));
2692 case CSSPropertyWebkitWrap:
2693 return RuntimeEnabledFeatures::cssExclusionsEnabled() && parseShorthand(propId, webkitWrapShorthand(), important);
2695 #if ENABLE(CSS_IMAGE_ORIENTATION)
2696 case CSSPropertyImageOrientation:
2697 validPrimitive = !id && validUnit(value, FAngle);
2700 #if ENABLE(CSS_IMAGE_RESOLUTION)
2701 case CSSPropertyImageResolution:
2702 parsedValue = parseImageResolution(m_valueList.get());
2705 m_valueList->next();
2708 case CSSPropertyBorderBottomStyle:
2709 case CSSPropertyBorderCollapse:
2710 case CSSPropertyBorderLeftStyle:
2711 case CSSPropertyBorderRightStyle:
2712 case CSSPropertyBorderTopStyle:
2713 case CSSPropertyBoxSizing:
2714 case CSSPropertyCaptionSide:
2715 case CSSPropertyClear:
2716 case CSSPropertyDirection:
2717 case CSSPropertyDisplay:
2718 case CSSPropertyEmptyCells:
2719 case CSSPropertyFloat:
2720 case CSSPropertyFontStyle:
2721 case CSSPropertyImageRendering:
2722 case CSSPropertyListStylePosition:
2723 case CSSPropertyListStyleType:
2724 case CSSPropertyOutlineStyle:
2725 case CSSPropertyOverflowX:
2726 case CSSPropertyOverflowY:
2727 case CSSPropertyPageBreakAfter:
2728 case CSSPropertyPageBreakBefore:
2729 case CSSPropertyPageBreakInside:
2730 case CSSPropertyPointerEvents:
2731 case CSSPropertyPosition:
2732 case CSSPropertyResize:
2733 case CSSPropertySpeak:
2734 case CSSPropertyTableLayout:
2735 case CSSPropertyTextLineThroughMode:
2736 case CSSPropertyTextLineThroughStyle:
2737 case CSSPropertyTextOverflow:
2738 case CSSPropertyTextOverlineMode:
2739 case CSSPropertyTextOverlineStyle:
2740 case CSSPropertyTextRendering:
2741 case CSSPropertyTextTransform:
2742 case CSSPropertyTextUnderlineMode:
2743 case CSSPropertyTextUnderlineStyle:
2744 #if ENABLE(CSS_VARIABLES)
2745 case CSSPropertyVariable:
2747 case CSSPropertyVisibility:
2748 case CSSPropertyWebkitAppearance:
2749 case CSSPropertyWebkitBackfaceVisibility:
2750 case CSSPropertyWebkitBorderAfterStyle:
2751 case CSSPropertyWebkitBorderBeforeStyle:
2752 case CSSPropertyWebkitBorderEndStyle:
2753 case CSSPropertyWebkitBorderFit:
2754 case CSSPropertyWebkitBorderStartStyle:
2755 case CSSPropertyWebkitBoxAlign:
2756 #if ENABLE(CSS_BOX_DECORATION_BREAK)
2757 case CSSPropertyWebkitBoxDecorationBreak:
2759 case CSSPropertyWebkitBoxDirection:
2760 case CSSPropertyWebkitBoxLines:
2761 case CSSPropertyWebkitBoxOrient:
2762 case CSSPropertyWebkitBoxPack:
2763 case CSSPropertyWebkitColorCorrection:
2764 case CSSPropertyWebkitColumnBreakAfter:
2765 case CSSPropertyWebkitColumnBreakBefore:
2766 case CSSPropertyWebkitColumnBreakInside:
2767 case CSSPropertyWebkitColumnRuleStyle:
2768 #if ENABLE(CSS3_FLEXBOX)
2769 case CSSPropertyWebkitAlignContent:
2770 case CSSPropertyWebkitAlignItems:
2771 case CSSPropertyWebkitAlignSelf:
2772 case CSSPropertyWebkitFlexDirection:
2773 case CSSPropertyWebkitFlexWrap:
2774 case CSSPropertyWebkitJustifyContent:
2776 case CSSPropertyWebkitFontKerning:
2777 case CSSPropertyWebkitFontSmoothing:
2778 case CSSPropertyWebkitHyphens:
2779 case CSSPropertyWebkitLineAlign:
2780 case CSSPropertyWebkitLineBreak:
2781 case CSSPropertyWebkitLineSnap:
2782 case CSSPropertyWebkitMarginAfterCollapse:
2783 case CSSPropertyWebkitMarginBeforeCollapse:
2784 case CSSPropertyWebkitMarginBottomCollapse:
2785 case CSSPropertyWebkitMarginTopCollapse:
2786 case CSSPropertyWebkitMarqueeDirection:
2787 case CSSPropertyWebkitMarqueeStyle:
2788 case CSSPropertyWebkitNbspMode:
2789 #if ENABLE(OVERFLOW_SCROLLING)
2790 case CSSPropertyWebkitOverflowScrolling:
2792 case CSSPropertyWebkitPrintColorAdjust:
2793 #if ENABLE(CSS_REGIONS)
2794 case CSSPropertyWebkitRegionBreakAfter:
2795 case CSSPropertyWebkitRegionBreakBefore:
2796 case CSSPropertyWebkitRegionBreakInside:
2797 case CSSPropertyWebkitRegionOverflow:
2799 case CSSPropertyWebkitRtlOrdering:
2800 case CSSPropertyWebkitTextCombine:
2801 case CSSPropertyWebkitTextEmphasisPosition:
2802 case CSSPropertyWebkitTextSecurity:
2803 case CSSPropertyWebkitTextSizeAdjust:
2804 case CSSPropertyWebkitTransformStyle:
2805 case CSSPropertyWebkitUserDrag:
2806 case CSSPropertyWebkitUserModify:
2807 case CSSPropertyWebkitUserSelect:
2808 #if ENABLE(CSS_EXCLUSIONS)
2809 case CSSPropertyWebkitWrapFlow:
2810 case CSSPropertyWebkitWrapThrough:
2812 case CSSPropertyWebkitWritingMode:
2813 case CSSPropertyWhiteSpace:
2814 case CSSPropertyWordBreak:
2815 case CSSPropertyWordWrap:
2816 // These properties should be handled before in isValidKeywordPropertyAndValue().
2817 ASSERT_NOT_REACHED();
2821 return parseSVGValue(propId, important);
2825 if (validPrimitive) {
2826 parsedValue = parseValidPrimitive(id, value);
2827 m_valueList->next();
2829 ASSERT(!m_parsedCalculation);
2831 if (!m_valueList->current() || inShorthand()) {
2832 addProperty(propId, parsedValue.release(), important);
2839 void CSSParser::addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
2842 if (lval->isValueList())
2843 static_cast<CSSValueList*>(lval.get())->append(rval);
2845 PassRefPtr<CSSValue> oldlVal(lval.release());
2846 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2847 list->append(oldlVal);
2856 static bool parseBackgroundClip(CSSParserValue* parserValue, RefPtr<CSSValue>& cssValue)
2858 if (parserValue->id == CSSValueBorderBox || parserValue->id == CSSValuePaddingBox
2859 || parserValue->id == CSSValueContentBox || parserValue->id == CSSValueWebkitText) {
2860 cssValue = cssValuePool().createIdentifierValue(parserValue->id);
2866 const int cMaxFillProperties = 9;
2868 bool CSSParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* properties, int numProperties, bool important)
2870 ASSERT(numProperties <= cMaxFillProperties);
2871 if (numProperties > cMaxFillProperties)
2874 ShorthandScope scope(this, propId);
2876 bool parsedProperty[cMaxFillProperties] = { false };
2877 RefPtr<CSSValue> values[cMaxFillProperties];
2878 RefPtr<CSSValue> clipValue;
2879 RefPtr<CSSValue> positionYValue;
2880 RefPtr<CSSValue> repeatYValue;
2881 bool foundClip = false;
2883 bool foundBackgroundPositionCSSProperty = false;
2885 while (m_valueList->current()) {
2886 CSSParserValue* val = m_valueList->current();
2887 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
2888 // We hit the end. Fill in all remaining values with the initial value.
2889 m_valueList->next();
2890 for (i = 0; i < numProperties; ++i) {
2891 if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i])
2892 // Color is not allowed except as the last item in a list for backgrounds.
2893 // Reject the entire property.
2896 if (!parsedProperty[i] && properties[i] != CSSPropertyBackgroundColor) {
2897 addFillValue(values[i], cssValuePool().createImplicitInitialValue());
2898 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
2899 addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
2900 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
2901 addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
2902 if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) {
2903 // If background-origin wasn't present, then reset background-clip also.
2904 addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
2907 parsedProperty[i] = false;
2909 if (!m_valueList->current())
2913 bool backgroundSizeCSSPropertyExpected = false;
2914 if ((val->unit == CSSParserValue::Operator && val->iValue == '/') && foundBackgroundPositionCSSProperty) {
2915 backgroundSizeCSSPropertyExpected = true;
2916 m_valueList->next();
2919 foundBackgroundPositionCSSProperty = false;
2921 for (i = 0; !found && i < numProperties; ++i) {
2923 if (backgroundSizeCSSPropertyExpected && properties[i] != CSSPropertyBackgroundSize)
2925 if (!backgroundSizeCSSPropertyExpected && properties[i] == CSSPropertyBackgroundSize)
2928 if (!parsedProperty[i]) {
2929 RefPtr<CSSValue> val1;
2930 RefPtr<CSSValue> val2;
2931 CSSPropertyID propId1, propId2;
2932 CSSParserValue* parserValue = m_valueList->current();
2933 if (parseFillProperty(properties[i], propId1, propId2, val1, val2)) {
2934 parsedProperty[i] = found = true;
2935 addFillValue(values[i], val1.release());
2936 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
2937 addFillValue(positionYValue, val2.release());
2938 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
2939 addFillValue(repeatYValue, val2.release());
2940 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
2941 // Reparse the value as a clip, and see if we succeed.
2942 if (parseBackgroundClip(parserValue, val1))
2943 addFillValue(clipValue, val1.release()); // The property parsed successfully.
2945 addFillValue(clipValue, cssValuePool().createImplicitInitialValue()); // Some value was used for origin that is not supported by clip. Just reset clip instead.
2947 if (properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) {
2949 addFillValue(clipValue, val1.release());
2952 if (properties[i] == CSSPropertyBackgroundPosition)
2953 foundBackgroundPositionCSSProperty = true;
2958 // if we didn't find at least one match, this is an
2959 // invalid shorthand and we have to ignore it
2964 // Now add all of the properties we found.
2965 for (i = 0; i < numProperties; i++) {
2966 // Fill in any remaining properties with the initial value.
2967 if (!parsedProperty[i]) {
2968 addFillValue(values[i], cssValuePool().createImplicitInitialValue());
2969 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
2970 addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
2971 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
2972 addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
2973 if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin)) {
2974 // If background-origin wasn't present, then reset background-clip also.
2975 addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
2978 if (properties[i] == CSSPropertyBackgroundPosition) {
2979 addProperty(CSSPropertyBackgroundPositionX, values[i].release(), important);
2980 // it's OK to call positionYValue.release() since we only see CSSPropertyBackgroundPosition once
2981 addProperty(CSSPropertyBackgroundPositionY, positionYValue.release(), important);
2982 } else if (properties[i] == CSSPropertyWebkitMaskPosition) {
2983 addProperty(CSSPropertyWebkitMaskPositionX, values[i].release(), important);
2984 // it's OK to call positionYValue.release() since we only see CSSPropertyWebkitMaskPosition once
2985 addProperty(CSSPropertyWebkitMaskPositionY, positionYValue.release(), important);
2986 } else if (properties[i] == CSSPropertyBackgroundRepeat) {
2987 addProperty(CSSPropertyBackgroundRepeatX, values[i].release(), important);
2988 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
2989 addProperty(CSSPropertyBackgroundRepeatY, repeatYValue.release(), important);
2990 } else if (properties[i] == CSSPropertyWebkitMaskRepeat) {
2991 addProperty(CSSPropertyWebkitMaskRepeatX, values[i].release(), important);
2992 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
2993 addProperty(CSSPropertyWebkitMaskRepeatY, repeatYValue.release(), important);
2994 } else if ((properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) && !foundClip)
2995 // Value is already set while updating origin
2998 addProperty(properties[i], values[i].release(), important);
3000 // Add in clip values when we hit the corresponding origin property.
3001 if (properties[i] == CSSPropertyBackgroundOrigin && !foundClip)
3002 addProperty(CSSPropertyBackgroundClip, clipValue.release(), important);
3003 else if (properties[i] == CSSPropertyWebkitMaskOrigin && !foundClip)
3004 addProperty(CSSPropertyWebkitMaskClip, clipValue.release(), important);
3010 #if ENABLE(CSS_VARIABLES)
3011 bool CSSParser::cssVariablesEnabled() const
3013 return m_context.isCSSVariablesEnabled;
3016 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr<CSSParserValueList> value, bool important)
3018 ASSERT(name.length > 12);
3019 AtomicString variableName = String(name.characters + 12, name.length - 12);
3021 StringBuilder builder;
3022 for (unsigned i = 0, size = value->size(); i < size; i++) {
3024 builder.append(' ');
3025 builder.append(value->valueAt(i)->createCSSValue()->cssText());
3027 addProperty(CSSPropertyVariable, CSSVariableValue::create(variableName, builder.toString()), important, false);
3031 void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
3034 if (lval->isValueList())
3035 static_cast<CSSValueList*>(lval.get())->append(rval);
3037 PassRefPtr<CSSValue> oldVal(lval.release());
3038 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3039 list->append(oldVal);
3048 bool CSSParser::parseAnimationShorthand(bool important)
3050 // When we parse the animation shorthand we need to look for animation-name
3051 // last because otherwise it might match against the keywords for fill mode,
3052 // timing functions and infinite iteration. This means that animation names
3053 // that are the same as keywords (e.g. 'forwards') won't always match in the
3054 // shorthand. In that case they should be using longhands (or reconsidering
3055 // their approach). This is covered by the animations spec bug:
3056 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=14790
3057 // And in the spec (editor's draft) at:
3058 // http://dev.w3.org/csswg/css3-animations/#animation-shorthand-property
3060 static const CSSPropertyID animationProperties[] = {
3061 CSSPropertyWebkitAnimationDuration,
3062 CSSPropertyWebkitAnimationTimingFunction,
3063 CSSPropertyWebkitAnimationDelay,
3064 CSSPropertyWebkitAnimationIterationCount,
3065 CSSPropertyWebkitAnimationDirection,
3066 CSSPropertyWebkitAnimationFillMode,
3067 CSSPropertyWebkitAnimationName
3069 const unsigned numProperties = 7;
3071 // The list of properties in the shorthand should be the same
3072 // length as the list we have here, even though they are
3073 // a different order.
3074 ASSERT(numProperties == webkitAnimationShorthand().length());
3076 ShorthandScope scope(this, CSSPropertyWebkitAnimation);
3078 bool parsedProperty[numProperties] = { false };
3079 RefPtr<CSSValue> values[numProperties];
3082 while (m_valueList->current()) {
3083 CSSParserValue* val = m_valueList->current();
3084 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3085 // We hit the end. Fill in all remaining values with the initial value.
3086 m_valueList->next();
3087 for (i = 0; i < numProperties; ++i) {
3088 if (!parsedProperty[i])
3089 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3090 parsedProperty[i] = false;
3092 if (!m_valueList->current())
3097 for (i = 0; i < numProperties; ++i) {
3098 if (!parsedProperty[i]) {
3099 RefPtr<CSSValue> val;
3100 if (parseAnimationProperty(animationProperties[i], val)) {
3101 parsedProperty[i] = found = true;
3102 addAnimationValue(values[i], val.release());
3108 // if we didn't find at least one match, this is an
3109 // invalid shorthand and we have to ignore it
3114 for (i = 0; i < numProperties; ++i) {
3115 // If we didn't find the property, set an intial value.
3116 if (!parsedProperty[i])
3117 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3119 addProperty(animationProperties[i], values[i].release(), important);
3125 bool CSSParser::parseTransitionShorthand(bool important)
3127 const unsigned numProperties = webkitTransitionShorthand().length();
3129 ShorthandScope scope(this, CSSPropertyWebkitTransition);
3131 bool parsedProperty[] = { false, false, false, false };
3132 RefPtr<CSSValue> values[4];
3135 while (m_valueList->current()) {
3136 CSSParserValue* val = m_valueList->current();
3137 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3138 // We hit the end. Fill in all remaining values with the initial value.
3139 m_valueList->next();
3140 for (i = 0; i < numProperties; ++i) {
3141 if (!parsedProperty[i])
3142 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3143 parsedProperty[i] = false;
3145 if (!m_valueList->current())
3150 for (i = 0; !found && i < numProperties; ++i) {
3151 if (!parsedProperty[i]) {
3152 RefPtr<CSSValue> val;
3153 if (parseAnimationProperty(webkitTransitionShorthand().properties()[i], val)) {
3154 parsedProperty[i] = found = true;
3155 addAnimationValue(values[i], val.release());
3160 // if we didn't find at least one match, this is an
3161 // invalid shorthand and we have to ignore it
3166 // Fill in any remaining properties with the initial value.
3167 for (i = 0; i < numProperties; ++i) {
3168 if (!parsedProperty[i])
3169 addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
3172 // Now add all of the properties we found.
3173 for (i = 0; i < numProperties; i++)
3174 addProperty(webkitTransitionShorthand().properties()[i], values[i].release(), important);
3179 bool CSSParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthand& shorthand, bool important)
3181 // We try to match as many properties as possible
3182 // We set up an array of booleans to mark which property has been found,
3183 // and we try to search for properties until it makes no longer any sense.
3184 ShorthandScope scope(this, propId);
3187 unsigned propertiesParsed = 0;
3188 bool propertyFound[6]= { false, false, false, false, false, false }; // 6 is enough size.
3190 while (m_valueList->current()) {
3192 for (unsigned propIndex = 0; !found && propIndex < shorthand.length(); ++propIndex) {
3193 if (!propertyFound[propIndex] && parseValue(shorthand.properties()[propIndex], important)) {
3194 propertyFound[propIndex] = found = true;
3199 // if we didn't find at least one match, this is an
3200 // invalid shorthand and we have to ignore it
3205 if (propertiesParsed == shorthand.length())
3208 // Fill in any remaining properties with the initial value.
3209 ImplicitScope implicitScope(this, PropertyImplicit);
3210 const StylePropertyShorthand* const* const propertiesForInitialization = shorthand.propertiesForInitialization();
3211 for (unsigned i = 0; i < shorthand.length(); ++i) {
3212 if (propertyFound[i])
3215 if (propertiesForInitialization) {
3216 const StylePropertyShorthand& initProperties = *(propertiesForInitialization[i]);
3217 for (unsigned propIndex = 0; propIndex < initProperties.length(); ++propIndex)
3218 addProperty(initProperties.properties()[propIndex], cssValuePool().createImplicitInitialValue(), important);
3220 addProperty(shorthand.properties()[i], cssValuePool().createImplicitInitialValue(), important);
3226 bool CSSParser::parse4Values(CSSPropertyID propId, const CSSPropertyID *properties, bool important)
3228 /* From the CSS 2 specs, 8.3
3229 * If there is only one value, it applies to all sides. If there are two values, the top and
3230 * bottom margins are set to the first value and the right and left margins are set to the second.
3231 * If there are three values, the top is set to the first value, the left and right are set to the
3232 * second, and the bottom is set to the third. If there are four values, they apply to the top,
3233 * right, bottom, and left, respectively.
3236 int num = inShorthand() ? 1 : m_valueList->size();
3238 ShorthandScope scope(this, propId);
3240 // the order is top, right, bottom, left
3243 if (!parseValue(properties[0], important))
3245 CSSValue *value = m_parsedProperties.last().value();
3246 ImplicitScope implicitScope(this, PropertyImplicit);
3247 addProperty(properties[1], value, important);
3248 addProperty(properties[2], value, important);
3249 addProperty(properties[3], value, important);
3253 if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
3255 CSSValue *value = m_parsedProperties[m_parsedProperties.size() - 2].value();
3256 ImplicitScope implicitScope(this, PropertyImplicit);
3257 addProperty(properties[2], value, important);
3258 value = m_parsedProperties[m_parsedProperties.size() - 2].value();
3259 addProperty(properties[3], value, important);
3263 if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || !parseValue(properties[2], important))
3265 CSSValue *value = m_parsedProperties[m_parsedProperties.size() - 2].value();
3266 ImplicitScope implicitScope(this, PropertyImplicit);
3267 addProperty(properties[3], value, important);
3271 if (!parseValue(properties[0], important) || !parseValue(properties[1], important) ||
3272 !parseValue(properties[2], important) || !parseValue(properties[3], important))
3284 // auto | <identifier>
3285 bool CSSParser::parsePage(CSSPropertyID propId, bool important)
3287 ASSERT(propId == CSSPropertyPage);
3289 if (m_valueList->size() != 1)
3292 CSSParserValue* value = m_valueList->current();
3296 if (value->id == CSSValueAuto) {
3297 addProperty(propId, cssValuePool().createIdentifierValue(value->id), important);
3299 } else if (value->id == 0 && value->unit == CSSPrimitiveValue::CSS_IDENT) {
3300 addProperty(propId, createPrimitiveStringValue(value), important);
3306 // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
3307 bool CSSParser::parseSize(CSSPropertyID propId, bool important)
3309 ASSERT(propId == CSSPropertySize);
3311 if (m_valueList->size() > 2)
3314 CSSParserValue* value = m_valueList->current();
3318 RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
3321 SizeParameterType paramType = parseSizeParameter(parsedValues.get(), value, None);
3322 if (paramType == None)
3325 // Second parameter, if any.
3326 value = m_valueList->next();
3328 paramType = parseSizeParameter(parsedValues.get(), value, paramType);
3329 if (paramType == None)
3333 addProperty(propId, parsedValues.release(), important);
3337 CSSParser::SizeParameterType CSSParser::parseSizeParameter(CSSValueList* parsedValues, CSSParserValue* value, SizeParameterType prevParamType)
3339 switch (value->id) {
3341 if (prevParamType == None) {
3342 parsedValues->append(cssValuePool().createIdentifierValue(value->id));
3346 case CSSValueLandscape:
3347 case CSSValuePortrait:
3348 if (prevParamType == None || prevParamType == PageSize) {
3349 parsedValues->append(cssValuePool().createIdentifierValue(value->id));
3358 case CSSValueLedger:
3360 case CSSValueLetter:
3361 if (prevParamType == None || prevParamType == Orientation) {
3362 // Normalize to Page Size then Orientation order by prepending.
3363 // This is not specified by the CSS3 Paged Media specification, but for simpler processing later (StyleResolver::applyPageSizeProperty).
3364 parsedValues->prepend(cssValuePool().createIdentifierValue(value->id));
3369 if (validUnit(value, FLength | FNonNeg) && (prevParamType == None || prevParamType == Length)) {
3370 parsedValues->append(createPrimitiveNumericValue(value));
3379 // [ <string> <string> ]+ | inherit | none
3380 // inherit and none are handled in parseValue.
3381 bool CSSParser::parseQuotes(CSSPropertyID propId, bool important)
3383 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
3384 while (CSSParserValue* val = m_valueList->current()) {
3385 RefPtr<CSSValue> parsedValue;
3386 if (val->unit == CSSPrimitiveValue::CSS_STRING)
3387 parsedValue = CSSPrimitiveValue::create(val->string, CSSPrimitiveValue::CSS_STRING);
3390 values->append(parsedValue.release());
3391 m_valueList->next();
3393 if (values->length()) {
3394 addProperty(propId, values.release(), important);
3395 m_valueList->next();
3401 // [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
3402 // in CSS 2.1 this got somewhat reduced:
3403 // [ <string> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
3404 bool CSSParser::parseContent(CSSPropertyID propId, bool important)
3406 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
3408 while (CSSParserValue* val = m_valueList->current()) {
3409 RefPtr<CSSValue> parsedValue;
3410 if (val->unit == CSSPrimitiveValue::CSS_URI) {
3412 parsedValue = CSSImageValue::create(completeURL(val->string));
3413 } else if (val->unit == CSSParserValue::Function) {
3414 // attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradient(...)
3415 CSSParserValueList* args = val->function->args.get();
3418 if (equalIgnoringCase(val->function->name, "attr(")) {
3419 parsedValue = parseAttr(args);
3422 } else if (equalIgnoringCase(val->function->name, "counter(")) {
3423 parsedValue = parseCounterContent(args, false);
3426 } else if (equalIgnoringCase(val->function->name, "counters(")) {
3427 parsedValue = parseCounterContent(args, true);
3430 #if ENABLE(CSS_IMAGE_SET)
3431 } else if (equalIgnoringCase(val->function->name, "-webkit-image-set(")) {
3432 parsedValue = parseImageSet(m_valueList.get());
3436 } else if (isGeneratedImageValue(val)) {
3437 if (!parseGeneratedImage(m_valueList.get(), parsedValue))
3441 } else if (val->unit == CSSPrimitiveValue::CSS_IDENT) {
3447 // FIXME: These are not yet implemented (http://bugs.webkit.org/show_bug.cgi?id=6503).
3451 case CSSValueOpenQuote:
3452 case CSSValueCloseQuote:
3453 case CSSValueNoOpenQuote:
3454 case CSSValueNoCloseQuote:
3456 case CSSValueNormal:
3457 parsedValue = cssValuePool().createIdentifierValue(val->id);
3459 } else if (val->unit == CSSPrimitiveValue::CSS_STRING) {
3460 parsedValue = createPrimitiveStringValue(val);
3464 values->append(parsedValue.release());
3465 m_valueList->next();
3468 if (values->length()) {
3469 addProperty(propId, values.release(), important);
3470 m_valueList->next();
3477 PassRefPtr<CSSValue> CSSParser::parseAttr(CSSParserValueList* args)
3479 if (args->size() != 1)
3482 CSSParserValue* a = args->current();
3484 if (a->unit != CSSPrimitiveValue::CSS_IDENT)
3487 String attrName = a->string;
3488 // CSS allows identifiers with "-" at the start, like "-webkit-mask-image".
3489 // But HTML attribute names can't have those characters, and we should not
3490 // even parse them inside attr().
3491 if (attrName[0] == '-')
3494 if (m_context.isHTMLDocument)
3495 attrName = attrName.lower();
3497 return cssValuePool().createValue(attrName, CSSPrimitiveValue::CSS_ATTR);
3500 PassRefPtr<CSSValue> CSSParser::parseBackgroundColor()
3502 int id = m_valueList->current()->id;
3503 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor ||
3504 (id >= CSSValueGrey && id < CSSValueWebkitText && inQuirksMode()))
3505 return cssValuePool().createIdentifierValue(id);
3506 return parseColor();
3509 bool CSSParser::parseFillImage(CSSParserValueList* valueList, RefPtr<CSSValue>& value)
3511 if (valueList->current()->id == CSSValueNone) {
3512 value = cssValuePool().createIdentifierValue(CSSValueNone);
3515 if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
3516 value = CSSImageValue::create(completeURL(valueList->current()->string));
3520 if (isGeneratedImageValue(valueList->current()))
3521 return parseGeneratedImage(valueList, value);
3523 #if ENABLE(CSS_IMAGE_SET)
3524 if (valueList->current()->unit == CSSParserValue::Function && equalIgnoringCase(valueList->current()->function->name, "-webkit-image-set(")) {
3525 value = parseImageSet(m_valueList.get());
3534 PassRefPtr<CSSValue> CSSParser::parseFillPositionX(CSSParserValueList* valueList)
3536 int id = valueList->current()->id;
3537 if (id == CSSValueLeft || id == CSSValueRight || id == CSSValueCenter) {
3539 if (id == CSSValueRight)
3541 else if (id == CSSValueCenter)
3543 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
3545 if (validUnit(valueList->current(), FPercent | FLength))
3546 return createPrimitiveNumericValue(valueList->current());
3550 PassRefPtr<CSSValue> CSSParser::parseFillPositionY(CSSParserValueList* valueList)
3552 int id = valueList->current()->id;
3553 if (id == CSSValueTop || id == CSSValueBottom || id == CSSValueCenter) {
3555 if (id == CSSValueBottom)
3557 else if (id == CSSValueCenter)
3559 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
3561 if (validUnit(valueList->current(), FPercent | FLength))
3562 return createPrimitiveNumericValue(valueList->current());
3566 PassRefPtr<CSSValue> CSSParser::parseFillPositionComponent(CSSParserValueList* valueList, unsigned& cumulativeFlags, FillPositionFlag& individualFlag)
3568 int id = valueList->current()->id;
3569 if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id == CSSValueBottom || id == CSSValueCenter) {
3571 if (id == CSSValueLeft || id == CSSValueRight) {
3572 if (cumulativeFlags & XFillPosition)
3574 cumulativeFlags |= XFillPosition;
3575 individualFlag = XFillPosition;
3576 if (id == CSSValueRight)
3579 else if (id == CSSValueTop || id == CSSValueBottom) {
3580 if (cumulativeFlags & YFillPosition)
3582 cumulativeFlags |= YFillPosition;
3583 individualFlag = YFillPosition;
3584 if (id == CSSValueBottom)
3586 } else if (id == CSSValueCenter) {
3587 // Center is ambiguous, so we're not sure which position we've found yet, an x or a y.
3589 cumulativeFlags |= AmbiguousFillPosition;
3590 individualFlag = AmbiguousFillPosition;
3592 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
3594 if (validUnit(valueList->current(), FPercent | FLength)) {
3595 if (!cumulativeFlags) {
3596 cumulativeFlags |= XFillPosition;
3597 individualFlag = XFillPosition;
3598 } else if (cumulativeFlags & (XFillPosition | AmbiguousFillPosition)) {
3599 cumulativeFlags |= YFillPosition;
3600 individualFlag = YFillPosition;
3602 if (m_parsedCalculation)
3603 m_parsedCalculation.release();
3606 return createPrimitiveNumericValue(valueList->current());
3611 void CSSParser::parseFillPosition(CSSParserValueList* valueList, RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2)
3613 CSSParserValue* value = valueList->current();
3615 // Parse the first value. We're just making sure that it is one of the valid keywords or a percentage/length.
3616 unsigned cumulativeFlags = 0;
3617 FillPositionFlag value1Flag = InvalidFillPosition;
3618 FillPositionFlag value2Flag = InvalidFillPosition;
3619 value1 = parseFillPositionComponent(valueList, cumulativeFlags, value1Flag);
3623 // It only takes one value for background-position to be correctly parsed if it was specified in a shorthand (since we
3624 // can assume that any other values belong to the rest of the shorthand). If we're not parsing a shorthand, though, the
3625 // value was explicitly specified for our property.
3626 value = valueList->next();
3628 // First check for the comma. If so, we are finished parsing this value or value pair.
3633 value2 = parseFillPositionComponent(valueList, cumulativeFlags, value2Flag);
3637 if (!inShorthand()) {
3645 // Only one value was specified. If that value was not a keyword, then it sets the x position, and the y position
3646 // is simply 50%. This is our default.
3647 // For keywords, the keyword was either an x-keyword (left/right), a y-keyword (top/bottom), or an ambiguous keyword (center).
3648 // For left/right/center, the default of 50% in the y is still correct.
3649 value2 = cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAGE);
3651 if (value1Flag == YFillPosition || value2Flag == XFillPosition)
3652 value1.swap(value2);
3655 void CSSParser::parseFillRepeat(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2)
3657 int id = m_valueList->current()->id;
3658 if (id == CSSValueRepeatX) {
3659 m_implicitShorthand = true;
3660 value1 = cssValuePool().createIdentifierValue(CSSValueRepeat);
3661 value2 = cssValuePool().createIdentifierValue(CSSValueNoRepeat);
3662 m_valueList->next();
3665 if (id == CSSValueRepeatY) {
3666 m_implicitShorthand = true;
3667 value1 = cssValuePool().createIdentifierValue(CSSValueNoRepeat);
3668 value2 = cssValuePool().createIdentifierValue(CSSValueRepeat);
3669 m_valueList->next();
3672 if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRound || id == CSSValueSpace)
3673 value1 = cssValuePool().createIdentifierValue(id);
3679 CSSParserValue* value = m_valueList->next();
3681 // Parse the second value if one is available
3682 if (value && !isComma(value)) {
3684 if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRound || id == CSSValueSpace) {
3685 value2 = cssValuePool().createIdentifierValue(id);
3686 m_valueList->next();
3691 // If only one value was specified, value2 is the same as value1.
3692 m_implicitShorthand = true;
3693 value2 = cssValuePool().createIdentifierValue(static_cast<CSSPrimitiveValue*>(value1.get())->getIdent());
3696 PassRefPtr<CSSValue> CSSParser::parseFillSize(CSSPropertyID propId, bool& allowComma)
3699 CSSParserValue* value = m_valueList->current();
3701 if (value->id == CSSValueContain || value->id == CSSValueCover)
3702 return cssValuePool().createIdentifierValue(value->id);
3704 RefPtr<CSSPrimitiveValue> parsedValue1;
3706 if (value->id == CSSValueAuto)
3707 parsedValue1 = cssValuePool().createIdentifierValue(CSSValueAuto);
3709 if (!validUnit(value, FLength | FPercent))
3711 parsedValue1 = createPrimitiveNumericValue(value);
3714 RefPtr<CSSPrimitiveValue> parsedValue2;
3715 if ((value = m_valueList->next())) {
3716 if (value->unit == CSSParserValue::Operator && value->iValue == ',')
3718 else if (value->id != CSSValueAuto) {
3719 if (!validUnit(value, FLength | FPercent)) {
3722 // We need to rewind the value list, so that when it is advanced we'll end up back at this value.
3723 m_valueList->previous();
3725 parsedValue2 = createPrimitiveNumericValue(value);
3727 } else if (!parsedValue2 && propId == CSSPropertyWebkitBackgroundSize) {
3728 // For backwards compatibility we set the second value to the first if it is omitted.
3729 // We only need to do this for -webkit-background-size. It should be safe to let masks match
3730 // the real property.
3731 parsedValue2 = parsedValue1;
3735 return parsedValue1;
3736 return cssValuePool().createValue(Pair::create(parsedValue1.release(), parsedValue2.release()));
3739 bool CSSParser::parseFillProperty(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2,
3740 RefPtr<CSSValue>& retValue1, RefPtr<CSSValue>& retValue2)
3742 RefPtr<CSSValueList> values;
3743 RefPtr<CSSValueList> values2;
3744 CSSParserValue* val;
3745 RefPtr<CSSValue> value;
3746 RefPtr<CSSValue> value2;
3748 bool allowComma = false;
3750 retValue1 = retValue2 = 0;
3753 if (propId == CSSPropertyBackgroundPosition) {
3754 propId1 = CSSPropertyBackgroundPositionX;
3755 propId2 = CSSPropertyBackgroundPositionY;
3756 } else if (propId == CSSPropertyWebkitMaskPosition) {
3757 propId1 = CSSPropertyWebkitMaskPositionX;
3758 propId2 = CSSPropertyWebkitMaskPositionY;
3759 } else if (propId == CSSPropertyBackgroundRepeat) {
3760 propId1 = CSSPropertyBackgroundRepeatX;
3761 propId2 = CSSPropertyBackgroundRepeatY;
3762 } else if (propId == CSSPropertyWebkitMaskRepeat) {
3763 propId1 = CSSPropertyWebkitMaskRepeatX;
3764 propId2 = CSSPropertyWebkitMaskRepeatY;
3767 while ((val = m_valueList->current())) {
3768 RefPtr<CSSValue> currValue;
3769 RefPtr<CSSValue> currValue2;
3774 m_valueList->next();
3779 case CSSPropertyBackgroundColor:
3780 currValue = parseBackgroundColor();
3782 m_valueList->next();
3784 case CSSPropertyBackgroundAttachment:
3785 case CSSPropertyWebkitMaskAttachment:
3786 if (val->id == CSSValueScroll || val->id == CSSValueFixed || val->id == CSSValueLocal) {
3787 currValue = cssValuePool().createIdentifierValue(val->id);
3788 m_valueList->next();
3791 case CSSPropertyBackgroundImage:
3792 case CSSPropertyWebkitMaskImage:
3793 if (parseFillImage(m_valueList.get(), currValue))
3794 m_valueList->next();
3796 case CSSPropertyWebkitBackgroundClip:
3797 case CSSPropertyWebkitBackgroundOrigin:
3798 case CSSPropertyWebkitMaskClip:
3799 case CSSPropertyWebkitMaskOrigin:
3800 // The first three values here are deprecated and do not apply to the version of the property that has
3801 // the -webkit- prefix removed.
3802 if (val->id == CSSValueBorder || val->id == CSSValuePadding || val->id == CSSValueContent ||
3803 val->id == CSSValueBorderBox || val->id == CSSValuePaddingBox || val->id == CSSValueContentBox ||
3804 ((propId == CSSPropertyWebkitBackgroundClip || propId == CSSPropertyWebkitMaskClip) &&
3805 (val->id == CSSValueText || val->id == CSSValueWebkitText))) {
3806 currValue = cssValuePool().createIdentifierValue(val->id);
3807 m_valueList->next();
3810 case CSSPropertyBackgroundClip:
3811 if (parseBackgroundClip(val, currValue))
3812 m_valueList->next();
3814 case CSSPropertyBackgroundOrigin:
3815 if (val->id == CSSValueBorderBox || val->id == CSSValuePaddingBox || val->id == CSSValueContentBox) {
3816 currValue = cssValuePool().createIdentifierValue(val->id);
3817 m_valueList->next();
3820 case CSSPropertyBackgroundPosition:
3821 case CSSPropertyWebkitMaskPosition:
3822 parseFillPosition(m_valueList.get(), currValue, currValue2);
3823 // parseFillPosition advances the m_valueList pointer
3825 case CSSPropertyBackgroundPositionX:
3826 case CSSPropertyWebkitMaskPositionX: {
3827 currValue = parseFillPositionX(m_valueList.get());
3829 m_valueList->next();
3832 case CSSPropertyBackgroundPositionY:
3833 case CSSPropertyWebkitMaskPositionY: {
3834 currValue = parseFillPositionY(m_valueList.get());
3836 m_valueList->next();
3839 case CSSPropertyWebkitBackgroundComposite:
3840 case CSSPropertyWebkitMaskComposite:
3841 if ((val->id >= CSSValueClear && val->id <= CSSValuePlusLighter) || val->id == CSSValueHighlight) {
3842 currValue = cssValuePool().createIdentifierValue(val->id);
3843 m_valueList->next();
3846 case CSSPropertyBackgroundRepeat:
3847 case CSSPropertyWebkitMaskRepeat:
3848 parseFillRepeat(currValue, currValue2);
3849 // parseFillRepeat advances the m_valueList pointer
3851 case CSSPropertyBackgroundSize:
3852 case CSSPropertyWebkitBackgroundSize:
3853 case CSSPropertyWebkitMaskSize: {
3854 currValue = parseFillSize(propId, allowComma);
3856 m_valueList->next();
3865 if (value && !values) {
3866 values = CSSValueList::createCommaSeparated();
3867 values->append(value.release());
3870 if (value2 && !values2) {
3871 values2 = CSSValueList::createCommaSeparated();
3872 values2->append(value2.release());
3876 values->append(currValue.release());
3878 value = currValue.release();
3881 values2->append(currValue2.release());
3883 value2 = currValue2.release();
3887 // When parsing any fill shorthand property, we let it handle building up the lists for all
3893 if (values && values->length()) {
3894 retValue1 = values.release();
3895 if (values2 && values2->length())
3896 retValue2 = values2.release();
3900 retValue1 = value.release();
3901 retValue2 = value2.release();
3907 PassRefPtr<CSSValue> CSSParser::parseAnimationDelay()
3909 CSSParserValue* value = m_valueList->current();
3910 if (validUnit(value, FTime))
3911 return createPrimitiveNumericValue(value);
3915 PassRefPtr<CSSValue> CSSParser::parseAnimationDirection()
3917 CSSParserValue* value = m_valueList->current();
3918 if (value->id == CSSValueNormal || value->id == CSSValueAlternate || value->id == CSSValueReverse || value->id == CSSValueAlternateReverse)
3919 return cssValuePool().createIdentifierValue(value->id);
3923 PassRefPtr<CSSValue> CSSParser::parseAnimationDuration()
3925 CSSParserValue* value = m_valueList->current();
3926 if (validUnit(value, FTime | FNonNeg))
3927 return createPrimitiveNumericValue(value);
3931 PassRefPtr<CSSValue> CSSParser::parseAnimationFillMode()
3933 CSSParserValue* value = m_valueList->current();
3934 if (value->id == CSSValueNone || value->id == CSSValueForwards || value->id == CSSValueBackwards || value->id == CSSValueBoth)
3935 return cssValuePool().createIdentifierValue(value->id);
3939 PassRefPtr<CSSValue> CSSParser::parseAnimationIterationCount()
3941 CSSParserValue* value = m_valueList->current();
3942 if (value->id == CSSValueInfinite)
3943 return cssValuePool().createIdentifierValue(value->id);
3944 if (validUnit(value, FNumber | FNonNeg))
3945 return createPrimitiveNumericValue(value);
3949 PassRefPtr<CSSValue> CSSParser::parseAnimationName()
3951 CSSParserValue* value = m_valueList->current();