mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
LibWeb: Add parser for the HTML "non-zero dimensions value" microsyntax
This commit is contained in:
parent
fe908e7db2
commit
28c929e85c
2 changed files with 23 additions and 0 deletions
|
@ -5242,4 +5242,26 @@ RefPtr<CSS::StyleValue> parse_dimension_value(StringView string)
|
|||
return parse_current_dimension_value(value, input, position);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-non-zero-dimension-values
|
||||
RefPtr<CSS::StyleValue> parse_nonzero_dimension_value(StringView string)
|
||||
{
|
||||
// 1. Let input be the string being parsed.
|
||||
// 2. Let value be the result of parsing input using the rules for parsing dimension values.
|
||||
auto value = parse_dimension_value(string);
|
||||
|
||||
// 3. If value is an error, return an error.
|
||||
if (!value)
|
||||
return nullptr;
|
||||
|
||||
// 4. If value is zero, return an error.
|
||||
if (value->is_length() && value->as_length().length().raw_value() == 0)
|
||||
return nullptr;
|
||||
if (value->is_percentage() && value->as_percentage().percentage().value() == 0)
|
||||
return nullptr;
|
||||
|
||||
// 5. If value is a percentage, return value as a percentage.
|
||||
// 6. Return value as a length.
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue