mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
LibWeb/CSS: Combine the CSSRuleList constructors
This commit is contained in:
parent
3d1665cc80
commit
9465492edf
Notes:
github-actions[bot]
2025-04-23 10:40:08 +00:00
Author: https://github.com/AtkinsSJ
Commit: 9465492edf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4354
7 changed files with 19 additions and 25 deletions
|
@ -45,7 +45,7 @@ GC::Ref<JS::Realm> internal_css_realm()
|
|||
GC::Ref<CSS::CSSStyleSheet> parse_css_stylesheet(CSS::Parser::ParsingParams const& context, StringView css, Optional<::URL::URL> location, Vector<NonnullRefPtr<CSS::MediaQuery>> media_query_list)
|
||||
{
|
||||
if (css.is_empty()) {
|
||||
auto rule_list = CSS::CSSRuleList::create_empty(*context.realm);
|
||||
auto rule_list = CSS::CSSRuleList::create(*context.realm);
|
||||
auto media_list = CSS::MediaList::create(*context.realm, {});
|
||||
auto style_sheet = CSS::CSSStyleSheet::create(*context.realm, rule_list, media_list, location);
|
||||
style_sheet->set_source_text({});
|
||||
|
|
|
@ -497,12 +497,12 @@ GC::Ptr<CSSMediaRule> Parser::convert_to_media_rule(AtRule const& rule, Nested n
|
|||
auto media_query_list = parse_a_media_query_list(media_query_tokens);
|
||||
auto media_list = MediaList::create(realm(), move(media_query_list));
|
||||
|
||||
GC::RootVector<CSSRule*> child_rules { realm().heap() };
|
||||
GC::RootVector<GC::Ref<CSSRule>> child_rules { realm().heap() };
|
||||
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);
|
||||
child_rules.append(*child_rule);
|
||||
},
|
||||
[&](Vector<Declaration> const& declarations) {
|
||||
child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations)));
|
||||
|
|
|
@ -141,7 +141,7 @@ GC::Ref<CSS::CSSStyleSheet> Parser::parse_as_css_stylesheet(Optional<::URL::URL>
|
|||
auto const& style_sheet = parse_a_stylesheet(m_token_stream, location);
|
||||
|
||||
// Interpret all of the resulting top-level qualified rules as style rules, defined below.
|
||||
GC::RootVector<CSSRule*> rules(realm().heap());
|
||||
GC::RootVector<GC::Ref<CSSRule>> rules(realm().heap());
|
||||
for (auto const& raw_rule : style_sheet.rules) {
|
||||
auto rule = convert_to_rule(raw_rule, Nested::No);
|
||||
// If any style rule is invalid, or any at-rule is not recognized or is invalid according to its grammar or context, it’s a parse error.
|
||||
|
@ -150,7 +150,7 @@ GC::Ref<CSS::CSSStyleSheet> Parser::parse_as_css_stylesheet(Optional<::URL::URL>
|
|||
log_parse_error();
|
||||
continue;
|
||||
}
|
||||
rules.append(rule);
|
||||
rules.append(*rule);
|
||||
}
|
||||
|
||||
auto rule_list = CSSRuleList::create(realm(), rules);
|
||||
|
|
|
@ -107,7 +107,7 @@ GC::Ptr<CSSStyleRule> Parser::convert_to_style_rule(QualifiedRule const& qualifi
|
|||
|
||||
auto declaration = convert_to_style_declaration(qualified_rule.declarations);
|
||||
|
||||
GC::RootVector<CSSRule*> child_rules { realm().heap() };
|
||||
GC::RootVector<GC::Ref<CSSRule>> child_rules { realm().heap() };
|
||||
for (auto& child : qualified_rule.child_rules) {
|
||||
child.visit(
|
||||
[&](Rule const& rule) {
|
||||
|
@ -116,7 +116,7 @@ GC::Ptr<CSSStyleRule> Parser::convert_to_style_rule(QualifiedRule const& qualifi
|
|||
// https://drafts.csswg.org/css-nesting-1/#nested-group-rules
|
||||
if (auto converted_rule = convert_to_rule(rule, Nested::Yes)) {
|
||||
if (is<CSSGroupingRule>(*converted_rule)) {
|
||||
child_rules.append(converted_rule);
|
||||
child_rules.append(*converted_rule);
|
||||
} else {
|
||||
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested {} is not allowed inside style rule; discarding.", converted_rule->class_name());
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ GC::Ptr<CSSStyleRule> Parser::convert_to_style_rule(QualifiedRule const& qualifi
|
|||
child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations)));
|
||||
});
|
||||
}
|
||||
auto nested_rules = CSSRuleList::create(realm(), move(child_rules));
|
||||
auto nested_rules = CSSRuleList::create(realm(), child_rules);
|
||||
return CSSStyleRule::create(realm(), move(selectors), *declaration, *nested_rules);
|
||||
}
|
||||
|
||||
|
@ -260,12 +260,12 @@ GC::Ptr<CSSRule> Parser::convert_to_layer_rule(AtRule const& rule, Nested nested
|
|||
}
|
||||
|
||||
// Then the rules
|
||||
GC::RootVector<CSSRule*> child_rules { realm().heap() };
|
||||
GC::RootVector<GC::Ref<CSSRule>> child_rules { realm().heap() };
|
||||
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);
|
||||
child_rules.append(*child_rule);
|
||||
},
|
||||
[&](Vector<Declaration> const& declarations) {
|
||||
child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations)));
|
||||
|
@ -350,7 +350,7 @@ GC::Ptr<CSSKeyframesRule> Parser::convert_to_keyframes_rule(AtRule const& rule)
|
|||
|
||||
auto name = name_token.to_string();
|
||||
|
||||
GC::RootVector<CSSRule*> keyframes(realm().heap());
|
||||
GC::RootVector<GC::Ref<CSSRule>> keyframes(realm().heap());
|
||||
rule.for_each_as_qualified_rule_list([&](auto& qualified_rule) {
|
||||
if (!qualified_rule.child_rules.is_empty()) {
|
||||
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @keyframes keyframe rule contains at-rules; discarding them.");
|
||||
|
@ -405,7 +405,7 @@ GC::Ptr<CSSKeyframesRule> Parser::convert_to_keyframes_rule(AtRule const& rule)
|
|||
}
|
||||
});
|
||||
|
||||
return CSSKeyframesRule::create(realm(), name, CSSRuleList::create(realm(), move(keyframes)));
|
||||
return CSSKeyframesRule::create(realm(), name, CSSRuleList::create(realm(), keyframes));
|
||||
}
|
||||
|
||||
GC::Ptr<CSSNamespaceRule> Parser::convert_to_namespace_rule(AtRule const& rule)
|
||||
|
@ -480,12 +480,12 @@ GC::Ptr<CSSSupportsRule> Parser::convert_to_supports_rule(AtRule const& rule, Ne
|
|||
return {};
|
||||
}
|
||||
|
||||
GC::RootVector<CSSRule*> child_rules { realm().heap() };
|
||||
GC::RootVector<GC::Ref<CSSRule>> child_rules { realm().heap() };
|
||||
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);
|
||||
child_rules.append(*child_rule);
|
||||
},
|
||||
[&](Vector<Declaration> const& declarations) {
|
||||
child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue