From 5186834e8087ad38e44d5d77973685cf25e4276e Mon Sep 17 00:00:00 2001 From: Elika Etemad Date: Wed, 18 Jul 2012 10:26:05 -0400 Subject: [PATCH] Bug 774835: Refactor nsHTMLReflowState::ApplyMinMaxConstraints to separate behavior of width and height. [r=roc] --HG-- extra : rebase_source : c6a25e9c19c65d86013ddf8afc15026ca02321c4 --- layout/forms/nsListControlFrame.cpp | 4 ++-- layout/generic/nsBlockFrame.cpp | 8 +++----- layout/generic/nsGfxScrollFrame.cpp | 3 ++- layout/generic/nsHTMLReflowState.cpp | 19 ------------------- layout/generic/nsHTMLReflowState.h | 22 ++++++++++++++++++---- layout/xul/base/src/nsBoxFrame.cpp | 2 +- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 98de719b90ff..c60bcc3e1dd1 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -427,7 +427,7 @@ nsListControlFrame::Reflow(nsPresContext* aPresContext, // When not doing an initial reflow, and when the height is auto, start off // with our computed height set to what we'd expect our height to be. nscoord computedHeight = CalcIntrinsicHeight(oldHeightOfARow, length); - state.ApplyMinMaxConstraints(nsnull, &computedHeight); + computedHeight = state.ApplyMinMaxHeight(computedHeight); state.SetComputedHeight(computedHeight); } @@ -485,7 +485,7 @@ nsListControlFrame::Reflow(nsPresContext* aPresContext, // Now compute the height we want to have nscoord computedHeight = CalcIntrinsicHeight(HeightOfARow(), length); - state.ApplyMinMaxConstraints(nsnull, &computedHeight); + computedHeight = state.ApplyMinMaxHeight(computedHeight); state.SetComputedHeight(computedHeight); nsHTMLScrollFrame::WillReflow(aPresContext); diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index 46b9ba085f97..7a9b6b231b54 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -1429,11 +1429,9 @@ nsBlockFrame::ComputeFinalSize(const nsHTMLReflowState& aReflowState, aMetrics.mCarriedOutBottomMargin.Zero(); } else if (NS_FRAME_IS_COMPLETE(aState.mReflowStatus)) { - nscoord autoHeight = bottomEdgeOfChildren; - autoHeight -= borderPadding.top; - nscoord oldAutoHeight = autoHeight; - aReflowState.ApplyMinMaxConstraints(nsnull, &autoHeight); - if (autoHeight != oldAutoHeight) { + nscoord contentHeight = bottomEdgeOfChildren - borderPadding.top; + nscoord autoHeight = aReflowState.ApplyMinMaxHeight(contentHeight); + if (autoHeight != contentHeight) { // Our min-height or max-height made our height change. Don't carry out // our kids' bottom margins. aMetrics.mCarriedOutBottomMargin.Zero(); diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 33af8d46f8f6..4261e14c9b47 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -298,7 +298,8 @@ static nsSize ComputeInsideBorderSize(ScrollReflowState* aState, aState->mReflowState.mComputedPadding.TopBottom(); } - aState->mReflowState.ApplyMinMaxConstraints(&contentWidth, &contentHeight); + contentWidth = aState->mReflowState.ApplyMinMaxWidth(contentWidth); + contentHeight = aState->mReflowState.ApplyMinMaxHeight(contentHeight); return nsSize(contentWidth + aState->mReflowState.mComputedPadding.LeftRight(), contentHeight + aState->mReflowState.mComputedPadding.TopBottom()); } diff --git a/layout/generic/nsHTMLReflowState.cpp b/layout/generic/nsHTMLReflowState.cpp index 692de1b5c6d3..4b641b7cc08f 100644 --- a/layout/generic/nsHTMLReflowState.cpp +++ b/layout/generic/nsHTMLReflowState.cpp @@ -2426,25 +2426,6 @@ nsCSSOffsetState::ComputePadding(nscoord aContainingBlockWidth, nsIAtom* aFrameT return isWidthDependent; } -void -nsHTMLReflowState::ApplyMinMaxConstraints(nscoord* aFrameWidth, - nscoord* aFrameHeight) const -{ - if (aFrameWidth) { - if (NS_UNCONSTRAINEDSIZE != mComputedMaxWidth) { - *aFrameWidth = NS_MIN(*aFrameWidth, mComputedMaxWidth); - } - *aFrameWidth = NS_MAX(*aFrameWidth, mComputedMinWidth); - } - - if (aFrameHeight) { - if (NS_UNCONSTRAINEDSIZE != mComputedMaxHeight) { - *aFrameHeight = NS_MIN(*aFrameHeight, mComputedMaxHeight); - } - *aFrameHeight = NS_MAX(*aFrameHeight, mComputedMinHeight); - } -} - void nsHTMLReflowState::ComputeMinMaxValues(nscoord aContainingBlockWidth, nscoord aContainingBlockHeight, diff --git a/layout/generic/nsHTMLReflowState.h b/layout/generic/nsHTMLReflowState.h index 127aedc35a46..8fcbaff743d9 100644 --- a/layout/generic/nsHTMLReflowState.h +++ b/layout/generic/nsHTMLReflowState.h @@ -413,11 +413,25 @@ public: nscoord& aContainingBlockHeight); /** - * Apply the mComputed(Min/Max)(Width/Height) values to the content - * size computed so far. If a passed-in pointer is null, we skip - * adjusting that dimension. + * Apply the mComputed(Min/Max)Width constraints to the content + * size computed so far. */ - void ApplyMinMaxConstraints(nscoord* aContentWidth, nscoord* aContentHeight) const; + nscoord ApplyMinMaxWidth(nscoord aWidth) const { + if (NS_UNCONSTRAINEDSIZE != mComputedMaxWidth) { + aWidth = NS_MIN(aWidth, mComputedMaxWidth); + } + return NS_MAX(aWidth, mComputedMinWidth); + } + /** + * Apply the mComputed(Min/Max)Height constraints to the content + * size computed so far. + */ + nscoord ApplyMinMaxHeight(nscoord aHeight) const { + if (NS_UNCONSTRAINEDSIZE != mComputedMaxHeight) { + aHeight = NS_MIN(aHeight, mComputedMaxHeight); + } + return NS_MAX(aHeight, mComputedMinHeight); + } bool ShouldReflowAllKids() const { // Note that we could make a stronger optimization for mVResize if diff --git a/layout/xul/base/src/nsBoxFrame.cpp b/layout/xul/base/src/nsBoxFrame.cpp index 817b729a9d9d..0159bbda6b0f 100644 --- a/layout/xul/base/src/nsBoxFrame.cpp +++ b/layout/xul/base/src/nsBoxFrame.cpp @@ -688,7 +688,7 @@ nsBoxFrame::Reflow(nsPresContext* aPresContext, computedSize.height -= outsideBoxSizing; // Note: might be negative now, but that's OK because min-width is // never negative. - aReflowState.ApplyMinMaxConstraints(nsnull, &computedSize.height); + computedSize.height = aReflowState.ApplyMinMaxHeight(computedSize.height); computedSize.height += outsideBoxSizing; } else { computedSize.height += m.top + m.bottom;