nsresult nsBlockReflowContext::ReflowBlock(const nsRect& aSpace, bool aApplyTopMargin, nsCollapsingMargin& aPrevMargin, nscoord aClearance, bool aIsAdjacentWithTop, nsLineBox* aLine, nsHTMLReflowState& aFrameRS, nsReflowStatus& aFrameReflowStatus, nsBlockReflowState& aState) { nsresult rv = NS_OK; mFrame = aFrameRS.frame; mSpace = aSpace; if (!aIsAdjacentWithTop) { aFrameRS.mFlags.mIsTopOfPage = false; // make sure this is cleared } if (aApplyTopMargin) { mTopMargin = aPrevMargin; #ifdef NOISY_VERTICAL_MARGINS nsFrame::ListTag(stdout, mOuterReflowState.frame); printf(": reflowing "); nsFrame::ListTag(stdout, mFrame); printf(" margin => %d, clearance => %d\n", mTopMargin.get(), aClearance); #endif // Adjust the available height if its constrained so that the // child frame doesn't think it can reflow into its margin area. if (NS_UNCONSTRAINEDSIZE != aFrameRS.availableHeight) { aFrameRS.availableHeight -= mTopMargin.get() + aClearance; } } nscoord tx = 0, ty = 0; // The values of x and y do not matter for floats, so don't bother calculating // them. Floats are guaranteed to have their own float manager, so tx and ty // don't matter. mX and mY don't matter becacuse they are only used in // PlaceBlock, which is not used for floats. if (aLine) { // Compute x/y coordinate where reflow will begin. Use the rules // from 10.3.3 to determine what to apply. At this point in the // reflow auto left/right margins will have a zero value. mX = tx = mSpace.x + aFrameRS.mComputedMargin.left; mY = ty = mSpace.y + mTopMargin.get() + aClearance; if ((mFrame->GetStateBits() & NS_BLOCK_FLOAT_MGR) == 0) aFrameRS.mBlockDelta = mOuterReflowState.mBlockDelta + ty - aLine->mBounds.y; } // Let frame know that we are reflowing it mFrame->WillReflow(mPresContext); #ifdef DEBUG mMetrics.width = nscoord(0xdeadbeef); mMetrics.height = nscoord(0xdeadbeef); #endif mOuterReflowState.mFloatManager->Translate(tx, ty); rv = mFrame->Reflow(mPresContext, mMetrics, aFrameRS, aFrameReflowStatus); mOuterReflowState.mFloatManager->Translate(-tx, -ty); #ifdef DEBUG if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) { if (CRAZY_WIDTH(mMetrics.width) || CRAZY_HEIGHT(mMetrics.height)) { printf("nsBlockReflowContext: "); nsFrame::ListTag(stdout, mFrame); printf(" metrics=%d,%d!\n", mMetrics.width, mMetrics.height); } if ((mMetrics.width == nscoord(0xdeadbeef)) || (mMetrics.height == nscoord(0xdeadbeef))) { printf("nsBlockReflowContext: "); nsFrame::ListTag(stdout, mFrame); printf(" didn't set w/h %d,%d!\n", mMetrics.width, mMetrics.height); } } #endif if (!mFrame->HasOverflowAreas()) { mMetrics.SetOverflowAreasToDesiredBounds(); } if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus) || (mFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) { // If frame is complete and has a next-in-flow, we need to delete // them now. Do not do this when a break-before is signaled because // the frame is going to get reflowed again (and may end up wanting // a next-in-flow where it ends up), unless it is an out of flow frame. if (NS_FRAME_IS_FULLY_COMPLETE(aFrameReflowStatus)) { nsIFrame* kidNextInFlow = mFrame->GetNextInFlow(); if (nsnull != kidNextInFlow) { // Remove all of the childs next-in-flows. Make sure that we ask // the right parent to do the removal (it's possible that the // parent is not this because we are executing pullup code). // Floats will eventually be removed via nsBlockFrame::RemoveFloat // which detaches the placeholder from the float. /* XXX promote DeleteChildsNextInFlow to nsIFrame to elminate this cast */ aState.mOverflowTracker->Finish(mFrame); static_cast<nsContainerFrame*>(kidNextInFlow->GetParent()) ->DeleteNextInFlowChild(mPresContext, kidNextInFlow, true); } } } return rv; }
nsresult nsInlineFrame::ReflowInlineFrame(nsPresContext* aPresContext, const nsHTMLReflowState& aReflowState, InlineReflowState& irs, nsIFrame* aFrame, nsReflowStatus& aStatus) { nsLineLayout* lineLayout = aReflowState.mLineLayout; PRBool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); PRBool pushedFrame; nsresult rv = lineLayout->ReflowFrame(aFrame, aStatus, nsnull, pushedFrame); if (NS_FAILED(rv)) { return rv; } if (NS_INLINE_IS_BREAK(aStatus)) { if (NS_INLINE_IS_BREAK_BEFORE(aStatus)) { if (aFrame != mFrames.FirstChild()) { // Change break-before status into break-after since we have // already placed at least one child frame. This preserves the // break-type so that it can be propagated upward. aStatus = NS_FRAME_NOT_COMPLETE | NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER | (aStatus & NS_INLINE_BREAK_TYPE_MASK); PushFrames(aPresContext, aFrame, irs.mPrevFrame); } else { // Preserve reflow status when breaking-before our first child // and propagate it upward without modification. // Note: if we're lazily setting the frame pointer for our child // frames, then we need to set it now. Don't return and leave the // remaining child frames in our child list with the wrong parent // frame pointer... if (irs.mSetParentPointer) { if (irs.mLineContainer && irs.mLineContainer->GetPrevContinuation()) { ReparentFloatsForInlineChild(irs.mLineContainer, aFrame->GetNextSibling(), PR_TRUE); } for (nsIFrame* f = aFrame->GetNextSibling(); f; f = f->GetNextSibling()) { f->SetParent(this); } } } } else { // Break-after if (NS_FRAME_IS_NOT_COMPLETE(aStatus)) { nsIFrame* newFrame; rv = CreateNextInFlow(aPresContext, this, aFrame, newFrame); if (NS_FAILED(rv)) { return rv; } } nsIFrame* nextFrame = aFrame->GetNextSibling(); if (nextFrame) { NS_FRAME_SET_INCOMPLETE(aStatus); PushFrames(aPresContext, nextFrame, aFrame); } else if (nsnull != GetNextInFlow()) { // We must return an incomplete status if there are more child // frames remaining in a next-in-flow that follows this frame. nsInlineFrame* nextInFlow = (nsInlineFrame*) GetNextInFlow(); while (nsnull != nextInFlow) { if (nextInFlow->mFrames.NotEmpty()) { NS_FRAME_SET_INCOMPLETE(aStatus); break; } nextInFlow = (nsInlineFrame*) nextInFlow->GetNextInFlow(); } } } } else if (NS_FRAME_IS_NOT_COMPLETE(aStatus)) { if (nsGkAtoms::placeholderFrame == aFrame->GetType()) { nsBlockReflowState* blockRS = lineLayout->mBlockRS; blockRS->mBlock->SplitPlaceholder(*blockRS, aFrame); // Allow the parent to continue reflowing aStatus = NS_FRAME_COMPLETE; } else { nsIFrame* newFrame; rv = CreateNextInFlow(aPresContext, this, aFrame, newFrame); if (NS_FAILED(rv)) { return rv; } if (!reflowingFirstLetter) { nsIFrame* nextFrame = aFrame->GetNextSibling(); if (nextFrame) { PushFrames(aPresContext, nextFrame, aFrame); } } } } return rv; }