LibWeb/SVG: Implement SVGElement.ownerSVGElement

This commit is contained in:
Jamie Mansfield 2024-07-16 11:26:25 +01:00 committed by Andreas Kling
parent 89531fb115
commit 6f3c5f5ae9
Notes: sideshowbarker 2024-07-17 07:14:22 +09:00
5 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,3 @@
svg.ownerSVGElement = 'null'
linearGradient.ownerSVGElement = '[object SVGSVGElement]'
linearGradient.ownerSVGElement == svg = 'true'

View File

@ -0,0 +1,14 @@
<script src="../include.js"></script>
<svg xmlns="http://www.w3.org/2000/svg" id="svg-element">
<linearGradient id="linear-gradient-element" />
</svg>
<script>
test(() => {
const svgElement = document.getElementById("svg-element");
println(`svg.ownerSVGElement = '${svgElement.ownerSVGElement}'`);
const linearGradientElement = document.getElementById("linear-gradient-element");
println(`linearGradient.ownerSVGElement = '${linearGradientElement.ownerSVGElement}'`);
println(`linearGradient.ownerSVGElement == svg = '${linearGradientElement.ownerSVGElement === svgElement}'`);
});
</script>

View File

@ -13,6 +13,7 @@
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/HTML/DOMStringMap.h>
#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGSVGElement.h>
#include <LibWeb/SVG/SVGUseElement.h>
namespace Web::SVG {
@ -125,6 +126,15 @@ JS::NonnullGCPtr<SVGAnimatedString> SVGElement::class_name()
return *m_class_name_animated_string;
}
// https://svgwg.org/svg2-draft/types.html#__svg__SVGElement__ownerSVGElement
JS::GCPtr<SVGSVGElement> 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<SVGSVGElement>();
}
JS::NonnullGCPtr<SVGAnimatedLength> SVGElement::svg_animated_length_for_property(CSS::PropertyID property) const
{
// FIXME: Create a proper animated value when animations are supported.

View File

@ -32,6 +32,7 @@ public:
void blur();
JS::NonnullGCPtr<SVGAnimatedString> class_name();
JS::GCPtr<SVGSVGElement> owner_svg_element();
protected:
SVGElement(DOM::Document&, DOM::QualifiedName);

View File

@ -3,6 +3,7 @@
#import <HTML/HTMLElement.idl>
#import <HTML/DOMStringMap.idl>
#import <SVG/SVGAnimatedString.idl>
#import <SVG/SVGSVGElement.idl>
// 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;
};