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 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/)
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #include "CSSParser.h"
29 #include "CSSTimingFunctionValue.h"
30 #include "CSSBorderImageValue.h"
31 #include "CSSCanvasValue.h"
32 #include "CSSCharsetRule.h"
33 #include "CSSCursorImageValue.h"
34 #include "CSSHelper.h"
35 #include "CSSImageValue.h"
36 #include "CSSFontFaceRule.h"
37 #include "CSSFontFaceSrcValue.h"
38 #include "CSSGradientValue.h"
39 #include "CSSImportRule.h"
40 #include "CSSInheritedValue.h"
41 #include "CSSInitialValue.h"
42 #include "CSSMediaRule.h"
43 #include "CSSMutableStyleDeclaration.h"
44 #include "CSSPrimitiveValue.h"
45 #include "CSSProperty.h"
46 #include "CSSPropertyNames.h"
47 #include "CSSQuirkPrimitiveValue.h"
48 #include "CSSReflectValue.h"
49 #include "CSSRuleList.h"
50 #include "CSSSelector.h"
51 #include "CSSStyleRule.h"
52 #include "CSSStyleSheet.h"
53 #include "CSSUnicodeRangeValue.h"
54 #include "CSSValueKeywords.h"
55 #include "CSSValueList.h"
56 #include "CSSVariableDependentValue.h"
57 #include "CSSVariablesDeclaration.h"
58 #include "CSSVariablesRule.h"
61 #include "FloatConversion.h"
62 #include "FontFamilyValue.h"
63 #include "FontValue.h"
64 #include "MediaList.h"
65 #include "MediaQueryExp.h"
68 #include "ShadowValue.h"
69 #include "WebKitCSSKeyframeRule.h"
70 #include "WebKitCSSKeyframesRule.h"
71 #include "WebKitCSSTransformValue.h"
74 #if ENABLE(DASHBOARD_SUPPORT)
75 #include "DashboardRegion.h"
81 extern int cssyydebug;
84 extern int cssyyparse(void* parser);
89 #include "CSSPropertyNames.cpp"
90 #include "CSSValueKeywords.c"
94 static bool equal(const CSSParserString& a, const char* b)
96 for (int i = 0; i < a.length; ++i) {
99 if (a.characters[i] != b[i])
105 static bool equalIgnoringCase(const CSSParserString& a, const char* b)
107 for (int i = 0; i < a.length; ++i) {
110 ASSERT(!isASCIIUpper(b[i]));
111 if (toASCIILower(a.characters[i]) != b[i])
117 static bool hasPrefix(const char* string, unsigned length, const char* prefix)
119 for (unsigned i = 0; i < length; ++i) {
122 if (string[i] != prefix[i])
128 CSSParser::CSSParser(bool strictParsing)
129 : m_strict(strictParsing)
135 , m_parsedProperties(static_cast<CSSProperty**>(fastMalloc(32 * sizeof(CSSProperty*))))
136 , m_numParsedProperties(0)
137 , m_maxParsedProperties(32)
138 , m_inParseShorthand(0)
139 , m_currentShorthand(0)
140 , m_implicitShorthand(false)
141 , m_hasFontFaceOnlyValues(false)
142 , m_defaultNamespace(starAtom)
145 , m_floatingMediaQuery(0)
146 , m_floatingMediaQueryExp(0)
147 , m_floatingMediaQueryExpList(0)
154 CSSParser::~CSSParser()
157 fastFree(m_parsedProperties);
165 if (m_floatingMediaQueryExpList) {
166 deleteAllValues(*m_floatingMediaQueryExpList);
167 delete m_floatingMediaQueryExpList;
169 delete m_floatingMediaQueryExp;
170 delete m_floatingMediaQuery;
171 fastDeleteAllValues(m_floatingSelectors);
172 deleteAllValues(m_floatingValueLists);
173 deleteAllValues(m_floatingFunctions);
174 deleteAllValues(m_reusableSelectorVector);
177 void CSSParserString::lower()
179 // FIXME: If we need Unicode lowercasing here, then we probably want the real kind
180 // that can potentially change the length of the string rather than the character
181 // by character kind. If we don't need Unicode lowercasing, it would be good to
182 // simplify this function.
184 if (charactersAreAllASCII(characters, length)) {
185 // Fast case for all-ASCII.
186 for (int i = 0; i < length; i++)
187 characters[i] = toASCIILower(characters[i]);
189 for (int i = 0; i < length; i++)
190 characters[i] = Unicode::toLower(characters[i]);
194 void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
196 int length = string.length() + strlen(prefix) + strlen(suffix) + 2;
199 m_data = static_cast<UChar*>(fastMalloc(length * sizeof(UChar)));
200 for (unsigned i = 0; i < strlen(prefix); i++)
201 m_data[i] = prefix[i];
203 memcpy(m_data + strlen(prefix), string.characters(), string.length() * sizeof(UChar));
205 unsigned start = strlen(prefix) + string.length();
206 unsigned end = start + strlen(suffix);
207 for (unsigned i = start; i < end; i++)
208 m_data[i] = suffix[i - start];
210 m_data[length - 1] = 0;
211 m_data[length - 2] = 0;
215 yytext = yy_c_buf_p = m_data;
216 yy_hold_char = *yy_c_buf_p;
219 void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string)
221 m_styleSheet = sheet;
222 m_defaultNamespace = starAtom; // Reset the default namespace.
224 setupParser("", string, "");
229 PassRefPtr<CSSRule> CSSParser::parseRule(CSSStyleSheet* sheet, const String& string)
231 m_styleSheet = sheet;
232 setupParser("@-webkit-rule{", string, "} ");
234 return m_rule.release();
237 PassRefPtr<CSSRule> CSSParser::parseKeyframeRule(CSSStyleSheet *sheet, const String &string)
239 m_styleSheet = sheet;
240 setupParser("@-webkit-keyframe-rule{ ", string, "} ");
242 return m_keyframe.release();
245 bool CSSParser::parseValue(CSSMutableStyleDeclaration* declaration, int id, const String& string, bool important)
247 ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
248 m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
250 setupParser("@-webkit-value{", string, "} ");
253 m_important = important;
260 if (m_hasFontFaceOnlyValues)
261 deleteFontFaceOnlyValues();
262 if (m_numParsedProperties) {
264 declaration->addParsedProperties(m_parsedProperties, m_numParsedProperties);
271 // color will only be changed when string contains a valid css color, making it
272 // possible to set up a default color.
273 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
276 CSSParser parser(true);
278 // First try creating a color specified by name or the "#" syntax.
279 if (!parser.parseColor(string, color, strict)) {
280 RefPtr<CSSMutableStyleDeclaration> dummyStyleDeclaration = CSSMutableStyleDeclaration::create();
282 // Now try to create a color from the rgb() or rgba() syntax.
283 if (parser.parseColor(dummyStyleDeclaration.get(), string)) {
284 CSSValue* value = parser.m_parsedProperties[0]->value();
285 if (value->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
286 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
287 color = primitiveValue->getRGBA32Value();
296 bool CSSParser::parseColor(CSSMutableStyleDeclaration* declaration, const String& string)
298 ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
299 m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
301 setupParser("@-webkit-decls{color:", string, "} ");
305 return (m_numParsedProperties && m_parsedProperties[0]->m_id == CSSPropertyColor);
308 void CSSParser::parseSelector(const String& string, Document* doc, CSSSelectorList& selectorList)
310 RefPtr<CSSStyleSheet> dummyStyleSheet = CSSStyleSheet::create(doc);
312 m_styleSheet = dummyStyleSheet.get();
313 m_selectorListForParseSelector = &selectorList;
315 setupParser("@-webkit-selector{", string, "}");
319 m_selectorListForParseSelector = 0;
322 bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration* declaration, const String& string)
324 ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
325 m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
327 setupParser("@-webkit-decls{", string, "} ");
332 if (m_hasFontFaceOnlyValues)
333 deleteFontFaceOnlyValues();
334 if (m_numParsedProperties) {
336 declaration->addParsedProperties(m_parsedProperties, m_numParsedProperties);
343 bool CSSParser::parseMediaQuery(MediaList* queries, const String& string)
345 if (string.isEmpty())
349 // can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
350 // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
351 setupParser("@-webkit-mediaquery ", string, "} ");
357 queries->appendMediaQuery(m_mediaQuery);
365 void CSSParser::addProperty(int propId, PassRefPtr<CSSValue> value, bool important)
367 auto_ptr<CSSProperty> prop(new CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand));
368 if (m_numParsedProperties >= m_maxParsedProperties) {
369 m_maxParsedProperties += 32;
370 if (m_maxParsedProperties > UINT_MAX / sizeof(CSSProperty*))
372 m_parsedProperties = static_cast<CSSProperty**>(fastRealloc(m_parsedProperties,
373 m_maxParsedProperties * sizeof(CSSProperty*)));
375 m_parsedProperties[m_numParsedProperties++] = prop.release();
378 void CSSParser::rollbackLastProperties(int num)
381 ASSERT(m_numParsedProperties >= static_cast<unsigned>(num));
383 for (int i = 0; i < num; ++i)
384 delete m_parsedProperties[--m_numParsedProperties];
387 void CSSParser::clearProperties()
389 for (unsigned i = 0; i < m_numParsedProperties; i++)
390 delete m_parsedProperties[i];
391 m_numParsedProperties = 0;
392 m_hasFontFaceOnlyValues = false;
395 Document* CSSParser::document() const
397 StyleBase* root = m_styleSheet;
399 while (root && root->parent())
400 root = root->parent();
401 if (root && root->isCSSStyleSheet())
402 doc = static_cast<CSSStyleSheet*>(root)->doc();
406 bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, bool strict)
408 if (unitflags & FNonNeg && value->fValue < 0)
412 switch (value->unit) {
413 case CSSPrimitiveValue::CSS_NUMBER:
414 b = (unitflags & FNumber);
415 if (!b && ((unitflags & (FLength | FAngle | FTime)) && (value->fValue == 0 || !strict))) {
416 value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX :
417 ((unitflags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS);
420 if (!b && (unitflags & FInteger) && value->isInt)
423 case CSSPrimitiveValue::CSS_PERCENTAGE:
424 b = (unitflags & FPercent);
426 case CSSParserValue::Q_EMS:
427 case CSSPrimitiveValue::CSS_EMS:
428 case CSSPrimitiveValue::CSS_REMS:
429 case CSSPrimitiveValue::CSS_EXS:
430 case CSSPrimitiveValue::CSS_PX:
431 case CSSPrimitiveValue::CSS_CM:
432 case CSSPrimitiveValue::CSS_MM:
433 case CSSPrimitiveValue::CSS_IN:
434 case CSSPrimitiveValue::CSS_PT:
435 case CSSPrimitiveValue::CSS_PC:
436 b = (unitflags & FLength);
438 case CSSPrimitiveValue::CSS_MS:
439 case CSSPrimitiveValue::CSS_S:
440 b = (unitflags & FTime);
442 case CSSPrimitiveValue::CSS_DEG:
443 case CSSPrimitiveValue::CSS_RAD:
444 case CSSPrimitiveValue::CSS_GRAD:
445 case CSSPrimitiveValue::CSS_TURN:
446 b = (unitflags & FAngle);
448 case CSSPrimitiveValue::CSS_HZ:
449 case CSSPrimitiveValue::CSS_KHZ:
450 case CSSPrimitiveValue::CSS_DIMENSION:
457 static int unitFromString(CSSParserValue* value)
459 if (value->unit != CSSPrimitiveValue::CSS_IDENT || value->id)
462 if (equal(value->string, "em"))
463 return CSSPrimitiveValue::CSS_EMS;
464 if (equal(value->string, "rem"))
465 return CSSPrimitiveValue::CSS_REMS;
466 if (equal(value->string, "ex"))
467 return CSSPrimitiveValue::CSS_EXS;
468 if (equal(value->string, "px"))
469 return CSSPrimitiveValue::CSS_PX;
470 if (equal(value->string, "cm"))
471 return CSSPrimitiveValue::CSS_CM;
472 if (equal(value->string, "mm"))
473 return CSSPrimitiveValue::CSS_MM;
474 if (equal(value->string, "in"))
475 return CSSPrimitiveValue::CSS_IN;
476 if (equal(value->string, "pt"))
477 return CSSPrimitiveValue::CSS_PT;
478 if (equal(value->string, "pc"))
479 return CSSPrimitiveValue::CSS_PC;
480 if (equal(value->string, "deg"))
481 return CSSPrimitiveValue::CSS_DEG;
482 if (equal(value->string, "rad"))
483 return CSSPrimitiveValue::CSS_RAD;
484 if (equal(value->string, "grad"))
485 return CSSPrimitiveValue::CSS_GRAD;
486 if (equal(value->string, "turn"))
487 return CSSPrimitiveValue::CSS_TURN;
488 if (equal(value->string, "ms"))
489 return CSSPrimitiveValue::CSS_MS;
490 if (equal(value->string, "s"))
491 return CSSPrimitiveValue::CSS_S;
492 if (equal(value->string, "Hz"))
493 return CSSPrimitiveValue::CSS_HZ;
494 if (equal(value->string, "kHz"))
495 return CSSPrimitiveValue::CSS_KHZ;
500 void CSSParser::checkForOrphanedUnits()
502 if (m_strict || inShorthand())
505 // The purpose of this code is to implement the WinIE quirk that allows unit types to be separated from their numeric values
506 // 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.
507 CSSParserValue* numericVal = 0;
508 unsigned size = m_valueList->size();
509 for (unsigned i = 0; i < size; i++) {
510 CSSParserValue* value = m_valueList->valueAt(i);
513 // Change the unit type of the numeric val to match.
514 int unit = unitFromString(value);
516 numericVal->unit = unit;
519 // Now delete the bogus unit value.
520 m_valueList->deleteValueAt(i);
521 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).
527 numericVal = (value->unit == CSSPrimitiveValue::CSS_NUMBER) ? value : 0;
531 bool CSSParser::parseValue(int propId, bool important)
536 CSSParserValue *value = m_valueList->current();
543 // In quirks mode, we will look for units that have been incorrectly separated from the number they belong to
544 // by a space. We go ahead and associate the unit with the number even though it is invalid CSS.
545 checkForOrphanedUnits();
547 int num = inShorthand() ? 1 : m_valueList->size();
549 if (id == CSSValueInherit) {
552 addProperty(propId, CSSInheritedValue::create(), important);
555 else if (id == CSSValueInitial) {
558 addProperty(propId, CSSInitialValue::createExplicit(), important);
562 // If we have any variables, then we don't parse the list of values yet. We add them to the declaration
563 // as unresolved, and allow them to be parsed later. The parse is considered "successful" for now, even though
564 // it might ultimately fail once the variable has been resolved.
565 if (!inShorthand() && checkForVariables(m_valueList)) {
566 addUnresolvedProperty(propId, important);
570 bool valid_primitive = false;
571 RefPtr<CSSValue> parsedValue;
573 switch (static_cast<CSSPropertyID>(propId)) {
574 /* The comment to the left defines all valid value of this properties as defined
575 * in CSS 2, Appendix F. Property index
578 /* All the CSS properties are not supported by the renderer at the moment.
579 * Note that all the CSS2 Aural properties are only checked, if CSS_AURAL is defined
580 * (see parseAuralValues). As we don't support them at all this seems reasonable.
583 case CSSPropertySize: // <length>{1,2} | auto | portrait | landscape | inherit
584 case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit
586 valid_primitive = true;
588 case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | inherit
589 if (id == CSSValueNormal ||
590 id == CSSValueEmbed ||
591 id == CSSValueBidiOverride)
592 valid_primitive = true;
595 case CSSPropertyPosition: // static | relative | absolute | fixed | inherit
596 if (id == CSSValueStatic ||
597 id == CSSValueRelative ||
598 id == CSSValueAbsolute ||
600 valid_primitive = true;
603 case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | inherit
604 case CSSPropertyPageBreakBefore:
605 case CSSPropertyWebkitColumnBreakAfter:
606 case CSSPropertyWebkitColumnBreakBefore:
607 if (id == CSSValueAuto ||
608 id == CSSValueAlways ||
609 id == CSSValueAvoid ||
610 id == CSSValueLeft ||
612 valid_primitive = true;
615 case CSSPropertyPageBreakInside: // avoid | auto | inherit
616 case CSSPropertyWebkitColumnBreakInside:
617 if (id == CSSValueAuto || id == CSSValueAvoid)
618 valid_primitive = true;
621 case CSSPropertyEmptyCells: // show | hide | inherit
622 if (id == CSSValueShow ||
624 valid_primitive = true;
627 case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
628 // close-quote | no-open-quote | no-close-quote ]+ | inherit
629 return parseContent(propId, important);
631 case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit
632 if (id == CSSValueNormal ||
634 id == CSSValuePreWrap ||
635 id == CSSValuePreLine ||
636 id == CSSValueNowrap)
637 valid_primitive = true;
640 case CSSPropertyClip: // <shape> | auto | inherit
641 if (id == CSSValueAuto)
642 valid_primitive = true;
643 else if (value->unit == CSSParserValue::Function)
644 return parseShape(propId, important);
647 /* Start of supported CSS properties with validation. This is needed for parseShorthand to work
648 * correctly and allows optimization in WebCore::applyRule(..)
650 case CSSPropertyCaptionSide: // top | bottom | left | right | inherit
651 if (id == CSSValueLeft || id == CSSValueRight ||
652 id == CSSValueTop || id == CSSValueBottom)
653 valid_primitive = true;
656 case CSSPropertyBorderCollapse: // collapse | separate | inherit
657 if (id == CSSValueCollapse || id == CSSValueSeparate)
658 valid_primitive = true;
661 case CSSPropertyVisibility: // visible | hidden | collapse | inherit
662 if (id == CSSValueVisible || id == CSSValueHidden || id == CSSValueCollapse)
663 valid_primitive = true;
666 case CSSPropertyOverflow: {
667 ShorthandScope scope(this, propId);
668 if (num != 1 || !parseValue(CSSPropertyOverflowX, important))
670 CSSValue* value = m_parsedProperties[m_numParsedProperties - 1]->value();
671 addProperty(CSSPropertyOverflowY, value, important);
674 case CSSPropertyOverflowX:
675 case CSSPropertyOverflowY: // visible | hidden | scroll | auto | marquee | overlay | inherit
676 if (id == CSSValueVisible || id == CSSValueHidden || id == CSSValueScroll || id == CSSValueAuto ||
677 id == CSSValueOverlay || id == CSSValueWebkitMarquee)
678 valid_primitive = true;
681 case CSSPropertyListStylePosition: // inside | outside | inherit
682 if (id == CSSValueInside || id == CSSValueOutside)
683 valid_primitive = true;
686 case CSSPropertyListStyleType:
687 // disc | circle | square | decimal | decimal-leading-zero | lower-roman |
688 // upper-roman | lower-greek | lower-alpha | lower-latin | upper-alpha |
689 // upper-latin | hebrew | armenian | georgian | cjk-ideographic | hiragana |
690 // katakana | hiragana-iroha | katakana-iroha | none | inherit
691 if ((id >= CSSValueDisc && id <= CSSValueKatakanaIroha) || id == CSSValueNone)
692 valid_primitive = true;
695 case CSSPropertyDisplay:
696 // inline | block | list-item | run-in | inline-block | table |
697 // inline-table | table-row-group | table-header-group | table-footer-group | table-row |
698 // table-column-group | table-column | table-cell | table-caption | box | inline-box | none | inherit
700 if ((id >= CSSValueInline && id <= CSSValueWapMarquee) || id == CSSValueNone)
702 if ((id >= CSSValueInline && id <= CSSValueWebkitInlineBox) || id == CSSValueNone)
704 valid_primitive = true;
707 case CSSPropertyDirection: // ltr | rtl | inherit
708 if (id == CSSValueLtr || id == CSSValueRtl)
709 valid_primitive = true;
712 case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none | inherit
713 if ((id >= CSSValueCapitalize && id <= CSSValueLowercase) || id == CSSValueNone)
714 valid_primitive = true;
717 case CSSPropertyFloat: // left | right | none | inherit + center for buggy CSS
718 if (id == CSSValueLeft || id == CSSValueRight ||
719 id == CSSValueNone || id == CSSValueCenter)
720 valid_primitive = true;
723 case CSSPropertyClear: // none | left | right | both | inherit
724 if (id == CSSValueNone || id == CSSValueLeft ||
725 id == CSSValueRight|| id == CSSValueBoth)
726 valid_primitive = true;
729 case CSSPropertyTextAlign:
730 // left | right | center | justify | webkit_left | webkit_right | webkit_center | start | end | <string> | inherit
731 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitCenter) || id == CSSValueStart || id == CSSValueEnd ||
732 value->unit == CSSPrimitiveValue::CSS_STRING)
733 valid_primitive = true;
736 case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto | inherit
737 if (id == CSSValueAuto || id == CSSValueNone || (id >= CSSValueInset && id <= CSSValueDouble))
738 valid_primitive = true;
741 case CSSPropertyBorderTopStyle: //// <border-style> | inherit
742 case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed |
743 case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset
744 case CSSPropertyBorderLeftStyle:
745 case CSSPropertyWebkitColumnRuleStyle:
746 if (id >= CSSValueNone && id <= CSSValueDouble)
747 valid_primitive = true;
750 case CSSPropertyFontWeight: // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
751 return parseFontWeight(important);
753 case CSSPropertyBorderSpacing: {
754 const int properties[2] = { CSSPropertyWebkitBorderHorizontalSpacing,
755 CSSPropertyWebkitBorderVerticalSpacing };
757 ShorthandScope scope(this, CSSPropertyBorderSpacing);
758 if (!parseValue(properties[0], important))
760 CSSValue* value = m_parsedProperties[m_numParsedProperties-1]->value();
761 addProperty(properties[1], value, important);
765 ShorthandScope scope(this, CSSPropertyBorderSpacing);
766 if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
772 case CSSPropertyWebkitBorderHorizontalSpacing:
773 case CSSPropertyWebkitBorderVerticalSpacing:
774 valid_primitive = validUnit(value, FLength|FNonNeg, m_strict);
776 case CSSPropertyOutlineColor: // <color> | invert | inherit
777 // Outline color has "invert" as additional keyword.
778 // Also, we want to allow the special focus color even in strict parsing mode.
779 if (propId == CSSPropertyOutlineColor && (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor)) {
780 valid_primitive = true;
784 case CSSPropertyBackgroundColor: // <color> | inherit
785 case CSSPropertyBorderTopColor: // <color> | inherit
786 case CSSPropertyBorderRightColor: // <color> | inherit
787 case CSSPropertyBorderBottomColor: // <color> | inherit
788 case CSSPropertyBorderLeftColor: // <color> | inherit
789 case CSSPropertyColor: // <color> | inherit
790 case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors
791 case CSSPropertyTextUnderlineColor:
792 case CSSPropertyTextOverlineColor:
793 case CSSPropertyWebkitColumnRuleColor:
794 case CSSPropertyWebkitTextFillColor:
795 case CSSPropertyWebkitTextStrokeColor:
796 if (id == CSSValueWebkitText)
797 valid_primitive = true; // Always allow this, even when strict parsing is on,
798 // since we use this in our UA sheets.
799 else if (id == CSSValueCurrentcolor)
800 valid_primitive = true;
801 else if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu ||
802 (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && !m_strict)) {
803 valid_primitive = true;
805 parsedValue = parseColor();
811 case CSSPropertyCursor: {
812 // [<uri>,]* [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |
813 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize |
814 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help |
815 // vertical-text | cell | context-menu | alias | copy | no-drop | not-allowed | -webkit-zoom-in
816 // -webkit-zoom-in | -webkit-zoom-out | all-scroll | -webkit-grab | -webkit-grabbing ] ] | inherit
817 RefPtr<CSSValueList> list;
818 while (value && value->unit == CSSPrimitiveValue::CSS_URI) {
820 list = CSSValueList::createCommaSeparated();
821 String uri = value->string;
823 value = m_valueList->next();
824 while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
825 coords.append(int(value->fValue));
826 value = m_valueList->next();
829 int nrcoords = coords.size();
830 if (nrcoords > 0 && nrcoords != 2)
833 hotspot = IntPoint(coords[0], coords[1]);
835 if (!uri.isNull() && m_styleSheet) {
836 // FIXME: The completeURL call should be done when using the CSSCursorImageValue,
837 // not when creating it.
838 list->append(CSSCursorImageValue::create(m_styleSheet->completeURL(uri), hotspot));
841 if ((m_strict && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ',')))
843 value = m_valueList->next(); // comma
846 if (!value) { // no value after url list (MSIE 5 compatibility)
847 if (list->length() != 1)
849 } else if (!m_strict && value->id == CSSValueHand) // MSIE 5 compatibility :/
850 list->append(CSSPrimitiveValue::createIdentifier(CSSValuePointer));
851 else if (value && ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone))
852 list->append(CSSPrimitiveValue::createIdentifier(value->id));
854 parsedValue = list.release();
858 if (!m_strict && value->id == CSSValueHand) { // MSIE 5 compatibility :/
859 id = CSSValuePointer;
860 valid_primitive = true;
861 } else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
862 valid_primitive = true;
866 case CSSPropertyBackgroundAttachment:
867 case CSSPropertyBackgroundClip:
868 case CSSPropertyWebkitBackgroundClip:
869 case CSSPropertyWebkitBackgroundComposite:
870 case CSSPropertyBackgroundImage:
871 case CSSPropertyBackgroundOrigin:
872 case CSSPropertyWebkitBackgroundOrigin:
873 case CSSPropertyBackgroundPosition:
874 case CSSPropertyBackgroundPositionX:
875 case CSSPropertyBackgroundPositionY:
876 case CSSPropertyBackgroundSize:
877 case CSSPropertyBackgroundRepeat:
878 case CSSPropertyBackgroundRepeatX:
879 case CSSPropertyBackgroundRepeatY:
880 case CSSPropertyWebkitMaskAttachment:
881 case CSSPropertyWebkitMaskClip:
882 case CSSPropertyWebkitMaskComposite:
883 case CSSPropertyWebkitMaskImage:
884 case CSSPropertyWebkitMaskOrigin:
885 case CSSPropertyWebkitMaskPosition:
886 case CSSPropertyWebkitMaskPositionX:
887 case CSSPropertyWebkitMaskPositionY:
888 case CSSPropertyWebkitMaskSize:
889 case CSSPropertyWebkitMaskRepeat:
890 case CSSPropertyWebkitMaskRepeatX:
891 case CSSPropertyWebkitMaskRepeatY: {
892 RefPtr<CSSValue> val1;
893 RefPtr<CSSValue> val2;
894 int propId1, propId2;
895 if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
896 addProperty(propId1, val1.release(), important);
898 addProperty(propId2, val2.release(), important);
901 m_implicitShorthand = false;
904 case CSSPropertyListStyleImage: // <uri> | none | inherit
905 if (id == CSSValueNone) {
906 parsedValue = CSSImageValue::create();
908 } else if (value->unit == CSSPrimitiveValue::CSS_URI) {
910 // FIXME: The completeURL call should be done when using the CSSImageValue,
911 // not when creating it.
912 parsedValue = CSSImageValue::create(m_styleSheet->completeURL(value->string));
915 } else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-gradient(")) {
916 if (parseGradient(parsedValue))
923 case CSSPropertyWebkitTextStrokeWidth:
924 case CSSPropertyOutlineWidth: // <border-width> | inherit
925 case CSSPropertyBorderTopWidth: //// <border-width> | inherit
926 case CSSPropertyBorderRightWidth: // Which is defined as
927 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
928 case CSSPropertyBorderLeftWidth:
929 case CSSPropertyWebkitColumnRuleWidth:
930 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
931 valid_primitive = true;
933 valid_primitive = validUnit(value, FLength, m_strict);
936 case CSSPropertyLetterSpacing: // normal | <length> | inherit
937 case CSSPropertyWordSpacing: // normal | <length> | inherit
938 if (id == CSSValueNormal)
939 valid_primitive = true;
941 valid_primitive = validUnit(value, FLength, m_strict);
944 case CSSPropertyWordBreak: // normal | break-all | break-word (this is a custom extension)
945 if (id == CSSValueNormal || id == CSSValueBreakAll || id == CSSValueBreakWord)
946 valid_primitive = true;
949 case CSSPropertyWordWrap: // normal | break-word
950 if (id == CSSValueNormal || id == CSSValueBreakWord)
951 valid_primitive = true;
954 case CSSPropertyTextIndent: // <length> | <percentage> | inherit
955 case CSSPropertyPaddingTop: //// <padding-width> | inherit
956 case CSSPropertyPaddingRight: // Which is defined as
957 case CSSPropertyPaddingBottom: // <length> | <percentage>
958 case CSSPropertyPaddingLeft: ////
959 case CSSPropertyWebkitPaddingStart:
960 valid_primitive = (!id && validUnit(value, FLength|FPercent, m_strict));
963 case CSSPropertyMaxHeight: // <length> | <percentage> | none | inherit
964 case CSSPropertyMaxWidth: // <length> | <percentage> | none | inherit
965 if (id == CSSValueNone || id == CSSValueIntrinsic || id == CSSValueMinIntrinsic) {
966 valid_primitive = true;
970 case CSSPropertyMinHeight: // <length> | <percentage> | inherit
971 case CSSPropertyMinWidth: // <length> | <percentage> | inherit
972 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic)
973 valid_primitive = true;
975 valid_primitive = (!id && validUnit(value, FLength|FPercent|FNonNeg, m_strict));
978 case CSSPropertyFontSize:
979 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit
980 if (id >= CSSValueXxSmall && id <= CSSValueLarger)
981 valid_primitive = true;
983 valid_primitive = (validUnit(value, FLength|FPercent|FNonNeg, m_strict));
986 case CSSPropertyFontStyle: // normal | italic | oblique | inherit
987 return parseFontStyle(important);
989 case CSSPropertyFontVariant: // normal | small-caps | inherit
990 return parseFontVariant(important);
992 case CSSPropertyVerticalAlign:
993 // baseline | sub | super | top | text-top | middle | bottom | text-bottom |
994 // <percentage> | <length> | inherit
996 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
997 valid_primitive = true;
999 valid_primitive = (!id && validUnit(value, FLength|FPercent, m_strict));
1002 case CSSPropertyHeight: // <length> | <percentage> | auto | inherit
1003 case CSSPropertyWidth: // <length> | <percentage> | auto | inherit
1004 if (id == CSSValueAuto || id == CSSValueIntrinsic || id == CSSValueMinIntrinsic)
1005 valid_primitive = true;
1007 // ### handle multilength case where we allow relative units
1008 valid_primitive = (!id && validUnit(value, FLength|FPercent|FNonNeg, m_strict));
1011 case CSSPropertyBottom: // <length> | <percentage> | auto | inherit
1012 case CSSPropertyLeft: // <length> | <percentage> | auto | inherit
1013 case CSSPropertyRight: // <length> | <percentage> | auto | inherit
1014 case CSSPropertyTop: // <length> | <percentage> | auto | inherit
1015 case CSSPropertyMarginTop: //// <margin-width> | inherit
1016 case CSSPropertyMarginRight: // Which is defined as
1017 case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit
1018 case CSSPropertyMarginLeft: ////
1019 case CSSPropertyWebkitMarginStart:
1020 if (id == CSSValueAuto)
1021 valid_primitive = true;
1023 valid_primitive = (!id && validUnit(value, FLength|FPercent, m_strict));
1026 case CSSPropertyZIndex: // auto | <integer> | inherit
1027 if (id == CSSValueAuto) {
1028 valid_primitive = true;
1032 case CSSPropertyOrphans: // <integer> | inherit
1033 case CSSPropertyWidows: // <integer> | inherit
1034 // ### not supported later on
1035 valid_primitive = (!id && validUnit(value, FInteger, false));
1038 case CSSPropertyLineHeight: // normal | <number> | <length> | <percentage> | inherit
1039 if (id == CSSValueNormal)
1040 valid_primitive = true;
1042 valid_primitive = (!id && validUnit(value, FNumber|FLength|FPercent|FNonNeg, m_strict));
1044 case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit
1045 if (id != CSSValueNone)
1046 return parseCounter(propId, 1, important);
1047 valid_primitive = true;
1049 case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit
1050 if (id != CSSValueNone)
1051 return parseCounter(propId, 0, important);
1052 valid_primitive = true;
1054 case CSSPropertyFontFamily:
1055 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit
1057 parsedValue = parseFontFamily();
1061 case CSSPropertyTextDecoration:
1062 case CSSPropertyWebkitTextDecorationsInEffect:
1063 // none | [ underline || overline || line-through || blink ] | inherit
1064 if (id == CSSValueNone) {
1065 valid_primitive = true;
1067 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1068 bool is_valid = true;
1069 while (is_valid && value) {
1070 switch (value->id) {
1073 case CSSValueUnderline:
1074 case CSSValueOverline:
1075 case CSSValueLineThrough:
1076 list->append(CSSPrimitiveValue::createIdentifier(value->id));
1081 value = m_valueList->next();
1083 if (list->length() && is_valid) {
1084 parsedValue = list.release();
1085 m_valueList->next();
1090 case CSSPropertyZoom: // normal | reset | document | <number> | <percentage> | inherit
1091 if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument)
1092 valid_primitive = true;
1094 valid_primitive = (!id && validUnit(value, FNumber | FPercent | FNonNeg, true));
1097 case CSSPropertyTableLayout: // auto | fixed | inherit
1098 if (id == CSSValueAuto || id == CSSValueFixed)
1099 valid_primitive = true;
1102 case CSSPropertySrc: // Only used within @font-face, so cannot use inherit | initial or be !important. This is a list of urls or local references.
1103 return parseFontFaceSrc();
1105 case CSSPropertyUnicodeRange:
1106 return parseFontFaceUnicodeRange();
1108 /* CSS3 properties */
1109 case CSSPropertyWebkitAppearance:
1110 if ((id >= CSSValueCheckbox && id <= CSSValueTextarea) || id == CSSValueNone)
1111 valid_primitive = true;
1114 case CSSPropertyWebkitBinding:
1116 if (id == CSSValueNone)
1117 valid_primitive = true;
1119 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
1120 CSSParserValue* val;
1121 RefPtr<CSSValue> parsedValue;
1122 while ((val = m_valueList->current())) {
1123 if (val->unit == CSSPrimitiveValue::CSS_URI && m_styleSheet) {
1124 // FIXME: The completeURL call should be done when using the CSSPrimitiveValue,
1125 // not when creating it.
1126 parsedValue = CSSPrimitiveValue::create(m_styleSheet->completeURL(val->string), CSSPrimitiveValue::CSS_URI);
1131 // FIXME: We can't use release() here since we might hit this path twice
1132 // but that logic seems wrong to me to begin with, we convert all non-uri values
1133 // into the last seen URI value!?
1134 // -webkit-binding: url(foo.xml), 1, 2; (if that were valid) is treated as:
1135 // -webkit-binding: url(foo.xml), url(foo.xml), url(foo.xml); !?
1136 values->append(parsedValue.get());
1137 m_valueList->next();
1139 if (!values->length())
1142 addProperty(propId, values.release(), important);
1143 m_valueList->next();
1148 case CSSPropertyWebkitBorderImage:
1149 case CSSPropertyWebkitMaskBoxImage:
1150 if (id == CSSValueNone)
1151 valid_primitive = true;
1153 RefPtr<CSSValue> result;
1154 if (parseBorderImage(propId, important, result)) {
1155 addProperty(propId, result, important);
1160 case CSSPropertyBorderTopRightRadius:
1161 case CSSPropertyBorderTopLeftRadius:
1162 case CSSPropertyBorderBottomLeftRadius:
1163 case CSSPropertyBorderBottomRightRadius: {
1164 if (num != 1 && num != 2)
1166 valid_primitive = validUnit(value, FLength, m_strict);
1167 if (!valid_primitive)
1169 RefPtr<CSSPrimitiveValue> parsedValue1 = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
1170 RefPtr<CSSPrimitiveValue> parsedValue2;
1172 value = m_valueList->next();
1173 valid_primitive = validUnit(value, FLength, m_strict);
1174 if (!valid_primitive)
1176 parsedValue2 = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
1178 parsedValue2 = parsedValue1;
1180 RefPtr<Pair> pair = Pair::create(parsedValue1.release(), parsedValue2.release());
1181 RefPtr<CSSPrimitiveValue> val = CSSPrimitiveValue::create(pair.release());
1182 addProperty(propId, val.release(), important);
1185 case CSSPropertyBorderRadius:
1186 case CSSPropertyWebkitBorderRadius:
1187 return parseBorderRadius(propId, important);
1188 case CSSPropertyOutlineOffset:
1189 valid_primitive = validUnit(value, FLength, m_strict);
1191 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
1192 case CSSPropertyBoxShadow:
1193 if (id == CSSValueNone)
1194 valid_primitive = true;
1196 return parseShadow(propId, important);
1198 case CSSPropertyWebkitBoxReflect:
1199 if (id == CSSValueNone)
1200 valid_primitive = true;
1202 return parseReflect(propId, important);
1204 case CSSPropertyOpacity:
1205 valid_primitive = validUnit(value, FNumber, m_strict);
1207 case CSSPropertyWebkitBoxAlign:
1208 if (id == CSSValueStretch || id == CSSValueStart || id == CSSValueEnd ||
1209 id == CSSValueCenter || id == CSSValueBaseline)
1210 valid_primitive = true;
1212 case CSSPropertyWebkitBoxDirection:
1213 if (id == CSSValueNormal || id == CSSValueReverse)
1214 valid_primitive = true;
1216 case CSSPropertyWebkitBoxLines:
1217 if (id == CSSValueSingle || id == CSSValueMultiple)
1218 valid_primitive = true;
1220 case CSSPropertyWebkitBoxOrient:
1221 if (id == CSSValueHorizontal || id == CSSValueVertical ||
1222 id == CSSValueInlineAxis || id == CSSValueBlockAxis)
1223 valid_primitive = true;
1225 case CSSPropertyWebkitBoxPack:
1226 if (id == CSSValueStart || id == CSSValueEnd ||
1227 id == CSSValueCenter || id == CSSValueJustify)
1228 valid_primitive = true;
1230 case CSSPropertyWebkitBoxFlex:
1231 valid_primitive = validUnit(value, FNumber, m_strict);
1233 case CSSPropertyWebkitBoxFlexGroup:
1234 case CSSPropertyWebkitBoxOrdinalGroup:
1235 valid_primitive = validUnit(value, FInteger|FNonNeg, true);
1237 case CSSPropertyWebkitBoxSizing:
1238 valid_primitive = id == CSSValueBorderBox || id == CSSValueContentBox;
1240 case CSSPropertyWebkitMarquee: {
1241 const int properties[5] = { CSSPropertyWebkitMarqueeDirection, CSSPropertyWebkitMarqueeIncrement,
1242 CSSPropertyWebkitMarqueeRepetition,
1243 CSSPropertyWebkitMarqueeStyle, CSSPropertyWebkitMarqueeSpeed };
1244 return parseShorthand(propId, properties, 5, important);
1246 case CSSPropertyWebkitMarqueeDirection:
1247 if (id == CSSValueForwards || id == CSSValueBackwards || id == CSSValueAhead ||
1248 id == CSSValueReverse || id == CSSValueLeft || id == CSSValueRight || id == CSSValueDown ||
1249 id == CSSValueUp || id == CSSValueAuto)
1250 valid_primitive = true;
1252 case CSSPropertyWebkitMarqueeIncrement:
1253 if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
1254 valid_primitive = true;
1256 valid_primitive = validUnit(value, FLength|FPercent, m_strict);
1258 case CSSPropertyWebkitMarqueeStyle:
1259 if (id == CSSValueNone || id == CSSValueSlide || id == CSSValueScroll || id == CSSValueAlternate)
1260 valid_primitive = true;
1262 case CSSPropertyWebkitMarqueeRepetition:
1263 if (id == CSSValueInfinite)
1264 valid_primitive = true;
1266 valid_primitive = validUnit(value, FInteger|FNonNeg, m_strict);
1268 case CSSPropertyWebkitMarqueeSpeed:
1269 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
1270 valid_primitive = true;
1272 valid_primitive = validUnit(value, FTime|FInteger|FNonNeg, m_strict);
1275 case CSSPropertyWapMarqueeDir:
1276 if (id == CSSValueLtr || id == CSSValueRtl)
1277 valid_primitive = true;
1279 case CSSPropertyWapMarqueeStyle:
1280 if (id == CSSValueNone || id == CSSValueSlide || id == CSSValueScroll || id == CSSValueAlternate)
1281 valid_primitive = true;
1283 case CSSPropertyWapMarqueeLoop:
1284 if (id == CSSValueInfinite)
1285 valid_primitive = true;
1287 valid_primitive = validUnit(value, FInteger | FNonNeg, m_strict);
1289 case CSSPropertyWapMarqueeSpeed:
1290 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
1291 valid_primitive = true;
1293 valid_primitive = validUnit(value, FTime | FInteger | FNonNeg, m_strict);
1296 case CSSPropertyWebkitUserDrag: // auto | none | element
1297 if (id == CSSValueAuto || id == CSSValueNone || id == CSSValueElement)
1298 valid_primitive = true;
1300 case CSSPropertyWebkitUserModify: // read-only | read-write
1301 if (id == CSSValueReadOnly || id == CSSValueReadWrite || id == CSSValueReadWritePlaintextOnly)
1302 valid_primitive = true;
1304 case CSSPropertyWebkitUserSelect: // auto | none | text
1305 if (id == CSSValueAuto || id == CSSValueNone || id == CSSValueText)
1306 valid_primitive = true;
1308 case CSSPropertyTextOverflow: // clip | ellipsis
1309 if (id == CSSValueClip || id == CSSValueEllipsis)
1310 valid_primitive = true;
1312 case CSSPropertyWebkitTransform:
1313 if (id == CSSValueNone)
1314 valid_primitive = true;
1316 PassRefPtr<CSSValue> val = parseTransform();
1318 addProperty(propId, val, important);
1324 case CSSPropertyWebkitTransformOrigin:
1325 case CSSPropertyWebkitTransformOriginX:
1326 case CSSPropertyWebkitTransformOriginY:
1327 case CSSPropertyWebkitTransformOriginZ: {
1328 RefPtr<CSSValue> val1;
1329 RefPtr<CSSValue> val2;
1330 RefPtr<CSSValue> val3;
1331 int propId1, propId2, propId3;
1332 if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
1333 addProperty(propId1, val1.release(), important);
1335 addProperty(propId2, val2.release(), important);
1337 addProperty(propId3, val3.release(), important);
1342 case CSSPropertyWebkitTransformStyle:
1343 if (value->id == CSSValueFlat || value->id == CSSValuePreserve3d)
1344 valid_primitive = true;
1346 case CSSPropertyWebkitBackfaceVisibility:
1347 if (value->id == CSSValueVisible || value->id == CSSValueHidden)
1348 valid_primitive = true;
1350 case CSSPropertyWebkitPerspective:
1351 if (id == CSSValueNone)
1352 valid_primitive = true;
1354 // Accepting valueless numbers is a quirk of the -webkit prefixed version of the property.
1355 if (validUnit(value, FNumber|FLength|FNonNeg, m_strict)) {
1356 RefPtr<CSSValue> val = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
1358 addProperty(propId, val.release(), important);
1365 case CSSPropertyWebkitPerspectiveOrigin:
1366 case CSSPropertyWebkitPerspectiveOriginX:
1367 case CSSPropertyWebkitPerspectiveOriginY: {
1368 RefPtr<CSSValue> val1;
1369 RefPtr<CSSValue> val2;
1370 int propId1, propId2;
1371 if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
1372 addProperty(propId1, val1.release(), important);
1374 addProperty(propId2, val2.release(), important);
1379 case CSSPropertyWebkitAnimationDelay:
1380 case CSSPropertyWebkitAnimationDirection:
1381 case CSSPropertyWebkitAnimationDuration:
1382 case CSSPropertyWebkitAnimationName:
1383 case CSSPropertyWebkitAnimationPlayState:
1384 case CSSPropertyWebkitAnimationIterationCount:
1385 case CSSPropertyWebkitAnimationTimingFunction:
1386 case CSSPropertyWebkitTransitionDelay:
1387 case CSSPropertyWebkitTransitionDuration:
1388 case CSSPropertyWebkitTransitionTimingFunction:
1389 case CSSPropertyWebkitTransitionProperty: {
1390 RefPtr<CSSValue> val;
1391 if (parseAnimationProperty(propId, val)) {
1392 addProperty(propId, val.release(), important);
1397 case CSSPropertyWebkitMarginCollapse: {
1398 const int properties[2] = { CSSPropertyWebkitMarginTopCollapse,
1399 CSSPropertyWebkitMarginBottomCollapse };
1401 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
1402 if (!parseValue(properties[0], important))
1404 CSSValue* value = m_parsedProperties[m_numParsedProperties-1]->value();
1405 addProperty(properties[1], value, important);
1408 else if (num == 2) {
1409 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
1410 if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
1416 case CSSPropertyWebkitMarginTopCollapse:
1417 case CSSPropertyWebkitMarginBottomCollapse:
1418 if (id == CSSValueCollapse || id == CSSValueSeparate || id == CSSValueDiscard)
1419 valid_primitive = true;
1421 case CSSPropertyTextLineThroughMode:
1422 case CSSPropertyTextOverlineMode:
1423 case CSSPropertyTextUnderlineMode:
1424 if (id == CSSValueContinuous || id == CSSValueSkipWhiteSpace)
1425 valid_primitive = true;
1427 case CSSPropertyTextLineThroughStyle:
1428 case CSSPropertyTextOverlineStyle:
1429 case CSSPropertyTextUnderlineStyle:
1430 if (id == CSSValueNone || id == CSSValueSolid || id == CSSValueDouble ||
1431 id == CSSValueDashed || id == CSSValueDotDash || id == CSSValueDotDotDash ||
1433 valid_primitive = true;
1435 case CSSPropertyTextLineThroughWidth:
1436 case CSSPropertyTextOverlineWidth:
1437 case CSSPropertyTextUnderlineWidth:
1438 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
1439 id == CSSValueMedium || id == CSSValueThick)
1440 valid_primitive = true;
1442 valid_primitive = !id && validUnit(value, FNumber|FLength|FPercent, m_strict);
1444 case CSSPropertyResize: // none | both | horizontal | vertical | auto
1445 if (id == CSSValueNone || id == CSSValueBoth || id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto)
1446 valid_primitive = true;
1448 case CSSPropertyWebkitColumnCount:
1449 if (id == CSSValueAuto)
1450 valid_primitive = true;
1452 valid_primitive = !id && validUnit(value, FInteger | FNonNeg, false);
1454 case CSSPropertyWebkitColumnGap: // normal | <length>
1455 if (id == CSSValueNormal)
1456 valid_primitive = true;
1458 valid_primitive = validUnit(value, FLength | FNonNeg, m_strict);
1460 case CSSPropertyWebkitColumnWidth: // auto | <length>
1461 if (id == CSSValueAuto)
1462 valid_primitive = true;
1463 else // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property.
1464 valid_primitive = validUnit(value, FLength, true);
1466 case CSSPropertyPointerEvents:
1467 // none | visiblePainted | visibleFill | visibleStroke | visible |
1468 // painted | fill | stroke | auto | all | inherit
1469 if (id == CSSValueVisible || id == CSSValueNone || id == CSSValueAll || id == CSSValueAuto ||
1470 (id >= CSSValueVisiblepainted && id <= CSSValueStroke))
1471 valid_primitive = true;
1474 // End of CSS3 properties
1476 // Apple specific properties. These will never be standardized and are purely to
1477 // support custom WebKit-based Apple applications.
1478 case CSSPropertyWebkitLineClamp:
1479 valid_primitive = (!id && validUnit(value, FPercent, false));
1481 case CSSPropertyWebkitTextSizeAdjust:
1482 if (id == CSSValueAuto || id == CSSValueNone)
1483 valid_primitive = true;
1485 case CSSPropertyWebkitRtlOrdering:
1486 if (id == CSSValueLogical || id == CSSValueVisual)
1487 valid_primitive = true;
1490 case CSSPropertyWebkitFontSizeDelta: // <length>
1491 valid_primitive = validUnit(value, FLength, m_strict);
1494 case CSSPropertyWebkitNbspMode: // normal | space
1495 if (id == CSSValueNormal || id == CSSValueSpace)
1496 valid_primitive = true;
1499 case CSSPropertyWebkitLineBreak: // normal | after-white-space
1500 if (id == CSSValueNormal || id == CSSValueAfterWhiteSpace)
1501 valid_primitive = true;
1504 case CSSPropertyWebkitMatchNearestMailBlockquoteColor: // normal | match
1505 if (id == CSSValueNormal || id == CSSValueMatch)
1506 valid_primitive = true;
1509 case CSSPropertyWebkitHighlight:
1510 if (id == CSSValueNone || value->unit == CSSPrimitiveValue::CSS_STRING)
1511 valid_primitive = true;
1514 case CSSPropertyWebkitBorderFit:
1515 if (id == CSSValueBorder || id == CSSValueLines)
1516 valid_primitive = true;
1519 case CSSPropertyWebkitTextSecurity:
1520 // disc | circle | square | none | inherit
1521 if (id == CSSValueDisc || id == CSSValueCircle || id == CSSValueSquare|| id == CSSValueNone)
1522 valid_primitive = true;
1525 #if ENABLE(DASHBOARD_SUPPORT)
1526 case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region>
1527 if (value->unit == CSSParserValue::Function || id == CSSValueNone)
1528 return parseDashboardRegions(propId, important);
1531 // End Apple-specific properties
1533 /* shorthand properties */
1534 case CSSPropertyBackground: {
1535 // Position must come before color in this array because a plain old "0" is a legal color
1536 // in quirks mode but it's usually the X coordinate of a position.
1537 // FIXME: Add CSSPropertyBackgroundSize to the shorthand.
1538 const int properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
1539 CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin,
1540 CSSPropertyBackgroundColor };
1541 return parseFillShorthand(propId, properties, 6, important);
1543 case CSSPropertyWebkitMask: {
1544 const int properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskRepeat,
1545 CSSPropertyWebkitMaskAttachment, CSSPropertyWebkitMaskPosition,
1546 CSSPropertyWebkitMaskOrigin };
1547 return parseFillShorthand(propId, properties, 5, important);
1549 case CSSPropertyBorder:
1550 // [ 'border-width' || 'border-style' || <color> ] | inherit
1552 const int properties[3] = { CSSPropertyBorderWidth, CSSPropertyBorderStyle,
1553 CSSPropertyBorderColor };
1554 return parseShorthand(propId, properties, 3, important);
1556 case CSSPropertyBorderTop:
1557 // [ 'border-top-width' || 'border-style' || <color> ] | inherit
1559 const int properties[3] = { CSSPropertyBorderTopWidth, CSSPropertyBorderTopStyle,
1560 CSSPropertyBorderTopColor};
1561 return parseShorthand(propId, properties, 3, important);
1563 case CSSPropertyBorderRight:
1564 // [ 'border-right-width' || 'border-style' || <color> ] | inherit
1566 const int properties[3] = { CSSPropertyBorderRightWidth, CSSPropertyBorderRightStyle,
1567 CSSPropertyBorderRightColor };
1568 return parseShorthand(propId, properties, 3, important);
1570 case CSSPropertyBorderBottom:
1571 // [ 'border-bottom-width' || 'border-style' || <color> ] | inherit
1573 const int properties[3] = { CSSPropertyBorderBottomWidth, CSSPropertyBorderBottomStyle,
1574 CSSPropertyBorderBottomColor };
1575 return parseShorthand(propId, properties, 3, important);
1577 case CSSPropertyBorderLeft:
1578 // [ 'border-left-width' || 'border-style' || <color> ] | inherit
1580 const int properties[3] = { CSSPropertyBorderLeftWidth, CSSPropertyBorderLeftStyle,
1581 CSSPropertyBorderLeftColor };
1582 return parseShorthand(propId, properties, 3, important);
1584 case CSSPropertyOutline:
1585 // [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit
1587 const int properties[3] = { CSSPropertyOutlineWidth, CSSPropertyOutlineStyle,
1588 CSSPropertyOutlineColor };
1589 return parseShorthand(propId, properties, 3, important);
1591 case CSSPropertyBorderColor:
1592 // <color>{1,4} | inherit
1594 const int properties[4] = { CSSPropertyBorderTopColor, CSSPropertyBorderRightColor,
1595 CSSPropertyBorderBottomColor, CSSPropertyBorderLeftColor };
1596 return parse4Values(propId, properties, important);
1598 case CSSPropertyBorderWidth:
1599 // <border-width>{1,4} | inherit
1601 const int properties[4] = { CSSPropertyBorderTopWidth, CSSPropertyBorderRightWidth,
1602 CSSPropertyBorderBottomWidth, CSSPropertyBorderLeftWidth };
1603 return parse4Values(propId, properties, important);
1605 case CSSPropertyBorderStyle:
1606 // <border-style>{1,4} | inherit
1608 const int properties[4] = { CSSPropertyBorderTopStyle, CSSPropertyBorderRightStyle,
1609 CSSPropertyBorderBottomStyle, CSSPropertyBorderLeftStyle };
1610 return parse4Values(propId, properties, important);
1612 case CSSPropertyMargin:
1613 // <margin-width>{1,4} | inherit
1615 const int properties[4] = { CSSPropertyMarginTop, CSSPropertyMarginRight,
1616 CSSPropertyMarginBottom, CSSPropertyMarginLeft };
1617 return parse4Values(propId, properties, important);
1619 case CSSPropertyPadding:
1620 // <padding-width>{1,4} | inherit
1622 const int properties[4] = { CSSPropertyPaddingTop, CSSPropertyPaddingRight,
1623 CSSPropertyPaddingBottom, CSSPropertyPaddingLeft };
1624 return parse4Values(propId, properties, important);
1626 case CSSPropertyFont:
1627 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
1628 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
1629 if (id >= CSSValueCaption && id <= CSSValueStatusBar)
1630 valid_primitive = true;
1632 return parseFont(important);
1634 case CSSPropertyListStyle:
1636 const int properties[3] = { CSSPropertyListStyleType, CSSPropertyListStylePosition,
1637 CSSPropertyListStyleImage };
1638 return parseShorthand(propId, properties, 3, important);
1640 case CSSPropertyWebkitColumns: {
1641 const int properties[2] = { CSSPropertyWebkitColumnWidth, CSSPropertyWebkitColumnCount };
1642 return parseShorthand(propId, properties, 2, important);
1644 case CSSPropertyWebkitColumnRule: {
1645 const int properties[3] = { CSSPropertyWebkitColumnRuleWidth, CSSPropertyWebkitColumnRuleStyle,
1646 CSSPropertyWebkitColumnRuleColor };
1647 return parseShorthand(propId, properties, 3, important);
1649 case CSSPropertyWebkitTextStroke: {
1650 const int properties[2] = { CSSPropertyWebkitTextStrokeWidth, CSSPropertyWebkitTextStrokeColor };
1651 return parseShorthand(propId, properties, 2, important);
1653 case CSSPropertyWebkitAnimation:
1654 return parseAnimationShorthand(important);
1655 case CSSPropertyWebkitTransition:
1656 return parseTransitionShorthand(important);
1657 case CSSPropertyInvalid:
1659 case CSSPropertyFontStretch:
1660 case CSSPropertyPage:
1661 case CSSPropertyTextLineThrough:
1662 case CSSPropertyTextOverline:
1663 case CSSPropertyTextUnderline:
1664 case CSSPropertyWebkitVariableDeclarationBlock:
1668 return parseSVGValue(propId, important);
1672 if (valid_primitive) {
1674 parsedValue = CSSPrimitiveValue::createIdentifier(id);
1675 else if (value->unit == CSSPrimitiveValue::CSS_STRING)
1676 parsedValue = CSSPrimitiveValue::create(value->string, (CSSPrimitiveValue::UnitTypes) value->unit);
1677 else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
1678 parsedValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
1679 else if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
1680 parsedValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
1681 else if (value->unit >= CSSParserValue::Q_EMS)
1682 parsedValue = CSSQuirkPrimitiveValue::create(value->fValue, CSSPrimitiveValue::CSS_EMS);
1683 m_valueList->next();
1686 if (!m_valueList->current() || inShorthand()) {
1687 addProperty(propId, parsedValue.release(), important);
1694 void CSSParser::addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
1697 if (lval->isValueList())
1698 static_cast<CSSValueList*>(lval.get())->append(rval);
1700 PassRefPtr<CSSValue> oldlVal(lval.release());
1701 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
1702 list->append(oldlVal);
1711 const int cMaxFillProperties = 9;
1713 bool CSSParser::parseFillShorthand(int propId, const int* properties, int numProperties, bool important)
1715 ASSERT(numProperties <= cMaxFillProperties);
1716 if (numProperties > cMaxFillProperties)
1719 ShorthandScope scope(this, propId);
1721 bool parsedProperty[cMaxFillProperties] = { false };
1722 RefPtr<CSSValue> values[cMaxFillProperties];
1723 RefPtr<CSSValue> clipValue;
1724 RefPtr<CSSValue> positionYValue;
1725 RefPtr<CSSValue> repeatYValue;
1728 while (m_valueList->current()) {
1729 CSSParserValue* val = m_valueList->current();
1730 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
1731 // We hit the end. Fill in all remaining values with the initial value.
1732 m_valueList->next();
1733 for (i = 0; i < numProperties; ++i) {
1734 if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i])
1735 // Color is not allowed except as the last item in a list for backgrounds.
1736 // Reject the entire property.
1739 if (!parsedProperty[i] && properties[i] != CSSPropertyBackgroundColor) {
1740 addFillValue(values[i], CSSInitialValue::createImplicit());
1741 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
1742 addFillValue(positionYValue, CSSInitialValue::createImplicit());
1743 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
1744 addFillValue(repeatYValue, CSSInitialValue::createImplicit());
1745 if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) {
1746 // If background-origin wasn't present, then reset background-clip also.
1747 addFillValue(clipValue, CSSInitialValue::createImplicit());
1750 parsedProperty[i] = false;
1752 if (!m_valueList->current())
1757 for (i = 0; !found && i < numProperties; ++i) {
1758 if (!parsedProperty[i]) {
1759 RefPtr<CSSValue> val1;
1760 RefPtr<CSSValue> val2;
1761 int propId1, propId2;
1762 if (parseFillProperty(properties[i], propId1, propId2, val1, val2)) {
1763 parsedProperty[i] = found = true;
1764 addFillValue(values[i], val1.release());
1765 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
1766 addFillValue(positionYValue, val2.release());
1767 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
1768 addFillValue(repeatYValue, val2.release());
1769 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
1770 // Reparse the value as a clip, and see if we succeed.
1771 if (parseFillProperty(CSSPropertyBackgroundClip, propId1, propId2, val1, val2))
1772 addFillValue(clipValue, val1.release()); // The property parsed successfully.
1774 addFillValue(clipValue, CSSInitialValue::createImplicit()); // Some value was used for origin that is not supported by clip. Just reset clip instead.
1780 // if we didn't find at least one match, this is an
1781 // invalid shorthand and we have to ignore it
1786 // Fill in any remaining properties with the initial value.
1787 for (i = 0; i < numProperties; ++i) {
1788 if (!parsedProperty[i]) {
1789 addFillValue(values[i], CSSInitialValue::createImplicit());
1790 if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
1791 addFillValue(positionYValue, CSSInitialValue::createImplicit());
1792 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
1793 addFillValue(repeatYValue, CSSInitialValue::createImplicit());
1794 if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) {
1795 // If background-origin wasn't present, then reset background-clip also.
1796 addFillValue(clipValue, CSSInitialValue::createImplicit());
1801 // Now add all of the properties we found.
1802 for (i = 0; i < numProperties; i++) {
1803 if (properties[i] == CSSPropertyBackgroundPosition) {
1804 addProperty(CSSPropertyBackgroundPositionX, values[i].release(), important);
1805 // it's OK to call positionYValue.release() since we only see CSSPropertyBackgroundPosition once
1806 addProperty(CSSPropertyBackgroundPositionY, positionYValue.release(), important);
1807 } else if (properties[i] == CSSPropertyWebkitMaskPosition) {
1808 addProperty(CSSPropertyWebkitMaskPositionX, values[i].release(), important);
1809 // it's OK to call positionYValue.release() since we only see CSSPropertyWebkitMaskPosition once
1810 addProperty(CSSPropertyWebkitMaskPositionY, positionYValue.release(), important);
1811 } else if (properties[i] == CSSPropertyBackgroundRepeat) {
1812 addProperty(CSSPropertyBackgroundRepeatX, values[i].release(), important);
1813 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
1814 addProperty(CSSPropertyBackgroundRepeatY, repeatYValue.release(), important);
1815 } else if (properties[i] == CSSPropertyWebkitMaskRepeat) {
1816 addProperty(CSSPropertyWebkitMaskRepeatX, values[i].release(), important);
1817 // it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once
1818 addProperty(CSSPropertyWebkitMaskRepeatY, repeatYValue.release(), important);
1820 addProperty(properties[i], values[i].release(), important);
1822 // Add in clip values when we hit the corresponding origin property.
1823 if (properties[i] == CSSPropertyBackgroundOrigin)
1824 addProperty(CSSPropertyBackgroundClip, clipValue.release(), important);
1825 else if (properties[i] == CSSPropertyWebkitMaskOrigin)
1826 addProperty(CSSPropertyWebkitMaskClip, clipValue.release(), important);
1832 void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
1835 if (lval->isValueList())
1836 static_cast<CSSValueList*>(lval.get())->append(rval);
1838 PassRefPtr<CSSValue> oldVal(lval.release());
1839 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
1840 list->append(oldVal);
1849 bool CSSParser::parseAnimationShorthand(bool important)
1851 const int properties[] = { CSSPropertyWebkitAnimationName,
1852 CSSPropertyWebkitAnimationDuration,
1853 CSSPropertyWebkitAnimationTimingFunction,
1854 CSSPropertyWebkitAnimationDelay,
1855 CSSPropertyWebkitAnimationIterationCount,
1856 CSSPropertyWebkitAnimationDirection };
1857 const int numProperties = sizeof(properties) / sizeof(properties[0]);
1859 ShorthandScope scope(this, CSSPropertyWebkitAnimation);
1861 bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary
1862 RefPtr<CSSValue> values[numProperties];
1865 while (m_valueList->current()) {
1866 CSSParserValue* val = m_valueList->current();
1867 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
1868 // We hit the end. Fill in all remaining values with the initial value.
1869 m_valueList->next();
1870 for (i = 0; i < numProperties; ++i) {
1871 if (!parsedProperty[i])
1872 addAnimationValue(values[i], CSSInitialValue::createImplicit());
1873 parsedProperty[i] = false;
1875 if (!m_valueList->current())
1880 for (i = 0; !found && i < numProperties; ++i) {
1881 if (!parsedProperty[i]) {
1882 RefPtr<CSSValue> val;
1883 if (parseAnimationProperty(properties[i], val)) {
1884 parsedProperty[i] = found = true;
1885 addAnimationValue(values[i], val.release());
1890 // if we didn't find at least one match, this is an
1891 // invalid shorthand and we have to ignore it
1896 // Fill in any remaining properties with the initial value.
1897 for (i = 0; i < numProperties; ++i) {
1898 if (!parsedProperty[i])
1899 addAnimationValue(values[i], CSSInitialValue::createImplicit());
1902 // Now add all of the properties we found.
1903 for (i = 0; i < numProperties; i++)
1904 addProperty(properties[i], values[i].release(), important);
1909 bool CSSParser::parseTransitionShorthand(bool important)
1911 const int properties[] = { CSSPropertyWebkitTransitionProperty,
1912 CSSPropertyWebkitTransitionDuration,
1913 CSSPropertyWebkitTransitionTimingFunction,
1914 CSSPropertyWebkitTransitionDelay };
1915 const int numProperties = sizeof(properties) / sizeof(properties[0]);
1917 ShorthandScope scope(this, CSSPropertyWebkitTransition);
1919 bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary
1920 RefPtr<CSSValue> values[numProperties];
1923 while (m_valueList->current()) {
1924 CSSParserValue* val = m_valueList->current();
1925 if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
1926 // We hit the end. Fill in all remaining values with the initial value.
1927 m_valueList->next();
1928 for (i = 0; i < numProperties; ++i) {
1929 if (!parsedProperty[i])
1930 addAnimationValue(values[i], CSSInitialValue::createImplicit());
1931 parsedProperty[i] = false;
1933 if (!m_valueList->current())
1938 for (i = 0; !found && i < numProperties; ++i) {
1939 if (!parsedProperty[i]) {
1940 RefPtr<CSSValue> val;
1941 if (parseAnimationProperty(properties[i], val)) {
1942 parsedProperty[i] = found = true;
1943 addAnimationValue(values[i], val.release());
1948 // if we didn't find at least one match, this is an
1949 // invalid shorthand and we have to ignore it
1954 // Fill in any remaining properties with the initial value.
1955 for (i = 0; i < numProperties; ++i) {
1956 if (!parsedProperty[i])
1957 addAnimationValue(values[i], CSSInitialValue::createImplicit());
1960 // Now add all of the properties we found.
1961 for (i = 0; i < numProperties; i++)
1962 addProperty(properties[i], values[i].release(), important);
1967 bool CSSParser::parseShorthand(int propId, const int *properties, int numProperties, bool important)
1969 // We try to match as many properties as possible
1970 // We set up an array of booleans to mark which property has been found,
1971 // and we try to search for properties until it makes no longer any sense.
1972 ShorthandScope scope(this, propId);
1975 bool fnd[6]; // Trust me ;)
1976 for (int i = 0; i < numProperties; i++)
1979 while (m_valueList->current()) {
1981 for (int propIndex = 0; !found && propIndex < numProperties; ++propIndex) {
1982 if (!fnd[propIndex]) {
1983 if (parseValue(properties[propIndex], important))
1984 fnd[propIndex] = found = true;
1988 // if we didn't find at least one match, this is an
1989 // invalid shorthand and we have to ignore it
1994 // Fill in any remaining properties with the initial value.
1995 m_implicitShorthand = true;
1996 for (int i = 0; i < numProperties; ++i) {
1998 addProperty(properties[i], CSSInitialValue::createImplicit(), important);
2000 m_implicitShorthand = false;
2005 bool CSSParser::parse4Values(int propId, const int *properties, bool important)
2007 /* From the CSS 2 specs, 8.3
2008 * If there is only one value, it applies to all sides. If there are two values, the top and
2009 * bottom margins are set to the first value and the right and left margins are set to the second.
2010 * If there are three values, the top is set to the first value, the left and right are set to the
2011 * second, and the bottom is set to the third. If there are four values, they apply to the top,
2012 * right, bottom, and left, respectively.
2015 int num = inShorthand() ? 1 : m_valueList->size();
2017 ShorthandScope scope(this, propId);
2019 // the order is top, right, bottom, left
2022 if (!parseValue(properties[0], important))
2024 CSSValue *value = m_parsedProperties[m_numParsedProperties-1]->value();
2025 m_implicitShorthand = true;
2026 addProperty(properties[1], value, important);
2027 addProperty(properties[2], value, important);
2028 addProperty(properties[3], value, important);
2029 m_implicitShorthand = false;
2033 if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
2035 CSSValue *value = m_parsedProperties[m_numParsedProperties-2]->value();
2036 m_implicitShorthand = true;
2037 addProperty(properties[2], value, important);
2038 value = m_parsedProperties[m_numParsedProperties-2]->value();
2039 addProperty(properties[3], value, important);
2040 m_implicitShorthand = false;
2044 if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || !parseValue(properties[2], important))
2046 CSSValue *value = m_parsedProperties[m_numParsedProperties-2]->value();
2047 m_implicitShorthand = true;
2048 addProperty(properties[3], value, important);
2049 m_implicitShorthand = false;
2053 if (!parseValue(properties[0], important) || !parseValue(properties[1], important) ||
2054 !parseValue(properties[2], important) || !parseValue(properties[3], important))
2066 // [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
2067 // in CSS 2.1 this got somewhat reduced:
2068 // [ <string> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
2069 bool CSSParser::parseContent(int propId, bool important)
2071 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
2073 while (CSSParserValue* val = m_valueList->current()) {
2074 RefPtr<CSSValue> parsedValue;
2075 if (val->unit == CSSPrimitiveValue::CSS_URI && m_styleSheet) {
2077 // FIXME: The completeURL call should be done when using the CSSImageValue,
2078 // not when creating it.
2079 parsedValue = CSSImageValue::create(m_styleSheet->completeURL(val->string));
2080 } else if (val->unit == CSSParserValue::Function) {
2081 // attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradient(...)
2082 CSSParserValueList* args = val->function->args;
2085 if (equalIgnoringCase(val->function->name, "attr(")) {
2086 parsedValue = parseAttr(args);
2089 } else if (equalIgnoringCase(val->function->name, "counter(")) {
2090 parsedValue = parseCounterContent(args, false);
2093 } else if (equalIgnoringCase(val->function->name, "counters(")) {
2094 parsedValue = parseCounterContent(args, true);
2097 } else if (equalIgnoringCase(val->function->name, "-webkit-gradient(")) {
2098 if (!parseGradient(parsedValue))
2100 } else if (equalIgnoringCase(val->function->name, "-webkit-canvas(")) {
2101 if (!parseCanvas(parsedValue))
2105 } else if (val->unit == CSSPrimitiveValue::CSS_IDENT) {
2110 // FIXME: These are not yet implemented (http://bugs.webkit.org/show_bug.cgi?id=6503).
2111 } else if (val->unit == CSSPrimitiveValue::CSS_STRING) {
2112 parsedValue = CSSPrimitiveValue::create(val->string, CSSPrimitiveValue::CSS_STRING);
2116 values->append(parsedValue.release());
2117 m_valueList->next();
2120 if (values->length()) {
2121 addProperty(propId, values.release(), important);
2122 m_valueList->next();
2129 PassRefPtr<CSSValue> CSSParser::parseAttr(CSSParserValueList* args)
2131 if (args->size() != 1)
2134 CSSParserValue* a = args->current();
2136 if (a->unit != CSSPrimitiveValue::CSS_IDENT)
2139 String attrName = a->string;
2140 // CSS allows identifiers with "-" at the start, like "-webkit-mask-image".
2141 // But HTML attribute names can't have those characters, and we should not
2142 // even parse them inside attr().
2143 if (attrName[0] == '-')
2146 if (document()->isHTMLDocument())
2147 attrName = attrName.lower();
2149 return CSSPrimitiveValue::create(attrName, CSSPrimitiveValue::CSS_ATTR);
2152 PassRefPtr<CSSValue> CSSParser::parseBackgroundColor()
2154 int id = m_valueList->current()->id;
2155 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor ||
2156 (id >= CSSValueGrey && id < CSSValueWebkitText && !m_strict))
2157 return CSSPrimitiveValue::createIdentifier(id);
2158 return parseColor();
2161 bool CSSParser::parseFillImage(RefPtr<CSSValue>& value)
2163 if (m_valueList->current()->id == CSSValueNone) {
2164 value = CSSImageValue::create();
2167 if (m_valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
2168 // FIXME: The completeURL call should be done when using the CSSImageValue,
2169 // not when creating it.
2171 value = CSSImageValue::create(m_styleSheet->completeURL(m_valueList->current()->string));
2175 if (m_valueList->current()->unit == CSSParserValue::Function) {
2176 if (equalIgnoringCase(m_valueList->current()->function->name, "-webkit-gradient("))
2177 return parseGradient(value);
2178 if (equalIgnoringCase(m_valueList->current()->function->name, "-webkit-canvas("))
2179 return parseCanvas(value);
2185 PassRefPtr<CSSValue> CSSParser::parseFillPositionXY(bool& xFound, bool& yFound)
2187 int id = m_valueList->current()->id;
2188 if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id == CSSValueBottom || id == CSSValueCenter) {
2190 if (id == CSSValueLeft || id == CSSValueRight) {
2194 if (id == CSSValueRight)
2197 else if (id == CSSValueTop || id == CSSValueBottom) {
2201 if (id == CSSValueBottom)
2204 else if (id == CSSValueCenter)
2205 // Center is ambiguous, so we're not sure which position we've found yet, an x or a y.
2207 return CSSPrimitiveValue::create(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
2209 if (validUnit(m_valueList->current(), FPercent|FLength, m_strict))
2210 return CSSPrimitiveValue::create(m_valueList->current()->fValue,
2211 (CSSPrimitiveValue::UnitTypes)m_valueList->current()->unit);
2216 void CSSParser::parseFillPosition(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2)
2218 CSSParserValue* value = m_valueList->current();
2220 // Parse the first value. We're just making sure that it is one of the valid keywords or a percentage/length.
2221 bool value1IsX = false, value1IsY = false;
2222 value1 = parseFillPositionXY(value1IsX, value1IsY);
2226 // It only takes one value for background-position to be correctly parsed if it was specified in a shorthand (since we
2227 // can assume that any other values belong to the rest of the shorthand). If we're not parsing a shorthand, though, the
2228 // value was explicitly specified for our property.
2229 value = m_valueList->next();
2231 // First check for the comma. If so, we are finished parsing this value or value pair.
2232 if (value && value->unit == CSSParserValue::Operator && value->iValue == ',')
2235 bool value2IsX = false, value2IsY = false;
2237 value2 = parseFillPositionXY(value2IsX, value2IsY);
2239 m_valueList->next();
2241 if (!inShorthand()) {
2249 // Only one value was specified. If that value was not a keyword, then it sets the x position, and the y position
2250 // is simply 50%. This is our default.
2251 // For keywords, the keyword was either an x-keyword (left/right), a y-keyword (top/bottom), or an ambiguous keyword (center).
2252 // For left/right/center, the default of 50% in the y is still correct.
2253 value2 = CSSPrimitiveValue::create(50, CSSPrimitiveValue::CSS_PERCENTAGE);
2255 if (value1IsY || value2IsX)
2256 value1.swap(value2);
2259 void CSSParser::parseFillRepeat(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2)
2261 CSSParserValue* value = m_valueList->current();
2263 int id = m_valueList->current()->id;
2264 if (id == CSSValueRepeatX) {
2265 m_implicitShorthand = true;
2266 value1 = CSSPrimitiveValue::createIdentifier(CSSValueRepeat);
2267 value2 = CSSPrimitiveValue::createIdentifier(CSSValueNoRepeat);
2268 m_valueList->next();
2271 if (id == CSSValueRepeatY) {
2272 m_implicitShorthand = true;
2273 value1 = CSSPrimitiveValue::createIdentifier(CSSValueNoRepeat);
2274 value2 = CSSPrimitiveValue::createIdentifier(CSSValueRepeat);
2275 m_valueList->next();
2278 if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRound || id == CSSValueSpace)
2279 value1 = CSSPrimitiveValue::createIdentifier(id);
2285 value = m_valueList->next();
2287 // First check for the comma. If so, we are finished parsing this value or value pair.
2288 if (value && value->unit == CSSParserValue::Operator && value->iValue == ',')
2292 id = m_valueList->current()->id;
2294 if (value && (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRound || id == CSSValueSpace)) {
2295 value2 = CSSPrimitiveValue::createIdentifier(id);
2296 m_valueList->next();
2298 // If only one value was specified, value2 is the same as value1.
2299 m_implicitShorthand = true;
2300 value2 = CSSPrimitiveValue::createIdentifier(static_cast<CSSPrimitiveValue*>(value1.get())->getIdent());
2304 PassRefPtr<CSSValue> CSSParser::parseFillSize(bool& allowComma)
2307 CSSParserValue* value = m_valueList->current();
2309 if (value->id == CSSValueContain || value->id == CSSValueCover)
2310 return CSSPrimitiveValue::createIdentifier(value->id);
2312 RefPtr<CSSPrimitiveValue> parsedValue1;
2314 if (value->id == CSSValueAuto)
2315 parsedValue1 = CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_UNKNOWN);
2317 if (!validUnit(value, FLength|FPercent, m_strict))
2319 parsedValue1 = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
2322 RefPtr<CSSPrimitiveValue> parsedValue2 = parsedValue1;
2323 if ((value = m_valueList->next())) {
2324 if (value->id == CSSValueAuto)
2325 parsedValue2 = CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_UNKNOWN);
2326 else if (value->unit == CSSParserValue::Operator && value->iValue == ',')
2329 if (!validUnit(value, FLength|FPercent, m_strict))
2331 parsedValue2 = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
2335 return CSSPrimitiveValue::create(Pair::create(parsedValue1.release(), parsedValue2.release()));
2338 bool CSSParser::parseFillProperty(int propId, int& propId1, int& propId2,
2339 RefPtr<CSSValue>& retValue1, RefPtr<CSSValue>& retValue2)
2341 RefPtr<CSSValueList> values;
2342 RefPtr<CSSValueList> values2;
2343 CSSParserValue* val;
2344 RefPtr<CSSValue> value;
2345 RefPtr<CSSValue> value2;
2347 bool allowComma = false;
2349 retValue1 = retValue2 = 0;
2352 if (propId == CSSPropertyBackgroundPosition) {
2353 propId1 = CSSPropertyBackgroundPositionX;
2354 propId2 = CSSPropertyBackgroundPositionY;
2355 } else if (propId == CSSPropertyWebkitMaskPosition) {
2356 propId1 = CSSPropertyWebkitMaskPositionX;
2357 propId2 = CSSPropertyWebkitMaskPositionY;
2358 } else if (propId == CSSPropertyBackgroundRepeat) {
2359 propId1 = CSSPropertyBackgroundRepeatX;
2360 propId2 = CSSPropertyBackgroundRepeatY;
2361 } else if (propId == CSSPropertyWebkitMaskRepeat) {
2362 propId1 = CSSPropertyWebkitMaskRepeatX;
2363 propId2 = CSSPropertyWebkitMaskRepeatY;
2366 while ((val = m_valueList->current())) {
2367 RefPtr<CSSValue> currValue;
2368 RefPtr<CSSValue> currValue2;
2371 if (val->unit != CSSParserValue::Operator || val->iValue != ',')
2373 m_valueList->next();
2378 case CSSPropertyBackgroundColor:
2379 currValue = parseBackgroundColor();
2381 m_valueList->next();
2383 case CSSPropertyBackgroundAttachment:
2384 case CSSPropertyWebkitMaskAttachment:
2385 if (val->id == CSSValueScroll || val->id == CSSValueFixed || val->id == CSSValueLocal) {
2386 currValue = CSSPrimitiveValue::createIdentifier(val->id);
2387 m_valueList->next();
2390 case CSSPropertyBackgroundImage:
2391 case CSSPropertyWebkitMaskImage:
2392 if (parseFillImage(currValue))
2393 m_valueList->next();
2395 case CSSPropertyWebkitBackgroundClip:
2396 case CSSPropertyWebkitBackgroundOrigin:
2397 case CSSPropertyWebkitMaskClip:
2398 case CSSPropertyWebkitMaskOrigin:
2399 // The first three values here are deprecated and do not apply to the version of the property that has
2400 // the -webkit- prefix removed.
2401 if (val->id == CSSValueBorder || val->id == CSSValuePadding || val->id == CSSValueContent ||
2402 val->id == CSSValueBorderBox || val->id == CSSValuePaddingBox || val->id == CSSValueContentBox ||
2403 ((propId == CSSPropertyWebkitBackgroundClip || propId == CSSPropertyWebkitMaskClip) &&
2404 (val->id == CSSValueText || val->id == CSSValueWebkitText))) {
2405 currValue = CSSPrimitiveValue::createIdentifier(val->id);
2406 m_valueList->next();
2409 case CSSPropertyBackgroundClip:
2410 if (val->id == CSSValueBorderBox || val->id == CSSValuePaddingBox || val->id == CSSValueWebkitText) {
2411 currValue = CSSPrimitiveValue::createIdentifier(val->id);
2412 m_valueList->next();
2415 case CSSPropertyBackgroundOrigin:
2416 if (val->id == CSSValueBorderBox || val->id == CSSValuePaddingBox || val->id == CSSValueContentBox) {
2417 currValue = CSSPrimitiveValue::createIdentifier(val->id);
2418 m_valueList->next();
2421 case CSSPropertyBackgroundPosition:
2422 case CSSPropertyWebkitMaskPosition:
2423 parseFillPosition(currValue, currValue2);
2424 // parseFillPosition advances the m_valueList pointer
2426 case CSSPropertyBackgroundPositionX:
2427 case CSSPropertyWebkitMaskPositionX: {
2428 bool xFound = false, yFound = true;
2429 currValue = parseFillPositionXY(xFound, yFound);
2431 m_valueList->next();
2434 case CSSPropertyBackgroundPositionY:
2435 case CSSPropertyWebkitMaskPositionY: {
2436 bool xFound = true, yFound = false;
2437 currValue = parseFillPositionXY(xFound, yFound);
2439 m_valueList->next();
2442 case CSSPropertyWebkitBackgroundComposite:
2443 case CSSPropertyWebkitMaskComposite:
2444 if ((val->id >= CSSValueClear && val->id <= CSSValuePlusLighter) || val->id == CSSValueHighlight) {
2445 currValue = CSSPrimitiveValue::createIdentifier(val->id);
2446 m_valueList->next();
2449 case CSSPropertyBackgroundRepeat:
2450 case CSSPropertyWebkitMaskRepeat:
2451 parseFillRepeat(currValue, currValue2);
2452 // parseFillRepeat advances the m_valueList pointer
2454 case CSSPropertyBackgroundSize:
2455 case CSSPropertyWebkitMaskSize: {
2456 currValue = parseFillSize(allowComma);
2458 m_valueList->next();
2465 if (value && !values) {
2466 values = CSSValueList::createCommaSeparated();
2467 values->append(value.release());
2470 if (value2 && !values2) {
2471 values2 = CSSValueList::createCommaSeparated();
2472 values2->append(value2.release());
2476 values->append(currValue.release());
2478 value = currValue.release();
2481 values2->append(currValue2.release());
2483 value2 = currValue2.release();
2487 // When parsing any fill shorthand property, we let it handle building up the lists for all
2493 if (values && values->length()) {
2494 retValue1 = values.release();
2495 if (values2 && values2->length())
2496 retValue2 = values2.release();
2500 retValue1 = value.release();
2501 retValue2 = value2.release();
2507 PassRefPtr<CSSValue> CSSParser::parseAnimationDelay()
2509 CSSParserValue* value = m_valueList->current();
2510 if (validUnit(value, FTime, m_strict))
2511 return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
2515 PassRefPtr<CSSValue> CSSParser::parseAnimationDirection()
2517 CSSParserValue* value = m_valueList->current();
2518 if (value->id == CSSValueNormal || value->id == CSSValueAlternate)
2519 return CSSPrimitiveValue::createIdentifier(value->id);
2523 PassRefPtr<CSSValue> CSSParser::parseAnimationDuration()
2525 CSSParserValue* value = m_valueList->current();
2526 if (validUnit(value, FTime|FNonNeg, m_strict))
2527 return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
2531 PassRefPtr<CSSValue> CSSParser::parseAnimationIterationCount()
2533 CSSParserValue* value = m_valueList->current();
2534 if (value->id == CSSValueInfinite)
2535 return CSSPrimitiveValue::createIdentifier(value->id);
2536 if (validUnit(value, FInteger|FNonNeg, m_strict))
2537 return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
2541 PassRefPtr<CSSValue> CSSParser::parseAnimationName()
2543 CSSParserValue* value = m_valueList->current();
2544 if (value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT) {
2545 if (value->id == CSSValueNone || (value->unit == CSSPrimitiveValue::CSS_STRING && equalIgnoringCase(value->string, "none"))) {
2546 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
2548 return CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_STRING);
2554 PassRefPtr<CSSValue> CSSParser::parseAnimationPlayState()
2556 CSSParserValue* value = m_valueList->current();
2557 if (value->id == CSSValueRunning || value->id == CSSValuePaused)
2558 return CSSPrimitiveValue::createIdentifier(value->id);
2562 PassRefPtr<CSSValue> CSSParser::parseAnimationProperty()
2564 CSSParserValue* value = m_valueList->current();
2565 if (value->unit != CSSPrimitiveValue::CSS_IDENT)
2567 int result = cssPropertyID(value->string);
2569 return CSSPrimitiveValue::createIdentifier(result);
2570 if (equalIgnoringCase(value->string, "all"))
2571 return CSSPrimitiveValue::createIdentifier(CSSValueAll);
2572 if (equalIgnoringCase(value->string, "none"))
2573 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
2577 void CSSParser::parseTransformOriginShorthand(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2, RefPtr<CSSValue>& value3)
2579 parseFillPosition(value1, value2);
2582 if (m_valueList->current() && validUnit(m_valueList->current(), FLength, m_strict))
2583 value3 = CSSPrimitiveValue::create(m_valueList->current()->fValue,
2584 (CSSPrimitiveValue::UnitTypes)m_valueList->current()->unit);
2586 m_valueList->next();
2589 bool CSSParser::parseTimingFunctionValue(CSSParserValueList*& args, double& result)
2591 CSSParserValue* v = args->current();
2592 if (!validUnit(v, FNumber, m_strict))
2595 if (result < 0 || result > 1.0)
2599 // The last number in the function has no comma after it, so we're done.
2601 if (v->unit != CSSParserValue::Operator && v->iValue != ',')
2607 PassRefPtr<CSSValue> CSSParser::parseAnimationTimingFunction()
2609 CSSParserValue* value = m_valueList->current();
2610 if (value->id == CSSValueEase || value->id == CSSValueLinear || value->id == CSSValueEaseIn || value->id == CSSValueEaseOut || value->id == CSSValueEaseInOut)
2611 return CSSPrimitiveValue::createIdentifier(value->id);
2613 // We must be a function.
2614 if (value->unit != CSSParserValue::Function)
2617 // The only timing function we accept for now is a cubic bezier function. 4 points must be specified.
2618 CSSParserValueList* args = value->function->args;
2619 if (!equalIgnoringCase(value->function->name, "cubic-bezier(") || !args || args->size() != 7)
2622 // There are two points specified. The values must be between 0 and 1.
2623 double x1, y1, x2, y2;
2625 if (!parseTimingFunctionValue(args, x1))
2627 if (!parseTimingFunctionValue(args, y1))
2629 if (!parseTimingFunctionValue(args, x2))
2631 if (!parseTimingFunctionValue(args, y2))
2634 return CSSTimingFunctionValue::create(x1, y1, x2, y2);
2637 bool CSSParser::parseAnimationProperty(int propId, RefPtr<CSSValue>& result)
2639 RefPtr<CSSValueList> values;
2640 CSSParserValue* val;
2641 RefPtr<CSSValue> value;
2642 bool allowComma = false;
2646 while ((val = m_valueList->current())) {
2647 RefPtr<CSSValue> currValue;
2649 if (val->unit != CSSParserValue::Operator || val->iValue != ',')
2651 m_valueList->next();
2656 case CSSPropertyWebkitAnimationDelay:
2657 case CSSPropertyWebkitTransitionDelay:
2658 currValue = parseAnimationDelay();
2660 m_valueList->next();
2662 case CSSPropertyWebkitAnimationDirection:
2663 currValue = parseAnimationDirection();
2665 m_valueList->next();
2667 case CSSPropertyWebkitAnimationDuration:
2668 case CSSPropertyWebkitTransitionDuration:
2669 currValue = parseAnimationDuration();
2671 m_valueList->next();
2673 case CSSPropertyWebkitAnimationIterationCount:
2674 currValue = parseAnimationIterationCount();
2676 m_valueList->next();
2678 case CSSPropertyWebkitAnimationName:
2679 currValue = parseAnimationName();
2681 m_valueList->next();
2683 case CSSPropertyWebkitAnimationPlayState:
2684 currValue = parseAnimationPlayState();
2686 m_valueList->next();
2688 case CSSPropertyWebkitTransitionProperty:
2689 currValue = parseAnimationProperty();
2691 m_valueList->next();
2693 case CSSPropertyWebkitAnimationTimingFunction:
2694 case CSSPropertyWebkitTransitionTimingFunction:
2695 currValue = parseAnimationTimingFunction();
2697 m_valueList->next();
2704 if (value && !values) {
2705 values = CSSValueList::createCommaSeparated();
2706 values->append(value.release());
2710 values->append(currValue.release());
2712 value = currValue.release();
2717 // When parsing the 'transition' shorthand property, we let it handle building up the lists for all
2723 if (values && values->length()) {
2724 result = values.release();
2728 result = value.release();
2736 #if ENABLE(DASHBOARD_SUPPORT)
2738 #define DASHBOARD_REGION_NUM_PARAMETERS 6
2739 #define DASHBOARD_REGION_SHORT_NUM_PARAMETERS 2
2741 static CSSParserValue* skipCommaInDashboardRegion(CSSParserValueList *args)
2743 if (args->size() == (DASHBOARD_REGION_NUM_PARAMETERS*2-1) ||
2744 args->size() == (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1)) {
2745 CSSParserValue* current = args->current();
2746 if (current->unit == CSSParserValue::Operator && current->iValue == ',')
2747 return args->next();
2749 return args->current();
2752 bool CSSParser::parseDashboardRegions(int propId, bool important)
2756 CSSParserValue* value = m_valueList->current();
2758 if (value->id == CSSValueNone) {
2759 if (m_valueList->next())
2761 addProperty(propId, CSSPrimitiveValue::createIdentifier(value->id), important);
2765 RefPtr<DashboardRegion> firstRegion = DashboardRegion::create();
2766 DashboardRegion* region = 0;
2770 region = firstRegion.get();
2772 RefPtr<DashboardRegion> nextRegion = DashboardRegion::create();
2773 region->m_next = nextRegion;
2774 region = nextRegion.get();
2777 if (value->unit != CSSParserValue::Function) {
2782 // Commas count as values, so allow:
2783 // dashboard-region(label, type, t, r, b, l) or dashboard-region(label type t r b l)
2784 // dashboard-region(label, type, t, r, b, l) or dashboard-region(label type t r b l)
2786 // dashboard-region(label, type) or dashboard-region(label type)
2787 // dashboard-region(label, type) or dashboard-region(label type)
2788 CSSParserValueList* args = value->function->args;
2789 if (!equalIgnoringCase(value->function->name, "dashboard-region(") || !args) {
2794 int numArgs = args->size();
2795 if ((numArgs != DASHBOARD_REGION_NUM_PARAMETERS && numArgs != (DASHBOARD_REGION_NUM_PARAMETERS*2-1)) &&
2796 (numArgs != DASHBOARD_REGION_SHORT_NUM_PARAMETERS && numArgs != (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1))) {
2801 // First arg is a label.
2802 CSSParserValue* arg = args->current();
2803 if (arg->unit != CSSPrimitiveValue::CSS_IDENT) {
2808 region->m_label = arg->string;
2810 // Second arg is a type.
2812 arg = skipCommaInDashboardRegion(args);
2813 if (arg->unit != CSSPrimitiveValue::CSS_IDENT) {
2818 if (equalIgnoringCase(arg->string, "circle"))
2819 region->m_isCircle = true;
2820 else if (equalIgnoringCase(arg->string, "rectangle"))
2821 region->m_isRectangle = true;
2827 region->m_geometryType = arg->string;
2829 if (numArgs == DASHBOARD_REGION_SHORT_NUM_PARAMETERS || numArgs == (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1)) {
2830 // This originally used CSSValueInvalid by accident. It might be more logical to use something else.
2831 RefPtr<CSSPrimitiveValue> amount = CSSPrimitiveValue::createIdentifier(CSSValueInvalid);
2833 region->setTop(amount);
2834 region->setRight(amount);
2835 region->setBottom(amount);
2836 region->setLeft(amount);
2838 // Next four arguments must be offset numbers
2840 for (i = 0; i < 4; i++) {
2842 arg = skipCommaInDashboardRegion(args);
2844 valid = arg->id == CSSValueAuto || validUnit(arg, FLength, m_strict);
2848 RefPtr<CSSPrimitiveValue> amount = arg->id == CSSValueAuto ?
2849 CSSPrimitiveValue::createIdentifier(CSSValueAuto) :
2850 CSSPrimitiveValue::create(arg->fValue, (CSSPrimitiveValue::UnitTypes) arg->unit);
2853 region->setTop(amount);
2855 region->setRight(amount);
2857 region->setBottom(amount);
2859 region->setLeft(amount);
2866 value = m_valueList->next();
2870 addProperty(propId, CSSPrimitiveValue::create(firstRegion.release()), important);
2875 #endif /* ENABLE(DASHBOARD_SUPPORT) */
2877 PassRefPtr<CSSValue> CSSParser::parseCounterContent(CSSParserValueList* args, bool counters)
2879 unsigned numArgs = args->size();
2880 if (counters && numArgs != 3 && numArgs != 5)
2882 if (!counters && numArgs != 1 && numArgs != 3)
2885 CSSParserValue* i = args->current();
2886 if (i->unit != CSSPrimitiveValue::CSS_IDENT)
2888 RefPtr<CSSPrimitiveValue> identifier = CSSPrimitiveValue::create(i->string, CSSPrimitiveValue::CSS_STRING);
2890 RefPtr<CSSPrimitiveValue> separator;
2892 separator = CSSPrimitiveValue::create(String(), CSSPrimitiveValue::CSS_STRING);
2895 if (i->unit != CSSParserValue::Operator || i->iValue != ',')
2899 if (i->unit != CSSPrimitiveValue::CSS_STRING)
2902 separator = CSSPrimitiveValue::create(i->string, (CSSPrimitiveValue::UnitTypes) i->unit);
2905 RefPtr<CSSPrimitiveValue> listStyle;
2907 if (!i) // Make the list style default decimal
2908 listStyle = CSSPrimitiveValue::create(CSSValueDecimal - CSSValueDisc, CSSPrimitiveValue::CSS_NUMBER);
2910 if (i->unit != CSSParserValue::Operator || i->iValue != ',')
2914 if (i->unit != CSSPrimitiveValue::CSS_IDENT)
2918 if (i->id == CSSValueNone)
2919 ls = CSSValueKatakanaIroha - CSSValueDisc + 1;
2920 else if (i->id >= CSSValueDisc && i->id <= CSSValueKatakanaIroha)
2921 ls = i->id - CSSValueDisc;
2925 listStyle = CSSPrimitiveValue::create(ls, (CSSPrimitiveValue::UnitTypes) i->unit);
2928 return CSSPrimitiveValue::create(Counter::create(identifier.release(), listStyle.release(), separator.release()));
2931 bool CSSParser::parseShape(int propId, bool important)
2933 CSSParserValue* value = m_valueList->current();
2934 CSSParserValueList* args = value->function->args;
2936 if (!equalIgnoringCase(value->function->name, "rect(") || !args)
2939 // rect(t, r, b, l) || rect(t r b l)
2940 if (args->size() != 4 && args->size() != 7)
2942 RefPtr<Rect> rect = Rect::create();
2945 CSSParserValue* a = args->current();
2947 valid = a->id == CSSValueAuto || validUnit(a, FLength, m_strict);
2950 RefPtr<CSSPrimitiveValue> length = a->id == CSSValueAuto ?
2951 CSSPrimitiveValue::createIdentifier(CSSValueAuto) :
2952 CSSPrimitiveValue::create(a->fValue, (CSSPrimitiveValue::UnitTypes) a->unit);
2954 rect->setTop(length);
2956 rect->setRight(length);
2958 rect->setBottom(length);
2960 rect->setLeft(length);
2962 if (a && args->size() == 7) {
2963 if (a->unit == CSSParserValue::Operator && a->iValue == ',') {
2973 addProperty(propId, CSSPrimitiveValue::create(rect.release()), important);
2974 m_valueList->next();
2980 // [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 'font-family'
2981 bool CSSParser::parseFont(bool important)
2984 CSSParserValue *value = m_valueList->current();
2985 RefPtr<FontValue> font = FontValue::create();
2986 // optional font-style, font-variant and font-weight
2990 if (id == CSSValueNormal) {
2991 // do nothing, it's the inital value for all three
2992 } else if (id == CSSValueItalic || id == CSSValueOblique) {
2995 font->style = CSSPrimitiveValue::createIdentifier(id);
2996 } else if (id == CSSValueSmallCaps) {
2999 font->variant = CSSPrimitiveValue::createIdentifier(id);
3000 } else if (id >= CSSValueBold && id <= CSSValueLighter) {
3003 font->weight = CSSPrimitiveValue::createIdentifier(id);
3007 } else if (!font->weight && validUnit(value, FInteger|FNonNeg, true)) {
3008 int weight = (int)value->fValue;
3012 else if (weight == 200)
3014 else if (weight == 300)
3016 else if (weight == 400)
3018 else if (weight == 500)
3020 else if (weight == 600)
3022 else if (weight == 700)
3024 else if (weight == 800)
3026 else if (weight == 900)
3030 font->weight = CSSPrimitiveValue::createIdentifier(val);
3038 value = m_valueList->next();
3043 // set undefined values to default
3045 font->style = CSSPrimitiveValue::createIdentifier(CSSValueNormal);
3047 font->variant = CSSPrimitiveValue::createIdentifier(CSSValueNormal);
3049 font->weight = CSSPrimitiveValue::createIdentifier(CSSValueNormal);
3051 // now a font size _must_ come
3052 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit
3053 if (value->id >= CSSValueXxSmall && value->id <= CSSValueLarger)
3054 font->size = CSSPrimitiveValue::createIdentifier(value->id);
3055 else if (validUnit(value, FLength|FPercent|FNonNeg, m_strict))
3056 font->size = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
3057 value = m_valueList->next();
3058 if (!font->size || !value)
3061 if (value->unit == CSSParserValue::Operator && value->iValue == '/') {
3063 value = m_valueList->next();
3066 if (value->id == CSSValueNormal) {
3067 // default value, nothing to do
3068 } else if (validUnit(value, FNumber|FLength|FPercent|FNonNeg, m_strict))
3069 font->lineHeight = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
3072 value = m_valueList->next();
3077 if (!font->lineHeight)
3078 font->lineHeight = CSSPrimitiveValue::createIdentifier(CSSValueNormal);
3080 // font family must come now
3081 font->family = parseFontFamily();
3083 if (m_valueList->current() || !font->family)
3086 addProperty(CSSPropertyFont, font.release(), important);
3090 PassRefPtr<CSSValueList> CSSParser::parseFontFamily()
3092 RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3093 CSSParserValue* value = m_valueList->current();
3095 FontFamilyValue* currFamily = 0;
3097 CSSParserValue* nextValue = m_valueList->next();
3098 bool nextValBreaksFont = !nextValue ||
3099 (nextValue->unit == CSSParserValue::Operator && nextValue->iValue == ',');
3100 bool nextValIsFontName = nextValue &&
3101 ((nextValue->id >= CSSValueSerif && nextValue->id <= CSSValueWebkitBody) ||
3102 (nextValue->unit == CSSPrimitiveValue::CSS_STRING || nextValue->unit == CSSPrimitiveValue::CSS_IDENT));
3104 if (value->id >= CSSValueSerif && value->id <= CSSValueWebkitBody) {
3106 currFamily->appendSpaceSeparated(value->string.characters, value->string.length);
3107 else if (nextValBreaksFont || !nextValIsFontName)
3108 list->append(CSSPrimitiveValue::createIdentifier(value->id));
3110 RefPtr<FontFamilyValue> newFamily = FontFamilyValue::create(value->string);
3111 currFamily = newFamily.get();
3112 list->append(newFamily.release());
3114 } else if (value->unit == CSSPrimitiveValue::CSS_STRING) {
3115 // Strings never share in a family name.
3117 list->append(FontFamilyValue::create(value->string));
3118 } else if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
3120 currFamily->appendSpaceSeparated(value->string.characters, value->string.length);
3121 else if (nextValBreaksFont || !nextValIsFontName)
3122 list->append(FontFamilyValue::create(value->string));
3124 RefPtr<FontFamilyValue> newFamily = FontFamilyValue::create(value->string);
3125 currFamily = newFamily.get();
3126 list->append(newFamily.release());
3135 if (nextValBreaksFont) {
3136 value = m_valueList->next();
3139 else if (nextValIsFontName)
3144 if (!list->length())
3146 return list.release();
3149 bool CSSParser::parseFontStyle(bool important)
3151 RefPtr<CSSValueList> values;
3152 if (m_valueList->size() > 1)
3153 values = CSSValueList::createCommaSeparated();
3154 CSSParserValue* val;
3155 bool expectComma = false;
3156 while ((val = m_valueList->current())) {
3157 RefPtr<CSSPrimitiveValue> parsedValue;
3160 if (val->id == CSSValueNormal || val->id == CSSValueItalic || val->id == CSSValueOblique)
3161 parsedValue = CSSPrimitiveValue::createIdentifier(val->id);
3162 else if (val->id == CSSValueAll && !values) {
3163 // 'all' is only allowed in @font-face and with no other values. Make a value list to
3164 // indicate that we are in the @font-face case.
3165 values = CSSValueList::createCommaSeparated();
3166 parsedValue = CSSPrimitiveValue::createIdentifier(val->id);
3168 } else if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3169 expectComma = false;
3170 m_valueList->next();
3177 m_valueList->next();
3180 values->append(parsedValue.release());
3182 addProperty(CSSPropertyFontStyle, parsedValue.release(), important);
3187 if (values && values->length()) {
3188 m_hasFontFaceOnlyValues = true;
3189 addProperty(CSSPropertyFontStyle, values.release(), important);
3196 bool CSSParser::parseFontVariant(bool important)
3198 RefPtr<CSSValueList> values;
3199 if (m_valueList->size() > 1)
3200 values = CSSValueList::createCommaSeparated();
3201 CSSParserValue* val;
3202 bool expectComma = false;
3203 while ((val = m_valueList->current())) {
3204 RefPtr<CSSPrimitiveValue> parsedValue;
3207 if (val->id == CSSValueNormal || val->id == CSSValueSmallCaps)
3208 parsedValue = CSSPrimitiveValue::createIdentifier(val->id);
3209 else if (val->id == CSSValueAll && !values) {
3210 // 'all' is only allowed in @font-face and with no other values. Make a value list to
3211 // indicate that we are in the @font-face case.
3212 values = CSSValueList::createCommaSeparated();
3213 parsedValue = CSSPrimitiveValue::createIdentifier(val->id);
3215 } else if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3216 expectComma = false;
3217 m_valueList->next();
3224 m_valueList->next();
3227 values->append(parsedValue.release());
3229 addProperty(CSSPropertyFontVariant, parsedValue.release(), important);
3234 if (values && values->length()) {
3235 m_hasFontFaceOnlyValues = true;
3236 addProperty(CSSPropertyFontVariant, values.release(), important);
3243 bool CSSParser::parseFontWeight(bool important)
3245 RefPtr<CSSValueList> values;
3246 if (m_valueList->size() > 1)
3247 values = CSSValueList::createCommaSeparated();
3248 CSSParserValue* val;
3249 bool expectComma = false;
3250 while ((val = m_valueList->current())) {
3251 RefPtr<CSSPrimitiveValue> parsedValue;
3254 if (val->unit == CSSPrimitiveValue::CSS_IDENT) {
3255 if (val->id >= CSSValueNormal && val->id <= CSSValue900)
3256 parsedValue = CSSPrimitiveValue::createIdentifier(val->id);
3257 else if (val->id == CSSValueAll && !values) {
3258 // 'all' is only allowed in @font-face and with no other values. Make a value list to
3259 // indicate that we are in the @font-face case.
3260 values = CSSValueList::createCommaSeparated();
3261 parsedValue = CSSPrimitiveValue::createIdentifier(val->id);
3263 } else if (validUnit(val, FInteger | FNonNeg, false)) {
3264 int weight = static_cast<int>(val->fValue);
3265 if (!(weight % 100) && weight >= 100 && weight <= 900)
3266 parsedValue = CSSPrimitiveValue::createIdentifier(CSSValue100 + weight / 100 - 1);
3268 } else if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
3269 expectComma = false;
3270 m_valueList->next();
3277 m_valueList->next();
3280 values->append(parsedValue.release());
3282 addProperty(CSSPropertyFontWeight, parsedValue.release(), important);
3287 if (values && values->length()) {
3288 m_hasFontFaceOnlyValues = true;
3289 addProperty(CSSPropertyFontWeight, values.release(), important);
3296 bool CSSParser::parseFontFaceSrc()
3298 RefPtr<CSSValueList> values(CSSValueList::createCommaSeparated());
3299 CSSParserValue* val;
3300 bool expectComma = false;
3301 bool allowFormat = false;
3302 bool failed = false;
3303 RefPtr<CSSFontFaceSrcValue> uriValue;
3304 while ((val = m_valueList->current())) {
3305 RefPtr<CSSFontFaceSrcValue> parsedValue;
3306 if (val->unit == CSSPrimitiveValue::CSS_URI && !expectComma && m_styleSheet) {
3307 // FIXME: The completeURL call should be done when using the CSSFontFaceSrcValue,
3308 // not when creating it.
3309 parsedValue = CSSFontFaceSrcValue::create(m_styleSheet->completeURL(val->string));
3310 uriValue = parsedValue;
3313 } else if (val->unit == CSSParserValue::Function) {
3314 // There are two allowed functions: local() and format().
3315 CSSParserValueList* args = val->function->args;
3316 if (args && args->size() == 1) {
3317 if (equalIgnoringCase(val->function->name, "local(") && !expectComma) {
3319 allowFormat = false;
3320 CSSParserValue* a = args->current();
3322 parsedValue = CSSFontFaceSrcValue::createLocal(a->string);
3323 } else if (equalIgnoringCase(val->function->name, "format(") && allowFormat && uriValue) {
3325 allowFormat = false;
3326 uriValue->setFormat(args->current()->string);
3328 m_valueList->next();
3332 } else if (val->unit == CSSParserValue::Operator && val->iValue == ',' && expectComma) {
3333 expectComma = false;
3334 allowFormat = false;
3336 m_valueList->next();
3341 values->append(parsedValue.release());
3346 m_valueList->next();
3349 if (values->length() && !failed) {
3350 addProperty(CSSPropertySrc, values.release(), m_important);
3351 m_valueList->next();
3358 bool CSSParser::parseFontFaceUnicodeRange()
3360 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
3361 CSSParserValue* currentValue;
3362 bool failed = false;
3363 while ((currentValue = m_valueList->current())) {
3364 if (m_valueList->current()->unit != CSSPrimitiveValue::CSS_UNICODE_RANGE) {