Changeset 140562 in webkit


Ignore:
Timestamp:
Jan 23, 2013 11:48:17 AM (11 years ago)
Author:
nghanavatian@rim.com
Message:

[BlackBerry] Optimize spellchecking by coalescing messages
https://bugs.webkit.org/show_bug.cgi?id=107707

Reviewed by Rob Buis.

PR233604
Instead of taking chunks one line at a time, coalesce them together
to fire off messages as close to our character limit as possible.
This should dramatically reduce the total number of messages in email
giving us a little performance bump.

Internally reviewed by Mike Fenton and Gen Mak.

  • WebKitSupport/DOMSupport.cpp:

(BlackBerry::WebKit::DOMSupport::trimWhitespaceFromRange):
(DOMSupport):

  • WebKitSupport/DOMSupport.h:
  • WebKitSupport/InputHandler.cpp:
  • WebKitSupport/InputHandler.h:

(InputHandler):

  • WebKitSupport/SpellingHandler.cpp:

(BlackBerry::WebKit::SpellingHandler::spellCheckTextBlock):
(BlackBerry::WebKit::SpellingHandler::createSpellCheckRequest):
(BlackBerry::WebKit::SpellingHandler::parseBlockForSpellChecking):
(BlackBerry::WebKit::SpellingHandler::getRangeForSpellCheckWithFineGranularity):

  • WebKitSupport/SpellingHandler.h:
Location:
trunk/Source/WebKit/blackberry
Files:
7 edited

