LibWeb/CSS: Extract SerializationMode into its own header

Prep for using this to serialize dimension types, and perhaps other
things in the future.
This commit is contained in:
Sam Atkins 2025-05-16 19:20:24 +01:00 committed by Tim Ledbetter
commit eec4365542
Notes: github-actions[bot] 2025-05-17 06:54:49 +00:00
26 changed files with 112 additions and 99 deletions

View file

@ -813,7 +813,7 @@ WebIDL::ExceptionOr<GC::RootVector<JS::Object*>> KeyframeEffect::get_keyframes()
TRY(object->set(vm.names.offset, keyframe.offset.has_value() ? JS::Value(keyframe.offset.value()) : JS::js_null(), ShouldThrowExceptions::Yes));
TRY(object->set(vm.names.computedOffset, JS::Value(keyframe.computed_offset.value()), ShouldThrowExceptions::Yes));
auto easing_value = keyframe.easing.get<NonnullRefPtr<CSS::CSSStyleValue const>>();
TRY(object->set(vm.names.easing, JS::PrimitiveString::create(vm, easing_value->to_string(CSS::CSSStyleValue::SerializationMode::Normal)), ShouldThrowExceptions::Yes));
TRY(object->set(vm.names.easing, JS::PrimitiveString::create(vm, easing_value->to_string(CSS::SerializationMode::Normal)), ShouldThrowExceptions::Yes));
if (keyframe.composite == Bindings::CompositeOperationOrAuto::Replace) {
TRY(object->set(vm.names.composite, JS::PrimitiveString::create(vm, "replace"sv), ShouldThrowExceptions::Yes));
@ -826,7 +826,7 @@ WebIDL::ExceptionOr<GC::RootVector<JS::Object*>> KeyframeEffect::get_keyframes()
}
for (auto const& [id, value] : keyframe.parsed_properties()) {
auto value_string = JS::PrimitiveString::create(vm, value->to_string(CSS::CSSStyleValue::SerializationMode::Normal));
auto value_string = JS::PrimitiveString::create(vm, value->to_string(CSS::SerializationMode::Normal));
TRY(object->set(JS::PropertyKey { CSS::camel_case_string_from_property_id(id), JS::PropertyKey::StringMayBeNumber::No }, value_string, ShouldThrowExceptions::Yes));
}

View file

@ -178,7 +178,7 @@ String CSSDescriptors::get_property_value(StringView property) const
if (descriptor_id.has_value()) {
auto match = m_descriptors.first_matching([descriptor_id](auto& entry) { return entry.descriptor_id == *descriptor_id; });
if (match.has_value())
return match->value->to_string(CSSStyleValue::SerializationMode::Normal);
return match->value->to_string(SerializationMode::Normal);
}
// 3. Return the empty string.
@ -215,7 +215,7 @@ String CSSDescriptors::serialized() const
// NB: Descriptors can't be shorthands.
// 5. Let value be the result of invoking serialize a CSS value of declaration.
auto value = descriptor.value->to_string(CSSStyleValue::SerializationMode::Normal);
auto value = descriptor.value->to_string(SerializationMode::Normal);
// 6. Let serialized declaration be the result of invoking serialize a CSS declaration with property name property, value value, and the important flag set if declaration has its important flag set.
auto serialized_declaration = serialize_a_css_declaration(property, value, Important::No);

View file

@ -64,7 +64,7 @@ String CSSFontFaceRule::serialized() const
builder.append("font-family: "sv);
// 3. The result of performing serialize a string on the rules font family name.
builder.append(descriptors.descriptor(DescriptorID::FontFamily)->to_string(CSSStyleValue::SerializationMode::Normal));
builder.append(descriptors.descriptor(DescriptorID::FontFamily)->to_string(SerializationMode::Normal));
// 4. The string ";", i.e., SEMICOLON (U+003B).
builder.append(';');
@ -75,7 +75,7 @@ String CSSFontFaceRule::serialized() const
builder.append(" src: "sv);
// 2. The result of invoking serialize a comma-separated list on performing serialize a URL or serialize a LOCAL for each source on the source list.
builder.append(sources->to_string(CSSStyleValue::SerializationMode::Normal));
builder.append(sources->to_string(SerializationMode::Normal));
// 3. The string ";", i.e., SEMICOLON (U+003B).
builder.append(';');
@ -84,7 +84,7 @@ String CSSFontFaceRule::serialized() const
// 6. If rules associated unicode-range descriptor is present, a single SPACE (U+0020), followed by the string "unicode-range:", followed by a single SPACE (U+0020), followed by the result of performing serialize a <'unicode-range'>, followed by the string ";", i.e., SEMICOLON (U+003B).
if (auto unicode_range = descriptors.descriptor(DescriptorID::UnicodeRange)) {
builder.append(" unicode-range: "sv);
builder.append(unicode_range->to_string(CSSStyleValue::SerializationMode::Normal));
builder.append(unicode_range->to_string(SerializationMode::Normal));
builder.append(';');
}
@ -99,7 +99,7 @@ String CSSFontFaceRule::serialized() const
// followed by the string ";", i.e., SEMICOLON (U+003B).
if (auto font_feature_settings = descriptors.descriptor(DescriptorID::FontFeatureSettings)) {
builder.append(" font-feature-settings: "sv);
builder.append(font_feature_settings->to_string(CSSStyleValue::SerializationMode::Normal));
builder.append(font_feature_settings->to_string(SerializationMode::Normal));
builder.append(";"sv);
}
@ -110,7 +110,7 @@ String CSSFontFaceRule::serialized() const
// NOTE: font-stretch is now an alias for font-width, so we use that instead.
if (auto font_width = descriptors.descriptor(DescriptorID::FontWidth)) {
builder.append(" font-stretch: "sv);
builder.append(font_width->to_string(CSSStyleValue::SerializationMode::Normal));
builder.append(font_width->to_string(SerializationMode::Normal));
builder.append(";"sv);
}
@ -120,7 +120,7 @@ String CSSFontFaceRule::serialized() const
// followed by the string ";", i.e., SEMICOLON (U+003B).
if (auto font_weight = descriptors.descriptor(DescriptorID::FontWeight)) {
builder.append(" font-weight: "sv);
builder.append(font_weight->to_string(CSSStyleValue::SerializationMode::Normal));
builder.append(font_weight->to_string(SerializationMode::Normal));
builder.append(";"sv);
}
@ -130,7 +130,7 @@ String CSSFontFaceRule::serialized() const
// followed by the string ";", i.e., SEMICOLON (U+003B).
if (auto font_style = descriptors.descriptor(DescriptorID::FontStyle)) {
builder.append(" font-style: "sv);
builder.append(font_style->to_string(CSSStyleValue::SerializationMode::Normal));
builder.append(font_style->to_string(SerializationMode::Normal));
builder.append(";"sv);
}

