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

LibWeb: Serialize StringStyleValue with quotes

In order to access the string's contents, use the new
`StringStyleValue::string_value()` method.

I think I found all the existing places that relied on
`StringStyleValue::to_string()` returning an unquoted string, but it's
hard to know for sure until things break.
This commit is contained in:
Sam Atkins 2023-09-12 11:33:11 +01:00 committed by Sam Atkins
parent 77ae510319
commit ff02de4ad0
5 changed files with 28 additions and 9 deletions

View file

@ -0,0 +1 @@
"wheeee"

View file

@ -0,0 +1,8 @@
<script src="../include.js"></script>
<script>
test(() => {
const e = document.createElement("div");
e.style.content = '"wheeee"';
println(e.style.content);
});
</script>

View file

@ -60,6 +60,7 @@
#include <LibWeb/CSS/StyleValues/PlaceSelfStyleValue.h> #include <LibWeb/CSS/StyleValues/PlaceSelfStyleValue.h>
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h> #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
#include <LibWeb/CSS/StyleValues/RectStyleValue.h> #include <LibWeb/CSS/StyleValues/RectStyleValue.h>
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
#include <LibWeb/CSS/StyleValues/StyleValueList.h> #include <LibWeb/CSS/StyleValues/StyleValueList.h>
#include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h> #include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h>
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h> #include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
@ -1543,7 +1544,15 @@ ErrorOr<void> StyleComputer::compute_cascaded_values(StyleProperties& style, DOM
cascade_declarations(style, element, pseudo_element, matching_rule_set.author_rules, CascadeOrigin::Author, Important::No); cascade_declarations(style, element, pseudo_element, matching_rule_set.author_rules, CascadeOrigin::Author, Important::No);
// Animation declarations [css-animations-2] // Animation declarations [css-animations-2]
if (auto animation_name = style.maybe_null_property(PropertyID::AnimationName)) { auto get_animation_name = [&]() -> Optional<String> {
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)) { if (auto source_declaration = style.property_source_declaration(PropertyID::AnimationName)) {
AnimationKey animation_key { AnimationKey animation_key {
.source_declaration = source_declaration, .source_declaration = source_declaration,
@ -1561,7 +1570,7 @@ ErrorOr<void> StyleComputer::compute_cascaded_values(StyleProperties& style, DOM
style.set_property(static_cast<PropertyID>(property_id_value), *property_value); style.set_property(static_cast<PropertyID>(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); auto active_animation = m_active_animations.get(animation_key);
if (!active_animation.has_value()) { if (!active_animation.has_value()) {
// New animation! // New animation!
@ -1682,7 +1691,7 @@ ErrorOr<void> StyleComputer::compute_cascaded_values(StyleProperties& style, DOM
} }
auto animation = make<Animation>(Animation { auto animation = make<Animation>(Animation {
.name = move(name), .name = animation_name.release_value(),
.duration = duration, .duration = duration,
.delay = delay, .delay = delay,
.iteration_count = iteration_count, .iteration_count = iteration_count,
@ -2127,7 +2136,7 @@ RefPtr<Gfx::Font const> StyleComputer::compute_font_for_style_values(DOM::Elemen
if (family->is_identifier()) { if (family->is_identifier()) {
found_font = find_generic_font(family->to_identifier()); found_font = find_generic_font(family->to_identifier());
} else if (family->is_string()) { } else if (family->is_string()) {
found_font = find_font(family->to_string()); found_font = find_font(family->as_string().string_value());
} }
if (found_font) if (found_font)
break; break;
@ -2135,7 +2144,7 @@ RefPtr<Gfx::Font const> StyleComputer::compute_font_for_style_values(DOM::Elemen
} else if (font_family.is_identifier()) { } else if (font_family.is_identifier()) {
found_font = find_generic_font(font_family.to_identifier()); found_font = find_generic_font(font_family.to_identifier());
} else if (font_family.is_string()) { } 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) { if (!found_font) {

View file

@ -660,7 +660,7 @@ CSS::ContentData StyleProperties::content() const
StringBuilder builder; StringBuilder builder;
for (auto const& item : content_style_value.content().values()) { for (auto const& item : content_style_value.content().values()) {
if (item->is_string()) { if (item->is_string()) {
builder.append(item->to_string()); builder.append(item->as_string().string_value());
} else { } else {
// TODO: Implement quotes, counters, images, and other things. // TODO: Implement quotes, counters, images, and other things.
} }
@ -672,7 +672,7 @@ CSS::ContentData StyleProperties::content() const
StringBuilder alt_text_builder; StringBuilder alt_text_builder;
for (auto const& item : content_style_value.alt_text()->values()) { for (auto const& item : content_style_value.alt_text()->values()) {
if (item->is_string()) { if (item->is_string()) {
alt_text_builder.append(item->to_string()); alt_text_builder.append(item->as_string().string_value());
} else { } else {
// TODO: Implement counters // TODO: Implement counters
} }
@ -951,7 +951,7 @@ Vector<Vector<String>> StyleProperties::grid_template_areas() const
String StyleProperties::grid_area() const String StyleProperties::grid_area() const
{ {
auto value = property(CSS::PropertyID::GridArea); auto value = property(CSS::PropertyID::GridArea);
return value->as_string().to_string(); return value->as_string().string_value();
} }
Optional<CSS::ObjectFit> StyleProperties::object_fit() const Optional<CSS::ObjectFit> StyleProperties::object_fit() const

View file

@ -19,7 +19,8 @@ public:
} }
virtual ~StringStyleValue() override = default; 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; } bool properties_equal(StringStyleValue const& other) const { return m_string == other.m_string; }