Changeset 73287 in webkit


Ignore:
Timestamp:
Dec 3, 2010 12:45:34 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2010-12-03 Jia Pu <jpu@apple.com>

Reviewed by Darin Adler.

Need to move all code that applies correction into correction panel callback.
https://bugs.webkit.org/show_bug.cgi?id=50426
<rdar://problem/8720832>

Added expected png file.

  • platform/mac/editing/spelling/delete-autocorrected-word-1-expected.checksum: Added.
  • platform/mac/editing/spelling/delete-autocorrected-word-1-expected.png: Added.

2010-12-03 Jia Pu <jpu@apple.com>

Reviewed by Darin Adler.

Need to move all code that applies correction into correction panel callback.
https://bugs.webkit.org/show_bug.cgi?id=50426
<rdar://problem/8720832>

No new test, since there's no behavioral change.

This patch is to prepare WebKit to work with upcoming AppKit changes. The main changes are:

  1. Moved all calls to applyCorrectionPanelInfo() into handleCorrectionPanelResult().
  2. Added more user dictionary learning code.
  3. Removed m_ prefix in all member variables of CorrectionPanelInfo.
  • editing/CorrectionPanelInfo.h: Remove m_ prefix on member variables. Added ReasonForDismissingCorrectionPanel enum type.
  • editing/Editor.cpp: Moved all calls to applyCorrectionPanelInfo() into handleCorrectionPanelResult(). Adopted new member variable naming in class CorrectionPanelInfo. (WebCore::Editor::respondToChangedSelection): (WebCore::Editor::~Editor): (WebCore::Editor::markMisspellingsAfterTypingToWord): (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): (WebCore::Editor::correctionPanelTimerFired): (WebCore::Editor::handleCorrectionPanelResult): (WebCore::Editor::startCorrectionPanelTimer): (WebCore::Editor::stopCorrectionPanelTimer): (WebCore::Editor::handleCancelOperation): (WebCore::Editor::dismissCorrectionPanel): (WebCore::Editor::applyCorrectionPanelInfo):
  • editing/Editor.h: Changed signature of dismissCorrectionPanel to use ReasonForDismissingCorrectionPanel.
  • loader/EmptyClients.h: Ditto. (WebCore::EmptyEditorClient::dismissCorrectionPanel):
  • page/EditorClient.h: Ditto.

2010-12-03 Jia Pu <jpu@apple.com>

Reviewed by Darin Adler.

Need to move all code that applies correction into correction panel callback.
https://bugs.webkit.org/show_bug.cgi?id=50426
<rdar://problem/8720832>

  • WebCoreSupport/WebEditorClient.h: Adopted new signature of dismissCorrectionPanel.
  • WebCoreSupport/WebEditorClient.mm: (WebEditorClient::~WebEditorClient): Adopted new signature of dismissCorrectionPanel. (WebEditorClient::showCorrectionPanel): Added more user dictionary learning code. (WebEditorClient::dismissCorrectionPanel): Adopted new signature of dismissCorrectionPanel.

2010-12-03 Jia Pu <jpu@apple.com>

Reviewed by Darin Adler.

Need to move all code that applies correction into correction panel callback.
https://bugs.webkit.org/show_bug.cgi?id=50426
<rdar://problem/8720832>

