bug 43178 - replace incorrect border, frame and rules handling code in content by css rules, initial patch - fantasai, a lof of input - bz r=bzbarsky
authorBernd <bmlk@gmx.de>
Sat, 09 Jan 2010 16:33:03 +0100
changeset 36972 ef065d84aaa4839b08bff660f16d146d604e6113
parent 36971 6a7294d0f3052220f7572846a4831dd6b627935c
child 36973 b9d15f414e28ffd954981531bf36a5bfd90c95c2
push id11094
push userbmlk@gmx.de
push dateSat, 09 Jan 2010 15:39:04 +0000
treeherdermozilla-central@ef065d84aaa4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs43178
milestone1.9.3a1pre
bug 43178 - replace incorrect border, frame and rules handling code in content by css rules, initial patch - fantasai, a lof of input - bz r=bzbarsky
content/html/content/src/nsHTMLTableElement.cpp
layout/base/nsCSSRenderingBorders.cpp
layout/base/nsStyleConsts.h
layout/generic/nsFrame.cpp
layout/reftests/table-bordercollapse/bordercol.css
layout/reftests/table-bordercollapse/borderhandling-1.html
layout/reftests/table-bordercollapse/borderhandling-2.html
layout/reftests/table-bordercollapse/borderhandling-3.html
layout/reftests/table-bordercollapse/borderhandling-4.html
layout/reftests/table-bordercollapse/borderhandling-5.xhtml
layout/reftests/table-bordercollapse/borderhandling-6.xhtml
layout/reftests/table-bordercollapse/borderhandling-7.xhtml
layout/reftests/table-bordercollapse/borderhandling-8.html
layout/reftests/table-bordercollapse/borderhandling-frame-border-ref.html
layout/reftests/table-bordercollapse/borderhandling-frame-border.html
layout/reftests/table-bordercollapse/borderhandling-ref.html
layout/reftests/table-bordercollapse/borderhandling-rules-border-ref.html
layout/reftests/table-bordercollapse/borderhandling-rules-border.html
layout/reftests/table-bordercollapse/reftest.list
layout/style/html.css
layout/style/nsCSSPropList.h
layout/style/nsCSSStruct.h
layout/style/nsHTMLStyleSheet.cpp
layout/style/nsHTMLStyleSheet.h
layout/style/nsRuleNode.cpp
layout/tables/nsTableFrame.cpp
--- a/content/html/content/src/nsHTMLTableElement.cpp
+++ b/content/html/content/src/nsHTMLTableElement.cpp
@@ -1024,147 +1024,17 @@ nsHTMLTableElement::ParseAttribute(PRInt
       return aResult.ParseIntWithBounds(aValue, 0);
     }
   }
 
   return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
                                               aResult);
 }
 
-static void 
-MapTableFrameInto(const nsMappedAttributes* aAttributes,
-                  nsRuleData* aData, PRUint8 aBorderStyle)
-{
-  if (!aData->mMarginData)
-    return;
 
-  // 0 out the sides that we want to hide based on the frame attribute
-  const nsAttrValue* frameValue = aAttributes->GetAttr(nsGkAtoms::frame);
-
-  if (frameValue && frameValue->Type() == nsAttrValue::eEnum) {
-    // adjust the border style based on the value of frame
-    switch (frameValue->GetEnumValue())
-    {
-    case NS_STYLE_TABLE_FRAME_NONE:
-      if (aData->mMarginData->mBorderStyle.mLeft.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mLeft.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mRight.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mRight.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mTop.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mTop.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mBottom.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mBottom.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      break;
-    case NS_STYLE_TABLE_FRAME_ABOVE:
-      if (aData->mMarginData->mBorderStyle.mLeft.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mLeft.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mRight.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mRight.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mBottom.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mBottom.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      break;
-    case NS_STYLE_TABLE_FRAME_BELOW: 
-      if (aData->mMarginData->mBorderStyle.mLeft.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mLeft.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mRight.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mRight.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mTop.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mTop.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      break;
-    case NS_STYLE_TABLE_FRAME_HSIDES:
-      if (aData->mMarginData->mBorderStyle.mLeft.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mLeft.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mRight.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mRight.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      break;
-    case NS_STYLE_TABLE_FRAME_LEFT:
-      if (aData->mMarginData->mBorderStyle.mRight.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mRight.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mTop.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mTop.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mBottom.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mBottom.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      break;
-    case NS_STYLE_TABLE_FRAME_RIGHT:
-      if (aData->mMarginData->mBorderStyle.mLeft.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mLeft.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mTop.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mTop.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mBottom.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mBottom.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      break;
-    case NS_STYLE_TABLE_FRAME_VSIDES:
-      if (aData->mMarginData->mBorderStyle.mTop.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mTop.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      if (aData->mMarginData->mBorderStyle.mBottom.GetUnit() == eCSSUnit_Null)
-        aData->mMarginData->mBorderStyle.mBottom.SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
-      break;
-    // BOX and BORDER are ignored, the caller has already set all the border sides
-    // any illegal value is also ignored
-    }
-  }
-
-  // set up defaults
-  if (aData->mMarginData->mBorderStyle.mLeft.GetUnit() == eCSSUnit_Null)
-    aData->mMarginData->mBorderStyle.mLeft.SetIntValue(aBorderStyle, eCSSUnit_Enumerated);
-  if (aData->mMarginData->mBorderStyle.mRight.GetUnit() == eCSSUnit_Null)
-    aData->mMarginData->mBorderStyle.mRight.SetIntValue(aBorderStyle, eCSSUnit_Enumerated);
-  if (aData->mMarginData->mBorderStyle.mTop.GetUnit() == eCSSUnit_Null)
-    aData->mMarginData->mBorderStyle.mTop.SetIntValue(aBorderStyle, eCSSUnit_Enumerated);
-  if (aData->mMarginData->mBorderStyle.mBottom.GetUnit() == eCSSUnit_Null)
-    aData->mMarginData->mBorderStyle.mBottom.SetIntValue(aBorderStyle, eCSSUnit_Enumerated);
-
-}
-
-// XXX The two callsites care about the two different halves of this
-// function, so split it, probably by just putting it in inline at the
-// callsites.
-static void 
-MapTableBorderInto(const nsMappedAttributes* aAttributes,
-                   nsRuleData* aData, PRUint8 aBorderStyle)
-{
-  const nsAttrValue* borderValue = aAttributes->GetAttr(nsGkAtoms::border);
-  if (!borderValue && !aAttributes->GetAttr(nsGkAtoms::frame))
-    return;
-
-  // the absence of "border" with the presence of "frame" implies
-  // border = 1 pixel
-  PRInt32 borderThickness = 1;
-
-  if (borderValue && borderValue->Type() == nsAttrValue::eInteger)
-    borderThickness = borderValue->GetIntegerValue();
-
-  if (aData->mTableData) {
-    if (0 != borderThickness) {
-      // border != 0 implies rules=all and frame=border
-      aData->mTableData->mRules.SetIntValue(NS_STYLE_TABLE_RULES_ALL, eCSSUnit_Enumerated);
-      aData->mTableData->mFrame.SetIntValue(NS_STYLE_TABLE_FRAME_BORDER, eCSSUnit_Enumerated);
-    }
-    else {
-      // border = 0 implies rules=none and frame=void
-      aData->mTableData->mRules.SetIntValue(NS_STYLE_TABLE_RULES_NONE, eCSSUnit_Enumerated);
-      aData->mTableData->mFrame.SetIntValue(NS_STYLE_TABLE_FRAME_NONE, eCSSUnit_Enumerated);
-    }
-  }
-
-  if (aData->mMarginData) {
-    // by default, set all border sides to the specified width
-    if (aData->mMarginData->mBorderWidth.mLeft.GetUnit() == eCSSUnit_Null)
-      aData->mMarginData->mBorderWidth.mLeft.SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
-    if (aData->mMarginData->mBorderWidth.mRight.GetUnit() == eCSSUnit_Null)
-      aData->mMarginData->mBorderWidth.mRight.SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
-    if (aData->mMarginData->mBorderWidth.mTop.GetUnit() == eCSSUnit_Null)
-      aData->mMarginData->mBorderWidth.mTop .SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
-    if (aData->mMarginData->mBorderWidth.mBottom.GetUnit() == eCSSUnit_Null)
-      aData->mMarginData->mBorderWidth.mBottom.SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
-
-    // now account for the frame attribute
-    MapTableFrameInto(aAttributes, aData, aBorderStyle);
-  }
-}
 
 static void
 MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
                       nsRuleData* aData)
 {
   // XXX Bug 211636:  This function is used by a single style rule
   // that's used to match two different type of elements -- tables, and
   // table cells.  (nsHTMLTableCellElement overrides
@@ -1196,39 +1066,32 @@ MapAttributesIntoRule(const nsMappedAttr
         if (aData->mTableData->mBorderSpacing.mYValue.GetUnit() == eCSSUnit_Null)
           aData->mTableData->mBorderSpacing.mYValue.SetFloatValue(100.0f * value->GetPercentValue(), eCSSUnit_Pixel);
       }
     }
   } 
   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Table)) {
     const nsStyleDisplay* readDisplay = aData->mStyleContext->GetStyleDisplay();
     if (readDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CELL) {
-      MapTableBorderInto(aAttributes, aData, 0);
-
       const nsAttrValue* value;
       // layout
       if (aData->mTableData->mLayout.GetUnit() == eCSSUnit_Null) {
         value = aAttributes->GetAttr(nsGkAtoms::layout);
         if (value && value->Type() == nsAttrValue::eEnum)
           aData->mTableData->mLayout.SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
       }
       
       // cols
       value = aAttributes->GetAttr(nsGkAtoms::cols);
       if (value) {
         if (value->Type() == nsAttrValue::eInteger) 
           aData->mTableData->mCols.SetIntValue(value->GetIntegerValue(), eCSSUnit_Integer);
         else // COLS had no value, so it refers to all columns
           aData->mTableData->mCols.SetIntValue(NS_STYLE_TABLE_COLS_ALL, eCSSUnit_Enumerated);
       }
-
-      // rules
-      value = aAttributes->GetAttr(nsGkAtoms::rules);
-      if (value && value->Type() == nsAttrValue::eEnum)
-        aData->mTableData->mRules.SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
     }
   }
   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Margin)) {
     const nsStyleDisplay* readDisplay = aData->mStyleContext->GetStyleDisplay();
   
     if (readDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CELL) {
       // align; Check for enumerated type (it may be another type if
       // illegal)
@@ -1333,85 +1196,51 @@ MapAttributesIntoRule(const nsMappedAttr
     const nsStyleDisplay* readDisplay = aData->mStyleContext->GetStyleDisplay();
   
     if (readDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CELL)
       nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
   }
   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) {
     const nsStyleTableBorder* tableStyle = aData->mStyleContext->GetStyleTableBorder();
     const nsStyleDisplay* readDisplay = aData->mStyleContext->GetStyleDisplay();
-    if (readDisplay->mDisplay == NS_STYLE_DISPLAY_TABLE_CELL) {
-      if (NS_STYLE_BORDER_SEPARATE == tableStyle->mBorderCollapse) {
-        // Set the cell's border from the table in the separate border
-        // model. If there is a border on the table, then the mapping to
-        // rules=all will take care of borders in the collapsing model.
-        // But if rules="none", we don't want to do this.
-        const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::border);
-        const nsAttrValue* rulesValue = aAttributes->GetAttr(nsGkAtoms::rules);
-        if ((!rulesValue || rulesValue->Type() != nsAttrValue::eEnum ||
-             rulesValue->GetEnumValue() != NS_STYLE_TABLE_RULES_NONE) &&
-            value &&
-            ((value->Type() == nsAttrValue::eInteger &&
-              value->GetIntegerValue() > 0) ||
-             value->IsEmptyString())) {
-          if (aData->mMarginData->mBorderWidth.mLeft.GetUnit() == eCSSUnit_Null)
-            aData->mMarginData->mBorderWidth.mLeft.SetFloatValue(1.0f, eCSSUnit_Pixel);
-          if (aData->mMarginData->mBorderWidth.mRight.GetUnit() == eCSSUnit_Null)
-            aData->mMarginData->mBorderWidth.mRight.SetFloatValue(1.0f, eCSSUnit_Pixel);
-          if (aData->mMarginData->mBorderWidth.mTop.GetUnit() == eCSSUnit_Null)
-            aData->mMarginData->mBorderWidth.mTop.SetFloatValue(1.0f, eCSSUnit_Pixel);
-          if (aData->mMarginData->mBorderWidth.mBottom.GetUnit() == eCSSUnit_Null)
-            aData->mMarginData->mBorderWidth.mBottom.SetFloatValue(1.0f, eCSSUnit_Pixel);
-
-          PRUint8 borderStyle = NS_STYLE_BORDER_STYLE_INSET;
-
-          if (aData->mMarginData->mBorderStyle.mLeft.GetUnit() == eCSSUnit_Null)
-            aData->mMarginData->mBorderStyle.mLeft.SetIntValue(borderStyle, eCSSUnit_Enumerated);
-          if (aData->mMarginData->mBorderStyle.mRight.GetUnit() == eCSSUnit_Null)
-            aData->mMarginData->mBorderStyle.mRight.SetIntValue(borderStyle, eCSSUnit_Enumerated);
-          if (aData->mMarginData->mBorderStyle.mTop.GetUnit() == eCSSUnit_Null)
-            aData->mMarginData->mBorderStyle.mTop.SetIntValue(borderStyle, eCSSUnit_Enumerated);
-          if (aData->mMarginData->mBorderStyle.mBottom.GetUnit() == eCSSUnit_Null)
-            aData->mMarginData->mBorderStyle.mBottom.SetIntValue(borderStyle, eCSSUnit_Enumerated);
-        }
-      }
-    }
-    else {
-      PRUint8 borderStyle = NS_STYLE_BORDER_STYLE_OUTSET;
+    if (readDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CELL) {
       // bordercolor
       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::bordercolor);
       nscolor color;
       if (value && presContext->UseDocumentColors() &&
           value->GetColorValue(color)) {
         if (aData->mMarginData->mBorderColor.mLeft.GetUnit() == eCSSUnit_Null)
           aData->mMarginData->mBorderColor.mLeft.SetColorValue(color);
         if (aData->mMarginData->mBorderColor.mRight.GetUnit() == eCSSUnit_Null)
           aData->mMarginData->mBorderColor.mRight.SetColorValue(color);
         if (aData->mMarginData->mBorderColor.mTop.GetUnit() == eCSSUnit_Null)
           aData->mMarginData->mBorderColor.mTop.SetColorValue(color);
         if (aData->mMarginData->mBorderColor.mBottom.GetUnit() == eCSSUnit_Null)
           aData->mMarginData->mBorderColor.mBottom.SetColorValue(color);
-
-        borderStyle = NS_STYLE_BORDER_STYLE_SOLID; // compat, see bug 349655
-      }
-      else if (NS_STYLE_BORDER_COLLAPSE == tableStyle->mBorderCollapse) {
-        // make the color grey
-        nscolor color = NS_RGB(80, 80, 80);
-        if (aData->mMarginData->mBorderColor.mLeft.GetUnit() == eCSSUnit_Null)
-          aData->mMarginData->mBorderColor.mLeft.SetColorValue(color);
-        if (aData->mMarginData->mBorderColor.mRight.GetUnit() == eCSSUnit_Null)
-          aData->mMarginData->mBorderColor.mRight.SetColorValue(color);
-        if (aData->mMarginData->mBorderColor.mTop.GetUnit() == eCSSUnit_Null)
-          aData->mMarginData->mBorderColor.mTop.SetColorValue(color);
-        if (aData->mMarginData->mBorderColor.mBottom.GetUnit() == eCSSUnit_Null)
-          aData->mMarginData->mBorderColor.mBottom.SetColorValue(color);
       }
 
-      // border and frame
-      MapTableBorderInto(aAttributes, aData, borderStyle);
+      // border
+      const nsAttrValue* borderValue = aAttributes->GetAttr(nsGkAtoms::border);
+      if (borderValue) {
+        // border = 1 pixel default
+        PRInt32 borderThickness = 1;
+
+        if (borderValue->Type() == nsAttrValue::eInteger)
+          borderThickness = borderValue->GetIntegerValue();
+
+        // by default, set all border sides to the specified width
+        if (aData->mMarginData->mBorderWidth.mLeft.GetUnit() == eCSSUnit_Null)
+          aData->mMarginData->mBorderWidth.mLeft.SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
+        if (aData->mMarginData->mBorderWidth.mRight.GetUnit() == eCSSUnit_Null)
+          aData->mMarginData->mBorderWidth.mRight.SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
+        if (aData->mMarginData->mBorderWidth.mTop.GetUnit() == eCSSUnit_Null)
+          aData->mMarginData->mBorderWidth.mTop .SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
+        if (aData->mMarginData->mBorderWidth.mBottom.GetUnit() == eCSSUnit_Null)
+          aData->mMarginData->mBorderWidth.mBottom.SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
+      }
     }
   }
   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Background)) {
     const nsStyleDisplay* readDisplay = aData->mStyleContext->GetStyleDisplay();
   
     if (readDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CELL)
       nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aData);
   }
