Bug 1007743 - Update flattened tree to correctly handle nodes distributed into Shadow DOM insertion points. r=smaug

This commit is contained in:
William Chen 2014-06-03 16:09:41 -07:00
parent 7680954aa6
commit 405db531dd
5 changed files with 56 additions and 7 deletions

View File

@ -190,8 +190,8 @@ ExplicitChildIterator::Get()
MOZ_ASSERT(!mIsFirst);
if (mIndexInInserted) {
XBLChildrenElement* point = static_cast<XBLChildrenElement*>(mChild);
return point->mInsertedChildren[mIndexInInserted - 1];
MatchedNodes assignedChildren = GetMatchedNodesForPoint(mChild);
return assignedChildren[mIndexInInserted - 1];
} else if (mShadowIterator) {
return mShadowIterator->Get();
}

View File

@ -153,14 +153,33 @@ nsIContent::FindFirstNonChromeOnlyAccessContent() const
nsIContent*
nsIContent::GetFlattenedTreeParent() const
{
if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
nsIContent* parent = GetXBLInsertionParent();
if (parent) {
return parent;
nsIContent* parent = nullptr;
nsTArray<nsIContent*>* destInsertionPoints = GetExistingDestInsertionPoints();
if (destInsertionPoints && !destInsertionPoints->IsEmpty()) {
// This node was distributed into an insertion point. The last node in
// the list of destination insertion insertion points is where this node
// appears in the composed tree (see Shadow DOM spec).
nsIContent* lastInsertionPoint = destInsertionPoints->LastElement();
parent = lastInsertionPoint->GetParent();
} else if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
parent = GetXBLInsertionParent();
}
if (!parent) {
parent = GetParent();
}
// Shadow roots never shows up in the flattened tree. Return the host
// instead.
if (parent && parent->HasFlag(NODE_IS_IN_SHADOW_TREE)) {
ShadowRoot* parentShadowRoot = ShadowRoot::FromNode(parent);
if (parentShadowRoot) {
return parentShadowRoot->GetHost();
}
}
return GetParent();
return parent;
}
nsIContent::IMEState

View File

@ -12,3 +12,4 @@ pref(dom.webcomponents.enabled,true) == remove-insertion-point-1.html remove-ins
pref(dom.webcomponents.enabled,true) == nested-insertion-point-1.html nested-insertion-point-1-ref.html
pref(dom.webcomponents.enabled,true) == basic-shadow-element-1.html basic-shadow-element-1-ref.html
pref(dom.webcomponents.enabled,true) == nested-shadow-element-1.html nested-shadow-element-1-ref.html
pref(dom.webcomponents.enabled,true) == update-dist-node-descendants-1.html update-dist-node-descendants-1-ref.html

View File

@ -0,0 +1,8 @@
<!DOCTYPE HTML>
<html>
<body>
<div>
<div><div><span>Hello World</span></div></div>
</div>
</body>
</html>

View File

@ -0,0 +1,21 @@
<!DOCTYPE HTML>
<html class="reftest-wait">
<head>
</head>
<body>
<div id="outer"><span id="distnode">Change me</span></div>
<script>
var shadowRoot = document.getElementById('outer').createShadowRoot();
shadowRoot.innerHTML = '<div><content></content></div>';
function tweak() {
var distNode = document.getElementById("distnode");
distNode.textContent = "Hello World";
document.documentElement.removeAttribute("class");
}
window.addEventListener("MozReftestInvalidate", tweak);
</script>
</body>
</html>