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

LibWeb: Use FlyString for CSS custom property names

This commit is contained in:
Andreas Kling 2022-03-03 13:34:08 +01:00
parent 7a19d0b4f9
commit e4fdb40158
3 changed files with 12 additions and 12 deletions

View file

@ -439,7 +439,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
style.set_property(property_id, value); style.set_property(property_id, value);
} }
bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView property_name, HashMap<String, NonnullRefPtr<PropertyDependencyNode>>& dependencies, Vector<StyleComponentValueRule> const& source, Vector<StyleComponentValueRule>& dest, size_t source_start_index, HashMap<String, StyleProperty const*> const& custom_properties) const bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView property_name, HashMap<FlyString, NonnullRefPtr<PropertyDependencyNode>>& dependencies, Vector<StyleComponentValueRule> const& source, Vector<StyleComponentValueRule>& dest, size_t source_start_index, HashMap<FlyString, StyleProperty const*> const& custom_properties) const
{ {
// FIXME: Do this better! // FIXME: Do this better!
// We build a copy of the tree of StyleComponentValueRules, with all var()s replaced with their contents. // We build a copy of the tree of StyleComponentValueRules, with all var()s replaced with their contents.
@ -532,14 +532,14 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
return true; return true;
} }
RefPtr<StyleValue> StyleComputer::resolve_unresolved_style_value(DOM::Element& element, PropertyID property_id, UnresolvedStyleValue const& unresolved, HashMap<String, StyleProperty const*> const& custom_properties) const RefPtr<StyleValue> StyleComputer::resolve_unresolved_style_value(DOM::Element& element, PropertyID property_id, UnresolvedStyleValue const& unresolved, HashMap<FlyString, StyleProperty const*> const& custom_properties) const
{ {
// Unresolved always contains a var(), unless it is a custom property's value, in which case we shouldn't be trying // Unresolved always contains a var(), unless it is a custom property's value, in which case we shouldn't be trying
// to produce a different StyleValue from it. // to produce a different StyleValue from it.
VERIFY(unresolved.contains_var()); VERIFY(unresolved.contains_var());
Vector<StyleComponentValueRule> expanded_values; Vector<StyleComponentValueRule> expanded_values;
HashMap<String, 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, custom_properties)) if (!expand_unresolved_values(element, string_from_property_id(property_id), dependencies, unresolved.values(), expanded_values, 0, custom_properties))
return {}; return {};
@ -549,7 +549,7 @@ RefPtr<StyleValue> StyleComputer::resolve_unresolved_style_value(DOM::Element& e
return {}; return {};
} }
void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& element, Vector<MatchingRule> const& matching_rules, CascadeOrigin cascade_origin, Important important, HashMap<String, StyleProperty const*> const& custom_properties) const void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& element, Vector<MatchingRule> const& matching_rules, CascadeOrigin cascade_origin, Important important, HashMap<FlyString, StyleProperty const*> const& custom_properties) const
{ {
for (auto const& match : matching_rules) { for (auto const& match : matching_rules) {
for (auto const& property : verify_cast<PropertyOwningCSSStyleDeclaration>(match.rule->declaration()).properties()) { for (auto const& property : verify_cast<PropertyOwningCSSStyleDeclaration>(match.rule->declaration()).properties()) {
@ -575,9 +575,9 @@ void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& e
} }
} }
static HashMap<String, StyleProperty const*> cascade_custom_properties(DOM::Element& element, Vector<MatchingRule> const& matching_rules) static HashMap<FlyString, StyleProperty const*> cascade_custom_properties(DOM::Element& element, Vector<MatchingRule> const& matching_rules)
{ {
HashMap<String, StyleProperty const*> custom_properties; HashMap<FlyString, StyleProperty const*> custom_properties;
if (auto* parent_element = element.parent_element()) { if (auto* parent_element = element.parent_element()) {
for (auto const& it : parent_element->custom_properties()) for (auto const& it : parent_element->custom_properties())

View file

@ -78,8 +78,8 @@ 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&, HashMap<String, StyleProperty const*> const&) const; RefPtr<StyleValue> resolve_unresolved_style_value(DOM::Element&, PropertyID, UnresolvedStyleValue const&, HashMap<FlyString, StyleProperty const*> const&) const;
bool expand_unresolved_values(DOM::Element&, StringView property_name, HashMap<String, NonnullRefPtr<PropertyDependencyNode>>& dependencies, Vector<StyleComponentValueRule> const& source, Vector<StyleComponentValueRule>& dest, size_t source_start_index, HashMap<String, StyleProperty const*> const& custom_properties) const; bool expand_unresolved_values(DOM::Element&, StringView property_name, HashMap<FlyString, NonnullRefPtr<PropertyDependencyNode>>& dependencies, Vector<StyleComponentValueRule> const& source, Vector<StyleComponentValueRule>& dest, size_t source_start_index, HashMap<FlyString, StyleProperty const*> const& custom_properties) const;
template<typename Callback> template<typename Callback>
void for_each_stylesheet(CascadeOrigin, Callback) const; void for_each_stylesheet(CascadeOrigin, Callback) const;
@ -89,7 +89,7 @@ private:
Vector<MatchingRule> author_rules; Vector<MatchingRule> author_rules;
}; };
void cascade_declarations(StyleProperties&, DOM::Element&, Vector<MatchingRule> const&, CascadeOrigin, Important important, HashMap<String, StyleProperty const*> const&) const; void cascade_declarations(StyleProperties&, DOM::Element&, Vector<MatchingRule> const&, CascadeOrigin, Important important, HashMap<FlyString, StyleProperty const*> const&) const;
void build_rule_cache(); void build_rule_cache();
void build_rule_cache_if_needed() const; void build_rule_cache_if_needed() const;

View file

@ -118,8 +118,8 @@ public:
m_custom_properties.set(move(custom_property_name), move(style_property)); m_custom_properties.set(move(custom_property_name), move(style_property));
} }
HashMap<String, CSS::StyleProperty> const& custom_properties() const { return m_custom_properties; } HashMap<FlyString, CSS::StyleProperty> const& custom_properties() const { return m_custom_properties; }
HashMap<String, CSS::StyleProperty>& custom_properties() { return m_custom_properties; } HashMap<FlyString, CSS::StyleProperty>& custom_properties() { return m_custom_properties; }
void queue_an_element_task(HTML::Task::Source, Function<void()>); void queue_an_element_task(HTML::Task::Source, Function<void()>);
@ -149,7 +149,7 @@ private:
RefPtr<CSS::CSSStyleDeclaration> m_inline_style; RefPtr<CSS::CSSStyleDeclaration> m_inline_style;
RefPtr<CSS::StyleProperties> m_specified_css_values; RefPtr<CSS::StyleProperties> m_specified_css_values;
HashMap<String, CSS::StyleProperty> m_custom_properties; HashMap<FlyString, CSS::StyleProperty> m_custom_properties;
RefPtr<DOMTokenList> m_class_list; RefPtr<DOMTokenList> m_class_list;
Vector<FlyString> m_classes; Vector<FlyString> m_classes;