Truly independent web browser
LibWeb: Let SVG animation subclasses pick their animated property
Jelle Raaijmakers7894a3ccdedf
diff --git a/Libraries/LibWeb/SVG/SVGAnimationElement.cpp b/Libraries/LibWeb/SVG/SVGAnimationElement.cppindex f5fb966e3c5..0b8c1fd4c86 100644--- a/Libraries/LibWeb/SVG/SVGAnimationElement.cpp+++ b/Libraries/LibWeb/SVG/SVGAnimationElement.cpp@@ -8,6 +8,8 @@#include <AK/Math.h>#include <LibWeb/Animations/DocumentTimeline.h>+#include <LibWeb/CSS/PropertyNameAndID.h>+#include <LibWeb/CSS/StyleValues/StyleValue.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/HTML/EventNames.h>#include <LibWeb/HTML/Scripting/Environments.h>@@ -123,6 +125,16 @@ Bindings::FillMode SVGAnimationElement::fill_mode() constreturn Bindings::FillMode::None;}+Animations::BaseKeyframe SVGAnimationElement::keyframe(double offset, CSS::PropertyID property_id, CSS::StyleValue const& value)+{+ 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);+ return keyframe;+}+void SVGAnimationElement::update_animation(){if (m_animation) {diff --git a/Libraries/LibWeb/SVG/SVGAnimationElement.h b/Libraries/LibWeb/SVG/SVGAnimationElement.hindex ec602076124..9f2de3f62ed 100644--- a/Libraries/LibWeb/SVG/SVGAnimationElement.h+++ b/Libraries/LibWeb/SVG/SVGAnimationElement.h@@ -42,12 +42,13 @@ protected: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 Optional<CSS::PropertyID> target_property() const;virtual Vector<Animations::BaseKeyframe> keyframes(SVGElement const& target, CSS::PropertyID) const = 0;+ static Animations::BaseKeyframe keyframe(double offset, CSS::PropertyID, CSS::StyleValue const&);void update_animation();private:- Optional<CSS::PropertyID> target_property() const;GC::Ptr<SMILTimeContainer> time_container();double simple_duration() const;Bindings::FillMode fill_mode() const;diff --git a/Libraries/LibWeb/SVG/SVGSetElement.cpp b/Libraries/LibWeb/SVG/SVGSetElement.cppindex f3d4054d70f..a6688355ad5 100644--- a/Libraries/LibWeb/SVG/SVGSetElement.cpp+++ b/Libraries/LibWeb/SVG/SVGSetElement.cpp@@ -4,7 +4,6 @@* 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>@@ -38,16 +37,7 @@ Vector<Animations::BaseKeyframe> SVGSetElement::keyframes(SVGElement const& targreturn {};// 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;+ return { keyframe(0, property_id, *value), keyframe(1, property_id, *value) };}}