PRBool isHTMLParagraph = 0 != (mState & NS_BLOCK_IS_HTML_PARAGRAPH); if (isHTMLParagraph && (aReflowState.mStyleDisplay->mDisplay == NS_STYLE_DISPLAY_BLOCK) && (((0 == aState.mKidXMost) || (0 == aState.mKidXMost - borderPadding.left)) && (0 == aState.mY - borderPadding.top))) {
if ((NS_SIZE_HAS_BOTH != ss) && ((0 == aState.mKidXMost - aState.mBorderPadding.left) || (0 == aState.mY - aState.mBorderPadding.top))) {
nsBlockFrame::ComputeFinalSize(const nsHTMLReflowState& aReflowState,                               nsBlockReflowState& aState,                               nsHTMLReflowMetrics& aMetrics){  const nsMargin& borderPadding = aState.BorderPadding();#ifdef NOISY_FINAL_SIZE  ListTag(stdout);  printf(": mY=%d mIsBottomMarginRoot=%s mPrevBottomMargin=%d bp=%d,%d\n",         aState.mY, aState.mIsBottomMarginRoot ? "yes" : "no",         aState.mPrevBottomMargin,         borderPadding.top, borderPadding.bottom);#endif  // Special check for zero sized content: If our content is zero  // sized then we collapse into nothingness.  //  // Consensus after discussion with a few CSS folks is that html's  // notion of collapsing <P>'s should take precedence over non  // auto-sided block elements. Therefore we don't honor the width,  // height, border or padding attributes (the parent has to not apply  // a margin for us also).  //  // Note that this is <b>only</b> done for html paragraphs. Its not  // appropriate to apply it to other containers, especially XML  // content!  PRBool isHTMLParagraph = 0 != (mState & NS_BLOCK_IS_HTML_PARAGRAPH);  if (isHTMLParagraph &&      (aReflowState.mStyleDisplay->mDisplay == NS_STYLE_DISPLAY_BLOCK) &&      (((0 == aState.mKidXMost) ||        (0 == aState.mKidXMost - borderPadding.left)) &&       (0 == aState.mY - borderPadding.top))) {    // Zero out most everything    aMetrics.width = 0;    aMetrics.height = 0;    aMetrics.ascent = 0;    aMetrics.descent = 0;    aMetrics.mCarriedOutBottomMargin = 0;    // Note: Don't zero out the max-element-sizes: they will be zero    // if this is truly empty, otherwise they won't because of a    // floater.    if (nsnull != aMetrics.maxElementSize) {      aMetrics.maxElementSize->width = aState.mMaxElementSize.width;      aMetrics.maxElementSize->height = aState.mMaxElementSize.height;    }  }  else {    // Compute final width    nscoord maxWidth = 0, maxHeight = 0;    nscoord minWidth = aState.mKidXMost + borderPadding.right;    if (!HaveAutoWidth(aReflowState)) {      // Use style defined width      aMetrics.width = borderPadding.left + aReflowState.mComputedWidth +        borderPadding.right;      // XXX quote css1 section here      if ((0 == aReflowState.mComputedWidth) && (aMetrics.width < minWidth)) {        aMetrics.width = minWidth;      }      // When style defines the width use it for the max-element-size      // because we can't shrink any smaller.      maxWidth = aMetrics.width;    }    else {      nscoord computedWidth = minWidth;      PRBool compact = PR_FALSE;#if 0      if (NS_STYLE_DISPLAY_COMPACT == aReflowState.mStyleDisplay->mDisplay) {        // If we are display: compact AND we have no lines or we have        // exactly one line and that line is not a block line AND that        // line doesn't end in a BR of any sort THEN we remain a compact        // frame.        if ((nsnull == mLines) ||            ((nsnull == mLines->mNext) && !mLines->IsBlock() &&             (NS_STYLE_CLEAR_NONE == mLines->GetBreakType())             /*XXX && (computedWidth <= aState.mCompactMarginWidth) */              )) {          compact = PR_TRUE;        }      }#endif      // There are two options here. We either shrink wrap around our      // contents or we fluff out to the maximum block width. Note:      // We always shrink wrap when given an unconstrained width.      if ((0 == (NS_BLOCK_SHRINK_WRAP & mFlags)) &&          !aState.mUnconstrainedWidth &&          !compact) {        // Set our width to the max width if we aren't already that        // wide. Note that the max-width has nothing to do with our        // contents (CSS2 section XXX)        computedWidth = borderPadding.left + aState.mContentArea.width +          borderPadding.right;      }      // See if we should compute our max element size      if (aState.mComputeMaxElementSize) {        if (aState.mNoWrap) {          // When no-wrap is true the max-element-size.width is the          // width of the widest line plus the right border. Note that          // aState.mKidXMost already has the left border factored in          maxWidth = aState.mKidXMost + borderPadding.right;        }        else {          // Add in border and padding dimensions to already computed          // max-element-size values.          maxWidth = aState.mMaxElementSize.width +            borderPadding.left + borderPadding.right;        }        // See if our max-element-size width is larger than our        // computed-width. This happens when we are impacted by a        // floater. When this does happen, our desired size needs to        // include room for the floater.        if (computedWidth < maxWidth) {#ifdef DEBUG_kipp          ListTag(stdout);          printf(": adjusting width from %d to %d\n", computedWidth,                 maxWidth);#endif          computedWidth = maxWidth;        }      }      // Apply min/max values      if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedMaxWidth) {        nscoord computedMaxWidth = aReflowState.mComputedMaxWidth +          borderPadding.left + borderPadding.right;        if (computedWidth > computedMaxWidth) {          computedWidth = aReflowState.mComputedMaxWidth;        }      }      if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedMinWidth) {        nscoord computedMinWidth = aReflowState.mComputedMinWidth +          borderPadding.left + borderPadding.right;        if (computedWidth < computedMinWidth) {          computedWidth = computedMinWidth;        }      }      aMetrics.width = computedWidth;    }    // Compute final height    if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedHeight) {      // Use style defined height      aMetrics.height = borderPadding.top + aReflowState.mComputedHeight +        borderPadding.bottom;      // When style defines the height use it for the max-element-size      // because we can't shrink any smaller.      maxHeight = aMetrics.height;      // Don't carry out a bottom margin when our height is fixed      // unless the bottom of the last line adjoins the bottom of our      // content area.      if (!aState.mIsBottomMarginRoot) {        if (aState.mY + aState.mPrevBottomMargin != aMetrics.height) {          aState.mPrevBottomMargin = 0;        }      }    }    else {      nscoord autoHeight = aState.mY;      // Shrink wrap our height around our contents.      if (aState.mIsBottomMarginRoot) {        // When we are a bottom-margin root make sure that our last        // childs bottom margin is fully applied.        // XXX check for a fit        autoHeight += aState.mPrevBottomMargin;      }      autoHeight += borderPadding.bottom;      // Apply min/max values      if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedMaxHeight) {        nscoord computedMaxHeight = aReflowState.mComputedMaxHeight +          borderPadding.top + borderPadding.bottom;        if (autoHeight > computedMaxHeight) {          autoHeight = computedMaxHeight;        }      }      if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedMinHeight) {        nscoord computedMinHeight = aReflowState.mComputedMinHeight +          borderPadding.top + borderPadding.bottom;        if (autoHeight < computedMinHeight) {          autoHeight = computedMinHeight;        }      }      aMetrics.height = autoHeight;      if (aState.mComputeMaxElementSize) {        maxHeight = aState.mMaxElementSize.height +          borderPadding.top + borderPadding.bottom;      }    }    aMetrics.ascent = aMetrics.height;    aMetrics.descent = 0;    if (aState.mComputeMaxElementSize) {      // Store away the final value      aMetrics.maxElementSize->width = maxWidth;      aMetrics.maxElementSize->height = maxHeight;    }    // Return bottom margin information    aMetrics.mCarriedOutBottomMargin =      aState.mIsBottomMarginRoot ? 0 : aState.mPrevBottomMargin;#ifdef DEBUG    if (CRAZY_WIDTH(aMetrics.width) || CRAZY_HEIGHT(aMetrics.height)) {      ListTag(stdout);      printf(": WARNING: desired:%d,%d\n", aMetrics.width, aMetrics.height);    }    if (aState.mComputeMaxElementSize &&        ((maxWidth > aMetrics.width) || (maxHeight > aMetrics.height))) {      ListTag(stdout);      printf(": WARNING: max-element-size:%d,%d desired:%d,%d maxSize:%d,%d\n",             maxWidth, maxHeight, aMetrics.width, aMetrics.height,             aState.mReflowState.availableWidth,             aState.mReflowState.availableHeight);    }#endif#ifdef NOISY_MAX_ELEMENT_SIZE    if (aState.mComputeMaxElementSize) {      IndentBy(stdout, GetDepth());      if (NS_UNCONSTRAINEDSIZE == aState.mReflowState.availableWidth) {        printf("PASS1 ");      }      ListTag(stdout);      printf(": max-element-size:%d,%d desired:%d,%d maxSize:%d,%d\n",             maxWidth, maxHeight, aMetrics.width, aMetrics.height,             aState.mReflowState.availableWidth,             aState.mReflowState.availableHeight);    }#endif  }  // Compute the combined area of our children// XXX_perf: This can be done incrementally  nscoord xa = 0, ya = 0, xb = aMetrics.width, yb = aMetrics.height;  if (NS_STYLE_OVERFLOW_HIDDEN != aReflowState.mStyleDisplay->mOverflow) {    nsLineBox* line = mLines;    while (nsnull != line) {      // Compute min and max x/y values for the reflowed frame's      // combined areas      nsRect lineCombinedArea;      line->GetCombinedArea(&lineCombinedArea);      nscoord x = lineCombinedArea.x;      nscoord y = lineCombinedArea.y;      nscoord xmost = x + lineCombinedArea.width;      nscoord ymost = y + lineCombinedArea.height;      if (x < xa) {        xa = x;      }      if (xmost > xb) {        xb = xmost;      }      if (y < ya) {        ya = y;      }      if (ymost > yb) {        yb = ymost;      }      line = line->mNext;    }    // Factor the bullet in; normally the bullet will be factored into    // the line-box's combined area. However, if the line is a block    // line then it won't; if there are no lines, it won't. So just    // factor it in anyway (it can't hurt if it was already done).    if (mBullet) {      nsRect r;      mBullet->GetRect(r);      if (r.x < xa) xa = r.x;      if (r.y < ya) ya = r.y;      nscoord xmost = r.XMost();      if (xmost > xb) xb = xmost;      nscoord ymost = r.YMost();      if (ymost > yb) yb = ymost;    }  }#ifdef NOISY_COMBINED_AREA  ListTag(stdout);  printf(": ca=%d,%d,%d,%d\n", xa, ya, xb-xa, yb-ya);#endif  // If the combined area of our children exceeds our bounding box  // then set the NS_FRAME_OUTSIDE_CHILDREN flag, otherwise clear it.  aMetrics.mCombinedArea.x = xa;  aMetrics.mCombinedArea.y = ya;  aMetrics.mCombinedArea.width = xb - xa;  aMetrics.mCombinedArea.height = yb - ya;  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;  }}