WebKit2: Implement TextChecker on Windows
authorjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Apr 2011 00:38:20 +0000 (00:38 +0000)
committerjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Apr 2011 00:38:20 +0000 (00:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=57862

Reviewed by Brian Weinstein.

Part 4: Implement checkGrammarOfString.

* Scripts/webkit2/messages.py:
The generated files should include TextCheckerClient.h for WebCore::GrammarDetail.

* Shared/API/c/win/WKBaseWin.h:
* Shared/APIObject.h:
* UIProcess/API/C/win/WKAPICastWin.h:

* UIProcess/API/C/win/WKGrammarDetail.cpp: Added.
(WKGrammarDetailGetTypeID):
(WKGrammarDetailCreate):
* UIProcess/API/C/win/WKGrammarDetail.h: Added.

* UIProcess/API/C/win/WKTextChecker.h:
Add the checkGrammarOfString WKTextCheckerClient function.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::checkGrammarOfString):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

* UIProcess/TextChecker.h:
* UIProcess/win/TextCheckerWin.cpp:
(WebKit::TextChecker::checkGrammarOfString):
Call the TextCheckerClient.
* UIProcess/mac/TextCheckerMac.mm:
(WebKit::TextChecker::checkSpellingOfString):
Add a comment about this not being used on Mac.
(WebKit::TextChecker::checkGrammarOfString):
Ditto, and call notImplemented.
* UIProcess/gtk/TextCheckerGtk.cpp:
(WebKit::TextChecker::checkGrammarOfString):
Call notImplemented.
* UIProcess/qt/TextCheckerQt.cpp:
(WebKit::TextChecker::checkGrammarOfString):
Ditto.

* UIProcess/win/WebGrammarDetail.cpp: Added.
(WebKit::WebGrammarDetail::create):
(WebKit::WebGrammarDetail::WebGrammarDetail):
Initialize the underlying WebCore::GrammarDetail.
* UIProcess/win/WebGrammarDetail.h: Added.
(WebKit::WebGrammarDetail::grammarDetail):
(WebKit::WebGrammarDetail::type):

* UIProcess/win/WebTextCheckerClient.cpp:
(WebKit::WebTextCheckerClient::checkGrammarOfString):
Populate the Vector of WebCore::GrammarDetails with the WebGrammarDetails.
* UIProcess/win/WebTextCheckerClient.h:

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::checkSpellingOfString):
Use WTF::notFound as the initial value for resultLocation.
(WebKit::WebEditorClient::checkGrammarOfString):
Send a sync message to the UI Process (similar to checkSpellingOfString and checkTextOfParagraph).

* win/WebKit2.vcproj:
Add WKGrammarDetail.h/.cpp and WebGrammarDetail.h/.cpp.
* win/WebKit2Generated.make:
Copy over WKGrammarDetail.h.

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

23 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/Scripts/webkit2/messages.py
Source/WebKit2/Shared/API/c/win/WKBaseWin.h
Source/WebKit2/Shared/APIObject.h
Source/WebKit2/UIProcess/API/C/win/WKAPICastWin.h
Source/WebKit2/UIProcess/API/C/win/WKGrammarDetail.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/C/win/WKGrammarDetail.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/C/win/WKTextChecker.h
Source/WebKit2/UIProcess/TextChecker.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp
Source/WebKit2/UIProcess/mac/TextCheckerMac.mm
Source/WebKit2/UIProcess/qt/TextCheckerQt.cpp
Source/WebKit2/UIProcess/win/TextCheckerWin.cpp
Source/WebKit2/UIProcess/win/WebGrammarDetail.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/win/WebGrammarDetail.h [new file with mode: 0644]
Source/WebKit2/UIProcess/win/WebTextCheckerClient.cpp
Source/WebKit2/UIProcess/win/WebTextCheckerClient.h
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit2/win/WebKit2.vcproj
Source/WebKit2/win/WebKit2Generated.make

