summaryrefslogtreecommitdiff
path: root/dom/base
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-09-16 13:30:35 +0000
committerMoonchild <moonchild@palemoon.org>2020-09-16 13:30:35 +0000
commit918973d57b689bea99dbeb5a9dfb1341032cbf54 (patch)
tree5e7ef7445f36495f5aa840929c6f2fc16cabc672 /dom/base
parent99e2dd7d2983b538b12dc5ef8aa6964bff643066 (diff)
downloaduxp-918973d57b689bea99dbeb5a9dfb1341032cbf54.tar.gz
Issue mcp-graveyard/UXP#1643 - Part 1: Add GetNodeDepth() to nsContentUtils.
Diffstat (limited to 'dom/base')
-rw-r--r--dom/base/nsContentUtils.cpp14
-rw-r--r--dom/base/nsContentUtils.h8
2 files changed, 22 insertions, 0 deletions
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
index 3568ced90d..20b6beffa1 100644
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -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;
+} \ No newline at end of file
diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h
index 8cf105bb3e..db9558d06c 100644
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -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();