1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 20:17:41 +00:00

LibWeb: Move ComponentValue to CSS::Parser namespace

This commit is contained in:
Sam Atkins 2022-04-12 12:13:10 +01:00 committed by Andreas Kling
parent c449cabae3
commit fff2c35f51
11 changed files with 26 additions and 23 deletions

View file

@ -9,7 +9,7 @@
#include <LibWeb/CSS/Parser/StyleBlockRule.h> #include <LibWeb/CSS/Parser/StyleBlockRule.h>
#include <LibWeb/CSS/Parser/StyleFunctionRule.h> #include <LibWeb/CSS/Parser/StyleFunctionRule.h>
namespace Web::CSS { namespace Web::CSS::Parser {
ComponentValue::ComponentValue(Token token) ComponentValue::ComponentValue(Token token)
: m_value(token) : m_value(token)

View file

@ -12,9 +12,11 @@
#include <LibWeb/CSS/Parser/Token.h> #include <LibWeb/CSS/Parser/Token.h>
namespace Web::CSS { namespace Web::CSS {
class StyleBlockRule; class StyleBlockRule;
class StyleFunctionRule; class StyleFunctionRule;
}
namespace Web::CSS::Parser {
// https://www.w3.org/TR/css-syntax-3/#component-value // https://www.w3.org/TR/css-syntax-3/#component-value
class ComponentValue { class ComponentValue {

View file

@ -21,14 +21,14 @@ public:
~Declaration(); ~Declaration();
String const& name() const { return m_name; } String const& name() const { return m_name; }
Vector<ComponentValue> const& values() const { return m_values; } Vector<Parser::ComponentValue> const& values() const { return m_values; }
Important importance() const { return m_important; } Important importance() const { return m_important; }
String to_string() const; String to_string() const;
private: private:
String m_name; String m_name;
Vector<ComponentValue> m_values; Vector<Parser::ComponentValue> m_values;
Important m_important { Important::No }; Important m_important { Important::No };
}; };

View file

@ -20,7 +20,7 @@ class StyleBlockRule : public RefCounted<StyleBlockRule> {
public: public:
StyleBlockRule(); StyleBlockRule();
explicit StyleBlockRule(Token token, Vector<ComponentValue>&& values) explicit StyleBlockRule(Token token, Vector<Parser::ComponentValue>&& values)
: m_token(move(token)) : m_token(move(token))
, m_values(move(values)) , m_values(move(values))
{ {
@ -33,12 +33,12 @@ public:
Token const& token() const { return m_token; } Token const& token() const { return m_token; }
Vector<ComponentValue> const& values() const { return m_values; } Vector<Parser::ComponentValue> const& values() const { return m_values; }
String to_string() const; String to_string() const;
private: private:
Token m_token; Token m_token;
Vector<ComponentValue> m_values; Vector<Parser::ComponentValue> m_values;
}; };
} }

View file

@ -20,16 +20,16 @@ class StyleFunctionRule : public RefCounted<StyleFunctionRule> {
public: public:
explicit StyleFunctionRule(String name); explicit StyleFunctionRule(String name);
StyleFunctionRule(String name, Vector<ComponentValue>&& values); StyleFunctionRule(String name, Vector<Parser::ComponentValue>&& values);
~StyleFunctionRule(); ~StyleFunctionRule();
String const& name() const { return m_name; } String const& name() const { return m_name; }
Vector<ComponentValue> const& values() const { return m_values; } Vector<Parser::ComponentValue> const& values() const { return m_values; }
String to_string() const; String to_string() const;
private: private:
String m_name; String m_name;
Vector<ComponentValue> m_values; Vector<Parser::ComponentValue> m_values;
}; };
} }

View file

@ -29,7 +29,7 @@ public:
bool is_qualified_rule() const { return m_type == Type::Qualified; } bool is_qualified_rule() const { return m_type == Type::Qualified; }
bool is_at_rule() const { return m_type == Type::At; } bool is_at_rule() const { return m_type == Type::At; }
Vector<ComponentValue> const& prelude() const { return m_prelude; } Vector<Parser::ComponentValue> const& prelude() const { return m_prelude; }
RefPtr<StyleBlockRule const> block() const { return m_block; } RefPtr<StyleBlockRule const> block() const { return m_block; }
String const& at_rule_name() const { return m_at_rule_name; } String const& at_rule_name() const { return m_at_rule_name; }
@ -38,7 +38,7 @@ public:
private: private:
Type const m_type; Type const m_type;
String m_at_rule_name; String m_at_rule_name;
Vector<ComponentValue> m_prelude; Vector<Parser::ComponentValue> m_prelude;
RefPtr<StyleBlockRule> m_block; RefPtr<StyleBlockRule> m_block;
}; };

View file

