Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Split the extra logical height distribution logic out of RenderTableS…
…ection::layoutRows

https://bugs.webkit.org/show_bug.cgi?id=80671

Reviewed by Adrienne Walker.

Refactoring only, no change in behavior expected.

* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::layoutRows):
Split the logic from here...

(WebCore::RenderTableSection::distributeExtraLogicalHeightToPercentRows):
(WebCore::RenderTableSection::distributeExtraLogicalHeightToAutoRows):
(WebCore::RenderTableSection::distributeRemainingExtraLogicalHeight):
(WebCore::RenderTableSection::distributeExtraLogicalHeightToRows):
... to those functions. Cleaned up the variable naming while at it and
made them follow the same signature as this may be useful to fix another
bug I have.

* rendering/RenderTableSection.h:
(RenderTableSection):
Added the previous 4 new functions.


Canonical link: https://commits.webkit.org/97931@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110336 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Julien Chaffraix committed Mar 9, 2012
1 parent 01b7cd6 commit 4c23753
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 60 deletions.
25 changes: 25 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,28 @@
2012-03-09 Julien Chaffraix <jchaffraix@webkit.org>

Split the extra logical height distribution logic out of RenderTableSection::layoutRows
https://bugs.webkit.org/show_bug.cgi?id=80671

Reviewed by Adrienne Walker.

Refactoring only, no change in behavior expected.

* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::layoutRows):
Split the logic from here...

(WebCore::RenderTableSection::distributeExtraLogicalHeightToPercentRows):
(WebCore::RenderTableSection::distributeExtraLogicalHeightToAutoRows):
(WebCore::RenderTableSection::distributeRemainingExtraLogicalHeight):
(WebCore::RenderTableSection::distributeExtraLogicalHeightToRows):
... to those functions. Cleaned up the variable naming while at it and
made them follow the same signature as this may be useful to fix another
bug I have.

* rendering/RenderTableSection.h:
(RenderTableSection):
Added the previous 4 new functions.

2012-03-09 Rob Buis <rbuis@rim.com>

Remove unused file FrameBlackBerry.cpp
Expand Down
158 changes: 98 additions & 60 deletions Source/WebCore/rendering/RenderTableSection.cpp
Expand Up @@ -424,7 +424,103 @@ void RenderTableSection::layout()
setNeedsLayout(false);
}

int RenderTableSection::layoutRows(int toAdd)
int RenderTableSection::distributeExtraLogicalHeightToPercentRows(int extraLogicalHeight, int totalPercent)
{
if (!totalPercent)
return extraLogicalHeight;

unsigned totalRows = m_grid.size();
int totalHeight = m_rowPos[totalRows] + extraLogicalHeight;
int add = 0;
totalPercent = min(totalPercent, 100);
int rowHeight = m_rowPos[1] - m_rowPos[0];
for (unsigned r = 0; r < totalRows; ++r) {
if (totalPercent > 0 && m_grid[r].logicalHeight.isPercent()) {
int toAdd = min<int>(extraLogicalHeight, (totalHeight * m_grid[r].logicalHeight.percent() / 100) - rowHeight);
// If toAdd is negative, then we don't want to shrink the row (this bug
// affected Outlook Web Access).
toAdd = max(0, toAdd);
add += toAdd;
extraLogicalHeight -= toAdd;
totalPercent -= m_grid[r].logicalHeight.percent();
}
ASSERT(totalRows >= 1);
if (r < totalRows - 1)
rowHeight = m_rowPos[r + 2] - m_rowPos[r + 1];
m_rowPos[r + 1] += add;
}
return extraLogicalHeight;
}

int RenderTableSection::distributeExtraLogicalHeightToAutoRows(int extraLogicalHeight, unsigned autoRowsCount)
{
if (!autoRowsCount)
return extraLogicalHeight;

int add = 0;
for (unsigned r = 0; r < m_grid.size(); ++r) {
if (autoRowsCount > 0 && m_grid[r].logicalHeight.isAuto()) {
// Recomputing |extraLogicalHeightForRow| guarantees that we properly ditribute round |extraLogicalHeight|.
int extraLogicalHeightForRow = extraLogicalHeight / autoRowsCount;
add += extraLogicalHeightForRow;
extraLogicalHeight -= extraLogicalHeightForRow;
--autoRowsCount;
}
m_rowPos[r + 1] += add;
}
return extraLogicalHeight;
}

int RenderTableSection::distributeRemainingExtraLogicalHeight(int extraLogicalHeight)
{
unsigned totalRows = m_grid.size();

if (extraLogicalHeight <= 0 || !m_rowPos[totalRows])
return extraLogicalHeight;

// FIXME: m_rowPos[totalRows] - m_rowPos[0] is the total rows' size.
int totalRowSize = m_rowPos[totalRows];
int add = 0;
int previousRowPosition = m_rowPos[0];
for (unsigned r = 0; r < totalRows; r++) {
// weight with the original height
add += extraLogicalHeight * (m_rowPos[r + 1] - previousRowPosition) / totalRowSize;
previousRowPosition = m_rowPos[r + 1];
m_rowPos[r + 1] += add;
}

return extraLogicalHeight;
}

