From c7cd4896890a92d4b4746abb9fb1660d0950b915 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 29 Sep 2021 15:51:22 +0100 Subject: LibWeb: Parse `@media` rules into CSSMediaRule objects This is not yet actually useful, since we only have a stub for parsing the query part, but now I have a nice way to test that things are working. :^) --- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Userland') diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 3f8a182783..39be9f7d04 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -1242,6 +1243,21 @@ RefPtr Parser::convert_to_rule(NonnullRefPtr rule) if (rule->m_type == StyleRule::Type::At) { if (has_ignored_vendor_prefix(rule->m_name)) { return {}; + } else if (rule->m_name.equals_ignoring_case("media"sv)) { + + auto media_query_tokens = TokenStream { rule->prelude() }; + auto media_query_list = parse_a_media_query_list(media_query_tokens); + + auto child_tokens = TokenStream { rule->block().values() }; + auto parser_rules = consume_a_list_of_rules(child_tokens, false); + NonnullRefPtrVector child_rules; + for (auto& raw_rule : parser_rules) { + if (auto child_rule = convert_to_rule(raw_rule)) + child_rules.append(*child_rule); + } + + return CSSMediaRule::create(MediaList::create(move(media_query_list)), move(child_rules)); + } else if (rule->m_name.equals_ignoring_case("import"sv) && !rule->prelude().is_empty()) { Optional url; -- cgit v1.2.3