This source file includes following definitions.
- m_effectiveLogicalWidthDirty
- recalcColumn
- fullRecalc
- shouldScaleColumns
- computeIntrinsicLogicalWidths
- applyPreferredLogicalWidthQuirks
- calcEffectiveLogicalWidth
- insertSpanCell
- layout
#include "config.h"
#include "core/rendering/AutoTableLayout.h"
#include "core/rendering/RenderTable.h"
#include "core/rendering/RenderTableCell.h"
#include "core/rendering/RenderTableCol.h"
#include "core/rendering/RenderTableSection.h"
using namespace std;
namespace WebCore {
AutoTableLayout::AutoTableLayout(RenderTable* table)
: TableLayout(table)
, m_hasPercent(false)
, m_effectiveLogicalWidthDirty(true)
{
}
AutoTableLayout::~AutoTableLayout()
{
}
void AutoTableLayout::recalcColumn(unsigned effCol)
{
Layout& columnLayout = m_layoutStruct[effCol];
RenderTableCell* fixedContributor = 0;
RenderTableCell* maxContributor = 0;
for (RenderObject* child = m_table->children()->firstChild(); child; child = child->nextSibling()) {
if (child->isRenderTableCol()){
toRenderTableCol(child)->clearPreferredLogicalWidthsDirtyBits();
} else if (child->isTableSection()) {
RenderTableSection* section = toRenderTableSection(child);
unsigned numRows = section->numRows();
for (unsigned i = 0; i < numRows; i++) {
RenderTableSection::CellStruct current = section->cellAt(i, effCol);
RenderTableCell* cell = current.primaryCell();
if (current.inColSpan || !cell)
continue;
bool cellHasContent = cell->children()->firstChild() || cell->style()->hasBorder() || cell->style()->hasPadding() || cell->style()->hasBackground();
if (cellHasContent)
columnLayout.emptyCellsOnly = false;
columnLayout.minLogicalWidth = max<int>(columnLayout.minLogicalWidth, cellHasContent ? 1 : 0);
columnLayout.maxLogicalWidth = max<int>(columnLayout.maxLogicalWidth, 1);
if (cell->colSpan() == 1) {
columnLayout.minLogicalWidth = max<int>(cell->minPreferredLogicalWidth(), columnLayout.minLogicalWidth);
if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogicalWidth) {
columnLayout.maxLogicalWidth = cell->maxPreferredLogicalWidth();
maxContributor = cell;
}
const int cCellMaxWidth = 32760;
Length cellLogicalWidth = cell->styleOrColLogicalWidth();
if (cellLogicalWidth.value() > cCellMaxWidth)
cellLogicalWidth.setValue(cCellMaxWidth);
if (cellLogicalWidth.isNegative())
cellLogicalWidth.setValue(0);
switch (cellLogicalWidth.type()) {
case Fixed:
if (cellLogicalWidth.isPositive() && !columnLayout.logicalWidth.isPercent()) {
int logicalWidth = cell->adjustBorderBoxLogicalWidthForBoxSizing(cellLogicalWidth.value());
if (columnLayout.logicalWidth.isFixed()) {
if ((logicalWidth > columnLayout.logicalWidth.value())
|| ((columnLayout.logicalWidth.value() == logicalWidth) && (maxContributor == cell))) {
columnLayout.logicalWidth.setValue(Fixed, logicalWidth);
fixedContributor = cell;
}
} else {
columnLayout.logicalWidth.setValue(Fixed, logicalWidth);
fixedContributor = cell;
}
}
break;
case Percent:
m_hasPercent = true;
if (cellLogicalWidth.isPositive() && (!columnLayout.logicalWidth.isPercent() || cellLogicalWidth.value() > columnLayout.logicalWidth.value()))
columnLayout.logicalWidth = cellLogicalWidth;
break;
default:
break;
}
} else if (!effCol || section->primaryCellAt(i, effCol - 1) != cell) {
insertSpanCell(cell);
}
}
}
}
if (columnLayout.logicalWidth.isFixed()) {
if (m_table->document().inQuirksMode() && columnLayout.maxLogicalWidth > columnLayout.logicalWidth.value() && fixedContributor != maxContributor) {
columnLayout.logicalWidth = Length();
fixedContributor = 0;
}
}
columnLayout.maxLogicalWidth = max(columnLayout.maxLogicalWidth, columnLayout.minLogicalWidth);
}
void AutoTableLayout::fullRecalc()
{
m_hasPercent = false;
m_effectiveLogicalWidthDirty = true;
unsigned nEffCols = m_table->numEffCols();
m_layoutStruct.resize(nEffCols);
m_layoutStruct.fill(Layout());
m_spanCells.fill(0);
Length groupLogicalWidth;
unsigned currentColumn = 0;
for (RenderTableCol* column = m_table->firstColumn(); column; column = column->nextColumn()) {
if (column->isTableColumnGroupWithColumnChildren())
groupLogicalWidth = column->style()->logicalWidth();
else {
Length colLogicalWidth = column->style()->logicalWidth();
if (colLogicalWidth.isAuto())
colLogicalWidth = groupLogicalWidth;
if ((colLogicalWidth.isFixed() || colLogicalWidth.isPercent()) && colLogicalWidth.isZero())
colLogicalWidth = Length();
unsigned effCol = m_table->colToEffCol(currentColumn);
unsigned span = column->span();
if (!colLogicalWidth.isAuto() && span == 1 && effCol < nEffCols && m_table->spanOfEffCol(effCol) == 1) {
m_layoutStruct[effCol].logicalWidth = colLogicalWidth;
if (colLogicalWidth.isFixed() && m_layoutStruct[effCol].maxLogicalWidth < colLogicalWidth.value())
m_layoutStruct[effCol].maxLogicalWidth = colLogicalWidth.value();
}
currentColumn += span;
}
if (column->isTableColumn() && !column->nextSibling())
groupLogicalWidth = Length();
}
for (unsigned i = 0; i < nEffCols; i++)
recalcColumn(i);
}
static bool shouldScaleColumns(RenderTable* table)
{
bool scale = true;
while (table) {
Length tw = table->style()->width();
if ((tw.isAuto() || tw.isPercent()) && !table->isOutOfFlowPositioned()) {
RenderBlock* cb = table->containingBlock();
while (cb && !cb->isRenderView() && !cb->isTableCell() &&
cb->style()->width().isAuto() && !cb->isOutOfFlowPositioned())
cb = cb->containingBlock();
table = 0;
if (cb && cb->isTableCell() &&
(cb->style()->width().isAuto() || cb->style()->width().isPercent())) {
RenderTableCell* cell = toRenderTableCell(cb);
if (cell->colSpan() > 1 || cell->table()->style()->width().isAuto())
scale = false;
else
table = cell->table();
}
}
else
table = 0;
}
return scale;
}
void AutoTableLayout::computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth)
{
fullRecalc();
int spanMaxLogicalWidth = calcEffectiveLogicalWidth();
minWidth = 0;
maxWidth = 0;
float maxPercent = 0;
float maxNonPercent = 0;
bool scaleColumns = shouldScaleColumns(m_table);
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 (m_layoutStruct[i].effectiveLogicalWidth.isPercent()) {
float percent = min(static_cast<float>(m_layoutStruct[i].effectiveLogicalWidth.percent()), remainingPercent);
float logicalWidth = static_cast<float>(m_layoutStruct[i].effectiveMaxLogicalWidth) * 100 / max(percent, epsilon);
maxPercent = max(logicalWidth, maxPercent);
remainingPercent -= percent;
} else
maxNonPercent += m_layoutStruct[i].effectiveMaxLogicalWidth;
}
}
if (scaleColumns) {
maxNonPercent = maxNonPercent * 100 / max(remainingPercent, epsilon);
maxWidth = max<int>(maxWidth, static_cast<int>(min(maxNonPercent, static_cast<float>(tableMaxWidth))));
maxWidth = max<int>(maxWidth, static_cast<int>(min(maxPercent, static_cast<float>(tableMaxWidth))));
}
maxWidth = max<int>(maxWidth, spanMaxLogicalWidth);
}
void AutoTableLayout::applyPreferredLogicalWidthQuirks(LayoutUnit& minWidth, LayoutUnit& maxWidth) const
{
Length tableLogicalWidth = m_table->style()->logicalWidth();
if (tableLogicalWidth.isFixed() && tableLogicalWidth.isPositive())
minWidth = maxWidth = max<int>(minWidth, tableLogicalWidth.value());
}
int AutoTableLayout::calcEffectiveLogicalWidth()
{
int maxLogicalWidth = 0;
size_t nEffCols = m_layoutStruct.size();
int spacingInRowDirection = m_table->hBorderSpacing();
for (size_t i = 0; i < nEffCols; ++i) {
m_layoutStruct[i].effectiveLogicalWidth = m_layoutStruct[i].logicalWidth;
m_layoutStruct[i].effectiveMinLogicalWidth = m_layoutStruct[i].minLogicalWidth;
m_layoutStruct[i].effectiveMaxLogicalWidth = m_layoutStruct[i].maxLogicalWidth;
}
for (size_t i = 0; i < m_spanCells.size(); ++i) {
RenderTableCell* cell = m_spanCells[i];
if (!cell)
break;
unsigned span = cell->colSpan();
Length cellLogicalWidth = cell->styleOrColLogicalWidth();
if (cellLogicalWidth.isZero())
cellLogicalWidth = Length();
unsigned effCol = m_table->colToEffCol(cell->col());
size_t lastCol = effCol;
int cellMinLogicalWidth = cell->minPreferredLogicalWidth() + spacingInRowDirection;
int cellMaxLogicalWidth = cell->maxPreferredLogicalWidth() + spacingInRowDirection;
float totalPercent = 0;
int spanMinLogicalWidth = 0;
int spanMaxLogicalWidth = 0;
bool allColsArePercent = true;
bool allColsAreFixed = true;
bool haveAuto = false;
bool spanHasEmptyCellsOnly = true;
int fixedWidth = 0;
while (lastCol < nEffCols && span > 0) {
Layout& columnLayout = m_layoutStruct[lastCol];
switch (columnLayout.logicalWidth.type()) {
case Percent:
totalPercent += columnLayout.logicalWidth.percent();
allColsAreFixed = false;
break;
case Fixed:
if (columnLayout.logicalWidth.value() > 0) {
fixedWidth += columnLayout.logicalWidth.value();
allColsArePercent = false;
break;
}
case Auto:
haveAuto = true;
default:
if (!columnLayout.effectiveLogicalWidth.isPercent()) {
columnLayout.effectiveLogicalWidth = Length();
allColsArePercent = false;
} else
totalPercent += columnLayout.effectiveLogicalWidth.percent();
allColsAreFixed = false;
}
if (!columnLayout.emptyCellsOnly)
spanHasEmptyCellsOnly = false;
span -= m_table->spanOfEffCol(lastCol);
spanMinLogicalWidth += columnLayout.effectiveMinLogicalWidth;
spanMaxLogicalWidth += columnLayout.effectiveMaxLogicalWidth;
lastCol++;
cellMinLogicalWidth -= spacingInRowDirection;
cellMaxLogicalWidth -= spacingInRowDirection;
}
if (cellLogicalWidth.isPercent()) {
if (totalPercent > cellLogicalWidth.percent() || allColsArePercent) {
cellLogicalWidth = Length();
} else {
maxLogicalWidth = max(maxLogicalWidth, static_cast<int>(max(spanMaxLogicalWidth, cellMaxLogicalWidth) * 100 / cellLogicalWidth.percent()));
float percentMissing = cellLogicalWidth.percent() - totalPercent;
int totalWidth = 0;
for (unsigned pos = effCol; pos < lastCol; ++pos) {
if (!m_layoutStruct[pos].effectiveLogicalWidth.isPercent())
totalWidth += m_layoutStruct[pos].effectiveMaxLogicalWidth;
}
for (unsigned pos = effCol; pos < lastCol && totalWidth > 0; ++pos) {
if (!m_layoutStruct[pos].effectiveLogicalWidth.isPercent()) {
float percent = percentMissing * static_cast<float>(m_layoutStruct[pos].effectiveMaxLogicalWidth) / totalWidth;
totalWidth -= m_layoutStruct[pos].effectiveMaxLogicalWidth;
percentMissing -= percent;
if (percent > 0)
m_layoutStruct[pos].effectiveLogicalWidth.setValue(Percent, percent);
else
m_layoutStruct[pos].effectiveLogicalWidth = Length();
}
}
}
}
if (cellMinLogicalWidth > spanMinLogicalWidth) {
if (allColsAreFixed) {
for (unsigned pos = effCol; fixedWidth > 0 && pos < lastCol; ++pos) {
int cellLogicalWidth = max(m_layoutStruct[pos].effectiveMinLogicalWidth, static_cast<int>(cellMinLogicalWidth * m_layoutStruct[pos].logicalWidth.value() / fixedWidth));
fixedWidth -= m_layoutStruct[pos].logicalWidth.value();
cellMinLogicalWidth -= cellLogicalWidth;
m_layoutStruct[pos].effectiveMinLogicalWidth = cellLogicalWidth;
}
} else if (allColsArePercent) {
int allocatedMinLogicalWidth = 0;
int allocatedMaxLogicalWidth = 0;
for (unsigned pos = effCol; pos < lastCol; ++pos) {
ASSERT(m_layoutStruct[pos].logicalWidth.isPercent() || m_layoutStruct[pos].effectiveLogicalWidth.isPercent());
float percent = m_layoutStruct[pos].logicalWidth.isPercent() ? m_layoutStruct[pos].logicalWidth.percent() : m_layoutStruct[pos].effectiveLogicalWidth.percent();
int columnMinLogicalWidth = static_cast<int>(percent * cellMinLogicalWidth / totalPercent);
int columnMaxLogicalWidth = static_cast<int>(percent * cellMaxLogicalWidth / totalPercent);
m_layoutStruct[pos].effectiveMinLogicalWidth = max(m_layoutStruct[pos].effectiveMinLogicalWidth, columnMinLogicalWidth);
m_layoutStruct[pos].effectiveMaxLogicalWidth = columnMaxLogicalWidth;
allocatedMinLogicalWidth += columnMinLogicalWidth;
allocatedMaxLogicalWidth += columnMaxLogicalWidth;
}
ASSERT(allocatedMinLogicalWidth <= cellMinLogicalWidth);
ASSERT(allocatedMaxLogicalWidth <= cellMaxLogicalWidth);
cellMinLogicalWidth -= allocatedMinLogicalWidth;
cellMaxLogicalWidth -= allocatedMaxLogicalWidth;
} else {
int remainingMaxLogicalWidth = spanMaxLogicalWidth;
int remainingMinLogicalWidth = spanMinLogicalWidth;
for (unsigned pos = effCol; remainingMaxLogicalWidth >= 0 && pos < lastCol; ++pos) {
if (m_layoutStruct[pos].logicalWidth.isFixed() && haveAuto && fixedWidth <= cellMinLogicalWidth) {
int colMinLogicalWidth = max<int>(m_layoutStruct[pos].effectiveMinLogicalWidth, m_layoutStruct[pos].logicalWidth.value());
fixedWidth -= m_layoutStruct[pos].logicalWidth.value();
remainingMinLogicalWidth -= m_layoutStruct[pos].effectiveMinLogicalWidth;
remainingMaxLogicalWidth -= m_layoutStruct[pos].effectiveMaxLogicalWidth;
cellMinLogicalWidth -= colMinLogicalWidth;
m_layoutStruct[pos].effectiveMinLogicalWidth = colMinLogicalWidth;
}
}
for (unsigned pos = effCol; remainingMaxLogicalWidth >= 0 && pos < lastCol && remainingMinLogicalWidth < cellMinLogicalWidth; ++pos) {
if (!(m_layoutStruct[pos].logicalWidth.isFixed() && haveAuto && fixedWidth <= cellMinLogicalWidth)) {
int colMinLogicalWidth = max<int>(m_layoutStruct[pos].effectiveMinLogicalWidth, static_cast<int>(remainingMaxLogicalWidth ? cellMinLogicalWidth * static_cast<float>(m_layoutStruct[pos].effectiveMaxLogicalWidth) / remainingMaxLogicalWidth : cellMinLogicalWidth));
colMinLogicalWidth = min<int>(m_layoutStruct[pos].effectiveMinLogicalWidth + (cellMinLogicalWidth - remainingMinLogicalWidth), colMinLogicalWidth);
remainingMaxLogicalWidth -= m_layoutStruct[pos].effectiveMaxLogicalWidth;
remainingMinLogicalWidth -= m_layoutStruct[pos].effectiveMinLogicalWidth;
cellMinLogicalWidth -= colMinLogicalWidth;
m_layoutStruct[pos].effectiveMinLogicalWidth = colMinLogicalWidth;
}
}
}
}
if (!cellLogicalWidth.isPercent()) {
if (cellMaxLogicalWidth > spanMaxLogicalWidth) {
for (unsigned pos = effCol; spanMaxLogicalWidth >= 0 && pos < lastCol; ++pos) {
int colMaxLogicalWidth = max(m_layoutStruct[pos].effectiveMaxLogicalWidth, static_cast<int>(spanMaxLogicalWidth ? cellMaxLogicalWidth * static_cast<float>(m_layoutStruct[pos].effectiveMaxLogicalWidth) / spanMaxLogicalWidth : cellMaxLogicalWidth));
spanMaxLogicalWidth -= m_layoutStruct[pos].effectiveMaxLogicalWidth;
cellMaxLogicalWidth -= colMaxLogicalWidth;
m_layoutStruct[pos].effectiveMaxLogicalWidth = colMaxLogicalWidth;
}
}
} else {
for (unsigned pos = effCol; pos < lastCol; ++pos)
m_layoutStruct[pos].maxLogicalWidth = max(m_layoutStruct[pos].maxLogicalWidth, m_layoutStruct[pos].minLogicalWidth);
}
if (spanHasEmptyCellsOnly) {
for (unsigned pos = effCol; pos < lastCol; ++pos)
m_layoutStruct[pos].emptyCellsOnly = false;
}
}
m_effectiveLogicalWidthDirty = false;
return min(maxLogicalWidth, INT_MAX / 2);
}
void AutoTableLayout::insertSpanCell(RenderTableCell *cell)
{
ASSERT_ARG(cell, cell && cell->colSpan() != 1);
if (!cell || cell->colSpan() == 1)
return;
unsigned size = m_spanCells.size();
if (!size || m_spanCells[size-1] != 0) {
m_spanCells.grow(size + 10);
for (unsigned i = 0; i < 10; i++)
m_spanCells[size+i] = 0;
size += 10;
}
unsigned pos = 0;
unsigned span = cell->colSpan();
while (pos < m_spanCells.size() && m_spanCells[pos] && span > m_spanCells[pos]->colSpan())
pos++;
memmove(m_spanCells.data()+pos+1, m_spanCells.data()+pos, (size-pos-1)*sizeof(RenderTableCell *));
m_spanCells[pos] = cell;
}
void AutoTableLayout::layout()
{
int tableLogicalWidth = m_table->logicalWidth() - m_table->bordersPaddingAndSpacingInRowDirection();
int available = tableLogicalWidth;
size_t nEffCols = m_table->numEffCols();
if (nEffCols != m_layoutStruct.size()) {
fullRecalc();
nEffCols = m_table->numEffCols();
}
if (m_effectiveLogicalWidthDirty)
calcEffectiveLogicalWidth();
bool havePercent = false;
int numAuto = 0;
int numFixed = 0;
float totalAuto = 0;
float totalFixed = 0;
float totalPercent = 0;
int allocAuto = 0;
unsigned numAutoEmptyCellsOnly = 0;
for (size_t i = 0; i < nEffCols; ++i) {
int cellLogicalWidth = m_layoutStruct[i].effectiveMinLogicalWidth;
m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth;
available -= cellLogicalWidth;
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
switch (logicalWidth.type()) {
case Percent:
havePercent = true;
totalPercent += logicalWidth.percent();
break;
case Fixed:
numFixed++;
totalFixed += m_layoutStruct[i].effectiveMaxLogicalWidth;
break;
case Auto:
if (m_layoutStruct[i].emptyCellsOnly)
numAutoEmptyCellsOnly++;
else {
numAuto++;
totalAuto += m_layoutStruct[i].effectiveMaxLogicalWidth;
allocAuto += cellLogicalWidth;
}
break;
default:
break;
}
}
if (available > 0 && havePercent) {
for (size_t i = 0; i < nEffCols; ++i) {
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (logicalWidth.isPercent()) {
int cellLogicalWidth = max<int>(m_layoutStruct[i].effectiveMinLogicalWidth, minimumValueForLength(logicalWidth, tableLogicalWidth));
available += m_layoutStruct[i].computedLogicalWidth - cellLogicalWidth;
m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth;
}
}
if (totalPercent > 100) {
int excess = tableLogicalWidth * (totalPercent - 100) / 100;
for (unsigned i = nEffCols; i; ) {
--i;
if (m_layoutStruct[i].effectiveLogicalWidth.isPercent()) {
int cellLogicalWidth = m_layoutStruct[i].computedLogicalWidth;
int reduction = min(cellLogicalWidth, excess);
excess -= reduction;
int newLogicalWidth = max<int>(m_layoutStruct[i].effectiveMinLogicalWidth, cellLogicalWidth - reduction);
available += cellLogicalWidth - newLogicalWidth;
m_layoutStruct[i].computedLogicalWidth = newLogicalWidth;
}
}
}
}
if (available > 0) {
for (size_t i = 0; i < nEffCols; ++i) {
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (logicalWidth.isFixed() && logicalWidth.value() > m_layoutStruct[i].computedLogicalWidth) {
available += m_layoutStruct[i].computedLogicalWidth - logicalWidth.value();
m_layoutStruct[i].computedLogicalWidth = logicalWidth.value();
}
}
}
if (available > 0 && numAuto) {
available += allocAuto;
for (size_t i = 0; i < nEffCols; ++i) {
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (logicalWidth.isAuto() && totalAuto && !m_layoutStruct[i].emptyCellsOnly) {
int cellLogicalWidth = 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;
}
}
}
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 && 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 && nEffCols > numAutoEmptyCellsOnly) {
unsigned total = nEffCols - numAutoEmptyCellsOnly;
for (unsigned i = nEffCols; i; ) {
--i;
if (m_layoutStruct[i].effectiveLogicalWidth.isAuto() && m_layoutStruct[i].emptyCellsOnly)
continue;
int cellLogicalWidth = available / total;
available -= cellLogicalWidth;
total--;
m_layoutStruct[i].computedLogicalWidth += cellLogicalWidth;
}
}
if (available < 0) {
if (available < 0) {
int logicalWidthBeyondMin = 0;
for (unsigned i = nEffCols; i; ) {
--i;
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (logicalWidth.isAuto())
logicalWidthBeyondMin += m_layoutStruct[i].computedLogicalWidth - m_layoutStruct[i].effectiveMinLogicalWidth;
}
for (unsigned i = nEffCols; i && logicalWidthBeyondMin > 0; ) {
--i;
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (logicalWidth.isAuto()) {
int minMaxDiff = m_layoutStruct[i].computedLogicalWidth - m_layoutStruct[i].effectiveMinLogicalWidth;
int reduce = available * minMaxDiff / logicalWidthBeyondMin;
m_layoutStruct[i].computedLogicalWidth += reduce;
available -= reduce;
logicalWidthBeyondMin -= minMaxDiff;
if (available >= 0)
break;
}
}
}
if (available < 0) {
int logicalWidthBeyondMin = 0;
for (unsigned i = nEffCols; i; ) {
--i;
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (logicalWidth.isFixed())
logicalWidthBeyondMin += m_layoutStruct[i].computedLogicalWidth - m_layoutStruct[i].effectiveMinLogicalWidth;
}
for (unsigned i = nEffCols; i && logicalWidthBeyondMin > 0; ) {
--i;
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (logicalWidth.isFixed()) {
int minMaxDiff = m_layoutStruct[i].computedLogicalWidth - m_layoutStruct[i].effectiveMinLogicalWidth;
int reduce = available * minMaxDiff / logicalWidthBeyondMin;
m_layoutStruct[i].computedLogicalWidth += reduce;
available -= reduce;
logicalWidthBeyondMin -= minMaxDiff;
if (available >= 0)
break;
}
}
}
if (available < 0) {
int logicalWidthBeyondMin = 0;
for (unsigned i = nEffCols; i; ) {
--i;
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (logicalWidth.isPercent())
logicalWidthBeyondMin += m_layoutStruct[i].computedLogicalWidth - m_layoutStruct[i].effectiveMinLogicalWidth;
}
for (unsigned i = nEffCols; i && logicalWidthBeyondMin > 0; ) {
--i;
Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
if (logicalWidth.isPercent()) {
int minMaxDiff = m_layoutStruct[i].computedLogicalWidth - m_layoutStruct[i].effectiveMinLogicalWidth;
int reduce = available * minMaxDiff / logicalWidthBeyondMin;
m_layoutStruct[i].computedLogicalWidth += reduce;
available -= reduce;
logicalWidthBeyondMin -= minMaxDiff;
if (available >= 0)
break;
}
}
}
}
int pos = 0;
for (size_t i = 0; i < nEffCols; ++i) {
m_table->setColumnPosition(i, pos);
pos += m_layoutStruct[i].computedLogicalWidth + m_table->hBorderSpacing();
}
m_table->setColumnPosition(m_table->columnPositions().size() - 1, pos);
}
}