mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 07:07:36 +00:00
LibWeb: Parse overflow property using TokenStream
Also simplify it a bit. We don't need to handle 1 / 2 values separately, but past Sam didn't realise that.
This commit is contained in:
parent
0578bec655
commit
4f773a7dae
2 changed files with 13 additions and 20 deletions
|
@ -4492,29 +4492,22 @@ RefPtr<StyleValue> Parser::parse_math_depth_value(TokenStream<ComponentValue>& t
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_overflow_value(Vector<ComponentValue> const& component_values)
|
RefPtr<StyleValue> Parser::parse_overflow_value(TokenStream<ComponentValue>& tokens)
|
||||||
{
|
{
|
||||||
auto tokens = TokenStream { component_values };
|
auto transaction = tokens.begin_transaction();
|
||||||
if (component_values.size() == 1) {
|
auto maybe_x_value = parse_css_value_for_property(PropertyID::OverflowX, tokens);
|
||||||
auto maybe_value = parse_css_value_for_property(PropertyID::Overflow, tokens);
|
if (!maybe_x_value)
|
||||||
if (!maybe_value)
|
return nullptr;
|
||||||
return nullptr;
|
auto maybe_y_value = parse_css_value_for_property(PropertyID::OverflowY, tokens);
|
||||||
return ShorthandStyleValue::create(PropertyID::Overflow,
|
transaction.commit();
|
||||||
{ PropertyID::OverflowX, PropertyID::OverflowY },
|
if (maybe_y_value) {
|
||||||
{ *maybe_value, *maybe_value });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component_values.size() == 2) {
|
|
||||||
auto maybe_x_value = parse_css_value_for_property(PropertyID::OverflowX, tokens);
|
|
||||||
auto maybe_y_value = parse_css_value_for_property(PropertyID::OverflowY, tokens);
|
|
||||||
if (!maybe_x_value || !maybe_y_value)
|
|
||||||
return nullptr;
|
|
||||||
return ShorthandStyleValue::create(PropertyID::Overflow,
|
return ShorthandStyleValue::create(PropertyID::Overflow,
|
||||||
{ PropertyID::OverflowX, PropertyID::OverflowY },
|
{ PropertyID::OverflowX, PropertyID::OverflowY },
|
||||||
{ maybe_x_value.release_nonnull(), maybe_y_value.release_nonnull() });
|
{ maybe_x_value.release_nonnull(), maybe_y_value.release_nonnull() });
|
||||||
}
|
}
|
||||||
|
return ShorthandStyleValue::create(PropertyID::Overflow,
|
||||||
return nullptr;
|
{ PropertyID::OverflowX, PropertyID::OverflowY },
|
||||||
|
{ *maybe_x_value, *maybe_x_value });
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_place_content_value(Vector<ComponentValue> const& component_values)
|
RefPtr<StyleValue> Parser::parse_place_content_value(Vector<ComponentValue> const& component_values)
|
||||||
|
@ -5915,7 +5908,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
|
||||||
return parsed_value.release_nonnull();
|
return parsed_value.release_nonnull();
|
||||||
return ParseError::SyntaxError;
|
return ParseError::SyntaxError;
|
||||||
case PropertyID::Overflow:
|
case PropertyID::Overflow:
|
||||||
if (auto parsed_value = parse_overflow_value(component_values))
|
if (auto parsed_value = parse_overflow_value(tokens); parsed_value && !tokens.has_next_token())
|
||||||
return parsed_value.release_nonnull();
|
return parsed_value.release_nonnull();
|
||||||
return ParseError::SyntaxError;
|
return ParseError::SyntaxError;
|
||||||
case PropertyID::PlaceContent:
|
case PropertyID::PlaceContent:
|
||||||
|
|
|
@ -242,7 +242,7 @@ private:
|
||||||
RefPtr<StyleValue> parse_font_family_value(TokenStream<ComponentValue>&);
|
RefPtr<StyleValue> parse_font_family_value(TokenStream<ComponentValue>&);
|
||||||
RefPtr<StyleValue> parse_list_style_value(TokenStream<ComponentValue>&);
|
RefPtr<StyleValue> parse_list_style_value(TokenStream<ComponentValue>&);
|
||||||
RefPtr<StyleValue> parse_math_depth_value(TokenStream<ComponentValue>&);
|
RefPtr<StyleValue> parse_math_depth_value(TokenStream<ComponentValue>&);
|
||||||
RefPtr<StyleValue> parse_overflow_value(Vector<ComponentValue> const&);
|
RefPtr<StyleValue> parse_overflow_value(TokenStream<ComponentValue>&);
|
||||||
RefPtr<StyleValue> parse_place_content_value(Vector<ComponentValue> const&);
|
RefPtr<StyleValue> parse_place_content_value(Vector<ComponentValue> const&);
|
||||||
RefPtr<StyleValue> parse_place_items_value(Vector<ComponentValue> const&);
|
RefPtr<StyleValue> parse_place_items_value(Vector<ComponentValue> const&);
|
||||||
RefPtr<StyleValue> parse_place_self_value(Vector<ComponentValue> const&);
|
RefPtr<StyleValue> parse_place_self_value(Vector<ComponentValue> const&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue