From 5d32582baadb75d0f1657c5706b646799edb9e54 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Tue, 23 Dec 2008 09:06:57 -0500 Subject: [PATCH] Suppress serialization of -moz-use-text-color in border shorthand in property getters just like we do in declaration serialization. (Bug 376075) r+sr=bzbarsky --- layout/style/nsCSSDeclaration.cpp | 18 ++++++++++++--- layout/style/nsCSSProps.cpp | 13 +++++++++-- .../test/test_shorthand_property_getters.html | 22 +++++++++++++++++++ layout/style/test/test_value_storage.html | 9 -------- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/layout/style/nsCSSDeclaration.cpp b/layout/style/nsCSSDeclaration.cpp index 86c3cc6445dd..907f6221d4ea 100644 --- a/layout/style/nsCSSDeclaration.cpp +++ b/layout/style/nsCSSDeclaration.cpp @@ -730,11 +730,23 @@ nsCSSDeclaration::GetValue(nsCSSProperty aProperty, nsCSSProps::kTypeTable[subprops[1]] == eCSSType_Value && nsCSSProps::kTypeTable[subprops[2]] == eCSSType_Value, "type mismatch"); + NS_ASSERTION(StringEndsWith(nsCSSProps::GetStringValue(subprops[2]), + NS_LITERAL_CSTRING("-color")) || + StringEndsWith(nsCSSProps::GetStringValue(subprops[2]), + NS_LITERAL_CSTRING("-color-value")), + "third subprop must be the color property"); + const nsCSSValue *colorValue = + static_cast(data->StorageFor(subprops[2])); + PRBool isMozUseTextColor = + colorValue->GetUnit() == eCSSUnit_Enumerated && + colorValue->GetIntValue() == NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR; if (!AppendValueToString(subprops[0], aValue) || !(aValue.Append(PRUnichar(' ')), AppendValueToString(subprops[1], aValue)) || - !(aValue.Append(PRUnichar(' ')), - AppendValueToString(subprops[2], aValue))) { + // Don't output a third value when it's -moz-use-text-color. + !(isMozUseTextColor || + (aValue.Append(PRUnichar(' ')), + AppendValueToString(subprops[2], aValue)))) { aValue.Truncate(); } break; @@ -1033,11 +1045,11 @@ nsCSSDeclaration::TryBorderShorthand(nsAString & aString, PRUint32 aPropertiesSe aString.Append(PRUnichar(' ')); AppendValueToString(eCSSProperty_border_top_style, aString); - aString.Append(PRUnichar(' ')); nsAutoString valueString; AppendValueToString(eCSSProperty_border_top_color, valueString); if (!valueString.EqualsLiteral("-moz-use-text-color")) { + aString.Append(PRUnichar(' ')); /* don't output this value, it's proprietary Mozilla and */ /* not intended to be exposed ; we can remove it from the */ /* values of the shorthand since this value represents the */ diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp index 277c1b5b71b6..1709e905604a 100644 --- a/layout/style/nsCSSProps.cpp +++ b/layout/style/nsCSSProps.cpp @@ -1349,6 +1349,7 @@ static const nsCSSProperty gBorderSubpropTable[] = { static const nsCSSProperty gBorderBottomSubpropTable[] = { // nsCSSDeclaration.cpp outputs the subproperties in this order. + // It also depends on the color being third. eCSSProperty_border_bottom_width, eCSSProperty_border_bottom_style, eCSSProperty_border_bottom_color, @@ -1403,6 +1404,7 @@ static const nsCSSProperty gMozBorderStartColorSubpropTable[] = { static const nsCSSProperty gMozBorderEndSubpropTable[] = { // nsCSSDeclaration.cpp output the subproperties in this order. + // It also depends on the color being third. eCSSProperty_border_end_width_value, eCSSProperty_border_end_style_value, eCSSProperty_border_end_color_value, @@ -1418,6 +1420,7 @@ static const nsCSSProperty gMozBorderEndSubpropTable[] = { static const nsCSSProperty gBorderLeftSubpropTable[] = { // nsCSSDeclaration.cpp outputs the subproperties in this order. + // It also depends on the color being third. eCSSProperty_border_left_width_value, eCSSProperty_border_left_style_value, eCSSProperty_border_left_color_value, @@ -1433,6 +1436,7 @@ static const nsCSSProperty gBorderLeftSubpropTable[] = { static const nsCSSProperty gBorderRightSubpropTable[] = { // nsCSSDeclaration.cpp outputs the subproperties in this order. + // It also depends on the color being third. eCSSProperty_border_right_width_value, eCSSProperty_border_right_style_value, eCSSProperty_border_right_color_value, @@ -1448,6 +1452,7 @@ static const nsCSSProperty gBorderRightSubpropTable[] = { static const nsCSSProperty gMozBorderStartSubpropTable[] = { // nsCSSDeclaration.cpp outputs the subproperties in this order. + // It also depends on the color being third. eCSSProperty_border_start_width_value, eCSSProperty_border_start_style_value, eCSSProperty_border_start_color_value, @@ -1509,6 +1514,7 @@ static const nsCSSProperty gMozBorderEndStyleSubpropTable[] = { static const nsCSSProperty gBorderTopSubpropTable[] = { // nsCSSDeclaration.cpp outputs the subproperties in this order. + // It also depends on the color being third. eCSSProperty_border_top_width, eCSSProperty_border_top_style, eCSSProperty_border_top_color, @@ -1636,13 +1642,16 @@ static const nsCSSProperty gMozMarginEndSubpropTable[] = { static const nsCSSProperty gOutlineSubpropTable[] = { // nsCSSDeclaration.cpp outputs the subproperties in this order. - eCSSProperty_outline_color, - eCSSProperty_outline_style, + // It also depends on the color being third. eCSSProperty_outline_width, + eCSSProperty_outline_style, + eCSSProperty_outline_color, eCSSProperty_UNKNOWN }; static const nsCSSProperty gMozColumnRuleSubpropTable[] = { + // nsCSSDeclaration.cpp outputs the subproperties in this order. + // It also depends on the color being third. eCSSProperty__moz_column_rule_width, eCSSProperty__moz_column_rule_style, eCSSProperty__moz_column_rule_color, diff --git a/layout/style/test/test_shorthand_property_getters.html b/layout/style/test/test_shorthand_property_getters.html index 820321d40884..2e73837a4049 100644 --- a/layout/style/test/test_shorthand_property_getters.html +++ b/layout/style/test/test_shorthand_property_getters.html @@ -42,6 +42,28 @@ is(e.style.border, "", "should not be able to serialize border"); e.setAttribute("style", "border-width: 3px 3px 3px 3px; border-style: solid dashed; border-color: green"); is(e.style.border, "", "should not be able to serialize border"); +// Test suppression of -moz-use-text-color in border shorthands. +e.setAttribute("style", "border: medium solid"); +ok(e.style.border == "medium solid" || + e.style.border == "solid medium", + "implied default color omitted serializing border"); +ok(e.style.borderLeft == "medium solid" || + e.style.borderLeft == "solid medium", + "implied default color omitted serializing border-left"); +ok(e.style.cssText == "border: medium solid;" || + e.style.cssText == "border: solid medium;", + "implied default color omitted serializing declaration"); +e.setAttribute("style", "border-right: medium solid"); +ok(e.style.borderRight == "medium solid" || + e.style.borderRight == "solid medium", + "implied default color omitted serializing border-right"); +ok(e.style.borderRight == "medium solid" || + e.style.borderRight == "solid medium", + "implied default color omitted serializing border-right"); +ok(e.style.cssText == "border-right: medium solid;" || + e.style.cssText == "border-right: solid medium;", + "implied default color omitted serializing declaration"); + diff --git a/layout/style/test/test_value_storage.html b/layout/style/test/test_value_storage.html index a5ee652be11c..ba1d2111f7d8 100644 --- a/layout/style/test/test_value_storage.html +++ b/layout/style/test/test_value_storage.html @@ -109,15 +109,6 @@ function xfail_ser_val(property, value) if (property in gShorthandsWithoutCondensingSerialize) return true; - // We output unneeded -moz-use-text-color only in the value getter and - // not the serialization. - // XXXbz is there any way we could actually filter for that, so that colors - // other than green could be used in the property database here? - if ((property.match(/^border(|-bottom|-left|-right|-top)$/) || - property.match(/^-moz-border(|-start|-end)$/)) && - !value.match(/(green|currentcolor)/i)) - return true; - // We condense multiple values in the serialization, but not in the // value getter. if (property.match(/^(border-(color|style|width)|margin|padding)$/) &&