mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:58:11 +00:00
LibWeb: Add serialize_a_srgb_value()
This moves the logic from ColorStyleValue::to_string() to a standalone function.
This commit is contained in:
parent
aa9f7cc597
commit
8603541e56
3 changed files with 23 additions and 7 deletions
|
@ -1071,15 +1071,9 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberSumPartW
|
|||
return value->resolve(layout_node, percentage_basis);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/css-color-4/#serializing-sRGB-values
|
||||
String ColorStyleValue::to_string() const
|
||||
{
|
||||
// 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);
|
||||
return serialize_a_srgb_value(m_color);
|
||||
}
|
||||
|
||||
bool ColorStyleValue::equals(StyleValue const& other) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue