adopt caption vertical margins to latest CSS2.1 revision, bug 478614, r/sr=dbaron
authorBernd <bmlk@gmx.de>
Sun, 28 Jun 2009 15:51:46 +0200
changeset 29651 b4b7eb4407c3
parent 29650 c7c2a3f3c487
child 29652 fd0b25ac9f0d
push id7765
push userbmlk@gmx.de
push dateSun, 28 Jun 2009 13:53:49 +0000
treeherdermozilla-central@b4b7eb4407c3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs478614
milestone1.9.2a1pre
adopt caption vertical margins to latest CSS2.1 revision, bug 478614, r/sr=dbaron
layout/reftests/bugs/478614-1-ref.html
layout/reftests/bugs/478614-1.html
layout/reftests/bugs/478614-2.html
layout/reftests/bugs/478614-3-ref.html
layout/reftests/bugs/478614-3.html
layout/reftests/bugs/478614-4-ref.html
layout/reftests/bugs/478614-4.html
layout/reftests/bugs/478614-5-ref.html
layout/reftests/bugs/478614-5.html
layout/reftests/bugs/478614-6-ref.html
layout/reftests/bugs/478614-6.html
layout/reftests/bugs/478614-7-ref.html
layout/reftests/bugs/478614-7.html
layout/reftests/bugs/reftest.list
layout/reftests/margin-collapsing/reftest.list
layout/tables/nsTableOuterFrame.cpp
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-1-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top: 150px}
+table {width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-1.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top: 50px;}
+table {margin-top: 100px; width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-2.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top: 50px; caption-side:top}
+table {margin-top: 100px; width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-3-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption { caption-side:bottom;}
+table {100px; width:100px;}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-3.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-bottom: 100px; caption-side:bottom;}
+table {margin-bottom: 100px; width:100px;}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-4-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top: 160px;margin-bottom:50px}
+table {width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-4.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top: 60px;margin-bottom:50px}
+table {margin-top: 100px; width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-5-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top:50px; caption-side:bottom}
+table {width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-5.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-bottom: 100px;margin-top:50px; caption-side:bottom}
+table {margin-bottom: 100px; width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-6-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top: 100px;margin-bottom:50px;caption-side:top-outside}
+table { width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-6.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top: 100px;caption-side:top-outside}
+table {margin-top: 50px; width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-7-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top: 50px;caption-side:bottom-outside}
+table {width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/478614-7.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Testcase for table + caption vertical margins (bug 478614)</title>
+<style type="text/css">
+caption {margin-top: 50px;caption-side:bottom-outside}
+table {margin-bottom: 50px; width:100px}
+</style>
+</head>
+<body>
+<table><caption>caption</caption>
+<tr><td>td</td></tr>
+</table>
+</body>
+</html>
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -1185,16 +1185,23 @@ fails == 472020-2.xul 472020-2-ref.xul
 != 476063-3.html 476063-3-ref.html
 == 476063-4.xhtml 476063-4-ref.xhtml
 == 476357-1.html 476357-1-ref.html
 == 476598-1a.html 476598-1-ref.html
 == 476598-1a.html 476598-1-ref2.html
 == 476598-1b.html 476598-1-ref.html
 == 476598-1b.html 476598-1-ref2.html
 != 476598-1-ref.html about:blank
+== 478614-1.html 478614-1-ref.html
+== 478614-2.html 478614-1-ref.html
+== 478614-3.html 478614-3-ref.html
+== 478614-4.html 478614-4-ref.html
+== 478614-5.html 478614-5-ref.html
+== 478614-6.html 478614-6-ref.html
+== 478614-7.html 478614-7-ref.html
 == 478377-1.xul 478377-1-ref.xul
 == 478811-1.html 478811-1-ref.html
 == 478811-2.html 478811-2-ref.html
 == 478811-3.html 478811-3-ref.html
 == 478811-4.html 478811-4-ref.html
 == 478956-1a.html 478956-1-ref.html
 == 478956-1b.html 478956-1-ref.html
 == 480017-1.html 480017-1-ref.html
--- a/layout/reftests/margin-collapsing/reftest.list
+++ b/layout/reftests/margin-collapsing/reftest.list
@@ -52,24 +52,24 @@
 == block-overflow-5d.html block-overflow-5-ref.html
 fails == table-sibling-1a.html table-sibling-1-ref.html # Bug 372303
 fails == table-sibling-1b.html table-sibling-1-ref.html # Bug 372303
 fails == table-sibling-1c.html table-sibling-1-ref.html # Bug 372303
 fails == table-sibling-2a.html table-sibling-2-ref.html # Bug 87277
 fails == table-sibling-2b.html table-sibling-2-ref.html # Bug 87277
 fails == table-sibling-2c.html table-sibling-2-ref.html # Bug 87277
 == table-caption-1a.html table-caption-1-ref.html
-fails == table-caption-1b.html table-caption-1-ref.html # Bug 297676 and 478614
-fails == table-caption-2a.html table-caption-2-ref.html # Bug 297676 and 478614
-fails == table-caption-2b.html table-caption-2-ref.html # Bug 297676 and 478614
-fails == table-caption-2c.html table-caption-2-ref.html # Bug 297676 and 478614
+== table-caption-1b.html table-caption-1-ref.html
+== table-caption-2a.html table-caption-2-ref.html
+== table-caption-2b.html table-caption-2-ref.html
+== table-caption-2c.html table-caption-2-ref.html
 == table-caption-top-1.html table-caption-top-1-ref.html
-fails == table-caption-top-2.html table-caption-top-2-ref.html # Bug 478614
+== table-caption-top-2.html table-caption-top-2-ref.html
 == table-caption-bottom-1.html table-caption-bottom-1-ref.html
-fails == table-caption-bottom-2.html table-caption-bottom-2-ref.html # Bug 478614
+== table-caption-bottom-2.html table-caption-bottom-2-ref.html
 fails == caption-sibling-1a.html caption-sibling-1-ref.html # Bug 144517
 fails == caption-sibling-1b.html caption-sibling-1-ref.html # Bug 144517
 fails == caption-sibling-1c.html caption-sibling-1-ref.html # Bug 144517
 == fieldset-sibling-1a.html fieldset-sibling-1-ref.html
 == fieldset-sibling-1b.html fieldset-sibling-1-ref.html
 == fieldset-sibling-1c.html fieldset-sibling-1-ref.html
 == fieldset-sibling-2a.html fieldset-sibling-2-ref1.html
 == fieldset-sibling-2b.html fieldset-sibling-2-ref1.html
--- a/layout/tables/nsTableOuterFrame.cpp
+++ b/layout/tables/nsTableOuterFrame.cpp
@@ -701,17 +701,23 @@ nsTableOuterFrame::SetDesiredSize(PRUint
       aWidth = PR_MAX(aInnerMargin.right, aCaptionMargin.left + captionWidth + aCaptionMargin.right) +
                innerWidth + aInnerMargin.left;
       break;
     default:
       aWidth = aInnerMargin.left + innerWidth + aInnerMargin.right;
       aWidth = PR_MAX(aWidth, captionRect.XMost() + aCaptionMargin.right);
   }
   aHeight = innerRect.YMost() + aInnerMargin.bottom;
-  aHeight = PR_MAX(aHeight, captionRect.YMost() + aCaptionMargin.bottom);
+  if (NS_STYLE_CAPTION_SIDE_BOTTOM != aCaptionSide) {
+    aHeight = PR_MAX(aHeight, captionRect.YMost() + aCaptionMargin.bottom);
+  }
+  else {
+    aHeight = PR_MAX(aHeight, captionRect.YMost() + aCaptionMargin.bottom +
+                              aInnerMargin.bottom);
+  }
 
 }
 
 // XXX This is now unused, but it probably should be used!
 void
 nsTableOuterFrame::BalanceLeftRightCaption(PRUint8         aCaptionSide,
                                            const nsMargin& aInnerMargin,
                                            const nsMargin& aCaptionMargin,
@@ -779,264 +785,187 @@ nsresult
 nsTableOuterFrame::GetCaptionOrigin(PRUint32         aCaptionSide,
                                     const nsSize&    aContainBlockSize,
                                     const nsSize&    aInnerSize, 
                                     const nsMargin&  aInnerMargin,
                                     const nsSize&    aCaptionSize,
                                     nsMargin&        aCaptionMargin,
                                     nsPoint&         aOrigin)
 {
-  // FIXME: This function expects computed margin values to be
-  // NS_AUTOMARGIN, but this is no longer the case.
   aOrigin.x = aOrigin.y = 0;
   if ((NS_UNCONSTRAINEDSIZE == aInnerSize.width) || (NS_UNCONSTRAINEDSIZE == aInnerSize.height) ||  
       (NS_UNCONSTRAINEDSIZE == aCaptionSize.width) || (NS_UNCONSTRAINEDSIZE == aCaptionSize.height)) {
     return NS_OK;
   }
   if (!mCaptionFrame) return NS_OK;
+  
+  NS_ASSERTION(NS_AUTOMARGIN != aCaptionMargin.left,   "The computed caption margin is auto?");
+  NS_ASSERTION(NS_AUTOMARGIN != aCaptionMargin.top,    "The computed caption margin is auto?");
+  NS_ASSERTION(NS_AUTOMARGIN != aCaptionMargin.bottom, "The computed caption margin is auto?");
 
-  // FIXME: Have two separate switch statements so we can coalesce the
-  // horizontal computation for top and bottom.
+  // horizontal computation
   switch(aCaptionSide) {
   case NS_STYLE_CAPTION_SIDE_BOTTOM:
   case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: {
-    if (NS_AUTOMARGIN == aCaptionMargin.left) {
-      aCaptionMargin.left = CalcAutoMargin(aCaptionMargin.left, aCaptionMargin.right,
-                                           aContainBlockSize.width, aCaptionSize.width);
-    }
+    // FIXME: Position relative to right edge for RTL.  (Based on table
+    // direction or table parent direction?)
     aOrigin.x = aCaptionMargin.left;
     if (aCaptionSide == NS_STYLE_CAPTION_SIDE_BOTTOM) {
       // We placed the caption using only the table's width as available
       // width, and we should position it this way as well.
       aOrigin.x += aInnerMargin.left;
     }
-    if (NS_AUTOMARGIN == aCaptionMargin.top) {
-      aCaptionMargin.top = 0;
-    }
-    // FIXME: Position relative to right edge for RTL.  (Based on table
-    // direction or table parent direction?)
-    nsCollapsingMargin marg;
-    marg.Include(aCaptionMargin.top);
-    marg.Include(aInnerMargin.bottom);
-    nscoord collapseMargin = marg.get();
-    if (NS_AUTOMARGIN == aCaptionMargin.bottom) {
-      nscoord height = aInnerSize.height + collapseMargin + aCaptionSize.height;
-      aCaptionMargin.bottom = CalcAutoMargin(aCaptionMargin.bottom, aInnerMargin.top,
-                                             aContainBlockSize.height, height);
-    }
-    aOrigin.y = aInnerMargin.top + aInnerSize.height + collapseMargin;
   } break;
   case NS_STYLE_CAPTION_SIDE_LEFT: {
-    if (NS_AUTOMARGIN == aCaptionMargin.left) {
-      if (NS_AUTOMARGIN != aInnerMargin.left) {
-        aCaptionMargin.left = CalcAutoMargin(aCaptionMargin.left, aCaptionMargin.right,
-                                             aInnerMargin.left, aCaptionSize.width);
-      } 
-      else {
-        // zero for now
-        aCaptionMargin.left = 0;
-      } 
-    }
     aOrigin.x = aCaptionMargin.left;
-    aOrigin.y = aInnerMargin.top;
-    switch(GetCaptionVerticalAlign()) {
-      case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
-        aOrigin.y = PR_MAX(0, aInnerMargin.top + ((aInnerSize.height - aCaptionSize.height) / 2));
-        break;
-      case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
-        aOrigin.y = PR_MAX(0, aInnerMargin.top + aInnerSize.height - aCaptionSize.height);
-        break;
-      default:
-        break;
-    }
   } break;
   case NS_STYLE_CAPTION_SIDE_RIGHT: {
-    if (NS_AUTOMARGIN == aCaptionMargin.left) {
-      if (NS_AUTOMARGIN != aInnerMargin.right) {
-        aCaptionMargin.left = CalcAutoMargin(aCaptionMargin.left, aCaptionMargin.right,
-                                             aInnerMargin.right, aCaptionSize.width);
-      }
-      else {
-       // zero for now
-       aCaptionMargin.left = 0;
-      } 
-    }
     aOrigin.x = aInnerMargin.left + aInnerSize.width + aCaptionMargin.left;
-    aOrigin.y = aInnerMargin.top;
-    switch(GetCaptionVerticalAlign()) {
-      case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
-        aOrigin.y += PR_MAX(0, (aInnerSize.height - aCaptionSize.height) / 2);
-        break;
-      case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
-        aOrigin.y += PR_MAX(0, aInnerSize.height - aCaptionSize.height);
-        break;
-      default:
-        break;
-    }
   } break;
   default: { // top
     NS_ASSERTION(aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP ||
                  aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE,
                  "unexpected caption side");
-    if (NS_AUTOMARGIN == aCaptionMargin.left) {
-      aCaptionMargin.left = CalcAutoMargin(aCaptionMargin.left, aCaptionMargin.right,
-                                           aContainBlockSize.width, aCaptionSize.width);
-    }
+    // FIXME: Position relative to right edge for RTL.  (Based on table
+    // direction or table parent direction?)
     aOrigin.x = aCaptionMargin.left;
     if (aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP) {
       // We placed the caption using only the table's width as available
       // width, and we should position it this way as well.
       aOrigin.x += aInnerMargin.left;
     }
-    // FIXME: Position relative to right edge for RTL.  (Based on table
-    // direction or table parent direction?)
-    if (NS_AUTOMARGIN == aCaptionMargin.bottom) {
-      aCaptionMargin.bottom = 0;
-    }
-    if (NS_AUTOMARGIN == aCaptionMargin.top) {
+    
+  } break;
+  }
+  // vertical computation
+  switch (aCaptionSide) {
+    case NS_STYLE_CAPTION_SIDE_RIGHT:
+    case NS_STYLE_CAPTION_SIDE_LEFT:
+      aOrigin.y = aInnerMargin.top;
+      switch (GetCaptionVerticalAlign()) {
+        case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
+          aOrigin.y = PR_MAX(0, aInnerMargin.top + ((aInnerSize.height - aCaptionSize.height) / 2));
+          break;
+        case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
+          aOrigin.y = PR_MAX(0, aInnerMargin.top + aInnerSize.height - aCaptionSize.height);
+          break;
+        default:
+          break;
+      }
+      break;
+    case NS_STYLE_CAPTION_SIDE_BOTTOM: {
+      aOrigin.y = aInnerMargin.top + aInnerSize.height + aCaptionMargin.top;
+    } break;
+    case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: {
       nsCollapsingMargin marg;
-      marg.Include(aCaptionMargin.bottom);
-      marg.Include(aInnerMargin.top);
+      marg.Include(aCaptionMargin.top);
+      marg.Include(aInnerMargin.bottom);
       nscoord collapseMargin = marg.get();
-      nscoord height = aCaptionSize.height + collapseMargin + aInnerSize.height;
-      aCaptionMargin.top = CalcAutoMargin(aCaptionMargin.top, aInnerMargin.bottom,
-                                          aContainBlockSize.height, height);
-    }
-    aOrigin.y = aCaptionMargin.top;
-  } break;
+      aOrigin.y = aInnerMargin.top + aInnerSize.height + collapseMargin;
+    } break;
+    case NS_STYLE_CAPTION_SIDE_TOP: {
+      aOrigin.y = aInnerMargin.top + aCaptionMargin.top;
+    } break;
+    case NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE: {
+      aOrigin.y = aCaptionMargin.top;
+    } break;
+    default:
+      NS_NOTREACHED("Unknown caption alignment type");
+      break;
   }
   return NS_OK;
 }
 
 nsresult 
 nsTableOuterFrame::GetInnerOrigin(PRUint32         aCaptionSide,
                                   const nsSize&    aContainBlockSize,
                                   const nsSize&    aCaptionSize, 
                                   const nsMargin&  aCaptionMargin,
                                   const nsSize&    aInnerSize,
                                   nsMargin&        aInnerMargin,
                                   nsPoint&         aOrigin)
 {
-  // FIXME: This function expects computed margin values to be
-  // NS_AUTOMARGIN, but this is no longer the case.
+  
+  NS_ASSERTION(NS_AUTOMARGIN != aCaptionMargin.left,  "The computed caption margin is auto?");
+  NS_ASSERTION(NS_AUTOMARGIN != aCaptionMargin.right, "The computed caption margin is auto?");
+  NS_ASSERTION(NS_AUTOMARGIN != aInnerMargin.left,    "The computed inner margin is auto?");
+  NS_ASSERTION(NS_AUTOMARGIN != aInnerMargin.right,   "The computed inner margin is auto?");
+  NS_ASSERTION(NS_AUTOMARGIN != aInnerMargin.top,     "The computed inner margin is auto?");
+  NS_ASSERTION(NS_AUTOMARGIN != aInnerMargin.bottom,  "The computed inner margin is auto?");
+  
   aOrigin.x = aOrigin.y = 0;
   if ((NS_UNCONSTRAINEDSIZE == aInnerSize.width) || (NS_UNCONSTRAINEDSIZE == aInnerSize.height) ||  
       (NS_UNCONSTRAINEDSIZE == aCaptionSize.width) || (NS_UNCONSTRAINEDSIZE == aCaptionSize.height)) {
     return NS_OK;
   }
 
   nscoord minCapWidth = aCaptionSize.width;
-  if (NS_AUTOMARGIN != aCaptionMargin.left)
-    minCapWidth += aCaptionMargin.left;
-  if (NS_AUTOMARGIN != aCaptionMargin.right)
-    minCapWidth += aCaptionMargin.right;
+  
+  minCapWidth += aCaptionMargin.left;
+  minCapWidth += aCaptionMargin.right;
 
-  switch(aCaptionSide) {
-  case NS_STYLE_CAPTION_SIDE_BOTTOM:
-  case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: {
-    if (NS_AUTOMARGIN == aInnerMargin.left) {
-      aInnerMargin.left = CalcAutoMargin(aInnerMargin.left, aInnerMargin.right,
-                                         aContainBlockSize.width, aInnerSize.width);
-    }
-    aOrigin.x = aInnerMargin.left;
-    if (NS_AUTOMARGIN == aInnerMargin.bottom) {
-      aInnerMargin.bottom = 0;
-    }
-    if (NS_AUTOMARGIN == aInnerMargin.top) {
-      nsCollapsingMargin marg;
-      marg.Include(aInnerMargin.bottom);
-      marg.Include(aCaptionMargin.top);
-      nscoord collapseMargin = marg.get();
-      nscoord height = aInnerSize.height + collapseMargin + aCaptionSize.height;
-      aInnerMargin.top = CalcAutoMargin(aInnerMargin.top, aCaptionMargin.bottom,
-                                        aContainBlockSize.height, height);
-    }
-    aOrigin.y = aInnerMargin.top;
-  } break;
+  // horizontal computation
+  switch (aCaptionSide) {
   case NS_STYLE_CAPTION_SIDE_LEFT: {
-    
-    if (NS_AUTOMARGIN == aInnerMargin.left) {
-      aInnerMargin.left = CalcAutoMargin(aInnerMargin.left, aInnerMargin.right,
-                                         aContainBlockSize.width, aInnerSize.width);
-      
-    }
     if (aInnerMargin.left < minCapWidth) {
       // shift the inner table to get some place for the caption
       aInnerMargin.right += aInnerMargin.left - minCapWidth;
       aInnerMargin.right  = PR_MAX(0, aInnerMargin.right);
       aInnerMargin.left   = minCapWidth;
     }
     aOrigin.x = aInnerMargin.left;
-    if (NS_AUTOMARGIN == aInnerMargin.top) {
-      aInnerMargin.top = 0;
-    }
-    aOrigin.y = aInnerMargin.top;
-    switch(GetCaptionVerticalAlign()) {
-      case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
-        aOrigin.y = PR_MAX(aInnerMargin.top, (aCaptionSize.height - aInnerSize.height) / 2);
-        break;
-      case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
-        aOrigin.y = PR_MAX(aInnerMargin.top, aCaptionSize.height - aInnerSize.height);
-        break;
-      default:
-        break;
-    }
   } break;
-  case NS_STYLE_CAPTION_SIDE_RIGHT: {
-    if (NS_AUTOMARGIN == aInnerMargin.right) {
-      aInnerMargin.right = CalcAutoMargin(aInnerMargin.left, aInnerMargin.right,
-                                          aContainBlockSize.width, aInnerSize.width);
-      if (aInnerMargin.right < minCapWidth) {
-        // shift the inner table to get some place for the caption
-        aInnerMargin.left -= aInnerMargin.right - minCapWidth;
-        aInnerMargin.left  = PR_MAX(0, aInnerMargin.left);
-        aInnerMargin.right = minCapWidth;
-      }
-    }
-    aOrigin.x = aInnerMargin.left;
-    if (NS_AUTOMARGIN == aInnerMargin.top) {
-      aInnerMargin.top = 0;
-    }
-    aOrigin.y = aInnerMargin.top;
-    switch(GetCaptionVerticalAlign()) {
-      case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
-        aOrigin.y = PR_MAX(aInnerMargin.top, (aCaptionSize.height - aInnerSize.height) / 2);
-        break;
-      case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
-        aOrigin.y = PR_MAX(aInnerMargin.top, aCaptionSize.height - aInnerSize.height);
-        break;
-      default:
-        break;
-    }
-  } break;
-  default: { // top
+  default: {
     NS_ASSERTION(aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP ||
                  aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE ||
+                 aCaptionSide == NS_STYLE_CAPTION_SIDE_BOTTOM ||
+                 aCaptionSide == NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE ||
+                 aCaptionSide == NS_STYLE_CAPTION_SIDE_RIGHT ||
                  aCaptionSide == NO_SIDE,
                  "unexpected caption side");
-    if (NS_AUTOMARGIN == aInnerMargin.left) {
-      aInnerMargin.left = CalcAutoMargin(aInnerMargin.left, aInnerMargin.right,
-                                         aContainBlockSize.width, aInnerSize.width);
-    }
     aOrigin.x = aInnerMargin.left;
-    if (NS_AUTOMARGIN == aInnerMargin.top) {
-      aInnerMargin.top = 0;
-    }
-    nsCollapsingMargin marg;
-    marg.Include(aCaptionMargin.bottom);
-    marg.Include(aInnerMargin.top);
-    nscoord collapseMargin = marg.get();
-    if (NS_AUTOMARGIN == aInnerMargin.bottom) {
-      nscoord height = aCaptionSize.height + collapseMargin + aInnerSize.height;
-      aInnerMargin.bottom = CalcAutoMargin(aCaptionMargin.bottom, aInnerMargin.top,
-                                           aContainBlockSize.height, height);
-    }
-    aOrigin.y = aCaptionMargin.top + aCaptionSize.height + collapseMargin;
   } break;
   }
+  
+  // vertical computation
+  switch (aCaptionSide) {
+    case NS_STYLE_CAPTION_SIDE_BOTTOM:
+    case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: {
+      aOrigin.y = aInnerMargin.top;
+    } break;
+    case NS_STYLE_CAPTION_SIDE_LEFT:
+    case NS_STYLE_CAPTION_SIDE_RIGHT: {
+      aOrigin.y = aInnerMargin.top;
+      switch (GetCaptionVerticalAlign()) {
+        case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
+          aOrigin.y = PR_MAX(aInnerMargin.top, (aCaptionSize.height - aInnerSize.height) / 2);
+          break;
+        case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
+          aOrigin.y = PR_MAX(aInnerMargin.top, aCaptionSize.height - aInnerSize.height);
+          break;
+        default:
+          break;
+      }
+    } break;
+    case NO_SIDE:
+    case NS_STYLE_CAPTION_SIDE_TOP: {
+      aOrigin.y = aInnerMargin.top + aCaptionMargin.top + aCaptionSize.height +
+                  aCaptionMargin.bottom;
+    } break;
+    case NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE: {
+      nsCollapsingMargin marg;
+      marg.Include(aCaptionMargin.bottom);
+      marg.Include(aInnerMargin.top);
+      nscoord collapseMargin = marg.get();
+      aOrigin.y = aCaptionMargin.top + aCaptionSize.height + collapseMargin;
+    } break;
+    default:
+      NS_NOTREACHED("Unknown caption alignment type");
+      break;
+  }
   return NS_OK;
 }
 
 void
 nsTableOuterFrame::OuterBeginReflowChild(nsPresContext*           aPresContext,
                                          nsIFrame*                aChildFrame,
                                          const nsHTMLReflowState& aOuterRS,
                                          void*                    aChildRSSpace,