mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 11:04:59 +00:00
LibWeb: Make HTMLProgressElement use the new double parser
This commit is contained in:
parent
6e9969ded0
commit
29a96b1304
1 changed files with 16 additions and 8 deletions
|
@ -47,15 +47,19 @@ void HTMLProgressElement::progress_position_updated()
|
|||
|
||||
double HTMLProgressElement::value() const
|
||||
{
|
||||
auto value_characters = attribute(HTML::AttributeNames::value).characters();
|
||||
auto const& value_characters = attribute(HTML::AttributeNames::value);
|
||||
if (value_characters == nullptr)
|
||||
return 0;
|
||||
|
||||
auto parsed_value = strtod(value_characters, nullptr);
|
||||
if (!isfinite(parsed_value) || parsed_value < 0)
|
||||
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-floating-point-number-values
|
||||
// 6. Skip ASCII whitespace within input given position.
|
||||
auto maybe_double = value_characters.to_double(AK::TrimWhitespace::Yes);
|
||||
if (!maybe_double.has_value())
|
||||
return 0;
|
||||
if (!isfinite(maybe_double.value()) || maybe_double.value() < 0)
|
||||
return 0;
|
||||
|
||||
return min(parsed_value, max());
|
||||
return min(maybe_double.value(), max());
|
||||
}
|
||||
|
||||
void HTMLProgressElement::set_value(double value)
|
||||
|
@ -69,15 +73,19 @@ void HTMLProgressElement::set_value(double value)
|
|||
|
||||
double HTMLProgressElement::max() const
|
||||
{
|
||||
auto max_characters = attribute(HTML::AttributeNames::max).characters();
|
||||
auto const& max_characters = attribute(HTML::AttributeNames::max);
|
||||
if (max_characters == nullptr)
|
||||
return 1;
|
||||
|
||||
auto parsed_value = strtod(max_characters, nullptr);
|
||||
if (!isfinite(parsed_value) || parsed_value <= 0)
|
||||
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-floating-point-number-values
|
||||
// 6. Skip ASCII whitespace within input given position.
|
||||
auto double_or_none = max_characters.to_double(AK::TrimWhitespace::Yes);
|
||||
if (!double_or_none.has_value())
|
||||
return 1;
|
||||
if (!isfinite(double_or_none.value()) || double_or_none.value() <= 0)
|
||||
return 1;
|
||||
|
||||
return parsed_value;
|
||||
return double_or_none.value();
|
||||
}
|
||||
|
||||
void HTMLProgressElement::set_max(double value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue