Commit 5351b4d9 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Missing value default for <animateTransform> 'type' is 'translate'

Also make sure dynamic changes are reflected earlier by calling
AnimationAttributeChanged() when the parsed attribute value changes.
Previously it would only refresh when moving to the next value range, or
otherwise invalidating animation state.

Fixed: 1145548
Change-Id: I8ff82c02e6bf8e3cb82ef4d21e2381cbc99bcd3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2520783
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824818}
parent 3b302cc5
...@@ -31,7 +31,7 @@ namespace blink { ...@@ -31,7 +31,7 @@ namespace blink {
SVGAnimateTransformElement::SVGAnimateTransformElement(Document& document) SVGAnimateTransformElement::SVGAnimateTransformElement(Document& document)
: SVGAnimateElement(svg_names::kAnimateTransformTag, document), : SVGAnimateElement(svg_names::kAnimateTransformTag, document),
transform_type_(SVGTransformType::kUnknown) {} transform_type_(SVGTransformType::kTranslate) {}
bool SVGAnimateTransformElement::HasValidAnimation() const { bool SVGAnimateTransformElement::HasValidAnimation() const {
if (GetAttributeType() == kAttributeTypeCSS) if (GetAttributeType() == kAttributeTypeCSS)
...@@ -61,12 +61,24 @@ SVGPropertyBase* SVGAnimateTransformElement::CreatePropertyForAnimation( ...@@ -61,12 +61,24 @@ SVGPropertyBase* SVGAnimateTransformElement::CreatePropertyForAnimation(
return MakeGarbageCollected<SVGTransformList>(transform_type_, value); return MakeGarbageCollected<SVGTransformList>(transform_type_, value);
} }
static SVGTransformType ParseTypeAttribute(const String& value) {
if (value.IsNull())
return SVGTransformType::kTranslate;
SVGTransformType transform_type = ParseTransformType(value);
// Since ParseTransformType() is also used when parsing transform lists, it accepts the value
// "matrix". That value is however not recognized by the 'type' attribute, so treat it as invalid.
if (transform_type == SVGTransformType::kMatrix)
transform_type = SVGTransformType::kUnknown;
return transform_type;
}
void SVGAnimateTransformElement::ParseAttribute( void SVGAnimateTransformElement::ParseAttribute(
const AttributeModificationParams& params) { const AttributeModificationParams& params) {
if (params.name == svg_names::kTypeAttr) { if (params.name == svg_names::kTypeAttr) {
transform_type_ = ParseTransformType(params.new_value); SVGTransformType old_transform_type = transform_type_;
if (transform_type_ == SVGTransformType::kMatrix) transform_type_ = ParseTypeAttribute(params.new_value);
transform_type_ = SVGTransformType::kUnknown; if (transform_type_ != old_transform_type)
AnimationAttributeChanged();
return; return;
} }
......
<!doctype html>
<title>&lt;animateTransform> 'type' attribute missing/invalid value default</title>
<link rel="help" href="https://svgwg.org/specs/animations/#AnimateTransformElementTypeAttribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<svg height="10">
<rect width="10" height="10" fill="blue">
<animateTransform attributeName="transform" type="translate"
fill="freeze" dur="1s" from="10 0" to="10 0"/>
</rect>
<rect width="10" height="10" fill="blue">
<animateTransform attributeName="transform"
fill="freeze" dur="1s" from="30 0" to="30 0"/>
</rect>
<rect width="10" height="10" fill="blue">
<animateTransform attributeName="transform" type="foo"
fill="freeze" dur="1s" from="50 0" to="50 0"/>
</rect>
<rect width="10" height="10" fill="blue">
<animateTransform attributeName="transform" type="foo"
fill="freeze" dur="1s" from="70 0" to="70 0"/>
</rect>
</svg>
<script>
const animations = document.querySelectorAll('animateTransform');
async_test(t => {
animations[0].addEventListener('beginEvent', t.step_func_done(function() {
let ctm = animations[0].targetElement.getCTM();
assert_equals(ctm.e, 10);
assert_equals(ctm.f, 0);
}));
}, document.title + ', "type" attribute is "translate"');
async_test(t => {
animations[1].addEventListener('beginEvent', t.step_func_done(function() {
let ctm = animations[1].targetElement.getCTM();
assert_equals(ctm.e, 30);
assert_equals(ctm.f, 0);
}));
}, document.title + ', missing "type" attribute');
async_test(t => {
animations[2].addEventListener('beginEvent', t.step_func_done(function() {
let ctm = animations[2].targetElement.getCTM();
assert_equals(ctm.e, 0);
assert_equals(ctm.f, 0);
}));
}, document.title + ', invalid "type" attribute');
async_test(t => {
animations[3].addEventListener('beginEvent', t.step_func(function() {
animations[3].removeAttribute('type');
window.requestAnimationFrame(t.step_func_done(function() {
let ctm = animations[3].targetElement.getCTM();
assert_equals(ctm.e, 70);
assert_equals(ctm.f, 0);
}));
}));
}, document.title + ', removed "type" attribute');
</script>
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