Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: Source/core/css/CSSParser.cpp

Issue 16339006: Make sure to use CSSValueID and CSSPropertyID rather than integers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/CSSParserValues.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 436 }
437 437
438 static bool parseColorValue(MutableStylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode) 438 static bool parseColorValue(MutableStylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
439 { 439 {
440 ASSERT(!string.isEmpty()); 440 ASSERT(!string.isEmpty());
441 bool strict = isStrictParserMode(cssParserMode); 441 bool strict = isStrictParserMode(cssParserMode);
442 if (!isColorPropertyID(propertyId)) 442 if (!isColorPropertyID(propertyId))
443 return false; 443 return false;
444 CSSParserString cssString; 444 CSSParserString cssString;
445 cssString.init(string); 445 cssString.init(string);
446 int valueID = cssValueKeywordID(cssString); 446 CSSValueID valueID = cssValueKeywordID(cssString);
447 bool validPrimitive = false; 447 bool validPrimitive = false;
448 if (valueID == CSSValueWebkitText) 448 if (valueID == CSSValueWebkitText)
449 validPrimitive = true; 449 validPrimitive = true;
450 else if (valueID == CSSValueCurrentcolor) 450 else if (valueID == CSSValueCurrentcolor)
451 validPrimitive = true; 451 validPrimitive = true;
452 else if ((valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || value ID == CSSValueMenu 452 else if ((valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || value ID == CSSValueMenu
453 || (valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWe bkitText && !strict)) { 453 || (valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWe bkitText && !strict)) {
454 validPrimitive = true; 454 validPrimitive = true;
455 } 455 }
456 456
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 if (lowerCaseString != "initial" && lowerCaseString != "inherit") 1063 if (lowerCaseString != "initial" && lowerCaseString != "inherit")
1064 return false; 1064 return false;
1065 1065
1066 // Parse initial/inherit shorthands using the CSSParser. 1066 // Parse initial/inherit shorthands using the CSSParser.
1067 if (shorthandForProperty(propertyId).length()) 1067 if (shorthandForProperty(propertyId).length())
1068 return false; 1068 return false;
1069 } 1069 }
1070 1070
1071 CSSParserString cssString; 1071 CSSParserString cssString;
1072 cssString.init(string); 1072 cssString.init(string);
1073 int valueID = cssValueKeywordID(cssString); 1073 CSSValueID valueID = cssValueKeywordID(cssString);
1074 1074
1075 if (!valueID) 1075 if (!valueID)
1076 return false; 1076 return false;
1077 1077
1078 RefPtr<CSSValue> value; 1078 RefPtr<CSSValue> value;
1079 if (valueID == CSSValueInherit) 1079 if (valueID == CSSValueInherit)
1080 value = cssValuePool().createInheritedValue(); 1080 value = cssValuePool().createInheritedValue();
1081 else if (valueID == CSSValueInitial) 1081 else if (valueID == CSSValueInitial)
1082 value = cssValuePool().createExplicitInitialValue(); 1082 value = cssValuePool().createExplicitInitialValue();
1083 else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext)) 1083 else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext))
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 } 1609 }
1610 1610
1611 bool CSSParser::validWidthOrHeight(CSSParserValue* value) 1611 bool CSSParser::validWidthOrHeight(CSSParserValue* value)
1612 { 1612 {
1613 int id = value->id; 1613 int id = value->id;
1614 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueW ebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAva ilable || id == CSSValueWebkitFitContent) 1614 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueW ebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAva ilable || id == CSSValueWebkitFitContent)
1615 return true; 1615 return true;
1616 return !id && validUnit(value, FLength | FPercent | FNonNeg); 1616 return !id && validUnit(value, FLength | FPercent | FNonNeg);
1617 } 1617 }
1618 1618
1619 inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(int identifi er, CSSParserValue* value) 1619 inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(CSSValueID i dentifier, CSSParserValue* value)
1620 { 1620 {
1621 if (identifier) 1621 if (identifier)
1622 return cssValuePool().createIdentifierValue(identifier); 1622 return cssValuePool().createIdentifierValue(identifier);
1623 if (value->unit == CSSPrimitiveValue::CSS_STRING) 1623 if (value->unit == CSSPrimitiveValue::CSS_STRING)
1624 return createPrimitiveStringValue(value); 1624 return createPrimitiveStringValue(value);
1625 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimit iveValue::CSS_KHZ) 1625 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimit iveValue::CSS_KHZ)
1626 return createPrimitiveNumericValue(value); 1626 return createPrimitiveNumericValue(value);
1627 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiv eValue::CSS_CHS) 1627 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiv eValue::CSS_CHS)
1628 return createPrimitiveNumericValue(value); 1628 return createPrimitiveNumericValue(value);
1629 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveV alue::CSS_VMAX) 1629 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveV alue::CSS_VMAX)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 1671
1672 CSSParserValue* value = m_valueList->current(); 1672 CSSParserValue* value = m_valueList->current();
1673 1673
1674 if (!value) 1674 if (!value)
1675 return false; 1675 return false;
1676 1676
1677 // Note: m_parsedCalculation is used to pass the calc value to validUnit and then cleared at the end of this function. 1677 // Note: m_parsedCalculation is used to pass the calc value to validUnit and then cleared at the end of this function.
1678 // FIXME: This is to avoid having to pass parsedCalc to all validUnit caller s. 1678 // FIXME: This is to avoid having to pass parsedCalc to all validUnit caller s.
1679 ASSERT(!m_parsedCalculation); 1679 ASSERT(!m_parsedCalculation);
1680 1680
1681 int id = value->id; 1681 CSSValueID id = value->id;
1682 1682
1683 int num = inShorthand() ? 1 : m_valueList->size(); 1683 int num = inShorthand() ? 1 : m_valueList->size();
1684 1684
1685 if (id == CSSValueInherit) { 1685 if (id == CSSValueInherit) {
1686 if (num != 1) 1686 if (num != 1)
1687 return false; 1687 return false;
1688 addExpandedPropertyForValue(propId, cssValuePool().createInheritedValue( ), important); 1688 addExpandedPropertyForValue(propId, cssValuePool().createInheritedValue( ), important);
1689 return true; 1689 return true;
1690 } 1690 }
1691 else if (id == CSSValueInitial) { 1691 else if (id == CSSValueInitial) {
(...skipping 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after
3496 // none 3496 // none
3497 // normal 3497 // normal
3498 switch (val->id) { 3498 switch (val->id) {
3499 case CSSValueOpenQuote: 3499 case CSSValueOpenQuote:
3500 case CSSValueCloseQuote: 3500 case CSSValueCloseQuote:
3501 case CSSValueNoOpenQuote: 3501 case CSSValueNoOpenQuote:
3502 case CSSValueNoCloseQuote: 3502 case CSSValueNoCloseQuote:
3503 case CSSValueNone: 3503 case CSSValueNone:
3504 case CSSValueNormal: 3504 case CSSValueNormal:
3505 parsedValue = cssValuePool().createIdentifierValue(val->id); 3505 parsedValue = cssValuePool().createIdentifierValue(val->id);
3506 default:
3507 break;
3506 } 3508 }
3507 } else if (val->unit == CSSPrimitiveValue::CSS_STRING) { 3509 } else if (val->unit == CSSPrimitiveValue::CSS_STRING) {
3508 parsedValue = createPrimitiveStringValue(val); 3510 parsedValue = createPrimitiveStringValue(val);
3509 } 3511 }
3510 if (!parsedValue) 3512 if (!parsedValue)
3511 break; 3513 break;
3512 values->append(parsedValue.release()); 3514 values->append(parsedValue.release());
3513 m_valueList->next(); 3515 m_valueList->next();
3514 } 3516 }
3515 3517
(...skipping 24 matching lines...) Expand all
3540 return 0; 3542 return 0;
3541 3543
3542 if (m_context.isHTMLDocument) 3544 if (m_context.isHTMLDocument)
3543 attrName = attrName.lower(); 3545 attrName = attrName.lower();
3544 3546
3545 return cssValuePool().createValue(attrName, CSSPrimitiveValue::CSS_ATTR); 3547 return cssValuePool().createValue(attrName, CSSPrimitiveValue::CSS_ATTR);
3546 } 3548 }
3547 3549
3548 PassRefPtr<CSSValue> CSSParser::parseBackgroundColor() 3550 PassRefPtr<CSSValue> CSSParser::parseBackgroundColor()
3549 { 3551 {
3550 int id = m_valueList->current()->id; 3552 CSSValueID id = m_valueList->current()->id;
3551 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowt ext) || id == CSSValueMenu || id == CSSValueCurrentcolor || 3553 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowt ext) || id == CSSValueMenu || id == CSSValueCurrentcolor ||
3552 (id >= CSSValueGrey && id < CSSValueWebkitText && inQuirksMode())) 3554 (id >= CSSValueGrey && id < CSSValueWebkitText && inQuirksMode()))
3553 return cssValuePool().createIdentifierValue(id); 3555 return cssValuePool().createIdentifierValue(id);
3554 return parseColor(); 3556 return parseColor();
3555 } 3557 }
3556 3558
3557 bool CSSParser::parseFillImage(CSSParserValueList* valueList, RefPtr<CSSValue>& value) 3559 bool CSSParser::parseFillImage(CSSParserValueList* valueList, RefPtr<CSSValue>& value)
3558 { 3560 {
3559 if (valueList->current()->id == CSSValueNone) { 3561 if (valueList->current()->id == CSSValueNone) {
3560 value = cssValuePool().createIdentifierValue(CSSValueNone); 3562 value = cssValuePool().createIdentifierValue(CSSValueNone);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3604 percent = 50; 3606 percent = 50;
3605 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCEN TAGE); 3607 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCEN TAGE);
3606 } 3608 }
3607 if (validUnit(valueList->current(), FPercent | FLength)) 3609 if (validUnit(valueList->current(), FPercent | FLength))
3608 return createPrimitiveNumericValue(valueList->current()); 3610 return createPrimitiveNumericValue(valueList->current());
3609 return 0; 3611 return 0;
3610 } 3612 }
3611 3613
3612 PassRefPtr<CSSPrimitiveValue> CSSParser::parseFillPositionComponent(CSSParserVal ueList* valueList, unsigned& cumulativeFlags, FillPositionFlag& individualFlag, FillPositionParsingMode parsingMode) 3614 PassRefPtr<CSSPrimitiveValue> CSSParser::parseFillPositionComponent(CSSParserVal ueList* valueList, unsigned& cumulativeFlags, FillPositionFlag& individualFlag, FillPositionParsingMode parsingMode)
3613 { 3615 {
3614 int id = valueList->current()->id; 3616 CSSValueID id = valueList->current()->id;
3615 if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id == CSSValueBottom || id == CSSValueCenter) { 3617 if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id == CSSValueBottom || id == CSSValueCenter) {
3616 int percent = 0; 3618 int percent = 0;
3617 if (id == CSSValueLeft || id == CSSValueRight) { 3619 if (id == CSSValueLeft || id == CSSValueRight) {
3618 if (cumulativeFlags & XFillPosition) 3620 if (cumulativeFlags & XFillPosition)
3619 return 0; 3621 return 0;
3620 cumulativeFlags |= XFillPosition; 3622 cumulativeFlags |= XFillPosition;
3621 individualFlag = XFillPosition; 3623 individualFlag = XFillPosition;
3622 if (id == CSSValueRight) 3624 if (id == CSSValueRight)
3623 percent = 100; 3625 percent = 100;
3624 } 3626 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3728 FillPositionFlag value3Flag = InvalidFillPosition; 3730 FillPositionFlag value3Flag = InvalidFillPosition;
3729 RefPtr<CSSPrimitiveValue> value3 = parseFillPositionComponent(valueList, cum ulativeFlags, value3Flag, ResolveValuesAsKeyword); 3731 RefPtr<CSSPrimitiveValue> value3 = parseFillPositionComponent(valueList, cum ulativeFlags, value3Flag, ResolveValuesAsKeyword);
3730 3732
3731 // value3 is not an expected value, we return. 3733 // value3 is not an expected value, we return.
3732 if (!value3) 3734 if (!value3)
3733 return; 3735 return;
3734 3736
3735 valueList->next(); 3737 valueList->next();
3736 3738
3737 bool swapNeeded = false; 3739 bool swapNeeded = false;
3738 int ident1 = parsedValue1->getIdent(); 3740 CSSValueID ident1 = static_cast<CSSValueID>(parsedValue1->getIdent());
3739 int ident2 = parsedValue2->getIdent(); 3741 CSSValueID ident2 = static_cast<CSSValueID>(parsedValue2->getIdent());
3740 int ident3 = value3->getIdent(); 3742 CSSValueID ident3 = static_cast<CSSValueID>(value3->getIdent());
3741 3743
3742 int firstPositionKeyword; 3744 CSSValueID firstPositionKeyword;
3743 int secondPositionKeyword; 3745 CSSValueID secondPositionKeyword;
3744 3746
3745 if (ident1 == CSSValueCenter) { 3747 if (ident1 == CSSValueCenter) {
3746 // <position> requires the first 'center' to be followed by a keyword. 3748 // <position> requires the first 'center' to be followed by a keyword.
3747 if (!isFillPositionKeyword(ident2)) 3749 if (!isFillPositionKeyword(ident2))
3748 return; 3750 return;
3749 3751
3750 // If 'center' is the first keyword then the last one needs to be a leng th. 3752 // If 'center' is the first keyword then the last one needs to be a leng th.
3751 if (isFillPositionKeyword(ident3)) 3753 if (isFillPositionKeyword(ident3))
3752 return; 3754 return;
3753 3755
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3799 value1 = createPrimitiveValuePair(parsedValue1, firstPositionValue); 3801 value1 = createPrimitiveValuePair(parsedValue1, firstPositionValue);
3800 value2 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(s econdPositionKeyword), secondPositionValue); 3802 value2 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(s econdPositionKeyword), secondPositionValue);
3801 } 3803 }
3802 3804
3803 if (ident1 == CSSValueTop || ident1 == CSSValueBottom || swapNeeded) 3805 if (ident1 == CSSValueTop || ident1 == CSSValueBottom || swapNeeded)
3804 value1.swap(value2); 3806 value1.swap(value2);
3805 3807
3806 #ifndef NDEBUG 3808 #ifndef NDEBUG
3807 CSSPrimitiveValue* first = toCSSPrimitiveValue(value1.get()); 3809 CSSPrimitiveValue* first = toCSSPrimitiveValue(value1.get());
3808 CSSPrimitiveValue* second = toCSSPrimitiveValue(value2.get()); 3810 CSSPrimitiveValue* second = toCSSPrimitiveValue(value2.get());
3809 ident1 = first->getPairValue()->first()->getIdent(); 3811 ident1 = static_cast<CSSValueID>(first->getPairValue()->first()->getIdent()) ;
3810 ident2 = second->getPairValue()->first()->getIdent(); 3812 ident2 = static_cast<CSSValueID>(second->getPairValue()->first()->getIdent() );
3811 ASSERT(ident1 == CSSValueLeft || ident1 == CSSValueRight); 3813 ASSERT(ident1 == CSSValueLeft || ident1 == CSSValueRight);
3812 ASSERT(ident2 == CSSValueBottom || ident2 == CSSValueTop); 3814 ASSERT(ident2 == CSSValueBottom || ident2 == CSSValueTop);
3813 #endif 3815 #endif
3814 } 3816 }
3815 3817
3816 inline bool CSSParser::isPotentialPositionValue(CSSParserValue* value) 3818 inline bool CSSParser::isPotentialPositionValue(CSSParserValue* value)
3817 { 3819 {
3818 return isFillPositionKeyword(value->id) || validUnit(value, FPercent | FLeng th, ReleaseParsedCalcValue); 3820 return isFillPositionKeyword(value->id) || validUnit(value, FPercent | FLeng th, ReleaseParsedCalcValue);
3819 } 3821 }
3820 3822
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3920 // For keywords, the keyword was either an x-keyword (left/right), a y-k eyword (top/bottom), or an ambiguous keyword (center). 3922 // For keywords, the keyword was either an x-keyword (left/right), a y-k eyword (top/bottom), or an ambiguous keyword (center).
3921 // For left/right/center, the default of 50% in the y is still correct. 3923 // For left/right/center, the default of 50% in the y is still correct.
3922 value2 = cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAG E); 3924 value2 = cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAG E);
3923 3925
3924 if (value1Flag == YFillPosition || value2Flag == XFillPosition) 3926 if (value1Flag == YFillPosition || value2Flag == XFillPosition)
3925 value1.swap(value2); 3927 value1.swap(value2);
3926 } 3928 }
3927 3929
3928 void CSSParser::parseFillRepeat(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& valu e2) 3930 void CSSParser::parseFillRepeat(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& valu e2)
3929 { 3931 {
3930 int id = m_valueList->current()->id; 3932 CSSValueID id = m_valueList->current()->id;
3931 if (id == CSSValueRepeatX) { 3933 if (id == CSSValueRepeatX) {
3932 m_implicitShorthand = true; 3934 m_implicitShorthand = true;
3933 value1 = cssValuePool().createIdentifierValue(CSSValueRepeat); 3935 value1 = cssValuePool().createIdentifierValue(CSSValueRepeat);
3934 value2 = cssValuePool().createIdentifierValue(CSSValueNoRepeat); 3936 value2 = cssValuePool().createIdentifierValue(CSSValueNoRepeat);
3935 m_valueList->next(); 3937 m_valueList->next();
3936 return; 3938 return;
3937 } 3939 }
3938 if (id == CSSValueRepeatY) { 3940 if (id == CSSValueRepeatY) {
3939 m_implicitShorthand = true; 3941 m_implicitShorthand = true;
3940 value1 = cssValuePool().createIdentifierValue(CSSValueNoRepeat); 3942 value1 = cssValuePool().createIdentifierValue(CSSValueNoRepeat);
(...skipping 15 matching lines...) Expand all
3956 id = value->id; 3958 id = value->id;
3957 if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRoun d || id == CSSValueSpace) { 3959 if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRoun d || id == CSSValueSpace) {
3958 value2 = cssValuePool().createIdentifierValue(id); 3960 value2 = cssValuePool().createIdentifierValue(id);
3959 m_valueList->next(); 3961 m_valueList->next();
3960 return; 3962 return;
3961 } 3963 }
3962 } 3964 }
3963 3965
3964 // If only one value was specified, value2 is the same as value1. 3966 // If only one value was specified, value2 is the same as value1.
3965 m_implicitShorthand = true; 3967 m_implicitShorthand = true;
3966 value2 = cssValuePool().createIdentifierValue(toCSSPrimitiveValue(value1.get ())->getIdent()); 3968 value2 = cssValuePool().createIdentifierValue(static_cast<CSSValueID>(toCSSP rimitiveValue(value1.get())->getIdent()));
3967 } 3969 }
3968 3970
3969 PassRefPtr<CSSValue> CSSParser::parseFillSize(CSSPropertyID propId, bool& allowC omma) 3971 PassRefPtr<CSSValue> CSSParser::parseFillSize(CSSPropertyID propId, bool& allowC omma)
3970 { 3972 {
3971 allowComma = true; 3973 allowComma = true;
3972 CSSParserValue* value = m_valueList->current(); 3974 CSSParserValue* value = m_valueList->current();
3973 3975
3974 if (value->id == CSSValueContain || value->id == CSSValueCover) 3976 if (value->id == CSSValueContain || value->id == CSSValueCover)
3975 return cssValuePool().createIdentifierValue(value->id); 3977 return cssValuePool().createIdentifierValue(value->id);
3976 3978
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
4248 if (value->id == CSSValueRunning || value->id == CSSValuePaused) 4250 if (value->id == CSSValueRunning || value->id == CSSValuePaused)
4249 return cssValuePool().createIdentifierValue(value->id); 4251 return cssValuePool().createIdentifierValue(value->id);
4250 return 0; 4252 return 0;
4251 } 4253 }
4252 4254
4253 PassRefPtr<CSSValue> CSSParser::parseAnimationProperty(AnimationParseContext& co ntext) 4255 PassRefPtr<CSSValue> CSSParser::parseAnimationProperty(AnimationParseContext& co ntext)
4254 { 4256 {
4255 CSSParserValue* value = m_valueList->current(); 4257 CSSParserValue* value = m_valueList->current();
4256 if (value->unit != CSSPrimitiveValue::CSS_IDENT) 4258 if (value->unit != CSSPrimitiveValue::CSS_IDENT)
4257 return 0; 4259 return 0;
4258 int result = cssPropertyID(value->string); 4260 CSSPropertyID result = cssPropertyID(value->string);
4259 if (result) 4261 if (result)
4260 return cssValuePool().createIdentifierValue(result); 4262 return cssValuePool().createIdentifierValue(result);
4261 if (equalIgnoringCase(value, "all")) { 4263 if (equalIgnoringCase(value, "all")) {
4262 context.sawAnimationPropertyKeyword(); 4264 context.sawAnimationPropertyKeyword();
4263 return cssValuePool().createIdentifierValue(CSSValueAll); 4265 return cssValuePool().createIdentifierValue(CSSValueAll);
4264 } 4266 }
4265 if (equalIgnoringCase(value, "none")) { 4267 if (equalIgnoringCase(value, "none")) {
4266 context.commitAnimationPropertyKeyword(); 4268 context.commitAnimationPropertyKeyword();
4267 context.sawAnimationPropertyKeyword(); 4269 context.sawAnimationPropertyKeyword();
4268 return cssValuePool().createIdentifierValue(CSSValueNone); 4270 return cssValuePool().createIdentifierValue(CSSValueNone);
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
4708 if (!i) // Make the list style default decimal 4710 if (!i) // Make the list style default decimal
4709 listStyle = cssValuePool().createIdentifierValue(CSSValueDecimal); 4711 listStyle = cssValuePool().createIdentifierValue(CSSValueDecimal);
4710 else { 4712 else {
4711 if (i->unit != CSSParserValue::Operator || i->iValue != ',') 4713 if (i->unit != CSSParserValue::Operator || i->iValue != ',')
4712 return 0; 4714 return 0;
4713 4715
4714 i = args->next(); 4716 i = args->next();
4715 if (i->unit != CSSPrimitiveValue::CSS_IDENT) 4717 if (i->unit != CSSPrimitiveValue::CSS_IDENT)
4716 return 0; 4718 return 0;
4717 4719
4718 int listStyleID = 0; 4720 CSSValueID listStyleID = CSSValueInvalid;
4719 if (i->id == CSSValueNone || (i->id >= CSSValueDisc && i->id <= CSSValue KatakanaIroha)) 4721 if (i->id == CSSValueNone || (i->id >= CSSValueDisc && i->id <= CSSValue KatakanaIroha))
4720 listStyleID = i->id; 4722 listStyleID = i->id;
4721 else 4723 else
4722 return 0; 4724 return 0;
4723 4725
4724 listStyle = cssValuePool().createIdentifierValue(listStyleID); 4726 listStyle = cssValuePool().createIdentifierValue(listStyleID);
4725 } 4727 }
4726 4728
4727 return cssValuePool().createValue(Counter::create(identifier.release(), list Style.release(), separator.release())); 4729 return cssValuePool().createValue(Counter::create(identifier.release(), list Style.release(), separator.release()));
4728 } 4730 }
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
5191 familyBuilder.commit(); 5193 familyBuilder.commit();
5192 5194
5193 if (!list->length()) 5195 if (!list->length())
5194 list = 0; 5196 list = 0;
5195 return list.release(); 5197 return list.release();
5196 } 5198 }
5197 5199
5198 bool CSSParser::parseLineHeight(bool important) 5200 bool CSSParser::parseLineHeight(bool important)
5199 { 5201 {
5200 CSSParserValue* value = m_valueList->current(); 5202 CSSParserValue* value = m_valueList->current();
5201 int id = value->id; 5203 CSSValueID id = value->id;
5202 bool validPrimitive = false; 5204 bool validPrimitive = false;
5203 // normal | <number> | <length> | <percentage> | inherit 5205 // normal | <number> | <length> | <percentage> | inherit
5204 if (id == CSSValueNormal) 5206 if (id == CSSValueNormal)
5205 validPrimitive = true; 5207 validPrimitive = true;
5206 else 5208 else
5207 validPrimitive = (!id && validUnit(value, FNumber | FLength | FPercent | FNonNeg)); 5209 validPrimitive = (!id && validUnit(value, FNumber | FLength | FPercent | FNonNeg));
5208 if (validPrimitive && (!m_valueList->next() || inShorthand())) 5210 if (validPrimitive && (!m_valueList->next() || inShorthand()))
5209 addProperty(CSSPropertyLineHeight, parseValidPrimitive(id, value), impor tant); 5211 addProperty(CSSPropertyLineHeight, parseValidPrimitive(id, value), impor tant);
5210 return validPrimitive; 5212 return validPrimitive;
5211 } 5213 }
5212 5214
5213 bool CSSParser::parseFontSize(bool important) 5215 bool CSSParser::parseFontSize(bool important)
5214 { 5216 {
5215 CSSParserValue* value = m_valueList->current(); 5217 CSSParserValue* value = m_valueList->current();
5216 int id = value->id; 5218 CSSValueID id = value->id;
5217 bool validPrimitive = false; 5219 bool validPrimitive = false;
5218 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit 5220 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit
5219 if (id >= CSSValueXxSmall && id <= CSSValueLarger) 5221 if (id >= CSSValueXxSmall && id <= CSSValueLarger)
5220 validPrimitive = true; 5222 validPrimitive = true;
5221 else 5223 else
5222 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg); 5224 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
5223 if (validPrimitive && (!m_valueList->next() || inShorthand())) 5225 if (validPrimitive && (!m_valueList->next() || inShorthand()))
5224 addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), importa nt); 5226 addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), importa nt);
5225 return validPrimitive; 5227 return validPrimitive;
5226 } 5228 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
5275 bool CSSParser::parseFontWeight(bool important) 5277 bool CSSParser::parseFontWeight(bool important)
5276 { 5278 {
5277 CSSParserValue* value = m_valueList->current(); 5279 CSSParserValue* value = m_valueList->current();
5278 if ((value->id >= CSSValueNormal) && (value->id <= CSSValue900)) { 5280 if ((value->id >= CSSValueNormal) && (value->id <= CSSValue900)) {
5279 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue( value->id), important); 5281 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue( value->id), important);
5280 return true; 5282 return true;
5281 } 5283 }
5282 if (validUnit(value, FInteger | FNonNeg, CSSQuirksMode)) { 5284 if (validUnit(value, FInteger | FNonNeg, CSSQuirksMode)) {
5283 int weight = static_cast<int>(value->fValue); 5285 int weight = static_cast<int>(value->fValue);
5284 if (!(weight % 100) && weight >= 100 && weight <= 900) { 5286 if (!(weight % 100) && weight >= 100 && weight <= 900) {
5285 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierVa lue(CSSValue100 + weight / 100 - 1), important); 5287 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierVa lue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important);
5286 return true; 5288 return true;
5287 } 5289 }
5288 } 5290 }
5289 return false; 5291 return false;
5290 } 5292 }
5291 5293
5292 bool CSSParser::parseFontFaceSrcURI(CSSValueList* valueList) 5294 bool CSSParser::parseFontFaceSrcURI(CSSValueList* valueList)
5293 { 5295 {
5294 RefPtr<CSSFontFaceSrcValue> uriValue(CSSFontFaceSrcValue::create(completeURL (m_valueList->current()->string))); 5296 RefPtr<CSSFontFaceSrcValue> uriValue(CSSFontFaceSrcValue::create(completeURL (m_valueList->current()->string)));
5295 5297
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after
6866 || equalIgnoringCase(a->function->name, "to(")) { 6868 || equalIgnoringCase(a->function->name, "to(")) {
6867 // The "from" and "to" stops expect 1 argument. 6869 // The "from" and "to" stops expect 1 argument.
6868 if (args->size() != 1) 6870 if (args->size() != 1)
6869 return false; 6871 return false;
6870 6872
6871 if (equalIgnoringCase(a->function->name, "from(")) 6873 if (equalIgnoringCase(a->function->name, "from("))
6872 stop.m_position = cssValuePool().createValue(0, CSSPrimitiveValue::C SS_NUMBER); 6874 stop.m_position = cssValuePool().createValue(0, CSSPrimitiveValue::C SS_NUMBER);
6873 else 6875 else
6874 stop.m_position = cssValuePool().createValue(1, CSSPrimitiveValue::C SS_NUMBER); 6876 stop.m_position = cssValuePool().createValue(1, CSSPrimitiveValue::C SS_NUMBER);
6875 6877
6876 int id = args->current()->id; 6878 CSSValueID id = args->current()->id;
6877 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWin dowtext) || id == CSSValueMenu) 6879 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWin dowtext) || id == CSSValueMenu)
6878 stop.m_color = cssValuePool().createIdentifierValue(id); 6880 stop.m_color = cssValuePool().createIdentifierValue(id);
6879 else 6881 else
6880 stop.m_color = p->parseColor(args->current()); 6882 stop.m_color = p->parseColor(args->current());
6881 if (!stop.m_color) 6883 if (!stop.m_color)
6882 return false; 6884 return false;
6883 } 6885 }
6884 6886
6885 // The "color-stop" function expects 3 arguments. 6887 // The "color-stop" function expects 3 arguments.
6886 if (equalIgnoringCase(a->function->name, "color-stop(")) { 6888 if (equalIgnoringCase(a->function->name, "color-stop(")) {
6887 if (args->size() != 3) 6889 if (args->size() != 3)
6888 return false; 6890 return false;
6889 6891
6890 CSSParserValue* stopArg = args->current(); 6892 CSSParserValue* stopArg = args->current();
6891 if (stopArg->unit == CSSPrimitiveValue::CSS_PERCENTAGE) 6893 if (stopArg->unit == CSSPrimitiveValue::CSS_PERCENTAGE)
6892 stop.m_position = cssValuePool().createValue(stopArg->fValue / 100, CSSPrimitiveValue::CSS_NUMBER); 6894 stop.m_position = cssValuePool().createValue(stopArg->fValue / 100, CSSPrimitiveValue::CSS_NUMBER);
6893 else if (stopArg->unit == CSSPrimitiveValue::CSS_NUMBER) 6895 else if (stopArg->unit == CSSPrimitiveValue::CSS_NUMBER)
6894 stop.m_position = cssValuePool().createValue(stopArg->fValue, CSSPri mitiveValue::CSS_NUMBER); 6896 stop.m_position = cssValuePool().createValue(stopArg->fValue, CSSPri mitiveValue::CSS_NUMBER);
6895 else 6897 else
6896 return false; 6898 return false;
6897 6899
6898 stopArg = args->next(); 6900 stopArg = args->next();
6899 if (stopArg->unit != CSSParserValue::Operator || stopArg->iValue != ',') 6901 if (stopArg->unit != CSSParserValue::Operator || stopArg->iValue != ',')
6900 return false; 6902 return false;
6901 6903
6902 stopArg = args->next(); 6904 stopArg = args->next();
6903 int id = stopArg->id; 6905 CSSValueID id = stopArg->id;
6904 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWin dowtext) || id == CSSValueMenu) 6906 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWin dowtext) || id == CSSValueMenu)
6905 stop.m_color = cssValuePool().createIdentifierValue(id); 6907 stop.m_color = cssValuePool().createIdentifierValue(id);
6906 else 6908 else
6907 stop.m_color = p->parseColor(stopArg); 6909 stop.m_color = p->parseColor(stopArg);
6908 if (!stop.m_color) 6910 if (!stop.m_color)
6909 return false; 6911 return false;
6910 } 6912 }
6911 6913
6912 return true; 6914 return true;
6913 } 6915 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
7060 isHorizontal = false; 7062 isHorizontal = false;
7061 break; 7063 break;
7062 default: 7064 default:
7063 return 0; 7065 return 0;
7064 } 7066 }
7065 return cssValuePool().createIdentifierValue(a->id); 7067 return cssValuePool().createIdentifierValue(a->id);
7066 } 7068 }
7067 7069
7068 static PassRefPtr<CSSPrimitiveValue> parseGradientColorOrKeyword(CSSParser* p, C SSParserValue* value) 7070 static PassRefPtr<CSSPrimitiveValue> parseGradientColorOrKeyword(CSSParser* p, C SSParserValue* value)
7069 { 7071 {
7070 int id = value->id; 7072 CSSValueID id = value->id;
7071 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowt ext) || id == CSSValueMenu || id == CSSValueCurrentcolor) 7073 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowt ext) || id == CSSValueMenu || id == CSSValueCurrentcolor)
7072 return cssValuePool().createIdentifierValue(id); 7074 return cssValuePool().createIdentifierValue(id);
7073 7075
7074 return p->parseColor(value); 7076 return p->parseColor(value);
7075 } 7077 }
7076 7078
7077 bool CSSParser::parseDeprecatedLinearGradient(CSSParserValueList* valueList, Ref Ptr<CSSValue>& gradient, CSSGradientRepeat repeating) 7079 bool CSSParser::parseDeprecatedLinearGradient(CSSParserValueList* valueList, Ref Ptr<CSSValue>& gradient, CSSGradientRepeat repeating)
7078 { 7080 {
7079 RefPtr<CSSLinearGradientValue> result = CSSLinearGradientValue::create(repea ting, CSSPrefixedLinearGradient); 7081 RefPtr<CSSLinearGradientValue> result = CSSLinearGradientValue::create(repea ting, CSSPrefixedLinearGradient);
7080 7082
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
7199 break; 7201 break;
7200 case CSSValueClosestSide: 7202 case CSSValueClosestSide:
7201 case CSSValueClosestCorner: 7203 case CSSValueClosestCorner:
7202 case CSSValueFarthestSide: 7204 case CSSValueFarthestSide:
7203 case CSSValueFarthestCorner: 7205 case CSSValueFarthestCorner:
7204 case CSSValueContain: 7206 case CSSValueContain:
7205 case CSSValueCover: 7207 case CSSValueCover:
7206 sizeValue = cssValuePool().createIdentifierValue(a->id); 7208 sizeValue = cssValuePool().createIdentifierValue(a->id);
7207 foundValue = true; 7209 foundValue = true;
7208 break; 7210 break;
7211 default:
7212 break;
7209 } 7213 }
7210 7214
7211 if (foundValue) { 7215 if (foundValue) {
7212 a = args->next(); 7216 a = args->next();
7213 if (!a) 7217 if (!a)
7214 return false; 7218 return false;
7215 7219
7216 expectComma = true; 7220 expectComma = true;
7217 } 7221 }
7218 } 7222 }
(...skipping 4342 matching lines...) Expand 10 before | Expand all | Expand 10 after
11561 11565
11562 if (!length) 11566 if (!length)
11563 return CSSPropertyInvalid; 11567 return CSSPropertyInvalid;
11564 if (length > maxCSSPropertyNameLength) 11568 if (length > maxCSSPropertyNameLength)
11565 return CSSPropertyInvalid; 11569 return CSSPropertyInvalid;
11566 11570
11567 return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPr opertyID(string.characters16(), length); 11571 return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPr opertyID(string.characters16(), length);
11568 } 11572 }
11569 11573
11570 template <typename CharacterType> 11574 template <typename CharacterType>
11571 static int cssValueKeywordID(const CharacterType* valueKeyword, unsigned length) 11575 static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
11572 { 11576 {
11573 char buffer[maxCSSValueKeywordLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character 11577 char buffer[maxCSSValueKeywordLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
11574 11578
11575 for (unsigned i = 0; i != length; ++i) { 11579 for (unsigned i = 0; i != length; ++i) {
11576 CharacterType c = valueKeyword[i]; 11580 CharacterType c = valueKeyword[i];
11577 if (c == 0 || c >= 0x7F) 11581 if (c == 0 || c >= 0x7F)
11578 return 0; // illegal character 11582 return CSSValueInvalid; // illegal character
11579 buffer[i] = WTF::toASCIILower(c); 11583 buffer[i] = WTF::toASCIILower(c);
11580 } 11584 }
11581 buffer[length] = '\0'; 11585 buffer[length] = '\0';
11582 11586
11583 if (buffer[0] == '-') { 11587 if (buffer[0] == '-') {
11584 // If the prefix is -apple- or -khtml-, change it to -webkit-. 11588 // If the prefix is -apple- or -khtml-, change it to -webkit-.
11585 // This makes the string one character longer. 11589 // This makes the string one character longer.
11586 if (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "- khtml-")) { 11590 if (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "- khtml-")) {
11587 memmove(buffer + 7, buffer + 6, length + 1 - 6); 11591 memmove(buffer + 7, buffer + 6, length + 1 - 6);
11588 memcpy(buffer, "-webkit", 7); 11592 memcpy(buffer, "-webkit", 7);
11589 ++length; 11593 ++length;
11590 } 11594 }
11591 } 11595 }
11592 11596
11593 const Value* hashTableEntry = findValue(buffer, length); 11597 const Value* hashTableEntry = findValue(buffer, length);
11594 return hashTableEntry ? hashTableEntry->id : 0; 11598 return hashTableEntry ? static_cast<CSSValueID>(hashTableEntry->id) : CSSVal ueInvalid;
11595 } 11599 }
11596 11600
11597 int cssValueKeywordID(const CSSParserString& string) 11601 CSSValueID cssValueKeywordID(const CSSParserString& string)
11598 { 11602 {
11599 unsigned length = string.length(); 11603 unsigned length = string.length();
11600 if (!length) 11604 if (!length)
11601 return 0; 11605 return CSSValueInvalid;
11602 if (length > maxCSSValueKeywordLength) 11606 if (length > maxCSSValueKeywordLength)
11603 return 0; 11607 return CSSValueInvalid;
11604 11608
11605 return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : c ssValueKeywordID(string.characters16(), length); 11609 return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : c ssValueKeywordID(string.characters16(), length);
11606 } 11610 }
11607 11611
11608 template <typename CharacterType> 11612 template <typename CharacterType>
11609 static inline bool isCSSTokenizerIdentifier(const CharacterType* characters, uns igned length) 11613 static inline bool isCSSTokenizerIdentifier(const CharacterType* characters, uns igned length)
11610 { 11614 {
11611 const CharacterType* end = characters + length; 11615 const CharacterType* end = characters + length;
11612 11616
11613 // -? 11617 // -?
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
11764 { 11768 {
11765 // The tokenizer checks for the construct of an+b. 11769 // The tokenizer checks for the construct of an+b.
11766 // However, since the {ident} rule precedes the {nth} rule, some of those 11770 // However, since the {ident} rule precedes the {nth} rule, some of those
11767 // tokens are identified as string literal. Furthermore we need to accept 11771 // tokens are identified as string literal. Furthermore we need to accept
11768 // "odd" and "even" which does not match to an+b. 11772 // "odd" and "even" which does not match to an+b.
11769 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") 11773 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
11770 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 11774 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
11771 } 11775 }
11772 11776
11773 } 11777 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/CSSParserValues.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698