diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index b136d30e65ee..6171bf01e4f1 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -990,8 +990,8 @@ void nsIContent::GetEventTargetParent(EventChainPreVisitor& aVisitor) { // dispatching event to Window object in a content page and // propagating the event to a chrome Element. if (targetInKnownToBeHandledScope && - nsContentUtils::ContentIsShadowIncludingDescendantOf( - this, targetInKnownToBeHandledScope->SubtreeRoot())) { + IsShadowIncludingInclusiveDescendantOf( + targetInKnownToBeHandledScope->SubtreeRoot())) { // Part of step 11.4. // "If target's root is a shadow-including inclusive ancestor of // parent, then" diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 1e72f01da338..e791ed474704 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -2200,32 +2200,6 @@ bool nsContentUtils::ContentIsHostIncludingDescendantOf( return false; } -bool nsContentUtils::ContentIsShadowIncludingDescendantOf( - const nsINode* aPossibleDescendant, const nsINode* aPossibleAncestor) { - MOZ_ASSERT(aPossibleDescendant, "The possible descendant is null!"); - MOZ_ASSERT(aPossibleAncestor, "The possible ancestor is null!"); - - if (aPossibleAncestor == aPossibleDescendant->GetComposedDoc()) { - return true; - } - - do { - if (aPossibleDescendant == aPossibleAncestor) { - return true; - } - - if (aPossibleDescendant->NodeType() == nsINode::DOCUMENT_FRAGMENT_NODE) { - ShadowRoot* shadowRoot = - ShadowRoot::FromNode(const_cast(aPossibleDescendant)); - aPossibleDescendant = shadowRoot ? shadowRoot->GetHost() : nullptr; - } else { - aPossibleDescendant = aPossibleDescendant->GetParentNode(); - } - } while (aPossibleDescendant); - - return false; -} - // static bool nsContentUtils::ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant, nsINode* aPossibleAncestor) { @@ -2285,7 +2259,7 @@ nsINode* nsContentUtils::Retarget(nsINode* aTargetA, nsINode* aTargetB) { } // or A's root is a shadow-including inclusive ancestor of B... - if (nsContentUtils::ContentIsShadowIncludingDescendantOf(aTargetB, root)) { + if (aTargetB->IsShadowIncludingInclusiveDescendantOf(root)) { // ...then return A. return aTargetA; } diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 7162a83ec429..3664849ece7a 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -344,13 +344,6 @@ class nsContentUtils { static bool ContentIsHostIncludingDescendantOf( const nsINode* aPossibleDescendant, const nsINode* aPossibleAncestor); - /** - * Similar to above, but does special case only ShadowRoot, - * not HTMLTemplateElement. - */ - static bool ContentIsShadowIncludingDescendantOf( - const nsINode* aPossibleDescendant, const nsINode* aPossibleAncestor); - /** * Similar to nsINode::IsInclusiveDescendantOf except it crosses document * boundaries, this function uses ancestor/descendant relations in the diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index d3165c847968..d70f288a977a 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -131,6 +131,26 @@ bool nsINode::IsInclusiveDescendantOf(const nsINode* aNode) const { return false; } +bool nsINode::IsShadowIncludingInclusiveDescendantOf( + const nsINode* aNode) const { + MOZ_ASSERT(aNode, "The node is nullptr."); + + if (this->GetComposedDoc() == aNode) { + return true; + } + + const nsINode* node = this; + do { + if (node == aNode) { + return true; + } + + node = node->GetParentOrShadowHostNode(); + } while (node); + + return false; +} + nsINode::nsSlots::nsSlots() : mWeakReference(nullptr) {} nsINode::nsSlots::~nsSlots() { diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 609cc3bea76c..3c15c375e795 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -424,6 +424,13 @@ class nsINode : public mozilla::dom::EventTarget { */ bool IsInclusiveDescendantOf(const nsINode* aNode) const; + /** + * https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-descendant + * + * @param aNode must not be nullptr. + */ + bool IsShadowIncludingInclusiveDescendantOf(const nsINode* aNode) const; + /** * Return this node as a document fragment. Asserts IsDocumentFragment(). * diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.cpp b/extensions/spellcheck/src/mozInlineSpellChecker.cpp index de5ce5e6dc59..91985115020b 100644 --- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp +++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp @@ -222,8 +222,7 @@ nsresult mozInlineSpellStatus::InitForNavigation( } // the anchor node might not be in the DOM anymore, check if (root && aOldAnchorNode && - !nsContentUtils::ContentIsShadowIncludingDescendantOf(aOldAnchorNode, - root)) { + !aOldAnchorNode->IsShadowIncludingInclusiveDescendantOf(root)) { *aContinue = false; return NS_OK; } @@ -1271,10 +1270,8 @@ nsresult mozInlineSpellChecker::DoSpellCheck( // aWordUtil.GetRootNode() nsINode* rootNode = aWordUtil.GetRootNode(); if (!beginNode->IsInComposedDoc() || !endNode->IsInComposedDoc() || - !nsContentUtils::ContentIsShadowIncludingDescendantOf(beginNode, - rootNode) || - !nsContentUtils::ContentIsShadowIncludingDescendantOf(endNode, - rootNode)) { + !beginNode->IsShadowIncludingInclusiveDescendantOf(rootNode) || + !endNode->IsShadowIncludingInclusiveDescendantOf(rootNode)) { // Just bail out and don't try to spell-check this return NS_OK; }