LibWeb: Note and fix Gfx related quirk in ColorStyleValue::to_string

This commit is contained in:
stelar7 2022-05-08 12:17:39 +02:00 committed by Linus Groh
commit 4359d4eb5d
Notes: sideshowbarker 2024-07-17 11:09:17 +09:00

View file

@ -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);
}