@@ -1421,26 +1250,24 @@ NS_IMETHODIMP_(PRBool)
 nsHTMLTableElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 {
   static const MappedAttributeEntry attributes[] = {
     { &nsGkAtoms::layout },
     { &nsGkAtoms::cellpadding },
     { &nsGkAtoms::cellspacing },
     { &nsGkAtoms::cols },
     { &nsGkAtoms::border },
-    { &nsGkAtoms::frame },
     { &nsGkAtoms::width },
     { &nsGkAtoms::height },
     { &nsGkAtoms::hspace },
     { &nsGkAtoms::vspace },
     
     { &nsGkAtoms::bordercolor },
     
     { &nsGkAtoms::align },
-    { &nsGkAtoms::rules },
     { nsnull }
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
     sBackgroundAttributeMap,
   };
--- a/layout/base/nsCSSRenderingBorders.cpp
+++ b/layout/base/nsCSSRenderingBorders.cpp
@@ -1047,21 +1047,16 @@ nsCSSBorderRenderer::DrawBorders()
     if (style == NS_STYLE_BORDER_STYLE_DASHED ||
         style == NS_STYLE_BORDER_STYLE_DOTTED)
     {
       // pretend that all borders aren't the same; we need to draw
       // things separately for dashed/dotting
       allBordersSame = PR_FALSE;
       dashedSides |= (1 << i);
     }
-
-    // just bail out entirely if RULES_MARKER
-    // got through (see bug 379419).
-    if (style & NS_STYLE_BORDER_STYLE_RULES_MARKER)
-      return;
   }
 
   SF(" allBordersSame: %d dashedSides: 0x%02x\n", allBordersSame, dashedSides);
 
   // Clamp the CTM to be pixel-aligned; we do this only
   // for translation-only matrices now, but we could do it
   // if the matrix has just a scale as well.  We should not
   // do it if there's a rotation.
--- a/layout/base/nsStyleConsts.h
+++ b/layout/base/nsStyleConsts.h
@@ -297,19 +297,16 @@
 #define NS_STYLE_BORDER_STYLE_DOTTED            3
 #define NS_STYLE_BORDER_STYLE_DASHED            4
 #define NS_STYLE_BORDER_STYLE_SOLID             5
 #define NS_STYLE_BORDER_STYLE_DOUBLE            6
 #define NS_STYLE_BORDER_STYLE_INSET             7
 #define NS_STYLE_BORDER_STYLE_OUTSET            8
 #define NS_STYLE_BORDER_STYLE_HIDDEN            9
 #define NS_STYLE_BORDER_STYLE_AUTO              10 // for outline-style only
-// a bit ORed onto the style for table border collapsing indicating that the style was 
-// derived from a table with its rules attribute set
-#define NS_STYLE_BORDER_STYLE_RULES_MARKER      0x10  
 
 // See nsStyleBorder mBorderImage
 #define NS_STYLE_BORDER_IMAGE_STRETCH           0
 #define NS_STYLE_BORDER_IMAGE_REPEAT            1
 #define NS_STYLE_BORDER_IMAGE_ROUND             2
 
 // See nsStyleDisplay
 #define NS_STYLE_CLEAR_NONE                     0
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -7567,17 +7567,19 @@ void nsFrame::DisplayIntrinsicWidthExit(
   if (!DR_state->mActive) return;
 
   NS_ASSERTION(aFrame, "non-null frame required");
   if (!aFrameTreeNode) return;
 
   DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode;
   if (treeNode->mDisplay) {
     DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
-    printf("Get%sWidth=%d\n", aType, aResult);
+    char width[16];
+    DR_state->PrettyUC(aResult, width);
+    printf("Get%sWidth=%s\n", aType, width);
   }
   DR_state->DeleteTreeNode(*treeNode);
 }
 
 void nsFrame::DisplayIntrinsicSizeExit(nsIFrame*            aFrame,
                                        const char*          aType,
                                        nsSize               aResult,
                                        void*                aFrameTreeNode)
--- a/layout/reftests/table-bordercollapse/bordercol.css
+++ b/layout/reftests/table-bordercollapse/bordercol.css
@@ -4,20 +4,20 @@ table {
 	}
 caption {
 	font-weight: bold;
 	font-style: italic;
 	}
 td {background-color:LightCyan }
 
 table.topLight {border-top: 1px solid #AFAFAF}
-table.bottom {border-bottom: 1px solid #505050}
+table.bottom {border-bottom: 1px solid black}
 table.bottomDark {border-bottom: 1px solid #444444}
 table.leftLight {border-left: 1px solid #AFAFAF}
-table.right {border-right: 1px solid  #505050}
+table.right {border-right: 1px solid  black}
 table.rightDark {border-right: 1px solid #444444}
-table.top {border-top: 1px solid  #505050}
-table.left {border-left: 1px solid  #505050}
+table.top {border-top: 1px solid  black}
+table.left {border-left: 1px solid  black}
 table.bc {border-collapse:collapse}
-tbody.border{border-top: 1px solid  #505050; border-bottom: 1px solid #505050; }
-tr.border{border-top: 1px solid  #505050; border-bottom: 1px solid  #505050; }
-td.border{border-left:1px solid #505050;}
+tbody.border{border-top: 1px solid  black; border-bottom: 1px solid black; }
+tr.border{border-top: 1px solid black; border-bottom: 1px solid  black; }
+td.border{border-left:1px solid black;}
 
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-1.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 50px; height: 50px;}
+</style>
+</head>
+<body>
+<table border><tr><td><div/></td></tr></table>
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-2.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 50px; height: 50px;}
+</style>
+</head>
+<body>
+<table border><td><div/></td></table>
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-3.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 50px; height: 50px;}
+</style>
+</head>
+<body>
+<table border><th><div/></th></table>
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-4.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 50px; height: 50px;}
+</style>
+</head>
+<body>
+<table border><tr><th><div/></th></tr></table>
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-5.xhtml
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+  <style>
+div {width: 50px; height: 50px;}
+</style>
+ </head>
+ <body>
+ <table border="1"><tr><th><div/></th></tr></table>
+ </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-6.xhtml
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+  <style>
+div {width: 50px; height: 50px;}
+</style>
+ </head>
+ <body>
+ <table border="1"><th><div/></th></table>
+ </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-7.xhtml
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+  <style>
+div {width: 50px; height: 50px;}
+</style>
+ </head>
+ <body>
+ <table border="1"><td><div/></td></table>
+ </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-8.html
@@ -0,0 +1,15 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 50px; height: 50px;}
+table {border-collapse:separate;
+       border: outset 1px  black;
+       }
+ td {border: inset 1px  black;} 
+</style>
+</head>
+<body>
+<table><tr><td><div/></td></tr></table>
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-frame-border-ref.html
@@ -0,0 +1,107 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 3px; height: 3px;}
+table.frame {border: outset thin ;}
+table.frameTop {border-top: outset thin ;}
+table.frameBottom {border-bottom: outset thin ;}
+table.frameRight {border-right: outset thin ;}
+table.frameLeft {border-left: outset thin ;}
+
+td.inner {border: inset thin;}
+
+</style>
+</head>
+<body>
+<table cellpadding="5" rules="all">
+<tr><th>frame/border</th><th>empty</th><th>border</th><th>border="0"</th><th>border="1"</th><th>border="3"</th></tr>
+<tr><th>empty</th>
+<td><table><tr><td><div/></td></tr></table></td></td>
+<td><table class="frame"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frame"><tr><td class="inner"><div/></td></tr></table></td>
+<td><table class="frame" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+<tr><th>frame</th>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frame"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frame"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table class="frame" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+<tr><th>frame="void"</th>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="above"</th>
+<td><table class="frameTop"><tr><td><div/></td></tr></table></td>
+<td><table class="frameTop"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frameTop"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table class="frameTop" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="below"</th>
+<td><table class="frameBottom"><tr><td><div/></td></tr></table></td>
+<td><table class="frameBottom"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frameBottom"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table class="frameBottom" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="hsides"</th>
+<td><table class="frameTop frameBottom"><tr><td><div/></td></tr></table></td>
+<td><table class="frameTop frameBottom"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frameTop frameBottom"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table class="frameTop frameBottom" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="lhs"</th>
+<td><table class="frameLeft"><tr><td><div/></td></tr></table></td>
+<td><table class="frameLeft"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frameLeft"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table class="frameLeft" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="rhs"</th>
+<td><table class="frameRight"><tr><td><div/></td></tr></table></td>
+<td><table class="frameRight"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frameRight"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table class="frameRight" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="vsides"</th>
+<td><table class="frameLeft frameRight"><tr><td><div/></td></tr></table></td>
+<td><table class="frameLeft frameRight"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frameLeft frameRight"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table class="frameLeft frameRight" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="box"</th>
+<td><table class="frame"><tr><td><div/></td></tr></table></td>
+<td><table class="frame"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frame"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table class="frame" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="border"</th>
+<td><table class="frame"><tr><td><div/></td></tr></table></td>
+<td><table class="frame"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table><tr><td><div/></td></tr></table></td>
+<td><table class="frame"><tr><td class="inner"><div/></td></tr></table></td></td>
+<td><table class="frame" style="border-width: 3px"><tr><td class="inner"><div/></td></tr></table></td>
+</tr>
+</table>
+
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-frame-border.html
@@ -0,0 +1,102 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 3px; height: 3px;}
+
+
+</style>
+</head>
+<body>
+<table cellpadding="5" rules="all">
+<tr><th>frame/border</th><th>empty</th><th>border</th><th>border="0"</th><th>border="1"</th><th>border="3"</th></tr>
+<tr><th>empty</th>
+<td><table><tr><td><div/></td></tr></table></td></td>
+<td><table border><tr><td><div/></td></tr></table></td></td>
+<td><table border="0"><tr><td><div/></td></tr></table></td>
+<td><table border="1"><tr><td><div/></td></tr></table></td>
+<td><table border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+<tr><th>frame</th>
+<td><table frame><tr><td><div/></td></tr></table></td>
+<td><table frame border><tr><td><div/></td></tr></table></td>
+<td><table frame border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+<tr><th>frame="void"</th>
+<td><table frame="void"><tr><td><div/></td></tr></table></td>
+<td><table frame="void" border><tr><td><div/></td></tr></table></td>
+<td><table frame="void" border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame="void" border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame="void" border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="above"</th>
+
+<td><table frame="above"><tr><td><div/></td></tr></table></td>
+<td><table frame="above" border><tr><td><div/></td></tr></table></td>
+<td><table frame="above" border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame="above" border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame="above" border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="below"</th>
+<td><table frame="below"><tr><td><div/></td></tr></table></td>
+<td><table frame="below" border><tr><td><div/></td></tr></table></td>
+<td><table frame="below" border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame="below" border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame="below" border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="hsides"</th>
+<td><table frame="hsides"><tr><td><div/></td></tr></table></td>
+<td><table frame="hsides" border><tr><td><div/></td></tr></table></td>
+<td><table frame="hsides" border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame="hsides" border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame="hsides" border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="lhs"</th>
+<td><table frame="lhs"><tr><td><div/></td></tr></table></td>
+<td><table frame="lhs" border><tr><td><div/></td></tr></table></td>
+<td><table frame="lhs" border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame="lhs" border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame="lhs" border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="rhs"</th>
+<td><table frame="rhs"><tr><td><div/></td></tr></table></td>
+<td><table frame="rhs" border><tr><td><div/></td></tr></table></td>
+<td><table frame="rhs" border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame="rhs" border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame="rhs" border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="vsides"</th>
+<td><table frame="vsides"><tr><td><div/></td></tr></table></td>
+<td><table frame="vsides" border><tr><td><div/></td></tr></table></td>
+<td><table frame="vsides" border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame="vsides" border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame="vsides" border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="box"</th>
+<td><table frame="box"><tr><td><div/></td></tr></table></td>
+<td><table frame="box" border><tr><td><div/></td></tr></table></td>
+<td><table frame="box" border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame="box" border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame="box" border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+
+<tr><th>frame="border"</th>
+<td><table frame="border"><tr><td><div/></td></tr></table></td>
+<td><table frame="border" border><tr><td><div/></td></tr></table></td>
+<td><table frame="border" border="0"><tr><td><div/></td></tr></table></td>
+<td><table frame="border" border="1"><tr><td><div/></td></tr></table></td>
+<td><table frame="border" border="3"><tr><td><div/></td></tr></table></td>
+</tr>
+</table>
+
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-ref.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 50px; height: 50px;}
+</style>
+</head>
+<body>
+<table border=1><tbody><tr><td><div/></td></tr></tbody></table>
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-rules-border-ref.html
@@ -0,0 +1,293 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 3px; height: 3px;}
+div {width: 3px; height: 3px;}
+table.frame {border: outset thin ;}
+
+table.bc{ border-collapse:collapse; border-style: hidden}
+.bcborder {border: 1px solid}
+td.inner {border: inset thin;}
+table.inner td {border: inset thin;}
+</style>
+</head>
+<body>
+<table cellpadding="5" rules="all">
+<tr><th>rules/border</th><th>empty</th><th>border</th><th>border="0"</th><th>border="1"</th><th>border="3"</th></tr>
+<tr><th>empty</th>
+<td><table>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="frame inner">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="frame inner">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="frame inner" style="border-width:3px">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+<tr><th>rules</th>
+<td><table>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="frame inner">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="frame inner">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="frame inner" style="border-width:3px">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+
+<tr><th>rules="none"</th>
+<td>
+<table>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="frame">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="frame">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="frame" style="border-width:3px">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+<tr><th>rules="groups"</th>
+<td>
+<table class="bc">
+   <colgroup class="bcborder"><col><col></colgroup>
+   <colgroup class="bcborder"><col></colgroup>
+   <thead class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc" style="border: 1px solid">
+   <colgroup class="bcborder"><col><col></colgroup>
+   <colgroup class="bcborder"><col></colgroup>
+   <thead class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc">
+   <colgroup class="bcborder"><col><col></colgroup>
+   <colgroup class="bcborder"><col></colgroup>
+   <thead class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc" style="border: 1px solid">
+   <colgroup class="bcborder"><col><col></colgroup>
+   <colgroup class="bcborder"><col></colgroup>
+   <thead class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc" style="border: 3px outset">
+   <colgroup class="bcborder"><col><col></colgroup>
+   <colgroup class="bcborder"><col></colgroup>
+   <thead class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody class="bcborder"><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+
+
+
+
+
+<tr><th>rules="rows"</th>
+<td>
+<table class="bc">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc" style="border: 1px solid">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc">
+  <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc" style="border: 1px solid">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc" style="border: 3px outset">
+  <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+
+<tr><th>rules="cols"</th>
+<td>
+<table table class="bc" >
+   <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table table class="bc" style="border: 1px solid">
+   <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table table class="bc" >
+   <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table table class="bc" style="border: 1px solid">
+   <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table table class="bc" style="border: 3px outset">
+   <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+
+<tr><th>rules="all"</th>
+<td>
+<table class="bc">
+   <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc" style="border: 1px solid">
+   <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc">
+  <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc" style="border: 1px solid">
+   <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table class="bc" style="border: 3px outset">
+  <colgroup><col class="bcborder"><col class="bcborder"></colgroup>
+   <colgroup><col class="bcborder"></colgroup>
+   <thead><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr><tr class="bcborder"><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+</table>
+
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-bordercollapse/borderhandling-rules-border.html
@@ -0,0 +1,287 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<style>
+div {width: 3px; height: 3px;}
+
+</style>
+</head>
+<body>
+<table cellpadding="5" rules="all">
+<tr><th>rules/border</th><th>empty</th><th>border</th><th>border="0"</th><th>border="1"</th><th>border="3"</th></tr>
+<tr><th>empty</th>
+<td><table>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table border>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table border="0">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table border="1">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table border="3">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+<tr><th>rules</th>
+<td><table rules>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules border>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules border="0">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules border="1">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules border="3">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+
+<tr><th>rules="none"</th>
+<td>
+<table rules="none">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="none" border>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="none" border="0">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="none" border="1">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="none" border="3">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+<tr><th>rules="groups"</th>
+<td>
+<table rules="groups">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="groups" border>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="groups" border="0">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="groups" border="1">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="groups" border="3">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+
+
+
+
+
+<tr><th>rules="rows"</th>
+<td>
+<table rules="rows">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="rows" border>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="rows" border="0">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="rows" border="1">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="rows" border="3">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+
+<tr><th>rules="cols"</th>
+<td>
+<table rules="cols">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="cols" border>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="cols" border="0">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="cols" border="1">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="cols" border="3">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+
+<tr><th>rules="all"</th>
+<td>
+<table rules="all">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="all" border>
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="all" border="0">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="all" border="1">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+<td><table rules="all" border="3">
+   <colgroup><col><col></colgroup>
+   <colgroup><col></colgroup>
+   <thead><tr><td><div/></td><td><div/></td><td><div/></td></tr></thead>
+   <tfoot><tr><td><div/></td><td><div/></td><td><div/></td></tr></tfoot>
+   <tbody><tr><td><div/></td><td><div/></td><td><div/></td></tr><tr><td><div/></td><td><div/></td><td><div/></td></tr></tbody>
+</table></td>
+</tr>
+</table>
+
+</body>
+</html>
\ No newline at end of file
--- a/layout/reftests/table-bordercollapse/reftest.list
+++ b/layout/reftests/table-bordercollapse/reftest.list
@@ -60,9 +60,18 @@ fails-if(MOZ_WIDGET_TOOLKIT=="cocoa") ==
 == frame_void_rules_groups.html frame_void_rules_groups_ref.html
 == frame_void_rules_none.html frame_void_rules_none_ref.html
 == frame_void_rules_rows.html frame_void_rules_rows_ref.html
 == frame_vsides_rules_all.html frame_vsides_rules_all_ref.html
 == frame_vsides_rules_cols.html frame_vsides_rules_cols_ref.html
 == frame_vsides_rules_groups.html frame_vsides_rules_groups_ref.html
 == frame_vsides_rules_none.html frame_vsides_rules_none_ref.html
 == frame_vsides_rules_rows.html frame_vsides_rules_rows_ref.html
-
+== borderhandling-1.html borderhandling-ref.html
+== borderhandling-2.html borderhandling-ref.html
+== borderhandling-3.html borderhandling-ref.html
+== borderhandling-4.html borderhandling-ref.html
+== borderhandling-5.xhtml borderhandling-ref.html
+== borderhandling-6.xhtml borderhandling-ref.html
+== borderhandling-7.xhtml borderhandling-ref.html
+== borderhandling-8.html borderhandling-ref.html
+== borderhandling-frame-border.html borderhandling-frame-border-ref.html
+== borderhandling-rules-border.html borderhandling-rules-border-ref.html
--- a/layout/style/html.css
+++ b/layout/style/html.css
@@ -194,20 +194,133 @@ table[align="left"] {
   float: left;
 }
 
 table[align="right"] {
   float: right;
   text-align: start;
 }
 
-table[rules]:not([rules="none"]) {
+
+/* border collapse rules */
+
+  /* Set hidden if we have 'frame' or 'rules' attribute.
+     Set it on all sides when we do so there's more consistency
+     in what authors should expect */
+
+  /* Put this first so 'border' and 'frame' rules can override it. */
+table[rules] { 
+  border: thin hidden; 
+}
+
+  /* 'border' before 'frame' so 'frame' overrides
+      A border with a given value should, of course, pass that value
+      as the border-width in pixels -> attr mapping */
+
+  /* 'border="0"' suppresses the border */
+table[border]:not([border="0"]) { 
+  border: thin outset; 
+}
+
+  
+table[frame] {
+  border: thin hidden;
+}
+
+/*increased specificity to compete with [border]:not([border="0"]) rule above*/
+table[frame][frame="void"]   { border-style: hidden; }
+table[frame][frame="above"]  { border-style: outset hidden hidden hidden; }
+table[frame][frame="below"]  { border-style: hidden hidden outset hidden; }
+table[frame][frame="lhs"]    { border-style: hidden hidden hidden outset; }
+table[frame][frame="rhs"]    { border-style: hidden outset hidden hidden; }
+table[frame][frame="hsides"] { border-style: outset hidden; }
+table[frame][frame="vsides"] { border-style: hidden outset; }
+table[frame][frame="box"],
+table[frame][frame="border"] { border-style: outset; }
+
+ 
+/* Internal Table Borders */
+
+  /* 'border' cell borders first */
+
+table[border]:not([border="0"])> * > tr > td,
+table[border]:not([border="0"])> * > tr > th,
+table[border]:not([border="0"])> * > td,
+table[border]:not([border="0"])> * > th,
+table[border]:not([border="0"])> td,
+table[border]:not([border="0"])> th
+{
+  border: thin inset;
+}
+
+/* collapse only if rules are really specified */
+table[rules]:not([rules="none"]):not([rules=""]) {
   border-collapse: collapse;
 }
-   
+
+/* only specified rules override 'border' settings  
+  (increased specificity to achieve this) */
+table[rules]:not([rules=""])> tr > td,
+table[rules]:not([rules=""])> * > tr > td,
+table[rules]:not([rules=""])> tr > th,
+table[rules]:not([rules=""])> * > tr > th,
+table[rules]:not([rules=""])> td,
+table[rules]:not([rules=""])> th
+{
+  border: thin none;
+}
+
+
+table[rules][rules="none"]  > tr > td,
+table[rules][rules="none"] > * > tr > td,
+table[rules][rules="none"] > tr > th,
+table[rules][rules="none"] > * > tr > th,
+table[rules][rules="none"] > td,
+table[rules][rules="none"] > th
+{
+  border: thin hidden;
+}
+
+table[rules][rules="all"] > tr > td,
+table[rules][rules="all"] > * > tr > td,
+table[rules][rules="all"] > tr > th,
+table[rules][rules="all"] > * > tr > th,
+table[rules][rules="all"] > td,
+table[rules][rules="all"] > th 
+{
+  border: thin solid ;
+}
+
+table[rules][rules="rows"] > tr,
+table[rules][rules="rows"] > * > tr {
+  border-top: thin solid;
+  border-bottom: thin solid;
+}
+
+
+table[rules][rules="cols"] > tr > td,
+table[rules][rules="cols"] > * > tr > td,
+table[rules][rules="cols"] > tr > th,
+table[rules][rules="cols"] > * > tr > th {
+  border-left: thin solid;
+  border-right: thin solid;
+}
+
+table[rules][rules="groups"] > colgroup {
+  border-left: thin solid;
+  border-right: thin solid;
+}
+table[rules][rules="groups"] > tfoot,
+table[rules][rules="groups"] > thead,
+table[rules][rules="groups"] > tbody {
+  border-top: thin solid;
+  border-bottom: thin solid;
+}
+  
+  
 /* caption inherits from table not table-outer */  
 caption {
   display: table-caption;
   text-align: center;
   -moz-box-sizing: border-box;
 }
 
 table[align="center"] > caption {
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -3066,38 +3066,16 @@ CSS_PROP_VISIBILITY(
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_None)
 CSS_PROP_TABLE(
     X,
     X,
     X,
     0,
     Table,
-    mFrame,
-    eCSSType_Value,
-    nsnull,
-    CSS_PROP_NO_OFFSET,
-    eStyleAnimType_None)
-CSS_PROP_TABLE(
-    X,
-    X,
-    X,
-    0,
-    Table,
-    mRules,
-    eCSSType_Value,
-    nsnull,
-    CSS_PROP_NO_OFFSET,
-    eStyleAnimType_None)
-CSS_PROP_TABLE(
-    X,
-    X,
-    X,
-    0,
-    Table,
     mCols,
     eCSSType_Value,
     nsnull,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_None)
 CSS_PROP_TABLE(
     X,
     X,
--- a/layout/style/nsCSSStruct.h
+++ b/layout/style/nsCSSStruct.h
@@ -502,18 +502,16 @@ struct nsCSSTable : public nsCSSStruct  
   ~nsCSSTable(void);
 
   nsCSSValue mBorderCollapse;
   nsCSSValuePair mBorderSpacing;
   nsCSSValue mCaptionSide;
   nsCSSValue mEmptyCells;
   
   nsCSSValue mLayout;
-  nsCSSValue mFrame; // Not mappable via CSS, only using HTML4 table attrs.
-  nsCSSValue mRules; // Not mappable via CSS, only using HTML4 table attrs.
   nsCSSValue mSpan; // Not mappable via CSS, only using HTML4 table attrs.
   nsCSSValue mCols; // Not mappable via CSS, only using HTML4 table attrs.
 private:
   nsCSSTable(const nsCSSTable& aOther); // NOT IMPLEMENTED
 };
 
 struct nsRuleDataTable : public nsCSSTable {
   nsRuleDataTable() {}
--- a/layout/style/nsHTMLStyleSheet.cpp
+++ b/layout/style/nsHTMLStyleSheet.cpp
@@ -118,178 +118,16 @@ nsHTMLStyleSheet::TableTHRule::MapRuleIn
       aRuleData->mTextData->mTextAlign.
         SetIntValue(NS_STYLE_TEXT_ALIGN_MOZ_CENTER_OR_INHERIT,
                     eCSSUnit_Enumerated);
     }
   }
   return NS_OK;
 }
 
-static void 
-ProcessTableRulesAttribute(void*       aStyleStruct, 
-                           nsRuleData* aRuleData,
-                           PRUint8     aSide,
-                           PRBool      aGroup,
-                           PRUint8     aRulesArg1,
-                           PRUint8     aRulesArg2,
-                           PRUint8     aRulesArg3)
-{
-  if (!aStyleStruct || !aRuleData || !aRuleData->mPresContext) return;
-
-  nsStyleContext* tableContext = aRuleData->mStyleContext->GetParent();
-  if (!tableContext)
-    return;
-  if (!aGroup) {
-    tableContext = tableContext->GetParent();
-    if (!tableContext)
-      return;
-  } 
-  
-  const nsStyleTable* tableData = tableContext->GetStyleTable();
-  if (aRulesArg1 == tableData->mRules ||
-      aRulesArg2 == tableData->mRules ||
-      aRulesArg3 == tableData->mRules) {
-    const nsStyleBorder* tableBorderData = tableContext->GetStyleBorder();
-    PRUint8 tableBorderStyle = tableBorderData->GetBorderStyle(aSide);
-
-    nsStyleBorder* borderData = (nsStyleBorder*)aStyleStruct;
-    if (!borderData)
-      return;
-    PRUint8 borderStyle = borderData->GetBorderStyle(aSide);
-    // XXX It appears that the style system erronously applies the custom style rule after css style, 
-    // consequently it does not properly fit into the casade. For now, assume that a border style of none
-    // implies that the style has not been set.
-    // XXXldb No, there's nothing wrong with the style system.  The problem
-    // is that the author of all these table rules made them work as
-    // post-resolve callbacks, which is an override mechanism that was meant
-    // to be used for other things.  They should instead map their rule data
-    // normally (see nsIStyleRule.h).
-    if (NS_STYLE_BORDER_STYLE_NONE == borderStyle) {
-      // use the table's border style if it is dashed or dotted, otherwise use solid
-      PRUint8 bStyle = ((NS_STYLE_BORDER_STYLE_NONE != tableBorderStyle) &&
-                        (NS_STYLE_BORDER_STYLE_HIDDEN != tableBorderStyle)) 
-                        ? tableBorderStyle : NS_STYLE_BORDER_STYLE_SOLID;
-      if ((NS_STYLE_BORDER_STYLE_DASHED != bStyle) && 
-          (NS_STYLE_BORDER_STYLE_DOTTED != bStyle) && 
-          (NS_STYLE_BORDER_STYLE_SOLID  != bStyle)) {
-        bStyle = NS_STYLE_BORDER_STYLE_SOLID;
-      }
-      bStyle |= NS_STYLE_BORDER_STYLE_RULES_MARKER;
-      borderData->SetBorderStyle(aSide, bStyle);
-
-      nscolor borderColor;
-      PRBool foreground;
-      borderData->GetBorderColor(aSide, borderColor, foreground);
-      if (foreground || NS_GET_A(borderColor) == 0) {
-        // use the table's border color if it is set, otherwise use black
-        nscolor tableBorderColor;
-        tableBorderData->GetBorderColor(aSide, tableBorderColor, foreground);
-        borderColor = (foreground || NS_GET_A(tableBorderColor) == 0)
-                        ? NS_RGB(0,0,0) : tableBorderColor;
-        borderData->SetBorderColor(aSide, borderColor);
-      }
-      // set the border width to be 1 pixel
-      borderData->SetBorderWidth(aSide, nsPresContext::CSSPixelsToAppUnits(1));
-    }
-  }
-}
-
-static void TbodyPostResolveCallback(void* aStyleStruct, nsRuleData* aRuleData)
-{
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_TOP, PR_TRUE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_GROUPS, NS_STYLE_TABLE_RULES_ROWS);
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_BOTTOM, PR_TRUE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_GROUPS, NS_STYLE_TABLE_RULES_ROWS);
-}
-
-NS_IMETHODIMP
-nsHTMLStyleSheet::TableTbodyRule::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) {
-    aRuleData->mCanStoreInRuleTree = PR_FALSE;
-    aRuleData->mPostResolveCallback = &TbodyPostResolveCallback;
-  }
-  return NS_OK;
-}
-// -----------------------------------------------------------
-
-static void RowPostResolveCallback(void* aStyleStruct, nsRuleData* aRuleData)
-{
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_TOP, PR_FALSE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_ROWS, NS_STYLE_TABLE_RULES_ROWS);
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_BOTTOM, PR_FALSE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_ROWS, NS_STYLE_TABLE_RULES_ROWS);
-}
-
-NS_IMETHODIMP
-nsHTMLStyleSheet::TableRowRule::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) {
-    aRuleData->mCanStoreInRuleTree = PR_FALSE;
-    aRuleData->mPostResolveCallback = &RowPostResolveCallback;
-  }
-  return NS_OK;
-}
-
-static void ColgroupPostResolveCallback(void* aStyleStruct, nsRuleData* aRuleData)
-{
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_LEFT, PR_TRUE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_GROUPS, NS_STYLE_TABLE_RULES_COLS);
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_RIGHT, PR_TRUE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_GROUPS, NS_STYLE_TABLE_RULES_COLS);
-}
-
-NS_IMETHODIMP
-nsHTMLStyleSheet::TableColgroupRule::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) {
-    aRuleData->mCanStoreInRuleTree = PR_FALSE;
-    aRuleData->mPostResolveCallback = &ColgroupPostResolveCallback;
-  }
-  return NS_OK;
-}
-
-static void ColPostResolveCallback(void* aStyleStruct, nsRuleData* aRuleData)
-{
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_LEFT, PR_FALSE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_COLS, NS_STYLE_TABLE_RULES_COLS);
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_RIGHT, PR_FALSE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_COLS, NS_STYLE_TABLE_RULES_COLS);
-}
-
-static void UngroupedColPostResolveCallback(void* aStyleStruct,
-                                            nsRuleData* aRuleData)
-{
-  // Pass PR_TRUE for aGroup, so that we find the table's style
-  // context correctly.
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_LEFT, PR_TRUE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_COLS, NS_STYLE_TABLE_RULES_COLS);
-  ::ProcessTableRulesAttribute(aStyleStruct, aRuleData, NS_SIDE_RIGHT, PR_TRUE, NS_STYLE_TABLE_RULES_ALL,
-                               NS_STYLE_TABLE_RULES_COLS, NS_STYLE_TABLE_RULES_COLS);
-}
-
-NS_IMETHODIMP
-nsHTMLStyleSheet::TableColRule::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) {
-    aRuleData->mCanStoreInRuleTree = PR_FALSE;
-    aRuleData->mPostResolveCallback = &ColPostResolveCallback;
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLStyleSheet::TableUngroupedColRule::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) {
-    aRuleData->mCanStoreInRuleTree = PR_FALSE;
-    aRuleData->mPostResolveCallback = &UngroupedColPostResolveCallback;
-  }
-  return NS_OK;
-}
 // -----------------------------------------------------------
 
 struct MappedAttrTableEntry : public PLDHashEntryHdr {
   nsMappedAttributes *mAttributes;
 };
 
 static PLDHashNumber
 MappedAttrTable_HashKey(PLDHashTable *table, const void *key)
@@ -343,61 +181,31 @@ nsHTMLStyleSheet::nsHTMLStyleSheet(void)
     mDocumentColorRule(nsnull)
 {
   mMappedAttrTable.ops = nsnull;
 }
 
 nsresult
 nsHTMLStyleSheet::Init()
 {
-  mTableTbodyRule = new TableTbodyRule();
-  if (!mTableTbodyRule)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(mTableTbodyRule);
-
-  mTableRowRule = new TableRowRule();
-  if (!mTableRowRule)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(mTableRowRule);
-
-  mTableColgroupRule = new TableColgroupRule();
-  if (!mTableColgroupRule)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(mTableColgroupRule);
-
-  mTableColRule = new TableColRule();
-  if (!mTableColRule)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(mTableColRule);
-
-  mTableUngroupedColRule = new TableUngroupedColRule();
-  if (!mTableUngroupedColRule)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(mTableUngroupedColRule);
-
   mTableTHRule = new TableTHRule();
   if (!mTableTHRule)
     return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(mTableTHRule);
   return NS_OK;
 }
 
 nsHTMLStyleSheet::~nsHTMLStyleSheet()
 {
   NS_IF_RELEASE(mURL);
 
   NS_IF_RELEASE(mLinkRule);
   NS_IF_RELEASE(mVisitedRule);
   NS_IF_RELEASE(mActiveRule);
   NS_IF_RELEASE(mDocumentColorRule);
-  NS_IF_RELEASE(mTableTbodyRule);
-  NS_IF_RELEASE(mTableRowRule);
-  NS_IF_RELEASE(mTableColgroupRule);
-  NS_IF_RELEASE(mTableColRule);
-  NS_IF_RELEASE(mTableUngroupedColRule);
   NS_IF_RELEASE(mTableTHRule);
 
   if (mMappedAttrTable.ops)
     PL_DHashTableFinish(&mMappedAttrTable);
 }
 
 NS_IMPL_ISUPPORTS2(nsHTMLStyleSheet, nsIStyleSheet, nsIStyleRuleProcessor)
 
