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

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

Issue 1111443003: Refactor the code distributing width to columns in auto layout tables. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated Created 5 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
« 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 d6dad14d1737a4bd1ae03338129b28002585d630..25277e519aca78b677b9fef7209218770da96198 100644
--- a/Source/core/layout/TableLayoutAlgorithmAuto.cpp
+++ b/Source/core/layout/TableLayoutAlgorithmAuto.cpp
@@ -590,74 +590,31 @@ void TableLayoutAlgorithmAuto::layout()
}
}
- // now satisfy variable
if (available > 0 && numAuto) {
- available += allocAuto; // this gets redistributed
- for (size_t i = 0; i < nEffCols; ++i) {
- Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
- if (logicalWidth.isAuto() && totalAuto && !m_layoutStruct[i].emptyCellsOnly) {
- int cellLogicalWidth = std::max<int>(m_layoutStruct[i].computedLogicalWidth, static_cast<int>(available * static_cast<float>(m_layoutStruct[i].effectiveMaxLogicalWidth) / totalAuto));
- available -= cellLogicalWidth;
- totalAuto -= m_layoutStruct[i].effectiveMaxLogicalWidth;
- m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth;
- }
- }
+ available += allocAuto;
+ distributeWidthToColumns(Auto, available, totalAuto, NonEmptyCells, InitialWidth);
}
- // spread over fixed columns
- if (available > 0 && numFixed) {
- for (size_t i = 0; i < nEffCols; ++i) {
- Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
- if (logicalWidth.isFixed()) {
- int cellLogicalWidth = static_cast<int>(available * static_cast<float>(m_layoutStruct[i].effectiveMaxLogicalWidth) / totalFixed);
- available -= cellLogicalWidth;
- totalFixed -= m_layoutStruct[i].effectiveMaxLogicalWidth;
- m_layoutStruct[i].computedLogicalWidth += cellLogicalWidth;
- }
- }
- }
+ if (available > 0 && numFixed)
+ distributeWidthToColumns(Fixed, available, totalFixed);
- // spread over percent colums
- if (available > 0 && m_hasPercent && totalPercent < 100) {
- for (size_t i = 0; i < nEffCols; ++i) {
- Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
- if (logicalWidth.isPercent()) {
- int cellLogicalWidth = available * logicalWidth.percent() / totalPercent;
- available -= cellLogicalWidth;
- totalPercent -= logicalWidth.percent();
- m_layoutStruct[i].computedLogicalWidth += cellLogicalWidth;
- if (!available || !totalPercent)
- break;
- }
- }
- }
+ if (available > 0 && m_hasPercent && totalPercent < 100)
+ distributeWidthToColumns(Percent, available, totalPercent);
- // spread over the rest
if (available > 0 && nEffCols > numAutoEmptyCellsOnly) {
unsigned total = nEffCols - numAutoEmptyCellsOnly;
- // still have some width to spread
- for (unsigned i = nEffCols; i; ) {
- --i;
- // variable columns with empty cells only don't get any width
- if (m_layoutStruct[i].effectiveLogicalWidth.isAuto() && m_layoutStruct[i].emptyCellsOnly)
- continue;
- int cellLogicalWidth = available / total;
- available -= cellLogicalWidth;
- total--;
- m_layoutStruct[i].computedLogicalWidth += cellLogicalWidth;
- }
+ distributeWidthToColumns(Auto, available, total, NonEmptyCells, LeftOverWidth, EndToStart);
}
rhogan 2015/04/28 13:44:08 This End to Start order for this left over width i
mstensho (USE GERRIT) 2015/04/28 21:53:12 OK. Worth a comment?
mstensho (USE GERRIT) 2015/05/04 20:42:47 Acknowledged.
// If we have overallocated, reduce every cell according to the difference between desired width and minwidth
// this seems to produce to the pixel exact results with IE. Wonder is some of this also holds for width distributing.
- // Need to reduce cells with the following prioritization:
// This is basically the reverse of how we grew the cells.
if (available < 0)
- shrinkCellWidth(Auto, available);
+ shrinkColumnWidth(Auto, available);
if (available < 0)
- shrinkCellWidth(Fixed, available);
+ shrinkColumnWidth(Fixed, available);
if (available < 0)
- shrinkCellWidth(Percent, available);
+ shrinkColumnWidth(Percent, available);
int pos = 0;
for (size_t i = 0; i < nEffCols; ++i) {
@@ -667,7 +624,38 @@ void TableLayoutAlgorithmAuto::layout()
m_table->setColumnPosition(m_table->columnPositions().size() - 1, pos);
}
-void TableLayoutAlgorithmAuto::shrinkCellWidth(const LengthType& lengthType, int& available)
+
+void TableLayoutAlgorithmAuto::distributeWidthToColumns(const LengthType& lengthType, int& available, int total, LimitToCells limitToCells, DistributionMode distributionMode, DistributionDirection distributionDirection)
+{
+ int nEffCols = static_cast<int>(m_table->numEffCols());
+ bool startToEnd = distributionDirection == StartToEnd;
+ for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i > -1; startToEnd ? ++i : --i) {
+ Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
+ if (limitToCells == NonEmptyCells && logicalWidth.isAuto() && m_layoutStruct[i].emptyCellsOnly)
+ continue;
+ if (distributionMode != LeftOverWidth && logicalWidth.type() != lengthType)
+ continue;
+
+ int factor = 1;
+ if (distributionMode == LeftOverWidth)
+ factor = 1;
+ else if (lengthType == Percent)
+ factor = logicalWidth.percent();
+ else if (lengthType == Auto || lengthType == Fixed)
+ factor = m_layoutStruct[i].effectiveMaxLogicalWidth;
+
+ int newWidth = available * factor / total;
+ int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_layoutStruct[i].computedLogicalWidth, newWidth) : newWidth;
+ available -= cellLogicalWidth;
+ total -= factor;
+ m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWidth) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWidth;
+
+ if (!available || !total)
+ return;
rhogan 2015/04/28 13:44:08 This is a change. We only bail early for auto and
mstensho (USE GERRIT) 2015/04/28 21:53:12 But is it safe to change the bailing policy at all
mstensho (USE GERRIT) 2015/05/04 20:42:47 OK, you added a comment, so I'll just trust you. :
+ }
+}
+
+void TableLayoutAlgorithmAuto::shrinkColumnWidth(const LengthType& lengthType, int& available)
{
size_t nEffCols = m_table->numEffCols();
int logicalWidthBeyondMin = 0;
« 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