A little selector matching cleanup. b=212603 r+sr=bzbarsky

This commit is contained in:
dbaron%dbaron.org 2003-07-13 23:09:10 +00:00
Родитель 6a8430d75d
Коммит 0f8da4d057
2 изменённых файлов: 54 добавлений и 74 удалений

Просмотреть файл

@ -3249,7 +3249,7 @@ RuleProcessorData::RuleProcessorData(nsIPresContext* aPresContext,
// see if there are attributes for the content // see if there are attributes for the content
PRInt32 attrCount = 0; PRInt32 attrCount = 0;
aContent->GetAttrCount(attrCount); aContent->GetAttrCount(attrCount);
mHasAttributes = PRBool(attrCount > 0); mHasAttributes = attrCount > 0;
// check for HTMLContent and Link status // check for HTMLContent and Link status
if (aContent->IsContentOfType(nsIContent::eHTML)) if (aContent->IsContentOfType(nsIContent::eHTML))
@ -3548,8 +3548,8 @@ static PRBool SelectorMatches(RuleProcessorData &data,
{ {
// if we are dealing with negations, reverse the values of PR_TRUE and PR_FALSE // if we are dealing with negations, reverse the values of PR_TRUE and PR_FALSE
PRBool localFalse = PRBool(0 < aNegationIndex); PRBool localFalse = 0 < aNegationIndex;
PRBool localTrue = PRBool(0 == aNegationIndex); PRBool localTrue = 0 == aNegationIndex;
PRBool result = localTrue; PRBool result = localTrue;
// Do not perform the test if aNegationIndex==1 // Do not perform the test if aNegationIndex==1
@ -3585,41 +3585,35 @@ static PRBool SelectorMatches(RuleProcessorData &data,
nsCOMPtr<nsIContent> firstChild; nsCOMPtr<nsIContent> firstChild;
nsCOMPtr<nsIContent> parent = data.mParentContent; nsCOMPtr<nsIContent> parent = data.mParentContent;
if (parent) { if (parent) {
PRBool acceptNonWhitespace =
nsCSSPseudoClasses::firstNode == pseudoClass->mAtom;
PRInt32 index = -1; PRInt32 index = -1;
do { do {
parent->ChildAt(++index, getter_AddRefs(firstChild)); parent->ChildAt(++index, getter_AddRefs(firstChild));
if (firstChild) { // stop at first non-comment and non-whitespace node (and non-text node for firstChild) // stop at first non-comment and non-whitespace node (and
if (IsSignificantChild(firstChild, (nsCSSPseudoClasses::firstNode == pseudoClass->mAtom))) { // non-text node for firstChild)
break; } while (firstChild &&
!IsSignificantChild(firstChild, acceptNonWhitespace));
} }
} result = localTrue == (data.mContent == firstChild);
else {
break;
}
} while (1 == 1);
}
result = PRBool(localTrue == (data.mContent == firstChild));
} }
else if ((nsCSSPseudoClasses::lastChild == pseudoClass->mAtom) || else if ((nsCSSPseudoClasses::lastChild == pseudoClass->mAtom) ||
(nsCSSPseudoClasses::lastNode == pseudoClass->mAtom)) { (nsCSSPseudoClasses::lastNode == pseudoClass->mAtom)) {
nsCOMPtr<nsIContent> lastChild; nsCOMPtr<nsIContent> lastChild;
nsCOMPtr<nsIContent> parent = data.mParentContent; nsCOMPtr<nsIContent> parent = data.mParentContent;
if (parent) { if (parent) {
PRBool acceptNonWhitespace =
nsCSSPseudoClasses::lastNode == pseudoClass->mAtom;
PRInt32 index; PRInt32 index;
parent->ChildCount(index); parent->ChildCount(index);
do { do {
parent->ChildAt(--index, getter_AddRefs(lastChild)); parent->ChildAt(--index, getter_AddRefs(lastChild));
if (lastChild) { // stop at first non-comment and non-whitespace node (and non-text node for lastChild) // stop at first non-comment and non-whitespace node (and
if (IsSignificantChild(lastChild, (nsCSSPseudoClasses::lastNode == pseudoClass->mAtom))) { // non-text node for lastChild)
break; } while (lastChild &&
!IsSignificantChild(lastChild, acceptNonWhitespace));
} }
} result = localTrue == (data.mContent == lastChild);
else {
break;
}
} while (1 == 1);
}
result = PRBool(localTrue == (data.mContent == lastChild));
} }
else if (nsCSSPseudoClasses::empty == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::empty == pseudoClass->mAtom) {
nsCOMPtr<nsIContent> child; nsCOMPtr<nsIContent> child;
@ -3627,16 +3621,9 @@ static PRBool SelectorMatches(RuleProcessorData &data,
PRInt32 index = -1; PRInt32 index = -1;
do { do {
element->ChildAt(++index, getter_AddRefs(child)); element->ChildAt(++index, getter_AddRefs(child));
if (child) { // stop at first non-comment and non-whitespace node // stop at first non-comment and non-whitespace node
if (IsSignificantChild(child, PR_TRUE)) { } while (child && !IsSignificantChild(child, PR_TRUE));
break; result = localTrue == (child == nsnull);
}
}
else {
break;
}
} while (1 == 1);
result = PRBool(localTrue == (child == nsnull));
} }
else if (nsCSSPseudoClasses::root == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::root == pseudoClass->mAtom) {
if (data.mParentContent) { if (data.mParentContent) {
@ -3647,6 +3634,9 @@ static PRBool SelectorMatches(RuleProcessorData &data,
} }
} }
else if (nsCSSPseudoClasses::mozBoundElement == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::mozBoundElement == pseudoClass->mAtom) {
// XXXldb How do we know where the selector came from? And what
// if there are multiple bindings, and we should be matching the
// outer one?
result = (data.mScopedRoot && data.mScopedRoot == data.mContent) result = (data.mScopedRoot && data.mScopedRoot == data.mContent)
? localTrue : localFalse; ? localTrue : localFalse;
} }
@ -3746,10 +3736,10 @@ static PRBool SelectorMatches(RuleProcessorData &data,
result = localTrue; result = localTrue;
} }
else if (nsCSSPseudoClasses::link == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::link == pseudoClass->mAtom) {
result = PRBool(localTrue == (eLinkState_Unvisited == data.mLinkState)); result = localTrue == (eLinkState_Unvisited == data.mLinkState);
} }
else if (nsCSSPseudoClasses::visited == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::visited == pseudoClass->mAtom) {
result = PRBool(localTrue == (eLinkState_Visited == data.mLinkState)); result = localTrue == (eLinkState_Visited == data.mLinkState);
} }
} }
} }
@ -4024,7 +4014,7 @@ static PRBool SelectorMatchesTree(RuleProcessorData &data,
} }
NS_IF_RELEASE(lastContent); NS_IF_RELEASE(lastContent);
} }
return PRBool(nsnull == selector); // matches if ran out of selectors return nsnull == selector; // matches if ran out of selectors
} }
static void ContentEnumFunc(nsICSSStyleRule* aRule, nsCSSSelector* aSelector, static void ContentEnumFunc(nsICSSStyleRule* aRule, nsCSSSelector* aSelector,

Просмотреть файл

@ -3249,7 +3249,7 @@ RuleProcessorData::RuleProcessorData(nsIPresContext* aPresContext,
// see if there are attributes for the content // see if there are attributes for the content
PRInt32 attrCount = 0; PRInt32 attrCount = 0;
aContent->GetAttrCount(attrCount); aContent->GetAttrCount(attrCount);
mHasAttributes = PRBool(attrCount > 0); mHasAttributes = attrCount > 0;
// check for HTMLContent and Link status // check for HTMLContent and Link status
if (aContent->IsContentOfType(nsIContent::eHTML)) if (aContent->IsContentOfType(nsIContent::eHTML))
@ -3548,8 +3548,8 @@ static PRBool SelectorMatches(RuleProcessorData &data,
{ {
// if we are dealing with negations, reverse the values of PR_TRUE and PR_FALSE // if we are dealing with negations, reverse the values of PR_TRUE and PR_FALSE
PRBool localFalse = PRBool(0 < aNegationIndex); PRBool localFalse = 0 < aNegationIndex;
PRBool localTrue = PRBool(0 == aNegationIndex); PRBool localTrue = 0 == aNegationIndex;
PRBool result = localTrue; PRBool result = localTrue;
// Do not perform the test if aNegationIndex==1 // Do not perform the test if aNegationIndex==1
@ -3585,41 +3585,35 @@ static PRBool SelectorMatches(RuleProcessorData &data,
nsCOMPtr<nsIContent> firstChild; nsCOMPtr<nsIContent> firstChild;
nsCOMPtr<nsIContent> parent = data.mParentContent; nsCOMPtr<nsIContent> parent = data.mParentContent;
if (parent) { if (parent) {
PRBool acceptNonWhitespace =
nsCSSPseudoClasses::firstNode == pseudoClass->mAtom;
PRInt32 index = -1; PRInt32 index = -1;
do { do {
parent->ChildAt(++index, getter_AddRefs(firstChild)); parent->ChildAt(++index, getter_AddRefs(firstChild));
if (firstChild) { // stop at first non-comment and non-whitespace node (and non-text node for firstChild) // stop at first non-comment and non-whitespace node (and
if (IsSignificantChild(firstChild, (nsCSSPseudoClasses::firstNode == pseudoClass->mAtom))) { // non-text node for firstChild)
break; } while (firstChild &&
!IsSignificantChild(firstChild, acceptNonWhitespace));
} }
} result = localTrue == (data.mContent == firstChild);
else {
break;
}
} while (1 == 1);
}
result = PRBool(localTrue == (data.mContent == firstChild));
} }
else if ((nsCSSPseudoClasses::lastChild == pseudoClass->mAtom) || else if ((nsCSSPseudoClasses::lastChild == pseudoClass->mAtom) ||
(nsCSSPseudoClasses::lastNode == pseudoClass->mAtom)) { (nsCSSPseudoClasses::lastNode == pseudoClass->mAtom)) {
nsCOMPtr<nsIContent> lastChild; nsCOMPtr<nsIContent> lastChild;
nsCOMPtr<nsIContent> parent = data.mParentContent; nsCOMPtr<nsIContent> parent = data.mParentContent;
if (parent) { if (parent) {
PRBool acceptNonWhitespace =
nsCSSPseudoClasses::lastNode == pseudoClass->mAtom;
PRInt32 index; PRInt32 index;
parent->ChildCount(index); parent->ChildCount(index);
do { do {
parent->ChildAt(--index, getter_AddRefs(lastChild)); parent->ChildAt(--index, getter_AddRefs(lastChild));
if (lastChild) { // stop at first non-comment and non-whitespace node (and non-text node for lastChild) // stop at first non-comment and non-whitespace node (and
if (IsSignificantChild(lastChild, (nsCSSPseudoClasses::lastNode == pseudoClass->mAtom))) { // non-text node for lastChild)
break; } while (lastChild &&
!IsSignificantChild(lastChild, acceptNonWhitespace));
} }
} result = localTrue == (data.mContent == lastChild);
else {
break;
}
} while (1 == 1);
}
result = PRBool(localTrue == (data.mContent == lastChild));
} }
else if (nsCSSPseudoClasses::empty == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::empty == pseudoClass->mAtom) {
nsCOMPtr<nsIContent> child; nsCOMPtr<nsIContent> child;
@ -3627,16 +3621,9 @@ static PRBool SelectorMatches(RuleProcessorData &data,
PRInt32 index = -1; PRInt32 index = -1;
do { do {
element->ChildAt(++index, getter_AddRefs(child)); element->ChildAt(++index, getter_AddRefs(child));
if (child) { // stop at first non-comment and non-whitespace node // stop at first non-comment and non-whitespace node
if (IsSignificantChild(child, PR_TRUE)) { } while (child && !IsSignificantChild(child, PR_TRUE));
break; result = localTrue == (child == nsnull);
}
}
else {
break;
}
} while (1 == 1);
result = PRBool(localTrue == (child == nsnull));
} }
else if (nsCSSPseudoClasses::root == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::root == pseudoClass->mAtom) {
if (data.mParentContent) { if (data.mParentContent) {
@ -3647,6 +3634,9 @@ static PRBool SelectorMatches(RuleProcessorData &data,
} }
} }
else if (nsCSSPseudoClasses::mozBoundElement == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::mozBoundElement == pseudoClass->mAtom) {
// XXXldb How do we know where the selector came from? And what
// if there are multiple bindings, and we should be matching the
// outer one?
result = (data.mScopedRoot && data.mScopedRoot == data.mContent) result = (data.mScopedRoot && data.mScopedRoot == data.mContent)
? localTrue : localFalse; ? localTrue : localFalse;
} }
@ -3746,10 +3736,10 @@ static PRBool SelectorMatches(RuleProcessorData &data,
result = localTrue; result = localTrue;
} }
else if (nsCSSPseudoClasses::link == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::link == pseudoClass->mAtom) {
result = PRBool(localTrue == (eLinkState_Unvisited == data.mLinkState)); result = localTrue == (eLinkState_Unvisited == data.mLinkState);
} }
else if (nsCSSPseudoClasses::visited == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::visited == pseudoClass->mAtom) {
result = PRBool(localTrue == (eLinkState_Visited == data.mLinkState)); result = localTrue == (eLinkState_Visited == data.mLinkState);
} }
} }
} }
@ -4024,7 +4014,7 @@ static PRBool SelectorMatchesTree(RuleProcessorData &data,
} }
NS_IF_RELEASE(lastContent); NS_IF_RELEASE(lastContent);
} }
return PRBool(nsnull == selector); // matches if ran out of selectors return nsnull == selector; // matches if ran out of selectors
} }
static void ContentEnumFunc(nsICSSStyleRule* aRule, nsCSSSelector* aSelector, static void ContentEnumFunc(nsICSSStyleRule* aRule, nsCSSSelector* aSelector,