From 33a90e073e1b414c2014c7a775128c40ca83e007 Mon Sep 17 00:00:00 2001 From: buster Date: Wed, 24 Jun 1998 00:40:33 +0000 Subject: [PATCH] now tables with precent width nested within tables with auto width work git-svn-id: svn://10.0.0.236/trunk@4366 18797224-902f-48f8-a5cc-f745e15eee43 --- .../table/src/BasicTableLayoutStrategy.cpp | 21 ----- .../layout/html/table/src/nsTableFrame.cpp | 85 ++++++++++++++----- .../tables/BasicTableLayoutStrategy.cpp | 21 ----- mozilla/layout/tables/nsTableFrame.cpp | 85 ++++++++++++++----- 4 files changed, 126 insertions(+), 86 deletions(-) diff --git a/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp b/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp index 50c5c910fa7..78c926b37f8 100644 --- a/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp +++ b/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp @@ -448,27 +448,6 @@ PRBool BasicTableLayoutStrategy::AssignFixedColumnWidths(nsIPresContext* aPresCo return PR_TRUE; } - -//XXX - /********************************************************************************** - 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. - We can't compute that here in the normal flow of control, because the parent table doesn't know - it's cells' sizes. - We can keep this logic as is, and do a second pass over the table - looking for this case and patching it up (an n-squared algorithm in the worse case, though - probably linear if we do things intelligently. At best, it's another pass through the - entire table and all the nested tables. - OR - We can write some new code that's smart enough to detect this case and skip over the cell - that contains the nested table. We determine the column width normally (having skipped the cell), - Then later in reflow, given the column widths, we can compute the cell width, and assign the - nested table its correct width. - Problem with this: what if the cell containing the nested table is the only cell in the column? - **********************************************************************************/ -// end XXX - PRBool BasicTableLayoutStrategy::BalanceProportionalColumns(nsIPresContext* aPresContext, const nsReflowState& aReflowState, nscoord aAvailWidth, diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index ace952fe5a5..f71fb1d4949 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -3195,32 +3195,73 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) /* 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; + 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; - table->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - 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); + outerTableFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - 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); + if (eStyleUnit_Auto == tablePosition->mWidth.GetUnit()) + { + 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, returning parentWidth %d from frame width %d\n", + aReflowState.frame, table, parentWidth, tableSize.width); + } break; } diff --git a/mozilla/layout/tables/BasicTableLayoutStrategy.cpp b/mozilla/layout/tables/BasicTableLayoutStrategy.cpp index 50c5c910fa7..78c926b37f8 100644 --- a/mozilla/layout/tables/BasicTableLayoutStrategy.cpp +++ b/mozilla/layout/tables/BasicTableLayoutStrategy.cpp @@ -448,27 +448,6 @@ PRBool BasicTableLayoutStrategy::AssignFixedColumnWidths(nsIPresContext* aPresCo return PR_TRUE; } - -//XXX - /********************************************************************************** - 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. - We can't compute that here in the normal flow of control, because the parent table doesn't know - it's cells' sizes. - We can keep this logic as is, and do a second pass over the table - looking for this case and patching it up (an n-squared algorithm in the worse case, though - probably linear if we do things intelligently. At best, it's another pass through the - entire table and all the nested tables. - OR - We can write some new code that's smart enough to detect this case and skip over the cell - that contains the nested table. We determine the column width normally (having skipped the cell), - Then later in reflow, given the column widths, we can compute the cell width, and assign the - nested table its correct width. - Problem with this: what if the cell containing the nested table is the only cell in the column? - **********************************************************************************/ -// end XXX - PRBool BasicTableLayoutStrategy::BalanceProportionalColumns(nsIPresContext* aPresContext, const nsReflowState& aReflowState, nscoord aAvailWidth, diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index ace952fe5a5..f71fb1d4949 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -3195,32 +3195,73 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) /* 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; + 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; - table->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - 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); + outerTableFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); + // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - 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); + if (eStyleUnit_Auto == tablePosition->mWidth.GetUnit()) + { + 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, returning parentWidth %d from frame width %d\n", + aReflowState.frame, table, parentWidth, tableSize.width); + } break; }