View file

@ -30,7 +30,7 @@ CSSPropertyRule::CSSPropertyRule(JS::Realm& realm, FlyString name, FlyString syn
Optional<String> CSSPropertyRule::initial_value() const
{
if (m_initial_value)
return m_initial_value->to_string(CSSStyleValue::SerializationMode::Normal);
return m_initial_value->to_string(SerializationMode::Normal);
return {};
}

View file

@ -392,8 +392,8 @@ String CSSStyleProperties::get_property_value(StringView property_name) const
auto maybe_custom_property = custom_property(FlyString::from_utf8_without_validation(property_name.bytes()));
if (maybe_custom_property.has_value()) {
return maybe_custom_property.value().value->to_string(
is_computed() ? CSSStyleValue::SerializationMode::ResolvedValue
: CSSStyleValue::SerializationMode::Normal);
is_computed() ? SerializationMode::ResolvedValue
: SerializationMode::Normal);
}
return {};
}
@ -402,8 +402,8 @@ String CSSStyleProperties::get_property_value(StringView property_name) const
if (!maybe_property.has_value())
return {};
return maybe_property->value->to_string(
is_computed() ? CSSStyleValue::SerializationMode::ResolvedValue
: CSSStyleValue::SerializationMode::Normal);
is_computed() ? SerializationMode::ResolvedValue
: SerializationMode::Normal);
}
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertypriority
@ -1109,7 +1109,7 @@ String CSSStyleProperties::serialized() const
// NB: There are no shorthands for custom properties.
// 5. Let value be the result of invoking serialize a CSS value of declaration.
auto value = declaration.value.value->to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal);
auto value = declaration.value.value->to_string(Web::CSS::SerializationMode::Normal);
// 6. Let serialized declaration be the result of invoking serialize a CSS declaration with property name property, value value,
// and the important flag set if declaration has its important flag set.
@ -1137,7 +1137,7 @@ String CSSStyleProperties::serialized() const
// FIXME: 4. Shorthand loop: For each shorthand in shorthands, follow these substeps: ...
// 5. Let value be the result of invoking serialize a CSS value of declaration.
auto value = declaration.value->to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal);
auto value = declaration.value->to_string(Web::CSS::SerializationMode::Normal);
// 6. Let serialized declaration be the result of invoking serialize a CSS declaration with property name property, value value,
// and the important flag set if declaration has its important flag set.

View file

@ -22,6 +22,7 @@
#include <LibURL/URL.h>
#include <LibWeb/CSS/Keyword.h>
#include <LibWeb/CSS/Length.h>
#include <LibWeb/CSS/SerializationMode.h>
#include <LibWeb/Forward.h>
namespace Web::CSS {
@ -385,10 +386,6 @@ public:
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; }
Keyword to_keyword() const;
enum class SerializationMode {
Normal,
ResolvedValue,
};
virtual String to_string(SerializationMode) const = 0;
[[nodiscard]] int to_font_weight() const;
@ -432,6 +429,6 @@ template<>
struct AK::Formatter<Web::CSS::CSSStyleValue> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::CSSStyleValue const& style_value)
{
return Formatter<StringView>::format(builder, style_value.to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal));
return Formatter<StringView>::format(builder, style_value.to_string(Web::CSS::SerializationMode::Normal));
}
};

View file

@ -74,7 +74,7 @@ public:
}
},
[](NonnullRefPtr<CalculatedStyleValue const> const& calculated) {
return calculated->to_string(CSSStyleValue::SerializationMode::Normal);
return calculated->to_string(SerializationMode::Normal);
});
}

View file

