Bug 1414303: Make nsLayoutUtils::CompareTreePosition handle Shadow DOM in a sensible way. r=xidorn

We probably need more fixes for counters and Shadow DOM. The spec only mentions
"document order", and this is the most reasonable thing to do accounting for
shadow DOM in that regard...

This ensures a reasonable behavior for all callers which pretty much expect
otherwise for all children to be connected.

MozReview-Commit-ID: YEQIKdjRTK

--HG--
extra : rebase_source : 9b31f5d00d270cf21476776144d62350b5453f99
This commit is contained in:
Emilio Cobos Álvarez 2018-05-14 16:34:45 +02:00
parent fd8a6b0d67
commit bdc9e3e0db
4 changed files with 24 additions and 8 deletions

View File

@ -0,0 +1,11 @@
<style>
* { counter-reset: c; }
</style>
<script>
function go() {
host.attachShadow({ mode: "open" }).innerHTML = form.outerHTML;
}
</script>
<body onload=go()>
<form id="form" style="counter-reset: c">
<div id="host">

View File

@ -530,3 +530,4 @@ load 1452839.html
load 1453702.html
load 1453342.html
load 1453196.html
pref(dom.webcomponents.shadowdom.enabled,true) load 1414303.html

View File

@ -99,7 +99,7 @@ nsGenConList::NodeAfter(const nsGenConNode* aNode1, const nsGenConNode* aNode2)
return pseudoType1 == 1;
}
}
// XXX Switch to the frame version of DoCompareTreePosition?
int32_t cmp = nsLayoutUtils::DoCompareTreePosition(content1, content2,
pseudoType1, -pseudoType2);
MOZ_ASSERT(cmp != 0, "same content, different frames");

View File

@ -1628,7 +1628,9 @@ nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
AutoTArray<nsINode*, 32> content1Ancestors;
nsINode* c1;
for (c1 = aContent1; c1 && c1 != aCommonAncestor; c1 = c1->GetParentNode()) {
for (c1 = aContent1;
c1 && c1 != aCommonAncestor;
c1 = c1->GetParentOrHostNode()) {
content1Ancestors.AppendElement(c1);
}
if (!c1 && aCommonAncestor) {
@ -1639,7 +1641,9 @@ nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
AutoTArray<nsINode*, 32> content2Ancestors;
nsINode* c2;
for (c2 = aContent2; c2 && c2 != aCommonAncestor; c2 = c2->GetParentNode()) {
for (c2 = aContent2;
c2 && c2 != aCommonAncestor;
c2 = c2->GetParentOrHostNode()) {
content2Ancestors.AppendElement(c2);
}
if (!c2 && aCommonAncestor) {
@ -1675,7 +1679,7 @@ nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
}
// content1Ancestor != content2Ancestor, so they must be siblings with the same parent
nsINode* parent = content1Ancestor->GetParentNode();
nsINode* parent = content1Ancestor->GetParentOrHostNode();
#ifdef DEBUG
// TODO: remove the uglyness, see bug 598468.
NS_ASSERTION(gPreventAssertInCompareTreePosition || parent,