Chromium Code Reviews| Index: third_party/WebKit/Source/core/svg/SVGLength.cpp |
| diff --git a/third_party/WebKit/Source/core/svg/SVGLength.cpp b/third_party/WebKit/Source/core/svg/SVGLength.cpp |
| index eb915deaae0bfbcfba087d24b208e0c90dc2c5fa..8d2c7e30c5f8fb3977002c085bcfa39699ed755e 100644 |
| --- a/third_party/WebKit/Source/core/svg/SVGLength.cpp |
| +++ b/third_party/WebKit/Source/core/svg/SVGLength.cpp |
| @@ -71,12 +71,38 @@ bool SVGLength::operator==(const SVGLength& other) const |
| return m_unitMode == other.m_unitMode && m_value == other.m_value; |
| } |
| +bool isCalcCSSUnitType(CSSPrimitiveValue::UnitType type) |
|
fs
2016/07/16 21:13:02
Make this static (and isSupportedCSSUnitType too,
Shanmuga Pandi
2016/07/18 13:35:33
Done.
|
| +{ |
| + return (type >= CSSPrimitiveValue::UnitType::Calc && type <= CSSPrimitiveValue::UnitType::CalcPercentageWithLengthAndNumber); |
|
fs
2016/07/16 21:13:02
Drop parenthesis.
Shanmuga Pandi
2016/07/18 13:35:33
Done.
|
| +} |
| + |
| +float SVGLength::resolveCalcValue(const SVGLengthContext& context) const |
|
fs
2016/07/16 21:13:02
We could consider going through CSSPrimitiveValue:
Shanmuga Pandi
2016/07/18 13:35:33
Done.
|
| +{ |
| + CSSLengthArray lengthArray; |
| + m_value->accumulateLengthArray(lengthArray); |
| + float value = 0; |
|
fs
2016/07/16 21:13:02
If we end up keeping this I suggest making this 'd
|
| + for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { |
| + double entry = lengthArray.values[i]; |
| + if (entry) |
| + value += context.convertValueToUserUnits(entry, unitMode(), SVGLength::toUnitType(i)); |
| + } |
| + return value; |
| +} |
| + |
| float SVGLength::value(const SVGLengthContext& context) const |
| { |
| + if (isCalculated()) |
| + return resolveCalcValue(context); |
| + |
| return context.convertValueToUserUnits( |
| m_value->getFloatValue(), unitMode(), m_value->typeWithCalcResolved()); |
| } |
| +void SVGLength::setValueAsNumber(float value) |
| +{ |
| + m_value = CSSPrimitiveValue::create(value, CSSPrimitiveValue::UnitType::UserUnits); |
| +} |
| + |
| void SVGLength::setValue(float value, const SVGLengthContext& context) |
| { |
| m_value = CSSPrimitiveValue::create( |
| @@ -86,7 +112,8 @@ void SVGLength::setValue(float value, const SVGLengthContext& context) |
| bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type) |
| { |
| - return (CSSPrimitiveValue::isLength(type) || type == CSSPrimitiveValue::UnitType::Number || type == CSSPrimitiveValue::UnitType::Percentage) |
| + return (CSSPrimitiveValue::isLength(type) || type == CSSPrimitiveValue::UnitType::Number |
| + || type == CSSPrimitiveValue::UnitType::Percentage || isCalcCSSUnitType(type)) |
| && type != CSSPrimitiveValue::UnitType::QuirkyEms; |
| } |
| @@ -139,11 +166,11 @@ SVGParsingError SVGLength::setValueAsString(const String& string) |
| return SVGParseStatus::ExpectedLength; |
| CSSPrimitiveValue* newValue = toCSSPrimitiveValue(parsed); |
| - // TODO(fs): Enable calc for SVG lengths |
| - if (newValue->isCalculated() || !isSupportedCSSUnitType(newValue->typeWithCalcResolved())) |
| + if (!isSupportedCSSUnitType(newValue->typeWithCalcResolved())) |
| return SVGParseStatus::ExpectedLength; |
| m_value = newValue; |
| + |
|
fs
2016/07/16 21:13:02
Drop.
Shanmuga Pandi
2016/07/18 13:35:32
Done.
|
| return SVGParseStatus::NoError; |
| } |
| @@ -246,7 +273,14 @@ void SVGLength::calculateAnimatedValue(SVGAnimationElement* animationElement, |
| ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement->attributeName())); |
| - CSSPrimitiveValue::UnitType newUnit = percentage < 0.5 ? fromLength->typeWithCalcResolved() : toLength->typeWithCalcResolved(); |
| + CSSPrimitiveValue::UnitType newUnit = CSSPrimitiveValue::UnitType::UserUnits; |
| + if (percentage < 0.5) { |
| + if (!fromLength->isCalculated()) |
|
fs
2016/07/16 21:13:02
Test for this code? (Preferably i think this would
Shanmuga Pandi
2016/07/18 13:35:32
Yes. We could just construct a calc_expression lat
fs
2016/07/18 13:56:48
Please add a TODO about constructing a calc() expr
|
| + newUnit = fromLength->typeWithCalcResolved(); |
| + } else { |
| + if (!toLength->isCalculated()) |
| + newUnit = toLength->typeWithCalcResolved(); |
| + } |
| animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, unitMode(), newUnit); |
| m_value = CSSPrimitiveValue::create(animatedNumber, newUnit); |
| } |