nsCompatibility mode;
BodyRule::MapRuleInfoInto(nsRuleData* aData){  if (!aData || (aData->mSID != eStyleStruct_Margin) || !aData->mMarginData || !mPart)    return NS_OK; // We only care about margins.  nsHTMLValue value;    PRInt32 bodyMarginWidth  = -1;  PRInt32 bodyMarginHeight = -1;  PRInt32 bodyTopMargin = -1;  PRInt32 bodyBottomMargin = -1;  PRInt32 bodyLeftMargin = -1;  PRInt32 bodyRightMargin = -1;  // check the mode (fortunately, the ruleData has a presContext for us to use!)  nsCompatibility mode;  NS_ASSERTION(aData->mPresContext, "null presContext in ruleNode was unexpected");  aData->mPresContext->GetCompatibilityMode(&mode);  if (mPart->GetAttrCount() > 0) {    // if marginwidth/marginheight are set, reflect them as 'margin'    mPart->GetHTMLAttribute(nsHTMLAtoms::marginwidth, value);    if (eHTMLUnit_Pixel == value.GetUnit()) {      bodyMarginWidth = value.GetPixelValue();      if (bodyMarginWidth < 0) bodyMarginWidth = 0;      nsCSSRect& margin = aData->mMarginData->mMargin;      if (margin.mLeft.GetUnit() == eCSSUnit_Null)        margin.mLeft.SetFloatValue((float)bodyMarginWidth, eCSSUnit_Pixel);      if (margin.mRight.GetUnit() == eCSSUnit_Null)        margin.mRight.SetFloatValue((float)bodyMarginWidth, eCSSUnit_Pixel);    }    mPart->GetHTMLAttribute(nsHTMLAtoms::marginheight, value);    if (eHTMLUnit_Pixel == value.GetUnit()) {      bodyMarginHeight = value.GetPixelValue();      if (bodyMarginHeight < 0) bodyMarginHeight = 0;      nsCSSRect& margin = aData->mMarginData->mMargin;      if (margin.mTop.GetUnit() == eCSSUnit_Null)        margin.mTop.SetFloatValue((float)bodyMarginHeight, eCSSUnit_Pixel);      if (margin.mBottom.GetUnit() == eCSSUnit_Null)        margin.mBottom.SetFloatValue((float)bodyMarginHeight, eCSSUnit_Pixel);    }    if (eCompatibility_NavQuirks == mode){      // topmargin (IE-attribute)      mPart->GetHTMLAttribute(nsHTMLAtoms::topmargin, value);      if (eHTMLUnit_Pixel == value.GetUnit()) {        bodyTopMargin = value.GetPixelValue();        if (bodyTopMargin < 0) bodyTopMargin = 0;        nsCSSRect& margin = aData->mMarginData->mMargin;        if (margin.mTop.GetUnit() == eCSSUnit_Null)          margin.mTop.SetFloatValue((float)bodyTopMargin, eCSSUnit_Pixel);      }      // bottommargin (IE-attribute)      mPart->GetHTMLAttribute(nsHTMLAtoms::bottommargin, value);      if (eHTMLUnit_Pixel == value.GetUnit()) {        bodyBottomMargin = value.GetPixelValue();        if (bodyBottomMargin < 0) bodyBottomMargin = 0;        nsCSSRect& margin = aData->mMarginData->mMargin;        if (margin.mBottom.GetUnit() == eCSSUnit_Null)          margin.mBottom.SetFloatValue((float)bodyBottomMargin, eCSSUnit_Pixel);      }      // leftmargin (IE-attribute)      mPart->GetHTMLAttribute(nsHTMLAtoms::leftmargin, value);      if (eHTMLUnit_Pixel == value.GetUnit()) {        bodyLeftMargin = value.GetPixelValue();        if (bodyLeftMargin < 0) bodyLeftMargin = 0;        nsCSSRect& margin = aData->mMarginData->mMargin;        if (margin.mLeft.GetUnit() == eCSSUnit_Null)          margin.mLeft.SetFloatValue((float)bodyLeftMargin, eCSSUnit_Pixel);      }      // rightmargin (IE-attribute)      mPart->GetHTMLAttribute(nsHTMLAtoms::rightmargin, value);      if (eHTMLUnit_Pixel == value.GetUnit()) {        bodyRightMargin = value.GetPixelValue();        if (bodyRightMargin < 0) bodyRightMargin = 0;        nsCSSRect& margin = aData->mMarginData->mMargin;        if (margin.mRight.GetUnit() == eCSSUnit_Null)          margin.mRight.SetFloatValue((float)bodyRightMargin, eCSSUnit_Pixel);      }    }  }  // if marginwidth or marginheight is set in the <frame> and not set in the <body>  // reflect them as margin in the <body>  if (bodyMarginWidth == -1 || bodyMarginHeight == -1) {    nsCOMPtr<nsISupports> container;    aData->mPresContext->GetContainer(getter_AddRefs(container));    if (container) {      nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));      if (docShell) {        nscoord frameMarginWidth=-1;  // default value        nscoord frameMarginHeight=-1; // default value        docShell->GetMarginWidth(&frameMarginWidth); // -1 indicates not set           docShell->GetMarginHeight(&frameMarginHeight);         if ((frameMarginWidth >= 0) && (bodyMarginWidth == -1)) { // set in <frame> & not in <body>           if (eCompatibility_NavQuirks == mode) {            if ((bodyMarginHeight == -1) && (0 > frameMarginHeight)) // nav quirk               frameMarginHeight = 0;          }        }        if ((frameMarginHeight >= 0) && (bodyMarginHeight == -1)) { // set in <frame> & not in <body>           if (eCompatibility_NavQuirks == mode) {            if ((bodyMarginWidth == -1) && (0 > frameMarginWidth)) // nav quirk              frameMarginWidth = 0;          }        }        if ((bodyMarginWidth == -1) && (frameMarginWidth >= 0)) {          nsCSSRect& margin = aData->mMarginData->mMargin;          if (margin.mLeft.GetUnit() == eCSSUnit_Null)            margin.mLeft.SetFloatValue((float)frameMarginWidth, eCSSUnit_Pixel);          if (margin.mRight.GetUnit() == eCSSUnit_Null)            margin.mRight.SetFloatValue((float)frameMarginWidth, eCSSUnit_Pixel);        }        if ((bodyMarginHeight == -1) && (frameMarginHeight >= 0)) {          nsCSSRect& margin = aData->mMarginData->mMargin;          if (margin.mTop.GetUnit() == eCSSUnit_Null)            margin.mTop.SetFloatValue((float)frameMarginHeight, eCSSUnit_Pixel);          if (margin.mBottom.GetUnit() == eCSSUnit_Null)            margin.mBottom.SetFloatValue((float)frameMarginHeight, eCSSUnit_Pixel);        }      }    }  }  return NS_OK;}