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

Unified Diff: third_party/WebKit/Source/core/svg/SVGLength.cpp

Issue 2097383002: Added support of calc() for SVGLength (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 5 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: 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 b3c29143acc73b1f878c105add5ef1a1f7b1e6e6..cc559a15873b30a131bf77a9f403700afe6864b3 100644
--- a/third_party/WebKit/Source/core/svg/SVGLength.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGLength.cpp
@@ -73,10 +73,18 @@ bool SVGLength::operator==(const SVGLength& other) const
float SVGLength::value(const SVGLengthContext& context) const
{
+ if (isCalculated())
+ return context.resolveValue(*asCSSPrimitiveValue(), unitMode());
+
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(
@@ -84,9 +92,15 @@ void SVGLength::setValue(float value, const SVGLengthContext& context)
m_value->typeWithCalcResolved());
}
-bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type)
+static bool isCalcCSSUnitType(CSSPrimitiveValue::UnitType type)
{
- return (CSSPrimitiveValue::isLength(type) || type == CSSPrimitiveValue::UnitType::Number || type == CSSPrimitiveValue::UnitType::Percentage)
+ return type >= CSSPrimitiveValue::UnitType::Calc && type <= CSSPrimitiveValue::UnitType::CalcPercentageWithLengthAndNumber;
+}
+
+static bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type)
+{
+ return (CSSPrimitiveValue::isLength(type) || type == CSSPrimitiveValue::UnitType::Number
+ || type == CSSPrimitiveValue::UnitType::Percentage || isCalcCSSUnitType(type))
&& type != CSSPrimitiveValue::UnitType::QuirkyEms;
}
@@ -139,8 +153,7 @@ SVGParsingError SVGLength::setValueAsString(const String& string)
return SVGParseStatus::ExpectedLength;
const 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;
@@ -246,7 +259,15 @@ void SVGLength::calculateAnimatedValue(SVGAnimationElement* animationElement,
ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement->attributeName()));
- CSSPrimitiveValue::UnitType newUnit = percentage < 0.5 ? fromLength->typeWithCalcResolved() : toLength->typeWithCalcResolved();
+ // TODO(shanmuga.m): Construct a calc() expression if the units fall in different categories.
+ CSSPrimitiveValue::UnitType newUnit = CSSPrimitiveValue::UnitType::UserUnits;
+ if (percentage < 0.5) {
+ if (!fromLength->isCalculated())
+ newUnit = fromLength->typeWithCalcResolved();
+ } else {
+ if (!toLength->isCalculated())
+ newUnit = toLength->typeWithCalcResolved();
+ }
animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, unitMode(), newUnit);
m_value = CSSPrimitiveValue::create(animatedNumber, newUnit);
}
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGLength.h ('k') | third_party/WebKit/Source/core/svg/SVGLengthContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698