diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp index e9a62093384..11ea56e41a0 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -189,13 +189,18 @@ bool CSSRuleList::evaluate_media_queries(HTML::Window const& window) any_media_queries_changed_match_state = true; break; } + case CSSRule::Type::Style: { + auto& style_rule = verify_cast(*rule); + if (style_rule.css_rules().evaluate_media_queries(window)) + any_media_queries_changed_match_state = true; + break; + } case CSSRule::Type::FontFace: case CSSRule::Type::Keyframe: case CSSRule::Type::Keyframes: case CSSRule::Type::LayerStatement: case CSSRule::Type::Namespace: case CSSRule::Type::NestedDeclarations: - case CSSRule::Type::Style: case CSSRule::Type::Property: break; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp b/Userland/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp index c0a89286e4c..8492fba460f 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp @@ -1,7 +1,7 @@ /* * Copyright (c) 2018-2022, Andreas Kling * Copyright (c) 2020-2021, the SerenityOS developers. - * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2021-2024, Sam Atkins * Copyright (c) 2021, Tobias Christiansen * Copyright (c) 2022, MacDue * @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -627,10 +628,21 @@ JS::GCPtr Parser::convert_to_media_rule(AtRule const& rule, Nested auto media_list = MediaList::create(m_context.realm(), move(media_query_list)); JS::MarkedVector child_rules { m_context.realm().heap() }; - rule.for_each_as_rule_list([&](auto& rule) { - if (auto child_rule = convert_to_rule(rule, nested)) - child_rules.append(child_rule); - }); + for (auto const& child : rule.child_rules_and_lists_of_declarations) { + child.visit( + [&](Rule const& rule) { + if (auto child_rule = convert_to_rule(rule, nested)) + child_rules.append(child_rule); + }, + [&](Vector const& declarations) { + auto* declaration = convert_to_style_declaration(declarations); + if (!declaration) { + dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); + return; + } + child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration)); + }); + } auto rule_list = CSSRuleList::create(m_context.realm(), child_rules); return CSSMediaRule::create(m_context.realm(), media_list, rule_list); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp b/Userland/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp index 18ba3a17c73..b36b13c2853 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp @@ -278,10 +278,21 @@ JS::GCPtr Parser::convert_to_layer_rule(AtRule const& rule, Nested nest // Then the rules JS::MarkedVector child_rules { m_context.realm().heap() }; - rule.for_each_as_rule_list([&](auto& rule) { - if (auto child_rule = convert_to_rule(rule, nested)) - child_rules.append(child_rule); - }); + for (auto const& child : rule.child_rules_and_lists_of_declarations) { + child.visit( + [&](Rule const& rule) { + if (auto child_rule = convert_to_rule(rule, nested)) + child_rules.append(child_rule); + }, + [&](Vector const& declarations) { + auto* declaration = convert_to_style_declaration(declarations); + if (!declaration) { + dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); + return; + } + child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration)); + }); + } auto rule_list = CSSRuleList::create(m_context.realm(), child_rules); return CSSLayerBlockRule::create(m_context.realm(), layer_name, rule_list); } @@ -489,10 +500,21 @@ JS::GCPtr Parser::convert_to_supports_rule(AtRule const& rule, } JS::MarkedVector child_rules { m_context.realm().heap() }; - rule.for_each_as_rule_list([&](auto& rule) { - if (auto child_rule = convert_to_rule(rule, nested)) - child_rules.append(child_rule); - }); + for (auto const& child : rule.child_rules_and_lists_of_declarations) { + child.visit( + [&](Rule const& rule) { + if (auto child_rule = convert_to_rule(rule, nested)) + child_rules.append(child_rule); + }, + [&](Vector const& declarations) { + auto* declaration = convert_to_style_declaration(declarations); + if (!declaration) { + dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); + return; + } + child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration)); + }); + } auto rule_list = CSSRuleList::create(m_context.realm(), child_rules); return CSSSupportsRule::create(m_context.realm(), supports.release_nonnull(), rule_list);