Add mechanism for returning computed value name of certain longhand properties of our fake shorthands. (Bug 531585) r=bzbarsky
authorL. David Baron <dbaron@dbaron.org>
Wed, 23 Dec 2009 06:35:46 -0500
changeset 36594 079fd624199bf0749ca37ec02d8e6ae709b6081c
parent 36593 3647e6e07a59419de0ba513e14e312363007c49f
child 36595 70a9757074b927b15596dc5077d422e22c190c8a
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs531585
milestone1.9.3a1pre
Add mechanism for returning computed value name of certain longhand properties of our fake shorthands. (Bug 531585) r=bzbarsky
layout/style/nsCSSPropList.h
layout/style/nsCSSProps.cpp
layout/style/nsCSSProps.h
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -712,17 +712,18 @@ CSS_PROP_SHORTHAND(
     BorderLeftColor,
     0)
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_BORDER(
     border-left-color-value,
     border_left_color_value,
     X,
     CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
-        CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED,
+        CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mBorderColor.mLeft,
     eCSSType_Value,
     kBorderColorKTable,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_Custom)
 CSS_PROP_BORDER(
     border-left-color-ltr-source,
@@ -768,17 +769,18 @@ CSS_PROP_SHORTHAND(
     border_left_style,
     BorderLeftStyle,
     0) // on/off will need reflow
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_BORDER(
     border-left-style-value,
     border_left_style_value,
     X,
-    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER,
+    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mBorderStyle.mLeft,
     eCSSType_Value,
     kBorderStyleKTable,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_None)
 CSS_PROP_BORDER(
     border-left-style-ltr-source,
@@ -810,17 +812,18 @@ CSS_PROP_SHORTHAND(
     border_left_width,
     BorderLeftWidth,
     0)
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_BORDER(
     border-left-width-value,
     border_left_width_value,
     X,
-    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER,
+    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mBorderWidth.mLeft,
     eCSSType_Value,
     kBorderWidthKTable,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_Custom)
 CSS_PROP_BORDER(
     border-left-width-ltr-source,
@@ -858,17 +861,18 @@ CSS_PROP_SHORTHAND(
     BorderRightColor,
     0)
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_BORDER(
     border-right-color-value,
     border_right_color_value,
     X,
     CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
-        CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED,
+        CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mBorderColor.mRight,
     eCSSType_Value,
     kBorderColorKTable,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_Custom)
 CSS_PROP_BORDER(
     border-right-color-ltr-source,
@@ -914,17 +918,18 @@ CSS_PROP_SHORTHAND(
     border_right_style,
     BorderRightStyle,
     0) // on/off will need reflow
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_BORDER(
     border-right-style-value,
     border_right_style_value,
     X,
-    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER,
+    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mBorderStyle.mRight,
     eCSSType_Value,
     kBorderStyleKTable,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_None)
 CSS_PROP_BORDER(
     border-right-style-ltr-source,
@@ -956,17 +961,18 @@ CSS_PROP_SHORTHAND(
     border_right_width,
     BorderRightWidth,
     0)
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_BORDER(
     border-right-width-value,
     border_right_width_value,
     X,
-    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER,
+    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mBorderWidth.mRight,
     eCSSType_Value,
     kBorderWidthKTable,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_Custom)
 CSS_PROP_BORDER(
     border-right-width-ltr-source,
@@ -1646,17 +1652,18 @@ CSS_PROP_SHORTHAND(
     margin_left,
     MarginLeft,
     0)
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_MARGIN(
     margin-left-value,
     margin_left_value,
     X,
-    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER,
+    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mMargin.mLeft,
     eCSSType_Value,
     nsnull,
     offsetof(nsStyleMargin, mMargin),
     eStyleAnimType_Sides_Left)
 CSS_PROP_MARGIN(
     margin-left-ltr-source,
@@ -1688,17 +1695,18 @@ CSS_PROP_SHORTHAND(
     margin_right,
     MarginRight,
     0)
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_MARGIN(
     margin-right-value,
     margin_right_value,
     X,
-    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER,
+    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mMargin.mRight,
     eCSSType_Value,
     nsnull,
     offsetof(nsStyleMargin, mMargin),
     eStyleAnimType_Sides_Right)
 CSS_PROP_MARGIN(
     margin-right-ltr-source,
@@ -1953,17 +1961,18 @@ CSS_PROP_SHORTHAND(
     padding_left,
     PaddingLeft,
     0)
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_PADDING(
     padding-left-value,
     padding_left_value,
     X,
-    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER,
+    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mPadding.mLeft,
     eCSSType_Value,
     nsnull,
     offsetof(nsStylePadding, mPadding),
     eStyleAnimType_Sides_Left)
 CSS_PROP_PADDING(
     padding-left-ltr-source,
@@ -1995,17 +2004,18 @@ CSS_PROP_SHORTHAND(
     padding_right,
     PaddingRight,
     0)
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_PADDING(
     padding-right-value,
     padding_right_value,
     X,
-    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER,
+    CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
+        CSS_PROPERTY_REPORT_OTHER_NAME,
     Margin,
     mPadding.mRight,
     eCSSType_Value,
     nsnull,
     offsetof(nsStylePadding, mPadding),
     eStyleAnimType_Sides_Right)
 CSS_PROP_PADDING(
     padding-right-ltr-source,
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -365,16 +365,45 @@ nsCSSProps::GetStringValue(nsCSSFontDesc
   if (gFontDescTable) {
     return gFontDescTable->GetStringValue(PRInt32(aFontDescID));
   } else {
     static nsDependentCString sNullStr("");
     return sNullStr;
   }
 }
 
+nsCSSProperty
+nsCSSProps::OtherNameFor(nsCSSProperty aProperty)
+{
+  switch (aProperty) {
+    case eCSSProperty_border_left_color_value:
+      return eCSSProperty_border_left_color;
+    case eCSSProperty_border_left_style_value:
+      return eCSSProperty_border_left_style;
+    case eCSSProperty_border_left_width_value:
+      return eCSSProperty_border_left_width;
+    case eCSSProperty_border_right_color_value:
+      return eCSSProperty_border_right_color;
+    case eCSSProperty_border_right_style_value:
+      return eCSSProperty_border_right_style;
+    case eCSSProperty_border_right_width_value:
+      return eCSSProperty_border_right_width;
+    case eCSSProperty_margin_left_value:
+      return eCSSProperty_margin_left;
+    case eCSSProperty_margin_right_value:
+      return eCSSProperty_margin_right;
+    case eCSSProperty_padding_left_value:
+      return eCSSProperty_padding_left;
+    case eCSSProperty_padding_right_value:
+      return eCSSProperty_padding_right;
+    default:
+      NS_ABORT_IF_FALSE(PR_FALSE, "bad caller");
+  }
+  return eCSSProperty_UNKNOWN;
+}
 
 /***************************************************************************/
 
 const PRInt32 nsCSSProps::kAppearanceKTable[] = {
   eCSSKeyword_none,                   NS_THEME_NONE,
   eCSSKeyword_button,                 NS_THEME_BUTTON,
   eCSSKeyword_radio,                  NS_THEME_RADIO,
   eCSSKeyword_checkbox,               NS_THEME_CHECKBOX,
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -74,16 +74,23 @@
 #define CSS_PROPERTY_START_IMAGE_LOADS            (1<<5)
 
 // Should be set only for properties with START_IMAGE_LOADS.  Indicates
 // that the property has an array value with a URL/image value at index
 // 0 in the array, rather than the URL/image being in the value or value
 // list.
 #define CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0          (1<<6)
 
+// This is a property for which the computed value should generally be
+// reported as the computed value of a property of a different name.  In
+// particular, the directional box properties (margin-left-value, etc.)
+// should be reported as being margin-left, etc.  Call
+// nsCSSProps::OtherNameFor to get the other property.
+#define CSS_PROPERTY_REPORT_OTHER_NAME            (1<<7)
+
 /**
  * Types of animatable values.
  */
 enum nsStyleAnimType {
   // requires a custom implementation in
   // nsStyleAnimation::ExtractComputedValue
   eStyleAnimType_Custom,
 
@@ -147,16 +154,21 @@ public:
   // Same but for @font-face descriptors
   static nsCSSFontDesc LookupFontDesc(const nsAString& aProperty);
   static nsCSSFontDesc LookupFontDesc(const nsACString& aProperty);
 
   // Given a property enum, get the string value
   static const nsAFlatCString& GetStringValue(nsCSSProperty aProperty);
   static const nsAFlatCString& GetStringValue(nsCSSFontDesc aFontDesc);
 
+  // Get the property to report the computed value of aProperty as being
+  // the computed value of.  aProperty must have the
+  // CSS_PROPERTY_REPORT_OTHER_NAME bit set.
+  static nsCSSProperty OtherNameFor(nsCSSProperty aProperty);
+
   // Given a CSS Property and a Property Enum Value
   // Return back a const nsString& representation of the 
   // value. Return back nullstr if no value is found
   static const nsAFlatCString& LookupPropertyValue(nsCSSProperty aProperty, PRInt32 aValue);
 
   // Get a color name for a predefined color value like buttonhighlight or activeborder
   // Sets the aStr param to the name of the propertyID
   static PRBool GetColorName(PRInt32 aPropID, nsCString &aStr);