("nsCSSBlockFrame::ReflowBlockFrame: availSize={%d,%d}", availSize.width, availSize.height));
("nsCSSBlockFrame::ReflowBlockFrame: xy={%d,%d} availSize={%d,%d}", x, y, availSize.width, availSize.height));
nsCSSBlockFrame::ReflowBlockFrame(nsCSSBlockReflowState& aState,                                  LineData*              aLine,                                  nsIFrame*              aFrame,                                  nsInlineReflowStatus&  aReflowResult){  NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW,     ("nsCSSBlockFrame::ReflowBlockFrame: line=%p frame=%p y=%d",      aLine, aFrame, aState.mY));  // Get the child margins  nsMargin childMargin;  const nsStyleSpacing* childSpacing;  aFrame->GetStyleData(eStyleStruct_Spacing,                       (const nsStyleStruct*&)childSpacing);  childSpacing->CalcMarginFor(aFrame, childMargin);  const nsStyleDisplay* childDisplay;  aFrame->GetStyleData(eStyleStruct_Display,                       (const nsStyleStruct*&)childDisplay);  // XXX Negative margins are set to zero; we could do better SOMEDAY  // Compute the top margin to apply to the child block  nscoord totalTopMargin = 0;  nscoord topMargin = 0;  nscoord childTopMargin = 0;  nscoord childBottomMargin = 0;  if (childSpacing->mMargin.GetTopUnit() <= eStyleUnit_Auto) {    // Provide an ebina style margin of 1 blank line before this block    // for most block elements.    // XXX need a complete list of the ones that he does this for    if (NS_STYLE_DISPLAY_LIST_ITEM != childDisplay->mDisplay) {      if (IsPseudoFrame() && (aState.mY == aState.mBorderPadding.top)) {        childTopMargin = 0;      }      else {        const nsFont& defaultFont = aState.mPresContext->GetDefaultFont();        nsIFontMetrics* fm = aState.mPresContext->GetMetricsFor(defaultFont);        childTopMargin = fm->GetHeight();        NS_RELEASE(fm);      }    }  }  else {    childTopMargin = childMargin.top;    if (childTopMargin < 0) childTopMargin = 0;  }  if (aState.mY == aState.mBorderPadding.top) {    // Since this is our first child we need to collapse its top    // margin with our top margin.    if (0 != aState.mBorderPadding.top) {      // Since we have a border/padding value the childs top margin      // does not collapse with our top margin.      topMargin = childTopMargin;    }    else {      nscoord outerTopMargin = aState.mOuterTopMargin;      if (childTopMargin > outerTopMargin) {        topMargin = childTopMargin - outerTopMargin;        totalTopMargin = childTopMargin;      }      else {        totalTopMargin = outerTopMargin;      }    }  }  else {    // For other children we collapse the margins between them.    if (childTopMargin > aState.mPrevBottomMargin) {      topMargin = childTopMargin - aState.mPrevBottomMargin;      totalTopMargin = childTopMargin;    }    else {      totalTopMargin = aState.mPrevBottomMargin;    }  }  if (childSpacing->mMargin.GetBottomUnit() > eStyleUnit_Auto) {    childBottomMargin = childMargin.bottom;    if (childBottomMargin < 0) childBottomMargin = 0;  }  nscoord x = aState.mX + childMargin.left + aState.mBulletPadding;  if (NS_STYLE_DISPLAY_LIST_ITEM == childDisplay->mDisplay) {    const nsStyleList* sl;    aFrame->GetStyleData(eStyleStruct_List,                         (const nsStyleStruct*&) sl);    if (NS_STYLE_LIST_STYLE_POSITION_OUTSIDE == sl->mListStylePosition) {      // Slide child list item so that it's just past our border; it      // will use our padding area to place it's bullet.      x -= aState.mLeftPadding;    }  }  nscoord y = aState.mY + topMargin;  aFrame->WillReflow(*aState.mPresContext);  aFrame->MoveTo(x, y);  // Compute the available space that the child block can reflow into  nsSize availSize;  if (aState.mUnconstrainedWidth) {#if 1    availSize.width = NS_UNCONSTRAINEDSIZE;#else    // Never give a block an unconstrained width#if 1    nsRect r;    aState.mPresContext->GetVisibleArea(r);    float p2t = aState.mPresContext->GetPixelsToTwips();    availSize.width = nscoord(p2t * r.width);#else    if (!aState.mHaveBlockMaxWidth) {      const nsReflowState* rsp = aState.parentReflowState;      aState.mBlockMaxWidth = 0;      while (nsnull != rsp) {        if (NS_UNCONSTRAINEDSIZE != rsp->maxSize.width) {          aState.mBlockMaxWidth = rsp->maxSize.width;          const nsStyleSpacing* spacing = nsnull;          rsp->frame->GetStyleData(eStyleStruct_Spacing,                                   (const nsStyleStruct *&)spacing);          if (nsnull!=spacing) {            nsMargin borderPadding;            spacing->CalcBorderPaddingFor(rsp->frame, borderPadding);            aState.mBlockMaxWidth -= borderPadding.right + borderPadding.left;          }          break;        }        rsp = rsp->parentReflowState;      }      aState.mHaveBlockMaxWidth = PR_TRUE;    }    availSize.width = aState.mBlockMaxWidth;#endif#endif  }  else {    availSize.width = aState.mInnerSize.width -      (childMargin.left + childMargin.right);  }  if (aState.mUnconstrainedHeight) {    availSize.height = NS_UNCONSTRAINEDSIZE;  }  else {    availSize.height = aState.mBottomEdge - (y + childBottomMargin);  }  NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW,     ("nsCSSBlockFrame::ReflowBlockFrame: availSize={%d,%d}",      availSize.width, availSize.height));  // Determine the reason for the reflow  nsReflowReason reason = eReflowReason_Resize;  nsFrameState state;  aFrame->GetFrameState(state);  if (NS_FRAME_FIRST_REFLOW & state) {    reason = eReflowReason_Initial;  }  else if (aState.mInlineLayout.mNextRCFrame == aFrame) {    reason = eReflowReason_Incremental;    // Make sure we only incrementally reflow once    aState.mInlineLayout.mNextRCFrame = nsnull;  }  // Reflow the block frame. Use the run-around API if possible;  // otherwise treat it as a rectangular lump and place it.  nsresult rv;  nsSize kidMaxElementSize;  nsReflowMetrics metrics(aState.mComputeMaxElementSize                          ? &kidMaxElementSize                          : nsnull);  metrics.posTopMargin = totalTopMargin;  nsReflowStatus reflowStatus;  nsIRunaround* runAround;  if ((nsnull != aState.mSpaceManager) &&      (NS_OK == aFrame->QueryInterface(kIRunaroundIID, (void**)&runAround))) {    // Reflow the block    nsReflowState reflowState(aFrame, aState, availSize);    reflowState.reason = reason;    nsRect r;    aState.mSpaceManager->Translate(x, y);    rv = runAround->Reflow(*aState.mPresContext, aState.mSpaceManager,                           metrics, reflowState, r, reflowStatus);    aState.mSpaceManager->Translate(-x, -y);    metrics.width = r.width;    metrics.height = r.height;    metrics.ascent = r.height;    metrics.descent = 0;  }  else {    nsReflowState reflowState(aFrame, aState, availSize);    reflowState.reason = reason;    rv = aFrame->Reflow(*aState.mPresContext, metrics, reflowState,                        reflowStatus);  }  if (NS_IS_REFLOW_ERROR(rv)) {    aReflowResult = nsInlineReflowStatus(rv);    return PR_FALSE;  }  if (NS_FRAME_IS_COMPLETE(reflowStatus)) {    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)      nsIFrame* parent;      aFrame->GetGeometricParent(parent);      ((nsCSSBlockFrame*)parent)->DeleteNextInFlowsFor(aFrame);    }    aLine->SetLastContentIsComplete();    aReflowResult = NS_FRAME_COMPLETE;  }  else {    aLine->ClearLastContentIsComplete();    aReflowResult = NS_FRAME_NOT_COMPLETE;  }  // If the block we just reflowed happens to end up being zero height  // then we do not let its margins take effect.  nscoord newY;  if (0 == metrics.height) {    // Leave aState.mPrevBottomMargin alone in this case so that it    // can carry forward to the next non-empty block.    newY = y = aState.mY;    aLine->mInnerBottomMargin = 0;    aLine->mOuterBottomMargin = 0;  }  else {    // Collapse the childs bottom margin with the grandchilds bottom    // margin.    if (childSpacing->mMargin.GetBottomUnit() <= eStyleUnit_Auto) {      // list-item's don't get bottom margins in ebina land      const nsStyleDisplay* childDisplay;      aFrame->GetStyleData(eStyleStruct_Display,                           (const nsStyleStruct*&)childDisplay);      if (NS_STYLE_DISPLAY_LIST_ITEM != childDisplay->mDisplay) {        const nsFont& defaultFont = aState.mPresContext->GetDefaultFont();        nsIFontMetrics* fm = aState.mPresContext->GetMetricsFor(defaultFont);        childBottomMargin = fm->GetHeight();        NS_RELEASE(fm);      }    }    else {      childBottomMargin -= metrics.posBottomMargin;      if (childBottomMargin < 0) childBottomMargin = 0;    }    // See if it fit    newY = y + metrics.height + childBottomMargin;    NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW,       ("nsCSSBlockFrame::ReflowBlockFrame: metrics={%d,%d} newY=%d maxY=%d",        metrics.width, metrics.height, newY, aState.mBottomEdge));    if ((mLines != aLine) && (newY > aState.mBottomEdge)) {      // None of the block fit. Push aLine and any other lines that follow      PushLines(aState);      aReflowResult = NS_INLINE_LINE_BREAK_BEFORE(reflowStatus);      return PR_FALSE;    }    aState.mPrevBottomMargin = metrics.posBottomMargin + childBottomMargin;    aLine->mInnerBottomMargin = metrics.posBottomMargin;    aLine->mOuterBottomMargin = childBottomMargin;  }  // Update max-element-size  if (aState.mComputeMaxElementSize) {    if (kidMaxElementSize.width > aState.mMaxElementSize.width) {      aState.mMaxElementSize.width = kidMaxElementSize.width;    }    if (kidMaxElementSize.height > aState.mMaxElementSize.height) {      aState.mMaxElementSize.height = kidMaxElementSize.height;    }  }  // Save away bounds before other adjustments  aLine->mBounds.x = x;  aLine->mBounds.y = y;  aLine->mBounds.width = metrics.width;  aLine->mBounds.height = metrics.height;  nscoord xmost = aLine->mBounds.XMost();NS_ASSERTION(xmost < 1000000, "bad line width");  if (xmost > aState.mKidXMost) {    aState.mKidXMost = xmost;  }  // Place child then align it and relatively position it  aFrame->SetRect(aLine->mBounds);  aState.mY = newY;  if (!aState.mUnconstrainedWidth) {    nsCSSLayout::HorizontallyPlaceChildren(aState.mPresContext,                                           aState.mBlock,                                           aState.mTextAlign,                                           aState.mDirection,                                           aFrame, 1,                                           metrics.width,                                           availSize.width);  }  nsCSSLayout::RelativePositionChildren(aState.mPresContext,                                        aState.mBlock,                                        aFrame, 1);  aState.mPrevChild = aFrame;  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;    rv = aState.mInlineLayout.MaybeCreateNextInFlow(aFrame, nextInFlow);    if (NS_OK != rv) {      aReflowResult = nsInlineReflowStatus(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 = nsInlineReflowStatus(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;}