mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibWeb: Make ColorStyleValue serialization spec compliant
[CSS Color 4] tells us to use either rgb() or rgba() notation, depending on the color's alpha value.
This commit is contained in:
parent
0d73487204
commit
956968d4b2
2 changed files with 10 additions and 1 deletions
|
@ -387,4 +387,13 @@ void ImageStyleValue::resource_did_load()
|
||||||
if (m_document && m_document->browsing_context())
|
if (m_document && m_document->browsing_context())
|
||||||
m_document->browsing_context()->set_needs_display({});
|
m_document->browsing_context()->set_needs_display({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://www.w3.org/TR/css-color-4/#serializing-sRGB-values
|
||||||
|
String ColorStyleValue::to_string() const
|
||||||
|
{
|
||||||
|
if (m_color.alpha() == 1)
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -683,7 +683,7 @@ public:
|
||||||
virtual ~ColorStyleValue() override { }
|
virtual ~ColorStyleValue() override { }
|
||||||
|
|
||||||
Color color() const { return m_color; }
|
Color color() const { return m_color; }
|
||||||
virtual String to_string() const override { return m_color.to_string(); }
|
virtual String to_string() const override;
|
||||||
virtual bool has_color() const override { return true; }
|
virtual bool has_color() const override { return true; }
|
||||||
virtual Color to_color(Layout::NodeWithStyle const&) const override { return m_color; }
|
virtual Color to_color(Layout::NodeWithStyle const&) const override { return m_color; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue