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

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: naively pass scaled width to non-table parents Created 4 years, 8 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
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..56982e17914c4269a2a5b02ca5f0c345de42f13b 100644
--- a/third_party/WebKit/Source/core/layout/TableLayoutAlgorithmAuto.cpp
+++ b/third_party/WebKit/Source/core/layout/TableLayoutAlgorithmAuto.cpp
@@ -177,8 +177,13 @@ void TableLayoutAlgorithmAuto::fullRecalc()
recalcColumn(i);
}
+static bool shouldScaleColumnsForParent(LayoutTable* table)
+{
+ return !table->containingBlock()->isTableCell();
dgrogan 2016/04/28 01:04:31 This is the naive first cut. It doesn't even imple
mstensho (USE GERRIT) 2016/04/28 09:18:05 I see. This approach should in theory not cause an
+}
+
// FIXME: This needs to be adapted for vertical writing modes.
-static bool shouldScaleColumns(LayoutTable* table)
+static bool shouldScaleColumnsForSelf(LayoutTable* table)
{
// 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.
@@ -215,9 +220,26 @@ void TableLayoutAlgorithmAuto::computeIntrinsicLogicalWidths(LayoutUnit& minWidt
int spanMaxLogicalWidth = calcEffectiveLogicalWidth();
minWidth = LayoutUnit();
maxWidth = LayoutUnit();
+
+ for (size_t i = 0; i < m_layoutStruct.size(); ++i) {
+ minWidth += m_layoutStruct[i].effectiveMinLogicalWidth;
+ maxWidth += m_layoutStruct[i].effectiveMaxLogicalWidth;
+ }
+ if (shouldScaleColumnsForParent(m_table))
+ maxWidth = std::max(maxWidth, scaledWidthFromPercentColumns());
+ maxWidth = LayoutUnit(std::max(maxWidth.floor(), spanMaxLogicalWidth));
+}
+
+LayoutUnit TableLayoutAlgorithmAuto::scaledWidthFromPercentColumns()
dgrogan 2016/04/28 01:04:31 Ignore that this is a separate function for now. I
+{
+ // 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"
+ if (!shouldScaleColumnsForSelf(m_table))
+ return LayoutUnit(0);
+
float maxPercent = 0;
float maxNonPercent = 0;
- bool scaleColumns = shouldScaleColumns(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.
@@ -225,27 +247,19 @@ void TableLayoutAlgorithmAuto::computeIntrinsicLogicalWidths(LayoutUnit& minWidt
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 (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);
- maxPercent = std::max(logicalWidth, maxPercent);
- remainingPercent -= percent;
- } else {
- maxNonPercent += m_layoutStruct[i].effectiveMaxLogicalWidth;
- }
+ 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);
+ maxPercent = std::max(logicalWidth, maxPercent);
+ remainingPercent -= percent;
+ } else {
+ maxNonPercent += m_layoutStruct[i].effectiveMaxLogicalWidth;
}
}
- if (scaleColumns) {
- 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))));
- }
-
- maxWidth = LayoutUnit(std::max(maxWidth.floor(), spanMaxLogicalWidth));
+ maxNonPercent = maxNonPercent * 100 / std::max(remainingPercent, epsilon);
+ LayoutUnit maxWidth = LayoutUnit(std::min(maxNonPercent, static_cast<float>(tableMaxWidth)));
+ return std::max(maxWidth, LayoutUnit(std::min(maxPercent, static_cast<float>(tableMaxWidth))));
}
void TableLayoutAlgorithmAuto::applyPreferredLogicalWidthQuirks(LayoutUnit& minWidth, LayoutUnit& maxWidth) const

Powered by Google App Engine
This is Rietveld 408576698