Bug 1596768 - Remove GetBindingParent usage in GetRootForContentSubtree. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 15 Nov 2019 16:53:19 +0000
changeset 502239 ce407536b1dc8c68340fc7197d047f8b81928b55
parent 502238 61ebc1a22544fa44ac2a4f9a2f120488a5f1d614
child 502240 c80cebff64aa82b4da9238b249a3b68dbb4a353d
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 GetRootForContentSubtree. r=smaug Shadow DOM is handled above. And do some minor drive-by cleanups. Unclear why we have both this and the RangeUtils version. Depends on D53194 Differential Revision: https://phabricator.services.mozilla.com/D53195
dom/base/nsINode.cpp
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -343,43 +343,42 @@ nsINode* nsINode::SubtreeRoot() const {
 }
 
 static nsIContent* GetRootForContentSubtree(nsIContent* aContent) {
   NS_ENSURE_TRUE(aContent, nullptr);
 
   // Special case for ShadowRoot because the ShadowRoot itself is
   // the root. This is necessary to prevent selection from crossing
   // the ShadowRoot boundary.
-  ShadowRoot* containingShadow = aContent->GetContainingShadow();
-  if (containingShadow) {
+  //
+  // FIXME(emilio): The NAC check should probably be done before this? We can
+  // have NAC inside shadow DOM.
+  if (ShadowRoot* containingShadow = aContent->GetContainingShadow()) {
     return containingShadow;
   }
-
-  nsIContent* stop = aContent->GetBindingParent();
-  while (aContent) {
-    nsIContent* parent = aContent->GetParent();
-    if (parent == stop) {
-      break;
-    }
-    aContent = parent;
+  if (nsIContent* nativeAnonRoot = aContent->GetClosestNativeAnonymousSubtreeRoot()) {
+    return nativeAnonRoot;
   }
-  return aContent;
+  if (Document* doc = aContent->GetUncomposedDoc()) {
+    return doc->GetRootElement();
+  }
+  return nsIContent::FromNode(aContent->SubtreeRoot());
 }
 
 nsIContent* nsINode::GetSelectionRootContent(PresShell* aPresShell) {
   NS_ENSURE_TRUE(aPresShell, nullptr);
 
   if (IsDocument()) return AsDocument()->GetRootElement();
   if (!IsContent()) return nullptr;
 
   if (GetComposedDoc() != aPresShell->GetDocument()) {
     return nullptr;
   }
 
-  if (static_cast<nsIContent*>(this)->HasIndependentSelection()) {
+  if (AsContent()->HasIndependentSelection()) {
     // This node should be a descendant of input/textarea editor.
     nsIContent* content = GetTextEditorRootContent();
     if (content) return content;
   }
 
   nsPresContext* presContext = aPresShell->GetPresContext();
   if (presContext) {
     HTMLEditor* htmlEditor = nsContentUtils::GetHTMLEditor(presContext);
@@ -387,17 +386,17 @@ nsIContent* nsINode::GetSelectionRootCon
       // This node is in HTML editor.
       Document* doc = GetComposedDoc();
       if (!doc || doc->HasFlag(NODE_IS_EDITABLE) ||
           !HasFlag(NODE_IS_EDITABLE)) {
         nsIContent* editorRoot = htmlEditor->GetRoot();
         NS_ENSURE_TRUE(editorRoot, nullptr);
         return nsContentUtils::IsInSameAnonymousTree(this, editorRoot)
                    ? editorRoot
-                   : GetRootForContentSubtree(static_cast<nsIContent*>(this));
+                   : GetRootForContentSubtree(AsContent());
       }
       // If the document isn't editable but this is editable, this is in
       // contenteditable.  Use the editing host element for selection root.
       return static_cast<nsIContent*>(this)->GetEditingHost();
     }
   }
 
   RefPtr<nsFrameSelection> fs = aPresShell->FrameSelection();
@@ -411,17 +410,17 @@ nsIContent* nsINode::GetSelectionRootCon
       if (!content) return nullptr;
     }
   }
 
   // This node might be in another subtree, if so, we should find this subtree's
   // root.  Otherwise, we can return the content simply.
   NS_ENSURE_TRUE(content, nullptr);
   if (!nsContentUtils::IsInSameAnonymousTree(this, content)) {
-    content = GetRootForContentSubtree(static_cast<nsIContent*>(this));
+    content = GetRootForContentSubtree(AsContent());
     // Fixup for ShadowRoot because the ShadowRoot itself does not have a frame.
     // Use the host as the root.
     if (ShadowRoot* shadowRoot = ShadowRoot::FromNode(content)) {
       content = shadowRoot->GetHost();
     }
   }
 
   return content;