Bug 1347164 - serialize colors using "rgba()" as the color-function, if they have a non-opaque alpha channel. r=dholbert
authorJerryShih <hshih@mozilla.com>
Mon, 20 Mar 2017 17:26:05 +0800
changeset 399052 049b04f008d612b0775bdd3998093e04a59254f8
parent 399051 db053627611a25450ae31cf281240d882e6cde4b
child 399053 c7aff74601c8f3ce1ca6f68ade7748cfd736a973
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1347164
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1347164 - serialize colors using "rgba()" as the color-function, if they have a non-opaque alpha channel. r=dholbert MozReview-Commit-ID: 44T8gy7UWFJ
layout/style/nsCSSValue.cpp
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -1675,23 +1675,27 @@ nsCSSValue::AppendToString(nsCSSProperty
     }
   }
   else if (IsNumericColorUnit(unit)) {
     if (aSerialization == eNormalized ||
         unit == eCSSUnit_RGBColor ||
         unit == eCSSUnit_RGBAColor) {
       nscolor color = GetColorValue();
       // For brevity, we omit the alpha component if it's equal to 255 (full
-      // opaque). Also, we try to preserve the author-specified function name,
-      // unless it's rgba() and we're omitting the alpha component - then we
-      // use rgb().
+      // opaque). Also, we use "rgba" rather than "rgb" when the color includes
+      // the non-opaque alpha value, for backwards-compat (even though they're
+      // aliases as of css-color-4).
+      // e.g.:
+      //   rgba(1, 2, 3, 1.0) => rgb(1, 2, 3)
+      //   rgba(1, 2, 3, 0.5) => rgba(1, 2, 3, 0.5)
+
       uint8_t a = NS_GET_A(color);
       bool showAlpha = (a != 255);
 
-      if (unit == eCSSUnit_RGBAColor && showAlpha) {
+      if (showAlpha) {
         aResult.AppendLiteral("rgba(");
       } else {
         aResult.AppendLiteral("rgb(");
       }
 
       NS_NAMED_LITERAL_STRING(comma, ", ");
 
       aResult.AppendInt(NS_GET_R(color), 10);