Bug 1355348 - Move IsFlattenedTreeDescendantOf helper to nsContentUtils; r=heycam
authorBrian Birtles <birtles@gmail.com>
Wed, 26 Apr 2017 13:00:10 +0900
changeset 569343 5881280a872d74f1a24fc212ec524209a5631758
parent 569342 dc594f991dc2846c7712d7bfd53915f8686dd09f
child 569344 f4de7213d853c01abe9bb2b1da738d4b0b90095d
push id56143
push userbmo:jeremychen@mozilla.com
push dateThu, 27 Apr 2017 10:17:21 +0000
reviewersheycam
bugs1355348
milestone55.0a1
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
dom/animation/EffectCompositor.cpp
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
--- 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);
 
   /*