nsIContent* aContent,
nsIContent* aParentContent, nsIAtom* aPseudoTag,
HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,                                  nsIAtom* aMedium,                                  nsIContent* aContent,                                  nsIStyleContext* aParentContext,                                  nsISupportsArray* aResults){  NS_PRECONDITION(nsnull != aPresContext, "null arg");  NS_PRECONDITION(nsnull != aContent, "null arg");  NS_PRECONDITION(nsnull != aResults, "null arg");  nsIStyledContent* styledContent;  if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIStyledContent), (void**)&styledContent))) {    PRInt32 nameSpace;    styledContent->GetNameSpaceID(nameSpace);    if (kNameSpaceID_HTML == nameSpace) {      nsIAtom*  tag;      styledContent->GetTag(tag);      // if we have anchor colors, check if this is an anchor with an href      if (tag == nsHTMLAtoms::a) {        if (mLinkRule || mVisitedRule || mActiveRule) {          nsLinkState linkState;          if (nsStyleUtil::IsHTMLLink(aContent, tag, aPresContext, &linkState)) {            switch (linkState) {              case eLinkState_Unvisited:                if (nsnull != mLinkRule) {                  aResults->AppendElement(mLinkRule);                }                break;              case eLinkState_Visited:                if (nsnull != mVisitedRule) {                  aResults->AppendElement(mVisitedRule);                }                break;              default:                break;            }            // No need to add to the active rule if it's not a link            if (mActiveRule) {  // test active state of link              nsIEventStateManager* eventStateManager;              if ((NS_OK == aPresContext->GetEventStateManager(&eventStateManager)) &&                  (nsnull != eventStateManager)) {                PRInt32 state;                if (NS_OK == eventStateManager->GetContentState(aContent, state)) {                  if (0 != (state & NS_EVENT_STATE_ACTIVE)) {                    aResults->AppendElement(mActiveRule);                  }                }                NS_RELEASE(eventStateManager);              }            } // end active rule          }        } // end link/visited/active rules      } // end A tag      // add the quirks background compatibility rule if in quirks mode      // and/or the Table TH rule for handling <TH> differently than <TD>      else if ((tag == nsHTMLAtoms::td) ||               (tag == nsHTMLAtoms::th) ||               (tag == nsHTMLAtoms::tr) ||               (tag == nsHTMLAtoms::thead) || // Nav4.X doesn't support row groups, but it is a lot               (tag == nsHTMLAtoms::tbody) || // easier passing from the table to rows this way               (tag == nsHTMLAtoms::tfoot)) {        // add the rule to handle text-align for a <th>        if (tag == nsHTMLAtoms::th) {          aResults->AppendElement(mTableTHRule);        }        nsCompatibility mode;        aPresContext->GetCompatibilityMode(&mode);        if (eCompatibility_NavQuirks == mode) {          if (mDocumentColorRule) {            aResults->AppendElement(mDocumentColorRule);          }          aResults->AppendElement(mTableBackgroundRule);        }      }      else if (tag == nsHTMLAtoms::html) {        if (mDocumentColorRule) {          aResults->AppendElement(mDocumentColorRule);        }      }      NS_IF_RELEASE(tag);    } // end html namespace    // just get the style rules from the content    styledContent->GetContentStyleRules(aResults);    NS_RELEASE(styledContent);  }  return NS_OK;}