diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-06-29 17:03:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 23:19:56 +0200 |
commit | d6b4022b58b1bbbd28c54484dc1a04475648ac25 (patch) | |
tree | 1df6ab089d75f3eaa7f18703d7e69f8acace177c /Userland/Libraries/LibWeb/CSS | |
parent | 54e1180f618442154b12a9b984549c644b3b3762 (diff) | |
download | serenity-d6b4022b58b1bbbd28c54484dc1a04475648ac25.zip |
LibWeb: Make CSS::QualifiedStyleRule's prelude StyleComponentValueRule
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
4 files changed, 18 insertions, 21 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index dce9f251ad..eee2356dfb 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -70,7 +71,7 @@ Vector<QualifiedStyleRule> Parser::parse_as_stylesheet() for (auto& rule : rules) { dbgln("PRE:"); for (auto& pre : rule.m_prelude) { - dbgln("{}", pre); + dbgln("{}", pre.to_string()); } dbgln("BLOCK:"); dbgln("{}", rule.m_block.to_string()); @@ -84,13 +85,8 @@ Vector<QualifiedStyleRule> Parser::parse_as_stylesheet() return rules; } -Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<String> parts) +Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<StyleComponentValueRule> parts) { - // TODO: - // This is a mess because the prelude is parsed as a string. - // It should really be parsed as its class, but the cpp gods have forsaken me - // and I can't make it work due to cyclic includes. - Vector<CSS::Selector::ComplexSelector> selectors; size_t index = 0; @@ -99,7 +95,7 @@ Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<String> pa return {}; } - auto currentToken = parts.at(index); + auto currentToken = parts.at(index).to_string(); CSS::Selector::SimpleSelector::Type type; if (currentToken == "*") { type = CSS::Selector::SimpleSelector::Type::Universal; @@ -134,7 +130,7 @@ Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<String> pa return simple_selector; } - currentToken = parts.at(index); + currentToken = parts.at(index).to_string(); if (currentToken.starts_with('[')) { auto adjusted = currentToken.substring(1, currentToken.length() - 2); @@ -176,7 +172,7 @@ Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<String> pa return {}; } - currentToken = parts.at(index); + currentToken = parts.at(index).to_string(); if (currentToken == ":") { is_pseudo = true; index++; @@ -186,7 +182,7 @@ Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<String> pa return {}; } - currentToken = parts.at(index); + currentToken = parts.at(index).to_string(); auto pseudo_name = currentToken; index++; @@ -236,7 +232,7 @@ Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<String> pa auto parse_complex_selector = [&]() -> Optional<CSS::Selector::ComplexSelector> { auto relation = CSS::Selector::ComplexSelector::Relation::Descendant; - auto currentToken = parts.at(index); + auto currentToken = parts.at(index).to_string(); if (is_combinator(currentToken)) { if (currentToken == ">") { relation = CSS::Selector::ComplexSelector::Relation::ImmediateChild; @@ -279,7 +275,7 @@ Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<String> pa break; } - auto currentToken = parts.at(index); + auto currentToken = parts.at(index).to_string(); if (currentToken != ",") { break; } @@ -390,7 +386,7 @@ AtStyleRule Parser::consume_an_at_rule() continue; } } - rule.m_prelude.append(value.to_string()); + rule.m_prelude.append(value); } } @@ -420,7 +416,7 @@ Optional<QualifiedStyleRule> Parser::consume_a_qualified_rule() continue; } } - rule.m_prelude.append(value.to_string()); + rule.m_prelude.append(value); } return rule; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index a41fb33bf4..1aadf31211 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -42,7 +43,7 @@ public: Vector<StyleComponentValueRule> parse_as_list_of_comma_separated_component_values(); - Vector<CSS::Selector::ComplexSelector> parse_selectors(Vector<String> parts); + Vector<CSS::Selector::ComplexSelector> parse_selectors(Vector<StyleComponentValueRule> parts); // FIXME: https://www.w3.org/TR/selectors-4/ Optional<String> parse_a_selector() { return {}; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h b/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h index 7de1c1779f..da2f3c2e98 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/QualifiedStyleRule.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,12 +8,10 @@ #pragma once #include <AK/Vector.h> -#include <LibWeb/CSS/Parser/StyleBlockRule.h> +#include <LibWeb/CSS/Parser/StyleComponentValueRule.h> namespace Web::CSS { -class StyleComponentValueRule; - class QualifiedStyleRule { friend class Parser; @@ -22,7 +21,7 @@ public: String to_string() const; private: - Vector<String> m_prelude; + Vector<StyleComponentValueRule> m_prelude; StyleBlockRule m_block; }; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp index 3794360613..e9457f9d63 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -104,7 +105,7 @@ String QualifiedStyleRule::to_string() const { StringBuilder builder; - append_raw(builder, " ", m_prelude); + append_with_to_string(builder, " ", m_prelude); builder.append(m_block.to_string()); return builder.to_string(); |