LibWeb: Implement SVGElement.viewportElement

This commit is contained in:
Andreas Kling 2025-05-09 01:05:03 +02:00 committed by Andreas Kling
commit 1dc6425ede
Notes: github-actions[bot] 2025-05-16 18:37:07 +00:00
4 changed files with 55 additions and 38 deletions

View file

@ -14,6 +14,7 @@
#include <LibWeb/SVG/SVGDescElement.h>
#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGSVGElement.h>
#include <LibWeb/SVG/SVGSymbolElement.h>
#include <LibWeb/SVG/SVGTitleElement.h>
#include <LibWeb/SVG/SVGUseElement.h>
@ -251,6 +252,21 @@ GC::Ptr<SVGSVGElement> SVGElement::owner_svg_element()
return shadow_including_first_ancestor_of_type<SVGSVGElement>();
}
// https://svgwg.org/svg2-draft/types.html#__svg__SVGElement__viewportElement
GC::Ptr<SVGElement> SVGElement::viewport_element()
{
for (auto* node = parent(); node; node = node->parent_or_shadow_host()) {
// https://svgwg.org/svg2-draft/coords.html#EstablishingANewSVGViewport
// The following elements establish new SVG viewports:
// - The svg element
// - A symbol element that is instanced by a use element.
if (is<SVGSVGElement>(*node) || is<SVGSymbolElement>(*node)) {
return static_cast<SVGElement*>(node);
}
}
return nullptr;
}
GC::Ref<SVGAnimatedLength> SVGElement::svg_animated_length_for_property(CSS::PropertyID property) const
{
// FIXME: Create a proper animated value when animations are supported.