Chromium Code Reviews| Index: Source/core/css/parser/CSSPropertyParser.cpp |
| diff --git a/Source/core/css/parser/CSSPropertyParser.cpp b/Source/core/css/parser/CSSPropertyParser.cpp |
| index 3ed4a660864f74fb5a0cb1082f61716d827093d0..f567885e5e5ab951bbe3d70ca6c8fcd826b7ecab 100644 |
| --- a/Source/core/css/parser/CSSPropertyParser.cpp |
| +++ b/Source/core/css/parser/CSSPropertyParser.cpp |
| @@ -74,10 +74,11 @@ static bool equalIgnoringCase(const CSSParserString& a, const char (&b)[N]) |
| return a.is8Bit() ? WTF::equalIgnoringCase(b, a.characters8(), length) : WTF::equalIgnoringCase(b, a.characters16(), length); |
| } |
| -CSSPropertyParser::CSSPropertyParser(CSSParserValueList* valueList, |
| +CSSPropertyParser::CSSPropertyParser(CSSParserValueList* valueList, const CSSParserTokenRange& range, |
| const CSSParserContext& context, WillBeHeapVector<CSSProperty, 256>& parsedProperties, |
| StyleRule::Type ruleType) |
| : m_valueList(valueList) |
| + , m_range(range) |
| , m_context(context) |
| , m_parsedProperties(parsedProperties) |
| , m_ruleType(ruleType) |
| @@ -88,12 +89,15 @@ CSSPropertyParser::CSSPropertyParser(CSSParserValueList* valueList, |
| } |
| bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool important, |
| - CSSParserValueList* valueList, const CSSParserContext& context, |
| + const CSSParserTokenRange& range, const CSSParserContext& context, |
| WillBeHeapVector<CSSProperty, 256>& parsedProperties, StyleRule::Type ruleType) |
| { |
| int parsedPropertiesSize = parsedProperties.size(); |
| - CSSPropertyParser parser(valueList, context, parsedProperties, ruleType); |
| + CSSParserValueList valueList(range); |
|
Timothy Loh
2015/09/04 01:24:40
Probably OK for now but at some point this needs t
|
| + if (!valueList.size()) |
| + return false; // Parser error |
| + CSSPropertyParser parser(&valueList, range, context, parsedProperties, ruleType); |
| CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); |
| bool parseSuccess; |
| @@ -335,6 +339,15 @@ static bool consumeComma(CSSParserValueList* valueList) |
| return true; |
| } |
| +static bool consumeCommaIncludingWhitespace(CSSParserTokenRange& valueList) |
| +{ |
| + CSSParserToken value = valueList.peek(); |
| + if (value.type() != CommaToken) |
| + return false; |
| + valueList.consumeIncludingWhitespace(); |
| + return true; |
| +} |
| + |
| static inline bool isForwardSlashOperator(CSSParserValue* value) |
| { |
| ASSERT(value); |
| @@ -431,6 +444,18 @@ void CSSPropertyParser::addExpandedPropertyForValue(CSSPropertyID propId, PassRe |
| addProperty(longhands[i], value, important); |
| } |
| +PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID propId) |
| +{ |
| + m_range.consumeWhitespace(); |
| + switch (propId) { |
| + case CSSPropertyWillChange: |
| + return parseWillChange(); |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| + return nullptr; |
| +} |
| + |
| bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool important) |
| { |
| CSSPropertyID propId = resolveCSSPropertyID(unresolvedProperty); |
| @@ -469,9 +494,17 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import |
| return true; |
| } |
| + RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; |
| + if (propId == CSSPropertyWillChange) { |
| + parsedValue = parseSingleValue(propId); |
| + if (!parsedValue || !m_range.atEnd()) |
| + return false; |
| + addProperty(propId, parsedValue.release(), important); |
| + return true; |
| + } |
| + |
| bool validPrimitive = false; |
| Units unitless = FUnknown; |
| - RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; |
| switch (propId) { |
| case CSSPropertySize: // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ] |
| @@ -1316,9 +1349,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import |
| case CSSPropertyWebkitColumnWidth: // auto | <length> |
| parsedValue = parseColumnWidth(); |
| break; |
| - case CSSPropertyWillChange: |
| - parsedValue = parseWillChange(); |
| - break; |
| // End of CSS3 properties |
| // Apple specific properties. These will never be standardized and are purely to |
| @@ -6811,22 +6841,27 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseImageSet(CSSParserValue |
| return imageSet.release(); |
| } |
| +static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeIdent(CSSParserTokenRange& range) |
| +{ |
| + ASSERT(range.peek().type() == IdentToken); |
| + return cssValuePool().createIdentifierValue(range.consumeIncludingWhitespace().id()); |
| +} |
| + |
| PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseWillChange() |
| { |
| RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated(); |
| - if (m_valueList->current()->id == CSSValueAuto) { |
| + if (m_range.peek().id() == CSSValueAuto) { |
| // FIXME: This will be read back as an empty string instead of auto |
| + m_range.consumeIncludingWhitespace(); |
| return values.release(); |
| } |
| // Every comma-separated list of identifiers is a valid will-change value, |
| // unless the list includes an explicitly disallowed identifier. |
| while (true) { |
| - CSSParserValue* currentValue = m_valueList->current(); |
| - if (!currentValue || currentValue->m_unit != CSSParserValue::Identifier) |
| + if (m_range.peek().type() != IdentToken) |
| return nullptr; |
| - |
| - CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(currentValue->string); |
| + CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(m_range.peek().value()); |
| if (unresolvedProperty) { |
| ASSERT(CSSPropertyMetadata::isEnabledProperty(unresolvedProperty)); |
| // Now "all" is used by both CSSValue and CSSPropertyValue. |
| @@ -6834,8 +6869,9 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseWillChange() |
| if (unresolvedProperty == CSSPropertyWillChange || unresolvedProperty == CSSPropertyAll) |
| return nullptr; |
| values->append(cssValuePool().createIdentifierValue(unresolvedProperty)); |
| + m_range.consumeIncludingWhitespace(); |
| } else { |
| - switch (currentValue->id) { |
| + switch (m_range.peek().id()) { |
| case CSSValueNone: |
| case CSSValueAll: |
| case CSSValueAuto: |
| @@ -6845,16 +6881,17 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseWillChange() |
| return nullptr; |
| case CSSValueContents: |
| case CSSValueScrollPosition: |
| - values->append(cssValuePool().createIdentifierValue(currentValue->id)); |
| + values->append(consumeIdent(m_range)); |
| break; |
| default: |
| + m_range.consumeIncludingWhitespace(); |
| break; |
| } |
| } |
| - if (!m_valueList->next()) |
| + if (m_range.atEnd()) |
| break; |
| - if (!consumeComma(m_valueList)) |
| + if (!consumeCommaIncludingWhitespace(m_range)) |
| return nullptr; |
| } |