@ -182,7 +182,7 @@ Size ComputedProperties::size_value(PropertyID id) const
}
// FIXME: Support `fit-content(<length>)`
dbgln("FIXME: Unsupported size value: `{}`, treating as `auto`", value.to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("FIXME: Unsupported size value: `{}`, treating as `auto`", value.to_string(SerializationMode::Normal));
return Size::make_auto();
}
@ -310,7 +310,7 @@ CSSPixels ComputedProperties::compute_line_height(CSSPixelRect const& viewport_r
if (line_height.as_calculated().resolves_to_number()) {
auto resolved = line_height.as_calculated().resolve_number(context);
if (!resolved.has_value()) {
dbgln("FIXME: Failed to resolve calc() line-height (number): {}", line_height.as_calculated().to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("FIXME: Failed to resolve calc() line-height (number): {}", line_height.as_calculated().to_string(SerializationMode::Normal));
return CSSPixels::nearest_value_for(m_font_list->first().pixel_metrics().line_spacing());
}
return Length(resolved.value(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics);
@ -318,7 +318,7 @@ CSSPixels ComputedProperties::compute_line_height(CSSPixelRect const& viewport_r
auto resolved = line_height.as_calculated().resolve_length(context);
if (!resolved.has_value()) {
dbgln("FIXME: Failed to resolve calc() line-height: {}", line_height.as_calculated().to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("FIXME: Failed to resolve calc() line-height: {}", line_height.as_calculated().to_string(SerializationMode::Normal));
return CSSPixels::nearest_value_for(m_font_list->first().pixel_metrics().line_spacing());
}
return resolved->to_px(viewport_rect, font_metrics, root_font_metrics);
@ -358,13 +358,13 @@ float ComputedProperties::resolve_opacity_value(CSSStyleValue const& value)
if (maybe_percentage.has_value())
unclamped_opacity = maybe_percentage->as_fraction();
else
dbgln("Unable to resolve calc() as opacity (percentage): {}", value.to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("Unable to resolve calc() as opacity (percentage): {}", value.to_string(SerializationMode::Normal));
} else if (calculated.resolves_to_number()) {
auto maybe_number = value.as_calculated().resolve_number(context);
if (maybe_number.has_value())
unclamped_opacity = maybe_number.value();
else
dbgln("Unable to resolve calc() as opacity (number): {}", value.to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("Unable to resolve calc() as opacity (number): {}", value.to_string(SerializationMode::Normal));
}
} else if (value.is_percentage()) {
unclamped_opacity = value.as_percentage().percentage().as_fraction();
@ -938,14 +938,14 @@ ComputedProperties::ContentDataAndQuoteNestingLevel ComputedProperties::content(
quote_nesting_level--;
break;
default:
dbgln("`{}` is not supported in `content` (yet?)", item->to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("`{}` is not supported in `content` (yet?)", item->to_string(SerializationMode::Normal));
break;
}
} else if (item->is_counter()) {
builder.append(item->as_counter().resolve(element));
} else {
// TODO: Implement images, and other things.
dbgln("`{}` is not supported in `content` (yet?)", item->to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("`{}` is not supported in `content` (yet?)", item->to_string(SerializationMode::Normal));
}
}
content_data.type = ContentData::Type::String;
@ -959,7 +959,7 @@ ComputedProperties::ContentDataAndQuoteNestingLevel ComputedProperties::content(
} else if (item->is_counter()) {
alt_text_builder.append(item->as_counter().resolve(element));
} else {
dbgln("`{}` is not supported in `content` alt-text (yet?)", item->to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("`{}` is not supported in `content` alt-text (yet?)", item->to_string(SerializationMode::Normal));
}
}
content_data.alt_text = MUST(alt_text_builder.to_string());
@ -1048,7 +1048,7 @@ Vector<TextDecorationLine> ComputedProperties::text_decoration_line() const
return { keyword_to_text_decoration_line(value.to_keyword()).release_value() };
}
dbgln("FIXME: Unsupported value for text-decoration-line: {}", value.to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("FIXME: Unsupported value for text-decoration-line: {}", value.to_string(SerializationMode::Normal));
return {};
}
@ -1686,7 +1686,7 @@ Containment ComputedProperties::contain() const
containment.paint_containment = true;
break;
default:
dbgln("`{}` is not supported in `contain` (yet?)", item->to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("`{}` is not supported in `contain` (yet?)", item->to_string(SerializationMode::Normal));
break;
}
}
@ -1789,7 +1789,7 @@ Vector<CounterData> ComputedProperties::counter_data(PropertyID property_id) con
if (maybe_int.has_value())
data.value = AK::clamp_to<i32>(*maybe_int);
} else {
dbgln("Unimplemented type for {} integer value: '{}'", string_from_property_id(property_id), counter.value->to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("Unimplemented type for {} integer value: '{}'", string_from_property_id(property_id), counter.value->to_string(SerializationMode::Normal));
}
}
result.append(move(data));
@ -1800,7 +1800,7 @@ Vector<CounterData> ComputedProperties::counter_data(PropertyID property_id) con
if (value.to_keyword() == Keyword::None)
return {};
dbgln("Unhandled type for {} value: '{}'", string_from_property_id(property_id), value.to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("Unhandled type for {} value: '{}'", string_from_property_id(property_id), value.to_string(SerializationMode::Normal));
return {};
}

View file

@ -82,7 +82,7 @@ GC::Ref<FontFace> FontFace::construct_impl(JS::Realm& realm, String family, Font
font_face->reject_status_promise(WebIDL::SyntaxError::create(realm, MUST(String::formatted("FontFace constructor: Invalid {}", to_string(descriptor_id)))));
return {};
}
return result->to_string(CSSStyleValue::SerializationMode::Normal);
return result->to_string(SerializationMode::Normal);
};
font_face->m_family = try_parse_descriptor(DescriptorID::FontFamily, family);
font_face->m_style = try_parse_descriptor(DescriptorID::FontStyle, descriptors.style);
@ -224,7 +224,7 @@ WebIDL::ExceptionOr<void> FontFace::set_family(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-family property
}
m_family = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_family = property->to_string(SerializationMode::Normal);
return {};
}
@ -244,7 +244,7 @@ WebIDL::ExceptionOr<void> FontFace::set_style(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-style property
}
m_style = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_style = property->to_string(SerializationMode::Normal);
return {};
}
@ -264,7 +264,7 @@ WebIDL::ExceptionOr<void> FontFace::set_weight(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-weight property
}
m_weight = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_weight = property->to_string(SerializationMode::Normal);
return {};
}
@ -285,7 +285,7 @@ WebIDL::ExceptionOr<void> FontFace::set_stretch(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
}
m_stretch = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_stretch = property->to_string(SerializationMode::Normal);
return {};
}
@ -305,7 +305,7 @@ WebIDL::ExceptionOr<void> FontFace::set_unicode_range(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
}
m_unicode_range = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_unicode_range = property->to_string(SerializationMode::Normal);
return {};
}
@ -325,7 +325,7 @@ WebIDL::ExceptionOr<void> FontFace::set_feature_settings(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
}
m_feature_settings = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_feature_settings = property->to_string(SerializationMode::Normal);
return {};
}
@ -345,7 +345,7 @@ WebIDL::ExceptionOr<void> FontFace::set_variation_settings(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
}
m_variation_settings = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_variation_settings = property->to_string(SerializationMode::Normal);
return {};
}
@ -365,7 +365,7 @@ WebIDL::ExceptionOr<void> FontFace::set_display(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
}
m_display = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_display = property->to_string(SerializationMode::Normal);
return {};
}
@ -385,7 +385,7 @@ WebIDL::ExceptionOr<void> FontFace::set_ascent_override(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
}
m_ascent_override = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_ascent_override = property->to_string(SerializationMode::Normal);
return {};
}
@ -405,7 +405,7 @@ WebIDL::ExceptionOr<void> FontFace::set_descent_override(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
}
m_descent_override = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_descent_override = property->to_string(SerializationMode::Normal);
return {};
}
@ -425,7 +425,7 @@ WebIDL::ExceptionOr<void> FontFace::set_line_gap_override(String const& string)
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
}
m_line_gap_override = property->to_string(CSSStyleValue::SerializationMode::Normal);
m_line_gap_override = property->to_string(SerializationMode::Normal);
return {};
}

