WebKit2: Implement TextChecker on Windows
authorjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Apr 2011 21:19:22 +0000 (21:19 +0000)
committerjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Apr 2011 21:19:22 +0000 (21:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=57862

Reviewed by Anders Carlsson.

Part 7: Implement getGuessesForWord, learnWord, and ignoreWord.

* UIProcess/API/C/win/WKTextChecker.cpp:
(WKTextCheckerChangeSpellingToWord):
* UIProcess/API/C/win/WKTextChecker.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::changeSpellingToWord):
Make this function const since it does not modify the WebPageProxy and making it const
allows WebTextChecker::changeSpellingToWord to take a const WebPageProxy.
(WebKit::WebPageProxy::learnWord):
* UIProcess/WebPageProxy.h:

* UIProcess/TextChecker.h:
* UIProcess/win/TextCheckerWin.cpp:
(WebKit::TextChecker::getGuessesForWord):
Ask the TextCheckerClient for the guesses.
(WebKit::TextChecker::learnWord):
Tell the TextCheckerClient.
(WebKit::TextChecker::ignoreWord):
Ditto.
* UIProcess/gtk/TextCheckerGtk.cpp:
(WebKit::TextChecker::learnWord):
Add an unused param that is necessary for Windows.
* UIProcess/mac/TextCheckerMac.mm:
(WebKit::TextChecker::learnWord):
Ditto.
* UIProcess/qt/TextCheckerQt.cpp:
(WebKit::TextChecker::learnWord):
Ditto.

* UIProcess/win/WebTextChecker.cpp:
(WebKit::WebTextChecker::changeSpellingToWord):
Tell the page.
* UIProcess/win/WebTextChecker.h:

* UIProcess/win/WebTextCheckerClient.cpp:
(WebKit::WebTextCheckerClient::guessesForWord):
(WebKit::WebTextCheckerClient::learnWord):
(WebKit::WebTextCheckerClient::ignoreWord):
* UIProcess/win/WebTextCheckerClient.h:

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

14 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/win/WKTextChecker.cpp
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/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/WebTextChecker.cpp
Source/WebKit2/UIProcess/win/WebTextChecker.h
Source/WebKit2/UIProcess/win/WebTextCheckerClient.cpp
Source/WebKit2/UIProcess/win/WebTextCheckerClient.h

index dc04ff5..5da020f 100644 (file)
@@ -1,3 +1,52 @@
+2011-04-11  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        WebKit2: Implement TextChecker on Windows
+        https://bugs.webkit.org/show_bug.cgi?id=57862
+
+        Part 7: Implement getGuessesForWord, learnWord, and ignoreWord.
+
+        * UIProcess/API/C/win/WKTextChecker.cpp:
+        (WKTextCheckerChangeSpellingToWord):
+        * UIProcess/API/C/win/WKTextChecker.h:
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::changeSpellingToWord):
+        Make this function const since it does not modify the WebPageProxy and making it const
+        allows WebTextChecker::changeSpellingToWord to take a const WebPageProxy.
+        (WebKit::WebPageProxy::learnWord):
+        * UIProcess/WebPageProxy.h:
+
+        * UIProcess/TextChecker.h:
+        * UIProcess/win/TextCheckerWin.cpp:
+        (WebKit::TextChecker::getGuessesForWord):
+        Ask the TextCheckerClient for the guesses.
+        (WebKit::TextChecker::learnWord):
+        Tell the TextCheckerClient.
+        (WebKit::TextChecker::ignoreWord):
+        Ditto.
+        * UIProcess/gtk/TextCheckerGtk.cpp:
+        (WebKit::TextChecker::learnWord):
+        Add an unused param that is necessary for Windows.
+        * UIProcess/mac/TextCheckerMac.mm:
+        (WebKit::TextChecker::learnWord):
+        Ditto.
+        * UIProcess/qt/TextCheckerQt.cpp:
+        (WebKit::TextChecker::learnWord):
+        Ditto.
+
+        * UIProcess/win/WebTextChecker.cpp:
+        (WebKit::WebTextChecker::changeSpellingToWord):
+        Tell the page.
+        * UIProcess/win/WebTextChecker.h:
+
+        * UIProcess/win/WebTextCheckerClient.cpp:
+        (WebKit::WebTextCheckerClient::guessesForWord):
+        (WebKit::WebTextCheckerClient::learnWord):
+        (WebKit::WebTextCheckerClient::ignoreWord):
+        * UIProcess/win/WebTextCheckerClient.h:
+
 2011-04-11  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Sam Weinig.
index 497e931..3329da2 100644 (file)
@@ -53,3 +53,8 @@ void WKTextCheckerCheckSpelling(WKPageRef page, bool startBeforeSelection)
 {
     WebTextChecker::shared()->checkSpelling(toImpl(page), startBeforeSelection);
 }
