mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:57:44 +00:00
LibWeb: Make parse_html_length() accept floating point numbers
This makes stuff like <img width="12.5"> work. This code is not great, so I've left a FIXME about improving it.
This commit is contained in:
parent
196a3eb239
commit
1206dd2215
1 changed files with 13 additions and 0 deletions
|
@ -4976,9 +4976,22 @@ RefPtr<CSS::Supports> parse_css_supports(CSS::ParsingContext const& context, Str
|
||||||
|
|
||||||
RefPtr<CSS::StyleValue> parse_html_length(DOM::Document const& document, StringView string)
|
RefPtr<CSS::StyleValue> parse_html_length(DOM::Document const& document, StringView string)
|
||||||
{
|
{
|
||||||
|
if (string.is_null())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
auto integer = string.to_int();
|
auto integer = string.to_int();
|
||||||
if (integer.has_value())
|
if (integer.has_value())
|
||||||
return CSS::LengthStyleValue::create(CSS::Length::make_px(integer.value()));
|
return CSS::LengthStyleValue::create(CSS::Length::make_px(integer.value()));
|
||||||
|
|
||||||
|
{
|
||||||
|
// FIXME: This is both ad-hoc and inefficient (note the String allocation!)
|
||||||
|
String string_copy(string);
|
||||||
|
char const* endptr = nullptr;
|
||||||
|
auto double_value = strtod(string_copy.characters(), const_cast<char**>(&endptr));
|
||||||
|
if (endptr != string_copy.characters())
|
||||||
|
return CSS::LengthStyleValue::create(CSS::Length::make_px(double_value));
|
||||||
|
}
|
||||||
|
|
||||||
return parse_css_value(CSS::ParsingContext(document), string);
|
return parse_css_value(CSS::ParsingContext(document), string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue