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

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

Issue 1921973005: [css tables] Don't pass table width increase due to % columns to parents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge ToT Created 4 years, 7 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 | « third_party/WebKit/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: 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..79132d7c0f879718b368c6ff048a6f2fcafc4c9d 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()
{
}
@@ -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,7 +236,7 @@ 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.
@@ -227,7 +246,7 @@ void TableLayoutAlgorithmAuto::computeIntrinsicLogicalWidths(LayoutUnit& minWidt
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);
@@ -239,10 +258,12 @@ 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 (m_scaledWidthFromPercentColumns > maxWidth && shouldScaleColumnsForParent(m_table))
+ maxWidth = m_scaledWidthFromPercentColumns;
}
maxWidth = LayoutUnit(std::max(maxWidth.floor(), spanMaxLogicalWidth));
« no previous file with comments | « third_party/WebKit/Source/core/layout/TableLayoutAlgorithmAuto.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698