Title: [123809] trunk/Source
Revision
123809
Author
[email protected]
Date
2012-07-26 16:05:02 -0700 (Thu, 26 Jul 2012)

Log Message

[BlackBerry] Support async spellcheck for the blackberry port
https://bugs.webkit.org/show_bug.cgi?id=92160

Source/WebCore:

Set USE_UNIFIED_TEXT_CHECKING for PLATFORM(BLACKBERRY) to use the
asynchronous spellchecking code path.

Patch by Nima Ghanavatian <[email protected]> on 2012-07-26
Reviewed by Rob Buis.

Internally reviewed by Mike Fenton.

* platform/text/TextChecking.h:
(WebCore):

Source/WebKit/blackberry:

PR124517
Implementing support for async spellcheck.

Patch by Nima Ghanavatian <[email protected]> on 2012-07-26
Reviewed by Rob Buis.

Internally reviewed by Mike Fenton.

* Api/WebPage.cpp:
(BlackBerry::WebKit::WebPage::spellCheckingRequestCancelled):
(WebKit):
(BlackBerry::WebKit::WebPage::spellCheckingRequestProcessed):
(BlackBerry::WebKit::WebPagePrivate::didChangeSettings):
* Api/WebPage.h:
* Api/WebSettings.cpp:
(WebKit):
(BlackBerry::WebKit::WebSettings::standardSettings):
(BlackBerry::WebKit::WebSettings::isAsynchronousSpellCheckingEnabled):
(BlackBerry::WebKit::WebSettings::setAsynchronousSpellCheckingEnabled):
* Api/WebSettings.h:
* WebCoreSupport/EditorClientBlackBerry.cpp:
(WebCore):
(WebCore::EditorClientBlackBerry::requestCheckingOfString):
(WebCore::EditorClientBlackBerry::checkTextOfParagraph):
* WebCoreSupport/EditorClientBlackBerry.h:
(EditorClientBlackBerry):
* WebKitSupport/InputHandler.cpp:
(BlackBerry::WebKit::InputHandler::requestCheckingOfString):
(BlackBerry::WebKit::InputHandler::convertTransactionIdToSequenceId):
(WebKit):
(BlackBerry::WebKit::InputHandler::spellCheckingRequestProcessed):
(BlackBerry::WebKit::InputHandler::spellCheckingRequestCancelled):
(BlackBerry::WebKit::InputHandler::getSpellChecker):
* WebKitSupport/InputHandler.h:
(WebCore):
(InputHandler):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (123808 => 123809)


--- trunk/Source/WebCore/ChangeLog	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebCore/ChangeLog	2012-07-26 23:05:02 UTC (rev 123809)
@@ -1,3 +1,18 @@
+2012-07-26  Nima Ghanavatian  <[email protected]>
+
+        [BlackBerry] Support async spellcheck for the blackberry port
+        https://bugs.webkit.org/show_bug.cgi?id=92160
+
+        Set USE_UNIFIED_TEXT_CHECKING for PLATFORM(BLACKBERRY) to use the
+        asynchronous spellchecking code path.
+
+        Reviewed by Rob Buis.
+
+        Internally reviewed by Mike Fenton.
+
+        * platform/text/TextChecking.h:
+        (WebCore):
+
 2012-07-26  Huang Dongsung  <[email protected]>
 
         Gather the duplicated timer code into CachedResource.

Modified: trunk/Source/WebCore/platform/text/TextChecking.h (123808 => 123809)


--- trunk/Source/WebCore/platform/text/TextChecking.h	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebCore/platform/text/TextChecking.h	2012-07-26 23:05:02 UTC (rev 123809)
@@ -39,8 +39,10 @@
 
 #define WTF_USE_GRAMMAR_CHECKING 1
 
+#if (PLATFORM(MAC) && (PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)) || PLATFORM(BLACKBERRY)
+#define WTF_USE_UNIFIED_TEXT_CHECKING 1
+#endif
 #if PLATFORM(MAC) && (PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
-#define WTF_USE_UNIFIED_TEXT_CHECKING 1
 #define WTF_USE_AUTOMATIC_TEXT_REPLACEMENT 1
 #endif
 

Modified: trunk/Source/WebKit/blackberry/Api/WebPage.cpp (123808 => 123809)


