Truly independent web browser
LibWeb: Apply <set> animations of CSS properties to their parent
Jelle Raaijmakers496cca2222cd
diff --git a/Libraries/LibWeb/Animations/Animatable.cpp b/Libraries/LibWeb/Animations/Animatable.cppindex cf6e93d5317..dbc23fea981 100644--- a/Libraries/LibWeb/Animations/Animatable.cpp+++ b/Libraries/LibWeb/Animations/Animatable.cpp@@ -130,7 +130,9 @@ WebIDL::ExceptionOr<Vector<GC::Ref<Animation>>> Animatable::get_animations_interif (m_impl) {auto& associated_animations = m_impl->associated_animations;for (auto const& animation : associated_animations) {- if (animation->is_relevant())+ // AD-HOC: SVG animation elements drive their animations with their own timing model, which script must not+ // be able to play, pause or cancel. Like other engines, do not expose them.+ if (animation->is_relevant() && !animation->is_smil_animation())relevant_animations.append(*animation);}}diff --git a/Libraries/LibWeb/Animations/Animation.h b/Libraries/LibWeb/Animations/Animation.hindex 5ed61fbe4ef..eaa8f8da998 100644--- a/Libraries/LibWeb/Animations/Animation.h+++ b/Libraries/LibWeb/Animations/Animation.h@@ -19,6 +19,7 @@ namespace Web::Animations {// Sorted by composite order:// https://www.w3.org/TR/css-animations-2/#animation-composite-orderenum class AnimationClass {+ SMILAnimation,CSSAnimationWithOwningElement,CSSTransition,CSSAnimationWithoutOwningElement,@@ -137,6 +138,7 @@ public:virtual bool is_css_animation() const { return false; }virtual bool is_css_transition() const { return false; }+ virtual bool is_smil_animation() const { return false; }Optional<DOM::AbstractElement> owning_element() const { return m_owning_element; }void set_owning_element(Optional<DOM::AbstractElement>&& value) { m_owning_element = move(value); }diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex 44ea69a011e..e378f2cfa4f 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -881,6 +881,7 @@ set(SOURCESSVG/AttributeNames.cppSVG/AttributeParsing.cppSVG/Path.cpp+ SVG/SMILAnimation.cppSVG/SVGAElement.cppSVG/SVGAnimatedEnumeration.cppSVG/SVGAnimatedInteger.cppdiff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.hindex e462e6dc618..2f62b332fbc 100644--- a/Libraries/LibWeb/Forward.h+++ b/Libraries/LibWeb/Forward.h@@ -1132,6 +1132,7 @@ class StorageShelf;namespace Web::SVG {class Path;+class SMILAnimation;class SVGAnimatedEnumeration;class SVGAnimatedInteger;class SVGAnimatedLength;diff --git a/Libraries/LibWeb/SVG/AttributeNames.h b/Libraries/LibWeb/SVG/AttributeNames.hindex abd70d944cf..2c8f876eeba 100644--- a/Libraries/LibWeb/SVG/AttributeNames.h+++ b/Libraries/LibWeb/SVG/AttributeNames.h@@ -105,6 +105,7 @@ namespace Web::SVG::AttributeNames {__ENUMERATE_SVG_ATTRIBUTE(targetX, "targetX") \__ENUMERATE_SVG_ATTRIBUTE(targetY, "targetY") \__ENUMERATE_SVG_ATTRIBUTE(textLength, "textLength") \+ __ENUMERATE_SVG_ATTRIBUTE(to, "to") \__ENUMERATE_SVG_ATTRIBUTE(transform, "transform") \__ENUMERATE_SVG_ATTRIBUTE(type, "type") \__ENUMERATE_SVG_ATTRIBUTE(values, "values") \diff --git a/Libraries/LibWeb/SVG/SMILAnimation.cpp b/Libraries/LibWeb/SVG/SMILAnimation.cppnew file mode 100644index 00000000000..e739cf51c1c--- /dev/null+++ b/Libraries/LibWeb/SVG/SMILAnimation.cpp@@ -0,0 +1,49 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibWeb/DOM/Document.h>+#include <LibWeb/SVG/SMILAnimation.h>+#include <LibWeb/SVG/SVGAnimationElement.h>++namespace Web::SVG {++GC_DEFINE_ALLOCATOR(SMILAnimation);++GC::Ref<SMILAnimation> SMILAnimation::create(SVGAnimationElement& animation_element)+{+ auto& environment = animation_element.document().relevant_settings_object();+ return GC::Heap::the().allocate<SMILAnimation>(environment, animation_element);+}++SMILAnimation::SMILAnimation(HTML::EnvironmentSettingsObject& environment, SVGAnimationElement& animation_element)+ : Animations::Animation(environment)+ , m_animation_element(animation_element)+{+}++// https://www.w3.org/TR/smil-animation/#AnimationSandwichModel+int SMILAnimation::class_specific_composite_order(GC::Ref<Animations::Animation> other) const+{+ // Within an OM, animations are prioritized according to when each begins. The animation first begun has lowest+ // priority and the most recently begun animation has highest priority. When two animations start at the same+ // moment in time, the activation order is resolved as follows:+ // ...+ // If two animations share no time dependency relationship (e.g., neither is defined relative to the other, even+ // indirectly) the element that appears first in the document has lower priority.+ // NB: Every animation begins at the same moment for now, so only their document order sets them apart.+ auto const& other_element = as<SMILAnimation>(*other).animation_element();+ if (m_animation_element.ptr() == &other_element)+ return 0;+ return m_animation_element->is_before(other_element) ? -1 : 1;+}++void SMILAnimation::visit_edges(Cell::Visitor& visitor)+{+ Base::visit_edges(visitor);+ visitor.visit(m_animation_element);+}++}diff --git a/Libraries/LibWeb/SVG/SMILAnimation.h b/Libraries/LibWeb/SVG/SMILAnimation.hnew file mode 100644index 00000000000..5e5fbac1cbc--- /dev/null+++ b/Libraries/LibWeb/SVG/SMILAnimation.h@@ -0,0 +1,35 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <LibWeb/Animations/Animation.h>+#include <LibWeb/Forward.h>++namespace Web::SVG {++class SMILAnimation final : public Animations::Animation {+ WEB_NON_IDL_WRAPPABLE(SMILAnimation, Animations::Animation);+ GC_DECLARE_ALLOCATOR(SMILAnimation);++public:+ static GC::Ref<SMILAnimation> create(SVGAnimationElement&);++ SVGAnimationElement& animation_element() const { return m_animation_element; }++ virtual bool is_smil_animation() const override { return true; }+ virtual Animations::AnimationClass animation_class() const override { return Animations::AnimationClass::SMILAnimation; }+ virtual int class_specific_composite_order(GC::Ref<Animations::Animation> other) const override;++private:+ SMILAnimation(HTML::EnvironmentSettingsObject&, SVGAnimationElement&);++ virtual void visit_edges(Cell::Visitor&) override;++ GC::Ref<SVGAnimationElement> m_animation_element;+};++}diff --git a/Libraries/LibWeb/SVG/SVGAnimationElement.cpp b/Libraries/LibWeb/SVG/SVGAnimationElement.cppindex f9a1dcd652c..f36de2cf53c 100644--- a/Libraries/LibWeb/SVG/SVGAnimationElement.cpp+++ b/Libraries/LibWeb/SVG/SVGAnimationElement.cpp@@ -6,8 +6,14 @@#include <LibWeb/SVG/SVGAnimationElement.h>+#include <AK/Math.h>+#include <LibWeb/Animations/DocumentTimeline.h>+#include <LibWeb/DOM/Document.h>#include <LibWeb/HTML/EventNames.h>+#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>#include <LibWeb/Layout/Node.h>+#include <LibWeb/SVG/AttributeNames.h>+#include <LibWeb/SVG/SMILAnimation.h>namespace Web::SVG {@@ -16,6 +22,100 @@ SVGAnimationElement::SVGAnimationElement(DOM::Document& document, DOM::Qualified{}+void SVGAnimationElement::visit_edges(Cell::Visitor& visitor)+{+ Base::visit_edges(visitor);+ visitor.visit(m_animation);+}++void SVGAnimationElement::inserted()+{+ Base::inserted();+ update_animation();+}++void SVGAnimationElement::removed_from(IsSubtreeRoot is_subtree_root, Node* old_ancestor, Node& old_root)+{+ Base::removed_from(is_subtree_root, old_ancestor, old_root);+ update_animation();+}++void SVGAnimationElement::moved_from(IsSubtreeRoot is_subtree_root, GC::Ptr<Node> old_ancestor)+{+ Base::moved_from(is_subtree_root, old_ancestor);+ update_animation();+}++void SVGAnimationElement::attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_)+{+ Base::attribute_changed(name, old_value, value, namespace_);+ if (name == AttributeNames::attributeName && !namespace_.has_value())+ update_animation();+}++// https://svgwg.org/specs/animations/#HrefAttribute+GC::Ptr<SVGElement> SVGAnimationElement::target_element()+{+ // FIXME: A URL reference to the element which is the target of this animation element and which therefore will be+ // modified over time.+ // If the ‘href’ attribute or the deprecated ‘xlink:href’ attribute is not provided, then the target element will+ // be the immediate parent element of the current animation element.+ return as_if<SVGElement>(parent_element().ptr());+}++// https://svgwg.org/specs/animations/#AttributeNameAttribute+Optional<CSS::PropertyID> SVGAnimationElement::target_property() const+{+ auto attribute_name = get_attribute(AttributeNames::attributeName);+ if (!attribute_name.has_value())+ return {};++ // That is, when determining if ‘attributeName’ corresponds to an attribute name or a CSS property name, the+ // implementation must first search through the list of CSS properties for a matching property name.+ // NB: Neither custom properties nor properties that cannot be animated have an animation.+ auto property_id = CSS::property_id_from_string(*attribute_name);+ if (!property_id.has_value() || property_id == CSS::PropertyID::Custom || !CSS::is_animatable_property(*property_id))+ return {};++ // FIXME: If no matching property is found, the implementation must search for a matching attribute on the target+ // element.+ return property_id;+}++void SVGAnimationElement::update_animation()+{+ if (m_animation) {+ m_animation->cancel();+ m_animation = nullptr;+ }++ if (!is_connected())+ return;+ auto target = target_element();+ if (!target)+ return;+ auto property_id = target_property();+ if (!property_id.has_value())+ return;+ auto keyframes = this->keyframes(*target, *property_id);+ if (keyframes.is_empty())+ return;++ // FIXME: Resolve the interval to play from the begin, dur and end attributes, and the other timing attributes.+ // FIXME: A running animation requests a rendering update on every frame, even when its output cannot change, as+ // with this indefinite one. This keeps the rendering loop running for as long as the element is connected.+ auto effect = MUST(Animations::KeyframeEffect::create_from_processed_keyframes(target, move(keyframes), AK::Infinity<double>));++ // AD-HOC: Animations begin once their element is connected, on the document's default timeline. They should+ // begin at the document begin of their SVG document fragment, which is the time of its load event.+ auto animation = SMILAnimation::create(*this);+ animation->set_timeline(document().timeline());+ animation->set_effect(effect);+ HTML::TemporaryExecutionContext execution_context { document().relevant_settings_object() };+ MUST(animation->play());+ m_animation = animation;+}+// https://svgwg.org/specs/animations/#__svg__SVGAnimationElement__onbeginvoid SVGAnimationElement::set_onbegin(GC::Ptr<WebIDL::CallbackType> value){diff --git a/Libraries/LibWeb/SVG/SVGAnimationElement.h b/Libraries/LibWeb/SVG/SVGAnimationElement.hindex 558d55a7e06..f5cbc4c708e 100644--- a/Libraries/LibWeb/SVG/SVGAnimationElement.h+++ b/Libraries/LibWeb/SVG/SVGAnimationElement.h@@ -7,6 +7,8 @@#pragma once#include <LibJS/Forward.h>+#include <LibWeb/Animations/KeyframeEffect.h>+#include <LibWeb/CSS/PropertyID.h>#include <LibWeb/Export.h>#include <LibWeb/SVG/SVGElement.h>@@ -16,6 +18,8 @@ class SVGAnimationElement : public SVGElement {WEB_WRAPPABLE(SVGAnimationElement, SVGElement);public:+ GC::Ptr<SVGElement> target_element();+void set_onbegin(GC::Ptr<WebIDL::CallbackType>);GC::Ptr<WebIDL::CallbackType> onbegin();@@ -27,6 +31,21 @@ public:protected:SVGAnimationElement(DOM::Document&, DOM::QualifiedName);++ virtual void visit_edges(Cell::Visitor&) override;+ virtual void inserted() override;+ virtual void removed_from(IsSubtreeRoot, Node* old_ancestor, Node& old_root) override;+ virtual void moved_from(IsSubtreeRoot, GC::Ptr<Node> old_ancestor) override;+ virtual void attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_) override;++ virtual Vector<Animations::BaseKeyframe> keyframes(SVGElement const& target, CSS::PropertyID) const = 0;++ void update_animation();++private:+ Optional<CSS::PropertyID> target_property() const;++ GC::Ptr<SMILAnimation> m_animation;};}diff --git a/Libraries/LibWeb/SVG/SVGAnimationElement.idl b/Libraries/LibWeb/SVG/SVGAnimationElement.idlindex 0250e728bcb..5139a8dcf7c 100644--- a/Libraries/LibWeb/SVG/SVGAnimationElement.idl+++ b/Libraries/LibWeb/SVG/SVGAnimationElement.idl@@ -2,7 +2,7 @@[Exposed=Window]interface SVGAnimationElement : SVGElement {- [FIXME] readonly attribute SVGElement? targetElement;+ readonly attribute SVGElement? targetElement;attribute EventHandler onbegin;attribute EventHandler onend;diff --git a/Libraries/LibWeb/SVG/SVGElement.h b/Libraries/LibWeb/SVG/SVGElement.hindex 893f7bcb526..0538c8a9f8e 100644--- a/Libraries/LibWeb/SVG/SVGElement.h+++ b/Libraries/LibWeb/SVG/SVGElement.h@@ -63,6 +63,8 @@ public:void mark_resource_box_referencing_elements_for_content_change();void note_svg_paint_resource_description_may_have_changed();+ RefPtr<CSS::StyleValue const> parse_presentation_attribute(CSS::PropertyID, Utf16View) const;+protected:SVGElement(DOM::Document&, DOM::QualifiedName);virtual void visit_edges(Cell::Visitor&) override;@@ -86,7 +88,6 @@ private:virtual bool is_svg_element() const final { return true; }- RefPtr<CSS::StyleValue const> parse_presentation_attribute(CSS::PropertyID, Utf16View) const;Vector<CSS::StyleProperty> const& presentation_attribute_style() const;void update_presentation_attribute_style(Utf16FlyString const& name, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_);void publish_presentation_attribute_style();diff --git a/Libraries/LibWeb/SVG/SVGSetElement.cpp b/Libraries/LibWeb/SVG/SVGSetElement.cppindex 91eac9a4784..f3d4054d70f 100644--- a/Libraries/LibWeb/SVG/SVGSetElement.cpp+++ b/Libraries/LibWeb/SVG/SVGSetElement.cpp@@ -4,6 +4,9 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <LibWeb/CSS/PropertyNameAndID.h>+#include <LibWeb/CSS/StyleValues/StyleValue.h>+#include <LibWeb/SVG/AttributeNames.h>#include <LibWeb/SVG/SVGSetElement.h>namespace Web::SVG {@@ -15,4 +18,36 @@ SVGSetElement::SVGSetElement(DOM::Document& document, DOM::QualifiedName qualifi{}+void SVGSetElement::attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_)+{+ Base::attribute_changed(name, old_value, value, namespace_);+ if (name == AttributeNames::to && !namespace_.has_value())+ update_animation();+}++// https://svgwg.org/specs/animations/#SetElementToAttribute+Vector<Animations::BaseKeyframe> SVGSetElement::keyframes(SVGElement const& target, CSS::PropertyID property_id) const+{+ // Specifies the value for the attribute during the duration of the ‘set’ element. The argument value must match the+ // attribute type.+ auto to = get_attribute(AttributeNames::to);+ if (!to.has_value())+ return {};+ auto value = target.parse_presentation_attribute(property_id, to->utf16_view());+ if (!value)+ return {};++ // NB: The value holds for the entire duration, so the effect starts and ends on it.+ Vector<Animations::BaseKeyframe> keyframes;+ for (auto offset : { 0.0, 1.0 }) {+ Animations::BaseKeyframe keyframe;+ keyframe.offset = offset;+ Animations::BaseKeyframe::ParsedProperties properties;+ properties.set(CSS::PropertyNameAndID::from_id(property_id), CSS::RustStyleValueHandle::retained(value->rust_style_value_data()));+ keyframe.properties = move(properties);+ keyframes.append(move(keyframe));+ }+ return keyframes;+}+}diff --git a/Libraries/LibWeb/SVG/SVGSetElement.h b/Libraries/LibWeb/SVG/SVGSetElement.hindex a2daf65ab19..a4be66f1c48 100644--- a/Libraries/LibWeb/SVG/SVGSetElement.h+++ b/Libraries/LibWeb/SVG/SVGSetElement.h@@ -16,6 +16,10 @@ class SVGSetElement final : public SVGAnimationElement {private:SVGSetElement(DOM::Document&, DOM::QualifiedName);++ virtual void attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_) override;++ virtual Vector<Animations::BaseKeyframe> keyframes(SVGElement const& target, CSS::PropertyID) const override;};}diff --git a/Tests/LibWeb/Ref/input/wpt-import/svg/animations/invalid-attribute-type-does-not-block-other-animations.html b/Tests/LibWeb/Ref/input/wpt-import/svg/animations/invalid-attribute-type-does-not-block-other-animations.htmlnew file mode 100644index 00000000000..60a523a57bf--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/svg/animations/invalid-attribute-type-does-not-block-other-animations.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<title>An invalid attribute type in one animation group must not block other animation groups</title>+<link rel="match" href="../../../../expected/wpt-import/svg/animations/../struct/reftests/reference/green-100x100.html">+<svg>+ <!-- Invalid animation: attributeType="CSS" on a non-CSS attribute. -->+ <rect>+ <animate attributeName="href" attributeType="CSS" values="foo" dur="1s"/>+ </rect>++ <!-- Valid animation: should still run despite the earlier invalid group. -->+ <rect width="100" height="100" fill="red">+ <set attributeName="fill" to="green" fill="freeze"/>+ </rect>+</svg>diff --git a/Tests/LibWeb/Text/expected/SVG/animation-element-target-element.txt b/Tests/LibWeb/Text/expected/SVG/animation-element-target-element.txtnew file mode 100644index 00000000000..3100537595a--- /dev/null+++ b/Tests/LibWeb/Text/expected/SVG/animation-element-target-element.txt@@ -0,0 +1,3 @@+in a rect: rect+detached: null+in a div: nulldiff --git a/Tests/LibWeb/Text/expected/SVG/set-element-composite-order.txt b/Tests/LibWeb/Text/expected/SVG/set-element-composite-order.txtnew file mode 100644index 00000000000..e07b67d6521--- /dev/null+++ b/Tests/LibWeb/Text/expected/SVG/set-element-composite-order.txt@@ -0,0 +1,2 @@+script animation over a newer set: rgb(0, 0, 255)+set later in document order over a newer one: rgb(0, 128, 0)diff --git a/Tests/LibWeb/Text/expected/SVG/set-element-not-in-get-animations.txt b/Tests/LibWeb/Text/expected/SVG/set-element-not-in-get-animations.txtnew file mode 100644index 00000000000..e28d0c65772--- /dev/null+++ b/Tests/LibWeb/Text/expected/SVG/set-element-not-in-get-animations.txt@@ -0,0 +1,3 @@+fill: rgb(0, 128, 0)+element animations: 0+document animations: 0diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/set-dynamic-attributeName-css-property-cleanup.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/set-dynamic-attributeName-css-property-cleanup.txtnew file mode 100644index 00000000000..78f6194d4dd--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/set-dynamic-attributeName-css-property-cleanup.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Changing attributeName on set element clears old animated CSS property\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txtindex 73232da2fe5..76cec12be4b 100644--- a/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt@@ -2,8 +2,8 @@ Harness status: OKFound 1780 tests-1124 Pass-656 Fail+1126 Pass+654 FailPass idl_test setupPass idl_test validationPass Partial interface Document: original interface defined@@ -1643,7 +1643,7 @@ Pass SVGAnimationElement interface object namePass SVGAnimationElement interface: existence and properties of interface prototype objectPass SVGAnimationElement interface: existence and properties of interface prototype object's "constructor" propertyPass SVGAnimationElement interface: existence and properties of interface prototype object's @@unscopables property-Fail SVGAnimationElement interface: attribute targetElement+Pass SVGAnimationElement interface: attribute targetElementPass SVGAnimationElement interface: attribute onbeginPass SVGAnimationElement interface: attribute onendPass SVGAnimationElement interface: attribute onrepeat@@ -1692,7 +1692,7 @@ Pass SVGSetElement interface: existence and properties of interface prototype obPass SVGSetElement interface: existence and properties of interface prototype object's @@unscopables propertyPass SVGSetElement must be primary interface of objects.setPass Stringification of objects.set-Fail SVGAnimationElement interface: objects.set must inherit property "targetElement" with the proper type+Pass SVGAnimationElement interface: objects.set must inherit property "targetElement" with the proper typePass SVGAnimationElement interface: objects.set must inherit property "onbegin" with the proper typePass SVGAnimationElement interface: objects.set must inherit property "onend" with the proper typePass SVGAnimationElement interface: objects.set must inherit property "onrepeat" with the proper typediff --git a/Tests/LibWeb/Text/input/SVG/animation-element-target-element.html b/Tests/LibWeb/Text/input/SVG/animation-element-target-element.htmlnew file mode 100644index 00000000000..f1ea79bb361--- /dev/null+++ b/Tests/LibWeb/Text/input/SVG/animation-element-target-element.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<svg>+ <rect id="rect" width="10" height="10"><set id="set" attributeName="fill" to="green"/></rect>+</svg>+<div id="div"></div>+<script>+ test(() => {+ println(`in a rect: ${document.getElementById("set").targetElement.id}`);+ const detached = document.createElementNS("http://www.w3.org/2000/svg", "set");+ println(`detached: ${detached.targetElement}`);+ document.getElementById("div").append(detached);+ println(`in a div: ${detached.targetElement}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/SVG/set-element-composite-order.html b/Tests/LibWeb/Text/input/SVG/set-element-composite-order.htmlnew file mode 100644index 00000000000..78b4f8a94dd--- /dev/null+++ b/Tests/LibWeb/Text/input/SVG/set-element-composite-order.html@@ -0,0 +1,30 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<svg>+ <rect id="scripted" width="100" height="100" fill="red"></rect>+ <rect id="ordered" width="100" height="100" fill="red"></rect>+</svg>+<script>+ asyncTest(async done => {+ const nextFrame = () => new Promise(requestAnimationFrame);+ const createSet = to => {+ const set = document.createElementNS("http://www.w3.org/2000/svg", "set");+ set.setAttribute("attributeName", "fill");+ set.setAttribute("to", to);+ return set;+ };++ scripted.animate([{ fill: "blue" }, { fill: "blue" }], { duration: Infinity });+ scripted.appendChild(createSet("green"));++ const lastSet = createSet("green");+ ordered.appendChild(lastSet);+ ordered.insertBefore(createSet("blue"), lastSet);++ await nextFrame();+ await nextFrame();+ println(`script animation over a newer set: ${getComputedStyle(scripted).fill}`);+ println(`set later in document order over a newer one: ${getComputedStyle(ordered).fill}`);+ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/SVG/set-element-not-in-get-animations.html b/Tests/LibWeb/Text/input/SVG/set-element-not-in-get-animations.htmlnew file mode 100644index 00000000000..a40df3cfa59--- /dev/null+++ b/Tests/LibWeb/Text/input/SVG/set-element-not-in-get-animations.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<svg>+ <rect id="rect" width="100" height="100" fill="red">+ <set attributeName="fill" to="green"/>+ </rect>+</svg>+<script>+ asyncTest(async done => {+ const nextFrame = () => new Promise(requestAnimationFrame);+ await nextFrame();+ await nextFrame();+ println(`fill: ${getComputedStyle(rect).fill}`);+ println(`element animations: ${rect.getAnimations().length}`);+ println(`document animations: ${document.getAnimations().length}`);+ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/set-dynamic-attributeName-css-property-cleanup.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/set-dynamic-attributeName-css-property-cleanup.htmlnew file mode 100644index 00000000000..753cc32da49--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/set-dynamic-attributeName-css-property-cleanup.html@@ -0,0 +1,33 @@+<!doctype html>+<title>Changing attributeName on set element clears old animated CSS property</title>+<link rel="help" href="https://w3c.github.io/svgwg/specs/animations/">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<svg>+ <rect id="rect" x="0" y="0" width="100" height="100" fill="green">+ <set id="set" attributeType="CSS" attributeName="opacity" to="0.5"/>+ </rect>+</svg>+<script>+ async_test(t => {+ let svg = document.querySelector('svg');+ let rect = document.getElementById('rect');+ let set = document.getElementById('set');++ window.onload = t.step_func(() => {+ window.requestAnimationFrame(t.step_func(() => {+ assert_equals(getComputedStyle(rect).opacity, '0.5',+ 'opacity should be 0.5 while set animates opacity');++ // Change attributeName from "opacity" to "x".+ // The old animated CSS property (opacity) should be cleared.+ set.setAttribute('attributeName', 'x');++ window.requestAnimationFrame(t.step_func_done(() => {+ assert_equals(getComputedStyle(rect).opacity, '1',+ 'opacity should revert to 1 after attributeName changed away from opacity');+ }));+ }));+ });+ });+</script>