nsIFrame* nextInFlow; aFrame->GetNextInFlow(&nextInFlow);
nsIFrame* nextInFlow = aFrame->GetNextInFlow();
nsLineLayout::ReflowFrame(nsIFrame* aFrame,                          nsReflowStatus& aReflowStatus,                          nsHTMLReflowMetrics* aMetrics,                          PRBool& aPushedFrame){  // Initialize OUT parameter  aPushedFrame = PR_FALSE;  PerFrameData* pfd;  nsresult rv = NewPerFrameData(&pfd);  if (NS_FAILED(rv)) {    return rv;  }  PerSpanData* psd = mCurrentSpan;  psd->AppendFrame(pfd);#ifdef REALLY_NOISY_REFLOW  nsFrame::IndentBy(stdout, mSpanDepth);  printf("%p: Begin ReflowFrame pfd=%p ", psd, pfd);  nsFrame::ListTag(stdout, aFrame);  printf("\n");#endif  // Compute the available size for the frame. This available width  // includes room for the side margins.  nsSize availSize;  if (NS_UNCONSTRAINEDSIZE == psd->mRightEdge) {    availSize.width = NS_UNCONSTRAINEDSIZE;  }  else {    availSize.width = psd->mRightEdge - psd->mX;    if (psd->mNoWrap) {      // Make up a width to use for reflowing into.  XXX what value to      // use? for tables, we want to limit it; for other elements      // (e.g. text) it can be unlimited...      availSize.width = psd->mReflowState->availableWidth;    }  }  if (NS_UNCONSTRAINEDSIZE == mBottomEdge) {    availSize.height = NS_UNCONSTRAINEDSIZE;  }  else {    availSize.height = mBottomEdge - mTopEdge;  }  // Get reflow reason set correctly. It's possible that a child was  // created and then it was decided that it could not be reflowed  // (for example, a block frame that isn't at the start of a  // line). In this case the reason will be wrong so we need to check  // the frame state.  const nsHTMLReflowState* rs = psd->mReflowState;  nsReflowReason reason = eReflowReason_Resize;  if (NS_FRAME_FIRST_REFLOW & aFrame->GetStateBits()) {    reason = eReflowReason_Initial;  }    else if (rs->reason == eReflowReason_Incremental) { // XXX    // XXXwaterson (above) previously used mBlockReflowState rather    // than psd->mReflowState.    // If the frame we're about to reflow is on the reflow path, then    // propagate the reflow as `incremental' so it unwinds correctly    // to the target frames below us.    PRBool frameIsOnReflowPath = rs->path->HasChild(aFrame);    if (frameIsOnReflowPath)      reason = eReflowReason_Incremental;    // But...if the incremental reflow command is a StyleChanged    // reflow and its target is the current span, change the reason    // to `style change', so that it propagates through the entire    // subtree.    nsHTMLReflowCommand* rc = rs->path->mReflowCommand;    if (rc) {      nsReflowType type;      rc->GetType(type);      if (type == eReflowType_StyleChanged) {        nsIFrame* parentFrame = psd->mFrame          ? psd->mFrame->mFrame          : mBlockReflowState->frame;        nsIFrame* target;        rc->GetTarget(target);        if (target == parentFrame) {          reason = eReflowReason_StyleChange;        }      }      else if (type == eReflowType_ReflowDirty &&               (aFrame->GetStateBits() & NS_FRAME_IS_DIRTY) &&               !frameIsOnReflowPath) {        reason = eReflowReason_Dirty;      }    }  }  else if (rs->reason == eReflowReason_StyleChange) {    reason = eReflowReason_StyleChange;  }  else if (rs->reason == eReflowReason_Dirty) {    if (aFrame->GetStateBits() & NS_FRAME_IS_DIRTY)      reason = eReflowReason_Dirty;  }  // Setup reflow state for reflowing the frame  nsHTMLReflowState reflowState(mPresContext, *psd->mReflowState,                                aFrame, availSize, reason);  reflowState.mLineLayout = this;  reflowState.mFlags.mIsTopOfPage = GetFlag(LL_ISTOPOFPAGE);  SetFlag(LL_UNDERSTANDSNWHITESPACE, PR_FALSE);  mTextJustificationNumSpaces = 0;  mTextJustificationNumLetters = 0;  // Stash copies of some of the computed state away for later  // (vertical alignment, for example)  pfd->mFrame = aFrame;  pfd->mMargin = reflowState.mComputedMargin;  pfd->mBorderPadding = reflowState.mComputedBorderPadding;  pfd->mFrameType = reflowState.mFrameType;  pfd->SetFlag(PFD_RELATIVEPOS,               (reflowState.mStyleDisplay->mPosition == NS_STYLE_POSITION_RELATIVE));  if (pfd->GetFlag(PFD_RELATIVEPOS)) {    pfd->mOffsets = reflowState.mComputedOffsets;  }  // NOTE: While the x coordinate remains relative to the parent span,  // the y coordinate is fixed at the top edge for the line. During  // VerticalAlignFrames we will repair this so that the y coordinate  // is properly set and relative to the appropriate span.  pfd->mBounds.x = psd->mX;  pfd->mBounds.y = mTopEdge;  // We want to guarantee that we always make progress when  // formatting. Therefore, if the object being placed on the line is  // too big for the line, but it is the only thing on the line  // (including counting floats) then we go ahead and place it  // anyway. Its also true that if the object is a part of a larger  // object (a multiple frame word) then we will place it on the line  // too.  //  // Capture this state *before* we reflow the frame in case it clears  // the state out. We need to know how to treat the current frame  // when breaking.  PRBool notSafeToBreak = CanPlaceFloatNow() || InWord();  // Apply start margins (as appropriate) to the frame computing the  // new starting x,y coordinates for the frame.  ApplyStartMargin(pfd, reflowState);  // Let frame know that are reflowing it. Note that we don't bother  // positioning the frame yet, because we're probably going to end up  // moving it when we do the vertical alignment  nscoord x = pfd->mBounds.x;  nscoord y = pfd->mBounds.y;  aFrame->WillReflow(mPresContext);  // Adjust spacemanager coordinate system for the frame. The  // spacemanager coordinates are <b>inside</b> the current spans  // border+padding, but the x/y coordinates are not (recall that  // frame coordinates are relative to the parents origin and that the  // parents border/padding is <b>inside</b> the parent  // frame. Therefore we have to subtract out the parents  // border+padding before translating.  nsHTMLReflowMetrics metrics(mComputeMaxElementWidth);#ifdef DEBUG  metrics.width = nscoord(0xdeadbeef);  metrics.height = nscoord(0xdeadbeef);  metrics.ascent = nscoord(0xdeadbeef);  metrics.descent = nscoord(0xdeadbeef);  if (mComputeMaxElementWidth) {    metrics.mMaxElementWidth = nscoord(0xdeadbeef);  }#endif  nscoord tx = x - psd->mReflowState->mComputedBorderPadding.left;  nscoord ty = y - psd->mReflowState->mComputedBorderPadding.top;  mSpaceManager->Translate(tx, ty);#ifdef IBMBIDI  PRInt32 start, end;  if (mPresContext->BidiEnabled()) {    if (aFrame->GetStateBits() & NS_FRAME_IS_BIDI) {      aFrame->GetOffsets(start, end);    }  }#endif // IBMBIDI  nsIAtom* frameType = aFrame->GetType();  rv = aFrame->Reflow(mPresContext, metrics, reflowState, aReflowStatus);  if (NS_FAILED(rv)) {    NS_WARNING( "Reflow of frame failed in nsLineLayout" );    return rv;  }  pfd->mJustificationNumSpaces = mTextJustificationNumSpaces;  pfd->mJustificationNumLetters = mTextJustificationNumLetters;  // XXX See if the frame is a placeholderFrame and if it is process  // the float.  if (frameType) {    if (nsLayoutAtoms::placeholderFrame == frameType) {      pfd->SetFlag(PFD_ISPLACEHOLDERFRAME, PR_TRUE);      nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)aFrame)->GetOutOfFlowFrame();      if (outOfFlowFrame) {        // Make sure it's floated and not absolutely positioned        const nsStyleDisplay* display = outOfFlowFrame->GetStyleDisplay();        if (!display->IsAbsolutelyPositioned()) {          if (eReflowReason_Incremental == reason) {            InitFloat((nsPlaceholderFrame*)aFrame, aReflowStatus);          }          else {            AddFloat((nsPlaceholderFrame*)aFrame, aReflowStatus);          }          if (outOfFlowFrame->GetType() == nsLayoutAtoms::letterFrame) {            SetFlag(LL_FIRSTLETTERSTYLEOK, PR_FALSE);            // An incomplete reflow status means we should split the            // float if the height is constrained (bug 145305). We            // never split floating first letters.            if (NS_FRAME_IS_NOT_COMPLETE(aReflowStatus))               aReflowStatus = NS_FRAME_COMPLETE;          }        }      }    }    else if (nsLayoutAtoms::textFrame == frameType) {      // Note non-empty text-frames for inline frame compatability hackery      pfd->SetFlag(PFD_ISTEXTFRAME, PR_TRUE);      // XXX An empty text frame at the end of the line seems not      // to have zero width.      if (metrics.width) {        pfd->SetFlag(PFD_ISNONEMPTYTEXTFRAME, PR_TRUE);        nsIContent* content = pfd->mFrame->GetContent();        nsCOMPtr<nsITextContent> textContent          = do_QueryInterface(content);        if (textContent) {          pfd->SetFlag(PFD_ISNONWHITESPACETEXTFRAME,                       !textContent->IsOnlyWhitespace());// fix for bug 40882#ifdef IBMBIDI          if (mPresContext->BidiEnabled()) {            const nsTextFragment* frag = textContent->Text();            if (frag->Is2b()) {              //PRBool isVisual;              //mPresContext->IsVisualMode(isVisual);              PRUnichar ch = /*(isVisual) ?                              *(frag->Get2b() + frag->GetLength() - 1) :*/ *frag->Get2b();              if (IS_BIDI_DIACRITIC(ch)) {                aFrame->SetProperty(nsLayoutAtoms::endsInDiacritic,                                    NS_INT32_TO_PTR(ch));              }            }          }#endif // IBMBIDI        }      }    }    else if (nsLayoutAtoms::letterFrame==frameType) {      pfd->SetFlag(PFD_ISLETTERFRAME, PR_TRUE);    }  }  mSpaceManager->Translate(-tx, -ty);  NS_ASSERTION(metrics.width>=0, "bad width");  NS_ASSERTION(metrics.height>=0,"bad height");  if (metrics.width<0) metrics.width=0;  if (metrics.height<0) metrics.height=0;#ifdef DEBUG  // Note: break-before means ignore the reflow metrics since the  // frame will be reflowed another time.  if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) {    if (CRAZY_WIDTH(metrics.width) || CRAZY_HEIGHT(metrics.height)) {      printf("nsLineLayout: ");      nsFrame::ListTag(stdout, aFrame);      printf(" metrics=%d,%d!\n", metrics.width, metrics.height);    }    if (mComputeMaxElementWidth &&        (nscoord(0xdeadbeef) == metrics.mMaxElementWidth)) {      printf("nsLineLayout: ");      nsFrame::ListTag(stdout, aFrame);      printf(" didn't set max-element-width!\n");    }#ifdef REALLY_NOISY_MAX_ELEMENT_SIZE    // Note: there are common reflow situations where this *correctly*    // occurs; so only enable this debug noise when you really need to    // analyze in detail.    if (mComputeMaxElementWidth &&        (metrics.mMaxElementWidth > metrics.width)) {      printf("nsLineLayout: ");      nsFrame::ListTag(stdout, aFrame);      printf(": WARNING: maxElementWidth=%d > metrics=%d\n",             metrics.mMaxElementWidth, metrics.width);    }#endif    if ((metrics.width == nscoord(0xdeadbeef)) ||        (metrics.height == nscoord(0xdeadbeef)) ||        (metrics.ascent == nscoord(0xdeadbeef)) ||        (metrics.descent == nscoord(0xdeadbeef))) {      printf("nsLineLayout: ");      nsFrame::ListTag(stdout, aFrame);      printf(" didn't set whad %d,%d,%d,%d!\n", metrics.width, metrics.height,             metrics.ascent, metrics.descent);    }  }#endif#ifdef DEBUG  if (nsBlockFrame::gNoisyMaxElementWidth) {    nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);    if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) {      if (mComputeMaxElementWidth) {        printf("  ");        nsFrame::ListTag(stdout, aFrame);        printf(": maxElementWidth=%d wh=%d,%d,\n",               metrics.mMaxElementWidth,               metrics.width, metrics.height);      }    }  }#endif  if (NS_FRAME_OUTSIDE_CHILDREN & aFrame->GetStateBits()) {    pfd->mCombinedArea = metrics.mOverflowArea;  }  else {    pfd->mCombinedArea.x = 0;    pfd->mCombinedArea.y = 0;    pfd->mCombinedArea.width = metrics.width;    pfd->mCombinedArea.height = metrics.height;  }  pfd->mBounds.width = metrics.width;  pfd->mBounds.height = metrics.height;  if (mComputeMaxElementWidth) {    pfd->mMaxElementWidth = metrics.mMaxElementWidth;  }  // Size the frame, but |RelativePositionFrames| will size the view.  aFrame->SetSize(nsSize(metrics.width, metrics.height));  // Tell the frame that we're done reflowing it  aFrame->DidReflow(mPresContext, &reflowState, NS_FRAME_REFLOW_FINISHED);  if (aMetrics) {    *aMetrics = metrics;  }  if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) {    // 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).    if (NS_FRAME_IS_COMPLETE(aReflowStatus)) {      nsIFrame* kidNextInFlow;      aFrame->GetNextInFlow(&kidNextInFlow);      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)        nsHTMLContainerFrame* parent = NS_STATIC_CAST(nsHTMLContainerFrame*,                                                      kidNextInFlow->GetParent());        parent->DeleteNextInFlowChild(mPresContext, kidNextInFlow);      }    }    // See if we can place the frame. If we can't fit it, then we    // return now.    if (CanPlaceFrame(pfd, reflowState, notSafeToBreak, metrics, aReflowStatus)) {      // Place the frame, updating aBounds with the final size and      // location.  Then apply the bottom+right margins (as      // appropriate) to the frame.      PlaceFrame(pfd, metrics);      PerSpanData* span = pfd->mSpan;      if (span) {        // The frame we just finished reflowing is an inline        // container.  It needs its child frames vertically aligned,        // so do most of it now.        VerticalAlignFrames(span);      }    }    else {      PushFrame(aFrame);      aPushedFrame = PR_TRUE;    }  }  else {    PushFrame(aFrame);  }#ifdef REALLY_NOISY_REFLOW  nsFrame::IndentBy(stdout, mSpanDepth);  printf("End ReflowFrame ");  nsFrame::ListTag(stdout, aFrame);  printf(" status=%x\n", aReflowStatus);#endif  if (aFrame->GetStateBits() & NS_FRAME_IS_BIDI) {    // Since aReflowStatus may change, check it at the end    if (NS_INLINE_IS_BREAK_BEFORE(aReflowStatus) ) {      aFrame->AdjustOffsetsForBidi(start, end);    }    else if (!NS_FRAME_IS_COMPLETE(aReflowStatus) ) {      PRInt32 newEnd;      aFrame->GetOffsets(start, newEnd);      if (newEnd != end) {        nsIFrame* nextInFlow;        aFrame->GetNextInFlow(&nextInFlow);        if (nextInFlow) {          nextInFlow->GetOffsets(start, end);          nextInFlow->AdjustOffsetsForBidi(newEnd, end);        } // nextInFlow      } // newEnd != end    } // !NS_FRAME_IS_COMPLETE(aReflowStatus)  } // isBidiFrame  return rv;}