| Index: Source/core/editing/Editor.cpp
|
| diff --git a/Source/core/editing/Editor.cpp b/Source/core/editing/Editor.cpp
|
| index 5931025ea9a51c20da854ecf48fcb311eb240469..1354d49a2408bb1601f932aaa47c037e42b2e59a 100644
|
| --- a/Source/core/editing/Editor.cpp
|
| +++ b/Source/core/editing/Editor.cpp
|
| @@ -421,7 +421,7 @@ void Editor::replaceSelectionWithFragment(PassRefPtr<DocumentFragment> fragment,
|
| return;
|
|
|
| RefPtr<Range> rangeToCheck = Range::create(m_frame->document(), firstPositionInNode(nodeToCheck), lastPositionInNode(nodeToCheck));
|
| - m_spellChecker->requestCheckingFor(SpellCheckRequest::create(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), TextCheckingProcessBatch, rangeToCheck, rangeToCheck));
|
| + markAllMisspellingsAndBadGrammarInRanges(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), rangeToCheck.get(), rangeToCheck.get());
|
| }
|
|
|
| void Editor::replaceSelectionWithText(const String& text, bool selectReplacement, bool smartReplace)
|
| @@ -1486,9 +1486,12 @@ void Editor::markBadGrammar(const VisibleSelection& selection)
|
| void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, Range* spellingRange, Range* grammarRange)
|
| {
|
| ASSERT(m_frame);
|
| - ASSERT(unifiedTextCheckerEnabled());
|
|
|
| - bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar;
|
| + bool shouldMarkGrammar = (textCheckingOptions & TextCheckingTypeGrammar) && isGrammarCheckingEnabled();
|
| + bool shouldMarkSpellling = (textCheckingOptions & TextCheckingTypeSpelling) && isContinuousSpellCheckingEnabled();
|
| +
|
| + if (!shouldMarkSpellling && !shouldMarkGrammar)
|
| + return;
|
|
|
| // This function is called with selections already expanded to word boundaries.
|
| if (!client() || !spellingRange || (shouldMarkGrammar && !grammarRange))
|
| @@ -1503,24 +1506,38 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textC
|
| return;
|
|
|
| Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange;
|
| - TextCheckingParagraph paragraphToCheck(rangeToCheck);
|
| - if (paragraphToCheck.isRangeEmpty() || paragraphToCheck.isEmpty())
|
| + TextCheckingParagraph fullParagraphToCheck(rangeToCheck);
|
| + if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty())
|
| return;
|
| - RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange();
|
|
|
| + // Since the text may be quite big chunk it up and adjust to the sentence boundary.
|
| + const int kChunkSize = 16 * 1024;
|
| + int start = fullParagraphToCheck.checkingStart();
|
| + int end = fullParagraphToCheck.checkingEnd();
|
| + start = std::min(start, end);
|
| + end = std::max(start, end);
|
| bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->asynchronousSpellCheckingEnabled();
|
| + const int kNumChunksToCheck = asynchronous ? (end - start + kChunkSize - 1) / (kChunkSize) : 1;
|
| + int currentChunkStart = start;
|
| + for (int iter = 0; iter < kNumChunksToCheck; ++iter) {
|
| + RefPtr<Range> checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunkSize);
|
| + setStart(checkRange.get(), startOfSentence(checkRange->startPosition()));
|
| + setEnd(checkRange.get(), endOfSentence(checkRange->endPosition()));
|
| + TextCheckingParagraph sentenceToCheck(checkRange, checkRange);
|
|
|
| - // In asynchronous mode, we intentionally check paragraph-wide sentence.
|
| - RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessIncremental, asynchronous ? paragraphRange : rangeToCheck, paragraphRange);
|
| + currentChunkStart += sentenceToCheck.checkingLength();
|
|
|
| - if (asynchronous) {
|
| - m_spellChecker->requestCheckingFor(request);
|
| - return;
|
| - }
|
| + RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, checkRange, iter);
|
| +
|
| + if (asynchronous) {
|
| + m_spellChecker->requestCheckingFor(request);
|
| + continue;
|
| + }
|
|
|
| - Vector<TextCheckingResult> results;
|
| - checkTextOfParagraph(textChecker(), paragraphToCheck.text(), resolveTextCheckingTypeMask(textCheckingOptions), results);
|
| - markAndReplaceFor(request, results);
|
| + Vector<TextCheckingResult> results;
|
| + checkTextOfParagraph(textChecker(), sentenceToCheck.text(), resolveTextCheckingTypeMask(textCheckingOptions), results);
|
| + markAndReplaceFor(request, results);
|
| + }
|
| }
|
|
|
| void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vector<TextCheckingResult>& results)
|
| @@ -1556,7 +1573,7 @@ void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect
|
| for (unsigned i = 0; i < results.size(); i++) {
|
| int spellingRangeEndOffset = paragraph.checkingEnd();
|
| const TextCheckingResult* result = &results[i];
|
| - int resultLocation = result->location;
|
| + int resultLocation = result->location + paragraph.checkingStart();
|
| int resultLength = result->length;
|
| bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && resultLocation + resultLength == ambiguousBoundaryOffset;
|
|
|
|
|