Changeset 78632 in webkit


Ignore:
Timestamp:
Feb 15, 2011 3:44:13 PM (13 years ago)
Author:
Darin Adler
Message:

2011-02-15 Jia Pu <jpu@apple.com>

Reviewed by Darin Adler.

Autocorrection should respect undo.
https://bugs.webkit.org/show_bug.cgi?id=52221
<rdar://problem/8663399>

Please see WebCore/ChangeLog for detailed description.

  • WebCoreSupport/WebEditorClient.cpp: (WebFrameImpl::replaceSelection): Adopted new signature of ReplaceSelectionCommand::create().

2011-02-15 Jia Pu <jpu@apple.com>

Reviewed by Darin Adler.

Autocorrection should respect undo.
https://bugs.webkit.org/show_bug.cgi?id=52221
<rdar://problem/8663399>

Please see WebCore/ChangeLog for detailed description.

  • WebCoreSupport/WebEditorClient.h: Updated for the new function declared in EditorClient.
  • WebCoreSupport/WebEditorClient.mm: (WebEditorClient::recordAutocorrectionResponse): Ditto.
  • WebView/WebFrame.mm: (-[WebFrame _replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:]):

Adopted new signature of ReplaceSelectionCommand::create().

2011-02-15 Jia Pu <jpu@apple.com>

Reviewed by Darin Adler.

Autocorrection should respect undo.
https://bugs.webkit.org/show_bug.cgi?id=52221
<rdar://problem/8663399>

Manual test: manual-tests/autocorrection/undo-autocorrection.html

When user undoes an autocorrection, we need to do four things:

  1. Revert the change in text that has been made by correction.
  2. Revert the selection to pre-correction state so that user can immediately continue typing.
  3. Add appropriate markers to reverted text so that it won't be corrected again and/or shown as misspelled.
  4. If applicable, notify spell checking service to record this reversion.

To achieve these, this patch introduces following changes:

  1. Created SpellingCorrectionCommand so that correction can be undone in similar way as any other editing command. SpellingCorrectionCommand is a composition of SetSelectionCommand, SpellingCorrectionRecordUndoCommand and ReplaceSelectionCommand.
  2. Created SetSelectionCommand so that undo command can restore selection state.
  3. Added member function recordAutocorrectionResponse() to editor client.

To improve readability, this patch also consolidates various boolean arguments in SelectionController::setSelection()
and ReplaceSelectionCommand::ReplaceSelectionCommand(). These boolean arguments have been
replaced by enum variable.

  • WebCore.exp.in: Updated for changes in Editor and ReplaceSelectionCommand.
  • WebCore.xcodeproj/project.pbxproj: Updated for new source files.
  • editing/CompositeEditCommand.cpp: (WebCore::CompositeEditCommand::moveParagraphs): Adopted new signature of ReplaceSelectionCommand::create().
  • editing/Editor.cpp: (WebCore::Editor::replaceSelectionWithFragment): Ditto. (WebCore::Editor::unappliedEditing): Cleaned up trailing whitespace. (WebCore::Editor::reappliedEditing): Ditto. (WebCore::Editor::selectComposition): Adopted new signature of SelectionController::setSelection(). (WebCore::Editor::confirmComposition): Ditto. (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Rearranged code to reduce the

level of deeply nested if statement. Adopted SpellingCorrectionCommand.

(WebCore::Editor::applyCorrectionPanelInfo): Adopted SpellingCorrectionCommand.
(WebCore::Editor::unappliedSpellCorrection): Function for adding markers to reverted text and

for notifiying editor client about undone correction.

(WebCore::Editor::changeSelectionAfterCommand): Adopted new signature of SelectionController::setSelection().
(WebCore::Editor::respondToChangedSelection): Use SelectionController::SetSelectionOptions

instead of boolean variables.

  • editing/Editor.h: Added Editor::unappliedSpellCorrection().
  • editing/EditorCommand.cpp: (WebCore::executeInsertFragment): Adopted new signature of ReplaceSelectionCommand::create().
  • editing/MoveSelectionCommand.cpp: (WebCore::MoveSelectionCommand::doApply): Ditto.
  • editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::ReplaceSelectionCommand): Replaced all boolean arguments

with an enum value.

  • editing/ReplaceSelectionCommand.h: (WebCore::ReplaceSelectionCommand::create): Ditto.
  • editing/SelectionController.cpp: Adopted new signature of SelectionController::setSelection(). (WebCore::SelectionController::moveTo): (WebCore::SelectionController::setSelection): (WebCore::SelectionController::respondToNodeModification): (WebCore::SelectionController::setBase): (WebCore::SelectionController::setExtent): (WebCore::SelectionController::setSelectedRange):
  • editing/SelectionController.h: (WebCore::SelectionController::setSelection): Replaced all boolean arguments with an enum value.
  • editing/SetSelectionCommand.cpp: Added. (WebCore::SetSelectionCommand::SetSelectionCommand): (WebCore::SetSelectionCommand::doApply): (WebCore::SetSelectionCommand::doUnapply):
  • editing/SetSelectionCommand.h: Added. (WebCore::SetSelectionCommand::create):
  • editing/mac/SpellingCorrectionCommand.cpp: Added. (WebCore::SpellingCorrectionRecordUndoCommand::create): (WebCore::SpellingCorrectionRecordUndoCommand::SpellingCorrectionRecordUndoCommand): (WebCore::SpellingCorrectionRecordUndoCommand::doApply): (WebCore::SpellingCorrectionRecordUndoCommand::doUnapply): (WebCore::SpellingCorrectionCommand::SpellingCorrectionCommand): (WebCore::SpellingCorrectionCommand::doApply):
  • editing/mac/SpellingCorrectionCommand.h: Added. (WebCore::SpellingCorrectionCommand::create):
  • loader/EmptyClients.h: Updated for the new function declared in EditorClient. (WebCore::EmptyEditorClient::recordAutocorrectionResponse):
  • manual-tests/autocorrection/undo-autocorrection.html: Added.
  • page/ContextMenuController.cpp: (WebCore::ContextMenuController::contextMenuItemSelected): Adopted new signature of ReplaceSelectionCommand::create().
  • page/DragController.cpp: (WebCore::DragController::concludeEditDrag): Ditto.
  • page/EditorClient.h: Added EditorClient::recordAutocorrectionResponse().

2011-02-15 Jia Pu <jpu@apple.com>

Reviewed by Darin Adler.

Autocorrection should respect undo.
https://bugs.webkit.org/show_bug.cgi?id=52221
<rdar://problem/8663399>

Please see WebCore/ChangeLog for detailed description.

  • WebProcess/WebCoreSupport/WebEditorClient.h: Updated for the new function declared in EditorClient.
  • WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm: (WebKit::WebEditorClient::recordAutocorrectionResponse): Ditto.
  • WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::replaceSelectionWithText): Adopted new signature of ReplaceSelectionCommand::create().
