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
case CSSPrimitiveValue::UnitType::Inches:
case CSSPrimitiveValue::UnitType::Points:
case CSSPrimitiveValue::UnitType::Picas:
case CSSPrimitiveValue::UnitType::UserUnits:
lengthType = UnitTypePixels;
return true;
case CSSPrimitiveValue::UnitType::Ems:
......
......@@ -280,10 +280,13 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan
case CSSPrimitiveValue::UnitType::Points:
case CSSPrimitiveValue::UnitType::Picas:
case CSSPrimitiveValue::UnitType::UserUnits:
break;
case CSSPrimitiveValue::UnitType::ViewportWidth:
case CSSPrimitiveValue::UnitType::ViewportHeight:
case CSSPrimitiveValue::UnitType::ViewportMin:
case CSSPrimitiveValue::UnitType::ViewportMax:
if (cssParserMode == SVGAttributeMode)
return nullptr;
break;
default:
return nullptr;
......@@ -301,6 +304,8 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan
unitType = CSSPrimitiveValue::UnitType::UserUnits;
return cssValuePool().createValue(range.consumeIncludingWhitespace().numericValue(), unitType);
}
if (cssParserMode == SVGAttributeMode)
return nullptr;
CalcParser calcParser(range, valueRange);
if (calcParser.value() && calcParser.value()->category() == CalcLength)
return calcParser.consumeValue();
......@@ -1850,6 +1855,22 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& ra
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)
{
CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
......@@ -2025,6 +2046,8 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
case CSSPropertyFlexGrow:
case CSSPropertyFlexShrink:
return consumeNumber(m_range, ValueRangeNonNegative);
case CSSPropertyStrokeDasharray:
return consumeStrokeDasharray(m_range);
default:
return nullptr;
}
......
......@@ -199,7 +199,6 @@ private:
PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceSrc();
bool parseSVGValue(CSSPropertyID propId, bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseSVGStrokeDasharray();
// CSS3 Parsing Routines (for properties specific to CSS3)
bool parseBorderImageShorthand(CSSPropertyID, bool important);
......
......@@ -1153,6 +1153,7 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
case CSSPropertyFlexGrow:
case CSSPropertyFlexShrink:
case CSSPropertyFlexFlow:
case CSSPropertyStrokeDasharray:
validPrimitive = false;
break;
......@@ -5441,12 +5442,6 @@ bool CSSPropertyParser::parseSVGValue(CSSPropertyID propId, bool important)
case CSSPropertyRy:
validPrimitive = validUnit(value, FLength | FPercent, SVGAttributeMode);
break;
case CSSPropertyStrokeDasharray: // none | <dasharray> | inherit
if (id == CSSValueNone)
validPrimitive = true;
else
parsedValue = parseSVGStrokeDasharray();
break;
default:
// 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)
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
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