mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb/CSS: Pull out Supports::Declaration parsing
Avoid repeating this in two places.
This commit is contained in:
parent
4ed1c56267
commit
faba11f33c
Notes:
github-actions[bot]
2025-12-02 09:51:11 +00:00
Author: https://github.com/AtkinsSJ
Commit: faba11f33c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6986
3 changed files with 22 additions and 11 deletions
|
|
@ -335,14 +335,9 @@ OwnPtr<BooleanExpression> Parser::parse_supports_feature(TokenStream<ComponentVa
|
||||||
// `<supports-decl> = ( <declaration> )`
|
// `<supports-decl> = ( <declaration> )`
|
||||||
if (first_token.is_block() && first_token.block().is_paren()) {
|
if (first_token.is_block() && first_token.block().is_paren()) {
|
||||||
TokenStream block_tokens { first_token.block().value };
|
TokenStream block_tokens { first_token.block().value };
|
||||||
// FIXME: Parsing and then converting back to a string is weird.
|
if (auto declaration = parse_supports_declaration(block_tokens)) {
|
||||||
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value() && !block_tokens.has_next_token()) {
|
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
auto supports_declaration = Supports::Declaration::create(
|
return BooleanExpressionInParens::create(declaration.release_nonnull<BooleanExpression>());
|
||||||
declaration->to_string(),
|
|
||||||
convert_to_style_property(*declaration).has_value());
|
|
||||||
|
|
||||||
return BooleanExpressionInParens::create(supports_declaration.release_nonnull<BooleanExpression>());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -396,6 +391,23 @@ OwnPtr<BooleanExpression> Parser::parse_supports_feature(TokenStream<ComponentVa
|
||||||
return {};
|
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
|
// https://www.w3.org/TR/mediaqueries-4/#typedef-general-enclosed
|
||||||
OwnPtr<GeneralEnclosed> Parser::parse_general_enclosed(TokenStream<ComponentValue>& tokens, MatchResult result)
|
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_boolean_expression_group(TokenStream<ComponentValue>&, MatchResult result_for_general_enclosed, ParseTest parse_test);
|
||||||
|
|
||||||
OwnPtr<BooleanExpression> parse_supports_feature(TokenStream<ComponentValue>&);
|
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&);
|
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);
|
supports = parse_a_supports(supports_tokens);
|
||||||
if (!supports) {
|
if (!supports) {
|
||||||
m_rule_context.append(RuleContext::SupportsCondition);
|
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();
|
m_rule_context.take_last();
|
||||||
if (declaration.has_value()) {
|
if (supports_declaration)
|
||||||
auto supports_declaration = Supports::Declaration::create(declaration->to_string(), convert_to_style_property(*declaration).has_value());
|
|
||||||
supports = Supports::create(supports_declaration.release_nonnull<BooleanExpression>());
|
supports = Supports::create(supports_declaration.release_nonnull<BooleanExpression>());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue