diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 82e2490d2f2..a51dd08ca73 100644 --- a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -77,7 +77,7 @@ void HTMLSelectElement::adjust_computed_style(CSS::StyleProperties& style) } // https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-size -WebIDL::UnsignedLong HTMLSelectElement::size() const +u32 HTMLSelectElement::display_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()) { @@ -94,8 +94,22 @@ WebIDL::UnsignedLong HTMLSelectElement::size() const return 1; } +// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-size +WebIDL::UnsignedLong HTMLSelectElement::size() const +{ + // The multiple, required, and size IDL attributes 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() && *size <= 2147483647) + return *size; + } + + return 0; +} + WebIDL::ExceptionOr HTMLSelectElement::set_size(WebIDL::UnsignedLong size) { + if (size > 2147483647) + size = 0; return set_attribute(HTML::AttributeNames::size, String::number(size)); } @@ -574,7 +588,7 @@ void HTMLSelectElement::update_selectedness() return; // If element's multiple attribute is absent, and element's display size is 1, - if (size() == 1) { + if (display_size() == 1) { bool has_selected_elements = false; for (auto const& option_element : list_of_options()) { if (option_element->selected()) { diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Libraries/LibWeb/HTML/HTMLSelectElement.h index c9656fea7b7..04263f26218 100644 --- a/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -115,6 +115,8 @@ private: void update_inner_text_element(); void queue_input_and_change_events(); + u32 display_size() const; + GC::Ptr m_options; GC::Ptr m_selected_options; bool m_is_open { false }; diff --git a/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt index f26674fa5c2..2f8169498cb 100644 --- a/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt +++ b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt @@ -77,6 +77,26 @@ marquee.getAttribute("scrolldelay") after marquee.setAttribute("scrollDelay", "4 marquee.scrollDelay after marquee.setAttribute("scrolldelay", "4294967295"): 85 marquee.getAttribute("scrolldelay") after marquee.scrollDelay = 4294967295: 85 marquee.scrollDelay after marquee.scrollDelay = 4294967295: 85 +select.getAttribute("size") after select.setAttribute("size", "0"): 0 +select.size after select.setAttribute("size", "0"): 0 +select.getAttribute("size") after select.size = 0: 0 +select.size after select.size = 0: 0 +select.getAttribute("size") after select.setAttribute("size", "1"): 1 +select.size after select.setAttribute("size", "1"): 1 +select.getAttribute("size") after select.size = 1: 1 +select.size after select.size = 1: 1 +select.getAttribute("size") after select.setAttribute("size", "2147483647"): 2147483647 +select.size after select.setAttribute("size", "2147483647"): 2147483647 +select.getAttribute("size") after select.size = 2147483647: 2147483647 +select.size after select.size = 2147483647: 2147483647 +select.getAttribute("size") after select.setAttribute("size", "2147483648"): 2147483648 +select.size after select.setAttribute("size", "2147483648"): 0 +select.getAttribute("size") after select.size = 2147483648: 0 +select.size after select.size = 2147483648: 0 +select.getAttribute("size") after select.setAttribute("size", "4294967295"): 4294967295 +select.size after select.setAttribute("size", "4294967295"): 0 +select.getAttribute("size") after select.size = 4294967295: 0 +select.size after select.size = 4294967295: 0 textarea.getAttribute("rows") after textarea.setAttribute("rows", "0"): 0 textarea.rows after textarea.setAttribute("rows", "0"): 2 textarea.getAttribute("rows") after textarea.rows = 0: 2 @@ -116,4 +136,4 @@ textarea.cols after textarea.cols = 2147483648: 20 textarea.getAttribute("cols") after textarea.setAttribute("cols", "4294967295"): 4294967295 textarea.cols after textarea.setAttribute("cols", "4294967295"): 20 textarea.getAttribute("cols") after textarea.cols = 4294967295: 20 -textarea.cols after textarea.cols = 4294967295: 20 \ No newline at end of file +textarea.cols after textarea.cols = 4294967295: 20 diff --git a/Tests/LibWeb/Text/expected/select.txt b/Tests/LibWeb/Text/expected/select.txt index a254062d157..d381c1eec5a 100644 --- a/Tests/LibWeb/Text/expected/select.txt +++ b/Tests/LibWeb/Text/expected/select.txt @@ -6,7 +6,7 @@ 6. "Three" 7. 45 8. 0 -9. 1 +9. 0 10. 3 11. 999 12. 10 diff --git a/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html index 3eb949da149..00ff3915bb0 100644 --- a/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html +++ b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html @@ -31,6 +31,7 @@ testProperty("input", "size", (input) => input.size, (input, value) => input.size = value); testProperty("marquee", "scrollAmount", (marquee) => marquee.scrollAmount, (marquee, value) => marquee.scrollAmount = value); testProperty("marquee", "scrollDelay", (marquee) => marquee.scrollDelay, (marquee, value) => marquee.scrollDelay = value); + testProperty("select", "size", (select) => select.size, (select, value) => select.size = value); testProperty("textarea", "rows", (textarea) => textarea.rows, (textarea, value) => textarea.rows = value); testProperty("textarea", "cols", (textarea) => textarea.cols, (textarea, value) => textarea.cols = value); });