From 1d02eeaa85db1108a36c72c7dc102b7eb97c4d2c Mon Sep 17 00:00:00 2001 From: "buster%netscape.com" Date: Mon, 2 Nov 1998 18:32:14 +0000 Subject: [PATCH] fixed rowspan/cell height problem where subsequent rowspanning cells can effect previous cell heights. git-svn-id: svn://10.0.0.236/trunk@13889 18797224-902f-48f8-a5cc-f745e15eee43 --- .../layout/html/table/src/nsTableRowFrame.cpp | 21 +- .../html/table/src/nsTableRowGroupFrame.cpp | 188 ++++++++++-------- mozilla/layout/tables/nsTableRowFrame.cpp | 21 +- .../layout/tables/nsTableRowGroupFrame.cpp | 188 ++++++++++-------- 4 files changed, 246 insertions(+), 172 deletions(-) diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.cpp b/mozilla/layout/html/table/src/nsTableRowFrame.cpp index c359e607f0f..709b84c0042 100644 --- a/mozilla/layout/html/table/src/nsTableRowFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowFrame.cpp @@ -176,10 +176,12 @@ NS_METHOD nsTableRowFrame::DidReflow(nsIPresContext& aPresContext, nsDidReflowStatus aStatus) { - if (gsDebug) printf("Row DidReflow: begin\n"); + if (gsDebug) printf("Row %p DidReflow: begin mRect.h=%d, mCellMTM=%d, mCellMBM=%d\n", + this, mRect.height, mCellMaxTopMargin, mCellMaxBottomMargin); if (NS_FRAME_REFLOW_FINISHED == aStatus) { // Resize and re-align the cell frames based on our row height - nscoord cellHeight = mRect.height - mCellMaxTopMargin - mCellMaxBottomMargin; + nscoord cellHeight = mRect.height - mCellMaxTopMargin - mCellMaxBottomMargin; + if (gsDebug) printf("Row DidReflow: cellHeight=%d\n", cellHeight); nsIFrame *cellFrame = mFirstChild; nsTableFrame* tableFrame; nsTableFrame::GetTableFrame(this, tableFrame); @@ -190,17 +192,26 @@ nsTableRowFrame::DidReflow(nsIPresContext& aPresContext, if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay) { PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(mRowIndex, (nsTableCellFrame *)cellFrame); - if (gsDebug) printf("Row DidReflow: cellFrame %p\n", cellFrame); + if (gsDebug) printf("Row DidReflow: cellFrame %p ", cellFrame); if (1==rowSpan) { // resize the cell's height nsSize cellFrameSize; cellFrame->GetSize(cellFrameSize); cellFrame->SizeTo(cellFrameSize.width, cellHeight); - if (gsDebug) printf("Row DidReflow: cellFrame %p given height %d\n", cellFrame, cellHeight); + if (gsDebug) printf("given height %d\n", cellHeight); // realign cell content based on the new height ((nsTableCellFrame *)cellFrame)->VerticallyAlignChild(&aPresContext); } + else + { + if (gsDebug) + { + nsSize cellFrameSize; + cellFrame->GetSize(cellFrameSize); + printf("has rowspan %d and height %d, unchanged.\n", rowSpan, cellFrameSize.height); + } + } } // Get the next cell cellFrame->GetNextSibling(cellFrame); @@ -208,8 +219,8 @@ nsTableRowFrame::DidReflow(nsIPresContext& aPresContext, } // Let our base class do the usual work + if (gsDebug) printf("Row DidReflow: returning superclass DidReflow.\n"); return nsContainerFrame::DidReflow(aPresContext, aStatus); - if (gsDebug) printf("Row DidReflow: end\n"); } void nsTableRowFrame::ResetMaxChildHeight() diff --git a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp index 98df6f76ff1..61f2008ef58 100644 --- a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp @@ -571,6 +571,7 @@ NS_METHOD nsTableRowGroupFrame::PullUpChildren(nsIPresContext& aPresContext void nsTableRowGroupFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize) { + if (gsDebug) printf("TRGF ShrinkWrapChildren begin\n"); // iterate children and for each row get its height PRBool atLeastOneRowSpanningCell = PR_FALSE; nscoord topInnerMargin = 0; @@ -596,6 +597,10 @@ void nsTableRowGroupFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, nscoord maxCellTopMargin = ((nsTableRowFrame*)rowFrame)->GetChildMaxTopMargin(); nscoord maxCellBottomMargin = ((nsTableRowFrame*)rowFrame)->GetChildMaxBottomMargin(); nscoord maxRowHeight = maxCellHeight + maxCellTopMargin + maxCellBottomMargin; + if (gsDebug) printf("TRGF SWC: for row %p, maxCellH=%d, maxCTM=%d, maxCBM=%d\n", + rowFrame, maxCellHeight, maxCellTopMargin, maxCellBottomMargin); + if (gsDebug) printf("TRGF SWC: rowHeight=%d, rowIndex=%d\n", + maxRowHeight, rowIndex); // save the row height for pass 2 below rowHeights[rowIndex] = maxRowHeight; @@ -613,111 +618,132 @@ void nsTableRowGroupFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, rowFrame->GetNextSibling(rowFrame); } - /* Step 2: now account for cells that span rows. - * a spanning cell's height is the sum of the heights of the rows it spans, + /* Step 2: Now account for cells that span rows. + * A spanning cell's height is the sum of the heights of the rows it spans, * or it's own desired height, whichever is greater. * If the cell's desired height is the larger value, resize the rows and contained * cells by an equal percentage of the additional space. + * We go through this loop twice. The first time, we are adjusting cell heights + * and row y-offsets on the fly. + * The second time through the loop, we're ensuring that subsequent row-spanning cells + * didn't change prior calculations. + * Since we are guaranteed to have found the max height spanners the first time through, + * we know we only need two passes, not an arbitrary number. */ /* TODO * 1. optimization, if (PR_TRUE==atLeastOneRowSpanningCell) ... otherwise skip this step entirely - * 2. find cases where spanning cells effect other spanning cells that began in rows above themselves. - * I think in this case, we have to make another pass through step 2. - * There should be a "rational" check to terminate that kind of loop after n passes, probably 3 or 4. */ - PRInt32 rowGroupHeight = 0; - rowFrame = mFirstChild; - rowIndex = 0; - while (nsnull != rowFrame) + PRInt32 rowGroupHeight; + for (PRInt32 counter; counter<2; counter++) { - const nsStyleDisplay *childDisplay; - rowFrame->GetStyleData(eStyleStruct_Display, ((nsStyleStruct *&)childDisplay)); - if (NS_STYLE_DISPLAY_TABLE_ROW == childDisplay->mDisplay) + rowGroupHeight = 0; + rowFrame = mFirstChild; + rowIndex = 0; + while (nsnull != rowFrame) { - // check this row for a cell with rowspans - nsIFrame *cellFrame; - rowFrame->FirstChild(cellFrame); - while (nsnull != cellFrame) + const nsStyleDisplay *childDisplay; + rowFrame->GetStyleData(eStyleStruct_Display, ((nsStyleStruct *&)childDisplay)); + if (NS_STYLE_DISPLAY_TABLE_ROW == childDisplay->mDisplay) { - const nsStyleDisplay *childDisplay; - cellFrame->GetStyleData(eStyleStruct_Display, ((nsStyleStruct *&)childDisplay)); - if (NS_STYLE_DISPLAY_TABLE_CELL == childDisplay->mDisplay) + if (gsDebug) printf("TRGF SWC: for row %p...\n", rowFrame); + // check this row for a cell with rowspans + nsIFrame *cellFrame; + rowFrame->FirstChild(cellFrame); + while (nsnull != cellFrame) { - nsTableFrame *tableFrame=nsnull; - nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame); - if (NS_FAILED(rv) || nsnull==tableFrame) - return; - PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(rowIndex,(nsTableCellFrame*)cellFrame); - if (rowSpan > 1) - { // found a cell with rowspan > 1, determine its height - nscoord heightOfRowsSpanned = 0; - PRInt32 i; - for ( i = 0; i < rowSpan; i++) - heightOfRowsSpanned += rowHeights[rowIndex + i]; + const nsStyleDisplay *childDisplay; + cellFrame->GetStyleData(eStyleStruct_Display, ((nsStyleStruct *&)childDisplay)); + if (NS_STYLE_DISPLAY_TABLE_CELL == childDisplay->mDisplay) + { + if (gsDebug) printf("TRGF SWC: for cell %p...\n", cellFrame); + nsTableFrame *tableFrame=nsnull; + nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame); + if (NS_FAILED(rv) || nsnull==tableFrame) + return; + PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(rowIndex,(nsTableCellFrame*)cellFrame); + if (rowSpan > 1) + { // found a cell with rowspan > 1, determine its height + if (gsDebug) printf("TRGF SWC: cell %p has rowspan=%d\n", cellFrame, rowSpan); + nscoord heightOfRowsSpanned = 0; + PRInt32 i; + for ( i = 0; i < rowSpan; i++) + heightOfRowsSpanned += rowHeights[rowIndex + i]; + if (gsDebug) printf("TRGF SWC: heightOfRowsSpanned=%d\n", heightOfRowsSpanned); - heightOfRowsSpanned -= topInnerMargin + bottomInnerMargin; + heightOfRowsSpanned -= topInnerMargin + bottomInnerMargin; + if (gsDebug) printf("TRGF SWC: after margins, heightOfRowsSpanned=%d\n", heightOfRowsSpanned); - /* if the cell height fits in the rows, expand the spanning cell's height and slap it in */ - nsSize cellFrameSize; - cellFrame->GetSize(cellFrameSize); - if (heightOfRowsSpanned > cellFrameSize.height) - { - cellFrame->SizeTo(cellFrameSize.width, heightOfRowsSpanned); - // Realign cell content based on new height - ((nsTableCellFrame*)cellFrame)->VerticallyAlignChild(aPresContext); - } - /* otherwise, distribute the excess height to the rows effected. - * push all subsequent rows down by the total change in height of all the rows above it - */ - else - { - PRInt32 excessHeight = cellFrameSize.height - heightOfRowsSpanned; - PRInt32 excessHeightPerRow = excessHeight/rowSpan; - - // for every row starting at the row with the spanning cell... - nsTableRowFrame *rowFrameToBeResized = (nsTableRowFrame *)rowFrame; - for (i = rowIndex; i < numRows; i++) + /* if the cell height fits in the rows, expand the spanning cell's height and slap it in */ + nsSize cellFrameSize; + cellFrame->GetSize(cellFrameSize); + if (heightOfRowsSpanned > cellFrameSize.height) { - // if the row is within the spanned range, resize the row - if (i < (rowIndex + rowSpan)) - { - // update the row height - rowHeights[i] += excessHeightPerRow; + if (gsDebug) printf("TRGF SWC: cell had h=%d, set to %d\n", + cellFrameSize.height, heightOfRowsSpanned); + cellFrame->SizeTo(cellFrameSize.width, heightOfRowsSpanned); + // Realign cell content based on new height + ((nsTableCellFrame*)cellFrame)->VerticallyAlignChild(aPresContext); + } + /* otherwise, distribute the excess height to the rows effected. + * push all subsequent rows down by the total change in height of all the rows above it + */ + else + { + PRInt32 excessHeight = cellFrameSize.height - heightOfRowsSpanned; + PRInt32 excessHeightPerRow = excessHeight/rowSpan; + if (gsDebug) printf("TRGF SWC: excessHeight=%d, excessHeightPerRow=%d\n", + excessHeight, excessHeightPerRow); - // adjust the height of the row - nsSize rowFrameSize; - rowFrameToBeResized->GetSize(rowFrameSize); - rowFrameToBeResized->SizeTo(rowFrameSize.width, rowHeights[i]); - } - - // if we're dealing with a row below the row containing the spanning cell, - // push that row down by the amount we've expanded the cell heights by - if ((i >= rowIndex) && (i != 0)) + // for every row starting at the row with the spanning cell... + nsTableRowFrame *rowFrameToBeResized = (nsTableRowFrame *)rowFrame; + for (i = rowIndex; i < numRows; i++) { - nsRect rowRect; + if (gsDebug) printf("TRGF SWC: for row index=%d\n", i); + // if the row is within the spanned range, resize the row + if (i < (rowIndex + rowSpan)) + { + // update the row height + rowHeights[i] += excessHeightPerRow; + + // adjust the height of the row + nsSize rowFrameSize; + rowFrameToBeResized->GetSize(rowFrameSize); + rowFrameToBeResized->SizeTo(rowFrameSize.width, rowHeights[i]); + if (gsDebug) printf("TRGF SWC: row %p sized to %d\n", + rowFrameToBeResized, rowHeights[i]); + } + + // if we're dealing with a row below the row containing the spanning cell, + // push that row down by the amount we've expanded the cell heights by + if ((i >= rowIndex) && (i != 0)) + { + nsRect rowRect; - rowFrameToBeResized->GetRect(rowRect); - nscoord delta = excessHeightPerRow * (i - rowIndex); - if (delta > excessHeight) - delta = excessHeight; - rowFrameToBeResized->MoveTo(rowRect.x, rowRect.y + delta); - } + rowFrameToBeResized->GetRect(rowRect); + nscoord delta = excessHeightPerRow * (i - rowIndex); + if (delta > excessHeight) + delta = excessHeight; + rowFrameToBeResized->MoveTo(rowRect.x, rowRect.y + delta); + if (gsDebug) printf("TRGF SWC: row %p moved to %d after delta %d\n", + rowFrameToBeResized, rowRect.y + delta, delta); + } - // Get the next row frame - rowFrameToBeResized->GetNextSibling((nsIFrame*&)rowFrameToBeResized); + // Get the next row frame + rowFrameToBeResized->GetNextSibling((nsIFrame*&)rowFrameToBeResized); + } } } } + // Get the next row child (cell frame) + cellFrame->GetNextSibling(cellFrame); } - // Get the next row child (cell frame) - cellFrame->GetNextSibling(cellFrame); + // Update the running row group height + rowGroupHeight += rowHeights[rowIndex]; + rowIndex++; } - // Update the running row group height - rowGroupHeight += rowHeights[rowIndex]; - rowIndex++; + // Get the next rowgroup child (row frame) + rowFrame->GetNextSibling(rowFrame); } - // Get the next rowgroup child (row frame) - rowFrame->GetNextSibling(rowFrame); } // Adjust our desired size diff --git a/mozilla/layout/tables/nsTableRowFrame.cpp b/mozilla/layout/tables/nsTableRowFrame.cpp index c359e607f0f..709b84c0042 100644 --- a/mozilla/layout/tables/nsTableRowFrame.cpp +++ b/mozilla/layout/tables/nsTableRowFrame.cpp @@ -176,10 +176,12 @@ NS_METHOD nsTableRowFrame::DidReflow(nsIPresContext& aPresContext, nsDidReflowStatus aStatus) { - if (gsDebug) printf("Row DidReflow: begin\n"); + if (gsDebug) printf("Row %p DidReflow: begin mRect.h=%d, mCellMTM=%d, mCellMBM=%d\n", + this, mRect.height, mCellMaxTopMargin, mCellMaxBottomMargin); if (NS_FRAME_REFLOW_FINISHED == aStatus) { // Resize and re-align the cell frames based on our row height - nscoord cellHeight = mRect.height - mCellMaxTopMargin - mCellMaxBottomMargin; + nscoord cellHeight = mRect.height - mCellMaxTopMargin - mCellMaxBottomMargin; + if (gsDebug) printf("Row DidReflow: cellHeight=%d\n", cellHeight); nsIFrame *cellFrame = mFirstChild; nsTableFrame* tableFrame; nsTableFrame::GetTableFrame(this, tableFrame); @@ -190,17 +192,26 @@ nsTableRowFrame::DidReflow(nsIPresContext& aPresContext, if (NS_STYLE_DISPLAY_TABLE_CELL == kidDisplay->mDisplay) { PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(mRowIndex, (nsTableCellFrame *)cellFrame); - if (gsDebug) printf("Row DidReflow: cellFrame %p\n", cellFrame); + if (gsDebug) printf("Row DidReflow: cellFrame %p ", cellFrame); if (1==rowSpan) { // resize the cell's height nsSize cellFrameSize; cellFrame->GetSize(cellFrameSize); cellFrame->SizeTo(cellFrameSize.width, cellHeight); - if (gsDebug) printf("Row DidReflow: cellFrame %p given height %d\n", cellFrame, cellHeight); + if (gsDebug) printf("given height %d\n", cellHeight); // realign cell content based on the new height ((nsTableCellFrame *)cellFrame)->VerticallyAlignChild(&aPresContext); } + else + { + if (gsDebug) + { + nsSize cellFrameSize; + cellFrame->GetSize(cellFrameSize); + printf("has rowspan %d and height %d, unchanged.\n", rowSpan, cellFrameSize.height); + } + } } // Get the next cell cellFrame->GetNextSibling(cellFrame); @@ -208,8 +219,8 @@ nsTableRowFrame::DidReflow(nsIPresContext& aPresContext, } // Let our base class do the usual work + if (gsDebug) printf("Row DidReflow: returning superclass DidReflow.\n"); return nsContainerFrame::DidReflow(aPresContext, aStatus); - if (gsDebug) printf("Row DidReflow: end\n"); } void nsTableRowFrame::ResetMaxChildHeight() diff --git a/mozilla/layout/tables/nsTableRowGroupFrame.cpp b/mozilla/layout/tables/nsTableRowGroupFrame.cpp index 98df6f76ff1..61f2008ef58 100644 --- a/mozilla/layout/tables/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/tables/nsTableRowGroupFrame.cpp @@ -571,6 +571,7 @@ NS_METHOD nsTableRowGroupFrame::PullUpChildren(nsIPresContext& aPresContext void nsTableRowGroupFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize) { + if (gsDebug) printf("TRGF ShrinkWrapChildren begin\n"); // iterate children and for each row get its height PRBool atLeastOneRowSpanningCell = PR_FALSE; nscoord topInnerMargin = 0; @@ -596,6 +597,10 @@ void nsTableRowGroupFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, nscoord maxCellTopMargin = ((nsTableRowFrame*)rowFrame)->GetChildMaxTopMargin(); nscoord maxCellBottomMargin = ((nsTableRowFrame*)rowFrame)->GetChildMaxBottomMargin(); nscoord maxRowHeight = maxCellHeight + maxCellTopMargin + maxCellBottomMargin; + if (gsDebug) printf("TRGF SWC: for row %p, maxCellH=%d, maxCTM=%d, maxCBM=%d\n", + rowFrame, maxCellHeight, maxCellTopMargin, maxCellBottomMargin); + if (gsDebug) printf("TRGF SWC: rowHeight=%d, rowIndex=%d\n", + maxRowHeight, rowIndex); // save the row height for pass 2 below rowHeights[rowIndex] = maxRowHeight; @@ -613,111 +618,132 @@ void nsTableRowGroupFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, rowFrame->GetNextSibling(rowFrame); } - /* Step 2: now account for cells that span rows. - * a spanning cell's height is the sum of the heights of the rows it spans, + /* Step 2: Now account for cells that span rows. + * A spanning cell's height is the sum of the heights of the rows it spans, * or it's own desired height, whichever is greater. * If the cell's desired height is the larger value, resize the rows and contained * cells by an equal percentage of the additional space. + * We go through this loop twice. The first time, we are adjusting cell heights + * and row y-offsets on the fly. + * The second time through the loop, we're ensuring that subsequent row-spanning cells + * didn't change prior calculations. + * Since we are guaranteed to have found the max height spanners the first time through, + * we know we only need two passes, not an arbitrary number. */ /* TODO * 1. optimization, if (PR_TRUE==atLeastOneRowSpanningCell) ... otherwise skip this step entirely - * 2. find cases where spanning cells effect other spanning cells that began in rows above themselves. - * I think in this case, we have to make another pass through step 2. - * There should be a "rational" check to terminate that kind of loop after n passes, probably 3 or 4. */ - PRInt32 rowGroupHeight = 0; - rowFrame = mFirstChild; - rowIndex = 0; - while (nsnull != rowFrame) + PRInt32 rowGroupHeight; + for (PRInt32 counter; counter<2; counter++) { - const nsStyleDisplay *childDisplay; - rowFrame->GetStyleData(eStyleStruct_Display, ((nsStyleStruct *&)childDisplay)); - if (NS_STYLE_DISPLAY_TABLE_ROW == childDisplay->mDisplay) + rowGroupHeight = 0; + rowFrame = mFirstChild; + rowIndex = 0; + while (nsnull != rowFrame) { - // check this row for a cell with rowspans - nsIFrame *cellFrame; - rowFrame->FirstChild(cellFrame); - while (nsnull != cellFrame) + const nsStyleDisplay *childDisplay; + rowFrame->GetStyleData(eStyleStruct_Display, ((nsStyleStruct *&)childDisplay)); + if (NS_STYLE_DISPLAY_TABLE_ROW == childDisplay->mDisplay) { - const nsStyleDisplay *childDisplay; - cellFrame->GetStyleData(eStyleStruct_Display, ((nsStyleStruct *&)childDisplay)); - if (NS_STYLE_DISPLAY_TABLE_CELL == childDisplay->mDisplay) + if (gsDebug) printf("TRGF SWC: for row %p...\n", rowFrame); + // check this row for a cell with rowspans + nsIFrame *cellFrame; + rowFrame->FirstChild(cellFrame); + while (nsnull != cellFrame) { - nsTableFrame *tableFrame=nsnull; - nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame); - if (NS_FAILED(rv) || nsnull==tableFrame) - return; - PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(rowIndex,(nsTableCellFrame*)cellFrame); - if (rowSpan > 1) - { // found a cell with rowspan > 1, determine its height - nscoord heightOfRowsSpanned = 0; - PRInt32 i; - for ( i = 0; i < rowSpan; i++) - heightOfRowsSpanned += rowHeights[rowIndex + i]; + const nsStyleDisplay *childDisplay; + cellFrame->GetStyleData(eStyleStruct_Display, ((nsStyleStruct *&)childDisplay)); + if (NS_STYLE_DISPLAY_TABLE_CELL == childDisplay->mDisplay) + { + if (gsDebug) printf("TRGF SWC: for cell %p...\n", cellFrame); + nsTableFrame *tableFrame=nsnull; + nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame); + if (NS_FAILED(rv) || nsnull==tableFrame) + return; + PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(rowIndex,(nsTableCellFrame*)cellFrame); + if (rowSpan > 1) + { // found a cell with rowspan > 1, determine its height + if (gsDebug) printf("TRGF SWC: cell %p has rowspan=%d\n", cellFrame, rowSpan); + nscoord heightOfRowsSpanned = 0; + PRInt32 i; + for ( i = 0; i < rowSpan; i++) + heightOfRowsSpanned += rowHeights[rowIndex + i]; + if (gsDebug) printf("TRGF SWC: heightOfRowsSpanned=%d\n", heightOfRowsSpanned); - heightOfRowsSpanned -= topInnerMargin + bottomInnerMargin; + heightOfRowsSpanned -= topInnerMargin + bottomInnerMargin; + if (gsDebug) printf("TRGF SWC: after margins, heightOfRowsSpanned=%d\n", heightOfRowsSpanned); - /* if the cell height fits in the rows, expand the spanning cell's height and slap it in */ - nsSize cellFrameSize; - cellFrame->GetSize(cellFrameSize); - if (heightOfRowsSpanned > cellFrameSize.height) - { - cellFrame->SizeTo(cellFrameSize.width, heightOfRowsSpanned); - // Realign cell content based on new height - ((nsTableCellFrame*)cellFrame)->VerticallyAlignChild(aPresContext); - } - /* otherwise, distribute the excess height to the rows effected. - * push all subsequent rows down by the total change in height of all the rows above it - */ - else - { - PRInt32 excessHeight = cellFrameSize.height - heightOfRowsSpanned; - PRInt32 excessHeightPerRow = excessHeight/rowSpan; - - // for every row starting at the row with the spanning cell... - nsTableRowFrame *rowFrameToBeResized = (nsTableRowFrame *)rowFrame; - for (i = rowIndex; i < numRows; i++) + /* if the cell height fits in the rows, expand the spanning cell's height and slap it in */ + nsSize cellFrameSize; + cellFrame->GetSize(cellFrameSize); + if (heightOfRowsSpanned > cellFrameSize.height) { - // if the row is within the spanned range, resize the row - if (i < (rowIndex + rowSpan)) - { - // update the row height - rowHeights[i] += excessHeightPerRow; + if (gsDebug) printf("TRGF SWC: cell had h=%d, set to %d\n", + cellFrameSize.height, heightOfRowsSpanned); + cellFrame->SizeTo(cellFrameSize.width, heightOfRowsSpanned); + // Realign cell content based on new height + ((nsTableCellFrame*)cellFrame)->VerticallyAlignChild(aPresContext); + } + /* otherwise, distribute the excess height to the rows effected. + * push all subsequent rows down by the total change in height of all the rows above it + */ + else + { + PRInt32 excessHeight = cellFrameSize.height - heightOfRowsSpanned; + PRInt32 excessHeightPerRow = excessHeight/rowSpan; + if (gsDebug) printf("TRGF SWC: excessHeight=%d, excessHeightPerRow=%d\n", + excessHeight, excessHeightPerRow); - // adjust the height of the row - nsSize rowFrameSize; - rowFrameToBeResized->GetSize(rowFrameSize); - rowFrameToBeResized->SizeTo(rowFrameSize.width, rowHeights[i]); - } - - // if we're dealing with a row below the row containing the spanning cell, - // push that row down by the amount we've expanded the cell heights by - if ((i >= rowIndex) && (i != 0)) + // for every row starting at the row with the spanning cell... + nsTableRowFrame *rowFrameToBeResized = (nsTableRowFrame *)rowFrame; + for (i = rowIndex; i < numRows; i++) { - nsRect rowRect; + if (gsDebug) printf("TRGF SWC: for row index=%d\n", i); + // if the row is within the spanned range, resize the row + if (i < (rowIndex + rowSpan)) + { + // update the row height + rowHeights[i] += excessHeightPerRow; + + // adjust the height of the row + nsSize rowFrameSize; + rowFrameToBeResized->GetSize(rowFrameSize); + rowFrameToBeResized->SizeTo(rowFrameSize.width, rowHeights[i]); + if (gsDebug) printf("TRGF SWC: row %p sized to %d\n", + rowFrameToBeResized, rowHeights[i]); + } + + // if we're dealing with a row below the row containing the spanning cell, + // push that row down by the amount we've expanded the cell heights by + if ((i >= rowIndex) && (i != 0)) + { + nsRect rowRect; - rowFrameToBeResized->GetRect(rowRect); - nscoord delta = excessHeightPerRow * (i - rowIndex); - if (delta > excessHeight) - delta = excessHeight; - rowFrameToBeResized->MoveTo(rowRect.x, rowRect.y + delta); - } + rowFrameToBeResized->GetRect(rowRect); + nscoord delta = excessHeightPerRow * (i - rowIndex); + if (delta > excessHeight) + delta = excessHeight; + rowFrameToBeResized->MoveTo(rowRect.x, rowRect.y + delta); + if (gsDebug) printf("TRGF SWC: row %p moved to %d after delta %d\n", + rowFrameToBeResized, rowRect.y + delta, delta); + } - // Get the next row frame - rowFrameToBeResized->GetNextSibling((nsIFrame*&)rowFrameToBeResized); + // Get the next row frame + rowFrameToBeResized->GetNextSibling((nsIFrame*&)rowFrameToBeResized); + } } } } + // Get the next row child (cell frame) + cellFrame->GetNextSibling(cellFrame); } - // Get the next row child (cell frame) - cellFrame->GetNextSibling(cellFrame); + // Update the running row group height + rowGroupHeight += rowHeights[rowIndex]; + rowIndex++; } - // Update the running row group height - rowGroupHeight += rowHeights[rowIndex]; - rowIndex++; + // Get the next rowgroup child (row frame) + rowFrame->GetNextSibling(rowFrame); } - // Get the next rowgroup child (row frame) - rowFrame->GetNextSibling(rowFrame); } // Adjust our desired size