зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1700051: part 20) Merge `mozInlineSpellStatus`'s constructor and its `Init` method. r=smaug
Allows to `const`-qualify some members. Differential Revision: https://phabricator.services.mozilla.com/D110083
This commit is contained in:
Родитель
b3f55e2753
Коммит
a4864650c7
|
@ -1555,9 +1555,11 @@ nsresult mozInlineSpellChecker::ResumeCheck(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
mozInlineSpellWordUtil wordUtil;
|
||||
nsresult rv = wordUtil.Init(*mTextEditor);
|
||||
if (NS_FAILED(rv)) return NS_OK; // editor doesn't like us, don't assert
|
||||
Maybe<mozInlineSpellWordUtil> wordUtil{
|
||||
mozInlineSpellWordUtil::Create(*mTextEditor)};
|
||||
if (!wordUtil) {
|
||||
return NS_OK; // editor doesn't like us, don't assert
|
||||
}
|
||||
|
||||
RefPtr<Selection> spellCheckSelection = GetSpellCheckSelection();
|
||||
if (NS_WARN_IF(!spellCheckSelection)) {
|
||||
|
@ -1565,7 +1567,7 @@ nsresult mozInlineSpellChecker::ResumeCheck(
|
|||
}
|
||||
|
||||
nsAutoCString currentDictionary;
|
||||
rv = mSpellCheck->GetCurrentDictionary(currentDictionary);
|
||||
nsresult rv = mSpellCheck->GetCurrentDictionary(currentDictionary);
|
||||
if (NS_FAILED(rv)) {
|
||||
MOZ_LOG(sInlineSpellCheckerLog, LogLevel::Debug,
|
||||
("%s: no active dictionary.", __FUNCTION__));
|
||||
|
@ -1583,15 +1585,15 @@ nsresult mozInlineSpellChecker::ResumeCheck(
|
|||
|
||||
CleanupRangesInSelection(spellCheckSelection);
|
||||
|
||||
rv = aStatus->FinishInitOnEvent(wordUtil);
|
||||
rv = aStatus->FinishInitOnEvent(*wordUtil);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!aStatus->mRange) return NS_OK; // empty range, nothing to do
|
||||
|
||||
bool doneChecking = true;
|
||||
if (aStatus->GetOperation() == mozInlineSpellStatus::eOpSelection)
|
||||
rv = DoSpellCheckSelection(wordUtil, spellCheckSelection);
|
||||
rv = DoSpellCheckSelection(*wordUtil, spellCheckSelection);
|
||||
else
|
||||
rv = DoSpellCheck(wordUtil, spellCheckSelection, aStatus, &doneChecking);
|
||||
rv = DoSpellCheck(*wordUtil, spellCheckSelection, aStatus, &doneChecking);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!doneChecking) rv = ScheduleSpellCheck(std::move(aStatus));
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
#include "mozInlineSpellWordUtil.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include "mozilla/BinarySearch.h"
|
||||
#include "mozilla/HTMLEditor.h"
|
||||
#include "mozilla/Logging.h"
|
||||
|
@ -21,7 +24,6 @@
|
|||
#include "nsRange.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIFrame.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -97,23 +99,24 @@ static bool IsDOMWordSeparator(char16_t ch) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// mozInlineSpellWordUtil::Init
|
||||
|
||||
nsresult mozInlineSpellWordUtil::Init(const TextEditor& aTextEditor) {
|
||||
mDocument = aTextEditor.GetDocument();
|
||||
if (NS_WARN_IF(!mDocument)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
// static
|
||||
Maybe<mozInlineSpellWordUtil> mozInlineSpellWordUtil::Create(
|
||||
const TextEditor& aTextEditor) {
|
||||
mozInlineSpellWordUtil util;
|
||||
util.mDocument = aTextEditor.GetDocument();
|
||||
if (NS_WARN_IF(!util.mDocument)) {
|
||||
return Nothing();
|
||||
}
|
||||
|
||||
mIsContentEditableOrDesignMode = !!aTextEditor.AsHTMLEditor();
|
||||
util.mIsContentEditableOrDesignMode = !!aTextEditor.AsHTMLEditor();
|
||||
|
||||
// Find the root node for the editor. For contenteditable the mRootNode could
|
||||
// change to shadow root if the begin and end are inside the shadowDOM.
|
||||
mRootNode = aTextEditor.GetRoot();
|
||||
if (NS_WARN_IF(!mRootNode)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
util.mRootNode = aTextEditor.GetRoot();
|
||||
if (NS_WARN_IF(!util.mRootNode)) {
|
||||
return Nothing();
|
||||
}
|
||||
return NS_OK;
|
||||
return Some(std::move(util));
|
||||
}
|
||||
|
||||
static inline bool IsSpellCheckingTextNode(nsINode* aNode) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#define mozInlineSpellWordUtil_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
@ -78,15 +79,8 @@ class NodeOffsetRange {
|
|||
|
||||
class MOZ_STACK_CLASS mozInlineSpellWordUtil {
|
||||
public:
|
||||
mozInlineSpellWordUtil()
|
||||
: mIsContentEditableOrDesignMode(false),
|
||||
mRootNode(nullptr),
|
||||
mSoftBegin(nullptr, 0),
|
||||
mSoftEnd(nullptr, 0),
|
||||
mNextWordIndex(-1),
|
||||
mSoftTextValid(false) {}
|
||||
|
||||
nsresult Init(const mozilla::TextEditor& aTextEditor);
|
||||
static mozilla::Maybe<mozInlineSpellWordUtil> Create(
|
||||
const mozilla::TextEditor& aTextEditor);
|
||||
|
||||
// sets the current position, this should be inside the range. If we are in
|
||||
// the middle of a word, we'll move to its start.
|
||||
|
@ -125,7 +119,15 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil {
|
|||
const nsINode* GetRootNode() const { return mRootNode; }
|
||||
|
||||
private:
|
||||
// cached stuff for the editor, set by Init
|
||||
mozInlineSpellWordUtil()
|
||||
: mIsContentEditableOrDesignMode(false),
|
||||
mRootNode(nullptr),
|
||||
mSoftBegin(nullptr, 0),
|
||||
mSoftEnd(nullptr, 0),
|
||||
mNextWordIndex(-1),
|
||||
mSoftTextValid(false) {}
|
||||
|
||||
// cached stuff for the editor
|
||||
RefPtr<mozilla::dom::Document> mDocument;
|
||||
bool mIsContentEditableOrDesignMode;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче