Issue #1643 - Part 1: Add GetNodeDepth() to nsContentUtils.

This commit is contained in:
Moonchild 2020-09-16 13:30:35 +00:00 committed by roytam1
commit d883c3ef98
2 changed files with 22 additions and 0 deletions

View file

@ -9843,3 +9843,17 @@ 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;
}

View file

@ -2763,6 +2763,14 @@ public:
static bool
IsCustomElementsEnabled() { return sIsCustomElementsEnabled; }
/**
* Returns the length of the parent-traversal path (in terms of the number of
* nodes) to an unparented/root node from aNode. An unparented/root node is
* considered to have a depth of 1, its children have a depth of 2, etc.
* aNode is expected to be non-null.
*/
static uint32_t GetNodeDepth(nsINode* aNode);
private:
static bool InitializeEventTable();