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

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

Issue 1421533006: Make SVGLength wrap a CSSPrimitiveValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments addressed Created 5 years, 2 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/SVGLengthTearOff.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGLengthTearOff.cpp b/third_party/WebKit/Source/core/svg/SVGLengthTearOff.cpp
index bf29952cee2d56b5a17dbf0eaaf5fdd9b13ef7bb..1efda4200211f106f7c83e0f48c0819d1b2ca0c5 100644
--- a/third_party/WebKit/Source/core/svg/SVGLengthTearOff.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGLengthTearOff.cpp
@@ -40,10 +40,10 @@ 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 != static_cast<unsigned short>(CSSPrimitiveValue::UnitType::Unknown)
+ && type <= static_cast<unsigned short>(CSSPrimitiveValue::UnitType::Picas);
}
inline bool canResolveRelativeUnits(const SVGElement* contextElement)
@@ -51,11 +51,47 @@ 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);
fs 2015/10/30 19:50:00 I think this function should map LengthTypeNumber
Stephen Chennney 2015/11/03 21:59:41 Yes. Done.
+}
+
+inline SVGLengthType toSVGLengthType(CSSPrimitiveValue::UnitType type)
+{
+ switch (type) {
+ case CSSPrimitiveValue::UnitType::Unknown:
+ return LengthTypeUnknown;
+ case CSSPrimitiveValue::UnitType::Number:
fs 2015/10/30 19:50:00 ...and if the above was true, this would not be a
Stephen Chennney 2015/11/03 21:59:41 Yes. Done, or at least about to be tested.
+ case CSSPrimitiveValue::UnitType::UserUnits:
+ return LengthTypeNumber;
+ case CSSPrimitiveValue::UnitType::Percentage:
+ return LengthTypePercentage;
+ case CSSPrimitiveValue::UnitType::Ems:
+ return LengthTypeEMS;
+ case CSSPrimitiveValue::UnitType::Exs:
+ return LengthTypeEXS;
+ case CSSPrimitiveValue::UnitType::Pixels:
+ return LengthTypePX;
+ case CSSPrimitiveValue::UnitType::Centimeters:
+ return LengthTypeCM;
+ case CSSPrimitiveValue::UnitType::Millimeters:
+ return LengthTypeMM;
+ case CSSPrimitiveValue::UnitType::Inches:
+ return LengthTypeIN;
+ case CSSPrimitiveValue::UnitType::Points:
+ return LengthTypePT;
+ case CSSPrimitiveValue::UnitType::Picas:
+ return LengthTypePC;
+ default:
+ return LengthTypeUnknown;
+ }
+}
} // namespace
SVGLengthType SVGLengthTearOff::unitType()
{
- return hasExposedLengthUnit() ? target()->unitType() : LengthTypeUnknown;
+ return hasExposedLengthUnit() ? toSVGLengthType(target()->typeWithCalcResolved()) : LengthTypeUnknown;
}
SVGLengthMode SVGLengthTearOff::unitMode()
@@ -139,12 +175,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 +191,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();
}

Powered by Google App Engine
This is Rietveld 408576698