Bug 1423583: Fix IsInSameAnonymousTree in Shadow DOM. r?smaug
MozReview-Commit-ID: 1EnQ7G1drfC
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -5450,24 +5450,28 @@ nsContentUtils::IsInSameAnonymousTree(co
* nodes in the same anonymous subtree as it will have a null
* bindingParent.
*
* XXXbz strictly speaking, that's not true for attribute nodes.
*/
return aContent->GetBindingParent() == nullptr;
}
- const nsIContent* nodeAsContent = static_cast<const nsIContent*>(aNode);
-
- // For nodes in a shadow tree, it is insufficient to simply compare
- // the binding parent because a node may host multiple ShadowRoots,
- // thus nodes in different shadow tree may have the same binding parent.
- if (aNode->IsInShadowTree()) {
- return nodeAsContent->GetContainingShadow() ==
- aContent->GetContainingShadow();
+ const nsIContent* nodeAsContent = aNode->AsContent();
+
+ // NOTE(emilio): This check below is not technically required right now, since
+ // there are no multiple shadow roots per element anymore, but will be if we
+ // ever move Shadow DOM outside of XBL.
+ if (aNode->IsInShadowTree() || aContent->IsInShadowTree()) {
+ // FIXME(emilio): We can't early return here because we propagate the
+ // containing shadow across native anonymous subtrees... It's not clear what
+ // the right thing to do here is of course, should we just clear it out?
+ if (nodeAsContent->GetContainingShadow() != aContent->GetContainingShadow()) {
+ return false;
+ }
}
return nodeAsContent->GetBindingParent() == aContent->GetBindingParent();
}
/* static */
void
nsContentUtils::NotifyInstalledMenuKeyboardListener(bool aInstalling)