From 2cd93059a020855366c070c043696e1be718db39 Mon Sep 17 00:00:00 2001 From: "buster%netscape.com" Date: Mon, 17 Aug 1998 23:37:04 +0000 Subject: [PATCH] fixed nested tables for the case where both parent and child table are %-width, and the columns are any variety of width types git-svn-id: svn://10.0.0.236/trunk@8109 18797224-902f-48f8-a5cc-f745e15eee43 --- .../table/src/BasicTableLayoutStrategy.cpp | 12 ++- .../layout/html/table/src/nsTableFrame.cpp | 96 ++++++++++++------- .../tables/BasicTableLayoutStrategy.cpp | 12 ++- mozilla/layout/tables/nsTableFrame.cpp | 96 ++++++++++++------- 4 files changed, 138 insertions(+), 78 deletions(-) diff --git a/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp b/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp index fba49dd286e..bfbfb36a841 100644 --- a/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp +++ b/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp @@ -37,6 +37,8 @@ static const PRBool gsDebug = PR_FALSE; static const PRBool gsDebugCLD = PR_FALSE; #endif +const nscoord gBigSpace = 100000; + /* ---------- ProportionalColumnLayoutStruct ---------- */ // TODO: make public so other subclasses can use it @@ -776,7 +778,7 @@ PRBool BasicTableLayoutStrategy::BalanceProportionalColumns(const nsReflowState& if (NS_UNCONSTRAINEDSIZE==aMaxWidth || NS_UNCONSTRAINEDSIZE==mMinTableWidth) { // the max width of the table fits comfortably in the available space if (gsDebug) printf (" * auto table laying out in NS_UNCONSTRAINEDSIZE, calling BalanceColumnsTableFits\n"); - nscoord bigSpace = 100000; + nscoord bigSpace = gBigSpace; bigSpace = PR_MAX(bigSpace, mMaxTableWidth); result = BalanceColumnsTableFits(aReflowState, bigSpace, bigSpace, aTableSpecifiedWidth, aTableIsAutoWidth); @@ -1285,8 +1287,9 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR nscoord otherWidth = (nscoord)((1.0f/remainingPercent)*((float)(widthOfOtherCells))); if (PR_TRUE==gsDebug) printf(" percentWidth=%d otherWidth=%d\n", percentWidth, otherWidth); - newTableWidth = PR_MAX(percentWidth, otherWidth); - newTableWidth = PR_MIN(newTableWidth, aMaxWidth); // since this is an auto-width table, it can't normally be wider than it's parent + newTableWidth = PR_MAX(percentWidth, otherWidth); // the table width is the larger of the two computations + newTableWidth = PR_MIN(newTableWidth, aMaxWidth); // an auto-width table can't normally be wider than it's parent + newTableWidth = PR_MIN(newTableWidth, mMaxTableWidth);// an auto-width table can't normally be wider than it's own computed max width } nscoord excess = newTableWidth-mFixedTableWidth; // the amount of new space that needs to be // accounted for in the non-fixed columns @@ -1450,7 +1453,8 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR // next, if the specified width of the table is greater than the table's computed width, expand the // table's computed width to match the specified width, giving the extra space to proportionately-sized // columns if possible. - if ((PR_FALSE==aTableIsAutoWidth) && (aAvailWidth > (tableWidth-widthOfFixedTableColumns))) + if ((PR_FALSE==aTableIsAutoWidth) && (aAvailWidth > (tableWidth-widthOfFixedTableColumns)) && + (gBigSpace!=aAvailWidth)) { DistributeExcessSpace(aAvailWidth, tableWidth, widthOfFixedTableColumns); } diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index 150ee4d246d..bb3c77be06f 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -466,7 +466,7 @@ PRInt32 nsTableFrame::GetEffectiveColSpan (PRInt32 aColIndex, nsTableCellFrame * { NS_PRECONDITION (nsnull!=aCell, "bad cell arg"); nsCellMap *cellMap = GetCellMap(); - NS_PRECONDITION (nsnull!=cellMap, "bad call, mCellMap not yet allocated."); + NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated."); NS_PRECONDITION (0<=aColIndex && aColIndexGetRowCount()==1) @@ -481,7 +481,7 @@ PRInt32 nsTableFrame::GetEffectiveColSpan (PRInt32 aColIndex, nsTableCellFrame * PRInt32 nsTableFrame::GetEffectiveCOLSAttribute() { nsCellMap *cellMap = GetCellMap(); - NS_PRECONDITION (nsnull!=cellMap, "bad call, mCellMap not yet allocated."); + NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated."); PRInt32 result; nsIFrame *tableFrame = this; // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! XXX @@ -629,13 +629,14 @@ nsCellMap * nsTableFrame::GetCellMap() } void nsTableFrame::EnsureCellMap() -{ +{ // XXX: must be called ONLY on first-in-flow if (mCellMap == nsnull) BuildCellMap(); } void nsTableFrame::BuildCellMap () { + // XXX: must be called only on first-in-flow! if (gsDebug==PR_TRUE) printf("Build Cell Map...\n"); int rowCount = GetRowCount(); @@ -897,12 +898,13 @@ void nsTableFrame::ListColumnLayoutData(FILE* out, PRInt32 aIndent) return; } - if (nsnull!=mCellMap) + nsCellMap *cellMap = GetCellMap(); + if (nsnull!=cellMap) { fprintf(out,"Column Layout Data \n"); PRInt32 numCols = GetColCount(); - PRInt32 numRows = mCellMap->GetRowCount(); + PRInt32 numRows = cellMap->GetRowCount(); for (PRInt32 colIndex = 0; colIndex= 0; ) @@ -910,7 +912,7 @@ void nsTableFrame::ListColumnLayoutData(FILE* out, PRInt32 aIndent) fprintf(out,"Column Data [%d] \n",colIndex); for (PRInt32 rowIndex = 0; rowIndex < numRows; rowIndex++) { - nsTableCellFrame *cellFrame = mCellMap->GetCellFrameAt(rowIndex, colIndex); + nsTableCellFrame *cellFrame = cellMap->GetCellFrameAt(rowIndex, colIndex); PRInt32 rowIndent; for (rowIndent = aIndent+2; --rowIndent >= 0; ) fputs(" ", out); fprintf(out,"Cell Data [%d] \n",rowIndex); @@ -956,11 +958,12 @@ void nsTableFrame::AppendLayoutData(nsVoidArray* aList, nsTableCellFrame* aTable void nsTableFrame::RecalcLayoutData() { - if (nsnull==mCellMap) + nsCellMap *cellMap = GetCellMap(); + if (nsnull==cellMap) return; // no info yet, so nothing useful to do PRInt32 colCount = GetColCount(); - PRInt32 rowCount = mCellMap->GetRowCount(); + PRInt32 rowCount = cellMap->GetRowCount(); PRInt32 row = 0; PRInt32 col = 0; @@ -984,7 +987,7 @@ void nsTableFrame::RecalcLayoutData() for (col = 0; col < colCount; col++) { nsTableCellFrame* cell = nsnull; - CellData* cellData = mCellMap->GetCellAt(row,col); + CellData* cellData = cellMap->GetCellAt(row,col); if (cellData) cell = cellData->mCell; @@ -1007,7 +1010,7 @@ void nsTableFrame::RecalcLayoutData() above = nsnull; else { - cellData = mCellMap->GetCellAt(row-1,col); + cellData = cellMap->GetCellAt(row-1,col); if (nsnull != cellData) above = cellData->mRealCell->mCell; @@ -1022,7 +1025,7 @@ void nsTableFrame::RecalcLayoutData() left = nsnull; else { - cellData = mCellMap->GetCellAt(row,col-1); + cellData = cellMap->GetCellAt(row,col-1); if (cellData != nsnull) left = cellData->mRealCell->mCell; @@ -1053,7 +1056,7 @@ void nsTableFrame::RecalcLayoutData() // Add top edge cells if (c != col) { - cellData = mCellMap->GetCellAt(r1,c); + cellData = cellMap->GetCellAt(r1,c); if ((cellData != nsnull) && (cellData->mCell != above)) { above = cellData->mCell; @@ -1070,7 +1073,7 @@ void nsTableFrame::RecalcLayoutData() if (r2 < rowCount) { // Add bottom edge cells - cellData = mCellMap->GetCellAt(r2,c); + cellData = cellMap->GetCellAt(r2,c); if ((cellData != nsnull) && cellData->mCell != below) { below = cellData->mCell; @@ -1095,7 +1098,7 @@ void nsTableFrame::RecalcLayoutData() { if (r != row) { - cellData = mCellMap->GetCellAt(r,c1); + cellData = cellMap->GetCellAt(r,c1); if ((cellData != nsnull) && (cellData->mCell != left)) { left = cellData->mCell; @@ -1112,7 +1115,7 @@ void nsTableFrame::RecalcLayoutData() if (c2 < colCount) { // Add right edge cells - cellData = mCellMap->GetCellAt(r,c2); + cellData = cellMap->GetCellAt(r,c2); if ((cellData != nsnull) && (cellData->mCell != right)) { right = cellData->mCell; @@ -2470,7 +2473,8 @@ void nsTableFrame::VerticallyAlignChildren(nsIPresContext* aPresContext, void nsTableFrame::AdjustColumnsForCOLSAttribute() { - NS_ASSERTION(nsnull!=mCellMap, "bad cell map"); + nsCellMap *cellMap = GetCellMap(); + NS_ASSERTION(nsnull!=cellMap, "bad cell map"); // any specified-width column turns off COLS attribute nsStyleTable* tableStyle = (nsStyleTable *)mStyleContext->GetMutableStyleData(eStyleStruct_Table); @@ -2482,7 +2486,7 @@ void nsTableFrame::AdjustColumnsForCOLSAttribute() { for (PRInt32 colIndex=0; colIndexGetCellFrameAt(rowIndex, colIndex); + nsTableCellFrame *cellFrame = cellMap->GetCellFrameAt(rowIndex, colIndex); // get the cell style info const nsStylePosition* cellPosition; if (nsnull!=cellFrame) @@ -2560,10 +2564,10 @@ nsTableFrame::SetColumnStyleFromCell(nsIPresContext * aPresContext, NS_METHOD nsTableFrame::GetColumnFrame(PRInt32 aColIndex, nsTableColFrame *&aColFrame) { aColFrame = nsnull; // initialize out parameter - nsTableFrame * firstInFlow = (nsTableFrame *)GetFirstInFlow(); - if (nsnull!=firstInFlow->mCellMap) + nsCellMap *cellMap = GetCellMap(); + if (nsnull!=cellMap) { // hooray, we get to do this the easy way because the info is cached - aColFrame = firstInFlow->mCellMap->GetColumnFrame(aColIndex); + aColFrame = cellMap->GetColumnFrame(aColIndex); NS_ASSERTION(nsnull!=aColFrame, "bad col frame"); } else @@ -3145,6 +3149,7 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) parentWidth = NS_UNCONSTRAINEDSIZE; if (nsnull != ((nsTableFrame*)table)->mColumnWidths) { + parentWidth=0; PRInt32 colIndex = ((nsTableCellFrame *)greatgrandchildFrame)->GetColIndex(); PRInt32 colSpan = ((nsTableFrame*)table)->GetEffectiveColSpan(colIndex, ((nsTableCellFrame *)greatgrandchildFrame)); for (PRInt32 i = 0; imColumnWidths) { + parentWidth=0; PRInt32 colIndex = ((nsTableCellFrame*)greatgrandchildFrame)->GetColIndex(); - parentWidth = ((nsTableFrame*)table)->GetColumnWidth(colIndex); + PRInt32 colSpan = ((nsTableFrame*)table)->GetEffectiveColSpan(colIndex, ((nsTableCellFrame *)greatgrandchildFrame)); + for (PRInt32 i = 0; iGetColumnWidth(i+colIndex); + if (eStyleUnit_Percent == tablePosition->mWidth.GetUnit()) + { + float percent = tablePosition->mWidth.GetPercentValue(); + parentWidth = (nscoord)(percent*((float)parentWidth)); + } } else { nsSize tableSize; table->GetSize(tableSize); parentWidth = tableSize.width; - spacing->CalcBorderPaddingFor(rs->frame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the row group - childFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(childFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the row - grandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(grandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the cell - greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); + if (0!=tableSize.width) + { // the table has been sized, so we can compute the available space for the child + spacing->CalcBorderPaddingFor(rs->frame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the row group + childFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(childFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the row + grandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(grandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the cell + greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + } + else + { + // the table has not yet been sized, so we need to infer the available space + parentWidth = rs->maxSize.width; + if (eStyleUnit_Percent == tablePosition->mWidth.GetUnit()) + { + float percent = tablePosition->mWidth.GetPercentValue(); + parentWidth = (nscoord)(percent*((float)parentWidth)); + } + } } if (PR_TRUE==gsDebugNT) printf("%p: found a table frame %p, returning parentWidth %d \n", diff --git a/mozilla/layout/tables/BasicTableLayoutStrategy.cpp b/mozilla/layout/tables/BasicTableLayoutStrategy.cpp index fba49dd286e..bfbfb36a841 100644 --- a/mozilla/layout/tables/BasicTableLayoutStrategy.cpp +++ b/mozilla/layout/tables/BasicTableLayoutStrategy.cpp @@ -37,6 +37,8 @@ static const PRBool gsDebug = PR_FALSE; static const PRBool gsDebugCLD = PR_FALSE; #endif +const nscoord gBigSpace = 100000; + /* ---------- ProportionalColumnLayoutStruct ---------- */ // TODO: make public so other subclasses can use it @@ -776,7 +778,7 @@ PRBool BasicTableLayoutStrategy::BalanceProportionalColumns(const nsReflowState& if (NS_UNCONSTRAINEDSIZE==aMaxWidth || NS_UNCONSTRAINEDSIZE==mMinTableWidth) { // the max width of the table fits comfortably in the available space if (gsDebug) printf (" * auto table laying out in NS_UNCONSTRAINEDSIZE, calling BalanceColumnsTableFits\n"); - nscoord bigSpace = 100000; + nscoord bigSpace = gBigSpace; bigSpace = PR_MAX(bigSpace, mMaxTableWidth); result = BalanceColumnsTableFits(aReflowState, bigSpace, bigSpace, aTableSpecifiedWidth, aTableIsAutoWidth); @@ -1285,8 +1287,9 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR nscoord otherWidth = (nscoord)((1.0f/remainingPercent)*((float)(widthOfOtherCells))); if (PR_TRUE==gsDebug) printf(" percentWidth=%d otherWidth=%d\n", percentWidth, otherWidth); - newTableWidth = PR_MAX(percentWidth, otherWidth); - newTableWidth = PR_MIN(newTableWidth, aMaxWidth); // since this is an auto-width table, it can't normally be wider than it's parent + newTableWidth = PR_MAX(percentWidth, otherWidth); // the table width is the larger of the two computations + newTableWidth = PR_MIN(newTableWidth, aMaxWidth); // an auto-width table can't normally be wider than it's parent + newTableWidth = PR_MIN(newTableWidth, mMaxTableWidth);// an auto-width table can't normally be wider than it's own computed max width } nscoord excess = newTableWidth-mFixedTableWidth; // the amount of new space that needs to be // accounted for in the non-fixed columns @@ -1450,7 +1453,8 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR // next, if the specified width of the table is greater than the table's computed width, expand the // table's computed width to match the specified width, giving the extra space to proportionately-sized // columns if possible. - if ((PR_FALSE==aTableIsAutoWidth) && (aAvailWidth > (tableWidth-widthOfFixedTableColumns))) + if ((PR_FALSE==aTableIsAutoWidth) && (aAvailWidth > (tableWidth-widthOfFixedTableColumns)) && + (gBigSpace!=aAvailWidth)) { DistributeExcessSpace(aAvailWidth, tableWidth, widthOfFixedTableColumns); } diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index 150ee4d246d..bb3c77be06f 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -466,7 +466,7 @@ PRInt32 nsTableFrame::GetEffectiveColSpan (PRInt32 aColIndex, nsTableCellFrame * { NS_PRECONDITION (nsnull!=aCell, "bad cell arg"); nsCellMap *cellMap = GetCellMap(); - NS_PRECONDITION (nsnull!=cellMap, "bad call, mCellMap not yet allocated."); + NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated."); NS_PRECONDITION (0<=aColIndex && aColIndexGetRowCount()==1) @@ -481,7 +481,7 @@ PRInt32 nsTableFrame::GetEffectiveColSpan (PRInt32 aColIndex, nsTableCellFrame * PRInt32 nsTableFrame::GetEffectiveCOLSAttribute() { nsCellMap *cellMap = GetCellMap(); - NS_PRECONDITION (nsnull!=cellMap, "bad call, mCellMap not yet allocated."); + NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated."); PRInt32 result; nsIFrame *tableFrame = this; // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! XXX @@ -629,13 +629,14 @@ nsCellMap * nsTableFrame::GetCellMap() } void nsTableFrame::EnsureCellMap() -{ +{ // XXX: must be called ONLY on first-in-flow if (mCellMap == nsnull) BuildCellMap(); } void nsTableFrame::BuildCellMap () { + // XXX: must be called only on first-in-flow! if (gsDebug==PR_TRUE) printf("Build Cell Map...\n"); int rowCount = GetRowCount(); @@ -897,12 +898,13 @@ void nsTableFrame::ListColumnLayoutData(FILE* out, PRInt32 aIndent) return; } - if (nsnull!=mCellMap) + nsCellMap *cellMap = GetCellMap(); + if (nsnull!=cellMap) { fprintf(out,"Column Layout Data \n"); PRInt32 numCols = GetColCount(); - PRInt32 numRows = mCellMap->GetRowCount(); + PRInt32 numRows = cellMap->GetRowCount(); for (PRInt32 colIndex = 0; colIndex= 0; ) @@ -910,7 +912,7 @@ void nsTableFrame::ListColumnLayoutData(FILE* out, PRInt32 aIndent) fprintf(out,"Column Data [%d] \n",colIndex); for (PRInt32 rowIndex = 0; rowIndex < numRows; rowIndex++) { - nsTableCellFrame *cellFrame = mCellMap->GetCellFrameAt(rowIndex, colIndex); + nsTableCellFrame *cellFrame = cellMap->GetCellFrameAt(rowIndex, colIndex); PRInt32 rowIndent; for (rowIndent = aIndent+2; --rowIndent >= 0; ) fputs(" ", out); fprintf(out,"Cell Data [%d] \n",rowIndex); @@ -956,11 +958,12 @@ void nsTableFrame::AppendLayoutData(nsVoidArray* aList, nsTableCellFrame* aTable void nsTableFrame::RecalcLayoutData() { - if (nsnull==mCellMap) + nsCellMap *cellMap = GetCellMap(); + if (nsnull==cellMap) return; // no info yet, so nothing useful to do PRInt32 colCount = GetColCount(); - PRInt32 rowCount = mCellMap->GetRowCount(); + PRInt32 rowCount = cellMap->GetRowCount(); PRInt32 row = 0; PRInt32 col = 0; @@ -984,7 +987,7 @@ void nsTableFrame::RecalcLayoutData() for (col = 0; col < colCount; col++) { nsTableCellFrame* cell = nsnull; - CellData* cellData = mCellMap->GetCellAt(row,col); + CellData* cellData = cellMap->GetCellAt(row,col); if (cellData) cell = cellData->mCell; @@ -1007,7 +1010,7 @@ void nsTableFrame::RecalcLayoutData() above = nsnull; else { - cellData = mCellMap->GetCellAt(row-1,col); + cellData = cellMap->GetCellAt(row-1,col); if (nsnull != cellData) above = cellData->mRealCell->mCell; @@ -1022,7 +1025,7 @@ void nsTableFrame::RecalcLayoutData() left = nsnull; else { - cellData = mCellMap->GetCellAt(row,col-1); + cellData = cellMap->GetCellAt(row,col-1); if (cellData != nsnull) left = cellData->mRealCell->mCell; @@ -1053,7 +1056,7 @@ void nsTableFrame::RecalcLayoutData() // Add top edge cells if (c != col) { - cellData = mCellMap->GetCellAt(r1,c); + cellData = cellMap->GetCellAt(r1,c); if ((cellData != nsnull) && (cellData->mCell != above)) { above = cellData->mCell; @@ -1070,7 +1073,7 @@ void nsTableFrame::RecalcLayoutData() if (r2 < rowCount) { // Add bottom edge cells - cellData = mCellMap->GetCellAt(r2,c); + cellData = cellMap->GetCellAt(r2,c); if ((cellData != nsnull) && cellData->mCell != below) { below = cellData->mCell; @@ -1095,7 +1098,7 @@ void nsTableFrame::RecalcLayoutData() { if (r != row) { - cellData = mCellMap->GetCellAt(r,c1); + cellData = cellMap->GetCellAt(r,c1); if ((cellData != nsnull) && (cellData->mCell != left)) { left = cellData->mCell; @@ -1112,7 +1115,7 @@ void nsTableFrame::RecalcLayoutData() if (c2 < colCount) { // Add right edge cells - cellData = mCellMap->GetCellAt(r,c2); + cellData = cellMap->GetCellAt(r,c2); if ((cellData != nsnull) && (cellData->mCell != right)) { right = cellData->mCell; @@ -2470,7 +2473,8 @@ void nsTableFrame::VerticallyAlignChildren(nsIPresContext* aPresContext, void nsTableFrame::AdjustColumnsForCOLSAttribute() { - NS_ASSERTION(nsnull!=mCellMap, "bad cell map"); + nsCellMap *cellMap = GetCellMap(); + NS_ASSERTION(nsnull!=cellMap, "bad cell map"); // any specified-width column turns off COLS attribute nsStyleTable* tableStyle = (nsStyleTable *)mStyleContext->GetMutableStyleData(eStyleStruct_Table); @@ -2482,7 +2486,7 @@ void nsTableFrame::AdjustColumnsForCOLSAttribute() { for (PRInt32 colIndex=0; colIndexGetCellFrameAt(rowIndex, colIndex); + nsTableCellFrame *cellFrame = cellMap->GetCellFrameAt(rowIndex, colIndex); // get the cell style info const nsStylePosition* cellPosition; if (nsnull!=cellFrame) @@ -2560,10 +2564,10 @@ nsTableFrame::SetColumnStyleFromCell(nsIPresContext * aPresContext, NS_METHOD nsTableFrame::GetColumnFrame(PRInt32 aColIndex, nsTableColFrame *&aColFrame) { aColFrame = nsnull; // initialize out parameter - nsTableFrame * firstInFlow = (nsTableFrame *)GetFirstInFlow(); - if (nsnull!=firstInFlow->mCellMap) + nsCellMap *cellMap = GetCellMap(); + if (nsnull!=cellMap) { // hooray, we get to do this the easy way because the info is cached - aColFrame = firstInFlow->mCellMap->GetColumnFrame(aColIndex); + aColFrame = cellMap->GetColumnFrame(aColIndex); NS_ASSERTION(nsnull!=aColFrame, "bad col frame"); } else @@ -3145,6 +3149,7 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) parentWidth = NS_UNCONSTRAINEDSIZE; if (nsnull != ((nsTableFrame*)table)->mColumnWidths) { + parentWidth=0; PRInt32 colIndex = ((nsTableCellFrame *)greatgrandchildFrame)->GetColIndex(); PRInt32 colSpan = ((nsTableFrame*)table)->GetEffectiveColSpan(colIndex, ((nsTableCellFrame *)greatgrandchildFrame)); for (PRInt32 i = 0; imColumnWidths) { + parentWidth=0; PRInt32 colIndex = ((nsTableCellFrame*)greatgrandchildFrame)->GetColIndex(); - parentWidth = ((nsTableFrame*)table)->GetColumnWidth(colIndex); + PRInt32 colSpan = ((nsTableFrame*)table)->GetEffectiveColSpan(colIndex, ((nsTableCellFrame *)greatgrandchildFrame)); + for (PRInt32 i = 0; iGetColumnWidth(i+colIndex); + if (eStyleUnit_Percent == tablePosition->mWidth.GetUnit()) + { + float percent = tablePosition->mWidth.GetPercentValue(); + parentWidth = (nscoord)(percent*((float)parentWidth)); + } } else { nsSize tableSize; table->GetSize(tableSize); parentWidth = tableSize.width; - spacing->CalcBorderPaddingFor(rs->frame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the row group - childFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(childFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the row - grandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(grandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the cell - greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); + if (0!=tableSize.width) + { // the table has been sized, so we can compute the available space for the child + spacing->CalcBorderPaddingFor(rs->frame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the row group + childFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(childFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the row + grandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(grandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the cell + greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + } + else + { + // the table has not yet been sized, so we need to infer the available space + parentWidth = rs->maxSize.width; + if (eStyleUnit_Percent == tablePosition->mWidth.GetUnit()) + { + float percent = tablePosition->mWidth.GetPercentValue(); + parentWidth = (nscoord)(percent*((float)parentWidth)); + } + } } if (PR_TRUE==gsDebugNT) printf("%p: found a table frame %p, returning parentWidth %d \n",