Bug 1302513 Part 5: Simplify nsCSSValue::AppendToString, now that aSerialization can only take one value. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 21 Jul 2017 18:07:14 -0700
changeset 613469 9e1ff9ae4d42c9029210c1b3a450a7243b4af326
parent 613460 96807b164a79ec618547c82ff4f764f659f2ae0c
child 613470 d12a58f58aa72792629e3872fa19a26d1c1c37e7
push id69813
push userbwerth@mozilla.com
push dateSat, 22 Jul 2017 01:08:09 +0000
bugs1302513
milestone56.0a1
Bug 1302513 Part 5: Simplify nsCSSValue::AppendToString, now that aSerialization can only take one value. MozReview-Commit-ID: 9qJOkJTzUY2
layout/style/nsCSSValue.cpp
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -1671,73 +1671,46 @@ nsCSSValue::AppendToString(nsCSSProperty
     nsAutoCString str;
     if (nsCSSProps::GetColorName(GetIntValue(), str)){
       AppendASCIItoUTF16(str, aResult);
     } else {
       MOZ_ASSERT(false, "bad color value");
     }
   }
   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 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 (showAlpha) {
-        aResult.AppendLiteral("rgba(");
-      } else {
-        aResult.AppendLiteral("rgb(");
-      }
-
-      NS_NAMED_LITERAL_STRING(comma, ", ");
-
-      aResult.AppendInt(NS_GET_R(color), 10);
-      aResult.Append(comma);
-      aResult.AppendInt(NS_GET_G(color), 10);
+    nscolor color = GetColorValue();
+    // For brevity, we omit the alpha component if it's equal to 255 (full
+    // 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 (showAlpha) {
+      aResult.AppendLiteral("rgba(");
+    } else {
+      aResult.AppendLiteral("rgb(");
+    }
+
+    NS_NAMED_LITERAL_STRING(comma, ", ");
+
+    aResult.AppendInt(NS_GET_R(color), 10);
+    aResult.Append(comma);
+    aResult.AppendInt(NS_GET_G(color), 10);
+    aResult.Append(comma);
+    aResult.AppendInt(NS_GET_B(color), 10);
+    if (showAlpha) {
       aResult.Append(comma);
-      aResult.AppendInt(NS_GET_B(color), 10);
-      if (showAlpha) {
-        aResult.Append(comma);
-        aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
-      }
-      aResult.Append(char16_t(')'));
-    } else if (eCSSUnit_HexColor == unit ||
-               eCSSUnit_HexColorAlpha == unit) {
-      nscolor color = GetColorValue();
-      aResult.Append('#');
-      aResult.AppendPrintf("%02x", NS_GET_R(color));
-      aResult.AppendPrintf("%02x", NS_GET_G(color));
-      aResult.AppendPrintf("%02x", NS_GET_B(color));
-      if (eCSSUnit_HexColorAlpha == unit) {
-        aResult.AppendPrintf("%02x", NS_GET_A(color));
-      }
-    } else if (eCSSUnit_ShortHexColor == unit ||
-               eCSSUnit_ShortHexColorAlpha == unit) {
-      nscolor color = GetColorValue();
-      aResult.Append('#');
-      aResult.AppendInt(NS_GET_R(color) / 0x11, 16);
-      aResult.AppendInt(NS_GET_G(color) / 0x11, 16);
-      aResult.AppendInt(NS_GET_B(color) / 0x11, 16);
-      if (eCSSUnit_ShortHexColorAlpha == unit) {
-        aResult.AppendInt(NS_GET_A(color) / 0x11, 16);
-      }
-    } else {
-      MOZ_ASSERT(IsFloatColorUnit());
-      mValue.mFloatColor->AppendToString(unit, aResult);
+      aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
     }
+    aResult.Append(char16_t(')'));
   }
   else if (eCSSUnit_ComplexColor == unit) {
     StyleComplexColor color = GetStyleComplexColorValue();
     nsCSSValue serializable;
     if (color.IsCurrentColor()) {
       serializable.SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
     } else if (color.IsNumericColor()) {
       serializable.SetColorValue(color.mColor);