LibWeb/CSS: Merge TranslationStyleValue into TransformationStyleValue

As with ScaleStyleValue, the serialization is the only unique part of
this class, and we can just move it over.
This commit is contained in:
Sam Atkins 2025-01-15 16:48:44 +00:00 committed by Andreas Kling
commit 03a4ecce19
Notes: github-actions[bot] 2025-01-17 09:15:27 +00:00
9 changed files with 36 additions and 125 deletions

View file

@ -87,6 +87,32 @@ String TransformationStyleValue::to_string(SerializationMode mode) const
}
return builder.to_string_without_validation();
}
if (m_properties.property == PropertyID::Translate) {
auto resolve_to_string = [mode](CSSStyleValue const& value) -> Optional<String> {
if (value.is_length()) {
if (value.as_length().length().raw_value() == 0)
return {};
}
if (value.is_percentage()) {
if (value.as_percentage().percentage().value() == 0)
return {};
}
return value.to_string(mode);
};
auto x_value = resolve_to_string(m_properties.values[0]);
auto y_value = resolve_to_string(m_properties.values[1]);
// FIXME: 3D translation
StringBuilder builder;
builder.append(x_value.value_or("0px"_string));
if (y_value.has_value()) {
builder.append(" "sv);
builder.append(y_value.value());
}
return builder.to_string_without_validation();
}
StringBuilder builder;
builder.append(CSS::to_string(m_properties.transform_function));