Issue #1783 - Part 1: Move GetNodeDepth to ResizeObserver.cpp

GetNodeDepth() is a specialized version for ResizeObserver to get the depth of
a node across Shadow DOM. It's better to have this in ResizeObserver.cpp
instead of the generic ContentUtils.

Also updated the function to bypass the shadow root itself and not count it
because ResizeObserver doesn't observe the shadow root and only needs the
relative depths among all observed targets. IOW we use the flattened tree here.
This commit is contained in:
Moonchild 2021-06-18 10:35:19 +00:00 committed by roytam1
commit 51d3f2d2f3
3 changed files with 33 additions and 27 deletions

View file

@ -9781,17 +9781,3 @@ nsContentUtils::GetClosestNonNativeAnonymousAncestor(Element* aElement)
}
return e;
}
/* static */ uint32_t
nsContentUtils::GetNodeDepth(nsINode* aNode)
{
uint32_t depth = 1;
MOZ_ASSERT(aNode, "Node shouldn't be null");
while ((aNode = aNode->GetParentNode())) {
++depth;
}
return depth;
}