1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:08:12 +00:00

LibWeb: Add a dedicated function for parsing HTML length values

Presentation attribute lengths (width, height, etc.) can always be
unit-less (e.g "400") so going via the normal CSS parsing path only
works when the document is in quirks mode.

Add a separate parse_html_length() that always allows unit-less values.
This commit is contained in:
Andreas Kling 2020-07-22 01:13:18 +02:00
parent 9fc00d5d12
commit 5a7e57457e
4 changed files with 12 additions and 2 deletions

View file

@ -928,4 +928,12 @@ RefPtr<StyleDeclaration> parse_css_declaration(const CSS::ParsingContext& contex
return parser.parse_standalone_declaration();
}
RefPtr<StyleValue> parse_html_length(const Document& document, const StringView& string)
{
auto integer = string.to_int();
if (integer.has_value())
return LengthStyleValue::create(Length::make_px(integer.value()));
return parse_css_value(CSS::ParsingContext(document), string);
}
}