From 28ed0c499166ae2cbbb8ddef0efa1b1c415ab672 Mon Sep 17 00:00:00 2001 From: buster Date: Tue, 30 Jun 1998 20:12:45 +0000 Subject: [PATCH] fixed-width cells no longer improperly impact the available size of subsequent cells in reflow pass 1 we correctly distribute extra space in a table proportionately. We try to give the extra space to auto-width columns first, and if there are none we distribute it to all columns. The percentage is based on the cell content's desired size. git-svn-id: svn://10.0.0.236/trunk@4722 18797224-902f-48f8-a5cc-f745e15eee43 --- .../table/src/BasicTableLayoutStrategy.cpp | 36 ++++++++++++++----- .../layout/html/table/src/nsTableRowFrame.cpp | 3 +- .../tables/BasicTableLayoutStrategy.cpp | 36 ++++++++++++++----- mozilla/layout/tables/nsTableRowFrame.cpp | 3 +- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp b/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp index a993f3cee98..6e263133e4e 100644 --- a/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp +++ b/mozilla/layout/html/table/src/BasicTableLayoutStrategy.cpp @@ -269,7 +269,7 @@ PRBool BasicTableLayoutStrategy::AssignFixedColumnWidths(nsIPresContext* aPresCo case eStyleUnit_Coord: haveColWidth = PR_TRUE; specifiedFixedColWidth = colPosition->mWidth.GetCoordValue(); - mTableFrame->SetColumnWidth(colIndex, specifiedFixedColWidth); //QQQ add in margins + mTableFrame->SetColumnWidth(colIndex, specifiedFixedColWidth); //QQQ add in margins? break; default: @@ -335,7 +335,7 @@ PRBool BasicTableLayoutStrategy::AssignFixedColumnWidths(nsIPresContext* aPresCo if (mTableFrame->GetColumnWidth(colIndex) < widthForThisCell) { if (gsDebug) printf (" setting fixed width to %d\n",widthForThisCell); - mTableFrame->SetColumnWidth(colIndex, widthForThisCell); + mTableFrame->SetColumnWidth(colIndex, widthForThisCell); //QQQ add in margins? maxColWidth = widthForThisCell; } } @@ -489,7 +489,7 @@ PRBool BasicTableLayoutStrategy::BalanceProportionalColumns(nsIPresContext* aPre if (gsDebug) printf (" * specified width table > maxTableWidth, calling BalanceColumnsTableFits\n"); result = BalanceColumnsTableFits(aPresContext, aReflowState, aAvailWidth, aMaxWidth, aTableFixedWidth); } - else if (aTableFixedWidthElementAt(cellIndex)); if (nsnull == data) { - // For cells that span rows there's only cell layout data for the first row + // For cells that span columns there's only cell layout data for the first column continue; } @@ -963,13 +963,20 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aTableFixedWidth, PRInt32 i; for (i = 0; iGetColumnWidth(autoColumns[i]); } // 2. next, compute the proportion to be added to each column, and add it for (i = 0; iGetColumnWidth(autoColumns[i]); float percent; if (0!=totalWidthOfAutoColumns) percent = (float)oldColWidth/(float)totalWidthOfAutoColumns; @@ -978,14 +985,13 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aTableFixedWidth, nscoord excessForThisColumn = (nscoord)(excess*percent); nscoord colWidth = excessForThisColumn+oldColWidth; if (gsDebug==PR_TRUE) - printf(" column %d was %d, now set to %d\n", + printf(" distribute excess to auto columns: column %d was %d, now set to %d\n", colIndex, aColWidths[colIndex], colWidth); mTableFrame->SetColumnWidth(colIndex, colWidth); } } // otherwise, distribute the space between all the columns // (they must be all fixed and percentage-width columns, or we would have gone into the block above) - // TODO - should extra space be proportionately distributed? XXX else { nscoord excessPerColumn = excess/aNumCols; @@ -993,7 +999,19 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aTableFixedWidth, printf(" aTableFixedWidth specified as %d, expanding columns by excess = %d\n", aTableFixedWidth, excess); for (PRInt32 colIndex = 0; colIndexGetColumnWidth(colIndex); + nscoord oldColWidth = aColWidths[colIndex]; + if (0==oldColWidth) + oldColWidth = mTableFrame->GetColumnWidth(colIndex); + float percent; + if (0!=aComputedTableWidth) + percent = (float)oldColWidth/(float)aComputedTableWidth; + else + percent = (float)1/(float)aNumCols; + nscoord excessForThisColumn = (nscoord)(excess*percent); + nscoord colWidth = excessForThisColumn+oldColWidth; + if (gsDebug==PR_TRUE) + printf(" distribute excess to all columns: column %d was %d, now set to %d\n", + colIndex, aColWidths[colIndex], colWidth); mTableFrame->SetColumnWidth(colIndex, colWidth); } } diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.cpp b/mozilla/layout/html/table/src/nsTableRowFrame.cpp index 6f3cb71b120..4391b5c988a 100644 --- a/mozilla/layout/html/table/src/nsTableRowFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowFrame.cpp @@ -922,7 +922,6 @@ nsTableRowFrame::ReflowUnmappedChildren( nsIPresContext* aPresContext, // Place our children, one at a time, until we are out of children nsSize kidMaxElementSize(0,0); nsSize* pKidMaxElementSize = (nsnull != aMaxElementSize) ? &kidMaxElementSize : nsnull; - nsSize kidAvailSize(aState.availSize); PRInt32 kidIndex = NextChildOffset(); nsIFrame* prevKidFrame; @@ -950,7 +949,7 @@ nsTableRowFrame::ReflowUnmappedChildren( nsIPresContext* aPresContext, } nsIFrame* kidFrame; - + nsSize kidAvailSize(aState.availSize); // Create a child frame -- always an nsTableCell frame nsIStyleContext* kidStyleContext = aPresContext->ResolveStyleContextFor(cell, this, PR_TRUE); if (nsnull == kidPrevInFlow) { diff --git a/mozilla/layout/tables/BasicTableLayoutStrategy.cpp b/mozilla/layout/tables/BasicTableLayoutStrategy.cpp index a993f3cee98..6e263133e4e 100644 --- a/mozilla/layout/tables/BasicTableLayoutStrategy.cpp +++ b/mozilla/layout/tables/BasicTableLayoutStrategy.cpp @@ -269,7 +269,7 @@ PRBool BasicTableLayoutStrategy::AssignFixedColumnWidths(nsIPresContext* aPresCo case eStyleUnit_Coord: haveColWidth = PR_TRUE; specifiedFixedColWidth = colPosition->mWidth.GetCoordValue(); - mTableFrame->SetColumnWidth(colIndex, specifiedFixedColWidth); //QQQ add in margins + mTableFrame->SetColumnWidth(colIndex, specifiedFixedColWidth); //QQQ add in margins? break; default: @@ -335,7 +335,7 @@ PRBool BasicTableLayoutStrategy::AssignFixedColumnWidths(nsIPresContext* aPresCo if (mTableFrame->GetColumnWidth(colIndex) < widthForThisCell) { if (gsDebug) printf (" setting fixed width to %d\n",widthForThisCell); - mTableFrame->SetColumnWidth(colIndex, widthForThisCell); + mTableFrame->SetColumnWidth(colIndex, widthForThisCell); //QQQ add in margins? maxColWidth = widthForThisCell; } } @@ -489,7 +489,7 @@ PRBool BasicTableLayoutStrategy::BalanceProportionalColumns(nsIPresContext* aPre if (gsDebug) printf (" * specified width table > maxTableWidth, calling BalanceColumnsTableFits\n"); result = BalanceColumnsTableFits(aPresContext, aReflowState, aAvailWidth, aMaxWidth, aTableFixedWidth); } - else if (aTableFixedWidthElementAt(cellIndex)); if (nsnull == data) { - // For cells that span rows there's only cell layout data for the first row + // For cells that span columns there's only cell layout data for the first column continue; } @@ -963,13 +963,20 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aTableFixedWidth, PRInt32 i; for (i = 0; iGetColumnWidth(autoColumns[i]); } // 2. next, compute the proportion to be added to each column, and add it for (i = 0; iGetColumnWidth(autoColumns[i]); float percent; if (0!=totalWidthOfAutoColumns) percent = (float)oldColWidth/(float)totalWidthOfAutoColumns; @@ -978,14 +985,13 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aTableFixedWidth, nscoord excessForThisColumn = (nscoord)(excess*percent); nscoord colWidth = excessForThisColumn+oldColWidth; if (gsDebug==PR_TRUE) - printf(" column %d was %d, now set to %d\n", + printf(" distribute excess to auto columns: column %d was %d, now set to %d\n", colIndex, aColWidths[colIndex], colWidth); mTableFrame->SetColumnWidth(colIndex, colWidth); } } // otherwise, distribute the space between all the columns // (they must be all fixed and percentage-width columns, or we would have gone into the block above) - // TODO - should extra space be proportionately distributed? XXX else { nscoord excessPerColumn = excess/aNumCols; @@ -993,7 +999,19 @@ void BasicTableLayoutStrategy::DistributeExcessSpace(nscoord aTableFixedWidth, printf(" aTableFixedWidth specified as %d, expanding columns by excess = %d\n", aTableFixedWidth, excess); for (PRInt32 colIndex = 0; colIndexGetColumnWidth(colIndex); + nscoord oldColWidth = aColWidths[colIndex]; + if (0==oldColWidth) + oldColWidth = mTableFrame->GetColumnWidth(colIndex); + float percent; + if (0!=aComputedTableWidth) + percent = (float)oldColWidth/(float)aComputedTableWidth; + else + percent = (float)1/(float)aNumCols; + nscoord excessForThisColumn = (nscoord)(excess*percent); + nscoord colWidth = excessForThisColumn+oldColWidth; + if (gsDebug==PR_TRUE) + printf(" distribute excess to all columns: column %d was %d, now set to %d\n", + colIndex, aColWidths[colIndex], colWidth); mTableFrame->SetColumnWidth(colIndex, colWidth); } } diff --git a/mozilla/layout/tables/nsTableRowFrame.cpp b/mozilla/layout/tables/nsTableRowFrame.cpp index 6f3cb71b120..4391b5c988a 100644 --- a/mozilla/layout/tables/nsTableRowFrame.cpp +++ b/mozilla/layout/tables/nsTableRowFrame.cpp @@ -922,7 +922,6 @@ nsTableRowFrame::ReflowUnmappedChildren( nsIPresContext* aPresContext, // Place our children, one at a time, until we are out of children nsSize kidMaxElementSize(0,0); nsSize* pKidMaxElementSize = (nsnull != aMaxElementSize) ? &kidMaxElementSize : nsnull; - nsSize kidAvailSize(aState.availSize); PRInt32 kidIndex = NextChildOffset(); nsIFrame* prevKidFrame; @@ -950,7 +949,7 @@ nsTableRowFrame::ReflowUnmappedChildren( nsIPresContext* aPresContext, } nsIFrame* kidFrame; - + nsSize kidAvailSize(aState.availSize); // Create a child frame -- always an nsTableCell frame nsIStyleContext* kidStyleContext = aPresContext->ResolveStyleContextFor(cell, this, PR_TRUE); if (nsnull == kidPrevInFlow) {