Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Unified Diff: Source/core/editing/Editor.cpp

Issue 23332004: Trigger spell check/remove markers if spell checker gets enabled/disabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/editing/Editor.cpp
diff --git a/Source/core/editing/Editor.cpp b/Source/core/editing/Editor.cpp
index ed070d6e1682218938ac64853296544dd149e13a..6d1a8a0d1b04b70bb4b05230e0d3aa1c66f71a0b 100644
--- a/Source/core/editing/Editor.cpp
+++ b/Source/core/editing/Editor.cpp
@@ -1475,24 +1475,44 @@ 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;
+ RefPtr<Range> checkRange = asynchronous ? fullParagraphToCheck.paragraphRange() : rangeToCheck;
+ RefPtr<Range> paragraphRange = fullParagraphToCheck.paragraphRange();
+ for (int iter = 0; iter < kNumChunksToCheck; ++iter) {
+ if (kNumChunksToCheck > 1 || !asynchronous) {
tony 2013/08/19 20:01:15 Having if (kNumChunksToCheck) conditions in the fo
+ checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunkSize);
+ setStart(checkRange.get(), startOfSentence(checkRange->startPosition()));
+ setEnd(checkRange.get(), endOfSentence(checkRange->endPosition()));
+ paragraphRange = checkRange;
+ }
- // In asynchronous mode, we intentionally check paragraph-wide sentence.
- RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessIncremental, asynchronous ? paragraphRange : rangeToCheck, paragraphRange);
+ TextCheckingParagraph sentenceToCheck(checkRange, paragraphRange);
+ if (kNumChunksToCheck > 1)
+ currentChunkStart += sentenceToCheck.checkingLength();
- if (asynchronous) {
- m_spellCheckRequester->requestCheckingFor(request);
- return;
- }
+ RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, paragraphRange, iter);
- Vector<TextCheckingResult> results;
- checkTextOfParagraph(textChecker(), paragraphToCheck.text(), resolveTextCheckingTypeMask(textCheckingOptions), results);
- markAndReplaceFor(request, results);
+ if (asynchronous) {
+ m_spellCheckRequester->requestCheckingFor(request);
+ continue;
+ }
+
+ Vector<TextCheckingResult> results;
+ checkTextOfParagraph(textChecker(), sentenceToCheck.text(), resolveTextCheckingTypeMask(textCheckingOptions), results);
+ markAndReplaceFor(request, results);
+ }
}
void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vector<TextCheckingResult>& results)
@@ -1528,7 +1548,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;
« no previous file with comments | « LayoutTests/editing/spelling/spelling-huge-text-sync-expected.txt ('k') | Source/core/editing/SpellCheckRequester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698