2011-03-23 Jia Pu <jpu@apple.com>

        Reviewed by Darin Adler.

        Hook up new AppKit autocorrection UI with WK2.
        https://bugs.webkit.org/show_bug.cgi?id=56055
        <rdar://problem/8947463>

        Please see WebCore/ChangeLog for detail.

        * platform/mac-wk2/Skipped: Enable autocorrection tests for WK2.
2011-03-23  Jia Pu  <jpu@apple.com>

        Reviewed by Darin Adler.

        Hook up new AppKit autocorrection UI with WK2.
        https://bugs.webkit.org/show_bug.cgi?id=56055
        <rdar://problem/8947463>

        This patch is to enable WK2 to utilize autocorrection UI on Mac OS X. It contains following
        major changes:

        1. All but one autocorrection related message is synchronous. Since dismissing autocorrection
        panel can potentially cause editing to occur, a synchronous dismissCorrectionPanelSoon() function
        is introduced to ensure all editing commands occur in correct order.

        2. Additional condition variable is needed to implement dismissCorrectionPanelSoon().
        To improve maintainability, CorrectionPanel class is introduced to manage the
        internal state related to correction panel. This change is applied to both WK1 and WK2.

        3. EditorClient::isShowingCorrectionPanel() has been removed. The original purpose is to allow
        editor to know when to handle ESC key event. Now this is handled internally in AppKit, so
        EditorClient::isShowingCorrectionPanel() isn't necessary anymore.

        4. The Editor* argument in EditorClient::showCorrectionPanel() has been removed, since we can
        access object via WebView or WKView.

        * editing/Editor.cpp:
        (WebCore::Editor::markMisspellingsAfterTypingToWord):
        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
        (WebCore::Editor::correctionPanelTimerFired):
        (WebCore::Editor::dismissCorrectionPanel):
        (WebCore::Editor::dismissCorrectionPanelSoon):
        (WebCore::Editor::applyAutocorrectionBeforeTypingIfAppropriate):
        * editing/Editor.h:
        * editing/EditorCommand.cpp:
        (WebCore::createCommandMap):
        * loader/EmptyClients.h:
        (WebCore::EmptyEditorClient::showCorrectionPanel):
        (WebCore::EmptyEditorClient::dismissCorrectionPanelSoon):
        * manual-tests/autocorrection/close-window-when-correction-is-shown.html: Added.
        * page/EditorClient.h:
2011-03-23  Jia Pu  <jpu@apple.com>

        Reviewed by Darin Adler.

        Hook up new AppKit autocorrection UI with WK2.
        https://bugs.webkit.org/show_bug.cgi?id=56055
        <rdar://problem/8947463>

        Please see WebCore/ChangeLog for detail.

        * WebKit.xcodeproj/project.pbxproj:
2011-03-23  Jia Pu  <jpu@apple.com>

        Reviewed by Darin Adler.

        Hook up new AppKit autocorrection UI with WK2.
        https://bugs.webkit.org/show_bug.cgi?id=56055
        <rdar://problem/8947463>

        Please see WebCore/ChangeLog for detail.

        * WebCoreSupport/CorrectionPanel.h: Added.
        (CorrectionPanel::isShowing):
        * WebCoreSupport/CorrectionPanel.mm: Added.
        (correctionBubbleType):
        (CorrectionPanel::CorrectionPanel):
        (CorrectionPanel::~CorrectionPanel):
        (CorrectionPanel::show):
        (CorrectionPanel::dismiss):
        (CorrectionPanel::dismissSoon):
        (CorrectionPanel::dismissInternal):
        (CorrectionPanel::recordAutocorrectionResponse):
        * WebCoreSupport/WebEditorClient.h:
        * WebCoreSupport/WebEditorClient.mm:
        (WebEditorClient::WebEditorClient):
        (WebEditorClient::showCorrectionPanel):
        (WebEditorClient::dismissCorrectionPanel):
        (WebEditorClient::dismissCorrectionPanelSoon):
        (WebEditorClient::recordAutocorrectionResponse):
        * WebView/WebView.mm:
        (-[WebView handleCorrectionPanelResult:]):
        * WebView/WebViewPrivate.h:
2011-03-23  Jia Pu  <jpu@apple.com>

        Reviewed by Darin Adler.

        Hook up new AppKit autocorrection UI with WK2.
        https://bugs.webkit.org/show_bug.cgi?id=56055
        <rdar://problem/8947463>

        Please see WebCore/ChangeLog for detail.

        The calls to AppKit are implemented in PageClientImpl. Other changes are necessary for the
        plumbing work.

        * UIProcess/API/mac/PageClientImpl.h:
        * UIProcess/API/mac/PageClientImpl.mm:
        (WebKit::PageClientImpl::showCorrectionPanel):
        (WebKit::PageClientImpl::dismissCorrectionPanel):
        (WebKit::PageClientImpl::dismissCorrectionPanelSoon):
        (WebKit::PageClientImpl::recordAutocorrectionResponse):
        * UIProcess/API/mac/WKView.mm:
        (-[WKView spellCheckerDocumentTag]):
        (-[WKView handleCorrectionPanelResult:]):
        * UIProcess/API/mac/WKViewPrivate.h:
        * UIProcess/PageClient.h:
        * UIProcess/WebPageProxy.cpp:
        (WebKit::WebPageProxy::didCommitLoadForFrame):
        (WebKit::WebPageProxy::showCorrectionPanel):
        (WebKit::WebPageProxy::dismissCorrectionPanel):
        (WebKit::WebPageProxy::dismissCorrectionPanelSoon):
        (WebKit::WebPageProxy::recordAutocorrectionResponse):
        (WebKit::WebPageProxy::handleCorrectionPanelResult):
        * UIProcess/WebPageProxy.h:
        * UIProcess/WebPageProxy.messages.in:
        * UIProcess/mac/CorrectionPanel.h: Added.
        (WebKit::CorrectionPanel::isShowing):
        * UIProcess/mac/CorrectionPanel.mm: Added.
        (correctionBubbleType):
        (WebKit::CorrectionPanel::CorrectionPanel):
        (WebKit::CorrectionPanel::~CorrectionPanel):
        (WebKit::CorrectionPanel::show):
        (WebKit::CorrectionPanel::dismiss):
        (WebKit::CorrectionPanel::dismissSoon):
        (WebKit::CorrectionPanel::dismissInternal):
        (WebKit::CorrectionPanel::recordAutocorrectionResponse):
        * WebKit2.xcodeproj/project.pbxproj:
        * WebProcess/WebCoreSupport/WebEditorClient.h:
        * WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm:
        (WebKit::WebEditorClient::showCorrectionPanel):
        (WebKit::WebEditorClient::dismissCorrectionPanel):
        (WebKit::WebEditorClient::dismissCorrectionPanelSoon):
        (WebKit::WebEditorClient::recordAutocorrectionResponse):
        * WebProcess/WebPage/WebPage.cpp:
        (WebKit::WebPage::handleCorrectionPanelResult):
        * WebProcess/WebPage/WebPage.h:
        * WebProcess/WebPage/WebPage.messages.in:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@81847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2de77018
