From e763429e44d4d3d3c69bced1235e2cc965ef97b1 Mon Sep 17 00:00:00 2001 From: "bmlk%gmx.de" Date: Mon, 29 Dec 2003 16:58:20 +0000 Subject: [PATCH] prescontext removal part 2 bug 229631 r/sr=roc --- .../html/table/src/BasicTableLayoutStrategy.h | 2 -- .../table/src/FixedTableLayoutStrategy.cpp | 28 +++++++++---------- .../html/table/src/FixedTableLayoutStrategy.h | 10 ++----- layout/tables/BasicTableLayoutStrategy.h | 2 -- layout/tables/FixedTableLayoutStrategy.cpp | 28 +++++++++---------- layout/tables/FixedTableLayoutStrategy.h | 10 ++----- 6 files changed, 34 insertions(+), 46 deletions(-) diff --git a/layout/html/table/src/BasicTableLayoutStrategy.h b/layout/html/table/src/BasicTableLayoutStrategy.h index e69103803f05..de614f491c16 100644 --- a/layout/html/table/src/BasicTableLayoutStrategy.h +++ b/layout/html/table/src/BasicTableLayoutStrategy.h @@ -102,8 +102,6 @@ protected: * Computes the minimum and maximum table widths. * Set column width information in each column frame and in the table frame. * - * @param aMaxWidth - the computed width of the table or - * UNCONSTRAINED_SIZE if an auto width table * @return PR_TRUE has a pct cell or col, PR_FALSE otherwise */ virtual PRBool AssignNonPctColumnWidths(nscoord aComputedWidth, diff --git a/layout/html/table/src/FixedTableLayoutStrategy.cpp b/layout/html/table/src/FixedTableLayoutStrategy.cpp index 0a37e824c129..8594feaa6679 100644 --- a/layout/html/table/src/FixedTableLayoutStrategy.cpp +++ b/layout/html/table/src/FixedTableLayoutStrategy.cpp @@ -64,10 +64,8 @@ PRBool FixedTableLayoutStrategy::BalanceColumnWidths(const nsHTMLReflowState& aR * as determined by the table width attribute. If no table width attribute, it gets 0 width */ PRBool -FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPresContext, - nscoord aComputedWidth, - const nsHTMLReflowState& aReflowState, - float aPixelToTwips) +FixedTableLayoutStrategy::AssignNonPctColumnWidths(nscoord aComputedWidth, + const nsHTMLReflowState& aReflowState) { // NS_ASSERTION(aComputedWidth != NS_UNCONSTRAINEDSIZE, "bad computed width"); const nsStylePosition* tablePosition = mTableFrame->GetStylePosition(); @@ -76,6 +74,8 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre PRInt32 numCols = mTableFrame->GetColCount(); PRInt32 colX; + float pixelToTwips; + mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&pixelToTwips); // availWidth is used as the basis for percentage width columns. It is aComputedWidth // minus table border, padding, & cellspacing nscoord spacingX = mTableFrame->GetCellSpacingX(); @@ -128,7 +128,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre (aComputedWidth != NS_UNCONSTRAINEDSIZE)) { // Only apply percentages if we're constrained. float percent = colPosition->mWidth.GetPercentValue(); - colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(percent * (float)availWidth), aPixelToTwips); + colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(percent * (float)availWidth), pixelToTwips); colFrame->SetWidth(PCT, colWidths[colX]); percTotal+=colWidths[colX]; } @@ -150,10 +150,10 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre if (eStyleUnit_Coord == cellPosition->mWidth.GetUnit()) { // need to add border and padding into fixed width nsMargin borderPadding = nsTableFrame::GetBorderPadding(nsSize(aReflowState.mComputedWidth, 0), - aPixelToTwips, cellFrame); + pixelToTwips, cellFrame); cellWidth = cellPosition->mWidth.GetCoordValue() + borderPadding.left + borderPadding.right; colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(((float) cellWidth) / ((float) colSpan)), - aPixelToTwips); + pixelToTwips); colFrame->SetWidth(MIN_CON, colWidths[colX]); } else if ((eStyleUnit_Percent == cellPosition->mWidth.GetUnit()) && @@ -161,10 +161,10 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre float percent = cellPosition->mWidth.GetPercentValue(); // need to add border and padding into percent width nsMargin borderPadding = nsTableFrame::GetBorderPadding(nsSize(aReflowState.mComputedWidth, 0), - aPixelToTwips, cellFrame); + pixelToTwips, cellFrame); cellWidth = NSToCoordRound(percent * (float) availWidth) + borderPadding.left + borderPadding.right; colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(((float) cellWidth) / ((float) colSpan)), - aPixelToTwips); + pixelToTwips); colFrame->SetWidth(PCT, colWidths[colX]); percTotal += colWidths[colX]; } @@ -194,7 +194,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre float percent = ((float)propInfo[colX])/((float)propTotal); amountToAllocate += NSToCoordRound(percent * (float)remainingWidth); colWidths[colX] = (amountToAllocate > 0) ? - nsTableFrame::RoundToPixel(amountToAllocate, aPixelToTwips, + nsTableFrame::RoundToPixel(amountToAllocate, pixelToTwips, eRoundUpIfHalfOrMore) : 0; totalColWidth += colWidths[colX]; amountToAllocate -= colWidths[colX]; @@ -214,7 +214,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre amountToAllocate += colAlloc; colWidths[colX] = (amountToAllocate > 0) ? nsTableFrame::RoundToPixel(amountToAllocate, - aPixelToTwips, + pixelToTwips, eRoundUpIfHalfOrMore) : 0; totalColWidth += colWidths[colX]; amountToAllocate -= colWidths[colX]; @@ -229,7 +229,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre if (colWidths[colX] > 0) { amountToAllocate += NSToCoordRound(remainingWidth * colWidths[colX] / divisor); nscoord colAlloc = (amountToAllocate > 0) ? - nsTableFrame::RoundToPixel(amountToAllocate, aPixelToTwips, + nsTableFrame::RoundToPixel(amountToAllocate, pixelToTwips, eRoundUpIfHalfOrMore) : 0; colWidths[colX] += colAlloc; totalColWidth += colAlloc; @@ -249,7 +249,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre colWidths[colX] = 0; // if there was too much allocated due to rounding, remove it from the last col if ((colX == lastColAllocated) && (overAllocation != 0)) { - nscoord thisRemoval = nsTableFrame::RoundToPixel(overAllocation, aPixelToTwips); + nscoord thisRemoval = nsTableFrame::RoundToPixel(overAllocation, pixelToTwips); colWidths[colX] -= thisRemoval; totalColWidth -= thisRemoval; @@ -267,7 +267,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre if(( colFrame->GetWidth(PCT) > 0) && ( percTotal > 0)){ amountToRemove += NSToCoordRound(overAllocation* colWidths[colX] / (float) percTotal); nscoord thisRemoval = (amountToRemove > 0) ? - nsTableFrame::RoundToPixel(amountToRemove, aPixelToTwips, + nsTableFrame::RoundToPixel(amountToRemove, pixelToTwips, eRoundUpIfHalfOrMore) : 0; colWidths[colX] -= thisRemoval; amountToRemove -= thisRemoval; diff --git a/layout/html/table/src/FixedTableLayoutStrategy.h b/layout/html/table/src/FixedTableLayoutStrategy.h index 562b8ff6f195..e49961f310f5 100644 --- a/layout/html/table/src/FixedTableLayoutStrategy.h +++ b/layout/html/table/src/FixedTableLayoutStrategy.h @@ -76,12 +76,10 @@ public: * Calculate the basis for percent width calculations of the table elements * @param aReflowState - the reflow state of the table * @param aAvailWidth - the available width for the table - * @param aPixelToTwips - the number of twips in a pixel. * @return - the basis for percent calculations */ virtual nscoord CalcPctAdjTableWidth(const nsHTMLReflowState& aReflowState, - nscoord aAvailWidth, - float aPixelToTwips) {return 0;}; + nscoord aAvailWidth) {return 0;}; protected: /* assign the width of all columns @@ -97,10 +95,8 @@ protected: * @return PR_TRUE if all is well, PR_FALSE if there was an unrecoverable error * */ - virtual PRBool AssignNonPctColumnWidths(nsIPresContext* aPresContext, - nscoord aComputedWidth, - const nsHTMLReflowState& aReflowState, - float aPixelToTwips); + virtual PRBool AssignNonPctColumnWidths(nscoord aComputedWidth, + const nsHTMLReflowState& aReflowState); }; diff --git a/layout/tables/BasicTableLayoutStrategy.h b/layout/tables/BasicTableLayoutStrategy.h index e69103803f05..de614f491c16 100644 --- a/layout/tables/BasicTableLayoutStrategy.h +++ b/layout/tables/BasicTableLayoutStrategy.h @@ -102,8 +102,6 @@ protected: * Computes the minimum and maximum table widths. * Set column width information in each column frame and in the table frame. * - * @param aMaxWidth - the computed width of the table or - * UNCONSTRAINED_SIZE if an auto width table * @return PR_TRUE has a pct cell or col, PR_FALSE otherwise */ virtual PRBool AssignNonPctColumnWidths(nscoord aComputedWidth, diff --git a/layout/tables/FixedTableLayoutStrategy.cpp b/layout/tables/FixedTableLayoutStrategy.cpp index 0a37e824c129..8594feaa6679 100644 --- a/layout/tables/FixedTableLayoutStrategy.cpp +++ b/layout/tables/FixedTableLayoutStrategy.cpp @@ -64,10 +64,8 @@ PRBool FixedTableLayoutStrategy::BalanceColumnWidths(const nsHTMLReflowState& aR * as determined by the table width attribute. If no table width attribute, it gets 0 width */ PRBool -FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPresContext, - nscoord aComputedWidth, - const nsHTMLReflowState& aReflowState, - float aPixelToTwips) +FixedTableLayoutStrategy::AssignNonPctColumnWidths(nscoord aComputedWidth, + const nsHTMLReflowState& aReflowState) { // NS_ASSERTION(aComputedWidth != NS_UNCONSTRAINEDSIZE, "bad computed width"); const nsStylePosition* tablePosition = mTableFrame->GetStylePosition(); @@ -76,6 +74,8 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre PRInt32 numCols = mTableFrame->GetColCount(); PRInt32 colX; + float pixelToTwips; + mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&pixelToTwips); // availWidth is used as the basis for percentage width columns. It is aComputedWidth // minus table border, padding, & cellspacing nscoord spacingX = mTableFrame->GetCellSpacingX(); @@ -128,7 +128,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre (aComputedWidth != NS_UNCONSTRAINEDSIZE)) { // Only apply percentages if we're constrained. float percent = colPosition->mWidth.GetPercentValue(); - colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(percent * (float)availWidth), aPixelToTwips); + colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(percent * (float)availWidth), pixelToTwips); colFrame->SetWidth(PCT, colWidths[colX]); percTotal+=colWidths[colX]; } @@ -150,10 +150,10 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre if (eStyleUnit_Coord == cellPosition->mWidth.GetUnit()) { // need to add border and padding into fixed width nsMargin borderPadding = nsTableFrame::GetBorderPadding(nsSize(aReflowState.mComputedWidth, 0), - aPixelToTwips, cellFrame); + pixelToTwips, cellFrame); cellWidth = cellPosition->mWidth.GetCoordValue() + borderPadding.left + borderPadding.right; colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(((float) cellWidth) / ((float) colSpan)), - aPixelToTwips); + pixelToTwips); colFrame->SetWidth(MIN_CON, colWidths[colX]); } else if ((eStyleUnit_Percent == cellPosition->mWidth.GetUnit()) && @@ -161,10 +161,10 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre float percent = cellPosition->mWidth.GetPercentValue(); // need to add border and padding into percent width nsMargin borderPadding = nsTableFrame::GetBorderPadding(nsSize(aReflowState.mComputedWidth, 0), - aPixelToTwips, cellFrame); + pixelToTwips, cellFrame); cellWidth = NSToCoordRound(percent * (float) availWidth) + borderPadding.left + borderPadding.right; colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(((float) cellWidth) / ((float) colSpan)), - aPixelToTwips); + pixelToTwips); colFrame->SetWidth(PCT, colWidths[colX]); percTotal += colWidths[colX]; } @@ -194,7 +194,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre float percent = ((float)propInfo[colX])/((float)propTotal); amountToAllocate += NSToCoordRound(percent * (float)remainingWidth); colWidths[colX] = (amountToAllocate > 0) ? - nsTableFrame::RoundToPixel(amountToAllocate, aPixelToTwips, + nsTableFrame::RoundToPixel(amountToAllocate, pixelToTwips, eRoundUpIfHalfOrMore) : 0; totalColWidth += colWidths[colX]; amountToAllocate -= colWidths[colX]; @@ -214,7 +214,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre amountToAllocate += colAlloc; colWidths[colX] = (amountToAllocate > 0) ? nsTableFrame::RoundToPixel(amountToAllocate, - aPixelToTwips, + pixelToTwips, eRoundUpIfHalfOrMore) : 0; totalColWidth += colWidths[colX]; amountToAllocate -= colWidths[colX]; @@ -229,7 +229,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre if (colWidths[colX] > 0) { amountToAllocate += NSToCoordRound(remainingWidth * colWidths[colX] / divisor); nscoord colAlloc = (amountToAllocate > 0) ? - nsTableFrame::RoundToPixel(amountToAllocate, aPixelToTwips, + nsTableFrame::RoundToPixel(amountToAllocate, pixelToTwips, eRoundUpIfHalfOrMore) : 0; colWidths[colX] += colAlloc; totalColWidth += colAlloc; @@ -249,7 +249,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre colWidths[colX] = 0; // if there was too much allocated due to rounding, remove it from the last col if ((colX == lastColAllocated) && (overAllocation != 0)) { - nscoord thisRemoval = nsTableFrame::RoundToPixel(overAllocation, aPixelToTwips); + nscoord thisRemoval = nsTableFrame::RoundToPixel(overAllocation, pixelToTwips); colWidths[colX] -= thisRemoval; totalColWidth -= thisRemoval; @@ -267,7 +267,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nsIPresContext* aPre if(( colFrame->GetWidth(PCT) > 0) && ( percTotal > 0)){ amountToRemove += NSToCoordRound(overAllocation* colWidths[colX] / (float) percTotal); nscoord thisRemoval = (amountToRemove > 0) ? - nsTableFrame::RoundToPixel(amountToRemove, aPixelToTwips, + nsTableFrame::RoundToPixel(amountToRemove, pixelToTwips, eRoundUpIfHalfOrMore) : 0; colWidths[colX] -= thisRemoval; amountToRemove -= thisRemoval; diff --git a/layout/tables/FixedTableLayoutStrategy.h b/layout/tables/FixedTableLayoutStrategy.h index 562b8ff6f195..e49961f310f5 100644 --- a/layout/tables/FixedTableLayoutStrategy.h +++ b/layout/tables/FixedTableLayoutStrategy.h @@ -76,12 +76,10 @@ public: * Calculate the basis for percent width calculations of the table elements * @param aReflowState - the reflow state of the table * @param aAvailWidth - the available width for the table - * @param aPixelToTwips - the number of twips in a pixel. * @return - the basis for percent calculations */ virtual nscoord CalcPctAdjTableWidth(const nsHTMLReflowState& aReflowState, - nscoord aAvailWidth, - float aPixelToTwips) {return 0;}; + nscoord aAvailWidth) {return 0;}; protected: /* assign the width of all columns @@ -97,10 +95,8 @@ protected: * @return PR_TRUE if all is well, PR_FALSE if there was an unrecoverable error * */ - virtual PRBool AssignNonPctColumnWidths(nsIPresContext* aPresContext, - nscoord aComputedWidth, - const nsHTMLReflowState& aReflowState, - float aPixelToTwips); + virtual PRBool AssignNonPctColumnWidths(nscoord aComputedWidth, + const nsHTMLReflowState& aReflowState); };