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

Unified Diff: Source/core/css/parser/LegacyCSSPropertyParser.cpp

Issue 1319343004: Add property parser code path based on CSSParserTokenRange (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add webkit-highlight parsing Created 5 years, 3 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
Index: Source/core/css/parser/LegacyCSSPropertyParser.cpp
diff --git a/Source/core/css/parser/CSSPropertyParser.cpp b/Source/core/css/parser/LegacyCSSPropertyParser.cpp
similarity index 98%
copy from Source/core/css/parser/CSSPropertyParser.cpp
copy to Source/core/css/parser/LegacyCSSPropertyParser.cpp
index d08862af53cf57c0a7509af8f5495f06444435a7..55150ba1806e6b1d22a8b2ae3122955337e9c730 100644
--- a/Source/core/css/parser/CSSPropertyParser.cpp
+++ b/Source/core/css/parser/LegacyCSSPropertyParser.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);
+ if (!valueList.size())
+ return false; // Parser error
+ CSSPropertyParser parser(&valueList, range, context, parsedProperties, ruleType);
CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty);
bool parseSuccess;
@@ -469,20 +473,23 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
return true;
}
+ RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr;
+ if ((parsedValue = parseSingleValue(propId))) {
+ if (!m_range.atEnd())
+ return false;
+ addProperty(propId, parsedValue.release(), important);
+ return true;
+ }
+ if (parseShorthand(propId, 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] ]
parsedValue = parseSize();
break;
- case CSSPropertyQuotes: // [<string> <string>]+ | none
- if (id == CSSValueNone)
- validPrimitive = true;
- else
- parsedValue = parseQuotes();
- break;
case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
// close-quote | no-open-quote | no-close-quote ]+ | inherit
@@ -498,24 +505,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
/* Start of supported CSS properties with validation. This is needed for parseShorthand to work
* correctly and allows optimization in blink::applyRule(..)
*/
- case CSSPropertyOverflow: {
- ShorthandScope scope(this, propId);
- if (!parseValue(CSSPropertyOverflowY, important) || m_valueList->current())
- return false;
-
- RefPtrWillBeRawPtr<CSSValue> overflowXValue = nullptr;
-
- // FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. If this value has been
- // set using the shorthand, then for now overflow-x will default to auto, but once we implement
- // pagination controls, it should default to hidden. If the overflow-y value is anything but
- // paged-x or paged-y, then overflow-x and overflow-y should have the same value.
- if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
- overflowXValue = cssValuePool().createIdentifierValue(CSSValueAuto);
- else
- overflowXValue = m_parsedProperties.last().value();
- addProperty(CSSPropertyOverflowX, overflowXValue.release(), important);
- return true;
- }
case CSSPropertyTextAlign:
// left | right | center | justify | -webkit-left | -webkit-right | -webkit-center | -webkit-match-parent
@@ -1281,19 +1270,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
return parseGridShorthand(important);
- case CSSPropertyWebkitMarginCollapse: {
- ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
- if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important))
- return false;
- if (!m_valueList->current()) {
- CSSValue* value = m_parsedProperties.last().value();
- addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
- return true;
- }
- if (!parseValue(webkitMarginCollapseShorthand().properties()[1], important))
- return false;
- return !m_valueList->current();
- }
case CSSPropertyWebkitColumnCount:
parsedValue = parseColumnCount();
break;
@@ -1309,9 +1285,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
@@ -1326,15 +1299,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
validPrimitive = validUnit(value, FLength | FUnitlessQuirk);
break;
- case CSSPropertyWebkitHighlight:
- if (id == CSSValueNone) {
- validPrimitive = true;
- } else if (value->unit() == CSSPrimitiveValue::UnitType::String) {
- parsedValue = createPrimitiveStringValue(value);
- m_valueList->next();
- }
- break;
-
case CSSPropertyWebkitHyphenateCharacter:
case CSSPropertyWebkitLocale:
if (id == CSSValueAuto) {
@@ -1443,9 +1407,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
return parseTransitionShorthand(important);
case CSSPropertyInvalid:
return false;
- case CSSPropertyPage:
- parsedValue = parsePage();
- break;
// CSS Text Layout Module Level 3: Vertical writing support
case CSSPropertyWebkitTextEmphasis:
return parseShorthand(propId, webkitTextEmphasisShorthand(), important);
@@ -1523,6 +1484,16 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
validPrimitive = false;
break;
+ // These were not accepted by the new path above so we should return false.
+ case CSSPropertyWebkitMarginCollapse:
+ case CSSPropertyWillChange:
+ case CSSPropertyPage:
+ case CSSPropertyOverflow:
+ case CSSPropertyQuotes:
+ case CSSPropertyWebkitHighlight:
+ validPrimitive = false;
+ break;
+
case CSSPropertyScrollSnapPointsX:
case CSSPropertyScrollSnapPointsY:
parsedValue = parseScrollSnapPoints();
@@ -2064,19 +2035,6 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseScrollSnapCoordinate()
return parsePositionList(m_valueList);
}
-PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parsePage()
-{
- CSSParserValue* value = m_valueList->current();
- m_valueList->next();
- ASSERT(value);
-
- if (value->id == CSSValueAuto)
- return cssValuePool().createIdentifierValue(value->id);
- if (value->m_unit == CSSParserValue::Identifier)
- return createPrimitiveCustomIdentValue(value);
- return nullptr;
-}
-
// <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ]
PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseSize()
{
@@ -2143,23 +2101,6 @@ CSSPropertyParser::SizeParameterType CSSPropertyParser::parseSizeParameter(CSSVa
}
}
-// [ <string> <string> ]+ | none, but none is handled in parseValue
-PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseQuotes()
-{
- RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
- while (CSSParserValue* val = m_valueList->current()) {
- RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr;
- if (val->unit() != CSSPrimitiveValue::UnitType::String)
- return nullptr;
- parsedValue = createPrimitiveStringValue(val);
- values->append(parsedValue.release());
- m_valueList->next();
- }
- if (values->length() && values->length() % 2 == 0)
- return values.release();
- return nullptr;
-}
-
// [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
// in CSS 2.1 this got somewhat reduced:
// [ <string> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
@@ -6716,56 +6657,6 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseImageSet(CSSParserValue
return imageSet.release();
}
-PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseWillChange()
-{
- RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
- if (m_valueList->current()->id == CSSValueAuto) {
- // FIXME: This will be read back as an empty string instead of auto
- 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)
- return nullptr;
-
- CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(currentValue->string);
- if (unresolvedProperty) {
- ASSERT(CSSPropertyMetadata::isEnabledProperty(unresolvedProperty));
- // Now "all" is used by both CSSValue and CSSPropertyValue.
- // Need to return nullptr when currentValue is CSSPropertyAll.
- if (unresolvedProperty == CSSPropertyWillChange || unresolvedProperty == CSSPropertyAll)
- return nullptr;
- values->append(cssValuePool().createIdentifierValue(unresolvedProperty));
- } else {
- switch (currentValue->id) {
- case CSSValueNone:
- case CSSValueAll:
- case CSSValueAuto:
- case CSSValueDefault:
- case CSSValueInitial:
- case CSSValueInherit:
- return nullptr;
- case CSSValueContents:
- case CSSValueScrollPosition:
- values->append(cssValuePool().createIdentifierValue(currentValue->id));
- break;
- default:
- break;
- }
- }
-
- if (!m_valueList->next())
- break;
- if (!consumeComma(m_valueList))
- return nullptr;
- }
-
- return values.release();
-}
-
PassRefPtrWillBeRawPtr<CSSFunctionValue> CSSPropertyParser::parseBuiltinFilterArguments(CSSParserValueList* args, CSSValueID filterType)
{
RefPtrWillBeRawPtr<CSSFunctionValue> filterValue = CSSFunctionValue::create(filterType);

Powered by Google App Engine
This is Rietveld 408576698