LibWeb/CSS: Support CalculatedOr::to_string() for integers and floats

IntegerOrCalculated and NumberOrCalculated's T types don't have a
to_string() method because they're i64 and double respectively, so use
String::number() for them instead.

Also rearrange this method to avoid checking the variant's contents
multiple times.
This commit is contained in:
Sam Atkins 2025-02-18 10:53:27 +00:00 committed by Andreas Kling
parent c77456a508
commit a0cd6dd607
Notes: github-actions[bot] 2025-02-28 12:51:55 +00:00

View file

@ -67,10 +67,17 @@ public:
String to_string() const
{
if (is_calculated())
return m_value.template get<NonnullRefPtr<CalculatedStyleValue>>()->to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal);
return m_value.template get<T>().to_string();
return m_value.visit(
[](T const& t) {
if constexpr (IsArithmetic<T>) {
return String::number(t);
} else {
return t.to_string();
}
},
[](NonnullRefPtr<CalculatedStyleValue> const& calculated) {
return calculated->to_string(CSSStyleValue::SerializationMode::Normal);
});
}
bool operator==(CalculatedOr<T> const& other) const