From a0cd6dd607a4cad1305617d7b7069422e7583a41 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 18 Feb 2025 10:53:27 +0000 Subject: [PATCH] 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. --- Libraries/LibWeb/CSS/CalculatedOr.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/CSS/CalculatedOr.h b/Libraries/LibWeb/CSS/CalculatedOr.h index dda9590d496..ee6d564fe4a 100644 --- a/Libraries/LibWeb/CSS/CalculatedOr.h +++ b/Libraries/LibWeb/CSS/CalculatedOr.h @@ -67,10 +67,17 @@ public: String to_string() const { - if (is_calculated()) - return m_value.template get>()->to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal); - - return m_value.template get().to_string(); + return m_value.visit( + [](T const& t) { + if constexpr (IsArithmetic) { + return String::number(t); + } else { + return t.to_string(); + } + }, + [](NonnullRefPtr const& calculated) { + return calculated->to_string(CSSStyleValue::SerializationMode::Normal); + }); } bool operator==(CalculatedOr const& other) const