+
+void WKTextCheckerChangeSpellingToWord(WKPageRef page, WKStringRef word)
+{
+    WebTextChecker::shared()->changeSpellingToWord(toImpl(page), toWTFString(word));
+}
index e6ca89a..31a855d 100644 (file)
@@ -46,6 +46,9 @@ typedef bool (*WKTextCheckerSpellingUIIsShowing)(const void *clientInfo);
 typedef void (*WKTextCheckerToggleSpellingUIIsShowing)(const void *clientInfo);
 typedef void (*WKTextCheckerUpdateSpellingUIWithMisspelledWord)(uint64_t tag, WKStringRef misspelledWord, const void *clientInfo);
 typedef void (*WKTextCheckerUpdateSpellingUIWithGrammarString)(uint64_t tag, WKStringRef badGrammarPhrase, WKGrammarDetailRef grammarDetail, const void *clientInfo);
+typedef WKArrayRef (*WKTextCheckerGuessesForWord)(uint64_t tag, WKStringRef word, const void *clientInfo);
+typedef void (*WKTextCheckerLearnWord)(uint64_t tag, WKStringRef word, const void *clientInfo);
+typedef void (*WKTextCheckerIgnoreWord)(uint64_t tag, WKStringRef word, const void *clientInfo);
 
 struct WKTextCheckerClient {
     int                                                                     version;
@@ -63,6 +66,9 @@ struct WKTextCheckerClient {
     WKTextCheckerToggleSpellingUIIsShowing                                  toggleSpellingUIIsShowing;
     WKTextCheckerUpdateSpellingUIWithMisspelledWord                         updateSpellingUIWithMisspelledWord;
     WKTextCheckerUpdateSpellingUIWithGrammarString                          updateSpellingUIWithGrammarString;
+    WKTextCheckerGuessesForWord                                             guessesForWord;
+    WKTextCheckerLearnWord                                                  learnWord;
+    WKTextCheckerIgnoreWord                                                 ignoreWord;
 };
 typedef struct WKTextCheckerClient WKTextCheckerClient;
 
@@ -72,6 +78,7 @@ WK_EXPORT void WKTextCheckerContinuousSpellCheckingEnabledStateChanged(bool);
 WK_EXPORT void WKTextCheckerGrammarCheckingEnabledStateChanged(bool);
 
 WK_EXPORT void WKTextCheckerCheckSpelling(WKPageRef page, bool startBeforeSelection);
+WK_EXPORT void WKTextCheckerChangeSpellingToWord(WKPageRef page, WKStringRef word);
 
 #ifdef __cplusplus
 }
index 99dbacc..69e2837 100644 (file)
@@ -71,7 +71,7 @@ public:
     static void updateSpellingUIWithMisspelledWord(int64_t spellDocumentTag, const String& misspelledWord);
     static void updateSpellingUIWithGrammarString(int64_t spellDocumentTag, const String& badGrammarPhrase, const WebCore::GrammarDetail&);
     static void getGuessesForWord(int64_t spellDocumentTag, const String& word, const String& context, Vector<String>& guesses);
-    static void learnWord(const String& word);
+    static void learnWord(int64_t spellDocumentTag, const String& word);
     static void ignoreWord(int64_t spellDocumentTag, const String& word);
 };
 
index 0cb9788..28536f9 100644 (file)
@@ -2369,7 +2369,7 @@ void WebPageProxy::advanceToNextMisspelling(bool startBeforeSelection) const
     process()->send(Messages::WebPage::AdvanceToNextMisspelling(startBeforeSelection), m_pageID);
 }
 
-void WebPageProxy::changeSpellingToWord(const String& word)
+void WebPageProxy::changeSpellingToWord(const String& word) const
 {
     if (word.isEmpty())
         return;
@@ -2465,7 +2465,7 @@ void WebPageProxy::learnWord(const String& word)
     MESSAGE_CHECK(m_pendingLearnOrIgnoreWordMessageCount);
     --m_pendingLearnOrIgnoreWordMessageCount;
 
-    TextChecker::learnWord(word);
+    TextChecker::learnWord(spellDocumentTag(), word);
 }
 
 void WebPageProxy::ignoreWord(const String& word)
index 01d4fb7..0d35b31 100644 (file)
@@ -453,7 +453,7 @@ public:
 #endif
 
     void advanceToNextMisspelling(bool startBeforeSelection) const;
-    void changeSpellingToWord(const String& word);
+    void changeSpellingToWord(const String& word) const;
     void unmarkAllMisspellings();
     void unmarkAllBadGrammar();
 #if PLATFORM(MAC)
index 11077b7..118bee1 100644 (file)
@@ -105,7 +105,7 @@ void TextChecker::getGuessesForWord(int64_t spellDocumentTag, const String& word
     notImplemented();
 }
 
-void TextChecker::learnWord(const String& word)
+void TextChecker::learnWord(int64_t, const String&)
 {
     notImplemented();
 }
