Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/TableLayoutAlgorithmAuto.cpp |
| diff --git a/third_party/WebKit/Source/core/layout/TableLayoutAlgorithmAuto.cpp b/third_party/WebKit/Source/core/layout/TableLayoutAlgorithmAuto.cpp |
| index 0ff2aad54ee239d5a6080cad371f6bc07eecb043..27d9aec8d6d21ec6c8c998fcc45ed43ac9ff17b8 100644 |
| --- a/third_party/WebKit/Source/core/layout/TableLayoutAlgorithmAuto.cpp |
| +++ b/third_party/WebKit/Source/core/layout/TableLayoutAlgorithmAuto.cpp |
| @@ -33,6 +33,7 @@ TableLayoutAlgorithmAuto::TableLayoutAlgorithmAuto(LayoutTable* table) |
| : TableLayoutAlgorithm(table) |
| , m_hasPercent(false) |
| , m_effectiveLogicalWidthDirty(true) |
| + , m_scaledWidthFromPercentColumns(0) |
|
mstensho (USE GERRIT)
2016/05/18 19:50:17
No need to explicitly initialize LayoutUnit to 0.
dgrogan
2016/05/18 22:28:33
Done.
|
| { |
| } |
| @@ -177,9 +178,27 @@ void TableLayoutAlgorithmAuto::fullRecalc() |
| recalcColumn(i); |
| } |
| +static bool shouldScaleColumnsForParent(LayoutTable* table) |
| +{ |
| + LayoutBlock* cb = table->containingBlock(); |
| + while (!cb->isLayoutView()) { |
| + // It doesn't matter if our table is auto or fixed: auto means we don't |
| + // scale. Fixed doesn't care if we do or not because it doesn't depend |
| + // on the cell contents' preferred widths. |
| + if (cb->isTableCell()) |
| + return false; |
| + cb = cb->containingBlock(); |
| + } |
| + return true; |
| +} |
| + |
| // FIXME: This needs to be adapted for vertical writing modes. |
| -static bool shouldScaleColumns(LayoutTable* table) |
| +static bool shouldScaleColumnsForSelf(LayoutTable* table) |
| { |
| + // Normally, scale all columns to satisfy this from CSS2.2: |
| + // "A percentage value for a column width is relative to the table width. |
| + // If the table has 'width: auto', a percentage represents a constraint on the column's width" |
| + |
| // A special case. If this table is not fixed width and contained inside |
| // a cell, then don't bloat the maxwidth by examining percentage growth. |
| while (true) { |
| @@ -217,17 +236,18 @@ void TableLayoutAlgorithmAuto::computeIntrinsicLogicalWidths(LayoutUnit& minWidt |
| maxWidth = LayoutUnit(); |
| float maxPercent = 0; |
| float maxNonPercent = 0; |
| - bool scaleColumns = shouldScaleColumns(m_table); |
| + bool scaleColumnsForSelf = shouldScaleColumnsForSelf(m_table); |
| // We substitute 0 percent by (epsilon / percentScaleFactor) percent in two places below to avoid division by zero. |
| // FIXME: Handle the 0% cases properly. |
| const float epsilon = 1 / 128.0f; |
| float remainingPercent = 100; |
| + |
| for (size_t i = 0; i < m_layoutStruct.size(); ++i) { |
| minWidth += m_layoutStruct[i].effectiveMinLogicalWidth; |
| maxWidth += m_layoutStruct[i].effectiveMaxLogicalWidth; |
| - if (scaleColumns) { |
| + if (scaleColumnsForSelf) { |
| if (m_layoutStruct[i].effectiveLogicalWidth.hasPercent()) { |
| float percent = std::min(static_cast<float>(m_layoutStruct[i].effectiveLogicalWidth.percent()), remainingPercent); |
| float logicalWidth = static_cast<float>(m_layoutStruct[i].effectiveMaxLogicalWidth) * 100 / std::max(percent, epsilon); |
| @@ -238,16 +258,24 @@ void TableLayoutAlgorithmAuto::computeIntrinsicLogicalWidths(LayoutUnit& minWidt |
| } |
| } |
| } |
| - |
| - if (scaleColumns) { |
| + if (scaleColumnsForSelf) { |
| maxNonPercent = maxNonPercent * 100 / std::max(remainingPercent, epsilon); |
| - maxWidth = std::max(maxWidth, LayoutUnit(std::min(maxNonPercent, static_cast<float>(tableMaxWidth)))); |
| - maxWidth = std::max(maxWidth, LayoutUnit(std::min(maxPercent, static_cast<float>(tableMaxWidth)))); |
| + m_scaledWidthFromPercentColumns = LayoutUnit(std::min(maxNonPercent, static_cast<float>(tableMaxWidth))); |
| + m_scaledWidthFromPercentColumns = std::max(m_scaledWidthFromPercentColumns, LayoutUnit(std::min(maxPercent, static_cast<float>(tableMaxWidth)))); |
| } |
| + if (shouldScaleColumnsForParent(m_table)) { |
|
mstensho (USE GERRIT)
2016/05/18 19:50:17
Should probably check |scaleColumnsForSelf| first,
dgrogan
2016/05/18 22:28:33
Done. Well, I changed to checking to see if m_scal
|
| + DCHECK(scaleColumnsForSelf); |
| + maxWidth = std::max(m_scaledWidthFromPercentColumns, maxWidth); |
| + } |
| maxWidth = LayoutUnit(std::max(maxWidth.floor(), spanMaxLogicalWidth)); |
| } |
| +LayoutUnit TableLayoutAlgorithmAuto::scaledWidthFromPercentColumns() |
|
mstensho (USE GERRIT)
2016/05/18 19:50:17
Make this inline?
dgrogan
2016/05/18 22:28:33
Done.
|
| +{ |
| + return m_scaledWidthFromPercentColumns; |
| +} |
| + |
| void TableLayoutAlgorithmAuto::applyPreferredLogicalWidthQuirks(LayoutUnit& minWidth, LayoutUnit& maxWidth) const |
| { |
| Length tableLogicalWidth = m_table->style()->logicalWidth(); |