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

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: true=>asynchronous 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
« no previous file with comments | « Source/core/editing/Editor.h ('k') | Source/core/editing/SpellCheckRequester.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/Editor.cpp
diff --git a/Source/core/editing/Editor.cpp b/Source/core/editing/Editor.cpp
index ed070d6e1682218938ac64853296544dd149e13a..95cfb24b40dffaf5ff6ba7186757bd63e5d609f8 100644
--- a/Source/core/editing/Editor.cpp
+++ b/Source/core/editing/Editor.cpp
@@ -1475,24 +1475,53 @@ 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();
+ if (kNumChunksToCheck == 1 && asynchronous) {
+ markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange.get(), paragraphRange.get(), asynchronous, 0);
+ return;
+ }
+
+ for (int iter = 0; iter < kNumChunksToCheck; ++iter) {
+ 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);
+ int checkingLength = 0;
+ markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange.get(), paragraphRange.get(), asynchronous, iter, &checkingLength);
+ currentChunkStart += checkingLength;
+ }
+}
+
+void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, Range* checkRange, Range* paragraphRange, bool asynchronous, int requestNumber, int* checkingLength)
+{
+ TextCheckingParagraph sentenceToCheck(checkRange, paragraphRange);
+ if (checkingLength)
+ *checkingLength = sentenceToCheck.checkingLength();
+
+ RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, paragraphRange, requestNumber);
if (asynchronous) {
m_spellCheckRequester->requestCheckingFor(request);
- return;
+ } else {
+ Vector<TextCheckingResult> results;
+ checkTextOfParagraph(textChecker(), sentenceToCheck.text(), resolveTextCheckingTypeMask(textCheckingOptions), results);
+ markAndReplaceFor(request, results);
}
-
- Vector<TextCheckingResult> results;
- checkTextOfParagraph(textChecker(), paragraphToCheck.text(), resolveTextCheckingTypeMask(textCheckingOptions), results);
- markAndReplaceFor(request, results);
}
void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vector<TextCheckingResult>& results)
@@ -1528,7 +1557,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 | « Source/core/editing/Editor.h ('k') | Source/core/editing/SpellCheckRequester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698