mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:17:45 +00:00
LibWeb: Convert QualifiedStyleRule to a RefPtr type in new Parser
This commit is contained in:
parent
f690259a42
commit
06cd418770
5 changed files with 28 additions and 26 deletions
|
@ -15,7 +15,7 @@ class DeclarationOrAtRule {
|
||||||
friend class Parser;
|
friend class Parser;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeclarationOrAtRule(AtStyleRule at);
|
explicit DeclarationOrAtRule(RefPtr<AtStyleRule> at);
|
||||||
explicit DeclarationOrAtRule(StyleDeclarationRule declaration);
|
explicit DeclarationOrAtRule(StyleDeclarationRule declaration);
|
||||||
~DeclarationOrAtRule();
|
~DeclarationOrAtRule();
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeclarationType m_type;
|
DeclarationType m_type;
|
||||||
AtStyleRule m_at;
|
RefPtr<AtStyleRule> m_at;
|
||||||
StyleDeclarationRule m_declaration;
|
StyleDeclarationRule m_declaration;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
#include <AK/SourceLocation.h>
|
#include <AK/SourceLocation.h>
|
||||||
#include <LibWeb/CSS/Parser/AtStyleRule.h>
|
#include <LibWeb/CSS/Parser/AtStyleRule.h>
|
||||||
#include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
|
#include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
|
||||||
|
@ -62,7 +63,7 @@ Token Parser::current_token()
|
||||||
return m_tokens.at(m_iterator_offset);
|
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);
|
auto rules = consume_a_list_of_rules(true);
|
||||||
|
|
||||||
|
@ -390,9 +391,9 @@ bool Parser::is_combinator(String input)
|
||||||
return input == ">" || input == "+" || input == "~" || 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 (;;) {
|
for (;;) {
|
||||||
auto token = next_token();
|
auto token = next_token();
|
||||||
|
@ -412,8 +413,8 @@ Vector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top_level)
|
||||||
|
|
||||||
reconsume_current_input_token();
|
reconsume_current_input_token();
|
||||||
auto maybe_qualified = consume_a_qualified_rule();
|
auto maybe_qualified = consume_a_qualified_rule();
|
||||||
if (maybe_qualified.has_value()) {
|
if (maybe_qualified) {
|
||||||
rules.append(maybe_qualified.value());
|
rules.append(maybe_qualified.release_nonnull());
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -427,15 +428,15 @@ Vector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top_level)
|
||||||
|
|
||||||
reconsume_current_input_token();
|
reconsume_current_input_token();
|
||||||
auto maybe_qualified = consume_a_qualified_rule();
|
auto maybe_qualified = consume_a_qualified_rule();
|
||||||
if (maybe_qualified.has_value()) {
|
if (maybe_qualified) {
|
||||||
rules.append(maybe_qualified.value());
|
rules.append(maybe_qualified.release_nonnull());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rules;
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
AtStyleRule Parser::consume_an_at_rule()
|
NonnullRefPtr<AtStyleRule> Parser::consume_an_at_rule()
|
||||||
{
|
{
|
||||||
auto initial = next_token();
|
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 (;;) {
|
for (;;) {
|
||||||
auto token = next_token();
|
auto token = next_token();
|
||||||
|
@ -479,7 +480,7 @@ Optional<QualifiedStyleRule> Parser::consume_a_qualified_rule()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token.is_open_curly()) {
|
if (token.is_open_curly()) {
|
||||||
rule.m_block = consume_a_simple_block();
|
rule->m_block = consume_a_simple_block();
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,7 +488,7 @@ Optional<QualifiedStyleRule> Parser::consume_a_qualified_rule()
|
||||||
|
|
||||||
reconsume_current_input_token();
|
reconsume_current_input_token();
|
||||||
auto value = consume_a_component_value();
|
auto value = consume_a_component_value();
|
||||||
rule.m_prelude.append(value);
|
rule->m_prelude.append(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rule;
|
return rule;
|
||||||
|
@ -690,9 +691,9 @@ Vector<DeclarationOrAtRule> Parser::consume_a_list_of_declarations()
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<QualifiedStyleRule> Parser::parse_as_rule()
|
RefPtr<QualifiedStyleRule> Parser::parse_as_rule()
|
||||||
{
|
{
|
||||||
Optional<QualifiedStyleRule> rule;
|
RefPtr<QualifiedStyleRule> rule;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto maybe_whitespace = peek_token();
|
auto maybe_whitespace = peek_token();
|
||||||
|
@ -730,7 +731,7 @@ Optional<QualifiedStyleRule> Parser::parse_as_rule()
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<QualifiedStyleRule> Parser::parse_as_list_of_rules()
|
NonnullRefPtrVector<QualifiedStyleRule> Parser::parse_as_list_of_rules()
|
||||||
{
|
{
|
||||||
return consume_a_list_of_rules(false);
|
return consume_a_list_of_rules(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,11 @@ public:
|
||||||
~Parser();
|
~Parser();
|
||||||
|
|
||||||
// The normal parser entry point, for parsing stylesheets.
|
// 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>.
|
// 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.
|
// 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]
|
// Used in @supports conditions. [CSS3-CONDITIONAL]
|
||||||
Optional<StyleDeclarationRule> parse_as_declaration();
|
Optional<StyleDeclarationRule> parse_as_declaration();
|
||||||
// For the contents of a style attribute, which parses text into the contents of a single style rule.
|
// 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();
|
void reconsume_current_input_token();
|
||||||
bool is_combinator(String);
|
bool is_combinator(String);
|
||||||
|
|
||||||
Vector<QualifiedStyleRule> consume_a_list_of_rules(bool top_level);
|
NonnullRefPtrVector<QualifiedStyleRule> consume_a_list_of_rules(bool top_level);
|
||||||
AtStyleRule consume_an_at_rule();
|
NonnullRefPtr<AtStyleRule> consume_an_at_rule();
|
||||||
Optional<QualifiedStyleRule> consume_a_qualified_rule();
|
RefPtr<QualifiedStyleRule> consume_a_qualified_rule();
|
||||||
Vector<DeclarationOrAtRule> consume_a_list_of_declarations();
|
Vector<DeclarationOrAtRule> consume_a_list_of_declarations();
|
||||||
Optional<StyleDeclarationRule> consume_a_declaration(Vector<StyleComponentValueRule>);
|
Optional<StyleDeclarationRule> consume_a_declaration(Vector<StyleComponentValueRule>);
|
||||||
Optional<StyleDeclarationRule> consume_a_declaration();
|
Optional<StyleDeclarationRule> consume_a_declaration();
|
||||||
|
|
|
@ -7,13 +7,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/RefCounted.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
|
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
|
||||||
#include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
|
#include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
class QualifiedStyleRule {
|
class QualifiedStyleRule : public RefCounted<QualifiedStyleRule> {
|
||||||
friend class Parser;
|
friend class Parser;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace Web::CSS {
|
||||||
AtStyleRule::AtStyleRule() { }
|
AtStyleRule::AtStyleRule() { }
|
||||||
AtStyleRule::~AtStyleRule() { }
|
AtStyleRule::~AtStyleRule() { }
|
||||||
|
|
||||||
DeclarationOrAtRule::DeclarationOrAtRule(AtStyleRule at)
|
DeclarationOrAtRule::DeclarationOrAtRule(RefPtr<AtStyleRule> at)
|
||||||
: m_type(DeclarationType::At)
|
: m_type(DeclarationType::At)
|
||||||
, m_at(move(at))
|
, m_at(move(at))
|
||||||
{
|
{
|
||||||
|
@ -94,7 +94,7 @@ String DeclarationOrAtRule::to_string() const
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
default:
|
default:
|
||||||
case DeclarationType::At:
|
case DeclarationType::At:
|
||||||
builder.append(m_at.to_string());
|
builder.append(m_at->to_string());
|
||||||
break;
|
break;
|
||||||
case DeclarationType::Declaration:
|
case DeclarationType::Declaration:
|
||||||
builder.append(m_declaration.to_string());
|
builder.append(m_declaration.to_string());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue