diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 4cfa72a0ee..0f5e7fb4b2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -6,6 +6,7 @@ */ #include +#include #include namespace Web::HTML { @@ -19,4 +20,19 @@ HTMLSelectElement::~HTMLSelectElement() { } +// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options +RefPtr const& HTMLSelectElement::options() +{ + if (!m_options) { + m_options = HTMLOptionsCollection::create(*this, [](DOM::Element const& element) { + // https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-option-list + // The list of options for a select element consists of all the option element children of + // the select element, and all the option element children of all the optgroup element children + // of the select element, in tree order. + return is(element); + }); + } + return m_options; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index e26d0e2bef..b59ef5c2d6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -10,6 +10,7 @@ #include #include +#include namespace Web::HTML { @@ -20,6 +21,8 @@ public: HTMLSelectElement(DOM::Document&, DOM::QualifiedName); virtual ~HTMLSelectElement() override; + RefPtr const& options(); + // ^FormAssociatedElement // https://html.spec.whatwg.org/multipage/forms.html#category-listed virtual bool is_listed() const override { return true; } @@ -36,6 +39,9 @@ public: // ^HTMLElement // https://html.spec.whatwg.org/multipage/forms.html#category-label virtual bool is_labelable() const override { return true; } + +private: + RefPtr m_options; }; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl index ddbfc31f69..6a2a348242 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl @@ -1,9 +1,11 @@ #import +#import interface HTMLSelectElement : HTMLElement { [Reflect] attribute boolean disabled; [Reflect] attribute boolean multiple; [Reflect] attribute boolean required; + [SameObject] readonly attribute HTMLOptionsCollection options; };