} else { if (eStyleUnit_Inherit == heightUnit) { mComputedHeight = containingBlockHeight; } else {  ComputeVerticalValue(containingBlockHeight, heightUnit, mStylePosition->mHeight, mComputedHeight); }   if (mComputedHeight > mComputedMaxHeight) { mComputedHeight = mComputedMaxHeight; } if (mComputedHeight < mComputedMinHeight) { mComputedHeight = mComputedMinHeight; } }   if (NS_AUTOHEIGHT != containingBlockHeight) { if (bottomIsAuto) {  mComputedOffsets.bottom = containingBlockHeight - mComputedOffsets.top - mComputedMargin.top - mComputedBorderPadding.top - mComputedHeight - mComputedBorderPadding.bottom - mComputedMargin.bottom;  } else if (marginTopIsAuto || marginBottomIsAuto) {   if (NS_FRAME_IS_REPLACED(mFrameType)) {   if (marginTopIsAuto) { mComputedMargin.top = NS_AUTOMARGIN; } if (marginBottomIsAuto) { mComputedMargin.bottom = NS_AUTOMARGIN; } } else {  nscoord availMarginSpace = containingBlockHeight - mComputedOffsets.top - mComputedBorderPadding.top - mComputedHeight - mComputedBorderPadding.bottom - mComputedOffsets.bottom;  if (marginTopIsAuto) { if (marginBottomIsAuto) {   mComputedMargin.top = availMarginSpace / 2; mComputedMargin.bottom = availMarginSpace - mComputedMargin.top; } else {  mComputedMargin.top = availMarginSpace - mComputedMargin.bottom; } } else {  mComputedMargin.bottom = availMarginSpace - mComputedMargin.top; } } }
nsHTMLReflowState::InitAbsoluteConstraints(nsIPresContext& aPresContext,                                           const nsHTMLReflowState* cbrs,                                           nscoord containingBlockWidth,                                           nscoord containingBlockHeight){  // If any of the offsets are 'auto', then get the placeholder frame  // and compute its origin relative to the containing block  nsPoint placeholderOffset(0, 0);  if ((eStyleUnit_Auto == mStylePosition->mOffset.GetLeftUnit()) ||      (eStyleUnit_Auto == mStylePosition->mOffset.GetTopUnit()) ||      (eStyleUnit_Auto == mStylePosition->mOffset.GetRightUnit()) ||      (eStyleUnit_Auto == mStylePosition->mOffset.GetBottomUnit())) {        // Get the placeholder frame    nsIFrame*     placeholderFrame;    nsCOMPtr<nsIPresShell> presShell;    aPresContext.GetShell(getter_AddRefs(presShell));    presShell->GetPlaceholderFrameFor(frame, &placeholderFrame);    NS_ASSERTION(nsnull != placeholderFrame, "no placeholder frame");    if (nsnull != placeholderFrame) {      placeholderFrame->GetOrigin(placeholderOffset);      nsIFrame* parent;      placeholderFrame->GetParent(&parent);      while ((nsnull != parent) && (parent != cbrs->frame)) {        nsPoint origin;        parent->GetOrigin(origin);        placeholderOffset += origin;        parent->GetParent(&parent);      }      // Offsets are relative to the containing block's padding edge, so translate      // from the frame's edge to the padding edge      nsMargin              blockBorder;      const nsStyleSpacing* blockSpacing;      cbrs->frame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct*&)blockSpacing);      blockSpacing->GetBorder(blockBorder);      placeholderOffset.x -= blockBorder.top;      placeholderOffset.y -= blockBorder.bottom;    }  }  nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();  nsStyleUnit heightUnit = mStylePosition->mHeight.GetUnit();  // Initialize the 'left' and 'right' computed offsets  PRBool        leftIsAuto = PR_FALSE, rightIsAuto = PR_FALSE;  nsStyleCoord  coord;  if (eStyleUnit_Inherit == mStylePosition->mOffset.GetLeftUnit()) {    mComputedOffsets.left = cbrs->mComputedOffsets.left;  } else if (eStyleUnit_Auto == mStylePosition->mOffset.GetLeftUnit()) {    if (NS_STYLE_DIRECTION_LTR == mStyleDisplay->mDirection) {      mComputedOffsets.left = placeholderOffset.x;    } else {      mComputedOffsets.left = 0;      leftIsAuto = PR_TRUE;    }  } else {    ComputeHorizontalValue(containingBlockWidth, mStylePosition->mOffset.GetLeftUnit(),                           mStylePosition->mOffset.GetLeft(coord),                           mComputedOffsets.left);  }  if (eStyleUnit_Inherit == mStylePosition->mOffset.GetRightUnit()) {    mComputedOffsets.right = cbrs->mComputedOffsets.right;  } else if (eStyleUnit_Auto == mStylePosition->mOffset.GetRightUnit()) {    if (NS_STYLE_DIRECTION_RTL == mStyleDisplay->mDirection) {      mComputedOffsets.right = placeholderOffset.x;    } else {      mComputedOffsets.right = 0;      rightIsAuto = PR_TRUE;    }  } else {    ComputeHorizontalValue(containingBlockWidth, mStylePosition->mOffset.GetRightUnit(),                           mStylePosition->mOffset.GetRight(coord),                           mComputedOffsets.right);  }  // Calculate the computed width  PRBool  marginLeftIsAuto = (eStyleUnit_Auto == mStyleSpacing->mMargin.GetLeftUnit());  PRBool  marginRightIsAuto = (eStyleUnit_Auto == mStyleSpacing->mMargin.GetRightUnit());  if (eStyleUnit_Auto == widthUnit) {    // The element has a 'width' value of 'auto'    if (NS_FRAME_IS_REPLACED(mFrameType)) {      // Substitute the element's intrinsic width      mComputedWidth = NS_INTRINSICSIZE;    } else {      // Any remaining 'auto' values for 'left', 'right', 'margin-left', or      // 'margin-right' are replaced with 0 (their default value)      mComputedWidth = containingBlockWidth - mComputedOffsets.left -        mComputedMargin.left - mComputedBorderPadding.left -        mComputedBorderPadding.right -        mComputedMargin.right - mComputedOffsets.right;      // Factor in any minimum and maximum size information      if (mComputedWidth > mComputedMaxWidth) {        mComputedWidth = mComputedMaxWidth;      } else if (mComputedWidth < mComputedMinWidth) {        mComputedWidth = mComputedMinWidth;      } else {        // Note that we wait until after checkin minimum and maximum size        // information, because if we use the minimum or maximum value instead        // then the rules are applied again and that means margin recalculation        leftIsAuto = PR_FALSE;        rightIsAuto = PR_FALSE;        marginLeftIsAuto = PR_FALSE;        marginRightIsAuto = PR_FALSE;      }    }  } else {    if (eStyleUnit_Inherit == widthUnit) {      mComputedWidth = containingBlockWidth;    } else {      // Use the specified value for the computed width      ComputeHorizontalValue(containingBlockWidth, widthUnit,                             mStylePosition->mWidth, mComputedWidth);    }    // Factor in any minimum and maximum size information    if (mComputedWidth > mComputedMaxWidth) {      mComputedWidth = mComputedMaxWidth;    } else if (mComputedWidth < mComputedMinWidth) {      mComputedWidth = mComputedMinWidth;    }  }  // Calculate any remaining 'auto' values for the offsets and margins  if (leftIsAuto) {    // Any 'auto' on 'margin-left' or 'margin-right' are replaced with 0    // (their default value)    mComputedOffsets.left = containingBlockWidth - mComputedMargin.left -      mComputedBorderPadding.left - mComputedWidth -      mComputedBorderPadding.right -      mComputedMargin.right - mComputedOffsets.right;  } else if (rightIsAuto) {    // Any 'auto' on 'margin-left' or 'margin-right' are replaced with 0    // (their default value)    mComputedOffsets.right = containingBlockWidth - mComputedOffsets.left -      mComputedMargin.left - mComputedBorderPadding.left - mComputedWidth -      mComputedBorderPadding.right - mComputedMargin.right;  } else if (marginLeftIsAuto || marginRightIsAuto) {    // All that's left to solve for are 'auto' values for 'margin-left' and    // 'margin-right'    if (NS_FRAME_IS_REPLACED(mFrameType)) {      // We can't solve for 'auto' values for 'margin-left' and 'margin-right'      // until after we reflow the frame and it tells us its intrinsic width      if (marginLeftIsAuto) {        mComputedMargin.left = NS_AUTOMARGIN;      }      if (marginRightIsAuto) {        mComputedMargin.right = NS_AUTOMARGIN;      }    } else {      // Calculate the amount of space for margins      nscoord availMarginSpace = containingBlockWidth -        mComputedOffsets.left - mComputedBorderPadding.left -        mComputedWidth - mComputedBorderPadding.right -        mComputedOffsets.right;        if (marginLeftIsAuto) {        if (marginRightIsAuto) {          // Both 'margin-left' and 'margin-right' are 'auto', so they get          // equal values          mComputedMargin.left = availMarginSpace / 2;          mComputedMargin.right = availMarginSpace - mComputedMargin.left;        } else {          // Just 'margin-left' is 'auto'          mComputedMargin.left = availMarginSpace - mComputedMargin.right;        }      } else {        // Just 'margin-right' is 'auto'        mComputedMargin.right = availMarginSpace - mComputedMargin.left;      }    }  }  // Initialize the 'top' and 'bottom' computed offsets  PRBool  bottomIsAuto = PR_FALSE;  if (eStyleUnit_Inherit == mStylePosition->mOffset.GetTopUnit()) {    mComputedOffsets.top = cbrs->mComputedOffsets.top;  } else if ((eStyleUnit_Auto == mStylePosition->mOffset.GetTopUnit()) ||      ((NS_AUTOHEIGHT == containingBlockHeight) &&       (eStyleUnit_Percent == mStylePosition->mOffset.GetTopUnit()))) {    // Use the placeholder position    mComputedOffsets.top = placeholderOffset.y;  } else {    nsStyleCoord c;    ComputeVerticalValue(containingBlockHeight,                         mStylePosition->mOffset.GetTopUnit(),                         mStylePosition->mOffset.GetTop(c),                         mComputedOffsets.top);  }  if (eStyleUnit_Inherit == mStylePosition->mOffset.GetBottomUnit()) {    mComputedOffsets.bottom = cbrs->mComputedOffsets.bottom;  } else if ((eStyleUnit_Auto == mStylePosition->mOffset.GetBottomUnit()) ||      ((NS_AUTOHEIGHT == containingBlockHeight) &&       (eStyleUnit_Percent == mStylePosition->mOffset.GetBottomUnit()))) {    if (eStyleUnit_Auto == heightUnit) {      mComputedOffsets.bottom = 0;            } else {      bottomIsAuto = PR_TRUE;    }  } else {    nsStyleCoord c;    ComputeVerticalValue(containingBlockHeight,                         mStylePosition->mOffset.GetBottomUnit(),                         mStylePosition->mOffset.GetBottom(c),                         mComputedOffsets.bottom);  }  // Check for a percentage based height and a containing block height  // that depends on its content height, i.e., not explicitly specified  if (eStyleUnit_Percent == heightUnit) {    if (NS_AUTOHEIGHT == containingBlockHeight) {      // Interpret the height like 'auto'      heightUnit = eStyleUnit_Auto;    }  }  // Calculate the computed height  PRBool  marginTopIsAuto = (eStyleUnit_Auto == mStyleSpacing->mMargin.GetTopUnit());  PRBool  marginBottomIsAuto = (eStyleUnit_Auto == mStyleSpacing->mMargin.GetBottomUnit());    if (eStyleUnit_Auto == heightUnit) {    if (NS_FRAME_IS_REPLACED(mFrameType)) {      mComputedHeight = NS_INTRINSICSIZE;    } else {      // Solve for the value of 'height'      if (NS_AUTOHEIGHT == containingBlockHeight) {        // If the containing block's height was not explicitly specified (i.e.,        // it depends on its content height), then so does our height        mComputedHeight = NS_AUTOHEIGHT;      } else {        // Replace any 'auto' on 'margin-top' or 'margin-bottom' with 0 (their        // default values). If 'bottom' is 'auto', then replace it with '0' (its        // default value), too        mComputedHeight = containingBlockHeight - mComputedOffsets.top -           mComputedMargin.top - mComputedBorderPadding.top -          mComputedBorderPadding.bottom -          mComputedMargin.bottom - mComputedOffsets.bottom;                // Factor in any minimum and maximum size information        if (mComputedHeight > mComputedMaxHeight) {          mComputedHeight = mComputedMaxHeight;        } else if (mComputedHeight < mComputedMinHeight) {          mComputedHeight = mComputedMinHeight;        } else {          // Note that we wait until after checkin minimum and maximum size          // information, because if we use the minimum or maximum value instead          // then the rules are applied again and that means margin recalculation          marginTopIsAuto = PR_FALSE;          marginBottomIsAuto = PR_FALSE;          bottomIsAuto = PR_FALSE;        }      }    }  } else {    if (eStyleUnit_Inherit == heightUnit) {      mComputedHeight = containingBlockHeight;    } else {      // Use the specified value for the computed height      ComputeVerticalValue(containingBlockHeight, heightUnit,                           mStylePosition->mHeight, mComputedHeight);    }    // Factor in any minimum and maximum size information    if (mComputedHeight > mComputedMaxHeight) {      mComputedHeight = mComputedMaxHeight;    }    if (mComputedHeight < mComputedMinHeight) {      mComputedHeight = mComputedMinHeight;    }  }  // Calculate any remaining 'auto' values for the offsets and margins  if (NS_AUTOHEIGHT != containingBlockHeight) {    if (bottomIsAuto) {      // Any 'auto' on 'margin-top' or 'margin-bottom' are replaced with 0      mComputedOffsets.bottom = containingBlockHeight - mComputedOffsets.top -        mComputedMargin.top - mComputedBorderPadding.top - mComputedHeight -        mComputedBorderPadding.bottom - mComputedMargin.bottom;    } else if (marginTopIsAuto || marginBottomIsAuto) {      // All that's left to solve for are 'auto' values for 'margin-top' and      // 'margin-bottom'      if (NS_FRAME_IS_REPLACED(mFrameType)) {        // We can't solve for 'auto' values for 'margin-top' and 'margin-bottom'        // until after we reflow the frame and it tells us its intrinsic height        if (marginTopIsAuto) {          mComputedMargin.top = NS_AUTOMARGIN;        }        if (marginBottomIsAuto) {          mComputedMargin.bottom = NS_AUTOMARGIN;        }      } else {        // Calculate the amount of space for margins        nscoord availMarginSpace = containingBlockHeight - mComputedOffsets.top -          mComputedBorderPadding.top - mComputedHeight - mComputedBorderPadding.bottom -          mComputedOffsets.bottom;        if (marginTopIsAuto) {          if (marginBottomIsAuto) {            // Both 'margin-top' and 'margin-bottom' are 'auto', so they get            // equal values            mComputedMargin.top = availMarginSpace / 2;            mComputedMargin.bottom = availMarginSpace - mComputedMargin.top;          } else {            // Just 'margin-top' is 'auto'            mComputedMargin.top = availMarginSpace - mComputedMargin.bottom;          }        } else {          // Just 'margin-bottom' is 'auto'          mComputedMargin.bottom = availMarginSpace - mComputedMargin.top;        }      }    }  }}