Bug 1566046: move `nsContentUtils::ContentIsShadowIncludingDescendantOf` to `nsINode::IsShadowIncludingInclusiveDescendantOf`. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D38079
This commit is contained in:
Mirko Brodesser 2019-07-15 11:56:00 +02:00
Родитель 1669cc6770
Коммит 8135a5859f
6 изменённых файлов: 33 добавлений и 42 удалений

Просмотреть файл

@ -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"

Просмотреть файл

@ -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<nsINode*>(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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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() {

Просмотреть файл

@ -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().
*

Просмотреть файл

@ -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;
}