Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp (128932 => 128933)
--- trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp 2012-09-18 21:37:03 UTC (rev 128932)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp 2012-09-18 21:38:57 UTC (rev 128933)
@@ -136,8 +136,9 @@
, m_composingTextEnd(0)
, m_pendingKeyboardVisibilityChange(NoChange)
, m_delayKeyboardVisibilityChange(false)
+ , m_request(0)
+ , m_processingTransactionId(-1)
{
- pthread_mutex_init(&m_sequenceMapMutex, 0);
}
InputHandler::~InputHandler()
@@ -545,32 +546,25 @@
void InputHandler::requestCheckingOfString(PassRefPtr<WebCore::TextCheckingRequest> textCheckingRequest)
{
- RefPtr<WebCore::TextCheckingRequest> request = textCheckingRequest;
+ m_request = textCheckingRequest;
- int32_t sequenceId = request->sequence();
-
- if (!isActiveTextEdit()) {
- spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
+ if (!m_request) {
+ SpellingLog(LogLevelWarn, "InputHandler::requestCheckingOfString did not receive a valid request.");
return;
}
+ unsigned requestLength = m_request->text().length();
+
// Check if the field should be spellchecked.
- if (!shouldSpellCheckElement(m_currentFocusElement.get())) {
- spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
+ if (!isActiveTextEdit() || !shouldSpellCheckElement(m_currentFocusElement.get()) || requestLength < 2) {
+ m_request->didCancel();
return;
}
- unsigned requestLength = request->text().length();
-
- if (requestLength < 2) {
- spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
- return;
- }
-
if (requestLength > MaxSpellCheckingStringLength) {
// Cancel this request and send it off in newly created chunks.
- spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
- if (m_currentFocusElement && m_currentFocusElement->document() && m_currentFocusElement->document()->frame() && m_currentFocusElement->document()->frame()->selection()) {
+ m_request->didCancel();
+ if (m_currentFocusElement->document() && m_currentFocusElement->document()->frame() && m_currentFocusElement->document()->frame()->selection()) {
// Convert from position back to selection so we can expand the range to include the previous line. This should handle cases when the user hits
// enter to finish composing a word and create a new line.
VisiblePosition caretPosition = m_currentFocusElement->document()->frame()->selection()->start();
@@ -583,53 +577,49 @@
wchar_t* checkingString = (wchar_t*)malloc(sizeof(wchar_t) * (requestLength + 1));
if (!checkingString) {
logAlways(LogLevelCritical, "InputHandler::requestCheckingOfString Cannot allocate memory for string.");
- spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
+ m_request->didCancel();
return;
}
int paragraphLength = 0;
- if (!convertStringToWchar(request->text(), checkingString, requestLength + 1, ¶graphLength)) {
+ if (!convertStringToWchar(m_request->text(), checkingString, requestLength + 1, ¶graphLength)) {
logAlways(LogLevelCritical, "InputHandler::requestCheckingOfString Failed to convert String to wchar type.");
free(checkingString);
- spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
+ m_request->didCancel();
return;
}
- BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex);
- int32_t transactionId = m_webPage->m_client->checkSpellingOfStringAsync(checkingString, paragraphLength);
+ m_processingTransactionId = m_webPage->m_client->checkSpellingOfStringAsync(checkingString, paragraphLength);
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 */);
+ if (m_processingTransactionId == -1) { // Error before sending request to input service.
+ m_request->didCancel();
return;
}
-
- // map sequenceId to transactionId.
- m_sequenceMap[transactionId] = sequenceId;
}
-int32_t InputHandler::convertTransactionIdToSequenceId(int32_t transactionId)
+void InputHandler::spellCheckingRequestCancelled(int32_t transactionId)
{
- BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex);
- 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;
+ if (transactionId != m_processingTransactionId)
+ SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestCancelled We are out of sync with input service. Expected transaction id %d, received %d.", m_processingTransactionId, transactionId);
+ else
+ SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestCancelled Request with transaction id %d has been cancelled.", transactionId);
+ m_request->didCancel();
+ m_processingTransactionId = -1;
}
void InputHandler::spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t* spannableString)
{
+ if (transactionId != m_processingTransactionId)
+ SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestProcessed We are out of sync with input service. Expected transaction id %d, received %d.", m_processingTransactionId, transactionId);
+
if (!spannableString || !isActiveTextEdit()) {
- spellCheckingRequestCancelled(transactionId, false /* isSequenceId */);
+ SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestProcessed Cancelling request with transactionId %d.", transactionId);
+ m_request->didCancel();
+ m_processingTransactionId = -1;
return;
}
@@ -648,7 +638,7 @@
if (!span)
break;
if (span->end < span->start) {
- spellCheckingRequestCancelled(transactionId, false /* isSequenceId */);
+ m_request->didCancel();
return;
}
if (span->attributes_mask & MISSPELLED_WORD_ATTRIB) {
@@ -662,44 +652,13 @@
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* spellChecker = getSpellChecker();
- if (!spellChecker || !sequenceId) {
- SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestProcessed Failed to process the request with sequenceId %d", sequenceId);
- spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
- return;
- }
- spellChecker->didCheckSucceeded(sequenceId, results);
+ m_request->didSucceed(results);
}
-void InputHandler::cancelAllSpellCheckingRequests()
-{
- BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex);
- for (std::map<int32_t, int32_t>::iterator it = m_sequenceMap.begin(); it != m_sequenceMap.end(); ++it)
- spellCheckingRequestCancelled(it->second, true /* isSequenceId */);
- m_sequenceMap.clear();
-}
-
-void InputHandler::spellCheckingRequestCancelled(int32_t id, bool isSequenceId)
-{
- if (!isActiveTextEdit())
- return;
-
- int32_t sequenceId = isSequenceId ? id : convertTransactionIdToSequenceId(id);
- SpellChecker* spellChecker = getSpellChecker();
- if (!spellChecker || !sequenceId) {
- SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestCancelled failed to cancel the request with sequenceId %d", sequenceId);
- return;
- }
- spellChecker->didCheckCanceled(sequenceId);
-}
-
SpellChecker* InputHandler::getSpellChecker()
{
- ASSERT(m_currentFocusElement);
- ASSERT(m_currentFocusElement->document());
+ if (!m_currentFocusElement || !m_currentFocusElement->document())
+ return 0;
if (Frame* frame = m_currentFocusElement->document()->frame())
if (Editor* editor = frame->editor())
@@ -772,9 +731,6 @@
// If the frame selection isn't focused, focus it.
if (!m_currentFocusElement->document()->frame()->selection()->isFocused())
m_currentFocusElement->document()->frame()->selection()->setFocused(true);
-
- // Cancel any spellcheck requests that might be ongoing.
- cancelAllSpellCheckingRequests();
}
// Clear the node details.
Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h (128932 => 128933)
--- trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h 2012-09-18 21:37:03 UTC (rev 128932)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h 2012-09-18 21:38:57 UTC (rev 128933)
@@ -137,7 +137,7 @@
void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>);
void spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t*);
- void spellCheckingRequestCancelled(int32_t id, bool isSequenceId = false);
+ void spellCheckingRequestCancelled(int32_t transactionId);
bool shouldRequestSpellCheckingOptionsForPoint(Platform::IntPoint&, const WebCore::Element*, imf_sp_text_t&);
void requestSpellingCheckingOptions(imf_sp_text_t&);
@@ -197,10 +197,8 @@
void learnText();
void sendLearnTextDetails(const WTF::String&);
- int32_t convertTransactionIdToSequenceId(int32_t transactionId);
void spellCheckBlock(WebCore::VisibleSelection&, WebCore::TextCheckingProcessType);
PassRefPtr<WebCore::Range> getRangeForSpellCheckWithFineGranularity(WebCore::VisiblePosition startPosition, WebCore::VisiblePosition endPosition);
- void cancelAllSpellCheckingRequests();
WebCore::SpellChecker* getSpellChecker();
bool shouldSpellCheckElement(const WebCore::Element*) const;
@@ -221,8 +219,8 @@
PendingKeyboardStateChange m_pendingKeyboardVisibilityChange;
bool m_delayKeyboardVisibilityChange;
- std::map<int32_t, int32_t> m_sequenceMap;
- pthread_mutex_t m_sequenceMapMutex;
+ RefPtr<WebCore::TextCheckingRequest> m_request;
+ int32_t m_processingTransactionId;
};
}