LibWeb: Add select element size property

This commit is contained in:
Bastiaan van der Plaat 2024-04-08 21:34:19 +02:00 committed by Andreas Kling
parent abb4b6d117
commit 4e5ce7b63e
Notes: sideshowbarker 2024-07-17 02:05:41 +09:00
5 changed files with 46 additions and 1 deletions

View file

@ -18,6 +18,7 @@
#include <LibWeb/HTML/HTMLOptGroupElement.h>
#include <LibWeb/HTML/HTMLOptionElement.h>
#include <LibWeb/HTML/HTMLSelectElement.h>
#include <LibWeb/HTML/Numbers.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Namespace.h>
@ -67,6 +68,22 @@ void HTMLSelectElement::adjust_computed_style(CSS::StyleProperties& style)
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-size
WebIDL::UnsignedLong HTMLSelectElement::size() const
{
// The size IDL attribute must reflect the respective content attributes of the same name. The size IDL attribute has a default value of 0.
if (auto size_string = get_attribute(HTML::AttributeNames::size); size_string.has_value()) {
if (auto size = parse_non_negative_integer(*size_string); size.has_value())
return *size;
}
return 0;
}
WebIDL::ExceptionOr<void> HTMLSelectElement::set_size(WebIDL::UnsignedLong size)
{
return set_attribute(HTML::AttributeNames::size, MUST(String::number(size)));
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
JS::GCPtr<HTMLOptionsCollection> const& HTMLSelectElement::options()
{