if (SelectorMatches(aPresContext, selector, content, PR_TRUE)) {
nsCompatibility compat = data.mIsQuirkMode ? eCompatibility_NavQuirks : eCompatibility_Standard; SelectorMatchesData newdata(data.mPresContext, content, data.mParentContext, data.mResults, &compat); if (SelectorMatches(newdata, selector, PR_TRUE)) {
static PRBool SelectorMatchesTree(nsIPresContext* aPresContext,                                   nsIContent* aLastContent,                                   nsCSSSelector* aSelector) {  nsCSSSelector* selector = aSelector;  if (selector) {    nsIContent* content = nsnull;    nsIContent* lastContent = aLastContent;    NS_ADDREF(lastContent);    while (nsnull != selector) { // check compound selectors      // for adjacent sibling combinators, the content to test against the      // selector is the previous sibling      if (PRUnichar('+') == selector->mOperator) {        nsIContent* parent;        PRInt32 index;        lastContent->GetParent(parent);        if (parent) {          parent->IndexOf(lastContent, index);          while (0 <= --index) {  // skip text & comment nodes            parent->ChildAt(index, content);            nsIAtom* tag;            content->GetTag(tag);            if ((tag != nsLayoutAtoms::textTagName) &&                 (tag != nsLayoutAtoms::commentTagName)) {              NS_IF_RELEASE(tag);              break;            }            NS_RELEASE(content);            NS_IF_RELEASE(tag);          }          NS_RELEASE(parent);        }      }      // for descendant combinators and child combinators, the content      // to test against is the parent      else {        lastContent->GetParent(content);      }      if (! content) {        break;      }      if (SelectorMatches(aPresContext, selector, content, PR_TRUE)) {        // to avoid greedy matching, we need to recurse if this is a        // descendant combinator and the next combinator is not        if ((NS_IS_GREEDY_OPERATOR(selector->mOperator)) &&            (selector->mNext) &&            (!NS_IS_GREEDY_OPERATOR(selector->mNext->mOperator))) {          // pretend the selector didn't match, and step through content          // while testing the same selector          // This approach is slightly strange is that when it recurses          // it tests from the top of the content tree, down.  This          // doesn't matter much for performance since most selectors          // don't match.  (If most did, it might be faster...)          if (SelectorMatchesTree(aPresContext, content, selector)) {            selector = nsnull; // indicate success            break;          }        }        selector = selector->mNext;      }      else {        // for adjacent sibling and child combinators, if we didn't find        // a match, we're done        if (!NS_IS_GREEDY_OPERATOR(selector->mOperator)) {          NS_RELEASE(content);          break;  // parent was required to match        }      }      NS_IF_RELEASE(lastContent);      lastContent = content;  // take refcount      content = nsnull;    }    NS_IF_RELEASE(lastContent);  }  return PRBool(nsnull == selector);  // matches if ran out of selectors}