Location:
trunk/Source
Files:
5 added
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r78630 r78632  
     12011-02-15  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Autocorrection should respect undo.
     6        https://bugs.webkit.org/show_bug.cgi?id=52221
     7        <rdar://problem/8663399>
     8
     9        Manual test: manual-tests/autocorrection/undo-autocorrection.html
     10
     11        When user undoes an autocorrection, we need to do four things:
     12        1. Revert the change in text that has been made by correction.
     13        2. Revert the selection to pre-correction state so that user can immediately continue typing.
     14        3. Add appropriate markers to reverted text so that it won't be corrected again and/or shown
     15           as misspelled.
     16        4. If applicable, notify spell checking service to record this reversion.
     17
     18        To achieve these, this patch introduces following changes:
     19        1. Created SpellingCorrectionCommand so that correction can be undone in similar way as any
     20           other editing command. SpellingCorrectionCommand is a composition of SetSelectionCommand,
     21           SpellingCorrectionRecordUndoCommand and ReplaceSelectionCommand.
     22        2. Created SetSelectionCommand so that undo command can restore selection state.
     23        3. Added member function recordAutocorrectionResponse() to editor client.
     24
     25        To improve readability, this patch also consolidates various boolean arguments in SelectionController::setSelection()
     26        and ReplaceSelectionCommand::ReplaceSelectionCommand(). These boolean arguments have been
     27        replaced by enum variable.
     28
     29        * WebCore.exp.in: Updated for changes in Editor and ReplaceSelectionCommand.
     30
     31        * WebCore.xcodeproj/project.pbxproj: Updated for new source files.
     32
     33        * editing/CompositeEditCommand.cpp:
     34        (WebCore::CompositeEditCommand::moveParagraphs): Adopted new signature of ReplaceSelectionCommand::create().
     35
     36        * editing/Editor.cpp:
     37        (WebCore::Editor::replaceSelectionWithFragment): Ditto.
     38        (WebCore::Editor::unappliedEditing): Cleaned up trailing whitespace.
     39        (WebCore::Editor::reappliedEditing): Ditto.
     40        (WebCore::Editor::selectComposition): Adopted new signature of SelectionController::setSelection().
     41        (WebCore::Editor::confirmComposition): Ditto.
     42        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Rearranged code to reduce the
     43            level of deeply nested if statement. Adopted SpellingCorrectionCommand.
     44        (WebCore::Editor::applyCorrectionPanelInfo): Adopted SpellingCorrectionCommand.
     45        (WebCore::Editor::unappliedSpellCorrection): Function for adding markers to reverted text and
     46            for notifiying editor client about undone correction.
     47        (WebCore::Editor::changeSelectionAfterCommand): Adopted new signature of SelectionController::setSelection().
     48        (WebCore::Editor::respondToChangedSelection): Use SelectionController::SetSelectionOptions
     49            instead of boolean variables.
     50
     51        * editing/Editor.h: Added Editor::unappliedSpellCorrection().
     52
     53        * editing/EditorCommand.cpp:
     54        (WebCore::executeInsertFragment): Adopted new signature of ReplaceSelectionCommand::create().
     55
     56        * editing/MoveSelectionCommand.cpp:
     57        (WebCore::MoveSelectionCommand::doApply): Ditto.
     58
     59        * editing/ReplaceSelectionCommand.cpp:
     60        (WebCore::ReplaceSelectionCommand::ReplaceSelectionCommand): Replaced all boolean arguments
     61            with an enum value.
     62
     63        * editing/ReplaceSelectionCommand.h:
     64        (WebCore::ReplaceSelectionCommand::create): Ditto.
     65
     66        * editing/SelectionController.cpp: Adopted new signature of SelectionController::setSelection().
     67        (WebCore::SelectionController::moveTo):
     68        (WebCore::SelectionController::setSelection):
     69        (WebCore::SelectionController::respondToNodeModification):
     70        (WebCore::SelectionController::setBase):
     71        (WebCore::SelectionController::setExtent):
     72        (WebCore::SelectionController::setSelectedRange):
     73
     74        * editing/SelectionController.h:
     75        (WebCore::SelectionController::setSelection): Replaced all boolean arguments with an enum value.
     76
     77        * editing/SetSelectionCommand.cpp: Added.
     78        (WebCore::SetSelectionCommand::SetSelectionCommand):
     79        (WebCore::SetSelectionCommand::doApply):
     80        (WebCore::SetSelectionCommand::doUnapply):
     81
     82        * editing/SetSelectionCommand.h: Added.
     83        (WebCore::SetSelectionCommand::create):
     84
     85        * editing/mac/SpellingCorrectionCommand.cpp: Added.
     86        (WebCore::SpellingCorrectionRecordUndoCommand::create):
     87        (WebCore::SpellingCorrectionRecordUndoCommand::SpellingCorrectionRecordUndoCommand):
     88        (WebCore::SpellingCorrectionRecordUndoCommand::doApply):
     89        (WebCore::SpellingCorrectionRecordUndoCommand::doUnapply):
     90        (WebCore::SpellingCorrectionCommand::SpellingCorrectionCommand):
     91        (WebCore::SpellingCorrectionCommand::doApply):
     92
     93        * editing/mac/SpellingCorrectionCommand.h: Added.
     94        (WebCore::SpellingCorrectionCommand::create):
     95
     96        * loader/EmptyClients.h: Updated for the new function declared in EditorClient.
     97        (WebCore::EmptyEditorClient::recordAutocorrectionResponse):
     98
     99        * manual-tests/autocorrection/undo-autocorrection.html: Added.
     100
     101        * page/ContextMenuController.cpp:
     102        (WebCore::ContextMenuController::contextMenuItemSelected): Adopted new signature of ReplaceSelectionCommand::create().
     103
     104        * page/DragController.cpp:
     105        (WebCore::DragController::concludeEditDrag): Ditto.
     106
     107        * page/EditorClient.h: Added EditorClient::recordAutocorrectionResponse().
     108
    11092011-02-15  Beth Dakin  <bdakin@apple.com>
    2110
  • trunk/Source/WebCore/WebCore.exp.in

    r78626 r78632  
    490490__ZN7WebCore19ResourceRequestBase6setURLERKNS_4KURLE
    491491__ZN7WebCore19SelectionController10setFocusedEb
    492 __ZN7WebCore19SelectionController12setSelectionERKNS_16VisibleSelectionEbbbNS0_19CursorAlignOnScrollENS_15TextGranularityENS_20DirectionalityPolicyE
     492__ZN7WebCore19SelectionController12setSelectionERKNS_16VisibleSelectionEjNS0_19CursorAlignOnScrollENS_15TextGranularityENS_20DirectionalityPolicyE
    493493__ZN7WebCore19SelectionController15revealSelectionERKNS_15ScrollAlignmentEb
    494494__ZN7WebCore19SelectionController16setSelectedRangeEPNS_5RangeENS_9EAffinityEb
     
    536536__ZN7WebCore22externalRepresentationEPNS_5FrameEj
    537537__ZN7WebCore23AuthenticationChallengeC1ERKNS_15ProtectionSpaceERKNS_10CredentialEjRKNS_16ResourceResponseERKNS_13ResourceErrorE
    538 __ZN7WebCore23ReplaceSelectionCommandC1EPNS_8DocumentEN3WTF10PassRefPtrINS_16DocumentFragmentEEEbbbbbNS_10EditActionE
    539538__ZN7WebCore23createFragmentFromNodesEPNS_8DocumentERKN3WTF6VectorIPNS_4NodeELm0EEE
    540539__ZN7WebCore23overrideDefaultLanguageERKN3WTF6StringE
     540__ZN7WebCore23ReplaceSelectionCommandC1EPNS_8DocumentEN3WTF10PassRefPtrINS_16DocumentFragmentEEEjNS_10EditActionE
    541541__ZN7WebCore24BinaryPropertyListWriter17writePropertyListEv
    542542__ZN7WebCore24DocumentMarkerController13removeMarkersEj
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r78617 r78632  
    47704770                B885E8D511E06DD2009FFBF4 /* InspectorApplicationCacheAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = B885E8D311E06DD2009FFBF4 /* InspectorApplicationCacheAgent.h */; settings = {ATTRIBUTES = (); }; };
    47714771                B8A6A6D5127B338D008673BA /* CorrectionPanelInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = B8A6A6D4127B338D008673BA /* CorrectionPanelInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4772                B8DBDB4B130B0F8A00F5CDB1 /* SetSelectionCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B8DBDB47130B0F8A00F5CDB1 /* SetSelectionCommand.cpp */; };
     4773                B8DBDB4C130B0F8A00F5CDB1 /* SetSelectionCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = B8DBDB48130B0F8A00F5CDB1 /* SetSelectionCommand.h */; };
     4774                B8DBDB4D130B0F8A00F5CDB1 /* SpellingCorrectionCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B8DBDB49130B0F8A00F5CDB1 /* SpellingCorrectionCommand.cpp */; };
     4775                B8DBDB4E130B0F8A00F5CDB1 /* SpellingCorrectionCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = B8DBDB4A130B0F8A00F5CDB1 /* SpellingCorrectionCommand.h */; };
    47724776                BC00F0040E0A185500FD04E3 /* DOMFile.h in Headers */ = {isa = PBXBuildFile; fileRef = BC00EFFE0E0A185500FD04E3 /* DOMFile.h */; };
    47734777                BC00F0050E0A185500FD04E3 /* DOMFile.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC00EFFF0E0A185500FD04E3 /* DOMFile.mm */; };
     
    1106211066                B885E8D311E06DD2009FFBF4 /* InspectorApplicationCacheAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorApplicationCacheAgent.h; sourceTree = "<group>"; };
    1106311067                B8A6A6D4127B338D008673BA /* CorrectionPanelInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CorrectionPanelInfo.h; sourceTree = "<group>"; };
     11068                B8DBDB47130B0F8A00F5CDB1 /* SetSelectionCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SetSelectionCommand.cpp; sourceTree = "<group>"; };
     11069                B8DBDB48130B0F8A00F5CDB1 /* SetSelectionCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SetSelectionCommand.h; sourceTree = "<group>"; };
     11070                B8DBDB49130B0F8A00F5CDB1 /* SpellingCorrectionCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpellingCorrectionCommand.cpp; sourceTree = "<group>"; };
     11071                B8DBDB4A130B0F8A00F5CDB1 /* SpellingCorrectionCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpellingCorrectionCommand.h; sourceTree = "<group>"; };
    1106411072                BC00EFFE0E0A185500FD04E3 /* DOMFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMFile.h; sourceTree = "<group>"; };
    1106511073                BC00EFFF0E0A185500FD04E3 /* DOMFile.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMFile.mm; sourceTree = "<group>"; };
     
    1532515333                                93309DC0099E64910056E581 /* SetNodeAttributeCommand.cpp */,
    1532615334                                93309DC1099E64910056E581 /* SetNodeAttributeCommand.h */,
     15335                                B8DBDB47130B0F8A00F5CDB1 /* SetSelectionCommand.cpp */,
     15336                                B8DBDB48130B0F8A00F5CDB1 /* SetSelectionCommand.h */,
     15337                                B8DBDB49130B0F8A00F5CDB1 /* SpellingCorrectionCommand.cpp */,
     15338                                B8DBDB4A130B0F8A00F5CDB1 /* SpellingCorrectionCommand.h */,
    1532715339                                4B6FA6F30C39E48C00087011 /* SmartReplace.cpp */,
    1532815340                                4B6FA6F20C39E48C00087011 /* SmartReplace.h */,
     
    2242122433                                975CA2A21303679D00E99AD9 /* JSCrypto.h in Headers */,
    2242222434                                26E98A10130A9FCA008EB7B2 /* TextCodecASCIIFastPath.h in Headers */,
     22435                                B8DBDB4C130B0F8A00F5CDB1 /* SetSelectionCommand.h in Headers */,
     22436                                B8DBDB4E130B0F8A00F5CDB1 /* SpellingCorrectionCommand.h in Headers */,
    2242322437                        );
    2242422438                        runOnlyForDeploymentPostprocessing = 0;
     
    2510325117                                A1E1154613015C4E0054AC8C /* PointLightSource.cpp in Sources */,
    2510425118                                A1E1154813015C5D0054AC8C /* SpotLightSource.cpp in Sources */,
     25119                                B8DBDB4B130B0F8A00F5CDB1 /* SetSelectionCommand.cpp in Sources */,
     25120                                B8DBDB4D130B0F8A00F5CDB1 /* SpellingCorrectionCommand.cpp in Sources */,
    2510525121                        );
    2510625122                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r77062 r78632  
    10071007    setEndingSelection(destination);
    10081008    ASSERT(endingSelection().isCaretOrRange());
    1009     applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment, true, false, !preserveStyle, false, true));
     1009    ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MovingParagraph;
     1010    if (!preserveStyle)
     1011        options |= ReplaceSelectionCommand::MatchStyle;
     1012    applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment, options));
    10101013
    10111014    document()->frame()->editor()->markMisspellingsAndBadGrammar(endingSelection());
  • trunk/Source/WebCore/editing/Editor.cpp

    r78533 r78632  
    7575#include "Sound.h"
    7676#include "SpellChecker.h"
     77#include "SpellingCorrectionCommand.h"
    7778#include "Text.h"
    7879#include "TextEvent.h"
     
    437438    if (m_frame->selection()->isNone() || !fragment)
    438439        return;
    439    
    440     applyCommand(ReplaceSelectionCommand::create(m_frame->document(), fragment, selectReplacement, smartReplace, matchStyle));
     440
     441    ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::PreventNesting;
     442    if (selectReplacement)
     443        options |= ReplaceSelectionCommand::SelectReplacement;
     444    if (smartReplace)
     445        options |= ReplaceSelectionCommand::SmartReplace;
     446    if (matchStyle)
     447        options |= ReplaceSelectionCommand::MatchStyle;
     448    applyCommand(ReplaceSelectionCommand::create(m_frame->document(), fragment, options, EditActionPaste));
    441449    revealSelectionAfterEditingOperation();
    442450
     
    11341142    if (client())
    11351143        client()->registerCommandForRedo(cmd);
    1136     respondToChangedContents(newSelection);   
     1144    respondToChangedContents(newSelection);
    11371145}
    11381146
     
    11491157    if (client())
    11501158        client()->registerCommandForUndo(cmd);
    1151     respondToChangedContents(newSelection);   
     1159    respondToChangedContents(newSelection);
    11521160}
    11531161
     
    15881596    VisibleSelection selection;
    15891597    selection.setWithoutValidation(range->startPosition(), range->endPosition());
    1590     m_frame->selection()->setSelection(selection, false, false);
     1598    m_frame->selection()->setSelection(selection, 0);
    15911599}
    15921600
     
    16461654
    16471655    if (preserveSelection) {
    1648         m_frame->selection()->setSelection(oldSelection, false, false);
     1656        m_frame->selection()->setSelection(oldSelection, 0);
    16491657        // An open typing command that disagrees about current selection would cause issues with typing later on.
    16501658        TypingCommand::closeTyping(m_lastEditCommand.get());
     
    23552363            ASSERT(resultLength > 0 && resultLocation >= 0);
    23562364
    2357             if (shouldShowCorrectionPanel && resultLocation + resultLength < spellingRangeEndOffset)
     2365            if (shouldShowCorrectionPanel && (resultLocation + resultLength < spellingRangeEndOffset || result->type != TextCheckingTypeCorrection))
    23582366                continue;
    23592367
     
    23702378            // adding links should be done only immediately after they are typed
    23712379            if (result->type == TextCheckingTypeLink && selectionOffset > resultLocation + resultLength + 1)
    2372                 doReplacement = false;
     2380                continue;
    23732381
    23742382            // Don't correct spelling in an already-corrected word.
    2375             if (doReplacement && result->type == TextCheckingTypeCorrection) {
     2383            if (result->type == TextCheckingTypeCorrection) {
    23762384                Node* node = rangeToReplace->startContainer();
    23772385                int startOffset = rangeToReplace->startOffset();
     
    23892397                }
    23902398            }
    2391             if (doReplacement && !shouldShowCorrectionPanel && selectionToReplace != m_frame->selection()->selection()) {
    2392                 if (m_frame->selection()->shouldChangeSelection(selectionToReplace)) {
     2399
     2400            if (!doReplacement)
     2401                continue;
     2402
     2403#if SUPPORT_AUTOCORRECTION_PANEL
     2404            if (shouldShowCorrectionPanel) {
     2405                if (resultLocation + resultLength == spellingRangeEndOffset) {
     2406                    // We only show the correction panel on the last word.
     2407                    Vector<FloatQuad> textQuads;
     2408                    rangeToReplace->getBorderAndTextQuads(textQuads);
     2409                    Vector<FloatQuad>::const_iterator end = textQuads.end();
     2410                    FloatRect totalBoundingBox;
     2411                    for (Vector<FloatQuad>::const_iterator it = textQuads.begin(); it < end; ++it)
     2412                        totalBoundingBox.unite(it->boundingBox());
     2413                    m_correctionPanelInfo.rangeToBeReplaced = rangeToReplace;
     2414                    m_correctionPanelInfo.replacedString = plainText(rangeToReplace.get());
     2415                    m_correctionPanelInfo.replacementString = result->replacement;
     2416                    m_correctionPanelInfo.isActive = true;
     2417                    client()->showCorrectionPanel(m_correctionPanelInfo.panelType, totalBoundingBox, m_correctionPanelInfo.replacedString, result->replacement, Vector<String>(), this);
     2418                    break;
     2419                }
     2420                // If this function is called for showing correction panel, we ignore other correction or replacement.
     2421                continue;
     2422            }
     2423#endif
     2424
     2425            if (selectionToReplace != m_frame->selection()->selection()) {
     2426                if (!m_frame->selection()->shouldChangeSelection(selectionToReplace))
     2427                    continue;
     2428            }
     2429
     2430            if (result->type == TextCheckingTypeLink) {
     2431                m_frame->selection()->setSelection(selectionToReplace);
     2432                selectionChanged = true;
     2433                restoreSelectionAfterChange = false;
     2434                if (canEditRichly())
     2435                    applyCommand(CreateLinkCommand::create(m_frame->document(), result->replacement));
     2436            } else if (canEdit() && shouldInsertText(result->replacement, rangeToReplace.get(), EditorInsertActionTyped)) {
     2437                String replacedString;
     2438                if (result->type == TextCheckingTypeCorrection)
     2439                    replacedString = plainText(rangeToReplace.get());
     2440
     2441                bool useSpellingCorrectionCommand = false;
     2442#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
     2443                if (result->type == TextCheckingTypeCorrection)
     2444                    useSpellingCorrectionCommand = true;
     2445#endif
     2446                if (useSpellingCorrectionCommand)
     2447                    applyCommand(SpellingCorrectionCommand::create(rangeToReplace, result->replacement));
     2448                else {
    23932449                    m_frame->selection()->setSelection(selectionToReplace);
    2394                     selectionChanged = true;
    2395                 } else {
    2396                     doReplacement = false;
     2450                    replaceSelectionWithText(result->replacement, false, false);
    23972451                }
    2398             }
    2399 
    2400             String replacedString;
    2401             if (doReplacement) {
    2402                 if (result->type == TextCheckingTypeLink) {
    2403                     restoreSelectionAfterChange = false;
    2404                     if (canEditRichly())
    2405                         applyCommand(CreateLinkCommand::create(m_frame->document(), result->replacement));
    2406                 } else if (canEdit() && shouldInsertText(result->replacement, rangeToReplace.get(), EditorInsertActionTyped)) {
    2407                     if (result->type == TextCheckingTypeCorrection)
    2408                         replacedString = plainText(rangeToReplace.get());
    2409 #if SUPPORT_AUTOCORRECTION_PANEL
    2410                     if (shouldShowCorrectionPanel && resultLocation + resultLength == spellingRangeEndOffset && result->type == TextCheckingTypeCorrection) {
    2411                         // We only show the correction panel on the last word.
    2412                         Vector<FloatQuad> textQuads;
    2413                         rangeToReplace->getBorderAndTextQuads(textQuads);
    2414                         Vector<FloatQuad>::const_iterator end = textQuads.end();
    2415                         FloatRect totalBoundingBox;
    2416                         for (Vector<FloatQuad>::const_iterator it = textQuads.begin(); it < end; ++it)
    2417                             totalBoundingBox.unite(it->boundingBox());
    2418                         m_correctionPanelInfo.rangeToBeReplaced = rangeToReplace;
    2419                         m_correctionPanelInfo.replacedString = replacedString;
    2420                         m_correctionPanelInfo.replacementString = result->replacement;
    2421                         m_correctionPanelInfo.isActive = true;
    2422                         client()->showCorrectionPanel(m_correctionPanelInfo.panelType, totalBoundingBox, m_correctionPanelInfo.replacedString, result->replacement, Vector<String>(), this);
    2423                         doReplacement = false;
    2424                     }
    2425 #endif
    2426                     if (doReplacement) {
    2427                         replaceSelectionWithText(result->replacement, false, false);
    2428                         offsetDueToReplacement += replacementLength - resultLength;
    2429                         if (resultLocation < selectionOffset) {
    2430                             selectionOffset += replacementLength - resultLength;
    2431                             if (ambiguousBoundaryOffset >= 0)
    2432                                 ambiguousBoundaryOffset = selectionOffset - 1;
    2433                         }
    2434 
    2435                         if (result->type == TextCheckingTypeCorrection) {
    2436                             // Add a marker so that corrections can easily be undone and won't be re-corrected.
    2437                             RefPtr<Range> replacedRange = paragraph.subrange(resultLocation, replacementLength);
    2438                             replacedRange->startContainer()->document()->markers()->addMarker(replacedRange.get(), DocumentMarker::Replacement, replacedString);
    2439                             replacedRange->startContainer()->document()->markers()->addMarker(replacedRange.get(), DocumentMarker::CorrectionIndicator, replacedString);
    2440                             replacedRange->startContainer()->document()->markers()->addMarker(replacedRange.get(), DocumentMarker::SpellCheckingExemption);
    2441                         }
    2442                     }
     2452
     2453                selectionChanged = true;
     2454                offsetDueToReplacement += replacementLength - resultLength;
     2455                if (resultLocation < selectionOffset) {
     2456                    selectionOffset += replacementLength - resultLength;
     2457                    if (ambiguousBoundaryOffset >= 0)
     2458                        ambiguousBoundaryOffset = selectionOffset - 1;
     2459                }
     2460
     2461                if (result->type == TextCheckingTypeCorrection) {
     2462                    // Add a marker so that corrections can easily be undone and won't be re-corrected.
     2463                    RefPtr<Range> replacedRange = paragraph.subrange(resultLocation, replacementLength);
     2464                    replacedRange->startContainer()->document()->markers()->addMarker(replacedRange.get(), DocumentMarker::Replacement, replacedString);
     2465                    replacedRange->startContainer()->document()->markers()->addMarker(replacedRange.get(), DocumentMarker::CorrectionIndicator, replacedString);
     2466                    replacedRange->startContainer()->document()->markers()->addMarker(replacedRange.get(), DocumentMarker::SpellCheckingExemption);
    24432467                }
    24442468            }
     
    26902714void Editor::applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>& markerTypesToAdd)
    26912715{
     2716#if SUPPORT_AUTOCORRECTION_PANEL
    26922717    if (!m_correctionPanelInfo.rangeToBeReplaced)
    26932718        return;
     
    27212746    // Clone the range, since the caller of this method may want to keep the original range around.
    27222747    RefPtr<Range> rangeToBeReplaced = m_correctionPanelInfo.rangeToBeReplaced->cloneRange(ec);
    2723     VisibleSelection selectionToReplace(rangeToBeReplaced.get(), DOWNSTREAM);
    2724     if (m_frame->selection()->shouldChangeSelection(selectionToReplace)) {
    2725         m_frame->selection()->setSelection(selectionToReplace);
    2726         replaceSelectionWithText(m_correctionPanelInfo.replacementString, false, false);
    2727         setEnd(paragraphRangeContainingCorrection.get(), m_frame->selection()->selection().start());
    2728         RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, m_correctionPanelInfo.replacementString.length());
    2729         DocumentMarkerController* markers = replacementRange->startContainer()->document()->markers();
    2730         size_t size = markerTypesToAdd.size();
    2731         for (size_t i = 0; i < size; ++i) {
    2732             if (m_correctionPanelInfo.panelType == CorrectionPanelInfo::PanelTypeReversion)
    2733                 markers->addMarker(replacementRange.get(), markerTypesToAdd[i]);
    2734             else
    2735                 markers->addMarker(replacementRange.get(), markerTypesToAdd[i], m_correctionPanelInfo.replacedString);
    2736         }
    2737     }
     2748    applyCommand(SpellingCorrectionCommand::create(rangeToBeReplaced, m_correctionPanelInfo.replacementString));
     2749    setEnd(paragraphRangeContainingCorrection.get(), m_frame->selection()->selection().start());
     2750    RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph,  m_correctionPanelInfo.replacementString.length());
     2751    String newText = plainText(replacementRange.get());
     2752
     2753    // Check to see if replacement succeeded.
     2754    if (newText != m_correctionPanelInfo.replacementString)
     2755        return;
     2756
     2757    DocumentMarkerController* markers = replacementRange->startContainer()->document()->markers();
     2758    size_t size = markerTypesToAdd.size();
     2759    for (size_t i = 0; i < size; ++i) {
     2760        if (m_correctionPanelInfo.panelType == CorrectionPanelInfo::PanelTypeReversion)
     2761            markers->addMarker(replacementRange.get(), markerTypesToAdd[i]);
     2762        else
     2763            markers->addMarker(replacementRange.get(), markerTypesToAdd[i], m_correctionPanelInfo.replacedString);
     2764    }
     2765#else // SUPPORT_AUTOCORRECTION_PANEL
     2766    UNUSED_PARAM(markerTypesToAdd);
     2767#endif // SUPPORT_AUTOCORRECTION_PANEL
    27382768}
    27392769
     
    27512781    ASSERT(m_correctionPanelInfo.rangeToBeReplaced->endPosition() == caretPosition);
    27522782    dismissCorrectionPanel(m_correctionPanelInfo.rangeToBeReplaced->endPosition() == caretPosition ? ReasonForDismissingCorrectionPanelAccepted : ReasonForDismissingCorrectionPanelIgnored);
     2783}
     2784
     2785void Editor::unappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction)
     2786{
     2787#if SUPPORT_AUTOCORRECTION_PANEL
     2788    client()->recordAutocorrectionResponse(EditorClient::AutocorrectionReverted, corrected, correction);
     2789    m_frame->document()->updateLayout();
     2790    m_frame->selection()->setSelection(selectionOfCorrected, SelectionController::CloseTyping | SelectionController::ClearTypingStyle | SelectionController::SpellCorrectionTriggered);
     2791    RefPtr<Range> range = Range::create(m_frame->document(), m_frame->selection()->selection().start(), m_frame->selection()->selection().end());
     2792
     2793    DocumentMarkerController* markers = m_frame->document()->markers();
     2794    markers->removeMarkers(range.get(), DocumentMarker::Spelling);
     2795    markers->addMarker(range.get(), DocumentMarker::Replacement);
     2796    markers->addMarker(range.get(), DocumentMarker::SpellCheckingExemption);
     2797#else // SUPPORT_AUTOCORRECTION_PANEL
     2798    UNUSED_PARAM(selectionOfCorrected);
     2799    UNUSED_PARAM(corrected);
     2800    UNUSED_PARAM(correction);
     2801#endif // SUPPORT_AUTOCORRECTION_PANEL
    27532802}
    27542803
     
    30243073    // See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ranges for selections that are no longer valid
    30253074    bool selectionDidNotChangeDOMPosition = newSelection == m_frame->selection()->selection();
    3026     if (selectionDidNotChangeDOMPosition || m_frame->selection()->shouldChangeSelection(newSelection))
    3027         m_frame->selection()->setSelection(newSelection, closeTyping, clearTypingStyle);
     3075    if (selectionDidNotChangeDOMPosition || m_frame->selection()->shouldChangeSelection(newSelection)) {
     3076        SelectionController::SetSelectionOptions options = 0;
     3077        if (closeTyping)
     3078            options |= SelectionController::CloseTyping;
     3079        if (clearTypingStyle)
     3080            options |= SelectionController::ClearTypingStyle;
     3081        m_frame->selection()->setSelection(newSelection, options);
     3082    }
    30283083
    30293084    // Some editing operations change the selection visually without affecting its position within the DOM.
     
    34493504}
    34503505
    3451 void Editor::respondToChangedSelection(const VisibleSelection& oldSelection, bool closeTyping)
     3506void Editor::respondToChangedSelection(const VisibleSelection& oldSelection, SelectionController::SetSelectionOptions options)
    34523507{
    34533508#if SUPPORT_AUTOCORRECTION_PANEL
     
    34603515#endif // SUPPORT_AUTOCORRECTION_PANEL
    34613516
     3517    bool closeTyping = options & SelectionController::CloseTyping;
    34623518    bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabled();
    34633519    bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled && isGrammarCheckingEnabled();
     
    34733529        }
    34743530
     3531        bool shouldCheckSpellingAndGrammar = true;
     3532#if SUPPORT_AUTOCORRECTION_PANEL
     3533        // Don't check spelling and grammar if the change of selection is triggered by spelling correction itself.
     3534        shouldCheckSpellingAndGrammar = !(options & SelectionController::SpellCorrectionTriggered);
     3535#endif
     3536
    34753537        // When typing we check spelling elsewhere, so don't redo it here.
    34763538        // If this is a change in selection resulting from a delete operation,
    34773539        // oldSelection may no longer be in the document.
    3478         if (closeTyping && oldSelection.isContentEditable() && oldSelection.start().node() && oldSelection.start().node()->inDocument()) {
     3540        if (shouldCheckSpellingAndGrammar && closeTyping && oldSelection.isContentEditable() && oldSelection.start().node() && oldSelection.start().node()->inDocument()) {
    34793541            VisiblePosition oldStart(oldSelection.visibleStart());
    34803542            VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary));
  • trunk/Source/WebCore/editing/Editor.h

    r78533 r78632  
    3636#include "EditorInsertAction.h"
    3737#include "FindOptions.h"
     38#include "SelectionController.h"
    3839#include "Timer.h"
    3940#include "VisibleSelection.h"
     
    168169    void unappliedEditing(PassRefPtr<EditCommand>);
    169170    void reappliedEditing(PassRefPtr<EditCommand>);
    170    
     171    void unappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction);
     172
    171173    bool selectionStartHasStyle(CSSStyleDeclaration*) const;
    172174
     
    354356    IntRect firstRectForRange(Range*) const;
    355357
    356     void respondToChangedSelection(const VisibleSelection& oldSelection, bool closeTyping);
     358    void respondToChangedSelection(const VisibleSelection& oldSelection, SelectionController::SetSelectionOptions);
    357359    bool shouldChangeSelection(const VisibleSelection& oldSelection, const VisibleSelection& newSelection, EAffinity, bool stillSelecting) const;
    358360
  • trunk/Source/WebCore/editing/EditorCommand.cpp

    r78532 r78632  
    195195static bool executeInsertFragment(Frame* frame, PassRefPtr<DocumentFragment> fragment)
    196196{
    197     applyCommand(ReplaceSelectionCommand::create(frame->document(), fragment,
    198         false, false, false, true, false, EditActionUnspecified));
     197    applyCommand(ReplaceSelectionCommand::create(frame->document(), fragment, ReplaceSelectionCommand::PreventNesting, EditActionUnspecified));
    199198    return true;
    200199}
  • trunk/Source/WebCore/editing/MoveSelectionCommand.cpp

    r76560 r78632  
    7171        return;
    7272    }
    73     applyCommandToComposite(ReplaceSelectionCommand::create(document(), m_fragment, true, m_smartInsert));
     73    ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting;
     74    if (m_smartInsert)
     75        options |= ReplaceSelectionCommand::SmartReplace;
     76    applyCommandToComposite(ReplaceSelectionCommand::create(document(), m_fragment, options));
    7477}
    7578
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r78150 r78632  
    341341}
    342342
    343 ReplaceSelectionCommand::ReplaceSelectionCommand(Document* document, PassRefPtr<DocumentFragment> fragment,
    344         bool selectReplacement, bool smartReplace, bool matchStyle, bool preventNesting, bool movingParagraph,
    345         EditAction editAction)
    346     : CompositeEditCommand(document),
    347       m_selectReplacement(selectReplacement),
    348       m_smartReplace(smartReplace),
    349       m_matchStyle(matchStyle),
    350       m_documentFragment(fragment),
    351       m_preventNesting(preventNesting),
    352       m_movingParagraph(movingParagraph),
    353       m_editAction(editAction),
    354       m_shouldMergeEnd(false)
     343ReplaceSelectionCommand::ReplaceSelectionCommand(Document* document, PassRefPtr<DocumentFragment> fragment, CommandOptions options, EditAction editAction)
     344    : CompositeEditCommand(document)
     345    , m_selectReplacement(options & SelectReplacement)
     346    , m_smartReplace(options & SmartReplace)
     347    , m_matchStyle(options & MatchStyle)
     348    , m_documentFragment(fragment)
     349    , m_preventNesting(options & PreventNesting)
     350    , m_movingParagraph(options & MovingParagraph)
     351    , m_editAction(editAction)
     352    , m_shouldMergeEnd(false)
    355353{
    356354}
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.h

    r71556 r78632  
    3737class ReplaceSelectionCommand : public CompositeEditCommand {
    3838public:
    39     static PassRefPtr<ReplaceSelectionCommand> create(Document* document, PassRefPtr<DocumentFragment> fragment,
    40         bool selectReplacement = true, bool smartReplace = false, bool matchStyle = false, bool preventNesting = true, bool movingParagraph = false,
    41         EditAction action = EditActionPaste)
     39    enum CommandOption {
     40        SelectReplacement = 1 << 0,
     41        SmartReplace = 1 << 1,
     42        MatchStyle = 1 << 2,
     43        PreventNesting = 1 << 3,
     44        MovingParagraph = 1 << 4
     45    };
     46
     47    typedef unsigned CommandOptions;
     48
     49    static PassRefPtr<ReplaceSelectionCommand> create(Document* document, PassRefPtr<DocumentFragment> fragment, CommandOptions options, EditAction action = EditActionPaste)
    4250    {
    43         return adoptRef(new ReplaceSelectionCommand(document, fragment, selectReplacement, smartReplace, matchStyle, preventNesting, movingParagraph, action));
     51        return adoptRef(new ReplaceSelectionCommand(document, fragment, options, action));
    4452    }
    4553
    4654private:
    47     ReplaceSelectionCommand(Document*, PassRefPtr<DocumentFragment>,
    48         bool selectReplacement, bool smartReplace, bool matchStyle, bool preventNesting, bool movingParagraph, EditAction);
     55    ReplaceSelectionCommand(Document*, PassRefPtr<DocumentFragment>, CommandOptions, EditAction);
    4956
    5057    virtual void doApply();
  • trunk/Source/WebCore/editing/SelectionController.cpp

    r78150 r78632  
    8989void SelectionController::moveTo(const VisiblePosition &pos, bool userTriggered, CursorAlignOnScroll align)
    9090{
    91     setSelection(VisibleSelection(pos.deepEquivalent(), pos.deepEquivalent(), pos.affinity()), true, true, userTriggered, align);
     91    SetSelectionOptions options = CloseTyping | ClearTypingStyle;
     92    if (userTriggered)
     93        options |= UserTriggered;
     94    setSelection(VisibleSelection(pos.deepEquivalent(), pos.deepEquivalent(), pos.affinity()), options, align);
    9295}
    9396
    9497void SelectionController::moveTo(const VisiblePosition &base, const VisiblePosition &extent, bool userTriggered)
    9598{
    96     setSelection(VisibleSelection(base.deepEquivalent(), extent.deepEquivalent(), base.affinity()), true, true, userTriggered);
     99    SetSelectionOptions options = CloseTyping | ClearTypingStyle;
     100    if (userTriggered)
     101        options |= UserTriggered;
     102    setSelection(VisibleSelection(base.deepEquivalent(), extent.deepEquivalent(), base.affinity()), options);
    97103}
    98104
    99105void SelectionController::moveTo(const Position &pos, EAffinity affinity, bool userTriggered)
    100106{
    101     setSelection(VisibleSelection(pos, affinity), true, true, userTriggered);
     107    SetSelectionOptions options = CloseTyping | ClearTypingStyle;
     108    if (userTriggered)
     109        options |= UserTriggered;
     110    setSelection(VisibleSelection(pos, affinity), options);
    102111}
    103112
    104113void SelectionController::moveTo(const Range *r, EAffinity affinity, bool userTriggered)
    105114{
     115    SetSelectionOptions options = CloseTyping | ClearTypingStyle;
     116    if (userTriggered)
     117        options |= UserTriggered;
    106118    VisibleSelection selection = r ? VisibleSelection(r->startPosition(), r->endPosition(), affinity) : VisibleSelection(Position(), Position(), affinity);
    107     setSelection(selection, true, true, userTriggered);
     119    setSelection(selection, options);
    108120}
    109121
    110122void SelectionController::moveTo(const Position &base, const Position &extent, EAffinity affinity, bool userTriggered)
    111123{
    112     setSelection(VisibleSelection(base, extent, affinity), true, true, userTriggered);
    113 }
    114 
    115 void SelectionController::setSelection(const VisibleSelection& s, bool closeTyping, bool shouldClearTypingStyle, bool userTriggered, CursorAlignOnScroll align, TextGranularity granularity, DirectionalityPolicy directionalityPolicy)
     124    SetSelectionOptions options = CloseTyping | ClearTypingStyle;
     125    if (userTriggered)
     126        options |= UserTriggered;
     127    setSelection(VisibleSelection(base, extent, affinity), options);
     128}
     129
     130void SelectionController::setSelection(const VisibleSelection& s, SetSelectionOptions options, CursorAlignOnScroll align, TextGranularity granularity, DirectionalityPolicy directionalityPolicy)
    116131{
    117132    m_granularity = granularity;
     133
     134    bool closeTyping = options & CloseTyping;
     135    bool shouldClearTypingStyle = options & ClearTypingStyle;
     136    bool userTriggered = options & UserTriggered;
    118137
    119138    setIsDirectional(directionalityPolicy == MakeDirectionalSelection);
     
    140159    // if document->frame() == m_frame we can get into an infinite loop
    141160    if (document && document->frame() && document->frame() != m_frame && document != m_frame->document()) {
    142         document->frame()->selection()->setSelection(s, closeTyping, shouldClearTypingStyle, userTriggered);
    143         return;
    144     }
    145    
     161        document->frame()->selection()->setSelection(s, options);
     162        return;
     163    }
     164
    146165    if (closeTyping)
    147166        TypingCommand::closeTyping(m_frame->editor()->lastEditCommand());
     
    169188    selectFrameElementInParentIfFullySelected();
    170189    notifyRendererOfSelectionChange(userTriggered);
    171     m_frame->editor()->respondToChangedSelection(oldSelection, closeTyping);
     190    m_frame->editor()->respondToChangedSelection(oldSelection, options);
    172191    if (userTriggered) {
    173192        ScrollAlignment alignment;
     
    251270
    252271    if (clearDOMTreeSelection)
    253         setSelection(VisibleSelection(), false, false);
     272        setSelection(VisibleSelection(), 0);
    254273}
    255274
     
    943962void SelectionController::setBase(const VisiblePosition &pos, bool userTriggered)
    944963{
    945     setSelection(VisibleSelection(pos.deepEquivalent(), m_selection.extent(), pos.affinity()), true, true, userTriggered);
     964    SetSelectionOptions options = CloseTyping | ClearTypingStyle;
     965    if (userTriggered)
     966        options |= UserTriggered;
     967    setSelection(VisibleSelection(pos.deepEquivalent(), m_selection.extent(), pos.affinity()), options);
    946968}
    947969
    948970void SelectionController::setExtent(const VisiblePosition &pos, bool userTriggered)
    949971{
    950     setSelection(VisibleSelection(m_selection.base(), pos.deepEquivalent(), pos.affinity()), true, true, userTriggered);
     972    SetSelectionOptions options = CloseTyping | ClearTypingStyle;
     973    if (userTriggered)
     974        options |= UserTriggered;
     975    setSelection(VisibleSelection(m_selection.base(), pos.deepEquivalent(), pos.affinity()), options);
    951976}
    952977
    953978void SelectionController::setBase(const Position &pos, EAffinity affinity, bool userTriggered)
    954979{
    955     setSelection(VisibleSelection(pos, m_selection.extent(), affinity), true, true, userTriggered);
     980    SetSelectionOptions options = CloseTyping | ClearTypingStyle;
     981    if (userTriggered)
     982        options |= UserTriggered;
     983    setSelection(VisibleSelection(pos, m_selection.extent(), affinity), options);
    956984}
    957985
    958986void SelectionController::setExtent(const Position &pos, EAffinity affinity, bool userTriggered)
    959987{
    960     setSelection(VisibleSelection(m_selection.base(), pos, affinity), true, true, userTriggered);
     988    SetSelectionOptions options = CloseTyping | ClearTypingStyle;
     989    if (userTriggered)
     990        options |= UserTriggered;
     991    setSelection(VisibleSelection(m_selection.base(), pos, affinity), options);
    961992}
    962993
     
    13901421    VisiblePosition visibleStart(startContainer, startOffset, collapsed ? affinity : DOWNSTREAM);
    13911422    VisiblePosition visibleEnd(endContainer, endOffset, SEL_DEFAULT_AFFINITY);
    1392     setSelection(VisibleSelection(visibleStart, visibleEnd), closeTyping);
     1423    SetSelectionOptions options = ClearTypingStyle;
     1424    if (closeTyping)
     1425        options |= CloseTyping;
     1426    setSelection(VisibleSelection(visibleStart, visibleEnd), options);
    13931427    return true;
    13941428}
  • trunk/Source/WebCore/editing/SelectionController.h

    r76248 r78632  
    5555    enum CursorAlignOnScroll { AlignCursorOnScrollIfNeeded,
    5656                               AlignCursorOnScrollAlways };
     57    enum SetSelectionOption {
     58        CloseTyping = 1 << 0,
     59        ClearTypingStyle = 1 << 1,
     60        UserTriggered = 1 << 2,
     61        SpellCorrectionTriggered = 1 << 3,
     62    };
     63    typedef unsigned SetSelectionOptions;
    5764
    5865    SelectionController(Frame* = 0, bool isDragCaretController = false);
     
    7077
    7178    const VisibleSelection& selection() const { return m_selection; }
    72     void setSelection(const VisibleSelection&, bool closeTyping = true, bool clearTypingStyle = true, bool userTriggered = false, CursorAlignOnScroll = AlignCursorOnScrollIfNeeded, TextGranularity = CharacterGranularity, DirectionalityPolicy = MakeDirectionalSelection);
    73     void setSelection(const VisibleSelection& selection, TextGranularity granularity, DirectionalityPolicy directionality = MakeDirectionalSelection) { setSelection(selection, true, true, false, AlignCursorOnScrollIfNeeded, granularity, directionality); }
     79    void setSelection(const VisibleSelection&, SetSelectionOptions = CloseTyping | ClearTypingStyle, CursorAlignOnScroll = AlignCursorOnScrollIfNeeded, TextGranularity = CharacterGranularity, DirectionalityPolicy = MakeDirectionalSelection);
     80    void setSelection(const VisibleSelection& selection, TextGranularity granularity, DirectionalityPolicy directionality = MakeDirectionalSelection) { setSelection(selection, CloseTyping | ClearTypingStyle, AlignCursorOnScrollIfNeeded, granularity, directionality); }
    7481    bool setSelectedRange(Range*, EAffinity, bool closeTyping);
    7582    void selectAll();
  • trunk/Source/WebCore/loader/EmptyClients.h

    r78533 r78632  
    513513    virtual void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel) { }
    514514    virtual bool isShowingCorrectionPanel() { return false; }
     515    virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String&, const String&) { }
    515516#endif
    516517    virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail&) { }
  • trunk/Source/WebCore/page/ContextMenuController.cpp

    r78480 r78632  
    279279        if (frame->editor()->shouldInsertText(item->title(), frame->selection()->toNormalizedRange().get(), EditorInsertActionPasted)) {
    280280            Document* document = frame->document();
    281             RefPtr<ReplaceSelectionCommand> command = ReplaceSelectionCommand::create(document, createFragmentFromMarkup(document, item->title(), ""), true, false, true);
     281            RefPtr<ReplaceSelectionCommand> command = ReplaceSelectionCommand::create(document, createFragmentFromMarkup(document, item->title(), ""), ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting);
    282282            applyCommand(command);
    283283            frame->selection()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
  • trunk/Source/WebCore/page/DragController.cpp

    r78590 r78632  
    467467            applyCommand(MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert, smartDelete));
    468468        } else {
    469             if (setSelectionToDragCaret(innerFrame, dragCaret, range, point))
    470                 applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse.get(), fragment, true, dragData->canSmartReplace(), chosePlainText));
     469            if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) {
     470                ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting;
     471                if (dragData->canSmartReplace())
     472                    options |= ReplaceSelectionCommand::SmartReplace;
     473                if (chosePlainText)
     474                    options |= ReplaceSelectionCommand::MatchStyle;
     475                applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse.get(), fragment, options));
     476            }
    471477        }
    472478    } else {
     
    479485        m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData);
    480486        if (setSelectionToDragCaret(innerFrame, dragCaret, range, point))
    481             applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse.get(), createFragmentFromText(range.get(), text), true, false, true));
     487            applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse.get(), createFragmentFromText(range.get(), text),  ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting));
    482488    }
    483489    cachedResourceLoader->setAllowStaleResources(false);
  • trunk/Source/WebCore/page/EditorClient.h

    r78534 r78632  
    162162
    163163#if SUPPORT_AUTOCORRECTION_PANEL
     164    enum AutocorrectionResponseType {
     165        AutocorrectionEdited,
     166        AutocorrectionReverted
     167    };
    164168    virtual void showCorrectionPanel(CorrectionPanelInfo::PanelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacmentString, const Vector<String>& alternativeReplacementStrings, Editor*) = 0;
    165169    virtual void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel) = 0;
    166170    virtual bool isShowingCorrectionPanel() = 0;
     171    virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString) = 0;
    167172#endif
    168173
  • trunk/Source/WebKit/chromium/ChangeLog

    r78620 r78632  
     12011-02-15  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Autocorrection should respect undo.
     6        https://bugs.webkit.org/show_bug.cgi?id=52221
     7        <rdar://problem/8663399>
     8
     9        Please see WebCore/ChangeLog for detailed description.
     10
     11        * WebCoreSupport/WebEditorClient.cpp:
     12        (WebFrameImpl::replaceSelection): Adopted new signature of ReplaceSelectionCommand::create().
     13
    1142011-02-15  Kenneth Russell  <kbr@google.com>
    215
  • trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp

    r78342 r78632  
    10581058        frame()->selection()->toNormalizedRange().get(), text);
    10591059    applyCommand(ReplaceSelectionCommand::create(
    1060         frame()->document(), fragment.get(), false, true, true));
     1060        frame()->document(), fragment.get(), ReplaceSelectionCommand::SmartReplace | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting));
    10611061}
    10621062
  • trunk/Source/WebKit/mac/ChangeLog

    r78627 r78632  
     12011-02-15  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Autocorrection should respect undo.
     6        https://bugs.webkit.org/show_bug.cgi?id=52221
     7        <rdar://problem/8663399>
     8
     9        Please see WebCore/ChangeLog for detailed description.
     10
     11        * WebCoreSupport/WebEditorClient.h: Updated for the new function declared in EditorClient.
     12
     13        * WebCoreSupport/WebEditorClient.mm:
     14        (WebEditorClient::recordAutocorrectionResponse): Ditto.
     15
     16        * WebView/WebFrame.mm:
     17        (-[WebFrame _replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:]):
     18             Adopted new signature of ReplaceSelectionCommand::create().
     19
    1202011-02-15  David Kilzer  <ddkilzer@apple.com>
    221
     
    2746        (-[WebView _setMinimumTimerInterval:]):
    2847        * WebView/WebViewPrivate.h:
    29 
    30 2011-01-26  MORITA Hajime  <morrita@google.com>
    31 
    32         Reviewed by Ryosuke Niwa.
    33 
    34         Refactoring: Extract TextCheckerClient from EditorClient
    35         https://bugs.webkit.org/show_bug.cgi?id=53213
    36 
    37         * WebCoreSupport/WebEditorClient.h:
    38         (WebEditorClient::textChecker):
    39 
    40 2011-02-07  Ryosuke Niwa  <rniwa@webkit.org>
    41 
    42         Reviewed by Adam Barth.
    43 
    44         Add EditorClient callbacks to override isDOMPasteAllowed and javaScriptCanAccessClipboard
    45         https://bugs.webkit.org/show_bug.cgi?id=52417
    46 
    47         Added two callback functions, canCopyCut and canPaste to EditorClient. They are currently
    48         not implemented.
    49 
    50         * WebCoreSupport/WebEditorClient.h:
    51         * WebCoreSupport/WebEditorClient.mm:
    52         (WebEditorClient::canCopyCut): Added.
    53         (WebEditorClient::canPaste): Added.
    5448
    55492011-02-11  Geoffrey Garen  <ggaren@apple.com>
  • trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h

    r78533 r78632  
    145145    virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel);
    146146    virtual bool isShowingCorrectionPanel();
     147    virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const WTF::String& replacedString, const WTF::String& replacementString);
    147148#endif
    148149private:
  • trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm

    r78532 r78632  
    963963    return m_correctionPanelIsShown;
    964964}
     965
     966void WebEditorClient::recordAutocorrectionResponse(EditorClient::AutocorrectionResponseType responseType, const String& replacedString, const String& replacementString)
     967{
     968    NSCorrectionResponse spellCheckerResponse = responseType == EditorClient::AutocorrectionReverted ? NSCorrectionResponseReverted : NSCorrectionResponseEdited;
     969    [[NSSpellChecker sharedSpellChecker] recordResponse:spellCheckerResponse toCorrection:replacementString forWord:replacedString language:nil inSpellDocumentWithTag:[m_webView spellCheckerDocumentTag]];
     970}
    965971#endif
    966972
  • trunk/Source/WebKit/mac/WebView/WebFrame.mm

    r78342 r78632  
    11371137    if (_private->coreFrame->selection()->isNone() || !fragment)
    11381138        return;
    1139    
    1140     applyCommand(ReplaceSelectionCommand::create(_private->coreFrame->document(), core(fragment), selectReplacement, smartReplace, matchStyle));
     1139    ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::PreventNesting;
     1140    if (selectReplacement)
     1141        options |= ReplaceSelectionCommand::SelectReplacement;
     1142    if (smartReplace)
     1143        options |= ReplaceSelectionCommand::SmartReplace;
     1144    if (matchStyle)
     1145        options |= ReplaceSelectionCommand::MatchStyle;
     1146    applyCommand(ReplaceSelectionCommand::create(_private->coreFrame->document(), core(fragment), options));
    11411147    _private->coreFrame->selection()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
    11421148}
  • trunk/Source/WebKit2/ChangeLog

    r78624 r78632  
     12011-02-15  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Autocorrection should respect undo.
     6        https://bugs.webkit.org/show_bug.cgi?id=52221
     7        <rdar://problem/8663399>
     8
     9        Please see WebCore/ChangeLog for detailed description.
     10
     11        * WebProcess/WebCoreSupport/WebEditorClient.h: Updated for the new function declared in EditorClient.
     12
     13        * WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm:
     14        (WebKit::WebEditorClient::recordAutocorrectionResponse): Ditto.
     15
     16        * WebProcess/WebPage/WebPage.cpp:
     17        (WebKit::WebPage::replaceSelectionWithText): Adopted new signature of ReplaceSelectionCommand::create().
     18
    1192011-02-15  Jessie Berlin  <jberlin@apple.com>
    220
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h

    r78533 r78632  
    146146    virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel);
    147147    virtual bool isShowingCorrectionPanel();
     148    virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const WTF::String& replacedString, const WTF::String& replacementString);
    148149#endif
    149150    WebPage* m_page;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm

    r76991 r78632  
    265265    return false;
    266266}
     267
     268void WebEditorClient::recordAutocorrectionResponse(EditorClient::AutocorrectionResponseType responseType, const String& replacedString, const String& replacementString)
     269{
     270    notImplemented();
     271}
    267272#endif
    268273
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r78620 r78632  
    16651665    if (frame->selection()->isNone())
    16661666        return;
    1667    
     1667
    16681668    RefPtr<DocumentFragment> textFragment = createFragmentFromText(frame->selection()->toNormalizedRange().get(), text);
    1669     applyCommand(ReplaceSelectionCommand::create(frame->document(), textFragment.release(), true, false, true));
     1669    applyCommand(ReplaceSelectionCommand::create(frame->document(), textFragment.release(), ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting));
    16701670    frame->selection()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
    16711671}
Note: See TracChangeset for help on using the changeset viewer.