Changeset 181268 in webkit
- Timestamp:
- Mar 9, 2015 10:09:52 AM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r181264 r181268 1 2015-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 1 24 2015-03-09 Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr> 2 25 -
trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp
r179534 r181268 69 69 return fragment; 70 70 } 71 unsigned spaceCount = 0;72 71 unsigned startPosition = m_position; 73 unsigned endPosition = findNextNonWhitespacePosition(startPosition, spaceCount);72 unsigned endPosition = skipToNextPosition(PositionType::NonWhitespace, startPosition); 74 73 ASSERT(startPosition <= endPosition); 75 74 if (endPosition > startPosition) { … … 77 76 bool isCollapsed = multipleWhitespace && m_style.collapseWhitespace; 78 77 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); 86 79 m_position = endPosition; 87 80 return TextFragment(startPosition, endPosition, width, TextFragment::Whitespace, isCollapsed, isBreakable); 88 81 } 89 endPosition = findNextBreakablePosition(startPosition + 1);82 endPosition = skipToNextPosition(PositionType::Breakable, startPosition + 1); 90 83 m_position = endPosition; 91 84 return TextFragment(startPosition, endPosition, textWidth(startPosition, endPosition, xPosition), TextFragment::NonWhitespace, false, m_style.breakWordOnOverflow); … … 115 108 116 109 template <typename CharacterType> 117 static unsigned nextBreakablePosition(LazyLineBreakIterator& lineBreakIterator, const FlowContents::Segment& segment, unsigned position)110 static unsigned nextBreakablePosition(LazyLineBreakIterator& lineBreakIterator, const FlowContents::Segment& segment, unsigned startPosition) 118 111 { 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); 123 113 } 124 114 125 unsigned TextFragmentIterator::findNextBreakablePosition(unsigned position) const 115 template <typename CharacterType> 116 static unsigned nextNonWhitespacePosition(const FlowContents::Segment& segment, unsigned startPosition, const TextFragmentIterator::Style& style) 126 117 { 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; 140 125 } 141 126 return position; 142 127 } 143 128 144 template <typename CharacterType> 145 static bool findNextNonWhitespace(const FlowContents::Segment& segment, const TextFragmentIterator::Style& style, unsigned& position, unsigned& spaceCount) 129 unsigned TextFragmentIterator::skipToNextPosition(PositionType positionType, unsigned startPosition) const 146 130 { 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; 159 133 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)); 163 136 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) 166 156 break; 167 157 } 168 return position;158 return currentPosition; 169 159 } 170 160 -
trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h
r179534 r181268 93 93 94 94 private: 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; 97 97 UChar characterAt(unsigned position) const; 98 98 bool isLineBreak(unsigned position) const;
Note: See TracChangeset
for help on using the changeset viewer.