Bug 1272409 part 2: Add GetNodeDepth() to nsContentUtils. r?dholbert
MozReview-Commit-ID: HyYuK3RXbSR
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -9547,8 +9547,25 @@ nsContentUtils::GetCustomPrototype(nsIDo
RefPtr<CustomElementsRegistry> registry(window->CustomElements());
if (!registry) {
return;
}
return registry->GetCustomPrototype(aAtom, aPrototype);
}
+
+/* static */ uint32_t
+nsContentUtils::GetNodeDepth(nsINode* aNode)
+{
+ uint32_t depth = 0;
+
+ if (aNode) {
+ nsINode* parent = aNode->GetParentNode();
+
+ while (parent) {
+ parent = parent->GetParentNode();
+ ++depth;
+ }
+ }
+
+ return depth;
+}
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2697,16 +2697,21 @@ public:
mozilla::dom::LifecycleCallbackArgs* aArgs = nullptr,
mozilla::dom::CustomElementDefinition* aDefinition = nullptr);
static void GetCustomPrototype(nsIDocument* aDoc,
int32_t aNamespaceID,
nsIAtom* aAtom,
JS::MutableHandle<JSObject*> prototype);
+ /**
+ * Returns the length of the parent-traversal path from node to root.
+ */
+ static uint32_t GetNodeDepth(nsINode* aNode);
+
private:
static bool InitializeEventTable();
static nsresult EnsureStringBundle(PropertiesFile aFile);
static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
nsIPrincipal* aPrincipal);