nsIContent* aContent,
nsIContent* aParentContent, nsIAtom* aPseudoTag,
PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,                                          nsIContent* aContent,                                          nsIStyleContext* aParentContext,                                          nsISupportsArray* aResults){  NS_PRECONDITION(nsnull != aPresContext, "null arg");  NS_PRECONDITION(nsnull != aContent, "null arg");  NS_PRECONDITION(nsnull != aResults, "null arg");  PRInt32 matchCount = 0;  nsIHTMLContent* htmlContent;  if (NS_OK == aContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent)) {    nsIAtom*  tag;    htmlContent->GetTag(tag);    // if we have anchor colors, check if this is an anchor with an href    if (tag == nsHTMLAtoms::a) {      if ((nsnull != mLinkRule) || (nsnull != mVisitedRule) || (nsnull != mActiveRule)) {        // test link state        nsILinkHandler* linkHandler;        if ((NS_OK == aPresContext->GetLinkHandler(&linkHandler)) &&            (nsnull != linkHandler)) {          nsAutoString base, href;  // XXX base??          nsresult attrState = htmlContent->GetAttribute("href", href);          if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {            nsIURL* docURL = nsnull;            nsIDocument* doc = nsnull;            aContent->GetDocument(doc);            if (nsnull != doc) {              docURL = doc->GetDocumentURL();              NS_RELEASE(doc);            }            nsAutoString absURLSpec;            nsresult rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec);            NS_IF_RELEASE(docURL);            nsLinkState  state;            if (NS_OK == linkHandler->GetLinkState(absURLSpec, state)) {              switch (state) {                case eLinkState_Unvisited:                  if (nsnull != mLinkRule) {                    aResults->AppendElement(mLinkRule);                    matchCount++;                  }                  break;                case eLinkState_Visited:                  if (nsnull != mVisitedRule) {                    aResults->AppendElement(mVisitedRule);                    matchCount++;                  }                  break;                case eLinkState_Active:                  if (nsnull != mActiveRule) {                    aResults->AppendElement(mActiveRule);                    matchCount++;                  }                  break;              }            }          }          NS_RELEASE(linkHandler);        }      }    } // end A tag    // just get the one and only style rule from the content    nsIStyleRule* rule;    htmlContent->GetStyleRule(rule);    if (nsnull != rule) {      aResults->AppendElement(rule);      NS_RELEASE(rule);      matchCount++;    }    NS_IF_RELEASE(tag);    NS_RELEASE(htmlContent);  }  return matchCount;}