@@ -449,34 +257,16 @@ nsHTMLStyleSheet::RulesMatching(ElementR
               ruleWalker->Forward(mActiveRule);
           }
         } // end link/visited/active rules
       } // end A tag
       // add the rule to handle text-align for a <th>
       else if (tag == nsGkAtoms::th) {
         ruleWalker->Forward(mTableTHRule);
       }
-      else if (tag == nsGkAtoms::tr) {
-        ruleWalker->Forward(mTableRowRule);
-      }
-      else if ((tag == nsGkAtoms::thead) || (tag == nsGkAtoms::tbody) || (tag == nsGkAtoms::tfoot)) {
-        ruleWalker->Forward(mTableTbodyRule);
-      }
-      else if (tag == nsGkAtoms::col) {
-        nsIContent* parent = aData->mParentContent;
-        if (parent && parent->IsHTML() &&
-            parent->Tag() == nsGkAtoms::colgroup) {
-          ruleWalker->Forward(mTableColRule);
-        } else {
-          ruleWalker->Forward(mTableUngroupedColRule);
-        }
-      }
-      else if (tag == nsGkAtoms::colgroup) {
-        ruleWalker->Forward(mTableColgroupRule);
-      }
       else if (tag == nsGkAtoms::table) {
         if (aData->mCompatMode == eCompatibility_NavQuirks) {
           nscolor bodyColor;
           nsresult rv =
             GetBodyColor(ruleWalker->CurrentNode()->GetPresContext(),
                          &bodyColor);
           if (NS_SUCCEEDED(rv) &&
               (!mDocumentColorRule || bodyColor != mDocumentColorRule->mColor)) {
@@ -562,23 +352,16 @@ NS_IMETHODIMP
 nsHTMLStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
 {
-  nsIAtom* pseudoTag = aData->mPseudoTag;
-  if (pseudoTag == nsCSSAnonBoxes::tableCol) {
-    nsRuleWalker *ruleWalker = aData->mRuleWalker;
-    if (ruleWalker) {
-      ruleWalker->Forward(mTableColRule);
-    }
-  }
   return NS_OK;
 }
 
 #ifdef MOZ_XUL
 NS_IMETHODIMP
 nsHTMLStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
 {
   return NS_OK;
--- a/layout/style/nsHTMLStyleSheet.h
+++ b/layout/style/nsHTMLStyleSheet.h
@@ -150,81 +150,22 @@ private:
   friend class TableTHRule;
   class TableTHRule: public GenericTableRule {
   public:
     TableTHRule() {}
 
     NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
   };
 
-  // this rule handles borders on a <thead>, <tbody>, <tfoot> when rules
-  // is set on its <table>
-  class TableTbodyRule;
-  friend class TableTbodyRule;
-  class TableTbodyRule: public GenericTableRule {
-  public:
-    TableTbodyRule() {}
-
-    NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
-  };
-
-  // this rule handles borders on a <row> when rules is set on its <table>
-  class TableRowRule;
-  friend class TableRowRule;
-  class TableRowRule: public GenericTableRule {
-  public:
-    TableRowRule() {}
-
-    NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
-  };
-
-  // this rule handles borders on a <colgroup> when rules is set on its <table>
-  class TableColgroupRule;
-  friend class TableColgroupRule;
-  class TableColgroupRule: public GenericTableRule {
-  public:
-    TableColgroupRule() {}
-
-    NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
-  };
-
-  // this rule handles borders on a <col> when rules is set on its <table>.
-  // This should only be used for <col>s which are in a colgroup or anonymous
-  // cols.
-  class TableColRule;
-  friend class TableColRule;
-  class TableColRule: public GenericTableRule {
-  public:
-    TableColRule() {}
-
-    NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
-  };
-
-  // this rule handles borders on a <col> when rules is set on its <table>.
-  // This should only be used for <col>s which are not in a colgroup.
-  class TableUngroupedColRule;
-  friend class TableUngroupedColRule;
-  class TableUngroupedColRule: public GenericTableRule {
-  public:
-    TableUngroupedColRule() {}
-
-    NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
-  };
-
   nsIURI*              mURL;
   nsIDocument*         mDocument;
   HTMLColorRule*       mLinkRule;
   HTMLColorRule*       mVisitedRule;
   HTMLColorRule*       mActiveRule;
   HTMLColorRule*       mDocumentColorRule;
-  TableTbodyRule*      mTableTbodyRule;
-  TableRowRule*        mTableRowRule;
-  TableColgroupRule*   mTableColgroupRule;
-  TableColRule*        mTableColRule;
-  TableUngroupedColRule* mTableUngroupedColRule;
   TableTHRule*         mTableTHRule;
 
   PLDHashTable         mMappedAttrTable;
 };
 
 // XXX convenience method. Calls Initialize() automatically.
 nsresult
 NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult, nsIURI* aURL, 
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -5243,24 +5243,16 @@ nsRuleNode::ComputeTableData(void* aStar
 {
   COMPUTE_START_RESET(Table, (), table, parentTable, Table, tableData)
 
   // table-layout: enum, inherit, initial
   SetDiscrete(tableData.mLayout, table->mLayoutStrategy, canStoreInRuleTree,
               SETDSC_ENUMERATED, parentTable->mLayoutStrategy,
               NS_STYLE_TABLE_LAYOUT_AUTO, 0, 0, 0, 0);
 
-  // rules: enum (not a real CSS prop)
-  if (eCSSUnit_Enumerated == tableData.mRules.GetUnit())
-    table->mRules = tableData.mRules.GetIntValue();
-
-  // frame: enum (not a real CSS prop)
-  if (eCSSUnit_Enumerated == tableData.mFrame.GetUnit())
-    table->mFrame = tableData.mFrame.GetIntValue();
-
   // cols: enum, int (not a real CSS prop)
   if (eCSSUnit_Enumerated == tableData.mCols.GetUnit() ||
       eCSSUnit_Integer == tableData.mCols.GetUnit())
     table->mCols = tableData.mCols.GetIntValue();
 
   // span: pixels (not a real CSS prop)
   if (eCSSUnit_Enumerated == tableData.mSpan.GetUnit() ||
       eCSSUnit_Integer == tableData.mSpan.GetUnit())
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -4599,52 +4599,38 @@ static PRUint8 styleToPriority[13] = { 0
 #define CELL_CORNER PR_TRUE
 
 /** return the border style, border color for a given frame and side
   * @param aFrame           - query the info for this frame 
   * @param aSide            - the side of the frame
   * @param aStyle           - the border style
   * @param aColor           - the border color
   * @param aTableIsLTR      - table direction is LTR
-  * @param aIgnoreTableEdge - if is a table edge any borders set for the purpose
-  *                           of satisfying the rules attribute should be ignored
   */
 static void 
 GetColorAndStyle(const nsIFrame*  aFrame,
                  PRUint8          aSide,
                  PRUint8&         aStyle,
                  nscolor&         aColor,
-                 PRBool           aTableIsLTR,
-                 PRBool           aIgnoreTableEdge)
+                 PRBool           aTableIsLTR)
 {
   NS_PRECONDITION(aFrame, "null frame");
   // initialize out arg
   aColor = 0;
   const nsStyleBorder* styleData = aFrame->GetStyleBorder();
   if(!aTableIsLTR) { // revert the directions
     if (NS_SIDE_RIGHT == aSide) {
       aSide = NS_SIDE_LEFT;
     }
     else if (NS_SIDE_LEFT == aSide) {
       aSide = NS_SIDE_RIGHT;
     }
   }
   aStyle = styleData->GetBorderStyle(aSide);
 
-  // if the rules marker is set, set the style either to none or remove the mask
-  if (NS_STYLE_BORDER_STYLE_RULES_MARKER & aStyle) {
-    if (aIgnoreTableEdge) {
-      aStyle = NS_STYLE_BORDER_STYLE_NONE;
-      return;
-    }
-    else {
-      aStyle &= ~NS_STYLE_BORDER_STYLE_RULES_MARKER;
-    }
-  }
-
   if ((NS_STYLE_BORDER_STYLE_NONE == aStyle) ||
       (NS_STYLE_BORDER_STYLE_HIDDEN == aStyle)) {
     return;
   }
   PRBool foreground;
   styleData->GetBorderColor(aSide, aColor, foreground);
   if (foreground) {
     aColor = aFrame->GetStyleColor()->mColor;
@@ -4652,58 +4638,52 @@ GetColorAndStyle(const nsIFrame*  aFrame
 }
 
 /** coerce the paint style as required by CSS2.1
   * @param aFrame           - query the info for this frame 
   * @param aSide            - the side of the frame
   * @param aStyle           - the border style
   * @param aColor           - the border color
   * @param aTableIsLTR      - table direction is LTR
-  * @param aIgnoreTableEdge - if is a table edge any borders set for the purpose
-  *                           of satisfying the rules attribute should be ignored
   */
 static void
 GetPaintStyleInfo(const nsIFrame*  aFrame,
                   PRUint8          aSide,
                   PRUint8&         aStyle,
                   nscolor&         aColor,
-                  PRBool           aTableIsLTR,
-                  PRBool           aIgnoreTableEdge)
-{
-  GetColorAndStyle(aFrame, aSide, aStyle, aColor, aTableIsLTR, aIgnoreTableEdge);
+                  PRBool           aTableIsLTR)
+{
+  GetColorAndStyle(aFrame, aSide, aStyle, aColor, aTableIsLTR);
   if (NS_STYLE_BORDER_STYLE_INSET    == aStyle) {
     aStyle = NS_STYLE_BORDER_STYLE_RIDGE;
   }
   else if (NS_STYLE_BORDER_STYLE_OUTSET    == aStyle) {
     aStyle = NS_STYLE_BORDER_STYLE_GROOVE;
   }
 }
 
 /** return the border style, border color and the width in pixel for a given
   * frame and side
   * @param aFrame           - query the info for this frame 
   * @param aSide            - the side of the frame
   * @param aStyle           - the border style
   * @param aColor           - the border color
   * @param aTableIsLTR      - table direction is LTR
-  * @param aIgnoreTableEdge - if is a table edge any borders set for the purpose
-  *                           of satisfying the rules attribute should be ignored
   * @param aWidth           - the border width in px.
   * @param aTwipsToPixels   - conversion factor from twips to pixel
   */
 static void
 GetColorAndStyle(const nsIFrame*  aFrame,
                  PRUint8          aSide,
                  PRUint8&         aStyle,
                  nscolor&         aColor,
                  PRBool           aTableIsLTR,
-                 PRBool           aIgnoreTableEdge,
                  BCPixelSize&     aWidth)
 {
-  GetColorAndStyle(aFrame, aSide, aStyle, aColor, aTableIsLTR, aIgnoreTableEdge);
+  GetColorAndStyle(aFrame, aSide, aStyle, aColor, aTableIsLTR);
   if ((NS_STYLE_BORDER_STYLE_NONE == aStyle) ||
       (NS_STYLE_BORDER_STYLE_HIDDEN == aStyle)) {
     aWidth = 0;
     return;
   }
   const nsStyleBorder* styleData = aFrame->GetStyleBorder();
   nscoord width;
   if(!aTableIsLTR) { // revert the directions
@@ -4809,29 +4789,26 @@ CompareBorders(PRBool              aIsCo
     *aFirstDominates = firstDominates;
 
   if (firstDominates)
     return aBorder1;
   return aBorder2;
 }
 
 /** calc the dominant border by considering the table, row/col group, row/col,
-  * cell. At the table edges borders coming from the 'rules' attribute should
-  * be ignored as they are only inner borders.
+  * cell. 
   * Depending on whether the side is vertical or horizontal and whether
   * adjacent frames are taken into account the ownership of a single border
   * segment is defined. The return value is the dominating border
   * The cellmap stores only top and left borders for each cellmap position.
   * If the cell border is owned by the cell that is left of the border
   * it will be an adjacent owner aka eAjaCellOwner. See celldata.h for the other
   * scenarios with a adjacent owner.
   * @param xxxFrame         - the frame for style information, might be zero if
   *                           it should not be considered
-  * @param aIgnoreTableEdge - if true the border should be ignored at the table
-  *                           edge, as rules can be drawn only inside the table
   * @param aSide            - side of the frames that should be considered
   * @param aAja             - the border comparison takes place from the point of
   *                           a frame that is adjacent to the cellmap entry, for
   *                           when a cell owns its lower border it will be the
   *                           adjacent owner as in the cellmap only top and left
   *                           borders are stored. 
   * @param aTwipsToPixels   - conversion factor as borders need to be drawn pixel
   *                           aligned.
@@ -4839,71 +4816,70 @@ CompareBorders(PRBool              aIsCo
 static BCCellBorder
 CompareBorders(const nsIFrame*  aTableFrame,
                const nsIFrame*  aColGroupFrame,
                const nsIFrame*  aColFrame,
                const nsIFrame*  aRowGroupFrame,
                const nsIFrame*  aRowFrame,
                const nsIFrame*  aCellFrame,
                PRBool           aTableIsLTR,
-               PRBool           aIgnoreTableEdge,
                PRUint8          aSide,
                PRBool           aAja)
 {
   BCCellBorder border, tempBorder;
   PRBool horizontal = (NS_SIDE_TOP == aSide) || (NS_SIDE_BOTTOM == aSide);
 
   // start with the table as dominant if present
   if (aTableFrame) {
-    GetColorAndStyle(aTableFrame, aSide, border.style, border.color, aTableIsLTR, aIgnoreTableEdge, border.width);
+    GetColorAndStyle(aTableFrame, aSide, border.style, border.color, aTableIsLTR, border.width);
     border.owner = eTableOwner;
     if (NS_STYLE_BORDER_STYLE_HIDDEN == border.style) {
       return border;
     }
   }
   // see if the colgroup is dominant
   if (aColGroupFrame) {
-    GetColorAndStyle(aColGroupFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, aIgnoreTableEdge, tempBorder.width);
+    GetColorAndStyle(aColGroupFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, tempBorder.width);
     tempBorder.owner = (aAja && !horizontal) ? eAjaColGroupOwner : eColGroupOwner;
     // pass here and below PR_FALSE for aSecondIsHorizontal as it is only used for corner calculations.
     border = CompareBorders(!CELL_CORNER, border, tempBorder, PR_FALSE);
     if (NS_STYLE_BORDER_STYLE_HIDDEN == border.style) {
       return border;
     }
   }
   // see if the col is dominant
   if (aColFrame) {
-    GetColorAndStyle(aColFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, aIgnoreTableEdge, tempBorder.width);
+    GetColorAndStyle(aColFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, tempBorder.width);
     tempBorder.owner = (aAja && !horizontal) ? eAjaColOwner : eColOwner;
     border = CompareBorders(!CELL_CORNER, border, tempBorder, PR_FALSE);
     if (NS_STYLE_BORDER_STYLE_HIDDEN == border.style) {
       return border;
     }
   }
   // see if the rowgroup is dominant
   if (aRowGroupFrame) {
-    GetColorAndStyle(aRowGroupFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, aIgnoreTableEdge, tempBorder.width);
+    GetColorAndStyle(aRowGroupFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, tempBorder.width);
     tempBorder.owner = (aAja && horizontal) ? eAjaRowGroupOwner : eRowGroupOwner;
     border = CompareBorders(!CELL_CORNER, border, tempBorder, PR_FALSE);
     if (NS_STYLE_BORDER_STYLE_HIDDEN == border.style) {
       return border;
     }
   }
   // see if the row is dominant
   if (aRowFrame) {
-    GetColorAndStyle(aRowFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, aIgnoreTableEdge, tempBorder.width);
+    GetColorAndStyle(aRowFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, tempBorder.width);
     tempBorder.owner = (aAja && horizontal) ? eAjaRowOwner : eRowOwner;
     border = CompareBorders(!CELL_CORNER, border, tempBorder, PR_FALSE);
     if (NS_STYLE_BORDER_STYLE_HIDDEN == border.style) {
       return border;
     }
   }
   // see if the cell is dominant
   if (aCellFrame) {
-    GetColorAndStyle(aCellFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, aIgnoreTableEdge, tempBorder.width);
+    GetColorAndStyle(aCellFrame, aSide, tempBorder.style, tempBorder.color, aTableIsLTR, tempBorder.width);
     tempBorder.owner = (aAja) ? eAjaCellOwner : eCellOwner;
     border = CompareBorders(!CELL_CORNER, border, tempBorder, PR_FALSE);
   }
   return border;
 }
 
 static PRBool 
 Perpendicular(PRUint8 aSide1, 
@@ -5258,152 +5234,146 @@ nsTableFrame::ExpandBCDamageArea(nsRect&
 
 #define MAX_TABLE_BORDER_WIDTH 255
 static PRUint8
 LimitBorderWidth(PRUint16 aWidth)
 {
   return NS_MIN(PRUint16(MAX_TABLE_BORDER_WIDTH), aWidth);
 }
 
-#define TABLE_EDGE  PR_TRUE
 #define ADJACENT    PR_TRUE
 #define HORIZONTAL  PR_TRUE
 
 void
 BCMapCellInfo::SetTableTopLeftContBCBorder()
 {
   BCCellBorder currentBorder;
   //calculate continuous top first row & rowgroup border: special case
   //because it must include the table in the collapse
   if (mTopRow) {
     currentBorder = CompareBorders(mTableFrame, nsnull, nsnull, mRowGroup,
                                    mTopRow, nsnull, mTableIsLTR,
-                                   TABLE_EDGE, NS_SIDE_TOP, !ADJACENT);
+                                   NS_SIDE_TOP, !ADJACENT);
     mTopRow->SetContinuousBCBorderWidth(NS_SIDE_TOP, currentBorder.width);
   }
   if (mCgAtRight && mColGroup) {
     //calculate continuous top colgroup border once per colgroup
     currentBorder = CompareBorders(mTableFrame, mColGroup, nsnull, mRowGroup,
                                    mTopRow, nsnull, mTableIsLTR,
-                                   TABLE_EDGE, NS_SIDE_TOP, !ADJACENT);
+                                   NS_SIDE_TOP, !ADJACENT);
     mColGroup->SetContinuousBCBorderWidth(NS_SIDE_TOP, currentBorder.width);
   }
   if (0 == mColIndex) {
     currentBorder = CompareBorders(mTableFrame, mColGroup, mLeftCol, nsnull,
-                                   nsnull, nsnull, mTableIsLTR, TABLE_EDGE,
-                                   NS_SIDE_LEFT, !ADJACENT);
+                                   nsnull, nsnull, mTableIsLTR, NS_SIDE_LEFT,
+                                   !ADJACENT);
     mTableFrame->SetContinuousLeftBCBorderWidth(currentBorder.width);
   }
 }
 
 void
 BCMapCellInfo::SetRowGroupLeftContBCBorder()
 {
   BCCellBorder currentBorder;
   //get row group continuous borders
   if (mRgAtBottom && mRowGroup) { //once per row group, so check for bottom
      currentBorder = CompareBorders(mTableFrame, mColGroup, mLeftCol, mRowGroup,
-                                    nsnull, nsnull, mTableIsLTR, TABLE_EDGE,
-                                    NS_SIDE_LEFT, !ADJACENT);
+                                    nsnull, nsnull, mTableIsLTR, NS_SIDE_LEFT,
+                                    !ADJACENT);
      mRowGroup->SetContinuousBCBorderWidth(mStartSide, currentBorder.width);
   }
 }
 
 void
 BCMapCellInfo::SetRowGroupRightContBCBorder()
 {
   BCCellBorder currentBorder;
   //get row group continuous borders
   if (mRgAtBottom && mRowGroup) { //once per mRowGroup, so check for bottom
     currentBorder = CompareBorders(mTableFrame, mColGroup, mRightCol, mRowGroup,
-                                   nsnull, nsnull, mTableIsLTR, TABLE_EDGE,
-                                   NS_SIDE_RIGHT, ADJACENT);
+                                   nsnull, nsnull, mTableIsLTR, NS_SIDE_RIGHT,
+                                   ADJACENT);
     mRowGroup->SetContinuousBCBorderWidth(mEndSide, currentBorder.width);
   }
 }
 
 void
 BCMapCellInfo::SetColumnTopRightContBCBorder()
 {
   BCCellBorder currentBorder;
   //calculate column continuous borders
   //we only need to do this once, so we'll do it only on the first row
   currentBorder = CompareBorders(mTableFrame, mCurrentColGroupFrame,
                                  mCurrentColFrame, mRowGroup, mTopRow, nsnull,
-                                 mTableIsLTR, TABLE_EDGE, NS_SIDE_TOP,
-                                 !ADJACENT);
+                                 mTableIsLTR, NS_SIDE_TOP, !ADJACENT);
   ((nsTableColFrame*) mCurrentColFrame)->SetContinuousBCBorderWidth(NS_SIDE_TOP,
                                                            currentBorder.width);
   if (mNumTableCols == GetCellEndColIndex() + 1) {
     currentBorder = CompareBorders(mTableFrame, mCurrentColGroupFrame,
                                    mCurrentColFrame, nsnull, nsnull, nsnull,
-                                   mTableIsLTR, TABLE_EDGE, NS_SIDE_RIGHT,
-                                   !ADJACENT);
+                                   mTableIsLTR, NS_SIDE_RIGHT, !ADJACENT);
   }
   else {
     currentBorder = CompareBorders(nsnull, mCurrentColGroupFrame,
                                    mCurrentColFrame, nsnull,nsnull, nsnull,
-                                   mTableIsLTR, !TABLE_EDGE, NS_SIDE_RIGHT,
-                                   !ADJACENT);
+                                   mTableIsLTR, NS_SIDE_RIGHT, !ADJACENT);
   }
   mCurrentColFrame->SetContinuousBCBorderWidth(NS_SIDE_RIGHT,
                                                currentBorder.width);
 }
 
 void
 BCMapCellInfo::SetColumnBottomContBCBorder()
 {
   BCCellBorder currentBorder;
   //get col continuous border
   currentBorder = CompareBorders(mTableFrame, mCurrentColGroupFrame,
                                  mCurrentColFrame, mRowGroup, mBottomRow,
-                                 nsnull, mTableIsLTR, TABLE_EDGE,
-                                 NS_SIDE_BOTTOM, ADJACENT);
+                                 nsnull, mTableIsLTR, NS_SIDE_BOTTOM, ADJACENT);
   mCurrentColFrame->SetContinuousBCBorderWidth(NS_SIDE_BOTTOM,
                                                currentBorder.width);
 }
 
 void
 BCMapCellInfo::SetColGroupBottomContBCBorder()
 {
   BCCellBorder currentBorder;
   if (mColGroup) {
     currentBorder = CompareBorders(mTableFrame, mColGroup, nsnull, mRowGroup,
-                                   mBottomRow, nsnull, mTableIsLTR, TABLE_EDGE,
+                                   mBottomRow, nsnull, mTableIsLTR,
                                    NS_SIDE_BOTTOM, ADJACENT);
     mColGroup->SetContinuousBCBorderWidth(NS_SIDE_BOTTOM, currentBorder.width);
   }
 }
 
 void
 BCMapCellInfo::SetRowGroupBottomContBCBorder()
 {
   BCCellBorder currentBorder;
   if (mRowGroup) {
     currentBorder = CompareBorders(mTableFrame, nsnull, nsnull, mRowGroup,
-                                   mBottomRow, nsnull, mTableIsLTR, TABLE_EDGE,
+                                   mBottomRow, nsnull, mTableIsLTR,
                                    NS_SIDE_BOTTOM, ADJACENT);
     mRowGroup->SetContinuousBCBorderWidth(NS_SIDE_BOTTOM, currentBorder.width);
   }
 }
 
 void
 BCMapCellInfo::SetInnerRowGroupBottomContBCBorder(const nsIFrame* aNextRowGroup,
                                                   nsTableRowFrame* aNextRow)
 {
   BCCellBorder currentBorder, adjacentBorder;
   
   const nsIFrame* rowgroup = (mRgAtBottom) ? mRowGroup : nsnull;
   currentBorder = CompareBorders(nsnull, nsnull, nsnull, rowgroup, mBottomRow,
-                                 nsnull, mTableIsLTR, !TABLE_EDGE,
-                                 NS_SIDE_BOTTOM, ADJACENT);
+                                 nsnull, mTableIsLTR, NS_SIDE_BOTTOM, ADJACENT);
 
   adjacentBorder = CompareBorders(nsnull, nsnull, nsnull, aNextRowGroup,
-                                  aNextRow, nsnull, mTableIsLTR, !TABLE_EDGE,
-                                  NS_SIDE_TOP, !ADJACENT);
+                                  aNextRow, nsnull, mTableIsLTR, NS_SIDE_TOP,
+                                  !ADJACENT);
   currentBorder = CompareBorders(PR_FALSE, currentBorder, adjacentBorder,
                                  HORIZONTAL);
   if (aNextRow) {
     aNextRow->SetContinuousBCBorderWidth(NS_SIDE_TOP, currentBorder.width);
   }
   if (mRgAtBottom && mRowGroup) {
     mRowGroup->SetContinuousBCBorderWidth(NS_SIDE_BOTTOM, currentBorder.width);
   }
@@ -5412,30 +5382,30 @@ BCMapCellInfo::SetInnerRowGroupBottomCon
 void
 BCMapCellInfo::SetRowLeftContBCBorder()
 {
   //get row continuous borders
   if (mCurrentRowFrame) {
     BCCellBorder currentBorder;
     currentBorder = CompareBorders(mTableFrame, mColGroup, mLeftCol, mRowGroup,
                                    mCurrentRowFrame, nsnull, mTableIsLTR,
-                                   TABLE_EDGE, NS_SIDE_LEFT, !ADJACENT);
+                                   NS_SIDE_LEFT, !ADJACENT);
     mCurrentRowFrame->SetContinuousBCBorderWidth(mStartSide,
                                                  currentBorder.width);
   }
 }
 
 void
 BCMapCellInfo::SetRowRightContBCBorder()
 {
   if (mCurrentRowFrame) {
     BCCellBorder currentBorder;
     currentBorder = CompareBorders(mTableFrame, mColGroup, mRightCol, mRowGroup,
                                    mCurrentRowFrame, nsnull, mTableIsLTR,
-                                   TABLE_EDGE, NS_SIDE_RIGHT, ADJACENT);
+                                   NS_SIDE_RIGHT, ADJACENT);
     mCurrentRowFrame->SetContinuousBCBorderWidth(mEndSide,
                                                  currentBorder.width);
   }
 }
 void
 BCMapCellInfo::SetTableTopBorderWidth(BCPixelSize aWidth)
 {
   mTableBCData->mTopBorderWidth =
@@ -5557,71 +5527,71 @@ BCMapCellInfo::IncrementRow(PRBool aRese
   mCurrentRowFrame = (aResetToTopRowOfCell) ? mTopRow :
                                                 mCurrentRowFrame->GetNextRow();
 }
 
 BCCellBorder
 BCMapCellInfo::GetTopEdgeBorder()
 {
   return CompareBorders(mTableFrame, mCurrentColGroupFrame, mCurrentColFrame,
-                        mRowGroup, mTopRow, mCell, mTableIsLTR, TABLE_EDGE,
-                        NS_SIDE_TOP, !ADJACENT);
+                        mRowGroup, mTopRow, mCell, mTableIsLTR, NS_SIDE_TOP,
+                        !ADJACENT);
 }
 
 BCCellBorder
 BCMapCellInfo::GetBottomEdgeBorder()
 {
   return CompareBorders(mTableFrame, mCurrentColGroupFrame, mCurrentColFrame,
-                        mRowGroup, mBottomRow, mCell, mTableIsLTR, TABLE_EDGE,
+                        mRowGroup, mBottomRow, mCell, mTableIsLTR,
                         NS_SIDE_BOTTOM, ADJACENT);
 }
 BCCellBorder
 BCMapCellInfo::GetLeftEdgeBorder()
 {
   return CompareBorders(mTableFrame, mColGroup, mLeftCol, mRowGroup,
-                        mCurrentRowFrame, mCell, mTableIsLTR, TABLE_EDGE,
-                        NS_SIDE_LEFT, !ADJACENT);
+                        mCurrentRowFrame, mCell, mTableIsLTR, NS_SIDE_LEFT,
+                        !ADJACENT);
 }
 BCCellBorder
 BCMapCellInfo::GetRightEdgeBorder()
 {
   return CompareBorders(mTableFrame, mColGroup, mRightCol, mRowGroup,
-                        mCurrentRowFrame, mCell, mTableIsLTR, TABLE_EDGE,
-                        NS_SIDE_RIGHT, ADJACENT);
+                        mCurrentRowFrame, mCell, mTableIsLTR, NS_SIDE_RIGHT, 
+                        ADJACENT);
 }
 BCCellBorder
 BCMapCellInfo::GetRightInternalBorder()
 {
   const nsIFrame* cg = (mCgAtRight) ? mColGroup : nsnull;
   return CompareBorders(nsnull, cg, mRightCol, nsnull, nsnull, mCell,
-                        mTableIsLTR, !TABLE_EDGE, NS_SIDE_RIGHT, ADJACENT);
+                        mTableIsLTR, NS_SIDE_RIGHT, ADJACENT);
 }
 
 BCCellBorder
 BCMapCellInfo::GetLeftInternalBorder()
 {
   const nsIFrame* cg = (mCgAtLeft) ? mColGroup : nsnull;
   return CompareBorders(nsnull, cg, mLeftCol, nsnull, nsnull, mCell,
-                        mTableIsLTR, !TABLE_EDGE, NS_SIDE_LEFT, !ADJACENT);
+                        mTableIsLTR, NS_SIDE_LEFT, !ADJACENT);
 }
 
 BCCellBorder
 BCMapCellInfo::GetBottomInternalBorder()
 {
   const nsIFrame* rg = (mRgAtBottom) ? mRowGroup : nsnull;
   return CompareBorders(nsnull, nsnull, nsnull, rg, mBottomRow, mCell,
-                        mTableIsLTR, !TABLE_EDGE, NS_SIDE_BOTTOM, ADJACENT);
+                        mTableIsLTR, NS_SIDE_BOTTOM, ADJACENT);
 }
 
 BCCellBorder
 BCMapCellInfo::GetTopInternalBorder()
 {
   const nsIFrame* rg = (mRgAtTop) ? mRowGroup : nsnull;
   return CompareBorders(nsnull, nsnull, nsnull, rg, mTopRow, mCell,
-                        mTableIsLTR, !TABLE_EDGE, NS_SIDE_TOP, !ADJACENT);
+                        mTableIsLTR, NS_SIDE_TOP, !ADJACENT);
 }
 
 /* Here is the order for storing border edges in the cell map as a cell is processed. There are 
    n=colspan top and bottom border edges per cell and n=rowspan left and right border edges per cell.
 
    1) On the top edge of the table, store the top edge. Never store the top edge otherwise, since
       a bottom edge from a cell above will take care of it.
    2) On the left edge of the table, store the left edge. Never store the left edge othewise, since
@@ -6908,82 +6878,67 @@ BCVerticalSeg::Paint(BCPaintBorderIterat
                      BCPixelSize            aHorSegHeight)
 {
   // get the border style, color and paint the segment
   PRUint8 side = (aIter.IsDamageAreaRightMost()) ? NS_SIDE_RIGHT :
                                                     NS_SIDE_LEFT;
   PRInt32 relColIndex = aIter.GetRelativeColIndex();
   nsTableColFrame* col           = mCol; if (!col) ABORT0();
   nsTableCellFrame* cell         = mFirstCell; // ???
+  nsIFrame* owner = nsnull;
   PRUint8 style = NS_STYLE_BORDER_STYLE_SOLID;
   nscolor color = 0xFFFFFFFF;
-  PRBool ignoreIfRules = (aIter.IsTableRightMost() ||
-                          aIter.IsTableLeftMost());
 
   switch (mOwner) {
     case eTableOwner:
-      ::GetPaintStyleInfo(aIter.mTable, side, style, color, aIter.mTableIsLTR,
-                          PR_FALSE);
+      owner = aIter.mTable;
       break;
     case eAjaColGroupOwner:
       side = NS_SIDE_RIGHT;
       if (!aIter.IsTableRightMost() && (relColIndex > 0)) {
         col = aIter.mVerInfo[relColIndex - 1].mCol;
       } // and fall through
     case eColGroupOwner:
       if (col) {
-        nsIFrame* cg = col->GetParent();
-        if (cg) {
-          ::GetPaintStyleInfo(cg, side, style, color, aIter.mTableIsLTR,
-                              ignoreIfRules);
-        }
+        owner = col->GetParent();
       }
       break;
     case eAjaColOwner:
       side = NS_SIDE_RIGHT;
       if (!aIter.IsTableRightMost() && (relColIndex > 0)) {
         col = aIter.mVerInfo[relColIndex - 1].mCol;
       } // and fall through
     case eColOwner:
-      if (col) {
-       ::GetPaintStyleInfo(col, side, style, color, aIter.mTableIsLTR,
-                           ignoreIfRules);
-      }
+      owner = col;
       break;
     case eAjaRowGroupOwner:
       NS_ERROR("a neighboring rowgroup can never own a vertical border");
       // and fall through
     case eRowGroupOwner:
       NS_ASSERTION(aIter.IsTableLeftMost() || aIter.IsTableRightMost(),
                   "row group can own border only at table edge");
-      if (mFirstRowGroup) {
-        ::GetPaintStyleInfo(mFirstRowGroup, side, style, color,
-                            aIter.mTableIsLTR, ignoreIfRules);
-      }
+      owner = mFirstRowGroup;
       break;
     case eAjaRowOwner:
       NS_ASSERTION(PR_FALSE, "program error"); // and fall through
     case eRowOwner:
       NS_ASSERTION(aIter.IsTableLeftMost() || aIter.IsTableRightMost(),
                    "row can own border only at table edge");
-      if (mFirstRow) {
-        ::GetPaintStyleInfo(mFirstRow, side, style, color, aIter.mTableIsLTR,
-                            ignoreIfRules);
-      }
+      owner = mFirstRow;
       break;
     case eAjaCellOwner:
       side = NS_SIDE_RIGHT;
       cell = mAjaCell; // and fall through
     case eCellOwner:
-      if (cell) {
-        ::GetPaintStyleInfo(cell, side, style, color, aIter.mTableIsLTR,
-                            PR_FALSE);
-      }
+      owner = cell;
       break;
   }
+  if (owner) {
+    ::GetPaintStyleInfo(owner, side, style, color, aIter.mTableIsLTR);
+  }
   BCPixelSize smallHalf, largeHalf;
   DivideBCBorderSize(mWidth, smallHalf, largeHalf);
   nsRect segRect(mOffsetX - nsPresContext::CSSPixelsToAppUnits(largeHalf),
                  mOffsetY,
                  nsPresContext::CSSPixelsToAppUnits(mWidth), mLength);
   nscoord bottomBevelOffset = (mIsBottomBevel) ?
                   nsPresContext::CSSPixelsToAppUnits(mBottomHorSegHeight) : 0;
   PRUint8 bottomBevelSide = ((aHorSegHeight > 0) ^ !aIter.mTableIsLTR) ?
@@ -7101,88 +7056,75 @@ BCHorizontalSeg::GetRightCorner(BCPaintB
  */
 void
 BCHorizontalSeg::Paint(BCPaintBorderIterator& aIter,
                        nsIRenderingContext&   aRenderingContext)
 {
   // get the border style, color and paint the segment
   PRUint8 side = (aIter.IsDamageAreaBottomMost()) ? NS_SIDE_BOTTOM :
                                                      NS_SIDE_TOP;
-  nsIFrame* rg   = aIter.mRg;   if (!rg) ABORT0();
-  nsIFrame* row  = aIter.mRow;        if (!row) ABORT0();
+  nsIFrame* rg   = aIter.mRg;  if (!rg) ABORT0();
+  nsIFrame* row  = aIter.mRow; if (!row) ABORT0();
   nsIFrame* cell = mFirstCell; if (!cell) ABORT0(); // ????
   nsIFrame* col;
+  nsIFrame* owner = nsnull;
 
   PRUint8 style = NS_STYLE_BORDER_STYLE_SOLID;
   nscolor color = 0xFFFFFFFF;
-  PRBool ignoreIfRules = (aIter.IsTableTopMost() ||
-                          aIter.IsTableBottomMost());
-
+ 
+  
   switch (mOwner) {
     case eTableOwner:
-      ::GetPaintStyleInfo(aIter.mTable, side, style, color, aIter.mTableIsLTR,
-                          PR_FALSE);
+      owner = aIter.mTable;
       break;
     case eAjaColGroupOwner:
       NS_ERROR("neighboring colgroups can never own a horizontal border");
       // and fall through
-    case eColGroupOwner: {
+    case eColGroupOwner: 
       NS_ASSERTION(aIter.IsTableTopMost() || aIter.IsTableBottomMost(),
                    "col group can own border only at the table edge");
       col = aIter.mTableFirstInFlow->GetColFrame(aIter.mColIndex - 1);
       if (!col) ABORT0();
-      nsIFrame* cg = col->GetParent(); if (!cg) ABORT0();
-      ::GetPaintStyleInfo(cg, side, style, color, aIter.mTableIsLTR,
-                          ignoreIfRules);
+      owner = col->GetParent(); 
       break;
-    }
     case eAjaColOwner:
       NS_ERROR("neighboring column can never own a horizontal border");
       // and fall through
     case eColOwner:
       NS_ASSERTION(aIter.IsTableTopMost() || aIter.IsTableBottomMost(),
                    "col can own border only at the table edge");
-      col = aIter.mTableFirstInFlow->GetColFrame(aIter.mColIndex - 1);
-      if (!col) ABORT0();
-      ::GetPaintStyleInfo(col, side, style, color, aIter.mTableIsLTR,
-                          ignoreIfRules);
+      owner = aIter.mTableFirstInFlow->GetColFrame(aIter.mColIndex - 1);
       break;
     case eAjaRowGroupOwner:
       side = NS_SIDE_BOTTOM;
       rg = (aIter.IsTableBottomMost()) ? aIter.mRg : aIter.mPrevRg;
       // and fall through
     case eRowGroupOwner:
-      if (rg) {
-        ::GetPaintStyleInfo(rg, side, style, color, aIter.mTableIsLTR,
-                            ignoreIfRules);
-      }
+      owner = rg;
       break;
     case eAjaRowOwner:
       side = NS_SIDE_BOTTOM;
       row = (aIter.IsTableBottomMost()) ? aIter.mRow : aIter.mPrevRow;
       // and fall through
       case eRowOwner:
-      if (row) {
-        ::GetPaintStyleInfo(row, side, style, color, aIter.mTableIsLTR,
-                            aIter.IsTableBottomMost());
-      }
+      owner = row;
       break;
     case eAjaCellOwner:
       side = NS_SIDE_BOTTOM;
       // if this is null due to the damage area origin-y > 0, then the border
       // won't show up anyway
       cell = mAjaCell;
       // and fall through
-      case eCellOwner:
-      if (cell) {
-        ::GetPaintStyleInfo(cell, side, style, color, aIter.mTableIsLTR,
-                            PR_FALSE);
-      }
+    case eCellOwner:
+      owner = cell;
       break;
   }
+  if (owner) {            
+    ::GetPaintStyleInfo(owner, side, style, color, aIter.mTableIsLTR);
+  }
   BCPixelSize smallHalf, largeHalf;
   DivideBCBorderSize(mWidth, smallHalf, largeHalf);
   nsRect segRect(mOffsetX,
                  mOffsetY - nsPresContext::CSSPixelsToAppUnits(largeHalf),
                  mLength,
                  nsPresContext::CSSPixelsToAppUnits(mWidth));
   if (aIter.mTableIsLTR) {
     nsCSSRendering::DrawTableBorderSegment(aRenderingContext, style, color,