summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-10-03 17:56:01 +0200
committerAndreas Kling <kling@serenityos.org>2021-10-03 17:59:15 +0200
commit956968d4b28c86883dee5df0e178826f8be7e418 (patch)
treecb6e5abe6773fdcabfa006eb358c46d296a327d4
parent0d73487204dec68920a833bf735711b38c349f14 (diff)
downloadserenity-956968d4b28c86883dee5df0e178826f8be7e418.zip
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.
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.cpp9
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h2
2 files changed, 10 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
index 2960d6f30e..99c4fe8306 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -387,4 +387,13 @@ void ImageStyleValue::resource_did_load()
if (m_document && m_document->browsing_context())
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);
+}
+
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 4ab90d8dfc..f12954a846 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -683,7 +683,7 @@ public:
virtual ~ColorStyleValue() override { }
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 Color to_color(Layout::NodeWithStyle const&) const override { return m_color; }