Changeset 128933 in webkit


Ignore:
Timestamp:
Sep 18, 2012 2:38:57 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[BlackBerry] Use didCancel and didSucceed instead of didCheckCancel and didCheckSucceed
https://bugs.webkit.org/show_bug.cgi?id=97033

Patch by Nima Ghanavatian <nghanavatian@rim.com> on 2012-09-18
Reviewed by Rob Buis.

Using these preferred public methods (the latter has a note to be made private) ensures that
the right SpellChecker object is being called during the callback in spellCheckingRequestProcessed
and spellCheckingRequestCancelled.

Internally reviewed by Mike Fenton.

By referencing the TextCheckingRequest object's methods, we don't need to keep track of the associated
SpellChecker for each request. Removing much of the code that was put in place incorrectly to achieve this.

  • WebKitSupport/InputHandler.cpp:

(BlackBerry::WebKit::InputHandler::InputHandler):
(BlackBerry::WebKit::InputHandler::requestCheckingOfString):
(BlackBerry::WebKit::InputHandler::spellCheckingRequestCancelled):
(BlackBerry::WebKit::InputHandler::spellCheckingRequestProcessed):
(BlackBerry::WebKit::InputHandler::getSpellChecker):

  • WebKitSupport/InputHandler.h:

(InputHandler):

