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
authorL. David Baron <dbaron@dbaron.org>
Tue, 23 Dec 2008 09:06:57 -0500
changeset 23022 db84bf8e7438695164cc6e31f2805c544c4ed23f
parent 23021 d696886de032cdb4eac542620f83d1e4f0accbf3
child 23023 4acaa6ee36651ca56e29a82fce265da9e9efda59
push idunknown
push userunknown
push dateunknown
bugs376075
milestone1.9.2a1pre
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
layout/style/nsCSSProps.cpp
layout/style/test/test_shorthand_property_getters.html
layout/style/test/test_value_storage.html
--- a/layout/style/nsCSSDeclaration.cpp
+++ b/layout/style/nsCSSDeclaration.cpp
@@ -725,21 +725,33 @@ nsCSSDeclaration::GetValue(nsCSSProperty
     case eCSSProperty__moz_column_rule:
     case eCSSProperty_outline: {
       const nsCSSProperty* subprops =
         nsCSSProps::SubpropertyEntryFor(aProperty);
       NS_ASSERTION(nsCSSProps::kTypeTable[subprops[0]] == eCSSType_Value &&
                    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<const nsCSSValue*>(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;
     }
     case eCSSProperty_margin_left:
     case eCSSProperty_margin_right:
     case eCSSProperty_margin_start:
     case eCSSProperty_margin_end:
@@ -1028,21 +1040,21 @@ nsCSSDeclaration::TryBorderShorthand(nsA
   if (border) {
     AppendASCIItoUTF16(nsCSSProps::GetStringValue(eCSSProperty_border), aString);
     aString.AppendLiteral(": ");
 
     AppendValueToString(eCSSProperty_border_top_width, aString);
     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 */
       /* initial value of border-*-color */
       aString.Append(valueString);
     }
     AppendImportanceToString(isImportant, aString);
     aString.AppendLiteral("; ");
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -1344,16 +1344,17 @@ static const nsCSSProperty gBorderSubpro
   eCSSProperty_border_left_color_value,
   eCSSProperty_border_left_color_ltr_source,
   eCSSProperty_border_left_color_rtl_source,
   eCSSProperty_UNKNOWN
 };
 
 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,
   eCSSProperty_UNKNOWN
 };
 
 static const nsCSSProperty gBorderColorSubpropTable[] = {
   // Code relies on these being in top-right-bottom-left order.
@@ -1398,61 +1399,65 @@ static const nsCSSProperty gMozBorderSta
   eCSSProperty_border_start_color_value,
   eCSSProperty_border_left_color_ltr_source,
   eCSSProperty_border_right_color_rtl_source,
   eCSSProperty_UNKNOWN
 };
 
 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,
   // extras:
   eCSSProperty_border_right_width_ltr_source,
   eCSSProperty_border_left_width_rtl_source,
   eCSSProperty_border_right_style_ltr_source,
   eCSSProperty_border_left_style_rtl_source,
   eCSSProperty_border_right_color_ltr_source,
   eCSSProperty_border_left_color_rtl_source,
   eCSSProperty_UNKNOWN
 };
 
 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,
   // extras:
   eCSSProperty_border_left_width_ltr_source,
   eCSSProperty_border_left_width_rtl_source,
   eCSSProperty_border_left_style_ltr_source,
   eCSSProperty_border_left_style_rtl_source,
   eCSSProperty_border_left_color_ltr_source,
   eCSSProperty_border_left_color_rtl_source,
   eCSSProperty_UNKNOWN
 };
 
 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,
   // extras:
   eCSSProperty_border_right_width_ltr_source,
   eCSSProperty_border_right_width_rtl_source,
   eCSSProperty_border_right_style_ltr_source,
   eCSSProperty_border_right_style_rtl_source,
   eCSSProperty_border_right_color_ltr_source,
   eCSSProperty_border_right_color_rtl_source,
   eCSSProperty_UNKNOWN
 };
 
 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,
   // extras:
   eCSSProperty_border_left_width_ltr_source,
   eCSSProperty_border_right_width_rtl_source,
   eCSSProperty_border_left_style_ltr_source,
   eCSSProperty_border_right_style_rtl_source,
@@ -1504,16 +1509,17 @@ static const nsCSSProperty gMozBorderEnd
   eCSSProperty_border_end_style_value,
   eCSSProperty_border_right_style_ltr_source,
   eCSSProperty_border_left_style_rtl_source,
   eCSSProperty_UNKNOWN
 };
 
 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,
   eCSSProperty_UNKNOWN
 };
 
 static const nsCSSProperty gBorderWidthSubpropTable[] = {
   // Code relies on these being in top-right-bottom-left order.
@@ -1631,23 +1637,26 @@ static const nsCSSProperty gMozMarginEnd
   eCSSProperty_margin_right_ltr_source,
   eCSSProperty_margin_left_rtl_source,
   eCSSProperty_UNKNOWN
 };
 
 
 static const nsCSSProperty gOutlineSubpropTable[] = {
   // nsCSSDeclaration.cpp outputs the subproperties in this order.
-  eCSSProperty_outline_color,
+  // It also depends on the color being third.
+  eCSSProperty_outline_width,
   eCSSProperty_outline_style,
-  eCSSProperty_outline_width,
+  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,
   eCSSProperty_UNKNOWN
 };
 
 static const nsCSSProperty gOverflowSubpropTable[] = {
   eCSSProperty_overflow_x,
--- a/layout/style/test/test_shorthand_property_getters.html
+++ b/layout/style/test/test_shorthand_property_getters.html
@@ -37,13 +37,35 @@ e.setAttribute("style", "border-width: 3
 is(e.style.border, "", "should not be able to serialize border");
 e.setAttribute("style", "border-width: 3px 3px 3px 3px; border-style: solid; border-color: blue blue blue green");
 is(e.style.border, "", "should not be able to serialize border");
 e.setAttribute("style", "border-width: 3px 2px 3px 3px; border-style: solid; border-color: green");
 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");
+
 
 </script>
 </pre>
 </body>
 </html>
--- a/layout/style/test/test_value_storage.html
+++ b/layout/style/test/test_value_storage.html
@@ -104,25 +104,16 @@ function xfail_ser_val(property, value)
   if (property != "font" && xfail_accepted(property, value))
     // We already failed the first test, which will make us always pass this
     // one.
     return false;
 
   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)$/) &&
       value.split(" ").length != 4)
     return true;
   if (property in gShortenableValues &&
       gShortenableValues[property].indexOf(value) != -1)
     return true;