2011-04-20 Jia Pu <jpu@apple.com>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Apr 2011 23:35:15 +0000 (23:35 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Apr 2011 23:35:15 +0000 (23:35 +0000)
        Reviewed by Adele Peterson.

        [Mac] Like autocorrection, other types of substitution need to respect undo.
        https://bugs.webkit.org/show_bug.cgi?id=59009
        <rdar://problem/8601537>

        Similar to autocorrection, we use SpellingCorrectionCommand to carry out other types of text substitution, so that
        if user undoes the substitution, it will not be applied again. For CreateLinkCommand,  we add marker when it's undone
        so that we won't automatically add link again.

        * editing/CreateLinkCommand.h:
        (WebCore::CreateLinkCommand::isCreateLinkCommand):
        * editing/EditCommand.cpp:
        (WebCore::EditCommand::isCreateLinkCommand):
        * editing/EditCommand.h:
        * editing/Editor.cpp:
        (WebCore::Editor::unappliedEditing):
        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
        * editing/SpellingCorrectionController.cpp:
        (WebCore::SpellingCorrectionController::respondToAppliedEditing):
        (WebCore::SpellingCorrectionController::respondToUnappliedEditing):
        * editing/SpellingCorrectionController.h:
        (WebCore::SpellingCorrectionController::UNLESS_ENABLED):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@84433 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/editing/CreateLinkCommand.h
Source/WebCore/editing/EditCommand.cpp
Source/WebCore/editing/EditCommand.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/SpellingCorrectionController.cpp
Source/WebCore/editing/SpellingCorrectionController.h

index 214795cb8ccbea12ade350ecd8639a5992b0903b..c7323b87449e5c16b8e75be1b338844dcabed074 100644 (file)
@@ -1,3 +1,29 @@
+2011-04-20  Jia Pu  <jpu@apple.com>
+
+        Reviewed by Adele Peterson.
+    
+        [Mac] Like autocorrection, other types of substitution need to respect undo.
+        https://bugs.webkit.org/show_bug.cgi?id=59009
+        <rdar://problem/8601537>
+
+        Similar to autocorrection, we use SpellingCorrectionCommand to carry out other types of text substitution, so that
+        if user undoes the substitution, it will not be applied again. For CreateLinkCommand,  we add marker when it's undone
+        so that we won't automatically add link again.
+
+        * editing/CreateLinkCommand.h:
+        (WebCore::CreateLinkCommand::isCreateLinkCommand):
+        * editing/EditCommand.cpp:
+        (WebCore::EditCommand::isCreateLinkCommand):
+        * editing/EditCommand.h:
+        * editing/Editor.cpp:
+        (WebCore::Editor::unappliedEditing):
+        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
+        * editing/SpellingCorrectionController.cpp:
+        (WebCore::SpellingCorrectionController::respondToAppliedEditing):
+        (WebCore::SpellingCorrectionController::respondToUnappliedEditing):
+        * editing/SpellingCorrectionController.h:
+        (WebCore::SpellingCorrectionController::UNLESS_ENABLED):
+
 2011-04-20  Steve Lacey  <sjl@chromium.org>
 
         Reviewed by Eric Carlson.
 2011-04-20  Steve Lacey  <sjl@chromium.org>
 
         Reviewed by Eric Carlson.
index ba5fe6f38cd76c53f7c31bc81b691187db9925dc..049fa8c2958f482218c356b6d66e5b2067642c40 100644 (file)
@@ -37,6 +37,8 @@ public:
         return adoptRef(new CreateLinkCommand(document, linkURL));
     }
 
         return adoptRef(new CreateLinkCommand(document, linkURL));
     }
 
+    bool isCreateLinkCommand() const { return true; }
+
 private:
     CreateLinkCommand(Document*, const String& linkURL);
 
 private:
     CreateLinkCommand(Document*, const String& linkURL);
 
