⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 126883 in webkit


Ignore:
Timestamp:
Aug 28, 2012, 8:46:22 AM (14 years ago)
Author:
commit-queue@webkit.org
Message:

[BlackBerry] Range boundaries should use endOfBlock instead of endOfLine.
https://bugs.webkit.org/show_bug.cgi?id=95135

The original implementation used nextLinePosition to iterate
through the field from the start of each line, and was bounded in
comparison to the endOfLine. This works fine as long as there aren't any
empty lines between paragraphs of text, since these will have
startOfLine == endOfLine and break out.

Also, protect map access with a mutex in case we get a response
before updating the map. Further, we should check the Range pointer
before using it, since its not guaranteed to be valid.

Internally reviewed by Mike Fenton.

Patch by Nima Ghanavatian <nghanavatian@rim.com> on 2012-08-28
Reviewed by Antonio Gomes.

  • WebKitSupport/InputHandler.cpp:

(BlackBerry::WebKit::InputHandler::spellCheckBlock):

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

Legend:

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

    r126878 r126883  
     12012-08-28  Nima Ghanavatian  <nghanavatian@rim.com>
     2
     3        [BlackBerry] Range boundaries should use endOfBlock instead of endOfLine.
     4        https://bugs.webkit.org/show_bug.cgi?id=95135
     5
     6        The original implementation used nextLinePosition to iterate
     7        through the field from the start of each line, and was bounded in
     8        comparison to the endOfLine. This works fine as long as there aren't any
     9        empty lines between paragraphs of text, since these will have
     10        startOfLine == endOfLine and break out.
     11
     12        Also, protect map access with a mutex in case we get a response
     13        before updating the map. Further, we should check the Range pointer
     14        before using it, since its not guaranteed to be valid.
     15
     16        Internally reviewed by Mike Fenton.
     17
     18        Reviewed by Antonio Gomes.
     19
     20        * WebKitSupport/InputHandler.cpp:
     21        (BlackBerry::WebKit::InputHandler::spellCheckBlock):
     22
    1232012-08-28  Andrew Lo  <anlo@rim.com>
    224
  • trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp

    r125808 r126883  
    136136    , m_delayKeyboardVisibilityChange(false)
    137137{
     138    pthread_mutex_init(&m_sequenceMapMutex, 0);
    138139}
    139140
     
    582583    }
    583584
     585    BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex);
    584586    int32_t transactionId = m_webPage->m_client->checkSpellingOfStringAsync(checkingString, paragraphLength);
    585587    free(checkingString);
     
    599601int32_t InputHandler::convertTransactionIdToSequenceId(int32_t transactionId)
    600602{
     603    BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex);
    601604    std::map<int32_t, int32_t>::iterator it = m_sequenceMap.find(transactionId);
    602605
     
    661664void InputHandler::cancelAllSpellCheckingRequests()
    662665{
     666    BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex);
    663667    for (std::map<int32_t, int32_t>::iterator it = m_sequenceMap.begin(); it != m_sequenceMap.end(); ++it)
    664668        spellCheckingRequestCancelled(it->second, true /* isSequenceId */);
     
    673677    int32_t sequenceId = isSequenceId ? id : convertTransactionIdToSequenceId(id);
    674678    SpellChecker* spellChecker = getSpellChecker();
    675     if (!spellChecker) {
     679    if (!spellChecker || !sequenceId) {
    676680        SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestCancelled failed to cancel the request with sequenceId %d", sequenceId);
    677681        return;
     
    857861        return;
    858862
     863    RefPtr<Range> rangeForSpellChecking = visibleSelection.toNormalizedRange();
     864    if (!rangeForSpellChecking || !rangeForSpellChecking->text() || !rangeForSpellChecking->text().length())
     865        return;
     866
    859867    SpellChecker* spellChecker = getSpellChecker();
    860868    if (!spellChecker) {
     
    862870        return;
    863871    }
    864 
    865     RefPtr<Range> rangeForSpellChecking = visibleSelection.toNormalizedRange();
    866872
    867873    // If we have a batch request, try to send off the entire block.
     
    877883    VisiblePosition startPos = visibleSelection.visibleStart();
    878884    VisiblePosition startOfCurrentLine = startOfLine(startPos);
    879     VisiblePosition endOfCurrentLine = endOfLine(startPos);
    880 
    881     while (startOfCurrentLine != endOfCurrentLine) {
     885    VisiblePosition endOfCurrentLine = endOfLine(startOfCurrentLine);
     886
     887    while (!isEndOfBlock(startOfCurrentLine)) {
    882888        // Create a selection with the start and end points of the line, and convert to Range to create a SpellCheckRequest.
    883889        rangeForSpellChecking = VisibleSelection(startOfCurrentLine, endOfCurrentLine).toNormalizedRange();
    884890
    885         if (rangeForSpellChecking->text().length() >= MaxSpellCheckingStringLength) {
     891        if (rangeForSpellChecking->text().length() < MaxSpellCheckingStringLength) {
     892            startOfCurrentLine = nextLinePosition(startOfCurrentLine, startOfCurrentLine.lineDirectionPointForBlockDirectionNavigation());
     893            endOfCurrentLine = endOfLine(startOfCurrentLine);
     894        } else {
    886895            // Iterate through words from the start of the line to the end.
    887896            rangeForSpellChecking = getRangeForSpellCheckWithFineGranularity(startOfCurrentLine, endOfCurrentLine);
     
    891900            }
    892901            startOfCurrentLine = VisiblePosition(rangeForSpellChecking->endPosition());
    893         } else {
    894             startOfCurrentLine = nextLinePosition(startOfCurrentLine, startOfCurrentLine.lineDirectionPointForBlockDirectionNavigation());
    895             endOfCurrentLine = endOfLine(startOfCurrentLine);
    896             // If we are at the last line, nextLinePosition will return the position at the end of the line. If we're not at the end, wrap with a call to startOfLine to be safe.
    897             if (startOfCurrentLine != endOfCurrentLine)
    898                 startOfCurrentLine = startOfLine(startOfCurrentLine);
    899902        }
    900903
  • trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h

    r125598 r126883  
    2727#include <imf/input_data.h>
    2828#include <map>
     29#include <pthread.h>
    2930#include <wtf/RefPtr.h>
    3031
     
    218219
    219220    std::map<int32_t, int32_t> m_sequenceMap;
     221    pthread_mutex_t m_sequenceMapMutex;
    220222};
    221223
Note: See TracChangeset for help on using the changeset viewer.