nsAttrSelector* attr = aSelector->mAttrList; do { nsAutoString  value; nsresult  attrState = aContent->GetAttribute(attr->mNameSpace, attr->mAttr, value); if (NS_FAILED(attrState) || (NS_CONTENT_ATTR_NOT_THERE == attrState)) { result = PR_FALSE; } else { PRBool isCaseSensitive = (attr->mCaseSensitive && !isHTMLContent); switch (attr->mFunction) { case NS_ATTR_FUNC_SET:    break; case NS_ATTR_FUNC_EQUALS: if (isCaseSensitive) { result = value.Equals(attr->mValue); } else { result = value.EqualsIgnoreCase(attr->mValue); } break; case NS_ATTR_FUNC_INCLUDES: result = ValueIncludes(value, attr->mValue, isCaseSensitive); break; case NS_ATTR_FUNC_DASHMATCH: result = ValueDashMatch(value, attr->mValue, isCaseSensitive); break;
if(!data.mHasAttributes) { result = PR_FALSE; } else { nsAttrSelector* attr = aSelector->mAttrList; do { nsAutoString  value; nsresult  attrState = data.mContent->GetAttribute(attr->mNameSpace, attr->mAttr, value); if (NS_FAILED(attrState) || (NS_CONTENT_ATTR_NOT_THERE == attrState)) { result = PR_FALSE;
static PRBool SelectorMatches(nsIPresContext* aPresContext,                              nsCSSSelector* aSelector, nsIContent* aContent,                              PRBool aTestState){  PRBool  result = PR_FALSE;  // Bail out early if we can  if(kNameSpaceID_Unknown != aSelector->mNameSpace) {    PRInt32 nameSpaceID;    aContent->GetNameSpaceID(nameSpaceID);    if(nameSpaceID != aSelector->mNameSpace) {      return result;    }  }  nsCOMPtr<nsIAtom> contentTag;  if (((nsnull == aSelector->mTag) || (      aContent->GetTag(*getter_AddRefs(contentTag)),      aSelector->mTag == contentTag.get()))) {    result = PR_TRUE;    // namespace/tag match    PRBool isHTMLContent = PR_FALSE;	  nsIHTMLContent* hc;	  if (NS_OK == aContent->QueryInterface(kIHTMLContentIID, (void**)&hc)) {	  	isHTMLContent = PR_TRUE;	    NS_RELEASE(hc);	  }    if (nsnull != aSelector->mAttrList) { // test for attribute match      nsAttrSelector* attr = aSelector->mAttrList;      do {        nsAutoString  value;        nsresult  attrState = aContent->GetAttribute(attr->mNameSpace, attr->mAttr, value);        if (NS_FAILED(attrState) || (NS_CONTENT_ATTR_NOT_THERE == attrState)) {          result = PR_FALSE;        }        else {			    PRBool isCaseSensitive = (attr->mCaseSensitive && !isHTMLContent); // Bug 24390: html attributes should not be case-sensitive          switch (attr->mFunction) {            case NS_ATTR_FUNC_SET:    break;            case NS_ATTR_FUNC_EQUALS:               if (isCaseSensitive) {                result = value.Equals(attr->mValue);              }              else {                result = value.EqualsIgnoreCase(attr->mValue);              }              break;            case NS_ATTR_FUNC_INCLUDES:               result = ValueIncludes(value, attr->mValue, isCaseSensitive);              break;            case NS_ATTR_FUNC_DASHMATCH:               result = ValueDashMatch(value, attr->mValue, isCaseSensitive);              break;          }        }        attr = attr->mNext;      } while ((PR_TRUE == result) && (nsnull != attr));    }    if ((PR_TRUE == result) &&        ((nsnull != aSelector->mID) || (nsnull != aSelector->mClassList))) {  // test for ID & class match      result = PR_FALSE;      nsIStyledContent* styledContent;      if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIStyledContent), (void**)&styledContent))) {        nsIAtom* contentID;        styledContent->GetID(contentID);        if ((nsnull == aSelector->mID) || (aSelector->mID == contentID)) {          result = PR_TRUE;          nsAtomList* classList = aSelector->mClassList;          while (nsnull != classList) {            if (NS_COMFALSE == styledContent->HasClass(classList->mAtom)) {              result = PR_FALSE;              break;            }            classList = classList->mNext;          }        }        NS_IF_RELEASE(contentID);        NS_RELEASE(styledContent);      }    }    if ((PR_TRUE == result) &&        (nsnull != aSelector->mPseudoClassList)) {  // test for pseudo class match      // first-child, root, lang, active, focus, hover, link, outOfDate, visited      // XXX disabled, enabled, selected, selection      nsAtomList* pseudoClass = aSelector->mPseudoClassList;      PRInt32 eventState = NS_EVENT_STATE_UNSPECIFIED;      nsLinkState linkState = nsLinkState(-1);  // not a link      nsIEventStateManager* eventStateManager = nsnull;      while ((PR_TRUE == result) && (nsnull != pseudoClass)) {        if (nsCSSAtoms::firstChildPseudo == pseudoClass->mAtom) {          nsIContent* firstChild = nsnull;          nsIContent* parent;          aContent->GetParent(parent);          if (parent) {            PRInt32 index = -1;            do {              parent->ChildAt(++index, firstChild);              if (firstChild) { // skip text & comments                if (IsSignificantChild(firstChild, PR_FALSE)) {                  break;                }                NS_RELEASE(firstChild);              }              else {                break;              }            } while (1 == 1);            NS_RELEASE(parent);          }          result = PRBool(aContent == firstChild);          NS_IF_RELEASE(firstChild);        }        else if (nsCSSAtoms::firstNodePseudo == pseudoClass->mAtom) {          nsIContent* firstChild = nsnull;          nsIContent* parent;          aContent->GetParent(parent);          if (parent) {            PRInt32 index = -1;            do {              parent->ChildAt(++index, firstChild);              if (firstChild) { // skip whitespace text & comments                if (IsSignificantChild(firstChild, PR_TRUE)) {                  break;                }                NS_RELEASE(firstChild);              }              else {                break;              }            } while (1 == 1);            NS_RELEASE(parent);          }          result = PRBool(aContent == firstChild);          NS_IF_RELEASE(firstChild);        }        else if (nsCSSAtoms::lastNodePseudo == pseudoClass->mAtom) {          nsIContent* lastChild = nsnull;          nsIContent* parent;          aContent->GetParent(parent);          if (parent) {            PRInt32 index;            parent->ChildCount(index);            do {              parent->ChildAt(--index, lastChild);              if (lastChild) { // skip whitespace text & comments                if (IsSignificantChild(lastChild, PR_TRUE)) {                  break;                }                NS_RELEASE(lastChild);              }              else {                break;              }            } while (1 == 1);            NS_RELEASE(parent);          }          result = PRBool(aContent == lastChild);          NS_IF_RELEASE(lastChild);        }        else if (nsCSSAtoms::rootPseudo == pseudoClass->mAtom) {          nsIContent* parent;          aContent->GetParent(parent);          if (parent) {            NS_RELEASE(parent);            result = PR_FALSE;          }          else {            result = PR_TRUE;          }        }        else if (nsCSSAtoms::langPseudo == pseudoClass->mAtom) {          // XXX not yet implemented          result = PR_FALSE;        }        else if (IsEventPseudo(pseudoClass->mAtom)) {          // check if the element is event-sensitive          if (!contentTag) {            aContent->GetTag(*getter_AddRefs(contentTag));          }#ifdef EVENT_DEBUG          nsAutoString strTag;          // easier to watch the string value than the ATOM          if (contentTag) {            contentTag->ToString(strTag);          }#endif          // Quirk Mode: check to see if the element is event-sensitive          //  - see if the selector applies to event pseudo classes          // NOTE: we distinguish between global and subjected selectors so          //       pass that information on to the determining routine          nsCompatibility quirkMode = eCompatibility_Standard;          aPresContext->GetCompatibilityMode(&quirkMode);          PRBool isSelectorGlobal = aSelector->mTag==nsnull ? PR_TRUE : PR_FALSE;          if ((eCompatibility_NavQuirks == quirkMode) &&              (!IsEventSensitive(pseudoClass->mAtom, contentTag, isSelectorGlobal))){            result = PR_FALSE;          } else if (aTestState) {            if (! eventStateManager) {              aPresContext->GetEventStateManager(&eventStateManager);            }            if (eventStateManager) {              eventStateManager->GetContentState(aContent, eventState);#ifdef EVENT_DEBUG              nsAutoString strPseudo, strTag;              pseudoClass->mAtom->ToString(strPseudo);              if (!contentTag) {                aContent->GetTag(*getter_AddRefs(contentTag));              }              if (contentTag) {                contentTag->ToString(strTag);              }              printf("Tag: %s PseudoClass: %s EventState: %d\n",                      strTag.ToNewCString(), strPseudo.ToNewCString(), (int)eventState);#endif            }            if (nsCSSAtoms::activePseudo == pseudoClass->mAtom) {              result = PRBool(0 != (eventState & NS_EVENT_STATE_ACTIVE));            }            else if (nsCSSAtoms::focusPseudo == pseudoClass->mAtom) {              result = PRBool(0 != (eventState & NS_EVENT_STATE_FOCUS));            }            else if (nsCSSAtoms::hoverPseudo == pseudoClass->mAtom) {              result = PRBool(0 != (eventState & NS_EVENT_STATE_HOVER));            }            else if (nsCSSAtoms::dragOverPseudo == pseudoClass->mAtom) {              result = PRBool(0 != (eventState & NS_EVENT_STATE_DRAGOVER));            }          }         }        else if (IsLinkPseudo(pseudoClass->mAtom)) {          if (!contentTag) aContent->GetTag(*getter_AddRefs(contentTag));          if (nsStyleUtil::IsHTMLLink(aContent, contentTag, aPresContext, &linkState) ||		      nsStyleUtil::IsSimpleXlink(aContent, aPresContext, &linkState)) {            if ((PR_FALSE != result) && (aTestState)) {              if (nsCSSAtoms::linkPseudo == pseudoClass->mAtom) {                result = PRBool(eLinkState_Unvisited == linkState);              }              else if (nsCSSAtoms::outOfDatePseudo == pseudoClass->mAtom) {                result = PRBool(eLinkState_OutOfDate == linkState);              }              else if (nsCSSAtoms::visitedPseudo == pseudoClass->mAtom) {                result = PRBool(eLinkState_Visited == linkState);              }            }          }          else {            result = PR_FALSE;  // not a link          }        }        else {          result = PR_FALSE;  // unknown pseudo class        }        pseudoClass = pseudoClass->mNext;      }      NS_IF_RELEASE(eventStateManager);    }  }  return result;}