Changeset 181268 in webkit


Ignore:
Timestamp:
Mar 9, 2015 10:09:52 AM (9 years ago)
Author:
Alan Bujtas
Message:

Simple line layout: Merge TextFragmentIterator::findNextBreakablePosition() and TextFragmentIterator::findNextNonWhitespacePosition().
https://bugs.webkit.org/show_bug.cgi?id=142344

Reviewed by Antti Koivisto.

This patch merges findNextBreakablePosition() and findNextNonWhitespacePosition() so that
the segment looping and position handling logic are no longer duplicated. It also unifies
the static next*() functions' signature.

No change in functionality.

  • rendering/SimpleLineLayoutTextFragmentIterator.cpp:

(WebCore::SimpleLineLayout::TextFragmentIterator::nextTextFragment):
(WebCore::SimpleLineLayout::nextBreakablePosition):
(WebCore::SimpleLineLayout::nextNonWhitespacePosition):
(WebCore::SimpleLineLayout::TextFragmentIterator::skipToNextPosition):
(WebCore::SimpleLineLayout::TextFragmentIterator::findNextBreakablePosition): Deleted.
(WebCore::SimpleLineLayout::findNextNonWhitespace): Deleted.
(WebCore::SimpleLineLayout::TextFragmentIterator::findNextNonWhitespacePosition): Deleted.

  • rendering/SimpleLineLayoutTextFragmentIterator.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r181264 r181268  
     12015-03-09  Zalan Bujtas  <zalan@apple.com>
     2
     3        Simple line layout: Merge TextFragmentIterator::findNextBreakablePosition() and TextFragmentIterator::findNextNonWhitespacePosition().
     4        https://bugs.webkit.org/show_bug.cgi?id=142344
     5
     6        Reviewed by Antti Koivisto.
     7
     8        This patch merges findNextBreakablePosition() and findNextNonWhitespacePosition() so that
     9        the segment looping and position handling logic are no longer duplicated. It also unifies
     10        the static next*() functions' signature.
     11
     12        No change in functionality.
     13
     14        * rendering/SimpleLineLayoutTextFragmentIterator.cpp:
     15        (WebCore::SimpleLineLayout::TextFragmentIterator::nextTextFragment):
     16        (WebCore::SimpleLineLayout::nextBreakablePosition):
     17        (WebCore::SimpleLineLayout::nextNonWhitespacePosition):
     18        (WebCore::SimpleLineLayout::TextFragmentIterator::skipToNextPosition):
     19        (WebCore::SimpleLineLayout::TextFragmentIterator::findNextBreakablePosition): Deleted.
     20        (WebCore::SimpleLineLayout::findNextNonWhitespace): Deleted.
     21        (WebCore::SimpleLineLayout::TextFragmentIterator::findNextNonWhitespacePosition): Deleted.
     22        * rendering/SimpleLineLayoutTextFragmentIterator.h:
     23
    1242015-03-09  Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
    225
  • trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp

    r179534 r181268  
    6969        return fragment;
    7070    }
    71     unsigned spaceCount = 0;
    7271    unsigned startPosition = m_position;
    73     unsigned endPosition = findNextNonWhitespacePosition(startPosition, spaceCount);
     72    unsigned endPosition = skipToNextPosition(PositionType::NonWhitespace, startPosition);
    7473    ASSERT(startPosition <= endPosition);
    7574    if (endPosition > startPosition) {
     
    7776        bool isCollapsed = multipleWhitespace && m_style.collapseWhitespace;
    7877        bool isBreakable = !isCollapsed && multipleWhitespace;
    79         float width = 0;
    80         if (isCollapsed)
    81             width = m_style.spaceWidth;
    82         else {
    83             unsigned length = endPosition - startPosition;
    84             width = length == spaceCount ? length * m_style.spaceWidth : textWidth(startPosition, endPosition, xPosition);
    85         }
     78        float width = isCollapsed ? m_style.spaceWidth : textWidth(startPosition, endPosition, xPosition);
    8679        m_position = endPosition;
    8780        return TextFragment(startPosition, endPosition, width, TextFragment::Whitespace, isCollapsed, isBreakable);
    8881    }
    89     endPosition = findNextBreakablePosition(startPosition + 1);
     82    endPosition = skipToNextPosition(PositionType::Breakable, startPosition + 1);
    9083    m_position = endPosition;
    9184    return TextFragment(startPosition, endPosition, textWidth(startPosition, endPosition, xPosition), TextFragment::NonWhitespace, false, m_style.breakWordOnOverflow);
     
    115108
    116109template <typename CharacterType>
    117 static unsigned nextBreakablePosition(LazyLineBreakIterator& lineBreakIterator, const FlowContents::Segment& segment, unsigned position)
     110static unsigned nextBreakablePosition(LazyLineBreakIterator& lineBreakIterator, const FlowContents::Segment& segment, unsigned startPosition)
    118111{
    119     const auto* characters = segment.text.characters<CharacterType>();
    120     unsigned segmentLength = segment.end - segment.start;
    121     unsigned segmentPosition = position - segment.start;
    122     return nextBreakablePositionNonLoosely<CharacterType, NBSPBehavior::IgnoreNBSP>(lineBreakIterator, characters, segmentLength, segmentPosition);
     112    return nextBreakablePositionNonLoosely<CharacterType, NBSPBehavior::IgnoreNBSP>(lineBreakIterator, segment.text.characters<CharacterType>(), segment.end - segment.start, startPosition);
    123113}
    124114
    125 unsigned TextFragmentIterator::findNextBreakablePosition(unsigned position) const
     115template <typename CharacterType>
     116static unsigned nextNonWhitespacePosition(const FlowContents::Segment& segment, unsigned startPosition, const TextFragmentIterator::Style& style)
    126117{
    127     while (!isEnd(position)) {
    128         auto& segment = m_flowContents.segmentForPosition(position);
    129         if (segment.text.impl() != m_lineBreakIterator.string().impl()) {
    130             UChar lastCharacter = segment.start > 0 ? characterAt(segment.start - 1) : 0;
    131             UChar secondToLastCharacter = segment.start > 1 ? characterAt(segment.start - 2) : 0;
    132             m_lineBreakIterator.setPriorContext(lastCharacter, secondToLastCharacter);
    133             m_lineBreakIterator.resetStringAndReleaseIterator(segment.text, m_style.locale, LineBreakIteratorModeUAX14);
    134         }
    135 
    136         unsigned breakable = segment.text.is8Bit() ? nextBreakablePosition<LChar>(m_lineBreakIterator, segment, position) : nextBreakablePosition<UChar>(m_lineBreakIterator, segment, position);
    137         position = segment.start + breakable;
    138         if (position < segment.end)
    139             break;
     118    const auto* text = segment.text.characters<CharacterType>();
     119    unsigned position = startPosition;
     120    for (; position < segment.end; ++position) {
     121        auto character = text[position];
     122        bool isWhitespace = character == ' ' || character == '\t' || (!style.preserveNewline && character == '\n');
     123        if (!isWhitespace)
     124            return position;
    140125    }
    141126    return position;
    142127}
    143128
    144 template <typename CharacterType>
    145 static bool findNextNonWhitespace(const FlowContents::Segment& segment, const TextFragmentIterator::Style& style, unsigned& position, unsigned& spaceCount)
     129unsigned TextFragmentIterator::skipToNextPosition(PositionType positionType, unsigned startPosition) const
    146130{
    147     const auto* text = segment.text.characters<CharacterType>();
    148     for (; position < segment.end; ++position) {
    149         auto character = text[position - segment.start];
    150         bool isSpace = character == ' ';
    151         bool isWhitespace = isSpace || character == '\t' || (!style.preserveNewline && character == '\n');
    152         if (!isWhitespace)
    153             return true;
    154         if (isSpace)
    155             ++spaceCount;
    156     }
    157     return false;
    158 }
     131    if (isEnd(startPosition))
     132        return startPosition;
    159133
    160 unsigned TextFragmentIterator::findNextNonWhitespacePosition(unsigned position, unsigned& spaceCount) const
    161 {
    162     FlowContents::Iterator it(m_flowContents, m_flowContents.segmentIndexForPosition(position));
     134    unsigned currentPosition = startPosition;
     135    FlowContents::Iterator it(m_flowContents, m_flowContents.segmentIndexForPosition(currentPosition));
    163136    for (auto end = m_flowContents.end(); it != end; ++it) {
    164         bool foundNonWhitespace = (*it).text.is8Bit() ? findNextNonWhitespace<LChar>(*it, m_style, position, spaceCount) : findNextNonWhitespace<UChar>(*it, m_style, position, spaceCount);
    165         if (foundNonWhitespace)
     137        auto& segment = *it;
     138        unsigned currentPositonRelativeToSegment = currentPosition - segment.start;
     139        unsigned nextPositionRelativeToSegment = 0;
     140        if (positionType == NonWhitespace) {
     141            nextPositionRelativeToSegment = segment.text.is8Bit() ? nextNonWhitespacePosition<LChar>(segment, currentPositonRelativeToSegment, m_style) :
     142                nextNonWhitespacePosition<UChar>(segment, currentPositonRelativeToSegment, m_style);
     143        } else if (positionType == Breakable) {
     144            if (segment.text.impl() != m_lineBreakIterator.string().impl()) {
     145                UChar lastCharacter = segment.start > 0 ? characterAt(segment.start - 1) : 0;
     146                UChar secondToLastCharacter = segment.start > 1 ? characterAt(segment.start - 2) : 0;
     147                m_lineBreakIterator.setPriorContext(lastCharacter, secondToLastCharacter);
     148                m_lineBreakIterator.resetStringAndReleaseIterator(segment.text, m_style.locale, LineBreakIteratorModeUAX14);
     149            }
     150            nextPositionRelativeToSegment = segment.text.is8Bit() ? nextBreakablePosition<LChar>(m_lineBreakIterator, segment, currentPositonRelativeToSegment) :
     151                nextBreakablePosition<UChar>(m_lineBreakIterator, segment, currentPositonRelativeToSegment);
     152        } else
     153            ASSERT_NOT_REACHED();
     154        currentPosition = segment.start + nextPositionRelativeToSegment;
     155        if (currentPosition < segment.end)
    166156            break;
    167157    }
    168     return position;
     158    return currentPosition;
    169159}
    170160
  • trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h

    r179534 r181268  
    9393
    9494private:
    95     unsigned findNextNonWhitespacePosition(unsigned position, unsigned& spaceCount) const;
    96     unsigned findNextBreakablePosition(unsigned position) const;
     95    enum PositionType { Breakable, NonWhitespace };
     96    unsigned skipToNextPosition(PositionType, unsigned startPosition) const;
    9797    UChar characterAt(unsigned position) const;
    9898    bool isLineBreak(unsigned position) const;
Note: See TracChangeset for help on using the changeset viewer.