Bug 413180: Stop distributing span pct-width to cols when there are only 0-width cols left. r+sr=dbaron a=beltzner
authordholbert@cs.stanford.edu
Fri, 22 Feb 2008 09:15:27 -0800
changeset 12107 831a166b13f46b2af8b1da90517fb9ee4d9a3fbf
parent 12106 18bda370b9fbf093c0c382d90f1868c0d171eb15
child 12108 22306d7b3237501f9e0420a8db84548ad0ffd6e1
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbeltzner
bugs413180
milestone1.9b4pre
Bug 413180: Stop distributing span pct-width to cols when there are only 0-width cols left. r+sr=dbaron a=beltzner
layout/tables/BasicTableLayoutStrategy.cpp
layout/tables/crashtests/413180-1.html
layout/tables/crashtests/crashtests.list
--- a/layout/tables/BasicTableLayoutStrategy.cpp
+++ b/layout/tables/BasicTableLayoutStrategy.cpp
@@ -568,26 +568,24 @@ BasicTableLayoutStrategy::DistributePctW
     for (scol = aFirstCol, scol_end = aFirstCol + aColCount;
          scol < scol_end; ++scol) {
         nsTableColFrame *scolFrame = mTableFrame->GetColFrame(scol);
         if (!scolFrame) {
             NS_ERROR("column frames out of sync with cell map");
             continue;
         }
 
-        // the percentage width (only to columns that don't
-        // already have percentage widths, in proportion to
-        // the existing pref widths)
-        float allocatedPct = 0.0f;
         if (scolFrame->GetPrefPercent() == 0.0f) {
             NS_ASSERTION((!spanHasNonPctPref ||
                           nonPctTotalPrefWidth != 0) &&
                          nonPctColCount != 0,
                          "should not be zero if we haven't allocated "
                          "all pref percent");
+
+            float allocatedPct; // % width to be given to this column
             if (spanHasNonPctPref) {
                 // Group so we're multiplying by 1.0f when we need
                 // to use up aSpanPrefPct.
                 allocatedPct = aSpanPrefPct *
                     (float(scolFrame->GetPrefCoord()) /
                      float(nonPctTotalPrefWidth));
             } else {
                 // distribute equally when all pref widths are 0
@@ -596,16 +594,26 @@ BasicTableLayoutStrategy::DistributePctW
             // Allocate the percent
             scolFrame->AddSpanPrefPercent(allocatedPct);
             
             // To avoid accumulating rounding error from division,
             // subtract this column's values from the totals.
             aSpanPrefPct -= allocatedPct;
             nonPctTotalPrefWidth -= scolFrame->GetPrefCoord();
             --nonPctColCount;
+
+            if (!aSpanPrefPct) {
+                // No more span-percent-width to distribute --> we're done.
+                NS_ASSERTION(spanHasNonPctPref ? 
+                             nonPctTotalPrefWidth == 0 :
+                             nonPctColCount == 0,
+                             "No more pct width to distribute, but there are "
+                             "still cols that need some.");
+                return;
+            }
         }
     }
 }
 
 void
 BasicTableLayoutStrategy::DistributeWidthToColumns(nscoord aWidth, 
                                                    PRInt32 aFirstCol, 
                                                    PRInt32 aColCount,
new file mode 100644
--- /dev/null
+++ b/layout/tables/crashtests/413180-1.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+
+<table>
+  <tr>
+    <td style="width: 9%" colspan="2"></td>
+  </tr>
+  <tr>
+    <td></td>
+  </tr>
+</table>
+
+</body>
+</html>
--- a/layout/tables/crashtests/crashtests.list
+++ b/layout/tables/crashtests/crashtests.list
@@ -38,8 +38,9 @@ load 391898-1.html
 load 391901-1.html
 load 397448-1.html
 load 398157-1.xhtml
 load 399209-1.xhtml
 load 403249-1.html
 load 403579-1.html
 load 404301-1.xhtml
 load 411582.xhtml
+load 413180-1.html