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

Unified Diff: Source/core/svg/SVGLengthTearOff.cpp

Issue 1162453002: [svg2] Make SVGLength wrap a CSSPrimitiveValue (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: nit Created 5 years, 7 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
« no previous file with comments | « Source/core/svg/SVGLengthTearOff.h ('k') | Source/core/svg/SVGSVGElement.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/SVGLengthTearOff.cpp
diff --git a/Source/core/svg/SVGLengthTearOff.cpp b/Source/core/svg/SVGLengthTearOff.cpp
index bf29952cee2d56b5a17dbf0eaaf5fdd9b13ef7bb..fdc18e5f1baee2045a7295d540d8d0a7f0afeb71 100644
--- a/Source/core/svg/SVGLengthTearOff.cpp
+++ b/Source/core/svg/SVGLengthTearOff.cpp
@@ -40,10 +40,9 @@ namespace blink {
namespace {
-inline SVGLengthType toSVGLengthType(unsigned short type)
+inline bool isValidLengthUnit(unsigned short type)
{
- ASSERT(type >= LengthTypeUnknown && type <= LengthTypePC);
- return static_cast<SVGLengthType>(type);
+ return type != CSSPrimitiveValue::CSS_UNKNOWN && type <= CSSPrimitiveValue::CSS_PC;
}
inline bool canResolveRelativeUnits(const SVGElement* contextElement)
@@ -51,11 +50,46 @@ inline bool canResolveRelativeUnits(const SVGElement* contextElement)
return contextElement && contextElement->inDocument();
}
+inline CSSPrimitiveValue::UnitType toCSSUnitType(unsigned short type)
+{
+ ASSERT(isValidLengthUnit(type));
+ return static_cast<CSSPrimitiveValue::UnitType>(type);
+}
+
+inline SVGLengthType toSVGLengthType(CSSPrimitiveValue::UnitType type)
+{
+ switch (type) {
+ case CSSPrimitiveValue::UnitType::CSS_UNKNOWN:
+ return LengthTypeUnknown;
+ case CSSPrimitiveValue::UnitType::CSS_NUMBER:
+ return LengthTypeNumber;
+ case CSSPrimitiveValue::UnitType::CSS_PERCENTAGE:
+ return LengthTypePercentage;
+ case CSSPrimitiveValue::UnitType::CSS_EMS:
+ return LengthTypeEMS;
+ case CSSPrimitiveValue::UnitType::CSS_EXS:
+ return LengthTypeEXS;
+ case CSSPrimitiveValue::UnitType::CSS_PX:
+ return LengthTypePX;
+ case CSSPrimitiveValue::UnitType::CSS_CM:
+ return LengthTypeCM;
+ case CSSPrimitiveValue::UnitType::CSS_MM:
+ return LengthTypeMM;
+ case CSSPrimitiveValue::UnitType::CSS_IN:
+ return LengthTypeIN;
+ case CSSPrimitiveValue::UnitType::CSS_PT:
+ return LengthTypePT;
+ case CSSPrimitiveValue::UnitType::CSS_PC:
+ return LengthTypePC;
+ default:
+ return LengthTypeUnknown;
+ }
+}
} // namespace
SVGLengthType SVGLengthTearOff::unitType()
{
- return hasExposedLengthUnit() ? target()->unitType() : LengthTypeUnknown;
+ return hasExposedLengthUnit() ? toSVGLengthType(target()->primitiveType()) : LengthTypeUnknown;
}
SVGLengthMode SVGLengthTearOff::unitMode()
@@ -139,12 +173,12 @@ void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
return;
}
- if (unitType == LengthTypeUnknown || unitType > LengthTypePC) {
+ if (!isValidLengthUnit(unitType)) {
exceptionState.throwDOMException(NotSupportedError, "Cannot set value with unknown or invalid units (" + String::number(unitType) + ").");
return;
}
- target()->newValueSpecifiedUnits(toSVGLengthType(unitType), valueInSpecifiedUnits);
+ target()->newValueSpecifiedUnits(toCSSUnitType(unitType), valueInSpecifiedUnits);
commitChange();
}
@@ -155,19 +189,19 @@ void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio
return;
}
- if (unitType == LengthTypeUnknown || unitType > LengthTypePC) {
+ if (!isValidLengthUnit(unitType)) {
exceptionState.throwDOMException(NotSupportedError, "Cannot convert to unknown or invalid units (" + String::number(unitType) + ").");
return;
}
- if ((target()->isRelative() || SVGLength::isRelativeUnit(toSVGLengthType(unitType)))
+ if ((target()->isRelative() || SVGLength::isRelativeUnit(toCSSUnitType(unitType)))
&& !canResolveRelativeUnits(contextElement())) {
exceptionState.throwDOMException(NotSupportedError, "Could not resolve relative length.");
return;
}
SVGLengthContext lengthContext(contextElement());
- target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext);
+ target()->convertToSpecifiedUnits(toCSSUnitType(unitType), lengthContext);
commitChange();
}
« no previous file with comments | « Source/core/svg/SVGLengthTearOff.h ('k') | Source/core/svg/SVGSVGElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698