--- trunk/Source/WebKit/blackberry/Api/WebPage.cpp	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebKit/blackberry/Api/WebPage.cpp	2012-07-26 23:05:02 UTC (rev 123809)
@@ -4593,11 +4593,16 @@
     static_cast<EditorClientBlackBerry*>(d->m_page->editorClient())->enableSpellChecking(enabled);
 }
 
-void WebPage::spellCheckingRequestProcessed(int32_t id, spannable_string_t* spannableString)
+void WebPage::spellCheckingRequestCancelled(int32_t transactionId)
 {
-    d->m_inputHandler->spellCheckingRequestProcessed(id, spannableString);
+    d->m_inputHandler->spellCheckingRequestCancelled(transactionId);
 }
 
+void WebPage::spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t* spannableString)
+{
+    d->m_inputHandler->spellCheckingRequestProcessed(transactionId, spannableString);
+}
+
 class DeferredTaskSelectionCancelled: public DeferredTask<&WebPagePrivate::m_wouldCancelSelection> {
 public:
     explicit DeferredTaskSelectionCancelled(WebPagePrivate* webPagePrivate)
@@ -6404,6 +6409,7 @@
     coreSettings->setDefaultTextEncodingName(webSettings->defaultTextEncodingName().impl());
     coreSettings->setDownloadableBinaryFontsEnabled(webSettings->downloadableBinaryFontsEnabled());
     coreSettings->setSpatialNavigationEnabled(m_webSettings->isSpatialNavigationEnabled());
+    coreSettings->setAsynchronousSpellCheckingEnabled(m_webSettings->isAsynchronousSpellCheckingEnabled());
 
     WebString stylesheetURL = webSettings->userStyleSheetString();
     if (stylesheetURL.isEmpty())

Modified: trunk/Source/WebKit/blackberry/Api/WebPage.h (123808 => 123809)


--- trunk/Source/WebKit/blackberry/Api/WebPage.h	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebKit/blackberry/Api/WebPage.h	2012-07-26 23:05:02 UTC (rev 123809)
@@ -256,7 +256,8 @@
     int32_t commitText(spannable_string_t*, int32_t relativeCursorPosition);
 
     void setSpellCheckingEnabled(bool);
-    void spellCheckingRequestProcessed(int32_t id, spannable_string_t*);
+    void spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t*);
+    void spellCheckingRequestCancelled(int32_t transactionId);
 
     void setSelection(const Platform::IntPoint& startPoint, const Platform::IntPoint& endPoint);
     void setCaretPosition(const Platform::IntPoint&);

Modified: trunk/Source/WebKit/blackberry/Api/WebSettings.cpp (123808 => 123809)