index 6ca5cb3..17ec00d 100644 (file)
@@ -1,3 +1,72 @@
+2011-04-07  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Brian Weinstein.
+
+        WebKit2: Implement TextChecker on Windows
+        https://bugs.webkit.org/show_bug.cgi?id=57862
+
+        Part 4: Implement checkGrammarOfString.
+
+        * Scripts/webkit2/messages.py:
+        The generated files should include TextCheckerClient.h for WebCore::GrammarDetail.
+
+        * Shared/API/c/win/WKBaseWin.h:
+        * Shared/APIObject.h:
+        * UIProcess/API/C/win/WKAPICastWin.h:
+
+        * UIProcess/API/C/win/WKGrammarDetail.cpp: Added.
+        (WKGrammarDetailGetTypeID):
+        (WKGrammarDetailCreate):
+        * UIProcess/API/C/win/WKGrammarDetail.h: Added.
+
+        * UIProcess/API/C/win/WKTextChecker.h:
+        Add the checkGrammarOfString WKTextCheckerClient function.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::checkGrammarOfString):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+
+        * UIProcess/TextChecker.h:
+        * UIProcess/win/TextCheckerWin.cpp:
+        (WebKit::TextChecker::checkGrammarOfString):
+        Call the TextCheckerClient.
+        * UIProcess/mac/TextCheckerMac.mm:
+        (WebKit::TextChecker::checkSpellingOfString):
+        Add a comment about this not being used on Mac.
+        (WebKit::TextChecker::checkGrammarOfString):
+        Ditto, and call notImplemented.
+        * UIProcess/gtk/TextCheckerGtk.cpp:
+        (WebKit::TextChecker::checkGrammarOfString):
+        Call notImplemented.
+        * UIProcess/qt/TextCheckerQt.cpp:
+        (WebKit::TextChecker::checkGrammarOfString):
+        Ditto.
+
+        * UIProcess/win/WebGrammarDetail.cpp: Added.
+        (WebKit::WebGrammarDetail::create):
+        (WebKit::WebGrammarDetail::WebGrammarDetail):
+        Initialize the underlying WebCore::GrammarDetail.
+        * UIProcess/win/WebGrammarDetail.h: Added.
+        (WebKit::WebGrammarDetail::grammarDetail):
+        (WebKit::WebGrammarDetail::type):
+
+        * UIProcess/win/WebTextCheckerClient.cpp:
+        (WebKit::WebTextCheckerClient::checkGrammarOfString):
+        Populate the Vector of WebCore::GrammarDetails with the WebGrammarDetails.
+        * UIProcess/win/WebTextCheckerClient.h:
+
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::checkSpellingOfString):
+        Use WTF::notFound as the initial value for resultLocation.
+        (WebKit::WebEditorClient::checkGrammarOfString):
+        Send a sync message to the UI Process (similar to checkSpellingOfString and checkTextOfParagraph).
+
+        * win/WebKit2.vcproj:
+        Add WKGrammarDetail.h/.cpp and WebGrammarDetail.h/.cpp.
+        * win/WebKit2Generated.make:
+        Copy over WKGrammarDetail.h.
+
 2011-04-07  Enrica Casucci  <enrica@apple.com>
 
         Reviewed by Oliver Hunt.
index 6f6c464..cf4c0d6 100644 (file)
@@ -434,6 +434,7 @@ def headers_for_type(type):
     special_cases = {
         'WTF::String': '<wtf/text/WTFString.h>',
         'WebCore::CompositionUnderline': '<WebCore/Editor.h>',
+        'WebCore::GrammarDetail': '<WebCore/TextCheckerClient.h>',
         'WebCore::KeypressCommand': '<WebCore/KeyboardEvent.h>',
         'WebCore::PluginInfo': '<WebCore/PluginData.h>',
         'WebCore::TextCheckingResult': '<WebCore/TextCheckerClient.h>',
index 1fa4150..d9c13e3 100644 (file)
@@ -33,5 +33,6 @@
 typedef const struct OpaqueWKView* WKViewRef;
 typedef const struct OpaqueWKEditCommand* WKEditCommandRef;
 typedef const struct OpaqueWKTextChecker* WKTextCheckerRef;
+typedef const struct OpaqueWKGrammarDetail* WKGrammarDetailRef;
 
 #endif /* WKBaseWin_h */
index 1555452..e5a7eed 100644 (file)
@@ -104,9 +104,10 @@ public:
         TypeBundleScriptWorld,
 
         // Platform specific
-        TypeView,
         TypeEditCommandProxy,
-        TypeTextChecker
+        TypeGrammarDetail,
+        TypeTextChecker,
+        TypeView
     };
 
     virtual ~APIObject()
