Commit 22ae9766 authored by rob.buis's avatar rob.buis Committed by Commit bot

Move stroke-dasharray property into CSSPropertyParser

Move stroke-dasharray property handling from
LegacyCSSPropertyParser into CSSPropertyParser.

With this change the stroke-dasharray produces UserUnits
CSSPrimitiveValues instead of Pixels. This caused
regressions on interpolation tests, I added UserUnits
to the unitTypeToLengthUnitType switch to fix this.

BUG=499780

Review URL: https://codereview.chromium.org/1442233002

Cr-Commit-Position: refs/heads/master@{#361069}
parent 6bed6e20
...@@ -556,6 +556,7 @@ bool CSSPrimitiveValue::unitTypeToLengthUnitType(UnitType unitType, LengthUnitTy ...@@ -556,6 +556,7 @@ bool CSSPrimitiveValue::unitTypeToLengthUnitType(UnitType unitType, LengthUnitTy
case CSSPrimitiveValue::UnitType::Inches: case CSSPrimitiveValue::UnitType::Inches:
case CSSPrimitiveValue::UnitType::Points: case CSSPrimitiveValue::UnitType::Points:
case CSSPrimitiveValue::UnitType::Picas: case CSSPrimitiveValue::UnitType::Picas:
case CSSPrimitiveValue::UnitType::UserUnits:
lengthType = UnitTypePixels; lengthType = UnitTypePixels;
return true; return true;
case CSSPrimitiveValue::UnitType::Ems: case CSSPrimitiveValue::UnitType::Ems:
......
...@@ -280,10 +280,13 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan ...@@ -280,10 +280,13 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan
case CSSPrimitiveValue::UnitType::Points: case CSSPrimitiveValue::UnitType::Points:
case CSSPrimitiveValue::UnitType::Picas: case CSSPrimitiveValue::UnitType::Picas:
case CSSPrimitiveValue::UnitType::UserUnits: case CSSPrimitiveValue::UnitType::UserUnits:
break;
case CSSPrimitiveValue::UnitType::ViewportWidth: case CSSPrimitiveValue::UnitType::ViewportWidth:
case CSSPrimitiveValue::UnitType::ViewportHeight: case CSSPrimitiveValue::UnitType::ViewportHeight:
case CSSPrimitiveValue::UnitType::ViewportMin: case CSSPrimitiveValue::UnitType::ViewportMin:
case CSSPrimitiveValue::UnitType::ViewportMax: case CSSPrimitiveValue::UnitType::ViewportMax:
if (cssParserMode == SVGAttributeMode)
return nullptr;
break; break;
default: default:
return nullptr; return nullptr;
...@@ -301,6 +304,8 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan ...@@ -301,6 +304,8 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan
unitType = CSSPrimitiveValue::UnitType::UserUnits; unitType = CSSPrimitiveValue::UnitType::UserUnits;
return cssValuePool().createValue(range.consumeIncludingWhitespace().numericValue(), unitType); return cssValuePool().createValue(range.consumeIncludingWhitespace().numericValue(), unitType);
} }
if (cssParserMode == SVGAttributeMode)
return nullptr;
CalcParser calcParser(range, valueRange); CalcParser calcParser(range, valueRange);
if (calcParser.value() && calcParser.value()->category() == CalcLength) if (calcParser.value() && calcParser.value()->category() == CalcLength)
return calcParser.consumeValue(); return calcParser.consumeValue();
...@@ -1850,6 +1855,22 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& ra ...@@ -1850,6 +1855,22 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& ra
return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative); return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
} }
static PassRefPtrWillBeRawPtr<CSSValue> consumeStrokeDasharray(CSSParserTokenRange& range)
{
CSSValueID id = range.peek().id();
if (id == CSSValueNone)
return consumeIdent(range);
RefPtrWillBeRawPtr<CSSValueList> dashes = CSSValueList::createCommaSeparated();
do {
RefPtrWillBeRawPtr<CSSPrimitiveValue> dash = consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
if (!dash || (consumeCommaIncludingWhitespace(range) && range.atEnd()))
return nullptr;
dashes->append(dash.release());
} while (!range.atEnd());
return dashes.release();
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID unresolvedProperty) PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID unresolvedProperty)
{ {
CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
...@@ -2025,6 +2046,8 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ...@@ -2025,6 +2046,8 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
case CSSPropertyFlexGrow: case CSSPropertyFlexGrow:
case CSSPropertyFlexShrink: case CSSPropertyFlexShrink:
return consumeNumber(m_range, ValueRangeNonNegative); return consumeNumber(m_range, ValueRangeNonNegative);
case CSSPropertyStrokeDasharray:
return consumeStrokeDasharray(m_range);
default: default:
return nullptr; return nullptr;
} }
......
...@@ -199,7 +199,6 @@ private: ...@@ -199,7 +199,6 @@ private:
PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceSrc(); PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceSrc();
bool parseSVGValue(CSSPropertyID propId, bool important); bool parseSVGValue(CSSPropertyID propId, bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseSVGStrokeDasharray();
// CSS3 Parsing Routines (for properties specific to CSS3) // CSS3 Parsing Routines (for properties specific to CSS3)
bool parseBorderImageShorthand(CSSPropertyID, bool important); bool parseBorderImageShorthand(CSSPropertyID, bool important);
......
...@@ -1153,6 +1153,7 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import ...@@ -1153,6 +1153,7 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
case CSSPropertyFlexGrow: case CSSPropertyFlexGrow:
case CSSPropertyFlexShrink: case CSSPropertyFlexShrink:
case CSSPropertyFlexFlow: case CSSPropertyFlexFlow:
case CSSPropertyStrokeDasharray:
validPrimitive = false; validPrimitive = false;
break; break;
...@@ -5441,12 +5442,6 @@ bool CSSPropertyParser::parseSVGValue(CSSPropertyID propId, bool important) ...@@ -5441,12 +5442,6 @@ bool CSSPropertyParser::parseSVGValue(CSSPropertyID propId, bool important)
case CSSPropertyRy: case CSSPropertyRy:
validPrimitive = validUnit(value, FLength | FPercent, SVGAttributeMode); validPrimitive = validUnit(value, FLength | FPercent, SVGAttributeMode);
break; break;
case CSSPropertyStrokeDasharray: // none | <dasharray> | inherit
if (id == CSSValueNone)
validPrimitive = true;
else
parsedValue = parseSVGStrokeDasharray();
break;
default: default:
// If you crash here, it's because you added a css property and are not handling it // If you crash here, it's because you added a css property and are not handling it
...@@ -5481,30 +5476,4 @@ bool CSSPropertyParser::parseSVGValue(CSSPropertyID propId, bool important) ...@@ -5481,30 +5476,4 @@ bool CSSPropertyParser::parseSVGValue(CSSPropertyID propId, bool important)
return true; return true;
} }
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSVGStrokeDasharray()
{
RefPtrWillBeRawPtr<CSSValueList> ret = CSSValueList::createCommaSeparated();
CSSParserValue* value = m_valueList->current();
bool validPrimitive = true;
while (value) {
validPrimitive = validUnit(value, FLength | FPercent | FNonNeg, SVGAttributeMode);
if (!validPrimitive)
break;
if (value->id)
ret->append(CSSPrimitiveValue::createIdentifier(value->id));
else if (value->unit() >= CSSPrimitiveValue::UnitType::Number && value->unit() <= CSSPrimitiveValue::UnitType::Kilohertz)
ret->append(CSSPrimitiveValue::create(value->fValue, value->unit()));
else if (value->unit() == CSSPrimitiveValue::UnitType::Rems || value->unit() == CSSPrimitiveValue::UnitType::Chs)
ret->append(CSSPrimitiveValue::create(value->fValue, value->unit()));
value = m_valueList->next();
bool commaConsumed = consumeComma(m_valueList);
value = m_valueList->current();
if (commaConsumed && !value)
return nullptr;
}
if (!validPrimitive)
return nullptr;
return ret.release();
}
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment