Skip to content

Commit 3fc29df

Browse files
author
Sam Weinig
committed
Move LineBreaker functions to LineBreaker.cpp
https://bugs.webkit.org/show_bug.cgi?id=126491 Reviewed by Simon Fraser. - Moves LineBreaker::nextLineBreak() and LineBreaker::nextSegmentBreak() to LineBreaker.cpp from RenderBlockLineLayout.cpp - Moves requiresIndent() to LineWidth.h/cpp from RenderBlockLineLayout.cpp so it can be shared. - Adds missing inline specifier to BreakingContext::handleEndOfLine() to avoid duplicate symbols. * rendering/RenderBlockLineLayout.cpp: (WebCore::updateLogicalInlinePositions): (WebCore::RenderBlockFlow::computeInlineDirectionPositionsForLine): * rendering/line/BreakingContextInlineHeaders.h: (WebCore::BreakingContext::handleEndOfLine): * rendering/line/LineBreaker.cpp: (WebCore::LineBreaker::nextLineBreak): (WebCore::LineBreaker::nextSegmentBreak): * rendering/line/LineWidth.cpp: (WebCore::requiresIndent): * rendering/line/LineWidth.h: Canonical link: https://commits.webkit.org/144380@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161314 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 0cfead3 commit 3fc29df

6 files changed

Lines changed: 166 additions & 136 deletions

File tree

Source/WebCore/ChangeLog

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
2014-01-04 Sam Weinig <sam@webkit.org>
2+
3+
Move LineBreaker functions to LineBreaker.cpp
4+
https://bugs.webkit.org/show_bug.cgi?id=126491
5+
6+
Reviewed by Simon Fraser.
7+
8+
- Moves LineBreaker::nextLineBreak() and LineBreaker::nextSegmentBreak() to
9+
LineBreaker.cpp from RenderBlockLineLayout.cpp
10+
- Moves requiresIndent() to LineWidth.h/cpp from RenderBlockLineLayout.cpp
11+
so it can be shared.
12+
- Adds missing inline specifier to BreakingContext::handleEndOfLine() to avoid
13+
duplicate symbols.
14+
15+
* rendering/RenderBlockLineLayout.cpp:
16+
(WebCore::updateLogicalInlinePositions):
17+
(WebCore::RenderBlockFlow::computeInlineDirectionPositionsForLine):
18+
* rendering/line/BreakingContextInlineHeaders.h:
19+
(WebCore::BreakingContext::handleEndOfLine):
20+
* rendering/line/LineBreaker.cpp:
21+
(WebCore::LineBreaker::nextLineBreak):
22+
(WebCore::LineBreaker::nextSegmentBreak):
23+
* rendering/line/LineWidth.cpp:
24+
(WebCore::requiresIndent):
25+
* rendering/line/LineWidth.h:
26+
127
2014-01-04 Martin Robinson <mrobinson@igalia.com>
228

329
[GTK] [CMake] Fix the video and audio build

Source/WebCore/rendering/RenderBlockLineLayout.cpp

Lines changed: 7 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -592,34 +592,15 @@ void RenderBlock::updateLogicalWidthForAlignment(const ETextAlign& textAlign, Bi
592592
}
593593
}
594594

595-
static IndentTextOrNot requiresIndent(bool isFirstLine, bool isAfterHardLineBreak, const RenderStyle& style)
595+
static void updateLogicalInlinePositions(RenderBlockFlow& block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight)
596596
{
597-
IndentTextOrNot shouldIndentText = DoNotIndentText;
598-
if (isFirstLine)
599-
shouldIndentText = IndentText;
600-
#if ENABLE(CSS3_TEXT)
601-
else if (isAfterHardLineBreak && style.textIndentLine() == TextIndentEachLine)
602-
shouldIndentText = IndentText;
603-
604-
if (style.textIndentType() == TextIndentHanging)
605-
shouldIndentText = shouldIndentText == IndentText ? DoNotIndentText : IndentText;
606-
#else
607-
UNUSED_PARAM(isAfterHardLineBreak);
608-
UNUSED_PARAM(style);
609-
#endif
610-
return shouldIndentText;
611-
}
612-
613-
static void updateLogicalInlinePositions(RenderBlockFlow* block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight)
614-
{
615-
LayoutUnit lineLogicalHeight = block->minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight);
616-
lineLogicalLeft = block->pixelSnappedLogicalLeftOffsetForLine(block->logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
617-
lineLogicalRight = block->pixelSnappedLogicalRightOffsetForLine(block->logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
597+
LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight);
598+
lineLogicalLeft = block.pixelSnappedLogicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
599+
lineLogicalRight = block.pixelSnappedLogicalRightOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
618600
availableLogicalWidth = lineLogicalRight - lineLogicalLeft;
619601
}
620602

621-
void RenderBlockFlow::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, const LineInfo& lineInfo, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd,
622-
GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
603+
void RenderBlockFlow::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, const LineInfo& lineInfo, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
623604
{
624605
ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
625606

@@ -633,7 +614,7 @@ void RenderBlockFlow::computeInlineDirectionPositionsForLine(RootInlineBox* line
633614
float lineLogicalLeft;
634615
float lineLogicalRight;
635616
float availableLogicalWidth;
636-
updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0);
617+
updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0);
637618
bool needsWordSpacing;
638619
#if ENABLE(CSS_SHAPES)
639620
ShapeInsideInfo* shapeInsideInfo = layoutShapeInsideInfo();
@@ -669,7 +650,7 @@ void RenderBlockFlow::computeInlineDirectionPositionsForLine(RootInlineBox* line
669650

670651
if (firstRun && firstRun->renderer().isReplaced()) {
671652
RenderBox& renderBox = toRenderBox(firstRun->renderer());
672-
updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight());
653+
updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight());
673654
}
674655

675656
computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
@@ -1996,115 +1977,6 @@ bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj)
19961977
return !it.atEnd();
19971978
}
19981979

1999-
InlineIterator LineBreaker::nextLineBreak(InlineBidiResolver& resolver, LineInfo& lineInfo, RenderTextInfo& renderTextInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements& wordMeasurements)
2000-
{
2001-
#if !ENABLE(CSS_SHAPES)
2002-
return nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
2003-
#else
2004-
ShapeInsideInfo* shapeInsideInfo = m_block.layoutShapeInsideInfo();
2005-
2006-
if (!shapeInsideInfo || !shapeInsideInfo->lineOverlapsShapeBounds())
2007-
return nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
2008-
2009-
InlineIterator end = resolver.position();
2010-
InlineIterator oldEnd = end;
2011-
2012-
if (!shapeInsideInfo->hasSegments()) {
2013-
end = nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
2014-
resolver.setPositionIgnoringNestedIsolates(oldEnd);
2015-
return oldEnd;
2016-
}
2017-
2018-
const SegmentList& segments = shapeInsideInfo->segments();
2019-
SegmentRangeList& segmentRanges = shapeInsideInfo->segmentRanges();
2020-
2021-
for (unsigned i = 0; i < segments.size() && !end.atEnd(); i++) {
2022-
InlineIterator segmentStart = resolver.position();
2023-
end = nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
2024-
2025-
ASSERT(segmentRanges.size() == i);
2026-
if (resolver.position().atEnd()) {
2027-
segmentRanges.append(LineSegmentRange(segmentStart, end));
2028-
break;
2029-
}
2030-
if (resolver.position() == end) {
2031-
// Nothing fit this segment
2032-
end = segmentStart;
2033-
segmentRanges.append(LineSegmentRange(segmentStart, segmentStart));
2034-
resolver.setPositionIgnoringNestedIsolates(segmentStart);
2035-
} else {
2036-
// Note that resolver.position is already skipping some of the white space at the beginning of the line,
2037-
// so that's why segmentStart might be different than resolver.position().
2038-
LineSegmentRange range(resolver.position(), end);
2039-
segmentRanges.append(range);
2040-
resolver.setPosition(end, numberOfIsolateAncestors(end));
2041-
2042-
if (lineInfo.previousLineBrokeCleanly()) {
2043-
// If we hit a new line break, just stop adding anything to this line.
2044-
break;
2045-
}
2046-
}
2047-
}
2048-
resolver.setPositionIgnoringNestedIsolates(oldEnd);
2049-
return end;
2050-
#endif
2051-
}
2052-
2053-
InlineIterator LineBreaker::nextSegmentBreak(InlineBidiResolver& resolver, LineInfo& lineInfo, RenderTextInfo& renderTextInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements& wordMeasurements)
2054-
{
2055-
reset();
2056-
2057-
ASSERT(resolver.position().root() == &m_block);
2058-
2059-
bool appliedStartWidth = resolver.position().offset();
2060-
2061-
LineWidth width(m_block, lineInfo.isFirstLine(), requiresIndent(lineInfo.isFirstLine(), lineInfo.previousLineBrokeCleanly(), m_block.style()));
2062-
2063-
skipLeadingWhitespace(resolver, lineInfo, lastFloatFromPreviousLine, width);
2064-
2065-
if (resolver.position().atEnd())
2066-
return resolver.position();
2067-
2068-
BreakingContext context(*this, resolver, lineInfo, width, renderTextInfo, lastFloatFromPreviousLine, appliedStartWidth, m_block);
2069-
2070-
while (context.currentObject()) {
2071-
context.initializeForCurrentObject();
2072-
if (context.currentObject()->isBR()) {
2073-
context.handleBR(m_clear);
2074-
} else if (context.currentObject()->isOutOfFlowPositioned()) {
2075-
context.handleOutOfFlowPositioned(m_positionedObjects);
2076-
} else if (context.currentObject()->isFloating()) {
2077-
context.handleFloat();
2078-
} else if (context.currentObject()->isRenderInline()) {
2079-
context.handleEmptyInline();
2080-
} else if (context.currentObject()->isReplaced()) {
2081-
context.handleReplaced();
2082-
} else if (context.currentObject()->isText()) {
2083-
if (context.handleText(wordMeasurements, m_hyphenated, consecutiveHyphenatedLines)) {
2084-
// We've hit a hard text line break. Our line break iterator is updated, so go ahead and early return.
2085-
return context.lineBreak();
2086-
}
2087-
} else if (context.currentObject()->isLineBreakOpportunity())
2088-
context.commitLineBreakAtCurrentWidth(context.currentObject());
2089-
else
2090-
ASSERT_NOT_REACHED();
2091-
2092-
if (context.atEnd())
2093-
return context.handleEndOfLine();
2094-
2095-
context.commitAndUpdateLineBreakIfNeeded();
2096-
2097-
if (context.atEnd())
2098-
return context.handleEndOfLine();
2099-
2100-
context.increment();
2101-
}
2102-
2103-
context.clearLineBreakIfFitsOnLine(true);
2104-
2105-
return context.handleEndOfLine();
2106-
}
2107-
21081980
void RenderBlockFlow::addOverflowFromInlineChildren()
21091981
{
21101982
if (auto layout = simpleLineLayout()) {

Source/WebCore/rendering/line/BreakingContextInlineHeaders.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ inline void checkMidpoints(LineMidpointState& lineMidpointState, InlineIterator&
10851085
}
10861086
}
10871087

1088-
InlineIterator BreakingContext::handleEndOfLine()
1088+
inline InlineIterator BreakingContext::handleEndOfLine()
10891089
{
10901090
#if ENABLE(CSS_SHAPES)
10911091
ShapeInsideInfo* shapeInfo = m_block.layoutShapeInsideInfo();

Source/WebCore/rendering/line/LineBreaker.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include "config.h"
2626
#include "LineBreaker.h"
2727

28+
#include "BreakingContextInlineHeaders.h"
2829
#include "RenderCombineText.h"
30+
#include "ShapeInsideInfo.h"
2931

3032
namespace WebCore {
3133

@@ -76,4 +78,113 @@ void LineBreaker::skipLeadingWhitespace(InlineBidiResolver& resolver, LineInfo&
7678
resolver.commitExplicitEmbedding();
7779
}
7880

81+
InlineIterator LineBreaker::nextLineBreak(InlineBidiResolver& resolver, LineInfo& lineInfo, RenderTextInfo& renderTextInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements& wordMeasurements)
82+
{
83+
#if !ENABLE(CSS_SHAPES)
84+
return nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
85+
#else
86+
ShapeInsideInfo* shapeInsideInfo = m_block.layoutShapeInsideInfo();
87+
88+
if (!shapeInsideInfo || !shapeInsideInfo->lineOverlapsShapeBounds())
89+
return nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
90+
91+
InlineIterator end = resolver.position();
92+
InlineIterator oldEnd = end;
93+
94+
if (!shapeInsideInfo->hasSegments()) {
95+
end = nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
96+
resolver.setPositionIgnoringNestedIsolates(oldEnd);
97+
return oldEnd;
98+
}
99+
100+
const SegmentList& segments = shapeInsideInfo->segments();
101+
SegmentRangeList& segmentRanges = shapeInsideInfo->segmentRanges();
102+
103+
for (unsigned i = 0; i < segments.size() && !end.atEnd(); i++) {
104+
InlineIterator segmentStart = resolver.position();
105+
end = nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
106+
107+
ASSERT(segmentRanges.size() == i);
108+
if (resolver.position().atEnd()) {
109+
segmentRanges.append(LineSegmentRange(segmentStart, end));
110+
break;
111+
}
112+
if (resolver.position() == end) {
113+
// Nothing fit this segment
114+
end = segmentStart;
115+
segmentRanges.append(LineSegmentRange(segmentStart, segmentStart));
116+
resolver.setPositionIgnoringNestedIsolates(segmentStart);
117+
} else {
118+
// Note that resolver.position is already skipping some of the white space at the beginning of the line,
119+
// so that's why segmentStart might be different than resolver.position().
120+
LineSegmentRange range(resolver.position(), end);
121+
segmentRanges.append(range);
122+
resolver.setPosition(end, numberOfIsolateAncestors(end));
123+
124+
if (lineInfo.previousLineBrokeCleanly()) {
125+
// If we hit a new line break, just stop adding anything to this line.
126+
break;
127+
}
128+
}
129+
}
130+
resolver.setPositionIgnoringNestedIsolates(oldEnd);
131+
return end;
132+
#endif
133+
}
134+
135+
InlineIterator LineBreaker::nextSegmentBreak(InlineBidiResolver& resolver, LineInfo& lineInfo, RenderTextInfo& renderTextInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements& wordMeasurements)
136+
{
137+
reset();
138+
139+
ASSERT(resolver.position().root() == &m_block);
140+
141+
bool appliedStartWidth = resolver.position().offset();
142+
143+
LineWidth width(m_block, lineInfo.isFirstLine(), requiresIndent(lineInfo.isFirstLine(), lineInfo.previousLineBrokeCleanly(), m_block.style()));
144+
145+
skipLeadingWhitespace(resolver, lineInfo, lastFloatFromPreviousLine, width);
146+
147+
if (resolver.position().atEnd())
148+
return resolver.position();
149+
150+
BreakingContext context(*this, resolver, lineInfo, width, renderTextInfo, lastFloatFromPreviousLine, appliedStartWidth, m_block);
151+
152+
while (context.currentObject()) {
153+
context.initializeForCurrentObject();
154+
if (context.currentObject()->isBR()) {
155+
context.handleBR(m_clear);
156+
} else if (context.currentObject()->isOutOfFlowPositioned()) {
157+
context.handleOutOfFlowPositioned(m_positionedObjects);
158+
} else if (context.currentObject()->isFloating()) {
159+
context.handleFloat();
160+
} else if (context.currentObject()->isRenderInline()) {
161+
context.handleEmptyInline();
162+
} else if (context.currentObject()->isReplaced()) {
163+
context.handleReplaced();
164+
} else if (context.currentObject()->isText()) {
165+
if (context.handleText(wordMeasurements, m_hyphenated, consecutiveHyphenatedLines)) {
166+
// We've hit a hard text line break. Our line break iterator is updated, so go ahead and early return.
167+
return context.lineBreak();
168+
}
169+
} else if (context.currentObject()->isLineBreakOpportunity())
170+
context.commitLineBreakAtCurrentWidth(context.currentObject());
171+
else
172+
ASSERT_NOT_REACHED();
173+
174+
if (context.atEnd())
175+
return context.handleEndOfLine();
176+
177+
context.commitAndUpdateLineBreakIfNeeded();
178+
179+
if (context.atEnd())
180+
return context.handleEndOfLine();
181+
182+
context.increment();
183+
}
184+
185+
context.clearLineBreakIfFitsOnLine(true);
186+
187+
return context.handleEndOfLine();
188+
}
189+
79190
}

Source/WebCore/rendering/line/LineWidth.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,22 @@ bool LineWidth::fitsOnLineExcludingTrailingCollapsedWhitespace() const
241241
return currentWidth() - m_trailingCollapsedWhitespaceWidth <= m_availableWidth;
242242
}
243243

244+
IndentTextOrNot requiresIndent(bool isFirstLine, bool isAfterHardLineBreak, const RenderStyle& style)
245+
{
246+
IndentTextOrNot shouldIndentText = DoNotIndentText;
247+
if (isFirstLine)
248+
shouldIndentText = IndentText;
249+
#if ENABLE(CSS3_TEXT)
250+
else if (isAfterHardLineBreak && style.textIndentLine() == TextIndentEachLine)
251+
shouldIndentText = IndentText;
252+
253+
if (style.textIndentType() == TextIndentHanging)
254+
shouldIndentText = shouldIndentText == IndentText ? DoNotIndentText : IndentText;
255+
#else
256+
UNUSED_PARAM(isAfterHardLineBreak);
257+
UNUSED_PARAM(style);
258+
#endif
259+
return shouldIndentText;
260+
}
261+
244262
}

Source/WebCore/rendering/line/LineWidth.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class FloatingObject;
3838
class RenderBlockFlow;
3939
class RenderObject;
4040
class RenderRubyRun;
41+
class RenderStyle;
4142

4243
struct LineSegment;
4344

@@ -92,6 +93,8 @@ class LineWidth {
9293
IndentTextOrNot m_shouldIndentText;
9394
};
9495

96+
IndentTextOrNot requiresIndent(bool isFirstLine, bool isAfterHardLineBreak, const RenderStyle&);
97+
9598
}
9699

97100
#endif // LineWidth_h

0 commit comments

Comments
 (0)