Changeset 69548 in webkit


Ignore:
Timestamp:
Oct 11, 2010 6:21:14 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-10-11 Jia Pu <jpu@apple.com>

Reviewed by Adele Peterson.

Should commit pending autocorrection before next round of text checking.
https://bugs.webkit.org/show_bug.cgi?id=46986
<rdar://problem/8424535>

  1. Apply pending autocorrection before calling markAllMisspellingsAndBadGrammarInRanges().
  2. Remove unneccessary calls to dismissCorrectionPanel(), since the panel is dismissed when selection changes, which occurs after every typing command.
  • editing/Editor.cpp: (WebCore::Editor::markMisspellingsAfterTypingToPosition): Apply pending autocorrection. (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Store current correction replacement in m_correctionReplacementString. (WebCore::Editor::startCorrectionPanelTimer): Remove call to dismissCorrectionPanel().
  • editing/Editor.h: Add m_correctionReplacementString to store proposed autocorrection string.
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r69546 r69548  
     12010-10-11  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Adele Peterson.
     4
     5        Should commit pending autocorrection before next round of text checking.
     6        https://bugs.webkit.org/show_bug.cgi?id=46986
     7        <rdar://problem/8424535>
     8
     9        1. Apply pending autocorrection before calling markAllMisspellingsAndBadGrammarInRanges().
     10        2. Remove unneccessary calls to dismissCorrectionPanel(), since the panel is dismissed when
     11           selection changes, which occurs after every typing command.
     12
     13        * editing/Editor.cpp:
     14        (WebCore::Editor::markMisspellingsAfterTypingToPosition): Apply pending autocorrection.
     15        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Store current correction replacement
     16          in m_correctionReplacementString.
     17        (WebCore::Editor::startCorrectionPanelTimer): Remove call to dismissCorrectionPanel().
     18        * editing/Editor.h: Add m_correctionReplacementString to store proposed autocorrection string.
     19
    1202010-10-11  Oliver Hunt  <oliver@apple.com>
    221
  • trunk/WebCore/editing/Editor.cpp

    r68902 r69548  
    24052405{
    24062406#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
     2407#if !defined(BUILDING_ON_SNOW_LEOPARD)
     2408    // Apply pending autocorrection before next round of spell checking.
     2409    bool didApplyCorrection = false;
     2410    if (m_rangeToBeReplacedByCorrection) {
     2411        ExceptionCode ec = 0;
     2412        RefPtr<Range> paragraphRangeContainingCorrection = m_rangeToBeReplacedByCorrection->cloneRange(ec);
     2413        if (!ec) {
     2414            setStart(paragraphRangeContainingCorrection.get(), startOfParagraph(m_rangeToBeReplacedByCorrection->startPosition()));
     2415            setEnd(paragraphRangeContainingCorrection.get(), endOfParagraph(m_rangeToBeReplacedByCorrection->endPosition()));
     2416            // After we replace the word at range m_rangeToBeReplacedByCorrection, we need to add
     2417            // autocorrection underline at that range. However, once the replacement took place, the
     2418            // value of m_rangeToBeReplacedByCorrection is not valid anymore. So before we carry out
     2419            // the replacement, we need to store the start position of m_rangeToBeReplacedByCorrection
     2420            // relative to the start position of the containing paragraph. We use correctionStartOffsetInParagraph
     2421            // to store this value. In order to obtain this offset, we need to first create a range
     2422            // which spans from the start of paragraph to the start position of m_rangeToBeReplacedByCorrection.
     2423            RefPtr<Range> correctionStartOffsetInParagraphAsRange = Range::create(paragraphRangeContainingCorrection->startContainer(ec)->document(), paragraphRangeContainingCorrection->startPosition(), paragraphRangeContainingCorrection->startPosition());
     2424            if (!ec) {
     2425                Position startPositionOfRangeToBeReplaced = m_rangeToBeReplacedByCorrection->startPosition();
     2426                correctionStartOffsetInParagraphAsRange->setEnd(startPositionOfRangeToBeReplaced.containerNode(), startPositionOfRangeToBeReplaced.computeOffsetInContainerNode(), ec);
     2427                if (!ec) {
     2428                    // Take note of the location of autocorrection so that we can add marker after the replacement took place.
     2429                    int correctionStartOffsetInParagraph = TextIterator::rangeLength(correctionStartOffsetInParagraphAsRange.get());
     2430                    Position caretPosition = m_frame->selection()->selection().end();
     2431                    RefPtr<Range> rangeToBeReplaced = m_rangeToBeReplacedByCorrection->cloneRange(ec);
     2432                    VisibleSelection selectionToReplace(rangeToBeReplaced.get(), DOWNSTREAM);
     2433                    if (m_frame->selection()->shouldChangeSelection(selectionToReplace)) {
     2434                        m_frame->selection()->setSelection(selectionToReplace);
     2435                        replaceSelectionWithText(m_correctionReplacementString, false, false);
     2436                        caretPosition.moveToOffset(caretPosition.offsetInContainerNode() + m_correctionReplacementString.length() - m_stringToBeReplacedByCorrection.length());
     2437                        RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, m_correctionReplacementString.length());
     2438                        replacementRange->startContainer()->document()->markers()->addMarker(replacementRange.get(), DocumentMarker::Replacement, m_correctionReplacementString);
     2439                        replacementRange->startContainer()->document()->markers()->addMarker(replacementRange.get(), DocumentMarker::CorrectionIndicator);
     2440                        m_frame->selection()->moveTo(caretPosition, false);
     2441                        didApplyCorrection = true;
     2442                    }
     2443                }
     2444            }
     2445        }
     2446        m_rangeToBeReplacedByCorrection.release();
     2447    }
     2448#endif
     2449
    24072450    TextCheckingOptions textCheckingOptions = 0;
    24082451    if (isContinuousSpellCheckingEnabled())
     
    27552798                        m_rangeToBeReplacedByCorrection = rangeToReplace;
    27562799                        m_stringToBeReplacedByCorrection = replacedString;
     2800                        m_correctionReplacementString = result->replacement;
    27572801                        client()->showCorrectionPanel(totalBoundingBox, m_stringToBeReplacedByCorrection, result->replacement, this);
    27582802                        doReplacement = false;
     
    27662810                            selectionOffset += replacementLength - resultLength;
    27672811                        if (result->type == TextCheckingTypeCorrection) {
    2768 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
    2769                             if (client())
    2770                                 client()->dismissCorrectionPanel(true);
    2771 #endif
    27722812                            // Add a marker so that corrections can easily be undone and won't be re-corrected.
    27732813                            RefPtr<Range> replacedRange = TextIterator::subrange(paragraphRange.get(), resultLocation, replacementLength);
     
    28582898#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
    28592899    static const double correctionPanelTimerInterval = 0.3;
    2860     if (client())
    2861         client()->dismissCorrectionPanel(true);
    28622900    if (isAutomaticSpellingCorrectionEnabled())
    28632901        m_correctionPanelTimer.startOneShot(correctionPanelTimerInterval);
  • trunk/WebCore/editing/Editor.h

    r68670 r69548  
    380380    RefPtr<Range> m_rangeToBeReplacedByCorrection;
    381381    String m_stringToBeReplacedByCorrection;
     382    String m_correctionReplacementString;
    382383    Timer<Editor> m_correctionPanelTimer;
    383384    VisibleSelection m_mark;
Note: See TracChangeset for help on using the changeset viewer.