Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(650)

Unified Diff: third_party/WebKit/Source/platform/graphics/Color.cpp

Issue 2608423002: Fix RGBA alpha parsing and serialization to adhere to W3 standard. (Closed)
Patch Set: NeedsRebaseline for failed layout tests Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/Color.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/Color.cpp b/third_party/WebKit/Source/platform/graphics/Color.cpp
index 3ad2e4d84d59cb85ee67ae9928e4615f93b9b2ee..3b406bf1a1addf7976e8fa71e0d6b7eb4ab519bc 100644
--- a/third_party/WebKit/Source/platform/graphics/Color.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Color.cpp
@@ -210,7 +210,16 @@ String Color::serializedAsCSSComponentValue() const {
result.appendNumber(static_cast<unsigned char>(blue()));
if (colorHasAlpha) {
result.append(", ");
- result.appendNumber(alpha() / 255.0f, 6);
+ // See <alphavalue> section in
+ // http://dev.w3.org/csswg/cssom/#serializing-css-values
+ int alphavalue = alpha();
+ float rounded = round(alphavalue * 100 / 255.0f) / 100;
+ if (round(rounded * 255) == alphavalue) {
+ result.appendNumber(rounded, 2);
+ } else {
+ rounded = round(alphavalue * 1000 / 255.0f) / 1000;
+ result.appendNumber(rounded, 3);
+ }
}
result.append(')');

Powered by Google App Engine
This is Rietveld 408576698