Reviewers: rwlbuis, fs, pdr.
CL:
https://codereview.chromium.org/2113943003/Message:
PTAL!!
Thanks!
Description:
SVGLength.setValue should set the value to <NUMBER>
As per SVG2, SVGLength.setValue should set the
SVGLength's value to a <number> whose value is value.
https://svgwg.org/svg2-draft/types.html#__svg__SVGLength__valueThis patch is supportive patch for calc() support for SVGLength.
BUG=558304
Base URL:
https://chromium.googlesource.com/chromium/src.git@masterAffected files (+16, -8 lines):
A third_party/WebKit/LayoutTests/svg/dom/SVGLength-setvalue-interface.html
M third_party/WebKit/Source/core/svg/SVGLength.cpp
M third_party/WebKit/Source/core/svg/SVGLengthTearOff.cpp
Index: third_party/WebKit/LayoutTests/svg/dom/SVGLength-setvalue-interface.html
diff --git a/third_party/WebKit/LayoutTests/svg/dom/SVGLength-setvalue-interface.html b/third_party/WebKit/LayoutTests/svg/dom/SVGLength-setvalue-interface.html
new file mode 100644
index 0000000000000000000000000000000000000000..fb8f80047271f753f9e9a545d32d65cf887a9a75
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/svg/dom/SVGLength-setvalue-interface.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<svg width="1" height="1" visibility="hidden">
+</svg>
+<script>
+test(function() {
+ var svgElement = document.querySelector("svg");
+ svgElement.setAttribute("width", "10em");
+ assert_equals(svgElement.width.baseVal.unitType, SVGLength.SVG_LENGTHTYPE_EMS);
+ svgElement.width.baseVal.value = 100;
+ assert_equals(svgElement.width.baseVal.value, 100);
+ assert_equals(svgElement.width.baseVal.unitType, SVGLength.SVG_LENGTHTYPE_NUMBER);
+}, "Tests setValue interface");
+</script>
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 8d66d974af40ea2aa6faf4d7a18ca2a7ebf75b5a..9baa811f2c1f63d5550b0ecd1583a83abfce7394 100644
--- a/third_party/WebKit/Source/core/svg/SVGLength.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGLength.cpp
@@ -79,9 +79,7 @@ float SVGLength::value(const SVGLengthContext& context) const
void SVGLength::setValue(float value, const SVGLengthContext& context)
{
- m_value = CSSPrimitiveValue::create(
- context.convertValueFromUserUnits(value, unitMode(), m_value->typeWithCalcResolved()),
- m_value->typeWithCalcResolved());
+ m_value = CSSPrimitiveValue::create(value, CSSPrimitiveValue::UnitType::UserUnits);
}
bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type)
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 ebff1f65177f326445c48f10344a3d3bf6ab2c7d..6e6c413022bddc85986b453c8876968dbc001f3a 100644
--- a/third_party/WebKit/Source/core/svg/SVGLengthTearOff.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGLengthTearOff.cpp
@@ -138,11 +138,6 @@ void SVGLengthTearOff::setValue(float value, ExceptionState& exceptionState)
return;
}
- if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) {
- exceptionState.throwDOMException(NotSupportedError, "Could not resolve relative length.");
- return;
- }
-
SVGLengthContext lengthContext(contextElement());
target()->setValue(value, lengthContext);
commitChange();