diff --git a/Tests/LibWeb/Text/expected/css/string-serializes-with-quotes.txt b/Tests/LibWeb/Text/expected/css/string-serializes-with-quotes.txt new file mode 100644 index 0000000000..f279816953 --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/string-serializes-with-quotes.txt @@ -0,0 +1 @@ +"wheeee" diff --git a/Tests/LibWeb/Text/input/css/string-serializes-with-quotes.html b/Tests/LibWeb/Text/input/css/string-serializes-with-quotes.html new file mode 100644 index 0000000000..cb4cc5fc18 --- /dev/null +++ b/Tests/LibWeb/Text/input/css/string-serializes-with-quotes.html @@ -0,0 +1,8 @@ + + diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 12b6e83694..57bd633591 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -1543,7 +1544,15 @@ ErrorOr StyleComputer::compute_cascaded_values(StyleProperties& style, DOM cascade_declarations(style, element, pseudo_element, matching_rule_set.author_rules, CascadeOrigin::Author, Important::No); // Animation declarations [css-animations-2] - if (auto animation_name = style.maybe_null_property(PropertyID::AnimationName)) { + auto get_animation_name = [&]() -> Optional { + auto animation_name = style.maybe_null_property(PropertyID::AnimationName); + if (animation_name.is_null()) + return OptionalNone {}; + if (animation_name->is_string()) + return animation_name->as_string().string_value(); + return animation_name->to_string(); + }; + if (auto animation_name = get_animation_name(); animation_name.has_value()) { if (auto source_declaration = style.property_source_declaration(PropertyID::AnimationName)) { AnimationKey animation_key { .source_declaration = source_declaration, @@ -1561,7 +1570,7 @@ ErrorOr StyleComputer::compute_cascaded_values(StyleProperties& style, DOM style.set_property(static_cast(property_id_value), *property_value); } } - } else if (auto name = animation_name->to_string(); !name.is_empty()) { + } else if (!animation_name->is_empty()) { auto active_animation = m_active_animations.get(animation_key); if (!active_animation.has_value()) { // New animation! @@ -1682,7 +1691,7 @@ ErrorOr StyleComputer::compute_cascaded_values(StyleProperties& style, DOM } auto animation = make(Animation { - .name = move(name), + .name = animation_name.release_value(), .duration = duration, .delay = delay, .iteration_count = iteration_count, @@ -2127,7 +2136,7 @@ RefPtr StyleComputer::compute_font_for_style_values(DOM::Elemen if (family->is_identifier()) { found_font = find_generic_font(family->to_identifier()); } else if (family->is_string()) { - found_font = find_font(family->to_string()); + found_font = find_font(family->as_string().string_value()); } if (found_font) break; @@ -2135,7 +2144,7 @@ RefPtr StyleComputer::compute_font_for_style_values(DOM::Elemen } else if (font_family.is_identifier()) { found_font = find_generic_font(font_family.to_identifier()); } else if (font_family.is_string()) { - found_font = find_font(font_family.to_string()); + found_font = find_font(font_family.as_string().string_value()); } if (!found_font) { diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 7e0907f355..5d6a9ae489 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -660,7 +660,7 @@ CSS::ContentData StyleProperties::content() const StringBuilder builder; for (auto const& item : content_style_value.content().values()) { if (item->is_string()) { - builder.append(item->to_string()); + builder.append(item->as_string().string_value()); } else { // TODO: Implement quotes, counters, images, and other things. } @@ -672,7 +672,7 @@ CSS::ContentData StyleProperties::content() const StringBuilder alt_text_builder; for (auto const& item : content_style_value.alt_text()->values()) { if (item->is_string()) { - alt_text_builder.append(item->to_string()); + alt_text_builder.append(item->as_string().string_value()); } else { // TODO: Implement counters } @@ -951,7 +951,7 @@ Vector> StyleProperties::grid_template_areas() const String StyleProperties::grid_area() const { auto value = property(CSS::PropertyID::GridArea); - return value->as_string().to_string(); + return value->as_string().string_value(); } Optional StyleProperties::object_fit() const diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h index 53a3c94ccb..ecb5643a05 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h @@ -19,7 +19,8 @@ public: } virtual ~StringStyleValue() override = default; - String to_string() const override { return m_string; } + String string_value() const { return m_string; } + String to_string() const override { return serialize_a_string(m_string); } bool properties_equal(StringStyleValue const& other) const { return m_string == other.m_string; }