nsCOMPtr<nsIStyleContext> tableContext = aRuleData->mStyleContext->GetParent();
nsStyleContext* tableContext = aRuleData->mStyleContext->GetParent();
ProcessTableRulesAttribute(nsStyleStruct* aStyleStruct,                            nsRuleData*    aRuleData,                           PRUint8        aSide,                           PRBool         aGroup,                           PRUint8        aRulesArg1,                           PRUint8        aRulesArg2,                           PRUint8        aRulesArg3){  if (!aStyleStruct || !aRuleData || !aRuleData->mPresContext) return;  nsCOMPtr<nsIStyleContext> tableContext = aRuleData->mStyleContext->GetParent();  if (!tableContext)    return;  if (!aGroup) {    tableContext = tableContext->GetParent();    if (!tableContext)      return;  }     const nsStyleTable* tableData =     (const nsStyleTable*)tableContext->GetStyleData(eStyleStruct_Table);  if (tableData && ((aRulesArg1 == tableData->mRules) ||                    (aRulesArg2 == tableData->mRules) ||                    (aRulesArg3 == tableData->mRules))) {    const nsStyleBorder* tableBorderData =       (const nsStyleBorder*)tableContext->GetStyleData(eStyleStruct_Border);    if (!tableBorderData)      return;    PRUint8 tableBorderStyle = tableBorderData->GetBorderStyle(aSide);    nsStyleBorder* borderData = (nsStyleBorder*)aStyleStruct;    if (!borderData)      return;    PRUint8 borderStyle = borderData->GetBorderStyle(aSide);    // XXX It appears that the style system erronously applies the custom style rule after css style,     // consequently it does not properly fit into the casade. For now, assume that a border style of none    // implies that the style has not been set.    if (NS_STYLE_BORDER_STYLE_NONE == borderStyle) {      // use the table's border style if it is dashed or dotted, otherwise use solid      PRUint8 bStyle = ((NS_STYLE_BORDER_STYLE_NONE != tableBorderStyle) &&                        (NS_STYLE_BORDER_STYLE_HIDDEN != tableBorderStyle))                         ? tableBorderStyle : NS_STYLE_BORDER_STYLE_SOLID;      if ((NS_STYLE_BORDER_STYLE_DASHED != bStyle) &&           (NS_STYLE_BORDER_STYLE_DOTTED != bStyle) &&           (NS_STYLE_BORDER_STYLE_SOLID  != bStyle)) {        bStyle = NS_STYLE_BORDER_STYLE_SOLID;      }      bStyle |= NS_STYLE_BORDER_STYLE_RULES_MASK;      borderData->SetBorderStyle(aSide, bStyle);      nscolor borderColor;      PRBool transparent, foreground;      borderData->GetBorderColor(aSide, borderColor, transparent, foreground);      if (transparent || foreground) {        // use the table's border color if it is set, otherwise use black        nscolor tableBorderColor;        tableBorderData->GetBorderColor(aSide, tableBorderColor, transparent, foreground);        borderColor = (transparent || foreground) ? NS_RGB(0,0,0) : tableBorderColor;        borderData->SetBorderColor(aSide, borderColor);      }      // set the border width to be 1 pixel      float p2t;      aRuleData->mPresContext->GetScaledPixelsToTwips(&p2t);      nscoord onePixel = NSToCoordRound(p2t);      nsStyleCoord coord(onePixel);      switch(aSide) {      case NS_SIDE_TOP:        borderData->mBorder.SetTop(coord);        break;      case NS_SIDE_RIGHT:        borderData->mBorder.SetRight(coord);        break;      case NS_SIDE_BOTTOM:        borderData->mBorder.SetBottom(coord);        break;      default: // NS_SIDE_LEFT        borderData->mBorder.SetLeft(coord);        break;      }    }  }}