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

Reviewed by Anders Carlsson.

Part 5: Implement the code show and hide the Spelling UI via the context menu item (both
Windows and Mac).

* UIProcess/API/C/win/WKTextChecker.h:
Add the new WKTextCheckerClient funtions.

* UIProcess/API/mac/WKView.mm:
(-[WKView validateUserInterfaceItem:]):
The title of the context menu item should be opposite of whether or not the spelling panel
is visible.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::contextMenuItemSelected):
If the "Show/Hide Spelling and Grammar" item is selected, call toggleSpellingUIIsShowing.
(WebKit::WebPageProxy::spellingUIIsShowing):
Call through to TextChecker.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

* UIProcess/TextChecker.h:
       * UIProcess/win/TextCheckerWin.cpp:
(WebKit::TextChecker::spellingUIIsShowing):
Call the TextCheckerClient.
(WebKit::TextChecker::toggleSpellingUIIsShowing):
Ditto.
* UIProcess/mac/TextCheckerMac.mm:
(WebKit::TextChecker::spellingUIIsShowing):
Ask the shared NSSpellChecker if the spellingPanel is visible.
(WebKit::TextChecker::toggleSpellingUIIsShowing):
Order the spellingPanel out or front (copied from WKView.mm).
* UIProcess/qt/TextCheckerQt.cpp:
(WebKit::TextChecker::spellingUIIsShowing):
Call notImplemented.
(WebKit::TextChecker::toggleSpellingUIIsShowing):
Ditto.
* UIProcess/gtk/TextCheckerGtk.cpp:
(WebKit::TextChecker::spellingUIIsShowing):
Ditto.
(WebKit::TextChecker::toggleSpellingUIIsShowing):
Ditto.

* UIProcess/win/WebTextCheckerClient.cpp:
(WebKit::WebTextCheckerClient::spellingUIIsShowing):
Call the client.
(WebKit::WebTextCheckerClient::toggleSpellingUIIsShowing):
Ditto.
* UIProcess/win/WebTextCheckerClient.h:

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::spellingUIIsShowing):
Send a sync message to the UI process to find out.
It needs to be sync because the Editor code relies on the value returned.

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

14 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/win/WKTextChecker.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
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/WebTextCheckerClient.cpp
Source/WebKit2/UIProcess/win/WebTextCheckerClient.h
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp

index 2a66649..6daf6ce 100644 (file)
@@ -1,3 +1,63 @@
+2011-04-08  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        WebKit2: Implement TextChecker on Windows
+        https://bugs.webkit.org/show_bug.cgi?id=57862
+
+        Part 5: Implement the code show and hide the Spelling UI via the context menu item (both
+        Windows and Mac).
+
+        * UIProcess/API/C/win/WKTextChecker.h:
+        Add the new WKTextCheckerClient funtions.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView validateUserInterfaceItem:]):
+        The title of the context menu item should be opposite of whether or not the spelling panel
+        is visible.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::contextMenuItemSelected):
+        If the "Show/Hide Spelling and Grammar" item is selected, call toggleSpellingUIIsShowing.
+        (WebKit::WebPageProxy::spellingUIIsShowing):
+        Call through to TextChecker.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+
+        * UIProcess/TextChecker.h:
+       * UIProcess/win/TextCheckerWin.cpp:
+        (WebKit::TextChecker::spellingUIIsShowing):
+        Call the TextCheckerClient.
+        (WebKit::TextChecker::toggleSpellingUIIsShowing):
+        Ditto.
+        * UIProcess/mac/TextCheckerMac.mm:
+        (WebKit::TextChecker::spellingUIIsShowing):
+        Ask the shared NSSpellChecker if the spellingPanel is visible.
+        (WebKit::TextChecker::toggleSpellingUIIsShowing):
+        Order the spellingPanel out or front (copied from WKView.mm).
+        * UIProcess/qt/TextCheckerQt.cpp:
+        (WebKit::TextChecker::spellingUIIsShowing):
+        Call notImplemented.
+        (WebKit::TextChecker::toggleSpellingUIIsShowing):
+        Ditto.
+        * UIProcess/gtk/TextCheckerGtk.cpp:
+        (WebKit::TextChecker::spellingUIIsShowing):
+        Ditto.
+        (WebKit::TextChecker::toggleSpellingUIIsShowing):
+        Ditto.
+        * UIProcess/win/WebTextCheckerClient.cpp:
+        (WebKit::WebTextCheckerClient::spellingUIIsShowing):
+        Call the client.
+        (WebKit::WebTextCheckerClient::toggleSpellingUIIsShowing):
+        Ditto.
+        * UIProcess/win/WebTextCheckerClient.h:
+
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::spellingUIIsShowing):
+        Send a sync message to the UI process to find out.
+        It needs to be sync because the Editor code relies on the value returned.
+
 2011-04-08  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Dan Bernstein.