--- trunk/Source/WebKit/blackberry/Api/WebSettings.cpp	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebKit/blackberry/Api/WebSettings.cpp	2012-07-26 23:05:02 UTC (rev 123809)
@@ -38,6 +38,7 @@
 namespace WebKit {
 
 DEFINE_STATIC_LOCAL(String, BlackBerryAllowCrossSiteRequests, ("BlackBerryAllowCrossSiteRequests"));
+DEFINE_STATIC_LOCAL(String, BlackBerryAsynchronousSpellChecking, ("BlackBerryAsynchronousSpellChecking"));
 DEFINE_STATIC_LOCAL(String, BlackBerryBackgroundColor, ("BlackBerryBackgroundColor"));
 DEFINE_STATIC_LOCAL(String, BlackBerryCookiesEnabled, ("BlackBerryCookiesEnabled"));
 DEFINE_STATIC_LOCAL(String, BlackBerryDirectRenderingToWindowEnabled, ("BlackBerryDirectRenderingToWindowEnabled"));
@@ -177,6 +178,7 @@
     settings->m_private->setBoolean(BlackBerryFullScreenVideoCapable, false);
     settings->m_private->setBoolean(BlackBerryCredentialAutofillEnabled, false);
     settings->m_private->setBoolean(BlackBerryFormAutofillEnabled, false);
+    settings->m_private->setBoolean(BlackBerryAsynchronousSpellChecking, true);
 
     if (BlackBerry::Platform::DeviceInfo::instance()->isMobile()) {
         WebCore::FloatSize currentPPI = Platform::Graphics::Screen::primaryScreen()->pixelsPerInch(-1);
@@ -807,6 +809,16 @@
     m_private->setBoolean(SpatialNavigationEnabled, enable);
 }
 
+bool WebSettings::isAsynchronousSpellCheckingEnabled() const
+{
+    return m_private->getBoolean(BlackBerryAsynchronousSpellChecking);
+}
+
+void WebSettings::setAsynchronousSpellCheckingEnabled(bool enable) const
+{
+    return m_private->setBoolean(BlackBerryAsynchronousSpellChecking, enable);
+}
+
 bool WebSettings::fullScreenVideoCapable() const
 {
     return m_private->getBoolean(BlackBerryFullScreenVideoCapable);

Modified: trunk/Source/WebKit/blackberry/Api/WebSettings.h (123808 => 123809)


--- trunk/Source/WebKit/blackberry/Api/WebSettings.h	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebKit/blackberry/Api/WebSettings.h	2012-07-26 23:05:02 UTC (rev 123809)
@@ -228,6 +228,9 @@
     bool isSpatialNavigationEnabled() const;
     void setSpatialNavigationEnabled(bool);
 
+    bool isAsynchronousSpellCheckingEnabled() const;
+    void setAsynchronousSpellCheckingEnabled(bool) const;
+
     bool fullScreenVideoCapable() const;
     void setFullScreenVideoCapable(bool);
 

Modified: trunk/Source/WebKit/blackberry/ChangeLog (123808 => 123809)


--- trunk/Source/WebKit/blackberry/ChangeLog	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2012-07-26 23:05:02 UTC (rev 123809)
@@ -1,3 +1,44 @@
+2012-07-26  Nima Ghanavatian  <[email protected]>
+
+        [BlackBerry] Support async spellcheck for the blackberry port
+        https://bugs.webkit.org/show_bug.cgi?id=92160
+
+        PR124517
+        Implementing support for async spellcheck.
+
+        Reviewed by Rob Buis.
+
+        Internally reviewed by Mike Fenton.
+
+        * Api/WebPage.cpp:
+        (BlackBerry::WebKit::WebPage::spellCheckingRequestCancelled):
+        (WebKit):
+        (BlackBerry::WebKit::WebPage::spellCheckingRequestProcessed):
+        (BlackBerry::WebKit::WebPagePrivate::didChangeSettings):
+        * Api/WebPage.h:
+        * Api/WebSettings.cpp:
+        (WebKit):
+        (BlackBerry::WebKit::WebSettings::standardSettings):
+        (BlackBerry::WebKit::WebSettings::isAsynchronousSpellCheckingEnabled):
+        (BlackBerry::WebKit::WebSettings::setAsynchronousSpellCheckingEnabled):
+        * Api/WebSettings.h:
+        * WebCoreSupport/EditorClientBlackBerry.cpp:
+        (WebCore):
+        (WebCore::EditorClientBlackBerry::requestCheckingOfString):
+        (WebCore::EditorClientBlackBerry::checkTextOfParagraph):
+        * WebCoreSupport/EditorClientBlackBerry.h:
+        (EditorClientBlackBerry):
+        * WebKitSupport/InputHandler.cpp:
+        (BlackBerry::WebKit::InputHandler::requestCheckingOfString):
+        (BlackBerry::WebKit::InputHandler::convertTransactionIdToSequenceId):
+        (WebKit):
+        (BlackBerry::WebKit::InputHandler::spellCheckingRequestProcessed):
+        (BlackBerry::WebKit::InputHandler::spellCheckingRequestCancelled):
+        (BlackBerry::WebKit::InputHandler::getSpellChecker):
+        * WebKitSupport/InputHandler.h:
+        (WebCore):
+        (InputHandler):
+
 2012-07-26  Mike Fenton  <[email protected]>
 
         [BlackBerry] Improve the logs in Selection Handler.

Modified: trunk/Source/WebKit/blackberry/WebCoreSupport/EditorClientBlackBerry.cpp (123808 => 123809)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/EditorClientBlackBerry.cpp	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/EditorClientBlackBerry.cpp	2012-07-26 23:05:02 UTC (rev 123809)
@@ -570,8 +570,13 @@
     notImplemented();
 }
 
-void EditorClientBlackBerry::requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>)
+void EditorClientBlackBerry::requestCheckingOfString(PassRefPtr<TextCheckingRequest> testCheckingRequest)
 {
+    m_webPagePrivate->m_inputHandler->requestCheckingOfString(textCheckingRequest);
+}
+
+void EditorClientBlackBerry::checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&)
+{
     notImplemented();
 }
 

