WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch (v1)
bug-82942-20120402135852.patch (text/plain), 176.36 KB, created by
Jia Pu
on 2012-04-02 13:58:53 PDT
(
hide
)
Description:
Patch (v1)
Filename:
MIME Type:
Creator:
Jia Pu
Created:
2012-04-02 13:58:53 PDT
Size:
176.36 KB
patch
obsolete
>Index: Source/WebCore/ChangeLog >=================================================================== >--- Source/WebCore/ChangeLog (revision 112931) >+++ Source/WebCore/ChangeLog (working copy) >@@ -1,3 +1,106 @@ >+2012-04-02 Jia Pu <jpu@apple.com> >+ >+ Rename SpellingCorrectionController to AlternativeTextController. >+ https://bugs.webkit.org/show_bug.cgi?id=82942 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ No new tests, since there's no change of funcationalities. >+ >+ This patch renames SpellingCorrectionController to AlternativeTextController, CorrectionPanelInfo to >+ AlternativeTextInfo, CorrectionPanelInfo::CorretionPanelType to AlternativeTextType, and ReasonForDismissingCorrectionPanel >+ to ReasonForDismissingAlternativeText. All these renaming reflects the fact that this class controls change >+ of text caused by both spell checking and alternative dictation results. It also renames a couple of functions >+ in the original SpellingCorrectionController class for the same reason. >+ >+ SpellingCorrectionPanel::replacementString has been replaced by AlternativeTextInfo::details which is an object >+ that can be instantiated with different subclasses. >+ >+ * CMakeLists.txt: >+ * Target.pri: >+ * WebCore.exp.in: >+ * WebCore.gypi: >+ * WebCore.vcproj/WebCore.vcproj: >+ * WebCore.xcodeproj/project.pbxproj: >+ * editing/AlternativeTextController.cpp: Copied from Source/WebCore/editing/SpellingCorrectionController.cpp. >+ (AutocorrectionAlternativeDetails): >+ (WebCore::AutocorrectionAlternativeDetails::create): >+ (WebCore::AutocorrectionAlternativeDetails::replacementString): >+ (WebCore::AutocorrectionAlternativeDetails::AutocorrectionAlternativeDetails): >+ (WebCore): >+ (WebCore::AlternativeTextController::AlternativeTextController): >+ (WebCore::AlternativeTextController::~AlternativeTextController): >+ (WebCore::AlternativeTextController::startAlternativeTextUITimer): >+ (WebCore::AlternativeTextController::stopAlternativeTextUITimer): >+ (WebCore::AlternativeTextController::stopPendingCorrection): >+ (WebCore::AlternativeTextController::applyPendingCorrection): >+ (WebCore::AlternativeTextController::hasPendingCorrection): >+ (WebCore::AlternativeTextController::isSpellingMarkerAllowed): >+ (WebCore::AlternativeTextController::show): >+ (WebCore::AlternativeTextController::handleCancelOperation): >+ (WebCore::AlternativeTextController::dismiss): >+ (WebCore::AlternativeTextController::dismissSoon): >+ (WebCore::AlternativeTextController::applyAlternativeText): >+ (WebCore::AlternativeTextController::applyAutocorrectionBeforeTypingIfAppropriate): >+ (WebCore::AlternativeTextController::respondToUnappliedSpellCorrection): >+ (WebCore::AlternativeTextController::timerFired): >+ (WebCore::AlternativeTextController::handleAlternativeTextUIResult): >+ (WebCore::AlternativeTextController::isAutomaticSpellingCorrectionEnabled): >+ (WebCore::AlternativeTextController::rootViewRectForRange): >+ (WebCore::AlternativeTextController::respondToChangedSelection): >+ (WebCore::AlternativeTextController::respondToAppliedEditing): >+ (WebCore::AlternativeTextController::respondToUnappliedEditing): >+ (WebCore::AlternativeTextController::client): >+ (WebCore::AlternativeTextController::textChecker): >+ (WebCore::AlternativeTextController::recordAutocorrectionResponseReversed): >+ (WebCore::AlternativeTextController::markReversed): >+ (WebCore::AlternativeTextController::markCorrection): >+ (WebCore::AlternativeTextController::recordSpellcheckerResponseForModifiedCorrection): >+ (WebCore::AlternativeTextController::deletedAutocorrectionAtPosition): >+ (WebCore::AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand): >+ (WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult): >+ * editing/AlternativeTextController.h: Copied from Source/WebCore/editing/SpellingCorrectionController.h. >+ (AlternativeTextDetails): >+ (WebCore::AlternativeTextDetails::AlternativeTextDetails): >+ (WebCore::AlternativeTextDetails::~AlternativeTextDetails): >+ (WebCore): >+ (AlternativeTextInfo): >+ (AlternativeTextController): >+ (WebCore::AlternativeTextController::UNLESS_ENABLED): >+ (WebCore::AlternativeTextController::shouldRemoveMarkersUponEditing): >+ * editing/Editor.cpp: >+ (WebCore::Editor::respondToChangedSelection): >+ (WebCore::Editor::appliedEditing): >+ (WebCore::Editor::unappliedEditing): >+ (WebCore::Editor::Editor): >+ (WebCore::Editor::insertTextWithoutSendingTextEvent): >+ (WebCore::Editor::insertLineBreak): >+ (WebCore::Editor::insertParagraphSeparator): >+ (WebCore::Editor::isAutomaticSpellingCorrectionEnabled): >+ (WebCore::Editor::markMisspellingsAfterTypingToWord): >+ (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): >+ (WebCore::Editor::markAndReplaceFor): >+ (WebCore::Editor::changeBackToReplacedString): >+ (WebCore::Editor::unappliedSpellCorrection): >+ (WebCore::Editor::updateMarkersForWordsAffectedByEditing): >+ (WebCore::Editor::deletedAutocorrectionAtPosition): >+ (WebCore::Editor::startAlternativeTextUITimer): >+ (WebCore::Editor::handleAlternativeTextUIResult): >+ (WebCore::Editor::dismissCorrectionPanelAsIgnored): >+ * editing/Editor.h: >+ (WebCore): >+ (Editor): >+ * editing/SpellingCorrectionCommand.cpp: >+ * editing/SpellingCorrectionController.cpp: Removed. >+ * editing/SpellingCorrectionController.h: Removed. >+ * editing/TypingCommand.cpp: >+ (WebCore::TypingCommand::markMisspellingsAfterTyping): >+ * loader/EmptyClients.h: >+ (WebCore::EmptyEditorClient::showCorrectionPanel): >+ (WebCore::EmptyEditorClient::dismissCorrectionPanel): >+ (WebCore::EmptyEditorClient::dismissCorrectionPanelSoon): >+ * page/EditorClient.h: >+ > 2012-04-02 Michael Saboff <msaboff@apple.com> > > WebKit should throttle memory pressure notifications in proportion to handler time >Index: Source/WebCore/CMakeLists.txt >=================================================================== >--- Source/WebCore/CMakeLists.txt (revision 112917) >+++ Source/WebCore/CMakeLists.txt (working copy) >@@ -654,6 +654,7 @@ SET(WebCore_SOURCES > > dom/default/PlatformMessagePortChannel.cpp > >+ editing/AlternativeTextController.cpp > editing/AppendNodeCommand.cpp > editing/ApplyBlockElementCommand.cpp > editing/ApplyStyleCommand.cpp >@@ -693,7 +694,6 @@ SET(WebCore_SOURCES > editing/SetSelectionCommand.cpp > editing/SmartReplace.cpp > editing/SpellChecker.cpp >- editing/SpellingCorrectionController.cpp > editing/SpellingCorrectionCommand.cpp > editing/SplitElementCommand.cpp > editing/SplitTextNodeCommand.cpp >Index: Source/WebCore/Target.pri >=================================================================== >--- Source/WebCore/Target.pri (revision 112917) >+++ Source/WebCore/Target.pri (working copy) >@@ -628,6 +628,7 @@ SOURCES += \ > dom/WheelEvent.cpp \ > dom/WindowEventContext.cpp \ > dom/default/PlatformMessagePortChannel.cpp \ >+ editing/AlternativeTextController.cpp \ > editing/AppendNodeCommand.cpp \ > editing/ApplyBlockElementCommand.cpp \ > editing/ApplyStyleCommand.cpp \ >@@ -669,7 +670,6 @@ SOURCES += \ > editing/SetSelectionCommand.cpp \ > editing/SpellChecker.cpp \ > editing/SpellingCorrectionCommand.cpp \ >- editing/SpellingCorrectionController.cpp \ > editing/SplitElementCommand.cpp \ > editing/SplitTextNodeCommand.cpp \ > editing/SplitTextNodeContainingElementCommand.cpp \ >@@ -1759,6 +1759,7 @@ HEADERS += \ > dom/WebKitNamedFlow.h \ > dom/WebKitTransitionEvent.h \ > dom/WheelEvent.h \ >+ editing/AlternativeTextController.h \ > editing/AppendNodeCommand.h \ > editing/ApplyBlockElementCommand.h \ > editing/ApplyStyleCommand.h \ >@@ -1800,7 +1801,6 @@ HEADERS += \ > editing/SetNodeAttributeCommand.h \ > editing/SmartReplace.h \ > editing/SpellingCorrectionCommand.h \ >- editing/SpellingCorrectionController.h \ > editing/SplitElementCommand.h \ > editing/SplitTextNodeCommand.h \ > editing/SplitTextNodeContainingElementCommand.h \ >Index: Source/WebCore/WebCore.exp.in >=================================================================== >--- Source/WebCore/WebCore.exp.in (revision 112917) >+++ Source/WebCore/WebCore.exp.in (working copy) >@@ -888,11 +888,11 @@ __ZN7WebCore6Editor24replaceSelectionWit > __ZN7WebCore6Editor26decreaseSelectionListLevelEv > __ZN7WebCore6Editor26increaseSelectionListLevelEv > __ZN7WebCore6Editor26writeSelectionToPasteboardERKN3WTF6StringERKNS1_6VectorIS2_Lm0EEE >-__ZN7WebCore6Editor27handleCorrectionPanelResultERKN3WTF6StringE > __ZN7WebCore6Editor27readSelectionFromPasteboardERKN3WTF6StringE > __ZN7WebCore6Editor28replaceSelectionWithFragmentEN3WTF10PassRefPtrINS_16DocumentFragmentEEEbbb > __ZN7WebCore6Editor29canDecreaseSelectionListLevelEv > __ZN7WebCore6Editor29canIncreaseSelectionListLevelEv >+__ZN7WebCore6Editor29handleAlternativeTextUIResultERKN3WTF6StringE > __ZN7WebCore6Editor30deleteSelectionWithSmartDeleteEb > __ZN7WebCore6Editor30pasteAsPlainTextBypassingDHTMLEv > __ZN7WebCore6Editor32guessesForUngrammaticalSelectionEv >Index: Source/WebCore/WebCore.gypi >=================================================================== >--- Source/WebCore/WebCore.gypi (revision 112917) >+++ Source/WebCore/WebCore.gypi (working copy) >@@ -2497,6 +2497,8 @@ > 'css/WebKitCSSShaderValue.cpp', > 'css/WebKitCSSShaderValue.h', > 'css/WebKitCSSTransformValue.cpp', >+ 'editing/AlternativeTextController.cpp', >+ 'editing/AlternativeTextController.h', > 'editing/AppendNodeCommand.cpp', > 'editing/AppendNodeCommand.h', > 'editing/ApplyBlockElementCommand.cpp', >@@ -2566,8 +2568,6 @@ > 'editing/SmartReplaceICU.cpp', > 'editing/SpellChecker.cpp', > 'editing/SpellChecker.h', >- 'editing/SpellingCorrectionController.cpp', >- 'editing/SpellingCorrectionController.h', > 'editing/SpellingCorrectionCommand.cpp', > 'editing/SpellingCorrectionCommand.h', > 'editing/SplitElementCommand.cpp', >Index: Source/WebCore/WebCore.vcproj/WebCore.vcproj >=================================================================== >--- Source/WebCore/WebCore.vcproj/WebCore.vcproj (revision 112917) >+++ Source/WebCore/WebCore.vcproj/WebCore.vcproj (working copy) >@@ -54074,6 +54074,62 @@ > > > </File> > </Filter> >+ <File >+ RelativePath="..\editing\AlternativeTextController.cpp" >+ > >+ <FileConfiguration >+ Name="Debug|Win32" >+ ExcludedFromBuild="true" >+ > >+ <Tool >+ Name="VCCLCompilerTool" >+ /> >+ </FileConfiguration> >+ <FileConfiguration >+ Name="Release|Win32" >+ ExcludedFromBuild="true" >+ > >+ <Tool >+ Name="VCCLCompilerTool" >+ /> >+ </FileConfiguration> >+ <FileConfiguration >+ Name="Debug_Cairo_CFLite|Win32" >+ ExcludedFromBuild="true" >+ > >+ <Tool >+ Name="VCCLCompilerTool" >+ /> >+ </FileConfiguration> >+ <FileConfiguration >+ Name="Release_Cairo_CFLite|Win32" >+ ExcludedFromBuild="true" >+ > >+ <Tool >+ Name="VCCLCompilerTool" >+ /> >+ </FileConfiguration> >+ <FileConfiguration >+ Name="Debug_All|Win32" >+ ExcludedFromBuild="true" >+ > >+ <Tool >+ Name="VCCLCompilerTool" >+ /> >+ </FileConfiguration> >+ <FileConfiguration >+ Name="Release_LTCG|Win32" >+ ExcludedFromBuild="true" >+ > >+ <Tool >+ Name="VCCLCompilerTool" >+ /> >+ </FileConfiguration> >+ </File> >+ <File >+ RelativePath="..\editing\AlternativeTextController.h" >+ > >+ </File> > <Filter > Name="editing" > > >@@ -56454,62 +56510,6 @@ > > > </File> > <File >- RelativePath="..\editing\SpellingCorrectionController.cpp" >- > >- <FileConfiguration >- Name="Debug|Win32" >- ExcludedFromBuild="true" >- > >- <Tool >- Name="VCCLCompilerTool" >- /> >- </FileConfiguration> >- <FileConfiguration >- Name="Release|Win32" >- ExcludedFromBuild="true" >- > >- <Tool >- Name="VCCLCompilerTool" >- /> >- </FileConfiguration> >- <FileConfiguration >- Name="Debug_Cairo_CFLite|Win32" >- ExcludedFromBuild="true" >- > >- <Tool >- Name="VCCLCompilerTool" >- /> >- </FileConfiguration> >- <FileConfiguration >- Name="Release_Cairo_CFLite|Win32" >- ExcludedFromBuild="true" >- > >- <Tool >- Name="VCCLCompilerTool" >- /> >- </FileConfiguration> >- <FileConfiguration >- Name="Debug_All|Win32" >- ExcludedFromBuild="true" >- > >- <Tool >- Name="VCCLCompilerTool" >- /> >- </FileConfiguration> >- <FileConfiguration >- Name="Release_LTCG|Win32" >- ExcludedFromBuild="true" >- > >- <Tool >- Name="VCCLCompilerTool" >- /> >- </FileConfiguration> >- </File> >- <File >- RelativePath="..\editing\SpellingCorrectionController.h" >- > >- </File> >- <File > RelativePath="..\editing\SplitElementCommand.cpp" > > > <FileConfiguration >Index: Source/WebCore/WebCore.xcodeproj/project.pbxproj >=================================================================== >--- Source/WebCore/WebCore.xcodeproj/project.pbxproj (revision 112917) >+++ Source/WebCore/WebCore.xcodeproj/project.pbxproj (working copy) >@@ -3701,8 +3701,6 @@ > A622A8FF122C44A600A785B3 /* GenericBinding.h in Headers */ = {isa = PBXBuildFile; fileRef = A622A8F9122C44A600A785B3 /* GenericBinding.h */; }; > A6D169621346B49B000EB770 /* ShadowRoot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A6D169611346B49B000EB770 /* ShadowRoot.cpp */; }; > A6D169641346B4C1000EB770 /* ShadowRoot.h in Headers */ = {isa = PBXBuildFile; fileRef = A6D169631346B4C1000EB770 /* ShadowRoot.h */; settings = {ATTRIBUTES = (Private, ); }; }; >- A7005CCC1330C4BA000CC0BA /* SpellingCorrectionController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7005CCA1330C4BA000CC0BA /* SpellingCorrectionController.cpp */; }; >- A7005CCD1330C4BA000CC0BA /* SpellingCorrectionController.h in Headers */ = {isa = PBXBuildFile; fileRef = A7005CCB1330C4BA000CC0BA /* SpellingCorrectionController.h */; settings = {ATTRIBUTES = (Private, ); }; }; > A7151BD812F1558F005A0F64 /* TextCheckerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A7151BD712F1558F005A0F64 /* TextCheckerClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; > A715E652134BBBEC00D8E713 /* ProgressShadowElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A715E650134BBBEC00D8E713 /* ProgressShadowElement.cpp */; }; > A715E653134BBBEC00D8E713 /* ProgressShadowElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A715E651134BBBEC00D8E713 /* ProgressShadowElement.h */; }; >@@ -5728,6 +5726,8 @@ > CE02F0C411E83ADD00C6684A /* ScriptControllerBase.h in Headers */ = {isa = PBXBuildFile; fileRef = CE02F0C311E83ADD00C6684A /* ScriptControllerBase.h */; settings = {ATTRIBUTES = (Private, ); }; }; > CE057FA51220731100A476D5 /* DocumentMarkerController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE057FA31220731100A476D5 /* DocumentMarkerController.cpp */; }; > CE057FA61220731100A476D5 /* DocumentMarkerController.h in Headers */ = {isa = PBXBuildFile; fileRef = CE057FA41220731100A476D5 /* DocumentMarkerController.h */; settings = {ATTRIBUTES = (Private, ); }; }; >+ CE30F8DE152A03E500C4CE14 /* AlternativeTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE30F8DC152A03E500C4CE14 /* AlternativeTextController.cpp */; }; >+ CE30F8DF152A03E500C4CE14 /* AlternativeTextController.h in Headers */ = {isa = PBXBuildFile; fileRef = CE30F8DD152A03E500C4CE14 /* AlternativeTextController.h */; settings = {ATTRIBUTES = (Private, ); }; }; > CE54FD381016D9A6008B44C8 /* ScriptSourceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = CE54FD371016D9A6008B44C8 /* ScriptSourceProvider.h */; settings = {ATTRIBUTES = (Private, ); }; }; > CEA3949C11D45CDA003094CF /* StaticHashSetNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEA3949A11D45CDA003094CF /* StaticHashSetNodeList.cpp */; }; > CEA3949D11D45CDA003094CF /* StaticHashSetNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = CEA3949B11D45CDA003094CF /* StaticHashSetNodeList.h */; }; >@@ -10700,8 +10700,6 @@ > A622A8F9122C44A600A785B3 /* GenericBinding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GenericBinding.h; path = generic/GenericBinding.h; sourceTree = "<group>"; }; > A6D169611346B49B000EB770 /* ShadowRoot.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShadowRoot.cpp; sourceTree = "<group>"; }; > A6D169631346B4C1000EB770 /* ShadowRoot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShadowRoot.h; sourceTree = "<group>"; }; >- A7005CCA1330C4BA000CC0BA /* SpellingCorrectionController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpellingCorrectionController.cpp; sourceTree = "<group>"; }; >- A7005CCB1330C4BA000CC0BA /* SpellingCorrectionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpellingCorrectionController.h; sourceTree = "<group>"; }; > A7151BD712F1558F005A0F64 /* TextCheckerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCheckerClient.h; sourceTree = "<group>"; }; > A715E650134BBBEC00D8E713 /* ProgressShadowElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProgressShadowElement.cpp; sourceTree = "<group>"; }; > A715E651134BBBEC00D8E713 /* ProgressShadowElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProgressShadowElement.h; sourceTree = "<group>"; }; >@@ -12815,6 +12813,8 @@ > CE02F0C311E83ADD00C6684A /* ScriptControllerBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptControllerBase.h; sourceTree = "<group>"; }; > CE057FA31220731100A476D5 /* DocumentMarkerController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentMarkerController.cpp; sourceTree = "<group>"; }; > CE057FA41220731100A476D5 /* DocumentMarkerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentMarkerController.h; sourceTree = "<group>"; }; >+ CE30F8DC152A03E500C4CE14 /* AlternativeTextController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AlternativeTextController.cpp; sourceTree = "<group>"; }; >+ CE30F8DD152A03E500C4CE14 /* AlternativeTextController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlternativeTextController.h; sourceTree = "<group>"; }; > CE54FD371016D9A6008B44C8 /* ScriptSourceProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptSourceProvider.h; sourceTree = "<group>"; }; > CE5CB1B314EDAB6F00BB2795 /* EventSender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventSender.h; sourceTree = "<group>"; }; > CEA3949A11D45CDA003094CF /* StaticHashSetNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticHashSetNodeList.cpp; sourceTree = "<group>"; }; >@@ -16575,6 +16575,8 @@ > isa = PBXGroup; > children = ( > ED501DC90B249F3900AE18D9 /* mac */, >+ CE30F8DC152A03E500C4CE14 /* AlternativeTextController.cpp */, >+ CE30F8DD152A03E500C4CE14 /* AlternativeTextController.h */, > 93309D87099E64910056E581 /* AppendNodeCommand.cpp */, > 93309D88099E64910056E581 /* AppendNodeCommand.h */, > 9B417063125662B3006B28FC /* ApplyBlockElementCommand.cpp */, >@@ -16666,8 +16668,6 @@ > A78FE13A12366B1000ACE8D0 /* SpellChecker.h */, > B8DBDB49130B0F8A00F5CDB1 /* SpellingCorrectionCommand.cpp */, > B8DBDB4A130B0F8A00F5CDB1 /* SpellingCorrectionCommand.h */, >- A7005CCA1330C4BA000CC0BA /* SpellingCorrectionController.cpp */, >- A7005CCB1330C4BA000CC0BA /* SpellingCorrectionController.h */, > 93309DC2099E64910056E581 /* SplitElementCommand.cpp */, > 93309DC3099E64910056E581 /* SplitElementCommand.h */, > 93309DC4099E64910056E581 /* SplitTextNodeCommand.cpp */, >@@ -21491,6 +21491,7 @@ > isa = PBXHeadersBuildPhase; > buildActionMask = 2147483647; > files = ( >+ CE30F8DF152A03E500C4CE14 /* AlternativeTextController.h in Headers */, > 97BC69DB1505F076001B74AC /* AbstractDatabase.h in Headers */, > 41E1B1D10FF5986900576B3B /* AbstractWorker.h in Headers */, > 29A8122E0FBB9C1D00510293 /* AccessibilityARIAGridCell.h in Headers */, >@@ -24076,7 +24077,6 @@ > 75415B0012958D5E003AD669 /* SpeechInputResultList.h in Headers */, > A78FE13C12366B1000ACE8D0 /* SpellChecker.h in Headers */, > B8DBDB4E130B0F8A00F5CDB1 /* SpellingCorrectionCommand.h in Headers */, >- A7005CCD1330C4BA000CC0BA /* SpellingCorrectionController.h in Headers */, > 93309E12099E64920056E581 /* SplitElementCommand.h in Headers */, > 93309E14099E64920056E581 /* SplitTextNodeCommand.h in Headers */, > 93309E16099E64920056E581 /* SplitTextNodeContainingElementCommand.h in Headers */, >@@ -27190,7 +27190,6 @@ > 75415C29129A9920003AD669 /* SpeechInputResultList.cpp in Sources */, > A78FE13B12366B1000ACE8D0 /* SpellChecker.cpp in Sources */, > B8DBDB4D130B0F8A00F5CDB1 /* SpellingCorrectionCommand.cpp in Sources */, >- A7005CCC1330C4BA000CC0BA /* SpellingCorrectionController.cpp in Sources */, > 93309E11099E64920056E581 /* SplitElementCommand.cpp in Sources */, > 93309E13099E64920056E581 /* SplitTextNodeCommand.cpp in Sources */, > 93309E15099E64920056E581 /* SplitTextNodeContainingElementCommand.cpp in Sources */, >@@ -27659,6 +27658,7 @@ > 1A3586E115264F950022A659 /* SVGAnimatedIntegerOptionalInteger.cpp in Sources */, > 1A3FF9C315265359002288A1 /* RenderNamedFlowThread.cpp in Sources */, > E1B25106152A0BAF0069B779 /* StylePropertyShorthand.cpp in Sources */, >+ CE30F8DE152A03E500C4CE14 /* AlternativeTextController.cpp in Sources */, > ); > runOnlyForDeploymentPostprocessing = 0; > }; >Index: Source/WebCore/editing/AlternativeTextController.cpp >=================================================================== >--- Source/WebCore/editing/AlternativeTextController.cpp (revision 112830) (from Source/WebCore/editing/SpellingCorrectionController.cpp:112830) >+++ Source/WebCore/editing/AlternativeTextController.cpp (working copy) >@@ -0,0 +1,565 @@ >+/* >+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. >+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR >+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "SpellingCorrectionController.h" >+ >+#include "DocumentMarkerController.h" >+#include "EditCommand.h" >+#include "EditorClient.h" >+#include "FloatQuad.h" >+#include "Frame.h" >+#include "FrameView.h" >+#include "Page.h" >+#include "SpellingCorrectionCommand.h" >+#include "TextCheckerClient.h" >+#include "TextCheckingHelper.h" >+#include "TextIterator.h" >+#include "VisibleSelection.h" >+#include "htmlediting.h" >+#include "markup.h" >+#include "visible_units.h" >+ >+namespace WebCore { >+ >+using namespace std; >+using namespace WTF; >+ >+#if USE(AUTOCORRECTION_PANEL) >+ >+static const Vector<DocumentMarker::MarkerType>& markerTypesForAutocorrection() >+{ >+ DEFINE_STATIC_LOCAL(Vector<DocumentMarker::MarkerType>, markerTypesForAutoCorrection, ()); >+ if (markerTypesForAutoCorrection.isEmpty()) { >+ markerTypesForAutoCorrection.append(DocumentMarker::Replacement); >+ markerTypesForAutoCorrection.append(DocumentMarker::CorrectionIndicator); >+ markerTypesForAutoCorrection.append(DocumentMarker::SpellCheckingExemption); >+ markerTypesForAutoCorrection.append(DocumentMarker::Autocorrected); >+ } >+ return markerTypesForAutoCorrection; >+} >+ >+static const Vector<DocumentMarker::MarkerType>& markerTypesForReplacement() >+{ >+ DEFINE_STATIC_LOCAL(Vector<DocumentMarker::MarkerType>, markerTypesForReplacement, ()); >+ if (markerTypesForReplacement.isEmpty()) { >+ markerTypesForReplacement.append(DocumentMarker::Replacement); >+ markerTypesForReplacement.append(DocumentMarker::SpellCheckingExemption); >+ } >+ return markerTypesForReplacement; >+} >+ >+static bool markersHaveIdenticalDescription(const Vector<DocumentMarker*>& markers) >+{ >+ if (markers.isEmpty()) >+ return true; >+ >+ const String& description = markers[0]->description(); >+ for (size_t i = 1; i < markers.size(); ++i) { >+ if (description != markers[i]->description()) >+ return false; >+ } >+ return true; >+} >+ >+SpellingCorrectionController::SpellingCorrectionController(Frame* frame) >+ : m_frame(frame) >+ , m_correctionPanelTimer(this, &SpellingCorrectionController::correctionPanelTimerFired) >+{ >+} >+ >+SpellingCorrectionController::~SpellingCorrectionController() >+{ >+ dismiss(ReasonForDismissingCorrectionPanelIgnored); >+} >+ >+void SpellingCorrectionController::startCorrectionPanelTimer(CorrectionPanelInfo::PanelType type) >+{ >+ const double correctionPanelTimerInterval = 0.3; >+ if (!isAutomaticSpellingCorrectionEnabled()) >+ return; >+ >+ // If type is PanelTypeReversion, then the new range has been set. So we shouldn't clear it. >+ if (type == CorrectionPanelInfo::PanelTypeCorrection) >+ m_correctionPanelInfo.rangeToBeReplaced.clear(); >+ m_correctionPanelInfo.panelType = type; >+ m_correctionPanelTimer.startOneShot(correctionPanelTimerInterval); >+} >+ >+void SpellingCorrectionController::stopCorrectionPanelTimer() >+{ >+ m_correctionPanelTimer.stop(); >+ m_correctionPanelInfo.rangeToBeReplaced.clear(); >+} >+ >+void SpellingCorrectionController::stopPendingCorrection(const VisibleSelection& oldSelection) >+{ >+ // Make sure there's no pending autocorrection before we call markMisspellingsAndBadGrammar() below. >+ VisibleSelection currentSelection(m_frame->selection()->selection()); >+ if (currentSelection == oldSelection) >+ return; >+ >+ stopCorrectionPanelTimer(); >+ dismiss(ReasonForDismissingCorrectionPanelIgnored); >+} >+ >+void SpellingCorrectionController::applyPendingCorrection(const VisibleSelection& selectionAfterTyping) >+{ >+ // Apply pending autocorrection before next round of spell checking. >+ bool doApplyCorrection = true; >+ VisiblePosition startOfSelection = selectionAfterTyping.visibleStart(); >+ VisibleSelection currentWord = VisibleSelection(startOfWord(startOfSelection, LeftWordIfOnBoundary), endOfWord(startOfSelection, RightWordIfOnBoundary)); >+ if (currentWord.visibleEnd() == startOfSelection) { >+ String wordText = plainText(currentWord.toNormalizedRange().get()); >+ if (wordText.length() > 0 && isAmbiguousBoundaryCharacter(wordText[wordText.length() - 1])) >+ doApplyCorrection = false; >+ } >+ if (doApplyCorrection) >+ handleCorrectionPanelResult(dismissSoon(ReasonForDismissingCorrectionPanelAccepted)); >+ else >+ m_correctionPanelInfo.rangeToBeReplaced.clear(); >+} >+ >+bool SpellingCorrectionController::hasPendingCorrection() const >+{ >+ return m_correctionPanelInfo.rangeToBeReplaced; >+} >+ >+bool SpellingCorrectionController::isSpellingMarkerAllowed(PassRefPtr<Range> misspellingRange) const >+{ >+ return !m_frame->document()->markers()->hasMarkers(misspellingRange.get(), DocumentMarker::SpellCheckingExemption); >+} >+ >+void SpellingCorrectionController::show(PassRefPtr<Range> rangeToReplace, const String& replacement) >+{ >+ FloatRect boundingBox = rootViewRectForRange(rangeToReplace.get()); >+ if (boundingBox.isEmpty()) >+ return; >+ m_correctionPanelInfo.replacedString = plainText(rangeToReplace.get()); >+ m_correctionPanelInfo.rangeToBeReplaced = rangeToReplace; >+ m_correctionPanelInfo.replacementString = replacement; >+ m_correctionPanelInfo.isActive = true; >+ client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, replacement, Vector<String>()); >+} >+ >+void SpellingCorrectionController::handleCancelOperation() >+{ >+ if (!m_correctionPanelInfo.isActive) >+ return; >+ m_correctionPanelInfo.isActive = false; >+ dismiss(ReasonForDismissingCorrectionPanelCancelled); >+} >+ >+void SpellingCorrectionController::dismiss(ReasonForDismissingCorrectionPanel reasonForDismissing) >+{ >+ if (!m_correctionPanelInfo.isActive) >+ return; >+ m_correctionPanelInfo.isActive = false; >+ m_correctionPanelIsDismissedByEditor = true; >+ if (client()) >+ client()->dismissCorrectionPanel(reasonForDismissing); >+} >+ >+String SpellingCorrectionController::dismissSoon(ReasonForDismissingCorrectionPanel reasonForDismissing) >+{ >+ if (!m_correctionPanelInfo.isActive) >+ return String(); >+ m_correctionPanelInfo.isActive = false; >+ m_correctionPanelIsDismissedByEditor = true; >+ if (!client()) >+ return String(); >+ return client()->dismissCorrectionPanelSoon(reasonForDismissing); >+} >+ >+void SpellingCorrectionController::applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>& markerTypesToAdd) >+{ >+ if (!m_correctionPanelInfo.rangeToBeReplaced) >+ return; >+ >+ ExceptionCode ec = 0; >+ RefPtr<Range> paragraphRangeContainingCorrection = m_correctionPanelInfo.rangeToBeReplaced->cloneRange(ec); >+ if (ec) >+ return; >+ >+ setStart(paragraphRangeContainingCorrection.get(), startOfParagraph(m_correctionPanelInfo.rangeToBeReplaced->startPosition())); >+ setEnd(paragraphRangeContainingCorrection.get(), endOfParagraph(m_correctionPanelInfo.rangeToBeReplaced->endPosition())); >+ >+ // After we replace the word at range rangeToBeReplaced, we need to add markers to that range. >+ // However, once the replacement took place, the value of rangeToBeReplaced is not valid anymore. >+ // So before we carry out the replacement, we need to store the start position of rangeToBeReplaced >+ // relative to the start position of the containing paragraph. We use correctionStartOffsetInParagraph >+ // to store this value. In order to obtain this offset, we need to first create a range >+ // which spans from the start of paragraph to the start position of rangeToBeReplaced. >+ RefPtr<Range> correctionStartOffsetInParagraphAsRange = Range::create(paragraphRangeContainingCorrection->startContainer(ec)->document(), paragraphRangeContainingCorrection->startPosition(), paragraphRangeContainingCorrection->startPosition()); >+ if (ec) >+ return; >+ >+ Position startPositionOfRangeToBeReplaced = m_correctionPanelInfo.rangeToBeReplaced->startPosition(); >+ correctionStartOffsetInParagraphAsRange->setEnd(startPositionOfRangeToBeReplaced.containerNode(), startPositionOfRangeToBeReplaced.computeOffsetInContainerNode(), ec); >+ if (ec) >+ return; >+ >+ // Take note of the location of autocorrection so that we can add marker after the replacement took place. >+ int correctionStartOffsetInParagraph = TextIterator::rangeLength(correctionStartOffsetInParagraphAsRange.get()); >+ >+ // Clone the range, since the caller of this method may want to keep the original range around. >+ RefPtr<Range> rangeToBeReplaced = m_correctionPanelInfo.rangeToBeReplaced->cloneRange(ec); >+ applyCommand(SpellingCorrectionCommand::create(rangeToBeReplaced, m_correctionPanelInfo.replacementString)); >+ setEnd(paragraphRangeContainingCorrection.get(), m_frame->selection()->selection().start()); >+ RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, m_correctionPanelInfo.replacementString.length()); >+ String newText = plainText(replacementRange.get()); >+ >+ // Check to see if replacement succeeded. >+ if (newText != m_correctionPanelInfo.replacementString) >+ return; >+ >+ DocumentMarkerController* markers = replacementRange->startContainer()->document()->markers(); >+ size_t size = markerTypesToAdd.size(); >+ for (size_t i = 0; i < size; ++i) { >+ DocumentMarker::MarkerType markerType = markerTypesToAdd[i]; >+ String description; >+ if (m_correctionPanelInfo.panelType != CorrectionPanelInfo::PanelTypeReversion && (markerType == DocumentMarker::Replacement || markerType == DocumentMarker::Autocorrected)) >+ description = m_correctionPanelInfo.replacedString; >+ markers->addMarker(replacementRange.get(), markerType, description); >+ } >+} >+ >+bool SpellingCorrectionController::applyAutocorrectionBeforeTypingIfAppropriate() >+{ >+ if (!m_correctionPanelInfo.rangeToBeReplaced || !m_correctionPanelInfo.isActive) >+ return false; >+ >+ if (m_correctionPanelInfo.panelType != CorrectionPanelInfo::PanelTypeCorrection) >+ return false; >+ >+ Position caretPosition = m_frame->selection()->selection().start(); >+ >+ if (m_correctionPanelInfo.rangeToBeReplaced->endPosition() == caretPosition) { >+ handleCorrectionPanelResult(dismissSoon(ReasonForDismissingCorrectionPanelAccepted)); >+ return true; >+ } >+ >+ // Pending correction should always be where caret is. But in case this is not always true, we still want to dismiss the panel without accepting the correction. >+ ASSERT(m_correctionPanelInfo.rangeToBeReplaced->endPosition() == caretPosition); >+ dismiss(ReasonForDismissingCorrectionPanelIgnored); >+ return false; >+} >+ >+void SpellingCorrectionController::respondToUnappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction) >+{ >+ client()->recordAutocorrectionResponse(EditorClient::AutocorrectionReverted, corrected, correction); >+ m_frame->document()->updateLayout(); >+ m_frame->selection()->setSelection(selectionOfCorrected, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::SpellCorrectionTriggered); >+ RefPtr<Range> range = Range::create(m_frame->document(), m_frame->selection()->selection().start(), m_frame->selection()->selection().end()); >+ >+ DocumentMarkerController* markers = m_frame->document()->markers(); >+ markers->removeMarkers(range.get(), DocumentMarker::Spelling | DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker); >+ markers->addMarker(range.get(), DocumentMarker::Replacement); >+ markers->addMarker(range.get(), DocumentMarker::SpellCheckingExemption); >+} >+ >+void SpellingCorrectionController::correctionPanelTimerFired(Timer<SpellingCorrectionController>*) >+{ >+ m_correctionPanelIsDismissedByEditor = false; >+ switch (m_correctionPanelInfo.panelType) { >+ case CorrectionPanelInfo::PanelTypeCorrection: { >+ VisibleSelection selection(m_frame->selection()->selection()); >+ VisiblePosition start(selection.start(), selection.affinity()); >+ VisiblePosition p = startOfWord(start, LeftWordIfOnBoundary); >+ VisibleSelection adjacentWords = VisibleSelection(p, start); >+ m_frame->editor()->markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeSpelling | TextCheckingTypeShowCorrectionPanel, adjacentWords.toNormalizedRange().get(), 0); >+ } >+ break; >+ case CorrectionPanelInfo::PanelTypeReversion: { >+ if (!m_correctionPanelInfo.rangeToBeReplaced) >+ break; >+ m_correctionPanelInfo.isActive = true; >+ m_correctionPanelInfo.replacedString = plainText(m_correctionPanelInfo.rangeToBeReplaced.get()); >+ FloatRect boundingBox = rootViewRectForRange(m_correctionPanelInfo.rangeToBeReplaced.get()); >+ if (!boundingBox.isEmpty()) >+ client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, m_correctionPanelInfo.replacementString, Vector<String>()); >+ } >+ break; >+ case CorrectionPanelInfo::PanelTypeSpellingSuggestions: { >+ if (!m_correctionPanelInfo.rangeToBeReplaced || plainText(m_correctionPanelInfo.rangeToBeReplaced.get()) != m_correctionPanelInfo.replacedString) >+ break; >+ String paragraphText = plainText(TextCheckingParagraph(m_correctionPanelInfo.rangeToBeReplaced).paragraphRange().get()); >+ Vector<String> suggestions; >+ textChecker()->getGuessesForWord(m_correctionPanelInfo.replacedString, paragraphText, suggestions); >+ if (suggestions.isEmpty()) { >+ m_correctionPanelInfo.rangeToBeReplaced.clear(); >+ break; >+ } >+ String topSuggestion = suggestions.first(); >+ suggestions.remove(0); >+ m_correctionPanelInfo.isActive = true; >+ FloatRect boundingBox = rootViewRectForRange(m_correctionPanelInfo.rangeToBeReplaced.get()); >+ if (!boundingBox.isEmpty()) >+ client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, topSuggestion, suggestions); >+ } >+ break; >+ } >+} >+ >+void SpellingCorrectionController::handleCorrectionPanelResult(const String& correction) >+{ >+ Range* replacedRange = m_correctionPanelInfo.rangeToBeReplaced.get(); >+ if (!replacedRange || m_frame->document() != replacedRange->ownerDocument()) >+ return; >+ >+ String currentWord = plainText(m_correctionPanelInfo.rangeToBeReplaced.get()); >+ // Check to see if the word we are about to correct has been changed between timer firing and callback being triggered. >+ if (currentWord != m_correctionPanelInfo.replacedString) >+ return; >+ >+ m_correctionPanelInfo.isActive = false; >+ >+ switch (m_correctionPanelInfo.panelType) { >+ case CorrectionPanelInfo::PanelTypeCorrection: >+ if (correction.length()) { >+ m_correctionPanelInfo.replacementString = correction; >+ applyCorrectionPanelInfo(markerTypesForAutocorrection()); >+ } else if (!m_correctionPanelIsDismissedByEditor) >+ replacedRange->startContainer()->document()->markers()->addMarker(replacedRange, DocumentMarker::RejectedCorrection, m_correctionPanelInfo.replacedString); >+ break; >+ case CorrectionPanelInfo::PanelTypeReversion: >+ case CorrectionPanelInfo::PanelTypeSpellingSuggestions: >+ if (correction.length()) { >+ m_correctionPanelInfo.replacementString = correction; >+ applyCorrectionPanelInfo(markerTypesForReplacement()); >+ } >+ break; >+ } >+ >+ m_correctionPanelInfo.rangeToBeReplaced.clear(); >+} >+ >+bool SpellingCorrectionController::isAutomaticSpellingCorrectionEnabled() >+{ >+ return client() && client()->isAutomaticSpellingCorrectionEnabled(); >+} >+ >+FloatRect SpellingCorrectionController::rootViewRectForRange(const Range* range) const >+{ >+ FrameView* view = m_frame->view(); >+ if (!view) >+ return FloatRect(); >+ Vector<FloatQuad> textQuads; >+ range->textQuads(textQuads); >+ FloatRect boundingRect; >+ size_t size = textQuads.size(); >+ for (size_t i = 0; i < size; ++i) >+ boundingRect.unite(textQuads[i].boundingBox()); >+ return view->contentsToRootView(IntRect(boundingRect)); >+} >+ >+void SpellingCorrectionController::respondToChangedSelection(const VisibleSelection& oldSelection) >+{ >+ VisibleSelection currentSelection(m_frame->selection()->selection()); >+ // When user moves caret to the end of autocorrected word and pauses, we show the panel >+ // containing the original pre-correction word so that user can quickly revert the >+ // undesired autocorrection. Here, we start correction panel timer once we confirm that >+ // the new caret position is at the end of a word. >+ if (!currentSelection.isCaret() || currentSelection == oldSelection) >+ return; >+ >+ VisiblePosition selectionPosition = currentSelection.start(); >+ >+ // Creating a Visible position triggers a layout and there is no >+ // guarantee that the selection is still valid. >+ if (selectionPosition.isNull()) >+ return; >+ >+ VisiblePosition endPositionOfWord = endOfWord(selectionPosition, LeftWordIfOnBoundary); >+ if (selectionPosition != endPositionOfWord) >+ return; >+ >+ Position position = endPositionOfWord.deepEquivalent(); >+ if (position.anchorType() != Position::PositionIsOffsetInAnchor) >+ return; >+ >+ Node* node = position.containerNode(); >+ int endOffset = position.offsetInContainerNode(); >+ Vector<DocumentMarker*> markers = node->document()->markers()->markersFor(node); >+ size_t markerCount = markers.size(); >+ for (size_t i = 0; i < markerCount; ++i) { >+ const DocumentMarker* marker = markers[i]; >+ if (!shouldStartTimerFor(marker, endOffset)) >+ continue; >+ RefPtr<Range> wordRange = Range::create(m_frame->document(), node, marker->startOffset(), node, marker->endOffset()); >+ String currentWord = plainText(wordRange.get()); >+ if (!currentWord.length()) >+ continue; >+ >+ m_correctionPanelInfo.rangeToBeReplaced = wordRange; >+ m_correctionPanelInfo.replacedString = currentWord; >+ if (marker->type() == DocumentMarker::Spelling) >+ startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeSpellingSuggestions); >+ else { >+ m_correctionPanelInfo.replacementString = marker->description(); >+ startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeReversion); >+ } >+ >+ break; >+ } >+} >+ >+void SpellingCorrectionController::respondToAppliedEditing(CompositeEditCommand* command) >+{ >+ if (command->isTopLevelCommand() && !command->shouldRetainAutocorrectionIndicator()) >+ m_frame->document()->markers()->removeMarkers(DocumentMarker::CorrectionIndicator); >+ >+ markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(command); >+ m_originalStringForLastDeletedAutocorrection = String(); >+} >+ >+void SpellingCorrectionController::respondToUnappliedEditing(EditCommandComposition* command) >+{ >+ if (!command->wasCreateLinkCommand()) >+ 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; >+} >+ >+TextCheckerClient* SpellingCorrectionController::textChecker() >+{ >+ if (EditorClient* owner = client()) >+ return owner->textChecker(); >+ return 0; >+} >+ >+void SpellingCorrectionController::recordAutocorrectionResponseReversed(const String& replacedString, const String& replacementString) >+{ >+ client()->recordAutocorrectionResponse(EditorClient::AutocorrectionReverted, replacedString, replacementString); >+} >+ >+void SpellingCorrectionController::recordAutocorrectionResponseReversed(const String& replacedString, PassRefPtr<Range> replacementRange) >+{ >+ recordAutocorrectionResponseReversed(replacedString, plainText(replacementRange.get())); >+} >+ >+void SpellingCorrectionController::markReversed(PassRefPtr<Range> changedRange) >+{ >+ changedRange->startContainer()->document()->markers()->removeMarkers(changedRange.get(), DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker); >+ changedRange->startContainer()->document()->markers()->addMarker(changedRange.get(), DocumentMarker::SpellCheckingExemption); >+} >+ >+void SpellingCorrectionController::markCorrection(PassRefPtr<Range> replacedRange, const String& replacedString) >+{ >+ Vector<DocumentMarker::MarkerType> markerTypesToAdd = markerTypesForAutocorrection(); >+ DocumentMarkerController* markers = replacedRange->startContainer()->document()->markers(); >+ for (size_t i = 0; i < markerTypesToAdd.size(); ++i) { >+ DocumentMarker::MarkerType markerType = markerTypesToAdd[i]; >+ if (markerType == DocumentMarker::Replacement || markerType == DocumentMarker::Autocorrected) >+ markers->addMarker(replacedRange.get(), markerType, replacedString); >+ else >+ markers->addMarker(replacedRange.get(), markerType); >+ } >+} >+ >+void SpellingCorrectionController::recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction) >+{ >+ if (!rangeOfCorrection) >+ return; >+ DocumentMarkerController* markers = rangeOfCorrection->startContainer()->document()->markers(); >+ Vector<DocumentMarker*> correctedOnceMarkers = markers->markersInRange(rangeOfCorrection, DocumentMarker::Autocorrected); >+ if (correctedOnceMarkers.isEmpty()) >+ return; >+ >+ // Spelling corrected text has been edited. We need to determine whether user has reverted it to original text or >+ // edited it to something else, and notify spellchecker accordingly. >+ if (markersHaveIdenticalDescription(correctedOnceMarkers) && correctedOnceMarkers[0]->description() == corrected) >+ client()->recordAutocorrectionResponse(EditorClient::AutocorrectionReverted, corrected, correction); >+ else >+ client()->recordAutocorrectionResponse(EditorClient::AutocorrectionEdited, corrected, correction); >+ markers->removeMarkers(rangeOfCorrection, DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker); >+} >+ >+void SpellingCorrectionController::deletedAutocorrectionAtPosition(const Position& position, const String& originalString) >+{ >+ m_originalStringForLastDeletedAutocorrection = originalString; >+ m_positionForLastDeletedAutocorrection = position; >+} >+ >+void SpellingCorrectionController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand* command) >+{ >+ Position endOfSelection = command->endingSelection().end(); >+ if (endOfSelection != m_positionForLastDeletedAutocorrection) >+ return; >+ >+ Position precedingCharacterPosition = endOfSelection.previous(); >+ if (endOfSelection == precedingCharacterPosition) >+ return; >+ >+ RefPtr<Range> precedingCharacterRange = Range::create(m_frame->document(), precedingCharacterPosition, endOfSelection); >+ String string = plainText(precedingCharacterRange.get()); >+ if (string.isEmpty() || !isWhitespace(string[string.length() - 1])) >+ return; >+ >+ // Mark this whitespace to indicate we have deleted an autocorrection following this >+ // whitespace. So if the user types the same original word again at this position, we >+ // won't autocorrect it again. >+ m_frame->document()->markers()->addMarker(precedingCharacterRange.get(), DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection); >+} >+ >+bool SpellingCorrectionController::processMarkersOnTextToBeReplacedByResult(const TextCheckingResult* result, Range* rangeToBeReplaced, const String& stringToBeReplaced) >+{ >+ DocumentMarkerController* markerController = m_frame->document()->markers(); >+ if (markerController->hasMarkers(rangeToBeReplaced, DocumentMarker::Replacement)) { >+ if (result->type == TextCheckingTypeCorrection) >+ recordSpellcheckerResponseForModifiedCorrection(rangeToBeReplaced, stringToBeReplaced, result->replacement); >+ return false; >+ } >+ >+ if (markerController->hasMarkers(rangeToBeReplaced, DocumentMarker::RejectedCorrection)) >+ return false; >+ >+ Position beginningOfRange = rangeToBeReplaced->startPosition(); >+ Position precedingCharacterPosition = beginningOfRange.previous(); >+ RefPtr<Range> precedingCharacterRange = Range::create(m_frame->document(), precedingCharacterPosition, beginningOfRange); >+ >+ Vector<DocumentMarker*> markers = markerController->markersInRange(precedingCharacterRange.get(), DocumentMarker::DeletedAutocorrection); >+ >+ for (size_t i = 0; i < markers.size(); ++i) { >+ if (markers[i]->description() == stringToBeReplaced) >+ return false; >+ } >+ >+ return true; >+} >+ >+#endif >+ >+} // namespace WebCore >Index: Source/WebCore/editing/AlternativeTextController.cpp >=================================================================== >--- Source/WebCore/editing/AlternativeTextController.cpp (revision 112830) >+++ Source/WebCore/editing/AlternativeTextController.cpp (working copy) >@@ -25,7 +25,7 @@ > */ > > #include "config.h" >-#include "SpellingCorrectionController.h" >+#include "AlternativeTextController.h" > > #include "DocumentMarkerController.h" > #include "EditCommand.h" >@@ -48,6 +48,22 @@ namespace WebCore { > using namespace std; > using namespace WTF; > >+class AutocorrectionAlternativeDetails : public AlternativeTextDetails { >+public: >+ static PassRefPtr<AutocorrectionAlternativeDetails> create(const String& replacementString) >+ { >+ return adoptRef(new AutocorrectionAlternativeDetails(replacementString)); >+ } >+ >+ const String& replacementString() const { return m_replacementString; } >+private: >+ AutocorrectionAlternativeDetails(const String& replacementString) >+ : m_replacementString(replacementString) >+ { } >+ >+ String m_replacementString; >+}; >+ > #if USE(AUTOCORRECTION_PANEL) > > static const Vector<DocumentMarker::MarkerType>& markerTypesForAutocorrection() >@@ -85,48 +101,48 @@ static bool markersHaveIdenticalDescript > return true; > } > >-SpellingCorrectionController::SpellingCorrectionController(Frame* frame) >+AlternativeTextController::AlternativeTextController(Frame* frame) > : m_frame(frame) >- , m_correctionPanelTimer(this, &SpellingCorrectionController::correctionPanelTimerFired) >+ , m_timer(this, &AlternativeTextController::timerFired) > { > } > >-SpellingCorrectionController::~SpellingCorrectionController() >+AlternativeTextController::~AlternativeTextController() > { >- dismiss(ReasonForDismissingCorrectionPanelIgnored); >+ dismiss(ReasonForDismissingAlternativeTextIgnored); > } > >-void SpellingCorrectionController::startCorrectionPanelTimer(CorrectionPanelInfo::PanelType type) >+void AlternativeTextController::startAlternativeTextUITimer(AlternativeTextType type) > { > const double correctionPanelTimerInterval = 0.3; > if (!isAutomaticSpellingCorrectionEnabled()) > return; > > // If type is PanelTypeReversion, then the new range has been set. So we shouldn't clear it. >- if (type == CorrectionPanelInfo::PanelTypeCorrection) >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >- m_correctionPanelInfo.panelType = type; >- m_correctionPanelTimer.startOneShot(correctionPanelTimerInterval); >+ if (type == AlternativeTextTypeCorrection) >+ m_alternativeTextInfo.rangeWithAlternative.clear(); >+ m_alternativeTextInfo.type = type; >+ m_timer.startOneShot(correctionPanelTimerInterval); > } > >-void SpellingCorrectionController::stopCorrectionPanelTimer() >+void AlternativeTextController::stopAlternativeTextUITimer() > { >- m_correctionPanelTimer.stop(); >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >+ m_timer.stop(); >+ m_alternativeTextInfo.rangeWithAlternative.clear(); > } > >-void SpellingCorrectionController::stopPendingCorrection(const VisibleSelection& oldSelection) >+void AlternativeTextController::stopPendingCorrection(const VisibleSelection& oldSelection) > { > // Make sure there's no pending autocorrection before we call markMisspellingsAndBadGrammar() below. > VisibleSelection currentSelection(m_frame->selection()->selection()); > if (currentSelection == oldSelection) > return; > >- stopCorrectionPanelTimer(); >- dismiss(ReasonForDismissingCorrectionPanelIgnored); >+ stopAlternativeTextUITimer(); >+ dismiss(ReasonForDismissingAlternativeTextIgnored); > } > >-void SpellingCorrectionController::applyPendingCorrection(const VisibleSelection& selectionAfterTyping) >+void AlternativeTextController::applyPendingCorrection(const VisibleSelection& selectionAfterTyping) > { > // Apply pending autocorrection before next round of spell checking. > bool doApplyCorrection = true; >@@ -138,87 +154,87 @@ void SpellingCorrectionController::apply > doApplyCorrection = false; > } > if (doApplyCorrection) >- handleCorrectionPanelResult(dismissSoon(ReasonForDismissingCorrectionPanelAccepted)); >+ handleAlternativeTextUIResult(dismissSoon(ReasonForDismissingAlternativeTextAccepted)); > else >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >+ m_alternativeTextInfo.rangeWithAlternative.clear(); > } > >-bool SpellingCorrectionController::hasPendingCorrection() const >+bool AlternativeTextController::hasPendingCorrection() const > { >- return m_correctionPanelInfo.rangeToBeReplaced; >+ return m_alternativeTextInfo.rangeWithAlternative; > } > >-bool SpellingCorrectionController::isSpellingMarkerAllowed(PassRefPtr<Range> misspellingRange) const >+bool AlternativeTextController::isSpellingMarkerAllowed(PassRefPtr<Range> misspellingRange) const > { > return !m_frame->document()->markers()->hasMarkers(misspellingRange.get(), DocumentMarker::SpellCheckingExemption); > } > >-void SpellingCorrectionController::show(PassRefPtr<Range> rangeToReplace, const String& replacement) >+void AlternativeTextController::show(PassRefPtr<Range> rangeToReplace, const String& replacement) > { > FloatRect boundingBox = rootViewRectForRange(rangeToReplace.get()); > if (boundingBox.isEmpty()) > return; >- m_correctionPanelInfo.replacedString = plainText(rangeToReplace.get()); >- m_correctionPanelInfo.rangeToBeReplaced = rangeToReplace; >- m_correctionPanelInfo.replacementString = replacement; >- m_correctionPanelInfo.isActive = true; >- client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, replacement, Vector<String>()); >+ m_alternativeTextInfo.originalText = plainText(rangeToReplace.get()); >+ m_alternativeTextInfo.rangeWithAlternative = rangeToReplace; >+ m_alternativeTextInfo.details = AutocorrectionAlternativeDetails::create(replacement); >+ m_alternativeTextInfo.isActive = true; >+ client()->showCorrectionPanel(m_alternativeTextInfo.type, boundingBox, m_alternativeTextInfo.originalText, replacement, Vector<String>()); > } > >-void SpellingCorrectionController::handleCancelOperation() >+void AlternativeTextController::handleCancelOperation() > { >- if (!m_correctionPanelInfo.isActive) >+ if (!m_alternativeTextInfo.isActive) > return; >- m_correctionPanelInfo.isActive = false; >- dismiss(ReasonForDismissingCorrectionPanelCancelled); >+ m_alternativeTextInfo.isActive = false; >+ dismiss(ReasonForDismissingAlternativeTextCancelled); > } > >-void SpellingCorrectionController::dismiss(ReasonForDismissingCorrectionPanel reasonForDismissing) >+void AlternativeTextController::dismiss(ReasonForDismissingAlternativeText reasonForDismissing) > { >- if (!m_correctionPanelInfo.isActive) >+ if (!m_alternativeTextInfo.isActive) > return; >- m_correctionPanelInfo.isActive = false; >- m_correctionPanelIsDismissedByEditor = true; >+ m_alternativeTextInfo.isActive = false; >+ m_isDismissedByEditing = true; > if (client()) > client()->dismissCorrectionPanel(reasonForDismissing); > } > >-String SpellingCorrectionController::dismissSoon(ReasonForDismissingCorrectionPanel reasonForDismissing) >+String AlternativeTextController::dismissSoon(ReasonForDismissingAlternativeText reasonForDismissing) > { >- if (!m_correctionPanelInfo.isActive) >+ if (!m_alternativeTextInfo.isActive) > return String(); >- m_correctionPanelInfo.isActive = false; >- m_correctionPanelIsDismissedByEditor = true; >+ m_alternativeTextInfo.isActive = false; >+ m_isDismissedByEditing = true; > if (!client()) > return String(); > return client()->dismissCorrectionPanelSoon(reasonForDismissing); > } > >-void SpellingCorrectionController::applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>& markerTypesToAdd) >+void AlternativeTextController::applyAlternativeText(const String& alternative, const Vector<DocumentMarker::MarkerType>& markerTypesToAdd) > { >- if (!m_correctionPanelInfo.rangeToBeReplaced) >+ if (!m_alternativeTextInfo.rangeWithAlternative) > return; > > ExceptionCode ec = 0; >- RefPtr<Range> paragraphRangeContainingCorrection = m_correctionPanelInfo.rangeToBeReplaced->cloneRange(ec); >+ RefPtr<Range> paragraphRangeContainingCorrection = m_alternativeTextInfo.rangeWithAlternative->cloneRange(ec); > if (ec) > return; > >- setStart(paragraphRangeContainingCorrection.get(), startOfParagraph(m_correctionPanelInfo.rangeToBeReplaced->startPosition())); >- setEnd(paragraphRangeContainingCorrection.get(), endOfParagraph(m_correctionPanelInfo.rangeToBeReplaced->endPosition())); >+ setStart(paragraphRangeContainingCorrection.get(), startOfParagraph(m_alternativeTextInfo.rangeWithAlternative->startPosition())); >+ setEnd(paragraphRangeContainingCorrection.get(), endOfParagraph(m_alternativeTextInfo.rangeWithAlternative->endPosition())); > >- // After we replace the word at range rangeToBeReplaced, we need to add markers to that range. >- // However, once the replacement took place, the value of rangeToBeReplaced is not valid anymore. >- // So before we carry out the replacement, we need to store the start position of rangeToBeReplaced >+ // After we replace the word at range rangeWithAlternative, we need to add markers to that range. >+ // However, once the replacement took place, the value of rangeWithAlternative is not valid anymore. >+ // So before we carry out the replacement, we need to store the start position of rangeWithAlternative > // relative to the start position of the containing paragraph. We use correctionStartOffsetInParagraph > // to store this value. In order to obtain this offset, we need to first create a range >- // which spans from the start of paragraph to the start position of rangeToBeReplaced. >+ // which spans from the start of paragraph to the start position of rangeWithAlternative. > RefPtr<Range> correctionStartOffsetInParagraphAsRange = Range::create(paragraphRangeContainingCorrection->startContainer(ec)->document(), paragraphRangeContainingCorrection->startPosition(), paragraphRangeContainingCorrection->startPosition()); > if (ec) > return; > >- Position startPositionOfRangeToBeReplaced = m_correctionPanelInfo.rangeToBeReplaced->startPosition(); >- correctionStartOffsetInParagraphAsRange->setEnd(startPositionOfRangeToBeReplaced.containerNode(), startPositionOfRangeToBeReplaced.computeOffsetInContainerNode(), ec); >+ Position startPositionOfrangeWithAlternative = m_alternativeTextInfo.rangeWithAlternative->startPosition(); >+ correctionStartOffsetInParagraphAsRange->setEnd(startPositionOfrangeWithAlternative.containerNode(), startPositionOfrangeWithAlternative.computeOffsetInContainerNode(), ec); > if (ec) > return; > >@@ -226,14 +242,14 @@ void SpellingCorrectionController::apply > int correctionStartOffsetInParagraph = TextIterator::rangeLength(correctionStartOffsetInParagraphAsRange.get()); > > // Clone the range, since the caller of this method may want to keep the original range around. >- RefPtr<Range> rangeToBeReplaced = m_correctionPanelInfo.rangeToBeReplaced->cloneRange(ec); >- applyCommand(SpellingCorrectionCommand::create(rangeToBeReplaced, m_correctionPanelInfo.replacementString)); >+ RefPtr<Range> rangeWithAlternative = m_alternativeTextInfo.rangeWithAlternative->cloneRange(ec); >+ applyCommand(SpellingCorrectionCommand::create(rangeWithAlternative, alternative)); > setEnd(paragraphRangeContainingCorrection.get(), m_frame->selection()->selection().start()); >- RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, m_correctionPanelInfo.replacementString.length()); >+ RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, alternative.length()); > String newText = plainText(replacementRange.get()); > > // Check to see if replacement succeeded. >- if (newText != m_correctionPanelInfo.replacementString) >+ if (newText != alternative) > return; > > DocumentMarkerController* markers = replacementRange->startContainer()->document()->markers(); >@@ -241,34 +257,34 @@ void SpellingCorrectionController::apply > for (size_t i = 0; i < size; ++i) { > DocumentMarker::MarkerType markerType = markerTypesToAdd[i]; > String description; >- if (m_correctionPanelInfo.panelType != CorrectionPanelInfo::PanelTypeReversion && (markerType == DocumentMarker::Replacement || markerType == DocumentMarker::Autocorrected)) >- description = m_correctionPanelInfo.replacedString; >+ if (m_alternativeTextInfo.type != AlternativeTextTypeReversion && (markerType == DocumentMarker::Replacement || markerType == DocumentMarker::Autocorrected)) >+ description = m_alternativeTextInfo.originalText; > markers->addMarker(replacementRange.get(), markerType, description); > } > } > >-bool SpellingCorrectionController::applyAutocorrectionBeforeTypingIfAppropriate() >+bool AlternativeTextController::applyAutocorrectionBeforeTypingIfAppropriate() > { >- if (!m_correctionPanelInfo.rangeToBeReplaced || !m_correctionPanelInfo.isActive) >+ if (!m_alternativeTextInfo.rangeWithAlternative || !m_alternativeTextInfo.isActive) > return false; > >- if (m_correctionPanelInfo.panelType != CorrectionPanelInfo::PanelTypeCorrection) >+ if (m_alternativeTextInfo.type != AlternativeTextTypeCorrection) > return false; > > Position caretPosition = m_frame->selection()->selection().start(); > >- if (m_correctionPanelInfo.rangeToBeReplaced->endPosition() == caretPosition) { >- handleCorrectionPanelResult(dismissSoon(ReasonForDismissingCorrectionPanelAccepted)); >+ if (m_alternativeTextInfo.rangeWithAlternative->endPosition() == caretPosition) { >+ handleAlternativeTextUIResult(dismissSoon(ReasonForDismissingAlternativeTextAccepted)); > return true; > } > > // Pending correction should always be where caret is. But in case this is not always true, we still want to dismiss the panel without accepting the correction. >- ASSERT(m_correctionPanelInfo.rangeToBeReplaced->endPosition() == caretPosition); >- dismiss(ReasonForDismissingCorrectionPanelIgnored); >+ ASSERT(m_alternativeTextInfo.rangeWithAlternative->endPosition() == caretPosition); >+ dismiss(ReasonForDismissingAlternativeTextIgnored); > return false; > } > >-void SpellingCorrectionController::respondToUnappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction) >+void AlternativeTextController::respondToUnappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction) > { > client()->recordAutocorrectionResponse(EditorClient::AutocorrectionReverted, corrected, correction); > m_frame->document()->updateLayout(); >@@ -281,11 +297,11 @@ void SpellingCorrectionController::respo > markers->addMarker(range.get(), DocumentMarker::SpellCheckingExemption); > } > >-void SpellingCorrectionController::correctionPanelTimerFired(Timer<SpellingCorrectionController>*) >+void AlternativeTextController::timerFired(Timer<AlternativeTextController>*) > { >- m_correctionPanelIsDismissedByEditor = false; >- switch (m_correctionPanelInfo.panelType) { >- case CorrectionPanelInfo::PanelTypeCorrection: { >+ m_isDismissedByEditing = false; >+ switch (m_alternativeTextInfo.type) { >+ case AlternativeTextTypeCorrection: { > VisibleSelection selection(m_frame->selection()->selection()); > VisiblePosition start(selection.start(), selection.affinity()); > VisiblePosition p = startOfWord(start, LeftWordIfOnBoundary); >@@ -293,76 +309,75 @@ void SpellingCorrectionController::corre > m_frame->editor()->markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeSpelling | TextCheckingTypeShowCorrectionPanel, adjacentWords.toNormalizedRange().get(), 0); > } > break; >- case CorrectionPanelInfo::PanelTypeReversion: { >- if (!m_correctionPanelInfo.rangeToBeReplaced) >+ case AlternativeTextTypeReversion: { >+ if (!m_alternativeTextInfo.rangeWithAlternative) > break; >- m_correctionPanelInfo.isActive = true; >- m_correctionPanelInfo.replacedString = plainText(m_correctionPanelInfo.rangeToBeReplaced.get()); >- FloatRect boundingBox = rootViewRectForRange(m_correctionPanelInfo.rangeToBeReplaced.get()); >- if (!boundingBox.isEmpty()) >- client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, m_correctionPanelInfo.replacementString, Vector<String>()); >+ m_alternativeTextInfo.isActive = true; >+ m_alternativeTextInfo.originalText = plainText(m_alternativeTextInfo.rangeWithAlternative.get()); >+ FloatRect boundingBox = rootViewRectForRange(m_alternativeTextInfo.rangeWithAlternative.get()); >+ if (!boundingBox.isEmpty()) { >+ const AutocorrectionAlternativeDetails* details = static_cast<const AutocorrectionAlternativeDetails*>(m_alternativeTextInfo.details.get()); >+ client()->showCorrectionPanel(m_alternativeTextInfo.type, boundingBox, m_alternativeTextInfo.originalText, details->replacementString(), Vector<String>()); >+ } > } > break; >- case CorrectionPanelInfo::PanelTypeSpellingSuggestions: { >- if (!m_correctionPanelInfo.rangeToBeReplaced || plainText(m_correctionPanelInfo.rangeToBeReplaced.get()) != m_correctionPanelInfo.replacedString) >+ case AlternativeTextTypeSpellingSuggestions: { >+ if (!m_alternativeTextInfo.rangeWithAlternative || plainText(m_alternativeTextInfo.rangeWithAlternative.get()) != m_alternativeTextInfo.originalText) > break; >- String paragraphText = plainText(TextCheckingParagraph(m_correctionPanelInfo.rangeToBeReplaced).paragraphRange().get()); >+ String paragraphText = plainText(TextCheckingParagraph(m_alternativeTextInfo.rangeWithAlternative).paragraphRange().get()); > Vector<String> suggestions; >- textChecker()->getGuessesForWord(m_correctionPanelInfo.replacedString, paragraphText, suggestions); >+ textChecker()->getGuessesForWord(m_alternativeTextInfo.originalText, paragraphText, suggestions); > if (suggestions.isEmpty()) { >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >+ m_alternativeTextInfo.rangeWithAlternative.clear(); > break; > } > String topSuggestion = suggestions.first(); > suggestions.remove(0); >- m_correctionPanelInfo.isActive = true; >- FloatRect boundingBox = rootViewRectForRange(m_correctionPanelInfo.rangeToBeReplaced.get()); >+ m_alternativeTextInfo.isActive = true; >+ FloatRect boundingBox = rootViewRectForRange(m_alternativeTextInfo.rangeWithAlternative.get()); > if (!boundingBox.isEmpty()) >- client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, topSuggestion, suggestions); >+ client()->showCorrectionPanel(m_alternativeTextInfo.type, boundingBox, m_alternativeTextInfo.originalText, topSuggestion, suggestions); > } > break; > } > } > >-void SpellingCorrectionController::handleCorrectionPanelResult(const String& correction) >+void AlternativeTextController::handleAlternativeTextUIResult(const String& result) > { >- Range* replacedRange = m_correctionPanelInfo.rangeToBeReplaced.get(); >+ Range* replacedRange = m_alternativeTextInfo.rangeWithAlternative.get(); > if (!replacedRange || m_frame->document() != replacedRange->ownerDocument()) > return; > >- String currentWord = plainText(m_correctionPanelInfo.rangeToBeReplaced.get()); >+ String currentWord = plainText(m_alternativeTextInfo.rangeWithAlternative.get()); > // Check to see if the word we are about to correct has been changed between timer firing and callback being triggered. >- if (currentWord != m_correctionPanelInfo.replacedString) >+ if (currentWord != m_alternativeTextInfo.originalText) > return; > >- m_correctionPanelInfo.isActive = false; >+ m_alternativeTextInfo.isActive = false; > >- switch (m_correctionPanelInfo.panelType) { >- case CorrectionPanelInfo::PanelTypeCorrection: >- if (correction.length()) { >- m_correctionPanelInfo.replacementString = correction; >- applyCorrectionPanelInfo(markerTypesForAutocorrection()); >- } else if (!m_correctionPanelIsDismissedByEditor) >- replacedRange->startContainer()->document()->markers()->addMarker(replacedRange, DocumentMarker::RejectedCorrection, m_correctionPanelInfo.replacedString); >+ switch (m_alternativeTextInfo.type) { >+ case AlternativeTextTypeCorrection: >+ if (result.length()) >+ applyAlternativeText(result, markerTypesForAutocorrection()); >+ else if (!m_isDismissedByEditing) >+ replacedRange->startContainer()->document()->markers()->addMarker(replacedRange, DocumentMarker::RejectedCorrection, m_alternativeTextInfo.originalText); > break; >- case CorrectionPanelInfo::PanelTypeReversion: >- case CorrectionPanelInfo::PanelTypeSpellingSuggestions: >- if (correction.length()) { >- m_correctionPanelInfo.replacementString = correction; >- applyCorrectionPanelInfo(markerTypesForReplacement()); >- } >+ case AlternativeTextTypeReversion: >+ case AlternativeTextTypeSpellingSuggestions: >+ if (result.length()) >+ applyAlternativeText(result, markerTypesForReplacement()); > break; > } > >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >+ m_alternativeTextInfo.rangeWithAlternative.clear(); > } > >-bool SpellingCorrectionController::isAutomaticSpellingCorrectionEnabled() >+bool AlternativeTextController::isAutomaticSpellingCorrectionEnabled() > { > return client() && client()->isAutomaticSpellingCorrectionEnabled(); > } > >-FloatRect SpellingCorrectionController::rootViewRectForRange(const Range* range) const >+FloatRect AlternativeTextController::rootViewRectForRange(const Range* range) const > { > FrameView* view = m_frame->view(); > if (!view) >@@ -376,7 +391,7 @@ FloatRect SpellingCorrectionController:: > return view->contentsToRootView(IntRect(boundingRect)); > } > >-void SpellingCorrectionController::respondToChangedSelection(const VisibleSelection& oldSelection) >+void AlternativeTextController::respondToChangedSelection(const VisibleSelection& oldSelection) > { > VisibleSelection currentSelection(m_frame->selection()->selection()); > // When user moves caret to the end of autocorrected word and pauses, we show the panel >@@ -414,20 +429,20 @@ void SpellingCorrectionController::respo > if (!currentWord.length()) > continue; > >- m_correctionPanelInfo.rangeToBeReplaced = wordRange; >- m_correctionPanelInfo.replacedString = currentWord; >+ m_alternativeTextInfo.rangeWithAlternative = wordRange; >+ m_alternativeTextInfo.originalText = currentWord; > if (marker->type() == DocumentMarker::Spelling) >- startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeSpellingSuggestions); >+ startAlternativeTextUITimer(AlternativeTextTypeSpellingSuggestions); > else { >- m_correctionPanelInfo.replacementString = marker->description(); >- startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeReversion); >+ m_alternativeTextInfo.details = AutocorrectionAlternativeDetails::create(marker->description()); >+ startAlternativeTextUITimer(AlternativeTextTypeReversion); > } > > break; > } > } > >-void SpellingCorrectionController::respondToAppliedEditing(CompositeEditCommand* command) >+void AlternativeTextController::respondToAppliedEditing(CompositeEditCommand* command) > { > if (command->isTopLevelCommand() && !command->shouldRetainAutocorrectionIndicator()) > m_frame->document()->markers()->removeMarkers(DocumentMarker::CorrectionIndicator); >@@ -436,7 +451,7 @@ void SpellingCorrectionController::respo > m_originalStringForLastDeletedAutocorrection = String(); > } > >-void SpellingCorrectionController::respondToUnappliedEditing(EditCommandComposition* command) >+void AlternativeTextController::respondToUnappliedEditing(EditCommandComposition* command) > { > if (!command->wasCreateLinkCommand()) > return; >@@ -448,35 +463,35 @@ void SpellingCorrectionController::respo > markers->addMarker(range.get(), DocumentMarker::SpellCheckingExemption); > } > >-EditorClient* SpellingCorrectionController::client() >+EditorClient* AlternativeTextController::client() > { > return m_frame->page() ? m_frame->page()->editorClient() : 0; > } > >-TextCheckerClient* SpellingCorrectionController::textChecker() >+TextCheckerClient* AlternativeTextController::textChecker() > { > if (EditorClient* owner = client()) > return owner->textChecker(); > return 0; > } > >-void SpellingCorrectionController::recordAutocorrectionResponseReversed(const String& replacedString, const String& replacementString) >+void AlternativeTextController::recordAutocorrectionResponseReversed(const String& replacedString, const String& replacementString) > { > client()->recordAutocorrectionResponse(EditorClient::AutocorrectionReverted, replacedString, replacementString); > } > >-void SpellingCorrectionController::recordAutocorrectionResponseReversed(const String& replacedString, PassRefPtr<Range> replacementRange) >+void AlternativeTextController::recordAutocorrectionResponseReversed(const String& replacedString, PassRefPtr<Range> replacementRange) > { > recordAutocorrectionResponseReversed(replacedString, plainText(replacementRange.get())); > } > >-void SpellingCorrectionController::markReversed(PassRefPtr<Range> changedRange) >+void AlternativeTextController::markReversed(PassRefPtr<Range> changedRange) > { > changedRange->startContainer()->document()->markers()->removeMarkers(changedRange.get(), DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker); > changedRange->startContainer()->document()->markers()->addMarker(changedRange.get(), DocumentMarker::SpellCheckingExemption); > } > >-void SpellingCorrectionController::markCorrection(PassRefPtr<Range> replacedRange, const String& replacedString) >+void AlternativeTextController::markCorrection(PassRefPtr<Range> replacedRange, const String& replacedString) > { > Vector<DocumentMarker::MarkerType> markerTypesToAdd = markerTypesForAutocorrection(); > DocumentMarkerController* markers = replacedRange->startContainer()->document()->markers(); >@@ -489,7 +504,7 @@ void SpellingCorrectionController::markC > } > } > >-void SpellingCorrectionController::recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction) >+void AlternativeTextController::recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction) > { > if (!rangeOfCorrection) > return; >@@ -507,13 +522,13 @@ void SpellingCorrectionController::recor > markers->removeMarkers(rangeOfCorrection, DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker); > } > >-void SpellingCorrectionController::deletedAutocorrectionAtPosition(const Position& position, const String& originalString) >+void AlternativeTextController::deletedAutocorrectionAtPosition(const Position& position, const String& originalString) > { > m_originalStringForLastDeletedAutocorrection = originalString; > m_positionForLastDeletedAutocorrection = position; > } > >-void SpellingCorrectionController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand* command) >+void AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand* command) > { > Position endOfSelection = command->endingSelection().end(); > if (endOfSelection != m_positionForLastDeletedAutocorrection) >@@ -534,19 +549,19 @@ void SpellingCorrectionController::markP > m_frame->document()->markers()->addMarker(precedingCharacterRange.get(), DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection); > } > >-bool SpellingCorrectionController::processMarkersOnTextToBeReplacedByResult(const TextCheckingResult* result, Range* rangeToBeReplaced, const String& stringToBeReplaced) >+bool AlternativeTextController::processMarkersOnTextToBeReplacedByResult(const TextCheckingResult* result, Range* rangeWithAlternative, const String& stringToBeReplaced) > { > DocumentMarkerController* markerController = m_frame->document()->markers(); >- if (markerController->hasMarkers(rangeToBeReplaced, DocumentMarker::Replacement)) { >+ if (markerController->hasMarkers(rangeWithAlternative, DocumentMarker::Replacement)) { > if (result->type == TextCheckingTypeCorrection) >- recordSpellcheckerResponseForModifiedCorrection(rangeToBeReplaced, stringToBeReplaced, result->replacement); >+ recordSpellcheckerResponseForModifiedCorrection(rangeWithAlternative, stringToBeReplaced, result->replacement); > return false; > } > >- if (markerController->hasMarkers(rangeToBeReplaced, DocumentMarker::RejectedCorrection)) >+ if (markerController->hasMarkers(rangeWithAlternative, DocumentMarker::RejectedCorrection)) > return false; > >- Position beginningOfRange = rangeToBeReplaced->startPosition(); >+ Position beginningOfRange = rangeWithAlternative->startPosition(); > Position precedingCharacterPosition = beginningOfRange.previous(); > RefPtr<Range> precedingCharacterRange = Range::create(m_frame->document(), precedingCharacterPosition, beginningOfRange); > >Index: Source/WebCore/editing/AlternativeTextController.h >=================================================================== >--- Source/WebCore/editing/AlternativeTextController.h (revision 112830) (from Source/WebCore/editing/SpellingCorrectionController.h:112830) >+++ Source/WebCore/editing/AlternativeTextController.h (working copy) >@@ -0,0 +1,157 @@ >+/* >+ * Copyright (C) 2010 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR >+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#ifndef SpellingCorrectionController_h >+#define SpellingCorrectionController_h >+ >+#include "DocumentMarker.h" >+#include "Range.h" >+#include "TextChecking.h" >+#include "Timer.h" >+#include "VisibleSelection.h" >+#include <wtf/Noncopyable.h> >+#include <wtf/UnusedParam.h> >+ >+namespace WebCore { >+ >+class CompositeEditCommand; >+class EditorClient; >+class EditCommand; >+class EditCommandComposition; >+class Frame; >+class TextCheckerClient; >+ >+struct CorrectionPanelInfo { >+ enum PanelType { >+ PanelTypeCorrection = 0, >+ PanelTypeReversion, >+ PanelTypeSpellingSuggestions >+ }; >+ >+ RefPtr<Range> rangeToBeReplaced; >+ String replacedString; >+ String replacementString; >+ PanelType panelType; >+ bool isActive; >+}; >+ >+struct TextCheckingResult; >+ >+enum ReasonForDismissingCorrectionPanel { >+ ReasonForDismissingCorrectionPanelCancelled = 0, >+ ReasonForDismissingCorrectionPanelIgnored, >+ ReasonForDismissingCorrectionPanelAccepted >+}; >+ >+#if USE(AUTOCORRECTION_PANEL) >+#define UNLESS_ENABLED(functionBody) ; >+#else >+#define UNLESS_ENABLED(functionBody) functionBody >+#endif >+ >+class SpellingCorrectionController { >+ WTF_MAKE_NONCOPYABLE(SpellingCorrectionController); WTF_MAKE_FAST_ALLOCATED; >+public: >+ SpellingCorrectionController(Frame*) UNLESS_ENABLED({}) >+ ~SpellingCorrectionController() UNLESS_ENABLED({}) >+ >+ void startCorrectionPanelTimer(CorrectionPanelInfo::PanelType) UNLESS_ENABLED({}) >+ void stopCorrectionPanelTimer() UNLESS_ENABLED({}) >+ >+ void dismiss(ReasonForDismissingCorrectionPanel) UNLESS_ENABLED({}) >+ String dismissSoon(ReasonForDismissingCorrectionPanel) UNLESS_ENABLED({ return String(); }) >+ void show(PassRefPtr<Range> rangeToReplace, const String& replacement) UNLESS_ENABLED({ UNUSED_PARAM(rangeToReplace); UNUSED_PARAM(replacement); }) >+ >+ void applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>&) UNLESS_ENABLED({}) >+ // Return true if correction was applied, false otherwise. >+ 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(CompositeEditCommand*) UNLESS_ENABLED({ }) >+ void respondToUnappliedEditing(EditCommandComposition*) UNLESS_ENABLED({ }) >+ void respondToChangedSelection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); }) >+ >+ void stopPendingCorrection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); }) >+ void applyPendingCorrection(const VisibleSelection& selectionAfterTyping) UNLESS_ENABLED({ UNUSED_PARAM(selectionAfterTyping); }) >+ >+ void handleCorrectionPanelResult(const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(correction); }) >+ void handleCancelOperation() UNLESS_ENABLED({}) >+ >+ bool hasPendingCorrection() const UNLESS_ENABLED({ return false; }) >+ bool isSpellingMarkerAllowed(PassRefPtr<Range> misspellingRange) const UNLESS_ENABLED({ UNUSED_PARAM(misspellingRange); return true; }) >+ bool isAutomaticSpellingCorrectionEnabled() UNLESS_ENABLED({ return false; }) >+ bool shouldRemoveMarkersUponEditing(); >+ >+ void correctionPanelTimerFired(Timer<SpellingCorrectionController>*) UNLESS_ENABLED({}) >+ void recordAutocorrectionResponseReversed(const String& replacedString, PassRefPtr<Range> replacementRange) UNLESS_ENABLED({ UNUSED_PARAM(replacedString); UNUSED_PARAM(replacementRange); }) >+ void markReversed(PassRefPtr<Range> changedRange) UNLESS_ENABLED({ UNUSED_PARAM(changedRange); }) >+ void markCorrection(PassRefPtr<Range> replacedRange, const String& replacedString) UNLESS_ENABLED({ UNUSED_PARAM(replacedRange); UNUSED_PARAM(replacedString); }) >+ void recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(rangeOfCorrection); UNUSED_PARAM(corrected); UNUSED_PARAM(correction); }) >+ >+ // This function returns false if the replacement should not be carried out. >+ bool processMarkersOnTextToBeReplacedByResult(const TextCheckingResult*, Range* rangeToBeReplaced, const String& stringToBeReplaced) UNLESS_ENABLED({ UNUSED_PARAM(rangeToBeReplaced); UNUSED_PARAM(stringToBeReplaced); return true; }); >+ void deletedAutocorrectionAtPosition(const Position&, const String& originalString) UNLESS_ENABLED({ UNUSED_PARAM(originalString); }) >+ >+#if USE(AUTOCORRECTION_PANEL) >+private: >+ void recordAutocorrectionResponseReversed(const String& replacedString, const String& replacementString); >+ >+ bool shouldStartTimerFor(const DocumentMarker* marker, int endOffset) const >+ { >+ return (((marker->type() == DocumentMarker::Replacement && !marker->description().isNull()) >+ || marker->type() == DocumentMarker::Spelling) && static_cast<int>(marker->endOffset()) == endOffset); >+ } >+ >+ EditorClient* client(); >+ TextCheckerClient* textChecker(); >+ FloatRect rootViewRectForRange(const Range*) const; >+ void markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand*); >+ >+ EditorClient* m_client; >+ Frame* m_frame; >+ >+ Timer<SpellingCorrectionController> m_correctionPanelTimer; >+ CorrectionPanelInfo m_correctionPanelInfo; >+ bool m_correctionPanelIsDismissedByEditor; >+ >+ String m_originalStringForLastDeletedAutocorrection; >+ Position m_positionForLastDeletedAutocorrection; >+#endif >+}; >+ >+#undef UNLESS_ENABLED >+ >+inline bool SpellingCorrectionController::shouldRemoveMarkersUponEditing() >+{ >+#if USE(MARKER_REMOVAL_UPON_EDITING) >+ return true; >+#else >+ return false; >+#endif >+} >+ >+} // namespace WebCore >+ >+#endif // SpellingCorrectionController_h >Index: Source/WebCore/editing/AlternativeTextController.h >=================================================================== >--- Source/WebCore/editing/AlternativeTextController.h (revision 112830) >+++ Source/WebCore/editing/AlternativeTextController.h (working copy) >@@ -23,8 +23,8 @@ > * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > */ > >-#ifndef SpellingCorrectionController_h >-#define SpellingCorrectionController_h >+#ifndef AlternativeTextController_h >+#define AlternativeTextController_h > > #include "DocumentMarker.h" > #include "Range.h" >@@ -43,26 +43,32 @@ class EditCommandComposition; > class Frame; > class TextCheckerClient; > >-struct CorrectionPanelInfo { >- enum PanelType { >- PanelTypeCorrection = 0, >- PanelTypeReversion, >- PanelTypeSpellingSuggestions >- }; >- >- RefPtr<Range> rangeToBeReplaced; >- String replacedString; >- String replacementString; >- PanelType panelType; >+class AlternativeTextDetails : public RefCounted<AlternativeTextDetails> { >+public: >+ AlternativeTextDetails() { } >+ virtual ~AlternativeTextDetails() { } >+}; >+ >+enum AlternativeTextType { >+ AlternativeTextTypeCorrection = 0, >+ AlternativeTextTypeReversion, >+ AlternativeTextTypeSpellingSuggestions, >+}; >+ >+struct AlternativeTextInfo { >+ RefPtr<Range> rangeWithAlternative; > bool isActive; >+ AlternativeTextType type; >+ String originalText; >+ RefPtr<AlternativeTextDetails> details; > }; > > struct TextCheckingResult; > >-enum ReasonForDismissingCorrectionPanel { >- ReasonForDismissingCorrectionPanelCancelled = 0, >- ReasonForDismissingCorrectionPanelIgnored, >- ReasonForDismissingCorrectionPanelAccepted >+enum ReasonForDismissingAlternativeText { >+ ReasonForDismissingAlternativeTextCancelled = 0, >+ ReasonForDismissingAlternativeTextIgnored, >+ ReasonForDismissingAlternativeTextAccepted > }; > > #if USE(AUTOCORRECTION_PANEL) >@@ -71,20 +77,19 @@ enum ReasonForDismissingCorrectionPanel > #define UNLESS_ENABLED(functionBody) functionBody > #endif > >-class SpellingCorrectionController { >- WTF_MAKE_NONCOPYABLE(SpellingCorrectionController); WTF_MAKE_FAST_ALLOCATED; >+class AlternativeTextController { >+ WTF_MAKE_NONCOPYABLE(AlternativeTextController); >+ WTF_MAKE_FAST_ALLOCATED; > public: >- SpellingCorrectionController(Frame*) UNLESS_ENABLED({}) >- ~SpellingCorrectionController() UNLESS_ENABLED({}) >+ AlternativeTextController(Frame*) UNLESS_ENABLED({ }) >+ ~AlternativeTextController() UNLESS_ENABLED({ }) > >- void startCorrectionPanelTimer(CorrectionPanelInfo::PanelType) UNLESS_ENABLED({}) >- void stopCorrectionPanelTimer() UNLESS_ENABLED({}) >+ void startAlternativeTextUITimer(AlternativeTextType) UNLESS_ENABLED({ }) >+ void stopAlternativeTextUITimer() UNLESS_ENABLED({ }) > >- void dismiss(ReasonForDismissingCorrectionPanel) UNLESS_ENABLED({}) >- String dismissSoon(ReasonForDismissingCorrectionPanel) UNLESS_ENABLED({ return String(); }) >+ void dismiss(ReasonForDismissingAlternativeText) UNLESS_ENABLED({ }) > void show(PassRefPtr<Range> rangeToReplace, const String& replacement) UNLESS_ENABLED({ UNUSED_PARAM(rangeToReplace); UNUSED_PARAM(replacement); }) > >- void applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>&) UNLESS_ENABLED({}) > // Return true if correction was applied, false otherwise. > bool applyAutocorrectionBeforeTypingIfAppropriate() UNLESS_ENABLED({ return false; }) > >@@ -96,19 +101,17 @@ public: > void stopPendingCorrection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); }) > void applyPendingCorrection(const VisibleSelection& selectionAfterTyping) UNLESS_ENABLED({ UNUSED_PARAM(selectionAfterTyping); }) > >- void handleCorrectionPanelResult(const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(correction); }) >- void handleCancelOperation() UNLESS_ENABLED({}) >+ void handleAlternativeTextUIResult(const String& result) UNLESS_ENABLED({ UNUSED_PARAM(result); }) >+ void handleCancelOperation() UNLESS_ENABLED({ }) > > bool hasPendingCorrection() const UNLESS_ENABLED({ return false; }) > bool isSpellingMarkerAllowed(PassRefPtr<Range> misspellingRange) const UNLESS_ENABLED({ UNUSED_PARAM(misspellingRange); return true; }) > bool isAutomaticSpellingCorrectionEnabled() UNLESS_ENABLED({ return false; }) > bool shouldRemoveMarkersUponEditing(); > >- void correctionPanelTimerFired(Timer<SpellingCorrectionController>*) UNLESS_ENABLED({}) > void recordAutocorrectionResponseReversed(const String& replacedString, PassRefPtr<Range> replacementRange) UNLESS_ENABLED({ UNUSED_PARAM(replacedString); UNUSED_PARAM(replacementRange); }) > void markReversed(PassRefPtr<Range> changedRange) UNLESS_ENABLED({ UNUSED_PARAM(changedRange); }) > void markCorrection(PassRefPtr<Range> replacedRange, const String& replacedString) UNLESS_ENABLED({ UNUSED_PARAM(replacedRange); UNUSED_PARAM(replacedString); }) >- void recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(rangeOfCorrection); UNUSED_PARAM(corrected); UNUSED_PARAM(correction); }) > > // This function returns false if the replacement should not be carried out. > bool processMarkersOnTextToBeReplacedByResult(const TextCheckingResult*, Range* rangeToBeReplaced, const String& stringToBeReplaced) UNLESS_ENABLED({ UNUSED_PARAM(rangeToBeReplaced); UNUSED_PARAM(stringToBeReplaced); return true; }); >@@ -116,7 +119,11 @@ public: > > #if USE(AUTOCORRECTION_PANEL) > private: >+ String dismissSoon(ReasonForDismissingAlternativeText); >+ void applyAlternativeText(const String& alternative, const Vector<DocumentMarker::MarkerType>&); >+ void timerFired(Timer<AlternativeTextController>*); > void recordAutocorrectionResponseReversed(const String& replacedString, const String& replacementString); >+ void recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction); > > bool shouldStartTimerFor(const DocumentMarker* marker, int endOffset) const > { >@@ -132,9 +139,9 @@ private: > EditorClient* m_client; > Frame* m_frame; > >- Timer<SpellingCorrectionController> m_correctionPanelTimer; >- CorrectionPanelInfo m_correctionPanelInfo; >- bool m_correctionPanelIsDismissedByEditor; >+ Timer<AlternativeTextController> m_timer; >+ AlternativeTextInfo m_alternativeTextInfo; >+ bool m_isDismissedByEditing; > > String m_originalStringForLastDeletedAutocorrection; > Position m_positionForLastDeletedAutocorrection; >@@ -143,7 +150,7 @@ private: > > #undef UNLESS_ENABLED > >-inline bool SpellingCorrectionController::shouldRemoveMarkersUponEditing() >+inline bool AlternativeTextController::shouldRemoveMarkersUponEditing() > { > #if USE(MARKER_REMOVAL_UPON_EDITING) > return true; >@@ -154,4 +161,4 @@ inline bool SpellingCorrectionController > > } // namespace WebCore > >-#endif // SpellingCorrectionController_h >+#endif // AlternativeTextController_h >Index: Source/WebCore/editing/Editor.cpp >=================================================================== >--- Source/WebCore/editing/Editor.cpp (revision 112917) >+++ Source/WebCore/editing/Editor.cpp (working copy) >@@ -28,6 +28,7 @@ > #include "Editor.h" > > #include "AXObjectCache.h" >+#include "AlternativeTextController.h" > #include "ApplyStyleCommand.h" > #include "CSSComputedStyleDeclaration.h" > #include "CSSProperty.h" >@@ -37,7 +38,6 @@ > #include "CachedResourceLoader.h" > #include "ClipboardEvent.h" > #include "CompositionEvent.h" >-#include "SpellingCorrectionController.h" > #include "CreateLinkCommand.h" > #include "DeleteButtonController.h" > #include "DeleteSelectionCommand.h" >@@ -482,7 +482,7 @@ void Editor::respondToChangedSelection(c > client()->respondToChangedSelection(m_frame); > setStartNewKillRingSequence(true); > m_deleteButtonController->respondToChangedSelection(oldSelection); >- m_spellingCorrector->respondToChangedSelection(oldSelection); >+ m_alternativeTextController->respondToChangedSelection(oldSelection); > } > > void Editor::respondToChangedContents(const VisibleSelection& endingSelection) >@@ -782,7 +782,7 @@ void Editor::appliedEditing(PassRefPtr<C > dispatchEditableContentChangedEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement()); > VisibleSelection newSelection(cmd->endingSelection()); > >- m_spellingCorrector->respondToAppliedEditing(cmd.get()); >+ m_alternativeTextController->respondToAppliedEditing(cmd.get()); > > // Don't clear the typing style with this selection change. We do those things elsewhere if necessary. > changeSelectionAfterCommand(newSelection, false, false); >@@ -812,7 +812,7 @@ void Editor::unappliedEditing(PassRefPtr > > VisibleSelection newSelection(cmd->startingSelection()); > changeSelectionAfterCommand(newSelection, true, true); >- m_spellingCorrector->respondToUnappliedEditing(cmd.get()); >+ m_alternativeTextController->respondToUnappliedEditing(cmd.get()); > > m_lastEditCommand = 0; > if (client()) >@@ -844,7 +844,7 @@ Editor::Editor(Frame* frame) > , m_shouldStyleWithCSS(false) > , m_killRing(adoptPtr(new KillRing)) > , m_spellChecker(adoptPtr(new SpellChecker(frame))) >- , m_spellingCorrector(adoptPtr(new SpellingCorrectionController(frame))) >+ , m_alternativeTextController(adoptPtr(new AlternativeTextController(frame))) > , m_areMarkedTextMatchesHighlighted(false) > , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv) > { >@@ -895,7 +895,7 @@ bool Editor::insertTextWithoutSendingTex > if (text.length() == 1 && isPunct(text[0]) && !isAmbiguousBoundaryCharacter(text[0])) > shouldConsiderApplyingAutocorrection = true; > >- bool autocorrectionWasApplied = shouldConsiderApplyingAutocorrection && m_spellingCorrector->applyAutocorrectionBeforeTypingIfAppropriate(); >+ bool autocorrectionWasApplied = shouldConsiderApplyingAutocorrection && m_alternativeTextController->applyAutocorrectionBeforeTypingIfAppropriate(); > > // Get the selection to use for the event that triggered this insertText. > // If the event handler changed the selection, we may want to use a different selection >@@ -931,7 +931,7 @@ bool Editor::insertLineBreak() > if (!shouldInsertText("\n", m_frame->selection()->toNormalizedRange().get(), EditorInsertActionTyped)) > return true; > >- bool autocorrectionIsApplied = m_spellingCorrector->applyAutocorrectionBeforeTypingIfAppropriate(); >+ bool autocorrectionIsApplied = m_alternativeTextController->applyAutocorrectionBeforeTypingIfAppropriate(); > TypingCommand::insertLineBreak(m_frame->document(), autocorrectionIsApplied ? TypingCommand::RetainAutocorrectionIndicator : 0); > revealSelectionAfterEditingOperation(); > >@@ -949,7 +949,7 @@ bool Editor::insertParagraphSeparator() > if (!shouldInsertText("\n", m_frame->selection()->toNormalizedRange().get(), EditorInsertActionTyped)) > return true; > >- bool autocorrectionIsApplied = m_spellingCorrector->applyAutocorrectionBeforeTypingIfAppropriate(); >+ bool autocorrectionIsApplied = m_alternativeTextController->applyAutocorrectionBeforeTypingIfAppropriate(); > TypingCommand::insertParagraphSeparator(m_frame->document(), autocorrectionIsApplied ? TypingCommand::RetainAutocorrectionIndicator : 0); > revealSelectionAfterEditingOperation(); > >@@ -1173,7 +1173,7 @@ void Editor::toggleAutomaticTextReplacem > > bool Editor::isAutomaticSpellingCorrectionEnabled() > { >- return m_spellingCorrector->isAutomaticSpellingCorrectionEnabled(); >+ return m_alternativeTextController->isAutomaticSpellingCorrectionEnabled(); > } > > void Editor::toggleAutomaticSpellingCorrection() >@@ -1772,7 +1772,7 @@ void Editor::markMisspellingsAfterTyping > #endif > > if (unifiedTextCheckerEnabled()) { >- m_spellingCorrector->applyPendingCorrection(selectionAfterTyping); >+ m_alternativeTextController->applyPendingCorrection(selectionAfterTyping); > > TextCheckingTypeMask textCheckingOptions = 0; > >@@ -1912,7 +1912,7 @@ void Editor::markAllMisspellingsAndBadGr > ASSERT(unifiedTextCheckerEnabled()); > > // There shouldn't be pending autocorrection at this moment. >- ASSERT(!m_spellingCorrector->hasPendingCorrection()); >+ ASSERT(!m_alternativeTextController->hasPendingCorrection()); > > bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar; > bool shouldShowCorrectionPanel = textCheckingOptions & TextCheckingTypeShowCorrectionPanel; >@@ -2005,7 +2005,7 @@ void Editor::markAndReplaceFor(PassRefPt > if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && resultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= spellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { > ASSERT(resultLength > 0 && resultLocation >= 0); > RefPtr<Range> misspellingRange = paragraph.subrange(resultLocation, resultLength); >- if (!m_spellingCorrector->isSpellingMarkerAllowed(misspellingRange)) >+ if (!m_alternativeTextController->isSpellingMarkerAllowed(misspellingRange)) > continue; > misspellingRange->startContainer()->document()->markers()->addMarker(misspellingRange.get(), DocumentMarker::Spelling, result->replacement); > } else if (shouldMarkGrammar && result->type == TextCheckingTypeGrammar && paragraph.checkingRangeCovers(resultLocation, resultLength)) { >@@ -2048,7 +2048,7 @@ void Editor::markAndReplaceFor(PassRefPt > continue; > > String replacedString = plainText(rangeToReplace.get()); >- bool existingMarkersPermitReplacement = m_spellingCorrector->processMarkersOnTextToBeReplacedByResult(result, rangeToReplace.get(), replacedString); >+ bool existingMarkersPermitReplacement = m_alternativeTextController->processMarkersOnTextToBeReplacedByResult(result, rangeToReplace.get(), replacedString); > if (!existingMarkersPermitReplacement) > continue; > >@@ -2059,7 +2059,7 @@ void Editor::markAndReplaceFor(PassRefPt > // shouldShowCorrectionPanel can be true only when the panel is available. > if (resultLocation + resultLength == spellingRangeEndOffset) { > // We only show the correction panel on the last word. >- m_spellingCorrector->show(rangeToReplace, result->replacement); >+ m_alternativeTextController->show(rangeToReplace, result->replacement); > break; > } > // If this function is called for showing correction panel, we ignore other correction or replacement. >@@ -2095,7 +2095,7 @@ void Editor::markAndReplaceFor(PassRefPt > > // Add a marker so that corrections can easily be undone and won't be re-corrected. > if (result->type == TextCheckingTypeCorrection) >- m_spellingCorrector->markCorrection(paragraph.subrange(resultLocation, replacementLength), replacedString); >+ m_alternativeTextController->markCorrection(paragraph.subrange(resultLocation, replacementLength), replacedString); > } > } > } >@@ -2128,12 +2128,12 @@ void Editor::changeBackToReplacedString( > if (!shouldInsertText(replacedString, selection.get(), EditorInsertActionPasted)) > return; > >- m_spellingCorrector->recordAutocorrectionResponseReversed(replacedString, selection); >+ m_alternativeTextController->recordAutocorrectionResponseReversed(replacedString, selection); > TextCheckingParagraph paragraph(selection); > replaceSelectionWithText(replacedString, false, false); > RefPtr<Range> changedRange = paragraph.subrange(paragraph.checkingStart(), replacedString.length()); > changedRange->startContainer()->document()->markers()->addMarker(changedRange.get(), DocumentMarker::Replacement, String()); >- m_spellingCorrector->markReversed(changedRange.get()); >+ m_alternativeTextController->markReversed(changedRange.get()); > } > > >@@ -2157,12 +2157,12 @@ void Editor::markMisspellingsAndBadGramm > > void Editor::unappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction) > { >- m_spellingCorrector->respondToUnappliedSpellCorrection(selectionOfCorrected, corrected, correction); >+ m_alternativeTextController->respondToUnappliedSpellCorrection(selectionOfCorrected, corrected, correction); > } > > void Editor::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSelectionAtWordBoundary) > { >- if (!m_spellingCorrector->shouldRemoveMarkersUponEditing()) >+ if (!m_alternativeTextController->shouldRemoveMarkersUponEditing()) > return; > > // We want to remove the markers from a word if an editing command will change the word. This can happen in one of >@@ -2232,7 +2232,7 @@ void Editor::updateMarkersForWordsAffect > > void Editor::deletedAutocorrectionAtPosition(const Position& position, const String& originalString) > { >- m_spellingCorrector->deletedAutocorrectionAtPosition(position, originalString); >+ m_alternativeTextController->deletedAutocorrectionAtPosition(position, originalString); > } > > PassRefPtr<Range> Editor::rangeForPoint(const IntPoint& windowPoint) >@@ -2357,20 +2357,20 @@ void Editor::addToKillRing(Range* range, > m_shouldStartNewKillRingSequence = false; > } > >-void Editor::startCorrectionPanelTimer() >+void Editor::startAlternativeTextUITimer() > { >- m_spellingCorrector->startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeCorrection); >+ m_alternativeTextController->startAlternativeTextUITimer(AlternativeTextTypeCorrection); > } > >-void Editor::handleCorrectionPanelResult(const String& correction) >+void Editor::handleAlternativeTextUIResult(const String& correction) > { >- m_spellingCorrector->handleCorrectionPanelResult(correction); >+ m_alternativeTextController->handleAlternativeTextUIResult(correction); > } > > > void Editor::dismissCorrectionPanelAsIgnored() > { >- m_spellingCorrector->dismiss(ReasonForDismissingCorrectionPanelIgnored); >+ m_alternativeTextController->dismiss(ReasonForDismissingAlternativeTextIgnored); > } > > bool Editor::insideVisibleArea(const LayoutPoint& point) const >@@ -2886,7 +2886,7 @@ void Editor::setMarkedTextMatchesAreHigh > > void Editor::respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions options) > { >- m_spellingCorrector->stopPendingCorrection(oldSelection); >+ m_alternativeTextController->stopPendingCorrection(oldSelection); > > bool closeTyping = options & FrameSelection::CloseTyping; > bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabled(); >Index: Source/WebCore/editing/Editor.h >=================================================================== >--- Source/WebCore/editing/Editor.h (revision 112917) >+++ Source/WebCore/editing/Editor.h (working copy) >@@ -61,7 +61,7 @@ class Pasteboard; > class SimpleFontData; > class SpellChecker; > class SpellCheckRequest; >-class SpellingCorrectionController; >+class AlternativeTextController; > class StylePropertySet; > class Text; > class TextCheckerClient; >@@ -319,9 +319,9 @@ public: > > void addToKillRing(Range*, bool prepend); > >- void startCorrectionPanelTimer(); >+ void startAlternativeTextUITimer(); > // If user confirmed a correction in the correction panel, correction has non-zero length, otherwise it means that user has dismissed the panel. >- void handleCorrectionPanelResult(const String& correction); >+ void handleAlternativeTextUIResult(const String& correction); > void dismissCorrectionPanelAsIgnored(); > > void pasteAsFragment(PassRefPtr<DocumentFragment>, bool smartReplace, bool matchStyle); >@@ -401,7 +401,7 @@ private: > bool m_shouldStyleWithCSS; > OwnPtr<KillRing> m_killRing; > OwnPtr<SpellChecker> m_spellChecker; >- OwnPtr<SpellingCorrectionController> m_spellingCorrector; >+ OwnPtr<AlternativeTextController> m_alternativeTextController; > VisibleSelection m_mark; > bool m_areMarkedTextMatchesHighlighted; > EditorParagraphSeparator m_defaultParagraphSeparator; >Index: Source/WebCore/editing/SpellingCorrectionCommand.cpp >=================================================================== >--- Source/WebCore/editing/SpellingCorrectionCommand.cpp (revision 112917) >+++ Source/WebCore/editing/SpellingCorrectionCommand.cpp (working copy) >@@ -26,12 +26,12 @@ > #include "config.h" > #include "SpellingCorrectionCommand.h" > >+#include "AlternativeTextController.h" > #include "Document.h" > #include "DocumentFragment.h" > #include "Frame.h" > #include "ReplaceSelectionCommand.h" > #include "SetSelectionCommand.h" >-#include "SpellingCorrectionController.h" > #include "TextIterator.h" > #include "markup.h" > >Index: Source/WebCore/editing/SpellingCorrectionController.cpp >=================================================================== >--- Source/WebCore/editing/SpellingCorrectionController.cpp (revision 112917) >+++ Source/WebCore/editing/SpellingCorrectionController.cpp (working copy) >@@ -1,565 +0,0 @@ >-/* >- * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. >- * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions >- * are met: >- * 1. Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * 2. Redistributions in binary form must reproduce the above copyright >- * notice, this list of conditions and the following disclaimer in the >- * documentation and/or other materials provided with the distribution. >- * >- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY >- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR >- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >- */ >- >-#include "config.h" >-#include "SpellingCorrectionController.h" >- >-#include "DocumentMarkerController.h" >-#include "EditCommand.h" >-#include "EditorClient.h" >-#include "FloatQuad.h" >-#include "Frame.h" >-#include "FrameView.h" >-#include "Page.h" >-#include "SpellingCorrectionCommand.h" >-#include "TextCheckerClient.h" >-#include "TextCheckingHelper.h" >-#include "TextIterator.h" >-#include "VisibleSelection.h" >-#include "htmlediting.h" >-#include "markup.h" >-#include "visible_units.h" >- >-namespace WebCore { >- >-using namespace std; >-using namespace WTF; >- >-#if USE(AUTOCORRECTION_PANEL) >- >-static const Vector<DocumentMarker::MarkerType>& markerTypesForAutocorrection() >-{ >- DEFINE_STATIC_LOCAL(Vector<DocumentMarker::MarkerType>, markerTypesForAutoCorrection, ()); >- if (markerTypesForAutoCorrection.isEmpty()) { >- markerTypesForAutoCorrection.append(DocumentMarker::Replacement); >- markerTypesForAutoCorrection.append(DocumentMarker::CorrectionIndicator); >- markerTypesForAutoCorrection.append(DocumentMarker::SpellCheckingExemption); >- markerTypesForAutoCorrection.append(DocumentMarker::Autocorrected); >- } >- return markerTypesForAutoCorrection; >-} >- >-static const Vector<DocumentMarker::MarkerType>& markerTypesForReplacement() >-{ >- DEFINE_STATIC_LOCAL(Vector<DocumentMarker::MarkerType>, markerTypesForReplacement, ()); >- if (markerTypesForReplacement.isEmpty()) { >- markerTypesForReplacement.append(DocumentMarker::Replacement); >- markerTypesForReplacement.append(DocumentMarker::SpellCheckingExemption); >- } >- return markerTypesForReplacement; >-} >- >-static bool markersHaveIdenticalDescription(const Vector<DocumentMarker*>& markers) >-{ >- if (markers.isEmpty()) >- return true; >- >- const String& description = markers[0]->description(); >- for (size_t i = 1; i < markers.size(); ++i) { >- if (description != markers[i]->description()) >- return false; >- } >- return true; >-} >- >-SpellingCorrectionController::SpellingCorrectionController(Frame* frame) >- : m_frame(frame) >- , m_correctionPanelTimer(this, &SpellingCorrectionController::correctionPanelTimerFired) >-{ >-} >- >-SpellingCorrectionController::~SpellingCorrectionController() >-{ >- dismiss(ReasonForDismissingCorrectionPanelIgnored); >-} >- >-void SpellingCorrectionController::startCorrectionPanelTimer(CorrectionPanelInfo::PanelType type) >-{ >- const double correctionPanelTimerInterval = 0.3; >- if (!isAutomaticSpellingCorrectionEnabled()) >- return; >- >- // If type is PanelTypeReversion, then the new range has been set. So we shouldn't clear it. >- if (type == CorrectionPanelInfo::PanelTypeCorrection) >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >- m_correctionPanelInfo.panelType = type; >- m_correctionPanelTimer.startOneShot(correctionPanelTimerInterval); >-} >- >-void SpellingCorrectionController::stopCorrectionPanelTimer() >-{ >- m_correctionPanelTimer.stop(); >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >-} >- >-void SpellingCorrectionController::stopPendingCorrection(const VisibleSelection& oldSelection) >-{ >- // Make sure there's no pending autocorrection before we call markMisspellingsAndBadGrammar() below. >- VisibleSelection currentSelection(m_frame->selection()->selection()); >- if (currentSelection == oldSelection) >- return; >- >- stopCorrectionPanelTimer(); >- dismiss(ReasonForDismissingCorrectionPanelIgnored); >-} >- >-void SpellingCorrectionController::applyPendingCorrection(const VisibleSelection& selectionAfterTyping) >-{ >- // Apply pending autocorrection before next round of spell checking. >- bool doApplyCorrection = true; >- VisiblePosition startOfSelection = selectionAfterTyping.visibleStart(); >- VisibleSelection currentWord = VisibleSelection(startOfWord(startOfSelection, LeftWordIfOnBoundary), endOfWord(startOfSelection, RightWordIfOnBoundary)); >- if (currentWord.visibleEnd() == startOfSelection) { >- String wordText = plainText(currentWord.toNormalizedRange().get()); >- if (wordText.length() > 0 && isAmbiguousBoundaryCharacter(wordText[wordText.length() - 1])) >- doApplyCorrection = false; >- } >- if (doApplyCorrection) >- handleCorrectionPanelResult(dismissSoon(ReasonForDismissingCorrectionPanelAccepted)); >- else >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >-} >- >-bool SpellingCorrectionController::hasPendingCorrection() const >-{ >- return m_correctionPanelInfo.rangeToBeReplaced; >-} >- >-bool SpellingCorrectionController::isSpellingMarkerAllowed(PassRefPtr<Range> misspellingRange) const >-{ >- return !m_frame->document()->markers()->hasMarkers(misspellingRange.get(), DocumentMarker::SpellCheckingExemption); >-} >- >-void SpellingCorrectionController::show(PassRefPtr<Range> rangeToReplace, const String& replacement) >-{ >- FloatRect boundingBox = rootViewRectForRange(rangeToReplace.get()); >- if (boundingBox.isEmpty()) >- return; >- m_correctionPanelInfo.replacedString = plainText(rangeToReplace.get()); >- m_correctionPanelInfo.rangeToBeReplaced = rangeToReplace; >- m_correctionPanelInfo.replacementString = replacement; >- m_correctionPanelInfo.isActive = true; >- client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, replacement, Vector<String>()); >-} >- >-void SpellingCorrectionController::handleCancelOperation() >-{ >- if (!m_correctionPanelInfo.isActive) >- return; >- m_correctionPanelInfo.isActive = false; >- dismiss(ReasonForDismissingCorrectionPanelCancelled); >-} >- >-void SpellingCorrectionController::dismiss(ReasonForDismissingCorrectionPanel reasonForDismissing) >-{ >- if (!m_correctionPanelInfo.isActive) >- return; >- m_correctionPanelInfo.isActive = false; >- m_correctionPanelIsDismissedByEditor = true; >- if (client()) >- client()->dismissCorrectionPanel(reasonForDismissing); >-} >- >-String SpellingCorrectionController::dismissSoon(ReasonForDismissingCorrectionPanel reasonForDismissing) >-{ >- if (!m_correctionPanelInfo.isActive) >- return String(); >- m_correctionPanelInfo.isActive = false; >- m_correctionPanelIsDismissedByEditor = true; >- if (!client()) >- return String(); >- return client()->dismissCorrectionPanelSoon(reasonForDismissing); >-} >- >-void SpellingCorrectionController::applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>& markerTypesToAdd) >-{ >- if (!m_correctionPanelInfo.rangeToBeReplaced) >- return; >- >- ExceptionCode ec = 0; >- RefPtr<Range> paragraphRangeContainingCorrection = m_correctionPanelInfo.rangeToBeReplaced->cloneRange(ec); >- if (ec) >- return; >- >- setStart(paragraphRangeContainingCorrection.get(), startOfParagraph(m_correctionPanelInfo.rangeToBeReplaced->startPosition())); >- setEnd(paragraphRangeContainingCorrection.get(), endOfParagraph(m_correctionPanelInfo.rangeToBeReplaced->endPosition())); >- >- // After we replace the word at range rangeToBeReplaced, we need to add markers to that range. >- // However, once the replacement took place, the value of rangeToBeReplaced is not valid anymore. >- // So before we carry out the replacement, we need to store the start position of rangeToBeReplaced >- // relative to the start position of the containing paragraph. We use correctionStartOffsetInParagraph >- // to store this value. In order to obtain this offset, we need to first create a range >- // which spans from the start of paragraph to the start position of rangeToBeReplaced. >- RefPtr<Range> correctionStartOffsetInParagraphAsRange = Range::create(paragraphRangeContainingCorrection->startContainer(ec)->document(), paragraphRangeContainingCorrection->startPosition(), paragraphRangeContainingCorrection->startPosition()); >- if (ec) >- return; >- >- Position startPositionOfRangeToBeReplaced = m_correctionPanelInfo.rangeToBeReplaced->startPosition(); >- correctionStartOffsetInParagraphAsRange->setEnd(startPositionOfRangeToBeReplaced.containerNode(), startPositionOfRangeToBeReplaced.computeOffsetInContainerNode(), ec); >- if (ec) >- return; >- >- // Take note of the location of autocorrection so that we can add marker after the replacement took place. >- int correctionStartOffsetInParagraph = TextIterator::rangeLength(correctionStartOffsetInParagraphAsRange.get()); >- >- // Clone the range, since the caller of this method may want to keep the original range around. >- RefPtr<Range> rangeToBeReplaced = m_correctionPanelInfo.rangeToBeReplaced->cloneRange(ec); >- applyCommand(SpellingCorrectionCommand::create(rangeToBeReplaced, m_correctionPanelInfo.replacementString)); >- setEnd(paragraphRangeContainingCorrection.get(), m_frame->selection()->selection().start()); >- RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, m_correctionPanelInfo.replacementString.length()); >- String newText = plainText(replacementRange.get()); >- >- // Check to see if replacement succeeded. >- if (newText != m_correctionPanelInfo.replacementString) >- return; >- >- DocumentMarkerController* markers = replacementRange->startContainer()->document()->markers(); >- size_t size = markerTypesToAdd.size(); >- for (size_t i = 0; i < size; ++i) { >- DocumentMarker::MarkerType markerType = markerTypesToAdd[i]; >- String description; >- if (m_correctionPanelInfo.panelType != CorrectionPanelInfo::PanelTypeReversion && (markerType == DocumentMarker::Replacement || markerType == DocumentMarker::Autocorrected)) >- description = m_correctionPanelInfo.replacedString; >- markers->addMarker(replacementRange.get(), markerType, description); >- } >-} >- >-bool SpellingCorrectionController::applyAutocorrectionBeforeTypingIfAppropriate() >-{ >- if (!m_correctionPanelInfo.rangeToBeReplaced || !m_correctionPanelInfo.isActive) >- return false; >- >- if (m_correctionPanelInfo.panelType != CorrectionPanelInfo::PanelTypeCorrection) >- return false; >- >- Position caretPosition = m_frame->selection()->selection().start(); >- >- if (m_correctionPanelInfo.rangeToBeReplaced->endPosition() == caretPosition) { >- handleCorrectionPanelResult(dismissSoon(ReasonForDismissingCorrectionPanelAccepted)); >- return true; >- } >- >- // Pending correction should always be where caret is. But in case this is not always true, we still want to dismiss the panel without accepting the correction. >- ASSERT(m_correctionPanelInfo.rangeToBeReplaced->endPosition() == caretPosition); >- dismiss(ReasonForDismissingCorrectionPanelIgnored); >- return false; >-} >- >-void SpellingCorrectionController::respondToUnappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction) >-{ >- client()->recordAutocorrectionResponse(EditorClient::AutocorrectionReverted, corrected, correction); >- m_frame->document()->updateLayout(); >- m_frame->selection()->setSelection(selectionOfCorrected, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::SpellCorrectionTriggered); >- RefPtr<Range> range = Range::create(m_frame->document(), m_frame->selection()->selection().start(), m_frame->selection()->selection().end()); >- >- DocumentMarkerController* markers = m_frame->document()->markers(); >- markers->removeMarkers(range.get(), DocumentMarker::Spelling | DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker); >- markers->addMarker(range.get(), DocumentMarker::Replacement); >- markers->addMarker(range.get(), DocumentMarker::SpellCheckingExemption); >-} >- >-void SpellingCorrectionController::correctionPanelTimerFired(Timer<SpellingCorrectionController>*) >-{ >- m_correctionPanelIsDismissedByEditor = false; >- switch (m_correctionPanelInfo.panelType) { >- case CorrectionPanelInfo::PanelTypeCorrection: { >- VisibleSelection selection(m_frame->selection()->selection()); >- VisiblePosition start(selection.start(), selection.affinity()); >- VisiblePosition p = startOfWord(start, LeftWordIfOnBoundary); >- VisibleSelection adjacentWords = VisibleSelection(p, start); >- m_frame->editor()->markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeSpelling | TextCheckingTypeShowCorrectionPanel, adjacentWords.toNormalizedRange().get(), 0); >- } >- break; >- case CorrectionPanelInfo::PanelTypeReversion: { >- if (!m_correctionPanelInfo.rangeToBeReplaced) >- break; >- m_correctionPanelInfo.isActive = true; >- m_correctionPanelInfo.replacedString = plainText(m_correctionPanelInfo.rangeToBeReplaced.get()); >- FloatRect boundingBox = rootViewRectForRange(m_correctionPanelInfo.rangeToBeReplaced.get()); >- if (!boundingBox.isEmpty()) >- client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, m_correctionPanelInfo.replacementString, Vector<String>()); >- } >- break; >- case CorrectionPanelInfo::PanelTypeSpellingSuggestions: { >- if (!m_correctionPanelInfo.rangeToBeReplaced || plainText(m_correctionPanelInfo.rangeToBeReplaced.get()) != m_correctionPanelInfo.replacedString) >- break; >- String paragraphText = plainText(TextCheckingParagraph(m_correctionPanelInfo.rangeToBeReplaced).paragraphRange().get()); >- Vector<String> suggestions; >- textChecker()->getGuessesForWord(m_correctionPanelInfo.replacedString, paragraphText, suggestions); >- if (suggestions.isEmpty()) { >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >- break; >- } >- String topSuggestion = suggestions.first(); >- suggestions.remove(0); >- m_correctionPanelInfo.isActive = true; >- FloatRect boundingBox = rootViewRectForRange(m_correctionPanelInfo.rangeToBeReplaced.get()); >- if (!boundingBox.isEmpty()) >- client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, topSuggestion, suggestions); >- } >- break; >- } >-} >- >-void SpellingCorrectionController::handleCorrectionPanelResult(const String& correction) >-{ >- Range* replacedRange = m_correctionPanelInfo.rangeToBeReplaced.get(); >- if (!replacedRange || m_frame->document() != replacedRange->ownerDocument()) >- return; >- >- String currentWord = plainText(m_correctionPanelInfo.rangeToBeReplaced.get()); >- // Check to see if the word we are about to correct has been changed between timer firing and callback being triggered. >- if (currentWord != m_correctionPanelInfo.replacedString) >- return; >- >- m_correctionPanelInfo.isActive = false; >- >- switch (m_correctionPanelInfo.panelType) { >- case CorrectionPanelInfo::PanelTypeCorrection: >- if (correction.length()) { >- m_correctionPanelInfo.replacementString = correction; >- applyCorrectionPanelInfo(markerTypesForAutocorrection()); >- } else if (!m_correctionPanelIsDismissedByEditor) >- replacedRange->startContainer()->document()->markers()->addMarker(replacedRange, DocumentMarker::RejectedCorrection, m_correctionPanelInfo.replacedString); >- break; >- case CorrectionPanelInfo::PanelTypeReversion: >- case CorrectionPanelInfo::PanelTypeSpellingSuggestions: >- if (correction.length()) { >- m_correctionPanelInfo.replacementString = correction; >- applyCorrectionPanelInfo(markerTypesForReplacement()); >- } >- break; >- } >- >- m_correctionPanelInfo.rangeToBeReplaced.clear(); >-} >- >-bool SpellingCorrectionController::isAutomaticSpellingCorrectionEnabled() >-{ >- return client() && client()->isAutomaticSpellingCorrectionEnabled(); >-} >- >-FloatRect SpellingCorrectionController::rootViewRectForRange(const Range* range) const >-{ >- FrameView* view = m_frame->view(); >- if (!view) >- return FloatRect(); >- Vector<FloatQuad> textQuads; >- range->textQuads(textQuads); >- FloatRect boundingRect; >- size_t size = textQuads.size(); >- for (size_t i = 0; i < size; ++i) >- boundingRect.unite(textQuads[i].boundingBox()); >- return view->contentsToRootView(IntRect(boundingRect)); >-} >- >-void SpellingCorrectionController::respondToChangedSelection(const VisibleSelection& oldSelection) >-{ >- VisibleSelection currentSelection(m_frame->selection()->selection()); >- // When user moves caret to the end of autocorrected word and pauses, we show the panel >- // containing the original pre-correction word so that user can quickly revert the >- // undesired autocorrection. Here, we start correction panel timer once we confirm that >- // the new caret position is at the end of a word. >- if (!currentSelection.isCaret() || currentSelection == oldSelection) >- return; >- >- VisiblePosition selectionPosition = currentSelection.start(); >- >- // Creating a Visible position triggers a layout and there is no >- // guarantee that the selection is still valid. >- if (selectionPosition.isNull()) >- return; >- >- VisiblePosition endPositionOfWord = endOfWord(selectionPosition, LeftWordIfOnBoundary); >- if (selectionPosition != endPositionOfWord) >- return; >- >- Position position = endPositionOfWord.deepEquivalent(); >- if (position.anchorType() != Position::PositionIsOffsetInAnchor) >- return; >- >- Node* node = position.containerNode(); >- int endOffset = position.offsetInContainerNode(); >- Vector<DocumentMarker*> markers = node->document()->markers()->markersFor(node); >- size_t markerCount = markers.size(); >- for (size_t i = 0; i < markerCount; ++i) { >- const DocumentMarker* marker = markers[i]; >- if (!shouldStartTimerFor(marker, endOffset)) >- continue; >- RefPtr<Range> wordRange = Range::create(m_frame->document(), node, marker->startOffset(), node, marker->endOffset()); >- String currentWord = plainText(wordRange.get()); >- if (!currentWord.length()) >- continue; >- >- m_correctionPanelInfo.rangeToBeReplaced = wordRange; >- m_correctionPanelInfo.replacedString = currentWord; >- if (marker->type() == DocumentMarker::Spelling) >- startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeSpellingSuggestions); >- else { >- m_correctionPanelInfo.replacementString = marker->description(); >- startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeReversion); >- } >- >- break; >- } >-} >- >-void SpellingCorrectionController::respondToAppliedEditing(CompositeEditCommand* command) >-{ >- if (command->isTopLevelCommand() && !command->shouldRetainAutocorrectionIndicator()) >- m_frame->document()->markers()->removeMarkers(DocumentMarker::CorrectionIndicator); >- >- markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(command); >- m_originalStringForLastDeletedAutocorrection = String(); >-} >- >-void SpellingCorrectionController::respondToUnappliedEditing(EditCommandComposition* command) >-{ >- if (!command->wasCreateLinkCommand()) >- 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; >-} >- >-TextCheckerClient* SpellingCorrectionController::textChecker() >-{ >- if (EditorClient* owner = client()) >- return owner->textChecker(); >- return 0; >-} >- >-void SpellingCorrectionController::recordAutocorrectionResponseReversed(const String& replacedString, const String& replacementString) >-{ >- client()->recordAutocorrectionResponse(EditorClient::AutocorrectionReverted, replacedString, replacementString); >-} >- >-void SpellingCorrectionController::recordAutocorrectionResponseReversed(const String& replacedString, PassRefPtr<Range> replacementRange) >-{ >- recordAutocorrectionResponseReversed(replacedString, plainText(replacementRange.get())); >-} >- >-void SpellingCorrectionController::markReversed(PassRefPtr<Range> changedRange) >-{ >- changedRange->startContainer()->document()->markers()->removeMarkers(changedRange.get(), DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker); >- changedRange->startContainer()->document()->markers()->addMarker(changedRange.get(), DocumentMarker::SpellCheckingExemption); >-} >- >-void SpellingCorrectionController::markCorrection(PassRefPtr<Range> replacedRange, const String& replacedString) >-{ >- Vector<DocumentMarker::MarkerType> markerTypesToAdd = markerTypesForAutocorrection(); >- DocumentMarkerController* markers = replacedRange->startContainer()->document()->markers(); >- for (size_t i = 0; i < markerTypesToAdd.size(); ++i) { >- DocumentMarker::MarkerType markerType = markerTypesToAdd[i]; >- if (markerType == DocumentMarker::Replacement || markerType == DocumentMarker::Autocorrected) >- markers->addMarker(replacedRange.get(), markerType, replacedString); >- else >- markers->addMarker(replacedRange.get(), markerType); >- } >-} >- >-void SpellingCorrectionController::recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction) >-{ >- if (!rangeOfCorrection) >- return; >- DocumentMarkerController* markers = rangeOfCorrection->startContainer()->document()->markers(); >- Vector<DocumentMarker*> correctedOnceMarkers = markers->markersInRange(rangeOfCorrection, DocumentMarker::Autocorrected); >- if (correctedOnceMarkers.isEmpty()) >- return; >- >- // Spelling corrected text has been edited. We need to determine whether user has reverted it to original text or >- // edited it to something else, and notify spellchecker accordingly. >- if (markersHaveIdenticalDescription(correctedOnceMarkers) && correctedOnceMarkers[0]->description() == corrected) >- client()->recordAutocorrectionResponse(EditorClient::AutocorrectionReverted, corrected, correction); >- else >- client()->recordAutocorrectionResponse(EditorClient::AutocorrectionEdited, corrected, correction); >- markers->removeMarkers(rangeOfCorrection, DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker); >-} >- >-void SpellingCorrectionController::deletedAutocorrectionAtPosition(const Position& position, const String& originalString) >-{ >- m_originalStringForLastDeletedAutocorrection = originalString; >- m_positionForLastDeletedAutocorrection = position; >-} >- >-void SpellingCorrectionController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand* command) >-{ >- Position endOfSelection = command->endingSelection().end(); >- if (endOfSelection != m_positionForLastDeletedAutocorrection) >- return; >- >- Position precedingCharacterPosition = endOfSelection.previous(); >- if (endOfSelection == precedingCharacterPosition) >- return; >- >- RefPtr<Range> precedingCharacterRange = Range::create(m_frame->document(), precedingCharacterPosition, endOfSelection); >- String string = plainText(precedingCharacterRange.get()); >- if (string.isEmpty() || !isWhitespace(string[string.length() - 1])) >- return; >- >- // Mark this whitespace to indicate we have deleted an autocorrection following this >- // whitespace. So if the user types the same original word again at this position, we >- // won't autocorrect it again. >- m_frame->document()->markers()->addMarker(precedingCharacterRange.get(), DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection); >-} >- >-bool SpellingCorrectionController::processMarkersOnTextToBeReplacedByResult(const TextCheckingResult* result, Range* rangeToBeReplaced, const String& stringToBeReplaced) >-{ >- DocumentMarkerController* markerController = m_frame->document()->markers(); >- if (markerController->hasMarkers(rangeToBeReplaced, DocumentMarker::Replacement)) { >- if (result->type == TextCheckingTypeCorrection) >- recordSpellcheckerResponseForModifiedCorrection(rangeToBeReplaced, stringToBeReplaced, result->replacement); >- return false; >- } >- >- if (markerController->hasMarkers(rangeToBeReplaced, DocumentMarker::RejectedCorrection)) >- return false; >- >- Position beginningOfRange = rangeToBeReplaced->startPosition(); >- Position precedingCharacterPosition = beginningOfRange.previous(); >- RefPtr<Range> precedingCharacterRange = Range::create(m_frame->document(), precedingCharacterPosition, beginningOfRange); >- >- Vector<DocumentMarker*> markers = markerController->markersInRange(precedingCharacterRange.get(), DocumentMarker::DeletedAutocorrection); >- >- for (size_t i = 0; i < markers.size(); ++i) { >- if (markers[i]->description() == stringToBeReplaced) >- return false; >- } >- >- return true; >-} >- >-#endif >- >-} // namespace WebCore >Index: Source/WebCore/editing/SpellingCorrectionController.h >=================================================================== >--- Source/WebCore/editing/SpellingCorrectionController.h (revision 112917) >+++ Source/WebCore/editing/SpellingCorrectionController.h (working copy) >@@ -1,157 +0,0 @@ >-/* >- * Copyright (C) 2010 Apple Inc. All rights reserved. >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions >- * are met: >- * 1. Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * 2. Redistributions in binary form must reproduce the above copyright >- * notice, this list of conditions and the following disclaimer in the >- * documentation and/or other materials provided with the distribution. >- * >- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY >- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR >- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >- */ >- >-#ifndef SpellingCorrectionController_h >-#define SpellingCorrectionController_h >- >-#include "DocumentMarker.h" >-#include "Range.h" >-#include "TextChecking.h" >-#include "Timer.h" >-#include "VisibleSelection.h" >-#include <wtf/Noncopyable.h> >-#include <wtf/UnusedParam.h> >- >-namespace WebCore { >- >-class CompositeEditCommand; >-class EditorClient; >-class EditCommand; >-class EditCommandComposition; >-class Frame; >-class TextCheckerClient; >- >-struct CorrectionPanelInfo { >- enum PanelType { >- PanelTypeCorrection = 0, >- PanelTypeReversion, >- PanelTypeSpellingSuggestions >- }; >- >- RefPtr<Range> rangeToBeReplaced; >- String replacedString; >- String replacementString; >- PanelType panelType; >- bool isActive; >-}; >- >-struct TextCheckingResult; >- >-enum ReasonForDismissingCorrectionPanel { >- ReasonForDismissingCorrectionPanelCancelled = 0, >- ReasonForDismissingCorrectionPanelIgnored, >- ReasonForDismissingCorrectionPanelAccepted >-}; >- >-#if USE(AUTOCORRECTION_PANEL) >-#define UNLESS_ENABLED(functionBody) ; >-#else >-#define UNLESS_ENABLED(functionBody) functionBody >-#endif >- >-class SpellingCorrectionController { >- WTF_MAKE_NONCOPYABLE(SpellingCorrectionController); WTF_MAKE_FAST_ALLOCATED; >-public: >- SpellingCorrectionController(Frame*) UNLESS_ENABLED({}) >- ~SpellingCorrectionController() UNLESS_ENABLED({}) >- >- void startCorrectionPanelTimer(CorrectionPanelInfo::PanelType) UNLESS_ENABLED({}) >- void stopCorrectionPanelTimer() UNLESS_ENABLED({}) >- >- void dismiss(ReasonForDismissingCorrectionPanel) UNLESS_ENABLED({}) >- String dismissSoon(ReasonForDismissingCorrectionPanel) UNLESS_ENABLED({ return String(); }) >- void show(PassRefPtr<Range> rangeToReplace, const String& replacement) UNLESS_ENABLED({ UNUSED_PARAM(rangeToReplace); UNUSED_PARAM(replacement); }) >- >- void applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>&) UNLESS_ENABLED({}) >- // Return true if correction was applied, false otherwise. >- 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(CompositeEditCommand*) UNLESS_ENABLED({ }) >- void respondToUnappliedEditing(EditCommandComposition*) UNLESS_ENABLED({ }) >- void respondToChangedSelection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); }) >- >- void stopPendingCorrection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); }) >- void applyPendingCorrection(const VisibleSelection& selectionAfterTyping) UNLESS_ENABLED({ UNUSED_PARAM(selectionAfterTyping); }) >- >- void handleCorrectionPanelResult(const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(correction); }) >- void handleCancelOperation() UNLESS_ENABLED({}) >- >- bool hasPendingCorrection() const UNLESS_ENABLED({ return false; }) >- bool isSpellingMarkerAllowed(PassRefPtr<Range> misspellingRange) const UNLESS_ENABLED({ UNUSED_PARAM(misspellingRange); return true; }) >- bool isAutomaticSpellingCorrectionEnabled() UNLESS_ENABLED({ return false; }) >- bool shouldRemoveMarkersUponEditing(); >- >- void correctionPanelTimerFired(Timer<SpellingCorrectionController>*) UNLESS_ENABLED({}) >- void recordAutocorrectionResponseReversed(const String& replacedString, PassRefPtr<Range> replacementRange) UNLESS_ENABLED({ UNUSED_PARAM(replacedString); UNUSED_PARAM(replacementRange); }) >- void markReversed(PassRefPtr<Range> changedRange) UNLESS_ENABLED({ UNUSED_PARAM(changedRange); }) >- void markCorrection(PassRefPtr<Range> replacedRange, const String& replacedString) UNLESS_ENABLED({ UNUSED_PARAM(replacedRange); UNUSED_PARAM(replacedString); }) >- void recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(rangeOfCorrection); UNUSED_PARAM(corrected); UNUSED_PARAM(correction); }) >- >- // This function returns false if the replacement should not be carried out. >- bool processMarkersOnTextToBeReplacedByResult(const TextCheckingResult*, Range* rangeToBeReplaced, const String& stringToBeReplaced) UNLESS_ENABLED({ UNUSED_PARAM(rangeToBeReplaced); UNUSED_PARAM(stringToBeReplaced); return true; }); >- void deletedAutocorrectionAtPosition(const Position&, const String& originalString) UNLESS_ENABLED({ UNUSED_PARAM(originalString); }) >- >-#if USE(AUTOCORRECTION_PANEL) >-private: >- void recordAutocorrectionResponseReversed(const String& replacedString, const String& replacementString); >- >- bool shouldStartTimerFor(const DocumentMarker* marker, int endOffset) const >- { >- return (((marker->type() == DocumentMarker::Replacement && !marker->description().isNull()) >- || marker->type() == DocumentMarker::Spelling) && static_cast<int>(marker->endOffset()) == endOffset); >- } >- >- EditorClient* client(); >- TextCheckerClient* textChecker(); >- FloatRect rootViewRectForRange(const Range*) const; >- void markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand*); >- >- EditorClient* m_client; >- Frame* m_frame; >- >- Timer<SpellingCorrectionController> m_correctionPanelTimer; >- CorrectionPanelInfo m_correctionPanelInfo; >- bool m_correctionPanelIsDismissedByEditor; >- >- String m_originalStringForLastDeletedAutocorrection; >- Position m_positionForLastDeletedAutocorrection; >-#endif >-}; >- >-#undef UNLESS_ENABLED >- >-inline bool SpellingCorrectionController::shouldRemoveMarkersUponEditing() >-{ >-#if USE(MARKER_REMOVAL_UPON_EDITING) >- return true; >-#else >- return false; >-#endif >-} >- >-} // namespace WebCore >- >-#endif // SpellingCorrectionController_h >Index: Source/WebCore/editing/TypingCommand.cpp >=================================================================== >--- Source/WebCore/editing/TypingCommand.cpp (revision 112917) >+++ Source/WebCore/editing/TypingCommand.cpp (working copy) >@@ -328,7 +328,7 @@ void TypingCommand::markMisspellingsAfte > strippedPreviousWord = plainText(range.get()).stripWhiteSpace(); > frame->editor()->markMisspellingsAfterTypingToWord(p1, endingSelection(), !strippedPreviousWord.isEmpty()); > } else if (commandType == TypingCommand::InsertText) >- frame->editor()->startCorrectionPanelTimer(); >+ frame->editor()->startAlternativeTextUITimer(); > } > } > >Index: Source/WebCore/loader/EmptyClients.h >=================================================================== >--- Source/WebCore/loader/EmptyClients.h (revision 112917) >+++ Source/WebCore/loader/EmptyClients.h (working copy) >@@ -520,9 +520,9 @@ public: > TextCheckerClient* textChecker() { return &m_textCheckerClient; } > > #if USE(AUTOCORRECTION_PANEL) >- virtual void showCorrectionPanel(CorrectionPanelInfo::PanelType, const FloatRect&, const String&, const String&, const Vector<String>&) { } >- virtual void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel) { } >- virtual String dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanel) { return String(); } >+ virtual void showCorrectionPanel(AlternativeTextType, const FloatRect&, const String&, const String&, const Vector<String>&) { } >+ virtual void dismissCorrectionPanel(ReasonForDismissingAlternativeText) { } >+ virtual String dismissCorrectionPanelSoon(ReasonForDismissingAlternativeText) { return String(); } > virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String&, const String&) { } > #endif > virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail&) { } >Index: Source/WebCore/page/EditorClient.h >=================================================================== >--- Source/WebCore/page/EditorClient.h (revision 112917) >+++ Source/WebCore/page/EditorClient.h (working copy) >@@ -27,7 +27,7 @@ > #ifndef EditorClient_h > #define EditorClient_h > >-#include "SpellingCorrectionController.h" >+#include "AlternativeTextController.h" > #include "EditorInsertAction.h" > #include "FloatRect.h" > #include "TextAffinity.h" >@@ -152,9 +152,9 @@ public: > }; > > #if USE(AUTOCORRECTION_PANEL) >- virtual void showCorrectionPanel(CorrectionPanelInfo::PanelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacmentString, const Vector<String>& alternativeReplacementStrings) = 0; >- virtual void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel) = 0; >- virtual String dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanel) = 0; >+ virtual void showCorrectionPanel(AlternativeTextType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacmentString, const Vector<String>& alternativeReplacementStrings) = 0; >+ virtual void dismissCorrectionPanel(ReasonForDismissingAlternativeText) = 0; >+ virtual String dismissCorrectionPanelSoon(ReasonForDismissingAlternativeText) = 0; > virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString) = 0; > #endif > >Index: Source/WebKit2/ChangeLog >=================================================================== >--- Source/WebKit2/ChangeLog (revision 112931) >+++ Source/WebKit2/ChangeLog (working copy) >@@ -1,3 +1,53 @@ >+2012-04-02 Jia Pu <jpu@apple.com> >+ >+ Rename SpellingCorrectionController to AlternativeTextController. >+ https://bugs.webkit.org/show_bug.cgi?id=82942 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ These changes are simply for adopting new class names. >+ >+ * UIProcess/API/mac/PageClientImpl.h: >+ (PageClientImpl): >+ * UIProcess/API/mac/PageClientImpl.mm: >+ (WebKit::PageClientImpl::showCorrectionPanel): >+ (WebKit::PageClientImpl::dismissCorrectionPanel): >+ (WebKit::PageClientImpl::dismissCorrectionPanelSoon): >+ * UIProcess/API/mac/WKView.mm: >+ (-[WKView handleCorrectionPanelResult:]): >+ * UIProcess/PageClient.h: >+ (PageClient): >+ * UIProcess/WebPageProxy.cpp: >+ (WebKit::WebPageProxy::didCommitLoadForFrame): >+ (WebKit::WebPageProxy::pageDidScroll): >+ (WebKit::WebPageProxy::processDidCrash): >+ (WebKit::WebPageProxy::showCorrectionPanel): >+ (WebKit::WebPageProxy::dismissCorrectionPanel): >+ (WebKit::WebPageProxy::dismissCorrectionPanelSoon): >+ (WebKit::WebPageProxy::handleAlternativeTextUIResult): >+ * UIProcess/WebPageProxy.h: >+ (WebPageProxy): >+ * UIProcess/mac/CorrectionPanel.h: >+ (CorrectionPanel): >+ * UIProcess/mac/CorrectionPanel.mm: >+ (correctionIndicatorType): >+ (WebKit::CorrectionPanel::CorrectionPanel): >+ (WebKit::CorrectionPanel::~CorrectionPanel): >+ (WebKit::CorrectionPanel::show): >+ (WebKit::CorrectionPanel::dismiss): >+ (WebKit::CorrectionPanel::dismissInternal): >+ (WebKit::CorrectionPanel::handleAcceptedReplacement): >+ * WebProcess/WebCoreSupport/WebEditorClient.h: >+ * WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm: >+ (WebKit::WebEditorClient::showCorrectionPanel): >+ (WebKit::WebEditorClient::dismissCorrectionPanel): >+ (WebKit::WebEditorClient::dismissCorrectionPanelSoon): >+ * WebProcess/WebPage/WebPage.cpp: >+ (WebKit::WebPage::handleAlternativeTextUIResult): >+ * WebProcess/WebPage/WebPage.h: >+ (WebPage): >+ * WebProcess/WebPage/WebPage.messages.in: >+ > 2012-04-02 Jesus Sanchez-Palencia <jesus.palencia@openbossa.org> > > [Qt][WK2] ResourceError::isCancellation() is always returning false >Index: Source/WebKit2/UIProcess/PageClient.h >=================================================================== >--- Source/WebKit2/UIProcess/PageClient.h (revision 112917) >+++ Source/WebKit2/UIProcess/PageClient.h (working copy) >@@ -29,8 +29,8 @@ > #include "ShareableBitmap.h" > #include "WebPageProxy.h" > #include "WebPopupMenuProxy.h" >+#include <WebCore/AlternativeTextController.h> > #include <WebCore/EditorClient.h> >-#include <WebCore/SpellingCorrectionController.h> > #include <wtf/Forward.h> > > #if PLATFORM(MAC) >@@ -185,9 +185,9 @@ public: > virtual CGContextRef containingWindowGraphicsContext() = 0; > virtual void didPerformDictionaryLookup(const String&, double scaleFactor, const DictionaryPopupInfo&) = 0; > virtual void dismissDictionaryLookupPanel() = 0; >- virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) = 0; >- virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel) = 0; >- virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel) = 0; >+ virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) = 0; >+ virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText) = 0; >+ virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText) = 0; > virtual void recordAutocorrectionResponse(WebCore::EditorClient::AutocorrectionResponseType, const String& replacedString, const String& replacementString) = 0; > virtual void recommendedScrollbarStyleDidChange(int32_t newStyle) = 0; > >Index: Source/WebKit2/UIProcess/WebPageProxy.cpp >=================================================================== >--- Source/WebKit2/UIProcess/WebPageProxy.cpp (revision 112917) >+++ Source/WebKit2/UIProcess/WebPageProxy.cpp (working copy) >@@ -1812,7 +1812,7 @@ void WebPageProxy::didCommitLoadForFrame > m_pageClient->resetTextInputState(); > #if !defined(BUILDING_ON_SNOW_LEOPARD) > // FIXME: Should this be moved inside resetTextInputState()? >- dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored); >+ dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored); > m_pageClient->dismissDictionaryLookupPanel(); > #endif > #endif >@@ -2369,7 +2369,7 @@ void WebPageProxy::pageDidScroll() > { > m_uiClient.pageDidScroll(this); > #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD) >- dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored); >+ dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored); > #endif > } > >@@ -3353,7 +3353,7 @@ void WebPageProxy::processDidCrash() > #endif > > #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD) >- dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored); >+ dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored); > m_pageClient->dismissDictionaryLookupPanel(); > #endif > } >@@ -3689,17 +3689,17 @@ void WebPageProxy::substitutionsPanelIsS > #if !defined(BUILDING_ON_SNOW_LEOPARD) > void WebPageProxy::showCorrectionPanel(int32_t panelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) > { >- m_pageClient->showCorrectionPanel((CorrectionPanelInfo::PanelType)panelType, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings); >+ m_pageClient->showCorrectionPanel((AlternativeTextType)panelType, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings); > } > > void WebPageProxy::dismissCorrectionPanel(int32_t reason) > { >- m_pageClient->dismissCorrectionPanel((ReasonForDismissingCorrectionPanel)reason); >+ m_pageClient->dismissCorrectionPanel((ReasonForDismissingAlternativeText)reason); > } > > void WebPageProxy::dismissCorrectionPanelSoon(int32_t reason, String& result) > { >- result = m_pageClient->dismissCorrectionPanelSoon((ReasonForDismissingCorrectionPanel)reason); >+ result = m_pageClient->dismissCorrectionPanelSoon((ReasonForDismissingAlternativeText)reason); > } > > void WebPageProxy::recordAutocorrectionResponse(int32_t responseType, const String& replacedString, const String& replacementString) >@@ -3708,11 +3708,11 @@ void WebPageProxy::recordAutocorrectionR > } > #endif // !defined(BUILDING_ON_SNOW_LEOPARD) > >-void WebPageProxy::handleCorrectionPanelResult(const String& result) >+void WebPageProxy::handleAlternativeTextUIResult(const String& result) > { > #if !defined(BUILDING_ON_SNOW_LEOPARD) > if (!isClosed()) >- process()->send(Messages::WebPage::HandleCorrectionPanelResult(result), m_pageID, 0); >+ process()->send(Messages::WebPage::HandleAlternativeTextUIResult(result), m_pageID, 0); > #endif > } > #endif // PLATFORM(MAC) >Index: Source/WebKit2/UIProcess/WebPageProxy.h >=================================================================== >--- Source/WebKit2/UIProcess/WebPageProxy.h (revision 112917) >+++ Source/WebKit2/UIProcess/WebPageProxy.h (working copy) >@@ -611,7 +611,7 @@ public: > void flashBackingStoreUpdates(const Vector<WebCore::IntRect>& updateRects); > > #if PLATFORM(MAC) >- void handleCorrectionPanelResult(const String& result); >+ void handleAlternativeTextUIResult(const String& result); > #endif > > static void setDebugPaintFlags(WKPageDebugPaintFlags flags) { s_debugPaintFlags = flags; } >Index: Source/WebKit2/UIProcess/API/mac/PageClientImpl.h >=================================================================== >--- Source/WebKit2/UIProcess/API/mac/PageClientImpl.h (revision 112917) >+++ Source/WebKit2/UIProcess/API/mac/PageClientImpl.h (working copy) >@@ -120,9 +120,9 @@ private: > virtual void didPerformDictionaryLookup(const String&, double scaleFactor, const DictionaryPopupInfo&); > virtual void dismissDictionaryLookupPanel(); > >- virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings); >- virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel); >- virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel); >+ virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings); >+ virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText); >+ virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText); > virtual void recordAutocorrectionResponse(WebCore::EditorClient::AutocorrectionResponseType, const String& replacedString, const String& replacementString); > > virtual void recommendedScrollbarStyleDidChange(int32_t newStyle); >Index: Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm >=================================================================== >--- Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm (revision 112917) >+++ Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm (working copy) >@@ -463,7 +463,7 @@ void PageClientImpl::dismissDictionaryLo > #endif > } > >-void PageClientImpl::showCorrectionPanel(CorrectionPanelInfo::PanelType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) >+void PageClientImpl::showCorrectionPanel(AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) > { > #if !defined(BUILDING_ON_SNOW_LEOPARD) > if (!isViewVisible() || !isViewInWindow()) >@@ -472,14 +472,14 @@ void PageClientImpl::showCorrectionPanel > #endif > } > >-void PageClientImpl::dismissCorrectionPanel(ReasonForDismissingCorrectionPanel reason) >+void PageClientImpl::dismissCorrectionPanel(ReasonForDismissingAlternativeText reason) > { > #if !defined(BUILDING_ON_SNOW_LEOPARD) > m_correctionPanel.dismiss(reason); > #endif > } > >-String PageClientImpl::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel reason) >+String PageClientImpl::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText reason) > { > #if !defined(BUILDING_ON_SNOW_LEOPARD) > return m_correctionPanel.dismiss(reason); >Index: Source/WebKit2/UIProcess/API/mac/WKView.mm >=================================================================== >--- Source/WebKit2/UIProcess/API/mac/WKView.mm (revision 112917) >+++ Source/WebKit2/UIProcess/API/mac/WKView.mm (working copy) >@@ -2852,7 +2852,7 @@ - (NSInteger)spellCheckerDocumentTag > > - (void)handleCorrectionPanelResult:(NSString*)result > { >- _data->_page->handleCorrectionPanelResult(result); >+ _data->_page->handleAlternativeTextUIResult(result); > } > > @end >Index: Source/WebKit2/UIProcess/mac/CorrectionPanel.h >=================================================================== >--- Source/WebKit2/UIProcess/mac/CorrectionPanel.h (revision 112917) >+++ Source/WebKit2/UIProcess/mac/CorrectionPanel.h (working copy) >@@ -28,7 +28,7 @@ > > #if !defined(BUILDING_ON_SNOW_LEOPARD) > #import <AppKit/NSSpellChecker.h> >-#import <WebCore/SpellingCorrectionController.h> >+#import <WebCore/AlternativeTextController.h> > #import <wtf/RetainPtr.h> > > @class WKView; >@@ -39,17 +39,17 @@ class CorrectionPanel { > public: > CorrectionPanel(); > ~CorrectionPanel(); >- void show(WKView*, WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings); >- String dismiss(WebCore::ReasonForDismissingCorrectionPanel); >+ void show(WKView*, WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings); >+ String dismiss(WebCore::ReasonForDismissingAlternativeText); > static void recordAutocorrectionResponse(WKView*, NSCorrectionResponse, const String& replacedString, const String& replacementString); > > private: > bool isShowing() const { return m_view; } >- String dismissInternal(WebCore::ReasonForDismissingCorrectionPanel, bool dismissingExternally); >+ String dismissInternal(WebCore::ReasonForDismissingAlternativeText, bool dismissingExternally); > void handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionIndicatorType); > > bool m_wasDismissedExternally; >- WebCore::ReasonForDismissingCorrectionPanel m_reasonForDismissing; >+ WebCore::ReasonForDismissingAlternativeText m_reasonForDismissing; > RetainPtr<WKView> m_view; > RetainPtr<NSString> m_resultForDismissal; > }; >Index: Source/WebKit2/UIProcess/mac/CorrectionPanel.mm >=================================================================== >--- Source/WebKit2/UIProcess/mac/CorrectionPanel.mm (revision 112917) >+++ Source/WebKit2/UIProcess/mac/CorrectionPanel.mm (working copy) >@@ -33,14 +33,14 @@ > > using namespace WebCore; > >-static inline NSCorrectionIndicatorType correctionIndicatorType(CorrectionPanelInfo::PanelType panelType) >+static inline NSCorrectionIndicatorType correctionIndicatorType(AlternativeTextType alternativeTextType) > { >- switch (panelType) { >- case CorrectionPanelInfo::PanelTypeCorrection: >+ switch (alternativeTextType) { >+ case AlternativeTextTypeCorrection: > return NSCorrectionIndicatorTypeDefault; >- case CorrectionPanelInfo::PanelTypeReversion: >+ case AlternativeTextTypeReversion: > return NSCorrectionIndicatorTypeReversion; >- case CorrectionPanelInfo::PanelTypeSpellingSuggestions: >+ case AlternativeTextTypeSpellingSuggestions: > return NSCorrectionIndicatorTypeGuesses; > } > ASSERT_NOT_REACHED(); >@@ -51,18 +51,18 @@ namespace WebKit { > > CorrectionPanel::CorrectionPanel() > : m_wasDismissedExternally(false) >- , m_reasonForDismissing(ReasonForDismissingCorrectionPanelIgnored) >+ , m_reasonForDismissing(ReasonForDismissingAlternativeTextIgnored) > { > } > > CorrectionPanel::~CorrectionPanel() > { >- dismissInternal(ReasonForDismissingCorrectionPanelIgnored, false); >+ dismissInternal(ReasonForDismissingAlternativeTextIgnored, false); > } > >-void CorrectionPanel::show(WKView* view, CorrectionPanelInfo::PanelType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) >+void CorrectionPanel::show(WKView* view, AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) > { >- dismissInternal(ReasonForDismissingCorrectionPanelIgnored, false); >+ dismissInternal(ReasonForDismissingAlternativeTextIgnored, false); > > if (!view) > return; >@@ -86,12 +86,12 @@ void CorrectionPanel::show(WKView* view, > }]; > } > >-String CorrectionPanel::dismiss(ReasonForDismissingCorrectionPanel reason) >+String CorrectionPanel::dismiss(ReasonForDismissingAlternativeText reason) > { > return dismissInternal(reason, true); > } > >-String CorrectionPanel::dismissInternal(ReasonForDismissingCorrectionPanel reason, bool dismissingExternally) >+String CorrectionPanel::dismissInternal(ReasonForDismissingAlternativeText reason, bool dismissingExternally) > { > if (!isShowing()) > return String(); >@@ -121,7 +121,7 @@ void CorrectionPanel::handleAcceptedRepl > if (acceptedReplacement) > [spellChecker recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag]; > else { >- if (!m_wasDismissedExternally || m_reasonForDismissing == ReasonForDismissingCorrectionPanelCancelled) >+ if (!m_wasDismissedExternally || m_reasonForDismissing == ReasonForDismissingAlternativeTextCancelled) > [spellChecker recordResponse:NSCorrectionResponseRejected toCorrection:proposedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag]; > else > [spellChecker recordResponse:NSCorrectionResponseIgnored toCorrection:proposedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag]; >Index: Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h >=================================================================== >--- Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h (revision 112917) >+++ Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h (working copy) >@@ -143,9 +143,9 @@ private: > virtual void setInputMethodState(bool enabled) OVERRIDE; > virtual void requestCheckingOfString(WebCore::SpellChecker*, const WebCore::TextCheckingRequest&) OVERRIDE; > #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD) >- virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) OVERRIDE; >- virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel) OVERRIDE; >- virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel) OVERRIDE; >+ virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) OVERRIDE; >+ virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText) OVERRIDE; >+ virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText) OVERRIDE; > virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString) OVERRIDE; > #endif > #if PLATFORM(GTK) >Index: Source/WebKit2/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm >=================================================================== >--- Source/WebKit2/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm (revision 112917) >+++ Source/WebKit2/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm (working copy) >@@ -239,17 +239,17 @@ void WebEditorClient::checkTextOfParagra > } > > #if !defined(BUILDING_ON_SNOW_LEOPARD) >-void WebEditorClient::showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType type, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) >+void WebEditorClient::showCorrectionPanel(WebCore::AlternativeTextType type, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) > { > m_page->send(Messages::WebPageProxy::ShowCorrectionPanel(type, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings)); > } > >-void WebEditorClient::dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel reason) >+void WebEditorClient::dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText reason) > { > m_page->send(Messages::WebPageProxy::DismissCorrectionPanel(reason)); > } > >-String WebEditorClient::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel reason) >+String WebEditorClient::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText reason) > { > String result; > m_page->sendSync(Messages::WebPageProxy::DismissCorrectionPanelSoon(reason), Messages::WebPageProxy::DismissCorrectionPanelSoon::Reply(result)); >Index: Source/WebKit2/WebProcess/WebPage/WebPage.cpp >=================================================================== >--- Source/WebKit2/WebProcess/WebPage/WebPage.cpp (revision 112917) >+++ Source/WebKit2/WebProcess/WebPage/WebPage.cpp (working copy) >@@ -3020,12 +3020,12 @@ bool WebPage::canHandleRequest(const Web > } > > #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD) >-void WebPage::handleCorrectionPanelResult(const String& result) >+void WebPage::handleAlternativeTextUIResult(const String& result) > { > Frame* frame = m_page->focusController()->focusedOrMainFrame(); > if (!frame) > return; >- frame->editor()->handleCorrectionPanelResult(result); >+ frame->editor()->handleAlternativeTextUIResult(result); > } > #endif > >Index: Source/WebKit2/WebProcess/WebPage/WebPage.h >=================================================================== >--- Source/WebKit2/WebProcess/WebPage/WebPage.h (revision 112917) >+++ Source/WebKit2/WebProcess/WebPage/WebPage.h (working copy) >@@ -487,7 +487,7 @@ public: > void unmarkAllBadGrammar(); > > #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD) >- void handleCorrectionPanelResult(const String&); >+ void handleAlternativeTextUIResult(const String&); > #endif > > // For testing purpose. >Index: Source/WebKit2/WebProcess/WebPage/WebPage.messages.in >=================================================================== >--- Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (revision 112917) >+++ Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (working copy) >@@ -258,6 +258,6 @@ messages -> WebPage { > #endif > > #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD) >- HandleCorrectionPanelResult(String result) >+ HandleAlternativeTextUIResult(String result) > #endif > } >Index: Source/WebKit/mac/ChangeLog >=================================================================== >--- Source/WebKit/mac/ChangeLog (revision 112931) >+++ Source/WebKit/mac/ChangeLog (working copy) >@@ -1,3 +1,31 @@ >+2012-04-02 Jia Pu <jpu@apple.com> >+ >+ Rename SpellingCorrectionController to AlternativeTextController. >+ https://bugs.webkit.org/show_bug.cgi?id=82942 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ These changes are simply adopting new class names. >+ >+ * WebCoreSupport/CorrectionPanel.h: >+ (CorrectionPanel): >+ * WebCoreSupport/CorrectionPanel.mm: >+ (correctionIndicatorType): >+ (CorrectionPanel::CorrectionPanel): >+ (CorrectionPanel::~CorrectionPanel): >+ (CorrectionPanel::show): >+ (CorrectionPanel::dismiss): >+ (CorrectionPanel::dismissInternal): >+ (CorrectionPanel::handleAcceptedReplacement): >+ * WebCoreSupport/WebEditorClient.h: >+ * WebCoreSupport/WebEditorClient.mm: >+ (WebEditorClient::~WebEditorClient): >+ (WebEditorClient::showCorrectionPanel): >+ (WebEditorClient::dismissCorrectionPanel): >+ (WebEditorClient::dismissCorrectionPanelSoon): >+ * WebView/WebView.mm: >+ (-[WebView handleCorrectionPanelResult:]): >+ > 2012-04-01 Jon Lee <jonlee@apple.com> > > Rename notification properties and functions >Index: Source/WebKit/mac/WebCoreSupport/CorrectionPanel.h >=================================================================== >--- Source/WebKit/mac/WebCoreSupport/CorrectionPanel.h (revision 112917) >+++ Source/WebKit/mac/WebCoreSupport/CorrectionPanel.h (working copy) >@@ -28,7 +28,7 @@ > > #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) > #import <AppKit/NSSpellChecker.h> >-#import <WebCore/SpellingCorrectionController.h> >+#import <WebCore/AlternativeTextController.h> > #import <wtf/RetainPtr.h> > > @class WebView; >@@ -38,17 +38,17 @@ class CorrectionPanel { > public: > CorrectionPanel(); > ~CorrectionPanel(); >- void show(WebView*, WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings); >- String dismiss(WebCore::ReasonForDismissingCorrectionPanel); >+ void show(WebView*, WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings); >+ String dismiss(WebCore::ReasonForDismissingAlternativeText); > static void recordAutocorrectionResponse(WebView*, NSCorrectionResponse, const String& replacedString, const String& replacementString); > > private: > bool isShowing() const { return m_view; } >- String dismissInternal(WebCore::ReasonForDismissingCorrectionPanel, bool dismissingExternally); >+ String dismissInternal(WebCore::ReasonForDismissingAlternativeText, bool dismissingExternally); > void handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionIndicatorType); > > bool m_wasDismissedExternally; >- WebCore::ReasonForDismissingCorrectionPanel m_reasonForDismissing; >+ WebCore::ReasonForDismissingAlternativeText m_reasonForDismissing; > RetainPtr<WebView> m_view; > RetainPtr<NSString> m_resultForDismissal; > }; >Index: Source/WebKit/mac/WebCoreSupport/CorrectionPanel.mm >=================================================================== >--- Source/WebKit/mac/WebCoreSupport/CorrectionPanel.mm (revision 112917) >+++ Source/WebKit/mac/WebCoreSupport/CorrectionPanel.mm (working copy) >@@ -30,14 +30,14 @@ > #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) > using namespace WebCore; > >-static inline NSCorrectionIndicatorType correctionIndicatorType(CorrectionPanelInfo::PanelType panelType) >+static inline NSCorrectionIndicatorType correctionIndicatorType(AlternativeTextType alternativeTextType) > { >- switch (panelType) { >- case CorrectionPanelInfo::PanelTypeCorrection: >+ switch (alternativeTextType) { >+ case AlternativeTextTypeCorrection: > return NSCorrectionIndicatorTypeDefault; >- case CorrectionPanelInfo::PanelTypeReversion: >+ case AlternativeTextTypeReversion: > return NSCorrectionIndicatorTypeReversion; >- case CorrectionPanelInfo::PanelTypeSpellingSuggestions: >+ case AlternativeTextTypeSpellingSuggestions: > return NSCorrectionIndicatorTypeGuesses; > } > ASSERT_NOT_REACHED(); >@@ -46,18 +46,18 @@ static inline NSCorrectionIndicatorType > > CorrectionPanel::CorrectionPanel() > : m_wasDismissedExternally(false) >- , m_reasonForDismissing(ReasonForDismissingCorrectionPanelIgnored) >+ , m_reasonForDismissing(ReasonForDismissingAlternativeTextIgnored) > { > } > > CorrectionPanel::~CorrectionPanel() > { >- dismissInternal(ReasonForDismissingCorrectionPanelIgnored, false); >+ dismissInternal(ReasonForDismissingAlternativeTextIgnored, false); > } > >-void CorrectionPanel::show(WebView* view, CorrectionPanelInfo::PanelType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) >+void CorrectionPanel::show(WebView* view, AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) > { >- dismissInternal(ReasonForDismissingCorrectionPanelIgnored, false); >+ dismissInternal(ReasonForDismissingAlternativeTextIgnored, false); > > if (!view) > return; >@@ -80,12 +80,12 @@ void CorrectionPanel::show(WebView* view > }]; > } > >-String CorrectionPanel::dismiss(ReasonForDismissingCorrectionPanel reason) >+String CorrectionPanel::dismiss(ReasonForDismissingAlternativeText reason) > { > return dismissInternal(reason, true); > } > >-String CorrectionPanel::dismissInternal(ReasonForDismissingCorrectionPanel reason, bool dismissingExternally) >+String CorrectionPanel::dismissInternal(ReasonForDismissingAlternativeText reason, bool dismissingExternally) > { > if (!isShowing()) > return String(); >@@ -115,7 +115,7 @@ void CorrectionPanel::handleAcceptedRepl > if (acceptedReplacement) > [spellChecker recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag]; > else { >- if (!m_wasDismissedExternally || m_reasonForDismissing == ReasonForDismissingCorrectionPanelCancelled) >+ if (!m_wasDismissedExternally || m_reasonForDismissing == ReasonForDismissingAlternativeTextCancelled) > [spellChecker recordResponse:NSCorrectionResponseRejected toCorrection:proposedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag]; > else > [spellChecker recordResponse:NSCorrectionResponseIgnored toCorrection:proposedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag]; >Index: Source/WebKit/mac/WebCoreSupport/WebEditorClient.h >=================================================================== >--- Source/WebKit/mac/WebCoreSupport/WebEditorClient.h (revision 112917) >+++ Source/WebKit/mac/WebCoreSupport/WebEditorClient.h (working copy) >@@ -137,9 +137,9 @@ public: > virtual void setInputMethodState(bool enabled) OVERRIDE; > virtual void requestCheckingOfString(WebCore::SpellChecker*, const WebCore::TextCheckingRequest&) OVERRIDE; > #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) >- virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) OVERRIDE; >- virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel) OVERRIDE; >- virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel) OVERRIDE; >+ virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) OVERRIDE; >+ virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText) OVERRIDE; >+ virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText) OVERRIDE; > virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString) OVERRIDE; > #endif > private: >Index: Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm >=================================================================== >--- Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm (revision 112917) >+++ Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm (working copy) >@@ -190,7 +190,7 @@ WebEditorClient::WebEditorClient(WebView > WebEditorClient::~WebEditorClient() > { > #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) >- dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored); >+ dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored); > #endif > } > >@@ -867,17 +867,17 @@ void WebEditorClient::updateSpellingUIWi > } > > #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) >-void WebEditorClient::showCorrectionPanel(CorrectionPanelInfo::PanelType panelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) >+void WebEditorClient::showCorrectionPanel(AlternativeTextType panelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) > { > m_correctionPanel.show(m_webView, panelType, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings); > } > >-void WebEditorClient::dismissCorrectionPanel(ReasonForDismissingCorrectionPanel reasonForDismissing) >+void WebEditorClient::dismissCorrectionPanel(ReasonForDismissingAlternativeText reasonForDismissing) > { > m_correctionPanel.dismiss(reasonForDismissing); > } > >-String WebEditorClient::dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanel reasonForDismissing) >+String WebEditorClient::dismissCorrectionPanelSoon(ReasonForDismissingAlternativeText reasonForDismissing) > { > return m_correctionPanel.dismiss(reasonForDismissing); > } >Index: Source/WebKit/mac/WebView/WebView.mm >=================================================================== >--- Source/WebKit/mac/WebView/WebView.mm (revision 112917) >+++ Source/WebKit/mac/WebView/WebView.mm (working copy) >@@ -5488,7 +5488,7 @@ - (void)handleCorrectionPanelResult:(NSS > WebFrame *webFrame = [self _selectedOrMainFrame]; > Frame* coreFrame = core(webFrame); > if (coreFrame) >- coreFrame->editor()->handleCorrectionPanelResult(result); >+ coreFrame->editor()->handleAlternativeTextUIResult(result); > } > #endif >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 82942
:
135179
|
135244
|
135254
|
135257
|
135349