Removed handling of block frames (its done by nsBlockReflowContext now)

This commit is contained in:
kipp%netscape.com 1998-12-05 16:05:23 +00:00
Родитель 62566ebe32
Коммит 57d07c51cf
2 изменённых файлов: 37 добавлений и 156 удалений

Просмотреть файл

@ -34,6 +34,9 @@
#undef NOISY_VERTICAL_ALIGN
#endif
#define PLACED_LEFT 0x1
#define PLACED_RIGHT 0x2
// XXX handle DIR=right-to-left
// XXX remove support for block reflow from this and move it into its
@ -84,17 +87,12 @@ nsInlineReflow::Init(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
mCarriedOutTopMargin = 0;
mCarriedOutBottomMargin = 0;
mIsBlock = PR_FALSE;
mIsFirstChild = PR_FALSE;
mFrameData = nsnull;
mFrameNum = 0;
mMaxElementSize.width = 0;
mMaxElementSize.height = 0;
mUpdatedBand = PR_FALSE;
mPlacedLeftFloater = PR_FALSE;
mTreatFrameAsBlock = PR_FALSE;
mRunInFrame = nsnull;
mCompactMarginWidth = 0;
mPlacedFloaters = 0;
}
void
@ -120,14 +118,14 @@ nsInlineReflow::UpdateBand(nscoord aX, nscoord aY,
mBottomEdge = aY + aHeight;
}
mUpdatedBand = PR_TRUE;
mPlacedLeftFloater = aPlacedLeftFloater;
mPlacedFloaters |= (aPlacedLeftFloater ? PLACED_LEFT : PLACED_RIGHT);
}
void
nsInlineReflow::UpdateFrames()
{
if (NS_STYLE_DIRECTION_LTR == mOuterReflowState.mDirection) {
if (mPlacedLeftFloater) {
if (PLACED_LEFT & mPlacedFloaters) {
PerFrameData* pfd = mFrameDataBase;
PerFrameData* end = pfd + mFrameNum;
for (; pfd < end; pfd++) {
@ -135,7 +133,7 @@ nsInlineReflow::UpdateFrames()
}
}
}
else if (!mPlacedLeftFloater) {
else if (PLACED_RIGHT & mPlacedFloaters) {
// XXX handle DIR=right-to-left
}
}
@ -226,15 +224,13 @@ nsInlineReflow::SetFrame(nsIFrame* aFrame)
mDisplay = nsnull;
mSpacing = nsnull;
mPosition = nsnull;
mTreatFrameAsBlock = TreatFrameAsBlockFrame();
return NS_OK;
}
nsReflowStatus
nsInlineReflow::ReflowFrame(nsIFrame* aFrame)
nsresult
nsInlineReflow::ReflowFrame(nsIFrame* aFrame, nsReflowStatus& aReflowStatus)
{
nsReflowStatus result;
nsSize innerMaxElementSize;
nsHTMLReflowMetrics metrics(mComputeMaxElementSize
? &innerMaxElementSize
@ -242,17 +238,10 @@ nsInlineReflow::ReflowFrame(nsIFrame* aFrame)
// Prepare for reflowing the frame
nsresult rv = SetFrame(aFrame);
if (NS_OK != rv) {
if (NS_FAILED(rv)) {
return rv;
}
// Do a quick check and see if we are trying to place a block on a
// line that already has a placed frame on it.
PRInt32 placedFrames = mLineLayout.GetPlacedFrames();
if (mTreatFrameAsBlock && (placedFrames > 0)) {
return NS_INLINE_LINE_BREAK_BEFORE();
}
// Next figure out how much available space there is for the frame.
// Calculate raw margin values.
CalculateMargins();
@ -263,15 +252,16 @@ nsInlineReflow::ReflowFrame(nsIFrame* aFrame)
// Compute the available area to reflow the frame into.
if (!ComputeAvailableSize()) {
return NS_INLINE_LINE_BREAK_BEFORE();
aReflowStatus = NS_INLINE_LINE_BREAK_BEFORE();
return NS_OK;
}
// Reflow the frame. If the frame must be placed somewhere else
// then we return immediately.
if (ReflowFrame(metrics, result)) {
if (ReflowFrame(metrics, aReflowStatus)) {
// See if we can place the frame. If we can't fit it, then we
// return now.
if (CanPlaceFrame(metrics, result)) {
if (CanPlaceFrame(metrics, aReflowStatus)) {
// Place the frame, updating aBounds with the final size and
// location. Then apply the bottom+right margins (as
// appropriate) to the frame.
@ -279,26 +269,16 @@ nsInlineReflow::ReflowFrame(nsIFrame* aFrame)
}
}
return result;
return rv;
}
// XXX looks more like a method on PerFrameData?
void
nsInlineReflow::CalculateMargins()
{
PerFrameData* pfd = mFrameData;
if (mTreatFrameAsBlock) {
const nsStyleSpacing* spacing = GetSpacing();
pfd->mMarginFlags = CalculateBlockMarginsFor(mPresContext, pfd->mFrame,
&mOuterReflowState,
spacing, pfd->mMargin);
}
else {
// Get the margins from the style system
PerFrameData* pfd = mFrameData;
nsHTMLReflowState::ComputeMarginFor(pfd->mFrame, &mOuterReflowState,
pfd->mMargin);
pfd->mMarginFlags = 0;
}
}
PRUintn
@ -369,6 +349,7 @@ nsInlineReflow::ApplyTopLeftMargins()
pfd->mBounds.y = mTopEdge;
// Compute left margin
nsIFrame* prevInFlow;
const nsStyleDisplay* display = GetDisplay();
switch (display->mFloats) {
default:
@ -382,9 +363,7 @@ nsInlineReflow::ApplyTopLeftMargins()
break;
case NS_STYLE_FLOAT_NONE:
if (!mTreatFrameAsBlock) {
// Only apply left-margin on the first-in flow for inline frames
nsIFrame* prevInFlow;
pfd->mFrame->GetPrevInFlow(prevInFlow);
if (nsnull != prevInFlow) {
// Zero this out so that when we compute the max-element-size
@ -392,7 +371,6 @@ nsInlineReflow::ApplyTopLeftMargins()
// margin.
pfd->mMargin.left = 0;
}
}
pfd->mBounds.x += pfd->mMargin.left;
break;
}
@ -465,11 +443,7 @@ nsInlineReflow::ReflowFrame(nsHTMLReflowMetrics& aMetrics,
// Setup reflow state for reflowing the frame
nsHTMLReflowState reflowState(mPresContext, frame, mOuterReflowState,
mFrameAvailSize);
if (!mTreatFrameAsBlock) {
reflowState.lineLayout = &mLineLayout;
}
reflowState.mRunInFrame = mRunInFrame;
reflowState.mCompactMarginWidth = mCompactMarginWidth;
reflowState.reason = reason;
mLineLayout.SetUnderstandsWhiteSpace(PR_FALSE);
@ -492,6 +466,7 @@ nsInlineReflow::ReflowFrame(nsHTMLReflowMetrics& aMetrics,
nscoord ty = y - mOuterReflowState.mBorderPadding.top;
mSpaceManager->Translate(tx, ty);
frame->MoveTo(x, y);
htmlReflow->Reflow(mPresContext, aMetrics, reflowState, aStatus);
// XXX could return this in aStatus to save a few cycles
// XXX could mandate that child sets up mCombinedArea too...
@ -577,7 +552,6 @@ nsInlineReflow::CanPlaceFrame(nsHTMLReflowMetrics& aMetrics,
break;
case NS_STYLE_FLOAT_NONE:
if (!mTreatFrameAsBlock) {
// Only apply right margin for the last-in-flow
if (NS_FRAME_IS_NOT_COMPLETE(aStatus)) {
// Zero this out so that when we compute the
@ -585,21 +559,11 @@ nsInlineReflow::CanPlaceFrame(nsHTMLReflowMetrics& aMetrics,
// adding in the right margin.
pfd->mMargin.right = 0;
}
}
mRightMargin = pfd->mMargin.right;
break;
}
}
// If the frame is a block frame but the parent frame is not a block
// frame and the frame count is not zero then break before the block
// frame. This forces blocks that are children of inlines to be the
// one and only child of the inline frame.
if (mTreatFrameAsBlock && !mOuterIsBlock && (0 != mFrameNum)) {
aStatus = NS_INLINE_LINE_BREAK_BEFORE();
return PR_FALSE;
}
// If this is the first frame going into this inline reflow or it's
// the first placed frame in the line or wrapping is disabled then
// the frame fits regardless of who much room there is. This
@ -621,8 +585,6 @@ nsInlineReflow::CanPlaceFrame(nsHTMLReflowMetrics& aMetrics,
// See if the frame fits. If it doesn't then we fabricate up a
// break-before status.
if (pfd->mBounds.XMost() + mRightMargin > mRightEdge) {
// Retain the completion status of the frame that was reflowed in
// case the caller cares.
aStatus = NS_INLINE_LINE_BREAK_BEFORE();
return PR_FALSE;
}
@ -638,25 +600,6 @@ nsInlineReflow::PlaceFrame(nsHTMLReflowMetrics& aMetrics)
{
PerFrameData* pfd = mFrameData;
// Remember this for later...
if (mTreatFrameAsBlock) {
mIsBlock = PR_TRUE;
// Special handling for CSS2 section 10.3.3
if ((aMetrics.width < mFrameAvailSize.width) &&
(NS_UNCONSTRAINEDSIZE != mRightEdge)) {
// The block frame didn't use all of the available space. See if
// it has auto left/right margins. If it does, center it.
const nsStyleSpacing* spacing = GetSpacing();
if (nsnull != spacing) {
if ((eStyleUnit_Auto == spacing->mMargin.GetLeftUnit()) &&
(eStyleUnit_Auto == spacing->mMargin.GetRightUnit())) {
pfd->mBounds.x += (mRightEdge - aMetrics.width) / 2;
}
}
}
}
//XXX disabled: css2 spec claims otherwise; the problem is we need to
//handle continuations differently so that empty continuations disappear
@ -683,7 +626,6 @@ nsInlineReflow::PlaceFrame(nsHTMLReflowMetrics& aMetrics)
// Save carried out information for caller
mCarriedOutTopMargin = aMetrics.mCarriedOutTopMargin;
mCarriedOutBottomMargin = aMetrics.mCarriedOutBottomMargin;
mCarriedOutMarginFlags = aMetrics.mCarriedOutMarginFlags;
// Advance to next X coordinate
mX = pfd->mBounds.XMost() + mRightMargin;
@ -731,16 +673,6 @@ nsInlineReflow::VerticalAlignFrames(nsRect& aLineBox,
PerFrameData* pfd0 = mFrameDataBase;
PerFrameData* end = pfd0 + mFrameNum;
// Short circuit 99% of this when this code has reflowed a single
// block frame.
if (mTreatFrameAsBlock) {
aLineBox = pfd0->mBounds;
aMaxAscent = pfd0->mAscent;
aMaxDescent = pfd0->mDescent;
pfd0->mFrame->SetRect(aLineBox);
return;
}
// XXX I think that the line box should wrap around the children,
// even if they have negative margins, right?
aLineBox.x = mLeftEdge;

Просмотреть файл

@ -47,29 +47,16 @@ public:
void Init(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
void SetIsFirstChild(PRBool aValue) {
mIsFirstChild = aValue;
}
void SetRunInFrame(nsBlockFrame* aBlockFrame) {
mRunInFrame = aBlockFrame;
}
void SetCompactMarginWidth(nscoord aWidth) {
mCompactMarginWidth = aWidth;
}
void UpdateBand(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
PRBool aPlacedLeftFloater);
nsReflowStatus ReflowFrame(nsIFrame* aFrame);
nsresult ReflowFrame(nsIFrame* aFrame, nsReflowStatus& aReflowStatus);
void VerticalAlignFrames(nsRect& aLineBox,
nscoord& aMaxAscent,
nscoord& aMaxDescent);
void HorizontalAlignFrames(nsRect& aLineBox,
PRBool aIsLastLine = PR_FALSE);
void HorizontalAlignFrames(nsRect& aLineBox, PRBool aAllowJustify);
void RelativePositionFrames(nsRect& aCombinedArea);
@ -80,16 +67,12 @@ public:
mFrameNum = aCount;
}
PRBool GetIsBlock() const { return mIsBlock; }
const nsSize& GetMaxElementSize() const { return mMaxElementSize; }
nscoord GetCarriedOutTopMargin() const { return mCarriedOutTopMargin; }
nscoord GetCarriedOutBottomMargin() const { return mCarriedOutBottomMargin; }
nscoord GetCarriedOutMarginFlags() const { return mCarriedOutMarginFlags; }
nscoord GetTopMargin() const {
return mFrameData->mMargin.top;
}
@ -98,10 +81,6 @@ public:
return mFrameData->mMargin.bottom;
}
PRUintn GetMarginFlags() const {
return mFrameData->mMarginFlags;
}
nscoord GetAvailWidth() const {
return mRightEdge - mX;
}
@ -162,9 +141,6 @@ protected:
nsIPresContext& mPresContext;
PRBool mOuterIsBlock;
nsBlockFrame* mRunInFrame;
nscoord mCompactMarginWidth;
PRIntn mFrameNum;
/*
@ -177,7 +153,6 @@ protected:
nscoord mDescent; // computed descent value
nsMargin mMargin; // computed margin value
PRUintn mMarginFlags;
// Location and size of frame after its reflowed but before it is
// positioned finally by VerticalAlignFrames
@ -200,16 +175,8 @@ protected:
const nsStyleSpacing* mSpacing;
const nsStylePosition* mPosition;
const nsStyleDisplay* mDisplay;
PRBool mTreatFrameAsBlock; // treat the frame as a block frame
// Entire reflow should act like a block; this means that somewhere
// during reflow we encountered a block frame. There can be more one
// than one frame in the reflow group (because of empty frames), so
// this flag keeps us honest regarding the state of this reflow.
PRBool mIsBlock;
PRBool mCanBreakBeforeFrame; // we can break before the frame
PRBool mIsFirstChild;
PRBool mComputeMaxElementSize;
nsSize mMaxElementSize;
@ -219,7 +186,6 @@ protected:
nscoord mRightMargin;/* XXX */
nscoord mCarriedOutTopMargin;
nscoord mCarriedOutBottomMargin;
PRUintn mCarriedOutMarginFlags;
// The computed available size and location for the frame
nsSize mFrameAvailSize;
@ -232,25 +198,8 @@ protected:
nscoord mBottomEdge;
PRBool mUpdatedBand;
PRBool mPlacedLeftFloater;
PRUint8 mPlacedFloaters;
PRBool mInWord;
};
inline nscoord
nsInlineReflow::MaxMargin(nscoord a, nscoord b)
{
if (a < 0) {
if (b < 0) {
if (a < b) return a;
return b;
}
return b + a;
}
else if (b < 0) {
return a + b;
}
if (a > b) return a;
return b;
}
#endif /* nsInlineReflow_h___ */