diff --git a/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp b/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp index 7124c615898..fcab28610d1 100644 --- a/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp +++ b/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp @@ -545,10 +545,13 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths() nscoord spanCellMinWidth; if (0!=spanInfo->effectiveMinWidthOfSpannedCols) { - spanCellMinWidth = (spanInfo->cellMinWidth * colFrame->GetEffectiveMinColWidth()) / - (spanInfo->effectiveMinWidthOfSpannedCols); + float percent = ((float)(colFrame->GetEffectiveMinColWidth())) / + ((float)(spanInfo->effectiveMinWidthOfSpannedCols)); + spanCellMinWidth = NSToCoordRound(((float)(spanInfo->cellMinWidth)) * percent); if (gsDebug==PR_TRUE) - printf ("spanCellMinWidth portion = %d \n", spanCellMinWidth); + printf ("spanCellMinWidth portion = %d from percent=%f, cellMW=%d, effMinColW=%d, sum=%d\n", + spanCellMinWidth, percent, spanInfo->cellMinWidth, colFrame->GetEffectiveMinColWidth(), + spanInfo->effectiveMinWidthOfSpannedCols); if (colMinWidth < spanCellMinWidth) colFrame->SetAdjustedMinColWidth(spanCellMinWidth); // set the new min width for the col } @@ -568,10 +571,10 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths() { float percent = ((float)(colFrame->GetEffectiveMaxColWidth())) / ((float)(spanInfo->effectiveMaxWidthOfSpannedCols)); - spanCellMaxWidth = (nscoord)(((float)(spanInfo->cellDesiredWidth)) * percent); + spanCellMaxWidth = NSToCoordRound(((float)(spanInfo->cellDesiredWidth)) * percent); if (gsDebug==PR_TRUE) - printf ("spanCellMaxWidth portion = %d with percent = %f from effMaxColW=%d and sum=%d\n", - spanCellMaxWidth, percent, colFrame->GetEffectiveMaxColWidth(), + printf ("spanCellMaxWidth portion = %d with percent = %f from cellDW = %d, effMaxColW=%d and sum=%d\n", + spanCellMaxWidth, percent, spanInfo->cellDesiredWidth, colFrame->GetEffectiveMaxColWidth(), spanInfo->effectiveMaxWidthOfSpannedCols); if (colMaxWidth < spanCellMaxWidth) { @@ -683,38 +686,52 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths() void BasicTableLayoutStrategy::SetMinAndMaxTableWidths() { + if (gsDebug) printf("SetMinAndMaxTableWidths\n"); PRInt32 colIndex, rowIndex; PRInt32 numRows = mTableFrame->GetRowCount(); nscoord colInset = mTableFrame->GetCellSpacing(); for (rowIndex = 0; rowIndexGetCellAt(rowIndex, colIndex); rowMinWidth += colInset; rowMaxWidth += colInset; if (nsnull==cellFrame) { // there is no cell in this row that corresponds to this column + if (gsDebug) printf(" col %d skipped because there is no cell\n", colIndex); continue; } if (colIndex!=cellFrame->GetColIndex()) { // For cells that span cols, we figured in the cell the first time we saw it + if (gsDebug) printf(" col %d skipped because it has colspan so we've already added it in\n", colIndex); continue; } + nsTableColFrame *colFrame = mTableFrame->GetColFrame(colIndex); nsSize cellMinSize = cellFrame->GetPass1MaxElementSize(); + nscoord cellMinWidth = PR_MAX(cellMinSize.width, colFrame->GetEffectiveMinColWidth()); nsSize cellMaxSize = cellFrame->GetPass1DesiredSize(); - //PRInt32 colSpan = mTableFrame->GetEffectiveColSpan(colIndex, cellFrame); + nscoord cellMaxWidth = PR_MAX(cellMaxSize.width, colFrame->GetEffectiveMaxColWidth()); + PRInt32 colSpan = mTableFrame->GetEffectiveColSpan(colIndex, cellFrame); + nscoord spanningCellMinWidth = (colSpan-1)*colInset; + if (gsDebug) printf(" cellMin=%d, cellMax=%d, spanningCellMin=%d\n", + cellMinWidth, cellMaxWidth, spanningCellMinWidth); + // spanning cells must be at least as wide as the columns they span, including the cell spacing spanned. if (NS_UNCONSTRAINEDSIZE!=rowMinWidth) - rowMinWidth += cellMinSize.width; + rowMinWidth += PR_MAX(cellMinWidth, spanningCellMinWidth); if (NS_UNCONSTRAINEDSIZE!=rowMaxWidth) - rowMaxWidth += cellMaxSize.width; + rowMaxWidth += PR_MAX(cellMaxWidth, spanningCellMinWidth); + if (gsDebug) printf(" rowMinWidth=%d, rowMaxWidth=%d\n", rowMinWidth, rowMaxWidth); } if (gsDebug) printf(" rowMinWidth=%d, rowMaxWidth=%d\n", rowMinWidth, rowMaxWidth); // the largest row widths are the table widths mMinTableWidth = PR_MAX(mMinTableWidth, rowMinWidth); mMaxTableWidth = PR_MAX(mMaxTableWidth, rowMaxWidth); + if (gsDebug) printf(" mMinTableWidth=%d, mMaxTableWidth=%d\n", mMinTableWidth, mMaxTableWidth); } // verify max of min row widths vs. sum of adjusted column min widths. bigger one wins nscoord sumOfAdjustedColMinWidths=colInset; @@ -723,9 +740,15 @@ void BasicTableLayoutStrategy::SetMinAndMaxTableWidths() nsTableColFrame *colFrame; mTableFrame->GetColumnFrame(colIndex, colFrame); sumOfAdjustedColMinWidths += colFrame->GetAdjustedMinColWidth() + colInset; + if (gsDebug) printf(" col %d has amcw=%d, cellspacing=%d, sum=%d\n", + colIndex, colFrame->GetAdjustedMinColWidth(), colInset, sumOfAdjustedColMinWidths); } + if (gsDebug) printf(" sumOfAdjustedColMinWidths=%d\n", sumOfAdjustedColMinWidths); + /* mMinTableWidth = PR_MAX(mMinTableWidth, sumOfAdjustedColMinWidths); - if (gsDebug) printf("minTW=%d, maxTW=%d with DMCW=%d\n", mMinTableWidth, mMaxTableWidth, sumOfAdjustedColMinWidths); + mMaxTableWidth = PR_MAX(mMinTableWidth, mMaxTableWidth); + */ + if (gsDebug) printf("end SetMinAndMaxTW: minTW=%d, maxTW=%d with DMCW=%d\n", mMinTableWidth, mMaxTableWidth, sumOfAdjustedColMinWidths); } // take the fixed space spanned by the columns in aColSpanList @@ -1251,8 +1274,7 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR } tableWidth += mTableFrame->GetColumnWidth(colIndex) + colInset; } - if (1==mNumCols) - tableWidth += colInset; + tableWidth += colInset; /* --- post-process if necessary --- */ @@ -1530,8 +1552,6 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aAvailWidth, // there's at least one auto-width column, so give it (them) the extra space // proportionately distributed extra space, based on the column's desired size nscoord totalEffectiveWidthOfAutoColumns = 0; - if (gsDebug==PR_TRUE) - printf(" aAvailWidth specified as %d, expanding columns by excess = %d\n", aAvailWidth, excess); // 1. first, get the total width of the auto columns PRInt32 i; for (i = 0; iSetColumnWidth(colIndex, colWidth); } + if (PR_TRUE==gsDebug) + printf("lost a few twips due to rounding errors: excess=%d, totalAdded=%d\n", excess, totalAdded); } // otherwise, distribute the space between all the columns // (they must be all fixed and percentage-width columns, or we would have gone into the block above) @@ -1576,6 +1603,7 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aAvailWidth, if (gsDebug==PR_TRUE) printf(" aAvailWidth specified as %d, expanding columns by excess = %d\n", aAvailWidth, excess); + nscoord totalAdded=0; for (PRInt32 colIndex = 0; colIndexSetColumnWidth(colIndex, colWidth); } + if (PR_TRUE==gsDebug) + printf("lost a few twips due to rounding errors: excess=%d, totalAdded=%d\n", excess, totalAdded); } } @@ -1888,12 +1919,12 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsConstrained( const nsReflowState& } else if (1==mNumCols) { // there is only one column, and we know that it's desired width doesn't fit - // so the column should be as wide as the available space allows it to be - if (gsDebug==PR_TRUE) printf (" 4 one-column: col %d set to width = %d\n", colIndex, aAvailWidth); - mTableFrame->SetColumnWidth(colIndex, aAvailWidth); + // so the column should be as wide as the available space allows it to be minus cell spacing + nscoord colWidth = aAvailWidth - (2*colInset); + mTableFrame->SetColumnWidth(colIndex, colWidth); if (gsDebug==PR_TRUE) - printf (" 4 one-col: col %d set to width = %d from available width %d\n", - colIndex, mTableFrame->GetColumnWidth(colIndex), aAvailWidth); + printf (" 4 one-col: col %d set to width = %d from available width %d and cell spacing %d\n", + colIndex, mTableFrame->GetColumnWidth(colIndex), aAvailWidth, colInset); } else if (PR_TRUE==isAutoWidth) { // column's width is determined by its content, done in post-processing @@ -1968,8 +1999,7 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsConstrained( const nsReflowState& } tableWidth += mTableFrame->GetColumnWidth(colIndex) + colInset; } - if (1==mNumCols) - tableWidth += colInset; + tableWidth += colInset; /* --- post-process if necessary --- */ // first, assign autoWidth columns a width if (PR_TRUE==atLeastOneAutoWidthColumn) diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp index 1a0c8725cc7..c39a0fca1d9 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp @@ -297,7 +297,7 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext, availSize.height = 1; nsSize maxKidElementSize; if (gsDebug==PR_TRUE) - printf(" nsTableCellFrame::ResizeReflow calling ReflowChild with availSize=%d,%d\n", + printf(" nsTableCellFrame::Reflow calling ReflowChild with availSize=%d,%d\n", availSize.width, availSize.height); nsReflowMetrics kidSize(pMaxElementSize); kidSize.width=kidSize.height=kidSize.ascent=kidSize.descent=0; @@ -306,7 +306,13 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext, mFirstChild->WillReflow(aPresContext); mFirstChild->MoveTo(leftInset, topInset); aStatus = ReflowChild(mFirstChild, &aPresContext, kidSize, kidReflowState); - +#ifdef NS_DEBUG + if (kidSize.width > availSize.width) + { + printf("WARNING: cell content returned desired width %d given avail width %d\n", + kidSize.width, availSize.width); + } +#endif if (PR_TRUE==gsDebug || PR_TRUE==gsDebugNT) { if (nsnull!=pMaxElementSize) @@ -323,6 +329,9 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext, mLastContentOffset = bodyPseudoFrame->GetLastContentOffset(); // Place the child + //////////////////////////////// HACK ////////////////////////////// + kidSize.width = PR_MIN(kidSize.width, availSize.width); + ///////////////////////////// END HACK ///////////////////////////// mFirstChild->SetRect(nsRect(leftInset, topInset, kidSize.width, kidSize.height)); diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.cpp b/mozilla/layout/html/table/src/nsTableRowFrame.cpp index 02f8165840f..fb24bde0f68 100644 --- a/mozilla/layout/html/table/src/nsTableRowFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowFrame.cpp @@ -413,6 +413,13 @@ nsresult nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext, nsReflowStatus status = ReflowChild(kidFrame, &aPresContext, desiredSize, kidReflowState); if (gsDebug) printf ("%p RR: desired=%d\n", this, desiredSize.width); +#ifdef NS_DEBUG + if (desiredSize.width > availWidth) + { + printf("WARNING: cell returned desired width %d given avail width %d\n", + desiredSize.width, availWidth); + } +#endif NS_ASSERTION(NS_FRAME_IS_COMPLETE(status), "unexpected reflow status"); if (gsDebug) @@ -476,6 +483,8 @@ nsresult nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext, // Get the next child kidFrame->GetNextSibling(kidFrame); + if (nsnull==kidFrame && cellColSpan>1) + aState.x += cellSpacing; } SetMaxChildHeight(aState.maxCellHeight,maxCellTopMargin, maxCellBottomMargin); // remember height of tallest child who doesn't have a row span @@ -488,7 +497,14 @@ nsresult nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext, if (gsDebug) printf("rr -- row %p width = %d from maxSize %d\n", this, aDesiredSize.width, aState.reflowState.maxSize.width); - + + if (aDesiredSize.width > aState.reflowState.maxSize.width) + { + printf ("%p error case, desired width = %d, maxSize=%d\n", + this, aDesiredSize.width, aState.reflowState.maxSize.width); + fflush (stdout); + } + NS_ASSERTION(aDesiredSize.width <= aState.reflowState.maxSize.width, "row calculated to be too wide."); return NS_OK; } @@ -964,13 +980,13 @@ nsTableRowFrame::Reflow(nsIPresContext& aPresContext, if (gsDebug==PR_TRUE) { if (nsnull!=aDesiredSize.maxElementSize) - printf("nsTableRowFrame::RR returning: %s with aDesiredSize=%d,%d, aMES=%d,%d\n", - NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete", + printf("%p: Row::RR returning: %s with aDesiredSize=%d,%d, aMES=%d,%d\n", + this, NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete", aDesiredSize.width, aDesiredSize.height, aDesiredSize.maxElementSize->width, aDesiredSize.maxElementSize->height); else - printf("nsTableRowFrame::RR returning: %s with aDesiredSize=%d,%d, aMES=NSNULL\n", - NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete", + printf("%p: Row::RR returning: %s with aDesiredSize=%d,%d, aMES=NSNULL\n", + this, NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete", aDesiredSize.width, aDesiredSize.height); } diff --git a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp index 36075015e83..1765b56cdf0 100644 --- a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp @@ -257,7 +257,6 @@ PRBool nsTableRowGroupFrame::ReflowMappedChildren( nsIPresContext* aPresCon #endif #endif NS_PRECONDITION(nsnull != mFirstChild, "no children"); -if (gsDebug) printf("\n\nREFLOWMAPPED FOR ROW GROUP FRAME\n"); PRInt32 childCount = 0; nsIFrame* prevKidFrame = nsnull; @@ -269,7 +268,7 @@ if (gsDebug) printf("\n\nREFLOWMAPPED FOR ROW GROUP FRAME\n"); nsSize kidMaxElementSize; nsSize* pKidMaxElementSize = (nsnull != aMaxElementSize) ? &kidMaxElementSize : nsnull; PRBool result = PR_TRUE; - + PRInt32 debugCounter=0; for (nsIFrame* kidFrame = mFirstChild; nsnull != kidFrame; ) { nsSize kidAvailSize(aState.availSize); if (0>=kidAvailSize.height) @@ -307,7 +306,11 @@ if (gsDebug) printf("\n\nREFLOWMAPPED FOR ROW GROUP FRAME\n"); eReflowReason_Resize); kidFrame->WillReflow(*aPresContext); kidFrame->MoveTo(kidMargin.left, aState.y + topMargin); + if (gsDebug) printf("%p RG reflowing child %d (frame=%p) with avail width = %d\n", + this, debugCounter, kidFrame, kidAvailSize.width); status = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState); + if (gsDebug) printf("%p RG child %d (frame=%p) returned desired width = %d\n", + this, debugCounter, kidFrame, desiredSize.width); // Did the child fit? if ((kidFrame != mFirstChild) && @@ -410,7 +413,7 @@ if (gsDebug) printf("\n\nREFLOWMAPPED FOR ROW GROUP FRAME\n"); // Get the next child kidFrame->GetNextSibling(kidFrame); - + debugCounter++; } // Update the child count diff --git a/mozilla/layout/tables/BasicTableLayoutStrategy.cpp b/mozilla/layout/tables/BasicTableLayoutStrategy.cpp index 7124c615898..fcab28610d1 100644 --- a/mozilla/layout/tables/BasicTableLayoutStrategy.cpp +++ b/mozilla/layout/tables/BasicTableLayoutStrategy.cpp @@ -545,10 +545,13 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths() nscoord spanCellMinWidth; if (0!=spanInfo->effectiveMinWidthOfSpannedCols) { - spanCellMinWidth = (spanInfo->cellMinWidth * colFrame->GetEffectiveMinColWidth()) / - (spanInfo->effectiveMinWidthOfSpannedCols); + float percent = ((float)(colFrame->GetEffectiveMinColWidth())) / + ((float)(spanInfo->effectiveMinWidthOfSpannedCols)); + spanCellMinWidth = NSToCoordRound(((float)(spanInfo->cellMinWidth)) * percent); if (gsDebug==PR_TRUE) - printf ("spanCellMinWidth portion = %d \n", spanCellMinWidth); + printf ("spanCellMinWidth portion = %d from percent=%f, cellMW=%d, effMinColW=%d, sum=%d\n", + spanCellMinWidth, percent, spanInfo->cellMinWidth, colFrame->GetEffectiveMinColWidth(), + spanInfo->effectiveMinWidthOfSpannedCols); if (colMinWidth < spanCellMinWidth) colFrame->SetAdjustedMinColWidth(spanCellMinWidth); // set the new min width for the col } @@ -568,10 +571,10 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths() { float percent = ((float)(colFrame->GetEffectiveMaxColWidth())) / ((float)(spanInfo->effectiveMaxWidthOfSpannedCols)); - spanCellMaxWidth = (nscoord)(((float)(spanInfo->cellDesiredWidth)) * percent); + spanCellMaxWidth = NSToCoordRound(((float)(spanInfo->cellDesiredWidth)) * percent); if (gsDebug==PR_TRUE) - printf ("spanCellMaxWidth portion = %d with percent = %f from effMaxColW=%d and sum=%d\n", - spanCellMaxWidth, percent, colFrame->GetEffectiveMaxColWidth(), + printf ("spanCellMaxWidth portion = %d with percent = %f from cellDW = %d, effMaxColW=%d and sum=%d\n", + spanCellMaxWidth, percent, spanInfo->cellDesiredWidth, colFrame->GetEffectiveMaxColWidth(), spanInfo->effectiveMaxWidthOfSpannedCols); if (colMaxWidth < spanCellMaxWidth) { @@ -683,38 +686,52 @@ PRBool BasicTableLayoutStrategy::AssignPreliminaryColumnWidths() void BasicTableLayoutStrategy::SetMinAndMaxTableWidths() { + if (gsDebug) printf("SetMinAndMaxTableWidths\n"); PRInt32 colIndex, rowIndex; PRInt32 numRows = mTableFrame->GetRowCount(); nscoord colInset = mTableFrame->GetCellSpacing(); for (rowIndex = 0; rowIndexGetCellAt(rowIndex, colIndex); rowMinWidth += colInset; rowMaxWidth += colInset; if (nsnull==cellFrame) { // there is no cell in this row that corresponds to this column + if (gsDebug) printf(" col %d skipped because there is no cell\n", colIndex); continue; } if (colIndex!=cellFrame->GetColIndex()) { // For cells that span cols, we figured in the cell the first time we saw it + if (gsDebug) printf(" col %d skipped because it has colspan so we've already added it in\n", colIndex); continue; } + nsTableColFrame *colFrame = mTableFrame->GetColFrame(colIndex); nsSize cellMinSize = cellFrame->GetPass1MaxElementSize(); + nscoord cellMinWidth = PR_MAX(cellMinSize.width, colFrame->GetEffectiveMinColWidth()); nsSize cellMaxSize = cellFrame->GetPass1DesiredSize(); - //PRInt32 colSpan = mTableFrame->GetEffectiveColSpan(colIndex, cellFrame); + nscoord cellMaxWidth = PR_MAX(cellMaxSize.width, colFrame->GetEffectiveMaxColWidth()); + PRInt32 colSpan = mTableFrame->GetEffectiveColSpan(colIndex, cellFrame); + nscoord spanningCellMinWidth = (colSpan-1)*colInset; + if (gsDebug) printf(" cellMin=%d, cellMax=%d, spanningCellMin=%d\n", + cellMinWidth, cellMaxWidth, spanningCellMinWidth); + // spanning cells must be at least as wide as the columns they span, including the cell spacing spanned. if (NS_UNCONSTRAINEDSIZE!=rowMinWidth) - rowMinWidth += cellMinSize.width; + rowMinWidth += PR_MAX(cellMinWidth, spanningCellMinWidth); if (NS_UNCONSTRAINEDSIZE!=rowMaxWidth) - rowMaxWidth += cellMaxSize.width; + rowMaxWidth += PR_MAX(cellMaxWidth, spanningCellMinWidth); + if (gsDebug) printf(" rowMinWidth=%d, rowMaxWidth=%d\n", rowMinWidth, rowMaxWidth); } if (gsDebug) printf(" rowMinWidth=%d, rowMaxWidth=%d\n", rowMinWidth, rowMaxWidth); // the largest row widths are the table widths mMinTableWidth = PR_MAX(mMinTableWidth, rowMinWidth); mMaxTableWidth = PR_MAX(mMaxTableWidth, rowMaxWidth); + if (gsDebug) printf(" mMinTableWidth=%d, mMaxTableWidth=%d\n", mMinTableWidth, mMaxTableWidth); } // verify max of min row widths vs. sum of adjusted column min widths. bigger one wins nscoord sumOfAdjustedColMinWidths=colInset; @@ -723,9 +740,15 @@ void BasicTableLayoutStrategy::SetMinAndMaxTableWidths() nsTableColFrame *colFrame; mTableFrame->GetColumnFrame(colIndex, colFrame); sumOfAdjustedColMinWidths += colFrame->GetAdjustedMinColWidth() + colInset; + if (gsDebug) printf(" col %d has amcw=%d, cellspacing=%d, sum=%d\n", + colIndex, colFrame->GetAdjustedMinColWidth(), colInset, sumOfAdjustedColMinWidths); } + if (gsDebug) printf(" sumOfAdjustedColMinWidths=%d\n", sumOfAdjustedColMinWidths); + /* mMinTableWidth = PR_MAX(mMinTableWidth, sumOfAdjustedColMinWidths); - if (gsDebug) printf("minTW=%d, maxTW=%d with DMCW=%d\n", mMinTableWidth, mMaxTableWidth, sumOfAdjustedColMinWidths); + mMaxTableWidth = PR_MAX(mMinTableWidth, mMaxTableWidth); + */ + if (gsDebug) printf("end SetMinAndMaxTW: minTW=%d, maxTW=%d with DMCW=%d\n", mMinTableWidth, mMaxTableWidth, sumOfAdjustedColMinWidths); } // take the fixed space spanned by the columns in aColSpanList @@ -1251,8 +1274,7 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsTableFits(const nsReflowState& aR } tableWidth += mTableFrame->GetColumnWidth(colIndex) + colInset; } - if (1==mNumCols) - tableWidth += colInset; + tableWidth += colInset; /* --- post-process if necessary --- */ @@ -1530,8 +1552,6 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aAvailWidth, // there's at least one auto-width column, so give it (them) the extra space // proportionately distributed extra space, based on the column's desired size nscoord totalEffectiveWidthOfAutoColumns = 0; - if (gsDebug==PR_TRUE) - printf(" aAvailWidth specified as %d, expanding columns by excess = %d\n", aAvailWidth, excess); // 1. first, get the total width of the auto columns PRInt32 i; for (i = 0; iSetColumnWidth(colIndex, colWidth); } + if (PR_TRUE==gsDebug) + printf("lost a few twips due to rounding errors: excess=%d, totalAdded=%d\n", excess, totalAdded); } // otherwise, distribute the space between all the columns // (they must be all fixed and percentage-width columns, or we would have gone into the block above) @@ -1576,6 +1603,7 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aAvailWidth, if (gsDebug==PR_TRUE) printf(" aAvailWidth specified as %d, expanding columns by excess = %d\n", aAvailWidth, excess); + nscoord totalAdded=0; for (PRInt32 colIndex = 0; colIndexSetColumnWidth(colIndex, colWidth); } + if (PR_TRUE==gsDebug) + printf("lost a few twips due to rounding errors: excess=%d, totalAdded=%d\n", excess, totalAdded); } } @@ -1888,12 +1919,12 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsConstrained( const nsReflowState& } else if (1==mNumCols) { // there is only one column, and we know that it's desired width doesn't fit - // so the column should be as wide as the available space allows it to be - if (gsDebug==PR_TRUE) printf (" 4 one-column: col %d set to width = %d\n", colIndex, aAvailWidth); - mTableFrame->SetColumnWidth(colIndex, aAvailWidth); + // so the column should be as wide as the available space allows it to be minus cell spacing + nscoord colWidth = aAvailWidth - (2*colInset); + mTableFrame->SetColumnWidth(colIndex, colWidth); if (gsDebug==PR_TRUE) - printf (" 4 one-col: col %d set to width = %d from available width %d\n", - colIndex, mTableFrame->GetColumnWidth(colIndex), aAvailWidth); + printf (" 4 one-col: col %d set to width = %d from available width %d and cell spacing %d\n", + colIndex, mTableFrame->GetColumnWidth(colIndex), aAvailWidth, colInset); } else if (PR_TRUE==isAutoWidth) { // column's width is determined by its content, done in post-processing @@ -1968,8 +1999,7 @@ PRBool BasicTableLayoutStrategy::BalanceColumnsConstrained( const nsReflowState& } tableWidth += mTableFrame->GetColumnWidth(colIndex) + colInset; } - if (1==mNumCols) - tableWidth += colInset; + tableWidth += colInset; /* --- post-process if necessary --- */ // first, assign autoWidth columns a width if (PR_TRUE==atLeastOneAutoWidthColumn) diff --git a/mozilla/layout/tables/nsTableCellFrame.cpp b/mozilla/layout/tables/nsTableCellFrame.cpp index 1a0c8725cc7..c39a0fca1d9 100644 --- a/mozilla/layout/tables/nsTableCellFrame.cpp +++ b/mozilla/layout/tables/nsTableCellFrame.cpp @@ -297,7 +297,7 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext, availSize.height = 1; nsSize maxKidElementSize; if (gsDebug==PR_TRUE) - printf(" nsTableCellFrame::ResizeReflow calling ReflowChild with availSize=%d,%d\n", + printf(" nsTableCellFrame::Reflow calling ReflowChild with availSize=%d,%d\n", availSize.width, availSize.height); nsReflowMetrics kidSize(pMaxElementSize); kidSize.width=kidSize.height=kidSize.ascent=kidSize.descent=0; @@ -306,7 +306,13 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext, mFirstChild->WillReflow(aPresContext); mFirstChild->MoveTo(leftInset, topInset); aStatus = ReflowChild(mFirstChild, &aPresContext, kidSize, kidReflowState); - +#ifdef NS_DEBUG + if (kidSize.width > availSize.width) + { + printf("WARNING: cell content returned desired width %d given avail width %d\n", + kidSize.width, availSize.width); + } +#endif if (PR_TRUE==gsDebug || PR_TRUE==gsDebugNT) { if (nsnull!=pMaxElementSize) @@ -323,6 +329,9 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext& aPresContext, mLastContentOffset = bodyPseudoFrame->GetLastContentOffset(); // Place the child + //////////////////////////////// HACK ////////////////////////////// + kidSize.width = PR_MIN(kidSize.width, availSize.width); + ///////////////////////////// END HACK ///////////////////////////// mFirstChild->SetRect(nsRect(leftInset, topInset, kidSize.width, kidSize.height)); diff --git a/mozilla/layout/tables/nsTableRowFrame.cpp b/mozilla/layout/tables/nsTableRowFrame.cpp index 02f8165840f..fb24bde0f68 100644 --- a/mozilla/layout/tables/nsTableRowFrame.cpp +++ b/mozilla/layout/tables/nsTableRowFrame.cpp @@ -413,6 +413,13 @@ nsresult nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext, nsReflowStatus status = ReflowChild(kidFrame, &aPresContext, desiredSize, kidReflowState); if (gsDebug) printf ("%p RR: desired=%d\n", this, desiredSize.width); +#ifdef NS_DEBUG + if (desiredSize.width > availWidth) + { + printf("WARNING: cell returned desired width %d given avail width %d\n", + desiredSize.width, availWidth); + } +#endif NS_ASSERTION(NS_FRAME_IS_COMPLETE(status), "unexpected reflow status"); if (gsDebug) @@ -476,6 +483,8 @@ nsresult nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext, // Get the next child kidFrame->GetNextSibling(kidFrame); + if (nsnull==kidFrame && cellColSpan>1) + aState.x += cellSpacing; } SetMaxChildHeight(aState.maxCellHeight,maxCellTopMargin, maxCellBottomMargin); // remember height of tallest child who doesn't have a row span @@ -488,7 +497,14 @@ nsresult nsTableRowFrame::ResizeReflow(nsIPresContext& aPresContext, if (gsDebug) printf("rr -- row %p width = %d from maxSize %d\n", this, aDesiredSize.width, aState.reflowState.maxSize.width); - + + if (aDesiredSize.width > aState.reflowState.maxSize.width) + { + printf ("%p error case, desired width = %d, maxSize=%d\n", + this, aDesiredSize.width, aState.reflowState.maxSize.width); + fflush (stdout); + } + NS_ASSERTION(aDesiredSize.width <= aState.reflowState.maxSize.width, "row calculated to be too wide."); return NS_OK; } @@ -964,13 +980,13 @@ nsTableRowFrame::Reflow(nsIPresContext& aPresContext, if (gsDebug==PR_TRUE) { if (nsnull!=aDesiredSize.maxElementSize) - printf("nsTableRowFrame::RR returning: %s with aDesiredSize=%d,%d, aMES=%d,%d\n", - NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete", + printf("%p: Row::RR returning: %s with aDesiredSize=%d,%d, aMES=%d,%d\n", + this, NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete", aDesiredSize.width, aDesiredSize.height, aDesiredSize.maxElementSize->width, aDesiredSize.maxElementSize->height); else - printf("nsTableRowFrame::RR returning: %s with aDesiredSize=%d,%d, aMES=NSNULL\n", - NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete", + printf("%p: Row::RR returning: %s with aDesiredSize=%d,%d, aMES=NSNULL\n", + this, NS_FRAME_IS_COMPLETE(aStatus)?"Complete":"Not Complete", aDesiredSize.width, aDesiredSize.height); } diff --git a/mozilla/layout/tables/nsTableRowGroupFrame.cpp b/mozilla/layout/tables/nsTableRowGroupFrame.cpp index 36075015e83..1765b56cdf0 100644 --- a/mozilla/layout/tables/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/tables/nsTableRowGroupFrame.cpp @@ -257,7 +257,6 @@ PRBool nsTableRowGroupFrame::ReflowMappedChildren( nsIPresContext* aPresCon #endif #endif NS_PRECONDITION(nsnull != mFirstChild, "no children"); -if (gsDebug) printf("\n\nREFLOWMAPPED FOR ROW GROUP FRAME\n"); PRInt32 childCount = 0; nsIFrame* prevKidFrame = nsnull; @@ -269,7 +268,7 @@ if (gsDebug) printf("\n\nREFLOWMAPPED FOR ROW GROUP FRAME\n"); nsSize kidMaxElementSize; nsSize* pKidMaxElementSize = (nsnull != aMaxElementSize) ? &kidMaxElementSize : nsnull; PRBool result = PR_TRUE; - + PRInt32 debugCounter=0; for (nsIFrame* kidFrame = mFirstChild; nsnull != kidFrame; ) { nsSize kidAvailSize(aState.availSize); if (0>=kidAvailSize.height) @@ -307,7 +306,11 @@ if (gsDebug) printf("\n\nREFLOWMAPPED FOR ROW GROUP FRAME\n"); eReflowReason_Resize); kidFrame->WillReflow(*aPresContext); kidFrame->MoveTo(kidMargin.left, aState.y + topMargin); + if (gsDebug) printf("%p RG reflowing child %d (frame=%p) with avail width = %d\n", + this, debugCounter, kidFrame, kidAvailSize.width); status = ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState); + if (gsDebug) printf("%p RG child %d (frame=%p) returned desired width = %d\n", + this, debugCounter, kidFrame, desiredSize.width); // Did the child fit? if ((kidFrame != mFirstChild) && @@ -410,7 +413,7 @@ if (gsDebug) printf("\n\nREFLOWMAPPED FOR ROW GROUP FRAME\n"); // Get the next child kidFrame->GetNextSibling(kidFrame); - + debugCounter++; } // Update the child count