From 191531b7b18d2edf97dc7bf88a9c19903eeae2d5 Mon Sep 17 00:00:00 2001 From: simonkrauter Date: Wed, 10 Jul 2024 16:10:14 -0300 Subject: [PATCH] LibWeb: Use correct default value for Previously the input element was displayed with value 0, when no value was set in the HTML. Now it uses `value_sanitization_algorithm()`, which will calculate the default value. In `value_sanitization_algorithm()` there was a logical mistake/typo. The comment from the spec says "unless the maximum is less than the minimum". The added layout test would fail without the code changes. Fixes #520 --- Tests/LibWeb/Layout/expected/input-range.txt | 26 +++++++++++++++++++ Tests/LibWeb/Layout/input/input-range.html | 8 ++++++ .../LibWeb/HTML/HTMLInputElement.cpp | 7 ++--- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/input-range.txt create mode 100644 Tests/LibWeb/Layout/input/input-range.html diff --git a/Tests/LibWeb/Layout/expected/input-range.txt b/Tests/LibWeb/Layout/expected/input-range.txt new file mode 100644 index 0000000000..85f212b1e2 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/input-range.txt @@ -0,0 +1,26 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x38 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x22 children: inline + frag 0 from BlockContainer start: 0, length: 0, rect: [8,9 200x16] baseline: 16 + frag 1 from BlockContainer start: 0, length: 0, rect: [208,9 200x16] baseline: 16 + BlockContainer at (8,9) content-size 200x16 inline-block [BFC] children: not-inline + BlockContainer
at (9,16) content-size 200x4 positioned children: not-inline + BlockContainer
at (9,16) content-size 100x4 positioned [BFC] children: not-inline + BlockContainer
at (109,10) content-size 16x16 children: not-inline + BlockContainer at (208,9) content-size 200x16 inline-block [BFC] children: not-inline + BlockContainer
at (209,16) content-size 200x4 positioned children: not-inline + BlockContainer
at (209,16) content-size 20x4 positioned [BFC] children: not-inline + BlockContainer
at (229,10) content-size 16x16 children: not-inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x38] + PaintableWithLines (BlockContainer) [8,8 784x22] + PaintableWithLines (BlockContainer) [8,9 200x16] overflow: [8,9 202x17] + PaintableWithLines (BlockContainer
) [8,15 202x6] overflow: [9,10 200x16] + PaintableWithLines (BlockContainer
) [9,16 100x4] + PaintableWithLines (BlockContainer
) [109,10 16x16] + PaintableWithLines (BlockContainer) [208,9 200x16] overflow: [208,9 202x17] + PaintableWithLines (BlockContainer
) [208,15 202x6] overflow: [209,10 200x16] + PaintableWithLines (BlockContainer
) [209,16 20x4] + PaintableWithLines (BlockContainer
) [229,10 16x16] diff --git a/Tests/LibWeb/Layout/input/input-range.html b/Tests/LibWeb/Layout/input/input-range.html new file mode 100644 index 0000000000..72eb9ccf19 --- /dev/null +++ b/Tests/LibWeb/Layout/input/input-range.html @@ -0,0 +1,8 @@ + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 20b9219e40..6d9ce3c6bb 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1104,10 +1104,7 @@ void HTMLInputElement::user_interaction_did_change_input_value() void HTMLInputElement::update_slider_thumb_element() { - double value = value_as_number(); - if (isnan(value)) - value = 0; - + double value = convert_string_to_number(value_sanitization_algorithm(m_value)).value_or(0); double minimum = *min(); double maximum = *max(); double position = (value - minimum) / (maximum - minimum) * 100; @@ -1380,7 +1377,7 @@ String HTMLInputElement::value_sanitization_algorithm(String const& value) const // The default value is the minimum plus half the difference between the minimum and the maximum, unless the maximum is less than the minimum, in which case the default value is the minimum. auto minimum = *min(); auto maximum = *max(); - if (maximum > minimum) + if (maximum < minimum) return JS::number_to_string(minimum); return JS::number_to_string(minimum + (maximum - minimum) / 2); }