Bug 1355348 - Move IsFlattenedTreeDescendantOf helper to nsContentUtils; r?heycam
In the next patch in this series we would like to use this functionality in
nsSMILController as well so this patch moves it to somewhere we can share it.
MozReview-Commit-ID: 1IzWoCCw4aD
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -949,30 +949,16 @@ EffectCompositor::SetPerformanceWarning(
}
bool
EffectCompositor::PreTraverse()
{
return PreTraverseInSubtree(nullptr);
}
-static bool
-IsFlattenedTreeDescendantOf(nsINode* aPossibleDescendant,
- nsINode* aPossibleAncestor)
-{
- do {
- if (aPossibleDescendant == aPossibleAncestor) {
- return true;
- }
- aPossibleDescendant = aPossibleDescendant->GetFlattenedTreeParentNode();
- } while (aPossibleDescendant);
-
- return false;
-}
-
bool
EffectCompositor::PreTraverseInSubtree(Element* aRoot)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mPresContext->RestyleManager()->IsServo());
bool foundElementsNeedingRestyle = false;
for (size_t i = 0; i < kCascadeLevelCount; ++i) {
@@ -984,17 +970,19 @@ EffectCompositor::PreTraverseInSubtree(E
if (!postedRestyle) {
continue;
}
NonOwningAnimationTarget target = iter.Key();
// Ignore restyles that aren't in the flattened tree subtree rooted at
// aRoot.
- if (aRoot && !IsFlattenedTreeDescendantOf(target.mElement, aRoot)) {
+ if (aRoot &&
+ !nsContentUtils::ContentIsFlattenedTreeDescendantOf(target.mElement,
+ aRoot)) {
continue;
}
// We need to post restyle hints even if the target is not in EffectSet to
// ensure the final restyling for removed animations.
// We can't call PostRestyleEvent directly here since we are still in the
// middle of the servo traversal.
mPresContext->RestyleManager()->AsServo()->
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -2394,16 +2394,34 @@ nsContentUtils::ContentIsCrossDocDescend
return true;
aPossibleDescendant = GetCrossDocParentNode(aPossibleDescendant);
} while (aPossibleDescendant);
return false;
}
+// static
+bool
+nsContentUtils::ContentIsFlattenedTreeDescendantOf(
+ const nsINode* aPossibleDescendant,
+ const nsINode* aPossibleAncestor)
+{
+ NS_PRECONDITION(aPossibleDescendant, "The possible descendant is null!");
+ NS_PRECONDITION(aPossibleAncestor, "The possible ancestor is null!");
+
+ do {
+ if (aPossibleDescendant == aPossibleAncestor) {
+ return true;
+ }
+ aPossibleDescendant = aPossibleDescendant->GetFlattenedTreeParentNode();
+ } while (aPossibleDescendant);
+
+ return false;
+}
// static
nsresult
nsContentUtils::GetAncestors(nsINode* aNode,
nsTArray<nsINode*>& aArray)
{
while (aNode) {
aArray.AppendElement(aNode);
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -320,16 +320,26 @@ public:
/**
* Similar to ContentIsDescendantOf except it crosses document boundaries,
* this function uses ancestor/descendant relations in the composed document
* (see shadow DOM spec).
*/
static bool ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant,
nsINode* aPossibleAncestor);
+ /**
+ * As with ContentIsCrossDocDescendantOf but crosses shadow boundaries but not
+ * cross document boundaries.
+ *
+ * @see nsINode::GetFlattenedTreeParentNode()
+ */
+ static bool
+ ContentIsFlattenedTreeDescendantOf(const nsINode* aPossibleDescendant,
+ const nsINode* aPossibleAncestor);
+
/*
* This method fills the |aArray| with all ancestor nodes of |aNode|
* including |aNode| at the zero index.
*/
static nsresult GetAncestors(nsINode* aNode,
nsTArray<nsINode*>& aArray);
/*