From 38acdd1740ed089c5ffe237228fe3b1aee6957de Mon Sep 17 00:00:00 2001 From: troy Date: Sun, 3 May 1998 04:57:29 +0000 Subject: [PATCH] Added ComputeDesiredRect() to share some common code between DoResizeReflow() and IncrementalReflow() --- layout/generic/nsBlockFrame.cpp | 108 ++++++++------------ layout/generic/nsBlockFrame.h | 4 + layout/generic/nsBlockReflowState.cpp | 108 ++++++++------------ layout/generic/nsBlockReflowState.h | 108 ++++++++------------ layout/html/base/src/nsBlockFrame.cpp | 108 ++++++++------------ layout/html/base/src/nsBlockFrame.h | 4 + layout/html/base/src/nsBlockReflowState.cpp | 108 ++++++++------------ layout/html/base/src/nsBlockReflowState.h | 108 ++++++++------------ 8 files changed, 260 insertions(+), 396 deletions(-) diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index b5b5a0e5618..36fb68ba71a 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -1059,38 +1059,8 @@ nsBlockFrame::DoResizeReflow(nsBlockReflowState& aState, } } - // Return our desired rect and our status - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; - if (!aState.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + - aState.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - aState.mY += aState.mBorderPadding.bottom; - nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - - aState.mPrevMaxNegBottomMargin; - if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (aState.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - aState.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - aState.mY += lastBottomMargin; - } - aDesiredRect.height = aState.mY; + // Return our desired rect + ComputeDesiredRect(aState, aMaxSize, aDesiredRect); // Set return status aStatus = frComplete; @@ -1258,7 +1228,7 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, } // XXX This isn't really right... - state.mKidXMost = mRect.XMost(); + state.mKidXMost = mRect.width - state.mBorderPadding.right; // If the previous line is a block, then factor in its bottom margin if (prevLine->mIsBlock) { @@ -1291,39 +1261,8 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, NS_NOTYETIMPLEMENTED("unexpected reflow command"); } - // Return our desired rect and our status - // XXX Share this code with DoResizeReflow()... - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = state.mKidXMost + state.mBorderPadding.right; - if (!state.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = state.mAvailSize.width + state.mBorderPadding.left + - state.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - state.mY += state.mBorderPadding.bottom; - nscoord lastBottomMargin = state.mPrevMaxPosBottomMargin - - state.mPrevMaxNegBottomMargin; - if (!state.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (state.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - state.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - state.mY += lastBottomMargin; - } - aDesiredRect.height = state.mY; + // Return our desired rect + ComputeDesiredRect(state, aMaxSize, aDesiredRect); // Now that reflow has finished, remove the cached pointer shell->RemoveCachedData(this); @@ -1336,6 +1275,43 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, return rv; } +void nsBlockFrame::ComputeDesiredRect(nsBlockReflowState& aState, + const nsSize& aMaxSize, + nsRect& aDesiredRect) +{ + aDesiredRect.x = 0; + aDesiredRect.y = 0; + aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; + if (!aState.mUnconstrainedWidth) { + // Make sure we're at least as wide as the max size we were given + nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + + aState.mBorderPadding.right; + if (aDesiredRect.width < maxWidth) { + aDesiredRect.width = maxWidth; + } + } + aState.mY += aState.mBorderPadding.bottom; + nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - + aState.mPrevMaxNegBottomMargin; + if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { + // It's possible that we don't have room for the last bottom + // margin (the last bottom margin is the margin following a block + // element that we contain; it isn't applied immediately because + // of the margin collapsing logic). This can happen when we are + // reflowed in a limited amount of space because we don't know in + // advance what the last bottom margin will be. + nscoord maxY = aMaxSize.height; + if (aState.mY + lastBottomMargin > maxY) { + lastBottomMargin = maxY - aState.mY; + if (lastBottomMargin < 0) { + lastBottomMargin = 0; + } + } + aState.mY += lastBottomMargin; + } + aDesiredRect.height = aState.mY; +} + //---------------------------------------------------------------------- PRBool diff --git a/layout/generic/nsBlockFrame.h b/layout/generic/nsBlockFrame.h index f3fa810539b..99b37464984 100644 --- a/layout/generic/nsBlockFrame.h +++ b/layout/generic/nsBlockFrame.h @@ -245,6 +245,10 @@ protected: nsRect& aDesiredRect, ReflowStatus& aStatus); + void ComputeDesiredRect(nsBlockReflowState& aState, + const nsSize& aMaxSize, + nsRect& aDesiredRect); + void DestroyLines(); void DrainOverflowList(); diff --git a/layout/generic/nsBlockReflowState.cpp b/layout/generic/nsBlockReflowState.cpp index b5b5a0e5618..36fb68ba71a 100644 --- a/layout/generic/nsBlockReflowState.cpp +++ b/layout/generic/nsBlockReflowState.cpp @@ -1059,38 +1059,8 @@ nsBlockFrame::DoResizeReflow(nsBlockReflowState& aState, } } - // Return our desired rect and our status - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; - if (!aState.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + - aState.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - aState.mY += aState.mBorderPadding.bottom; - nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - - aState.mPrevMaxNegBottomMargin; - if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (aState.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - aState.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - aState.mY += lastBottomMargin; - } - aDesiredRect.height = aState.mY; + // Return our desired rect + ComputeDesiredRect(aState, aMaxSize, aDesiredRect); // Set return status aStatus = frComplete; @@ -1258,7 +1228,7 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, } // XXX This isn't really right... - state.mKidXMost = mRect.XMost(); + state.mKidXMost = mRect.width - state.mBorderPadding.right; // If the previous line is a block, then factor in its bottom margin if (prevLine->mIsBlock) { @@ -1291,39 +1261,8 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, NS_NOTYETIMPLEMENTED("unexpected reflow command"); } - // Return our desired rect and our status - // XXX Share this code with DoResizeReflow()... - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = state.mKidXMost + state.mBorderPadding.right; - if (!state.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = state.mAvailSize.width + state.mBorderPadding.left + - state.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - state.mY += state.mBorderPadding.bottom; - nscoord lastBottomMargin = state.mPrevMaxPosBottomMargin - - state.mPrevMaxNegBottomMargin; - if (!state.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (state.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - state.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - state.mY += lastBottomMargin; - } - aDesiredRect.height = state.mY; + // Return our desired rect + ComputeDesiredRect(state, aMaxSize, aDesiredRect); // Now that reflow has finished, remove the cached pointer shell->RemoveCachedData(this); @@ -1336,6 +1275,43 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, return rv; } +void nsBlockFrame::ComputeDesiredRect(nsBlockReflowState& aState, + const nsSize& aMaxSize, + nsRect& aDesiredRect) +{ + aDesiredRect.x = 0; + aDesiredRect.y = 0; + aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; + if (!aState.mUnconstrainedWidth) { + // Make sure we're at least as wide as the max size we were given + nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + + aState.mBorderPadding.right; + if (aDesiredRect.width < maxWidth) { + aDesiredRect.width = maxWidth; + } + } + aState.mY += aState.mBorderPadding.bottom; + nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - + aState.mPrevMaxNegBottomMargin; + if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { + // It's possible that we don't have room for the last bottom + // margin (the last bottom margin is the margin following a block + // element that we contain; it isn't applied immediately because + // of the margin collapsing logic). This can happen when we are + // reflowed in a limited amount of space because we don't know in + // advance what the last bottom margin will be. + nscoord maxY = aMaxSize.height; + if (aState.mY + lastBottomMargin > maxY) { + lastBottomMargin = maxY - aState.mY; + if (lastBottomMargin < 0) { + lastBottomMargin = 0; + } + } + aState.mY += lastBottomMargin; + } + aDesiredRect.height = aState.mY; +} + //---------------------------------------------------------------------- PRBool diff --git a/layout/generic/nsBlockReflowState.h b/layout/generic/nsBlockReflowState.h index b5b5a0e5618..36fb68ba71a 100644 --- a/layout/generic/nsBlockReflowState.h +++ b/layout/generic/nsBlockReflowState.h @@ -1059,38 +1059,8 @@ nsBlockFrame::DoResizeReflow(nsBlockReflowState& aState, } } - // Return our desired rect and our status - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; - if (!aState.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + - aState.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - aState.mY += aState.mBorderPadding.bottom; - nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - - aState.mPrevMaxNegBottomMargin; - if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (aState.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - aState.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - aState.mY += lastBottomMargin; - } - aDesiredRect.height = aState.mY; + // Return our desired rect + ComputeDesiredRect(aState, aMaxSize, aDesiredRect); // Set return status aStatus = frComplete; @@ -1258,7 +1228,7 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, } // XXX This isn't really right... - state.mKidXMost = mRect.XMost(); + state.mKidXMost = mRect.width - state.mBorderPadding.right; // If the previous line is a block, then factor in its bottom margin if (prevLine->mIsBlock) { @@ -1291,39 +1261,8 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, NS_NOTYETIMPLEMENTED("unexpected reflow command"); } - // Return our desired rect and our status - // XXX Share this code with DoResizeReflow()... - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = state.mKidXMost + state.mBorderPadding.right; - if (!state.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = state.mAvailSize.width + state.mBorderPadding.left + - state.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - state.mY += state.mBorderPadding.bottom; - nscoord lastBottomMargin = state.mPrevMaxPosBottomMargin - - state.mPrevMaxNegBottomMargin; - if (!state.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (state.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - state.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - state.mY += lastBottomMargin; - } - aDesiredRect.height = state.mY; + // Return our desired rect + ComputeDesiredRect(state, aMaxSize, aDesiredRect); // Now that reflow has finished, remove the cached pointer shell->RemoveCachedData(this); @@ -1336,6 +1275,43 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, return rv; } +void nsBlockFrame::ComputeDesiredRect(nsBlockReflowState& aState, + const nsSize& aMaxSize, + nsRect& aDesiredRect) +{ + aDesiredRect.x = 0; + aDesiredRect.y = 0; + aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; + if (!aState.mUnconstrainedWidth) { + // Make sure we're at least as wide as the max size we were given + nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + + aState.mBorderPadding.right; + if (aDesiredRect.width < maxWidth) { + aDesiredRect.width = maxWidth; + } + } + aState.mY += aState.mBorderPadding.bottom; + nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - + aState.mPrevMaxNegBottomMargin; + if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { + // It's possible that we don't have room for the last bottom + // margin (the last bottom margin is the margin following a block + // element that we contain; it isn't applied immediately because + // of the margin collapsing logic). This can happen when we are + // reflowed in a limited amount of space because we don't know in + // advance what the last bottom margin will be. + nscoord maxY = aMaxSize.height; + if (aState.mY + lastBottomMargin > maxY) { + lastBottomMargin = maxY - aState.mY; + if (lastBottomMargin < 0) { + lastBottomMargin = 0; + } + } + aState.mY += lastBottomMargin; + } + aDesiredRect.height = aState.mY; +} + //---------------------------------------------------------------------- PRBool diff --git a/layout/html/base/src/nsBlockFrame.cpp b/layout/html/base/src/nsBlockFrame.cpp index b5b5a0e5618..36fb68ba71a 100644 --- a/layout/html/base/src/nsBlockFrame.cpp +++ b/layout/html/base/src/nsBlockFrame.cpp @@ -1059,38 +1059,8 @@ nsBlockFrame::DoResizeReflow(nsBlockReflowState& aState, } } - // Return our desired rect and our status - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; - if (!aState.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + - aState.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - aState.mY += aState.mBorderPadding.bottom; - nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - - aState.mPrevMaxNegBottomMargin; - if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (aState.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - aState.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - aState.mY += lastBottomMargin; - } - aDesiredRect.height = aState.mY; + // Return our desired rect + ComputeDesiredRect(aState, aMaxSize, aDesiredRect); // Set return status aStatus = frComplete; @@ -1258,7 +1228,7 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, } // XXX This isn't really right... - state.mKidXMost = mRect.XMost(); + state.mKidXMost = mRect.width - state.mBorderPadding.right; // If the previous line is a block, then factor in its bottom margin if (prevLine->mIsBlock) { @@ -1291,39 +1261,8 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, NS_NOTYETIMPLEMENTED("unexpected reflow command"); } - // Return our desired rect and our status - // XXX Share this code with DoResizeReflow()... - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = state.mKidXMost + state.mBorderPadding.right; - if (!state.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = state.mAvailSize.width + state.mBorderPadding.left + - state.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - state.mY += state.mBorderPadding.bottom; - nscoord lastBottomMargin = state.mPrevMaxPosBottomMargin - - state.mPrevMaxNegBottomMargin; - if (!state.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (state.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - state.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - state.mY += lastBottomMargin; - } - aDesiredRect.height = state.mY; + // Return our desired rect + ComputeDesiredRect(state, aMaxSize, aDesiredRect); // Now that reflow has finished, remove the cached pointer shell->RemoveCachedData(this); @@ -1336,6 +1275,43 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, return rv; } +void nsBlockFrame::ComputeDesiredRect(nsBlockReflowState& aState, + const nsSize& aMaxSize, + nsRect& aDesiredRect) +{ + aDesiredRect.x = 0; + aDesiredRect.y = 0; + aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; + if (!aState.mUnconstrainedWidth) { + // Make sure we're at least as wide as the max size we were given + nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + + aState.mBorderPadding.right; + if (aDesiredRect.width < maxWidth) { + aDesiredRect.width = maxWidth; + } + } + aState.mY += aState.mBorderPadding.bottom; + nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - + aState.mPrevMaxNegBottomMargin; + if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { + // It's possible that we don't have room for the last bottom + // margin (the last bottom margin is the margin following a block + // element that we contain; it isn't applied immediately because + // of the margin collapsing logic). This can happen when we are + // reflowed in a limited amount of space because we don't know in + // advance what the last bottom margin will be. + nscoord maxY = aMaxSize.height; + if (aState.mY + lastBottomMargin > maxY) { + lastBottomMargin = maxY - aState.mY; + if (lastBottomMargin < 0) { + lastBottomMargin = 0; + } + } + aState.mY += lastBottomMargin; + } + aDesiredRect.height = aState.mY; +} + //---------------------------------------------------------------------- PRBool diff --git a/layout/html/base/src/nsBlockFrame.h b/layout/html/base/src/nsBlockFrame.h index f3fa810539b..99b37464984 100644 --- a/layout/html/base/src/nsBlockFrame.h +++ b/layout/html/base/src/nsBlockFrame.h @@ -245,6 +245,10 @@ protected: nsRect& aDesiredRect, ReflowStatus& aStatus); + void ComputeDesiredRect(nsBlockReflowState& aState, + const nsSize& aMaxSize, + nsRect& aDesiredRect); + void DestroyLines(); void DrainOverflowList(); diff --git a/layout/html/base/src/nsBlockReflowState.cpp b/layout/html/base/src/nsBlockReflowState.cpp index b5b5a0e5618..36fb68ba71a 100644 --- a/layout/html/base/src/nsBlockReflowState.cpp +++ b/layout/html/base/src/nsBlockReflowState.cpp @@ -1059,38 +1059,8 @@ nsBlockFrame::DoResizeReflow(nsBlockReflowState& aState, } } - // Return our desired rect and our status - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; - if (!aState.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + - aState.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - aState.mY += aState.mBorderPadding.bottom; - nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - - aState.mPrevMaxNegBottomMargin; - if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (aState.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - aState.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - aState.mY += lastBottomMargin; - } - aDesiredRect.height = aState.mY; + // Return our desired rect + ComputeDesiredRect(aState, aMaxSize, aDesiredRect); // Set return status aStatus = frComplete; @@ -1258,7 +1228,7 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, } // XXX This isn't really right... - state.mKidXMost = mRect.XMost(); + state.mKidXMost = mRect.width - state.mBorderPadding.right; // If the previous line is a block, then factor in its bottom margin if (prevLine->mIsBlock) { @@ -1291,39 +1261,8 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, NS_NOTYETIMPLEMENTED("unexpected reflow command"); } - // Return our desired rect and our status - // XXX Share this code with DoResizeReflow()... - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = state.mKidXMost + state.mBorderPadding.right; - if (!state.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = state.mAvailSize.width + state.mBorderPadding.left + - state.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - state.mY += state.mBorderPadding.bottom; - nscoord lastBottomMargin = state.mPrevMaxPosBottomMargin - - state.mPrevMaxNegBottomMargin; - if (!state.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (state.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - state.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - state.mY += lastBottomMargin; - } - aDesiredRect.height = state.mY; + // Return our desired rect + ComputeDesiredRect(state, aMaxSize, aDesiredRect); // Now that reflow has finished, remove the cached pointer shell->RemoveCachedData(this); @@ -1336,6 +1275,43 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, return rv; } +void nsBlockFrame::ComputeDesiredRect(nsBlockReflowState& aState, + const nsSize& aMaxSize, + nsRect& aDesiredRect) +{ + aDesiredRect.x = 0; + aDesiredRect.y = 0; + aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; + if (!aState.mUnconstrainedWidth) { + // Make sure we're at least as wide as the max size we were given + nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + + aState.mBorderPadding.right; + if (aDesiredRect.width < maxWidth) { + aDesiredRect.width = maxWidth; + } + } + aState.mY += aState.mBorderPadding.bottom; + nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - + aState.mPrevMaxNegBottomMargin; + if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { + // It's possible that we don't have room for the last bottom + // margin (the last bottom margin is the margin following a block + // element that we contain; it isn't applied immediately because + // of the margin collapsing logic). This can happen when we are + // reflowed in a limited amount of space because we don't know in + // advance what the last bottom margin will be. + nscoord maxY = aMaxSize.height; + if (aState.mY + lastBottomMargin > maxY) { + lastBottomMargin = maxY - aState.mY; + if (lastBottomMargin < 0) { + lastBottomMargin = 0; + } + } + aState.mY += lastBottomMargin; + } + aDesiredRect.height = aState.mY; +} + //---------------------------------------------------------------------- PRBool diff --git a/layout/html/base/src/nsBlockReflowState.h b/layout/html/base/src/nsBlockReflowState.h index b5b5a0e5618..36fb68ba71a 100644 --- a/layout/html/base/src/nsBlockReflowState.h +++ b/layout/html/base/src/nsBlockReflowState.h @@ -1059,38 +1059,8 @@ nsBlockFrame::DoResizeReflow(nsBlockReflowState& aState, } } - // Return our desired rect and our status - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; - if (!aState.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + - aState.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - aState.mY += aState.mBorderPadding.bottom; - nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - - aState.mPrevMaxNegBottomMargin; - if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (aState.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - aState.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - aState.mY += lastBottomMargin; - } - aDesiredRect.height = aState.mY; + // Return our desired rect + ComputeDesiredRect(aState, aMaxSize, aDesiredRect); // Set return status aStatus = frComplete; @@ -1258,7 +1228,7 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, } // XXX This isn't really right... - state.mKidXMost = mRect.XMost(); + state.mKidXMost = mRect.width - state.mBorderPadding.right; // If the previous line is a block, then factor in its bottom margin if (prevLine->mIsBlock) { @@ -1291,39 +1261,8 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, NS_NOTYETIMPLEMENTED("unexpected reflow command"); } - // Return our desired rect and our status - // XXX Share this code with DoResizeReflow()... - aDesiredRect.x = 0; - aDesiredRect.y = 0; - aDesiredRect.width = state.mKidXMost + state.mBorderPadding.right; - if (!state.mUnconstrainedWidth) { - // Make sure we're at least as wide as the max size we were given - nscoord maxWidth = state.mAvailSize.width + state.mBorderPadding.left + - state.mBorderPadding.right; - if (aDesiredRect.width < maxWidth) { - aDesiredRect.width = maxWidth; - } - } - state.mY += state.mBorderPadding.bottom; - nscoord lastBottomMargin = state.mPrevMaxPosBottomMargin - - state.mPrevMaxNegBottomMargin; - if (!state.mUnconstrainedHeight && (lastBottomMargin > 0)) { - // It's possible that we don't have room for the last bottom - // margin (the last bottom margin is the margin following a block - // element that we contain; it isn't applied immediately because - // of the margin collapsing logic). This can happen when we are - // reflowed in a limited amount of space because we don't know in - // advance what the last bottom margin will be. - nscoord maxY = aMaxSize.height; - if (state.mY + lastBottomMargin > maxY) { - lastBottomMargin = maxY - state.mY; - if (lastBottomMargin < 0) { - lastBottomMargin = 0; - } - } - state.mY += lastBottomMargin; - } - aDesiredRect.height = state.mY; + // Return our desired rect + ComputeDesiredRect(state, aMaxSize, aDesiredRect); // Now that reflow has finished, remove the cached pointer shell->RemoveCachedData(this); @@ -1336,6 +1275,43 @@ nsBlockFrame::IncrementalReflow(nsIPresContext* aPresContext, return rv; } +void nsBlockFrame::ComputeDesiredRect(nsBlockReflowState& aState, + const nsSize& aMaxSize, + nsRect& aDesiredRect) +{ + aDesiredRect.x = 0; + aDesiredRect.y = 0; + aDesiredRect.width = aState.mKidXMost + aState.mBorderPadding.right; + if (!aState.mUnconstrainedWidth) { + // Make sure we're at least as wide as the max size we were given + nscoord maxWidth = aState.mAvailSize.width + aState.mBorderPadding.left + + aState.mBorderPadding.right; + if (aDesiredRect.width < maxWidth) { + aDesiredRect.width = maxWidth; + } + } + aState.mY += aState.mBorderPadding.bottom; + nscoord lastBottomMargin = aState.mPrevMaxPosBottomMargin - + aState.mPrevMaxNegBottomMargin; + if (!aState.mUnconstrainedHeight && (lastBottomMargin > 0)) { + // It's possible that we don't have room for the last bottom + // margin (the last bottom margin is the margin following a block + // element that we contain; it isn't applied immediately because + // of the margin collapsing logic). This can happen when we are + // reflowed in a limited amount of space because we don't know in + // advance what the last bottom margin will be. + nscoord maxY = aMaxSize.height; + if (aState.mY + lastBottomMargin > maxY) { + lastBottomMargin = maxY - aState.mY; + if (lastBottomMargin < 0) { + lastBottomMargin = 0; + } + } + aState.mY += lastBottomMargin; + } + aDesiredRect.height = aState.mY; +} + //---------------------------------------------------------------------- PRBool