mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-30 08:18:49 +00:00
LibWeb: Use correct default value for <input type=range>
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
This commit is contained in:
parent
907dc84c1e
commit
191531b7b1
Notes:
sideshowbarker
2024-07-17 11:29:41 +09:00
Author: https://github.com/simonkrauter
Commit: 191531b7b1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/555
Issue: https://github.com/LadybirdBrowser/ladybird/issues/520
3 changed files with 36 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue