Changeset 102553 in webkit


Ignore:
Timestamp:
Dec 11, 2011 7:12:06 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Asynchronous path synchronous path of SpellChecker should share the code to mark misspellings.
https://bugs.webkit.org/show_bug.cgi?id=73616

Patch by Shinya Kawanaka <shinyak@google.com> on 2011-12-11
Reviewed by Hajime Morita.

Asynchronous spellchecking path should call the same method for the synchronous spellchecking path
to mark misspellings.

No new tests. Covered by existing tests.

  • editing/Editor.cpp:

(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
(WebCore::Editor::markAndReplaceFor):

Takes SpellCheckRequest object.

  • editing/Editor.h:
  • editing/SpellChecker.cpp:

(WebCore::SpellChecker::didCheck):

Calls the same method of synchronous spellchecking path.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r102552 r102553  
     12011-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
    1222011-12-11  Luke Macpherson   <macpherson@chromium.org>
    223
  • trunk/Source/WebCore/editing/Editor.cpp

    r102527 r102553  
    20162016    if (paragraphToCheck.isRangeEmpty() || paragraphToCheck.isEmpty())
    20172017        return;
     2018    RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange();
    20182019
    20192020    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
    20202025    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);
    20242027        return;
    20252028    }
     
    20282031    checkTextOfParagraph(textChecker(), paragraphToCheck.textCharacters(), paragraphToCheck.textLength(),
    20292032        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
     2036void 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());
    20362042
    20372043    bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling;
  • trunk/Source/WebCore/editing/Editor.h

    r102357 r102553  
    6262class SimpleFontData;
    6363class SpellChecker;
     64class SpellCheckRequest;
    6465class SpellingCorrectionController;
    6566class Text;
     
    224225    void markBadGrammar(const VisibleSelection&);
    225226    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>&);
    227228
    228229#if USE(AUTOMATIC_TEXT_REPLACEMENT)
  • trunk/Source/WebCore/editing/SpellChecker.cpp

    r102328 r102553  
    164164}
    165165
    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.
    197166void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& results)
    198167{
     
    204173    }
    205174
    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);
    234176
    235177    if (m_lastProcessedSequence < sequence)
Note: See TracChangeset for help on using the changeset viewer.