Bug 1596768 - Remove GetBindingParent usage in nsContentUtils::IsInSameAnonymousTree. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 15 Nov 2019 17:05:15 +0000
changeset 502249 db1a18b908bfaf15485d1dd5430f67c46b5d65a8
parent 502248 eebf1f2557be7ef8fd8558d07531dd1318e1eedf
child 502250 afb9438378f091aa9f31192c235191625c3d538a
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1596768
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1596768 - Remove GetBindingParent usage in nsContentUtils::IsInSameAnonymousTree. r=smaug Check Shadow DOM and NAC separately. Depends on D53195 Differential Revision: https://phabricator.services.mozilla.com/D53196
dom/base/nsContentUtils.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -4990,28 +4990,28 @@ bool nsContentUtils::HasNonEmptyTextCont
 }
 
 /* static */
 bool nsContentUtils::IsInSameAnonymousTree(const nsINode* aNode,
                                            const nsIContent* aContent) {
   MOZ_ASSERT(aNode, "Must have a node to work with");
   MOZ_ASSERT(aContent, "Must have a content to work with");
 
-  if (!aNode->IsContent()) {
-    /**
-     * The root isn't an nsIContent, so it's a document or attribute.  The only
-     * 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;
-  }
-
-  return aNode->AsContent()->GetBindingParent() == aContent->GetBindingParent();
+  if (aNode->IsInNativeAnonymousSubtree() != aContent->IsInNativeAnonymousSubtree()) {
+    return false;
+  }
+
+  if (aNode->IsInNativeAnonymousSubtree()) {
+    return aContent->GetClosestNativeAnonymousSubtreeRoot() ==
+           aNode->GetClosestNativeAnonymousSubtreeRoot();
+  }
+
+  // FIXME: This doesn't deal with disconnected nodes whatsoever, but it didn't
+  // use to either. Maybe that's fine.
+  return aNode->GetContainingShadow() == aContent->GetContainingShadow();
 }
 
 /* static */
 bool nsContentUtils::IsInInteractiveHTMLContent(const Element* aElement,
                                                 const Element* aStop) {
   const Element* element = aElement;
   while (element && element != aStop) {
     if (element->IsInteractiveHTMLContent(true)) {