Add CSS3 pseudo-class selector :only-child

bug 237568, patch by Sander <mybugzilla@juima.org>, r=bzbarsky, sr=dbaron
This commit is contained in:
mvl%exedo.nl 2004-05-25 13:43:52 +00:00
Родитель 3fc52ef947
Коммит 2ee57e12be
4 изменённых файлов: 44 добавлений и 0 удалений

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

@ -3478,6 +3478,27 @@ static PRBool SelectorMatches(RuleProcessorData &data,
} }
result = localTrue == (data.mContent == lastChild); result = localTrue == (data.mContent == lastChild);
} }
else if (nsCSSPseudoClasses::onlyChild == pseudoClass->mAtom) {
nsIContent *onlyChild = nsnull;
nsIContent *moreChild = nsnull;
nsIContent *parent = data.mParentContent;
if (parent) {
PRInt32 index = -1;
do {
onlyChild = parent->GetChildAt(++index);
// stop at first non-comment, non-whitespace and non-text node
} while (onlyChild &&
!IsSignificantChild(onlyChild, PR_FALSE));
if (data.mContent == onlyChild) {
// see if there's any more
do {
moreChild = parent->GetChildAt(++index);
} while (moreChild && !IsSignificantChild(moreChild, PR_FALSE));
}
}
result = localTrue == (data.mContent == onlyChild &&
moreChild == nsnull);
}
else if (nsCSSPseudoClasses::empty == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::empty == pseudoClass->mAtom) {
nsIContent *child = nsnull; nsIContent *child = nsnull;
nsIContent *element = data.mContent; nsIContent *element = data.mContent;

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

@ -73,4 +73,5 @@ CSS_PSEUDO_CLASS(firstChild, ":first-child")
CSS_PSEUDO_CLASS(firstNode, ":-moz-first-node") CSS_PSEUDO_CLASS(firstNode, ":-moz-first-node")
CSS_PSEUDO_CLASS(lastChild, ":last-child") CSS_PSEUDO_CLASS(lastChild, ":last-child")
CSS_PSEUDO_CLASS(lastNode, ":-moz-last-node") CSS_PSEUDO_CLASS(lastNode, ":-moz-last-node")
CSS_PSEUDO_CLASS(onlyChild, ":only-child")

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

@ -73,4 +73,5 @@ CSS_PSEUDO_CLASS(firstChild, ":first-child")
CSS_PSEUDO_CLASS(firstNode, ":-moz-first-node") CSS_PSEUDO_CLASS(firstNode, ":-moz-first-node")
CSS_PSEUDO_CLASS(lastChild, ":last-child") CSS_PSEUDO_CLASS(lastChild, ":last-child")
CSS_PSEUDO_CLASS(lastNode, ":-moz-last-node") CSS_PSEUDO_CLASS(lastNode, ":-moz-last-node")
CSS_PSEUDO_CLASS(onlyChild, ":only-child")

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

@ -3478,6 +3478,27 @@ static PRBool SelectorMatches(RuleProcessorData &data,
} }
result = localTrue == (data.mContent == lastChild); result = localTrue == (data.mContent == lastChild);
} }
else if (nsCSSPseudoClasses::onlyChild == pseudoClass->mAtom) {
nsIContent *onlyChild = nsnull;
nsIContent *moreChild = nsnull;
nsIContent *parent = data.mParentContent;
if (parent) {
PRInt32 index = -1;
do {
onlyChild = parent->GetChildAt(++index);
// stop at first non-comment, non-whitespace and non-text node
} while (onlyChild &&
!IsSignificantChild(onlyChild, PR_FALSE));
if (data.mContent == onlyChild) {
// see if there's any more
do {
moreChild = parent->GetChildAt(++index);
} while (moreChild && !IsSignificantChild(moreChild, PR_FALSE));
}
}
result = localTrue == (data.mContent == onlyChild &&
moreChild == nsnull);
}
else if (nsCSSPseudoClasses::empty == pseudoClass->mAtom) { else if (nsCSSPseudoClasses::empty == pseudoClass->mAtom) {
nsIContent *child = nsnull; nsIContent *child = nsnull;
nsIContent *element = data.mContent; nsIContent *element = data.mContent;