NS_RELEASE(parentContext);
inline nscoord CalcSideFor(const nsIFrame* aFrame, const nsStyleCoord& aCoord,                            PRUint8 aSpacing, PRUint8 aSide,                           const nscoord* aEnumTable, PRInt32 aNumEnums){  nscoord result = 0;  switch (aCoord.GetUnit()) {    case eStyleUnit_Auto:      // Auto margins are handled by layout      break;    case eStyleUnit_Inherit:      nsIFrame* parentFrame;      aFrame->GetParent(&parentFrame);  // XXX may not be direct parent...      if (nsnull != parentFrame) {        nsIStyleContext* parentContext;        parentFrame->GetStyleContext(&parentContext);        if (nsnull != parentContext) {          nsMargin  parentSpacing;          switch (aSpacing) {            case NS_SPACING_MARGIN:              {                const nsStyleMargin* parentMargin = (const nsStyleMargin*)parentContext->GetStyleData(eStyleStruct_Margin);                parentMargin->CalcMarginFor(parentFrame, parentSpacing);                }              break;            case NS_SPACING_PADDING:              {                const nsStylePadding* parentPadding = (const nsStylePadding*)parentContext->GetStyleData(eStyleStruct_Padding);                parentPadding->CalcPaddingFor(parentFrame, parentSpacing);                }              break;            case NS_SPACING_BORDER:              {                const nsStyleBorder* parentBorder = (const nsStyleBorder*)parentContext->GetStyleData(eStyleStruct_Border);                parentBorder->CalcBorderFor(parentFrame, parentSpacing);                }              break;          }          switch (aSide) {            case NS_SIDE_LEFT:    result = parentSpacing.left;   break;            case NS_SIDE_TOP:     result = parentSpacing.top;    break;            case NS_SIDE_RIGHT:   result = parentSpacing.right;  break;            case NS_SIDE_BOTTOM:  result = parentSpacing.bottom; break;          }          NS_RELEASE(parentContext);        }      }      break;    case eStyleUnit_Percent:      {        nscoord baseWidth = 0;        PRBool  isBase = PR_FALSE;        nsIFrame* frame;        aFrame->GetParent(&frame);        while (nsnull != frame) {          frame->IsPercentageBase(isBase);          if (isBase) {            nsSize  size;            frame->GetSize(size);            baseWidth = size.width;            // subtract border of containing block            const nsStyleBorder* borderData = nsnull;            frame->GetStyleData(eStyleStruct_Border,                                (const nsStyleStruct*&)borderData);            if (borderData) {              nsMargin border;              borderData->CalcBorderFor(frame, border);              baseWidth -= (border.left + border.right);            }            // if aFrame is not absolutely positioned, subtract            // padding of containing block            const nsStyleDisplay* displayData = nsnull;            aFrame->GetStyleData(eStyleStruct_Display,                                 (const nsStyleStruct*&)displayData);            if (displayData &&                displayData->mPosition != NS_STYLE_POSITION_ABSOLUTE &&                displayData->mPosition != NS_STYLE_POSITION_FIXED) {              const nsStylePadding* paddingData = nsnull;              frame->GetStyleData(eStyleStruct_Padding,                                  (const nsStyleStruct*&)paddingData);              if (paddingData) {                nsMargin padding;                paddingData->CalcPaddingFor(frame, padding);                baseWidth -= (padding.left + padding.right);              }            }            break;          }          frame->GetParent(&frame);        }        result = (nscoord)((float)baseWidth * aCoord.GetPercentValue());      }      break;    case eStyleUnit_Coord:      result = aCoord.GetCoordValue();      break;    case eStyleUnit_Enumerated:      if (nsnull != aEnumTable) {        PRInt32 value = aCoord.GetIntValue();        if ((0 <= value) && (value < aNumEnums)) {          return aEnumTable[aCoord.GetIntValue()];        }      }      break;    case eStyleUnit_Null:    case eStyleUnit_Normal:    case eStyleUnit_Integer:    case eStyleUnit_Proportional:    default:      result = 0;      break;  }  if ((NS_SPACING_PADDING == aSpacing) || (NS_SPACING_BORDER == aSpacing)) {    if (result < 0) {      result = 0;    }  }  return result;}