Modified: trunk/Source/WebKit/blackberry/WebCoreSupport/EditorClientBlackBerry.h (123808 => 123809)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/EditorClientBlackBerry.h	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/EditorClientBlackBerry.h	2012-07-26 23:05:02 UTC (rev 123809)
@@ -87,6 +87,7 @@
     virtual void checkGrammarOfString(const UChar*, int, Vector<GrammarDetail, 0u>&, int*, int*);
     virtual void getGuessesForWord(const String&, const String&, Vector<String>&);
     virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>);
+    virtual void checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&);
 
     virtual TextCheckerClient* textChecker();
     virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail&);

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp (123808 => 123809)


--- trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp	2012-07-26 23:05:02 UTC (rev 123809)
@@ -53,6 +53,8 @@
 #include "ScopePointer.h"
 #include "SelectPopupClient.h"
 #include "SelectionHandler.h"
+#include "SpellChecker.h"
+#include "TextCheckerClient.h"
 #include "TextIterator.h"
 #include "WebPageClient.h"
 #include "WebPage_p.h"
@@ -518,14 +520,129 @@
     sendLearnTextDetails(textInField);
 }
 
+void InputHandler::requestCheckingOfString(PassRefPtr<WebCore::TextCheckingRequest> textCheckingRequest)
+{
+    RefPtr<WebCore::TextCheckingRequest> request = textCheckingRequest;
 
-void InputHandler::spellCheckingRequestProcessed(int32_t id, spannable_string_t* spannableString)
+    int32_t sequenceId = request->sequence();
+    int requestLength = request->text().length();
+    if (!requestLength /* || requestLength > maxSpellCheckStringLength */) {
+        spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
+        return;
+    }
+
+    wchar_t* checkingString = (wchar_t*)malloc(sizeof(wchar_t) * (requestLength + 1));
+    if (!checkingString) {
+        BlackBerry::Platform::logAlways(BlackBerry::Platform::LogLevelCritical, "InputHandler::requestCheckingOfString Cannot allocate memory for string.");
+        spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
+        return;
+    }
+
+    int stringLength = 0;
+    if (!convertStringToWchar(request->text(), checkingString, requestLength + 1, &stringLength)) {
+        BlackBerry::Platform::logAlways(BlackBerry::Platform::LogLevelCritical, "InputHandler::requestCheckingOfString Failed to convert String to wchar type.");
+        free(checkingString);
+        spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
+        return;
+    }
+
+    int32_t transactionId = m_webPage->m_client->checkSpellingOfStringAsync(checkingString, stringLength);
+    free(checkingString);
+
+    // If the call to the input service did not go through, then cancel the request so we don't block endlessly.
+    // This should still take transactionId as a parameter to maintain the same behavior as if InputMethodSupport
+    // were to cancel a request during processing.
+    if (transactionId == -1) { // Error before sending request to input service.
+        spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
+        return;
+    }
+
+    // map sequenceId to transactionId.
+    m_sequenceMap[transactionId] = sequenceId;
+}
+
+int32_t InputHandler::convertTransactionIdToSequenceId(int32_t transactionId)
 {
-    UNUSED_PARAM(id);
-    UNUSED_PARAM(spannableString);
-    // TODO implement.
+    std::map<int32_t, int32_t>::iterator it = m_sequenceMap.find(transactionId);
+
+    if (it == m_sequenceMap.end())
+        return 0;
+
+    int32_t sequenceId = it->second;
+    // We only convert this value when we have received its response, so its safe to remove it from the map.
+    m_sequenceMap.erase(it);
+
+    return sequenceId;
 }
 