index 0761f5a..5a09172 100644 (file)
@@ -35,10 +35,12 @@ namespace WebKit {
 class WebView;
 class WebEditCommandProxy;
 class WebTextChecker;
+class WebGrammarDetail;
 
 WK_ADD_API_MAPPING(WKViewRef, WebView)
 WK_ADD_API_MAPPING(WKEditCommandRef, WebEditCommandProxy)
 WK_ADD_API_MAPPING(WKTextCheckerRef, WebTextChecker)
+WK_ADD_API_MAPPING(WKGrammarDetailRef, WebGrammarDetail)
 
 }
 
diff --git a/Source/WebKit2/UIProcess/API/C/win/WKGrammarDetail.cpp b/Source/WebKit2/UIProcess/API/C/win/WKGrammarDetail.cpp
new file mode 100644 (file)
index 0000000..d45de6d
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "WKGrammarDetail.h"
+
+#include "APIObject.h"
+#include "WKAPICast.h"
+#include "WebGrammarDetail.h"
+
+using namespace WebKit;
+
+WKTypeID WKGrammarDetailGetTypeID()
+{
+    return toAPI(APIObject::TypeGrammarDetail);
+}
+
+WKGrammarDetailRef WKGrammarDetailCreate(int location, int length, WKArrayRef guesses, WKStringRef userDescription)
+{
+    RefPtr<WebGrammarDetail> detail = WebGrammarDetail::create(location, length, toImpl(guesses), toWTFString(userDescription));
+    return toAPI(detail.release().releaseRef());
+}
diff --git a/Source/WebKit2/UIProcess/API/C/win/WKGrammarDetail.h b/Source/WebKit2/UIProcess/API/C/win/WKGrammarDetail.h
new file mode 100644 (file)
index 0000000..1a03e2b
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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 WKGrammarDetail_h
+#define WKGrammarDetail_h
+
+#include <WebKit2/WKBase.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+WK_EXPORT WKTypeID WKGrammarDetailGetTypeID();
+WK_EXPORT WKGrammarDetailRef WKGrammarDetailCreate(int location, int length, WKArrayRef guesses, WKStringRef userDescription);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* WKGrammarDetail_h */
index 87593ba..803d6bb 100644 (file)
@@ -41,6 +41,7 @@ typedef void (*WKTextCheckerSetGrammarCheckingEnabled)(bool enabled, const void
 typedef uint64_t (*WKTextCheckerUniqueSpellDocumentTag)(const void *clientInfo);
 typedef void (*WKTextCheckerCloseSpellDocumentWithTag)(uint64_t tag, const void *clientInfo);
 typedef void (*WKTextCheckerCheckSpellingOfString)(uint64_t tag, WKStringRef text, int32_t* misspellingLocation, int32_t* misspellingLength, const void *clientInfo);
+typedef void (*WKTextCheckerCheckGrammarOfString)(uint64_t tag, WKStringRef text, WKArrayRef* grammarDetails, int32_t* badGrammarLocation, int32_t* badGrammarLength, const void *clientInfo);
 
 struct WKTextCheckerClient {
     int                                                                     version;
@@ -53,6 +54,7 @@ struct WKTextCheckerClient {
     WKTextCheckerUniqueSpellDocumentTag                                     uniqueSpellDocumentTag;
     WKTextCheckerCloseSpellDocumentWithTag                                  closeSpellDocumentWithTag;
     WKTextCheckerCheckSpellingOfString                                      checkSpellingOfString;
+    WKTextCheckerCheckGrammarOfString                                       checkGrammarOfString;
 };
 typedef struct WKTextCheckerClient WKTextCheckerClient;
 
index 4934700..fa665ad 100644 (file)
@@ -61,6 +61,7 @@ public:
     static Vector<WebCore::TextCheckingResult> checkTextOfParagraph(int64_t spellDocumentTag, const UChar* text, int length, uint64_t checkingTypes);
 #endif
     static void checkSpellingOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, int32_t& misspellingLocation, int32_t& misspellingLength);
+    static void checkGrammarOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength);
     static void updateSpellingUIWithMisspelledWord(const String& misspelledWord);
     static void updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const WebCore::GrammarDetail&);
     static void getGuessesForWord(int64_t spellDocumentTag, const String& word, const String& context, Vector<String>& guesses);
