From 6f3c5f5ae9f0ee055c44ace5efab0c443626bb5d Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 16 Jul 2024 11:26:25 +0100 Subject: [PATCH] LibWeb/SVG: Implement SVGElement.ownerSVGElement --- .../expected/SVG/svg-ownerSVGElement-attribute.txt | 3 +++ .../input/SVG/svg-ownerSVGElement-attribute.html | 14 ++++++++++++++ Userland/Libraries/LibWeb/SVG/SVGElement.cpp | 10 ++++++++++ Userland/Libraries/LibWeb/SVG/SVGElement.h | 1 + Userland/Libraries/LibWeb/SVG/SVGElement.idl | 3 ++- 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/SVG/svg-ownerSVGElement-attribute.txt create mode 100644 Tests/LibWeb/Text/input/SVG/svg-ownerSVGElement-attribute.html diff --git a/Tests/LibWeb/Text/expected/SVG/svg-ownerSVGElement-attribute.txt b/Tests/LibWeb/Text/expected/SVG/svg-ownerSVGElement-attribute.txt new file mode 100644 index 00000000000..d22c66fdb0d --- /dev/null +++ b/Tests/LibWeb/Text/expected/SVG/svg-ownerSVGElement-attribute.txt @@ -0,0 +1,3 @@ + svg.ownerSVGElement = 'null' +linearGradient.ownerSVGElement = '[object SVGSVGElement]' +linearGradient.ownerSVGElement == svg = 'true' diff --git a/Tests/LibWeb/Text/input/SVG/svg-ownerSVGElement-attribute.html b/Tests/LibWeb/Text/input/SVG/svg-ownerSVGElement-attribute.html new file mode 100644 index 00000000000..0748662ba08 --- /dev/null +++ b/Tests/LibWeb/Text/input/SVG/svg-ownerSVGElement-attribute.html @@ -0,0 +1,14 @@ + + + + + diff --git a/Userland/Libraries/LibWeb/SVG/SVGElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGElement.cpp index 1226535db8e..9164381b26d 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGElement.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace Web::SVG { @@ -125,6 +126,15 @@ JS::NonnullGCPtr SVGElement::class_name() return *m_class_name_animated_string; } +// https://svgwg.org/svg2-draft/types.html#__svg__SVGElement__ownerSVGElement +JS::GCPtr SVGElement::owner_svg_element() +{ + // The ownerSVGElement IDL attribute represents the nearest ancestor ‘svg’ element. + // On getting ownerSVGElement, the nearest ancestor ‘svg’ element is returned; + // if the current element is the outermost svg element, then null is returned. + return first_ancestor_of_type(); +} + JS::NonnullGCPtr SVGElement::svg_animated_length_for_property(CSS::PropertyID property) const { // FIXME: Create a proper animated value when animations are supported. diff --git a/Userland/Libraries/LibWeb/SVG/SVGElement.h b/Userland/Libraries/LibWeb/SVG/SVGElement.h index 6dd10577657..26b7177423d 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGElement.h @@ -32,6 +32,7 @@ public: void blur(); JS::NonnullGCPtr class_name(); + JS::GCPtr owner_svg_element(); protected: SVGElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/SVG/SVGElement.idl b/Userland/Libraries/LibWeb/SVG/SVGElement.idl index c24d8e085fc..d132fa57892 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGElement.idl +++ b/Userland/Libraries/LibWeb/SVG/SVGElement.idl @@ -3,6 +3,7 @@ #import #import #import +#import // https://svgwg.org/svg2-draft/types.html#InterfaceSVGElement [Exposed=Window] @@ -10,7 +11,7 @@ interface SVGElement : Element { [SameObject] readonly attribute SVGAnimatedString className; - [FIXME] readonly attribute SVGSVGElement? ownerSVGElement; + readonly attribute SVGSVGElement? ownerSVGElement; [FIXME] readonly attribute SVGElement? viewportElement; };