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

LibWeb: Parse place-self property using TokenStream

This commit is contained in:
Sam Atkins 2023-12-08 17:26:19 +00:00 committed by Sam Atkins
parent 5a8f57f7b3
commit 513dee04d4
2 changed files with 7 additions and 5 deletions

View file

@ -4560,16 +4560,17 @@ RefPtr<StyleValue> Parser::parse_place_items_value(TokenStream<ComponentValue>&
{ *maybe_align_items_value, *maybe_justify_items_value });
}
RefPtr<StyleValue> Parser::parse_place_self_value(Vector<ComponentValue> const& component_values)
RefPtr<StyleValue> Parser::parse_place_self_value(TokenStream<ComponentValue>& tokens)
{
auto tokens = TokenStream { component_values };
auto transaction = tokens.begin_transaction();
auto maybe_align_self_value = parse_css_value_for_property(PropertyID::AlignSelf, tokens);
if (!maybe_align_self_value)
return nullptr;
if (component_values.size() == 1) {
if (!tokens.has_next_token()) {
if (!property_accepts_identifier(PropertyID::JustifySelf, maybe_align_self_value->to_identifier()))
return nullptr;
transaction.commit();
return ShorthandStyleValue::create(PropertyID::PlaceSelf,
{ PropertyID::AlignSelf, PropertyID::JustifySelf },
{ *maybe_align_self_value, *maybe_align_self_value });
@ -4578,6 +4579,7 @@ RefPtr<StyleValue> Parser::parse_place_self_value(Vector<ComponentValue> const&
auto maybe_justify_self_value = parse_css_value_for_property(PropertyID::JustifySelf, tokens);
if (!maybe_justify_self_value)
return nullptr;
transaction.commit();
return ShorthandStyleValue::create(PropertyID::PlaceSelf,
{ PropertyID::AlignSelf, PropertyID::JustifySelf },
{ *maybe_align_self_value, *maybe_justify_self_value });
@ -5921,7 +5923,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::PlaceSelf:
if (auto parsed_value = parse_place_self_value(component_values))
if (auto parsed_value = parse_place_self_value(tokens); parsed_value && !tokens.has_next_token())
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::Quotes:

View file

@ -245,7 +245,7 @@ private:
RefPtr<StyleValue> parse_overflow_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_place_content_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_place_items_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_place_self_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_place_self_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_quotes_value(TokenStream<ComponentValue>&);
enum class AllowInsetKeyword {
No,