bug 11026 - rounding error on balancing when max element size is too large.

This commit is contained in:
karnaze%netscape.com 1999-08-23 04:41:30 +00:00
parent a099869098
commit 580f6c95ec
4 changed files with 44 additions and 38 deletions

View File

@ -1077,9 +1077,9 @@ AC_Wrapup(nsTableFrame* aTableFrame,
void
AC_Increase(PRInt32 aNumAutoCols,
nsColInfo** aColInfo,
PRInt32 aDivisor,
PRInt32& aAvailWidth)
nsColInfo** aColInfo,
PRInt32 aDivisor,
PRInt32& aAvailWidth)
{
for (PRInt32 i = 0; i < aNumAutoCols; i++) {
if ((aAvailWidth <= 0) || (aDivisor <= 0)) {
@ -1087,12 +1087,15 @@ AC_Increase(PRInt32 aNumAutoCols,
}
float percent = ((float)aColInfo[i]->mMaxWidth) / (float)aDivisor;
aDivisor -= aColInfo[i]->mMaxWidth;
nscoord addition = PR_MIN(aAvailWidth, NSToCoordRound(((float)(aAvailWidth)) * percent));
addition = PR_MIN(addition, aColInfo[i]->mMaxWidth - aColInfo[i]->mWidth);
// don't let the total additions exceed what is available
if (i == aNumAutoCols - 1) {
addition = PR_MIN(addition, aAvailWidth);
nscoord addition = NSToCoordRound(((float)(aAvailWidth)) * percent);
// if its the last col, try to give what's left to it
if ((i == aNumAutoCols - 1) && (addition < aAvailWidth)) {
addition = aAvailWidth;
}
// don't let the addition exceed what is available to add
addition = PR_MIN(addition, aAvailWidth);
// don't go over the col max
addition = PR_MIN(addition, aColInfo[i]->mMaxWidth - aColInfo[i]->mWidth);
aColInfo[i]->mWidth += addition;
aAvailWidth -= addition;
}
@ -1100,9 +1103,9 @@ AC_Increase(PRInt32 aNumAutoCols,
void
AC_Decrease(PRInt32 aNumAutoCols,
nsColInfo** aColInfo,
PRInt32 aDivisor,
PRInt32& aExcess)
nsColInfo** aColInfo,
PRInt32 aDivisor,
PRInt32& aExcess)
{
for (PRInt32 i = 0; i < aNumAutoCols; i++) {
if ((aExcess <= 0) || (aDivisor <= 0)) {
@ -1110,19 +1113,20 @@ AC_Decrease(PRInt32 aNumAutoCols,
}
float percent = ((float)aColInfo[i]->mMaxWidth) / (float)aDivisor;
aDivisor -= aColInfo[i]->mMaxWidth;
nscoord reduction = PR_MIN(aExcess, NSToCoordRound(((float)(aExcess)) * percent));
// don't go over the col min
reduction = PR_MIN(reduction, aColInfo[i]->mWidth - aColInfo[i]->mMinWidth);
// don't let the total reductions exceed what is available
if (i == aNumAutoCols - 1) {
reduction = PR_MIN(reduction, aExcess);
nscoord reduction = NSToCoordRound(((float)(aExcess)) * percent);
// if its the last col, try to remove the remaining excess from it
if ((i == aNumAutoCols - 1) && (reduction < aExcess)) {
reduction = aExcess;
}
// don't let the reduction exceed what is available to reduce
reduction = PR_MIN(reduction, aExcess);
// don't go under the col min
reduction = PR_MIN(reduction, aColInfo[i]->mWidth - aColInfo[i]->mMinWidth);
aColInfo[i]->mWidth -= reduction;
aExcess -= reduction;
}
}
void
AC_Sort(nsColInfo** aColInfo, PRInt32 aNumCols)
{

View File

@ -52,7 +52,6 @@ static PRBool DEBUG_REFLOW_ROWGRP = PR_FALSE;
static PRBool DEBUG_REFLOW_ROW = PR_FALSE;
static PRBool DEBUG_REFLOW_CELL = PR_FALSE;
static PRBool DEBUG_REFLOW_AREA = PR_FALSE;
/* ============================================================================ */
/** nsTableFrame maps the inner portion of a table (everything except captions.)

View File

@ -1077,9 +1077,9 @@ AC_Wrapup(nsTableFrame* aTableFrame,
void
AC_Increase(PRInt32 aNumAutoCols,
nsColInfo** aColInfo,
PRInt32 aDivisor,
PRInt32& aAvailWidth)
nsColInfo** aColInfo,
PRInt32 aDivisor,
PRInt32& aAvailWidth)
{
for (PRInt32 i = 0; i < aNumAutoCols; i++) {
if ((aAvailWidth <= 0) || (aDivisor <= 0)) {
@ -1087,12 +1087,15 @@ AC_Increase(PRInt32 aNumAutoCols,
}
float percent = ((float)aColInfo[i]->mMaxWidth) / (float)aDivisor;
aDivisor -= aColInfo[i]->mMaxWidth;
nscoord addition = PR_MIN(aAvailWidth, NSToCoordRound(((float)(aAvailWidth)) * percent));
addition = PR_MIN(addition, aColInfo[i]->mMaxWidth - aColInfo[i]->mWidth);
// don't let the total additions exceed what is available
if (i == aNumAutoCols - 1) {
addition = PR_MIN(addition, aAvailWidth);
nscoord addition = NSToCoordRound(((float)(aAvailWidth)) * percent);
// if its the last col, try to give what's left to it
if ((i == aNumAutoCols - 1) && (addition < aAvailWidth)) {
addition = aAvailWidth;
}
// don't let the addition exceed what is available to add
addition = PR_MIN(addition, aAvailWidth);
// don't go over the col max
addition = PR_MIN(addition, aColInfo[i]->mMaxWidth - aColInfo[i]->mWidth);
aColInfo[i]->mWidth += addition;
aAvailWidth -= addition;
}
@ -1100,9 +1103,9 @@ AC_Increase(PRInt32 aNumAutoCols,
void
AC_Decrease(PRInt32 aNumAutoCols,
nsColInfo** aColInfo,
PRInt32 aDivisor,
PRInt32& aExcess)
nsColInfo** aColInfo,
PRInt32 aDivisor,
PRInt32& aExcess)
{
for (PRInt32 i = 0; i < aNumAutoCols; i++) {
if ((aExcess <= 0) || (aDivisor <= 0)) {
@ -1110,19 +1113,20 @@ AC_Decrease(PRInt32 aNumAutoCols,
}
float percent = ((float)aColInfo[i]->mMaxWidth) / (float)aDivisor;
aDivisor -= aColInfo[i]->mMaxWidth;
nscoord reduction = PR_MIN(aExcess, NSToCoordRound(((float)(aExcess)) * percent));
// don't go over the col min
reduction = PR_MIN(reduction, aColInfo[i]->mWidth - aColInfo[i]->mMinWidth);
// don't let the total reductions exceed what is available
if (i == aNumAutoCols - 1) {
reduction = PR_MIN(reduction, aExcess);
nscoord reduction = NSToCoordRound(((float)(aExcess)) * percent);
// if its the last col, try to remove the remaining excess from it
if ((i == aNumAutoCols - 1) && (reduction < aExcess)) {
reduction = aExcess;
}
// don't let the reduction exceed what is available to reduce
reduction = PR_MIN(reduction, aExcess);
// don't go under the col min
reduction = PR_MIN(reduction, aColInfo[i]->mWidth - aColInfo[i]->mMinWidth);
aColInfo[i]->mWidth -= reduction;
aExcess -= reduction;
}
}
void
AC_Sort(nsColInfo** aColInfo, PRInt32 aNumCols)
{

View File

@ -52,7 +52,6 @@ static PRBool DEBUG_REFLOW_ROWGRP = PR_FALSE;
static PRBool DEBUG_REFLOW_ROW = PR_FALSE;
static PRBool DEBUG_REFLOW_CELL = PR_FALSE;
static PRBool DEBUG_REFLOW_AREA = PR_FALSE;
/* ============================================================================ */
/** nsTableFrame maps the inner portion of a table (everything except captions.)