зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1700051: part 9) Change `mozInlineSpellStatus::CreateForNavigation` to return `Result<...,...>`. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D109744
This commit is contained in:
Родитель
5dde374aaf
Коммит
ad87ef090b
|
@ -214,48 +214,49 @@ mozInlineSpellStatus::CreateForEditorChange(
|
||||||
// not be processed, *aContinue will be false.
|
// not be processed, *aContinue will be false.
|
||||||
|
|
||||||
// static
|
// static
|
||||||
nsresult mozInlineSpellStatus::CreateForNavigation(
|
Result<UniquePtr<mozInlineSpellStatus>, nsresult>
|
||||||
UniquePtr<mozInlineSpellStatus>& aStatus,
|
mozInlineSpellStatus::CreateForNavigation(
|
||||||
mozInlineSpellChecker& aSpellChecker, bool aForceCheck,
|
mozInlineSpellChecker& aSpellChecker, bool aForceCheck,
|
||||||
int32_t aNewPositionOffset, nsINode* aOldAnchorNode,
|
int32_t aNewPositionOffset, nsINode* aOldAnchorNode,
|
||||||
uint32_t aOldAnchorOffset, nsINode* aNewAnchorNode,
|
uint32_t aOldAnchorOffset, nsINode* aNewAnchorNode,
|
||||||
uint32_t aNewAnchorOffset, bool* aContinue) {
|
uint32_t aNewAnchorOffset, bool* aContinue) {
|
||||||
aStatus = MakeUnique<mozInlineSpellStatus>(&aSpellChecker);
|
UniquePtr<mozInlineSpellStatus> status =
|
||||||
|
MakeUnique<mozInlineSpellStatus>(&aSpellChecker);
|
||||||
|
|
||||||
aStatus->mOp = eOpNavigation;
|
status->mOp = eOpNavigation;
|
||||||
|
|
||||||
aStatus->mForceNavigationWordCheck = aForceCheck;
|
status->mForceNavigationWordCheck = aForceCheck;
|
||||||
aStatus->mNewNavigationPositionOffset = aNewPositionOffset;
|
status->mNewNavigationPositionOffset = aNewPositionOffset;
|
||||||
|
|
||||||
// get the root node for checking
|
// get the root node for checking
|
||||||
TextEditor* textEditor = aStatus->mSpellChecker->mTextEditor;
|
TextEditor* textEditor = status->mSpellChecker->mTextEditor;
|
||||||
if (NS_WARN_IF(!textEditor)) {
|
if (NS_WARN_IF(!textEditor)) {
|
||||||
return NS_ERROR_FAILURE;
|
return Err(NS_ERROR_FAILURE);
|
||||||
}
|
}
|
||||||
Element* root = textEditor->GetRoot();
|
Element* root = textEditor->GetRoot();
|
||||||
if (NS_WARN_IF(!root)) {
|
if (NS_WARN_IF(!root)) {
|
||||||
return NS_ERROR_FAILURE;
|
return Err(NS_ERROR_FAILURE);
|
||||||
}
|
}
|
||||||
// the anchor node might not be in the DOM anymore, check
|
// the anchor node might not be in the DOM anymore, check
|
||||||
if (root && aOldAnchorNode &&
|
if (root && aOldAnchorNode &&
|
||||||
!aOldAnchorNode->IsShadowIncludingInclusiveDescendantOf(root)) {
|
!aOldAnchorNode->IsShadowIncludingInclusiveDescendantOf(root)) {
|
||||||
*aContinue = false;
|
*aContinue = false;
|
||||||
return NS_OK;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
aStatus->mOldNavigationAnchorRange =
|
status->mOldNavigationAnchorRange =
|
||||||
aStatus->PositionToCollapsedRange(aOldAnchorNode, aOldAnchorOffset);
|
status->PositionToCollapsedRange(aOldAnchorNode, aOldAnchorOffset);
|
||||||
if (NS_WARN_IF(!aStatus->mOldNavigationAnchorRange)) {
|
if (NS_WARN_IF(!status->mOldNavigationAnchorRange)) {
|
||||||
return NS_ERROR_FAILURE;
|
return Err(NS_ERROR_FAILURE);
|
||||||
}
|
}
|
||||||
aStatus->mAnchorRange =
|
status->mAnchorRange =
|
||||||
aStatus->PositionToCollapsedRange(aNewAnchorNode, aNewAnchorOffset);
|
status->PositionToCollapsedRange(aNewAnchorNode, aNewAnchorOffset);
|
||||||
if (NS_WARN_IF(!aStatus->mAnchorRange)) {
|
if (NS_WARN_IF(!status->mAnchorRange)) {
|
||||||
return NS_ERROR_FAILURE;
|
return Err(NS_ERROR_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
*aContinue = true;
|
*aContinue = true;
|
||||||
return NS_OK;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mozInlineSpellStatus::InitForSelection
|
// mozInlineSpellStatus::InitForSelection
|
||||||
|
@ -1749,14 +1750,18 @@ nsresult mozInlineSpellChecker::HandleNavigationEvent(
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
bool shouldPost;
|
bool shouldPost;
|
||||||
UniquePtr<mozInlineSpellStatus> status;
|
Result<UniquePtr<mozInlineSpellStatus>, nsresult> res =
|
||||||
rv = status->CreateForNavigation(
|
mozInlineSpellStatus::CreateForNavigation(
|
||||||
status, *this, aForceWordSpellCheck, aNewPositionOffset,
|
*this, aForceWordSpellCheck, aNewPositionOffset, currentAnchorNode,
|
||||||
currentAnchorNode, currentAnchorOffset, mCurrentSelectionAnchorNode,
|
currentAnchorOffset, mCurrentSelectionAnchorNode,
|
||||||
mCurrentSelectionOffset, &shouldPost);
|
mCurrentSelectionOffset, &shouldPost);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
if (NS_WARN_IF(res.isErr())) {
|
||||||
|
return res.unwrapErr();
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldPost) {
|
if (shouldPost) {
|
||||||
rv = ScheduleSpellCheck(std::move(status));
|
rv = ScheduleSpellCheck(res.unwrap());
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,12 +43,11 @@ class mozInlineSpellStatus {
|
||||||
nsINode* aStartNode, uint32_t aStartOffset,
|
nsINode* aStartNode, uint32_t aStartOffset,
|
||||||
nsINode* aEndNode, uint32_t aEndOffset);
|
nsINode* aEndNode, uint32_t aEndOffset);
|
||||||
|
|
||||||
static nsresult CreateForNavigation(
|
static mozilla::Result<mozilla::UniquePtr<mozInlineSpellStatus>, nsresult>
|
||||||
mozilla::UniquePtr<mozInlineSpellStatus>& aStatus,
|
CreateForNavigation(mozInlineSpellChecker& aSpellChecker, bool aForceCheck,
|
||||||
mozInlineSpellChecker& aSpellChecker, bool aForceCheck,
|
int32_t aNewPositionOffset, nsINode* aOldAnchorNode,
|
||||||
int32_t aNewPositionOffset, nsINode* aOldAnchorNode,
|
uint32_t aOldAnchorOffset, nsINode* aNewAnchorNode,
|
||||||
uint32_t aOldAnchorOffset, nsINode* aNewAnchorNode,
|
uint32_t aNewAnchorOffset, bool* aContinue);
|
||||||
uint32_t aNewAnchorOffset, bool* aContinue);
|
|
||||||
nsresult InitForSelection();
|
nsresult InitForSelection();
|
||||||
nsresult InitForRange(nsRange* aRange);
|
nsresult InitForRange(nsRange* aRange);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче