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

Unified Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp

Issue 1512603002: Move content property into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch for landing Created 5 years 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
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 058d7a97e54975cb0ff8920814f2fee34c6aca7a..01669d15a13b58ae1d147a92985e4c5e48c93be2 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"
@@ -2796,6 +2797,86 @@ 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
+ // even parse them inside attr().
+ // TODO(timloh): We should allow any <ident-token> here.
+ 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;
+
+ // TODO(timloh): Make this a CSSStringValue.
+ RefPtrWillBeRawPtr<CSSCustomIdentValue> separator = nullptr;
+ 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 (consumeCommaIncludingWhitespace(args)) {
+ CSSValueID id = args.peek().id();
+ if ((id != CSSValueNone && (id < CSSValueDisc || id > CSSValueKatakanaIroha)))
+ return nullptr;
+ listStyle = consumeIdent(args);
+ } else {
+ listStyle = cssValuePool().createIdentifierValue(CSSValueDecimal);
+ }
+
+ if (!args.atEnd())
+ return nullptr;
+ 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)
+ parsedValue = consumeString(range);
+ if (!parsedValue) {
+ 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);
@@ -3037,6 +3118,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;
}

Powered by Google App Engine
This is Rietveld 408576698