Bug 1347164 - serialize colors using "rgba()" as the color-function, if they have a non-opaque alpha channel. r=dholbert a=gchang
authorJerryShih <hshih@mozilla.com>
Tue, 21 Mar 2017 20:17:00 +0100
changeset 395337 786d0d85a2c3df3348cf7deaf6d2e69e8e52c9d7
parent 395336 c695dd62fdde3fdc59d58d0191d6391c20f39ff5
child 395338 88faae10767178868b55354cc46ada5027bbe89a
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert, gchang
bugs1347164
milestone54.0a2
Bug 1347164 - serialize colors using "rgba()" as the color-function, if they have a non-opaque alpha channel. r=dholbert a=gchang MozReview-Commit-ID: 44T8gy7UWFJ
layout/style/nsCSSValue.cpp
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -1656,23 +1656,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);