Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| index 6432b846e62d74e23d9fd369d8c4ff6327c26caa..59fe3fe2bbf2348dbee65f2fc5b051516dca3238 100644 |
| --- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| +++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| @@ -7,6 +7,7 @@ |
| #include "core/StylePropertyShorthand.h" |
| #include "core/css/CSSCalculationValue.h" |
| +#include "core/css/CSSCounterValue.h" |
| #include "core/css/CSSCrossfadeValue.h" |
| #include "core/css/CSSCursorImageValue.h" |
| #include "core/css/CSSCustomIdentValue.h" |
| @@ -2617,6 +2618,87 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeImage(CSSParserTokenRange& range, |
| return nullptr; |
| } |
| +static PassRefPtrWillBeRawPtr<CSSValue> consumeAttr(CSSParserTokenRange args, CSSParserContext context) |
| +{ |
| + if (args.peek().type() != IdentToken) |
| + return nullptr; |
| + |
| + String attrName = args.consumeIncludingWhitespace().value(); |
| + // CSS allows identifiers with "-" at the start, like "-webkit-mask-image". |
| + // But HTML attribute names can't have those characters, and we should not |
|
Timothy Loh
2015/12/15 04:44:54
This comment seems wrong. The HTML spec doesn't se
|
| + // even parse them inside attr(). |
| + if (attrName[0] == '-' || !args.atEnd()) |
| + return nullptr; |
| + |
| + if (context.isHTMLDocument()) |
| + attrName = attrName.lower(); |
| + |
| + RefPtrWillBeRawPtr<CSSFunctionValue> attrValue = CSSFunctionValue::create(CSSValueAttr); |
| + attrValue->append(CSSCustomIdentValue::create(attrName)); |
| + return attrValue.release(); |
| +} |
| + |
| +static PassRefPtrWillBeRawPtr<CSSValue> consumeCounterContent(CSSParserTokenRange args, bool counters) |
| +{ |
| + RefPtrWillBeRawPtr<CSSCustomIdentValue> identifier = consumeCustomIdent(args); |
| + if (!identifier) |
| + return nullptr; |
| + |
| + RefPtrWillBeRawPtr<CSSCustomIdentValue> separator = nullptr; |
|
Timothy Loh
2015/12/15 04:44:54
I guess I'll take a TODO here...
// TODO(timloh):
|
| + if (!counters) { |
| + separator = CSSCustomIdentValue::create(String()); |
| + } else { |
| + if (!consumeCommaIncludingWhitespace(args)) |
| + return nullptr; |
| + if (args.peek().type() != StringToken) |
| + return nullptr; |
| + separator = CSSCustomIdentValue::create(args.consumeIncludingWhitespace().value()); |
| + } |
| + |
| + RefPtrWillBeRawPtr<CSSPrimitiveValue> listStyle = nullptr; |
| + if (args.atEnd()) { // Make the list style default decimal |
|
Timothy Loh
2015/12/15 04:44:54
How about (one less args.atEnd(), longest line isn
|
| + listStyle = cssValuePool().createIdentifierValue(CSSValueDecimal); |
| + } else { |
| + if (!consumeCommaIncludingWhitespace(args)) |
| + return nullptr; |
| + CSSValueID id = args.consumeIncludingWhitespace().id(); |
| + if ((id != CSSValueNone && (id < CSSValueDisc || id > CSSValueKatakanaIroha)) || !args.atEnd()) |
| + return nullptr; |
| + listStyle = cssValuePool().createIdentifierValue(id); |
| + } |
| + |
| + return CSSCounterValue::create(identifier.release(), listStyle.release(), separator.release()); |
| +} |
| + |
| +static PassRefPtrWillBeRawPtr<CSSValueList> consumeContent(CSSParserTokenRange& range, CSSParserContext context) |
| +{ |
| + RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated(); |
| + |
| + do { |
| + RefPtrWillBeRawPtr<CSSValue> parsedValue = consumeImage(range, context); |
| + if (!parsedValue) { |
| + parsedValue = consumeIdent<CSSValueOpenQuote, CSSValueCloseQuote, CSSValueNoOpenQuote, CSSValueNoCloseQuote, CSSValueNormal>(range); |
| + if (!parsedValue) |
|
Timothy Loh
2015/12/15 04:44:54
I think it'd look nicer if these weren't nested --
|
| + parsedValue = consumeString(range); |
| + if (!parsedValue) { |
| + if (range.peek().type() == FunctionToken) { |
| + if (range.peek().functionId() == CSSValueAttr) |
| + parsedValue = consumeAttr(consumeFunction(range), context); |
| + else if (range.peek().functionId() == CSSValueCounter) |
| + parsedValue = consumeCounterContent(consumeFunction(range), false); |
| + else if (range.peek().functionId() == CSSValueCounters) |
| + parsedValue = consumeCounterContent(consumeFunction(range), true); |
| + } |
| + if (!parsedValue) |
| + return nullptr; |
| + } |
| + } |
| + values->append(parsedValue.release()); |
| + } while (!range.atEnd()); |
| + |
| + return values.release(); |
| +} |
| + |
| PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID unresolvedProperty) |
| { |
| CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
| @@ -2856,6 +2938,8 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty |
| return consumeContain(m_range); |
| case CSSPropertyTransformOrigin: |
| return consumeTransformOrigin(m_range, m_context.mode(), UnitlessQuirk::Forbid); |
| + case CSSPropertyContent: |
| + return consumeContent(m_range, m_context); |
| default: |
| return nullptr; |
| } |