Bug 1394935: Introduce nsContentUtils::CommonFlattenedTreeAncestorForStyle. r?bholley
MozReview-Commit-ID: GThZUOIe30o
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -39,16 +39,17 @@
#include "mozilla/LoadInfo.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/CustomElementRegistry.h"
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/DOMException.h"
#include "mozilla/dom/DOMExceptionBinding.h"
#include "mozilla/dom/DOMTypes.h"
#include "mozilla/dom/Element.h"
+#include "mozilla/dom/ElementInlines.h"
#include "mozilla/dom/FileSystemSecurity.h"
#include "mozilla/dom/FileBlobImpl.h"
#include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/dom/HTMLTemplateElement.h"
#include "mozilla/dom/HTMLContentElement.h"
#include "mozilla/dom/HTMLShadowElement.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/Promise.h"
@@ -2788,16 +2789,26 @@ nsContentUtils::GetCommonFlattenedTreeAn
nsIContent* aContent2)
{
return GetCommonAncestorInternal(aContent1, aContent2, [](nsIContent* aContent) {
return aContent->GetFlattenedTreeParent();
});
}
/* static */
+Element*
+nsContentUtils::GetCommonFlattenedTreeAncestorForStyle(Element* aElement1,
+ Element* aElement2)
+{
+ return GetCommonAncestorInternal(aElement1, aElement2, [](Element* aElement) {
+ return aElement->GetFlattenedTreeParentElementForStyle();
+ });
+}
+
+/* static */
bool
nsContentUtils::PositionIsBefore(nsINode* aNode1, nsINode* aNode2)
{
return (aNode2->CompareDocumentPosition(*aNode1) &
(nsIDOMNode::DOCUMENT_POSITION_PRECEDING |
nsIDOMNode::DOCUMENT_POSITION_DISCONNECTED)) ==
nsIDOMNode::DOCUMENT_POSITION_PRECEDING;
}
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -407,16 +407,23 @@ public:
if (aContent1 == aContent2) {
return aContent1;
}
return GetCommonFlattenedTreeAncestorHelper(aContent1, aContent2);
}
/**
+ * Returns the common flattened tree ancestor from the point of view of the
+ * style system, if any, for two given content nodes.
+ */
+ static Element* GetCommonFlattenedTreeAncestorForStyle(
+ Element* aElement1, Element* aElement2);
+
+ /**
* Returns true if aNode1 is before aNode2 in the same connected
* tree.
*/
static bool PositionIsBefore(nsINode* aNode1, nsINode* aNode2);
/**
* Utility routine to compare two "points", where a point is a
* node/offset pair