spacingStyle->SetBorderStyle(NS_SIDE_TOP,    NS_STYLE_BORDER_STYLE_BG_INSET); spacingStyle->SetBorderStyle(NS_SIDE_LEFT,   NS_STYLE_BORDER_STYLE_BG_INSET); spacingStyle->SetBorderStyle(NS_SIDE_BOTTOM, NS_STYLE_BORDER_STYLE_BG_INSET); spacingStyle->SetBorderStyle(NS_SIDE_RIGHT,  NS_STYLE_BORDER_STYLE_BG_INSET);
nsCompatibility mode; aPresContext->GetCompatibilityMode(&mode); PRUint8 borderStyle = (eCompatibility_NavQuirks == mode) ? NS_STYLE_BORDER_STYLE_BG_INSET : NS_STYLE_BORDER_STYLE_INSET;
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,                  nsIMutableStyleContext*        aContext,                  nsIPresContext*                aPresContext){  NS_PRECONDITION(nsnull!=aContext, "bad style context arg");  NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg");  if (nsnull!=aAttributes)  {    float sp2t;    aPresContext->GetScaledPixelsToTwips(&sp2t);    nsHTMLValue value;    const nsStyleDisplay* readDisplay = (nsStyleDisplay*)                aContext->GetStyleData(eStyleStruct_Display);    if (readDisplay && (readDisplay->mDisplay == NS_STYLE_DISPLAY_TABLE_CELL)) {      // set the cell's border from the table      aAttributes->GetAttribute(nsHTMLAtoms::border, value);      if (((value.GetUnit() == eHTMLUnit_Pixel) && (value.GetPixelValue() > 0)) ||          (value.GetUnit() == eHTMLUnit_Empty)) {        float p2t;        aPresContext->GetPixelsToTwips(&p2t);        nscoord onePixel = NSIntPixelsToTwips(1, p2t);        nsStyleSpacing* spacingStyle = (nsStyleSpacing*)aContext->GetMutableStyleData(eStyleStruct_Spacing);        nsStyleCoord width;        width.SetCoordValue(onePixel);        spacingStyle->mBorder.SetTop(width);        spacingStyle->mBorder.SetLeft(width);        spacingStyle->mBorder.SetBottom(width);        spacingStyle->mBorder.SetRight(width);        spacingStyle->SetBorderStyle(NS_SIDE_TOP,    NS_STYLE_BORDER_STYLE_BG_INSET);        spacingStyle->SetBorderStyle(NS_SIDE_LEFT,   NS_STYLE_BORDER_STYLE_BG_INSET);        spacingStyle->SetBorderStyle(NS_SIDE_BOTTOM, NS_STYLE_BORDER_STYLE_BG_INSET);        spacingStyle->SetBorderStyle(NS_SIDE_RIGHT,  NS_STYLE_BORDER_STYLE_BG_INSET);        // BG_INSET results in a border color based on background colors      }    }    else {  // handle attributes for table      // width      aAttributes->GetAttribute(nsHTMLAtoms::width, value);      if (value.GetUnit() != eHTMLUnit_Null) {        nsStylePosition* position = (nsStylePosition*)          aContext->GetMutableStyleData(eStyleStruct_Position);        switch (value.GetUnit()) {        case eHTMLUnit_Percent:          // 0 width remains default auto          //if (value.GetPercentValue() > 0.0f) {            position->mWidth.SetPercentValue(value.GetPercentValue());          //}          break;        case eHTMLUnit_Pixel:          // 0 width remains default auto          //if (value.GetPixelValue() > 0) {            position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), sp2t));          //}          break;        default:          break;        }      }      // height      aAttributes->GetAttribute(nsHTMLAtoms::height, value);      if (value.GetUnit() != eHTMLUnit_Null) {        nsStylePosition* position = (nsStylePosition*)          aContext->GetMutableStyleData(eStyleStruct_Position);        switch (value.GetUnit()) {        case eHTMLUnit_Percent:          position->mHeight.SetPercentValue(value.GetPercentValue());          break;        case eHTMLUnit_Pixel:          position->mHeight.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), sp2t));          break;        default:          break;        }      }      nsStyleSpacing* spacing = (nsStyleSpacing*)        aContext->GetMutableStyleData(eStyleStruct_Spacing);      // default border style is the Nav4.6 extension which uses the background color as the      // basis of the outset border. If the table has a transparant background then it finds      // the closest ancestor that has a non transparant backgound. NS_STYLE_BORDER_OUTSET       // uses the border color of the table and if that is not set, then it uses the color.      nsCompatibility mode;      aPresContext->GetCompatibilityMode(&mode);      PRUint8 borderStyle = (eCompatibility_NavQuirks == mode)                             ? NS_STYLE_BORDER_STYLE_BG_OUTSET : NS_STYLE_BORDER_STYLE_OUTSET;      // bordercolor      aAttributes->GetAttribute(nsHTMLAtoms::bordercolor, value);      if ((eHTMLUnit_Color == value.GetUnit()) || (eHTMLUnit_ColorName == value.GetUnit())) {        nscolor color = value.GetColorValue();        spacing->SetBorderColor(0, color);        spacing->SetBorderColor(1, color);        spacing->SetBorderColor(2, color);        spacing->SetBorderColor(3, color);        borderStyle = NS_STYLE_BORDER_STYLE_OUTSET; // use css outset      }      // border and frame      MapTableBorderInto(aAttributes, aContext, aPresContext, borderStyle);      // align; Check for enumerated type (it may be another type if      // illegal)      aAttributes->GetAttribute(nsHTMLAtoms::align, value);      if (value.GetUnit() == eHTMLUnit_Enumerated) {        if ((NS_STYLE_TEXT_ALIGN_CENTER == value.GetIntValue()) ||            (NS_STYLE_TEXT_ALIGN_MOZ_CENTER == value.GetIntValue())) {          nsStyleCoord otto(eStyleUnit_Auto);          spacing->mMargin.SetLeft(otto);          spacing->mMargin.SetRight(otto);        }        else {          nsStyleDisplay* display = (nsStyleDisplay*)            aContext->GetMutableStyleData(eStyleStruct_Display);          switch (value.GetIntValue()) {          case NS_STYLE_TEXT_ALIGN_LEFT:            display->mFloats = NS_STYLE_FLOAT_LEFT;            break;          case NS_STYLE_TEXT_ALIGN_RIGHT:          case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT:            display->mFloats = NS_STYLE_FLOAT_RIGHT;            break;          }        }      }      // layout      nsStyleTable* tableStyle=nsnull;      aAttributes->GetAttribute(nsHTMLAtoms::layout, value);      if (value.GetUnit() == eHTMLUnit_Enumerated) {  // it may be another type if illegal        tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);        tableStyle->mLayoutStrategy = value.GetIntValue();      }      // cellpadding      aAttributes->GetAttribute(nsHTMLAtoms::cellpadding, value);      if (value.GetUnit() == eHTMLUnit_Pixel) {        if (nsnull==tableStyle)          tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);        tableStyle->mCellPadding.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), sp2t));      }      else if (value.GetUnit() == eHTMLUnit_Percent) {        if (nsnull==tableStyle)          tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);        tableStyle->mCellPadding.SetPercentValue(value.GetPercentValue());      }      // cellspacing  (reuses tableStyle if already resolved)      // ua.css sets cellspacing      aAttributes->GetAttribute(nsHTMLAtoms::cellspacing, value);      if (value.GetUnit() == eHTMLUnit_Pixel) {        if (nsnull==tableStyle)          tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);        tableStyle->mBorderSpacingX.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), sp2t));        tableStyle->mBorderSpacingY.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), sp2t));      }      // cols      aAttributes->GetAttribute(nsHTMLAtoms::cols, value);      if (value.GetUnit() != eHTMLUnit_Null) {        if (nsnull==tableStyle)          tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);        if (value.GetUnit() == eHTMLUnit_Integer)          tableStyle->mCols = value.GetIntValue();        else // COLS had no value, so it refers to all columns          tableStyle->mCols = NS_STYLE_TABLE_COLS_ALL;      }      // rules, must come after handling of border which set the default      aAttributes->GetAttribute(nsHTMLAtoms::rules, value);      if (value.GetUnit() == eHTMLUnit_Enumerated) {        if (nsnull==tableStyle)          tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);        tableStyle->mRules = value.GetIntValue();      }      //background: color      nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext);      nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext);    }  }}