diff --git a/Tests/LibWeb/Text/expected/fieldset-elements.txt b/Tests/LibWeb/Text/expected/fieldset-elements.txt new file mode 100644 index 00000000000..56f152eced6 --- /dev/null +++ b/Tests/LibWeb/Text/expected/fieldset-elements.txt @@ -0,0 +1,2 @@ +1. 3 +2. "PASS" diff --git a/Tests/LibWeb/Text/input/fieldset-elements.html b/Tests/LibWeb/Text/input/fieldset-elements.html new file mode 100644 index 00000000000..401165f415d --- /dev/null +++ b/Tests/LibWeb/Text/input/fieldset-elements.html @@ -0,0 +1,24 @@ + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp index d2409ef4f6b..d3b371a5ede 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp @@ -5,8 +5,14 @@ */ #include +#include #include +#include #include +#include +#include +#include +#include namespace Web::HTML { @@ -25,6 +31,12 @@ void HTMLFieldSetElement::initialize(JS::Realm& realm) set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLFieldSetElement"_fly_string)); } +void HTMLFieldSetElement::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_elements); +} + // https://html.spec.whatwg.org/multipage/form-elements.html#concept-fieldset-disabled bool HTMLFieldSetElement::is_disabled() const { @@ -45,4 +57,23 @@ bool HTMLFieldSetElement::is_disabled() const return false; } +// https://html.spec.whatwg.org/multipage/form-elements.html#dom-fieldset-elements +JS::GCPtr const& HTMLFieldSetElement::elements() +{ + // The elements IDL attribute must return an HTMLCollection rooted at the fieldset element, whose filter matches listed elements. + if (!m_elements) { + m_elements = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, [](DOM::Element const& element) { + // FIXME: Form-associated custom elements return also true + return is(element) + || is(element) + || is(element) + || is(element) + || is(element) + || is(element) + || is(element); + }); + } + return m_elements; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h index 0713df207af..52bc7db8000 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include @@ -30,6 +31,8 @@ public: bool is_disabled() const; + JS::GCPtr const& elements(); + // ^FormAssociatedElement // https://html.spec.whatwg.org/multipage/forms.html#category-listed virtual bool is_listed() const override { return true; } @@ -43,6 +46,9 @@ private: HTMLFieldSetElement(DOM::Document&, DOM::QualifiedName); virtual void initialize(JS::Realm&) override; + virtual void visit_edges(Cell::Visitor&) override; + + JS::GCPtr m_elements; }; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl index cf35c6d1f25..9e133e70d50 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl @@ -12,7 +12,7 @@ interface HTMLFieldSetElement : HTMLElement { readonly attribute DOMString type; - // FIXME: [SameObject] readonly attribute HTMLCollection elements; + [SameObject] readonly attribute HTMLCollection elements; // FIXME: readonly attribute boolean willValidate; // FIXME: [SameObject] readonly attribute ValidityState validity; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 9aaa943bf06..953eec60dcb 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -396,6 +396,8 @@ static bool is_form_control(DOM::Element const& element) return true; } + // FIXME: Form-associated custom elements return also true + return false; }