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(nsIStyledContent::GetIID(), (void**)&styledContent))) { PRInt32 nameSpace; styledContent->GetNameSpaceID(nameSpace); if (kNameSpaceID_HTML == nameSpace) { nsIAtom*  tag; styledContent->GetTag(tag);  if (tag == nsHTMLAtoms::a) { if ((nsnull != mLinkRule) || (nsnull != mVisitedRule)) {  nsILinkHandler* linkHandler;  if (NS_OK == aPresContext->GetLinkHandler(&linkHandler)) { nsAutoString base, href; nsresult attrState = styledContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::href, href);  if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {  if (! linkHandler) { if (nsnull != mLinkRule) { aResults->AppendElement(mLinkRule); } } else { nsIURI* docURL = nsnull;  nsIHTMLContent* htmlContent; if (NS_SUCCEEDED(styledContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) { htmlContent->GetBaseURL(docURL);  nsAutoString absURLSpec; nsresult rv; #ifndef NECKO rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec); #else nsIURI *baseUri = nsnull; rv = docURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri); if (NS_FAILED(rv)) return 0;  rv = NS_MakeAbsoluteURI(href, baseUri, absURLSpec);  NS_RELEASE(baseUri); #endif NS_IF_RELEASE(docURL);  nsLinkState  state; if (NS_OK == linkHandler->GetLinkState(absURLSpec.GetUnicode(), state)) { switch (state) { case eLinkState_Unvisited: if (nsnull != mLinkRule) { aResults->AppendElement(mLinkRule); } break; case eLinkState_Visited: if (nsnull != mVisitedRule) { aResults->AppendElement(mVisitedRule); } break; default: break; } } NS_RELEASE(htmlContent); } } } } NS_IF_RELEASE(linkHandler); } if (nsnull != mActiveRule) { 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); } } }  else if ((tag == nsHTMLAtoms::td) || (tag == nsHTMLAtoms::th) || (tag == nsHTMLAtoms::tr) || (tag == nsHTMLAtoms::thead) || (tag == nsHTMLAtoms::tbody) || (tag == nsHTMLAtoms::tfoot)) { 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); }   styledContent->GetContentStyleRules(aResults);  NS_RELEASE(styledContent); }
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(nsIStyledContent::GetIID(), (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 ((nsnull != mLinkRule) || (nsnull != mVisitedRule)) {          // test link state          nsILinkHandler* linkHandler;          if (NS_OK == aPresContext->GetLinkHandler(&linkHandler)) {            nsAutoString base, href;            nsresult attrState = styledContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::href, href);            if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {              if (! linkHandler) {                if (nsnull != mLinkRule) {                  aResults->AppendElement(mLinkRule);                }              }              else {                nsIURI* docURL = nsnull;                nsIHTMLContent* htmlContent;                if (NS_SUCCEEDED(styledContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) {                  htmlContent->GetBaseURL(docURL);                                 nsAutoString absURLSpec;                  nsresult rv;#ifndef NECKO                  rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec);#else                  nsIURI *baseUri = nsnull;                  rv = docURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri);                  if (NS_FAILED(rv)) return 0;                  rv = NS_MakeAbsoluteURI(href, baseUri, absURLSpec);                  NS_RELEASE(baseUri);#endif // NECKO                  NS_IF_RELEASE(docURL);                  nsLinkState  state;                  if (NS_OK == linkHandler->GetLinkState(absURLSpec.GetUnicode(), state)) {                    switch (state) {                      case eLinkState_Unvisited:                        if (nsnull != mLinkRule) {                          aResults->AppendElement(mLinkRule);                        }                        break;                      case eLinkState_Visited:                        if (nsnull != mVisitedRule) {                          aResults->AppendElement(mVisitedRule);                        }                        break;                      default:                        break;                    }                  }                  NS_RELEASE(htmlContent);                }              }            }          }          NS_IF_RELEASE(linkHandler);        } // end link/visited rules        if (nsnull != 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 A tag      // add the quirks background compatibility rule if in quirks mode      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)) {        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;}