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().
--- 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);