Legend:

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

    r140541 r140562  
     12013-01-23  Nima Ghanavatian  <nghanavatian@rim.com>
     2
     3        [BlackBerry] Optimize spellchecking by coalescing messages
     4        https://bugs.webkit.org/show_bug.cgi?id=107707
     5
     6        Reviewed by Rob Buis.
     7
     8        PR233604
     9        Instead of taking chunks one line at a time, coalesce them together
     10        to fire off messages as close to our character limit as possible.
     11        This should dramatically reduce the total number of messages in email
     12        giving us a little performance bump.
     13
     14        Internally reviewed by Mike Fenton and Gen Mak.
     15
     16        * WebKitSupport/DOMSupport.cpp:
     17        (BlackBerry::WebKit::DOMSupport::trimWhitespaceFromRange):
     18        (DOMSupport):
     19        * WebKitSupport/DOMSupport.h:
     20        * WebKitSupport/InputHandler.cpp:
     21        * WebKitSupport/InputHandler.h:
     22        (InputHandler):
     23        * WebKitSupport/SpellingHandler.cpp:
     24        (BlackBerry::WebKit::SpellingHandler::spellCheckTextBlock):
     25        (BlackBerry::WebKit::SpellingHandler::createSpellCheckRequest):
     26        (BlackBerry::WebKit::SpellingHandler::parseBlockForSpellChecking):
     27        (BlackBerry::WebKit::SpellingHandler::getRangeForSpellCheckWithFineGranularity):
     28        * WebKitSupport/SpellingHandler.h:
     29
    1302013-01-23  Shinya Kawanaka  <shinyak@chromium.org>
    231
  • trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.cpp

    r140161 r140562  
    517517}
    518518
     519PassRefPtr<Range> trimWhitespaceFromRange(PassRefPtr<Range> range)
     520{
     521    return trimWhitespaceFromRange(VisiblePosition(range->startPosition()), VisiblePosition(range->endPosition()));
     522}
     523
    519524PassRefPtr<Range> trimWhitespaceFromRange(VisiblePosition startPosition, VisiblePosition endPosition)
    520525{
  • trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.h

    r140161 r140562  
    9494WebCore::Frame* incrementFrame(WebCore::Frame* curr, bool forward, bool wrapFlag);
    9595
     96PassRefPtr<WebCore::Range> trimWhitespaceFromRange(PassRefPtr<WebCore::Range>);
    9697PassRefPtr<WebCore::Range> trimWhitespaceFromRange(WebCore::VisiblePosition startPosition, WebCore::VisiblePosition endPosition);
    9798bool isEmptyRangeOrAllSpaces(WebCore::VisiblePosition, WebCore::VisiblePosition);
  • trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp

    r140170 r140562  
    7171#include <BlackBerryPlatformKeyboardEvent.h>
    7272#include <BlackBerryPlatformLog.h>
    73 #include <BlackBerryPlatformMisc.h>
    7473#include <BlackBerryPlatformScreen.h>
    7574#include <BlackBerryPlatformSettings.h>
  • trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h

    r140170 r140562  
    2424
    2525#include <BlackBerryPlatformInputEvents.h>
     26#include <BlackBerryPlatformMisc.h>
    2627#include <BlackBerryPlatformSettings.h>
    2728
     
    241242    SpellingHandler* m_spellingHandler;
    242243
     244    DISABLE_COPY(InputHandler);
    243245};
    244246
  • trunk/Source/WebKit/blackberry/WebKitSupport/SpellingHandler.cpp

    r140349 r140562  
    1010#include "Range.h"
    1111#include "SpellChecker.h"
    12 #include "TextIterator.h"
    1312#include "visible_units.h"
    1413
     
    4544void SpellingHandler::spellCheckTextBlock(WebCore::VisibleSelection& visibleSelection, WebCore::TextCheckingProcessType textCheckingProcessType)
    4645{
     46    SpellingLog(Platform::LogLevelInfo, "SpellingHandler::spellCheckTextBlock");
     47
    4748    // Check if this request can be sent off in one message, or if it needs to be broken down.
    4849    RefPtr<Range> rangeForSpellChecking = visibleSelection.toNormalizedRange();
     
    8081{
    8182    RefPtr<WebCore::Range> rangeForSpellChecking = rangeForSpellCheckingPtr;
    82     if (isSpellCheckActive() && rangeForSpellChecking->text().length() >= MinSpellCheckingStringLength)
     83    rangeForSpellChecking = DOMSupport::trimWhitespaceFromRange(rangeForSpellChecking);
     84
     85    SpellingLog(Platform::LogLevelInfo, "SpellingHandler::createSpellCheckRequest Substring text is '%s', of size %d"
     86        , rangeForSpellChecking->text().latin1().data()
     87        , rangeForSpellChecking->text().length());
     88
     89    if (rangeForSpellChecking->text().length() >= MinSpellCheckingStringLength)
    8390        m_inputHandler->callRequestCheckingFor(SpellCheckRequest::create(TextCheckingTypeSpelling, textCheckingProcessType, rangeForSpellChecking, rangeForSpellChecking));
    8491}
     
    8693void SpellingHandler::parseBlockForSpellChecking(WebCore::Timer<SpellingHandler>*)
    8794{
    88     if (isEndOfDocument(m_startOfCurrentLine)) {
    89         m_isSpellCheckActive = false;
    90         return;
    91     }
    92 
    9395    // Create a selection with the start and end points of the line, and convert to Range to create a SpellCheckRequest.
    94     RefPtr<Range> rangeForSpellChecking = VisibleSelection(m_startOfCurrentLine, m_endOfCurrentLine).toNormalizedRange();
     96    RefPtr<Range> rangeForSpellChecking = makeRange(m_startOfCurrentLine, m_endOfCurrentLine);
    9597    if (!rangeForSpellChecking) {
    96         SpellingLog(Platform::LogLevelInfo, "SpellingHandler::spellCheckBlock Failed to set text range for spellchecking.");
     98        SpellingLog(Platform::LogLevelInfo, "SpellingHandler::parseBlockForSpellChecking Failed to set text range for spellchecking.");
    9799        return;
    98100    }
    99101
    100102    if (rangeForSpellChecking->text().length() < MaxSpellCheckingStringLength) {
    101         m_startOfCurrentLine = nextLinePosition(m_startOfCurrentLine, m_startOfCurrentLine.lineDirectionPointForBlockDirectionNavigation());
    102         m_endOfCurrentLine = endOfLine(m_startOfCurrentLine);
    103     } else {
    104         // Iterate through words from the start of the line to the end.
    105         rangeForSpellChecking = getRangeForSpellCheckWithFineGranularity(m_startOfCurrentLine, m_endOfCurrentLine);
    106         if (!rangeForSpellChecking) {
    107             SpellingLog(Platform::LogLevelWarn, "SpellingHandler::spellCheckBlock Failed to set text range with fine granularity.");
     103        if (isEndOfDocument(m_endOfCurrentLine)) {
     104            createSpellCheckRequest(rangeForSpellChecking, m_textCheckingProcessType);
     105            m_isSpellCheckActive = false;
    108106            return;
    109107        }
    110         m_startOfCurrentLine = VisiblePosition(rangeForSpellChecking->endPosition());
    111         m_endOfCurrentLine = endOfLine(m_startOfCurrentLine);
    112         rangeForSpellChecking = DOMSupport::trimWhitespaceFromRange(VisiblePosition(rangeForSpellChecking->startPosition()), VisiblePosition(rangeForSpellChecking->endPosition()));
     108        m_endOfCurrentLine = endOfLine(nextLinePosition(m_endOfCurrentLine, m_endOfCurrentLine.lineDirectionPointForBlockDirectionNavigation()));
     109        m_timer.startOneShot(s_timeout);
     110        return;
    113111    }
    114112
    115     SpellingLog(Platform::LogLevelInfo,
    116         "SpellingHandler::spellCheckBlock Substring text is '%s', of size %d",
    117         rangeForSpellChecking->text().latin1().data(),
    118         rangeForSpellChecking->text().length());
     113    // Iterate through words from the start of the line to the end.
     114    rangeForSpellChecking = getRangeForSpellCheckWithFineGranularity(m_startOfCurrentLine, m_endOfCurrentLine);
     115
     116    m_startOfCurrentLine = VisiblePosition(rangeForSpellChecking->endPosition());
     117    m_endOfCurrentLine = endOfLine(m_startOfCurrentLine);
    119118
    120119    // Call spellcheck with substring.
     
    126125PassRefPtr<Range> SpellingHandler::getRangeForSpellCheckWithFineGranularity(WebCore::VisiblePosition startPosition, WebCore::VisiblePosition endPosition)
    127126{
     127    SpellingLog(Platform::LogLevelWarn, "SpellingHandler::getRangeForSpellCheckWithFineGranularity");
     128    ASSERT(makeRange(startPosition, endOfCurrentWord));
    128129    VisiblePosition endOfCurrentWord = endOfWord(startPosition);
    129130
     
    131132    while (startPosition != endPosition) {
    132133        // Check the text length within this range.
    133         if (VisibleSelection(startPosition, endOfCurrentWord).toNormalizedRange()->text().length() >= MaxSpellCheckingStringLength) {
     134        if (makeRange(startPosition, endOfCurrentWord)->text().length() >= MaxSpellCheckingStringLength) {
    134135            // If this is not the first word, return a Range with end boundary set to the previous word.
    135             if (startOfWord(endOfCurrentWord, LeftWordIfOnBoundary) != startPosition && !DOMSupport::isEmptyRangeOrAllSpaces(startPosition, endOfCurrentWord))
    136                 return VisibleSelection(startPosition, endOfWord(previousWordPosition(endOfCurrentWord), LeftWordIfOnBoundary)).toNormalizedRange();
    137 
     136            if (startOfWord(endOfCurrentWord, LeftWordIfOnBoundary) != startPosition && !DOMSupport::isEmptyRangeOrAllSpaces(startPosition, endOfCurrentWord)) {
     137                // When a series of whitespace follows a word, previousWordPosition will jump passed all of them, and using LeftWordIfOnBoundary brings us to
     138                // our starting position. Check for this case and use RightWordIfOnBoundary to jump back over the word.
     139                VisiblePosition endOfPreviousWord = endOfWord(previousWordPosition(endOfCurrentWord), LeftWordIfOnBoundary);
     140                if (startPosition == endOfPreviousWord)
     141                    return makeRange(startPosition, endOfWord(previousWordPosition(endOfCurrentWord), RightWordIfOnBoundary));
     142                return makeRange(startPosition, endOfPreviousWord);
     143            }
    138144            // Our first word has gone over the character limit. Increment the starting position past an uncheckable word.
    139145            startPosition = endOfCurrentWord;
    140146            endOfCurrentWord = endOfWord(nextWordPosition(endOfCurrentWord));
    141147        } else if (endOfCurrentWord == endPosition)
    142             return VisibleSelection(startPosition, endPosition).toNormalizedRange(); // Return the last segment if the end of our word lies at the end of the range.
     148            return makeRange(startPosition, endPosition); // Return the last segment if the end of our word lies at the end of the range.
    143149        else
    144150            endOfCurrentWord = endOfWord(nextWordPosition(endOfCurrentWord)); // Increment the current word.
    145151    }
    146     return 0;
     152    // This will return an range with no string, but allows processing to continue
     153    return makeRange(startPosition, endPosition);
    147154}
    148155
  • trunk/Source/WebKit/blackberry/WebKitSupport/SpellingHandler.h

    r140170 r140562  
    1919namespace WebCore {
    2020class Range;
    21 class SpellChecker;
    22 class VisibleSelection;
    23 class VisiblePosition;
    2421}
    2522
Note: See TracChangeset for help on using the changeset viewer.