mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-16 04:59:23 +00:00
LibWeb: Add generic logic for parsing "positional-value-list-shorthands"
Continues the work started in #5386 to simplify handling of positional value list shorthand properties. Previously we would parse these as `StyleValueList`s and then rely on `StyleComputer::for_each_property_expanding_shorthands` to expand them into longhands. This required a bit of work to handle `ShorthandStyleValue`s for the `@page` `margin` descriptor.
This commit is contained in:
parent
b1e77b3522
commit
a7e5ded188
Notes:
github-actions[bot]
2025-09-09 09:47:05 +00:00
Author: https://github.com/Calme1709
Commit: a7e5ded188
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6136
Reviewed-by: https://github.com/gmta ✅
6 changed files with 57 additions and 199 deletions
|
@ -810,6 +810,13 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue const>> Parser::parse_css_value(Pr
|
|||
break;
|
||||
}
|
||||
|
||||
if (property_is_positional_value_list_shorthand(property_id)) {
|
||||
if (auto parsed_value = parse_positional_value_list_shorthand(property_id, tokens); parsed_value && !tokens.has_next_token())
|
||||
return parsed_value.release_nonnull();
|
||||
|
||||
return ParseError::SyntaxError;
|
||||
}
|
||||
|
||||
// If there's only 1 ComponentValue, we can only produce a single StyleValue.
|
||||
if (component_values.size() == 1) {
|
||||
auto stream = TokenStream { component_values };
|
||||
|
@ -891,6 +898,48 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue const>> Parser::parse_css_value(Pr
|
|||
return { ShorthandStyleValue::create(property_id, move(longhand_properties), move(longhand_values)) };
|
||||
}
|
||||
|
||||
RefPtr<StyleValue const> Parser::parse_positional_value_list_shorthand(PropertyID property_id, TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
auto const& longhands = longhands_for_shorthand(property_id);
|
||||
|
||||
Vector<ValueComparingNonnullRefPtr<StyleValue const>> parsed_values;
|
||||
|
||||
while (auto parsed_value = parse_css_value_for_property(property_id, tokens))
|
||||
parsed_values.append(parsed_value.release_nonnull());
|
||||
|
||||
if (parsed_values.size() == 0 || parsed_values.size() > longhands.size())
|
||||
return nullptr;
|
||||
|
||||
switch (longhands.size()) {
|
||||
case 2: {
|
||||
switch (parsed_values.size()) {
|
||||
case 1:
|
||||
return ShorthandStyleValue::create(property_id, longhands, { parsed_values[0], parsed_values[0] });
|
||||
case 2:
|
||||
return ShorthandStyleValue::create(property_id, longhands, parsed_values);
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
case 4: {
|
||||
switch (parsed_values.size()) {
|
||||
case 1:
|
||||
return ShorthandStyleValue::create(property_id, longhands, { parsed_values[0], parsed_values[0], parsed_values[0], parsed_values[0] });
|
||||
case 2:
|
||||
return ShorthandStyleValue::create(property_id, longhands, { parsed_values[0], parsed_values[1], parsed_values[0], parsed_values[1] });
|
||||
case 3:
|
||||
return ShorthandStyleValue::create(property_id, longhands, { parsed_values[0], parsed_values[1], parsed_values[2], parsed_values[1] });
|
||||
case 4:
|
||||
return ShorthandStyleValue::create(property_id, longhands, parsed_values);
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
default:
|
||||
TODO();
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<StyleValue const> Parser::parse_color_scheme_value(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
// normal | [ light | dark | <custom-ident> ]+ && only?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue