diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp index a74c875eee8..990091f222c 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp @@ -173,7 +173,7 @@ bool is_animatable_property(PropertyID); Optional property_id_from_camel_case_string(StringView); Optional property_id_from_string(StringView); -StringView string_from_property_id(PropertyID); +[[nodiscard]] FlyString const& string_from_property_id(PropertyID); bool is_inherited_property(PropertyID); NonnullRefPtr property_initial_value(JS::Realm&, PropertyID); @@ -401,7 +401,7 @@ Optional property_id_from_string(StringView string) return {}; } -StringView string_from_property_id(PropertyID property_id) { +FlyString const& string_from_property_id(PropertyID property_id) { switch (property_id) { )~~~"); @@ -412,14 +412,18 @@ StringView string_from_property_id(PropertyID property_id) { member_generator.set("name", name); member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( - case PropertyID::@name:titlecase@: - return "@name@"sv; + case PropertyID::@name:titlecase@: { + static FlyString name = "@name@"_fly_string; + return name; + } )~~~"); }); generator.append(R"~~~( - default: - return "(invalid CSS::PropertyID)"sv; + default: { + static FlyString invalid_property_id_string = "(invalid CSS::PropertyID)"_fly_string; + return invalid_property_id_string; + } } } diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index 5ebbe1c3689..a844b889e65 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -56,7 +56,7 @@ String PropertyOwningCSSStyleDeclaration::item(size_t index) const { if (index >= m_properties.size()) return {}; - return MUST(String::from_utf8(CSS::string_from_property_id(m_properties[index].property_id))); + return CSS::string_from_property_id(m_properties[index].property_id).to_string(); } JS::NonnullGCPtr ElementInlineCSSStyleDeclaration::create(DOM::Element& element, Vector properties, HashMap custom_properties) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 3e14432385d..6fa8e7a79ed 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -7019,7 +7019,7 @@ static RefPtr get_custom_property(DOM::Element const& element, return nullptr; } -bool Parser::expand_variables(DOM::Element& element, Optional pseudo_element, StringView property_name, HashMap>& dependencies, TokenStream& source, Vector& dest) +bool Parser::expand_variables(DOM::Element& element, Optional pseudo_element, FlyString const& property_name, HashMap>& dependencies, TokenStream& source, Vector& dest) { // Arbitrary large value chosen to avoid the billion-laughs attack. // https://www.w3.org/TR/css-variables-1/#long-variables @@ -7081,7 +7081,7 @@ bool Parser::expand_variables(DOM::Element& element, Optionaladd_child(child); if (parent->has_cycles()) @@ -7109,7 +7109,7 @@ bool Parser::expand_variables(DOM::Element& element, Optional& source, Vector& dest) +bool Parser::expand_unresolved_values(DOM::Element& element, FlyString const& property_name, TokenStream& source, Vector& dest) { while (source.has_next_token()) { auto const& value = source.next_token(); @@ -7180,7 +7180,7 @@ bool Parser::expand_unresolved_values(DOM::Element& element, StringView property } // https://drafts.csswg.org/css-values-5/#attr-substitution -bool Parser::substitute_attr_function(DOM::Element& element, StringView property_name, Function const& attr_function, Vector& dest) +bool Parser::substitute_attr_function(DOM::Element& element, FlyString const& property_name, Function const& attr_function, Vector& dest) { // First, parse the arguments to attr(): // attr() = attr( ? , ?) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index d9b0b8a85cc..2f5c6276421 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -307,9 +307,9 @@ private: Optional parse_supports_feature(TokenStream&); NonnullRefPtr resolve_unresolved_style_value(DOM::Element&, Optional, PropertyID, UnresolvedStyleValue const&); - bool expand_variables(DOM::Element&, Optional, StringView property_name, HashMap>& dependencies, TokenStream& source, Vector& dest); - bool expand_unresolved_values(DOM::Element&, StringView property_name, TokenStream& source, Vector& dest); - bool substitute_attr_function(DOM::Element& element, StringView property_name, Function const& attr_function, Vector& dest); + bool expand_variables(DOM::Element&, Optional, FlyString const& property_name, HashMap>& dependencies, TokenStream& source, Vector& dest); + bool expand_unresolved_values(DOM::Element&, FlyString const& property_name, TokenStream& source, Vector& dest); + bool substitute_attr_function(DOM::Element& element, FlyString const& property_name, Function const& attr_function, Vector& dest); static bool has_ignored_vendor_prefix(StringView); diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index c74cc760563..1e533efce86 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -79,7 +79,7 @@ String ResolvedCSSStyleDeclaration::item(size_t index) const if (index > length()) return {}; auto property_id = static_cast(index + to_underlying(first_longhand_property_id)); - return MUST(String::from_utf8(string_from_property_id(property_id))); + return string_from_property_id(property_id).to_string(); } static NonnullRefPtr style_value_for_background_property(Layout::NodeWithStyle const& layout_node, Function(BackgroundLayerData const&)> callback, Function()> default_value) diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 3f72ec1a584..48e67100b3b 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -384,12 +384,12 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho if (show_specified_style && layout_node.dom_node() && layout_node.dom_node()->is_element() && verify_cast(layout_node.dom_node())->computed_css_values()) { struct NameAndValue { - String name; + FlyString name; String value; }; Vector properties; verify_cast(*layout_node.dom_node()).computed_css_values()->for_each_property([&](auto property_id, auto& value) { - properties.append({ MUST(String::from_utf8(CSS::string_from_property_id(property_id))), value.to_string() }); + properties.append({ CSS::string_from_property_id(property_id), value.to_string() }); }); quick_sort(properties, [](auto& a, auto& b) { return a.name < b.name; });