Bug 829363 - Make :scope match style scope roots. r=bzbarsky

This commit is contained in:
Cameron McCormack 2013-01-16 15:48:29 +11:00
parent 397c611222
commit 39a2dac253
9 changed files with 75 additions and 3 deletions

View File

@ -49,3 +49,6 @@
HTTP(..) == scoped-style-font-face.html scoped-style-font-face-ref.html
== scoped-style-keyframes.html scoped-style-keyframes-ref.html
pref(layout.css.supports-rule.enabled,true) == scoped-style-supports.html scoped-style-supports-ref.html
== scoped-style-pseudo-001.html scoped-style-pseudo-001-ref.html
== scoped-style-pseudo-002.html scoped-style-pseudo-002-ref.html
== scoped-style-pseudo-003.html scoped-style-pseudo-003-ref.html

View File

@ -0,0 +1,6 @@
<!DOCTYPE html>
<body>
<p>First</p>
<p style="color: green">Second</p>
<p>Third</p>
</body>

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<body>
<p>First</p>
<p>
<style scoped>
:scope { color: green }
</style>
Second
</p>
<p>Third</p>
</body>

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<body>
<p>First</p>
<p style="color: green">
<div style="border: 2px solid black">Second</div>
</p>
<p>Third</p>
</body>

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<body>
<p>First</p>
<p>
<style scoped>
:scope { color: green }
</style>
<div>
<style scoped>
:scope { border: 2px solid black }
</style>
Second
</div>
</p>
<p>Third</p>
</body>

View File

@ -0,0 +1,6 @@
<!DOCTYPE html>
<body>
<p>First</p>
<p><span>Second</span></p>
<p>Third</p>
</body>

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<body>
<p>First</p>
<p>
<style scoped>
p :scope { color: red }
</style>
<span>Second</span>
</p>
<p>Third</p>
</body>

View File

@ -2030,7 +2030,18 @@ static bool SelectorMatches(Element* aElement,
break;
case nsCSSPseudoClasses::ePseudoClass_scope:
if (aTreeMatchContext.HasSpecifiedScope()) {
if (aTreeMatchContext.mForScopedStyle) {
if (aTreeMatchContext.mCurrentStyleScope) {
// If mCurrentStyleScope is null, aElement must be the style
// scope root. This is because the PopStyleScopeForSelectorMatching
// call in SelectorMatchesTree sets mCurrentStyleScope to null
// as soon as we visit the style scope element, and we won't
// progress further up the tree after this call to
// SelectorMatches. Thus if mCurrentStyleScope is still set,
// we know the selector does not match.
return false;
}
} else if (aTreeMatchContext.HasSpecifiedScope()) {
if (!aTreeMatchContext.IsScopeElement(aElement)) {
return false;
}

View File

@ -159,8 +159,8 @@ struct NS_STACK_CLASS TreeMatchContext {
bool PopStyleScopeForSelectorMatching(mozilla::dom::Element* aElement)
{
NS_ASSERTION(mForScopedStyle, "only call PopScopeForSelectorMatching when "
"mForScopedStyle is true");
NS_ASSERTION(mForScopedStyle, "only call PopStyleScopeForSelectorMatching "
"when mForScopedStyle is true");
if (!mCurrentStyleScope) {
return false;