When inserting a col into a colgroup after a col with span, insert it after the last columnframe spanned by the span. Bug 404301, r=bernd, sr=roc, a=schrep
authorbzbarsky@mit.edu
Mon, 19 Nov 2007 20:29:40 -0800
changeset 8201 46b8ea7d2d326eb417ffa9a44d33713da169003e
parent 8200 e13888942d6fa41614c55544b3f7bf027a4d2877
child 8202 1a4c07f4300c4d1276045a36f027e87e8482a356
push idunknown
push userunknown
push dateunknown
reviewersbernd, roc, schrep
bugs404301
milestone1.9b2pre
When inserting a col into a colgroup after a col with span, insert it after the last columnframe spanned by the span. Bug 404301, r=bernd, sr=roc, a=schrep
layout/reftests/bugs/404301-1-ref.html
layout/reftests/bugs/404301-1.html
layout/reftests/bugs/reftest.list
layout/tables/nsTableColGroupFrame.cpp
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/404301-1-ref.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+table { background: white }
+col[span] { background: green }
+td { color: white }
+</style>
+</head>
+<body>
+ <table>
+   <colgroup id="x">
+     <col span="2"></col>
+     <col></col>
+     <col id="y"></col>
+   </colgroup>
+   <tr>
+     <td>One</td>
+     <td>Two</td>
+     <td>Three</td>
+     <td>Four</td>
+   </tr>
+ </table>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/404301-1.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+table { background: white }
+col[span] { background: green }
+td { color: white }
+</style>
+</head>
+<body onload="runTest()">
+ <table>
+   <colgroup id="x">
+     <col span="2"></col>
+     <col id="y"></col>
+   </colgroup>
+   <tr>
+     <td>One</td>
+     <td>Two</td>
+     <td>Three</td>
+     <td>Four</td>
+   </tr>
+ </table>
+
+ <script>
+   function runTest() {
+     document.body.offsetWidth;
+     document.getElementById("x").insertBefore(document.createElement("col"),
+                                               document.getElementById("y"));
+   }
+ </script>
+</body>
+</html>
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -467,8 +467,9 @@ fails == 386310-1d.html 386310-1-ref.htm
 == 403656-3.html 403656-3-ref.html
 == 403656-4.html 403656-4-ref.html
 == 403656-5.html 403656-5-ref.html
 == 403733-1.html 403733-1-ref.html
 == 403962-1.xhtml 403962-1-ref.xhtml
 == 404030-1.html 404030-1-ref.html
 != 404030-1-notref.html 404030-1.html
 != 404030-1-notref2.html 404030-1.html
++== 404301-1.html 404301-1-ref.html
--- a/layout/tables/nsTableColGroupFrame.cpp
+++ b/layout/tables/nsTableColGroupFrame.cpp
@@ -210,17 +210,19 @@ nsTableColGroupFrame::AppendFrames(nsIAt
                                    nsIFrame*       aFrameList)
 {
   NS_ASSERTION(!aListName, "unexpected child list");
 
   nsTableColFrame* col = GetFirstColumn();
   nsTableColFrame* nextCol;
   while (col && col->GetColType() == eColAnonymousColGroup) {
     // this colgroup spans one or more columns but now that there is a
-    // real column below, spanned anonymous columns should be removed
+    // real column below, spanned anonymous columns should be removed,
+    // since the HTML spec says to ignore the span of a colgroup if it
+    // has content columns in it.
     nextCol = col->GetNextCol();
     RemoveFrame(nsnull, col);
     col = nextCol;
   }
 
   mFrames.AppendFrames(this, aFrameList);
   InsertColsReflow(GetStartColumnIndex() + mColCount, aFrameList);
   return NS_OK;
@@ -236,23 +238,35 @@ nsTableColGroupFrame::InsertFrames(nsIAt
                "inserting after sibling frame with different parent");
 
   nsFrameList frames(aFrameList); // convience for getting last frame
   nsIFrame* lastFrame = frames.LastChild();
 
   nsTableColFrame* col = GetFirstColumn();
   nsTableColFrame* nextCol;
   while (col && col->GetColType() == eColAnonymousColGroup) {
-    // this colgroup spans one or more columns but now that there is 
-    // real column below, spanned anonymous columns should be removed
+    // this colgroup spans one or more columns but now that there is a
+    // real column below, spanned anonymous columns should be removed,
+    // since the HTML spec says to ignore the span of a colgroup if it
+    // has content columns in it.
     nextCol = col->GetNextCol();
     RemoveFrame(nsnull, col);
     col = nextCol;
   }
 
+  if (aPrevFrame) {
+    col = GetNextColumn(aPrevFrame);
+    while (col && col->GetColType() == eColAnonymousCol) {
+      // This is a column frame from a <col span="N">.  We want to
+      // insert our new frame after the end of this span
+      aPrevFrame = col;
+      col = col->GetNextCol();
+    }
+  }
+
   mFrames.InsertFrames(this, aPrevFrame, aFrameList);
   nsIFrame* prevFrame = nsTableFrame::GetFrameAtOrBefore(this, aPrevFrame,
                                                          nsGkAtoms::tableColFrame);
 
   PRInt32 colIndex = (prevFrame) ? ((nsTableColFrame*)prevFrame)->GetColIndex() + 1 : GetStartColumnIndex();
   InsertColsReflow(colIndex, aFrameList, lastFrame);
 
   return NS_OK;