+void InputHandler::spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t* spannableString)
+{
+    if (!spannableString) {
+        spellCheckingRequestCancelled(transactionId, false /* isSequenceId */);
+        return;
+    }
+
+    Vector<TextCheckingResult> results;
+
+    // Convert the spannableString to TextCheckingResult then append to results vector.
+    String replacement;
+    TextCheckingResult textCheckingResult;
+    textCheckingResult.type = TextCheckingTypeSpelling;
+    textCheckingResult.replacement = replacement;
+    textCheckingResult.location = 0;
+    textCheckingResult.length = 0;
+
+    span_t* span = spannableString->spans;
+    for (unsigned int i = 0; i < spannableString->spans_count; i++) {
+        if (!span)
+            break;
+        if (span->end < span->start) {
+            spellCheckingRequestCancelled(transactionId, false /* isSequenceId */);
+            return;
+        }
+        if (span->attributes_mask & MISSPELLED_WORD_ATTRIB) {
+            textCheckingResult.location = span->start;
+            // The end point includes the character that it is before. Ie, 0, 0
+            // applies to the first character as the end point includes the character
+            // at the position. This means the endPosition is always +1.
+            textCheckingResult.length = span->end - span->start + 1;
+            results.append(textCheckingResult);
+        }
+        span++;
+    }
+
+    // transactionId here is for use with the input service. We need to translate this to sequenceId used with SpellChecker.
+    int32_t sequenceId = convertTransactionIdToSequenceId(transactionId);
+
+    SpellChecker* sp = getSpellChecker();
+    if (!sp || !sequenceId) {
+        InputLog(LogLevelWarn, "InputHandler::spellCheckingRequestProcessed failed to process the request with sequenceId %d", sequenceId);
+        spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
+        return;
+    }
+    sp->didCheckSucceeded(sequenceId, results);
+}
+
+void InputHandler::spellCheckingRequestCancelled(int32_t id, bool isSequenceId)
+{
+    int32_t sequenceId = isSequenceId ? id : convertTransactionIdToSequenceId(id);
+    SpellChecker* sp = getSpellChecker();
+    if (!sp) {
+        InputLog(LogLevelWarn, "InputHandler::spellCheckingRequestCancelled failed to cancel the request with sequenceId %d", sequenceId);
+        return;
+    }
+    sp->didCheckCanceled(sequenceId);
+}
+
+SpellChecker* InputHandler::getSpellChecker()
+{
+    if (Frame* frame = m_currentFocusElement->document()->frame())
+        if (Editor* editor = frame->editor())
+            return editor->spellChecker();
+
+    return 0;
+}
+
 void InputHandler::setElementUnfocused(bool refocusOccuring)
 {
     if (isActiveTextEdit()) {

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h (123808 => 123809)


--- trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h	2012-07-26 23:03:40 UTC (rev 123808)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h	2012-07-26 23:05:02 UTC (rev 123809)
@@ -22,7 +22,7 @@
 #include <BlackBerryPlatformInputEvents.h>
 
 #include <imf/input_data.h>
-
+#include <map>
 #include <wtf/RefPtr.h>
 
 namespace WTF {
@@ -37,6 +37,8 @@
 class HTMLSelectElement;
 class IntRect;
 class Node;
+class SpellChecker;
+class TextCheckingRequest;
 }
 
 namespace BlackBerry {
@@ -122,7 +124,9 @@
     int32_t setComposingText(spannable_string_t*, int32_t relativeCursorPosition);
     int32_t commitText(spannable_string_t*, int32_t relativeCursorPosition);
 
-    void spellCheckingRequestProcessed(int32_t id, spannable_string_t*);
+    void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>);
+    void spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t*);
+    void spellCheckingRequestCancelled(int32_t id, bool isSequenceId = false);
 
 private:
     enum PendingKeyboardStateChange { NoChange, Visible, NotVisible };
@@ -179,6 +183,8 @@
 
     void learnText();
     void sendLearnTextDetails(const WTF::String&);
+    int32_t convertTransactionIdToSequenceId(int32_t transactionId);
+    WebCore::SpellChecker* getSpellChecker();
 
     WebPagePrivate* m_webPage;
 
@@ -196,6 +202,8 @@
 
     PendingKeyboardStateChange m_pendingKeyboardVisibilityChange;
     bool m_delayKeyboardVisibilityChange;
+
+    std::map<int32_t, int32_t> m_sequenceMap;
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to