Changeset 56047 in webkit


Ignore:
Timestamp:
Mar 16, 2010 12:39:28 AM (14 years ago)
Author:
hamaji@chromium.org
Message:

2010-03-16 Shinichiro Hamaji <hamaji@chromium.org>

Reviewed by Darin Adler.

RenderText::m_text should be a String, not RefPtr<StringImpl>
https://bugs.webkit.org/show_bug.cgi?id=36010

Refactoring only, so no new tests.

  • platform/text/PlatformString.h: (WebCore::String::makeLower): (WebCore::String::makeUpper): (WebCore::String::makeSecure): (WebCore::String::makeCapitalized): (WebCore::String::containsOnlyASCII):
  • rendering/RenderText.cpp: (WebCore::RenderText::RenderText): (WebCore::RenderText::widthFromCache): (WebCore::RenderText::trimmedPrefWidths): (WebCore::RenderText::containsOnlyWhitespace): (WebCore::RenderText::setTextInternal): (WebCore::RenderText::setText): (WebCore::RenderText::previousOffset): (WebCore::RenderText::previousOffsetForBackwardDeletion): (WebCore::RenderText::nextOffset):
  • rendering/RenderText.h: (WebCore::RenderText::text): (WebCore::RenderText::characters): (WebCore::RenderText::textLength):
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56046 r56047  
     12010-03-16  Shinichiro Hamaji  <hamaji@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        RenderText::m_text should be a String, not RefPtr<StringImpl>
     6        https://bugs.webkit.org/show_bug.cgi?id=36010
     7
     8        Refactoring only, so no new tests.
     9
     10        * platform/text/PlatformString.h:
     11        (WebCore::String::makeLower):
     12        (WebCore::String::makeUpper):
     13        (WebCore::String::makeSecure):
     14        (WebCore::String::makeCapitalized):
     15        (WebCore::String::containsOnlyASCII):
     16        * rendering/RenderText.cpp:
     17        (WebCore::RenderText::RenderText):
     18        (WebCore::RenderText::widthFromCache):
     19        (WebCore::RenderText::trimmedPrefWidths):
     20        (WebCore::RenderText::containsOnlyWhitespace):
     21        (WebCore::RenderText::setTextInternal):
     22        (WebCore::RenderText::setText):
     23        (WebCore::RenderText::previousOffset):
     24        (WebCore::RenderText::previousOffsetForBackwardDeletion):
     25        (WebCore::RenderText::nextOffset):
     26        * rendering/RenderText.h:
     27        (WebCore::RenderText::text):
     28        (WebCore::RenderText::characters):
     29        (WebCore::RenderText::textLength):
     30
    1312010-03-16  Adam Barth  <abarth@webkit.org>
    232
  • trunk/WebCore/platform/text/PlatformString.h

    r53418 r56047  
    6464struct StringHash;
    6565
     66// Declarations of string operations
     67
     68bool charactersAreAllASCII(const UChar*, size_t);
     69int charactersToIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
     70unsigned charactersToUIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
     71int64_t charactersToInt64Strict(const UChar*, size_t, bool* ok = 0, int base = 10);
     72uint64_t charactersToUInt64Strict(const UChar*, size_t, bool* ok = 0, int base = 10);
     73intptr_t charactersToIntPtrStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
     74
     75int charactersToInt(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
     76unsigned charactersToUInt(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
     77int64_t charactersToInt64(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
     78uint64_t charactersToUInt64(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
     79intptr_t charactersToIntPtr(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
     80
     81double charactersToDouble(const UChar*, size_t, bool* ok = 0);
     82float charactersToFloat(const UChar*, size_t, bool* ok = 0);
     83
     84int find(const UChar*, size_t, UChar, int startPosition = 0);
     85int reverseFind(const UChar*, size_t, UChar, int startPosition = -1);
     86
    6687class String {
    6788public:
     
    133154    String& replace(const String& a, const String& b) { if (m_impl) m_impl = m_impl->replace(a.impl(), b.impl()); return *this; }
    134155    String& replace(unsigned index, unsigned len, const String& b) { if (m_impl) m_impl = m_impl->replace(index, len, b.impl()); return *this; }
     156
     157    void makeLower() { if (m_impl) m_impl = m_impl->lower(); }
     158    void makeUpper() { if (m_impl) m_impl = m_impl->upper(); }
     159    void makeSecure(UChar aChar) { if (m_impl) m_impl = m_impl->secure(aChar); }
     160    void makeCapitalized(UChar previousCharacter) { if (m_impl) m_impl = m_impl->capitalize(previousCharacter); }
    135161
    136162    void truncate(unsigned len);
     
    257283    unsigned numCharactersInGraphemeClusters(unsigned) const;
    258284
     285    bool containsOnlyASCII() const { return charactersAreAllASCII(characters(), length()); }
     286
    259287private:
    260288    RefPtr<StringImpl> m_impl;
     
    295323inline void swap(String& a, String& b) { a.swap(b); }
    296324
    297 // String Operations
    298 
    299 bool charactersAreAllASCII(const UChar*, size_t);
    300 
    301 int charactersToIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
    302 unsigned charactersToUIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
    303 int64_t charactersToInt64Strict(const UChar*, size_t, bool* ok = 0, int base = 10);
    304 uint64_t charactersToUInt64Strict(const UChar*, size_t, bool* ok = 0, int base = 10);
    305 intptr_t charactersToIntPtrStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
    306 
    307 int charactersToInt(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
    308 unsigned charactersToUInt(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
    309 int64_t charactersToInt64(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
    310 uint64_t charactersToUInt64(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
    311 intptr_t charactersToIntPtr(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage
    312 
    313 double charactersToDouble(const UChar*, size_t, bool* ok = 0);
    314 float charactersToFloat(const UChar*, size_t, bool* ok = 0);
    315 
    316 int find(const UChar*, size_t, UChar, int startPosition = 0);
    317 int reverseFind(const UChar*, size_t, UChar, int startPosition = -1);
     325// Definitions of string operations
    318326
    319327#ifdef __OBJC__
  • trunk/WebCore/rendering/RenderText.cpp

    r55928 r56047  
    4949namespace WebCore {
    5050
    51 // FIXME: Move to StringImpl.h eventually.
    52 static inline bool charactersAreAllASCII(StringImpl* text)
    53 {
    54     return charactersAreAllASCII(text->characters(), text->length());
    55 }
    56 
    5751RenderText::RenderText(Node* node, PassRefPtr<StringImpl> str)
    5852     : RenderObject(node)
     
    6761     , m_linesDirty(false)
    6862     , m_containsReversedText(false)
    69      , m_isAllASCII(charactersAreAllASCII(m_text.get()))
     63     , m_isAllASCII(m_text.containsOnlyASCII())
    7064     , m_knownNotToUseFallbackFonts(false)
    7165{
     
    443437        bool isSpace;
    444438        bool previousCharWasSpace = true; // FIXME: Preserves historical behavior, but seems wrong for start > 0.
     439        ASSERT(m_text);
     440        StringImpl& text = *m_text.impl();
    445441        for (int i = start; i < start + len; i++) {
    446             char c = (*m_text)[i];
     442            char c = text[i];
    447443            if (c <= ' ') {
    448444                if (c == ' ' || c == '\n') {
     
    487483    int len = textLength();
    488484
    489     if (!len || (stripFrontSpaces && m_text->containsOnlyWhitespace())) {
     485    if (!len || (stripFrontSpaces && text()->containsOnlyWhitespace())) {
    490486        beginMinW = 0;
    491487        endMinW = 0;
     
    507503    hasBreak = m_hasBreak;
    508504
    509     if ((*m_text)[0] == ' ' || ((*m_text)[0] == '\n' && !style()->preserveNewline()) || (*m_text)[0] == '\t') {
     505    ASSERT(m_text);
     506    StringImpl& text = *m_text.impl();
     507    if (text[0] == ' ' || (text[0] == '\n' && !style()->preserveNewline()) || text[0] == '\t') {
    510508        const Font& f = style()->font(); // FIXME: This ignores first-line.
    511509        if (stripFrontSpaces) {
     
    530528        for (int i = 0; i < len; i++) {
    531529            int linelen = 0;
    532             while (i + linelen < len && (*m_text)[i + linelen] != '\n')
     530            while (i + linelen < len && text[i + linelen] != '\n')
    533531                linelen++;
    534532
     
    778776bool RenderText::containsOnlyWhitespace(unsigned from, unsigned len) const
    779777{
     778    ASSERT(m_text);
     779    StringImpl& text = *m_text.impl();
    780780    unsigned currPos;
    781781    for (currPos = from;
    782          currPos < from + len && ((*m_text)[currPos] == '\n' || (*m_text)[currPos] == ' ' || (*m_text)[currPos] == '\t');
     782         currPos < from + len && (text[currPos] == '\n' || text[currPos] == ' ' || text[currPos] == '\t');
    783783         currPos++) { }
    784784    return currPos >= (from + len);
     
    953953            // leading, trailing and multiple contiguous space characters.
    954954
    955             m_text = m_text->replace('\n', ' ');
     955            m_text.replace('\n', ' ');
    956956
    957957            // If xml:space="preserve" is set, white-space is set to "pre", which
     
    964964            // Then, all contiguous space characters will be consolidated.   
    965965
    966            m_text = m_text->replace('\n', StringImpl::empty());
     966           m_text.replace('\n', StringImpl::empty());
    967967
    968968           // If xml:space="default" is set, white-space is set to "nowrap", which handles
     
    970970        }
    971971
    972         m_text = m_text->replace('\t', ' ');
     972        m_text.replace('\t', ' ');
    973973    }
    974974#endif
     
    978978            case TTNONE:
    979979                break;
    980             case CAPITALIZE: {
    981                 m_text = m_text->capitalize(previousCharacter());
     980            case CAPITALIZE:
     981                m_text.makeCapitalized(previousCharacter());
    982982                break;
    983             }
    984983            case UPPERCASE:
    985                 m_text = m_text->upper();
     984                m_text.makeUpper();
    986985                break;
    987986            case LOWERCASE:
    988                 m_text = m_text->lower();
     987                m_text.makeLower();
    989988                break;
    990989        }
     
    996995                break;
    997996            case TSCIRCLE:
    998                 m_text = m_text->secure(whiteBullet);
     997                m_text.makeSecure(whiteBullet);
    999998                break;
    1000999            case TSDISC:
    1001                 m_text = m_text->secure(bullet);
     1000                m_text.makeSecure(bullet);
    10021001                break;
    10031002            case TSSQUARE:
    1004                 m_text = m_text->secure(blackSquare);
     1003                m_text.makeSecure(blackSquare);
    10051004        }
    10061005    }
    10071006
    10081007    ASSERT(m_text);
    1009     ASSERT(!isBR() || (textLength() == 1 && (*m_text)[0] == '\n'));
    1010 
    1011     m_isAllASCII = charactersAreAllASCII(m_text.get());
     1008    ASSERT(!isBR() || (textLength() == 1 && m_text[0] == '\n'));
     1009
     1010    m_isAllASCII = m_text.containsOnlyASCII();
    10121011}
    10131012
     
    10161015    ASSERT(text);
    10171016
    1018     if (!force && equal(m_text.get(), text.get()))
     1017    if (!force && equal(m_text.impl(), text.get()))
    10191018        return;
    10201019
     
    12461245int RenderText::previousOffset(int current) const
    12471246{
    1248     StringImpl* si = m_text.get();
     1247    StringImpl* si = m_text.impl();
    12491248    TextBreakIterator* iterator = cursorMovementIterator(si->characters(), si->length());
    12501249    if (!iterator)
     
    12941293{
    12951294#if PLATFORM(MAC)
     1295    ASSERT(m_text);
     1296    StringImpl& text = *m_text.impl();
    12961297    UChar32 character;
    12971298    while (current > 0) {
    1298         if (U16_IS_TRAIL((*m_text)[--current]))
     1299        if (U16_IS_TRAIL(text[--current]))
    12991300            --current;
    13001301        if (current < 0)
    13011302            break;
    13021303
    1303         UChar32 character = m_text->characterStartingAt(current);
     1304        UChar32 character = text.characterStartingAt(current);
    13041305
    13051306        // We don't combine characters in Armenian ... Limbu range for backward deletion.
     
    13151316
    13161317    // Hangul
    1317     character = m_text->characterStartingAt(current);
     1318    character = text.characterStartingAt(current);
    13181319    if (((character >= HANGUL_CHOSEONG_START) && (character <= HANGUL_JONGSEONG_END)) || ((character >= HANGUL_SYLLABLE_START) && (character <= HANGUL_SYLLABLE_END))) {
    13191320        HangulState state;
     
    13311332        initialState = state;
    13321333
    1333         while (current > 0 && ((character = m_text->characterStartingAt(current - 1)) >= HANGUL_CHOSEONG_START) && (character <= HANGUL_SYLLABLE_END) && ((character <= HANGUL_JONGSEONG_END) || (character >= HANGUL_SYLLABLE_START))) {
     1334        while (current > 0 && ((character = text.characterStartingAt(current - 1)) >= HANGUL_CHOSEONG_START) && (character <= HANGUL_SYLLABLE_END) && ((character <= HANGUL_JONGSEONG_END) || (character >= HANGUL_SYLLABLE_START))) {
    13341335            switch (state) {
    13351336            case HangulStateV:
     
    13691370int RenderText::nextOffset(int current) const
    13701371{
    1371     StringImpl* si = m_text.get();
     1372    StringImpl* si = m_text.impl();
    13721373    TextBreakIterator* iterator = cursorMovementIterator(si->characters(), si->length());
    13731374    if (!iterator)
  • trunk/WebCore/rendering/RenderText.h

    r51522 r56047  
    5151    virtual void destroy();
    5252
    53     StringImpl* text() const { return m_text.get(); }
     53    StringImpl* text() const { return m_text.impl(); }
    5454
    5555    InlineTextBox* createInlineTextBox();
     
    6464    virtual VisiblePosition positionForPoint(const IntPoint&);
    6565
    66     const UChar* characters() const { return m_text->characters(); }
    67     unsigned textLength() const { return m_text->length(); } // non virtual implementation of length()
     66    const UChar* characters() const { return m_text.characters(); }
     67    unsigned textLength() const { return m_text.length(); } // non virtual implementation of length()
    6868    void positionLineBox(InlineBox*);
    6969
     
    152152    int m_minWidth; // here to minimize padding in 64-bit.
    153153
    154     RefPtr<StringImpl> m_text;
     154    String m_text;
    155155
    156156    InlineTextBox* m_firstTextBox;
Note: See TracChangeset for help on using the changeset viewer.