Changeset 128933 in webkit
- Timestamp:
- Sep 18, 2012 2:38:57 PM (12 years ago)
- Location:
- trunk/Source/WebKit/blackberry
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/blackberry/ChangeLog
r128923 r128933 1 2012-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 1 26 2012-09-18 Jessica Cao <jecao@rim.com> 2 27 -
trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp
r128858 r128933 137 137 , m_pendingKeyboardVisibilityChange(NoChange) 138 138 , m_delayKeyboardVisibilityChange(false) 139 { 140 pthread_mutex_init(&m_sequenceMapMutex, 0); 139 , m_request(0) 140 , m_processingTransactionId(-1) 141 { 141 142 } 142 143 … … 546 547 void InputHandler::requestCheckingOfString(PassRefPtr<WebCore::TextCheckingRequest> textCheckingRequest) 547 548 { 548 RefPtr<WebCore::TextCheckingRequest>request = textCheckingRequest;549 550 i nt32_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(); 556 557 557 558 // 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(); 567 561 return; 568 562 } … … 570 564 if (requestLength > MaxSpellCheckingStringLength) { 571 565 // 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()) { 574 568 // 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 575 569 // enter to finish composing a word and create a new line. … … 584 578 if (!checkingString) { 585 579 logAlways(LogLevelCritical, "InputHandler::requestCheckingOfString Cannot allocate memory for string."); 586 spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */);580 m_request->didCancel(); 587 581 return; 588 582 } 589 583 590 584 int paragraphLength = 0; 591 if (!convertStringToWchar( request->text(), checkingString, requestLength + 1, ¶graphLength)) {585 if (!convertStringToWchar(m_request->text(), checkingString, requestLength + 1, ¶graphLength)) { 592 586 logAlways(LogLevelCritical, "InputHandler::requestCheckingOfString Failed to convert String to wchar type."); 593 587 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); 600 593 free(checkingString); 601 594 … … 603 596 // This should still take transactionId as a parameter to maintain the same behavior as if InputMethodSupport 604 597 // 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 604 void 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; 627 612 } 628 613 629 614 void InputHandler::spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t* spannableString) 630 615 { 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 631 619 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; 633 623 return; 634 624 } … … 649 639 break; 650 640 if (span->end < span->start) { 651 spellCheckingRequestCancelled(transactionId, false /* isSequenceId */);641 m_request->didCancel(); 652 642 return; 653 643 } … … 663 653 } 664 654 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); 697 656 } 698 657 699 658 SpellChecker* InputHandler::getSpellChecker() 700 659 { 701 ASSERT(m_currentFocusElement);702 ASSERT(m_currentFocusElement->document());660 if (!m_currentFocusElement || !m_currentFocusElement->document()) 661 return 0; 703 662 704 663 if (Frame* frame = m_currentFocusElement->document()->frame()) … … 773 732 if (!m_currentFocusElement->document()->frame()->selection()->isFocused()) 774 733 m_currentFocusElement->document()->frame()->selection()->setFocused(true); 775 776 // Cancel any spellcheck requests that might be ongoing.777 cancelAllSpellCheckingRequests();778 734 } 779 735 -
trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h
r128858 r128933 138 138 void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>); 139 139 void spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t*); 140 void spellCheckingRequestCancelled(int32_t id, bool isSequenceId = false);140 void spellCheckingRequestCancelled(int32_t transactionId); 141 141 142 142 bool shouldRequestSpellCheckingOptionsForPoint(Platform::IntPoint&, const WebCore::Element*, imf_sp_text_t&); … … 198 198 void learnText(); 199 199 void sendLearnTextDetails(const WTF::String&); 200 int32_t convertTransactionIdToSequenceId(int32_t transactionId);201 200 void spellCheckBlock(WebCore::VisibleSelection&, WebCore::TextCheckingProcessType); 202 201 PassRefPtr<WebCore::Range> getRangeForSpellCheckWithFineGranularity(WebCore::VisiblePosition startPosition, WebCore::VisiblePosition endPosition); 203 void cancelAllSpellCheckingRequests();204 202 WebCore::SpellChecker* getSpellChecker(); 205 203 bool shouldSpellCheckElement(const WebCore::Element*) const; … … 222 220 bool m_delayKeyboardVisibilityChange; 223 221 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; 226 224 }; 227 225
Note: See TracChangeset
for help on using the changeset viewer.