From c15083e2e7110bdc879361c9f2245db9b9437eff Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Fri, 26 Mar 2021 09:21:12 +0000 Subject: [PATCH] Bug 1700051: part 11) Change `mozInlineSpellStatus::InitForRange` to static factory method. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D109746 --- .../spellcheck/src/mozInlineSpellChecker.cpp | 35 +++++++++++----------- extensions/spellcheck/src/mozInlineSpellChecker.h | 3 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.cpp b/extensions/spellcheck/src/mozInlineSpellChecker.cpp index 332e5266f1de..8b270c43bb01 100644 --- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp +++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp @@ -273,18 +273,23 @@ UniquePtr mozInlineSpellStatus::CreateForSelection( return status; } -// mozInlineSpellStatus::InitForRange +// mozInlineSpellStatus::CreateForRange // // Called to cause the spellcheck of the given range. This will look like // a change operation over the given range. -nsresult mozInlineSpellStatus::InitForRange(nsRange* aRange) { +// static +UniquePtr mozInlineSpellStatus::CreateForRange( + mozInlineSpellChecker& aSpellChecker, nsRange* aRange) { MOZ_LOG(sInlineSpellCheckerLog, LogLevel::Debug, ("%s: range=%p", __FUNCTION__, aRange)); - mOp = eOpChange; - mRange = aRange; - return NS_OK; + UniquePtr status = + MakeUnique(&aSpellChecker); + + status->mOp = eOpChange; + status->mRange = aRange; + return status; } // mozInlineSpellStatus::FinishInitOnEvent @@ -853,9 +858,8 @@ nsresult mozInlineSpellChecker::SpellCheckRange(nsRange* aRange) { return NS_ERROR_NOT_INITIALIZED; } - auto status = MakeUnique(this); - nsresult rv = status->InitForRange(aRange); - NS_ENSURE_SUCCESS(rv, rv); + UniquePtr status = + mozInlineSpellStatus::CreateForRange(*this, aRange); return ScheduleSpellCheck(std::move(status)); } @@ -931,9 +935,8 @@ mozInlineSpellChecker::RemoveWordFromDictionary(const nsAString& word) { nsresult rv = mSpellCheck->RemoveWordFromDictionary(word); NS_ENSURE_SUCCESS(rv, rv); - auto status = MakeUnique(this); - rv = status->InitForRange(nullptr); - NS_ENSURE_SUCCESS(rv, rv); + UniquePtr status = + mozInlineSpellStatus::CreateForRange(*this, nullptr); return ScheduleSpellCheck(std::move(status)); } @@ -1065,9 +1068,8 @@ nsresult mozInlineSpellChecker::SpellCheckBetweenNodes(nsINode* aStartNode, if (!range) return NS_OK; // range is empty: nothing to do - auto status = MakeUnique(this); - rv = status->InitForRange(range); - NS_ENSURE_SUCCESS(rv, rv); + UniquePtr status = + mozInlineSpellStatus::CreateForRange(*this, range); return ScheduleSpellCheck(std::move(status)); } @@ -1219,9 +1221,8 @@ nsresult mozInlineSpellChecker::DoSpellCheckSelection( // We use this state object for all calls, and just update its range. Note // that we don't need to call FinishInit since we will be filling in the // necessary information. - auto status = MakeUnique(this); - rv = status->InitForRange(nullptr); - NS_ENSURE_SUCCESS(rv, rv); + UniquePtr status = + mozInlineSpellStatus::CreateForRange(*this, nullptr); bool doneChecking; for (int32_t idx = 0; idx < count; idx++) { diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.h b/extensions/spellcheck/src/mozInlineSpellChecker.h index 500bf1d28e48..774dee53322a 100644 --- a/extensions/spellcheck/src/mozInlineSpellChecker.h +++ b/extensions/spellcheck/src/mozInlineSpellChecker.h @@ -52,7 +52,8 @@ class mozInlineSpellStatus { static mozilla::UniquePtr CreateForSelection( mozInlineSpellChecker& aSpellChecker); - nsresult InitForRange(nsRange* aRange); + static mozilla::UniquePtr CreateForRange( + mozInlineSpellChecker& aSpellChecker, nsRange* aRange); nsresult FinishInitOnEvent(mozInlineSpellWordUtil& aWordUtil); -- 2.11.4.GIT