From e76026372844004bc0d6a5876363093d272d4c7f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 22 Nov 2021 17:27:09 +0000 Subject: [PATCH] LibWeb: Parse CSS `` --- .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 22 ++++++++++++++++--- Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 6 ++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 6248325a0f..d56ad35bd2 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1111,10 +1111,26 @@ Optional Parser::parse_supports_feature(TokenStream -Optional Parser::parse_general_enclosed(TokenStream&) +// https://www.w3.org/TR/mediaqueries-4/#typedef-general-enclosed +Optional Parser::parse_general_enclosed(TokenStream& tokens) { - // FIXME: Actually parse this! https://www.w3.org/TR/mediaqueries-5/#typedef-general-enclosed + tokens.skip_whitespace(); + auto start_position = tokens.position(); + + auto& first_token = tokens.next_token(); + + // `[ ) ]` + if (first_token.is_function()) + return GeneralEnclosed { first_token.to_string() }; + + // `( )` + if (first_token.is_block() && first_token.block().is_paren()) { + auto& block = first_token.block(); + if (!block.values().is_empty() && block.values().first().is(Token::Type::Ident)) + return GeneralEnclosed { first_token.to_string() }; + } + + tokens.rewind_to_position(start_position); return {}; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 4f028b6053..191d5da917 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -170,10 +171,7 @@ private: template [[nodiscard]] NonnullRefPtr consume_a_function(TokenStream&); - struct GeneralEnclosed { - }; - template - [[nodiscard]] Optional parse_general_enclosed(TokenStream&); + [[nodiscard]] Optional parse_general_enclosed(TokenStream&); [[nodiscard]] RefPtr convert_to_rule(NonnullRefPtr); [[nodiscard]] RefPtr convert_to_declaration(NonnullRefPtr);