@ -44,7 +44,7 @@ StyleFunctionRule::StyleFunctionRule(String name)
{ {
} }
StyleFunctionRule::StyleFunctionRule(String name, Vector<ComponentValue>&& values) StyleFunctionRule::StyleFunctionRule(String name, Vector<Parser::ComponentValue>&& values)
: m_name(move(name)) : m_name(move(name))
, m_values(move(values)) , m_values(move(values))
{ {

View file

@ -526,10 +526,10 @@ static RefPtr<StyleValue> get_custom_property(DOM::Element const& element, FlySt
return nullptr; return nullptr;
} }
bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView property_name, HashMap<FlyString, NonnullRefPtr<PropertyDependencyNode>>& dependencies, Vector<ComponentValue> const& source, Vector<ComponentValue>& dest, size_t source_start_index) const bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView property_name, HashMap<FlyString, NonnullRefPtr<PropertyDependencyNode>>& dependencies, Vector<Parser::ComponentValue> const& source, Vector<Parser::ComponentValue>& dest, size_t source_start_index) const
{ {
// FIXME: Do this better! // FIXME: Do this better!
// We build a copy of the tree of StyleComponentValueRules, with all var()s and attr()s replaced with their contents. // We build a copy of the tree of ComponentValues, with all var()s and attr()s replaced with their contents.
// This is a very naive solution, and we could do better if the CSS Parser could accept tokens one at a time. // This is a very naive solution, and we could do better if the CSS Parser could accept tokens one at a time.
// Arbitrary large value chosen to avoid the billion-laughs attack. // Arbitrary large value chosen to avoid the billion-laughs attack.
@ -619,7 +619,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
} }
auto const& source_function = value.function(); auto const& source_function = value.function();
Vector<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<StyleFunctionRule> function = adopt_ref(*new StyleFunctionRule(source_function.name(), move(function_values))); NonnullRefPtr<StyleFunctionRule> function = adopt_ref(*new StyleFunctionRule(source_function.name(), move(function_values)));
@ -628,7 +628,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
} }
if (value.is_block()) { if (value.is_block()) {
auto const& source_block = value.block(); auto const& source_block = value.block();
Vector<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<StyleBlockRule> block = adopt_ref(*new StyleBlockRule(source_block.token(), move(block_values))); NonnullRefPtr<StyleBlockRule> block = adopt_ref(*new StyleBlockRule(source_block.token(), move(block_values)));
@ -647,7 +647,7 @@ RefPtr<StyleValue> StyleComputer::resolve_unresolved_style_value(DOM::Element& e
// to produce a different StyleValue from it. // to produce a different StyleValue from it.
VERIFY(unresolved.contains_var_or_attr()); VERIFY(unresolved.contains_var_or_attr());
Vector<ComponentValue> expanded_values; Vector<Parser::ComponentValue> expanded_values;
HashMap<FlyString, NonnullRefPtr<PropertyDependencyNode>> dependencies; HashMap<FlyString, NonnullRefPtr<PropertyDependencyNode>> dependencies;
if (!expand_unresolved_values(element, string_from_property_id(property_id), dependencies, unresolved.values(), expanded_values, 0)) if (!expand_unresolved_values(element, string_from_property_id(property_id), dependencies, unresolved.values(), expanded_values, 0))
return {}; return {};

View file

@ -86,7 +86,7 @@ private:
void compute_defaulted_property_value(StyleProperties&, DOM::Element const*, CSS::PropertyID, Optional<CSS::Selector::PseudoElement>) const; void compute_defaulted_property_value(StyleProperties&, DOM::Element const*, CSS::PropertyID, Optional<CSS::Selector::PseudoElement>) const;
RefPtr<StyleValue> resolve_unresolved_style_value(DOM::Element&, PropertyID, UnresolvedStyleValue const&) const; RefPtr<StyleValue> resolve_unresolved_style_value(DOM::Element&, PropertyID, UnresolvedStyleValue const&) const;
bool expand_unresolved_values(DOM::Element&, StringView property_name, HashMap<FlyString, NonnullRefPtr<PropertyDependencyNode>>& dependencies, Vector<ComponentValue> const& source, Vector<ComponentValue>& dest, size_t source_start_index) const; bool expand_unresolved_values(DOM::Element&, StringView property_name, HashMap<FlyString, NonnullRefPtr<PropertyDependencyNode>>& dependencies, Vector<Parser::ComponentValue> const& source, Vector<Parser::ComponentValue>& dest, size_t source_start_index) const;
template<typename Callback> template<typename Callback>
void for_each_stylesheet(CascadeOrigin, Callback) const; void for_each_stylesheet(CascadeOrigin, Callback) const;

View file

@ -1625,7 +1625,7 @@ private:
class UnresolvedStyleValue final : public StyleValue { class UnresolvedStyleValue final : public StyleValue {
public: public:
static NonnullRefPtr<UnresolvedStyleValue> create(Vector<ComponentValue>&& values, bool contains_var_or_attr) static NonnullRefPtr<UnresolvedStyleValue> create(Vector<Parser::ComponentValue>&& values, bool contains_var_or_attr)
{ {
return adopt_ref(*new UnresolvedStyleValue(move(values), contains_var_or_attr)); return adopt_ref(*new UnresolvedStyleValue(move(values), contains_var_or_attr));
} }
@ -1633,18 +1633,18 @@ public:
virtual String to_string() const override; virtual String to_string() const override;
Vector<ComponentValue> const& values() const { return m_values; } Vector<Parser::ComponentValue> const& values() const { return m_values; }
bool contains_var_or_attr() const { return m_contains_var_or_attr; } bool contains_var_or_attr() const { return m_contains_var_or_attr; }
private: private:
UnresolvedStyleValue(Vector<ComponentValue>&& values, bool contains_var_or_attr) UnresolvedStyleValue(Vector<Parser::ComponentValue>&& values, bool contains_var_or_attr)
: StyleValue(Type::Unresolved) : StyleValue(Type::Unresolved)
, m_values(move(values)) , m_values(move(values))
, m_contains_var_or_attr(contains_var_or_attr) , m_contains_var_or_attr(contains_var_or_attr)
{ {
} }
Vector<ComponentValue> m_values; Vector<Parser::ComponentValue> m_values;
bool m_contains_var_or_attr { false }; bool m_contains_var_or_attr { false };
}; };

View file

@ -99,6 +99,7 @@ enum class ValueID;
} }
namespace Web::CSS::Parser { namespace Web::CSS::Parser {
class ComponentValue;
class Parser; class Parser;
} }