Bug 1394935: Introduce ContentIsFlattenedTreeDescendantOfForStyle. r?bholley draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 31 Aug 2017 19:42:06 +0200
changeset 656811 867da97dddfb756d8b811a223d8eea300908f790
parent 656810 8e79bd7132ca1524ba168f407ff0af2da1bd8ac6
child 656812 3c5242de5783bfc5f49e56de2aab44ed0b77bce2
push id77325
push userbmo:emilio@crisal.io
push dateThu, 31 Aug 2017 18:09:13 +0000
reviewersbholley
bugs1394935
milestone57.0a1
Bug 1394935: Introduce ContentIsFlattenedTreeDescendantOfForStyle. r?bholley MozReview-Commit-ID: 69w9nnRJsIy
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -2640,16 +2640,36 @@ nsContentUtils::ContentIsFlattenedTreeDe
     }
     aPossibleDescendant = aPossibleDescendant->GetFlattenedTreeParentNode();
   } while (aPossibleDescendant);
 
   return false;
 }
 
 // static
+bool
+nsContentUtils::ContentIsFlattenedTreeDescendantOfForStyle(
+  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->GetFlattenedTreeParentNodeForStyle();
+  } while (aPossibleDescendant);
+
+  return false;
+}
+
+// static
 nsresult
 nsContentUtils::GetAncestors(nsINode* aNode,
                              nsTArray<nsINode*>& aArray)
 {
   while (aNode) {
     aArray.AppendElement(aNode);
     aNode = aNode->GetParentNode();
   }
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -338,16 +338,26 @@ public:
    * cross document boundaries.
    *
    * @see nsINode::GetFlattenedTreeParentNode()
    */
   static bool
   ContentIsFlattenedTreeDescendantOf(const nsINode* aPossibleDescendant,
                                      const nsINode* aPossibleAncestor);
 
+  /**
+   * Same as `ContentIsFlattenedTreeDescendantOf`, but from the flattened tree
+   * point of view of the style system
+   *
+   * @see nsINode::GetFlattenedTreeParentNodeForStyle()
+   */
+  static bool
+  ContentIsFlattenedTreeDescendantOfForStyle(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);
 
   /*