index a9c3455..a0ff741 100644 (file)
@@ -377,7 +377,7 @@ void TextChecker::getGuessesForWord(int64_t spellDocumentTag, const String& word
         guesses.append(guess);
 }
 
-void TextChecker::learnWord(const String& word)
+void TextChecker::learnWord(int64_t, const String& word)
 {
     [[NSSpellChecker sharedSpellChecker] learnWord:word];
 }
index 322448b..2582cc2 100644 (file)
@@ -106,7 +106,7 @@ void TextChecker::getGuessesForWord(int64_t spellDocumentTag, const String& word
     notImplemented();
 }
 
-void TextChecker::learnWord(const String& word)
+void TextChecker::learnWord(int64_t, const String&)
 {
     notImplemented();
 }
index afdf199..9f7c766 100644 (file)
@@ -124,17 +124,17 @@ void TextChecker::updateSpellingUIWithGrammarString(int64_t spellDocumentTag, co
 
 void TextChecker::getGuessesForWord(int64_t spellDocumentTag, const String& word, const String& context, Vector<String>& guesses)
 {
-    notImplemented();
+    WebTextChecker::shared()->client().guessesForWord(spellDocumentTag, word, guesses);
 }
 
-void TextChecker::learnWord(const String& word)
+void TextChecker::learnWord(int64_t spellDocumentTag, const String& word)
 {
-    notImplemented();
+    WebTextChecker::shared()->client().learnWord(spellDocumentTag, word);
 }
 
 void TextChecker::ignoreWord(int64_t spellDocumentTag, const String& word)
 {
-    notImplemented();
+    WebTextChecker::shared()->client().ignoreWord(spellDocumentTag, word);
 }
 
 } // namespace WebKit
index 52d3b1a..2761844 100644 (file)
@@ -27,6 +27,7 @@
 #include "WebTextChecker.h"
 
 #include "TextChecker.h"
+#include "WKAPICast.h"
 #include "WebContext.h"
 #include <wtf/RefPtr.h>
 
@@ -75,4 +76,9 @@ void WebTextChecker::checkSpelling(const WebPageProxy* page, bool startBeforeSel
     page->advanceToNextMisspelling(startBeforeSelection);
 }
 
+void WebTextChecker::changeSpellingToWord(const WebPageProxy* page, const String& text)
+{
+    page->changeSpellingToWord(text);
+}
+
 } // namespace WebKit
index 090158c..a1c574c 100644 (file)
@@ -48,6 +48,7 @@ public:
     void grammarCheckingEnabledStateChanged(bool);
 
     void checkSpelling(const WebPageProxy*, bool startBeforeSelection);
+    void changeSpellingToWord(const WebPageProxy*, const String&);
 
 private:
     WebTextChecker();
index 0608ccf..86e52c6 100644 (file)
@@ -145,4 +145,31 @@ void WebTextCheckerClient::updateSpellingUIWithGrammarString(uint64_t tag, const
     m_client.updateSpellingUIWithGrammarString(tag, toAPI(badGrammarPhrase.impl()), toAPI(grammarDetail), m_client.clientInfo);
 }
 
+void WebTextCheckerClient::guessesForWord(uint64_t tag, const String& word, Vector<String>& guesses)
+{
+    if (!m_client.guessesForWord)
+        return;
+
+    RefPtr<ImmutableArray> wkGuesses = adoptRef(toImpl(m_client.guessesForWord(tag, toAPI(word.impl()), m_client.clientInfo)));
+    size_t numGuesses = wkGuesses->size();
+    for (size_t i = 0; i < numGuesses; ++i)
+        guesses.append(wkGuesses->at<WebString>(i)->string());
+}
+
+void WebTextCheckerClient::learnWord(uint64_t tag, const String& word)
+{
+    if (!m_client.learnWord)
+        return;
+
+    m_client.learnWord(tag, toAPI(word.impl()), m_client.clientInfo);
+}
+
+void WebTextCheckerClient::ignoreWord(uint64_t tag, const String& word)
+{
+    if (!m_client.ignoreWord)
+        return;
+
+    m_client.ignoreWord(tag, toAPI(word.impl()), m_client.clientInfo);
+}
+
 } // namespace WebKit
index 70448c4..50fb42d 100644 (file)
@@ -51,6 +51,9 @@ public:
     void toggleSpellingUIIsShowing();
     void updateSpellingUIWithMisspelledWord(uint64_t tag, const String& misspelledWord);
     void updateSpellingUIWithGrammarString(uint64_t tag, const String& badGrammarPhrase, const WebCore::GrammarDetail&);
+    void guessesForWord(uint64_t tag, const String& word, Vector<String>& guesses);
+    void learnWord(uint64_t tag, const String& word);
+    void ignoreWord(uint64_t tag, const String& word);
 };
 
 } // namespace WebKit