Truly independent web browser
LibWeb: Create SVGAnimateMotionElement for <animateMotion> elements
Jelle Raaijmakers85fc4eaec3e4
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex e378f2cfa4f..b951d13a98e 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -892,6 +892,7 @@ set(SOURCESSVG/SVGAnimatedRect.cppSVG/SVGAnimatedString.cppSVG/SVGAnimatedTransformList.cpp+ SVG/SVGAnimateMotionElement.cppSVG/SVGAnimationElement.cppSVG/SVGCircleElement.cppSVG/SVGClipPathElement.cppdiff --git a/Libraries/LibWeb/DOM/ElementFactory.cpp b/Libraries/LibWeb/DOM/ElementFactory.cppindex 1c2810a5bef..2c5e0926f51 100644--- a/Libraries/LibWeb/DOM/ElementFactory.cpp+++ b/Libraries/LibWeb/DOM/ElementFactory.cpp@@ -95,6 +95,7 @@#include <LibWeb/MathML/TagNames.h>#include <LibWeb/Namespace.h>#include <LibWeb/SVG/SVGAElement.h>+#include <LibWeb/SVG/SVGAnimateMotionElement.h>#include <LibWeb/SVG/SVGCircleElement.h>#include <LibWeb/SVG/SVGClipPathElement.h>#include <LibWeb/SVG/SVGDefsElement.h>@@ -512,6 +513,8 @@ static GC::Ref<SVG::SVGElement> create_svg_element(Document& document, Qualifiedif (local_name == SVG::TagNames::svg)return create_element_on_heap<SVG::SVGSVGElement>(document, move(qualified_name));+ if (local_name == SVG::TagNames::animateMotion)+ return create_element_on_heap<SVG::SVGAnimateMotionElement>(document, move(qualified_name));// FIXME: Support SVG's mixedCase tag names properly.if (local_name.equals_ignoring_ascii_case(SVG::TagNames::clipPath))return create_element_on_heap<SVG::SVGClipPathElement>(document, move(qualified_name));diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.hindex 2f62b332fbc..389334adae4 100644--- a/Libraries/LibWeb/Forward.h+++ b/Libraries/LibWeb/Forward.h@@ -1140,6 +1140,7 @@ class SVGAnimatedLengthList;class SVGAnimatedNumber;class SVGAnimatedNumberList;class SVGAnimatedRect;+class SVGAnimateMotionElement;class SVGAnimationElement;class SVGCircleElement;class SVGClipPathElement;diff --git a/Libraries/LibWeb/SVG/SVGAnimateMotionElement.cpp b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.cppnew file mode 100644index 00000000000..17eb5fcdf14--- /dev/null+++ b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.cpp@@ -0,0 +1,25 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibWeb/SVG/SVGAnimateMotionElement.h>++namespace Web::SVG {++GC_DEFINE_ALLOCATOR(SVGAnimateMotionElement);++SVGAnimateMotionElement::SVGAnimateMotionElement(DOM::Document& document, DOM::QualifiedName qualified_name)+ : SVGAnimationElement(document, move(qualified_name))+{+}++// https://svgwg.org/specs/animations/#AnimateMotionElement+Vector<Animations::BaseKeyframe> SVGAnimateMotionElement::keyframes(SVGElement const&, CSS::PropertyID) const+{+ // FIXME: The ‘animateMotion’ element causes a referenced element to move along a motion path.+ return {};+}++}diff --git a/Libraries/LibWeb/SVG/SVGAnimateMotionElement.h b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.hnew file mode 100644index 00000000000..a039639d058--- /dev/null+++ b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.h@@ -0,0 +1,23 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <LibWeb/SVG/SVGAnimationElement.h>++namespace Web::SVG {++class SVGAnimateMotionElement final : public SVGAnimationElement {+ WEB_WRAPPABLE(SVGAnimateMotionElement, SVGAnimationElement);+ GC_DECLARE_ALLOCATOR(SVGAnimateMotionElement);++private:+ SVGAnimateMotionElement(DOM::Document&, DOM::QualifiedName);++ virtual Vector<Animations::BaseKeyframe> keyframes(SVGElement const& target, CSS::PropertyID) const override;+};++}diff --git a/Libraries/LibWeb/SVG/SVGAnimateMotionElement.idl b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.idlnew file mode 100644index 00000000000..cd8da33c3cb--- /dev/null+++ b/Libraries/LibWeb/SVG/SVGAnimateMotionElement.idl@@ -0,0 +1,4 @@+// https://svgwg.org/specs/animations/#InterfaceSVGAnimateMotionElement+[Exposed=Window]+interface SVGAnimateMotionElement : SVGAnimationElement {+};diff --git a/Libraries/LibWeb/SVG/TagNames.h b/Libraries/LibWeb/SVG/TagNames.hindex f58bbeb50b5..031af961c31 100644--- a/Libraries/LibWeb/SVG/TagNames.h+++ b/Libraries/LibWeb/SVG/TagNames.h@@ -12,6 +12,7 @@ namespace Web::SVG::TagNames {#define ENUMERATE_SVG_TAGS \__ENUMERATE_SVG_TAG(a, "a") \+ __ENUMERATE_SVG_TAG(animateMotion, "animateMotion") \__ENUMERATE_SVG_TAG(circle, "circle") \__ENUMERATE_SVG_TAG(clipPath, "clipPath") \__ENUMERATE_SVG_TAG(defs, "defs") \diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmakeindex 221d99cab78..0fccb876fb2 100644--- a/Libraries/LibWeb/idl_files.cmake+++ b/Libraries/LibWeb/idl_files.cmake@@ -495,6 +495,7 @@ libweb_js_bindings(SVG/SVGAnimatedNumberList)libweb_js_bindings(SVG/SVGAnimatedRect)libweb_js_bindings(SVG/SVGAnimatedString)libweb_js_bindings(SVG/SVGAnimatedTransformList)+libweb_js_bindings(SVG/SVGAnimateMotionElement)libweb_js_bindings(SVG/SVGAnimationElement)libweb_js_bindings(SVG/SVGCircleElement)libweb_js_bindings(SVG/SVGClipPathElement)diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txtindex 3269ced0dc7..00c47ca8b03 100644--- a/Tests/LibWeb/Text/expected/all-window-properties.txt+++ b/Tests/LibWeb/Text/expected/all-window-properties.txt@@ -398,6 +398,7 @@ ResizeObserverEntryResizeObserverSizeResponseSVGAElement+SVGAnimateMotionElementSVGAnimatedEnumerationSVGAnimatedIntegerSVGAnimatedLengthdiff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txtindex 249fd41587f..3669f2e4a03 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-1128 Pass-652 Fail+1141 Pass+639 FailPass idl_test setupPass idl_test validationPass Partial interface Document: original interface defined@@ -1712,21 +1712,21 @@ Pass SVGElement interface: objects.set must inherit property "ownerSVGElement" wPass SVGElement interface: objects.set must inherit property "viewportElement" with the proper typeFail SVGElement interface: objects.set must inherit property "correspondingElement" with the proper typeFail SVGElement interface: objects.set must inherit property "correspondingUseElement" with the proper type-Fail SVGAnimateMotionElement interface: existence and properties of interface object-Fail SVGAnimateMotionElement interface object length-Fail SVGAnimateMotionElement interface object name-Fail SVGAnimateMotionElement interface: existence and properties of interface prototype object-Fail SVGAnimateMotionElement interface: existence and properties of interface prototype object's "constructor" property-Fail SVGAnimateMotionElement interface: existence and properties of interface prototype object's @@unscopables property-Fail SVGAnimateMotionElement must be primary interface of objects.animateMotion-Fail Stringification of objects.animateMotion-Fail SVGAnimationElement interface: objects.animateMotion must inherit property "targetElement" with the proper type-Fail SVGAnimationElement interface: objects.animateMotion must inherit property "onbegin" with the proper type-Fail SVGAnimationElement interface: objects.animateMotion must inherit property "onend" with the proper type-Fail SVGAnimationElement interface: objects.animateMotion must inherit property "onrepeat" with the proper type+Pass SVGAnimateMotionElement interface: existence and properties of interface object+Pass SVGAnimateMotionElement interface object length+Pass SVGAnimateMotionElement interface object name+Pass SVGAnimateMotionElement interface: existence and properties of interface prototype object+Pass SVGAnimateMotionElement interface: existence and properties of interface prototype object's "constructor" property+Pass SVGAnimateMotionElement interface: existence and properties of interface prototype object's @@unscopables property+Pass SVGAnimateMotionElement must be primary interface of objects.animateMotion+Pass Stringification of objects.animateMotion+Pass SVGAnimationElement interface: objects.animateMotion must inherit property "targetElement" with the proper type+Pass SVGAnimationElement interface: objects.animateMotion must inherit property "onbegin" with the proper type+Pass SVGAnimationElement interface: objects.animateMotion must inherit property "onend" with the proper type+Pass SVGAnimationElement interface: objects.animateMotion must inherit property "onrepeat" with the proper typeFail SVGAnimationElement interface: objects.animateMotion must inherit property "getStartTime()" with the proper typeFail SVGAnimationElement interface: objects.animateMotion must inherit property "getCurrentTime()" with the proper type-Fail SVGAnimationElement interface: objects.animateMotion must inherit property "getSimpleDuration()" with the proper type+Pass SVGAnimationElement interface: objects.animateMotion must inherit property "getSimpleDuration()" with the proper typeFail SVGAnimationElement interface: objects.animateMotion must inherit property "beginElement()" with the proper typeFail SVGAnimationElement interface: objects.animateMotion must inherit property "beginElementAt(float)" with the proper typeFail SVGAnimationElement interface: calling beginElementAt(float) on objects.animateMotion with too few arguments must throw TypeError