Changeset 102553 in webkit
- Timestamp:
- Dec 11, 2011 7:12:06 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r102552 r102553 1 2011-12-11 Shinya Kawanaka <shinyak@google.com> 2 3 Asynchronous path synchronous path of SpellChecker should share the code to mark misspellings. 4 https://bugs.webkit.org/show_bug.cgi?id=73616 5 6 Reviewed by Hajime Morita. 7 8 Asynchronous spellchecking path should call the same method for the synchronous spellchecking path 9 to mark misspellings. 10 11 No new tests. Covered by existing tests. 12 13 * editing/Editor.cpp: 14 (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): 15 (WebCore::Editor::markAndReplaceFor): 16 Takes SpellCheckRequest object. 17 * editing/Editor.h: 18 * editing/SpellChecker.cpp: 19 (WebCore::SpellChecker::didCheck): 20 Calls the same method of synchronous spellchecking path. 21 1 22 2011-12-11 Luke Macpherson <macpherson@chromium.org> 2 23 -
trunk/Source/WebCore/editing/Editor.cpp
r102527 r102553 2016 2016 if (paragraphToCheck.isRangeEmpty() || paragraphToCheck.isEmpty()) 2017 2017 return; 2018 RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange(); 2018 2019 2019 2020 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->asynchronousSpellCheckingEnabled() && !shouldShowCorrectionPanel; 2021 2022 // In asynchronous mode, we intentionally check paragraph-wide sentence. 2023 RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), asynchronous ? paragraphRange : rangeToCheck, paragraphRange); 2024 2020 2025 if (asynchronous) { 2021 // In asynchronous mode, we intentionally check paragraph-wide sentence. 2022 RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange(); 2023 m_spellChecker->requestCheckingFor(SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), paragraphRange, paragraphRange)); 2026 m_spellChecker->requestCheckingFor(request); 2024 2027 return; 2025 2028 } … … 2028 2031 checkTextOfParagraph(textChecker(), paragraphToCheck.textCharacters(), paragraphToCheck.textLength(), 2029 2032 resolveTextCheckingTypeMask(textCheckingOptions), results); 2030 markAndReplaceFor(textCheckingOptions, results, rangeToCheck, paragraphToCheck.paragraphRange()); 2031 } 2032 2033 void Editor::markAndReplaceFor(TextCheckingTypeMask textCheckingOptions, const Vector<TextCheckingResult>& results, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange) 2034 { 2035 TextCheckingParagraph paragraph(checkingRange, paragraphRange); 2033 markAndReplaceFor(request, results); 2034 } 2035 2036 void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vector<TextCheckingResult>& results) 2037 { 2038 ASSERT(request); 2039 2040 TextCheckingTypeMask textCheckingOptions = request->mask(); 2041 TextCheckingParagraph paragraph(request->checkingRange(), request->paragraphRange()); 2036 2042 2037 2043 bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling; -
trunk/Source/WebCore/editing/Editor.h
r102357 r102553 62 62 class SimpleFontData; 63 63 class SpellChecker; 64 class SpellCheckRequest; 64 65 class SpellingCorrectionController; 65 66 class Text; … … 224 225 void markBadGrammar(const VisibleSelection&); 225 226 void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection); 226 void markAndReplaceFor( TextCheckingTypeMask, const Vector<TextCheckingResult>&, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange);227 void markAndReplaceFor(PassRefPtr<SpellCheckRequest>, const Vector<TextCheckingResult>&); 227 228 228 229 #if USE(AUTOMATIC_TEXT_REPLACEMENT) -
trunk/Source/WebCore/editing/SpellChecker.cpp
r102328 r102553 164 164 } 165 165 166 static bool forwardIterator(PositionIterator& iterator, int distance)167 {168 int remaining = distance;169 while (!iterator.atEnd()) {170 if (iterator.node()->isCharacterDataNode()) {171 int length = lastOffsetForEditing(iterator.node());172 int last = length - iterator.offsetInLeafNode();173 if (remaining < last) {174 iterator.setOffsetInLeafNode(iterator.offsetInLeafNode() + remaining);175 return true;176 }177 178 remaining -= last;179 iterator.setOffsetInLeafNode(iterator.offsetInLeafNode() + last);180 }181 182 iterator.increment();183 }184 185 return false;186 }187 188 static DocumentMarker::MarkerType toMarkerType(TextCheckingType type)189 {190 if (type == TextCheckingTypeSpelling)191 return DocumentMarker::Spelling;192 ASSERT(type == TextCheckingTypeGrammar);193 return DocumentMarker::Grammar;194 }195 196 // Currenntly ignoring TextCheckingResult::details but should be handled. See Bug 56368.197 166 void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& results) 198 167 { … … 204 173 } 205 174 206 int startOffset = 0; 207 PositionIterator start = m_processingRequest->checkingRange()->startPosition(); 208 for (size_t i = 0; i < results.size(); ++i) { 209 if (results[i].type != TextCheckingTypeSpelling && results[i].type != TextCheckingTypeGrammar) 210 continue; 211 212 // To avoid moving the position backward, we assume the given results are sorted with 213 // startOffset as the ones returned by [NSSpellChecker requestCheckingOfString:]. 214 ASSERT(startOffset <= results[i].location); 215 if (!forwardIterator(start, results[i].location - startOffset)) 216 break; 217 PositionIterator end = start; 218 if (!forwardIterator(end, results[i].length)) 219 break; 220 221 // Users or JavaScript applications may change text while a spell-checker checks its 222 // spellings in the background. To avoid adding markers to the words modified by users or 223 // JavaScript applications, retrieve the words in the specified region and compare them with 224 // the original ones. 225 RefPtr<Range> range = Range::create(m_processingRequest->checkingRange()->ownerDocument(), start, end); 226 // FIXME: Use textContent() compatible string conversion. 227 String destination = range->text(); 228 String source = m_processingRequest->text().substring(results[i].location, results[i].length); 229 if (destination == source) 230 m_processingRequest->checkingRange()->ownerDocument()->markers()->addMarker(range.get(), toMarkerType(results[i].type)); 231 232 startOffset = results[i].location; 233 } 175 m_frame->editor()->markAndReplaceFor(m_processingRequest, results); 234 176 235 177 if (m_lastProcessedSequence < sequence)
Note: See TracChangeset
for help on using the changeset viewer.