mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 02:10:26 +00:00
LibWeb: Mirror options collection on the select element
This commit is contained in:
parent
e4fb4d7c1a
commit
3e296a1b92
Notes:
github-actions[bot]
2026-01-06 12:05:11 +00:00
Author: https://github.com/lpas
Commit: 3e296a1b92
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6749
Reviewed-by: https://github.com/Psychpsyo
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/konradekk
Reviewed-by: https://github.com/shannonbooth
5 changed files with 37 additions and 13 deletions
|
|
@ -39,6 +39,11 @@ GC_DEFINE_ALLOCATOR(HTMLSelectElement);
|
|||
HTMLSelectElement::HTMLSelectElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
{
|
||||
m_legacy_platform_object_flags = LegacyPlatformObjectFlags {
|
||||
.supports_indexed_properties = true,
|
||||
.has_indexed_property_setter = true,
|
||||
.indexed_property_setter_has_identifier = true,
|
||||
};
|
||||
}
|
||||
|
||||
HTMLSelectElement::~HTMLSelectElement() = default;
|
||||
|
|
@ -120,12 +125,12 @@ void HTMLSelectElement::set_size(WebIDL::UnsignedLong size)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
|
||||
GC::Ptr<HTMLOptionsCollection> const& HTMLSelectElement::options()
|
||||
GC::Ptr<HTMLOptionsCollection> const& HTMLSelectElement::options() const
|
||||
{
|
||||
// The options IDL attribute must return an HTMLOptionsCollection rooted at the select node,
|
||||
// whose filter matches the elements in the list of options.
|
||||
if (!m_options) {
|
||||
m_options = HTMLOptionsCollection::create(*this, [this](DOM::Element const& element) {
|
||||
m_options = HTMLOptionsCollection::create(const_cast<HTMLSelectElement&>(*this), [this](DOM::Element const& element) {
|
||||
auto const* maybe_option = as_if<HTML::HTMLOptionElement>(element);
|
||||
return maybe_option && maybe_option->nearest_select_element() == this;
|
||||
});
|
||||
|
|
@ -153,6 +158,14 @@ HTMLOptionElement* HTMLSelectElement::item(WebIDL::UnsignedLong index)
|
|||
return as<HTMLOptionElement>(const_cast<HTMLOptionsCollection&>(*options()).item(index));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#the-select-element:htmlselectelement
|
||||
Optional<JS::Value> HTMLSelectElement::item_value(size_t index) const
|
||||
{
|
||||
// The options collection is also mirrored on the HTMLSelectElement object. The supported property indices at any
|
||||
// instant are the indices supported by the object returned by the options attribute at that instant.
|
||||
return (const_cast<HTMLOptionsCollection&>(*options()).item_value(index));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-nameditem
|
||||
HTMLOptionElement* HTMLSelectElement::named_item(FlyString const& name)
|
||||
{
|
||||
|
|
@ -171,6 +184,16 @@ WebIDL::ExceptionOr<void> HTMLSelectElement::add(HTMLOptionOrOptGroupElement ele
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#the-select-element:set-the-value-of-a-new-indexed-property
|
||||
WebIDL::ExceptionOr<void> HTMLSelectElement::set_value_of_indexed_property(u32 n, JS::Value new_value)
|
||||
{
|
||||
// When the user agent is to set the value of a new indexed property or set the value of an existing indexed property
|
||||
// for a select element, it must instead run the corresponding algorithm on the select element's options collection.
|
||||
TRY(const_cast<HTMLOptionsCollection&>(*options()).set_value_of_indexed_property(n, new_value));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-remove
|
||||
void HTMLSelectElement::remove()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue