diff --git a/layout/html/table/src/nsTableFrame.cpp b/layout/html/table/src/nsTableFrame.cpp index dca6c7a478a9..e2edb8394bff 100644 --- a/layout/html/table/src/nsTableFrame.cpp +++ b/layout/html/table/src/nsTableFrame.cpp @@ -2129,9 +2129,7 @@ void nsTableFrame::BalanceColumnWidths(nsIPresContext* aPresContext, if (nsnull==mColumnWidths) { mColumnWidths = new PRInt32[numCols]; - // SEC should be a memset - for (PRInt32 i = 0; iChildCount(numRows); PRInt32 *rowHeights = new PRInt32[numRows]; + nsCRT::memset (rowHeights, 0, numRows*sizeof(PRInt32)); if (gsDebug==PR_TRUE) printf("Height Step 1...\n"); for (rowIndex = 0; rowIndex < numRows; rowIndex++) { @@ -2318,7 +2317,7 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, nsTableCellFrame *cellFrame; rowFrame->ChildAt(cellIndex, (nsIFrame*&)cellFrame); - PRInt32 rowSpan = cellFrame->GetRowSpan(); + PRInt32 rowSpan = GetEffectiveRowSpan(rowIndex, cellFrame);//cellFrame->GetRowSpan(); if (1==rowSpan) { if (gsDebug==PR_TRUE) printf(" setting cell[%d,%d] height to %d\n", rowIndex, cellIndex, rowHeights[rowIndex]); @@ -2368,7 +2367,7 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, // get the next cell nsTableCellFrame *cellFrame; rowFrame->ChildAt(cellIndex, (nsIFrame*&)cellFrame); - PRInt32 rowSpan = cellFrame->GetRowSpan(); + PRInt32 rowSpan = GetEffectiveRowSpan(rowIndex, cellFrame);//cellFrame->GetRowSpan(); if (1 1, determine it's height if (gsDebug==PR_TRUE) printf(" cell[%d,%d] has a rowspan = %d\n", rowIndex, cellIndex, rowSpan); @@ -2427,7 +2426,8 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, nsTableCellFrame *frame; rowFrameToBeResized->ChildAt(j, (nsIFrame*&)frame); - if (frame->GetRowSpan()==1) + PRInt32 frameRowSpan = GetEffectiveRowSpan(i, frame); + if (frameRowSpan==1) { nsSize frameSize(0,0); @@ -3196,80 +3196,83 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) } } // or if it's another table (we're nested) use its computed width - nsIFrame* table = nsnull; - rs->frame->QueryInterface(kTableFrameCID, (void**) &table); - if (nsnull != table) { - /* We found the nearest containing table (actually, the inner table). - This defines what our percentage size is relative to. Use its desired width - as the basis for computing our width. - ********************************************************************************** - Nav4 compatibility code: if the inner table has a percent width and the outer - table has an auto width, the parentWidth is the width the containing cell would be - without the inner table. - ********************************************************************************** - */ - // Compute and subtract out the insets (sum of border and padding) for the table - nsMargin borderPadding; - /* the following hack is because the outer table really holds the position info */ - // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - nsIFrame * outerTableFrame = nsnull; - table->GetGeometricParent(outerTableFrame); - const nsStylePosition* tablePosition; - outerTableFrame->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); - const nsStyleSpacing* spacing; - outerTableFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! + if (rs->frame!=aReflowState.frame) + { + nsIFrame* table = nsnull; + rs->frame->QueryInterface(kTableFrameCID, (void**) &table); + if (nsnull != table) { + /* We found the nearest containing table (actually, the inner table). + This defines what our percentage size is relative to. Use its desired width + as the basis for computing our width. + ********************************************************************************** + Nav4 compatibility code: if the inner table has a percent width and the outer + table has an auto width, the parentWidth is the width the containing cell would be + without the inner table. + ********************************************************************************** + */ + // Compute and subtract out the insets (sum of border and padding) for the table + nsMargin borderPadding; + /* the following hack is because the outer table really holds the position info */ + // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! + nsIFrame * outerTableFrame = nsnull; + table->GetGeometricParent(outerTableFrame); + const nsStylePosition* tablePosition; + outerTableFrame->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); + const nsStyleSpacing* spacing; + outerTableFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - if (eStyleUnit_Auto == tablePosition->mWidth.GetUnit()) - { - parentWidth = 0; - if (nsnull != ((nsTableFrame*)table)->mColumnWidths) + if (eStyleUnit_Auto == tablePosition->mWidth.GetUnit()) { - PRInt32 colIndex = ((nsTableCellFrame *)greatgrandchildFrame)->GetColIndex(); - PRInt32 colSpan = ((nsTableCellFrame *)greatgrandchildFrame)->GetColSpan(); - for (PRInt32 i = 0; iGetColumnWidth(i+colIndex); - // subtract out cell border and padding - greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - if (PR_TRUE==gsDebugNT) - printf("%p: found a table frame %p with auto width, returning parentWidth %d from cell in col %d with span %d\n", - aReflowState.frame, table, parentWidth, colIndex, colSpan); + parentWidth = 0; + if (nsnull != ((nsTableFrame*)table)->mColumnWidths) + { + PRInt32 colIndex = ((nsTableCellFrame *)greatgrandchildFrame)->GetColIndex(); + PRInt32 colSpan = ((nsTableCellFrame *)greatgrandchildFrame)->GetColSpan(); + for (PRInt32 i = 0; iGetColumnWidth(i+colIndex); + // subtract out cell border and padding + greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + if (PR_TRUE==gsDebugNT) + printf("%p: found a table frame %p with auto width, returning parentWidth %d from cell in col %d with span %d\n", + aReflowState.frame, table, parentWidth, colIndex, colSpan); + } + else + { + if (PR_TRUE==gsDebugNT) + printf("%p: found a table frame %p with auto width, returning parentWidth %d because parent has no info yet.\n", + aReflowState.frame, table, parentWidth); + } + } else { + nsSize tableSize; + table->GetSize(tableSize); + parentWidth = tableSize.width; + spacing->CalcBorderPaddingFor(rs->frame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the row group + childFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(childFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the row + grandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(grandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the cell + greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + if (PR_TRUE==gsDebugNT) - printf("%p: found a table frame %p with auto width, returning parentWidth %d because parent has no info yet.\n", - aReflowState.frame, table, parentWidth); + printf("%p: found a table frame %p, returning parentWidth %d from frame width %d\n", + aReflowState.frame, table, parentWidth, tableSize.width); } - + break; } - else - { - nsSize tableSize; - table->GetSize(tableSize); - parentWidth = tableSize.width; - spacing->CalcBorderPaddingFor(rs->frame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the row group - childFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(childFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the row - grandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(grandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the cell - greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - - if (PR_TRUE==gsDebugNT) - printf("%p: found a table frame %p, returning parentWidth %d from frame width %d\n", - aReflowState.frame, table, parentWidth, tableSize.width); - } - break; } if (nsnull==childFrame) diff --git a/layout/html/table/src/nsTableFrame.h b/layout/html/table/src/nsTableFrame.h index 2611ea8ac2a2..cd7c5892396c 100644 --- a/layout/html/table/src/nsTableFrame.h +++ b/layout/html/table/src/nsTableFrame.h @@ -203,6 +203,15 @@ public: PRInt32& aOutNumColumns, PRInt32 *& aOutColumnIndexes); + /** return the row span of a cell, taking into account row span magic at the bottom + * of a table. + * @param aRowIndex the first row that contains the cell + * @param aCell the content object representing the cell + * @return the row span, correcting for row spans that extend beyond the bottom + * of the table. + */ + virtual PRInt32 GetEffectiveRowSpan(PRInt32 aRowIndex, nsTableCellFrame *aCell); + // For DEBUGGING Purposes Only NS_IMETHOD MoveTo(nscoord aX, nscoord aY); NS_IMETHOD SizeTo(nscoord aWidth, nscoord aHeight); @@ -342,15 +351,6 @@ protected: void MapHTMLBorderStyle(nsStyleSpacing& aSpacingStyle, nscoord aBorderWidth); PRBool ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, PRInt32& aResult); - /** return the row span of a cell, taking into account row span magic at the bottom - * of a table. - * @param aRowIndex the first row that contains the cell - * @param aCell the content object representing the cell - * @return the row span, correcting for row spans that extend beyond the bottom - * of the table. - */ - virtual PRInt32 GetEffectiveRowSpan(PRInt32 aRowIndex, nsTableCellFrame *aCell); - /** build as much of the CellMap as possible from the info we have so far */ virtual void BuildCellMap (); diff --git a/layout/html/table/src/nsTableRowFrame.cpp b/layout/html/table/src/nsTableRowFrame.cpp index 11bd1a7b7330..56c70cd4cfd2 100644 --- a/layout/html/table/src/nsTableRowFrame.cpp +++ b/layout/html/table/src/nsTableRowFrame.cpp @@ -69,7 +69,6 @@ struct RowReflowState { nscoord maxCellHeight; nscoord maxCellVertSpace; // the maximum MAX(cellheight+top+bottom) nscoord maxCellHorzSpace; // the maximum MAX(cellheight+top+bottom) - nsTableFrame *tableFrame; @@ -105,7 +104,8 @@ nsTableRowFrame::nsTableRowFrame(nsIContent* aContent, : nsContainerFrame(aContent, aParentFrame), mTallestCell(0), mCellMaxTopMargin(0), - mCellMaxBottomMargin(0) + mCellMaxBottomMargin(0), + mMinRowSpan(1) { } @@ -221,6 +221,42 @@ PRInt32 nsTableRowFrame::GetMaxColumns() const return sum; } +/* GetMinRowSpan is needed for deviant cases where every cell in a row has a rowspan > 1. + * It sets mMinRowSpan, which is used in FixMinCellHeight and PlaceChild + */ +void nsTableRowFrame::GetMinRowSpan() +{ + PRInt32 minRowSpan=-1; + nsIFrame *frame=mFirstChild; + while (nsnull!=frame) + { + PRInt32 rowSpan = ((nsTableCellFrame *)frame)->GetRowSpan(); + if (-1==minRowSpan) + minRowSpan = rowSpan; + else if (minRowSpan>rowSpan) + minRowSpan = rowSpan; + frame->GetNextSibling(frame); + } + mMinRowSpan = minRowSpan; +} + +void nsTableRowFrame::FixMinCellHeight() +{ + nsIFrame *frame=mFirstChild; + while (nsnull!=frame) + { + PRInt32 rowSpan = ((nsTableCellFrame *)frame)->GetRowSpan(); + if (mMinRowSpan==rowSpan) + { + nsRect rect; + frame->GetRect(rect); + if (rect.height > mTallestCell) + mTallestCell = rect.height; + } + frame->GetNextSibling(frame); + } +} + // Collapse child's top margin with previous bottom margin nscoord nsTableRowFrame::GetTopMarginFor( nsIPresContext* aCX, @@ -269,16 +305,16 @@ void nsTableRowFrame::PlaceChild(nsIPresContext* aPresContext, if (nsnull != aMaxElementSize) { aMaxElementSize->width += aKidMaxElementSize.width; - if ((1==rowSpan) && (aKidMaxElementSize.height>aMaxElementSize->height)) + if ((mMinRowSpan==rowSpan) && (aKidMaxElementSize.height>aMaxElementSize->height)) { aMaxElementSize->height = aKidMaxElementSize.height; } } - if ((1==rowSpan) && (aState.maxCellHeightChildCount()) { aStatus = ReflowUnmappedChildren(aPresContext, state, aDesiredSize.maxElementSize); + GetMinRowSpan(); + FixMinCellHeight(); } } else { // We were unable to pull-up all the existing frames from the diff --git a/layout/html/table/src/nsTableRowFrame.h b/layout/html/table/src/nsTableRowFrame.h index 91a42b11e286..859656fcc9f0 100644 --- a/layout/html/table/src/nsTableRowFrame.h +++ b/layout/html/table/src/nsTableRowFrame.h @@ -133,6 +133,16 @@ protected: /** destructor */ virtual ~nsTableRowFrame(); + // row-specific methods + + void nsTableRowFrame::GetMinRowSpan(); + + void nsTableRowFrame::FixMinCellHeight(); + + + + //overrides + nscoord GetTopMarginFor(nsIPresContext* aCX, RowReflowState& aState, const nsMargin& aKidMargin); @@ -185,6 +195,7 @@ private: nscoord mTallestCell; // not my height, but the height of my tallest child nscoord mCellMaxTopMargin; nscoord mCellMaxBottomMargin; + PRInt32 mMinRowSpan; // the smallest row span among all my child cells }; diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index dca6c7a478a9..e2edb8394bff 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -2129,9 +2129,7 @@ void nsTableFrame::BalanceColumnWidths(nsIPresContext* aPresContext, if (nsnull==mColumnWidths) { mColumnWidths = new PRInt32[numCols]; - // SEC should be a memset - for (PRInt32 i = 0; iChildCount(numRows); PRInt32 *rowHeights = new PRInt32[numRows]; + nsCRT::memset (rowHeights, 0, numRows*sizeof(PRInt32)); if (gsDebug==PR_TRUE) printf("Height Step 1...\n"); for (rowIndex = 0; rowIndex < numRows; rowIndex++) { @@ -2318,7 +2317,7 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, nsTableCellFrame *cellFrame; rowFrame->ChildAt(cellIndex, (nsIFrame*&)cellFrame); - PRInt32 rowSpan = cellFrame->GetRowSpan(); + PRInt32 rowSpan = GetEffectiveRowSpan(rowIndex, cellFrame);//cellFrame->GetRowSpan(); if (1==rowSpan) { if (gsDebug==PR_TRUE) printf(" setting cell[%d,%d] height to %d\n", rowIndex, cellIndex, rowHeights[rowIndex]); @@ -2368,7 +2367,7 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, // get the next cell nsTableCellFrame *cellFrame; rowFrame->ChildAt(cellIndex, (nsIFrame*&)cellFrame); - PRInt32 rowSpan = cellFrame->GetRowSpan(); + PRInt32 rowSpan = GetEffectiveRowSpan(rowIndex, cellFrame);//cellFrame->GetRowSpan(); if (1 1, determine it's height if (gsDebug==PR_TRUE) printf(" cell[%d,%d] has a rowspan = %d\n", rowIndex, cellIndex, rowSpan); @@ -2427,7 +2426,8 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, nsTableCellFrame *frame; rowFrameToBeResized->ChildAt(j, (nsIFrame*&)frame); - if (frame->GetRowSpan()==1) + PRInt32 frameRowSpan = GetEffectiveRowSpan(i, frame); + if (frameRowSpan==1) { nsSize frameSize(0,0); @@ -3196,80 +3196,83 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) } } // or if it's another table (we're nested) use its computed width - nsIFrame* table = nsnull; - rs->frame->QueryInterface(kTableFrameCID, (void**) &table); - if (nsnull != table) { - /* We found the nearest containing table (actually, the inner table). - This defines what our percentage size is relative to. Use its desired width - as the basis for computing our width. - ********************************************************************************** - Nav4 compatibility code: if the inner table has a percent width and the outer - table has an auto width, the parentWidth is the width the containing cell would be - without the inner table. - ********************************************************************************** - */ - // Compute and subtract out the insets (sum of border and padding) for the table - nsMargin borderPadding; - /* the following hack is because the outer table really holds the position info */ - // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - nsIFrame * outerTableFrame = nsnull; - table->GetGeometricParent(outerTableFrame); - const nsStylePosition* tablePosition; - outerTableFrame->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); - const nsStyleSpacing* spacing; - outerTableFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! + if (rs->frame!=aReflowState.frame) + { + nsIFrame* table = nsnull; + rs->frame->QueryInterface(kTableFrameCID, (void**) &table); + if (nsnull != table) { + /* We found the nearest containing table (actually, the inner table). + This defines what our percentage size is relative to. Use its desired width + as the basis for computing our width. + ********************************************************************************** + Nav4 compatibility code: if the inner table has a percent width and the outer + table has an auto width, the parentWidth is the width the containing cell would be + without the inner table. + ********************************************************************************** + */ + // Compute and subtract out the insets (sum of border and padding) for the table + nsMargin borderPadding; + /* the following hack is because the outer table really holds the position info */ + // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! + nsIFrame * outerTableFrame = nsnull; + table->GetGeometricParent(outerTableFrame); + const nsStylePosition* tablePosition; + outerTableFrame->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); + const nsStyleSpacing* spacing; + outerTableFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - if (eStyleUnit_Auto == tablePosition->mWidth.GetUnit()) - { - parentWidth = 0; - if (nsnull != ((nsTableFrame*)table)->mColumnWidths) + if (eStyleUnit_Auto == tablePosition->mWidth.GetUnit()) { - PRInt32 colIndex = ((nsTableCellFrame *)greatgrandchildFrame)->GetColIndex(); - PRInt32 colSpan = ((nsTableCellFrame *)greatgrandchildFrame)->GetColSpan(); - for (PRInt32 i = 0; iGetColumnWidth(i+colIndex); - // subtract out cell border and padding - greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - if (PR_TRUE==gsDebugNT) - printf("%p: found a table frame %p with auto width, returning parentWidth %d from cell in col %d with span %d\n", - aReflowState.frame, table, parentWidth, colIndex, colSpan); + parentWidth = 0; + if (nsnull != ((nsTableFrame*)table)->mColumnWidths) + { + PRInt32 colIndex = ((nsTableCellFrame *)greatgrandchildFrame)->GetColIndex(); + PRInt32 colSpan = ((nsTableCellFrame *)greatgrandchildFrame)->GetColSpan(); + for (PRInt32 i = 0; iGetColumnWidth(i+colIndex); + // subtract out cell border and padding + greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + if (PR_TRUE==gsDebugNT) + printf("%p: found a table frame %p with auto width, returning parentWidth %d from cell in col %d with span %d\n", + aReflowState.frame, table, parentWidth, colIndex, colSpan); + } + else + { + if (PR_TRUE==gsDebugNT) + printf("%p: found a table frame %p with auto width, returning parentWidth %d because parent has no info yet.\n", + aReflowState.frame, table, parentWidth); + } + } else { + nsSize tableSize; + table->GetSize(tableSize); + parentWidth = tableSize.width; + spacing->CalcBorderPaddingFor(rs->frame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the row group + childFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(childFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the row + grandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(grandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + // same for the cell + greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); + parentWidth -= (borderPadding.right + borderPadding.left); + if (PR_TRUE==gsDebugNT) - printf("%p: found a table frame %p with auto width, returning parentWidth %d because parent has no info yet.\n", - aReflowState.frame, table, parentWidth); + printf("%p: found a table frame %p, returning parentWidth %d from frame width %d\n", + aReflowState.frame, table, parentWidth, tableSize.width); } - + break; } - else - { - nsSize tableSize; - table->GetSize(tableSize); - parentWidth = tableSize.width; - spacing->CalcBorderPaddingFor(rs->frame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the row group - childFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(childFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the row - grandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(grandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - // same for the cell - greatgrandchildFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - spacing->CalcBorderPaddingFor(greatgrandchildFrame, borderPadding); - parentWidth -= (borderPadding.right + borderPadding.left); - - if (PR_TRUE==gsDebugNT) - printf("%p: found a table frame %p, returning parentWidth %d from frame width %d\n", - aReflowState.frame, table, parentWidth, tableSize.width); - } - break; } if (nsnull==childFrame) diff --git a/layout/tables/nsTableFrame.h b/layout/tables/nsTableFrame.h index 2611ea8ac2a2..cd7c5892396c 100644 --- a/layout/tables/nsTableFrame.h +++ b/layout/tables/nsTableFrame.h @@ -203,6 +203,15 @@ public: PRInt32& aOutNumColumns, PRInt32 *& aOutColumnIndexes); + /** return the row span of a cell, taking into account row span magic at the bottom + * of a table. + * @param aRowIndex the first row that contains the cell + * @param aCell the content object representing the cell + * @return the row span, correcting for row spans that extend beyond the bottom + * of the table. + */ + virtual PRInt32 GetEffectiveRowSpan(PRInt32 aRowIndex, nsTableCellFrame *aCell); + // For DEBUGGING Purposes Only NS_IMETHOD MoveTo(nscoord aX, nscoord aY); NS_IMETHOD SizeTo(nscoord aWidth, nscoord aHeight); @@ -342,15 +351,6 @@ protected: void MapHTMLBorderStyle(nsStyleSpacing& aSpacingStyle, nscoord aBorderWidth); PRBool ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, PRInt32& aResult); - /** return the row span of a cell, taking into account row span magic at the bottom - * of a table. - * @param aRowIndex the first row that contains the cell - * @param aCell the content object representing the cell - * @return the row span, correcting for row spans that extend beyond the bottom - * of the table. - */ - virtual PRInt32 GetEffectiveRowSpan(PRInt32 aRowIndex, nsTableCellFrame *aCell); - /** build as much of the CellMap as possible from the info we have so far */ virtual void BuildCellMap (); diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index 11bd1a7b7330..56c70cd4cfd2 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -69,7 +69,6 @@ struct RowReflowState { nscoord maxCellHeight; nscoord maxCellVertSpace; // the maximum MAX(cellheight+top+bottom) nscoord maxCellHorzSpace; // the maximum MAX(cellheight+top+bottom) - nsTableFrame *tableFrame; @@ -105,7 +104,8 @@ nsTableRowFrame::nsTableRowFrame(nsIContent* aContent, : nsContainerFrame(aContent, aParentFrame), mTallestCell(0), mCellMaxTopMargin(0), - mCellMaxBottomMargin(0) + mCellMaxBottomMargin(0), + mMinRowSpan(1) { } @@ -221,6 +221,42 @@ PRInt32 nsTableRowFrame::GetMaxColumns() const return sum; } +/* GetMinRowSpan is needed for deviant cases where every cell in a row has a rowspan > 1. + * It sets mMinRowSpan, which is used in FixMinCellHeight and PlaceChild + */ +void nsTableRowFrame::GetMinRowSpan() +{ + PRInt32 minRowSpan=-1; + nsIFrame *frame=mFirstChild; + while (nsnull!=frame) + { + PRInt32 rowSpan = ((nsTableCellFrame *)frame)->GetRowSpan(); + if (-1==minRowSpan) + minRowSpan = rowSpan; + else if (minRowSpan>rowSpan) + minRowSpan = rowSpan; + frame->GetNextSibling(frame); + } + mMinRowSpan = minRowSpan; +} + +void nsTableRowFrame::FixMinCellHeight() +{ + nsIFrame *frame=mFirstChild; + while (nsnull!=frame) + { + PRInt32 rowSpan = ((nsTableCellFrame *)frame)->GetRowSpan(); + if (mMinRowSpan==rowSpan) + { + nsRect rect; + frame->GetRect(rect); + if (rect.height > mTallestCell) + mTallestCell = rect.height; + } + frame->GetNextSibling(frame); + } +} + // Collapse child's top margin with previous bottom margin nscoord nsTableRowFrame::GetTopMarginFor( nsIPresContext* aCX, @@ -269,16 +305,16 @@ void nsTableRowFrame::PlaceChild(nsIPresContext* aPresContext, if (nsnull != aMaxElementSize) { aMaxElementSize->width += aKidMaxElementSize.width; - if ((1==rowSpan) && (aKidMaxElementSize.height>aMaxElementSize->height)) + if ((mMinRowSpan==rowSpan) && (aKidMaxElementSize.height>aMaxElementSize->height)) { aMaxElementSize->height = aKidMaxElementSize.height; } } - if ((1==rowSpan) && (aState.maxCellHeightChildCount()) { aStatus = ReflowUnmappedChildren(aPresContext, state, aDesiredSize.maxElementSize); + GetMinRowSpan(); + FixMinCellHeight(); } } else { // We were unable to pull-up all the existing frames from the diff --git a/layout/tables/nsTableRowFrame.h b/layout/tables/nsTableRowFrame.h index 91a42b11e286..859656fcc9f0 100644 --- a/layout/tables/nsTableRowFrame.h +++ b/layout/tables/nsTableRowFrame.h @@ -133,6 +133,16 @@ protected: /** destructor */ virtual ~nsTableRowFrame(); + // row-specific methods + + void nsTableRowFrame::GetMinRowSpan(); + + void nsTableRowFrame::FixMinCellHeight(); + + + + //overrides + nscoord GetTopMarginFor(nsIPresContext* aCX, RowReflowState& aState, const nsMargin& aKidMargin); @@ -185,6 +195,7 @@ private: nscoord mTallestCell; // not my height, but the height of my tallest child nscoord mCellMaxTopMargin; nscoord mCellMaxBottomMargin; + PRInt32 mMinRowSpan; // the smallest row span among all my child cells };