index 49c0672..86cb7e4 100644 (file)
@@ -2388,6 +2388,11 @@ void WebPageProxy::checkSpellingOfString(const String& text, int32_t& misspellin
     TextChecker::checkSpellingOfString(spellDocumentTag(), text.characters(), text.length(), misspellingLocation, misspellingLength);
 }
 
+void WebPageProxy::checkGrammarOfString(const String& text, Vector<WebCore::GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength)
+{
+    TextChecker::checkGrammarOfString(spellDocumentTag(), text.characters(), text.length(), grammarDetails, badGrammarLocation, badGrammarLength);
+}
+
 void WebPageProxy::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
 {
     TextChecker::updateSpellingUIWithMisspelledWord(misspelledWord);
index cbb1573..c95849f 100644 (file)
@@ -643,6 +643,7 @@ private:
     void checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<WebCore::TextCheckingResult>& results);
 #endif
     void checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength);
+    void checkGrammarOfString(const String& text, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength);
     void updateSpellingUIWithMisspelledWord(const String& misspelledWord);
     void updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const WebCore::GrammarDetail&);
     void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses);
index ead5aff..d69e6f3 100644 (file)
@@ -183,6 +183,7 @@ messages -> WebPageProxy {
     CheckTextOfParagraph(WTF::String text, uint64_t checkingTypes) -> (Vector<WebCore::TextCheckingResult> results)
 #endif
     CheckSpellingOfString(WTF::String text) -> (int32_t misspellingLocation, int32_t misspellingLength)
+    CheckGrammarOfString(WTF::String text) -> (Vector<WebCore::GrammarDetail> results, int32_t badGrammarLocation, int32_t badGrammarLength)
     UpdateSpellingUIWithMisspelledWord(WTF::String misspelledWord)
     UpdateSpellingUIWithGrammarString(WTF::String badGrammarPhrase, WebCore::GrammarDetail grammarDetail)
     GetGuessesForWord(WTF::String word, WTF::String context) -> (Vector<WTF::String> guesses)
index 147c646..b6169d2 100644 (file)
@@ -74,6 +74,11 @@ void TextChecker::checkSpellingOfString(int64_t, const UChar*, uint32_t, int32_t
     notImplemented();
 }
 
+void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&)
+{
+    notImplemented();
+}
+
 void TextChecker::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
 {
     notImplemented();
index 8dc0373..004afa6 100644 (file)
@@ -299,6 +299,13 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume
 
 void TextChecker::checkSpellingOfString(int64_t, const UChar*, uint32_t, int32_t&, int32_t&)
 {
+    // Mac uses checkTextOfParagraph instead.
+    notImplemented();
+}
+
+void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&)
+{
+    // Mac uses checkTextOfParagraph instead.
     notImplemented();
 }
 
index 80d8217..7b0c2d9 100644 (file)
@@ -75,6 +75,11 @@ void TextChecker::checkSpellingOfString(int64_t, const UChar*, uint32_t, int32_t
     notImplemented();
 }
 