2011-03-23 Jia Pu <jpu@apple.com>
Reviewed by Darin Adler.
Hook up new AppKit autocorrection UI with WK2.
https://bugs.webkit.org/show_bug.cgi?id=56055
<rdar://problem/8947463>
Please see WebCore/ChangeLog for detail.
* platform/mac-wk2/Skipped: Enable autocorrection tests for WK2.
2011-03-23 Carol Szabo <carol.szabo@nokia.com>
Reviewed by David Hyatt.
......
......@@ -569,23 +569,6 @@ platform/mac/editing/deleting/backward-delete.html
platform/mac/editing/pasteboard/dataTransfer-set-data-file-url.html
platform/mac/editing/selection/doubleclick-should-not-expand-across-lines.html
platform/mac/editing/selection/word-thai.html
platform/mac/editing/spelling/autocorrection-contraction.html
platform/mac/editing/spelling/autocorrection-delete.html
platform/mac/editing/spelling/autocorrection-removing-underline-after-paste.html
platform/mac/editing/spelling/autocorrection-removing-underline.html
platform/mac/editing/spelling/autocorrection-simple.html
platform/mac/editing/spelling/click-autocorrected-word.html
platform/mac/editing/spelling/delete-autocorrected-word-1.html
platform/mac/editing/spelling/delete-into-autocorrected-word.html
platform/mac/editing/spelling/delete-into-misspelled-word.html
platform/mac/editing/spelling/editing-multiple-words-with-markers.html
platform/mac/editing/spelling/editing-word-with-marker-1.html
platform/mac/editing/spelling/editing-word-with-marker-2.html
platform/mac/editing/spelling/forward-delete-into-autocorrected-word.html
platform/mac/editing/spelling/move-cursor-around-misspelled-word.html
platform/mac/editing/spelling/move-cursor-to-autocorrected-word.html
platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word.html
platform/mac/editing/spelling/removing-underline-after-accepting-autocorrection-using-punctuation.html
platform/mac/fast/forms/input-appearance-spinbutton-up.html
platform/mac/fast/forms/input-number-click.html
platform/mac/fast/forms/listbox-scrollbar-hit-test.html
......
2011-03-23 Jia Pu <jpu@apple.com>
Reviewed by Darin Adler.
Hook up new AppKit autocorrection UI with WK2.
https://bugs.webkit.org/show_bug.cgi?id=56055
<rdar://problem/8947463>
This patch is to enable WK2 to utilize autocorrection UI on Mac OS X. It contains following
major changes:
1. All but one autocorrection related message is synchronous. Since dismissing autocorrection
panel can potentially cause editing to occur, a synchronous dismissCorrectionPanelSoon() function
is introduced to ensure all editing commands occur in correct order.
2. Additional condition variable is needed to implement dismissCorrectionPanelSoon().
To improve maintainability, CorrectionPanel class is introduced to manage the
internal state related to correction panel. This change is applied to both WK1 and WK2.
3. EditorClient::isShowingCorrectionPanel() has been removed. The original purpose is to allow
editor to know when to handle ESC key event. Now this is handled internally in AppKit, so
EditorClient::isShowingCorrectionPanel() isn't necessary anymore.
4. The Editor* argument in EditorClient::showCorrectionPanel() has been removed, since we can
access object via WebView or WKView.
* editing/Editor.cpp:
(WebCore::Editor::markMisspellingsAfterTypingToWord):
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
(WebCore::Editor::correctionPanelTimerFired):
(WebCore::Editor::dismissCorrectionPanel):
(WebCore::Editor::dismissCorrectionPanelSoon):
(WebCore::Editor::applyAutocorrectionBeforeTypingIfAppropriate):
* editing/Editor.h:
* editing/EditorCommand.cpp:
(WebCore::createCommandMap):
* loader/EmptyClients.h:
(WebCore::EmptyEditorClient::showCorrectionPanel):
(WebCore::EmptyEditorClient::dismissCorrectionPanelSoon):
* manual-tests/autocorrection/close-window-when-correction-is-shown.html: Added.
* page/EditorClient.h:
2011-03-22 Ojan Vafai <ojan@chromium.org>
Reviewed by Antti Koivisto.
......@@ -2072,7 +2072,7 @@ void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart,
doApplyCorrection = false;
}
if (doApplyCorrection)
dismissCorrectionPanel(ReasonForDismissingCorrectionPanelAccepted);
handleCorrectionPanelResult(dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanelAccepted));
else
m_correctionPanelInfo.rangeToBeReplaced.clear();
#else
......@@ -2387,7 +2387,7 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
m_correctionPanelInfo.replacedString = plainText(rangeToReplace.get());
m_correctionPanelInfo.replacementString = result->replacement;
m_correctionPanelInfo.isActive = true;
client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, result->replacement, Vector<String>(), this);
client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, result->replacement, Vector<String>());
break;
}
// If this function is called for showing correction panel, we ignore other correction or replacement.
......@@ -2517,7 +2517,7 @@ void Editor::correctionPanelTimerFired(Timer<Editor>*)
m_correctionPanelInfo.replacedString = plainText(m_correctionPanelInfo.rangeToBeReplaced.get());
FloatRect boundingBox = windowRectForRange(m_correctionPanelInfo.rangeToBeReplaced.get());
if (!boundingBox.isEmpty())
client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, m_correctionPanelInfo.replacementString, Vector<String>(), this);
client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, m_correctionPanelInfo.replacementString, Vector<String>());
}
break;
case CorrectionPanelInfo::PanelTypeSpellingSuggestions: {
......@@ -2535,7 +2535,7 @@ void Editor::correctionPanelTimerFired(Timer<Editor>*)
m_correctionPanelInfo.isActive = true;
FloatRect boundingBox = windowRectForRange(m_correctionPanelInfo.rangeToBeReplaced.get());
if (!boundingBox.isEmpty())
client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, topSuggestion, suggestions, this);
client()->showCorrectionPanel(m_correctionPanelInfo.panelType, boundingBox, m_correctionPanelInfo.replacedString, topSuggestion, suggestions);
}
break;
}
......@@ -2601,39 +2601,36 @@ void Editor::stopCorrectionPanelTimer()
#endif
}
void Editor::handleCancelOperation()
void Editor::dismissCorrectionPanel(ReasonForDismissingCorrectionPanel reasonForDismissing)
{
#if SUPPORT_AUTOCORRECTION_PANEL
if (!m_correctionPanelInfo.isActive)
return;
m_correctionPanelInfo.isActive = false;
m_correctionPanelIsDismissedByEditor = true;
if (client())
client()->dismissCorrectionPanel(ReasonForDismissingCorrectionPanelCancelled);
#endif
}
bool Editor::isShowingCorrectionPanel()
{
#if SUPPORT_AUTOCORRECTION_PANEL
if (client())
return client()->isShowingCorrectionPanel();
client()->dismissCorrectionPanel(reasonForDismissing);
#else
UNUSED_PARAM(reasonForDismissing);
#endif
return false;
}
void Editor::dismissCorrectionPanel(ReasonForDismissingCorrectionPanel reasonForDismissing)
String Editor::dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanel reasonForDismissing)
{
#if SUPPORT_AUTOCORRECTION_PANEL
if (!m_correctionPanelInfo.isActive)
return;
return String();
m_correctionPanelInfo.isActive = false;
m_correctionPanelIsDismissedByEditor = true;
if (client())
client()->dismissCorrectionPanel(reasonForDismissing);
if (!client())
return String();
return client()->dismissCorrectionPanelSoon(reasonForDismissing);
#else
UNUSED_PARAM(reasonForDismissing);
return String();
#endif
}
void Editor::removeSpellAndCorrectionMarkersFromWordsToBeEdited(bool doNotRemoveIfSelectionAtWordBoundary)
{
// We want to remove the markers from a word if an editing command will change the word. This can happen in one of
......@@ -2768,7 +2765,7 @@ bool Editor::applyAutocorrectionBeforeTypingIfAppropriate()
Position caretPosition = m_frame->selection()->selection().start();
if (m_correctionPanelInfo.rangeToBeReplaced->endPosition() == caretPosition) {
dismissCorrectionPanel(ReasonForDismissingCorrectionPanelAccepted);
handleCorrectionPanelResult(dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanelAccepted));
return true;
}
......
......@@ -320,11 +320,9 @@ public:
void addToKillRing(Range*, bool prepend);
void handleCancelOperation();
void startCorrectionPanelTimer(CorrectionPanelInfo::PanelType);
// 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);
bool isShowingCorrectionPanel();
void pasteAsFragment(PassRefPtr<DocumentFragment>, bool smartReplace, bool matchStyle);
void pasteAsPlainText(const String&, bool smartReplace);
......@@ -425,6 +423,7 @@ private:
Node* findEventTargetFromSelection() const;
void stopCorrectionPanelTimer();
void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel);
String dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanel);
void applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>& markerTypesToAdd);
// Return true if correction was applied, false otherwise.
bool applyAutocorrectionBeforeTypingIfAppropriate();
......
......@@ -1091,14 +1091,6 @@ static bool executeYankAndSelect(Frame* frame, Event*, EditorCommandSource, cons
return true;
}
#if SUPPORT_AUTOCORRECTION_PANEL
static bool executeCancelOperation(Frame* frame, Event*, EditorCommandSource, const String&)
{
frame->editor()->handleCancelOperation();
return true;
}
#endif
// Supported functions
static bool supported(Frame*)
......@@ -1249,13 +1241,6 @@ static bool enabledUndo(Frame* frame, Event*, EditorCommandSource)
return frame->editor()->canUndo();
}
#if SUPPORT_AUTOCORRECTION_PANEL
static bool enabledDismissCorrectionPanel(Frame* frame, Event*, EditorCommandSource)
{
return frame->editor()->isShowingCorrectionPanel();
}
#endif
// State functions
static TriState stateNone(Frame*, Event*)
......@@ -1532,10 +1517,6 @@ static const CommandMap& createCommandMap()
#if PLATFORM(MAC)
{ "TakeFindStringFromSelection", { executeTakeFindStringFromSelection, supportedFromMenuOrKeyBinding, enabledTakeFindStringFromSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
#endif
#if SUPPORT_AUTOCORRECTION_PANEL
{ "CancelOperation", { executeCancelOperation, supportedFromMenuOrKeyBinding, enabledDismissCorrectionPanel, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
#endif
};
// These unsupported commands are listed here since they appear in the Microsoft
......
......@@ -511,9 +511,9 @@ public:
TextCheckerClient* textChecker() { return &m_textCheckerClient; }
#if SUPPORT_AUTOCORRECTION_PANEL
virtual void showCorrectionPanel(CorrectionPanelInfo::PanelType, const FloatRect&, const String&, const String&, const Vector<String>&, Editor*) { }
virtual void showCorrectionPanel(CorrectionPanelInfo::PanelType, const FloatRect&, const String&, const String&, const Vector<String>&) { }
virtual void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel) { }
virtual bool isShowingCorrectionPanel() { return false; }
virtual String dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanel) { return String(); }
virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String&, const String&) { }
#endif
virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail&) { }
......
<html>
<head>
<style>
.editing {
border: 2px solid red;
padding: 12px;
font-size: 24px;
}
</style>
<script src=../../../../LayoutTests/editing/editing.js language="JavaScript" type="text/JavaScript" ></script>
<script>
function editingTest() {
typeCharacterCommand('t');
typeCharacterCommand('h');
typeCharacterCommand('e');
typeCharacterCommand(' ');
typeCharacterCommand('m');
typeCharacterCommand('e');
typeCharacterCommand('s');
typeCharacterCommand('a');
typeCharacterCommand('e');
typeCharacterCommand('g');
typeCharacterCommand('e');
typeCharacterCommand('e');
typeCharacterCommand(' ');
execMoveSelectionBackwardByCharacterCommand();
}
</script>
<title>Testing closing window when correction suggestion is shown</title>
</head>
<body>
<div><p>This test verifies that when correction suggestion is visible, closing window doesn't hang or crash.</p>
<p>After seeing the panel with multiple candidates, close the window.</p>
<div contenteditable id="root" class="editing">
<span id="test"></span>
</div>
<script>
runEditingTest();
</script>
</body>
</html>
......@@ -158,14 +158,15 @@ public:
virtual TextCheckerClient* textChecker() = 0;
#if SUPPORT_AUTOCORRECTION_PANEL
enum AutocorrectionResponseType {
AutocorrectionEdited,
AutocorrectionReverted
};
virtual void showCorrectionPanel(CorrectionPanelInfo::PanelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacmentString, const Vector<String>& alternativeReplacementStrings, Editor*) = 0;
#if SUPPORT_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 bool isShowingCorrectionPanel() = 0;
virtual String dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanel) = 0;
virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString) = 0;
#endif
......
2011-03-23 Jia Pu <jpu@apple.com>
Reviewed by Darin Adler.
Hook up new AppKit autocorrection UI with WK2.
https://bugs.webkit.org/show_bug.cgi?id=56055
<rdar://problem/8947463>
Please see WebCore/ChangeLog for detail.
* WebKit.xcodeproj/project.pbxproj:
2011-03-17 Jeff Miller <jeffm@apple.com>
Use a consistent set of file patterns in the svn:ignore property for all .xcodeproj directories, specifically:
......
......@@ -344,6 +344,8 @@
B6CE5C25100BC5F500219936 /* WebApplicationCache.h in Headers */ = {isa = PBXBuildFile; fileRef = B68049710FFBCEC1009F7F62 /* WebApplicationCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
B804176F1217A83100466BAE /* WebInspectorFrontend.h in Headers */ = {isa = PBXBuildFile; fileRef = B804176D1217A83100466BAE /* WebInspectorFrontend.h */; };
B80417701217A83100466BAE /* WebInspectorFrontend.mm in Sources */ = {isa = PBXBuildFile; fileRef = B804176E1217A83100466BAE /* WebInspectorFrontend.mm */; };
B82958D3132707D0000D0E79 /* CorrectionPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = B82958D1132707D0000D0E79 /* CorrectionPanel.h */; };
B82958D4132707D0000D0E79 /* CorrectionPanel.mm in Sources */ = {isa = PBXBuildFile; fileRef = B82958D2132707D0000D0E79 /* CorrectionPanel.mm */; };
BC26C69E10B743F400B687ED /* WebSerializedJSValue.h in Headers */ = {isa = PBXBuildFile; fileRef = BC26C69D10B743F400B687ED /* WebSerializedJSValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
BC26C6A510B7447A00B687ED /* WebSerializedJSValue.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC26C6A410B7447A00B687ED /* WebSerializedJSValue.mm */; };
BC2E464D0FD8A96800A9D9DE /* WebViewData.h in Headers */ = {isa = PBXBuildFile; fileRef = BC2E464B0FD8A96800A9D9DE /* WebViewData.h */; };
......@@ -660,6 +662,8 @@
B68049720FFBCEC1009F7F62 /* WebApplicationCache.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebApplicationCache.mm; sourceTree = "<group>"; };
B804176D1217A83100466BAE /* WebInspectorFrontend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebInspectorFrontend.h; sourceTree = "<group>"; };
B804176E1217A83100466BAE /* WebInspectorFrontend.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebInspectorFrontend.mm; sourceTree = "<group>"; };
B82958D1132707D0000D0E79 /* CorrectionPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CorrectionPanel.h; sourceTree = "<group>"; };
B82958D2132707D0000D0E79 /* CorrectionPanel.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CorrectionPanel.mm; sourceTree = "<group>"; };
BC26C69D10B743F400B687ED /* WebSerializedJSValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSerializedJSValue.h; sourceTree = "<group>"; };
BC26C6A410B7447A00B687ED /* WebSerializedJSValue.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSerializedJSValue.mm; sourceTree = "<group>"; };
BC2E464B0FD8A96800A9D9DE /* WebViewData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewData.h; sourceTree = "<group>"; };
......@@ -1295,6 +1299,8 @@
F5B36B400281DE87018635CB /* WebCoreSupport */ = {
isa = PBXGroup;
children = (
B82958D1132707D0000D0E79 /* CorrectionPanel.h */,
B82958D2132707D0000D0E79 /* CorrectionPanel.mm */,
598AD91D1201CECF00ABAE4E /* WebDeviceOrientationClient.mm */,
598AD9191201CEC900ABAE4E /* WebDeviceOrientationClient.h */,
B68049710FFBCEC1009F7F62 /* WebApplicationCache.h */,
......@@ -1645,6 +1651,7 @@
3AE15D5012DBDED4009323C8 /* WebStorageManagerInternal.h in Headers */,
3ABB3C7A1309C3B500E93D94 /* WebStorageTrackerClient.h in Headers */,
BC42D324131ED1E00075FA4B /* WebLocalizableStringsInternal.h in Headers */,
B82958D3132707D0000D0E79 /* CorrectionPanel.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -2015,6 +2022,7 @@
CDA62AE3125F87C2007FD118 /* WebFullScreenController.mm in Sources */,
3ABB3C7B1309C3B500E93D94 /* WebStorageTrackerClient.mm in Sources */,
BC42D34D131ED3880075FA4B /* WebLocalizableStringsInternal.mm in Sources */,
B82958D4132707D0000D0E79 /* CorrectionPanel.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
2011-03-23 Jia Pu <jpu@apple.com>
Reviewed by Darin Adler.
Hook up new AppKit autocorrection UI with WK2.
https://bugs.webkit.org/show_bug.cgi?id=56055
<rdar://problem/8947463>
Please see WebCore/ChangeLog for detail.
* WebCoreSupport/CorrectionPanel.h: Added.
(CorrectionPanel::isShowing):
* WebCoreSupport/CorrectionPanel.mm: Added.
(correctionBubbleType):
(CorrectionPanel::CorrectionPanel):
(CorrectionPanel::~CorrectionPanel):
(CorrectionPanel::show):
(CorrectionPanel::dismiss):
(CorrectionPanel::dismissSoon):
(CorrectionPanel::dismissInternal):
(CorrectionPanel::recordAutocorrectionResponse):
* WebCoreSupport/WebEditorClient.h:
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::WebEditorClient):
(WebEditorClient::showCorrectionPanel):
(WebEditorClient::dismissCorrectionPanel):
(WebEditorClient::dismissCorrectionPanelSoon):
(WebEditorClient::recordAutocorrectionResponse):
* WebView/WebView.mm:
(-[WebView handleCorrectionPanelResult:]):
* WebView/WebViewPrivate.h:
2011-03-23 Enrica Casucci <enrica@apple.com>
Reviewed by Alexey Proskuryakov.
......
/*
* Copyright (C) 2011 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 CorrectionPanel_h
#define CorrectionPanel_h
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
#import <AppKit/NSTextChecker.h>
#import <WebCore/CorrectionPanelInfo.h>
#import <wtf/RetainPtr.h>
@class WebView;
class CorrectionPanel {
WTF_MAKE_NONCOPYABLE(CorrectionPanel);
public:
CorrectionPanel();
~CorrectionPanel();
void show(WebView*, WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings);
void dismiss(WebCore::ReasonForDismissingCorrectionPanel);
String dismissSoon(WebCore::ReasonForDismissingCorrectionPanel);
static void recordAutocorrectionResponse(WebView*, NSCorrectionResponse, const String& replacedString, const String& replacementString);
private:
bool isShowing() const { return m_view; }
void dismissInternal(WebCore::ReasonForDismissingCorrectionPanel, bool dismissingExternally);
void handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionBubbleType);
bool m_wasDismissedExternally;
WebCore::ReasonForDismissingCorrectionPanel m_reasonForDismissing;
RetainPtr<WebView> m_view;
RetainPtr<NSString> m_resultForSynchronousDismissal;
RetainPtr<NSCondition> m_resultCondition;
};
#endif // !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
#endif // CorrectionPanel_h
/*
* Copyright (C) 2011 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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.
*/
#import "CorrectionPanel.h"
#import "WebViewPrivate.h"
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
using namespace WebCore;
static inline NSCorrectionBubbleType correctionBubbleType(CorrectionPanelInfo::PanelType panelType)
{
switch (panelType) {
case CorrectionPanelInfo::PanelTypeCorrection:
return NSCorrectionBubbleTypeCorrection;
case CorrectionPanelInfo::PanelTypeReversion:
return NSCorrectionBubbleTypeReversion;
case CorrectionPanelInfo::PanelTypeSpellingSuggestions:
return NSCorrectionBubbleTypeGuesses;
}
ASSERT_NOT_REACHED();
return NSCorrectionBubbleTypeCorrection;
}
CorrectionPanel::CorrectionPanel()
: m_wasDismissedExternally(false)
, m_reasonForDismissing(ReasonForDismissingCorrectionPanelIgnored)
, m_resultCondition(AdoptNS, [[NSCondition alloc] init])
{
}
CorrectionPanel::~CorrectionPanel()
{
dismissInternal(ReasonForDismissingCorrectionPanelIgnored, false);
}
void CorrectionPanel::show(WebView* view, CorrectionPanelInfo::PanelType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
{
dismissInternal(ReasonForDismissingCorrectionPanelIgnored, false);
if (!view)
return;
NSString* replacedStringAsNSString = replacedString;
NSString* replacementStringAsNSString = replacementString;
m_view = view;
NSCorrectionBubbleType bubbleType = correctionBubbleType(type);
NSMutableArray* alternativeStrings = 0;
if (!alternativeReplacementStrings.isEmpty()) {
size_t size = alternativeReplacementStrings.size();
alternativeStrings = [NSMutableArray arrayWithCapacity:size];
for (size_t i = 0; i < size; ++i)
[alternativeStrings addObject:(NSString*)alternativeReplacementStrings[i]];
}
[[NSSpellChecker sharedSpellChecker] showCorrectionBubbleOfType:bubbleType primaryString:replacementStringAsNSString alternativeStrings:alternativeStrings forStringInRect:boundingBoxOfReplacedString view:m_view.get() completionHandler:^(NSString* acceptedString) {
handleAcceptedReplacement(acceptedString, replacedStringAsNSString, replacementStringAsNSString, bubbleType);
}];
}
void CorrectionPanel::dismiss(ReasonForDismissingCorrectionPanel reason)
{
dismissInternal(reason, true);
}
String CorrectionPanel::dismissSoon(ReasonForDismissingCorrectionPanel reason)
{
if (!isShowing())
return String();
dismissInternal(reason, true);
[m_resultCondition.get() lock];
while (!m_resultForSynchronousDismissal)
[m_resultCondition.get() wait];
[m_resultCondition.get() unlock];
return m_resultForSynchronousDismissal.get();
}
void CorrectionPanel::dismissInternal(ReasonForDismissingCorrectionPanel reason, bool dismissingExternally)
{
m_wasDismissedExternally = dismissingExternally;
if (!isShowing())
return;
m_reasonForDismissing = reason;
m_resultForSynchronousDismissal.clear();
if (reason == ReasonForDismissingCorrectionPanelAccepted)
[[NSSpellChecker sharedSpellChecker] dismissCorrectionBubbleForView:m_view.get()];
else
[[NSSpellChecker sharedSpellChecker] cancelCorrectionBubbleForView:m_view.get()];
m_view.clear();
}
void CorrectionPanel::recordAutocorrectionResponse(WebView* view, NSCorrectionResponse response, const String& replacedString, const String& replacementString)
{
[[NSSpellChecker sharedSpellChecker] recordResponse:response toCorrection:replacementString forWord:replacedString language:nil inSpellDocumentWithTag:[view spellCheckerDocumentTag]];
}
void CorrectionPanel::handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionBubbleType correctionBubbleType)
{