int RenderTableSection::distributeExtraLogicalHeightToRows(int extraLogicalHeight)
{
if (!extraLogicalHeight)
return extraLogicalHeight;

unsigned totalRows = m_grid.size();
if (!totalRows)
return extraLogicalHeight;

if (!m_rowPos[totalRows] && nextSibling())
return extraLogicalHeight;

unsigned autoRowsCount = 0;
int totalPercent = 0;
for (unsigned r = 0; r < totalRows; r++) {
if (m_grid[r].logicalHeight.isAuto())
++autoRowsCount;
else if (m_grid[r].logicalHeight.isPercent())
totalPercent += m_grid[r].logicalHeight.percent();
}

int remainingExtraLogicalHeight = extraLogicalHeight;
remainingExtraLogicalHeight = distributeExtraLogicalHeightToPercentRows(remainingExtraLogicalHeight, totalPercent);
remainingExtraLogicalHeight = distributeExtraLogicalHeightToAutoRows(remainingExtraLogicalHeight, autoRowsCount);
remainingExtraLogicalHeight = distributeRemainingExtraLogicalHeight(remainingExtraLogicalHeight);
return remainingExtraLogicalHeight;
}

int RenderTableSection::layoutRows(int extraLogicalHeight)
{
#ifndef NDEBUG
setNeedsLayoutIsForbidden(true);
Expand All @@ -442,65 +538,7 @@ int RenderTableSection::layoutRows(int toAdd)
m_overflowingCells.clear();
m_forceSlowPaintPathWithOverflowingCell = false;

if (toAdd && totalRows && (m_rowPos[totalRows] || !nextSibling())) {
int totalHeight = m_rowPos[totalRows] + toAdd;

int dh = toAdd;
int totalPercent = 0;
int numAuto = 0;
for (unsigned r = 0; r < totalRows; r++) {
if (m_grid[r].logicalHeight.isAuto())
numAuto++;
else if (m_grid[r].logicalHeight.isPercent())
totalPercent += m_grid[r].logicalHeight.percent();
}
if (totalPercent) {
// try to satisfy percent
int add = 0;
totalPercent = min(totalPercent, 100);
int rh = m_rowPos[1] - m_rowPos[0];
for (unsigned r = 0; r < totalRows; r++) {
if (totalPercent > 0 && m_grid[r].logicalHeight.isPercent()) {
int toAdd = min<int>(dh, (totalHeight * m_grid[r].logicalHeight.percent() / 100) - rh);
// If toAdd is negative, then we don't want to shrink the row (this bug
// affected Outlook Web Access).
toAdd = max(0, toAdd);
add += toAdd;
dh -= toAdd;
totalPercent -= m_grid[r].logicalHeight.percent();
}
ASSERT(totalRows >= 1);
if (r < totalRows - 1)
rh = m_rowPos[r + 2] - m_rowPos[r + 1];
m_rowPos[r + 1] += add;
}
}
if (numAuto) {
// distribute over variable cols
int add = 0;
for (unsigned r = 0; r < totalRows; r++) {
if (numAuto > 0 && m_grid[r].logicalHeight.isAuto()) {
int toAdd = dh / numAuto;
add += toAdd;
dh -= toAdd;
numAuto--;
}
m_rowPos[r + 1] += add;
}
}
if (dh > 0 && m_rowPos[totalRows]) {
// if some left overs, distribute equally.
int tot = m_rowPos[totalRows];
int add = 0;
int prev = m_rowPos[0];
for (unsigned r = 0; r < totalRows; r++) {
// weight with the original height
add += dh * (m_rowPos[r + 1] - prev) / tot;
prev = m_rowPos[r + 1];
m_rowPos[r + 1] += add;
}
}
}
extraLogicalHeight = distributeExtraLogicalHeightToRows(extraLogicalHeight);

int hspacing = table()->hBorderSpacing();
int vspacing = table()->vBorderSpacing();
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/rendering/RenderTableSection.h
Expand Up @@ -185,6 +185,13 @@ class RenderTableSection : public RenderBox {

void ensureRows(unsigned);

// Those methods return the remaining extra logical height.
// FIXME: We may want to introduce a structure holding the in-flux layout information.
int distributeExtraLogicalHeightToRows(int extraLogicalHeight);
int distributeExtraLogicalHeightToPercentRows(int extraLogicalHeight, int totalPercent);
int distributeExtraLogicalHeightToAutoRows(int extraLogicalHeight, unsigned autoRowsCount);
int distributeRemainingExtraLogicalHeight(int extraLogicalHeight);

bool hasOverflowingCell() const { return m_overflowingCells.size() || m_forceSlowPaintPathWithOverflowingCell; }

CellSpan fullTableRowSpan() const { return CellSpan(0, m_grid.size()); }
Expand Down

0 comments on commit 4c23753

Please sign in to comment.