From 9cf5b67162d9d8ffc993ac8330e7c04f3bd741f2 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 19 Aug 2023 13:58:54 +1200 Subject: [PATCH] LibWeb: Return a HTMLFormControlsCollection from HTMLFormElement element Instead of a HTMLCollection --- .../html-form-controls-collection.txt | 8 +++++++ .../input/html-form-controls-collection.html | 24 +++++++++++++++++++ .../Libraries/LibWeb/HTML/HTMLFormElement.cpp | 5 ++-- .../Libraries/LibWeb/HTML/HTMLFormElement.h | 4 ++-- .../Libraries/LibWeb/HTML/HTMLFormElement.idl | 5 ++-- 5 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/html-form-controls-collection.txt create mode 100644 Tests/LibWeb/Text/input/html-form-controls-collection.html diff --git a/Tests/LibWeb/Text/expected/html-form-controls-collection.txt b/Tests/LibWeb/Text/expected/html-form-controls-collection.txt new file mode 100644 index 0000000000..1fcbce521a --- /dev/null +++ b/Tests/LibWeb/Text/expected/html-form-controls-collection.txt @@ -0,0 +1,8 @@ + HTMLFormControlsCollection +RadioNodeList +2 +button +text +null +HTMLInputElement +text diff --git a/Tests/LibWeb/Text/input/html-form-controls-collection.html b/Tests/LibWeb/Text/input/html-form-controls-collection.html new file mode 100644 index 0000000000..8e28c16c96 --- /dev/null +++ b/Tests/LibWeb/Text/input/html-form-controls-collection.html @@ -0,0 +1,24 @@ +
+ + +
+ + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 033509500f..89bc6de3ed 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -406,10 +407,10 @@ static bool is_form_control(DOM::Element const& element) } // https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements -JS::NonnullGCPtr HTMLFormElement::elements() const +JS::NonnullGCPtr HTMLFormElement::elements() const { if (!m_elements) { - m_elements = DOM::HTMLCollection::create(const_cast(*this), DOM::HTMLCollection::Scope::Descendants, [](Element const& element) { + m_elements = DOM::HTMLFormControlsCollection::create(const_cast(*this), DOM::HTMLCollection::Scope::Descendants, [](Element const& element) { return is_form_control(element); }); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h index b91c91c970..204413a0f8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h @@ -67,7 +67,7 @@ public: ErrorOr>> get_submittable_elements(); - JS::NonnullGCPtr elements() const; + JS::NonnullGCPtr elements() const; unsigned length() const; WebIDL::ExceptionOr check_validity(); @@ -110,7 +110,7 @@ private: Vector> m_associated_elements; - JS::GCPtr mutable m_elements; + JS::GCPtr mutable m_elements; bool m_constructing_entry_list { false }; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl index 6371af33e8..30b95985e9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl @@ -1,4 +1,4 @@ -#import +#import #import // https://html.spec.whatwg.org/multipage/semantics.html#htmlformelement @@ -20,8 +20,7 @@ interface HTMLFormElement : HTMLElement { boolean checkValidity(); boolean reportValidity(); - // FIXME: Should be a HTMLFormControlsCollection - [SameObject] readonly attribute HTMLCollection elements; + [SameObject] readonly attribute HTMLFormControlsCollection elements; readonly attribute unsigned long length;