Adopted new signature of dismissCorrectionPanel.

  • WebProcess/WebCoreSupport/WebEditorClient.h:
  • WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm: (WebKit::WebEditorClient::dismissCorrectionPanel):
Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r73280 r73287  
     12010-12-03  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Need to move all code that applies correction into correction panel callback.
     6        https://bugs.webkit.org/show_bug.cgi?id=50426
     7        <rdar://problem/8720832>
     8
     9        Added expected png file.
     10
     11        * platform/mac/editing/spelling/delete-autocorrected-word-1-expected.checksum: Added.
     12        * platform/mac/editing/spelling/delete-autocorrected-word-1-expected.png: Added.
     13
    1142010-12-03  Sam Weinig  <sam@webkit.org>
    215
  • trunk/WebCore/ChangeLog

    r73285 r73287  
     12010-12-03  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Need to move all code that applies correction into correction panel callback.
     6        https://bugs.webkit.org/show_bug.cgi?id=50426
     7        <rdar://problem/8720832>
     8
     9        No new test, since there's no behavioral change.
     10
     11        This patch is to prepare WebKit to work with upcoming AppKit changes. The main changes are:
     12        1. Moved all calls to applyCorrectionPanelInfo() into handleCorrectionPanelResult().
     13        2. Added more user dictionary learning code.
     14        3. Removed m_ prefix in all member variables of CorrectionPanelInfo.
     15
     16        * editing/CorrectionPanelInfo.h: Remove m_ prefix on member variables. Added ReasonForDismissingCorrectionPanel enum type.
     17
     18        * editing/Editor.cpp: Moved all calls to applyCorrectionPanelInfo() into handleCorrectionPanelResult().
     19          Adopted new member variable naming in class CorrectionPanelInfo.
     20        (WebCore::Editor::respondToChangedSelection):
     21        (WebCore::Editor::~Editor):
     22        (WebCore::Editor::markMisspellingsAfterTypingToWord):
     23        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
     24        (WebCore::Editor::correctionPanelTimerFired):
     25        (WebCore::Editor::handleCorrectionPanelResult):
     26        (WebCore::Editor::startCorrectionPanelTimer):
     27        (WebCore::Editor::stopCorrectionPanelTimer):
     28        (WebCore::Editor::handleCancelOperation):
     29        (WebCore::Editor::dismissCorrectionPanel):
     30        (WebCore::Editor::applyCorrectionPanelInfo):
     31
     32        * editing/Editor.h: Changed signature of dismissCorrectionPanel to use ReasonForDismissingCorrectionPanel.
     33
     34        * loader/EmptyClients.h: Ditto.
     35        (WebCore::EmptyEditorClient::dismissCorrectionPanel):
     36
     37        * page/EditorClient.h: Ditto.
     38
    1392010-12-03  Pavel Feldman  <pfeldman@chromium.org>
    240
  • trunk/WebCore/editing/CorrectionPanelInfo.h

    r73088 r73287  
    4949    };
    5050
    51     RefPtr<Range> m_rangeToBeReplaced;
    52     String m_replacedString;
    53     String m_replacementString;
    54     PanelType m_panelType;
    55     bool m_isActive;
     51    RefPtr<Range> rangeToBeReplaced;
     52    String replacedString;
     53    String replacementString;
     54    PanelType panelType;
     55    bool isActive;
    5656};
    5757
    58 enum CorrectionWasRejectedOrNot { CorrectionWasNotRejected, CorrectionWasRejected };
    59 
     58enum ReasonForDismissingCorrectionPanel {
     59    ReasonForDismissingCorrectionPanelCancelled = 0,
     60    ReasonForDismissingCorrectionPanelIgnored,
     61    ReasonForDismissingCorrectionPanelAccepted
     62};
    6063} // namespace WebCore
    6164
  • trunk/WebCore/editing/Editor.cpp

    r73088 r73287  
    9494
    9595#if SUPPORT_AUTOCORRECTION_PANEL
    96 static const Vector<DocumentMarker::MarkerType>& markerTypesForAutocorrection()
    97 {
    98     DEFINE_STATIC_LOCAL(Vector<DocumentMarker::MarkerType>, markerTypesForAutoCorrection, ());
    99     if (markerTypesForAutoCorrection.isEmpty()) {
    100         markerTypesForAutoCorrection.append(DocumentMarker::Replacement);
    101         markerTypesForAutoCorrection.append(DocumentMarker::CorrectionIndicator);
    102     }
    103     return markerTypesForAutoCorrection;
    104 }
    105 
    10696static FloatRect boundingBoxForRange(Range* range)
    10797{
     
    115105}
    116106#endif // SUPPORT_AUTOCORRECTION_PANEL
     107
     108static const Vector<DocumentMarker::MarkerType>& markerTypesForAutocorrection()
     109{
     110    DEFINE_STATIC_LOCAL(Vector<DocumentMarker::MarkerType>, markerTypesForAutoCorrection, ());
     111    if (markerTypesForAutoCorrection.isEmpty()) {
     112        markerTypesForAutoCorrection.append(DocumentMarker::Replacement);
     113        markerTypesForAutoCorrection.append(DocumentMarker::CorrectionIndicator);
     114    }
     115    return markerTypesForAutoCorrection;
     116}
    117117
    118118static const Vector<DocumentMarker::MarkerType>& markerTypesForReplacement()
     
    501501    if (currentSelection != oldSelection) {
    502502        stopCorrectionPanelTimer();
    503         dismissCorrectionPanel(CorrectionWasNotRejected);
     503        dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored);
    504504    }
    505505#endif // SUPPORT_AUTOCORRECTION_PANEL
     
    536536            String currentWord = plainText(wordRange.get());
    537537            if (currentWord.length()) {
    538                 m_correctionPanelInfo.m_rangeToBeReplaced = wordRange;
    539                 m_correctionPanelInfo.m_replacedString = currentWord;
     538                m_correctionPanelInfo.rangeToBeReplaced = wordRange;
     539                m_correctionPanelInfo.replacedString = currentWord;
    540540                if (marker.type == DocumentMarker::Spelling)
    541541                    startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeSpellingSuggestions);
    542542                else {
    543                     m_correctionPanelInfo.m_replacementString = marker.description;
     543                    m_correctionPanelInfo.replacementString = marker.description;
    544544                    startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeReversion);
    545545                }
     
    11481148{
    11491149#if SUPPORT_AUTOCORRECTION_PANEL
    1150     dismissCorrectionPanel(CorrectionWasNotRejected);
     1150    dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored);
    11511151#endif
    11521152}
     
    20562056    }
    20572057    if (doApplyCorrection)
    2058         applyCorrectionPanelInfo(markerTypesForAutocorrection());
    2059     m_correctionPanelInfo.m_rangeToBeReplaced.clear();
     2058        dismissCorrectionPanel(ReasonForDismissingCorrectionPanelAccepted);
     2059    else
     2060        m_correctionPanelInfo.rangeToBeReplaced.clear();
    20602061#else
    20612062    UNUSED_PARAM(selectionAfterTyping);
     
    23742375                        for (Vector<FloatQuad>::const_iterator it = textQuads.begin(); it < end; ++it)
    23752376                            totalBoundingBox.unite(it->boundingBox());
    2376                         m_correctionPanelInfo.m_rangeToBeReplaced = rangeToReplace;
    2377                         m_correctionPanelInfo.m_replacedString = replacedString;
    2378                         m_correctionPanelInfo.m_replacementString = result->replacement;
    2379                         m_correctionPanelInfo.m_isActive = true;
    2380                         client()->showCorrectionPanel(m_correctionPanelInfo.m_panelType, totalBoundingBox, m_correctionPanelInfo.m_replacedString, result->replacement, Vector<String>(), this);
     2377                        m_correctionPanelInfo.rangeToBeReplaced = rangeToReplace;
     2378                        m_correctionPanelInfo.replacedString = replacedString;
     2379                        m_correctionPanelInfo.replacementString = result->replacement;
     2380                        m_correctionPanelInfo.isActive = true;
     2381                        client()->showCorrectionPanel(m_correctionPanelInfo.panelType, totalBoundingBox, m_correctionPanelInfo.replacedString, result->replacement, Vector<String>(), this);
    23812382                        doReplacement = false;
    23822383                    }
     
    24562457{
    24572458#if SUPPORT_AUTOCORRECTION_PANEL
    2458     switch (m_correctionPanelInfo.m_panelType) {
     2459    m_correctionPanelIsDismissedByEditor = false;
     2460    switch (m_correctionPanelInfo.panelType) {
    24592461    case CorrectionPanelInfo::PanelTypeCorrection: {
    24602462        VisibleSelection selection(frame()->selection()->selection());
     
    24662468        break;
    24672469    case CorrectionPanelInfo::PanelTypeReversion: {
    2468         m_correctionPanelInfo.m_isActive = true;
    2469         m_correctionPanelInfo.m_replacedString = plainText(m_correctionPanelInfo.m_rangeToBeReplaced.get());
    2470         client()->showCorrectionPanel(m_correctionPanelInfo.m_panelType, boundingBoxForRange(m_correctionPanelInfo.m_rangeToBeReplaced.get()), m_correctionPanelInfo.m_replacedString, m_correctionPanelInfo.m_replacementString, Vector<String>(), this);
     2470        m_correctionPanelInfo.isActive = true;
     2471        m_correctionPanelInfo.replacedString = plainText(m_correctionPanelInfo.rangeToBeReplaced.get());
     2472        client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBoxForRange(m_correctionPanelInfo.rangeToBeReplaced.get()), m_correctionPanelInfo.replacedString, m_correctionPanelInfo.replacementString, Vector<String>(), this);
    24712473    }
    24722474        break;
    24732475    case CorrectionPanelInfo::PanelTypeSpellingSuggestions: {
    2474         if (plainText(m_correctionPanelInfo.m_rangeToBeReplaced.get()) != m_correctionPanelInfo.m_replacedString)
     2476        if (plainText(m_correctionPanelInfo.rangeToBeReplaced.get()) != m_correctionPanelInfo.replacedString)
    24752477            break;
    2476         String paragraphText = plainText(TextCheckingParagraph(m_correctionPanelInfo.m_rangeToBeReplaced).paragraphRange().get());
     2478        String paragraphText = plainText(TextCheckingParagraph(m_correctionPanelInfo.rangeToBeReplaced).paragraphRange().get());
    24772479        Vector<String> suggestions;
    2478         client()->getGuessesForWord(m_correctionPanelInfo.m_replacedString, paragraphText, suggestions);
     2480        client()->getGuessesForWord(m_correctionPanelInfo.replacedString, paragraphText, suggestions);
    24792481        if (suggestions.isEmpty())
    24802482            break;
    24812483        String topSuggestion = suggestions.first();
    24822484        suggestions.remove(0);
    2483         m_correctionPanelInfo.m_isActive = true;
    2484         client()->showCorrectionPanel(m_correctionPanelInfo.m_panelType, boundingBoxForRange(m_correctionPanelInfo.m_rangeToBeReplaced.get()), m_correctionPanelInfo.m_replacedString, topSuggestion, suggestions, this);
     2485        m_correctionPanelInfo.isActive = true;
     2486        client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBoxForRange(m_correctionPanelInfo.rangeToBeReplaced.get()), m_correctionPanelInfo.replacedString, topSuggestion, suggestions, this);
    24852487    }
    24862488        break;
     
    24912493void Editor::handleCorrectionPanelResult(const String& correction)
    24922494{
    2493     Range* replacedRange = m_correctionPanelInfo.m_rangeToBeReplaced.get();
     2495    Range* replacedRange = m_correctionPanelInfo.rangeToBeReplaced.get();
    24942496    if (!replacedRange || m_frame->document() != replacedRange->ownerDocument())
    24952497        return;
    24962498
    2497     String currentWord = plainText(m_correctionPanelInfo.m_rangeToBeReplaced.get());
     2499    String currentWord = plainText(m_correctionPanelInfo.rangeToBeReplaced.get());
    24982500    // Check to see if the word we are about to correct has been changed between timer firing and callback being triggered.
    2499     if (currentWord != m_correctionPanelInfo.m_replacedString)
    2500         return;
    2501 
    2502     m_correctionPanelInfo.m_isActive = false;
    2503 
    2504     switch (m_correctionPanelInfo.m_panelType) {
     2501    if (currentWord != m_correctionPanelInfo.replacedString)
     2502        return;
     2503
     2504    m_correctionPanelInfo.isActive = false;
     2505
     2506    switch (m_correctionPanelInfo.panelType) {
    25052507    case CorrectionPanelInfo::PanelTypeCorrection:
    2506         replacedRange->startContainer()->document()->markers()->addMarker(replacedRange, DocumentMarker::RejectedCorrection, m_correctionPanelInfo.m_replacedString);
     2508        if (correction.length()) {
     2509            m_correctionPanelInfo.replacementString = correction;
     2510            applyCorrectionPanelInfo(markerTypesForAutocorrection());
     2511        } else {
     2512            if (!m_correctionPanelIsDismissedByEditor)
     2513                replacedRange->startContainer()->document()->markers()->addMarker(replacedRange, DocumentMarker::RejectedCorrection, m_correctionPanelInfo.replacedString);
     2514        }
    25072515        break;
    25082516    case CorrectionPanelInfo::PanelTypeReversion:
    2509         applyCorrectionPanelInfo(markerTypesForReplacement());
    25102517    case CorrectionPanelInfo::PanelTypeSpellingSuggestions:
    25112518        if (correction.length()) {
    2512             m_correctionPanelInfo.m_replacementString = correction;
     2519            m_correctionPanelInfo.replacementString = correction;
    25132520            applyCorrectionPanelInfo(markerTypesForReplacement());
    25142521        }
     
    25162523    }
    25172524
    2518     m_correctionPanelInfo.m_rangeToBeReplaced.clear();
     2525    m_correctionPanelInfo.rangeToBeReplaced.clear();
    25192526}
    25202527
     
    25262533        if (type == CorrectionPanelInfo::PanelTypeCorrection)
    25272534            // If type is PanelTypeReversion, then the new range has been set. So we shouldn't clear it.
    2528             m_correctionPanelInfo.m_rangeToBeReplaced.clear();
    2529         m_correctionPanelInfo.m_panelType = type;
     2535            m_correctionPanelInfo.rangeToBeReplaced.clear();
     2536        m_correctionPanelInfo.panelType = type;
    25302537        m_correctionPanelTimer.startOneShot(correctionPanelTimerInterval);
    25312538    }
     
    25392546#if SUPPORT_AUTOCORRECTION_PANEL
    25402547    m_correctionPanelTimer.stop();
    2541     m_correctionPanelInfo.m_rangeToBeReplaced.clear();
     2548    m_correctionPanelInfo.rangeToBeReplaced.clear();
    25422549#endif
    25432550}
     
    25462553{
    25472554#if SUPPORT_AUTOCORRECTION_PANEL
    2548     if (!m_correctionPanelInfo.m_isActive)
    2549         return;
    2550     m_correctionPanelInfo.m_isActive = false;
     2555    if (!m_correctionPanelInfo.isActive)
     2556        return;
     2557    m_correctionPanelInfo.isActive = false;
    25512558    if (client())
    2552         client()->dismissCorrectionPanel(CorrectionWasRejected);
     2559        client()->dismissCorrectionPanel(ReasonForDismissingCorrectionPanelCancelled);
    25532560#endif
    25542561}
     
    25632570}
    25642571
    2565 void Editor::dismissCorrectionPanel(CorrectionWasRejectedOrNot correctionWasRejectedOrNot)
     2572void Editor::dismissCorrectionPanel(ReasonForDismissingCorrectionPanel reasonForDismissing)
    25662573{
    25672574#if SUPPORT_AUTOCORRECTION_PANEL
    2568     if (!m_correctionPanelInfo.m_isActive)
    2569         return;
    2570     m_correctionPanelInfo.m_isActive = false;
     2575    if (!m_correctionPanelInfo.isActive)
     2576        return;
     2577    m_correctionPanelInfo.isActive = false;
     2578    m_correctionPanelIsDismissedByEditor = true;
    25712579    if (client())
    2572         client()->dismissCorrectionPanel(correctionWasRejectedOrNot);
     2580        client()->dismissCorrectionPanel(reasonForDismissing);
    25732581#else
    2574     UNUSED_PARAM(correctionWasRejectedOrNot);
     2582    UNUSED_PARAM(reasonForDismissing);
    25752583#endif
    25762584}
     
    26742682void Editor::applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>& markerTypesToAdd)
    26752683{
    2676     if (!m_correctionPanelInfo.m_rangeToBeReplaced)
     2684    if (!m_correctionPanelInfo.rangeToBeReplaced)
    26772685        return;
    26782686
    26792687    ExceptionCode ec = 0;
    2680     RefPtr<Range> paragraphRangeContainingCorrection = m_correctionPanelInfo.m_rangeToBeReplaced->cloneRange(ec);
     2688    RefPtr<Range> paragraphRangeContainingCorrection = m_correctionPanelInfo.rangeToBeReplaced->cloneRange(ec);
    26812689    if (ec)
    26822690        return;
    26832691
    2684     setStart(paragraphRangeContainingCorrection.get(), startOfParagraph(m_correctionPanelInfo.m_rangeToBeReplaced->startPosition()));
    2685     setEnd(paragraphRangeContainingCorrection.get(), endOfParagraph(m_correctionPanelInfo.m_rangeToBeReplaced->endPosition()));
    2686 
    2687     // After we replace the word at range m_rangeToBeReplaced, we need to add markers to that range.
    2688     // However, once the replacement took place, the value of m_rangeToBeReplaced is not valid anymore.
    2689     // So before we carry out the replacement, we need to store the start position of m_rangeToBeReplaced
     2692    setStart(paragraphRangeContainingCorrection.get(), startOfParagraph(m_correctionPanelInfo.rangeToBeReplaced->startPosition()));
     2693    setEnd(paragraphRangeContainingCorrection.get(), endOfParagraph(m_correctionPanelInfo.rangeToBeReplaced->endPosition()));
     2694
     2695    // After we replace the word at range rangeToBeReplaced, we need to add markers to that range.
     2696    // However, once the replacement took place, the value of rangeToBeReplaced is not valid anymore.
     2697    // So before we carry out the replacement, we need to store the start position of rangeToBeReplaced
    26902698    // relative to the start position of the containing paragraph. We use correctionStartOffsetInParagraph
    26912699    // to store this value. In order to obtain this offset, we need to first create a range
    2692     // which spans from the start of paragraph to the start position of m_rangeToBeReplaced.
     2700    // which spans from the start of paragraph to the start position of rangeToBeReplaced.
    26932701    RefPtr<Range> correctionStartOffsetInParagraphAsRange = Range::create(paragraphRangeContainingCorrection->startContainer(ec)->document(), paragraphRangeContainingCorrection->startPosition(), paragraphRangeContainingCorrection->startPosition());
    26942702    if (ec)
    26952703        return;
    26962704
    2697     Position startPositionOfRangeToBeReplaced = m_correctionPanelInfo.m_rangeToBeReplaced->startPosition();
     2705    Position startPositionOfRangeToBeReplaced = m_correctionPanelInfo.rangeToBeReplaced->startPosition();
    26982706    correctionStartOffsetInParagraphAsRange->setEnd(startPositionOfRangeToBeReplaced.containerNode(), startPositionOfRangeToBeReplaced.computeOffsetInContainerNode(), ec);
    26992707    if (ec)
     
    27052713
    27062714    // Clone the range, since the caller of this method may want to keep the original range around.
    2707     RefPtr<Range> rangeToBeReplaced = m_correctionPanelInfo.m_rangeToBeReplaced->cloneRange(ec);
     2715    RefPtr<Range> rangeToBeReplaced = m_correctionPanelInfo.rangeToBeReplaced->cloneRange(ec);
    27082716    VisibleSelection selectionToReplace(rangeToBeReplaced.get(), DOWNSTREAM);
    27092717    if (m_frame->selection()->shouldChangeSelection(selectionToReplace)) {
    27102718        m_frame->selection()->setSelection(selectionToReplace);
    2711         replaceSelectionWithText(m_correctionPanelInfo.m_replacementString, false, false);
    2712         caretPosition.moveToOffset(caretPosition.offsetInContainerNode() + m_correctionPanelInfo.m_replacementString.length() - m_correctionPanelInfo.m_replacedString.length());
     2719        replaceSelectionWithText(m_correctionPanelInfo.replacementString, false, false);
     2720        caretPosition.moveToOffset(caretPosition.offsetInContainerNode() + m_correctionPanelInfo.replacementString.length() - m_correctionPanelInfo.replacedString.length());
    27132721        setEnd(paragraphRangeContainingCorrection.get(), endOfParagraph(caretPosition));
    2714         RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, m_correctionPanelInfo.m_replacementString.length());
     2722        RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, m_correctionPanelInfo.replacementString.length());
    27152723        DocumentMarkerController* markers = replacementRange->startContainer()->document()->markers();
    27162724        size_t size = markerTypesToAdd.size();
    27172725        for (size_t i = 0; i < size; ++i)
    2718             markers->addMarker(replacementRange.get(), markerTypesToAdd[i], m_correctionPanelInfo.m_replacementString);
     2726            markers->addMarker(replacementRange.get(), markerTypesToAdd[i], m_correctionPanelInfo.replacementString);
    27192727        m_frame->selection()->moveTo(caretPosition, false);
    27202728    }
  • trunk/WebCore/editing/Editor.h

    r73088 r73287  
    384384    CorrectionPanelInfo m_correctionPanelInfo;
    385385    Timer<Editor> m_correctionPanelTimer;
     386    bool m_correctionPanelIsDismissedByEditor;
    386387    VisibleSelection m_mark;
    387388    bool m_areMarkedTextMatchesHighlighted;
     
    410411    Node* findEventTargetFromSelection() const;
    411412    void stopCorrectionPanelTimer();
    412     void dismissCorrectionPanel(CorrectionWasRejectedOrNot);
     413    void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel);
    413414    void applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>& markerTypesToAdd);
    414415};
  • trunk/WebCore/loader/EmptyClients.h

    r73088 r73287  
    482482#if SUPPORT_AUTOCORRECTION_PANEL
    483483    virtual void showCorrectionPanel(CorrectionPanelInfo::PanelType, const FloatRect&, const String&, const String&, const Vector<String>&, Editor*) { }
    484     virtual void dismissCorrectionPanel(CorrectionWasRejectedOrNot) { }
     484    virtual void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel) { }
    485485    virtual bool isShowingCorrectionPanel() { return false; }
    486486#endif
  • trunk/WebCore/page/EditorClient.h

    r73088 r73287  
    192192#if SUPPORT_AUTOCORRECTION_PANEL
    193193    virtual void showCorrectionPanel(CorrectionPanelInfo::PanelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacmentString, const Vector<String>& alternativeReplacementStrings, Editor*) = 0;
    194     virtual void dismissCorrectionPanel(CorrectionWasRejectedOrNot) = 0;
     194    virtual void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel) = 0;
    195195    virtual bool isShowingCorrectionPanel() = 0;
    196196#endif
  • trunk/WebKit/mac/ChangeLog

    r73237 r73287  
     12010-12-03  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Need to move all code that applies correction into correction panel callback.
     6        https://bugs.webkit.org/show_bug.cgi?id=50426
     7        <rdar://problem/8720832>
     8
     9        * WebCoreSupport/WebEditorClient.h: Adopted new signature of dismissCorrectionPanel.
     10
     11        * WebCoreSupport/WebEditorClient.mm:
     12        (WebEditorClient::~WebEditorClient): Adopted new signature of dismissCorrectionPanel.
     13        (WebEditorClient::showCorrectionPanel): Added more user dictionary learning code.
     14        (WebEditorClient::dismissCorrectionPanel): Adopted new signature of dismissCorrectionPanel.
     15
    1162010-12-02  Simon Fraser  <simon.fraser@apple.com>
    217
  • trunk/WebKit/mac/WebCoreSupport/WebEditorClient.h

    r73088 r73287  
    135135#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
    136136    virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const WTF::String& replacedString, const WTF::String& replacementString, const WTF::Vector<WTF::String>& alternativeReplacementStrings, WebCore::Editor*);
    137     virtual void dismissCorrectionPanel(WebCore::CorrectionWasRejectedOrNot);
     137    virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel);
    138138    virtual bool isShowingCorrectionPanel();
    139139#endif
     
    148148#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
    149149    BOOL m_correctionPanelIsShown;
     150    BOOL m_correctionPanelIsDismissedExternally;
     151    WebCore::ReasonForDismissingCorrectionPanel m_reasonForDismissingCorrectionPanel;
    150152#endif
    151153};
  • trunk/WebKit/mac/WebCoreSupport/WebEditorClient.mm

    r73088 r73287  
    211211{
    212212#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
    213     dismissCorrectionPanel(WebCore::CorrectionWasNotRejected);
     213    dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored);
    214214#endif
    215215}
     
    874874#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
    875875void WebEditorClient::showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType panelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings, Editor* editor) {
    876     dismissCorrectionPanel(WebCore::CorrectionWasNotRejected);
     876    dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored);
    877877
    878878    NSRect boundingBoxAsNSRect = boundingBoxOfReplacedString;
     
    885885
    886886    m_correctionPanelIsShown = YES;
     887    m_correctionPanelIsDismissedExternally = NO;
     888    m_reasonForDismissingCorrectionPanel = ReasonForDismissingCorrectionPanelIgnored;
     889
    887890    NSCorrectionBubbleType bubbleType = correctionBubbleType(panelType);
    888891    NSMutableArray *alternativeStrings = nil;
     
    893896            [alternativeStrings addObject:(NSString*)alternativeReplacementStrings[i]];
    894897    }
    895 
     898    NSSpellChecker *spellChecker = [NSSpellChecker sharedSpellChecker];
    896899    [[NSSpellChecker sharedSpellChecker] showCorrectionBubbleOfType:bubbleType primaryString:replacementStringAsNSString alternativeStrings:alternativeStrings forStringInRect:boundingBoxAsNSRect view:m_webView completionHandler:^(NSString *acceptedString) {
    897900        switch (bubbleType) {
    898901        case NSCorrectionBubbleTypeCorrection:
    899             if (!acceptedString) {
    900                 [[NSSpellChecker sharedSpellChecker] recordResponse:NSCorrectionResponseRejected toCorrection:replacementStringAsNSString forWord:replacedStringAsNSString language:nil inSpellDocumentWithTag:[m_webView spellCheckerDocumentTag]];
    901                 editor->handleCorrectionPanelResult(String());
     902            if (acceptedString)
     903                [spellChecker recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedString forWord:replacedStringAsNSString language:nil inSpellDocumentWithTag:spellCheckerDocumentTag()];
     904            else {
     905                if (!m_correctionPanelIsDismissedExternally || m_reasonForDismissingCorrectionPanel == ReasonForDismissingCorrectionPanelCancelled)
     906                    [spellChecker recordResponse:NSCorrectionResponseRejected toCorrection:replacementStringAsNSString forWord:replacedStringAsNSString language:nil inSpellDocumentWithTag:spellCheckerDocumentTag()];
     907                else
     908                    [spellChecker recordResponse:NSCorrectionResponseIgnored toCorrection:replacementStringAsNSString forWord:replacedStringAsNSString language:nil inSpellDocumentWithTag:spellCheckerDocumentTag()];
    902909            }
    903910            break;
    904911        case NSCorrectionBubbleTypeReversion:
    905             if (acceptedString) {
    906                 [[NSSpellChecker sharedSpellChecker] recordResponse:NSCorrectionResponseReverted toCorrection:replacedStringAsNSString forWord:replacementStringAsNSString language:nil inSpellDocumentWithTag:[m_webView spellCheckerDocumentTag]];
    907                 editor->handleCorrectionPanelResult(String());
    908             }
     912            if (acceptedString)
     913                [spellChecker recordResponse:NSCorrectionResponseReverted toCorrection:replacedStringAsNSString forWord:acceptedString language:nil inSpellDocumentWithTag:spellCheckerDocumentTag()];
    909914            break;
    910915        case NSCorrectionBubbleTypeGuesses:
    911916            if (acceptedString)
    912917                [[NSSpellChecker sharedSpellChecker] recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedString forWord:replacedStringAsNSString language:nil inSpellDocumentWithTag:[m_webView spellCheckerDocumentTag]];
    913             editor->handleCorrectionPanelResult(String(acceptedString));
    914918            break;
    915919        }
     920        editor->handleCorrectionPanelResult(String(acceptedString));
    916921    }];
    917922}
    918923
    919 void WebEditorClient::dismissCorrectionPanel(WebCore::CorrectionWasRejectedOrNot correctionWasRejectedOrNot)
     924void WebEditorClient::dismissCorrectionPanel(ReasonForDismissingCorrectionPanel reasonForDismissing)
    920925{
    921926    if (isShowingCorrectionPanel()) {
    922         if (correctionWasRejectedOrNot == CorrectionWasRejected)
     927        m_correctionPanelIsDismissedExternally = YES;
     928        m_reasonForDismissingCorrectionPanel = reasonForDismissing;
     929        if (reasonForDismissing == ReasonForDismissingCorrectionPanelAccepted)
     930            [[NSSpellChecker sharedSpellChecker] dismissCorrectionBubbleForView:m_webView];
     931        else
    923932            [[NSSpellChecker sharedSpellChecker] cancelCorrectionBubbleForView:m_webView];
    924         else
    925             [[NSSpellChecker sharedSpellChecker] dismissCorrectionBubbleForView:m_webView];
    926933        m_correctionPanelIsShown = NO;
    927934    }
  • trunk/WebKit2/ChangeLog

    r73286 r73287  
     12010-12-03  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Need to move all code that applies correction into correction panel callback.
     6        https://bugs.webkit.org/show_bug.cgi?id=50426
     7        <rdar://problem/8720832>
     8
     9        Adopted new signature of dismissCorrectionPanel.
     10
     11        * WebProcess/WebCoreSupport/WebEditorClient.h:
     12        * WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm:
     13        (WebKit::WebEditorClient::dismissCorrectionPanel):
     14
    1152010-12-03  Jessie Berlin  <jberlin@apple.com>
    216
  • trunk/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h

    r73088 r73287  
    136136#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
    137137    virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings, WebCore::Editor*);
    138     virtual void dismissCorrectionPanel(WebCore::CorrectionWasRejectedOrNot);
     138    virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel);
    139139    virtual bool isShowingCorrectionPanel();
    140140#endif
  • trunk/WebKit2/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm

    r73088 r73287  
    229229}
    230230
    231 void WebEditorClient::dismissCorrectionPanel(WebCore::CorrectionWasRejectedOrNot)
     231void WebEditorClient::dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel)
    232232{
    233233    notImplemented();
Note: See TracChangeset for help on using the changeset viewer.