+void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&)
+{
+    notImplemented();
+}
+
 void TextChecker::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
 {
     notImplemented();
index 5133585..3216378 100644 (file)
@@ -97,6 +97,11 @@ void TextChecker::checkSpellingOfString(int64_t spellDocumentTag, const UChar* t
     WebTextChecker::shared()->client().checkSpellingOfString(spellDocumentTag, String(text, length), misspellingLocation, misspellingLength);
 }
 
+void TextChecker::checkGrammarOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, Vector<WebCore::GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength)
+{
+    WebTextChecker::shared()->client().checkGrammarOfString(spellDocumentTag, String(text, length), grammarDetails, badGrammarLocation, badGrammarLength);
+}
+
 void TextChecker::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
 {
     notImplemented();
diff --git a/Source/WebKit2/UIProcess/win/WebGrammarDetail.cpp b/Source/WebKit2/UIProcess/win/WebGrammarDetail.cpp
new file mode 100644 (file)
index 0000000..2280438
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "WebGrammarDetail.h"
+
+#include "ImmutableArray.h"
+#include "WKGrammarDetail.h"
+#include "WebString.h"
+
+namespace WebKit {
+
+PassRefPtr<WebGrammarDetail> WebGrammarDetail::create(int location, int length, ImmutableArray* guesses, const String& userDescription)
+{
+    return adoptRef(new WebGrammarDetail(location, length, guesses, userDescription));
+}
+
+WebGrammarDetail::WebGrammarDetail(int location, int length, ImmutableArray* guesses, const String& userDescription)
+{
+    m_grammarDetail.location = location;
+    m_grammarDetail.length = length;
+
+    size_t numGuesses = guesses->size();
+    m_grammarDetail.guesses.reserveCapacity(numGuesses);
+    for (size_t i = 0; i < numGuesses; ++i)
+        m_grammarDetail.guesses.uncheckedAppend(guesses->at<WebString>(i)->string());
+
+    m_grammarDetail.userDescription = userDescription;
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/win/WebGrammarDetail.h b/Source/WebKit2/UIProcess/win/WebGrammarDetail.h
new file mode 100644 (file)
index 0000000..6fc2256
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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 WebGrammarDetail_h
+#define WebGrammarDetail_h
+
+#include "APIObject.h"
+#include <WebCore/TextCheckerClient.h>
+#include <wtf/Forward.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebKit {
+
+class ImmutableArray;
+
+class WebGrammarDetail : public APIObject {
+public:
+    static const Type APIType = TypeGrammarDetail;
+    static PassRefPtr<WebGrammarDetail> create(int location, int length, ImmutableArray* guesses, const String& userDescription);
+
+    const WebCore::GrammarDetail& grammarDetail() { return m_grammarDetail; }
+
+private:
+    WebGrammarDetail(int location, int length, ImmutableArray* guesses, const String& userDescription);
+
+    virtual Type type() const { return APIType; }
+
+    WebCore::GrammarDetail m_grammarDetail;
+};
+
+} // namespace WebKit
+
+#endif // WebGrammarDetail_h
index 61c3cd6..aee57e1 100644 (file)
 #include "config.h"
 #include "WebTextCheckerClient.h"
 
+#include "ImmutableArray.h"
 #include "WKAPICast.h"
+#include "WKSharedAPICast.h"
+#include "WebGrammarDetail.h"
 #include <wtf/text/WTFString.h>
 
 namespace WebKit {
@@ -95,4 +98,18 @@ void WebTextCheckerClient::checkSpellingOfString(uint64_t tag, const String& tex
     m_client.checkSpellingOfString(tag, toAPI(text.impl()), &misspellingLocation, &misspellingLength, m_client.clientInfo);
 }
 
+void WebTextCheckerClient::checkGrammarOfString(uint64_t tag, const String& text, Vector<WebCore::GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength)
+{
+    if (!m_client.checkGrammarOfString)
+        return;
+
+    WKArrayRef wkGrammarDetailsRef = 0;
+    m_client.checkGrammarOfString(tag, toAPI(text.impl()), &wkGrammarDetailsRef, &badGrammarLocation, &badGrammarLength, m_client.clientInfo);
+
+    RefPtr<ImmutableArray> wkGrammarDetails = adoptRef(toImpl(wkGrammarDetailsRef));
+    size_t numGrammarDetails = wkGrammarDetails->size();
+    for (size_t i = 0; i < numGrammarDetails; ++i)
+        grammarDetails.append(wkGrammarDetails->at<WebGrammarDetail>(i)->grammarDetail());
+}
+
 } // namespace WebKit
index 9647a8d..31d751c 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "APIClient.h"
 #include "WKTextChecker.h"
+#include <WebCore/TextCheckerClient.h>
 #include <wtf/Forward.h>
 #include <wtf/Vector.h>
 
@@ -43,6 +44,7 @@ public:
     uint64_t uniqueSpellDocumentTag();
     void closeSpellDocumentWithTag(uint64_t);
     void checkSpellingOfString(uint64_t tag, const String& text, int32_t& misspellingLocation, int32_t& misspellingLength);
+    void checkGrammarOfString(uint64_t tag, const String& text, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength);
 };
 
 } // namespace WebKit
