PrepareInlineReflow(aState, aFrame, PR_TRUE);
PRBool asBlock = PR_TRUE; const nsStyleDisplay* display; nsresult rv = aFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&) display); if ((NS_OK == rv) && (nsnull != display)) { switch (display->mDisplay) { case NS_STYLE_DISPLAY_TABLE: asBlock = PR_FALSE; break; } } PrepareInlineReflow(aState, aFrame, asBlock);
nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,                               LineData* aLine,                               nsIFrame* aFrame,                               nsReflowStatus& aReflowResult){  NS_PRECONDITION(0 == aState.mLineLayout.GetPlacedFrames(),                  "non-empty line with a block");  nsInlineReflow& ir = *aState.mInlineReflow;  // Prepare the inline reflow engine  PrepareInlineReflow(aState, aFrame, PR_TRUE);  ir.SetIsFirstChild((aLine == mLines) &&                     (aFrame == aLine->mFirstChild));  // Reflow the block frame  nsReflowStatus reflowStatus = ir.ReflowFrame(aFrame);  if (NS_IS_REFLOW_ERROR(reflowStatus)) {    aReflowResult = reflowStatus;    return PR_FALSE;  }  aReflowResult = reflowStatus;  if (NS_FRAME_IS_COMPLETE(reflowStatus)) {    aLine->SetLastContentIsComplete();  }  else {    aLine->ClearLastContentIsComplete();  }  // XXX We need to check the *type* of break and if it's a column/page  // break apply and cause the block to be split (assuming we are  // laying out in a column).#if XXX  if (NS_INLINE_IS_BREAK(reflowStatus)) {    // XXX For now we ignore it  }#endif  // Align the frame  ir.VerticalAlignFrames(aLine->mBounds);  ir.HorizontalAlignFrames(aLine->mBounds);  ir.RelativePositionFrames();  // Calculate margins (XXX: identical copy is in PlaceLine)  nscoord topMargin = 0, bottomMargin = 0;  PRBool haveCarriedMargins =     CalculateMargins(aState, aLine, PR_FALSE, topMargin, bottomMargin);  if (!haveCarriedMargins) {    // When the child being reflowed has no margin to give, we still    // need to make sure that the previous lines bottom margin is    // applied, but only if the line has a non-zero height (lines with    // no height and no carried margin need to not upset the margin    // state)    if (0 != aLine->mBounds.height) {      topMargin = aState.mPrevBottomMargin;    }  }  else {    // A special hack: if we have carried margins but the line has no    // height then collapse the carried margins down into a single    // (bottom margin) value.    if (0 == aLine->mBounds.height) {      bottomMargin = nsInlineReflow::MaxMargin(topMargin, bottomMargin);      topMargin = 0;    }  }  // Try to place the frame  nscoord newY = aLine->mBounds.YMost() + topMargin;  if ((mLines != aLine) && (newY > aState.mBottomEdge)) {    // The frame doesn't fit inside our available space. Push the    // line to the next-in-flow and return our incomplete status to    // our parent.    PushLines(aState);    aReflowResult = NS_FRAME_NOT_COMPLETE;    return PR_FALSE;  }  aState.mY = newY;  // Apply collapsed top-margin value  if (0 != topMargin) {    SlideFrames(aLine, topMargin);  }  // Record bottom margin value for sibling to sibling compression  // or for returning as our carried out bottom margin.  // Adjust running margin value when either we have carried margins  // from the line or we have a non-zero height line.  if (haveCarriedMargins || (0 != aLine->mBounds.height)) {    aState.mPrevBottomMargin = bottomMargin;  }  aLine->mCarriedOutTopMargin = ir.GetCarriedOutTopMargin();  aLine->mCarriedOutBottomMargin = ir.GetCarriedOutBottomMargin();  nscoord xmost = aLine->mBounds.XMost();  if (xmost > aState.mKidXMost) {    aState.mKidXMost = xmost;  }  // Update max-element-size  if (aState.mComputeMaxElementSize) {    const nsSize& kidMaxElementSize = ir.GetMaxElementSize();    if (kidMaxElementSize.width > aState.mMaxElementSize.width) {      aState.mMaxElementSize.width = kidMaxElementSize.width;    }    if (kidMaxElementSize.height > aState.mMaxElementSize.height) {      aState.mMaxElementSize.height = kidMaxElementSize.height;    }  }  aState.mPrevChild = aFrame;  // Refresh our available space in case a floater was placed by our  // child.  // XXX expensive!  aState.GetAvailableSpace();  if (NS_FRAME_IS_NOT_COMPLETE(reflowStatus)) {    // Some of the block fit. We need to have the block frame    // continued, so we make sure that it has a next-in-flow now.    nsIFrame* nextInFlow;    nsresult rv;    rv = nsHTMLContainerFrame::CreateNextInFlow(aState.mPresContext,                                                this,                                                aFrame,                                                nextInFlow);    if (NS_OK != rv) {      aReflowResult = rv;      return PR_FALSE;    }    if (nsnull != nextInFlow) {      // We made a next-in-flow for the block child frame. Create a      // line to map the block childs next-in-flow.      LineData* line = new LineData(nextInFlow, 1,                                    (LINE_IS_BLOCK |                                     LINE_LAST_CONTENT_IS_COMPLETE));      if (nsnull == line) {        aReflowResult = NS_ERROR_OUT_OF_MEMORY;        return PR_FALSE;      }      line->mNext = aLine->mNext;      aLine->mNext = line;    }    // Advance mPrevLine because we are keeping aLine (since some of    // the child block frame fit). Then push any remaining lines to    // our next-in-flow    aState.mPrevLine = aLine;    if (nsnull != aLine->mNext) {      PushLines(aState);    }    aReflowResult = NS_INLINE_LINE_BREAK_AFTER(reflowStatus);    return PR_FALSE;  }  return PR_TRUE;}