summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/AtStyleRule.h26
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.h6
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp23
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.h11
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/StyleRule.h (renamed from Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h)13
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp39
6 files changed, 47 insertions, 71 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/AtStyleRule.h b/Userland/Libraries/LibWeb/CSS/Parser/AtStyleRule.h
deleted file mode 100644
index 7473fb0f4d..0000000000
--- a/Userland/Libraries/LibWeb/CSS/Parser/AtStyleRule.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2020-2021, the SerenityOS developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/String.h>
-#include <LibWeb/CSS/Parser/QualifiedStyleRule.h>
-
-namespace Web::CSS {
-
-class AtStyleRule : public QualifiedStyleRule {
- friend class Parser;
-
-public:
- AtStyleRule();
- ~AtStyleRule();
- String to_string() const;
-
-private:
- String m_name;
-};
-
-}
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.h b/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.h
index 30a64bc081..31df3cd068 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.h
+++ b/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.h
@@ -6,8 +6,8 @@
#pragma once
-#include <LibWeb/CSS/Parser/AtStyleRule.h>
#include <LibWeb/CSS/Parser/StyleDeclarationRule.h>
+#include <LibWeb/CSS/Parser/StyleRule.h>
namespace Web::CSS {
@@ -15,7 +15,7 @@ class DeclarationOrAtRule {
friend class Parser;
public:
- explicit DeclarationOrAtRule(RefPtr<AtStyleRule> at);
+ explicit DeclarationOrAtRule(RefPtr<StyleRule> at);
explicit DeclarationOrAtRule(StyleDeclarationRule declaration);
~DeclarationOrAtRule();
@@ -28,7 +28,7 @@ public:
private:
DeclarationType m_type;
- RefPtr<AtStyleRule> m_at;
+ RefPtr<StyleRule> m_at;
StyleDeclarationRule m_declaration;
};
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index b538eb1729..c28ec8c668 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -10,13 +10,12 @@
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/CSSStyleRule.h>
#include <LibWeb/CSS/CSSStyleSheet.h>
-#include <LibWeb/CSS/Parser/AtStyleRule.h>
#include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
#include <LibWeb/CSS/Parser/Parser.h>
-#include <LibWeb/CSS/Parser/QualifiedStyleRule.h>
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
#include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
#include <LibWeb/CSS/Parser/StyleFunctionRule.h>
+#include <LibWeb/CSS/Parser/StyleRule.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Dump.h>
@@ -453,9 +452,9 @@ void Parser::reconsume_current_input_token()
--m_iterator_offset;
}
-NonnullRefPtrVector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top_level)
+NonnullRefPtrVector<StyleRule> Parser::consume_a_list_of_rules(bool top_level)
{
- NonnullRefPtrVector<QualifiedStyleRule> rules;
+ NonnullRefPtrVector<StyleRule> rules;
for (;;) {
auto token = next_token();
@@ -498,12 +497,12 @@ NonnullRefPtrVector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top
return rules;
}
-NonnullRefPtr<AtStyleRule> Parser::consume_an_at_rule()
+NonnullRefPtr<StyleRule> Parser::consume_an_at_rule()
{
auto initial = next_token();
- AtStyleRule rule;
- rule.m_name = initial.m_value.to_string();
+ NonnullRefPtr<StyleRule> rule = create<StyleRule>(StyleRule::Type::At);
+ rule->m_name = initial.m_value.to_string();
for (;;) {
auto token = next_token();
@@ -517,7 +516,7 @@ NonnullRefPtr<AtStyleRule> Parser::consume_an_at_rule()
}
if (token.is_open_curly()) {
- rule.m_block = consume_a_simple_block();
+ rule->m_block = consume_a_simple_block();
return rule;
}
@@ -525,13 +524,13 @@ NonnullRefPtr<AtStyleRule> Parser::consume_an_at_rule()
reconsume_current_input_token();
auto value = consume_a_component_value();
- rule.m_prelude.append(value);
+ rule->m_prelude.append(value);
}
}
-RefPtr<QualifiedStyleRule> Parser::consume_a_qualified_rule()
+RefPtr<StyleRule> Parser::consume_a_qualified_rule()
{
- NonnullRefPtr<QualifiedStyleRule> rule = create<QualifiedStyleRule>();
+ NonnullRefPtr<StyleRule> rule = create<StyleRule>(StyleRule::Type::Qualified);
for (;;) {
auto token = next_token();
@@ -917,7 +916,7 @@ Vector<Vector<StyleComponentValueRule>> Parser::parse_as_comma_separated_list_of
return lists;
}
-RefPtr<CSSRule> Parser::convert_rule(NonnullRefPtr<QualifiedStyleRule>)
+RefPtr<CSSRule> Parser::convert_rule(NonnullRefPtr<StyleRule>)
{
return {};
}
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
index 3c48524382..d4257b479d 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
@@ -9,13 +9,12 @@
#include <AK/NonnullOwnPtrVector.h>
#include <AK/Vector.h>
-#include <LibWeb/CSS/Parser/AtStyleRule.h>
#include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
-#include <LibWeb/CSS/Parser/QualifiedStyleRule.h>
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
#include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
#include <LibWeb/CSS/Parser/StyleDeclarationRule.h>
#include <LibWeb/CSS/Parser/StyleFunctionRule.h>
+#include <LibWeb/CSS/Parser/StyleRule.h>
#include <LibWeb/CSS/Parser/Tokenizer.h>
#include <LibWeb/CSS/Selector.h>
@@ -91,9 +90,9 @@ private:
Token current_token();
void reconsume_current_input_token();
- NonnullRefPtrVector<QualifiedStyleRule> consume_a_list_of_rules(bool top_level);
- NonnullRefPtr<AtStyleRule> consume_an_at_rule();
- RefPtr<QualifiedStyleRule> consume_a_qualified_rule();
+ NonnullRefPtrVector<StyleRule> consume_a_list_of_rules(bool top_level);
+ NonnullRefPtr<StyleRule> consume_an_at_rule();
+ RefPtr<StyleRule> consume_a_qualified_rule();
Vector<DeclarationOrAtRule> consume_a_list_of_declarations();
Optional<StyleDeclarationRule> consume_a_declaration(Vector<StyleComponentValueRule>);
Optional<StyleDeclarationRule> consume_a_declaration();
@@ -101,7 +100,7 @@ private:
NonnullRefPtr<StyleBlockRule> consume_a_simple_block();
NonnullRefPtr<StyleFunctionRule> consume_a_function();
- RefPtr<CSSRule> convert_rule(NonnullRefPtr<QualifiedStyleRule>);
+ RefPtr<CSSRule> convert_rule(NonnullRefPtr<StyleRule>);
ParsingContext m_context;
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h b/Userland/Libraries/LibWeb/CSS/Parser/StyleRule.h
index 87ccc2840d..f1bb1c43b4 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h
+++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRule.h
@@ -14,12 +14,17 @@
namespace Web::CSS {
-class QualifiedStyleRule : public RefCounted<QualifiedStyleRule> {
+class StyleRule : public RefCounted<StyleRule> {
friend class Parser;
public:
- QualifiedStyleRule();
- ~QualifiedStyleRule();
+ enum class Type {
+ At,
+ Qualified,
+ };
+
+ StyleRule(Type);
+ ~StyleRule();
Vector<StyleComponentValueRule> const& prelude() const { return m_prelude; }
StyleBlockRule const& block() const { return *m_block; }
@@ -27,6 +32,8 @@ public:
String to_string() const;
private:
+ Type const m_type;
+ String m_name; // At-rules only
Vector<StyleComponentValueRule> m_prelude;
RefPtr<StyleBlockRule> m_block;
};
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp
index 790d75e0cc..18c1a8328d 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp
@@ -5,20 +5,16 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibWeb/CSS/Parser/AtStyleRule.h>
#include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
-#include <LibWeb/CSS/Parser/QualifiedStyleRule.h>
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
#include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
#include <LibWeb/CSS/Parser/StyleDeclarationRule.h>
#include <LibWeb/CSS/Parser/StyleFunctionRule.h>
+#include <LibWeb/CSS/Parser/StyleRule.h>
namespace Web::CSS {
-AtStyleRule::AtStyleRule() { }
-AtStyleRule::~AtStyleRule() { }
-
-DeclarationOrAtRule::DeclarationOrAtRule(RefPtr<AtStyleRule> at)
+DeclarationOrAtRule::DeclarationOrAtRule(RefPtr<StyleRule> at)
: m_type(DeclarationType::At)
, m_at(move(at))
{
@@ -30,8 +26,11 @@ DeclarationOrAtRule::DeclarationOrAtRule(StyleDeclarationRule declaration)
}
DeclarationOrAtRule::~DeclarationOrAtRule() { }
-QualifiedStyleRule::QualifiedStyleRule() { }
-QualifiedStyleRule::~QualifiedStyleRule() { }
+StyleRule::StyleRule(StyleRule::Type type)
+ : m_type(type)
+{
+}
+StyleRule::~StyleRule() { }
StyleBlockRule::StyleBlockRule() { }
StyleBlockRule::~StyleBlockRule() { }
@@ -77,17 +76,6 @@ void append_raw(StringBuilder& builder, SeparatorType& separator, CollectionType
}
}
-String AtStyleRule::to_string() const
-{
- StringBuilder builder;
- builder.append("@");
- builder.append(m_name);
-
- builder.append(QualifiedStyleRule::to_string());
-
- return builder.to_string();
-}
-
String DeclarationOrAtRule::to_string() const
{
StringBuilder builder;
@@ -104,12 +92,21 @@ String DeclarationOrAtRule::to_string() const
return builder.to_string();
}
-String QualifiedStyleRule::to_string() const
+String StyleRule::to_string() const
{
StringBuilder builder;
+ if (m_type == Type::At) {
+ builder.append("@");
+ builder.append(m_name);
+ }
+
append_with_to_string(builder, " ", m_prelude);
- builder.append(m_block->to_string());
+
+ if (m_block)
+ builder.append(m_block->to_string());
+ else
+ builder.append(';');
return builder.to_string();
}