1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 05:55:06 +00:00

LibHTML: Add LengthStyleValue and create those when parsing number values.

This commit is contained in:
Andreas Kling 2019-07-03 07:55:22 +02:00
parent 4b82ac3c8e
commit 8ac2b30de7
3 changed files with 43 additions and 7 deletions

View file

@ -11,5 +11,15 @@ StyleValue::~StyleValue()
NonnullRefPtr<StyleValue> StyleValue::parse(const StringView& str)
{
return adopt(*new PrimitiveStyleValue(str));
String string(str);
bool ok;
int as_int = string.to_int(ok);
if (ok)
return adopt(*new LengthStyleValue(Length(as_int, Length::Type::Absolute)));
unsigned as_uint = string.to_uint(ok);
if (ok)
return adopt(*new LengthStyleValue(Length(as_uint, Length::Type::Absolute)));
if (string == "auto")
return adopt(*new LengthStyleValue(Length()));
return adopt(*new StringStyleValue(str));
}