From ed9c8cebed2fd1165f45262924f2114ce1f8a8c9 Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Fri, 28 May 2021 07:56:12 +0000 Subject: [PATCH] Bug 1687263: part 1) Add `NodeOffset::operator==(const RangeBoundary)`. r=smaug Required for the following review. Differential Revision: https://phabricator.services.mozilla.com/D116093 --- extensions/spellcheck/src/mozInlineSpellWordUtil.cpp | 14 ++++++++++++++ extensions/spellcheck/src/mozInlineSpellWordUtil.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp index d8c15c1eb883..fee48b0dbda0 100644 --- a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp +++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp @@ -99,6 +99,20 @@ static bool IsDOMWordSeparator(char16_t ch) { return false; } +bool NodeOffset::operator==( + const mozilla::RangeBoundary& aRangeBoundary) const { + if (aRangeBoundary.Container() != mNode) { + return false; + } + + const Maybe rangeBoundaryOffset = + aRangeBoundary.Offset(RangeBoundary::OffsetFilter::kValidOffsets); + + MOZ_ASSERT(mOffset >= 0); + return rangeBoundaryOffset && + (*rangeBoundaryOffset == static_cast(mOffset)); +} + // static Maybe mozInlineSpellWordUtil::Create( const TextEditor& aTextEditor) { diff --git a/extensions/spellcheck/src/mozInlineSpellWordUtil.h b/extensions/spellcheck/src/mozInlineSpellWordUtil.h index 9db705fd998c..17d45078770a 100644 --- a/extensions/spellcheck/src/mozInlineSpellWordUtil.h +++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.h @@ -10,6 +10,7 @@ #include "mozilla/Attributes.h" #include "mozilla/Maybe.h" +#include "mozilla/RangeBoundary.h" #include "mozilla/Result.h" #include "mozilla/dom/Document.h" #include "nsCOMPtr.h" @@ -41,6 +42,8 @@ struct NodeOffset { return mNode == aOther.mNode && mOffset == aOther.mOffset; } + bool operator==(const mozilla::RangeBoundary& aRangeBoundary) const; + bool operator!=(const NodeOffset& aOther) const { return !(*this == aOther); } nsINode* Node() const { return mNode.get(); } -- 2.11.4.GIT