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; };