Bug 1399626 - Part 3: Add a variant of ComparePoints to nsContentUtils which takes RangeBoundaries, r=masayuki draft
authorMichael Layzell <michael@thelayzells.com>
Wed, 13 Sep 2017 16:53:49 -0400
changeset 672782 41507a50a158951342fc68925c0866df07f2a968
parent 672781 c28fe5cd1c2b4936e2884116a7f252616d9b321d
child 672783 9440e6bef786e6c9562fff8e0fb97205d5b44d9f
push id82373
push userbmo:nika@thelayzells.com
push dateFri, 29 Sep 2017 19:23:28 +0000
reviewersmasayuki
bugs1399626
milestone58.0a1
Bug 1399626 - Part 3: Add a variant of ComparePoints to nsContentUtils which takes RangeBoundaries, r=masayuki This is a temporary implementation, which will hopefully be fleshed out in the future to not require calling the `Offset()` methods. Currently it just dispatches to the existing implementation using Container() and Offset().
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -2877,16 +2877,30 @@ nsContentUtils::ComparePoints(nsIDOMNode
                               bool* aDisconnected)
 {
   nsCOMPtr<nsINode> parent1 = do_QueryInterface(aParent1);
   nsCOMPtr<nsINode> parent2 = do_QueryInterface(aParent2);
   NS_ENSURE_TRUE(parent1 && parent2, -1);
   return ComparePoints(parent1, aOffset1, parent2, aOffset2);
 }
 
+/* static */
+int32_t
+nsContentUtils::ComparePoints(const RawRangeBoundary& aFirst,
+                              const RawRangeBoundary& aSecond,
+                              bool* aDisconnected)
+{
+  if (NS_WARN_IF(!aFirst.IsSet()) || NS_WARN_IF(!aSecond.IsSet())) {
+    return -1;
+  }
+  return ComparePoints(aFirst.Container(), aFirst.Offset(),
+                       aSecond.Container(), aSecond.Offset(),
+                       aDisconnected);
+}
+
 inline bool
 IsCharInSet(const char* aSet,
             const char16_t aChar)
 {
   char16_t ch;
   while ((ch = *aSet)) {
     if (aChar == char16_t(ch)) {
       return true;
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -32,16 +32,17 @@
 #include "mozilla/dom/AutocompleteInfoBinding.h"
 #include "mozilla/dom/BindingDeclarations.h" // For CallerType
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/net/ReferrerPolicy.h"
 #include "mozilla/Logging.h"
 #include "mozilla/NotNull.h"
 #include "mozilla/Maybe.h"
+#include "mozilla/RangeBoundary.h"
 #include "nsIContentPolicy.h"
 #include "nsIDocument.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsPIDOMWindow.h"
 #include "nsRFPService.h"
 
 #if defined(XP_WIN)
 // Undefine LoadImage to prevent naming conflict with Windows.
@@ -441,16 +442,19 @@ public:
    *      (0x3FFFFF) at most.  Therefore, they can be int32_t for now.
    */
   static int32_t ComparePoints(nsINode* aParent1, int32_t aOffset1,
                                nsINode* aParent2, int32_t aOffset2,
                                bool* aDisconnected = nullptr);
   static int32_t ComparePoints(nsIDOMNode* aParent1, int32_t aOffset1,
                                nsIDOMNode* aParent2, int32_t aOffset2,
                                bool* aDisconnected = nullptr);
+  static int32_t ComparePoints(const mozilla::RawRangeBoundary& aFirst,
+                               const mozilla::RawRangeBoundary& aSecond,
+                               bool* aDisconnected = nullptr);
 
   /**
    * Brute-force search of the element subtree rooted at aContent for
    * an element with the given id.  aId must be nonempty, otherwise
    * this method may return nodes even if they have no id!
    */
   static Element* MatchElementId(nsIContent *aContent, const nsAString& aId);