View file

@ -270,7 +270,7 @@ RefPtr<CSSStyleValue const> interpolate_transform(DOM::Element& element, CSSStyl
} else if (calculated.resolves_to_number()) {
values.append(NumberPercentage { calculated });
} else {
dbgln("Calculation `{}` inside {} transform-function is not a recognized type", calculated.to_string(CSSStyleValue::SerializationMode::Normal), to_string(transformation.transform_function()));
dbgln("Calculation `{}` inside {} transform-function is not a recognized type", calculated.to_string(SerializationMode::Normal), to_string(transformation.transform_function()));
return {};
}
break;

View file

@ -31,7 +31,7 @@ String MediaFeatureValue::to_string() const
[](ResolutionOrCalculated const& resolution) { return resolution.to_string(); },
[](IntegerOrCalculated const& integer) {
if (integer.is_calculated())
return integer.calculated()->to_string(CSSStyleValue::SerializationMode::Normal);
return integer.calculated()->to_string(SerializationMode::Normal);
return String::number(integer.value());
});
}

View file

@ -1086,7 +1086,7 @@ RefPtr<CSSStyleValue const> Parser::parse_rect_value(TokenStream<ComponentValue>
if (!maybe_length.has_value())
return nullptr;
if (maybe_length.value().is_calculated()) {
dbgln("FIXME: Support calculated lengths in rect(): {}", maybe_length.value().calculated()->to_string(CSS::CSSStyleValue::SerializationMode::Normal));
dbgln("FIXME: Support calculated lengths in rect(): {}", maybe_length.value().calculated()->to_string(CSS::SerializationMode::Normal));
return nullptr;
}
params.append(maybe_length.value().value());

View file

@ -122,7 +122,7 @@ public:
String to_string() const
{
if (is_calculated())
return m_value.template get<NonnullRefPtr<CalculatedStyleValue const>>()->to_string(CSSStyleValue::SerializationMode::Normal);
return m_value.template get<NonnullRefPtr<CalculatedStyleValue const>>()->to_string(SerializationMode::Normal);
if (is_percentage())
return m_value.template get<Percentage>().to_string();
return m_value.template get<T>().to_string();

View file

@ -0,0 +1,16 @@
/*
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
namespace Web::CSS {
enum class SerializationMode : u8 {
Normal,
ResolvedValue,
};
}

View file

@ -1248,7 +1248,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
if (!resolved_end_property) {
if (resolved_start_property) {
computed_properties.set_animated_property(it.key, *resolved_start_property);
dbgln_if(LIBWEB_CSS_ANIMATION_DEBUG, "No end property for property {}, using {}", string_from_property_id(it.key), resolved_start_property->to_string(CSSStyleValue::SerializationMode::Normal));
dbgln_if(LIBWEB_CSS_ANIMATION_DEBUG, "No end property for property {}, using {}", string_from_property_id(it.key), resolved_start_property->to_string(SerializationMode::Normal));
}
continue;
}
@ -1267,11 +1267,11 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
}
if (auto next_value = interpolate_property(*effect->target(), it.key, *start, *end, progress_in_keyframe)) {
dbgln_if(LIBWEB_CSS_ANIMATION_DEBUG, "Interpolated value for property {} at {}: {} -> {} = {}", string_from_property_id(it.key), progress_in_keyframe, start->to_string(CSSStyleValue::SerializationMode::Normal), end->to_string(CSSStyleValue::SerializationMode::Normal), next_value->to_string(CSSStyleValue::SerializationMode::Normal));
dbgln_if(LIBWEB_CSS_ANIMATION_DEBUG, "Interpolated value for property {} at {}: {} -> {} = {}", string_from_property_id(it.key), progress_in_keyframe, start->to_string(SerializationMode::Normal), end->to_string(SerializationMode::Normal), next_value->to_string(SerializationMode::Normal));
computed_properties.set_animated_property(it.key, *next_value);
} else {
// If interpolate_property() fails, the element should not be rendered
dbgln_if(LIBWEB_CSS_ANIMATION_DEBUG, "Interpolated value for property {} at {}: {} -> {} is invalid", string_from_property_id(it.key), progress_in_keyframe, start->to_string(CSSStyleValue::SerializationMode::Normal), end->to_string(CSSStyleValue::SerializationMode::Normal));
dbgln_if(LIBWEB_CSS_ANIMATION_DEBUG, "Interpolated value for property {} at {}: {} -> {} is invalid", string_from_property_id(it.key), progress_in_keyframe, start->to_string(SerializationMode::Normal), end->to_string(SerializationMode::Normal));
computed_properties.set_animated_property(PropertyID::Visibility, CSSKeywordValue::create(Keyword::Hidden));
}
}
@ -1556,7 +1556,7 @@ void StyleComputer::start_needed_transitions(ComputedProperties const& previous_
// there is a matching transition-property value,
// and the end value of the running transition is not equal to the value of the property in the after-change style, then:
if (has_running_transition && matching_transition_properties.has_value() && !existing_transition->transition_end_value()->equals(after_change_value)) {
dbgln_if(CSS_TRANSITIONS_DEBUG, "Transition step 4. existing end value = {}, after change value = {}", existing_transition->transition_end_value()->to_string(CSSStyleValue::SerializationMode::Normal), after_change_value.to_string(CSSStyleValue::SerializationMode::Normal));
dbgln_if(CSS_TRANSITIONS_DEBUG, "Transition step 4. existing end value = {}, after change value = {}", existing_transition->transition_end_value()->to_string(SerializationMode::Normal), after_change_value.to_string(SerializationMode::Normal));
// 1. If the current value of the property in the running transition is equal to the value of the property in the after-change style,
// or if these two values are not transitionable,
// then implementations must cancel the running transition.
@ -2686,7 +2686,7 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::Element& elem
return OptionalNone {};
if (animation_name->is_string())
return animation_name->as_string().string_value().to_string();
return animation_name->to_string(CSSStyleValue::SerializationMode::Normal);
return animation_name->to_string(SerializationMode::Normal);
}();
if (animation_name.has_value()) {

View file

@ -177,7 +177,7 @@ struct ColorStopListElement {
using LinearColorStopListElement = ColorStopListElement<LengthPercentage>;
using AngularColorStopListElement = ColorStopListElement<AnglePercentage>;
static void serialize_color_stop_list(StringBuilder& builder, auto const& color_stop_list, CSSStyleValue::SerializationMode mode)
static void serialize_color_stop_list(StringBuilder& builder, auto const& color_stop_list, SerializationMode mode)
{
bool first = true;
for (auto const& element : color_stop_list) {

View file

@ -34,7 +34,7 @@ Gfx::Path Inset::to_path(CSSPixelRect reference_box, Layout::Node const& node) c
return path_from_resolved_rect(top, right, bottom, left);
}
String Inset::to_string(CSSStyleValue::SerializationMode) const
String Inset::to_string(SerializationMode) const
{
return MUST(String::formatted("inset({} {} {} {})", inset_box.top(), inset_box.right(), inset_box.bottom(), inset_box.left()));
}
@ -49,7 +49,7 @@ Gfx::Path Xywh::to_path(CSSPixelRect reference_box, Layout::Node const& node) co
return path_from_resolved_rect(top, right, bottom, left);
}
String Xywh::to_string(CSSStyleValue::SerializationMode) const
String Xywh::to_string(SerializationMode) const
{
return MUST(String::formatted("xywh({} {} {} {})", x, y, width, height));
}
@ -68,7 +68,7 @@ Gfx::Path Rect::to_path(CSSPixelRect reference_box, Layout::Node const& node) co
return path_from_resolved_rect(top, max(right, left), max(bottom, top), left);
}
String Rect::to_string(CSSStyleValue::SerializationMode) const
String Rect::to_string(SerializationMode) const
{
return MUST(String::formatted("rect({} {} {} {})", box.top(), box.right(), box.bottom(), box.left()));
}
@ -123,7 +123,7 @@ Gfx::Path Circle::to_path(CSSPixelRect reference_box, Layout::Node const& node)
return path;
}
String Circle::to_string(CSSStyleValue::SerializationMode mode) const
String Circle::to_string(SerializationMode mode) const
{
return MUST(String::formatted("circle({} at {})", radius_to_string(radius), position->to_string(mode)));
}
@ -168,7 +168,7 @@ Gfx::Path Ellipse::to_path(CSSPixelRect reference_box, Layout::Node const& node)
return path;
}
String Ellipse::to_string(CSSStyleValue::SerializationMode mode) const
String Ellipse::to_string(SerializationMode mode) const
{
return MUST(String::formatted("ellipse({} {} at {})", radius_to_string(radius_x), radius_to_string(radius_y), position->to_string(mode)));
}
@ -193,7 +193,7 @@ Gfx::Path Polygon::to_path(CSSPixelRect reference_box, Layout::Node const& node)
return path;
}
String Polygon::to_string(CSSStyleValue::SerializationMode) const
String Polygon::to_string(SerializationMode) const
{
StringBuilder builder;
builder.append("polygon("sv);

View file

@ -17,7 +17,7 @@ namespace Web::CSS {
struct Inset {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string(CSSStyleValue::SerializationMode) const;
String to_string(SerializationMode) const;
bool operator==(Inset const&) const = default;
@ -26,7 +26,7 @@ struct Inset {
struct Xywh {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string(CSSStyleValue::SerializationMode) const;
String to_string(SerializationMode) const;
bool operator==(Xywh const&) const = default;
@ -38,7 +38,7 @@ struct Xywh {
struct Rect {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string(CSSStyleValue::SerializationMode) const;
String to_string(SerializationMode) const;
bool operator==(Rect const&) const = default;
@ -54,7 +54,7 @@ using ShapeRadius = Variant<LengthPercentage, FitSide>;
struct Circle {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string(CSSStyleValue::SerializationMode) const;
String to_string(SerializationMode) const;
bool operator==(Circle const&) const = default;
@ -64,7 +64,7 @@ struct Circle {
struct Ellipse {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string(CSSStyleValue::SerializationMode) const;
String to_string(SerializationMode) const;
bool operator==(Ellipse const&) const = default;
@ -81,7 +81,7 @@ struct Polygon {
};
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string(CSSStyleValue::SerializationMode) const;
String to_string(SerializationMode) const;
bool operator==(Polygon const&) const = default;

View file

@ -130,17 +130,17 @@ static NonnullRefPtr<CalculationNode const> simplify_2_children(T const& origina
return original;
}
static String serialize_a_calculation_tree(CalculationNode const&, CalculationContext const&, CSSStyleValue::SerializationMode);
static String serialize_a_calculation_tree(CalculationNode const&, CalculationContext const&, SerializationMode);
// https://drafts.csswg.org/css-values-4/#serialize-a-math-function
static String serialize_a_math_function(CalculationNode const& fn, CalculationContext const& context, CSSStyleValue::SerializationMode serialization_mode)
static String serialize_a_math_function(CalculationNode const& fn, CalculationContext const& context, SerializationMode serialization_mode)
{
// To serialize a math function fn:
// 1. If the root of the calculation tree fn represents is a numeric value (number, percentage, or dimension), and
// the serialization being produced is of a computed value or later, then clamp the value to the range allowed
// for its context (if necessary), then serialize the value as normal and return the result.
if (fn.type() == CalculationNode::Type::Numeric && serialization_mode == CSSStyleValue::SerializationMode::ResolvedValue) {
if (fn.type() == CalculationNode::Type::Numeric && serialization_mode == SerializationMode::ResolvedValue) {
// FIXME: Clamp the value. Note that we might have an infinite/nan value here.
return static_cast<NumericCalculationNode const&>(fn).value_to_string();
}
@ -311,7 +311,7 @@ static Vector<NonnullRefPtr<CalculationNode const>> sort_a_calculations_children
}
// https://drafts.csswg.org/css-values-4/#serialize-a-calculation-tree
static String serialize_a_calculation_tree(CalculationNode const& root, CalculationContext const& context, CSSStyleValue::SerializationMode serialization_mode)
static String serialize_a_calculation_tree(CalculationNode const& root, CalculationContext const& context, SerializationMode serialization_mode)
{
// 1. Let root be the root node of the calculation tree.
// NOTE: Already the case.

View file

@ -90,7 +90,7 @@ static String generate_a_counter_representation(CSSStyleValue const& counter_sty
}
// FIXME: Handle `symbols()` function for counter_style.
dbgln("FIXME: Unsupported counter style '{}'", counter_style.to_string(CSSStyleValue::SerializationMode::Normal));
dbgln("FIXME: Unsupported counter style '{}'", counter_style.to_string(SerializationMode::Normal));
return MUST(String::formatted("{}", value));
}

View file

@ -10,7 +10,7 @@ namespace Web::CSS {
String EdgeStyleValue::to_string(SerializationMode mode) const
{
if (mode == CSSStyleValue::SerializationMode::ResolvedValue) {
if (mode == SerializationMode::ResolvedValue) {
// FIXME: Figure out how to get the proper calculation context here
CalculationContext context {};
return resolved_value(context)->offset().to_string();

View file

@ -426,7 +426,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
};
Vector<NameAndValue> properties;
as<DOM::Element>(*layout_node.dom_node()).computed_properties()->for_each_property([&](auto property_id, auto& value) {
properties.append({ CSS::string_from_property_id(property_id), value.to_string(CSS::CSSStyleValue::SerializationMode::Normal) });
properties.append({ CSS::string_from_property_id(property_id), value.to_string(CSS::SerializationMode::Normal) });
});
quick_sort(properties, [](auto& a, auto& b) { return a.name < b.name; });
@ -827,14 +827,14 @@ void dump_style_properties(StringBuilder& builder, CSS::CSSStyleProperties const
builder.appendff("Declarations ({}):\n", declaration.length());
for (auto& property : declaration.properties()) {
indent(builder, indent_levels);
builder.appendff(" {}: '{}'", CSS::string_from_property_id(property.property_id), property.value->to_string(CSS::CSSStyleValue::SerializationMode::Normal));
builder.appendff(" {}: '{}'", CSS::string_from_property_id(property.property_id), property.value->to_string(CSS::SerializationMode::Normal));
if (property.important == CSS::Important::Yes)
builder.append(" \033[31;1m!important\033[0m"sv);
builder.append('\n');
}
for (auto& property : declaration.custom_properties()) {
indent(builder, indent_levels);
builder.appendff(" {}: '{}'", property.key, property.value.value->to_string(CSS::CSSStyleValue::SerializationMode::Normal));
builder.appendff(" {}: '{}'", property.key, property.value.value->to_string(CSS::SerializationMode::Normal));
if (property.value.important == CSS::Important::Yes)
builder.append(" \033[31;1m!important\033[0m"sv);
builder.append('\n');
@ -847,7 +847,7 @@ void dump_descriptors(StringBuilder& builder, CSS::CSSDescriptors const& descrip
builder.appendff("Declarations ({}):\n", descriptors.length());
for (auto const& descriptor : descriptors.descriptors()) {
indent(builder, indent_levels);
builder.appendff(" {}: '{}'", CSS::to_string(descriptor.descriptor_id), descriptor.value->to_string(CSS::CSSStyleValue::SerializationMode::Normal));
builder.appendff(" {}: '{}'", CSS::to_string(descriptor.descriptor_id), descriptor.value->to_string(CSS::SerializationMode::Normal));
builder.append('\n');
}
}

View file

@ -646,7 +646,7 @@ Vector<GC::Ref<DOM::Node>> clear_the_value(FlyString const& command, GC::Ref<DOM
auto new_style_value = CSS::StyleValueList::create(move(new_values), value_list.separator());
MUST(inline_style->set_property(
string_from_property_id(CSS::PropertyID::TextDecoration),
new_style_value->to_string(CSS::CSSStyleValue::SerializationMode::Normal),
new_style_value->to_string(CSS::SerializationMode::Normal),
{}));
};
if (command == CommandNames::strikethrough)
@ -1184,7 +1184,7 @@ Optional<String> effective_command_value(GC::Ptr<DOM::Node> node, FlyString cons
auto resolved_value = resolved_background_color();
if (!resolved_value.has_value())
return {};
return resolved_value.value()->to_string(CSS::CSSStyleValue::SerializationMode::ResolvedValue);
return resolved_value.value()->to_string(CSS::SerializationMode::ResolvedValue);
}
// 5. If command is "subscript" or "superscript":
@ -1264,7 +1264,7 @@ Optional<String> effective_command_value(GC::Ptr<DOM::Node> node, FlyString cons
auto optional_value = resolved_value(*node, command_definition.relevant_css_property.value());
if (!optional_value.has_value())
return {};
return optional_value.value()->to_string(CSS::CSSStyleValue::SerializationMode::ResolvedValue);
return optional_value.value()->to_string(CSS::SerializationMode::ResolvedValue);
}
// https://w3c.github.io/editing/docs/execCommand/#first-equivalent-point
@ -2741,7 +2741,7 @@ void justify_the_selection(DOM::Document& document, JustifyAlignment alignment)
&& element->inline_style()->length() == 1) {
auto text_align = element->inline_style()->property(CSS::PropertyID::TextAlign);
if (text_align.has_value()) {
auto align_value = text_align.value().value->to_string(CSS::CSSStyleValue::SerializationMode::Normal);
auto align_value = text_align.value().value->to_string(CSS::SerializationMode::Normal);
if (align_value.equals_ignoring_ascii_case(alignment_keyword))
++number_of_matching_attributes;
}
@ -3927,7 +3927,7 @@ Optional<String> specified_command_value(GC::Ref<DOM::Element> element, FlyStrin
// that it sets property to.
auto style_value = property_in_style_attribute(element, property.value());
if (style_value.has_value())
return style_value.value()->to_string(CSS::CSSStyleValue::SerializationMode::Normal);
return style_value.value()->to_string(CSS::SerializationMode::Normal);
// 11. If element is a font element that has an attribute whose effect is to create a presentational hint for
// property, return the value that the hint sets property to. (For a size of 7, this will be the non-CSS value
@ -3938,7 +3938,7 @@ Optional<String> specified_command_value(GC::Ref<DOM::Element> element, FlyStrin
font_element.apply_presentational_hints(cascaded_properties);
auto property_value = cascaded_properties->property(property.value());
if (property_value)
return property_value->to_string(CSS::CSSStyleValue::SerializationMode::Normal);
return property_value->to_string(CSS::SerializationMode::Normal);
}
// 12. If element is in the following list, and property is equal to the CSS property name listed for it, return the

View file

@ -34,10 +34,10 @@ public:
auto font_size = font_style_value.longhand(CSS::PropertyID::FontSize);
auto font_family = font_style_value.longhand(CSS::PropertyID::FontFamily);
return ByteString::formatted("{} {} {} {}",
font_style->to_string(CSS::CSSStyleValue::SerializationMode::Normal),
font_weight->to_string(CSS::CSSStyleValue::SerializationMode::Normal),
font_size->to_string(CSS::CSSStyleValue::SerializationMode::Normal),
font_family->to_string(CSS::CSSStyleValue::SerializationMode::Normal));
font_style->to_string(CSS::SerializationMode::Normal),
font_weight->to_string(CSS::SerializationMode::Normal),
font_size->to_string(CSS::SerializationMode::Normal),
font_family->to_string(CSS::SerializationMode::Normal));
}
void set_font(StringView font)

View file

@ -315,7 +315,7 @@ void ConnectionFromClient::debug_request(u64 page_id, ByteString request, ByteSt
dbgln("+ Element {}", element->debug_description());
for (size_t i = 0; i < Web::CSS::ComputedProperties::number_of_properties; ++i) {
auto property = styles->maybe_null_property(static_cast<Web::CSS::PropertyID>(i));
dbgln("| {} = {}", Web::CSS::string_from_property_id(static_cast<Web::CSS::PropertyID>(i)), property ? property->to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal) : ""_string);
dbgln("| {} = {}", Web::CSS::string_from_property_id(static_cast<Web::CSS::PropertyID>(i)), property ? property->to_string(Web::CSS::SerializationMode::Normal) : ""_string);
}
dbgln("---");
}
@ -483,7 +483,7 @@ void ConnectionFromClient::inspect_dom_node(u64 page_id, WebView::DOMNodePropert
properties->for_each_property([&](auto property_id, auto& value) {
serialized.set(
Web::CSS::string_from_property_id(property_id),
value.to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal));
value.to_string(Web::CSS::SerializationMode::Normal));
});
return serialized;
@ -517,12 +517,12 @@ void ConnectionFromClient::inspect_dom_node(u64 page_id, WebView::DOMNodePropert
serialized.set("border-bottom-width"sv, box_model.border.bottom.to_double());
serialized.set("border-left-width"sv, box_model.border.left.to_double());
serialized.set("box-sizing"sv, properties->property(Web::CSS::PropertyID::BoxSizing).to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal));
serialized.set("display"sv, properties->property(Web::CSS::PropertyID::Display).to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal));
serialized.set("float"sv, properties->property(Web::CSS::PropertyID::Float).to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal));
serialized.set("line-height"sv, properties->property(Web::CSS::PropertyID::LineHeight).to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal));
serialized.set("position"sv, properties->property(Web::CSS::PropertyID::Position).to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal));
serialized.set("z-index"sv, properties->property(Web::CSS::PropertyID::ZIndex).to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal));
serialized.set("box-sizing"sv, properties->property(Web::CSS::PropertyID::BoxSizing).to_string(Web::CSS::SerializationMode::Normal));
serialized.set("display"sv, properties->property(Web::CSS::PropertyID::Display).to_string(Web::CSS::SerializationMode::Normal));
serialized.set("float"sv, properties->property(Web::CSS::PropertyID::Float).to_string(Web::CSS::SerializationMode::Normal));
serialized.set("line-height"sv, properties->property(Web::CSS::PropertyID::LineHeight).to_string(Web::CSS::SerializationMode::Normal));
serialized.set("position"sv, properties->property(Web::CSS::PropertyID::Position).to_string(Web::CSS::SerializationMode::Normal));
serialized.set("z-index"sv, properties->property(Web::CSS::PropertyID::ZIndex).to_string(Web::CSS::SerializationMode::Normal));
return serialized;
};

View file

@ -1378,7 +1378,7 @@ Messages::WebDriverClient::GetElementCssValueResponse WebDriverConnection::get_e
// computed value of parameter URL variables["property name"] from element's style declarations.
if (auto property = Web::CSS::property_id_from_string(name); property.has_value()) {
if (auto computed_properties = element->computed_properties())
computed_value = computed_properties->property(property.value()).to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal);
computed_value = computed_properties->property(property.value()).to_string(Web::CSS::SerializationMode::Normal);
}
}
// -> Otherwise