Location:
trunk/Source/WebKit/blackberry
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/blackberry/ChangeLog

    r128923 r128933  
     12012-09-18  Nima Ghanavatian  <nghanavatian@rim.com>
     2
     3        [BlackBerry] Use didCancel and didSucceed instead of didCheckCancel and didCheckSucceed
     4        https://bugs.webkit.org/show_bug.cgi?id=97033
     5
     6        Reviewed by Rob Buis.
     7
     8        Using these preferred public methods (the latter has a note to be made private) ensures that
     9        the right SpellChecker object is being called during the callback in spellCheckingRequestProcessed
     10        and spellCheckingRequestCancelled.
     11
     12        Internally reviewed by Mike Fenton.
     13
     14        By referencing the TextCheckingRequest object's methods, we don't need to keep track of the associated
     15        SpellChecker for each request. Removing much of the code that was put in place incorrectly to achieve this.
     16
     17        * WebKitSupport/InputHandler.cpp:
     18        (BlackBerry::WebKit::InputHandler::InputHandler):
     19        (BlackBerry::WebKit::InputHandler::requestCheckingOfString):
     20        (BlackBerry::WebKit::InputHandler::spellCheckingRequestCancelled):
     21        (BlackBerry::WebKit::InputHandler::spellCheckingRequestProcessed):
     22        (BlackBerry::WebKit::InputHandler::getSpellChecker):
     23        * WebKitSupport/InputHandler.h:
     24        (InputHandler):
     25
    1262012-09-18  Jessica Cao  <jecao@rim.com>
    227
  • trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp

    r128858 r128933  
    137137    , m_pendingKeyboardVisibilityChange(NoChange)
    138138    , m_delayKeyboardVisibilityChange(false)
    139 {
    140     pthread_mutex_init(&m_sequenceMapMutex, 0);
     139    , m_request(0)
     140    , m_processingTransactionId(-1)
     141{
    141142}
    142143
     
    546547void InputHandler::requestCheckingOfString(PassRefPtr<WebCore::TextCheckingRequest> textCheckingRequest)
    547548{
    548     RefPtr<WebCore::TextCheckingRequest> request = textCheckingRequest;
    549 
    550     int32_t sequenceId = request->sequence();
    551 
    552     if (!isActiveTextEdit()) {
    553         spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
    554         return;
    555     }
     549    m_request = textCheckingRequest;
     550
     551    if (!m_request) {
     552        SpellingLog(LogLevelWarn, "InputHandler::requestCheckingOfString did not receive a valid request.");
     553        return;
     554    }
     555
     556    unsigned requestLength = m_request->text().length();
    556557
    557558    // Check if the field should be spellchecked.
    558     if (!shouldSpellCheckElement(m_currentFocusElement.get())) {
    559         spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
    560         return;
    561     }
    562 
    563     unsigned requestLength = request->text().length();
    564 
    565     if (requestLength < 2) {
    566         spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
     559    if (!isActiveTextEdit() || !shouldSpellCheckElement(m_currentFocusElement.get()) || requestLength < 2) {
     560        m_request->didCancel();
    567561        return;
    568562    }
     
    570564    if (requestLength > MaxSpellCheckingStringLength) {
    571565        // Cancel this request and send it off in newly created chunks.
    572         spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
    573         if (m_currentFocusElement && m_currentFocusElement->document() && m_currentFocusElement->document()->frame() && m_currentFocusElement->document()->frame()->selection()) {
     566        m_request->didCancel();
     567        if (m_currentFocusElement->document() && m_currentFocusElement->document()->frame() && m_currentFocusElement->document()->frame()->selection()) {
    574568            // 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
    575569            // enter to finish composing a word and create a new line.
     
    584578    if (!checkingString) {
    585579        logAlways(LogLevelCritical, "InputHandler::requestCheckingOfString Cannot allocate memory for string.");
    586         spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
     580        m_request->didCancel();
    587581        return;
    588582    }
    589583
    590584    int paragraphLength = 0;
    591     if (!convertStringToWchar(request->text(), checkingString, requestLength + 1, &paragraphLength)) {
     585    if (!convertStringToWchar(m_request->text(), checkingString, requestLength + 1, &paragraphLength)) {
    592586        logAlways(LogLevelCritical, "InputHandler::requestCheckingOfString Failed to convert String to wchar type.");
    593587        free(checkingString);
    594         spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
    595         return;
    596     }
    597 
    598     BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex);
    599     int32_t transactionId = m_webPage->m_client->checkSpellingOfStringAsync(checkingString, paragraphLength);
     588        m_request->didCancel();
     589        return;
     590    }
     591
     592    m_processingTransactionId = m_webPage->m_client->checkSpellingOfStringAsync(checkingString, paragraphLength);
    600593    free(checkingString);
    601594
     
    603596    // This should still take transactionId as a parameter to maintain the same behavior as if InputMethodSupport
    604597    // were to cancel a request during processing.
    605     if (transactionId == -1) { // Error before sending request to input service.
    606         spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
    607         return;
    608     }
    609 
    610     // map sequenceId to transactionId.
    611     m_sequenceMap[transactionId] = sequenceId;
    612 }
    613 
    614 int32_t InputHandler::convertTransactionIdToSequenceId(int32_t transactionId)
    615 {
    616     BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex);
    617     std::map<int32_t, int32_t>::iterator it = m_sequenceMap.find(transactionId);
    618 
    619     if (it == m_sequenceMap.end())
    620         return 0;
    621 
    622     int32_t sequenceId = it->second;
    623     // We only convert this value when we have received its response, so its safe to remove it from the map.
    624     m_sequenceMap.erase(it);
    625 
    626     return sequenceId;
     598    if (m_processingTransactionId == -1) { // Error before sending request to input service.
     599        m_request->didCancel();
     600        return;
     601    }
     602}
     603
     604void InputHandler::spellCheckingRequestCancelled(int32_t transactionId)
     605{
     606    if (transactionId != m_processingTransactionId)
     607        SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestCancelled We are out of sync with input service. Expected transaction id %d, received %d.", m_processingTransactionId, transactionId);
     608    else
     609        SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestCancelled Request with transaction id %d has been cancelled.", transactionId);
     610    m_request->didCancel();
     611    m_processingTransactionId = -1;
    627612}
    628613
    629614void InputHandler::spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t* spannableString)
    630615{
     616    if (transactionId != m_processingTransactionId)
     617        SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestProcessed We are out of sync with input service. Expected transaction id %d, received %d.", m_processingTransactionId, transactionId);
     618
    631619    if (!spannableString || !isActiveTextEdit()) {
    632         spellCheckingRequestCancelled(transactionId, false /* isSequenceId */);
     620        SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestProcessed Cancelling request with transactionId %d.", transactionId);
     621        m_request->didCancel();
     622        m_processingTransactionId = -1;
    633623        return;
    634624    }
     
    649639            break;
    650640        if (span->end < span->start) {
    651             spellCheckingRequestCancelled(transactionId, false /* isSequenceId */);
     641            m_request->didCancel();
    652642            return;
    653643        }
     
    663653    }
    664654
    665     // transactionId here is for use with the input service. We need to translate this to sequenceId used with SpellChecker.
    666     int32_t sequenceId = convertTransactionIdToSequenceId(transactionId);
    667 
    668     SpellChecker* spellChecker = getSpellChecker();
    669     if (!spellChecker || !sequenceId) {
    670         SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestProcessed Failed to process the request with sequenceId %d", sequenceId);
    671         spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);
    672         return;
    673     }
    674     spellChecker->didCheckSucceeded(sequenceId, results);
    675 }
    676 
    677 void InputHandler::cancelAllSpellCheckingRequests()
    678 {
    679     BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex);
    680     for (std::map<int32_t, int32_t>::iterator it = m_sequenceMap.begin(); it != m_sequenceMap.end(); ++it)
    681         spellCheckingRequestCancelled(it->second, true /* isSequenceId */);
    682     m_sequenceMap.clear();
    683 }
    684 
    685 void InputHandler::spellCheckingRequestCancelled(int32_t id, bool isSequenceId)
    686 {
    687     if (!isActiveTextEdit())
    688         return;
    689 
    690     int32_t sequenceId = isSequenceId ? id : convertTransactionIdToSequenceId(id);
    691     SpellChecker* spellChecker = getSpellChecker();
    692     if (!spellChecker || !sequenceId) {
    693         SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestCancelled failed to cancel the request with sequenceId %d", sequenceId);
    694         return;
    695     }
    696     spellChecker->didCheckCanceled(sequenceId);
     655    m_request->didSucceed(results);
    697656}
    698657
    699658SpellChecker* InputHandler::getSpellChecker()
    700659{
    701     ASSERT(m_currentFocusElement);
    702     ASSERT(m_currentFocusElement->document());
     660    if (!m_currentFocusElement || !m_currentFocusElement->document())
     661        return 0;
    703662
    704663    if (Frame* frame = m_currentFocusElement->document()->frame())
     
    773732        if (!m_currentFocusElement->document()->frame()->selection()->isFocused())
    774733            m_currentFocusElement->document()->frame()->selection()->setFocused(true);
    775 
    776         // Cancel any spellcheck requests that might be ongoing.
    777         cancelAllSpellCheckingRequests();
    778734    }
    779735
  • trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h

    r128858 r128933  
    138138    void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>);
    139139    void spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t*);
    140     void spellCheckingRequestCancelled(int32_t id, bool isSequenceId = false);
     140    void spellCheckingRequestCancelled(int32_t transactionId);
    141141
    142142    bool shouldRequestSpellCheckingOptionsForPoint(Platform::IntPoint&, const WebCore::Element*, imf_sp_text_t&);
     
    198198    void learnText();
    199199    void sendLearnTextDetails(const WTF::String&);
    200     int32_t convertTransactionIdToSequenceId(int32_t transactionId);
    201200    void spellCheckBlock(WebCore::VisibleSelection&, WebCore::TextCheckingProcessType);
    202201    PassRefPtr<WebCore::Range> getRangeForSpellCheckWithFineGranularity(WebCore::VisiblePosition startPosition, WebCore::VisiblePosition endPosition);
    203     void cancelAllSpellCheckingRequests();
    204202    WebCore::SpellChecker* getSpellChecker();
    205203    bool shouldSpellCheckElement(const WebCore::Element*) const;
     
    222220    bool m_delayKeyboardVisibilityChange;
    223221
    224     std::map<int32_t, int32_t> m_sequenceMap;
    225     pthread_mutex_t m_sequenceMapMutex;
     222    RefPtr<WebCore::TextCheckingRequest> m_request;
     223    int32_t m_processingTransactionId;
    226224};
    227225
Note: See TracChangeset for help on using the changeset viewer.