Bug 648722 part 1. Add a :scope pseudo-class that just matches the same thing as :root for now. r=dbaron

This commit is contained in:
Boris Zbarsky 2012-12-04 23:15:47 -05:00
parent a13eed37dc
commit cd6c640261
3 changed files with 23 additions and 4 deletions

View File

@ -100,6 +100,9 @@
/* :root tests */
:root { background-color: green; }
/* :-moz-scope tests */
:-moz-scope { background-color: green; }
/* :nth-child(n) tests */
.nthchild1 > :nth-last-child(odd) { background-color: lime; }
.nthchild1 > :nth-child(odd) { background-color: lime; }
@ -537,7 +540,9 @@
var namespaced = /\|[^=]/.test( q );
var prepend = namespaced ? "xHTML|*#root3 " : "#root3 ";
q = (restrict === false || restrict === ":root" ? "" : prepend) + q.replace(/,/g, ", " + prepend);
q = (restrict === false || restrict === ":root" ||
restrict === ":-moz-scope" ? "" : prepend) +
q.replace(/,/g, ", " + prepend);
var nq = q.replace(/>/g, "&gt;").replace(/</g, "&lt;");
if ( namespaced ) {
@ -630,16 +635,20 @@
if ( root == document ) {
t( ":root Selector", ":root", ["html"], false );
t( ":-moz-scope Selector", ":-moz-scope", ["html"], false );
} else {
t( ":root Selector", ":root", [], ":root" );
t( ":-moz-scope Selector", ":-moz-scope", [], ":-moz-scope" );
if ( !root.parentNode ) {
t( ":root All Selector", ":root *", [], ":root" );
t( ":-moz-scope All Selector", ":-moz-scope *", [], ":-moz-scope" );
}
}
if ( root.parentNode || root == document ) {
assert( query(":root *").length == query("*").length - (root == document ? 1 : 0), type + ": :root All Selector" );
assert( query(":-moz-scope *").length == query("*").length - (root == document ? 1 : 0), type + ": :-moz-scope All Selector" );
}
t( "Element Selector", "p", ["firstp","ap","sndp","en","sap","first"] );

View File

@ -53,7 +53,8 @@
// The CSS_PSEUDO_CLASS entries should all come before the
// CSS_STATE_PSEUDO_CLASS entries. The CSS_PSEUDO_CLASS entry order
// must be the same as the order of cases in SelectorMatches.
// must be the same as the order of cases in SelectorMatches. :not
// must be the last CSS_PSEUDO_CLASS.
CSS_PSEUDO_CLASS(empty, ":empty")
CSS_PSEUDO_CLASS(mozOnlyWhitespace, ":-moz-only-whitespace")
@ -102,6 +103,10 @@ CSS_PSEUDO_CLASS(mozWindowInactive, ":-moz-window-inactive")
// according to HTML integer attribute parsing rules.
CSS_PSEUDO_CLASS(mozTableBorderNonzero, ":-moz-table-border-nonzero")
// Matches whatever the contextual reference elements are for the
// matching operation.
CSS_PSEUDO_CLASS(scope, ":-moz-scope")
// :not needs to come at the end of the non-bit pseudo-class list, since
// it doesn't actually get directly matched on in SelectorMatches.
CSS_PSEUDO_CLASS(notPseudo, ":not")

View File

@ -1782,8 +1782,7 @@ static bool SelectorMatches(Element* aElement,
break;
case nsCSSPseudoClasses::ePseudoClass_root:
if (aElement->GetParent() ||
aElement != aElement->OwnerDoc()->GetRootElement()) {
if (aElement != aElement->OwnerDoc()->GetRootElement()) {
return false;
}
break;
@ -2024,6 +2023,12 @@ static bool SelectorMatches(Element* aElement,
}
break;
case nsCSSPseudoClasses::ePseudoClass_scope:
if (aElement != aElement->OwnerDoc()->GetRootElement()) {
return false;
}
break;
default:
NS_ABORT_IF_FALSE(false, "How did that happen?");
}