const nsHTMLValue*  value; nsresult  result = mAttributes ? mAttributes->GetAttribute(aAttribute, &value) : NS_CONTENT_ATTR_NOT_THERE;  char cbuf[20]; nscolor color; if (NS_CONTENT_ATTR_HAS_VALUE == result) { nsIHTMLContent* htmlContent; result = mContent->QueryInterface(kIHTMLContentIID, (void **)&htmlContent); if (NS_OK != result) { return result; }  if (NS_CONTENT_ATTR_HAS_VALUE == htmlContent->AttributeToString(aAttribute, *value, aResult)) { NS_RELEASE(htmlContent); return result; } NS_RELEASE(htmlContent);   switch (value->GetUnit()) { case eHTMLUnit_Null: case eHTMLUnit_Empty: aResult.Truncate(); break;  case eHTMLUnit_String: case eHTMLUnit_ColorName: value->GetStringValue(aResult); break;  case eHTMLUnit_Integer: aResult.Truncate(); aResult.Append(value->GetIntValue(), 10); break;  case eHTMLUnit_Pixel: aResult.Truncate(); aResult.Append(value->GetPixelValue(), 10); break;  case eHTMLUnit_Percent: aResult.Truncate(); aResult.Append(PRInt32(value->GetPercentValue() * 100.0f), 10); aResult.Append('%'); break;  case eHTMLUnit_Color: color = nscolor(value->GetColorValue()); PR_snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x", NS_GET_R(color), NS_GET_G(color), NS_GET_B(color)); aResult.Truncate(); aResult.Append(cbuf); break;  default: case eHTMLUnit_Enumerated: NS_NOTREACHED("no default enumerated value to string conversion"); result = NS_CONTENT_ATTR_NOT_THERE; break; } }  return result; }
nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,                                   nsString &aResult) const{#if 0  NS_ASSERTION((kNameSpaceID_HTML == aNameSpaceID) ||                (kNameSpaceID_None == aNameSpaceID) ||                (kNameSpaceID_Unknown == aNameSpaceID),                "html content only holds HTML attributes");#endif  if ((kNameSpaceID_HTML != aNameSpaceID) &&       (kNameSpaceID_None != aNameSpaceID) &&      (kNameSpaceID_Unknown != aNameSpaceID)) {    return NS_CONTENT_ATTR_NOT_THERE;  }  const nsHTMLValue*  value;  nsresult  result = mAttributes ? mAttributes->GetAttribute(aAttribute, &value) :                     NS_CONTENT_ATTR_NOT_THERE;  char cbuf[20];  nscolor color;  if (NS_CONTENT_ATTR_HAS_VALUE == result) {    nsIHTMLContent* htmlContent;    result = mContent->QueryInterface(kIHTMLContentIID, (void **)&htmlContent);    if (NS_OK != result) {      return result;    }    // Try subclass conversion routine first    if (NS_CONTENT_ATTR_HAS_VALUE ==        htmlContent->AttributeToString(aAttribute, *value, aResult)) {      NS_RELEASE(htmlContent);      return result;    }    NS_RELEASE(htmlContent);    // Provide default conversions for most everything    switch (value->GetUnit()) {    case eHTMLUnit_Null:    case eHTMLUnit_Empty:      aResult.Truncate();      break;    case eHTMLUnit_String:    case eHTMLUnit_ColorName:      value->GetStringValue(aResult);      break;    case eHTMLUnit_Integer:      aResult.Truncate();      aResult.Append(value->GetIntValue(), 10);      break;    case eHTMLUnit_Pixel:      aResult.Truncate();      aResult.Append(value->GetPixelValue(), 10);      break;    case eHTMLUnit_Percent:      aResult.Truncate();      aResult.Append(PRInt32(value->GetPercentValue() * 100.0f), 10);      aResult.Append('%');      break;    case eHTMLUnit_Color:      color = nscolor(value->GetColorValue());      PR_snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",                  NS_GET_R(color), NS_GET_G(color), NS_GET_B(color));      aResult.Truncate();      aResult.Append(cbuf);      break;    default:    case eHTMLUnit_Enumerated:      NS_NOTREACHED("no default enumerated value to string conversion");      result = NS_CONTENT_ATTR_NOT_THERE;      break;    }  }  return result;}