diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 86860aee6dfc..f53c8bf323c6 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -187,6 +187,7 @@ public: /** * Returns the parent node of aChild crossing document boundaries. + * Uses the parent node in the composed document. */ static nsINode* GetCrossDocParentNode(nsINode* aChild); @@ -217,7 +218,8 @@ public: /** * Similar to ContentIsDescendantOf except it crosses document boundaries, - * also crosses ShadowRoot boundaries from ShadowRoot to its host. + * this function uses ancestor/descendant relations in the composed document + * (see shadow DOM spec). */ static bool ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant, nsINode* aPossibleAncestor); diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index c4adf16fdc07..015f26156e24 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -2025,6 +2025,10 @@ nsContentUtils::GetCrossDocParentNode(nsINode* aChild) NS_PRECONDITION(aChild, "The child is null!"); nsINode* parent = aChild->GetParentNode(); + if (parent && parent->IsContent() && aChild->IsContent()) { + parent = aChild->AsContent()->GetFlattenedTreeParent(); + } + if (parent || !aChild->IsNodeOfType(nsINode::eDOCUMENT)) return parent; @@ -2083,12 +2087,6 @@ nsContentUtils::ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant, if (aPossibleDescendant == aPossibleAncestor) return true; - // Step over shadow root to the host node. - ShadowRoot* shadowRoot = ShadowRoot::FromNode(aPossibleDescendant); - if (shadowRoot) { - aPossibleDescendant = shadowRoot->GetHost(); - } - aPossibleDescendant = GetCrossDocParentNode(aPossibleDescendant); } while (aPossibleDescendant);