From 4359d4eb5d99518865e1344fa65d7ea3136726eb Mon Sep 17 00:00:00 2001 From: stelar7 Date: Sun, 8 May 2022 12:17:39 +0200 Subject: [PATCH] LibWeb: Note and fix Gfx related quirk in ColorStyleValue::to_string --- Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 188d78a344..eecd4aa489 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -1071,7 +1071,10 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberSumPartW // https://www.w3.org/TR/css-color-4/#serializing-sRGB-values String ColorStyleValue::to_string() const { - if (m_color.alpha() == 1) + // The serialized form is derived from the computed value and thus, uses either the rgb() or rgba() form + // (depending on whether the alpha is exactly 1, or not), with lowercase letters for the function name. + // NOTE: Since we use Gfx::Color, having an "alpha of 1" means its value is 255. + if (m_color.alpha() == 255) return String::formatted("rgb({}, {}, {})", m_color.red(), m_color.green(), m_color.blue()); return String::formatted("rgba({}, {}, {}, {})", m_color.red(), m_color.green(), m_color.blue(), (float)(m_color.alpha()) / 255.0f); }