Fix slight errors when widths can't be round-tripped through floats. (Bug 467141) r+sr=roc

This commit is contained in:
L. David Baron 2008-12-04 08:09:53 -08:00
Родитель 4260a65399
Коммит e3204bb21a
3 изменённых файлов: 28 добавлений и 6 удалений

Просмотреть файл

@ -168,6 +168,18 @@ FixedTableLayoutStrategy::MarkIntrinsicWidthsDirty()
mLastCalcWidth = nscoord_MIN;
}
static inline nscoord
AllocateUnassigned(nscoord aUnassignedSpace, float aShare)
{
if (aShare == 1.0f) {
// This happens when the numbers we're dividing to get aShare
// are equal. We want to return unassignedSpace exactly, even
// if it can't be precisely round-tripped through float.
return aUnassignedSpace;
}
return NSToCoordRound(float(aUnassignedSpace) * aShare);
}
/* virtual */ void
FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowState)
{
@ -357,8 +369,8 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt
if (colFrame->GetPrefPercent() == 0.0f) {
NS_ASSERTION(colFrame->GetFinalWidth() <= specUndist,
"widths don't add up");
nscoord toAdd = NSToCoordRound(float(unassignedSpace) *
(float(colFrame->GetFinalWidth()) / float(specUndist)));
nscoord toAdd = AllocateUnassigned(unassignedSpace,
float(colFrame->GetFinalWidth()) / float(specUndist));
specUndist -= colFrame->GetFinalWidth();
colFrame->SetFinalWidth(colFrame->GetFinalWidth() + toAdd);
unassignedSpace -= toAdd;
@ -386,8 +398,8 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt
"widths don't add up");
pctUndist = colFrame->GetPrefPercent();
}
nscoord toAdd = NSToCoordRound(float(unassignedSpace) *
(colFrame->GetPrefPercent() / pctUndist));
nscoord toAdd = AllocateUnassigned(unassignedSpace,
colFrame->GetPrefPercent() / pctUndist);
colFrame->SetFinalWidth(colFrame->GetFinalWidth() + toAdd);
unassignedSpace -= toAdd;
pctUndist -= colFrame->GetPrefPercent();
@ -406,12 +418,13 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt
continue;
}
NS_ASSERTION(colFrame->GetFinalWidth() == 0, "yikes");
nscoord toAdd = NSToCoordRound(float(unassignedSpace) /
float(colsLeft));
nscoord toAdd = AllocateUnassigned(unassignedSpace,
1.0f / float(colsLeft));
colFrame->SetFinalWidth(toAdd);
unassignedSpace -= toAdd;
--colsLeft;
}
NS_ASSERTION(unassignedSpace == 0, "failed to redistribute");
}
}
for (PRInt32 col = 0; col < colCount; ++col) {

Просмотреть файл

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table width="16211982" cellspacing="0" style="table-layout: fixed;"><tbody><tr><td width="26"></td></tr></tbody></table>
</body>
</html>

Просмотреть файл

@ -56,3 +56,4 @@ load 416845-3.html
load 423514-1.xhtml
load 456041.html
load 457115.html
load 467141-1.html