index 9d0f7e5..ce122c8 100644 (file)
@@ -405,7 +405,7 @@ void WebEditorClient::learnWord(const String& word)
 
 void WebEditorClient::checkSpellingOfString(const UChar* text, int length, int* misspellingLocation, int* misspellingLength)
 {
-    int32_t resultLocation = -1;
+    int32_t resultLocation = WTF::notFound;
     int32_t resultLength = 0;
     // FIXME: It would be nice if we wouldn't have to copy the text here.
     m_page->sendSync(Messages::WebPageProxy::CheckSpellingOfString(String(text, length)),
@@ -420,9 +420,15 @@ String WebEditorClient::getAutoCorrectSuggestionForMisspelledWord(const String&)
     return String();
 }
 
-void WebEditorClient::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*)
+void WebEditorClient::checkGrammarOfString(const UChar* text, int length, Vector<WebCore::GrammarDetail>& grammarDetails, int* badGrammarLocation, int* badGrammarLength)
 {
-    notImplemented();
+    int32_t resultLocation = WTF::notFound;
+    int32_t resultLength = 0;
+    // FIXME: It would be nice if we wouldn't have to copy the text here.
+    m_page->sendSync(Messages::WebPageProxy::CheckGrammarOfString(String(text, length)),
+        Messages::WebPageProxy::CheckGrammarOfString::Reply(grammarDetails, resultLocation, resultLength));
+    *badGrammarLocation = resultLocation;
+    *badGrammarLength = resultLength;
 }
 
 void WebEditorClient::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail)
index b31958f..982ad97 100755 (executable)
                                                        >
                                                </File>
                                                <File
+                                                       RelativePath="..\UIProcess\API\C\win\WKGrammarDetail.cpp"
+                                                       >
+                                               </File>
+                                               <File
+                                                       RelativePath="..\UIProcess\API\C\win\WKGrammarDetail.h"
+                                                       >
+                                               </File>
+                                               <File
                                                        RelativePath="..\UIProcess\API\C\win\WKTextChecker.cpp"
                                                        >
                                                </File>
                                        >
                                </File>
                                <File
+                                       RelativePath="..\UIProcess\win\WebGrammarDetail.cpp"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\UIProcess\win\WebGrammarDetail.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\UIProcess\win\WebInspectorProxyWin.cpp"
                                        >
                                </File>
index a1c6a1e..694c0d5 100644 (file)
@@ -75,6 +75,7 @@ all:
     xcopy /y /d "..\UIProcess\API\C\WKProtectionSpaceTypes.h" "%ConfigurationBuildDir%\include\WebKit2"
     xcopy /y /d "..\UIProcess\API\C\WKResourceCacheManager.h" "%ConfigurationBuildDir%\include\WebKit2"
     xcopy /y /d "..\UIProcess\API\C\win\WKContextPrivateWin.h" "%ConfigurationBuildDir%\include\WebKit2"
+    xcopy /y /d "..\UIProcess\API\C\win\WKGrammarDetail.h" "%ConfigurationBuildDir%\include\WebKit2"
     xcopy /y /d "..\UIProcess\API\C\win\WKTextChecker.h" "%ConfigurationBuildDir%\include\WebKit2"
     xcopy /y /d "..\UIProcess\API\C\win\WKView.h" "%ConfigurationBuildDir%\include\WebKit2"
     xcopy /y /d "..\UIProcess\API\C\win\WKViewPrivate.h" "%ConfigurationBuildDir%\include\WebKit2"