nscoord x0 = 0, y0 = 0, x1 = aMetrics.width, y1 = aMetrics.height; LineData* line = mLines; while (nsnull != line) {   nscoord x = line->mCombinedArea.x; nscoord y = line->mCombinedArea.y; nscoord xmost = x + line->mCombinedArea.width; nscoord ymost = y + line->mCombinedArea.height; if (x < x0) x0 = x; if (xmost > x1) x1 = xmost; if (y < y0) y0 = y; if (ymost > y1) y1 = ymost;   nsVoidArray* floaters = line->mFloaters; if (nsnull != floaters) { PRInt32 i, n = floaters->Count(); for (i = 0; i < n; i++) { nsPlaceholderFrame* ph = (nsPlaceholderFrame*) floaters->ElementAt(i); nsIFrame* frame = ph->GetAnchoredItem();   nsRect r; frame->GetRect(r); if (r.x < x0) x0 = r.x; if (r.XMost() > x1) x1 = r.XMost(); if (r.y < y0) y0 = r.y; if (r.YMost() > y1) y1 = r.YMost(); } } line = line->mNext; } aMetrics.mCombinedArea.x = x0; aMetrics.mCombinedArea.y = y0; aMetrics.mCombinedArea.width = x1 - x0; aMetrics.mCombinedArea.height = y1 - y0;    if ((aMetrics.mCombinedArea.x < 0) || (aMetrics.mCombinedArea.y < 0) || (aMetrics.mCombinedArea.XMost() > aMetrics.width) || (aMetrics.mCombinedArea.YMost() > aMetrics.height)) { mState |= NS_FRAME_OUTSIDE_CHILDREN; } else { mState &= ~NS_FRAME_OUTSIDE_CHILDREN; }
nsBlockFrame::ComputeFinalSize(nsBlockReflowState&  aState,                               nsHTMLReflowMetrics& aMetrics){  // Compute final width  if (eHTMLFrameConstraint_Unconstrained != aState.widthConstraint) {    // Use style defined width    aMetrics.width = aState.mBorderPadding.left +      aState.minWidth + aState.mBorderPadding.right;  }  else {    // There are two options here. We either shrink wrap around our    // contents or we fluff out to the maximum available width. Note:    // We always shrink wrap when given an unconstrained width.    nscoord contentWidth = aState.mKidXMost + aState.mBorderPadding.right;    if ((0 == (NS_BODY_SHRINK_WRAP & mFlags)) && !aState.mUnconstrainedWidth) {      // Fluff out to the max width if we aren't already that wide      if (contentWidth < aState.maxSize.width) {        contentWidth = aState.maxSize.width;      }    }    aMetrics.width = contentWidth;  }  // Compute final height  if (eHTMLFrameConstraint_Unconstrained != aState.heightConstraint) {    // Use style defined height    aMetrics.height = aState.mBorderPadding.top +      aState.minHeight + aState.mBorderPadding.bottom;  }  else {    // Shrink wrap our height around our contents.    if (aState.mIsMarginRoot) {      // When we are a margin root make sure that our last childs      // bottom margin is fully applied.      if ((NS_BODY_NO_AUTO_MARGINS & mFlags) &&          (NS_CARRIED_BOTTOM_MARGIN_IS_AUTO & aState.mPrevMarginFlags)) {        // Do not apply last auto margin when the last childs margin        // is auto and we are configured to ignore them.      }      else {        aState.mY += aState.mPrevBottomMargin;      }    }    aState.mY += aState.mBorderPadding.bottom;    aMetrics.height = aState.mY;  }  // Return top and bottom margin information  if (aState.mIsMarginRoot) {    aMetrics.mCarriedOutTopMargin = 0;    aMetrics.mCarriedOutBottomMargin = 0;    aMetrics.mCarriedOutMarginFlags = 0;  }  else {    aMetrics.mCarriedOutTopMargin = aState.mCollapsedTopMargin;    aMetrics.mCarriedOutBottomMargin = aState.mPrevBottomMargin;    aMetrics.mCarriedOutMarginFlags = aState.mCarriedOutMarginFlags;    if (NS_CARRIED_BOTTOM_MARGIN_IS_AUTO & aState.mPrevMarginFlags) {      aMetrics.mCarriedOutMarginFlags |= NS_CARRIED_BOTTOM_MARGIN_IS_AUTO;    }  }  // Special check for zero sized content: If our content is zero  // sized then we collapse into nothingness.  if ((eHTMLFrameConstraint_Unconstrained == aState.widthConstraint) &&      (eHTMLFrameConstraint_Unconstrained == aState.heightConstraint) &&      ((0 == aState.mKidXMost - aState.mBorderPadding.left) &&       (0 == aState.mY - aState.mBorderPadding.top))) {    aMetrics.width = 0;    aMetrics.height = 0;  }  aMetrics.ascent = aMetrics.height;  aMetrics.descent = 0;  // XXX this needs reworking I suppose  if (aState.mComputeMaxElementSize) {    *aMetrics.maxElementSize = aState.mMaxElementSize;    // Add in our border and padding to the max-element-size so that    // we don't shrink too far.    aMetrics.maxElementSize->width += aState.mBorderPadding.left +      aState.mBorderPadding.right;    aMetrics.maxElementSize->height += aState.mBorderPadding.top +      aState.mBorderPadding.bottom;    // Factor in any left and right floaters as well    LineData* line = mLines;    PRInt32 maxLeft = 0, maxRight = 0;    while (nsnull != line) {      if (nsnull != line->mFloaters) {        nsRect r;        nsMargin floaterMargin;        PRInt32 leftSum = 0, rightSum = 0;        PRInt32 n = line->mFloaters->Count();        for (PRInt32 i = 0; i < n; i++) {          nsPlaceholderFrame* placeholder = (nsPlaceholderFrame*)            line->mFloaters->ElementAt(i);          nsIFrame* floater = placeholder->GetAnchoredItem();          floater->GetRect(r);          const nsStyleDisplay* floaterDisplay;          const nsStyleSpacing* floaterSpacing;          floater->GetStyleData(eStyleStruct_Display,                                (const nsStyleStruct*&)floaterDisplay);          floater->GetStyleData(eStyleStruct_Spacing,                                (const nsStyleStruct*&)floaterSpacing);          floaterSpacing->CalcMarginFor(floater, floaterMargin);          nscoord width = r.width + floaterMargin.left + floaterMargin.right;          NS_ASSERTION((NS_STYLE_FLOAT_LEFT == floaterDisplay->mFloats) ||                       (NS_STYLE_FLOAT_RIGHT == floaterDisplay->mFloats),                       "invalid float type");          if (NS_STYLE_FLOAT_LEFT == floaterDisplay->mFloats) {            leftSum += width;          }          else {            rightSum += width;          }        }        if (leftSum > maxLeft) maxLeft = leftSum;        if (rightSum > maxRight) maxRight = rightSum;      }      line = line->mNext;    }    // XXX what to do???    if (maxLeft > aMetrics.maxElementSize->width) {      aMetrics.maxElementSize->width = maxLeft;    }    if (maxRight > aMetrics.maxElementSize->width) {      aMetrics.maxElementSize->width = maxRight;    }  }}