mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
LibWeb: Break friendship between CSS Function and Parser
Again, this means deviating from the spec by creating a complete Function in one go instead of creating it empty and then poking at its internals.
This commit is contained in:
parent
7d67e428a6
commit
d67e817d8e
4 changed files with 14 additions and 14 deletions
|
@ -10,11 +10,6 @@
|
||||||
|
|
||||||
namespace Web::CSS::Parser {
|
namespace Web::CSS::Parser {
|
||||||
|
|
||||||
Function::Function(FlyString name)
|
|
||||||
: m_name(move(name))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Function::Function(FlyString name, Vector<ComponentValue>&& values)
|
Function::Function(FlyString name, Vector<ComponentValue>&& values)
|
||||||
: m_name(move(name))
|
: m_name(move(name))
|
||||||
, m_values(move(values))
|
, m_values(move(values))
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
namespace Web::CSS::Parser {
|
namespace Web::CSS::Parser {
|
||||||
|
|
||||||
class Function : public RefCounted<Function> {
|
class Function : public RefCounted<Function> {
|
||||||
friend class Parser;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Function(FlyString name);
|
static NonnullRefPtr<Function> create(FlyString name, Vector<ComponentValue>&& values)
|
||||||
Function(FlyString name, Vector<ComponentValue>&& values);
|
{
|
||||||
|
return adopt_ref(*new Function(move(name), move(values)));
|
||||||
|
}
|
||||||
|
|
||||||
~Function();
|
~Function();
|
||||||
|
|
||||||
StringView name() const { return m_name; }
|
StringView name() const { return m_name; }
|
||||||
|
@ -30,6 +31,8 @@ public:
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Function(FlyString name, Vector<ComponentValue>&& values);
|
||||||
|
|
||||||
FlyString m_name;
|
FlyString m_name;
|
||||||
Vector<ComponentValue> m_values;
|
Vector<ComponentValue> m_values;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1878,7 +1878,9 @@ NonnullRefPtr<Function> Parser::consume_a_function(TokenStream<T>& tokens)
|
||||||
|
|
||||||
// Create a function with its name equal to the value of the current input token
|
// Create a function with its name equal to the value of 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 function = make_ref_counted<Function>(((Token)name_ident).function());
|
// NOTE: We create the Function fully initialized when we return it instead.
|
||||||
|
FlyString function_name = ((Token)name_ident).function();
|
||||||
|
Vector<ComponentValue> function_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 (;;) {
|
||||||
|
@ -1887,14 +1889,14 @@ NonnullRefPtr<Function> Parser::consume_a_function(TokenStream<T>& tokens)
|
||||||
// <)-token>
|
// <)-token>
|
||||||
if (token.is(Token::Type::CloseParen)) {
|
if (token.is(Token::Type::CloseParen)) {
|
||||||
// Return the function.
|
// Return the function.
|
||||||
return function;
|
return Function::create(move(function_name), move(function_values));
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EOF-token>
|
// <EOF-token>
|
||||||
if (token.is(Token::Type::EndOfFile)) {
|
if (token.is(Token::Type::EndOfFile)) {
|
||||||
// This is a parse error. Return the function.
|
// This is a parse error. Return the function.
|
||||||
log_parse_error();
|
log_parse_error();
|
||||||
return function;
|
return Function::create(move(function_name), move(function_values));
|
||||||
}
|
}
|
||||||
|
|
||||||
// anything else
|
// anything else
|
||||||
|
@ -1903,7 +1905,7 @@ NonnullRefPtr<Function> Parser::consume_a_function(TokenStream<T>& tokens)
|
||||||
tokens.reconsume_current_input_token();
|
tokens.reconsume_current_input_token();
|
||||||
|
|
||||||
// Consume a component value and append the returned value to the function’s value.
|
// Consume a component value and append the returned value to the function’s value.
|
||||||
function->m_values.append(consume_a_component_value(tokens));
|
function_values.append(consume_a_component_value(tokens));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -622,7 +622,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
|
||||||
Vector<Parser::ComponentValue> function_values;
|
Vector<Parser::ComponentValue> function_values;
|
||||||
if (!expand_unresolved_values(element, property_name, dependencies, source_function.values(), function_values, 0))
|
if (!expand_unresolved_values(element, property_name, dependencies, source_function.values(), function_values, 0))
|
||||||
return false;
|
return false;
|
||||||
NonnullRefPtr<Parser::Function> function = adopt_ref(*new Parser::Function(source_function.name(), move(function_values)));
|
NonnullRefPtr<Parser::Function> function = Parser::Function::create(source_function.name(), move(function_values));
|
||||||
dest.empend(function);
|
dest.empend(function);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue