diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index 0eb71e9a81a..292b5a44c53 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -1632,6 +1632,50 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext* aPresContext, aDesiredSize.maxElementSize = pass1MaxElementSize; } + // See if we are supposed to compute our maximum width + if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + PRBool isAutoWidth = RequiresPass1Layout() && + (eStyleUnit_Auto == aReflowState.mStylePosition->mWidth.GetUnit()); + + // See if the pass1 maximum width is no longer valid because one of the + // cell maximum widths changed + if (isAutoWidth && !IsMaximumWidthValid()) { + // Initialize the strategy and have it compute the natural size of + // the table + mTableLayoutStrategy->Initialize(nsnull, NS_UNCONSTRAINEDSIZE); + + // Now the maximum width is valid + mBits.mMaximumWidthValid = PR_TRUE; + + // Initializing the table layout strategy assigns preliminary column + // widths. We can't leave the column widths this way, and so we need to + // balance the column widths to get them back to what we had previously. + // XXX It would be nice to have a cleaner way to calculate the updated + // maximum width + BalanceColumnWidths(aPresContext, aReflowState, + nsSize(aReflowState.availableWidth, aReflowState.availableHeight), + aDesiredSize.maxElementSize); + } + + if (isAutoWidth) { + // Ask the strategy for the natural width of the content area + aDesiredSize.mMaximumWidth = mTableLayoutStrategy->GetTableMaxContentWidth(); + + // Add in space for border + nsMargin border; + GetTableBorder (border); // this gets the max border value at every edge + aDesiredSize.mMaximumWidth += border.left + border.right; + + // Add in space for padding + aDesiredSize.mMaximumWidth += aReflowState.mComputedPadding.left + + aReflowState.mComputedPadding.right; + + } else { + // We're not auto width so the natural width is the same as the desired width + aDesiredSize.mMaximumWidth = aDesiredSize.width; + } + } + if (nsDebugTable::gRflTable) nsTableFrame::DebugReflow("T::Rfl ex", this, nsnull, &aDesiredSize, aStatus); return rv; } @@ -3582,6 +3626,20 @@ void nsTableFrame::InvalidateFirstPassCache() firstInFlow->mBits.mFirstPassValid=PR_FALSE; } +PRBool nsTableFrame::IsMaximumWidthValid() const +{ + nsTableFrame * firstInFlow = (nsTableFrame *)GetFirstInFlow(); + NS_ASSERTION(nsnull!=firstInFlow, "illegal state -- no first in flow"); + return (PRBool)firstInFlow->mBits.mMaximumWidthValid; +} + +void nsTableFrame::InvalidateMaximumWidth() +{ + nsTableFrame * firstInFlow = (nsTableFrame *)GetFirstInFlow(); + NS_ASSERTION(nsnull!=firstInFlow, "illegal state -- no first in flow"); + firstInFlow->mBits.mMaximumWidthValid=PR_FALSE; +} + PRInt32 nsTableFrame::GetColumnWidth(PRInt32 aColIndex) { nsTableFrame * firstInFlow = (nsTableFrame *)GetFirstInFlow(); diff --git a/mozilla/layout/html/table/src/nsTableFrame.h b/mozilla/layout/html/table/src/nsTableFrame.h index f8ece30602e..7673a10cf80 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.h +++ b/mozilla/layout/html/table/src/nsTableFrame.h @@ -629,6 +629,9 @@ protected: /** returns PR_TRUE if the cached column info is still valid */ virtual PRBool IsColumnWidthsValid() const; + + /** returns PR_TRUE if the cached pass1 maximum width is still valid */ + virtual PRBool IsMaximumWidthValid() const; nsIFrame* GetFirstBodyRowGroupFrame(); PRBool MoveOverflowToChildList(nsIPresContext* aPresContext); @@ -684,6 +687,8 @@ public: virtual void InvalidateColumnWidths(); + virtual void InvalidateMaximumWidth(); + protected: /** Support methods for DidSetStyleContext */ @@ -829,6 +834,7 @@ protected: unsigned mFirstPassValid:1; // PR_TRUE if first pass data is still legit, PR_FALSE if it needs to be recalculated unsigned mIsInvariantWidth:1; // PR_TRUE if table width cannot change unsigned mNonPercentSpansPercent:1; + unsigned mMaximumWidthValid:1; int : 26; // unused } mBits; diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp index 54495fd7aeb..f1bf5b711d5 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp @@ -351,6 +351,12 @@ nsresult nsTableOuterFrame::IR_TargetIsChild(nsIPresContext* aPresContext } else if (aNextFrame==mCaptionFrame) { rv = IR_TargetIsCaptionFrame(aPresContext, aDesiredSize, aReflowState, aStatus); + + // If we're supposed to update our maximum width, then just use the inner + // table's maximum width + if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + aDesiredSize.mMaximumWidth = mInnerTableMaximumWidth; + } } else { const nsStyleDisplay* nextDisplay; @@ -595,9 +601,21 @@ nsresult nsTableOuterFrame::IR_InnerTableReflow(nsIPresContext* aPresCont // day we'll be able to make tables behave too. FixBadReflowState(aReflowState.reflowState, innerReflowState); + // If we're supposed to update our maximum width, then ask the child to + // as well + if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + innerSize.mFlags |= NS_REFLOW_CALC_MAX_WIDTH; + } rv = ReflowChild(mInnerTableFrame, aPresContext, innerSize, innerReflowState, 0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus); mInnerTableFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED); + if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + aDesiredSize.mMaximumWidth = innerSize.mMaximumWidth; + + // Update the cached value + mInnerTableMaximumWidth = innerSize.mMaximumWidth; + } + // if there is a caption and the width or height of the inner table changed from a successful reflow, // then reflow or move the caption as needed if ((nsnull != mCaptionFrame) && (PR_TRUE==NS_SUCCEEDED(rv))) { @@ -866,6 +884,11 @@ NS_METHOD nsTableOuterFrame::Reflow(nsIPresContext* aPresContext, rv = ReflowChild(mInnerTableFrame, aPresContext, innerSize, innerReflowState, 0, 0, 0, aStatus); + if (NS_UNCONSTRAINEDSIZE == innerReflowState.availableWidth) { + // Remember the inner table's maximum width + mInnerTableMaximumWidth = innerSize.width; + } + // Table's max element size is the MAX of the caption's max element size // and the inner table's max element size... if (nsnull != aDesiredSize.maxElementSize) { diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.h b/mozilla/layout/html/table/src/nsTableOuterFrame.h index 9bbc917b5f6..48e7aa669aa 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.h +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.h @@ -240,10 +240,10 @@ private: nsIFrame *mCaptionFrame; /** used to track caption max element size */ - PRInt32 mMinCaptionWidth; - - nsSize mMaxElementSize; + PRInt32 mMinCaptionWidth; + nsSize mMaxElementSize; + nscoord mInnerTableMaximumWidth; }; inline nscoord nsTableOuterFrame::GetMinCaptionWidth() diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.cpp b/mozilla/layout/html/table/src/nsTableRowFrame.cpp index 89b30cbab3a..0761797e932 100644 --- a/mozilla/layout/html/table/src/nsTableRowFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowFrame.cpp @@ -1236,7 +1236,11 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext* aPresContext, // Pass along the reflow command nsSize kidMaxElementSize; - nsHTMLReflowMetrics desiredSize(&kidMaxElementSize, NS_REFLOW_CALC_MAX_WIDTH); + // Unless this is a fixed-layout table, then have the cell incrementally + // update its maximum width + nsHTMLReflowMetrics desiredSize(&kidMaxElementSize, + aReflowState.tableFrame->RequiresPass1Layout() ? + NS_REFLOW_CALC_MAX_WIDTH : 0); nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState, aNextFrame, kidAvailSize); @@ -1260,75 +1264,28 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext* aPresContext, desiredSize.height = kidMaxElementSize.height; #endif - // Update the cell layout data. + // Update the cell layout data.. If the cell's maximum width changed, + // then inform the table that its maximum width needs to be recomputed ((nsTableCellFrame *)aNextFrame)->SetPass1MaxElementSize(kidMaxElementSize); - // XXX TROY Not ready to be turned on yet... -#if 0 - ((nsTableCellFrame *)aNextFrame)->SetMaximumWidth(desiredSize.mMaximumWidth); -#endif - -#if 1 - // Now see if we need to do the regular pass 1 reflow and gather the preferred - // width. If the new minimum width is different from the old minimum width, - // then we should consider the max element size - if (aReflowState.tableFrame->ColumnsCanBeInvalidatedBy(*(nsTableCellFrame*)aNextFrame, - oldMinSize.width != kidMaxElementSize.width)) { - // For fixed-layout tables we don't need to know the preferred width - if (aReflowState.tableFrame->RequiresPass1Layout()) { -#ifdef DEBUG_troy - // Changes to the cell frame could require the columns to be rebalanced. - // XXX We don't really need to compute the max element size again, we just - // computed it above. However, for the time being do compute it again and - // make sure it's consistent... - nscoord prevMaxElementWidth = kidMaxElementSize.width; -#endif - - // Do the unconstrained reflow and get the pass1 information - // XXX Why the reflow reason of eReflowReason_Initial? - kidReflowState.reason = eReflowReason_Initial; - kidReflowState.reflowCommand = nsnull; - kidReflowState.availableWidth = NS_UNCONSTRAINEDSIZE; - rv = ReflowChild(aNextFrame, aPresContext, desiredSize, kidReflowState, - aReflowState.x, GetChildMaxTopMargin(), 0, aStatus); - - //XXX: this is a hack, shouldn't it be the case that a min size is - // never larger than a desired size? - if (kidMaxElementSize.width>desiredSize.width) - desiredSize.width = kidMaxElementSize.width; - if (kidMaxElementSize.height>desiredSize.height) - desiredSize.height = kidMaxElementSize.height; - -#ifdef DEBUG_troy - // XXX See above - NS_ASSERTION(prevMaxElementWidth == kidMaxElementSize.width, - "different max element width!"); -#else - ((nsTableCellFrame *)aNextFrame)->SetPass1MaxElementSize(kidMaxElementSize); -#endif - - // Update the cell layout data. - ((nsTableCellFrame *)aNextFrame)->SetMaximumWidth(desiredSize.width); + if (desiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + // If the cell is not auto-width, then the natural width is the + // desired width + PRBool isAutoWidth = eStyleUnit_Auto == kidReflowState.mStylePosition->mWidth.GetUnit(); + + if (!isAutoWidth) { + // Reset the natural width to be the desired width + // XXX This isn't the best thing to do, but if we don't then the table + // layout strategy will compute a different maximum content width than we + // computed for the initial reflow. That's because the table layout + // strategy doesn't check whether the cell is auto-width... + desiredSize.mMaximumWidth = desiredSize.width; } - - // Now that we know the minimum and preferred widths see if the column - // widths need to be rebalanced - if (aReflowState.tableFrame->ColumnsAreValidFor(*(nsTableCellFrame*)aNextFrame, - oldMinSize.width, - oldMaximumWidth)) { - // The column widths don't need to be rebalanced. Now reflow the cell - // again this time constraining the width back to the column width again - kidReflowState.reason = eReflowReason_Resize; - kidReflowState.availableWidth = cellAvailWidth; - rv = ReflowChild(aNextFrame, aPresContext, desiredSize, kidReflowState, - aReflowState.x, GetChildMaxTopMargin(), 0, aStatus); - - } else { - // The column widths need to be rebalanced, so don't waste time reflowing - // the cell again. Tell the table to rebalance the column widths - aReflowState.tableFrame->InvalidateColumnWidths(); + ((nsTableCellFrame *)aNextFrame)->SetMaximumWidth(desiredSize.mMaximumWidth); + if (oldMaximumWidth != desiredSize.mMaximumWidth) { + aReflowState.tableFrame->InvalidateMaximumWidth(); } } -#else + // Now that we know the minimum and preferred widths see if the column // widths need to be rebalanced if (!aReflowState.tableFrame->ColumnsAreValidFor(*(nsTableCellFrame*)aNextFrame, @@ -1338,7 +1295,6 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext* aPresContext, // the column widths aReflowState.tableFrame->InvalidateColumnWidths(); } -#endif // Calculate the cell's actual size given its pass2 size. This function // takes into account the specified height (in the style), and any special diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index 0eb71e9a81a..292b5a44c53 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -1632,6 +1632,50 @@ NS_METHOD nsTableFrame::Reflow(nsIPresContext* aPresContext, aDesiredSize.maxElementSize = pass1MaxElementSize; } + // See if we are supposed to compute our maximum width + if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + PRBool isAutoWidth = RequiresPass1Layout() && + (eStyleUnit_Auto == aReflowState.mStylePosition->mWidth.GetUnit()); + + // See if the pass1 maximum width is no longer valid because one of the + // cell maximum widths changed + if (isAutoWidth && !IsMaximumWidthValid()) { + // Initialize the strategy and have it compute the natural size of + // the table + mTableLayoutStrategy->Initialize(nsnull, NS_UNCONSTRAINEDSIZE); + + // Now the maximum width is valid + mBits.mMaximumWidthValid = PR_TRUE; + + // Initializing the table layout strategy assigns preliminary column + // widths. We can't leave the column widths this way, and so we need to + // balance the column widths to get them back to what we had previously. + // XXX It would be nice to have a cleaner way to calculate the updated + // maximum width + BalanceColumnWidths(aPresContext, aReflowState, + nsSize(aReflowState.availableWidth, aReflowState.availableHeight), + aDesiredSize.maxElementSize); + } + + if (isAutoWidth) { + // Ask the strategy for the natural width of the content area + aDesiredSize.mMaximumWidth = mTableLayoutStrategy->GetTableMaxContentWidth(); + + // Add in space for border + nsMargin border; + GetTableBorder (border); // this gets the max border value at every edge + aDesiredSize.mMaximumWidth += border.left + border.right; + + // Add in space for padding + aDesiredSize.mMaximumWidth += aReflowState.mComputedPadding.left + + aReflowState.mComputedPadding.right; + + } else { + // We're not auto width so the natural width is the same as the desired width + aDesiredSize.mMaximumWidth = aDesiredSize.width; + } + } + if (nsDebugTable::gRflTable) nsTableFrame::DebugReflow("T::Rfl ex", this, nsnull, &aDesiredSize, aStatus); return rv; } @@ -3582,6 +3626,20 @@ void nsTableFrame::InvalidateFirstPassCache() firstInFlow->mBits.mFirstPassValid=PR_FALSE; } +PRBool nsTableFrame::IsMaximumWidthValid() const +{ + nsTableFrame * firstInFlow = (nsTableFrame *)GetFirstInFlow(); + NS_ASSERTION(nsnull!=firstInFlow, "illegal state -- no first in flow"); + return (PRBool)firstInFlow->mBits.mMaximumWidthValid; +} + +void nsTableFrame::InvalidateMaximumWidth() +{ + nsTableFrame * firstInFlow = (nsTableFrame *)GetFirstInFlow(); + NS_ASSERTION(nsnull!=firstInFlow, "illegal state -- no first in flow"); + firstInFlow->mBits.mMaximumWidthValid=PR_FALSE; +} + PRInt32 nsTableFrame::GetColumnWidth(PRInt32 aColIndex) { nsTableFrame * firstInFlow = (nsTableFrame *)GetFirstInFlow(); diff --git a/mozilla/layout/tables/nsTableFrame.h b/mozilla/layout/tables/nsTableFrame.h index f8ece30602e..7673a10cf80 100644 --- a/mozilla/layout/tables/nsTableFrame.h +++ b/mozilla/layout/tables/nsTableFrame.h @@ -629,6 +629,9 @@ protected: /** returns PR_TRUE if the cached column info is still valid */ virtual PRBool IsColumnWidthsValid() const; + + /** returns PR_TRUE if the cached pass1 maximum width is still valid */ + virtual PRBool IsMaximumWidthValid() const; nsIFrame* GetFirstBodyRowGroupFrame(); PRBool MoveOverflowToChildList(nsIPresContext* aPresContext); @@ -684,6 +687,8 @@ public: virtual void InvalidateColumnWidths(); + virtual void InvalidateMaximumWidth(); + protected: /** Support methods for DidSetStyleContext */ @@ -829,6 +834,7 @@ protected: unsigned mFirstPassValid:1; // PR_TRUE if first pass data is still legit, PR_FALSE if it needs to be recalculated unsigned mIsInvariantWidth:1; // PR_TRUE if table width cannot change unsigned mNonPercentSpansPercent:1; + unsigned mMaximumWidthValid:1; int : 26; // unused } mBits; diff --git a/mozilla/layout/tables/nsTableOuterFrame.cpp b/mozilla/layout/tables/nsTableOuterFrame.cpp index 54495fd7aeb..f1bf5b711d5 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.cpp +++ b/mozilla/layout/tables/nsTableOuterFrame.cpp @@ -351,6 +351,12 @@ nsresult nsTableOuterFrame::IR_TargetIsChild(nsIPresContext* aPresContext } else if (aNextFrame==mCaptionFrame) { rv = IR_TargetIsCaptionFrame(aPresContext, aDesiredSize, aReflowState, aStatus); + + // If we're supposed to update our maximum width, then just use the inner + // table's maximum width + if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + aDesiredSize.mMaximumWidth = mInnerTableMaximumWidth; + } } else { const nsStyleDisplay* nextDisplay; @@ -595,9 +601,21 @@ nsresult nsTableOuterFrame::IR_InnerTableReflow(nsIPresContext* aPresCont // day we'll be able to make tables behave too. FixBadReflowState(aReflowState.reflowState, innerReflowState); + // If we're supposed to update our maximum width, then ask the child to + // as well + if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + innerSize.mFlags |= NS_REFLOW_CALC_MAX_WIDTH; + } rv = ReflowChild(mInnerTableFrame, aPresContext, innerSize, innerReflowState, 0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus); mInnerTableFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED); + if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + aDesiredSize.mMaximumWidth = innerSize.mMaximumWidth; + + // Update the cached value + mInnerTableMaximumWidth = innerSize.mMaximumWidth; + } + // if there is a caption and the width or height of the inner table changed from a successful reflow, // then reflow or move the caption as needed if ((nsnull != mCaptionFrame) && (PR_TRUE==NS_SUCCEEDED(rv))) { @@ -866,6 +884,11 @@ NS_METHOD nsTableOuterFrame::Reflow(nsIPresContext* aPresContext, rv = ReflowChild(mInnerTableFrame, aPresContext, innerSize, innerReflowState, 0, 0, 0, aStatus); + if (NS_UNCONSTRAINEDSIZE == innerReflowState.availableWidth) { + // Remember the inner table's maximum width + mInnerTableMaximumWidth = innerSize.width; + } + // Table's max element size is the MAX of the caption's max element size // and the inner table's max element size... if (nsnull != aDesiredSize.maxElementSize) { diff --git a/mozilla/layout/tables/nsTableOuterFrame.h b/mozilla/layout/tables/nsTableOuterFrame.h index 9bbc917b5f6..48e7aa669aa 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.h +++ b/mozilla/layout/tables/nsTableOuterFrame.h @@ -240,10 +240,10 @@ private: nsIFrame *mCaptionFrame; /** used to track caption max element size */ - PRInt32 mMinCaptionWidth; - - nsSize mMaxElementSize; + PRInt32 mMinCaptionWidth; + nsSize mMaxElementSize; + nscoord mInnerTableMaximumWidth; }; inline nscoord nsTableOuterFrame::GetMinCaptionWidth() diff --git a/mozilla/layout/tables/nsTableRowFrame.cpp b/mozilla/layout/tables/nsTableRowFrame.cpp index 89b30cbab3a..0761797e932 100644 --- a/mozilla/layout/tables/nsTableRowFrame.cpp +++ b/mozilla/layout/tables/nsTableRowFrame.cpp @@ -1236,7 +1236,11 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext* aPresContext, // Pass along the reflow command nsSize kidMaxElementSize; - nsHTMLReflowMetrics desiredSize(&kidMaxElementSize, NS_REFLOW_CALC_MAX_WIDTH); + // Unless this is a fixed-layout table, then have the cell incrementally + // update its maximum width + nsHTMLReflowMetrics desiredSize(&kidMaxElementSize, + aReflowState.tableFrame->RequiresPass1Layout() ? + NS_REFLOW_CALC_MAX_WIDTH : 0); nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState, aNextFrame, kidAvailSize); @@ -1260,75 +1264,28 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext* aPresContext, desiredSize.height = kidMaxElementSize.height; #endif - // Update the cell layout data. + // Update the cell layout data.. If the cell's maximum width changed, + // then inform the table that its maximum width needs to be recomputed ((nsTableCellFrame *)aNextFrame)->SetPass1MaxElementSize(kidMaxElementSize); - // XXX TROY Not ready to be turned on yet... -#if 0 - ((nsTableCellFrame *)aNextFrame)->SetMaximumWidth(desiredSize.mMaximumWidth); -#endif - -#if 1 - // Now see if we need to do the regular pass 1 reflow and gather the preferred - // width. If the new minimum width is different from the old minimum width, - // then we should consider the max element size - if (aReflowState.tableFrame->ColumnsCanBeInvalidatedBy(*(nsTableCellFrame*)aNextFrame, - oldMinSize.width != kidMaxElementSize.width)) { - // For fixed-layout tables we don't need to know the preferred width - if (aReflowState.tableFrame->RequiresPass1Layout()) { -#ifdef DEBUG_troy - // Changes to the cell frame could require the columns to be rebalanced. - // XXX We don't really need to compute the max element size again, we just - // computed it above. However, for the time being do compute it again and - // make sure it's consistent... - nscoord prevMaxElementWidth = kidMaxElementSize.width; -#endif - - // Do the unconstrained reflow and get the pass1 information - // XXX Why the reflow reason of eReflowReason_Initial? - kidReflowState.reason = eReflowReason_Initial; - kidReflowState.reflowCommand = nsnull; - kidReflowState.availableWidth = NS_UNCONSTRAINEDSIZE; - rv = ReflowChild(aNextFrame, aPresContext, desiredSize, kidReflowState, - aReflowState.x, GetChildMaxTopMargin(), 0, aStatus); - - //XXX: this is a hack, shouldn't it be the case that a min size is - // never larger than a desired size? - if (kidMaxElementSize.width>desiredSize.width) - desiredSize.width = kidMaxElementSize.width; - if (kidMaxElementSize.height>desiredSize.height) - desiredSize.height = kidMaxElementSize.height; - -#ifdef DEBUG_troy - // XXX See above - NS_ASSERTION(prevMaxElementWidth == kidMaxElementSize.width, - "different max element width!"); -#else - ((nsTableCellFrame *)aNextFrame)->SetPass1MaxElementSize(kidMaxElementSize); -#endif - - // Update the cell layout data. - ((nsTableCellFrame *)aNextFrame)->SetMaximumWidth(desiredSize.width); + if (desiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) { + // If the cell is not auto-width, then the natural width is the + // desired width + PRBool isAutoWidth = eStyleUnit_Auto == kidReflowState.mStylePosition->mWidth.GetUnit(); + + if (!isAutoWidth) { + // Reset the natural width to be the desired width + // XXX This isn't the best thing to do, but if we don't then the table + // layout strategy will compute a different maximum content width than we + // computed for the initial reflow. That's because the table layout + // strategy doesn't check whether the cell is auto-width... + desiredSize.mMaximumWidth = desiredSize.width; } - - // Now that we know the minimum and preferred widths see if the column - // widths need to be rebalanced - if (aReflowState.tableFrame->ColumnsAreValidFor(*(nsTableCellFrame*)aNextFrame, - oldMinSize.width, - oldMaximumWidth)) { - // The column widths don't need to be rebalanced. Now reflow the cell - // again this time constraining the width back to the column width again - kidReflowState.reason = eReflowReason_Resize; - kidReflowState.availableWidth = cellAvailWidth; - rv = ReflowChild(aNextFrame, aPresContext, desiredSize, kidReflowState, - aReflowState.x, GetChildMaxTopMargin(), 0, aStatus); - - } else { - // The column widths need to be rebalanced, so don't waste time reflowing - // the cell again. Tell the table to rebalance the column widths - aReflowState.tableFrame->InvalidateColumnWidths(); + ((nsTableCellFrame *)aNextFrame)->SetMaximumWidth(desiredSize.mMaximumWidth); + if (oldMaximumWidth != desiredSize.mMaximumWidth) { + aReflowState.tableFrame->InvalidateMaximumWidth(); } } -#else + // Now that we know the minimum and preferred widths see if the column // widths need to be rebalanced if (!aReflowState.tableFrame->ColumnsAreValidFor(*(nsTableCellFrame*)aNextFrame, @@ -1338,7 +1295,6 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext* aPresContext, // the column widths aReflowState.tableFrame->InvalidateColumnWidths(); } -#endif // Calculate the cell's actual size given its pass2 size. This function // takes into account the specified height (in the style), and any special