mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +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> )`
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue