LibWeb: Implement Document.rootElement (SVG2 extension to Document)

This commit is contained in:
Andreas Kling 2025-05-09 00:30:40 +02:00 committed by Andreas Kling
commit 879cba762b
Notes: github-actions[bot] 2025-05-16 18:37:14 +00:00
4 changed files with 16 additions and 3 deletions

View file

@ -151,6 +151,7 @@
#include <LibWeb/ResizeObserver/ResizeObserverEntry.h> #include <LibWeb/ResizeObserver/ResizeObserverEntry.h>
#include <LibWeb/SVG/SVGDecodedImageData.h> #include <LibWeb/SVG/SVGDecodedImageData.h>
#include <LibWeb/SVG/SVGElement.h> #include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGSVGElement.h>
#include <LibWeb/SVG/SVGStyleElement.h> #include <LibWeb/SVG/SVGStyleElement.h>
#include <LibWeb/SVG/SVGTitleElement.h> #include <LibWeb/SVG/SVGTitleElement.h>
#include <LibWeb/Selection/Selection.h> #include <LibWeb/Selection/Selection.h>
@ -892,6 +893,12 @@ Element const* Document::document_element() const
return first_child_of_type<Element>(); return first_child_of_type<Element>();
} }
// https://www.w3.org/TR/SVG2/struct.html#InterfaceDocumentExtensions
GC::Ptr<SVG::SVGSVGElement> Document::root_element()
{
return as_if<SVG::SVGSVGElement>(document_element());
}
// https://html.spec.whatwg.org/multipage/dom.html#the-html-element-2 // https://html.spec.whatwg.org/multipage/dom.html#the-html-element-2
HTML::HTMLHtmlElement* Document::html_element() HTML::HTMLHtmlElement* Document::html_element()
{ {

View file

@ -270,6 +270,9 @@ public:
Element* document_element(); Element* document_element();
Element const* document_element() const; Element const* document_element() const;
// https://www.w3.org/TR/SVG2/struct.html#InterfaceDocumentExtensions
GC::Ptr<SVG::SVGSVGElement> root_element();
HTML::HTMLHtmlElement* html_element(); HTML::HTMLHtmlElement* html_element();
HTML::HTMLHeadElement* head(); HTML::HTMLHeadElement* head();
GC::Ptr<HTML::HTMLTitleElement> title_element(); GC::Ptr<HTML::HTMLTitleElement> title_element();

View file

@ -156,6 +156,9 @@ interface Document : Node {
// special event handler IDL attributes that only apply to Document objects // special event handler IDL attributes that only apply to Document objects
[LegacyLenientThis] attribute EventHandler onreadystatechange; [LegacyLenientThis] attribute EventHandler onreadystatechange;
attribute EventHandler onvisibilitychange; attribute EventHandler onvisibilitychange;
// https://www.w3.org/TR/SVG2/struct.html#InterfaceDocumentExtensions
readonly attribute SVGSVGElement? rootElement;
}; };
dictionary ElementCreationOptions { dictionary ElementCreationOptions {

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 1781 tests Found 1781 tests
873 Pass 874 Pass
908 Fail 907 Fail
Pass idl_test setup Pass idl_test setup
Pass idl_test validation Pass idl_test validation
Pass Partial interface Document: original interface defined Pass Partial interface Document: original interface defined
@ -1784,4 +1784,4 @@ Fail SVGDiscardElement interface object name
Fail SVGDiscardElement interface: existence and properties of interface prototype object Fail SVGDiscardElement interface: existence and properties of interface prototype object
Fail SVGDiscardElement interface: existence and properties of interface prototype object's "constructor" property Fail SVGDiscardElement interface: existence and properties of interface prototype object's "constructor" property
Fail SVGDiscardElement interface: existence and properties of interface prototype object's @@unscopables property Fail SVGDiscardElement interface: existence and properties of interface prototype object's @@unscopables property
Fail Document interface: attribute rootElement Pass Document interface: attribute rootElement