index 7b0eab48fb69fa24863d414dae38675c02726d58..9f8b225a5852c0236be6a14224ff6a32930f497c 100644 (file)
@@ -194,6 +194,11 @@ bool EditCommand::isTypingCommand() const
     return false;
 }
 
     return false;
 }
 
+bool EditCommand::isCreateLinkCommand() const
+{
+    return false;
+}
+
 bool EditCommand::shouldRetainAutocorrectionIndicator() const
 {
     return false;
 bool EditCommand::shouldRetainAutocorrectionIndicator() const
 {
     return false;
index 8ee37fe96cc27b9e1a3df3089651eba2f8fa4446..dc20eec745e11d456ad6772d8e4231a4ce113962 100644 (file)
@@ -54,6 +54,7 @@ public:
     
     virtual bool isInsertTextCommand() const;
     virtual bool isTypingCommand() const;
     
     virtual bool isInsertTextCommand() const;
     virtual bool isTypingCommand() const;
+    virtual bool isCreateLinkCommand() const;
     
     virtual bool preservesTypingStyle() const;
 
     
     virtual bool preservesTypingStyle() const;
 
index e7c5c1d8a82b6c884bd4eab7cbfd5896ace77b8e..995ebeaf13f38ad65a93f315b42f96b8fffbfb54 100644 (file)
@@ -1021,6 +1021,7 @@ void Editor::unappliedEditing(PassRefPtr<EditCommand> cmd)
     
     VisibleSelection newSelection(cmd->startingSelection());
     changeSelectionAfterCommand(newSelection, true, true);
     
     VisibleSelection newSelection(cmd->startingSelection());
     changeSelectionAfterCommand(newSelection, true, true);
+    m_spellingCorrector->respondToUnappliedEditing(cmd.get());
     
     m_lastEditCommand = 0;
     if (client())
     
     m_lastEditCommand = 0;
     if (client())
@@ -2232,18 +2233,16 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
             if (result->type == TextCheckingTypeLink && selectionOffset > resultLocation + resultLength + 1)
                 continue;
 
             if (result->type == TextCheckingTypeLink && selectionOffset > resultLocation + resultLength + 1)
                 continue;
 
-            String replacedString;
+            String replacedString = plainText(rangeToReplace.get());
 
             // Don't correct spelling in an already-corrected word.
 
             // Don't correct spelling in an already-corrected word.
-            if (result->type == TextCheckingTypeCorrection) {
-                replacedString = plainText(rangeToReplace.get());
-                DocumentMarkerController* markers = m_frame->document()->markers();
-                if (markers->hasMarkers(rangeToReplace.get(), DocumentMarker::Replacement)) {
-                    doReplacement = false;
+            DocumentMarkerController* markers = m_frame->document()->markers();
+            if (markers->hasMarkers(rangeToReplace.get(), DocumentMarker::Replacement)) {
+                doReplacement = false;
+                if (result->type == TextCheckingTypeCorrection)
                     m_spellingCorrector->recordSpellcheckerResponseForModifiedCorrection(rangeToReplace.get(), replacedString, result->replacement);
                     m_spellingCorrector->recordSpellcheckerResponseForModifiedCorrection(rangeToReplace.get(), replacedString, result->replacement);
-                } else if (markers->hasMarkers(rangeToReplace.get(), DocumentMarker::RejectedCorrection))
-                    doReplacement = false;
-            }
+            } else if (markers->hasMarkers(rangeToReplace.get(), DocumentMarker::RejectedCorrection))
+                doReplacement = false;
 
             if (!(shouldPerformReplacement || shouldShowCorrectionPanel) || !doReplacement)
                 continue;
 
             if (!(shouldPerformReplacement || shouldShowCorrectionPanel) || !doReplacement)
                 continue;
@@ -2272,12 +2271,7 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
                 if (canEditRichly())
                     applyCommand(CreateLinkCommand::create(m_frame->document(), result->replacement));
             } else if (canEdit() && shouldInsertText(result->replacement, rangeToReplace.get(), EditorInsertActionTyped)) {
                 if (canEditRichly())
                     applyCommand(CreateLinkCommand::create(m_frame->document(), result->replacement));
             } else if (canEdit() && shouldInsertText(result->replacement, rangeToReplace.get(), EditorInsertActionTyped)) {
-                if (result->type == TextCheckingTypeCorrection)
-                    applyCommand(SpellingCorrectionCommand::create(rangeToReplace, result->replacement));
-                else {
-                    m_frame->selection()->setSelection(selectionToReplace);
-                    replaceSelectionWithText(result->replacement, false, false);
-                }
+                applyCommand(SpellingCorrectionCommand::create(rangeToReplace, result->replacement));
 
                 if (AXObjectCache::accessibilityEnabled()) {
                     if (Element* root = m_frame->selection()->selection().rootEditableElement())
 
                 if (AXObjectCache::accessibilityEnabled()) {
                     if (Element* root = m_frame->selection()->selection().rootEditableElement())
index c377fe8a623833ecd19ff3a1a857c339b53e37a3..5a3f51855c928d8c7e9be69f5643529df524ac6e 100644 (file)
@@ -409,12 +409,24 @@ void SpellingCorrectionController::respondToChangedSelection(const VisibleSelect
     }
 }
 
     }
 }
 
-void SpellingCorrectionController::respondToAppliedEditing(PassRefPtr<EditCommand> command)
+void SpellingCorrectionController::respondToAppliedEditing(EditCommand* command)
 {
     if (command->isTopLevelCommand() && !command->shouldRetainAutocorrectionIndicator())
         m_frame->document()->markers()->removeMarkers(DocumentMarker::CorrectionIndicator);
 }
 
 {
     if (command->isTopLevelCommand() && !command->shouldRetainAutocorrectionIndicator())
         m_frame->document()->markers()->removeMarkers(DocumentMarker::CorrectionIndicator);
 }
 
+void SpellingCorrectionController::respondToUnappliedEditing(EditCommand* command)
+{
+    if (!command->isCreateLinkCommand())
+        return;
+    RefPtr<Range> range = Range::create(m_frame->document(), command->startingSelection().start(), command->startingSelection().end());
+    if (!range)
+        return;
+    DocumentMarkerController* markers = m_frame->document()->markers();
+    markers->addMarker(range.get(), DocumentMarker::Replacement);
+    markers->addMarker(range.get(), DocumentMarker::SpellCheckingExemption);
+}
+
 EditorClient* SpellingCorrectionController::client()
 {
     return m_frame->page() ? m_frame->page()->editorClient() : 0;
 EditorClient* SpellingCorrectionController::client()
 {
     return m_frame->page() ? m_frame->page()->editorClient() : 0;
index 691510a3303c025c97048e041b0d1c2a6a0bd9ab..0b3e8b7bd91418a7ac81ff05d5138f75ea59f673 100644 (file)
@@ -96,7 +96,8 @@ public:
     bool applyAutocorrectionBeforeTypingIfAppropriate() UNLESS_ENABLED({ return false; })
 
     void respondToUnappliedSpellCorrection(const VisibleSelection&, const String& corrected, const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(corrected); UNUSED_PARAM(correction); })
     bool applyAutocorrectionBeforeTypingIfAppropriate() UNLESS_ENABLED({ return false; })
 
     void respondToUnappliedSpellCorrection(const VisibleSelection&, const String& corrected, const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(corrected); UNUSED_PARAM(correction); })
-    void respondToAppliedEditing(PassRefPtr<EditCommand>) UNLESS_ENABLED({})
+    void respondToAppliedEditing(EditCommand*) UNLESS_ENABLED({})
+    void respondToUnappliedEditing(EditCommand*) UNLESS_ENABLED({})
     void respondToChangedSelection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); })
 
     void stopPendingCorrection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); })
     void respondToChangedSelection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); })
 
     void stopPendingCorrection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); })