Don't distribute percentage width from column-spanning cells to columns that have no cells originating. (Bug 810586) r=dholbert
authorL. David Baron <dbaron@dbaron.org>
Wed, 02 Jan 2013 22:58:05 -0500
changeset 126516 637e063b20555cc0d921ac701e2856d8004cbfd9
parent 126515 5fae52f44675a1ae8335f53296bb8065cf21dd31
child 126517 b5c0b31b73bafe7bc21a671f8e3e2f1516e6225c
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs810586
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Don't distribute percentage width from column-spanning cells to columns that have no cells originating. (Bug 810586) r=dholbert This makes the distribution of pref/min width and the distribution of percentage width from column-spanning cells more consistent with each other. Having them inconsistent means that a column-spanning cell that has both percentage width and minimum intrinsic width might distribute those widths among its columns differently, which can then lead to the percentages unnecessarily increasing the table's preferred intrinsic width. (It *might* also be worth fixing the FLEX_ALL_LARGE case in DistributeWidthToColumns to also check for originating cells, since it's now the only case that doesn't, except that we can't guarantee that there are columns with originating cells, so it would really require splitting that case, which is extra complexity that doesn't seem worth it for such a rarely-hit and non-interoperable case.)
layout/reftests/table-width/distribute-percent-nonoriginating-ref.html
layout/reftests/table-width/distribute-percent-nonoriginating.html
layout/reftests/table-width/reftest.list
layout/tables/BasicTableLayoutStrategy.cpp
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-width/distribute-percent-nonoriginating-ref.html
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML>
+<title>Testcase, bug 810586</title>
+<table style="background: yellow" cellspacing="0" cellpadding="0">
+  <tr>
+    <td>Text</td>
+  </tr>
+</table>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/table-width/distribute-percent-nonoriginating.html
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML>
+<title>Testcase, bug 810586</title>
+<table style="background: yellow" cellspacing="0" cellpadding="0">
+  <tr>
+    <td colspan="2" width="100%">Text</td>
+  </tr>
+</table>
--- a/layout/reftests/table-width/reftest.list
+++ b/layout/reftests/table-width/reftest.list
@@ -58,8 +58,9 @@ fails == default-box-sizing-collapse-qui
 == colgroup-vs-column-2.html colgroup-vs-column-2-ref.html
 == colgroup-vs-column-3.html colgroup-vs-column-3-ref.html
 == colgroup-vs-column-4.html colgroup-vs-column-4-ref.html
 == dynamic-fixed-layout-1.html dynamic-fixed-layout-1-ref.html
 == cell-pref-width-border-box.html cell-pref-width-border-box-ref.html
 == colspan-distribute-to-empty-1a.html colspan-distribute-to-empty-1-ref.html
 == colspan-distribute-to-empty-1b.html colspan-distribute-to-empty-1-ref.html
 == colspan-distribute-to-empty-2.html colspan-distribute-to-empty-2-ref.html
+== distribute-percent-nonoriginating.html distribute-percent-nonoriginating-ref.html
--- a/layout/tables/BasicTableLayoutStrategy.cpp
+++ b/layout/tables/BasicTableLayoutStrategy.cpp
@@ -556,27 +556,30 @@ BasicTableLayoutStrategy::DistributePctW
                                                       int32_t aColCount)
 {
     // First loop to determine:
     int32_t nonPctColCount = 0; // number of spanned columns without % width
     nscoord nonPctTotalPrefWidth = 0; // total pref width of those columns
     // and to reduce aSpanPrefPct by columns that already have % width
 
     int32_t scol, scol_end;
+    nsTableCellMap *cellMap = mTableFrame->GetCellMap();
     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;
         }
         float scolPct = scolFrame->GetPrefPercent();
         if (scolPct == 0.0f) {
             nonPctTotalPrefWidth += scolFrame->GetPrefCoord();
-            ++nonPctColCount;
+            if (cellMap->GetNumCellsOriginatingInCol(scol) > 0) {
+                ++nonPctColCount;
+            }
         } else {
             aSpanPrefPct -= scolPct;
         }
     }
 
     if (aSpanPrefPct <= 0.0f || nonPctColCount == 0) {
         // There's no %-width on the colspan left over to distribute,
         // or there are no columns to which we could distribute %-width
@@ -603,28 +606,32 @@ BasicTableLayoutStrategy::DistributePctW
 
             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 {
+            } else if (cellMap->GetNumCellsOriginatingInCol(scol) > 0) {
                 // distribute equally when all pref widths are 0
                 allocatedPct = aSpanPrefPct / float(nonPctColCount);
+            } else {
+                allocatedPct = 0.0f;
             }
             // 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 (cellMap->GetNumCellsOriginatingInCol(scol) > 0) {
+                --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.");