Bug 1394935: Introduce nsContentUtils::CommonFlattenedTreeAncestorForStyle. r?bholley draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 31 Aug 2017 09:42:24 +0200
changeset 656812 3c5242de5783bfc5f49e56de2aab44ed0b77bce2
parent 656811 867da97dddfb756d8b811a223d8eea300908f790
child 656813 7e15bea104df62ee4cef9dba0f8509853d20601e
push id77325
push userbmo:emilio@crisal.io
push dateThu, 31 Aug 2017 18:09:13 +0000
reviewersbholley
bugs1394935
milestone57.0a1
Bug 1394935: Introduce nsContentUtils::CommonFlattenedTreeAncestorForStyle. r?bholley MozReview-Commit-ID: GThZUOIe30o
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
--- 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