Bug 1708422: part 10) Factor `ShouldSpellCheckRange` out. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D114104
This commit is contained in:
Mirko Brodesser 2021-05-20 09:03:27 +00:00
Родитель 882cc710a4
Коммит ddbcce9316
1 изменённых файлов: 14 добавлений и 6 удалений

Просмотреть файл

@ -1296,6 +1296,8 @@ class MOZ_STACK_CLASS mozInlineSpellChecker::SpellCheckerTimeSlice {
void CheckWordsAndAddRangesForMisspellings(
const nsTArray<nsString>& aWords, nsTArray<NodeOffsetRange>&& aRanges);
bool ShouldSpellCheckRange(const nsRange& aRange) const;
mozInlineSpellChecker& mInlineSpellChecker;
mozInlineSpellWordUtil& mWordUtil;
mozilla::dom::Selection& mSpellCheckSelection;
@ -1303,6 +1305,17 @@ class MOZ_STACK_CLASS mozInlineSpellChecker::SpellCheckerTimeSlice {
bool& mDoneChecking;
};
bool mozInlineSpellChecker::SpellCheckerTimeSlice::ShouldSpellCheckRange(
const nsRange& aRange) const {
nsINode* beginNode = aRange.GetStartContainer();
nsINode* endNode = aRange.GetEndContainer();
const nsINode* rootNode = mWordUtil.GetRootNode();
return beginNode->IsInComposedDoc() && endNode->IsInComposedDoc() &&
beginNode->IsShadowIncludingInclusiveDescendantOf(rootNode) &&
endNode->IsShadowIncludingInclusiveDescendantOf(rootNode);
}
// mozInlineSpellChecker::SpellCheckerTimeSlice::Execute
//
// This function checks words intersecting the given range, excluding those
@ -1372,12 +1385,7 @@ nsresult mozInlineSpellChecker::SpellCheckerTimeSlice::Execute() {
nsINode* endNode = mStatus->mRange->GetEndContainer();
int32_t endOffset = mStatus->mRange->EndOffset();
// Now check that we're still looking at a range that's under
// aWordUtil.GetRootNode()
const nsINode* rootNode = mWordUtil.GetRootNode();
if (!beginNode->IsInComposedDoc() || !endNode->IsInComposedDoc() ||
!beginNode->IsShadowIncludingInclusiveDescendantOf(rootNode) ||
!endNode->IsShadowIncludingInclusiveDescendantOf(rootNode)) {
if (!ShouldSpellCheckRange(*mStatus->mRange)) {
// Just bail out and don't try to spell-check this
return NS_OK;
}