Bug 1272409 - Part 1: Add GetNodeDepth() to nsContentUtils. r=smaug

`GetNodeDepth()` will be used in the next patch.

Depends on D27614

Differential Revision: https://phabricator.services.mozilla.com/D27615

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Fariskhi Vidyan 2019-04-26 20:29:11 +00:00
Родитель d332d1218d
Коммит 595e58baba
2 изменённых файлов: 33 добавлений и 0 удалений

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

@ -10621,6 +10621,21 @@ bool nsContentUtils::
nsThreadManager::MainThreadHasPendingHighPriorityEvents();
}
/* static */
uint32_t nsContentUtils::GetNodeDepth(nsINode* aNode) {
uint32_t depth = 1;
MOZ_ASSERT(aNode, "Node shouldn't be null");
// Use GetFlattenedTreeParentNode to bypass the shadow root and cross the
// shadow boundary to calculate the node depth without the shadow root.
while ((aNode = aNode->GetFlattenedTreeParentNode())) {
++depth;
}
return depth;
}
/* static */
bool nsContentUtils::IsURIInPrefList(nsIURI* aURI, const char* aPrefName) {
MOZ_ASSERT(aPrefName);

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

@ -3360,6 +3360,24 @@ class nsContentUtils {
static bool HighPriorityEventPendingForTopLevelDocumentBeforeContentfulPaint(
Document* aDocument);
/**
* 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.
* Note: The shadow root is not part of the calculation because the caller,
* ResizeObserver, doesn't observe the shadow root, and only needs relative
* depths among all the observed targets. In other words, we calculate the
* depth of the flattened tree.
*
* However, these is a spec issue about how to handle shadow DOM case. We
* may need to update this function later:
* https://github.com/w3c/csswg-drafts/issues/3840
*
* https://drafts.csswg.org/resize-observer/#calculate-depth-for-node-h
*/
static uint32_t GetNodeDepth(nsINode* aNode);
private:
static bool InitializeEventTable();