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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/CSSParserValues.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSParser.cpp
diff --git a/Source/core/css/CSSParser.cpp b/Source/core/css/CSSParser.cpp
index 4fbcf74fdc80e402882492fbebbd6265b18705e8..795d4266277b277e9a7ca06900c9dd5d314c3167 100644
--- a/Source/core/css/CSSParser.cpp
+++ b/Source/core/css/CSSParser.cpp
@@ -443,7 +443,7 @@ static bool parseColorValue(MutableStylePropertySet* declaration, CSSPropertyID
return false;
CSSParserString cssString;
cssString.init(string);
- int valueID = cssValueKeywordID(cssString);
+ CSSValueID valueID = cssValueKeywordID(cssString);
bool validPrimitive = false;
if (valueID == CSSValueWebkitText)
validPrimitive = true;
@@ -1070,7 +1070,7 @@ static bool parseKeywordValue(MutableStylePropertySet* declaration, CSSPropertyI
CSSParserString cssString;
cssString.init(string);
- int valueID = cssValueKeywordID(cssString);
+ CSSValueID valueID = cssValueKeywordID(cssString);
if (!valueID)
return false;
@@ -1616,7 +1616,7 @@ bool CSSParser::validWidthOrHeight(CSSParserValue* value)
return !id && validUnit(value, FLength | FPercent | FNonNeg);
}
-inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(int identifier, CSSParserValue* value)
+inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(CSSValueID identifier, CSSParserValue* value)
{
if (identifier)
return cssValuePool().createIdentifierValue(identifier);
@@ -1678,7 +1678,7 @@ bool CSSParser::parseValue(CSSPropertyID propId, bool important)
// FIXME: This is to avoid having to pass parsedCalc to all validUnit callers.
ASSERT(!m_parsedCalculation);
- int id = value->id;
+ CSSValueID id = value->id;
int num = inShorthand() ? 1 : m_valueList->size();
@@ -3503,6 +3503,8 @@ bool CSSParser::parseContent(CSSPropertyID propId, bool important)
case CSSValueNone:
case CSSValueNormal:
parsedValue = cssValuePool().createIdentifierValue(val->id);
+ default:
+ break;
}
} else if (val->unit == CSSPrimitiveValue::CSS_STRING) {
parsedValue = createPrimitiveStringValue(val);
@@ -3547,7 +3549,7 @@ PassRefPtr<CSSValue> CSSParser::parseAttr(CSSParserValueList* args)
PassRefPtr<CSSValue> CSSParser::parseBackgroundColor()
{
- int id = m_valueList->current()->id;
+ CSSValueID id = m_valueList->current()->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor ||
(id >= CSSValueGrey && id < CSSValueWebkitText && inQuirksMode()))
return cssValuePool().createIdentifierValue(id);
@@ -3611,7 +3613,7 @@ PassRefPtr<CSSValue> CSSParser::parseFillPositionY(CSSParserValueList* valueList
PassRefPtr<CSSPrimitiveValue> CSSParser::parseFillPositionComponent(CSSParserValueList* valueList, unsigned& cumulativeFlags, FillPositionFlag& individualFlag, FillPositionParsingMode parsingMode)
{
- int id = valueList->current()->id;
+ CSSValueID id = valueList->current()->id;
if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id == CSSValueBottom || id == CSSValueCenter) {
int percent = 0;
if (id == CSSValueLeft || id == CSSValueRight) {
@@ -3735,12 +3737,12 @@ void CSSParser::parse3ValuesFillPosition(CSSParserValueList* valueList, RefPtr<C
valueList->next();
bool swapNeeded = false;
- int ident1 = parsedValue1->getIdent();
- int ident2 = parsedValue2->getIdent();
- int ident3 = value3->getIdent();
+ CSSValueID ident1 = static_cast<CSSValueID>(parsedValue1->getIdent());
+ CSSValueID ident2 = static_cast<CSSValueID>(parsedValue2->getIdent());
+ CSSValueID ident3 = static_cast<CSSValueID>(value3->getIdent());
- int firstPositionKeyword;
- int secondPositionKeyword;
+ CSSValueID firstPositionKeyword;
+ CSSValueID secondPositionKeyword;
if (ident1 == CSSValueCenter) {
// <position> requires the first 'center' to be followed by a keyword.
@@ -3806,8 +3808,8 @@ void CSSParser::parse3ValuesFillPosition(CSSParserValueList* valueList, RefPtr<C
#ifndef NDEBUG
CSSPrimitiveValue* first = toCSSPrimitiveValue(value1.get());
CSSPrimitiveValue* second = toCSSPrimitiveValue(value2.get());
- ident1 = first->getPairValue()->first()->getIdent();
- ident2 = second->getPairValue()->first()->getIdent();
+ ident1 = static_cast<CSSValueID>(first->getPairValue()->first()->getIdent());
+ ident2 = static_cast<CSSValueID>(second->getPairValue()->first()->getIdent());
ASSERT(ident1 == CSSValueLeft || ident1 == CSSValueRight);
ASSERT(ident2 == CSSValueBottom || ident2 == CSSValueTop);
#endif
@@ -3927,7 +3929,7 @@ void CSSParser::parse2ValuesFillPosition(CSSParserValueList* valueList, RefPtr<C
void CSSParser::parseFillRepeat(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2)
{
- int id = m_valueList->current()->id;
+ CSSValueID id = m_valueList->current()->id;
if (id == CSSValueRepeatX) {
m_implicitShorthand = true;
value1 = cssValuePool().createIdentifierValue(CSSValueRepeat);
@@ -3963,7 +3965,7 @@ void CSSParser::parseFillRepeat(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& valu
// If only one value was specified, value2 is the same as value1.
m_implicitShorthand = true;
- value2 = cssValuePool().createIdentifierValue(toCSSPrimitiveValue(value1.get())->getIdent());
+ value2 = cssValuePool().createIdentifierValue(static_cast<CSSValueID>(toCSSPrimitiveValue(value1.get())->getIdent()));
}
PassRefPtr<CSSValue> CSSParser::parseFillSize(CSSPropertyID propId, bool& allowComma)
@@ -4255,7 +4257,7 @@ PassRefPtr<CSSValue> CSSParser::parseAnimationProperty(AnimationParseContext& co
CSSParserValue* value = m_valueList->current();
if (value->unit != CSSPrimitiveValue::CSS_IDENT)
return 0;
- int result = cssPropertyID(value->string);
+ CSSPropertyID result = cssPropertyID(value->string);
if (result)
return cssValuePool().createIdentifierValue(result);
if (equalIgnoringCase(value, "all")) {
@@ -4715,7 +4717,7 @@ PassRefPtr<CSSValue> CSSParser::parseCounterContent(CSSParserValueList* args, bo
if (i->unit != CSSPrimitiveValue::CSS_IDENT)
return 0;
- int listStyleID = 0;
+ CSSValueID listStyleID = CSSValueInvalid;
if (i->id == CSSValueNone || (i->id >= CSSValueDisc && i->id <= CSSValueKatakanaIroha))
listStyleID = i->id;
else
@@ -5198,7 +5200,7 @@ PassRefPtr<CSSValueList> CSSParser::parseFontFamily()
bool CSSParser::parseLineHeight(bool important)
{
CSSParserValue* value = m_valueList->current();
- int id = value->id;
+ CSSValueID id = value->id;
bool validPrimitive = false;
// normal | <number> | <length> | <percentage> | inherit
if (id == CSSValueNormal)
@@ -5213,7 +5215,7 @@ bool CSSParser::parseLineHeight(bool important)
bool CSSParser::parseFontSize(bool important)
{
CSSParserValue* value = m_valueList->current();
- int id = value->id;
+ CSSValueID id = value->id;
bool validPrimitive = false;
// <absolute-size> | <relative-size> | <length> | <percentage> | inherit
if (id >= CSSValueXxSmall && id <= CSSValueLarger)
@@ -5282,7 +5284,7 @@ bool CSSParser::parseFontWeight(bool important)
if (validUnit(value, FInteger | FNonNeg, CSSQuirksMode)) {
int weight = static_cast<int>(value->fValue);
if (!(weight % 100) && weight >= 100 && weight <= 900) {
- addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(CSSValue100 + weight / 100 - 1), important);
+ addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important);
return true;
}
}
@@ -6873,7 +6875,7 @@ static bool parseDeprecatedGradientColorStop(CSSParser* p, CSSParserValue* a, CS
else
stop.m_position = cssValuePool().createValue(1, CSSPrimitiveValue::CSS_NUMBER);
- int id = args->current()->id;
+ CSSValueID id = args->current()->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu)
stop.m_color = cssValuePool().createIdentifierValue(id);
else
@@ -6900,7 +6902,7 @@ static bool parseDeprecatedGradientColorStop(CSSParser* p, CSSParserValue* a, CS
return false;
stopArg = args->next();
- int id = stopArg->id;
+ CSSValueID id = stopArg->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu)
stop.m_color = cssValuePool().createIdentifierValue(id);
else
@@ -7067,7 +7069,7 @@ static PassRefPtr<CSSPrimitiveValue> valueFromSideKeyword(CSSParserValue* a, boo
static PassRefPtr<CSSPrimitiveValue> parseGradientColorOrKeyword(CSSParser* p, CSSParserValue* value)
{
- int id = value->id;
+ CSSValueID id = value->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor)
return cssValuePool().createIdentifierValue(id);
@@ -7206,6 +7208,8 @@ bool CSSParser::parseDeprecatedRadialGradient(CSSParserValueList* valueList, Ref
sizeValue = cssValuePool().createIdentifierValue(a->id);
foundValue = true;
break;
+ default:
+ break;
}
if (foundValue) {
@@ -11568,14 +11572,14 @@ CSSPropertyID cssPropertyID(const CSSParserString& string)
}
template <typename CharacterType>
-static int cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
+static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
{
char buffer[maxCSSValueKeywordLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
for (unsigned i = 0; i != length; ++i) {
CharacterType c = valueKeyword[i];
if (c == 0 || c >= 0x7F)
- return 0; // illegal character
+ return CSSValueInvalid; // illegal character
buffer[i] = WTF::toASCIILower(c);
}
buffer[length] = '\0';
@@ -11591,16 +11595,16 @@ static int cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
}
const Value* hashTableEntry = findValue(buffer, length);
- return hashTableEntry ? hashTableEntry->id : 0;
+ return hashTableEntry ? static_cast<CSSValueID>(hashTableEntry->id) : CSSValueInvalid;
}
-int cssValueKeywordID(const CSSParserString& string)
+CSSValueID cssValueKeywordID(const CSSParserString& string)
{
unsigned length = string.length();
if (!length)
- return 0;
+ return CSSValueInvalid;
if (length > maxCSSValueKeywordLength)
- return 0;
+ return CSSValueInvalid;
return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : cssValueKeywordID(string.characters16(), length);
}
« 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