From 1b29a31cc13b6463e8f698b70aa9b44cf58633d8 Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Fri, 20 Nov 1998 22:27:21 +0000 Subject: [PATCH] Work around more bugs in the style context code and use old margin calculations; factored get-containing-block-width better --- layout/html/base/src/nsFrameReflowState.cpp | 67 +++++++++++++-------- layout/html/base/src/nsIHTMLReflow.h | 14 ++++- 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/layout/html/base/src/nsFrameReflowState.cpp b/layout/html/base/src/nsFrameReflowState.cpp index 2d80172051f..3423d1548cf 100644 --- a/layout/html/base/src/nsFrameReflowState.cpp +++ b/layout/html/base/src/nsFrameReflowState.cpp @@ -57,32 +57,40 @@ nsHTMLReflowState::GetPageBoxReflowState(const nsReflowState* aParentRS) } nscoord -nsHTMLReflowState::GetContainingBlockContentWidth() const +nsHTMLReflowState::GetContainingBlockContentWidth(const nsReflowState* aParentRS) { nscoord width = 0; const nsHTMLReflowState* rs = - GetContainingBlockReflowState(parentReflowState); + GetContainingBlockReflowState(aParentRS); if (nsnull != rs) { - if (rs->HaveFixedContentWidth()) { - width = rs->minWidth; - } - else if (NS_UNCONSTRAINEDSIZE != rs->maxSize.width) { - width = rs->maxSize.width; - if (nsnull != rs->frame) { - // Subtract out the border and padding values because the - // percentage is to be computed relative to the content - // width, not the outer width. - const nsStyleSpacing* spacing; - nsresult rv; - rv = rs->frame->GetStyleData(eStyleStruct_Spacing, - (const nsStyleStruct*&) spacing); - if (NS_SUCCEEDED(rv) && (nsnull != spacing)) { - nsMargin borderPadding; - rs->ComputeBorderPaddingFor(rs->frame, - (nsHTMLReflowState*) rs->parentReflowState, - borderPadding); - width -= borderPadding.left + borderPadding.right; - } + return ((nsHTMLReflowState*)aParentRS)->GetContentWidth();/* XXX cast */ + } + return width; +} + +nscoord +nsHTMLReflowState::GetContentWidth() const +{ + nscoord width = 0; + if (HaveFixedContentWidth()) { + width = minWidth; + } + else if (NS_UNCONSTRAINEDSIZE != maxSize.width) { + width = maxSize.width; + if (nsnull != frame) { + // Subtract out the border and padding values because the + // percentage is to be computed relative to the content + // width, not the outer width. + const nsStyleSpacing* spacing; + nsresult rv; + rv = frame->GetStyleData(eStyleStruct_Spacing, + (const nsStyleStruct*&) spacing); + if (NS_SUCCEEDED(rv) && (nsnull != spacing)) { + nsMargin borderPadding; + ComputeBorderPaddingFor(frame, + parentReflowState, + borderPadding); + width -= borderPadding.left + borderPadding.right; } } } @@ -318,7 +326,7 @@ nsHTMLReflowState::ComputeHorizontalValue(const nsHTMLReflowState& aRS, { aResult = 0; if (eStyleUnit_Percent == aUnit) { - nscoord width = aRS.GetContainingBlockContentWidth(); + nscoord width = aRS.GetContentWidth(); float pct = aCoord.GetPercentValue(); aResult = NSToCoordFloor(width * pct); } @@ -333,7 +341,7 @@ nsHTMLReflowState::ComputeVerticalValue(const nsHTMLReflowState& aRS, aResult = 0; if (eStyleUnit_Percent == aUnit) { // XXX temporary! - nscoord width = aRS.GetContainingBlockContentWidth(); + nscoord width = aRS.GetContentWidth(); float pct = aCoord.GetPercentValue(); aResult = NSToCoordFloor(width * pct); } @@ -350,7 +358,16 @@ nsHTMLReflowState::ComputeMarginFor(nsIFrame* aFrame, (const nsStyleStruct*&) spacing); if (NS_SUCCEEDED(rv) && (nsnull != spacing)) { // If style style can provide us the margin directly, then use it. - if (!spacing->GetMargin(aResult) && (nsnull != aParentRS)) { +#if 0 + if (!spacing->GetMargin(aResult) && (nsnull != aParentRS)) +#else + spacing->CalcMarginFor(aFrame, aResult); + if ((eStyleUnit_Percent == spacing->mMargin.GetTopUnit()) || + (eStyleUnit_Percent == spacing->mMargin.GetRightUnit()) || + (eStyleUnit_Percent == spacing->mMargin.GetBottomUnit()) || + (eStyleUnit_Percent == spacing->mMargin.GetLeftUnit())) +#endif + { // We have to compute the value (because it's uncomputable by // the style code). const nsHTMLReflowState* rs = GetContainingBlockReflowState(aParentRS); diff --git a/layout/html/base/src/nsIHTMLReflow.h b/layout/html/base/src/nsIHTMLReflow.h index 395af52b7b5..c7dea0ef424 100644 --- a/layout/html/base/src/nsIHTMLReflow.h +++ b/layout/html/base/src/nsIHTMLReflow.h @@ -224,7 +224,11 @@ struct nsHTMLReflowState : nsReflowState { return eHTMLFrameConstraint_FixedContent == heightConstraint; } - nscoord GetContainingBlockContentWidth() const; + /** + * Return the width of the content area based on this reflow state's + * state. + */ + nscoord GetContentWidth() const; /** * Get the containing block reflow state, starting from a frames @@ -234,6 +238,14 @@ struct nsHTMLReflowState : nsReflowState { static const nsHTMLReflowState* GetContainingBlockReflowState(const nsReflowState* aParentRS); + /** + * First find the containing block's reflow state using + * GetContainingBlockReflowState, then ask the containing block for + * it's content width using GetContentWidth + */ + static nscoord + GetContainingBlockContentWidth(const nsReflowState* aParentRS); + /** * Get the page box reflow state, starting from a frames * parent reflow state (the parent reflow state may or may not end