mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
LibWeb: Convert StyleFunctionRule.m_values to ComponentValues
The input is ComponentValues, and the output is too, so storing as a String in the middle was inefficient and unnecessary.
This commit is contained in:
parent
fabc09a593
commit
cf333574ac
3 changed files with 17 additions and 12 deletions
|
@ -734,7 +734,7 @@ NonnullRefPtr<StyleFunctionRule> Parser::consume_a_function(TokenStream<T>& toke
|
|||
|
||||
tokens.reconsume_current_input_token();
|
||||
auto value = consume_a_component_value(tokens);
|
||||
function->m_values.append(value.token().m_value.to_string());
|
||||
function->m_values.append(value);
|
||||
}
|
||||
|
||||
return function;
|
||||
|
@ -1059,8 +1059,13 @@ RefPtr<CSSRule> Parser::convert_to_rule(NonnullRefPtr<StyleRule> rule)
|
|||
auto url_token = rule->prelude().first();
|
||||
if (url_token.is_function()) {
|
||||
auto& function = url_token.function();
|
||||
if (function.name().equals_ignoring_case("url"sv) && !function.values().is_empty())
|
||||
url = url_token.function().values().first();
|
||||
if (function.name().equals_ignoring_case("url"sv) && !function.values().is_empty()) {
|
||||
auto& argument_token = url_token.function().values().first();
|
||||
if (argument_token.is(Token::Type::String))
|
||||
url = argument_token.token().string();
|
||||
else
|
||||
dbgln("First argument to url() was not a string: '{}'", argument_token.to_debug_string());
|
||||
}
|
||||
}
|
||||
|
||||
if (url_token.is(Token::Type::String))
|
||||
|
@ -1307,8 +1312,11 @@ RefPtr<StyleValue> Parser::parse_css_value(PropertyID property_id, TokenStream<S
|
|||
// FIXME: Handle fallback value as second parameter
|
||||
// https://www.w3.org/TR/css-variables-1/#using-variables
|
||||
if (!token.function().values().is_empty()) {
|
||||
auto& property_name = token.function().values().first();
|
||||
return CustomStyleValue::create(property_name);
|
||||
auto& property_name_token = token.function().values().first();
|
||||
if (property_name_token.is(Token::Type::Ident))
|
||||
return CustomStyleValue::create(property_name_token.token().ident());
|
||||
else
|
||||
dbgln("First argument to var() function was not an ident: '{}'", property_name_token.to_debug_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,20 +23,17 @@ public:
|
|||
~StyleFunctionRule();
|
||||
|
||||
String const& name() const { return m_name; }
|
||||
Vector<String> const& values() const { return m_values; }
|
||||
Vector<StyleComponentValueRule> const& values() const { return m_values; }
|
||||
// FIXME: This method is a temporary hack while much of the parser still expects a string, rather than tokens.
|
||||
String values_as_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
for (auto& value : m_values)
|
||||
builder.append(value);
|
||||
return builder.to_string();
|
||||
return "";
|
||||
}
|
||||
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
String m_name;
|
||||
Vector<String> m_values;
|
||||
Vector<StyleComponentValueRule> m_values;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ String StyleFunctionRule::to_string() const
|
|||
|
||||
builder.append(m_name);
|
||||
builder.append("(");
|
||||
append_raw(builder, ", ", m_values);
|
||||
append_with_to_string(builder, ", ", m_values);
|
||||
builder.append(")");
|
||||
|
||||
return builder.to_string();
|
||||
|
|
Loading…
Add table
Reference in a new issue