Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[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 <nghanavatian@rim.com> 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 <nghanavatian@rim.com> 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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@123809 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information...
commit b7da7933eefb3812173e8c387501733ec9edd958 1 parent f89d459
commit-queue authored
View
15 Source/WebCore/ChangeLog
@@ -1,3 +1,18 @@
+2012-07-26 Nima Ghanavatian <nghanavatian@rim.com>
+
+ [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 <luxtella@company100.net>
Gather the duplicated timer code into CachedResource.
View
4 Source/WebCore/platform/text/TextChecking.h
@@ -39,8 +39,10 @@ namespace WebCore {
#define WTF_USE_GRAMMAR_CHECKING 1
-#if PLATFORM(MAC) && (PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
+#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_AUTOMATIC_TEXT_REPLACEMENT 1
#endif
View
10 Source/WebKit/blackberry/Api/WebPage.cpp
@@ -4593,9 +4593,14 @@ void WebPage::setSpellCheckingEnabled(bool enabled)
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> {
@@ -6404,6 +6409,7 @@ void WebPagePrivate::didChangeSettings(WebSettings* webSettings)
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())
View
3  Source/WebKit/blackberry/Api/WebPage.h
@@ -256,7 +256,8 @@ class BLACKBERRY_EXPORT WebPage : public Platform::GuardedPointerBase {
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&);
View
12 Source/WebKit/blackberry/Api/WebSettings.cpp
@@ -38,6 +38,7 @@ namespace BlackBerry {
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 @@ WebSettings* WebSettings::standardSettings()
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 @@ void WebSettings::setSpatialNavigationEnabled(bool enable)
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);
View
3  Source/WebKit/blackberry/Api/WebSettings.h
@@ -228,6 +228,9 @@ class BLACKBERRY_EXPORT WebSettings {
bool isSpatialNavigationEnabled() const;
void setSpatialNavigationEnabled(bool);
+ bool isAsynchronousSpellCheckingEnabled() const;
+ void setAsynchronousSpellCheckingEnabled(bool) const;
+
bool fullScreenVideoCapable() const;
void setFullScreenVideoCapable(bool);
View
41 Source/WebKit/blackberry/ChangeLog
@@ -1,3 +1,44 @@
+2012-07-26 Nima Ghanavatian <nghanavatian@rim.com>
+
+ [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 <mifenton@rim.com>
[BlackBerry] Improve the logs in Selection Handler.
View
7 Source/WebKit/blackberry/WebCoreSupport/EditorClientBlackBerry.cpp
@@ -570,7 +570,12 @@ void EditorClientBlackBerry::checkGrammarOfString(const UChar*, int, WTF::Vector
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();
}
View
1  Source/WebKit/blackberry/WebCoreSupport/EditorClientBlackBerry.h
@@ -87,6 +87,7 @@ class EditorClientBlackBerry : public EditorClient, public TextCheckerClient {
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&);
View
125 Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp
@@ -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,12 +520,127 @@ void InputHandler::learnText()
sendLearnTextDetails(textInField);
}
+void InputHandler::requestCheckingOfString(PassRefPtr<WebCore::TextCheckingRequest> textCheckingRequest)
+{
+ RefPtr<WebCore::TextCheckingRequest> request = textCheckingRequest;
+
+ 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;
+}
-void InputHandler::spellCheckingRequestProcessed(int32_t id, spannable_string_t* spannableString)
+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)
View
12 Source/WebKit/blackberry/WebKitSupport/InputHandler.h
@@ -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 HTMLInputElement;
class HTMLSelectElement;
class IntRect;
class Node;
+class SpellChecker;
+class TextCheckingRequest;
}
namespace BlackBerry {
@@ -122,7 +124,9 @@ class InputHandler {
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 @@ class InputHandler {
void learnText();
void sendLearnTextDetails(const WTF::String&);
+ int32_t convertTransactionIdToSequenceId(int32_t transactionId);
+ WebCore::SpellChecker* getSpellChecker();
WebPagePrivate* m_webPage;
@@ -196,6 +202,8 @@ class InputHandler {
PendingKeyboardStateChange m_pendingKeyboardVisibilityChange;
bool m_delayKeyboardVisibilityChange;
+
+ std::map<int32_t, int32_t> m_sequenceMap;
};
}
Please sign in to comment.
Something went wrong with that request. Please try again.