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

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: Rebase 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 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;
}

Powered by Google App Engine
This is Rietveld 408576698