зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1545239 - Move GetNodeDepth into ResizeObserver.cpp r=dholbert
GetNodeDepth() is a special version for ResizeObserver to get the depth of node (across Shadow DOM). Based on the comment in D27615, it's better to move it into ResizeObserver.cpp. Differential Revision: https://phabricator.services.mozilla.com/D28736 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
dfac78ef7c
Коммит
6521583602
|
@ -7,13 +7,43 @@
|
|||
#include "mozilla/dom/ResizeObserver.h"
|
||||
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsSVGUtils.h"
|
||||
#include <limits>
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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;
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(ResizeObservation, mTarget)
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(ResizeObservation, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(ResizeObservation, Release)
|
||||
|
@ -136,7 +166,7 @@ void ResizeObserver::GatherActiveObservations(uint32_t aDepth) {
|
|||
continue;
|
||||
}
|
||||
|
||||
uint32_t targetDepth = nsContentUtils::GetNodeDepth(observation->Target());
|
||||
uint32_t targetDepth = GetNodeDepth(observation->Target());
|
||||
|
||||
if (targetDepth > aDepth) {
|
||||
mActiveTargets.AppendElement(observation);
|
||||
|
@ -172,7 +202,7 @@ uint32_t ResizeObserver::BroadcastActiveObservations() {
|
|||
// will be based on the updated size from last delivered observations.
|
||||
observation->UpdateBroadcastSize(rect.Size());
|
||||
|
||||
uint32_t targetDepth = nsContentUtils::GetNodeDepth(observation->Target());
|
||||
uint32_t targetDepth = GetNodeDepth(observation->Target());
|
||||
|
||||
if (targetDepth < shallowestTargetDepth) {
|
||||
shallowestTargetDepth = targetDepth;
|
||||
|
|
|
@ -10524,21 +10524,6 @@ 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);
|
||||
|
|
|
@ -3256,24 +3256,6 @@ 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();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче