if (0 < attrCount) {  mPart->GetHTMLAttribute(nsHTMLAtoms::marginwidth, value); if (eHTMLUnit_Pixel == value.GetUnit()) { bodyMarginWidth = NSIntPixelsToTwips(value.GetPixelValue(), p2t); if (bodyMarginWidth < 0) { bodyMarginWidth = 0;
if ((!bodyStyleColor->BackgroundIsTransparent()) || (!htmlStyleColor->BackgroundIsTransparent()) || (!canvasStyleColor->BackgroundIsTransparent()) || (NS_STYLE_BG_PROPAGATED_FROM_CHILD == (htmlStyleColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_FROM_CHILD)) ) {    if (!(htmlStyleColor->BackgroundIsTransparent())) { styleColor = htmlStyleColor; } else { styleColor = bodyStyleColor; }   canvasStyleColor->mBackgroundAttachment = styleColor->mBackgroundAttachment; canvasStyleColor->mBackgroundRepeat = styleColor->mBackgroundRepeat; canvasStyleColor->mBackgroundColor = styleColor->mBackgroundColor; canvasStyleColor->mBackgroundXPosition = styleColor->mBackgroundXPosition; canvasStyleColor->mBackgroundYPosition = styleColor->mBackgroundYPosition; canvasStyleColor->mBackgroundImage = styleColor->mBackgroundImage; canvasStyleColor->mBackgroundFlags = (styleColor->mBackgroundFlags & ~NS_STYLE_BG_PROPAGATED_TO_PARENT); canvasStyleColor->mBackgroundFlags |= NS_STYLE_BG_PROPAGATED_FROM_CHILD;  bFixedBackground = canvasStyleColor->mBackgroundAttachment == NS_STYLE_BG_ATTACHMENT_FIXED ? PR_TRUE : PR_FALSE;   styleColor->mBackgroundImage.SetLength(0); styleColor->mBackgroundAttachment = NS_STYLE_BG_ATTACHMENT_SCROLL; styleColor->mBackgroundFlags = NS_STYLE_BG_COLOR_TRANSPARENT | NS_STYLE_BG_IMAGE_NONE | NS_STYLE_BG_PROPAGATED_TO_PARENT;        if (styleColor == bodyStyleColor) { htmlStyleColor->mBackgroundFlags |= NS_STYLE_BG_PROPAGATED_TO_PARENT; } }  nsCOMPtr<nsIPresShell> presShell; aPresContext->GetShell(getter_AddRefs(presShell)); if (presShell) { nsCOMPtr<nsIDocument> doc; presShell->GetDocument(getter_AddRefs(doc)); if (doc) { nsIHTMLContentContainer*  htmlContainer; if (NS_OK == doc->QueryInterface(kIHTMLContentContainerIID, (void**)&htmlContainer)) { nsIHTMLStyleSheet* styleSheet; if (NS_OK == htmlContainer->GetAttributeStyleSheet(&styleSheet)) { styleSheet->SetDocumentForegroundColor(styleColor->mColor); if (!(styleColor->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)) { styleSheet->SetDocumentBackgroundColor(styleColor->mBackgroundColor);
BodyRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext){  if (nsnull != mPart) {    nsStyleSpacing* styleSpacing = (nsStyleSpacing*)(aContext->GetMutableStyleData(eStyleStruct_Spacing));    if (nsnull != styleSpacing) {      nsHTMLValue   value;      PRInt32       attrCount;      float         p2t;      mPart->GetAttributeCount(attrCount);      aPresContext->GetScaledPixelsToTwips(&p2t);      nscoord bodyMarginWidth  = -1;      nscoord bodyMarginHeight = -1;      if (0 < attrCount) {        // if marginwidth/marginheigth is set reflect them as 'margin'        mPart->GetHTMLAttribute(nsHTMLAtoms::marginwidth, value);        if (eHTMLUnit_Pixel == value.GetUnit()) {          bodyMarginWidth = NSIntPixelsToTwips(value.GetPixelValue(), p2t);          if (bodyMarginWidth < 0) {            bodyMarginWidth = 0;          }          nsStyleCoord  widthCoord(bodyMarginWidth);          styleSpacing->mMargin.SetLeft(widthCoord);          styleSpacing->mMargin.SetRight(widthCoord);        }        mPart->GetHTMLAttribute(nsHTMLAtoms::marginheight, value);        if (eHTMLUnit_Pixel == value.GetUnit()) {          bodyMarginHeight = NSIntPixelsToTwips(value.GetPixelValue(), p2t);          if (bodyMarginHeight < 0) {            bodyMarginHeight = 0;          }                nsStyleCoord  heightCoord(bodyMarginHeight);          styleSpacing->mMargin.SetTop(heightCoord);          styleSpacing->mMargin.SetBottom(heightCoord);        }      }      // XXX This is all pretty hokey...      // if marginwidth or marginheight is set in the <frame> and not set in the <body>      // reflect them as margin in the <body>      if ((0 > bodyMarginWidth) || (0 > bodyMarginHeight)) {        nsISupports* container;        aPresContext->GetContainer(&container);        if (nsnull != container) {          nsCompatibility mode;          aPresContext->GetCompatibilityMode(&mode);          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) && (0 > bodyMarginWidth)) { // set in <frame> & not in <body>               if (eCompatibility_NavQuirks == mode) {                if ((0 > bodyMarginHeight) && (0 > frameMarginHeight)) { // nav quirk                   frameMarginHeight = 0;                }              }            }            if ((frameMarginHeight >= 0) && (0 > bodyMarginHeight)) { // set in <frame> & not in <body>               if (eCompatibility_NavQuirks == mode) {                if ((0 > bodyMarginWidth) && (0 > frameMarginWidth)) { // nav quirk                  frameMarginWidth = 0;                }              }            }            if ((0 > bodyMarginWidth) && (frameMarginWidth >= 0)) {              nsStyleCoord widthCoord(frameMarginWidth);              styleSpacing->mMargin.SetLeft(widthCoord);              styleSpacing->mMargin.SetRight(widthCoord);            }            if ((0 > bodyMarginHeight) && (frameMarginHeight >= 0)) {              nsStyleCoord heightCoord(frameMarginHeight);              styleSpacing->mMargin.SetTop(heightCoord);              styleSpacing->mMargin.SetBottom(heightCoord);            }          }          NS_RELEASE(container);        }      }    }  }  return NS_OK;}