mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-25 18:58:56 +00:00
LibWeb/CSS: Accept nested style rules in grouping at-rules
When converting an AtRule to a grouping rule, allow both style rules, and lists of declarations.
This commit is contained in:
parent
ce947ff983
commit
6bb1ffbcd3
Notes:
github-actions[bot]
2024-11-07 14:12:36 +00:00
Author: https://github.com/AtkinsSJ
Commit: 6bb1ffbcd3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2202
3 changed files with 53 additions and 14 deletions
|
@ -189,13 +189,18 @@ bool CSSRuleList::evaluate_media_queries(HTML::Window const& window)
|
||||||
any_media_queries_changed_match_state = true;
|
any_media_queries_changed_match_state = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CSSRule::Type::Style: {
|
||||||
|
auto& style_rule = verify_cast<CSSStyleRule>(*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::FontFace:
|
||||||
case CSSRule::Type::Keyframe:
|
case CSSRule::Type::Keyframe:
|
||||||
case CSSRule::Type::Keyframes:
|
case CSSRule::Type::Keyframes:
|
||||||
case CSSRule::Type::LayerStatement:
|
case CSSRule::Type::LayerStatement:
|
||||||
case CSSRule::Type::Namespace:
|
case CSSRule::Type::Namespace:
|
||||||
case CSSRule::Type::NestedDeclarations:
|
case CSSRule::Type::NestedDeclarations:
|
||||||
case CSSRule::Type::Style:
|
|
||||||
case CSSRule::Type::Property:
|
case CSSRule::Type::Property:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
||||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||||
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
* Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org>
|
||||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||||
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
|
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
|
||||||
*
|
*
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <LibWeb/CSS/CSSMediaRule.h>
|
#include <LibWeb/CSS/CSSMediaRule.h>
|
||||||
|
#include <LibWeb/CSS/CSSNestedDeclarations.h>
|
||||||
#include <LibWeb/CSS/CalculatedOr.h>
|
#include <LibWeb/CSS/CalculatedOr.h>
|
||||||
#include <LibWeb/CSS/MediaList.h>
|
#include <LibWeb/CSS/MediaList.h>
|
||||||
#include <LibWeb/CSS/MediaQuery.h>
|
#include <LibWeb/CSS/MediaQuery.h>
|
||||||
|
@ -627,10 +628,21 @@ JS::GCPtr<CSSMediaRule> Parser::convert_to_media_rule(AtRule const& rule, Nested
|
||||||
auto media_list = MediaList::create(m_context.realm(), move(media_query_list));
|
auto media_list = MediaList::create(m_context.realm(), move(media_query_list));
|
||||||
|
|
||||||
JS::MarkedVector<CSSRule*> child_rules { m_context.realm().heap() };
|
JS::MarkedVector<CSSRule*> child_rules { m_context.realm().heap() };
|
||||||
rule.for_each_as_rule_list([&](auto& rule) {
|
for (auto const& child : rule.child_rules_and_lists_of_declarations) {
|
||||||
if (auto child_rule = convert_to_rule(rule, nested))
|
child.visit(
|
||||||
child_rules.append(child_rule);
|
[&](Rule const& rule) {
|
||||||
});
|
if (auto child_rule = convert_to_rule(rule, nested))
|
||||||
|
child_rules.append(child_rule);
|
||||||
|
},
|
||||||
|
[&](Vector<Declaration> 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);
|
auto rule_list = CSSRuleList::create(m_context.realm(), child_rules);
|
||||||
return CSSMediaRule::create(m_context.realm(), media_list, rule_list);
|
return CSSMediaRule::create(m_context.realm(), media_list, rule_list);
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,10 +278,21 @@ JS::GCPtr<CSSRule> Parser::convert_to_layer_rule(AtRule const& rule, Nested nest
|
||||||
|
|
||||||
// Then the rules
|
// Then the rules
|
||||||
JS::MarkedVector<CSSRule*> child_rules { m_context.realm().heap() };
|
JS::MarkedVector<CSSRule*> child_rules { m_context.realm().heap() };
|
||||||
rule.for_each_as_rule_list([&](auto& rule) {
|
for (auto const& child : rule.child_rules_and_lists_of_declarations) {
|
||||||
if (auto child_rule = convert_to_rule(rule, nested))
|
child.visit(
|
||||||
child_rules.append(child_rule);
|
[&](Rule const& rule) {
|
||||||
});
|
if (auto child_rule = convert_to_rule(rule, nested))
|
||||||
|
child_rules.append(child_rule);
|
||||||
|
},
|
||||||
|
[&](Vector<Declaration> 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);
|
auto rule_list = CSSRuleList::create(m_context.realm(), child_rules);
|
||||||
return CSSLayerBlockRule::create(m_context.realm(), layer_name, rule_list);
|
return CSSLayerBlockRule::create(m_context.realm(), layer_name, rule_list);
|
||||||
}
|
}
|
||||||
|
@ -489,10 +500,21 @@ JS::GCPtr<CSSSupportsRule> Parser::convert_to_supports_rule(AtRule const& rule,
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::MarkedVector<CSSRule*> child_rules { m_context.realm().heap() };
|
JS::MarkedVector<CSSRule*> child_rules { m_context.realm().heap() };
|
||||||
rule.for_each_as_rule_list([&](auto& rule) {
|
for (auto const& child : rule.child_rules_and_lists_of_declarations) {
|
||||||
if (auto child_rule = convert_to_rule(rule, nested))
|
child.visit(
|
||||||
child_rules.append(child_rule);
|
[&](Rule const& rule) {
|
||||||
});
|
if (auto child_rule = convert_to_rule(rule, nested))
|
||||||
|
child_rules.append(child_rule);
|
||||||
|
},
|
||||||
|
[&](Vector<Declaration> 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);
|
auto rule_list = CSSRuleList::create(m_context.realm(), child_rules);
|
||||||
return CSSSupportsRule::create(m_context.realm(), supports.release_nonnull(), rule_list);
|
return CSSSupportsRule::create(m_context.realm(), supports.release_nonnull(), rule_list);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue