Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Unified Diff: Source/core/layout/TableLayoutAlgorithmAuto.cpp

Issue 988443003: Don't add artifical 1 pixel width to empty tables (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/layout/TableLayoutAlgorithmAuto.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/layout/TableLayoutAlgorithmAuto.cpp
diff --git a/Source/core/layout/TableLayoutAlgorithmAuto.cpp b/Source/core/layout/TableLayoutAlgorithmAuto.cpp
index 450fe6fef269d70eccea5fa2f7b1842b9087220a..22354b5fffd07e5fb63355f58f2a2a3ca6e1c9fb 100644
--- a/Source/core/layout/TableLayoutAlgorithmAuto.cpp
+++ b/Source/core/layout/TableLayoutAlgorithmAuto.cpp
@@ -63,16 +63,11 @@ void TableLayoutAlgorithmAuto::recalcColumn(unsigned effCol)
if (current.inColSpan || !cell)
continue;
+ columnLayout.columnHasNoCells = false;
- bool cellHasContent = cell->children()->firstChild() || cell->style()->hasBorder() || cell->style()->hasPadding() || cell->style()->hasBackground();
- if (cellHasContent)
+ if (cell->maxPreferredLogicalWidth())
columnLayout.emptyCellsOnly = false;
- // A cell originates in this column. Ensure we have
- // a min/max width of at least 1px for this column now.
- columnLayout.minLogicalWidth = std::max<int>(columnLayout.minLogicalWidth, cellHasContent ? 1 : 0);
- columnLayout.maxLogicalWidth = std::max<int>(columnLayout.maxLogicalWidth, 1);
-
if (cell->colSpan() == 1) {
columnLayout.minLogicalWidth = std::max<int>(cell->minPreferredLogicalWidth(), columnLayout.minLogicalWidth);
if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogicalWidth) {
@@ -120,6 +115,9 @@ void TableLayoutAlgorithmAuto::recalcColumn(unsigned effCol)
break;
}
} else if (!effCol || section->primaryCellAt(i, effCol - 1) != cell) {
+ // If a cell originates in this spanning column ensure we have a min/max width of at least 1px for it.
+ columnLayout.minLogicalWidth = std::max<int>(columnLayout.minLogicalWidth, cell->maxPreferredLogicalWidth() ? 1 : 0);
+
// This spanning cell originates in this column. Insert the cell into spanning cells list.
insertSpanCell(cell);
}
@@ -373,13 +371,13 @@ int TableLayoutAlgorithmAuto::calcEffectiveLogicalWidth()
int totalWidth = 0;
for (unsigned pos = effCol; pos < lastCol; ++pos) {
if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent())
- totalWidth += m_layoutStruct[pos].effectiveMaxLogicalWidth;
+ totalWidth += m_layoutStruct[pos].clampedEffectiveMaxLogicalWidth();
}
for (unsigned pos = effCol; pos < lastCol && totalWidth > 0; ++pos) {
if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent()) {
float percent = percentMissing * static_cast<float>(m_layoutStruct[pos].effectiveMaxLogicalWidth) / totalWidth;
- totalWidth -= m_layoutStruct[pos].effectiveMaxLogicalWidth;
+ totalWidth -= m_layoutStruct[pos].clampedEffectiveMaxLogicalWidth();
percentMissing -= percent;
if (percent > 0)
m_layoutStruct[pos].effectiveLogicalWidth.setValue(Percent, percent);
@@ -538,7 +536,7 @@ void TableLayoutAlgorithmAuto::layout()
break;
case Fixed:
numFixed++;
- totalFixed += m_layoutStruct[i].effectiveMaxLogicalWidth;
+ totalFixed += m_layoutStruct[i].clampedEffectiveMaxLogicalWidth();
// fall through
break;
case Auto:
@@ -546,7 +544,7 @@ void TableLayoutAlgorithmAuto::layout()
numAutoEmptyCellsOnly++;
} else {
numAuto++;
- totalAuto += m_layoutStruct[i].effectiveMaxLogicalWidth;
+ totalAuto += m_layoutStruct[i].clampedEffectiveMaxLogicalWidth();
allocAuto += cellLogicalWidth;
}
break;
@@ -594,13 +592,17 @@ void TableLayoutAlgorithmAuto::layout()
}
}
- // Give each auto width column its share of the available width.
+ // Give each auto width column its share of the available width, non-empty columns then empty columns.
if (available > 0 && numAuto) {
available += allocAuto;
distributeWidthToColumns<float, Auto, NonEmptyCells, InitialWidth, StartToEnd>(available, totalAuto);
}
+ if (available > 0 && numAutoEmptyCellsOnly) {
+ unsigned total = numAutoEmptyCellsOnly;
+ distributeWidthToColumns<unsigned, Auto, EmptyCells, InitialWidth, StartToEnd>(available, total);
+ }
- // Any remaining available width expands fixed width, percent width and non-empty auto width columns, in that order.
+ // Any remaining available width expands fixed width, percent width, and non-empty auto width columns, in that order.
if (available > 0 && numFixed)
distributeWidthToColumns<float, Fixed, AllCells, ExtraWidth, StartToEnd>(available, totalFixed);
@@ -643,6 +645,10 @@ void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total& t
const Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (cellsToProcess == NonEmptyCells && logicalWidth.isAuto() && m_layoutStruct[i].emptyCellsOnly)
continue;
+ // When allocating width to columns with nothing but empty cells we avoid
+ // columns that exist only to flesh out a colspan and have no actual cells.
+ if (cellsToProcess == EmptyCells && logicalWidth.isAuto() && (!m_layoutStruct[i].emptyCellsOnly || m_layoutStruct[i].columnHasNoCells))
+ continue;
if (distributionMode != LeftoverWidth && logicalWidth.type() != lengthType)
continue;
@@ -651,7 +657,7 @@ void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total& t
if (lengthType == Percent)
factor = logicalWidth.percent();
else if (lengthType == Auto || lengthType == Fixed)
- factor = m_layoutStruct[i].effectiveMaxLogicalWidth;
+ factor = m_layoutStruct[i].clampedEffectiveMaxLogicalWidth();
}
int newWidth = available * factor / total;
« no previous file with comments | « Source/core/layout/TableLayoutAlgorithmAuto.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698