Bug 653881 - Add a compatibility hack to allow <xbl:children> elements to be optional when selecting via the child CSS selector. This allows old CSS selectors selecting default content to continue working in the new world. r=dbaron

--HG--
extra : rebase_source : 4d538fcbd8a6b58408dc46835632a4664ba8d0d8
This commit is contained in:
Blake Kaplan 2013-06-28 18:48:13 -07:00
parent f6fd48c4ef
commit 2ea3b24b47
4 changed files with 78 additions and 0 deletions

View File

@ -48,3 +48,5 @@ skip-if(B2G) == multipleinsertionpoints-insertmultiple.xhtml multipleinsertionpo
== multipleappendwithxul.xhtml multipleappendwithxul-ref.xhtml
== multipleappendwithinput.xhtml multipleappendwithinput-ref.xhtml
== multipleappendwitheditable.xhtml multipleappendwitheditable-ref.xhtml
skip-if(B2G) == xbl-children-1.xhtml xbl-children-1-ref.xhtml

View File

@ -0,0 +1,16 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
#result {
color: green;
text-decoration: underline;
text-transform: lowercase;
background: yellow;
}
</style>
</head>
<body>
<div id="result">text</div>
</body>
</html>

View File

@ -0,0 +1,39 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<binding id="a">
<content>
<xhtml:div class="aparent">
<xhtml:div class="a">
<children>
<xhtml:div class="b">
TEXT
</xhtml:div>
</children>
</xhtml:div>
</xhtml:div>
</content>
</binding>
</bindings>
<style>
@namespace xbl "http://www.mozilla.org/xbl";
.a > .b { color: green; }
.a > xbl|children > .b { text-decoration: underline; }
.a .b { text-transform: lowercase; }
.aparent > * > .b { background: yellow; }
/* Inverse cases. */
.a > * > xbl|children > .b { color: red !important; }
</style>
</head>
<body>
<div style="-moz-binding: url(#a);" />
</body>
</html>

View File

@ -2287,6 +2287,27 @@ static bool SelectorMatchesTree(Element* aPrevElement,
// traverse further up the tree.
aTreeMatchContext.PopStyleScopeForSelectorMatching(element);
}
// Compatibility hack: First try matching this selector as though the
// <xbl:children> element wasn't in the tree to allow old selectors
// were written before <xbl:children> participated in CSS selector
// matching to work.
if (selector->mOperator == '>' &&
element->NodeInfo()->Equals(nsGkAtoms::children,
kNameSpaceID_XBL)) {
Element* styleScope = aTreeMatchContext.mCurrentStyleScope;
if (SelectorMatchesTree(element, selector, aTreeMatchContext,
aLookForRelevantLink)) {
// It matched, don't try matching on the <xbl:children> element at
// all.
return true;
}
// We want to reset mCurrentStyleScope on aTreeMatchContext
// back to its state before the SelectorMatchesTree call, in
// case that call happens to traverse past the style scope element
// and sets it to null.
aTreeMatchContext.mCurrentStyleScope = styleScope;
}
}
}
if (!element) {