diff --git a/layout/html/table/src/nsTableFrame.cpp b/layout/html/table/src/nsTableFrame.cpp index f6a2945e76b2..8e9ce4845867 100644 --- a/layout/html/table/src/nsTableFrame.cpp +++ b/layout/html/table/src/nsTableFrame.cpp @@ -1968,6 +1968,7 @@ PRBool nsTableFrame::NeedsReflow(const nsHTMLReflowState& aReflowState) nsresult nsTableFrame::AdjustSiblingsAfterReflow(nsIPresContext& aPresContext, InnerTableReflowState& aReflowState, nsIFrame* aKidFrame, + nsSize* aMaxElementSize, nscoord aDeltaY) { NS_PRECONDITION(NS_UNCONSTRAINEDSIZE == aReflowState.reflowState.availableHeight, @@ -1993,6 +1994,25 @@ nsresult nsTableFrame::AdjustSiblingsAfterReflow(nsIPresContext& aPresCon // Adjust the running y-offset aReflowState.y += kidRect.height; + + // Update the max element size + //XXX: this should call into layout strategy to get the width field + if (aMaxElementSize) + { + const nsStyleSpacing* tableSpacing; + GetStyleData(eStyleStruct_Spacing , ((const nsStyleStruct *&)tableSpacing)); + nsMargin borderPadding; + GetTableBorder (borderPadding); // gets the max border thickness for each edge + nsMargin padding; + tableSpacing->GetPadding(padding); + borderPadding += padding; + nscoord cellSpacing = GetCellSpacingX(); + nsSize kidMaxElementSize; + ((nsTableRowGroupFrame*)kidFrame)->GetMaxElementSize(kidMaxElementSize); + nscoord kidWidth = kidMaxElementSize.width + borderPadding.left + borderPadding.right + cellSpacing*2; + aMaxElementSize->width = PR_MAX(aMaxElementSize->width, kidWidth); + aMaxElementSize->height += kidMaxElementSize.height; + } // Adjust the y-origin if its position actually changed if (aDeltaY != 0) { @@ -3131,7 +3151,8 @@ NS_METHOD nsTableFrame::IR_StyleChanged(nsIPresContext& aPresContext, // data member does not include the table's border/padding... nsresult nsTableFrame::RecoverState(InnerTableReflowState& aReflowState, - nsIFrame* aKidFrame) + nsIFrame* aKidFrame, + nsSize* aMaxElementSize) { // Walk the list of children looking for aKidFrame for (nsIFrame* frame = mFrames.FirstChild(); frame; frame->GetNextSibling(&frame)) { @@ -3173,6 +3194,25 @@ nsTableFrame::RecoverState(InnerTableReflowState& aReflowState, if (frame != aReflowState.footerFrame) { aReflowState.y += kidSize.height; } + + // Update the max element size + //XXX: this should call into layout strategy to get the width field + if (nsnull != aMaxElementSize) + { + const nsStyleSpacing* tableSpacing; + GetStyleData(eStyleStruct_Spacing , ((const nsStyleStruct *&)tableSpacing)); + nsMargin borderPadding; + GetTableBorder (borderPadding); // gets the max border thickness for each edge + nsMargin padding; + tableSpacing->GetPadding(padding); + borderPadding += padding; + nscoord cellSpacing = GetCellSpacingX(); + nsSize kidMaxElementSize; + ((nsTableRowGroupFrame*)frame)->GetMaxElementSize(kidMaxElementSize); + nscoord kidWidth = kidMaxElementSize.width + borderPadding.left + borderPadding.right + cellSpacing*2; + aMaxElementSize->width = PR_MAX(aMaxElementSize->width, kidWidth); + aMaxElementSize->height += kidMaxElementSize.height; + } } return NS_OK; @@ -3187,14 +3227,16 @@ NS_METHOD nsTableFrame::IR_TargetIsChild(nsIPresContext& aPresContext, { nsresult rv; // Recover the state as if aNextFrame is about to be reflowed - RecoverState(aReflowState, aNextFrame); + RecoverState(aReflowState, aNextFrame, aDesiredSize.maxElementSize); // Remember the old rect nsRect oldKidRect; aNextFrame->GetRect(oldKidRect); // Pass along the reflow command - nsHTMLReflowMetrics desiredSize(nsnull); + nsSize kidMaxElementSize; + nsHTMLReflowMetrics desiredSize(aDesiredSize.maxElementSize ? &kidMaxElementSize + : nsnull); nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState, aNextFrame, aReflowState.availSize); @@ -3216,12 +3258,30 @@ NS_METHOD nsTableFrame::IR_TargetIsChild(nsIPresContext& aPresContext, aReflowState.availSize.height -= kidRect.height; } + // Update the max element size + //XXX: this should call into layout strategy to get the width field + if (nsnull != aDesiredSize.maxElementSize) + { + const nsStyleSpacing* tableSpacing; + GetStyleData(eStyleStruct_Spacing , ((const nsStyleStruct *&)tableSpacing)); + nsMargin borderPadding; + GetTableBorder (borderPadding); // gets the max border thickness for each edge + nsMargin padding; + tableSpacing->GetPadding(padding); + borderPadding += padding; + nscoord cellSpacing = GetCellSpacingX(); + nscoord kidWidth = kidMaxElementSize.width + borderPadding.left + borderPadding.right + cellSpacing*2; + aDesiredSize.maxElementSize->width = PR_MAX(aDesiredSize.maxElementSize->width, kidWidth); + aDesiredSize.maxElementSize->height += kidMaxElementSize.height; + } + // If the column width info is valid, then adjust the row group frames // that follow. Otherwise, return and we'll recompute the column widths // and reflow all the row group frames if (!NeedsReflow(aReflowState.reflowState)) { // Adjust the row groups that follow - AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, desiredSize.height - + AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, + aDesiredSize.maxElementSize, desiredSize.height - oldKidRect.height); // Return our size and our status diff --git a/layout/html/table/src/nsTableFrame.h b/layout/html/table/src/nsTableFrame.h index 872397690d56..c65c68a093e4 100644 --- a/layout/html/table/src/nsTableFrame.h +++ b/layout/html/table/src/nsTableFrame.h @@ -550,10 +550,12 @@ protected: NS_IMETHOD AdjustSiblingsAfterReflow(nsIPresContext& aPresContext, InnerTableReflowState& aReflowState, nsIFrame* aKidFrame, + nsSize* aMaxElementSize, nscoord aDeltaY); nsresult RecoverState(InnerTableReflowState& aReflowState, - nsIFrame* aKidFrame); + nsIFrame* aKidFrame, + nsSize* aMaxElementSize); NS_METHOD AdjustForCollapsingRowGroup(nsIFrame* aRowGroupFrame, PRInt32& aRowX); diff --git a/layout/html/table/src/nsTableRowFrame.cpp b/layout/html/table/src/nsTableRowFrame.cpp index df614e317a7f..1a13def1b85f 100644 --- a/layout/html/table/src/nsTableRowFrame.cpp +++ b/layout/html/table/src/nsTableRowFrame.cpp @@ -1099,10 +1099,15 @@ NS_METHOD nsTableRowFrame::RecoverState(nsIPresContext& aPresContext, RowReflowState& aReflowState, nsIFrame* aKidFrame, nscoord& aMaxCellTopMargin, - nscoord& aMaxCellBottomMargin) + nscoord& aMaxCellBottomMargin, + nsSize* aMaxElementSize) { // Initialize OUT parameters aMaxCellTopMargin = aMaxCellBottomMargin = 0; + if (aMaxElementSize) { + aMaxElementSize->width = 0; + aMaxElementSize->height = 0; + } // Walk the child frames (except aKidFrame) and find the table cell frames for (nsIFrame* frame = mFrames.FirstChild(); frame; frame->GetNextSibling(&frame)) { @@ -1146,11 +1151,16 @@ NS_METHOD nsTableRowFrame::RecoverState(nsIPresContext& aPresContext, } } - // XXX We also need to recover the max element size if requested by the - // caller... - // - // We should be using GetReflowMetrics() to get information from the - // table cell, and that will include the max element size... + // Recover the max element size if requested + if (aMaxElementSize) { + PRInt32 rowSpan = aReflowState.tableFrame->GetEffectiveRowSpan((nsTableCellFrame*)frame); + nsSize kidMaxElementSize = ((nsTableCellFrame *)frame)->GetPass1MaxElementSize(); + + aMaxElementSize->width += kidMaxElementSize.width; + if (1 == rowSpan) { + aMaxElementSize->height = PR_MAX(aMaxElementSize->height, kidMaxElementSize.height); + } + } } } } @@ -1266,7 +1276,8 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext& aPresContext, { // Recover our reflow state nscoord maxCellTopMargin, maxCellBottomMargin; - RecoverState(aPresContext, aReflowState, aNextFrame, maxCellTopMargin, maxCellBottomMargin); + RecoverState(aPresContext, aReflowState, aNextFrame, maxCellTopMargin, + maxCellBottomMargin, aDesiredSize.maxElementSize); // Get the frame's margins nsMargin kidMargin; @@ -1292,11 +1303,11 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext& aPresContext, nsSize kidAvailSize(cellAvailWidth, NS_UNCONSTRAINEDSIZE); // Pass along the reflow command - nsSize kidMaxElementSize; + nsSize kidMaxElementSize; nsHTMLReflowMetrics desiredSize(&kidMaxElementSize); - nsHTMLReflowState kidReflowState(aPresContext, - aReflowState.reflowState, - aNextFrame, kidAvailSize); + nsHTMLReflowState kidReflowState(aPresContext, + aReflowState.reflowState, + aNextFrame, kidAvailSize); // Remember the current desired size, we'll need it later nsSize oldMinSize = ((nsTableCellFrame*)aNextFrame)->GetPass1MaxElementSize(); @@ -1392,7 +1403,7 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext& aPresContext, // Return our desired size. Note that our desired width is just whatever width // we were given by the row group frame aDesiredSize.width = aReflowState.availSize.width; - aDesiredSize.height = aReflowState.maxCellVertSpace; + aDesiredSize.height = aReflowState.maxCellVertSpace; } else { // pass reflow to unknown frame child @@ -1467,6 +1478,12 @@ nsTableRowFrame::Reflow(nsIPresContext& aPresContext, break; } + // If we computed our max element element size, then cache it so we can return + // it later when asked + if (aDesiredSize.maxElementSize) { + mMaxElementSize = *aDesiredSize.maxElementSize; + } + if (nsDebugTable::gRflRow) nsTableFrame::DebugReflow("TR::Rfl ex", this, nsnull, &aDesiredSize); return rv; } diff --git a/layout/html/table/src/nsTableRowFrame.h b/layout/html/table/src/nsTableRowFrame.h index 729334c5cb1f..7d3abcd21e27 100644 --- a/layout/html/table/src/nsTableRowFrame.h +++ b/layout/html/table/src/nsTableRowFrame.h @@ -170,6 +170,8 @@ public: virtual PRBool Contains(const nsPoint& aPoint); + void GetMaxElementSize(nsSize& aMaxElementSize) const; + /** used by yje row group frame code */ void ReflowCellFrame(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, @@ -230,7 +232,8 @@ protected: RowReflowState& aState, nsIFrame* aKidFrame, nscoord& aMaxCellTopMargin, - nscoord& aMaxCellBottomMargin); + nscoord& aMaxCellBottomMargin, + nsSize* aMaxElementSize); void PlaceChild(nsIPresContext& aPresContext, RowReflowState& aState, @@ -284,6 +287,7 @@ private: nscoord mCellMaxTopMargin; nscoord mCellMaxBottomMargin; PRInt32 mMinRowSpan; // the smallest row span among all my child cells + nsSize mMaxElementSize; // cached max element size PRBool mInitializedChildren; // PR_TRUE if child cells have been initialized // (for now, that means "added to the table", and // is NOT the same as having nsIFrame::Init() called.) @@ -304,4 +308,10 @@ inline void nsTableRowFrame::SetRowIndex (int aRowIndex) inline void nsTableRowFrame::ResetInitChildren() { mInitializedChildren=PR_FALSE; } +inline void nsTableRowFrame::GetMaxElementSize(nsSize& aMaxElementSize) const +{ + aMaxElementSize.width = mMaxElementSize.width; + aMaxElementSize.height = mMaxElementSize.height; +} + #endif diff --git a/layout/html/table/src/nsTableRowGroupFrame.cpp b/layout/html/table/src/nsTableRowGroupFrame.cpp index 70650db21bad..5d06d250e980 100644 --- a/layout/html/table/src/nsTableRowGroupFrame.cpp +++ b/layout/html/table/src/nsTableRowGroupFrame.cpp @@ -794,19 +794,27 @@ nsresult nsTableRowGroupFrame::AdjustSiblingsAfterReflow(nsIPresContext& aPresContext, RowGroupReflowState& aReflowState, nsIFrame* aKidFrame, + nsSize* aMaxElementSize, nscoord aDeltaY) { NS_PRECONDITION(NS_UNCONSTRAINEDSIZE == aReflowState.reflowState.availableHeight, "we're not in galley mode"); nsIFrame* lastKidFrame = aKidFrame; - if (aDeltaY != 0) { - // Move the frames that follow aKidFrame by aDeltaY - nsIFrame* kidFrame; + // Move the frames that follow aKidFrame by aDeltaY and update the max element + // size + nsIFrame* kidFrame; + for (aKidFrame->GetNextSibling(&kidFrame); kidFrame; kidFrame->GetNextSibling(&kidFrame)) { + // Update the max element size + if (aMaxElementSize) { + nsSize kidMaxElementSize; + ((nsTableRowFrame*)kidFrame)->GetMaxElementSize(kidMaxElementSize); + + aMaxElementSize->width = PR_MAX(aMaxElementSize->width, kidMaxElementSize.width); + } - GetNextFrame(aKidFrame, &kidFrame); - - while (nsnull != kidFrame) { + // Move the frame if we need to + if (aDeltaY != 0) { nsPoint origin; // Adjust the y-origin @@ -819,16 +827,12 @@ nsTableRowGroupFrame::AdjustSiblingsAfterReflow(nsIPresContext& aPresContex if (NS_OK == kidFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->WillReflow(aPresContext); } + kidFrame->MoveTo(origin.x, origin.y); - - // Get the next frame - lastKidFrame = kidFrame; - GetNextFrame(kidFrame, &kidFrame); } - } else { - // Get the last frame - lastKidFrame = GetLastFrame(); + // Remember the last frame + lastKidFrame = kidFrame; } // Update our running y-offset to reflect the bottommost child @@ -1071,6 +1075,12 @@ nsTableRowGroupFrame::Reflow(nsIPresContext& aPresContext, } } + // If we computed our max element element size, then cache it so we can return + // it later when asked + if (aDesiredSize.maxElementSize) { + mMaxElementSize = *aDesiredSize.maxElementSize; + } + if (nsDebugTable::gRflRowGrp) nsTableFrame::DebugReflow("TRG::Rfl ex", this, nsnull, &aDesiredSize); return rv; } @@ -1401,7 +1411,8 @@ NS_METHOD nsTableRowGroupFrame::GetHeightOfRows(nscoord& aResult) // - firstRow nsresult nsTableRowGroupFrame::RecoverState(RowGroupReflowState& aReflowState, - nsIFrame* aKidFrame) + nsIFrame* aKidFrame, + nsSize* aMaxElementSize) { // Walk the list of children looking for aKidFrame for (nsIFrame* frame = mFrames.FirstChild(); frame; frame->GetNextSibling(&frame)) { @@ -1420,20 +1431,20 @@ nsTableRowGroupFrame::RecoverState(RowGroupReflowState& aReflowState, } // Update the maximum element size - if (aReflowState.firstRow) { - aReflowState.firstRow = PR_FALSE; - // XXX Today you can't ask for max-element-size when doing an - // incremental reflow -#if 0 - if (aMaxElementSize) { - aMaxElementSize->width = aKidMaxElementSize.width; - aMaxElementSize->height = aKidMaxElementSize.height; + if (aMaxElementSize) { + // Get the row frame's cached max element size + nsSize kidMaxElementSize; + ((nsTableRowFrame*)frame)->GetMaxElementSize(kidMaxElementSize); + + if (aReflowState.firstRow) { + aMaxElementSize->width = kidMaxElementSize.width; + aMaxElementSize->height = kidMaxElementSize.height; + } else { + aMaxElementSize->width = PR_MAX(aMaxElementSize->width, kidMaxElementSize.width); } - - } else if (aMaxElementSize) { - aMaxElementSize->width = PR_MAX(aMaxElementSize->width, aKidMaxElementSize.width); -#endif } + + aReflowState.firstRow = PR_FALSE; } return NS_OK; @@ -1448,7 +1459,7 @@ NS_METHOD nsTableRowGroupFrame::IR_TargetIsChild(nsIPresContext& aPresConte { nsresult rv; // Recover the state as if aNextFrame is about to be reflowed - RecoverState(aReflowState, aNextFrame); + RecoverState(aReflowState, aNextFrame, aDesiredSize.maxElementSize); // Remember the old rect nsRect oldKidRect; @@ -1457,15 +1468,15 @@ NS_METHOD nsTableRowGroupFrame::IR_TargetIsChild(nsIPresContext& aPresConte // Pass along the reflow command nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState, aNextFrame, aReflowState.availSize); - nsHTMLReflowMetrics desiredSize(nsnull); + nsSize kidMaxElementSize; + nsHTMLReflowMetrics desiredSize(aDesiredSize.maxElementSize ? &kidMaxElementSize : nsnull); rv = ReflowChild(aNextFrame, aPresContext, desiredSize, kidReflowState, aStatus); // Place the row frame - nsSize kidMaxElementSize; nsRect kidRect(0, aReflowState.y, desiredSize.width, desiredSize.height); - PlaceChild(aPresContext, aReflowState, aNextFrame, kidRect, nsnull, - kidMaxElementSize); + PlaceChild(aPresContext, aReflowState, aNextFrame, kidRect, + aDesiredSize.maxElementSize, kidMaxElementSize); // See if the table needs a reflow (e.g., if the column widths have // changed). If so, just return and don't bother adjusting the rows @@ -1479,14 +1490,16 @@ NS_METHOD nsTableRowGroupFrame::IR_TargetIsChild(nsIPresContext& aPresConte ((nsTableRowFrame*)aNextFrame)->DidResize(aPresContext, aReflowState.reflowState); // Adjust the frames that follow... - AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, desiredSize.height - - oldKidRect.height); + AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, + aDesiredSize.maxElementSize, + desiredSize.height - oldKidRect.height); aDesiredSize.height = aReflowState.y; } else { // Adjust the frames that follow... - AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, desiredSize.height - - oldKidRect.height); + AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, + aDesiredSize.maxElementSize, + desiredSize.height - oldKidRect.height); // Now recalculate the row heights CalculateRowHeights(aPresContext, aDesiredSize, aReflowState.reflowState); diff --git a/layout/html/table/src/nsTableRowGroupFrame.h b/layout/html/table/src/nsTableRowGroupFrame.h index cba84665d073..f5f1300f58d9 100644 --- a/layout/html/table/src/nsTableRowGroupFrame.h +++ b/layout/html/table/src/nsTableRowGroupFrame.h @@ -188,6 +188,8 @@ public: virtual PRBool ContinueReflow(nsIPresContext& aPresContext, nscoord y, nscoord height) { return PR_TRUE; } + void GetMaxElementSize(nsSize& aMaxElementSize) const; + protected: /** implement abstract method on nsHTMLContainerFrame */ @@ -240,10 +242,12 @@ protected: nsresult AdjustSiblingsAfterReflow(nsIPresContext& aPresContext, RowGroupReflowState& aReflowState, nsIFrame* aKidFrame, + nsSize* aMaxElementSize, nscoord aDeltaY); nsresult RecoverState(RowGroupReflowState& aReflowState, - nsIFrame* aKidFrame); + nsIFrame* aKidFrame, + nsSize* aMaxElementSize); /** * Reflow the frames we've already created @@ -302,8 +306,14 @@ public: private: nsIAtom *mType; + nsSize mMaxElementSize; }; +inline void nsTableRowGroupFrame::GetMaxElementSize(nsSize& aMaxElementSize) const +{ + aMaxElementSize = mMaxElementSize; +} + #endif diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index f6a2945e76b2..8e9ce4845867 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -1968,6 +1968,7 @@ PRBool nsTableFrame::NeedsReflow(const nsHTMLReflowState& aReflowState) nsresult nsTableFrame::AdjustSiblingsAfterReflow(nsIPresContext& aPresContext, InnerTableReflowState& aReflowState, nsIFrame* aKidFrame, + nsSize* aMaxElementSize, nscoord aDeltaY) { NS_PRECONDITION(NS_UNCONSTRAINEDSIZE == aReflowState.reflowState.availableHeight, @@ -1993,6 +1994,25 @@ nsresult nsTableFrame::AdjustSiblingsAfterReflow(nsIPresContext& aPresCon // Adjust the running y-offset aReflowState.y += kidRect.height; + + // Update the max element size + //XXX: this should call into layout strategy to get the width field + if (aMaxElementSize) + { + const nsStyleSpacing* tableSpacing; + GetStyleData(eStyleStruct_Spacing , ((const nsStyleStruct *&)tableSpacing)); + nsMargin borderPadding; + GetTableBorder (borderPadding); // gets the max border thickness for each edge + nsMargin padding; + tableSpacing->GetPadding(padding); + borderPadding += padding; + nscoord cellSpacing = GetCellSpacingX(); + nsSize kidMaxElementSize; + ((nsTableRowGroupFrame*)kidFrame)->GetMaxElementSize(kidMaxElementSize); + nscoord kidWidth = kidMaxElementSize.width + borderPadding.left + borderPadding.right + cellSpacing*2; + aMaxElementSize->width = PR_MAX(aMaxElementSize->width, kidWidth); + aMaxElementSize->height += kidMaxElementSize.height; + } // Adjust the y-origin if its position actually changed if (aDeltaY != 0) { @@ -3131,7 +3151,8 @@ NS_METHOD nsTableFrame::IR_StyleChanged(nsIPresContext& aPresContext, // data member does not include the table's border/padding... nsresult nsTableFrame::RecoverState(InnerTableReflowState& aReflowState, - nsIFrame* aKidFrame) + nsIFrame* aKidFrame, + nsSize* aMaxElementSize) { // Walk the list of children looking for aKidFrame for (nsIFrame* frame = mFrames.FirstChild(); frame; frame->GetNextSibling(&frame)) { @@ -3173,6 +3194,25 @@ nsTableFrame::RecoverState(InnerTableReflowState& aReflowState, if (frame != aReflowState.footerFrame) { aReflowState.y += kidSize.height; } + + // Update the max element size + //XXX: this should call into layout strategy to get the width field + if (nsnull != aMaxElementSize) + { + const nsStyleSpacing* tableSpacing; + GetStyleData(eStyleStruct_Spacing , ((const nsStyleStruct *&)tableSpacing)); + nsMargin borderPadding; + GetTableBorder (borderPadding); // gets the max border thickness for each edge + nsMargin padding; + tableSpacing->GetPadding(padding); + borderPadding += padding; + nscoord cellSpacing = GetCellSpacingX(); + nsSize kidMaxElementSize; + ((nsTableRowGroupFrame*)frame)->GetMaxElementSize(kidMaxElementSize); + nscoord kidWidth = kidMaxElementSize.width + borderPadding.left + borderPadding.right + cellSpacing*2; + aMaxElementSize->width = PR_MAX(aMaxElementSize->width, kidWidth); + aMaxElementSize->height += kidMaxElementSize.height; + } } return NS_OK; @@ -3187,14 +3227,16 @@ NS_METHOD nsTableFrame::IR_TargetIsChild(nsIPresContext& aPresContext, { nsresult rv; // Recover the state as if aNextFrame is about to be reflowed - RecoverState(aReflowState, aNextFrame); + RecoverState(aReflowState, aNextFrame, aDesiredSize.maxElementSize); // Remember the old rect nsRect oldKidRect; aNextFrame->GetRect(oldKidRect); // Pass along the reflow command - nsHTMLReflowMetrics desiredSize(nsnull); + nsSize kidMaxElementSize; + nsHTMLReflowMetrics desiredSize(aDesiredSize.maxElementSize ? &kidMaxElementSize + : nsnull); nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState, aNextFrame, aReflowState.availSize); @@ -3216,12 +3258,30 @@ NS_METHOD nsTableFrame::IR_TargetIsChild(nsIPresContext& aPresContext, aReflowState.availSize.height -= kidRect.height; } + // Update the max element size + //XXX: this should call into layout strategy to get the width field + if (nsnull != aDesiredSize.maxElementSize) + { + const nsStyleSpacing* tableSpacing; + GetStyleData(eStyleStruct_Spacing , ((const nsStyleStruct *&)tableSpacing)); + nsMargin borderPadding; + GetTableBorder (borderPadding); // gets the max border thickness for each edge + nsMargin padding; + tableSpacing->GetPadding(padding); + borderPadding += padding; + nscoord cellSpacing = GetCellSpacingX(); + nscoord kidWidth = kidMaxElementSize.width + borderPadding.left + borderPadding.right + cellSpacing*2; + aDesiredSize.maxElementSize->width = PR_MAX(aDesiredSize.maxElementSize->width, kidWidth); + aDesiredSize.maxElementSize->height += kidMaxElementSize.height; + } + // If the column width info is valid, then adjust the row group frames // that follow. Otherwise, return and we'll recompute the column widths // and reflow all the row group frames if (!NeedsReflow(aReflowState.reflowState)) { // Adjust the row groups that follow - AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, desiredSize.height - + AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, + aDesiredSize.maxElementSize, desiredSize.height - oldKidRect.height); // Return our size and our status diff --git a/layout/tables/nsTableFrame.h b/layout/tables/nsTableFrame.h index 872397690d56..c65c68a093e4 100644 --- a/layout/tables/nsTableFrame.h +++ b/layout/tables/nsTableFrame.h @@ -550,10 +550,12 @@ protected: NS_IMETHOD AdjustSiblingsAfterReflow(nsIPresContext& aPresContext, InnerTableReflowState& aReflowState, nsIFrame* aKidFrame, + nsSize* aMaxElementSize, nscoord aDeltaY); nsresult RecoverState(InnerTableReflowState& aReflowState, - nsIFrame* aKidFrame); + nsIFrame* aKidFrame, + nsSize* aMaxElementSize); NS_METHOD AdjustForCollapsingRowGroup(nsIFrame* aRowGroupFrame, PRInt32& aRowX); diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index df614e317a7f..1a13def1b85f 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -1099,10 +1099,15 @@ NS_METHOD nsTableRowFrame::RecoverState(nsIPresContext& aPresContext, RowReflowState& aReflowState, nsIFrame* aKidFrame, nscoord& aMaxCellTopMargin, - nscoord& aMaxCellBottomMargin) + nscoord& aMaxCellBottomMargin, + nsSize* aMaxElementSize) { // Initialize OUT parameters aMaxCellTopMargin = aMaxCellBottomMargin = 0; + if (aMaxElementSize) { + aMaxElementSize->width = 0; + aMaxElementSize->height = 0; + } // Walk the child frames (except aKidFrame) and find the table cell frames for (nsIFrame* frame = mFrames.FirstChild(); frame; frame->GetNextSibling(&frame)) { @@ -1146,11 +1151,16 @@ NS_METHOD nsTableRowFrame::RecoverState(nsIPresContext& aPresContext, } } - // XXX We also need to recover the max element size if requested by the - // caller... - // - // We should be using GetReflowMetrics() to get information from the - // table cell, and that will include the max element size... + // Recover the max element size if requested + if (aMaxElementSize) { + PRInt32 rowSpan = aReflowState.tableFrame->GetEffectiveRowSpan((nsTableCellFrame*)frame); + nsSize kidMaxElementSize = ((nsTableCellFrame *)frame)->GetPass1MaxElementSize(); + + aMaxElementSize->width += kidMaxElementSize.width; + if (1 == rowSpan) { + aMaxElementSize->height = PR_MAX(aMaxElementSize->height, kidMaxElementSize.height); + } + } } } } @@ -1266,7 +1276,8 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext& aPresContext, { // Recover our reflow state nscoord maxCellTopMargin, maxCellBottomMargin; - RecoverState(aPresContext, aReflowState, aNextFrame, maxCellTopMargin, maxCellBottomMargin); + RecoverState(aPresContext, aReflowState, aNextFrame, maxCellTopMargin, + maxCellBottomMargin, aDesiredSize.maxElementSize); // Get the frame's margins nsMargin kidMargin; @@ -1292,11 +1303,11 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext& aPresContext, nsSize kidAvailSize(cellAvailWidth, NS_UNCONSTRAINEDSIZE); // Pass along the reflow command - nsSize kidMaxElementSize; + nsSize kidMaxElementSize; nsHTMLReflowMetrics desiredSize(&kidMaxElementSize); - nsHTMLReflowState kidReflowState(aPresContext, - aReflowState.reflowState, - aNextFrame, kidAvailSize); + nsHTMLReflowState kidReflowState(aPresContext, + aReflowState.reflowState, + aNextFrame, kidAvailSize); // Remember the current desired size, we'll need it later nsSize oldMinSize = ((nsTableCellFrame*)aNextFrame)->GetPass1MaxElementSize(); @@ -1392,7 +1403,7 @@ NS_METHOD nsTableRowFrame::IR_TargetIsChild(nsIPresContext& aPresContext, // Return our desired size. Note that our desired width is just whatever width // we were given by the row group frame aDesiredSize.width = aReflowState.availSize.width; - aDesiredSize.height = aReflowState.maxCellVertSpace; + aDesiredSize.height = aReflowState.maxCellVertSpace; } else { // pass reflow to unknown frame child @@ -1467,6 +1478,12 @@ nsTableRowFrame::Reflow(nsIPresContext& aPresContext, break; } + // If we computed our max element element size, then cache it so we can return + // it later when asked + if (aDesiredSize.maxElementSize) { + mMaxElementSize = *aDesiredSize.maxElementSize; + } + if (nsDebugTable::gRflRow) nsTableFrame::DebugReflow("TR::Rfl ex", this, nsnull, &aDesiredSize); return rv; } diff --git a/layout/tables/nsTableRowFrame.h b/layout/tables/nsTableRowFrame.h index 729334c5cb1f..7d3abcd21e27 100644 --- a/layout/tables/nsTableRowFrame.h +++ b/layout/tables/nsTableRowFrame.h @@ -170,6 +170,8 @@ public: virtual PRBool Contains(const nsPoint& aPoint); + void GetMaxElementSize(nsSize& aMaxElementSize) const; + /** used by yje row group frame code */ void ReflowCellFrame(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, @@ -230,7 +232,8 @@ protected: RowReflowState& aState, nsIFrame* aKidFrame, nscoord& aMaxCellTopMargin, - nscoord& aMaxCellBottomMargin); + nscoord& aMaxCellBottomMargin, + nsSize* aMaxElementSize); void PlaceChild(nsIPresContext& aPresContext, RowReflowState& aState, @@ -284,6 +287,7 @@ private: nscoord mCellMaxTopMargin; nscoord mCellMaxBottomMargin; PRInt32 mMinRowSpan; // the smallest row span among all my child cells + nsSize mMaxElementSize; // cached max element size PRBool mInitializedChildren; // PR_TRUE if child cells have been initialized // (for now, that means "added to the table", and // is NOT the same as having nsIFrame::Init() called.) @@ -304,4 +308,10 @@ inline void nsTableRowFrame::SetRowIndex (int aRowIndex) inline void nsTableRowFrame::ResetInitChildren() { mInitializedChildren=PR_FALSE; } +inline void nsTableRowFrame::GetMaxElementSize(nsSize& aMaxElementSize) const +{ + aMaxElementSize.width = mMaxElementSize.width; + aMaxElementSize.height = mMaxElementSize.height; +} + #endif diff --git a/layout/tables/nsTableRowGroupFrame.cpp b/layout/tables/nsTableRowGroupFrame.cpp index 70650db21bad..5d06d250e980 100644 --- a/layout/tables/nsTableRowGroupFrame.cpp +++ b/layout/tables/nsTableRowGroupFrame.cpp @@ -794,19 +794,27 @@ nsresult nsTableRowGroupFrame::AdjustSiblingsAfterReflow(nsIPresContext& aPresContext, RowGroupReflowState& aReflowState, nsIFrame* aKidFrame, + nsSize* aMaxElementSize, nscoord aDeltaY) { NS_PRECONDITION(NS_UNCONSTRAINEDSIZE == aReflowState.reflowState.availableHeight, "we're not in galley mode"); nsIFrame* lastKidFrame = aKidFrame; - if (aDeltaY != 0) { - // Move the frames that follow aKidFrame by aDeltaY - nsIFrame* kidFrame; + // Move the frames that follow aKidFrame by aDeltaY and update the max element + // size + nsIFrame* kidFrame; + for (aKidFrame->GetNextSibling(&kidFrame); kidFrame; kidFrame->GetNextSibling(&kidFrame)) { + // Update the max element size + if (aMaxElementSize) { + nsSize kidMaxElementSize; + ((nsTableRowFrame*)kidFrame)->GetMaxElementSize(kidMaxElementSize); + + aMaxElementSize->width = PR_MAX(aMaxElementSize->width, kidMaxElementSize.width); + } - GetNextFrame(aKidFrame, &kidFrame); - - while (nsnull != kidFrame) { + // Move the frame if we need to + if (aDeltaY != 0) { nsPoint origin; // Adjust the y-origin @@ -819,16 +827,12 @@ nsTableRowGroupFrame::AdjustSiblingsAfterReflow(nsIPresContext& aPresContex if (NS_OK == kidFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->WillReflow(aPresContext); } + kidFrame->MoveTo(origin.x, origin.y); - - // Get the next frame - lastKidFrame = kidFrame; - GetNextFrame(kidFrame, &kidFrame); } - } else { - // Get the last frame - lastKidFrame = GetLastFrame(); + // Remember the last frame + lastKidFrame = kidFrame; } // Update our running y-offset to reflect the bottommost child @@ -1071,6 +1075,12 @@ nsTableRowGroupFrame::Reflow(nsIPresContext& aPresContext, } } + // If we computed our max element element size, then cache it so we can return + // it later when asked + if (aDesiredSize.maxElementSize) { + mMaxElementSize = *aDesiredSize.maxElementSize; + } + if (nsDebugTable::gRflRowGrp) nsTableFrame::DebugReflow("TRG::Rfl ex", this, nsnull, &aDesiredSize); return rv; } @@ -1401,7 +1411,8 @@ NS_METHOD nsTableRowGroupFrame::GetHeightOfRows(nscoord& aResult) // - firstRow nsresult nsTableRowGroupFrame::RecoverState(RowGroupReflowState& aReflowState, - nsIFrame* aKidFrame) + nsIFrame* aKidFrame, + nsSize* aMaxElementSize) { // Walk the list of children looking for aKidFrame for (nsIFrame* frame = mFrames.FirstChild(); frame; frame->GetNextSibling(&frame)) { @@ -1420,20 +1431,20 @@ nsTableRowGroupFrame::RecoverState(RowGroupReflowState& aReflowState, } // Update the maximum element size - if (aReflowState.firstRow) { - aReflowState.firstRow = PR_FALSE; - // XXX Today you can't ask for max-element-size when doing an - // incremental reflow -#if 0 - if (aMaxElementSize) { - aMaxElementSize->width = aKidMaxElementSize.width; - aMaxElementSize->height = aKidMaxElementSize.height; + if (aMaxElementSize) { + // Get the row frame's cached max element size + nsSize kidMaxElementSize; + ((nsTableRowFrame*)frame)->GetMaxElementSize(kidMaxElementSize); + + if (aReflowState.firstRow) { + aMaxElementSize->width = kidMaxElementSize.width; + aMaxElementSize->height = kidMaxElementSize.height; + } else { + aMaxElementSize->width = PR_MAX(aMaxElementSize->width, kidMaxElementSize.width); } - - } else if (aMaxElementSize) { - aMaxElementSize->width = PR_MAX(aMaxElementSize->width, aKidMaxElementSize.width); -#endif } + + aReflowState.firstRow = PR_FALSE; } return NS_OK; @@ -1448,7 +1459,7 @@ NS_METHOD nsTableRowGroupFrame::IR_TargetIsChild(nsIPresContext& aPresConte { nsresult rv; // Recover the state as if aNextFrame is about to be reflowed - RecoverState(aReflowState, aNextFrame); + RecoverState(aReflowState, aNextFrame, aDesiredSize.maxElementSize); // Remember the old rect nsRect oldKidRect; @@ -1457,15 +1468,15 @@ NS_METHOD nsTableRowGroupFrame::IR_TargetIsChild(nsIPresContext& aPresConte // Pass along the reflow command nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState, aNextFrame, aReflowState.availSize); - nsHTMLReflowMetrics desiredSize(nsnull); + nsSize kidMaxElementSize; + nsHTMLReflowMetrics desiredSize(aDesiredSize.maxElementSize ? &kidMaxElementSize : nsnull); rv = ReflowChild(aNextFrame, aPresContext, desiredSize, kidReflowState, aStatus); // Place the row frame - nsSize kidMaxElementSize; nsRect kidRect(0, aReflowState.y, desiredSize.width, desiredSize.height); - PlaceChild(aPresContext, aReflowState, aNextFrame, kidRect, nsnull, - kidMaxElementSize); + PlaceChild(aPresContext, aReflowState, aNextFrame, kidRect, + aDesiredSize.maxElementSize, kidMaxElementSize); // See if the table needs a reflow (e.g., if the column widths have // changed). If so, just return and don't bother adjusting the rows @@ -1479,14 +1490,16 @@ NS_METHOD nsTableRowGroupFrame::IR_TargetIsChild(nsIPresContext& aPresConte ((nsTableRowFrame*)aNextFrame)->DidResize(aPresContext, aReflowState.reflowState); // Adjust the frames that follow... - AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, desiredSize.height - - oldKidRect.height); + AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, + aDesiredSize.maxElementSize, + desiredSize.height - oldKidRect.height); aDesiredSize.height = aReflowState.y; } else { // Adjust the frames that follow... - AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, desiredSize.height - - oldKidRect.height); + AdjustSiblingsAfterReflow(aPresContext, aReflowState, aNextFrame, + aDesiredSize.maxElementSize, + desiredSize.height - oldKidRect.height); // Now recalculate the row heights CalculateRowHeights(aPresContext, aDesiredSize, aReflowState.reflowState); diff --git a/layout/tables/nsTableRowGroupFrame.h b/layout/tables/nsTableRowGroupFrame.h index cba84665d073..f5f1300f58d9 100644 --- a/layout/tables/nsTableRowGroupFrame.h +++ b/layout/tables/nsTableRowGroupFrame.h @@ -188,6 +188,8 @@ public: virtual PRBool ContinueReflow(nsIPresContext& aPresContext, nscoord y, nscoord height) { return PR_TRUE; } + void GetMaxElementSize(nsSize& aMaxElementSize) const; + protected: /** implement abstract method on nsHTMLContainerFrame */ @@ -240,10 +242,12 @@ protected: nsresult AdjustSiblingsAfterReflow(nsIPresContext& aPresContext, RowGroupReflowState& aReflowState, nsIFrame* aKidFrame, + nsSize* aMaxElementSize, nscoord aDeltaY); nsresult RecoverState(RowGroupReflowState& aReflowState, - nsIFrame* aKidFrame); + nsIFrame* aKidFrame, + nsSize* aMaxElementSize); /** * Reflow the frames we've already created @@ -302,8 +306,14 @@ public: private: nsIAtom *mType; + nsSize mMaxElementSize; }; +inline void nsTableRowGroupFrame::GetMaxElementSize(nsSize& aMaxElementSize) const +{ + aMaxElementSize = mMaxElementSize; +} + #endif diff --git a/layout/xul/base/src/nsTreeRowGroupFrame.cpp b/layout/xul/base/src/nsTreeRowGroupFrame.cpp index 30937912783f..2f0f5e574988 100644 --- a/layout/xul/base/src/nsTreeRowGroupFrame.cpp +++ b/layout/xul/base/src/nsTreeRowGroupFrame.cpp @@ -628,7 +628,7 @@ nsTreeRowGroupFrame::IR_TargetIsChild(nsIPresContext& aPresContext, if (aNextFrame && (aNextFrame == mScrollbar)) { nsresult rv; // Recover the state as if aNextFrame is about to be reflowed - RecoverState(aReflowState, aNextFrame); + RecoverState(aReflowState, aNextFrame, aDesiredSize.maxElementSize); // Remember the old rect nsRect oldKidRect;