diff --git a/layout/style/nsCSSValue.cpp b/layout/style/nsCSSValue.cpp index 3535de7661d4..35a1a8bd4fb2 100644 --- a/layout/style/nsCSSValue.cpp +++ b/layout/style/nsCSSValue.cpp @@ -1660,38 +1660,31 @@ nsCSSValue::AppendToString(nsCSSPropertyID aProperty, nsAString& aResult, unit == eCSSUnit_RGBColor || unit == eCSSUnit_RGBAColor) { nscolor color = GetColorValue(); - if (aSerialization == eNormalized && - color == NS_RGBA(0, 0, 0, 0)) { - // Use the strictest match for 'transparent' so we do correct - // round-tripping of all other rgba() values. - aResult.AppendLiteral("transparent"); + // 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(). + uint8_t a = NS_GET_A(color); + bool showAlpha = (a != 255); + + if (unit == eCSSUnit_RGBAColor && showAlpha) { + aResult.AppendLiteral("rgba("); } else { - // 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(). - uint8_t a = NS_GET_A(color); - bool showAlpha = (a != 255); - - if (unit == eCSSUnit_RGBAColor && 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.AppendFloat(nsStyleUtil::ColorComponentToFloat(a)); - } - aResult.Append(char16_t(')')); + 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.AppendFloat(nsStyleUtil::ColorComponentToFloat(a)); + } + aResult.Append(char16_t(')')); } else if (eCSSUnit_HexColor == unit || eCSSUnit_HexColorAlpha == unit) { nscolor color = GetColorValue(); diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 465a3bdf7d5d..f014b4fad724 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -1115,11 +1115,6 @@ void nsComputedDOMStyle::SetToRGBAColor(nsROCSSPrimitiveValue* aValue, nscolor aColor) { - if (NS_GET_A(aColor) == 0) { - aValue->SetIdent(eCSSKeyword_transparent); - return; - } - nsROCSSPrimitiveValue *red = new nsROCSSPrimitiveValue; nsROCSSPrimitiveValue *green = new nsROCSSPrimitiveValue; nsROCSSPrimitiveValue *blue = new nsROCSSPrimitiveValue; diff --git a/layout/style/test/chrome/hover_helper.html b/layout/style/test/chrome/hover_helper.html index 9da5ee436903..91f7c6c9b9b8 100644 --- a/layout/style/test/chrome/hover_helper.html +++ b/layout/style/test/chrome/hover_helper.html @@ -65,7 +65,7 @@ function step1() { synthesizeMouse(divone, 5, 7, moveEvent, window); is(getComputedStyle(divone, "").backgroundColor, "rgb(0, 0, 255)", ":hover applies"); - is(getComputedStyle(divone.firstChild, "").backgroundColor, "transparent", + is(getComputedStyle(divone.firstChild, "").backgroundColor, "rgba(0, 0, 0, 0)", ":hover does not apply"); synthesizeMouse(divone, 5, 2, moveEvent, window); is(getComputedStyle(divone, "").backgroundColor, "rgb(0, 0, 255)", @@ -73,9 +73,9 @@ function step1() { is(getComputedStyle(divone.firstChild, "").backgroundColor, "rgb(255, 0, 0)", ":hover applies"); synthesizeMouse(divone, 15, 7, moveEvent, window); - is(getComputedStyle(divone, "").backgroundColor, "transparent", + is(getComputedStyle(divone, "").backgroundColor, "rgba(0, 0, 0, 0)", ":hover does not apply"); - is(getComputedStyle(divone.firstChild, "").backgroundColor, "transparent", + is(getComputedStyle(divone.firstChild, "").backgroundColor, "rgba(0, 0, 0, 0)", ":hover does not apply"); synthesizeMouse(divone, 15, 2, moveEvent, window); is(getComputedStyle(divone, "").backgroundColor, "rgb(0, 0, 255)", @@ -115,7 +115,7 @@ function step3() { step4(); return; } - is(getComputedStyle(divtwo, "").backgroundColor, "transparent", + is(getComputedStyle(divtwo, "").backgroundColor, "rgba(0, 0, 0, 0)", ":hover does not apply"); setResize("step4()"); /* expect to get a second resize from the oscillation */ @@ -144,7 +144,7 @@ var step6called = false; function step6() { is(step6called, false, "step6 called only once"); step6called = true; - is(getComputedStyle(divtwo, "").backgroundColor, "transparent", + is(getComputedStyle(divtwo, "").backgroundColor, "rgba(0, 0, 0, 0)", ":hover does not apply"); synthesizeMouse(divtwoparent, 2, 5, moveEvent, window); setTimeout(step7, 500); // time to detect oscillations if they exist @@ -156,7 +156,7 @@ function step7() { if (step7called) return; step7called = true; - is(getComputedStyle(divtwo, "").backgroundColor, "transparent", + is(getComputedStyle(divtwo, "").backgroundColor, "rgba(0, 0, 0, 0)", ":hover does not apply"); setTimeout(step8, 500); // time to detect oscillations if they exist } @@ -195,7 +195,7 @@ function step10() { step11(); return; } - is(getComputedStyle(divtwo, "").backgroundColor, "transparent", + is(getComputedStyle(divtwo, "").backgroundColor, "rgba(0, 0, 0, 0)", ":hover does not apply"); setResize("step11()"); /* expect to get a second resize from the oscillation */ @@ -224,7 +224,7 @@ var step13called = false; function step13() { is(step13called, false, "step13 called only once"); step13called = true; - is(getComputedStyle(divtwo, "").backgroundColor, "transparent", + is(getComputedStyle(divtwo, "").backgroundColor, "rgba(0, 0, 0, 0)", ":hover does not apply"); setResize("step14()"); divtwoparent.scrollLeft = 0; /* mouse now over 2,5 */ @@ -251,7 +251,7 @@ function step15() { if (step15called) return; step15called = true; - is(getComputedStyle(divtwo, "").backgroundColor, "transparent", + is(getComputedStyle(divtwo, "").backgroundColor, "rgba(0, 0, 0, 0)", ":hover does not apply"); setTimeout(finish, 500); // time to detect oscillations if they exist } diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index aabf062483e1..b8ae3f6021b6 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -2235,8 +2235,8 @@ var gCSSProperties = { domProp: "backgroundColor", inherited: false, type: CSS_TYPE_LONGHAND, - initial_values: [ "transparent", "rgba(255, 127, 15, 0)", "hsla(240, 97%, 50%, 0.0)", "rgba(0, 0, 0, 0)", "rgba(255,255,255,-3.7)" ], - other_values: [ "green", "rgb(255, 0, 128)", "#fc2", "#96ed2a", "black", "rgba(255,255,0,3)", "hsl(240, 50%, 50%)", "rgb(50%, 50%, 50%)", "-moz-default-background-color", "rgb(100, 100.0, 100)" ], + initial_values: [ "transparent", "rgba(0, 0, 0, 0)" ], + other_values: [ "green", "rgb(255, 0, 128)", "#fc2", "#96ed2a", "black", "rgba(255,255,0,3)", "hsl(240, 50%, 50%)", "rgb(50%, 50%, 50%)", "-moz-default-background-color", "rgb(100, 100.0, 100)", "rgba(255, 127, 15, 0)", "hsla(240, 97%, 50%, 0.0)", "rgba(255,255,255,-3.7)" ], invalid_values: [ "#0", "#00", "#00000", "#0000000", "#000000000", "rgb(100, 100%, 100)" ], quirks_values: { "000000": "#000000", "96ed2a": "#96ed2a" }, }, diff --git a/layout/style/test/test_additional_sheets.html b/layout/style/test/test_additional_sheets.html index 2fe69ab8aba3..9ca5fa7690cd 100644 --- a/layout/style/test/test_additional_sheets.html +++ b/layout/style/test/test_additional_sheets.html @@ -205,7 +205,7 @@ function loadAndCheck(win, firstType, secondType, swap, result1, result2) secondType.removeRules(win, secondStyle); is(cs.getPropertyValue('color'), 'rgb(0, 0, 0)', firstType.type + " vs " + secondType.type + " 3"); - is(cs.getPropertyValue('background-color'), 'transparent', firstType.type + " vs " + secondType.type + " 4"); + is(cs.getPropertyValue('background-color'), 'rgba(0, 0, 0, 0)', firstType.type + " vs " + secondType.type + " 4"); } // There are 8 cases. Regular against regular, regular against important, important diff --git a/layout/style/test/test_bug229915.html b/layout/style/test/test_bug229915.html index e24dd61c8551..3ffcdec9a540 100644 --- a/layout/style/test/test_bug229915.html +++ b/layout/style/test/test_bug229915.html @@ -45,7 +45,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=229915 const GREEN = "rgb(0, 128, 0)"; const BLACK = "rgb(0, 0, 0)"; -const TRANSPARENT = "transparent"; +const TRANSPARENT = "rgba(0, 0, 0, 0)"; const WHITE = "rgb(255, 255, 255)"; function make_prev() { diff --git a/layout/style/test/test_bug372770.html b/layout/style/test/test_bug372770.html index 208a79e3eff9..7a8bf6ff3c6f 100644 --- a/layout/style/test/test_bug372770.html +++ b/layout/style/test/test_bug372770.html @@ -35,18 +35,12 @@ for (i = 0; i < colors.length; ++i) { is(style2.color, color, "Rule style color roundtripping failed at color " + i); } -// This code is only here because of bug 372783. Once that's fixed, this test -// for "rgba(0, 0, 0, 0)" will fail. style1.color = "rgba(0, 0, 0, 0)"; style2.color = "rgba(0, 0, 0, 0)"; -is(style1.color, "transparent", - "Inline style should give transparent for rgba(0,0,0,0)"); -is(style2.color, "transparent", - "Rule style should give transparent for rgba(0,0,0,0)"); -todo(style1.color == "rgba(0, 0, 0, 0)", - "Inline style should round-trip black transparent color correctly"); -todo(style2.color == "rgba(0, 0, 0, 0)", - "Rule style should round-trip black transparent color correctly"); +is(style1.color, "rgba(0, 0, 0, 0)", + "Inline style should round-trip black transparent color correctly"); +is(style2.color, "rgba(0, 0, 0, 0)", + "Rule style should round-trip black transparent color correctly"); for (var i = 0; i <= 100; ++i) { if (i == 70 || i == 90) { diff --git a/layout/style/test/test_bug635286.html b/layout/style/test/test_bug635286.html index b4e1f86807a7..f4264bd6c5ee 100644 --- a/layout/style/test/test_bug635286.html +++ b/layout/style/test/test_bug635286.html @@ -36,7 +36,7 @@ window.addEventListener("load", function() { cases.forEach(function(aCase, aIndex) { is(window.getComputedStyle(aCase) .getPropertyValue("background-color"), - "transparent", + "rgba(0, 0, 0, 0)", aCase.textContent); }); SimpleTest.finish(); diff --git a/layout/style/test/test_computed_style.html b/layout/style/test/test_computed_style.html index dbcc71b7cd8b..77e91b9dfddc 100644 --- a/layout/style/test/test_computed_style.html +++ b/layout/style/test/test_computed_style.html @@ -361,8 +361,8 @@ var noframe_container = document.getElementById("content"); "markerEnd" : "", "clipPath" : "", "filter" : "", - "fill" : " transparent", - "stroke" : " transparent", + "fill" : " rgba(0, 0, 0, 0)", + "stroke" : " rgba(0, 0, 0, 0)", }; for (var prop in testStyles) { diff --git a/layout/style/test/test_default_computed_style.html b/layout/style/test/test_default_computed_style.html index 60f3dcab0105..55f6dc3f3f47 100644 --- a/layout/style/test/test_default_computed_style.html +++ b/layout/style/test/test_default_computed_style.html @@ -45,7 +45,7 @@ is(cs_pseudo.display, "block", "Our ::before is block"); // And now our actual tests is(cs_default.display, "block", "We have block display by default"); is(cs_default.marginTop, "16px", "We have 16px margin by default"); -is(cs_default.backgroundColor, "transparent", +is(cs_default.backgroundColor, "rgba(0, 0, 0, 0)", "We have transparent background by default"); is(cs_default.color, "rgb(0, 0, 0)", "We have black text by default"); is(cs_default_pseudo.content, "none", "We have no content by default");