diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-09-29 15:51:22 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-01 20:03:03 +0200 |
commit | c7cd4896890a92d4b4746abb9fb1660d0950b915 (patch) | |
tree | 84c573dc412e10b743ab6fb3b9b5a7f886d67b9d /Userland | |
parent | b4833bf2a338359b7ea349b0826165fdc849a7b4 (diff) | |
download | serenity-c7cd4896890a92d4b4746abb9fb1660d0950b915.zip |
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. :^)
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
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 <AK/Debug.h> #include <AK/NonnullRefPtrVector.h> #include <AK/SourceLocation.h> +#include <LibWeb/CSS/CSSMediaRule.h> #include <LibWeb/CSS/CSSStyleDeclaration.h> #include <LibWeb/CSS/CSSStyleRule.h> #include <LibWeb/CSS/CSSStyleSheet.h> @@ -1242,6 +1243,21 @@ RefPtr<CSSRule> Parser::convert_to_rule(NonnullRefPtr<StyleRule> 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<CSSRule> 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<AK::URL> url; |