if (brc.BlockShouldInvalidateItself() && !mRect.IsEmpty()) { Invalidate(aState.mPresContext, mRect);
if (reflowState.HaveFixedContentWidth()) {   kidAvailSize.width = reflowState.minWidth + bp.left + bp.right; } else {    const nsHTMLReflowState* rsp = &aState; kidAvailSize.width = 0; while (nsnull != rsp) { if (eHTMLFrameConstraint_FixedContent == rsp->widthConstraint) { kidAvailSize.width = rsp->minWidth; break; } else if (NS_UNCONSTRAINEDSIZE != rsp->widthConstraint) { kidAvailSize.width = rsp->maxSize.width; if (kidAvailSize.width > 0) { break; } }  rsp = (const nsHTMLReflowState*) rsp->parentReflowState; }
nsBlockFrame::ReflowFloater(nsBlockReflowState& aState,                            nsPlaceholderFrame* aPlaceholder,                            nsRect&             aCombinedRectResult,                            nsMargin&           aMarginResult,                            nsMargin&           aComputedOffsetsResult,                            nsReflowStatus&     aReflowStatus){  // Delete the placeholder's next in flows, if any  nsIFrame* nextInFlow;  aPlaceholder->GetNextInFlow(&nextInFlow);  if (nextInFlow) {    // If aPlaceholder's parent is an inline, nextInFlow's will be a block.    nsHTMLContainerFrame* parent;    nextInFlow->GetParent((nsIFrame**)&parent);    parent->DeleteNextInFlowChild(aState.mPresContext, nextInFlow);  }  // Reflow the floater.  nsIFrame* floater = aPlaceholder->GetOutOfFlowFrame();  aReflowStatus = NS_FRAME_COMPLETE;#ifdef NOISY_FLOATER  printf("Reflow Floater %p in parent %p, availSpace(%d,%d,%d,%d)\n",          aPlaceholder->GetOutOfFlowFrame(), this,           aState.mAvailSpaceRect.x, aState.mAvailSpaceRect.y,           aState.mAvailSpaceRect.width, aState.mAvailSpaceRect.height  );#endif  // Compute the available width. By default, assume the width of the  // containing block.  nscoord availWidth;  if (aState.GetFlag(BRS_UNCONSTRAINEDWIDTH)) {    availWidth = NS_UNCONSTRAINEDSIZE;  }  else {    const nsStyleDisplay* floaterDisplay;    floater->GetStyleData(eStyleStruct_Display,                          (const nsStyleStruct*&)floaterDisplay);    nsCompatibility mode;    aState.mPresContext->GetCompatibilityMode(&mode);    nsIFrame* prevInFlow;    floater->GetPrevInFlow(&prevInFlow);    // if the floater is continued, constrain its width to the prev-in-flow's width    if (prevInFlow) {      nsRect rect;      prevInFlow->GetRect(rect);      availWidth = rect.width;    }    else if (NS_STYLE_DISPLAY_TABLE != floaterDisplay->mDisplay ||             eCompatibility_NavQuirks != mode ) {      availWidth = aState.mContentArea.width;    }    else {      // give tables only the available space      // if they can shrink we may not be constrained to place      // them in the next line      availWidth = aState.mAvailSpaceRect.width;      // round down to twips per pixel so that we fit      // needed when prev. floater has procentage width      // (maybe is a table flaw that makes table chose to round up      // but i don't want to change that, too risky)      nscoord twp;      float p2t;      aState.mPresContext->GetScaledPixelsToTwips(&p2t);      twp = NSIntPixelsToTwips(1,p2t);      availWidth -=  availWidth % twp;    }  }  nscoord availHeight = ((NS_UNCONSTRAINEDSIZE == aState.mAvailSpaceRect.height) ||                         (NS_UNCONSTRAINEDSIZE == aState.mContentArea.height))                        ? NS_UNCONSTRAINEDSIZE                         : PR_MAX(0, aState.mContentArea.height - aState.mY);  // If the floater's width is automatic, we can't let the floater's  // width shrink below its maxElementWidth.  const nsStylePosition* position;  floater->GetStyleData(eStyleStruct_Position,                        NS_REINTERPRET_CAST(const nsStyleStruct*&, position));  PRBool isAutoWidth = (eStyleUnit_Auto == position->mWidth.GetUnit());  // We'll need to compute the max element size if either 1) we're  // auto-width or 2) the state wanted us to compute it anyway.  PRBool computeMaxElementWidth =    isAutoWidth || aState.GetFlag(BRS_COMPUTEMAXELEMENTWIDTH);  nsRect availSpace(aState.BorderPadding().left,                    aState.BorderPadding().top,                    availWidth, availHeight);  // construct the html reflow state for the floater. ReflowBlock will   // initialize it and set its reason.  nsHTMLReflowState floaterRS(aState.mPresContext, aState.mReflowState, floater,                               nsSize(availSpace.width, availSpace.height),                               aState.mReflowState.reason, PR_FALSE);  // Setup a block reflow state to reflow the floater.  nsBlockReflowContext brc(aState.mPresContext, aState.mReflowState,                           computeMaxElementWidth,                           aState.GetFlag(BRS_COMPUTEMAXWIDTH));  // Reflow the floater  PRBool isAdjacentWithTop = aState.IsAdjacentWithTop();  nsCollapsingMargin margin;  nsresult rv = brc.ReflowBlock(availSpace, PR_TRUE, margin, isAdjacentWithTop,                                 aComputedOffsetsResult, floaterRS, aReflowStatus);  // An incomplete reflow status means we should split the floater   // if the height is constrained (bug 145305).   if (NS_FRAME_IS_NOT_COMPLETE(aReflowStatus) && (NS_UNCONSTRAINEDSIZE == availHeight))     aReflowStatus = NS_FRAME_COMPLETE;  if (NS_SUCCEEDED(rv) && isAutoWidth) {    nscoord maxElementWidth = brc.GetMaxElementWidth();    if (maxElementWidth > availSpace.width) {      // The floater's maxElementWidth is larger than the available      // width. Reflow it again, this time pinning the width to the      // maxElementWidth.      availSpace.width = maxElementWidth;      nsCollapsingMargin marginMEW;      // construct the html reflow state for the floater.       // ReflowBlock will initialize it and set its reason.      nsHTMLReflowState redoFloaterRS(aState.mPresContext, aState.mReflowState, floater,                                       nsSize(availSpace.width, availSpace.height),                                       aState.mReflowState.reason, PR_FALSE);      rv = brc.ReflowBlock(availSpace, PR_TRUE, marginMEW, isAdjacentWithTop,                            aComputedOffsetsResult, redoFloaterRS, aReflowStatus);    }  }  if (brc.BlockShouldInvalidateItself() && !mRect.IsEmpty()) {    Invalidate(aState.mPresContext, mRect);  }  // Remove the floater from the reflow tree.  if (aState.mReflowState.path)    aState.mReflowState.path->RemoveChild(floater);  if (NS_FAILED(rv)) {    return rv;  }  // Capture the margin information for the caller  const nsMargin& m = brc.GetMargin();  aMarginResult.top = brc.GetTopMargin();  aMarginResult.right = m.right;  brc.GetCarriedOutBottomMargin().Include(m.bottom);  aMarginResult.bottom = brc.GetCarriedOutBottomMargin().get();  aMarginResult.left = m.left;  const nsHTMLReflowMetrics& metrics = brc.GetMetrics();  aCombinedRectResult = metrics.mOverflowArea;  // Set the rect, make sure the view is properly sized and positioned,  // and tell the frame we're done reflowing it  // XXXldb This seems like the wrong place to be doing this -- shouldn't  // we be doing this in nsBlockReflowState::FlowAndPlaceFloater after  // we've positioned the floater, and shouldn't we be doing the equivalent  // of |::PlaceFrameView| here?  floater->SizeTo(aState.mPresContext, metrics.width, metrics.height);  nsIView*  view;  floater->GetView(aState.mPresContext, &view);  if (view) {    nsContainerFrame::SyncFrameViewAfterReflow(aState.mPresContext, floater, view,                                               &metrics.mOverflowArea,                                               NS_FRAME_NO_MOVE_VIEW);  }  // Pass floaterRS so the frame hierarchy can be used (redoFloaterRS has the same hierarchy)    floater->DidReflow(aState.mPresContext, &floaterRS, NS_FRAME_REFLOW_FINISHED);  // If we computed it, then stash away the max-element-width for later  if (computeMaxElementWidth) {    nscoord mew = brc.GetMaxElementWidth();    mew += aMarginResult.left + aMarginResult.right;    aState.StoreMaxElementWidth(floater, mew);    aState.UpdateMaxElementWidth(mew); // fix for bug 13553  }#ifdef NOISY_FLOATER  printf("end ReflowFloater %p, sized to %d,%d\n", floater, metrics.width, metrics.height);#endif  // If the placeholder was continued and its first-in-flow was followed by a   // <BR>, then cache the <BR>'s break type in aState.mFloaterBreakType so that  // the next frame after the placeholder can combine that break type with its own  nsIFrame* prevPlaceholder = nsnull;  aPlaceholder->GetPrevInFlow(&prevPlaceholder);  if (prevPlaceholder) {    // the break occurs only after the last continued placeholder    PRBool lastPlaceholder = PR_TRUE;    nsIFrame* next;    aPlaceholder->GetNextSibling(&next);    if (next) {      nsCOMPtr<nsIAtom> nextType;      next->GetFrameType(getter_AddRefs(nextType));      if (nsLayoutAtoms::placeholderFrame == nextType) {        lastPlaceholder = PR_FALSE;      }    }    if (lastPlaceholder) {      // get the containing block of prevPlaceholder which is our prev-in-flow      if (mPrevInFlow) {        // get the break type of the last line in mPrevInFlow        line_iterator endLine = --((nsBlockFrame*)mPrevInFlow)->end_lines();        PRUint8 breakType = endLine->GetBreakType();        if ((NS_STYLE_CLEAR_LEFT           == breakType) ||            (NS_STYLE_CLEAR_RIGHT          == breakType) ||            (NS_STYLE_CLEAR_LEFT_AND_RIGHT == breakType)) {          aState.mFloaterBreakType = breakType;        }      }      else NS_ASSERTION(PR_FALSE, "no prev in flow");    }  }  return NS_OK;}