nsInlineReflow::MaxMargin(childsCarriedOutBottomMargin, childsTopMargin);
nsInlineReflow::MaxMargin(childsCarriedOutTopMargin, childsTopMargin);
nsBlockFrame::CalculateMargins(nsBlockReflowState& aState,                               LineData* aLine,                               PRBool aInlineContext,                               nscoord& aTopMarginResult,                               nscoord& aBottomMarginResult){  PRUintn result = 0;  nsInlineReflow& ir = *aState.mInlineReflow;  // First get the childs top and bottom margins. For inline  // situations the child frame(s) margins were applied during line  // layout, therefore we consider them zero here.  nscoord childsTopMargin, childsBottomMargin;  PRUintn marginFlags;  if (aInlineContext) {    childsTopMargin = 0;    childsBottomMargin = 0;    marginFlags = ir.GetCarriedOutMarginFlags();  }  else {    childsTopMargin = ir.GetTopMargin();    childsBottomMargin = ir.GetBottomMargin();    marginFlags = ir.GetMarginFlags();  }  // Get the carried margin values. Note that even in an inline  // situation there may be a carried margin (e.g. an inline frame  // contains a block frame and the block frame has top/bottom  // margins). While CSS doesn't specify what this means, we do to  // improve compatability with poorly formed HTML (and commonly used  // HTML).  nscoord childsCarriedOutTopMargin = ir.GetCarriedOutTopMargin();  nscoord childsCarriedOutBottomMargin = ir.GetCarriedOutBottomMargin();  if (childsCarriedOutTopMargin || childsCarriedOutBottomMargin) {    result |= HAVE_CARRIED_MARGIN;  }  // Compute the collapsed top margin value (this is a generational  // margin collapse not a sibling margin collapse).  nscoord collapsedTopMargin =     nsInlineReflow::MaxMargin(childsCarriedOutBottomMargin, childsTopMargin);  // Now perform sibling to sibling margin collapsing.  collapsedTopMargin = nsInlineReflow::MaxMargin(aState.mPrevBottomMargin,                                                 collapsedTopMargin);  PRBool topMarginIsAuto = PR_FALSE;  if (NS_CARRIED_TOP_MARGIN_IS_AUTO & marginFlags) {    if (aInlineContext) {      topMarginIsAuto = collapsedTopMargin == childsCarriedOutTopMargin;    }    else {      topMarginIsAuto = collapsedTopMargin == childsTopMargin;    }  }  // Compute the collapsed bottom margin value (this is a generational  // margin collapse not a sibling margin collapse).  nscoord collapsedBottomMargin =    nsInlineReflow::MaxMargin(childsCarriedOutBottomMargin,                              childsBottomMargin);  if (NS_CARRIED_BOTTOM_MARGIN_IS_AUTO & marginFlags) {    if (aInlineContext) {      if (collapsedBottomMargin == childsCarriedOutBottomMargin) {        result |= NS_CARRIED_BOTTOM_MARGIN_IS_AUTO;      }    }    else if (collapsedBottomMargin == childsBottomMargin) {      result |= NS_CARRIED_BOTTOM_MARGIN_IS_AUTO;    }  }  // Now that we have the collapsed margin values, address any special  // situations that limit or change how the margins are applied.  if (0 == aLine->mBounds.height) {    // When a line is empty, we collapse its top and bottom margins to    // a single bottom margin value.    // XXX This is not obviously a part of the css2 box model.    collapsedBottomMargin =      nsInlineReflow::MaxMargin(collapsedTopMargin, collapsedBottomMargin);    collapsedTopMargin = 0;  }  else {    PRBool isTopLine = (aState.mY == aState.mBorderPadding.top);    if (isTopLine) {      if (!aState.mIsMarginRoot) {        // We are not a root for margin collapsing and this is our first        // non-empty-line (with a block child).        if (topMarginIsAuto) {          // Propogate auto-margin flag outward          aState.mCarriedOutMarginFlags |= NS_CARRIED_TOP_MARGIN_IS_AUTO;          result |= NS_CARRIED_TOP_MARGIN_IS_AUTO;        }        // Keep the collapsed margin value around to pass out to our        // parent. We don't apply its top margin (our parent will) so        // zero it out.        aState.mCollapsedTopMargin = collapsedTopMargin;        collapsedTopMargin = 0;      }      else if (topMarginIsAuto && (NS_BODY_NO_AUTO_MARGINS & mFlags)) {        // Our top margin is an auto margin and we are supposed to        // ignore them. Change it to zero.        collapsedTopMargin = 0;      }    }  }  aTopMarginResult = collapsedTopMargin;  aBottomMarginResult = collapsedBottomMargin;  return result;}