mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:47:42 +00:00
LibWeb: Break friendship between CSS Block and Parser
This means deviating a little from the spec, so that we create a complete Block in one go instead of creating an empty one and then poking at its internals.
This commit is contained in:
parent
7128e8e2e6
commit
f235da27d9
4 changed files with 14 additions and 11 deletions
|
@ -9,12 +9,12 @@
|
||||||
|
|
||||||
namespace Web::CSS::Parser {
|
namespace Web::CSS::Parser {
|
||||||
|
|
||||||
Block::Block() = default;
|
|
||||||
Block::Block(Token token, Vector<ComponentValue>&& values)
|
Block::Block(Token token, Vector<ComponentValue>&& values)
|
||||||
: m_token(move(token))
|
: m_token(move(token))
|
||||||
, m_values(move(values))
|
, m_values(move(values))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Block::~Block() = default;
|
Block::~Block() = default;
|
||||||
|
|
||||||
String Block::to_string() const
|
String Block::to_string() const
|
||||||
|
|
|
@ -16,11 +16,12 @@
|
||||||
namespace Web::CSS::Parser {
|
namespace Web::CSS::Parser {
|
||||||
|
|
||||||
class Block : public RefCounted<Block> {
|
class Block : public RefCounted<Block> {
|
||||||
friend class Parser;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Block();
|
static NonnullRefPtr<Block> create(Token token, Vector<ComponentValue>&& values)
|
||||||
Block(Token, Vector<ComponentValue>&&);
|
{
|
||||||
|
return adopt_ref(*new Block(move(token), move(values)));
|
||||||
|
}
|
||||||
|
|
||||||
~Block();
|
~Block();
|
||||||
|
|
||||||
bool is_curly() const { return m_token.is(Token::Type::OpenCurly); }
|
bool is_curly() const { return m_token.is(Token::Type::OpenCurly); }
|
||||||
|
@ -34,6 +35,7 @@ public:
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Block(Token, Vector<ComponentValue>&&);
|
||||||
Token m_token;
|
Token m_token;
|
||||||
Vector<ComponentValue> m_values;
|
Vector<ComponentValue> m_values;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1834,8 +1834,9 @@ NonnullRefPtr<Block> Parser::consume_a_simple_block(TokenStream<T>& tokens)
|
||||||
|
|
||||||
// Create a simple block with its associated token set to the current input token
|
// Create a simple block with its associated token set to the current input token
|
||||||
// and with its value initially set to an empty list.
|
// and with its value initially set to an empty list.
|
||||||
auto block = make_ref_counted<Block>();
|
// NOTE: We create the Block fully initialized when we return it instead.
|
||||||
block->m_token = tokens.current_token();
|
Token block_token = tokens.current_token();
|
||||||
|
Vector<ComponentValue> block_values;
|
||||||
|
|
||||||
// Repeatedly consume the next input token and process it as follows:
|
// Repeatedly consume the next input token and process it as follows:
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -1844,13 +1845,13 @@ NonnullRefPtr<Block> Parser::consume_a_simple_block(TokenStream<T>& tokens)
|
||||||
// ending token
|
// ending token
|
||||||
if (token.is(ending_token)) {
|
if (token.is(ending_token)) {
|
||||||
// Return the block.
|
// Return the block.
|
||||||
return block;
|
return Block::create(move(block_token), move(block_values));
|
||||||
}
|
}
|
||||||
// <EOF-token>
|
// <EOF-token>
|
||||||
if (token.is(Token::Type::EndOfFile)) {
|
if (token.is(Token::Type::EndOfFile)) {
|
||||||
// This is a parse error. Return the block.
|
// This is a parse error. Return the block.
|
||||||
log_parse_error();
|
log_parse_error();
|
||||||
return block;
|
return Block::create(move(block_token), move(block_values));
|
||||||
}
|
}
|
||||||
|
|
||||||
// anything else
|
// anything else
|
||||||
|
@ -1859,7 +1860,7 @@ NonnullRefPtr<Block> Parser::consume_a_simple_block(TokenStream<T>& tokens)
|
||||||
tokens.reconsume_current_input_token();
|
tokens.reconsume_current_input_token();
|
||||||
|
|
||||||
// Consume a component value and append it to the value of the block.
|
// Consume a component value and append it to the value of the block.
|
||||||
block->m_values.append(consume_a_component_value(tokens));
|
block_values.empend(consume_a_component_value(tokens));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -631,7 +631,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
|
||||||
Vector<Parser::ComponentValue> block_values;
|
Vector<Parser::ComponentValue> block_values;
|
||||||
if (!expand_unresolved_values(element, property_name, dependencies, source_block.values(), block_values, 0))
|
if (!expand_unresolved_values(element, property_name, dependencies, source_block.values(), block_values, 0))
|
||||||
return false;
|
return false;
|
||||||
NonnullRefPtr<Parser::Block> block = adopt_ref(*new Parser::Block(source_block.token(), move(block_values)));
|
NonnullRefPtr<Parser::Block> block = Parser::Block::create(source_block.token(), move(block_values));
|
||||||
dest.empend(move(block));
|
dest.empend(move(block));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue