зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
d332d1218d
Коммит
595e58baba
|
@ -10621,6 +10621,21 @@ bool nsContentUtils::
|
||||||
nsThreadManager::MainThreadHasPendingHighPriorityEvents();
|
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 */
|
/* static */
|
||||||
bool nsContentUtils::IsURIInPrefList(nsIURI* aURI, const char* aPrefName) {
|
bool nsContentUtils::IsURIInPrefList(nsIURI* aURI, const char* aPrefName) {
|
||||||
MOZ_ASSERT(aPrefName);
|
MOZ_ASSERT(aPrefName);
|
||||||
|
|
|
@ -3360,6 +3360,24 @@ class nsContentUtils {
|
||||||
static bool HighPriorityEventPendingForTopLevelDocumentBeforeContentfulPaint(
|
static bool HighPriorityEventPendingForTopLevelDocumentBeforeContentfulPaint(
|
||||||
Document* aDocument);
|
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:
|
private:
|
||||||
static bool InitializeEventTable();
|
static bool InitializeEventTable();
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче