diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-07-01 16:49:33 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 23:19:56 +0200 |
commit | 06cd41877025caddf9154d33a70f8e7b8f63bbc3 (patch) | |
tree | 0cda1e454f72f1cb3e02461f8fd8dab2c80e2ade /Userland/Libraries/LibWeb/CSS | |
parent | f690259a4224d894a0b22aeabcd36ddfb5117b6b (diff) | |
download | serenity-06cd41877025caddf9154d33a70f8e7b8f63bbc3.zip |
LibWeb: Convert QualifiedStyleRule to a RefPtr type in new Parser
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
5 files changed, 28 insertions, 26 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.h b/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.h index de37a23cc5..30a64bc081 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.h @@ -15,7 +15,7 @@ class DeclarationOrAtRule { friend class Parser; public: - explicit DeclarationOrAtRule(AtStyleRule at); + explicit DeclarationOrAtRule(RefPtr<AtStyleRule> at); explicit DeclarationOrAtRule(StyleDeclarationRule declaration); ~DeclarationOrAtRule(); @@ -28,7 +28,7 @@ public: private: DeclarationType m_type; - AtStyleRule m_at; + RefPtr<AtStyleRule> m_at; StyleDeclarationRule m_declaration; }; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index fb28936bdc..c4453cfed5 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -5,6 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/NonnullRefPtrVector.h> #include <AK/SourceLocation.h> #include <LibWeb/CSS/Parser/AtStyleRule.h> #include <LibWeb/CSS/Parser/DeclarationOrAtRule.h> @@ -62,7 +63,7 @@ Token Parser::current_token() return m_tokens.at(m_iterator_offset); } -Vector<QualifiedStyleRule> Parser::parse_as_stylesheet() +NonnullRefPtrVector<QualifiedStyleRule> Parser::parse_as_stylesheet() { auto rules = consume_a_list_of_rules(true); @@ -390,9 +391,9 @@ bool Parser::is_combinator(String input) return input == ">" || input == "+" || input == "~" || input == "||"; } -Vector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top_level) +NonnullRefPtrVector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top_level) { - Vector<QualifiedStyleRule> rules; + NonnullRefPtrVector<QualifiedStyleRule> rules; for (;;) { auto token = next_token(); @@ -412,8 +413,8 @@ Vector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top_level) reconsume_current_input_token(); auto maybe_qualified = consume_a_qualified_rule(); - if (maybe_qualified.has_value()) { - rules.append(maybe_qualified.value()); + if (maybe_qualified) { + rules.append(maybe_qualified.release_nonnull()); } continue; @@ -427,15 +428,15 @@ Vector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top_level) reconsume_current_input_token(); auto maybe_qualified = consume_a_qualified_rule(); - if (maybe_qualified.has_value()) { - rules.append(maybe_qualified.value()); + if (maybe_qualified) { + rules.append(maybe_qualified.release_nonnull()); } } return rules; } -AtStyleRule Parser::consume_an_at_rule() +NonnullRefPtr<AtStyleRule> Parser::consume_an_at_rule() { auto initial = next_token(); @@ -466,9 +467,9 @@ AtStyleRule Parser::consume_an_at_rule() } } -Optional<QualifiedStyleRule> Parser::consume_a_qualified_rule() +RefPtr<QualifiedStyleRule> Parser::consume_a_qualified_rule() { - QualifiedStyleRule rule; + NonnullRefPtr<QualifiedStyleRule> rule = create<QualifiedStyleRule>(); for (;;) { auto token = next_token(); @@ -479,7 +480,7 @@ Optional<QualifiedStyleRule> Parser::consume_a_qualified_rule() } if (token.is_open_curly()) { - rule.m_block = consume_a_simple_block(); + rule->m_block = consume_a_simple_block(); return rule; } @@ -487,7 +488,7 @@ Optional<QualifiedStyleRule> Parser::consume_a_qualified_rule() reconsume_current_input_token(); auto value = consume_a_component_value(); - rule.m_prelude.append(value); + rule->m_prelude.append(value); } return rule; @@ -690,9 +691,9 @@ Vector<DeclarationOrAtRule> Parser::consume_a_list_of_declarations() return list; } -Optional<QualifiedStyleRule> Parser::parse_as_rule() +RefPtr<QualifiedStyleRule> Parser::parse_as_rule() { - Optional<QualifiedStyleRule> rule; + RefPtr<QualifiedStyleRule> rule; for (;;) { auto maybe_whitespace = peek_token(); @@ -730,7 +731,7 @@ Optional<QualifiedStyleRule> Parser::parse_as_rule() return {}; } -Vector<QualifiedStyleRule> Parser::parse_as_list_of_rules() +NonnullRefPtrVector<QualifiedStyleRule> Parser::parse_as_list_of_rules() { return consume_a_list_of_rules(false); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 10e7d433ae..6686f22c0f 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -27,11 +27,11 @@ public: ~Parser(); // The normal parser entry point, for parsing stylesheets. - Vector<QualifiedStyleRule> parse_as_stylesheet(); + NonnullRefPtrVector<QualifiedStyleRule> parse_as_stylesheet(); // For the content of at-rules such as @media. It differs from "Parse a stylesheet" in the handling of <CDO-token> and <CDC-token>. - Vector<QualifiedStyleRule> parse_as_list_of_rules(); + NonnullRefPtrVector<QualifiedStyleRule> parse_as_list_of_rules(); // For use by the CSSStyleSheet#insertRule method, and similar functions which might exist, which parse text into a single rule. - Optional<QualifiedStyleRule> parse_as_rule(); + RefPtr<QualifiedStyleRule> parse_as_rule(); // Used in @supports conditions. [CSS3-CONDITIONAL] Optional<StyleDeclarationRule> parse_as_declaration(); // For the contents of a style attribute, which parses text into the contents of a single style rule. @@ -71,9 +71,9 @@ private: void reconsume_current_input_token(); bool is_combinator(String); - Vector<QualifiedStyleRule> consume_a_list_of_rules(bool top_level); - AtStyleRule consume_an_at_rule(); - Optional<QualifiedStyleRule> consume_a_qualified_rule(); + NonnullRefPtrVector<QualifiedStyleRule> consume_a_list_of_rules(bool top_level); + NonnullRefPtr<AtStyleRule> consume_an_at_rule(); + RefPtr<QualifiedStyleRule> consume_a_qualified_rule(); Vector<DeclarationOrAtRule> consume_a_list_of_declarations(); Optional<StyleDeclarationRule> consume_a_declaration(Vector<StyleComponentValueRule>); Optional<StyleDeclarationRule> consume_a_declaration(); diff --git a/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h b/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h index 81e6b61533..87ccc2840d 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h @@ -7,13 +7,14 @@ #pragma once +#include <AK/RefCounted.h> #include <AK/Vector.h> #include <LibWeb/CSS/Parser/StyleBlockRule.h> #include <LibWeb/CSS/Parser/StyleComponentValueRule.h> namespace Web::CSS { -class QualifiedStyleRule { +class QualifiedStyleRule : public RefCounted<QualifiedStyleRule> { friend class Parser; public: diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp index 7080e21466..790d75e0cc 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp @@ -18,7 +18,7 @@ namespace Web::CSS { AtStyleRule::AtStyleRule() { } AtStyleRule::~AtStyleRule() { } -DeclarationOrAtRule::DeclarationOrAtRule(AtStyleRule at) +DeclarationOrAtRule::DeclarationOrAtRule(RefPtr<AtStyleRule> at) : m_type(DeclarationType::At) , m_at(move(at)) { @@ -94,7 +94,7 @@ String DeclarationOrAtRule::to_string() const switch (m_type) { default: case DeclarationType::At: - builder.append(m_at.to_string()); + builder.append(m_at->to_string()); break; case DeclarationType::Declaration: builder.append(m_declaration.to_string()); |