Changeset 162184 in webkit


Ignore:
Timestamp:
Jan 16, 2014 10:22:46 PM (10 years ago)
Author:
weinig@apple.com
Message:

TextBreakIterator's should support Latin-1 for all iterator types (Part 3)
https://bugs.webkit.org/show_bug.cgi?id=126856

Reviewed by Ryosuke Niwa.

Change all the TextBreakIterator creation functions to take StringViews. Remove a few
now unnecessary up-conversions to UTF-16 in the process.

../WebCore:

  • dom/CharacterData.cpp:
  • editing/TextCheckingHelper.cpp:
  • editing/VisibleUnits.cpp:
  • platform/graphics/StringTruncator.cpp:
  • platform/graphics/mac/ComplexTextController.cpp:
  • platform/text/TextBoundaries.cpp:
  • platform/text/TextBreakIterator.cpp:
  • platform/text/TextBreakIterator.h:
  • rendering/RenderText.cpp:

../WebKit/ios:

  • Misc/WebNSStringDrawing.mm:

../WebKit2:

  • UIProcess/efl/TextCheckerEfl.cpp:

(WebKit::nextWordOffset):
(WebKit::TextChecker::checkTextOfParagraph):

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r162180 r162184  
     12014-01-15  Sam Weinig  <sam@webkit.org>
     2
     3        TextBreakIterator's should support Latin-1 for all iterator types (Part 3)
     4        https://bugs.webkit.org/show_bug.cgi?id=126856
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Change all the TextBreakIterator creation functions to take StringViews. Remove a few
     9        now unnecessary up-conversions to UTF-16 in the process.
     10
     11        * dom/CharacterData.cpp:
     12        * editing/TextCheckingHelper.cpp:
     13        * editing/VisibleUnits.cpp:
     14        * platform/graphics/StringTruncator.cpp:
     15        * platform/graphics/mac/ComplexTextController.cpp:
     16        * platform/text/TextBoundaries.cpp:
     17        * platform/text/TextBreakIterator.cpp:
     18        * platform/text/TextBreakIterator.h:
     19        * rendering/RenderText.cpp:
     20
    1212014-01-16  Anders Carlsson  <andersca@apple.com>
    222
  • trunk/Source/WebCore/dom/CharacterData.cpp

    r161851 r162184  
    7575    // We need at least two characters look-ahead to account for UTF-16 surrogates.
    7676    if (characterLengthLimit < characterLength) {
    77         NonSharedCharacterBreakIterator it(string.deprecatedCharacters() + offset, (characterLengthLimit + 2 > characterLength) ? characterLength : characterLengthLimit + 2);
     77        NonSharedCharacterBreakIterator it(StringView(string).substring(offset, (characterLengthLimit + 2 > characterLength) ? characterLength : characterLengthLimit + 2));
    7878        if (!isTextBreak(it, characterLengthLimit))
    7979            characterLengthLimit = textBreakPreceding(it, characterLengthLimit);
  • trunk/Source/WebCore/editing/TextCheckingHelper.cpp

    r161851 r162184  
    7171#endif
    7272
    73 static void findMisspellings(TextCheckerClient* client, const UChar* text, int start, int length, Vector<TextCheckingResult>& results)
    74 {
    75     TextBreakIterator* iterator = wordBreakIterator(text + start, length);
     73static void findMisspellings(TextCheckerClient* client, const UChar* text, int length, Vector<TextCheckingResult>& results)
     74{
     75    TextBreakIterator* iterator = wordBreakIterator(StringView(text, length));
    7676    if (!iterator)
    7777        return;
     
    8484        int misspellingLocation = -1;
    8585        int misspellingLength = 0;
    86         client->checkSpellingOfString(text + start + wordStart, wordLength, &misspellingLocation, &misspellingLength);
     86        client->checkSpellingOfString(text + wordStart, wordLength, &misspellingLocation, &misspellingLength);
    8787        if (0 < misspellingLength) {
    8888            ASSERT(0 <= misspellingLocation && misspellingLocation <= wordLength);
     
    9090            TextCheckingResult misspelling;
    9191            misspelling.type = TextCheckingTypeSpelling;
    92             misspelling.location = start + wordStart + misspellingLocation;
     92            misspelling.location = wordStart + misspellingLocation;
    9393            misspelling.length = misspellingLength;
    9494            misspelling.replacement = client->getAutoCorrectSuggestionForMisspelledWord(String(text + misspelling.location, misspelling.length));
     
    649649    Vector<TextCheckingResult> spellingResult;
    650650    if (checkingTypes & TextCheckingTypeSpelling)
    651         findMisspellings(client, text, 0, length, spellingResult);
     651        findMisspellings(client, text, length, spellingResult);
    652652
    653653#if USE(GRAMMAR_CHECKING)
  • trunk/Source/WebCore/editing/VisibleUnits.cpp

    r161861 r162184  
    302302    len += textBox->len();
    303303
    304     return wordBreakIterator(string.data(), len);
    305 } 
     304    return wordBreakIterator(StringView(string.data(), len));
     305}
    306306
    307307static TextBreakIterator* wordBreakIteratorForMaxOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox,
     
    323323    }
    324324
    325     return wordBreakIterator(string.data(), len);
    326 } 
     325    return wordBreakIterator(StringView(string.data(), len));
     326}
    327327
    328328static bool isLogicalStartOfWord(TextBreakIterator* iter, int position, bool hardLineBreak)
     
    386386            iter = wordBreakIteratorForMaxOffsetBoundary(visiblePosition, textBox, nextBoxInDifferentBlock, string, leafBoxes);
    387387        else if (movingIntoNewBox) {
    388             iter = wordBreakIterator(textBox->renderer().text()->deprecatedCharacters() + textBox->start(), textBox->len());
     388            iter = wordBreakIterator(StringView(textBox->renderer().text()).substring(textBox->start(), textBox->len()));
    389389            previouslyVisitedBox = box;
    390390        }
     
    10471047static unsigned startSentenceBoundary(const UChar* characters, unsigned length, unsigned, BoundarySearchContextAvailability, bool&)
    10481048{
    1049     TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
     1049    TextBreakIterator* iterator = sentenceBreakIterator(StringView(characters, length));
    10501050    // FIXME: The following function can return -1; we don't handle that.
    10511051    return textBreakPreceding(iterator, length);
     
    10591059static unsigned endSentenceBoundary(const UChar* characters, unsigned length, unsigned, BoundarySearchContextAvailability, bool&)
    10601060{
    1061     TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
     1061    TextBreakIterator* iterator = sentenceBreakIterator(StringView(characters, length));
    10621062    return textBreakNext(iterator);
    10631063}
     
    10721072{
    10731073    // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's not right.
    1074     TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
     1074    TextBreakIterator* iterator = sentenceBreakIterator(StringView(characters, length));
    10751075    // FIXME: The following function can return -1; we don't handle that.
    10761076    return textBreakPreceding(iterator, length);
     
    10871087    // FIXME: This is identical to endSentenceBoundary. This isn't right, it needs to
    10881088    // move to the equivlant position in the following sentence.
    1089     TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
     1089    TextBreakIterator* iterator = sentenceBreakIterator(StringView(characters, length));
    10901090    return textBreakFollowing(iterator, 0);
    10911091}
  • trunk/Source/WebCore/platform/graphics/StringTruncator.cpp

    r161851 r162184  
    6464   
    6565    unsigned omitStart = (keepCount + 1) / 2;
    66     NonSharedCharacterBreakIterator it(string.deprecatedCharacters(), length);
     66    NonSharedCharacterBreakIterator it(StringView(string).substring(0, length));
    6767    unsigned omitEnd = boundedTextBreakFollowing(it, omitStart + (length - keepCount) - 1, length);
    6868    omitStart = textBreakAtOrPreceding(it, omitStart);
     
    116116#endif
    117117
    118     NonSharedCharacterBreakIterator it(string.deprecatedCharacters(), length);
     118    NonSharedCharacterBreakIterator it(StringView(string).substring(0, length));
    119119    unsigned keepLength = textBreakAtOrPreceding(it, keepCount);
    120120    unsigned truncatedLength = shouldInsertEllipsis ? keepLength + 1 : keepLength;
     
    132132    ASSERT(keepCount < STRING_BUFFER_SIZE);
    133133
    134     NonSharedCharacterBreakIterator it(string.deprecatedCharacters(), length);
     134    NonSharedCharacterBreakIterator it(StringView(string).substring(0, length));
    135135    unsigned keepLength = textBreakAtOrPreceding(it, keepCount);
    136136    memcpy(buffer, string.deprecatedCharacters(), sizeof(UChar) * keepLength);
     
    144144    ASSERT(keepCount < STRING_BUFFER_SIZE);
    145145
    146     TextBreakIterator* it = wordBreakIterator(string.deprecatedCharacters(), length);
     146    TextBreakIterator* it = wordBreakIterator(StringView(string).substring(0, length));
    147147    unsigned keepLength = textBreakAtOrPreceding(it, keepCount);
    148148    memcpy(buffer, string.deprecatedCharacters(), sizeof(UChar) * keepLength);
     
    164164    unsigned startIndex = length - keepCount;
    165165
    166     NonSharedCharacterBreakIterator it(string.deprecatedCharacters(), length);
     166    NonSharedCharacterBreakIterator it(string);
    167167    unsigned adjustedStartIndex = startIndex;
    168168    startIndex = boundedTextBreakFollowing(it, startIndex, length - startIndex);
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp

    r161589 r162184  
    210210                CFIndex hitIndex = hitGlyphStart + (hitGlyphEnd - hitGlyphStart) * (m_run.ltr() ? x / adjustedAdvance : 1 - x / adjustedAdvance);
    211211                int stringLength = complexTextRun.stringLength();
    212                 TextBreakIterator* cursorPositionIterator = cursorMovementIterator(complexTextRun.characters(), stringLength);
     212                TextBreakIterator* cursorPositionIterator = cursorMovementIterator(StringView(complexTextRun.characters(), stringLength));
    213213                int clusterStart;
    214214                if (isTextBreak(cursorPositionIterator, hitIndex))
  • trunk/Source/WebCore/platform/text/TextBoundaries.cpp

    r160526 r162184  
    6262int findNextWordFromIndex(const UChar* chars, int len, int position, bool forward)
    6363{
    64     TextBreakIterator* it = wordBreakIterator(chars, len);
     64    TextBreakIterator* it = wordBreakIterator(StringView(chars, len));
    6565
    6666    if (forward) {
     
    9191void findWordBoundary(const UChar* chars, int len, int position, int* start, int* end)
    9292{
    93     TextBreakIterator* it = wordBreakIterator(chars, len);
     93    TextBreakIterator* it = wordBreakIterator(StringView(chars, len));
    9494    *end = textBreakFollowing(it, position);
    9595    if (*end < 0)
     
    100100void findEndWordBoundary(const UChar* chars, int len, int position, int* end)
    101101{
    102     TextBreakIterator* it = wordBreakIterator(chars, len);
     102    TextBreakIterator* it = wordBreakIterator(StringView(chars, len));
    103103    *end = textBreakFollowing(it, position);
    104104    if (*end < 0)
  • trunk/Source/WebCore/platform/text/TextBreakIterator.cpp

    r162109 r162184  
    139139// Static iterators
    140140
    141 TextBreakIterator* wordBreakIterator(const UChar* buffer, int length)
     141TextBreakIterator* wordBreakIterator(StringView string)
    142142{
    143143    static TextBreakIterator* staticWordBreakIterator = initializeIterator(UBRK_WORD);
     
    145145        return nullptr;
    146146
    147     return setTextForIterator(*staticWordBreakIterator, StringView(buffer, length));
    148 }
    149 
    150 TextBreakIterator* sentenceBreakIterator(const UChar* buffer, int length)
     147    return setTextForIterator(*staticWordBreakIterator, string);
     148}
     149
     150TextBreakIterator* sentenceBreakIterator(StringView string)
    151151{
    152152    static TextBreakIterator* staticSentenceBreakIterator = initializeIterator(UBRK_SENTENCE);
     
    154154        return nullptr;
    155155
    156     return setTextForIterator(*staticSentenceBreakIterator, StringView(buffer, length));
    157 }
    158 
    159 TextBreakIterator* cursorMovementIterator(const UChar* buffer, int length)
     156    return setTextForIterator(*staticSentenceBreakIterator, string);
     157}
     158
     159TextBreakIterator* cursorMovementIterator(StringView string)
    160160{
    161161#if !PLATFORM(IOS)
     
    251251        return nullptr;
    252252
    253     return setTextForIterator(*staticCursorMovementIterator, StringView(buffer, length));
     253    return setTextForIterator(*staticCursorMovementIterator, string);
    254254}
    255255
     
    286286}
    287287
    288 NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(const UChar* buffer, int length)
     288NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(StringView string)
    289289{
    290290    m_iterator = nonSharedCharacterBreakIterator;
     
    296296        return;
    297297
    298     m_iterator = setTextForIterator(*m_iterator, StringView(buffer, length));
     298    m_iterator = setTextForIterator(*m_iterator, string);
    299299}
    300300
     
    365365        return stringLength;
    366366
    367     NonSharedCharacterBreakIterator it(s.deprecatedCharacters(), stringLength);
     367    NonSharedCharacterBreakIterator it(s);
    368368    if (!it)
    369369        return stringLength;
     
    386386        return std::min(stringLength, numGraphemeClusters);
    387387
    388     NonSharedCharacterBreakIterator it(s.deprecatedCharacters(), stringLength);
     388    NonSharedCharacterBreakIterator it(s);
    389389    if (!it)
    390390        return std::min(stringLength, numGraphemeClusters);
  • trunk/Source/WebCore/platform/text/TextBreakIterator.h

    r161844 r162184  
    3737// from character break iterator is Thai prepend characters, see bug 24342.
    3838// Use this for insertion point and selection manipulations.
    39 TextBreakIterator* cursorMovementIterator(const UChar*, int length);
     39TextBreakIterator* cursorMovementIterator(StringView);
    4040
    41 TextBreakIterator* wordBreakIterator(const UChar*, int length);
    42 TextBreakIterator* sentenceBreakIterator(const UChar*, int length);
     41TextBreakIterator* wordBreakIterator(StringView);
     42TextBreakIterator* sentenceBreakIterator(StringView);
    4343
    4444TextBreakIterator* acquireLineBreakIterator(StringView, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
     
    170170    WTF_MAKE_NONCOPYABLE(NonSharedCharacterBreakIterator);
    171171public:
    172     NonSharedCharacterBreakIterator(const UChar*, int length);
     172    NonSharedCharacterBreakIterator(StringView);
    173173    ~NonSharedCharacterBreakIterator();
    174174
  • trunk/Source/WebCore/platform/text/enchant/TextCheckerEnchant.cpp

    r151316 r162184  
    9292        return;
    9393
    94     TextBreakIterator* iter = wordBreakIterator(string.characters(), string.length());
     94    TextBreakIterator* iter = wordBreakIterator(string);
    9595    if (!iter)
    9696        return;
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r161851 r162184  
    135135    }
    136136
    137     TextBreakIterator* boundary = wordBreakIterator(stringWithPrevious.characters(), length + 1);
     137    TextBreakIterator* boundary = wordBreakIterator(StringView(stringWithPrevious.characters(), length + 1));
    138138    if (!boundary)
    139139        return;
     
    13411341
    13421342    StringImpl* textImpl = m_text.impl();
    1343     TextBreakIterator* iterator = cursorMovementIterator(textImpl->characters16(), textImpl->length());
     1343    TextBreakIterator* iterator = cursorMovementIterator(StringView(textImpl->characters16(), textImpl->length()));
    13441344    if (!iterator)
    13451345        return current - 1;
     
    14941494
    14951495    StringImpl* textImpl = m_text.impl();
    1496     TextBreakIterator* iterator = cursorMovementIterator(textImpl->characters16(), textImpl->length());
     1496    TextBreakIterator* iterator = cursorMovementIterator(StringView(textImpl->characters16(), textImpl->length()));
    14971497    if (!iterator)
    14981498        return current + 1;
  • trunk/Source/WebKit/ios/ChangeLog

    r162158 r162184  
     12014-01-15  Sam Weinig  <sam@webkit.org>
     2
     3        TextBreakIterator's should support Latin-1 for all iterator types (Part 3)
     4        https://bugs.webkit.org/show_bug.cgi?id=126856
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Change all the TextBreakIterator creation functions to take StringViews. Remove a few
     9        now unnecessary up-conversions to UTF-16 in the process.
     10
     11        * Misc/WebNSStringDrawing.mm:
     12
    1132014-01-16  Anders Carlsson  <andersca@apple.com>
    214
  • trunk/Source/WebKit/ios/Misc/WebNSStringDrawing.mm

    r160106 r162184  
    457457                            // We can break on characters. We should do something smarter, like split the length of the entire line
    458458                            // Don't, however, break in the middle of a character.
    459                             NonSharedCharacterBreakIterator it(pos, lengthRemaining);
     459                            NonSharedCharacterBreakIterator it(StringView(pos, lengthRemaining));
    460460                            breakPos = boundedTextBreakFollowing(it, 0, lengthRemaining);
    461461                        }                       
     
    538538                    // Fit it on a line one character at a time and break when no more characters fit
    539539                    // Force at least one character to avoid the edge case where a single glyph doesn't fit within width
    540                     NonSharedCharacterBreakIterator it(pos, lengthRemaining);
     540                    NonSharedCharacterBreakIterator it(StringView(pos, lengthRemaining));
    541541                    int offset = 0;
    542542                    int nextCharBreak = boundedTextBreakFollowing(it, offset, lengthRemaining);
  • trunk/Source/WebKit2/ChangeLog

    r162182 r162184  
     12014-01-15  Sam Weinig  <sam@webkit.org>
     2
     3        TextBreakIterator's should support Latin-1 for all iterator types (Part 3)
     4        https://bugs.webkit.org/show_bug.cgi?id=126856
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Change all the TextBreakIterator creation functions to take StringViews. Remove a few
     9        now unnecessary up-conversions to UTF-16 in the process.
     10
     11        * UIProcess/efl/TextCheckerEfl.cpp:
     12        (WebKit::nextWordOffset):
     13        (WebKit::TextChecker::checkTextOfParagraph):
     14
    1152014-01-16  Eunmi Lee  <eunmi15.lee@samsung.com>
    216
  • trunk/Source/WebKit2/UIProcess/efl/TextCheckerEfl.cpp

    r151314 r162184  
    128128    //        For many word separators, the method doesn't properly determine the boundaries
    129129    //        without resetting the iterator.
    130     TextBreakIterator* textIterator = wordBreakIterator(text, length);
     130    TextBreakIterator* textIterator = wordBreakIterator(StringView(text, length));
    131131    if (!textIterator)
    132132        return currentOffset;
     
    154154#if ENABLE(SPELLCHECK)
    155155    if (checkingTypes & TextCheckingTypeSpelling) {
    156         TextBreakIterator* textIterator = wordBreakIterator(text, length);
     156        TextBreakIterator* textIterator = wordBreakIterator(StringView(text, length));
    157157        if (!textIterator)
    158158            return paragraphCheckingResult;
Note: See TracChangeset for help on using the changeset viewer.