mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibWeb: Make CSS::QualifiedStyleRule's prelude StyleComponentValueRule
This commit is contained in:
parent
54e1180f61
commit
d6b4022b58
Notes:
sideshowbarker
2024-07-18 09:15:18 +09:00
Author: https://github.com/AtkinsSJ
Commit: d6b4022b58
Pull-request: https://github.com/SerenityOS/serenity/pull/8341
4 changed files with 18 additions and 21 deletions
|
@ -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;
|
||||
|
|
|
@ -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 {}; }
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue