Bug 1394935: Introduce ContentIsFlattenedTreeDescendantOfForStyle. r?bholley
MozReview-Commit-ID: 69w9nnRJsIy
--- 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);
/*