bug 46623 - allocate proportional and auto cols together when balancing columns. (sr=buster, r=peterl)

allow columns (due to colspan) containing no originating cols at the end of the table to exist
This commit is contained in:
karnaze%netscape.com 2001-01-12 23:07:54 +00:00
Родитель 10ce246c1c
Коммит 84a6a94d17
10 изменённых файлов: 132 добавлений и 200 удалений

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

@ -44,9 +44,8 @@ static PRInt32 gsDebugCount = 0;
// 2) max (PCT, PCT_ADJ)
// 3) FIX
// 4) FIX_ADJ
// 5) PROportional
// 6) max(DES_CON, DES_ADJ)
// 7) for a fixed width table, the column may get more
// 5) max(DES_CON, DES_ADJ), but use MIN_PRO if present
// 6) for a fixed width table, the column may get more
// space if the sum of the col allocations is insufficient
@ -59,7 +58,6 @@ PRBool CanAllocate(PRInt32 aType,
case PCT:
case FIX:
case DES_CON:
case MIN_PRO:
return (WIDTH_NOT_SET == aPrevType);
case FIX_ADJ:
return (WIDTH_NOT_SET == aPrevType) || (FIX == aPrevType);
@ -190,7 +188,7 @@ BasicTableLayoutStrategy::BalanceColumnWidths(nsIPresContext* aPresCont
return PR_FALSE;
}
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
// determine if the table is auto/fixed and get the fixed width if available
nscoord maxWidth = aMaxWidthIn;
@ -301,21 +299,11 @@ BasicTableLayoutStrategy::BalanceColumnWidths(nsIPresContext* aPresCont
return BCW_Wrapup(aPresContext, this, mTableFrame, allocTypes);
}
}
// allocate proportional cols up to their min proportional value
if ((totalAllocated < maxWidth) && (totalCounts[MIN_PRO] > 0)) {
if (totalAllocated + totalWidths[MIN_PRO] - dupedWidths[MIN_PRO] <= maxWidth) {
AllocateFully(totalAllocated, allocTypes, MIN_PRO);
//NS_WARN_IF_FALSE(totalAllocated <= maxWidth, "over allocated");
}
else {
AllocateConstrained(maxWidth - totalAllocated, MIN_PRO, PR_FALSE, allocTypes, p2t);
return BCW_Wrapup(aPresContext, this, mTableFrame, allocTypes);
}
}
// allocate auto cols
if ((totalAllocated < maxWidth) && (totalCounts[DES_CON] > 0)) {
if (totalAllocated + totalWidths[DES_CON] - dupedWidths[DES_CON]<= maxWidth) {
// allocate proportional and auto cols together
if ((totalAllocated < maxWidth) && (totalCounts[MIN_PRO] + totalCounts[DES_CON] > 0)) {
if (totalAllocated + totalWidths[MIN_PRO] - dupedWidths[MIN_PRO] +
totalWidths[DES_CON] - dupedWidths[DES_CON] <= maxWidth) {
AllocateFully(totalAllocated, allocTypes, DES_CON);
//NS_WARN_IF_FALSE(totalAllocated <= maxWidth, "over allocated");
}
@ -361,8 +349,6 @@ nscoord GetColWidth(nsTableColFrame* aColFrame,
return aColFrame->GetWidth(aWidthType);
case PCT:
return aColFrame->GetPctWidth();
case MIN_PRO:
return aColFrame->GetWidth(aWidthType);
default:
NS_ASSERTION(PR_FALSE, "invalid call");
return WIDTH_NOT_SET;
@ -374,7 +360,7 @@ void BasicTableLayoutStrategy::AllocateFully(nscoord& aTotalAllocated,
PRInt32* aAllocTypes,
PRInt32 aWidthType)
{
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
for (PRInt32 colX = 0; colX < numCols; colX++) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
if (!colFrame) continue;
@ -383,6 +369,15 @@ void BasicTableLayoutStrategy::AllocateFully(nscoord& aTotalAllocated,
}
nscoord oldWidth = mTableFrame->GetColumnWidth(colX);
nscoord newWidth = GetColWidth(colFrame, aWidthType);
// proportional and desired widths are handled together
PRBool haveProWidth = PR_FALSE;
if (DES_CON == aWidthType) {
nscoord proWidth = colFrame->GetWidth(MIN_PRO);
if (proWidth >= 0) {
haveProWidth = PR_TRUE;
newWidth = proWidth;
}
}
if (WIDTH_NOT_SET == newWidth) continue;
@ -390,7 +385,7 @@ void BasicTableLayoutStrategy::AllocateFully(nscoord& aTotalAllocated,
mTableFrame->SetColumnWidth(colX, newWidth);
aTotalAllocated += newWidth - oldWidth;
}
aAllocTypes[colX] = aWidthType;
aAllocTypes[colX] = (haveProWidth) ? MIN_PRO : aWidthType;
}
}
@ -407,7 +402,7 @@ void BasicTableLayoutStrategy::AllocateUnconstrained(PRInt32 aAllocAmount,
{
// set up allocTypes to exclude anything but auto cols if possible
PRInt32 colX;
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
for (colX = 0; colX < numCols; colX++) {
if (aExcludePct && (PCT == aAllocTypes[colX])) {
aAllocTypes[colX] = FINISHED;
@ -489,7 +484,7 @@ BasicTableLayoutStrategy::ComputeNonPctColspanWidths(const nsHTMLReflowState& aR
PRBool aConsiderPct,
float aPixelToTwips)
{
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
// zero out prior ADJ values
PRInt32 colX;
@ -571,7 +566,7 @@ void DumpColWidths(nsTableFrame& aTableFrame,
aCellFrame->GetRowIndex(rowIndex);
printf ("%s (row,col)=(%d,%d) width=%s limit=%s count=%d\n", aMessage, rowIndex, aColIndex,
widths[aWidthType], limits[aLimitType], dumpCount++);
for (PRInt32 i = 0; i < aTableFrame.GetEffectiveColCount(); i++) {
for (PRInt32 i = 0; i < aTableFrame.GetColCount(); i++) {
printf(" col %d = ", i);
nsTableColFrame* colFrame = aTableFrame.GetColFrame(i);
for (PRInt32 j = 0; j < NUM_WIDTHS; j++) {
@ -713,6 +708,7 @@ BasicTableLayoutStrategy::ComputeNonPctColspanWidths(PRInt32 aWidthInd
}
if (availWidth > 0) {
nscoord usedWidth = 0;
// get the correct numerator in a similar fashion to getting the divisor
for (spanX = 0; spanX < aColSpan; spanX++) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(aColIndex + spanX);
@ -778,12 +774,9 @@ BasicTableLayoutStrategy::ComputeNonPctColspanWidths(PRInt32 aWidthInd
}
else if (LIMIT_NONE == aLimitType) {
if ((MIN_CON == aWidthIndex) && (0 == minTotal)) {
// put everything in the first col
if (0 == spanX) {
divisor = 1;
numerator = 1;
}
else continue;
// divide evenly among the spanned cols
divisor = aColSpan;
numerator = 1;
}
else {
if (autoDesTotal > 0) { // there were auto cols
@ -807,6 +800,13 @@ BasicTableLayoutStrategy::ComputeNonPctColspanWidths(PRInt32 aWidthInd
? NSToCoordRound( ((float)availWidth) / ((float)aColSpan) )
: NSToCoordRound( (((float)numerator) / ((float)divisor)) * availWidth);
newColAdjWidth = nsTableFrame::RoundToPixel(newColAdjWidth, aPixelToTwips);
// don't let the new allocation exceed the avail total
newColAdjWidth = PR_MIN(newColAdjWidth, availWidth - usedWidth);
// put the remainder of the avail total in the last spanned col
if (spanX == aColSpan - 1) {
newColAdjWidth = availWidth - usedWidth;
}
usedWidth += newColAdjWidth;
// MIN_CON gets added to what is there, the others don't
if (MIN_CON == aWidthIndex) {
newColAdjWidth += colWidth;
@ -845,7 +845,7 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre
if (gsDebugAssign) {printf("AssignNonPctColWidths en max=%d count=%d \n", aMaxWidth, gsDebugCount++); mTableFrame->Dump(aPresContext, PR_FALSE, PR_TRUE, PR_FALSE);}
PRBool rv = PR_FALSE;
PRInt32 numRows = mTableFrame->GetRowCount();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 colX, rowX;
mCellSpacingTotal = 0;
@ -961,6 +961,8 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre
mCellSpacingTotal += spacingX; // add last cell spacing on right
}
ComputeNonPctColspanWidths(aReflowState, PR_FALSE, aPixelToTwips);
// figure the proportional widths for porportional cols
if (rawPropTotal > 0) {
// get the total desired widths
@ -1004,8 +1006,6 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre
}
}
ComputeNonPctColspanWidths(aReflowState, PR_FALSE, aPixelToTwips);
// Set the col's fixed width if present
// Set the table col width for each col to the content min.
for (colX = 0; colX < numCols; colX++) {
@ -1033,7 +1033,7 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre
void
BasicTableLayoutStrategy::ReduceOverSpecifiedPctCols(nscoord aExcess)
{
nscoord numCols = mTableFrame->GetEffectiveColCount();
nscoord numCols = mTableFrame->GetColCount();
for (PRInt32 colX = numCols - 1; (colX >= 0) && (aExcess > 0); colX--) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
if (!colFrame) continue;
@ -1065,7 +1065,7 @@ BasicTableLayoutStrategy::AssignPctColumnWidths(const nsHTMLReflowState aReflowS
{
mTableFrame->SetHasCellSpanningPctCol(PR_FALSE); // this gets refigured below
PRInt32 numRows = mTableFrame->GetRowCount();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 colX, rowX;
@ -1328,7 +1328,7 @@ BasicTableLayoutStrategy::AssignPctColumnWidths(const nsHTMLReflowState aReflowS
colWidth = PR_MAX(colWidth, colFrame->GetDesWidth()); // XXX check this
float avail = (float)PR_MAX(cellPctWidth - colPctWidthTotal, 0);
float colPctAdj = (0 == spanTotal)
? avail / ((float) colSpan)
? avail / ((float) colSpan) / ((float)basis)
: (avail / (float)basis) * (((float)colWidth) / (float)spanTotal);
if (colPctAdj > 0) {
nscoord colPctAdjWidth = colFrame->GetWidth(PCT_ADJ);
@ -1362,7 +1362,7 @@ nscoord BasicTableLayoutStrategy::GetTableMinWidth() const
{
nscoord minWidth = 0;
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
for (PRInt32 colX = 0; colX < numCols; colX++) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
if (!colFrame) continue;
@ -1384,7 +1384,7 @@ nscoord BasicTableLayoutStrategy::GetTableMaxWidth(const nsHTMLReflowState& aRef
if (mTableFrame->IsAutoWidth()) {
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
for (PRInt32 colX = 0; colX < numCols; colX++) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
if (!colFrame) continue;
@ -1435,7 +1435,7 @@ void BasicTableLayoutStrategy::CalculateTotals(PRInt32& aCellSpacing,
a0ProportionalCount = 0;
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
PRInt32 colX;
for (colX = 0; colX < numCols; colX++) {
@ -1621,7 +1621,7 @@ void BasicTableLayoutStrategy::AllocateConstrained(PRInt32 aAvailWidth,
return;
}
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
PRInt32 numConstrainedCols = 0;
nscoord sumMaxConstraints = 0;
nscoord sumMinConstraints = 0;
@ -1652,6 +1652,15 @@ void BasicTableLayoutStrategy::AllocateConstrained(PRInt32 aAvailWidth,
}
nscoord minWidth = mTableFrame->GetColumnWidth(colX);
nscoord maxWidth = GetColWidth(colFrame, aWidthType);
// proportional and desired widths are handled together
PRBool haveProWidth = PR_FALSE;
if (DES_CON == aWidthType) {
nscoord proWidth = colFrame->GetWidth(MIN_PRO);
if (proWidth >= 0) {
haveProWidth = PR_TRUE;
maxWidth = proWidth;
}
}
if (maxWidth <= 0) continue;
@ -1666,7 +1675,7 @@ void BasicTableLayoutStrategy::AllocateConstrained(PRInt32 aAvailWidth,
AC_Wrapup(mTableFrame, numConstrainedCols, colInfo, PR_TRUE);
return;
}
aAllocTypes[colX] = aWidthType;
aAllocTypes[colX] = (haveProWidth) ? MIN_PRO : aWidthType;
constrColX++;
}

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

@ -341,36 +341,6 @@ nsTableCellMap::InsertCells(nsVoidArray& aCellFrames,
}
}
PRInt32
nsTableCellMap::RemoveUnusedCols(PRInt32 aMaxToRemove)
{
PRInt32 numColsRemoved = 0;
for (PRInt32 colX = mCols.Count() - 1; colX >= 0; colX--) {
nsColInfo* colInfo = (nsColInfo *) mCols.ElementAt(colX);
if (!colInfo || (colInfo->mNumCellsOrig > 0) || (colInfo->mNumCellsSpan > 0)) {
return numColsRemoved;
}
else {
// remove the col from the cols array
colInfo = (nsColInfo *) mCols.ElementAt(colX);
mCols.RemoveElementAt(colX);
delete colInfo;
// remove the col entry from each of the maps
nsCellMap* cellMap = mFirstMap;
while (cellMap) {
cellMap->RemoveCol(colX);
cellMap = cellMap->GetNextSibling();
}
numColsRemoved++;
if (numColsRemoved >= aMaxToRemove) {
return numColsRemoved;
}
}
}
return numColsRemoved;
}
void
nsTableCellMap::RemoveCell(nsTableCellFrame* aCellFrame,
@ -821,13 +791,13 @@ PRBool nsCellMap::CellsSpanInOrOut(nsTableCellMap& aMap,
if (aStartRowIndex > 0) {
cellData = GetMapCellAt(aMap, aStartRowIndex, colX, PR_TRUE);
if (cellData && (cellData->IsRowSpan())) {
return PR_TRUE; // a cell row spans into
return PR_TRUE; // there is a row span into the region
}
}
if (aEndRowIndex < mRowCount - 1) {
cellData = GetMapCellAt(aMap, aEndRowIndex + 1, colX, PR_TRUE);
if ((cellData) && (cellData->IsRowSpan())) {
return PR_TRUE; // a cell row spans out
return PR_TRUE; // there is a row span out of the region
}
}
}
@ -835,7 +805,14 @@ PRBool nsCellMap::CellsSpanInOrOut(nsTableCellMap& aMap,
for (PRInt32 rowX = aStartRowIndex; rowX <= aEndRowIndex; rowX++) {
CellData* cellData = GetMapCellAt(aMap, rowX, aStartColIndex, PR_TRUE);
if (cellData && (cellData->IsColSpan())) {
return PR_TRUE;
return PR_TRUE; // there is a col span into the region
}
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(rowX));
if (row) {
cellData = (CellData *)(row->ElementAt(aEndColIndex + 1));
if (cellData && (cellData->IsColSpan())) {
return PR_TRUE; // there is a col span out of the region
}
}
}
}
@ -1040,8 +1017,6 @@ void nsCellMap::ExpandWithCells(nsTableCellMap& aMap,
}
}
}
// remove any unused cols
aMap.RemoveUnusedCols(aMap.GetColCount());
}
void nsCellMap::ShrinkWithoutRows(nsTableCellMap& aMap,
@ -1086,9 +1061,6 @@ void nsCellMap::ShrinkWithoutRows(nsTableCellMap& aMap,
// Decrement our row and next available index counts.
mRowCount--;
// remove cols that may not be needed any more due to the removal of the rows
aMap.RemoveUnusedCols(colCount);
}
}
@ -1259,9 +1231,6 @@ void nsCellMap::ShrinkWithoutCell(nsTableCellMap& aMap,
}
}
}
// remove cols that may not be needed any more due to the removal of the cell
aMap.RemoveUnusedCols(aMap.GetColCount());
}
void
@ -1369,8 +1338,6 @@ nsCellMap::RebuildConsideringRows(nsIPresContext* aPresContext,
delete row;
}
delete [] origRows;
// remove any unused cols
aMap.RemoveUnusedCols(aMap.GetColCount());
}
void nsCellMap::RebuildConsideringCells(nsTableCellMap& aMap,
@ -1463,16 +1430,13 @@ void nsCellMap::RemoveCell(nsTableCellMap& aMap,
PRBool isZeroRowSpan;
PRInt32 rowSpan = GetRowSpan(aMap, aRowIndex, startColIndex, PR_FALSE, isZeroRowSpan);
#if 0 // A bunch of unused stuff assuming no function call side effects
PRInt32 endRowIndex = aRowIndex + rowSpan - 1;
PRBool isZeroColSpan;
PRInt32 endColIndex = startColIndex +
GetEffectiveColSpan(aMap, aRowIndex, startColIndex, isZeroColSpan) - 1;
// record whether removing the cells is going to cause complications due
// to existing row spans, col spans or table sizing.
#endif
PRBool spansCauseRebuild = CellsSpanInOrOut(aMap, aRowIndex, aRowIndex + rowSpan - 1,
startColIndex, numCols - 1);
// XXX if the cell has a col span to the end of the map, and the end has no originating
// cells, we need to assume that this the only such cell, and rebuild so that there are
// no extraneous cols at the end. The same is true for removing rows.
if (spansCauseRebuild) {
RebuildConsideringCells(aMap, nsnull, aRowIndex, startColIndex, PR_FALSE);

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

@ -112,7 +112,6 @@ public:
PRInt32* aColSpan = nsnull);
void AddColsAtEnd(PRUint32 aNumCols);
PRInt32 RemoveUnusedCols(PRInt32 aMaxNumToRemove);
PRBool RowIsSpannedInto(PRInt32 aRowIndex);
PRBool RowHasSpanningCells(PRInt32 aRowIndex);

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

@ -730,11 +730,7 @@ void nsTableFrame::RemoveCol(nsIPresContext& aPresContext,
if (aRemoveFromCellMap) {
nsTableCellMap* cellMap = GetCellMap();
if (cellMap) {
// check to see if the cell map can remove the col
if (cellMap->RemoveUnusedCols(1) < 1) {
// it couldn't be removed so we need a new anonymous col frame
CreateAnonymousColFrames(aPresContext, 1, eColAnonymousCell, PR_TRUE);
}
CreateAnonymousColFrames(aPresContext, 1, eColAnonymousCell, PR_TRUE);
}
}
}

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

@ -909,8 +909,6 @@ NS_METHOD nsTableRowFrame::ResizeReflow(nsIPresContext* aPresContext,
availWidth = CalculateCellAvailableWidth(aReflowState.tableFrame,
kidFrame, cellColIndex,
cellColSpan, cellSpacingX);
if (aReflowState.x + availWidth > aReflowState.reflowState.mComputedWidth)
availWidth -= (aReflowState.x + availWidth - aReflowState.reflowState.mComputedWidth);
}
// remember the rightmost (ltr) or leftmost (rtl) column this cell spans into

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

@ -44,9 +44,8 @@ static PRInt32 gsDebugCount = 0;
// 2) max (PCT, PCT_ADJ)
// 3) FIX
// 4) FIX_ADJ
// 5) PROportional
// 6) max(DES_CON, DES_ADJ)
// 7) for a fixed width table, the column may get more
// 5) max(DES_CON, DES_ADJ), but use MIN_PRO if present
// 6) for a fixed width table, the column may get more
// space if the sum of the col allocations is insufficient
@ -59,7 +58,6 @@ PRBool CanAllocate(PRInt32 aType,
case PCT:
case FIX:
case DES_CON:
case MIN_PRO:
return (WIDTH_NOT_SET == aPrevType);
case FIX_ADJ:
return (WIDTH_NOT_SET == aPrevType) || (FIX == aPrevType);
@ -190,7 +188,7 @@ BasicTableLayoutStrategy::BalanceColumnWidths(nsIPresContext* aPresCont
return PR_FALSE;
}
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
// determine if the table is auto/fixed and get the fixed width if available
nscoord maxWidth = aMaxWidthIn;
@ -301,21 +299,11 @@ BasicTableLayoutStrategy::BalanceColumnWidths(nsIPresContext* aPresCont
return BCW_Wrapup(aPresContext, this, mTableFrame, allocTypes);
}
}
// allocate proportional cols up to their min proportional value
if ((totalAllocated < maxWidth) && (totalCounts[MIN_PRO] > 0)) {
if (totalAllocated + totalWidths[MIN_PRO] - dupedWidths[MIN_PRO] <= maxWidth) {
AllocateFully(totalAllocated, allocTypes, MIN_PRO);
//NS_WARN_IF_FALSE(totalAllocated <= maxWidth, "over allocated");
}
else {
AllocateConstrained(maxWidth - totalAllocated, MIN_PRO, PR_FALSE, allocTypes, p2t);
return BCW_Wrapup(aPresContext, this, mTableFrame, allocTypes);
}
}
// allocate auto cols
if ((totalAllocated < maxWidth) && (totalCounts[DES_CON] > 0)) {
if (totalAllocated + totalWidths[DES_CON] - dupedWidths[DES_CON]<= maxWidth) {
// allocate proportional and auto cols together
if ((totalAllocated < maxWidth) && (totalCounts[MIN_PRO] + totalCounts[DES_CON] > 0)) {
if (totalAllocated + totalWidths[MIN_PRO] - dupedWidths[MIN_PRO] +
totalWidths[DES_CON] - dupedWidths[DES_CON] <= maxWidth) {
AllocateFully(totalAllocated, allocTypes, DES_CON);
//NS_WARN_IF_FALSE(totalAllocated <= maxWidth, "over allocated");
}
@ -361,8 +349,6 @@ nscoord GetColWidth(nsTableColFrame* aColFrame,
return aColFrame->GetWidth(aWidthType);
case PCT:
return aColFrame->GetPctWidth();
case MIN_PRO:
return aColFrame->GetWidth(aWidthType);
default:
NS_ASSERTION(PR_FALSE, "invalid call");
return WIDTH_NOT_SET;
@ -374,7 +360,7 @@ void BasicTableLayoutStrategy::AllocateFully(nscoord& aTotalAllocated,
PRInt32* aAllocTypes,
PRInt32 aWidthType)
{
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
for (PRInt32 colX = 0; colX < numCols; colX++) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
if (!colFrame) continue;
@ -383,6 +369,15 @@ void BasicTableLayoutStrategy::AllocateFully(nscoord& aTotalAllocated,
}
nscoord oldWidth = mTableFrame->GetColumnWidth(colX);
nscoord newWidth = GetColWidth(colFrame, aWidthType);
// proportional and desired widths are handled together
PRBool haveProWidth = PR_FALSE;
if (DES_CON == aWidthType) {
nscoord proWidth = colFrame->GetWidth(MIN_PRO);
if (proWidth >= 0) {
haveProWidth = PR_TRUE;
newWidth = proWidth;
}
}
if (WIDTH_NOT_SET == newWidth) continue;
@ -390,7 +385,7 @@ void BasicTableLayoutStrategy::AllocateFully(nscoord& aTotalAllocated,
mTableFrame->SetColumnWidth(colX, newWidth);
aTotalAllocated += newWidth - oldWidth;
}
aAllocTypes[colX] = aWidthType;
aAllocTypes[colX] = (haveProWidth) ? MIN_PRO : aWidthType;
}
}
@ -407,7 +402,7 @@ void BasicTableLayoutStrategy::AllocateUnconstrained(PRInt32 aAllocAmount,
{
// set up allocTypes to exclude anything but auto cols if possible
PRInt32 colX;
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
for (colX = 0; colX < numCols; colX++) {
if (aExcludePct && (PCT == aAllocTypes[colX])) {
aAllocTypes[colX] = FINISHED;
@ -489,7 +484,7 @@ BasicTableLayoutStrategy::ComputeNonPctColspanWidths(const nsHTMLReflowState& aR
PRBool aConsiderPct,
float aPixelToTwips)
{
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
// zero out prior ADJ values
PRInt32 colX;
@ -571,7 +566,7 @@ void DumpColWidths(nsTableFrame& aTableFrame,
aCellFrame->GetRowIndex(rowIndex);
printf ("%s (row,col)=(%d,%d) width=%s limit=%s count=%d\n", aMessage, rowIndex, aColIndex,
widths[aWidthType], limits[aLimitType], dumpCount++);
for (PRInt32 i = 0; i < aTableFrame.GetEffectiveColCount(); i++) {
for (PRInt32 i = 0; i < aTableFrame.GetColCount(); i++) {
printf(" col %d = ", i);
nsTableColFrame* colFrame = aTableFrame.GetColFrame(i);
for (PRInt32 j = 0; j < NUM_WIDTHS; j++) {
@ -713,6 +708,7 @@ BasicTableLayoutStrategy::ComputeNonPctColspanWidths(PRInt32 aWidthInd
}
if (availWidth > 0) {
nscoord usedWidth = 0;
// get the correct numerator in a similar fashion to getting the divisor
for (spanX = 0; spanX < aColSpan; spanX++) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(aColIndex + spanX);
@ -778,12 +774,9 @@ BasicTableLayoutStrategy::ComputeNonPctColspanWidths(PRInt32 aWidthInd
}
else if (LIMIT_NONE == aLimitType) {
if ((MIN_CON == aWidthIndex) && (0 == minTotal)) {
// put everything in the first col
if (0 == spanX) {
divisor = 1;
numerator = 1;
}
else continue;
// divide evenly among the spanned cols
divisor = aColSpan;
numerator = 1;
}
else {
if (autoDesTotal > 0) { // there were auto cols
@ -807,6 +800,13 @@ BasicTableLayoutStrategy::ComputeNonPctColspanWidths(PRInt32 aWidthInd
? NSToCoordRound( ((float)availWidth) / ((float)aColSpan) )
: NSToCoordRound( (((float)numerator) / ((float)divisor)) * availWidth);
newColAdjWidth = nsTableFrame::RoundToPixel(newColAdjWidth, aPixelToTwips);
// don't let the new allocation exceed the avail total
newColAdjWidth = PR_MIN(newColAdjWidth, availWidth - usedWidth);
// put the remainder of the avail total in the last spanned col
if (spanX == aColSpan - 1) {
newColAdjWidth = availWidth - usedWidth;
}
usedWidth += newColAdjWidth;
// MIN_CON gets added to what is there, the others don't
if (MIN_CON == aWidthIndex) {
newColAdjWidth += colWidth;
@ -845,7 +845,7 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre
if (gsDebugAssign) {printf("AssignNonPctColWidths en max=%d count=%d \n", aMaxWidth, gsDebugCount++); mTableFrame->Dump(aPresContext, PR_FALSE, PR_TRUE, PR_FALSE);}
PRBool rv = PR_FALSE;
PRInt32 numRows = mTableFrame->GetRowCount();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 colX, rowX;
mCellSpacingTotal = 0;
@ -961,6 +961,8 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre
mCellSpacingTotal += spacingX; // add last cell spacing on right
}
ComputeNonPctColspanWidths(aReflowState, PR_FALSE, aPixelToTwips);
// figure the proportional widths for porportional cols
if (rawPropTotal > 0) {
// get the total desired widths
@ -1004,8 +1006,6 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre
}
}
ComputeNonPctColspanWidths(aReflowState, PR_FALSE, aPixelToTwips);
// Set the col's fixed width if present
// Set the table col width for each col to the content min.
for (colX = 0; colX < numCols; colX++) {
@ -1033,7 +1033,7 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre
void
BasicTableLayoutStrategy::ReduceOverSpecifiedPctCols(nscoord aExcess)
{
nscoord numCols = mTableFrame->GetEffectiveColCount();
nscoord numCols = mTableFrame->GetColCount();
for (PRInt32 colX = numCols - 1; (colX >= 0) && (aExcess > 0); colX--) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
if (!colFrame) continue;
@ -1065,7 +1065,7 @@ BasicTableLayoutStrategy::AssignPctColumnWidths(const nsHTMLReflowState aReflowS
{
mTableFrame->SetHasCellSpanningPctCol(PR_FALSE); // this gets refigured below
PRInt32 numRows = mTableFrame->GetRowCount();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 colX, rowX;
@ -1328,7 +1328,7 @@ BasicTableLayoutStrategy::AssignPctColumnWidths(const nsHTMLReflowState aReflowS
colWidth = PR_MAX(colWidth, colFrame->GetDesWidth()); // XXX check this
float avail = (float)PR_MAX(cellPctWidth - colPctWidthTotal, 0);
float colPctAdj = (0 == spanTotal)
? avail / ((float) colSpan)
? avail / ((float) colSpan) / ((float)basis)
: (avail / (float)basis) * (((float)colWidth) / (float)spanTotal);
if (colPctAdj > 0) {
nscoord colPctAdjWidth = colFrame->GetWidth(PCT_ADJ);
@ -1362,7 +1362,7 @@ nscoord BasicTableLayoutStrategy::GetTableMinWidth() const
{
nscoord minWidth = 0;
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
for (PRInt32 colX = 0; colX < numCols; colX++) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
if (!colFrame) continue;
@ -1384,7 +1384,7 @@ nscoord BasicTableLayoutStrategy::GetTableMaxWidth(const nsHTMLReflowState& aRef
if (mTableFrame->IsAutoWidth()) {
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
for (PRInt32 colX = 0; colX < numCols; colX++) {
nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX);
if (!colFrame) continue;
@ -1435,7 +1435,7 @@ void BasicTableLayoutStrategy::CalculateTotals(PRInt32& aCellSpacing,
a0ProportionalCount = 0;
nscoord spacingX = mTableFrame->GetCellSpacingX();
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
PRInt32 colX;
for (colX = 0; colX < numCols; colX++) {
@ -1621,7 +1621,7 @@ void BasicTableLayoutStrategy::AllocateConstrained(PRInt32 aAvailWidth,
return;
}
PRInt32 numCols = mTableFrame->GetEffectiveColCount();
PRInt32 numCols = mTableFrame->GetColCount();
PRInt32 numConstrainedCols = 0;
nscoord sumMaxConstraints = 0;
nscoord sumMinConstraints = 0;
@ -1652,6 +1652,15 @@ void BasicTableLayoutStrategy::AllocateConstrained(PRInt32 aAvailWidth,
}
nscoord minWidth = mTableFrame->GetColumnWidth(colX);
nscoord maxWidth = GetColWidth(colFrame, aWidthType);
// proportional and desired widths are handled together
PRBool haveProWidth = PR_FALSE;
if (DES_CON == aWidthType) {
nscoord proWidth = colFrame->GetWidth(MIN_PRO);
if (proWidth >= 0) {
haveProWidth = PR_TRUE;
maxWidth = proWidth;
}
}
if (maxWidth <= 0) continue;
@ -1666,7 +1675,7 @@ void BasicTableLayoutStrategy::AllocateConstrained(PRInt32 aAvailWidth,
AC_Wrapup(mTableFrame, numConstrainedCols, colInfo, PR_TRUE);
return;
}
aAllocTypes[colX] = aWidthType;
aAllocTypes[colX] = (haveProWidth) ? MIN_PRO : aWidthType;
constrColX++;
}

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

@ -341,36 +341,6 @@ nsTableCellMap::InsertCells(nsVoidArray& aCellFrames,
}
}
PRInt32
nsTableCellMap::RemoveUnusedCols(PRInt32 aMaxToRemove)
{
PRInt32 numColsRemoved = 0;
for (PRInt32 colX = mCols.Count() - 1; colX >= 0; colX--) {
nsColInfo* colInfo = (nsColInfo *) mCols.ElementAt(colX);
if (!colInfo || (colInfo->mNumCellsOrig > 0) || (colInfo->mNumCellsSpan > 0)) {
return numColsRemoved;
}
else {
// remove the col from the cols array
colInfo = (nsColInfo *) mCols.ElementAt(colX);
mCols.RemoveElementAt(colX);
delete colInfo;
// remove the col entry from each of the maps
nsCellMap* cellMap = mFirstMap;
while (cellMap) {
cellMap->RemoveCol(colX);
cellMap = cellMap->GetNextSibling();
}
numColsRemoved++;
if (numColsRemoved >= aMaxToRemove) {
return numColsRemoved;
}
}
}
return numColsRemoved;
}
void
nsTableCellMap::RemoveCell(nsTableCellFrame* aCellFrame,
@ -821,13 +791,13 @@ PRBool nsCellMap::CellsSpanInOrOut(nsTableCellMap& aMap,
if (aStartRowIndex > 0) {
cellData = GetMapCellAt(aMap, aStartRowIndex, colX, PR_TRUE);
if (cellData && (cellData->IsRowSpan())) {
return PR_TRUE; // a cell row spans into
return PR_TRUE; // there is a row span into the region
}
}
if (aEndRowIndex < mRowCount - 1) {
cellData = GetMapCellAt(aMap, aEndRowIndex + 1, colX, PR_TRUE);
if ((cellData) && (cellData->IsRowSpan())) {
return PR_TRUE; // a cell row spans out
return PR_TRUE; // there is a row span out of the region
}
}
}
@ -835,7 +805,14 @@ PRBool nsCellMap::CellsSpanInOrOut(nsTableCellMap& aMap,
for (PRInt32 rowX = aStartRowIndex; rowX <= aEndRowIndex; rowX++) {
CellData* cellData = GetMapCellAt(aMap, rowX, aStartColIndex, PR_TRUE);
if (cellData && (cellData->IsColSpan())) {
return PR_TRUE;
return PR_TRUE; // there is a col span into the region
}
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(rowX));
if (row) {
cellData = (CellData *)(row->ElementAt(aEndColIndex + 1));
if (cellData && (cellData->IsColSpan())) {
return PR_TRUE; // there is a col span out of the region
}
}
}
}
@ -1040,8 +1017,6 @@ void nsCellMap::ExpandWithCells(nsTableCellMap& aMap,
}
}
}
// remove any unused cols
aMap.RemoveUnusedCols(aMap.GetColCount());
}
void nsCellMap::ShrinkWithoutRows(nsTableCellMap& aMap,
@ -1086,9 +1061,6 @@ void nsCellMap::ShrinkWithoutRows(nsTableCellMap& aMap,
// Decrement our row and next available index counts.
mRowCount--;
// remove cols that may not be needed any more due to the removal of the rows
aMap.RemoveUnusedCols(colCount);
}
}
@ -1259,9 +1231,6 @@ void nsCellMap::ShrinkWithoutCell(nsTableCellMap& aMap,
}
}
}
// remove cols that may not be needed any more due to the removal of the cell
aMap.RemoveUnusedCols(aMap.GetColCount());
}
void
@ -1369,8 +1338,6 @@ nsCellMap::RebuildConsideringRows(nsIPresContext* aPresContext,
delete row;
}
delete [] origRows;
// remove any unused cols
aMap.RemoveUnusedCols(aMap.GetColCount());
}
void nsCellMap::RebuildConsideringCells(nsTableCellMap& aMap,
@ -1463,16 +1430,13 @@ void nsCellMap::RemoveCell(nsTableCellMap& aMap,
PRBool isZeroRowSpan;
PRInt32 rowSpan = GetRowSpan(aMap, aRowIndex, startColIndex, PR_FALSE, isZeroRowSpan);
#if 0 // A bunch of unused stuff assuming no function call side effects
PRInt32 endRowIndex = aRowIndex + rowSpan - 1;
PRBool isZeroColSpan;
PRInt32 endColIndex = startColIndex +
GetEffectiveColSpan(aMap, aRowIndex, startColIndex, isZeroColSpan) - 1;
// record whether removing the cells is going to cause complications due
// to existing row spans, col spans or table sizing.
#endif
PRBool spansCauseRebuild = CellsSpanInOrOut(aMap, aRowIndex, aRowIndex + rowSpan - 1,
startColIndex, numCols - 1);
// XXX if the cell has a col span to the end of the map, and the end has no originating
// cells, we need to assume that this the only such cell, and rebuild so that there are
// no extraneous cols at the end. The same is true for removing rows.
if (spansCauseRebuild) {
RebuildConsideringCells(aMap, nsnull, aRowIndex, startColIndex, PR_FALSE);

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

@ -112,7 +112,6 @@ public:
PRInt32* aColSpan = nsnull);
void AddColsAtEnd(PRUint32 aNumCols);
PRInt32 RemoveUnusedCols(PRInt32 aMaxNumToRemove);
PRBool RowIsSpannedInto(PRInt32 aRowIndex);
PRBool RowHasSpanningCells(PRInt32 aRowIndex);

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

@ -730,11 +730,7 @@ void nsTableFrame::RemoveCol(nsIPresContext& aPresContext,
if (aRemoveFromCellMap) {
nsTableCellMap* cellMap = GetCellMap();
if (cellMap) {
// check to see if the cell map can remove the col
if (cellMap->RemoveUnusedCols(1) < 1) {
// it couldn't be removed so we need a new anonymous col frame
CreateAnonymousColFrames(aPresContext, 1, eColAnonymousCell, PR_TRUE);
}
CreateAnonymousColFrames(aPresContext, 1, eColAnonymousCell, PR_TRUE);
}
}
}

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

@ -909,8 +909,6 @@ NS_METHOD nsTableRowFrame::ResizeReflow(nsIPresContext* aPresContext,
availWidth = CalculateCellAvailableWidth(aReflowState.tableFrame,
kidFrame, cellColIndex,
cellColSpan, cellSpacingX);
if (aReflowState.x + availWidth > aReflowState.reflowState.mComputedWidth)
availWidth -= (aReflowState.x + availWidth - aReflowState.reflowState.mComputedWidth);
}
// remember the rightmost (ltr) or leftmost (rtl) column this cell spans into