index 803d6bb..0fd5443 100644 (file)
@@ -42,6 +42,8 @@ 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);
+typedef bool (*WKTextCheckerSpellingUIIsShowing)(const void *clientInfo);
+typedef void (*WKTextCheckerToggleSpellingUIIsShowing)(const void *clientInfo);
 
 struct WKTextCheckerClient {
     int                                                                     version;
@@ -55,6 +57,8 @@ struct WKTextCheckerClient {
     WKTextCheckerCloseSpellDocumentWithTag                                  closeSpellDocumentWithTag;
     WKTextCheckerCheckSpellingOfString                                      checkSpellingOfString;
     WKTextCheckerCheckGrammarOfString                                       checkGrammarOfString;
+    WKTextCheckerSpellingUIIsShowing                                        spellingUIIsShowing;
+    WKTextCheckerToggleSpellingUIIsShowing                                  toggleSpellingUIIsShowing;
 };
 typedef struct WKTextCheckerClient WKTextCheckerClient;
 
index d5bbe21..b4f1cd2 100644 (file)
@@ -611,7 +611,7 @@ static void validateCommandCallback(WKStringRef commandName, bool isEnabled, int
 
     if (action == @selector(showGuessPanel:)) {
         if (NSMenuItem *menuItem = ::menuItem(item))
-            [menuItem setTitle:contextMenuItemTagShowSpellingPanel([[[NSSpellChecker sharedSpellChecker] spellingPanel] isVisible])];
+            [menuItem setTitle:contextMenuItemTagShowSpellingPanel(![[[NSSpellChecker sharedSpellChecker] spellingPanel] isVisible])];
         return _data->_page->selectionState().isContentEditable;
     }
 
index fa665ad..391fa44 100644 (file)
@@ -62,6 +62,8 @@ public:
 #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 bool spellingUIIsShowing();
+    static void toggleSpellingUIIsShowing();
     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 f9681cb..5bd0172 100644 (file)
@@ -2302,6 +2302,10 @@ void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
         process()->updateTextCheckerState();
         return;
     }
+    if (item.action() == ContextMenuItemTagShowSpellingPanel) {
+        TextChecker::toggleSpellingUIIsShowing();
+        return;
+    }
     if (item.action() == ContextMenuItemTagLearnSpelling || item.action() == ContextMenuItemTagIgnoreSpelling)
         ++m_pendingLearnOrIgnoreWordMessageCount;
 
@@ -2416,6 +2420,11 @@ void WebPageProxy::checkGrammarOfString(const String& text, Vector<WebCore::Gram
     TextChecker::checkGrammarOfString(spellDocumentTag(), text.characters(), text.length(), grammarDetails, badGrammarLocation, badGrammarLength);
 }
 
+void WebPageProxy::spellingUIIsShowing(bool& isShowing)
+{
+    isShowing = TextChecker::spellingUIIsShowing();
+}
+
 void WebPageProxy::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
 {
     TextChecker::updateSpellingUIWithMisspelledWord(misspelledWord);
index 6434e27..f2dc5e5 100644 (file)
@@ -648,6 +648,7 @@ private:
 #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 spellingUIIsShowing(bool&);
     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 d69e6f3..9936c00 100644 (file)
@@ -184,6 +184,7 @@ messages -> WebPageProxy {
 #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)
+    SpellingUIIsShowing() -> (bool isShowing)
     UpdateSpellingUIWithMisspelledWord(WTF::String misspelledWord)
     UpdateSpellingUIWithGrammarString(WTF::String badGrammarPhrase, WebCore::GrammarDetail grammarDetail)
     GetGuessesForWord(WTF::String word, WTF::String context) -> (Vector<WTF::String> guesses)
index b6169d2..8f63e83 100644 (file)
@@ -79,6 +79,17 @@ void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<W
     notImplemented();
 }
 
+bool TextChecker::spellingUIIsShowing()
+{
+    notImplemented();
+    return false;
+}
+
+void TextChecker::toggleSpellingUIIsShowing()
+{
+    notImplemented();
+}
+
 void TextChecker::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
 {
     notImplemented();
index 004afa6..9e0594a 100644 (file)
@@ -309,6 +309,20 @@ void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<W
     notImplemented();
 }
 
+bool TextChecker::spellingUIIsShowing()
+{
+    return [[[NSSpellChecker sharedSpellChecker] spellingPanel] isVisible];
+}
+
+void TextChecker::toggleSpellingUIIsShowing()
+{
+    NSPanel *spellingPanel = [[NSSpellChecker sharedSpellChecker] spellingPanel];
+    if ([spellingPanel isVisible])
+        [spellingPanel orderOut:nil];
+    else
+        [spellingPanel orderFront:nil];
+}
+
 void TextChecker::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
 {
     [[NSSpellChecker sharedSpellChecker] updateSpellingPanelWithMisspelledWord:misspelledWord];
index 7b0c2d9..6bb7eaf 100644 (file)
@@ -80,6 +80,17 @@ void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<W
     notImplemented();
 }
 
+bool TextChecker::spellingUIIsShowing()
+{
+    notImplemented();
+    return false;
+}
+
+void TextChecker::toggleSpellingUIIsShowing()
+{
+    notImplemented();
+}
+
 void TextChecker::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
 {
     notImplemented();
index 3216378..cfe1a96 100644 (file)
@@ -102,6 +102,16 @@ void TextChecker::checkGrammarOfString(int64_t spellDocumentTag, const UChar* te
     WebTextChecker::shared()->client().checkGrammarOfString(spellDocumentTag, String(text, length), grammarDetails, badGrammarLocation, badGrammarLength);
 }
 
+bool TextChecker::spellingUIIsShowing()
+{
+    return WebTextChecker::shared()->client().spellingUIIsShowing();
+}
+
+void TextChecker::toggleSpellingUIIsShowing()
+{
+    WebTextChecker::shared()->client().toggleSpellingUIIsShowing();
+}
+
 void TextChecker::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
 {
     notImplemented();
index aee57e1..818cdc7 100644 (file)
@@ -112,4 +112,20 @@ void WebTextCheckerClient::checkGrammarOfString(uint64_t tag, const String& text
         grammarDetails.append(wkGrammarDetails->at<WebGrammarDetail>(i)->grammarDetail());
 }
 
+bool WebTextCheckerClient::spellingUIIsShowing()
+{
+    if (!m_client.spellingUIIsShowing)
+        return false;
+
+    return m_client.spellingUIIsShowing(m_client.clientInfo);
+}
+
+void WebTextCheckerClient::toggleSpellingUIIsShowing()
+{
+    if (!m_client.toggleSpellingUIIsShowing)
+        return;
+
+    return m_client.toggleSpellingUIIsShowing(m_client.clientInfo);
+}
+
 } // namespace WebKit
index 31d751c..21bedae 100644 (file)
@@ -45,6 +45,8 @@ public:
     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);
+    bool spellingUIIsShowing();
+    void toggleSpellingUIIsShowing();
 };
 
 } // namespace WebKit
index fcab6c3..5883962 100644 (file)
@@ -448,8 +448,9 @@ void WebEditorClient::showSpellingUI(bool)
 
 bool WebEditorClient::spellingUIIsShowing()
 {
-    notImplemented();
-    return false;
+    bool isShowing = false;
+    m_page->sendSync(Messages::WebPageProxy::SpellingUIIsShowing(), Messages::WebPageProxy::SpellingUIIsShowing::Reply(isShowing));
+    return isShowing;
 }
 
 void WebEditorClient::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)