mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-05 01:10:24 +00:00
LibWeb/CSS: Pull out Supports::Declaration parsing
Avoid repeating this in two places.
This commit is contained in:
Notes:
github-actions[bot]
2025-12-02 09:51:11 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/faba11f33c0 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6986
@@ -335,14 +335,9 @@ OwnPtr<BooleanExpression> Parser::parse_supports_feature(TokenStream<ComponentVa
|
||||
// `<supports-decl> = ( <declaration> )`
|
||||
if (first_token.is_block() && first_token.block().is_paren()) {
|
||||
TokenStream block_tokens { first_token.block().value };
|
||||
// FIXME: Parsing and then converting back to a string is weird.
|
||||
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value() && !block_tokens.has_next_token()) {
|
||||
if (auto declaration = parse_supports_declaration(block_tokens)) {
|
||||
transaction.commit();
|
||||
auto supports_declaration = Supports::Declaration::create(
|
||||
declaration->to_string(),
|
||||
convert_to_style_property(*declaration).has_value());
|
||||
|
||||
return BooleanExpressionInParens::create(supports_declaration.release_nonnull<BooleanExpression>());
|
||||
return BooleanExpressionInParens::create(declaration.release_nonnull<BooleanExpression>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,6 +391,23 @@ OwnPtr<BooleanExpression> Parser::parse_supports_feature(TokenStream<ComponentVa
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-conditional-5/#typedef-supports-decl
|
||||
OwnPtr<Supports::Declaration> Parser::parse_supports_declaration(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
// `<supports-decl> = ( <declaration> )`
|
||||
// NB: Here, we only care about the <declaration> part.
|
||||
auto transaction = tokens.begin_transaction();
|
||||
tokens.discard_whitespace();
|
||||
if (auto declaration = consume_a_declaration(tokens); declaration.has_value()) {
|
||||
tokens.discard_whitespace();
|
||||
if (!tokens.has_next_token()) {
|
||||
transaction.commit();
|
||||
return Supports::Declaration::create(declaration->to_string(), convert_to_style_property(*declaration).has_value());
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/mediaqueries-4/#typedef-general-enclosed
|
||||
OwnPtr<GeneralEnclosed> Parser::parse_general_enclosed(TokenStream<ComponentValue>& tokens, MatchResult result)
|
||||
{
|
||||
|
||||
@@ -564,6 +564,7 @@ private:
|
||||
OwnPtr<BooleanExpression> parse_boolean_expression_group(TokenStream<ComponentValue>&, MatchResult result_for_general_enclosed, ParseTest parse_test);
|
||||
|
||||
OwnPtr<BooleanExpression> parse_supports_feature(TokenStream<ComponentValue>&);
|
||||
OwnPtr<Supports::Declaration> parse_supports_declaration(TokenStream<ComponentValue>&);
|
||||
|
||||
NonnullRefPtr<StyleValue const> resolve_unresolved_style_value(DOM::AbstractElement, GuardedSubstitutionContexts&, PropertyNameAndID const&, UnresolvedStyleValue const&);
|
||||
|
||||
|
||||
@@ -245,12 +245,10 @@ GC::Ptr<CSSImportRule> Parser::convert_to_import_rule(AtRule const& rule)
|
||||
supports = parse_a_supports(supports_tokens);
|
||||
if (!supports) {
|
||||
m_rule_context.append(RuleContext::SupportsCondition);
|
||||
auto declaration = consume_a_declaration(supports_tokens);
|
||||
auto supports_declaration = parse_supports_declaration(supports_tokens);
|
||||
m_rule_context.take_last();
|
||||
if (declaration.has_value()) {
|
||||
auto supports_declaration = Supports::Declaration::create(declaration->to_string(), convert_to_style_property(*declaration).has_value());
|
||||
if (supports_declaration)
|
||||
supports = Supports::create(supports_declaration.release_nonnull<BooleanExpression>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user