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

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

Issue 21130005: Trigger spell check/remove markers if spell checker gets enabled/disabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: copy&paste bug fixed 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 5931025ea9a51c20da854ecf48fcb311eb240469..f3d291e2e24449d3024efc50ed12b3602521227d 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,40 @@ 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();
- bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->asynchronousSpellCheckingEnabled();
-
- // In asynchronous mode, we intentionally check paragraph-wide sentence.
- RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessIncremental, asynchronous ? paragraphRange : rangeToCheck, paragraphRange);
+ // Since the text may be quite big chunk it up and adjust to the sentence boundary.
+ static const int chunkSize = 8 * 1024;
tony 2013/08/12 19:45:15 Nit: kChunkSize. Also, I'm not sure static buys y
+ int start = fullParagraphToCheck.checkingStart();
+ int end = fullParagraphToCheck.checkingEnd();
+ start = std::min(start, end);
+ end = std::max(start, end);
+ const int loopNum = (end - start + chunkSize - 1) / (chunkSize);
+ int currentChunkStart = start;
+ for (int iter = 0; iter < loopNum; ++iter) {
+ RefPtr<Range> checkRange = fullParagraphToCheck.subrange(currentChunkStart, chunkSize);
+ setStart(checkRange.get(), startOfSentence(checkRange->startPosition()));
+ setEnd(checkRange.get(), endOfSentence(checkRange->endPosition()));
+ TextCheckingParagraph sentenceToCheck(checkRange, checkRange);
+
+ currentChunkStart += sentenceToCheck.checkingLength();
+
+ bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->asynchronousSpellCheckingEnabled();
+
+ RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, checkRange, 0/*iter*/);
tony 2013/08/12 19:45:15 I don't think you need to pass in the last paramet
+
+ if (asynchronous) {
+ m_spellChecker->requestCheckingFor(request);
+ continue;
+ }
- if (asynchronous) {
- m_spellChecker->requestCheckingFor(request);
+ Vector<TextCheckingResult> results;
+ checkTextOfParagraph(textChecker(), sentenceToCheck.text(), resolveTextCheckingTypeMask(textCheckingOptions), results);
+ markAndReplaceFor(request, results);
return;
}
-
- Vector<TextCheckingResult> results;
- checkTextOfParagraph(textChecker(), paragraphToCheck.text(), resolveTextCheckingTypeMask(textCheckingOptions), results);
- markAndReplaceFor(request, results);
}
void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vector<TextCheckingResult>& results)
@@ -1556,7 +1575,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;

Powered by Google App Engine
This is Rietveld 408576698