Commit c825d655 authored by shanmuga.m's avatar shanmuga.m Committed by Commit bot

SVGLength.value setter should set the value to <number>

As per SVG2, SVGLength.value setter should set the
SVGLength's value to a <number> whose value is value.
https://svgwg.org/svg2-draft/types.html#__svg__SVGLength__value

This patch is supportive patch for calc() support for SVGLength.

BUG=558304

Review-Url: https://codereview.chromium.org/2113943003
Cr-Commit-Position: refs/heads/master@{#403440}
parent c1105ec7
<!DOCTYPE html>
<title>Tests SVGLength.value setter</title>
<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 SVGLength.value setter");
</script>
......@@ -77,6 +77,11 @@ float SVGLength::value(const SVGLengthContext& context) const
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(
......
......@@ -56,6 +56,7 @@ public:
float value(const SVGLengthContext&) const;
void setValue(float, const SVGLengthContext&);
void setValueAsNumber(float);
float valueInSpecifiedUnits() const { return m_value->getFloatValue(); }
void setValueInSpecifiedUnits(float value)
......
......@@ -138,13 +138,7 @@ 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);
target()->setValueAsNumber(value);
commitChange();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment