blob: 4447686af712004ab2208f21986969871c1133ab [file] [log] [blame]
darin55ae73e2007-05-11 15:47:28 +00001/*
kociendabb0c24b2001-08-24 14:24:40 +00002 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
mitz@apple.com86470c82011-01-27 01:39:27 +00003 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved.
eric@webkit.orgddbec0aa2010-01-06 01:13:11 +00004 * Copyright (C) 2010 Google Inc. All rights reserved.
kociendabb0c24b2001-08-24 14:24:40 +00005 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
ddkilzerc8eccec2007-09-26 02:29:57 +000018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
kociendabb0c24b2001-08-24 14:24:40 +000020 *
kociendabb0c24b2001-08-24 14:24:40 +000021 */
darinbe4c67d2005-12-19 19:53:12 +000022
mjsb64c50a2005-10-03 21:13:12 +000023#include "config.h"
darin36d11362006-04-11 16:30:21 +000024
mitz@apple.com4c1ff322009-07-13 00:54:12 +000025#include "BidiResolver.h"
mitz@apple.comb2107652010-06-21 16:54:52 +000026#include "Hyphenation.h"
hyatt@apple.com71eeb442010-02-11 20:05:51 +000027#include "InlineIterator.h"
eseidel3a6d1322006-01-09 03:14:50 +000028#include "InlineTextBox.h"
ggarenec11e5b2007-02-25 02:14:54 +000029#include "Logging.h"
darin36d11362006-04-11 16:30:21 +000030#include "RenderArena.h"
hyatt@apple.com4d046b72011-01-31 20:39:09 +000031#include "RenderCombineText.h"
hyatt@apple.coma10d30e2011-09-22 22:28:21 +000032#include "RenderFlowThread.h"
hyatt@apple.comc3c7e902009-01-28 21:48:33 +000033#include "RenderInline.h"
eric@webkit.orgb35848a2010-06-10 08:33:22 +000034#include "RenderLayer.h"
mjsd26b2972007-02-13 13:09:04 +000035#include "RenderListMarker.h"
mitz@apple.comddb59872011-04-05 05:21:16 +000036#include "RenderRubyRun.h"
hyattd8048342006-05-31 01:48:18 +000037#include "RenderView.h"
hyatt@apple.comcc1737c2010-09-16 20:20:02 +000038#include "Settings.h"
dbates@webkit.orgf6f05a92010-05-17 04:58:25 +000039#include "TrailingFloatsRootInlineBox.h"
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +000040#include "VerticalPositionCache.h"
darin36d11362006-04-11 16:30:21 +000041#include "break_lines.h"
mjsbb863512006-05-09 09:27:55 +000042#include <wtf/AlwaysInline.h>
slewis@apple.coma7615ca2008-07-12 05:51:33 +000043#include <wtf/RefCountedLeakCounter.h>
bolsinga@apple.com97e42c42008-11-15 04:47:20 +000044#include <wtf/StdLibExtras.h>
darin91298e52006-06-12 01:10:17 +000045#include <wtf/Vector.h>
paroga@webkit.org10c9e1b2011-01-29 17:04:51 +000046#include <wtf/unicode/CharacterNames.h>
hyatt8c371e52004-06-16 01:19:26 +000047
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +000048#if ENABLE(CSS_EXCLUSIONS)
commit-queue@webkit.org3a988eb2012-09-26 19:55:35 +000049#include "ExclusionShapeInsideInfo.h"
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +000050#endif
51
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +000052#if ENABLE(SVG)
zimmermann@webkit.org6e96afd2010-09-10 15:35:50 +000053#include "RenderSVGInlineText.h"
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +000054#include "SVGRootInlineBox.h"
55#endif
56
darin7bd70952006-04-13 07:07:34 +000057using namespace std;
darinf9e5d6c2007-01-09 14:54:26 +000058using namespace WTF;
59using namespace Unicode;
darin7bd70952006-04-13 07:07:34 +000060
darinb9481ed2006-03-20 02:57:59 +000061namespace WebCore {
mjsfe301d72003-10-02 18:46:18 +000062
hyatt1d5d87b2007-04-24 04:55:54 +000063// We don't let our line box tree for a single line get any deeper than this.
64const unsigned cMaxLineDepth = 200;
eric@webkit.org060caf62011-05-03 22:11:39 +000065
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +000066#if ENABLE(CSS_EXCLUSIONS)
commit-queue@webkit.org3a988eb2012-09-26 19:55:35 +000067static inline ExclusionShapeInsideInfo* layoutExclusionShapeInsideInfo(const RenderBlock* block)
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +000068{
commit-queue@webkit.org3a988eb2012-09-26 19:55:35 +000069 return block->view()->layoutState()->exclusionShapeInsideInfo();
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +000070}
71#endif
72
hyatt@apple.com5950bd42011-09-27 20:39:57 +000073class LineWidth {
74public:
75 LineWidth(RenderBlock* block, bool isFirstLine)
76 : m_block(block)
77 , m_uncommittedWidth(0)
78 , m_committedWidth(0)
79 , m_overhangWidth(0)
80 , m_left(0)
81 , m_right(0)
82 , m_availableWidth(0)
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +000083#if ENABLE(CSS_EXCLUSIONS)
84 , m_segment(0)
85#endif
hyatt@apple.com5950bd42011-09-27 20:39:57 +000086 , m_isFirstLine(isFirstLine)
87 {
88 ASSERT(block);
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +000089#if ENABLE(CSS_EXCLUSIONS)
commit-queue@webkit.org3a988eb2012-09-26 19:55:35 +000090 ExclusionShapeInsideInfo* exclusionShapeInsideInfo = layoutExclusionShapeInsideInfo(m_block);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +000091 if (exclusionShapeInsideInfo)
92 m_segment = exclusionShapeInsideInfo->currentSegment();
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +000093#endif
hyatt@apple.com5950bd42011-09-27 20:39:57 +000094 updateAvailableWidth();
95 }
eae@chromium.org271b04a2012-09-26 16:25:41 +000096 bool fitsOnLine() const { return currentWidth() <= m_availableWidth; }
97 bool fitsOnLine(float extra) const { return currentWidth() + extra <= m_availableWidth; }
hyatt@apple.com5950bd42011-09-27 20:39:57 +000098 float currentWidth() const { return m_committedWidth + m_uncommittedWidth; }
99
100 // FIXME: We should eventually replace these three functions by ones that work on a higher abstraction.
101 float uncommittedWidth() const { return m_uncommittedWidth; }
102 float committedWidth() const { return m_committedWidth; }
103 float availableWidth() const { return m_availableWidth; }
104
robert@webkit.org0903cf52012-12-11 18:14:16 +0000105 void updateAvailableWidth(LayoutUnit minimumHeight = 0);
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000106 void shrinkAvailableWidthForNewFloatIfNeeded(RenderBlock::FloatingObject*);
107 void addUncommittedWidth(float delta) { m_uncommittedWidth += delta; }
108 void commit()
109 {
110 m_committedWidth += m_uncommittedWidth;
111 m_uncommittedWidth = 0;
112 }
113 void applyOverhang(RenderRubyRun*, RenderObject* startRenderer, RenderObject* endRenderer);
114 void fitBelowFloats();
115
116private:
117 void computeAvailableWidthFromLeftAndRight()
118 {
eae@chromium.orgb1054552012-06-05 04:42:55 +0000119 m_availableWidth = max(0.0f, m_right - m_left) + m_overhangWidth;
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000120 }
121
122private:
123 RenderBlock* m_block;
124 float m_uncommittedWidth;
125 float m_committedWidth;
126 float m_overhangWidth; // The amount by which |m_availableWidth| has been inflated to account for possible contraction due to ruby overhang.
eae@chromium.orgb1054552012-06-05 04:42:55 +0000127 float m_left;
128 float m_right;
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000129 float m_availableWidth;
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +0000130#if ENABLE(CSS_EXCLUSIONS)
131 const LineSegment* m_segment;
132#endif
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000133 bool m_isFirstLine;
134};
135
robert@webkit.org0903cf52012-12-11 18:14:16 +0000136static LayoutUnit logicalHeightForLine(RenderBlock* block, bool isFirstLine, LayoutUnit replacedHeight = 0)
robert@webkit.org4f76df92012-07-03 17:41:35 +0000137{
robert@webkit.org0903cf52012-12-11 18:14:16 +0000138 if (!block->document()->inNoQuirksMode() && replacedHeight)
139 return replacedHeight;
robert@webkit.org4f76df92012-07-03 17:41:35 +0000140
robert@webkit.org0903cf52012-12-11 18:14:16 +0000141 if (!(block->style(isFirstLine)->lineBoxContain() & LineBoxContainBlock))
142 return 0;
143
144 return max<LayoutUnit>(replacedHeight, block->lineHeight(isFirstLine, block->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
robert@webkit.org4f76df92012-07-03 17:41:35 +0000145}
146
robert@webkit.org0903cf52012-12-11 18:14:16 +0000147inline void LineWidth::updateAvailableWidth(LayoutUnit replacedHeight)
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000148{
leviw@chromium.org0e230612012-03-01 19:33:44 +0000149 LayoutUnit height = m_block->logicalHeight();
robert@webkit.org0903cf52012-12-11 18:14:16 +0000150 LayoutUnit logicalHeight = logicalHeightForLine(m_block, m_isFirstLine, replacedHeight);
robert@webkit.org4f76df92012-07-03 17:41:35 +0000151 m_left = m_block->logicalLeftOffsetForLine(height, m_isFirstLine, logicalHeight);
152 m_right = m_block->logicalRightOffsetForLine(height, m_isFirstLine, logicalHeight);
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000153
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +0000154#if ENABLE(CSS_EXCLUSIONS)
155 if (m_segment) {
156 m_left = max<float>(m_segment->logicalLeft, m_left);
157 m_right = min<float>(m_segment->logicalRight, m_right);
158 }
159#endif
160
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000161 computeAvailableWidthFromLeftAndRight();
162}
163
164inline void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(RenderBlock::FloatingObject* newFloat)
165{
leviw@chromium.orgd32486e2012-03-16 10:52:56 +0000166 LayoutUnit height = m_block->logicalHeight();
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000167 if (height < m_block->logicalTopForFloat(newFloat) || height >= m_block->logicalBottomForFloat(newFloat))
168 return;
169
170 if (newFloat->type() == RenderBlock::FloatingObject::FloatLeft) {
eae@chromium.org5adcf0f2012-10-30 13:36:31 +0000171 float newLeft = m_block->logicalRightForFloat(newFloat);
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000172 if (m_isFirstLine && m_block->style()->isLeftToRightDirection())
robert@webkit.org3bb2d322012-10-21 09:44:21 +0000173 newLeft += floorToInt(m_block->textIndentOffset());
174 m_left = max<float>(m_left, newLeft);
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000175 } else {
eae@chromium.org5adcf0f2012-10-30 13:36:31 +0000176 float newRight = m_block->logicalLeftForFloat(newFloat);
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000177 if (m_isFirstLine && !m_block->style()->isLeftToRightDirection())
robert@webkit.org3bb2d322012-10-21 09:44:21 +0000178 newRight -= floorToInt(m_block->textIndentOffset());
179 m_right = min<float>(m_right, newRight);
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000180 }
181
182 computeAvailableWidthFromLeftAndRight();
183}
184
185void LineWidth::applyOverhang(RenderRubyRun* rubyRun, RenderObject* startRenderer, RenderObject* endRenderer)
186{
187 int startOverhang;
188 int endOverhang;
189 rubyRun->getOverhang(m_isFirstLine, startRenderer, endRenderer, startOverhang, endOverhang);
190
191 startOverhang = min<int>(startOverhang, m_committedWidth);
192 m_availableWidth += startOverhang;
193
194 endOverhang = max(min<int>(endOverhang, m_availableWidth - currentWidth()), 0);
195 m_availableWidth += endOverhang;
196 m_overhangWidth += startOverhang + endOverhang;
197}
198
199void LineWidth::fitBelowFloats()
200{
201 ASSERT(!m_committedWidth);
202 ASSERT(!fitsOnLine());
203
leviw@chromium.orgd32486e2012-03-16 10:52:56 +0000204 LayoutUnit floatLogicalBottom;
205 LayoutUnit lastFloatLogicalBottom = m_block->logicalHeight();
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000206 float newLineWidth = m_availableWidth;
207 float newLineLeft = m_left;
208 float newLineRight = m_right;
209 while (true) {
210 floatLogicalBottom = m_block->nextFloatLogicalBottomBelow(lastFloatLogicalBottom);
hyatt@apple.comd4d3bcf2011-10-04 18:17:04 +0000211 if (floatLogicalBottom <= lastFloatLogicalBottom)
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000212 break;
213
214 newLineLeft = m_block->logicalLeftOffsetForLine(floatLogicalBottom, m_isFirstLine);
215 newLineRight = m_block->logicalRightOffsetForLine(floatLogicalBottom, m_isFirstLine);
216 newLineWidth = max(0.0f, newLineRight - newLineLeft);
217 lastFloatLogicalBottom = floatLogicalBottom;
218 if (newLineWidth >= m_uncommittedWidth)
219 break;
220 }
221
222 if (newLineWidth > m_availableWidth) {
223 m_block->setLogicalHeight(lastFloatLogicalBottom);
224 m_availableWidth = newLineWidth + m_overhangWidth;
225 m_left = newLineLeft;
226 m_right = newLineRight;
227 }
228}
229
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000230class LineInfo {
231public:
232 LineInfo()
233 : m_isFirstLine(true)
234 , m_isLastLine(false)
235 , m_isEmpty(true)
236 , m_previousLineBrokeCleanly(true)
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000237 , m_floatPaginationStrut(0)
robert@webkit.org8cbab142011-12-30 20:58:29 +0000238 , m_runsFromLeadingWhitespace(0)
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000239 { }
240
241 bool isFirstLine() const { return m_isFirstLine; }
242 bool isLastLine() const { return m_isLastLine; }
243 bool isEmpty() const { return m_isEmpty; }
244 bool previousLineBrokeCleanly() const { return m_previousLineBrokeCleanly; }
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000245 LayoutUnit floatPaginationStrut() const { return m_floatPaginationStrut; }
robert@webkit.org8cbab142011-12-30 20:58:29 +0000246 unsigned runsFromLeadingWhitespace() const { return m_runsFromLeadingWhitespace; }
247 void resetRunsFromLeadingWhitespace() { m_runsFromLeadingWhitespace = 0; }
248 void incrementRunsFromLeadingWhitespace() { m_runsFromLeadingWhitespace++; }
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000249
250 void setFirstLine(bool firstLine) { m_isFirstLine = firstLine; }
251 void setLastLine(bool lastLine) { m_isLastLine = lastLine; }
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000252 void setEmpty(bool empty, RenderBlock* block = 0, LineWidth* lineWidth = 0)
253 {
254 if (m_isEmpty == empty)
255 return;
256 m_isEmpty = empty;
257 if (!empty && block && floatPaginationStrut()) {
258 block->setLogicalHeight(block->logicalHeight() + floatPaginationStrut());
259 setFloatPaginationStrut(0);
260 lineWidth->updateAvailableWidth();
261 }
262 }
263
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000264 void setPreviousLineBrokeCleanly(bool previousLineBrokeCleanly) { m_previousLineBrokeCleanly = previousLineBrokeCleanly; }
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000265 void setFloatPaginationStrut(LayoutUnit strut) { m_floatPaginationStrut = strut; }
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000266
267private:
268 bool m_isFirstLine;
269 bool m_isLastLine;
270 bool m_isEmpty;
271 bool m_previousLineBrokeCleanly;
hyatt@apple.com5950bd42011-09-27 20:39:57 +0000272 LayoutUnit m_floatPaginationStrut;
robert@webkit.org8cbab142011-12-30 20:58:29 +0000273 unsigned m_runsFromLeadingWhitespace;
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000274};
hyatt1d5d87b2007-04-24 04:55:54 +0000275
eae@chromium.orgee8613e2011-11-12 01:12:58 +0000276static inline LayoutUnit borderPaddingMarginStart(RenderInline* child)
hyattffe78712003-02-11 01:59:29 +0000277{
hyatt@apple.com0415e5d2010-10-07 17:40:25 +0000278 return child->marginStart() + child->paddingStart() + child->borderStart();
hyattffe78712003-02-11 01:59:29 +0000279}
280
eae@chromium.orgee8613e2011-11-12 01:12:58 +0000281static inline LayoutUnit borderPaddingMarginEnd(RenderInline* child)
rniwa@webkit.org33a346a2011-04-06 17:06:14 +0000282{
283 return child->marginEnd() + child->paddingEnd() + child->borderEnd();
284}
285
robert@webkit.org6dc9a232012-10-08 18:44:03 +0000286static bool shouldAddBorderPaddingMargin(RenderObject* child, bool &checkSide)
287{
288 if (!child || (child->isText() && !toRenderText(child)->textLength()))
289 return true;
290 checkSide = false;
291 return checkSide;
292}
293
eae@chromium.orgee8613e2011-11-12 01:12:58 +0000294static LayoutUnit inlineLogicalWidth(RenderObject* child, bool start = true, bool end = true)
hyattffe78712003-02-11 01:59:29 +0000295{
hyatt1d5d87b2007-04-24 04:55:54 +0000296 unsigned lineDepth = 1;
eae@chromium.orgee8613e2011-11-12 01:12:58 +0000297 LayoutUnit extraWidth = 0;
hyattffe78712003-02-11 01:59:29 +0000298 RenderObject* parent = child->parent();
rniwa@webkit.org63db8cb2011-04-06 21:08:20 +0000299 while (parent->isRenderInline() && lineDepth++ < cMaxLineDepth) {
300 RenderInline* parentAsRenderInline = toRenderInline(parent);
robert@webkit.org6dc9a232012-10-08 18:44:03 +0000301 if (start && shouldAddBorderPaddingMargin(child->previousSibling(), start))
rniwa@webkit.org63db8cb2011-04-06 21:08:20 +0000302 extraWidth += borderPaddingMarginStart(parentAsRenderInline);
robert@webkit.org6dc9a232012-10-08 18:44:03 +0000303 if (end && shouldAddBorderPaddingMargin(child->nextSibling(), end))
rniwa@webkit.org63db8cb2011-04-06 21:08:20 +0000304 extraWidth += borderPaddingMarginEnd(parentAsRenderInline);
robert@webkit.org6dc9a232012-10-08 18:44:03 +0000305 if (!start && !end)
306 return extraWidth;
hyattffe78712003-02-11 01:59:29 +0000307 child = parent;
308 parent = child->parent();
309 }
310 return extraWidth;
311}
312
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000313static void determineDirectionality(TextDirection& dir, InlineIterator iter)
leviw@chromium.org7781b6a2011-06-27 22:01:38 +0000314{
315 while (!iter.atEnd()) {
316 if (iter.atParagraphSeparator())
317 return;
318 if (UChar current = iter.current()) {
319 Direction charDirection = direction(current);
320 if (charDirection == LeftToRight) {
321 dir = LTR;
322 return;
323 }
324 if (charDirection == RightToLeft || charDirection == RightToLeftArabic) {
325 dir = RTL;
326 return;
327 }
328 }
329 iter.increment();
330 }
331}
332
hyatt@apple.comb3466af2009-06-13 06:04:40 +0000333static void checkMidpoints(LineMidpointState& lineMidpointState, InlineIterator& lBreak)
hyattfe99c872003-07-31 22:25:29 +0000334{
335 // Check to see if our last midpoint is a start point beyond the line break. If so,
hyattdca76e92005-11-02 08:52:50 +0000336 // shave it off the list, and shave off a trailing space if the previous end point doesn't
337 // preserve whitespace.
eric@webkit.org8c25a592011-03-29 13:18:11 +0000338 if (lBreak.m_obj && lineMidpointState.numMidpoints && !(lineMidpointState.numMidpoints % 2)) {
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000339 InlineIterator* midpoints = lineMidpointState.midpoints.data();
340 InlineIterator& endpoint = midpoints[lineMidpointState.numMidpoints - 2];
341 const InlineIterator& startpoint = midpoints[lineMidpointState.numMidpoints - 1];
mitz@apple.com15035e62008-07-05 20:44:44 +0000342 InlineIterator currpoint = endpoint;
hyattfe99c872003-07-31 22:25:29 +0000343 while (!currpoint.atEnd() && currpoint != startpoint && currpoint != lBreak)
mitz@apple.com1a301772008-03-11 18:30:36 +0000344 currpoint.increment();
hyattfe99c872003-07-31 22:25:29 +0000345 if (currpoint == lBreak) {
346 // We hit the line break before the start point. Shave off the start point.
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000347 lineMidpointState.numMidpoints--;
eric@webkit.org8c25a592011-03-29 13:18:11 +0000348 if (endpoint.m_obj->style()->collapseWhiteSpace())
eric@webkit.org86a865a2011-03-29 15:30:41 +0000349 endpoint.m_pos--;
hyattfe99c872003-07-31 22:25:29 +0000350 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000351 }
hyattfe99c872003-07-31 22:25:29 +0000352}
353
hyatt@apple.comb3466af2009-06-13 06:04:40 +0000354static void addMidpoint(LineMidpointState& lineMidpointState, const InlineIterator& midpoint)
hyatt85586af2003-02-19 23:22:42 +0000355{
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000356 if (lineMidpointState.midpoints.size() <= lineMidpointState.numMidpoints)
357 lineMidpointState.midpoints.grow(lineMidpointState.numMidpoints + 10);
hyatt85586af2003-02-19 23:22:42 +0000358
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000359 InlineIterator* midpoints = lineMidpointState.midpoints.data();
360 midpoints[lineMidpointState.numMidpoints++] = midpoint;
hyatt85586af2003-02-19 23:22:42 +0000361}
362
eric@webkit.org5bee2942011-04-08 02:12:31 +0000363static inline BidiRun* createRun(int start, int end, RenderObject* obj, InlineBidiResolver& resolver)
364{
365 return new (obj->renderArena()) BidiRun(start, end, obj, resolver.context(), resolver.dir());
366}
367
368void RenderBlock::appendRunsForObject(BidiRunList<BidiRun>& runs, int start, int end, RenderObject* obj, InlineBidiResolver& resolver)
hyatt33f8d492002-11-12 21:44:52 +0000369{
leviw@chromium.orgd8df17d2012-05-24 21:47:47 +0000370 if (start > end || shouldSkipCreatingRunsForObject(obj))
hyatteb003b82002-11-15 22:35:10 +0000371 return;
hyatt85586af2003-02-19 23:22:42 +0000372
hyatt@apple.comb3466af2009-06-13 06:04:40 +0000373 LineMidpointState& lineMidpointState = resolver.midpointState();
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000374 bool haveNextMidpoint = (lineMidpointState.currentMidpoint < lineMidpointState.numMidpoints);
mitz@apple.com15035e62008-07-05 20:44:44 +0000375 InlineIterator nextMidpoint;
hyatt85586af2003-02-19 23:22:42 +0000376 if (haveNextMidpoint)
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000377 nextMidpoint = lineMidpointState.midpoints[lineMidpointState.currentMidpoint];
378 if (lineMidpointState.betweenMidpoints) {
eric@webkit.org8c25a592011-03-29 13:18:11 +0000379 if (!(haveNextMidpoint && nextMidpoint.m_obj == obj))
hyatt33f8d492002-11-12 21:44:52 +0000380 return;
eric@webkit.org060caf62011-05-03 22:11:39 +0000381 // This is a new start point. Stop ignoring objects and
hyatt33f8d492002-11-12 21:44:52 +0000382 // adjust our start.
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000383 lineMidpointState.betweenMidpoints = false;
eric@webkit.org86a865a2011-03-29 15:30:41 +0000384 start = nextMidpoint.m_pos;
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000385 lineMidpointState.currentMidpoint++;
hyatt33f8d492002-11-12 21:44:52 +0000386 if (start < end)
eric@webkit.org5bee2942011-04-08 02:12:31 +0000387 return appendRunsForObject(runs, start, end, obj, resolver);
mitz@apple.com15035e62008-07-05 20:44:44 +0000388 } else {
eric@webkit.org8c25a592011-03-29 13:18:11 +0000389 if (!haveNextMidpoint || (obj != nextMidpoint.m_obj)) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000390 runs.addRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000391 return;
392 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000393
hyatt78b85132004-03-29 20:07:45 +0000394 // An end midpoint has been encountered within our object. We
hyatt33f8d492002-11-12 21:44:52 +0000395 // need to go ahead and append a run with our endpoint.
eric@webkit.org86a865a2011-03-29 15:30:41 +0000396 if (static_cast<int>(nextMidpoint.m_pos + 1) <= end) {
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000397 lineMidpointState.betweenMidpoints = true;
398 lineMidpointState.currentMidpoint++;
eric@webkit.org86a865a2011-03-29 15:30:41 +0000399 if (nextMidpoint.m_pos != UINT_MAX) { // UINT_MAX means stop at the object and don't include any of it.
400 if (static_cast<int>(nextMidpoint.m_pos + 1) > start)
eric@webkit.org5bee2942011-04-08 02:12:31 +0000401 runs.addRun(createRun(start, nextMidpoint.m_pos + 1, obj, resolver));
402 return appendRunsForObject(runs, nextMidpoint.m_pos + 1, end, obj, resolver);
hyattc64f9fc2003-03-14 01:25:59 +0000403 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000404 } else
eric@webkit.org5bee2942011-04-08 02:12:31 +0000405 runs.addRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000406 }
407}
408
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000409static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRootLineBox, bool isOnlyRun = false)
410{
411 if (isRootLineBox)
eric@webkit.org49b9d952009-07-03 01:29:07 +0000412 return toRenderBlock(obj)->createAndAppendRootInlineBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000413
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000414 if (obj->isText()) {
415 InlineTextBox* textBox = toRenderText(obj)->createInlineTextBox();
416 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
417 // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.)
418 if (obj->isBR())
hyatt@apple.comce8ee2a2010-08-27 20:29:34 +0000419 textBox->setIsText(isOnlyRun || obj->document()->inNoQuirksMode());
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000420 return textBox;
421 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000422
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000423 if (obj->isBox())
424 return toRenderBox(obj)->createInlineBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000425
eric@webkit.org49b9d952009-07-03 01:29:07 +0000426 return toRenderInline(obj)->createAndAppendInlineFlowBox();
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000427}
428
429static inline void dirtyLineBoxesForRenderer(RenderObject* o, bool fullLayout)
430{
431 if (o->isText()) {
commit-queue@webkit.orgd639fb72012-09-01 19:46:16 +0000432 RenderText* renderText = toRenderText(o);
433 renderText->updateTextIfNeeded(); // FIXME: Counters depend on this hack. No clue why. Should be investigated and removed.
434 renderText->dirtyLineBoxes(fullLayout);
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000435 } else
436 toRenderInline(o)->dirtyLineBoxes(fullLayout);
437}
438
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000439static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox)
440{
441 do {
442 if (parentBox->isConstructed() || parentBox->nextOnLine())
443 return true;
444 parentBox = parentBox->parent();
445 } while (parentBox);
446 return false;
447}
448
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000449InlineFlowBox* RenderBlock::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox, bool startNewSegment)
hyattffe78712003-02-11 01:59:29 +0000450{
451 // See if we have an unconstructed line box for this object that is also
452 // the last item on the line.
hyatt1d5d87b2007-04-24 04:55:54 +0000453 unsigned lineDepth = 1;
hyatt1d5d87b2007-04-24 04:55:54 +0000454 InlineFlowBox* parentBox = 0;
455 InlineFlowBox* result = 0;
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000456 bool hasDefaultLineBoxContain = style()->lineBoxContain() == RenderStyle::initialLineBoxContain();
hyatt1d5d87b2007-04-24 04:55:54 +0000457 do {
hyatt@apple.com415d8de2009-01-26 22:29:19 +0000458 ASSERT(obj->isRenderInline() || obj == this);
eric@webkit.org060caf62011-05-03 22:11:39 +0000459
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000460 RenderInline* inlineFlow = (obj != this) ? toRenderInline(obj) : 0;
461
hyatt1d5d87b2007-04-24 04:55:54 +0000462 // Get the last box we made for this render object.
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000463 parentBox = inlineFlow ? inlineFlow->lastLineBox() : toRenderBlock(obj)->lastLineBox();
hyattffe78712003-02-11 01:59:29 +0000464
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000465 // If this box or its ancestor is constructed then it is from a previous line, and we need
466 // to make a new box for our line. If this box or its ancestor is unconstructed but it has
hyatt1d5d87b2007-04-24 04:55:54 +0000467 // something following it on the line, then we know we have to make a new box
468 // as well. In this situation our inline has actually been split in two on
469 // the same line (this can happen with very fancy language mixtures).
470 bool constructedNewBox = false;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000471 bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000472 bool mustCreateBoxesToRoot = startNewSegment && !(parentBox && parentBox->isRootInlineBox());
473 bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox) && !mustCreateBoxesToRoot;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000474 if (allowedToConstructNewBox && !canUseExistingParentBox) {
hyatt1d5d87b2007-04-24 04:55:54 +0000475 // We need to make a new box for this render object. Once
476 // made, we need to place it at the end of the current line.
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000477 InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this);
hyatt1d5d87b2007-04-24 04:55:54 +0000478 ASSERT(newBox->isInlineFlowBox());
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000479 parentBox = toInlineFlowBox(newBox);
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000480 parentBox->setFirstLineStyleBit(lineInfo.isFirstLine());
hyatt@apple.com2a5eb212011-03-22 23:21:54 +0000481 parentBox->setIsHorizontal(isHorizontalWritingMode());
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000482 if (!hasDefaultLineBoxContain)
483 parentBox->clearDescendantsHaveSameLineHeightAndBaseline();
hyatt1d5d87b2007-04-24 04:55:54 +0000484 constructedNewBox = true;
485 }
mitz@apple.come1364202008-02-28 01:06:41 +0000486
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000487 if (constructedNewBox || canUseExistingParentBox) {
488 if (!result)
489 result = parentBox;
hyatt1d5d87b2007-04-24 04:55:54 +0000490
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000491 // If we have hit the block itself, then |box| represents the root
492 // inline box for the line, and it doesn't have to be appended to any parent
493 // inline.
494 if (childBox)
495 parentBox->addToLine(childBox);
mitz@apple.come1364202008-02-28 01:06:41 +0000496
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000497 if (!constructedNewBox || obj == this)
498 break;
mitz@apple.come1364202008-02-28 01:06:41 +0000499
eric@webkit.org060caf62011-05-03 22:11:39 +0000500 childBox = parentBox;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000501 }
mitz@apple.come1364202008-02-28 01:06:41 +0000502
hyatt1d5d87b2007-04-24 04:55:54 +0000503 // If we've exceeded our line depth, then jump straight to the root and skip all the remaining
504 // intermediate inline flows.
505 obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent();
hyattffe78712003-02-11 01:59:29 +0000506
hyatt1d5d87b2007-04-24 04:55:54 +0000507 } while (true);
508
509 return result;
hyattffe78712003-02-11 01:59:29 +0000510}
511
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000512template <typename CharacterType>
513static inline bool endsWithASCIISpaces(const CharacterType* characters, unsigned pos, unsigned end)
514{
515 while (isASCIISpace(characters[pos])) {
516 pos++;
517 if (pos >= end)
518 return true;
519 }
520 return false;
521}
522
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000523static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns)
hyattffe78712003-02-11 01:59:29 +0000524{
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000525 BidiRun* run = bidiRuns.logicallyLastRun();
526 if (!run)
527 return true;
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000528 unsigned pos = run->stop();
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000529 RenderObject* r = run->m_object;
530 if (!r->isText() || r->isBR())
531 return false;
532 RenderText* renderText = toRenderText(r);
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000533 unsigned length = renderText->textLength();
534 if (pos >= length)
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000535 return true;
536
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000537 if (renderText->is8Bit())
538 return endsWithASCIISpaces(renderText->characters8(), pos, length);
539 return endsWithASCIISpaces(renderText->characters16(), pos, length);
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000540}
541
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000542RootInlineBox* RenderBlock::constructLine(BidiRunList<BidiRun>& bidiRuns, const LineInfo& lineInfo)
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000543{
544 ASSERT(bidiRuns.firstRun());
hyattffe78712003-02-11 01:59:29 +0000545
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000546 bool rootHasSelectedChildren = false;
hyattffe78712003-02-11 01:59:29 +0000547 InlineFlowBox* parentBox = 0;
robert@webkit.org8cbab142011-12-30 20:58:29 +0000548 int runCount = bidiRuns.runCount() - lineInfo.runsFromLeadingWhitespace();
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000549 for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) {
hyattffe78712003-02-11 01:59:29 +0000550 // Create a box for our object.
robert@webkit.org8cbab142011-12-30 20:58:29 +0000551 bool isOnlyRun = (runCount == 1);
552 if (runCount == 2 && !r->m_object->isListMarker())
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000553 isOnlyRun = (!style()->isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->m_object->isListMarker();
mitz@apple.come1364202008-02-28 01:06:41 +0000554
robert@webkit.org56e5a9f2012-02-17 21:10:42 +0000555 if (lineInfo.isEmpty())
556 continue;
557
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000558 InlineBox* box = createInlineBoxForRenderer(r->m_object, false, isOnlyRun);
mitz@apple.com576e84e2008-04-24 19:09:48 +0000559 r->m_box = box;
560
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000561 ASSERT(box);
562 if (!box)
563 continue;
hyattffe78712003-02-11 01:59:29 +0000564
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000565 if (!rootHasSelectedChildren && box->renderer()->selectionState() != RenderObject::SelectionNone)
566 rootHasSelectedChildren = true;
567
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000568 // If we have no parent box yet, or if the run is not simply a sibling,
569 // then we need to construct inline boxes as necessary to properly enclose the
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000570 // run's inline box. Segments can only be siblings at the root level, as
571 // they are positioned separately.
572#if ENABLE(CSS_EXCLUSIONS)
573 bool runStartsSegment = r->m_startsSegment;
574#else
575 bool runStartsSegment = false;
576#endif
577 if (!parentBox || parentBox->renderer() != r->m_object->parent() || runStartsSegment)
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000578 // Create new inline boxes all the way back to the appropriate insertion point.
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000579 parentBox = createLineBoxes(r->m_object->parent(), lineInfo, box, runStartsSegment);
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000580 else {
581 // Append the inline box to this line.
582 parentBox->addToLine(box);
583 }
mitz@apple.com576e84e2008-04-24 19:09:48 +0000584
macpherson@chromium.org258babf2011-06-10 06:20:58 +0000585 bool visuallyOrdered = r->m_object->style()->rtlOrdering() == VisualOrder;
xji@chromium.org6b0c0172011-02-14 19:21:12 +0000586 box->setBidiLevel(r->level());
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000587
588 if (box->isInlineTextBox()) {
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000589 InlineTextBox* text = toInlineTextBox(box);
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000590 text->setStart(r->m_start);
591 text->setLen(r->m_stop - r->m_start);
rniwa@webkit.org296fcae2012-03-29 09:48:42 +0000592 text->setDirOverride(r->dirOverride(visuallyOrdered));
mitz@apple.comb2107652010-06-21 16:54:52 +0000593 if (r->m_hasHyphen)
594 text->setHasHyphen(true);
hyatt0c3a9862004-02-23 21:26:26 +0000595 }
hyattffe78712003-02-11 01:59:29 +0000596 }
597
598 // We should have a root inline box. It should be unconstructed and
599 // be the last continuation of our line list.
ggarenf9f32ae2007-03-26 20:08:53 +0000600 ASSERT(lastLineBox() && !lastLineBox()->isConstructed());
hyattffe78712003-02-11 01:59:29 +0000601
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000602 // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box
603 // from the bidi runs walk above has a selection state.
604 if (rootHasSelectedChildren)
605 lastLineBox()->root()->setHasSelectedChildren(true);
606
hyattffe78712003-02-11 01:59:29 +0000607 // Set bits on our inline flow boxes that indicate which sides should
608 // paint borders/margins/padding. This knowledge will ultimately be used when
609 // we determine the horizontal positions and widths of all the inline boxes on
610 // the line.
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000611 bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->m_object && bidiRuns.logicallyLastRun()->m_object->isText() ? !reachedEndOfTextRenderer(bidiRuns) : true;
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000612 lastLineBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, bidiRuns.logicallyLastRun()->m_object);
hyattffe78712003-02-11 01:59:29 +0000613
614 // Now mark the line boxes as being constructed.
615 lastLineBox()->setConstructed();
616
617 // Return the last line.
hyatt0c3a9862004-02-23 21:26:26 +0000618 return lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000619}
620
mitz@apple.com390fa322011-02-24 23:07:06 +0000621ETextAlign RenderBlock::textAlignmentForLine(bool endsWithSoftBreak) const
622{
623 ETextAlign alignment = style()->textAlign();
624 if (!endsWithSoftBreak && alignment == JUSTIFY)
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000625 alignment = TASTART;
mitz@apple.com390fa322011-02-24 23:07:06 +0000626
627 return alignment;
628}
629
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000630static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
631{
632 // The direction of the block should determine what happens with wide lines.
633 // In particular with RTL blocks, wide lines should still spill out to the left.
634 if (isLeftToRightDirection) {
635 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
636 trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
637 return;
638 }
639
640 if (trailingSpaceRun)
641 trailingSpaceRun->m_box->setLogicalWidth(0);
642 else if (totalLogicalWidth > availableLogicalWidth)
643 logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
644}
645
646static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
647{
648 // Wide lines spill out of the block based off direction.
649 // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
650 // side of the block.
651 if (isLeftToRightDirection) {
652 if (trailingSpaceRun) {
653 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
654 trailingSpaceRun->m_box->setLogicalWidth(0);
655 }
656 if (totalLogicalWidth < availableLogicalWidth)
657 logicalLeft += availableLogicalWidth - totalLogicalWidth;
658 return;
659 }
660
661 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
662 trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
663 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
664 } else
665 logicalLeft += availableLogicalWidth - totalLogicalWidth;
666}
667
668static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
669{
670 float trailingSpaceWidth = 0;
671 if (trailingSpaceRun) {
672 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
673 trailingSpaceWidth = min(trailingSpaceRun->m_box->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2);
674 trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceWidth));
675 }
676 if (isLeftToRightDirection)
677 logicalLeft += max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0);
678 else
679 logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
680}
681
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000682void RenderBlock::setMarginsForRubyRun(BidiRun* run, RenderRubyRun* renderer, RenderObject* previousObject, const LineInfo& lineInfo)
683{
684 int startOverhang;
685 int endOverhang;
686 RenderObject* nextObject = 0;
687 for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) {
simon.fraser@apple.com2f071852012-06-25 00:11:30 +0000688 if (!runWithNextObject->m_object->isOutOfFlowPositioned() && !runWithNextObject->m_box->isLineBreak()) {
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000689 nextObject = runWithNextObject->m_object;
690 break;
691 }
692 }
693 renderer->getOverhang(lineInfo.isFirstLine(), renderer->style()->isLeftToRightDirection() ? previousObject : nextObject, renderer->style()->isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang);
694 setMarginStartForChild(renderer, -startOverhang);
695 setMarginEndForChild(renderer, -endOverhang);
696}
697
commit-queue@webkit.orge60bb902011-09-08 19:18:43 +0000698static inline float measureHyphenWidth(RenderText* renderer, const Font& font)
699{
700 RenderStyle* style = renderer->style();
701 return font.width(RenderBlock::constructTextRun(renderer, font, style->hyphenString().string(), style));
702}
703
enrica@apple.com885c84d2012-10-10 05:48:51 +0000704class WordMeasurement {
705public:
706 WordMeasurement()
707 : renderer(0)
708 , width(0)
709 , startOffset(0)
710 , endOffset(0)
711 {
712 }
713
714 RenderText* renderer;
715 float width;
716 int startOffset;
717 int endOffset;
718 HashSet<const SimpleFontData*> fallbackFonts;
719};
720
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000721static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText* renderer, float xPos, const LineInfo& lineInfo,
enrica@apple.com885c84d2012-10-10 05:48:51 +0000722 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000723{
leviw@chromium.orgb6b22be2012-10-11 02:47:06 +0000724#if !(PLATFORM(CHROMIUM) && OS(DARWIN))
enrica@apple.com885c84d2012-10-10 05:48:51 +0000725 UNUSED_PARAM(wordMeasurements);
726#endif
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000727 HashSet<const SimpleFontData*> fallbackFonts;
728 GlyphOverflow glyphOverflow;
729
enrica@apple.com885c84d2012-10-10 05:48:51 +0000730 const Font& font = renderer->style(lineInfo.isFirstLine())->font();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000731 // Always compute glyph overflow if the block's line-box-contain value is "glyphs".
732 if (lineBox->fitsToGlyphs()) {
733 // If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization
734 // will keep us from computing glyph bounds in nearly all cases.
735 bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading();
736 int baselineShift = lineBox->verticalPositionForBox(run->m_box, verticalPositionCache);
enrica@apple.com885c84d2012-10-10 05:48:51 +0000737 int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0;
738 int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0;
739 int boxAscent = font.fontMetrics().ascent() - baselineShift;
740 int boxDescent = font.fontMetrics().descent() + baselineShift;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000741 if (boxAscent > rootDescent || boxDescent > rootAscent)
742 glyphOverflow.computeBounds = true;
743 }
744
leviw@chromium.orgd32486e2012-03-16 10:52:56 +0000745 LayoutUnit hyphenWidth = 0;
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000746 if (toInlineTextBox(run->m_box)->hasHyphen()) {
zimmermann@webkit.org8a7e7ff2011-05-24 15:27:36 +0000747 const Font& font = renderer->style(lineInfo.isFirstLine())->font();
commit-queue@webkit.orge60bb902011-09-08 19:18:43 +0000748 hyphenWidth = measureHyphenWidth(renderer, font);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000749 }
enrica@apple.com885c84d2012-10-10 05:48:51 +0000750 float measuredWidth = 0;
751
leviw@chromium.orgb6b22be2012-10-11 02:47:06 +0000752#if !(PLATFORM(CHROMIUM) && OS(DARWIN))
enrica@apple.com885c84d2012-10-10 05:48:51 +0000753 bool kerningIsEnabled = font.typesettingFeatures() & Kerning;
754
755 // Since we don't cache glyph overflows, we need to re-measure the run if
756 // the style is linebox-contain: glyph.
757
758 if (!lineBox->fitsToGlyphs() && renderer->canUseSimpleFontCodePath()) {
759 int lastEndOffset = run->m_start;
760 for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOffset < run->m_stop; ++i) {
761 const WordMeasurement& wordMeasurement = wordMeasurements[i];
762 if (wordMeasurement.width <=0 || wordMeasurement.startOffset == wordMeasurement.endOffset)
763 continue;
764 if (wordMeasurement.renderer != renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop)
765 continue;
766
767 lastEndOffset = wordMeasurement.endOffset;
768 if (kerningIsEnabled && lastEndOffset == run->m_stop) {
769 measuredWidth += renderer->width(wordMeasurement.startOffset, lastEndOffset - wordMeasurement.startOffset, xPos, lineInfo.isFirstLine());
770 if (i > 0)
771 measuredWidth += renderer->style()->wordSpacing();
772 } else
773 measuredWidth += wordMeasurement.width;
774 if (!wordMeasurement.fallbackFonts.isEmpty()) {
775 HashSet<const SimpleFontData*>::const_iterator end = wordMeasurement.fallbackFonts.end();
776 for (HashSet<const SimpleFontData*>::const_iterator it = wordMeasurement.fallbackFonts.begin(); it != end; ++it)
777 fallbackFonts.add(*it);
778 }
779 }
780 if (measuredWidth && lastEndOffset != run->m_stop) {
781 // If we don't have enough cached data, we'll measure the run again.
782 measuredWidth = 0;
783 fallbackFonts.clear();
784 }
785 }
786#endif
787
788 if (!measuredWidth)
789 measuredWidth = renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow);
790
791 run->m_box->setLogicalWidth(measuredWidth + hyphenWidth);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000792 if (!fallbackFonts.isEmpty()) {
793 ASSERT(run->m_box->isText());
caio.oliveira@openbossa.org4c11ee02012-03-29 18:48:23 +0000794 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000795 ASSERT(it->value.first.isEmpty());
796 copyToVector(fallbackFonts, it->value.first);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000797 run->m_box->parent()->clearDescendantsHaveSameLineHeightAndBaseline();
798 }
799 if ((glyphOverflow.top || glyphOverflow.bottom || glyphOverflow.left || glyphOverflow.right)) {
800 ASSERT(run->m_box->isText());
caio.oliveira@openbossa.org4c11ee02012-03-29 18:48:23 +0000801 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000802 it->value.second = glyphOverflow;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000803 run->m_box->clearKnownToHaveNoOverflow();
804 }
805}
806
807static inline void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth)
808{
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000809 if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth)
810 return;
811
812 size_t i = 0;
813 for (BidiRun* r = firstRun; r; r = r->next()) {
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000814#if ENABLE(CSS_EXCLUSIONS)
815 // This method is called once per segment, do not move past the current segment.
816 if (r->m_startsSegment)
817 break;
818#endif
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000819 if (!r->m_box || r == trailingSpaceRun)
820 continue;
821
822 if (r->m_object->isText()) {
823 unsigned opportunitiesInRun = expansionOpportunities[i++];
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000824
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000825 ASSERT(opportunitiesInRun <= expansionOpportunityCount);
826
827 // Only justify text if whitespace is collapsed.
828 if (r->m_object->style()->collapseWhiteSpace()) {
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000829 InlineTextBox* textBox = toInlineTextBox(r->m_box);
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000830 int expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
831 textBox->setExpansion(expansion);
832 totalLogicalWidth += expansion;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000833 }
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000834 expansionOpportunityCount -= opportunitiesInRun;
835 if (!expansionOpportunityCount)
836 break;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000837 }
838 }
839}
840
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000841void RenderBlock::updateLogicalWidthForAlignment(const ETextAlign& textAlign, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount)
842{
843 // Armed with the total width of the line (without justification),
844 // we now examine our text-align property in order to determine where to position the
845 // objects horizontally. The total width of the line can be increased if we end up
846 // justifying text.
847 switch (textAlign) {
848 case LEFT:
849 case WEBKIT_LEFT:
850 updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
851 break;
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000852 case RIGHT:
853 case WEBKIT_RIGHT:
854 updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
855 break;
856 case CENTER:
857 case WEBKIT_CENTER:
858 updateLogicalWidthForCenterAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
859 break;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000860 case JUSTIFY:
861 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
862 if (expansionOpportunityCount) {
863 if (trailingSpaceRun) {
864 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
865 trailingSpaceRun->m_box->setLogicalWidth(0);
866 }
867 break;
868 }
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000869 // Fall through
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000870 case TASTART:
871 if (style()->isLeftToRightDirection())
872 updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
873 else
874 updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
875 break;
876 case TAEND:
877 if (style()->isLeftToRightDirection())
878 updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
879 else
880 updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
881 break;
882 }
883}
884
robert@webkit.org0903cf52012-12-11 18:14:16 +0000885static void updateLogicalInlinePositions(RenderBlock* block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, LayoutUnit boxLogicalHeight)
886{
887 LayoutUnit lineLogicalHeight = logicalHeightForLine(block, firstLine, boxLogicalHeight);
888 lineLogicalLeft = block->pixelSnappedLogicalLeftOffsetForLine(block->logicalHeight(), firstLine, lineLogicalHeight);
889 lineLogicalRight = block->pixelSnappedLogicalRightOffsetForLine(block->logicalHeight(), firstLine, lineLogicalHeight);
890 availableLogicalWidth = lineLogicalRight - lineLogicalLeft;
891}
892
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000893void RenderBlock::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, const LineInfo& lineInfo, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd,
enrica@apple.com885c84d2012-10-10 05:48:51 +0000894 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
hyattffe78712003-02-11 01:59:29 +0000895{
mitz@apple.com390fa322011-02-24 23:07:06 +0000896 ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
robert@webkit.org4f76df92012-07-03 17:41:35 +0000897
robert@webkit.org328ecd02012-08-09 21:12:44 +0000898 // CSS 2.1: "'Text-indent' only affects a line if it is the first formatted line of an element. For example, the first line of an anonymous block
899 // box is only affected if it is the first child of its parent element."
900 bool firstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this);
robert@webkit.org0903cf52012-12-11 18:14:16 +0000901 float lineLogicalLeft;
902 float lineLogicalRight;
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000903 float availableLogicalWidth;
robert@webkit.org0903cf52012-12-11 18:14:16 +0000904 updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, firstLine, 0);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000905 bool needsWordSpacing;
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +0000906#if ENABLE(CSS_EXCLUSIONS)
commit-queue@webkit.org3a988eb2012-09-26 19:55:35 +0000907 ExclusionShapeInsideInfo* exclusionShapeInsideInfo = layoutExclusionShapeInsideInfo(this);
908 if (exclusionShapeInsideInfo && exclusionShapeInsideInfo->hasSegments()) {
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000909 BidiRun* segmentStart = firstRun;
910 const SegmentList& segments = exclusionShapeInsideInfo->segments();
911 float logicalLeft = max<float>(roundToInt(segments[0].logicalLeft), lineLogicalLeft);
912 float logicalRight = min<float>(floorToInt(segments[0].logicalRight), lineLogicalRight);
913 float startLogicalLeft = logicalLeft;
914 float endLogicalRight = logicalLeft;
915 float minLogicalLeft = logicalLeft;
916 float maxLogicalRight = logicalLeft;
917 lineBox->beginPlacingBoxRangesInInlineDirection(logicalLeft);
918 for (size_t i = 0; i < segments.size(); i++) {
919 if (i) {
920 logicalLeft = max<float>(roundToInt(segments[i].logicalLeft), lineLogicalLeft);
921 logicalRight = min<float>(floorToInt(segments[i].logicalRight), lineLogicalRight);
922 }
923 availableLogicalWidth = logicalRight - logicalLeft;
924 BidiRun* newSegmentStart = computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, logicalLeft, availableLogicalWidth, segmentStart, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
925 needsWordSpacing = false;
926 endLogicalRight = lineBox->placeBoxRangeInInlineDirection(segmentStart->m_box, newSegmentStart ? newSegmentStart->m_box : 0, logicalLeft, minLogicalLeft, maxLogicalRight, needsWordSpacing, textBoxDataMap);
927 if (!newSegmentStart || !newSegmentStart->next())
928 break;
929 ASSERT(newSegmentStart->m_startsSegment);
930 // Discard the empty segment start marker bidi runs
931 segmentStart = newSegmentStart->next();
932 }
933 lineBox->endPlacingBoxRangesInInlineDirection(startLogicalLeft, endLogicalRight, minLogicalLeft, maxLogicalRight);
934 return;
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +0000935 }
936#endif
robert@webkit.org0903cf52012-12-11 18:14:16 +0000937
938 if (firstRun && firstRun->m_object->isReplaced()) {
939 RenderBox* renderBox = toRenderBox(firstRun->m_object);
940 updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, firstLine, renderBox->logicalHeight());
941 }
942
943 computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000944 // The widths of all runs are now known. We can now place every inline box (and
945 // compute accurate widths for the inline flow boxes).
946 needsWordSpacing = false;
947 lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing, textBoxDataMap);
948}
mitz@apple.com390fa322011-02-24 23:07:06 +0000949
robert@webkit.org0903cf52012-12-11 18:14:16 +0000950BidiRun* RenderBlock::computeInlineDirectionPositionsForSegment(RootInlineBox* lineBox, const LineInfo& lineInfo, ETextAlign textAlign, float& logicalLeft,
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000951 float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache,
952 WordMeasurements& wordMeasurements)
953{
darin06dcb9c2005-08-15 04:31:09 +0000954 bool needsWordSpacing = false;
mitz@apple.com390fa322011-02-24 23:07:06 +0000955 float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();
mitz@apple.com86470c82011-01-27 01:39:27 +0000956 unsigned expansionOpportunityCount = 0;
957 bool isAfterExpansion = true;
958 Vector<unsigned, 16> expansionOpportunities;
mitz@apple.comddb59872011-04-05 05:21:16 +0000959 RenderObject* previousObject = 0;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000960
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000961 BidiRun* r = firstRun;
962 for (; r; r = r->next()) {
963#if ENABLE(CSS_EXCLUSIONS)
964 // Once we have reached the start of the next segment, we have finished
965 // computing the positions for this segment's contents.
966 if (r->m_startsSegment)
967 break;
968#endif
simon.fraser@apple.com2f071852012-06-25 00:11:30 +0000969 if (!r->m_box || r->m_object->isOutOfFlowPositioned() || r->m_box->isLineBreak())
hyatt98ee7e42003-05-14 01:39:15 +0000970 continue; // Positioned objects are only participating to figure out their
971 // correct static x position. They have no effect on the width.
hyatt0c05e102006-04-14 08:15:00 +0000972 // Similarly, line break boxes have no effect on the width.
mitz@apple.come1364202008-02-28 01:06:41 +0000973 if (r->m_object->isText()) {
darin@apple.com36744d62009-01-25 20:23:04 +0000974 RenderText* rt = toRenderText(r->m_object);
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000975 if (textAlign == JUSTIFY && r != trailingSpaceRun) {
mitz@apple.com80968932011-03-26 00:46:26 +0000976 if (!isAfterExpansion)
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000977 toInlineTextBox(r->m_box)->setCanHaveLeadingExpansion(true);
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000978 unsigned opportunitiesInRun;
979 if (rt->is8Bit())
980 opportunitiesInRun = Font::expansionOpportunityCount(rt->characters8() + r->m_start, r->m_stop - r->m_start, r->m_box->direction(), isAfterExpansion);
981 else
982 opportunitiesInRun = Font::expansionOpportunityCount(rt->characters16() + r->m_start, r->m_stop - r->m_start, r->m_box->direction(), isAfterExpansion);
mitz@apple.com86470c82011-01-27 01:39:27 +0000983 expansionOpportunities.append(opportunitiesInRun);
984 expansionOpportunityCount += opportunitiesInRun;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000985 }
986
mitz@apple.come1364202008-02-28 01:06:41 +0000987 if (int length = rt->textLength()) {
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000988 if (!r->m_start && needsWordSpacing && isSpaceOrNewline(rt->characterAt(r->m_start)))
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +0000989 totalLogicalWidth += rt->style(lineInfo.isFirstLine())->font().wordSpacing();
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000990 needsWordSpacing = !isSpaceOrNewline(rt->characterAt(r->m_stop - 1)) && r->m_stop == length;
darin06dcb9c2005-08-15 04:31:09 +0000991 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000992
enrica@apple.com885c84d2012-10-10 05:48:51 +0000993 setLogicalWidthForTextRun(lineBox, r, rt, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
mitz@apple.com86470c82011-01-27 01:39:27 +0000994 } else {
995 isAfterExpansion = false;
996 if (!r->m_object->isRenderInline()) {
997 RenderBox* renderBox = toRenderBox(r->m_object);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000998 if (renderBox->isRubyRun())
999 setMarginsForRubyRun(r, toRenderRubyRun(renderBox), previousObject, lineInfo);
mitz@apple.com86470c82011-01-27 01:39:27 +00001000 r->m_box->setLogicalWidth(logicalWidthForChild(renderBox));
1001 totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox);
1002 }
hyattffe78712003-02-11 01:59:29 +00001003 }
hyatt4b381692003-03-10 21:11:59 +00001004
hyatt@apple.com546a2482010-10-07 21:16:49 +00001005 totalLogicalWidth += r->m_box->logicalWidth();
mitz@apple.comddb59872011-04-05 05:21:16 +00001006 previousObject = r->m_object;
hyattffe78712003-02-11 01:59:29 +00001007 }
1008
mitz@apple.com86470c82011-01-27 01:39:27 +00001009 if (isAfterExpansion && !expansionOpportunities.isEmpty()) {
1010 expansionOpportunities.last()--;
1011 expansionOpportunityCount--;
1012 }
1013
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00001014 updateLogicalWidthForAlignment(textAlign, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount);
hyattffe78712003-02-11 01:59:29 +00001015
leviw@chromium.orgd70a0072011-05-03 23:28:11 +00001016 computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth);
mitz@apple.come1364202008-02-28 01:06:41 +00001017
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001018 return r;
hyattffe78712003-02-11 01:59:29 +00001019}
1020
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +00001021void RenderBlock::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
1022 VerticalPositionCache& verticalPositionCache)
hyattffe78712003-02-11 01:59:29 +00001023{
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +00001024 setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache));
hyattffe78712003-02-11 01:59:29 +00001025
1026 // Now make sure we place replaced render objects correctly.
mitz@apple.com887f3592008-02-25 22:03:08 +00001027 for (BidiRun* r = firstRun; r; r = r->next()) {
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +00001028 ASSERT(r->m_box);
mitz@apple.come1364202008-02-28 01:06:41 +00001029 if (!r->m_box)
eseidel789896f2005-11-27 22:52:09 +00001030 continue; // Skip runs with no line boxes.
hyatt0c3a9862004-02-23 21:26:26 +00001031
hyatt98ee7e42003-05-14 01:39:15 +00001032 // Align positioned boxes with the top of the line box. This is
1033 // a reasonable approximation of an appropriate y position.
simon.fraser@apple.com2f071852012-06-25 00:11:30 +00001034 if (r->m_object->isOutOfFlowPositioned())
hyatt@apple.com35d2ad52010-10-20 18:17:36 +00001035 r->m_box->setLogicalTop(logicalHeight());
hyatt98ee7e42003-05-14 01:39:15 +00001036
1037 // Position is used to properly position both replaced elements and
1038 // to update the static normal flow x/y of positioned elements.
hyatt@apple.com6a551ad2009-02-11 22:43:12 +00001039 if (r->m_object->isText())
1040 toRenderText(r->m_object)->positionLineBox(r->m_box);
1041 else if (r->m_object->isBox())
1042 toRenderBox(r->m_object)->positionLineBox(r->m_box);
hyatt98ee7e42003-05-14 01:39:15 +00001043 }
mitz@apple.coma927be62008-03-21 05:30:19 +00001044 // Positioned objects and zero-length text nodes destroy their boxes in
1045 // position(), which unnecessarily dirties the line.
1046 lineBox->markDirty(false);
hyattffe78712003-02-11 01:59:29 +00001047}
kociendabb0c24b2001-08-24 14:24:40 +00001048
mitz@apple.comc13ea5f2008-04-18 21:18:26 +00001049static inline bool isCollapsibleSpace(UChar character, RenderText* renderer)
1050{
1051 if (character == ' ' || character == '\t' || character == softHyphen)
1052 return true;
1053 if (character == '\n')
1054 return !renderer->style()->preserveNewline();
1055 if (character == noBreakSpace)
1056 return renderer->style()->nbspMode() == SPACE;
1057 return false;
1058}
1059
hyatt@apple.com14e332d2011-03-25 21:57:07 +00001060
1061static void setStaticPositions(RenderBlock* block, RenderBox* child)
1062{
1063 // FIXME: The math here is actually not really right. It's a best-guess approximation that
1064 // will work for the common cases
1065 RenderObject* containerBlock = child->container();
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001066 LayoutUnit blockHeight = block->logicalHeight();
hyatt@apple.com14e332d2011-03-25 21:57:07 +00001067 if (containerBlock->isRenderInline()) {
1068 // A relative positioned inline encloses us. In this case, we also have to determine our
1069 // position as though we were an inline. Set |staticInlinePosition| and |staticBlockPosition| on the relative positioned
1070 // inline so that we can obtain the value later.
robert@webkit.org82903f42012-08-28 19:18:40 +00001071 toRenderInline(containerBlock)->layer()->setStaticInlinePosition(block->startAlignedOffsetForLine(blockHeight, false));
hyatt@apple.com14e332d2011-03-25 21:57:07 +00001072 toRenderInline(containerBlock)->layer()->setStaticBlockPosition(blockHeight);
1073 }
1074
1075 if (child->style()->isOriginalDisplayInlineType())
robert@webkit.org82903f42012-08-28 19:18:40 +00001076 block->setStaticInlinePositionForChild(child, blockHeight, block->startAlignedOffsetForLine(blockHeight, false));
hyatt@apple.com14e332d2011-03-25 21:57:07 +00001077 else
hyatt@apple.coma5cac3f2011-10-12 18:51:17 +00001078 block->setStaticInlinePositionForChild(child, blockHeight, block->startOffsetForContent(blockHeight));
hyatt@apple.com14e332d2011-03-25 21:57:07 +00001079 child->layer()->setStaticBlockPosition(blockHeight);
1080}
1081
msaboff@apple.com142fc202012-10-18 18:03:14 +00001082template <typename CharacterType>
1083static inline int findFirstTrailingSpace(RenderText* lastText, const CharacterType* characters, int start, int stop)
1084{
1085 int firstSpace = stop;
1086 while (firstSpace > start) {
1087 UChar current = characters[firstSpace - 1];
1088 if (!isCollapsibleSpace(current, lastText))
1089 break;
1090 firstSpace--;
1091 }
1092
1093 return firstSpace;
1094}
1095
eric@webkit.org5bee2942011-04-08 02:12:31 +00001096inline BidiRun* RenderBlock::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext)
eric@webkit.org0894bb82011-04-03 08:29:40 +00001097{
eric@webkit.org5bee2942011-04-08 02:12:31 +00001098 if (!bidiRuns.runCount()
1099 || !bidiRuns.logicallyLastRun()->m_object->style()->breakOnlyAfterWhiteSpace()
1100 || !bidiRuns.logicallyLastRun()->m_object->style()->autoWrap())
eric@webkit.org0894bb82011-04-03 08:29:40 +00001101 return 0;
1102
eric@webkit.org5bee2942011-04-08 02:12:31 +00001103 BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun();
eric@webkit.org0894bb82011-04-03 08:29:40 +00001104 RenderObject* lastObject = trailingSpaceRun->m_object;
1105 if (!lastObject->isText())
1106 return 0;
1107
1108 RenderText* lastText = toRenderText(lastObject);
msaboff@apple.com142fc202012-10-18 18:03:14 +00001109 int firstSpace;
1110 if (lastText->is8Bit())
1111 firstSpace = findFirstTrailingSpace(lastText, lastText->characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop());
1112 else
1113 firstSpace = findFirstTrailingSpace(lastText, lastText->characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop());
1114
eric@webkit.org0894bb82011-04-03 08:29:40 +00001115 if (firstSpace == trailingSpaceRun->stop())
1116 return 0;
1117
1118 TextDirection direction = style()->direction();
eric@webkit.org5bee2942011-04-08 02:12:31 +00001119 bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun());
eric@webkit.org0894bb82011-04-03 08:29:40 +00001120 if (firstSpace != trailingSpaceRun->start()) {
eric@webkit.org5bee2942011-04-08 02:12:31 +00001121 BidiContext* baseContext = currentContext;
eric@webkit.org0894bb82011-04-03 08:29:40 +00001122 while (BidiContext* parent = baseContext->parent())
1123 baseContext = parent;
1124
1125 BidiRun* newTrailingRun = new (renderArena()) BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->m_object, baseContext, OtherNeutral);
1126 trailingSpaceRun->m_stop = firstSpace;
1127 if (direction == LTR)
eric@webkit.org5bee2942011-04-08 02:12:31 +00001128 bidiRuns.addRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +00001129 else
eric@webkit.org5bee2942011-04-08 02:12:31 +00001130 bidiRuns.prependRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +00001131 trailingSpaceRun = newTrailingRun;
1132 return trailingSpaceRun;
1133 }
1134 if (!shouldReorder)
1135 return trailingSpaceRun;
1136
1137 if (direction == LTR) {
eric@webkit.org5bee2942011-04-08 02:12:31 +00001138 bidiRuns.moveRunToEnd(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +00001139 trailingSpaceRun->m_level = 0;
1140 } else {
eric@webkit.org5bee2942011-04-08 02:12:31 +00001141 bidiRuns.moveRunToBeginning(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +00001142 trailingSpaceRun->m_level = 1;
1143 }
1144 return trailingSpaceRun;
1145}
1146
mitz@apple.comd17e8c02011-04-16 21:59:36 +00001147void RenderBlock::appendFloatingObjectToLastLine(FloatingObject* floatingObject)
1148{
mitz@apple.com0c4ce9f2011-05-04 02:20:02 +00001149 ASSERT(!floatingObject->m_originatingLine);
1150 floatingObject->m_originatingLine = lastRootBox();
mitz@apple.comd17e8c02011-04-16 21:59:36 +00001151 lastRootBox()->appendFloat(floatingObject->renderer());
1152}
1153
eric@webkit.orga26de042011-09-08 18:46:01 +00001154// FIXME: This should be a BidiStatus constructor or create method.
rniwa@webkit.orgc275acf2012-03-05 23:09:22 +00001155static inline BidiStatus statusWithDirection(TextDirection textDirection, bool isOverride)
eric@webkit.orga26de042011-09-08 18:46:01 +00001156{
1157 WTF::Unicode::Direction direction = textDirection == LTR ? LeftToRight : RightToLeft;
rniwa@webkit.orgc275acf2012-03-05 23:09:22 +00001158 RefPtr<BidiContext> context = BidiContext::create(textDirection == LTR ? 0 : 1, direction, isOverride, FromStyleOrDOM);
eric@webkit.orga26de042011-09-08 18:46:01 +00001159
1160 // This copies BidiStatus and may churn the ref on BidiContext. I doubt it matters.
1161 return BidiStatus(direction, direction, direction, context.release());
1162}
1163
1164// FIXME: BidiResolver should have this logic.
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001165static inline void constructBidiRunsForSegment(InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfRuns, VisualDirectionOverride override, bool previousLineBrokeCleanly)
eric@webkit.orga26de042011-09-08 18:46:01 +00001166{
1167 // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead
1168 // of the resolver owning the runs.
1169 ASSERT(&topResolver.runs() == &bidiRuns);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001170 RenderObject* currentRoot = topResolver.position().root();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001171 topResolver.createBidiRunsForLine(endOfRuns, override, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +00001172
1173 while (!topResolver.isolatedRuns().isEmpty()) {
1174 // It does not matter which order we resolve the runs as long as we resolve them all.
1175 BidiRun* isolatedRun = topResolver.isolatedRuns().last();
1176 topResolver.isolatedRuns().removeLast();
1177
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001178 RenderObject* startObj = isolatedRun->object();
1179
eric@webkit.orga26de042011-09-08 18:46:01 +00001180 // Only inlines make sense with unicode-bidi: isolate (blocks are already isolated).
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001181 // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the
1182 // tree to see which parent inline is the isolate. We could change enterIsolate
1183 // to take a RenderObject and do this logic there, but that would be a layering
1184 // violation for BidiResolver (which knows nothing about RenderObject).
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001185 RenderInline* isolatedInline = toRenderInline(containingIsolate(startObj, currentRoot));
eric@webkit.orga26de042011-09-08 18:46:01 +00001186 InlineBidiResolver isolatedResolver;
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001187 EUnicodeBidi unicodeBidi = isolatedInline->style()->unicodeBidi();
1188 TextDirection direction;
1189 if (unicodeBidi == Plaintext)
1190 determineDirectionality(direction, InlineIterator(isolatedInline, isolatedRun->object(), 0));
1191 else {
rniwa@webkit.org4d4bd332012-08-20 21:34:11 +00001192 ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride);
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001193 direction = isolatedInline->style()->direction();
1194 }
rniwa@webkit.orgc275acf2012-03-05 23:09:22 +00001195 isolatedResolver.setStatus(statusWithDirection(direction, isOverride(unicodeBidi)));
eric@webkit.orga26de042011-09-08 18:46:01 +00001196
1197 // FIXME: The fact that we have to construct an Iterator here
1198 // currently prevents this code from moving into BidiResolver.
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001199 if (!bidiFirstSkippingEmptyInlines(isolatedInline, &isolatedResolver))
rniwa@webkit.org2343fab2011-11-25 20:21:06 +00001200 continue;
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001201
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001202 // The starting position is the beginning of the first run within the isolate that was identified
1203 // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the
1204 // first run within the isolate.
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001205 InlineIterator iter = InlineIterator(isolatedInline, startObj, isolatedRun->m_start);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001206 isolatedResolver.setPositionIgnoringNestedIsolates(iter);
eric@webkit.orga26de042011-09-08 18:46:01 +00001207
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001208 // We stop at the next end of line; we may re-enter this isolate in the next call to constructBidiRuns().
eric@webkit.orga26de042011-09-08 18:46:01 +00001209 // FIXME: What should end and previousLineBrokeCleanly be?
1210 // rniwa says previousLineBrokeCleanly is just a WinIE hack and could always be false here?
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001211 isolatedResolver.createBidiRunsForLine(endOfRuns, NoVisualOverride, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +00001212 // Note that we do not delete the runs from the resolver.
rniwa@webkit.orgd0ad8882012-05-23 07:37:07 +00001213 // We're not guaranteed to get any BidiRuns in the previous step. If we don't, we allow the placeholder
leviw@chromium.orgf0d6f362012-05-23 04:00:47 +00001214 // itself to be turned into an InlineBox. We can't remove it here without potentially losing track of
1215 // the logically last run.
1216 if (isolatedResolver.runs().runCount())
1217 bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs());
eric@webkit.orga26de042011-09-08 18:46:01 +00001218
1219 // If we encountered any nested isolate runs, just move them
1220 // to the top resolver's list for later processing.
1221 if (!isolatedResolver.isolatedRuns().isEmpty()) {
1222 topResolver.isolatedRuns().append(isolatedResolver.isolatedRuns());
1223 isolatedResolver.isolatedRuns().clear();
1224 }
1225 }
1226}
1227
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001228static inline void constructBidiRunsForLine(const RenderBlock* block, InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfLine, VisualDirectionOverride override, bool previousLineBrokeCleanly)
1229{
1230#if !ENABLE(CSS_EXCLUSIONS)
1231 UNUSED_PARAM(block);
1232 constructBidiRunsForSegment(topResolver, bidiRuns, endOfLine, override, previousLineBrokeCleanly);
1233#else
1234 ExclusionShapeInsideInfo* exclusionShapeInsideInfo = layoutExclusionShapeInsideInfo(block);
1235 if (!exclusionShapeInsideInfo || !exclusionShapeInsideInfo->hasSegments()) {
1236 constructBidiRunsForSegment(topResolver, bidiRuns, endOfLine, override, previousLineBrokeCleanly);
1237 return;
1238 }
1239
1240 const SegmentRangeList& segmentRanges = exclusionShapeInsideInfo->segmentRanges();
1241 ASSERT(segmentRanges.size());
1242
1243 for (size_t i = 0; i < segmentRanges.size(); i++) {
1244 InlineIterator segmentStart = segmentRanges[i].start;
1245 InlineIterator segmentEnd = segmentRanges[i].end;
1246 if (i) {
1247 ASSERT(segmentStart.m_obj);
1248 BidiRun* segmentMarker = createRun(segmentStart.m_pos, segmentStart.m_pos, segmentStart.m_obj, topResolver);
1249 segmentMarker->m_startsSegment = true;
1250 bidiRuns.addRun(segmentMarker);
1251 // Do not collapse midpoints between segments
1252 topResolver.midpointState().betweenMidpoints = false;
1253 }
1254 topResolver.setPosition(segmentStart, numberOfIsolateAncestors(segmentStart));
1255 constructBidiRunsForSegment(topResolver, bidiRuns, segmentEnd, override, previousLineBrokeCleanly);
1256 }
1257#endif
1258}
1259
eric@webkit.org45e33a52011-05-04 11:51:09 +00001260// This function constructs line boxes for all of the text runs in the resolver and computes their position.
enrica@apple.com885c84d2012-10-10 05:48:51 +00001261RootInlineBox* RenderBlock::createLineBoxesFromBidiRuns(BidiRunList<BidiRun>& bidiRuns, const InlineIterator& end, LineInfo& lineInfo, VerticalPositionCache& verticalPositionCache, BidiRun* trailingSpaceRun, WordMeasurements& wordMeasurements)
eric@webkit.org45e33a52011-05-04 11:51:09 +00001262{
1263 if (!bidiRuns.runCount())
1264 return 0;
1265
1266 // FIXME: Why is this only done when we had runs?
1267 lineInfo.setLastLine(!end.m_obj);
1268
1269 RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo);
1270 if (!lineBox)
1271 return 0;
1272
1273 lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly());
1274
1275#if ENABLE(SVG)
1276 bool isSVGRootInlineBox = lineBox->isSVGRootInlineBox();
1277#else
1278 bool isSVGRootInlineBox = false;
1279#endif
1280
1281 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
1282
1283 // Now we position all of our text runs horizontally.
1284 if (!isSVGRootInlineBox)
enrica@apple.com885c84d2012-10-10 05:48:51 +00001285 computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache, wordMeasurements);
eric@webkit.org45e33a52011-05-04 11:51:09 +00001286
1287 // Now position our text runs vertically.
1288 computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache);
1289
1290#if ENABLE(SVG)
1291 // SVG text layout code computes vertical & horizontal positions on its own.
1292 // Note that we still need to execute computeVerticalPositionsForLine() as
1293 // it calls InlineTextBox::positionLineBox(), which tracks whether the box
1294 // contains reversed text or not. If we wouldn't do that editing and thus
1295 // text selection in RTL boxes would not work as expected.
1296 if (isSVGRootInlineBox) {
1297 ASSERT(isSVGText());
1298 static_cast<SVGRootInlineBox*>(lineBox)->computePerCharacterLayoutInformation();
1299 }
1300#endif
1301
1302 // Compute our overflow now.
1303 lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap);
1304
1305#if PLATFORM(MAC)
1306 // Highlight acts as an overflow inflation.
1307 if (style()->highlight() != nullAtom)
1308 lineBox->addHighlightOverflow();
1309#endif
1310 return lineBox;
1311}
1312
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001313// Like LayoutState for layout(), LineLayoutState keeps track of global information
1314// during an entire linebox tree layout pass (aka layoutInlineChildren).
1315class LineLayoutState {
1316public:
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001317 LineLayoutState(bool fullLayout, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001318 : m_lastFloat(0)
1319 , m_endLine(0)
1320 , m_floatIndex(0)
1321 , m_endLineLogicalTop(0)
1322 , m_endLineMatched(false)
1323 , m_checkForFloatsFromLastLine(false)
1324 , m_isFullLayout(fullLayout)
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001325 , m_repaintLogicalTop(repaintLogicalTop)
1326 , m_repaintLogicalBottom(repaintLogicalBottom)
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001327 , m_usesRepaintBounds(false)
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001328 { }
1329
1330 void markForFullLayout() { m_isFullLayout = true; }
1331 bool isFullLayout() const { return m_isFullLayout; }
1332
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001333 bool usesRepaintBounds() const { return m_usesRepaintBounds; }
1334
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001335 void setRepaintRange(LayoutUnit logicalHeight)
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001336 {
1337 m_usesRepaintBounds = true;
1338 m_repaintLogicalTop = m_repaintLogicalBottom = logicalHeight;
1339 }
1340
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001341 void updateRepaintRangeFromBox(RootInlineBox* box, LayoutUnit paginationDelta = 0)
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001342 {
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001343 m_usesRepaintBounds = true;
eae@chromium.org9717cd82012-11-07 18:33:44 +00001344 m_repaintLogicalTop = min(m_repaintLogicalTop, box->logicalTopVisualOverflow() + min<LayoutUnit>(paginationDelta, 0));
1345 m_repaintLogicalBottom = max(m_repaintLogicalBottom, box->logicalBottomVisualOverflow() + max<LayoutUnit>(paginationDelta, 0));
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001346 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001347
1348 bool endLineMatched() const { return m_endLineMatched; }
1349 void setEndLineMatched(bool endLineMatched) { m_endLineMatched = endLineMatched; }
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001350
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001351 bool checkForFloatsFromLastLine() const { return m_checkForFloatsFromLastLine; }
1352 void setCheckForFloatsFromLastLine(bool check) { m_checkForFloatsFromLastLine = check; }
1353
1354 LineInfo& lineInfo() { return m_lineInfo; }
1355 const LineInfo& lineInfo() const { return m_lineInfo; }
1356
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001357 LayoutUnit endLineLogicalTop() const { return m_endLineLogicalTop; }
1358 void setEndLineLogicalTop(LayoutUnit logicalTop) { m_endLineLogicalTop = logicalTop; }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001359
1360 RootInlineBox* endLine() const { return m_endLine; }
1361 void setEndLine(RootInlineBox* line) { m_endLine = line; }
1362
1363 RenderBlock::FloatingObject* lastFloat() const { return m_lastFloat; }
1364 void setLastFloat(RenderBlock::FloatingObject* lastFloat) { m_lastFloat = lastFloat; }
1365
1366 Vector<RenderBlock::FloatWithRect>& floats() { return m_floats; }
1367
1368 unsigned floatIndex() const { return m_floatIndex; }
1369 void setFloatIndex(unsigned floatIndex) { m_floatIndex = floatIndex; }
1370
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001371private:
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001372 Vector<RenderBlock::FloatWithRect> m_floats;
1373 RenderBlock::FloatingObject* m_lastFloat;
1374 RootInlineBox* m_endLine;
1375 LineInfo m_lineInfo;
1376 unsigned m_floatIndex;
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001377 LayoutUnit m_endLineLogicalTop;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001378 bool m_endLineMatched;
1379 bool m_checkForFloatsFromLastLine;
1380
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001381 bool m_isFullLayout;
1382
1383 // FIXME: Should this be a range object instead of two ints?
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001384 LayoutUnit& m_repaintLogicalTop;
1385 LayoutUnit& m_repaintLogicalBottom;
1386
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001387 bool m_usesRepaintBounds;
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001388};
1389
1390static void deleteLineRange(LineLayoutState& layoutState, RenderArena* arena, RootInlineBox* startLine, RootInlineBox* stopLine = 0)
eric@webkit.org455d90e2011-05-09 22:27:27 +00001391{
1392 RootInlineBox* boxToDelete = startLine;
1393 while (boxToDelete && boxToDelete != stopLine) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001394 layoutState.updateRepaintRangeFromBox(boxToDelete);
eric@webkit.orge2532d92011-05-16 23:10:49 +00001395 // Note: deleteLineRange(renderArena(), firstRootBox()) is not identical to deleteLineBoxTree().
1396 // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing.
eric@webkit.org455d90e2011-05-09 22:27:27 +00001397 RootInlineBox* next = boxToDelete->nextRootBox();
1398 boxToDelete->deleteLine(arena);
1399 boxToDelete = next;
1400 }
1401}
1402
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001403void RenderBlock::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild)
eric@webkit.org060caf62011-05-03 22:11:39 +00001404{
1405 // We want to skip ahead to the first dirty line
1406 InlineBidiResolver resolver;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001407 RootInlineBox* startLine = determineStartPosition(layoutState, resolver);
eric@webkit.org060caf62011-05-03 22:11:39 +00001408
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001409 unsigned consecutiveHyphenatedLines = 0;
1410 if (startLine) {
1411 for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox())
1412 consecutiveHyphenatedLines++;
1413 }
1414
eric@webkit.org060caf62011-05-03 22:11:39 +00001415 // FIXME: This would make more sense outside of this function, but since
1416 // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call
1417 // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html.
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001418 if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) {
eric@webkit.org218b4e02012-03-28 19:25:02 +00001419 setNeedsLayout(true, MarkOnlyThis); // Mark as needing a full layout to force us to repaint.
eric@webkit.org060caf62011-05-03 22:11:39 +00001420 RenderView* v = view();
1421 if (v && !v->doingFullRepaint() && hasLayer()) {
1422 // Because we waited until we were already inside layout to discover
1423 // that the block really needed a full layout, we missed our chance to repaint the layer
1424 // before layout started. Luckily the layer has cached the repaint rect for its original
1425 // position and size, and so we can use that to make a repaint happen now.
leviw@chromium.org52066f32012-09-12 19:17:03 +00001426 repaintUsingContainer(containerForRepaint(), pixelSnappedIntRect(layer()->repaintRect()));
eric@webkit.org060caf62011-05-03 22:11:39 +00001427 }
1428 }
1429
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001430 if (m_floatingObjects && !m_floatingObjects->set().isEmpty())
1431 layoutState.setLastFloat(m_floatingObjects->set().last());
eric@webkit.org060caf62011-05-03 22:11:39 +00001432
1433 // We also find the first clean line and extract these lines. We will add them back
1434 // if we determine that we're able to synchronize after handling all our dirty lines.
1435 InlineIterator cleanLineStart;
1436 BidiStatus cleanLineBidiStatus;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001437 if (!layoutState.isFullLayout() && startLine)
1438 determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus);
eric@webkit.org060caf62011-05-03 22:11:39 +00001439
1440 if (startLine) {
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001441 if (!layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001442 layoutState.setRepaintRange(logicalHeight());
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001443 deleteLineRange(layoutState, renderArena(), startLine);
eric@webkit.org060caf62011-05-03 22:11:39 +00001444 }
1445
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001446 if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001447 // If the last line before the start line ends with a line break that clear floats,
1448 // adjust the height accordingly.
1449 // A line break can be either the first or the last object on a line, depending on its direction.
1450 if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) {
1451 RenderObject* lastObject = lastLeafChild->renderer();
1452 if (!lastObject->isBR())
1453 lastObject = lastRootBox()->firstLeafChild()->renderer();
1454 if (lastObject->isBR()) {
1455 EClear clear = lastObject->style()->clear();
1456 if (clear != CNONE)
1457 newLine(clear);
1458 }
1459 }
1460 }
1461
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001462 layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001463 linkToEndLineIfNeeded(layoutState);
1464 repaintDirtyFloats(layoutState.floats());
1465}
eric@webkit.org060caf62011-05-03 22:11:39 +00001466
mitz@apple.com6a859602012-08-27 15:31:56 +00001467RenderBlock::RenderTextInfo::RenderTextInfo()
1468 : m_text(0)
mitz@apple.comd4c153d2012-09-16 23:36:41 +00001469 , m_font(0)
mitz@apple.com6a859602012-08-27 15:31:56 +00001470{
1471}
1472
1473RenderBlock::RenderTextInfo::~RenderTextInfo()
1474{
1475}
1476
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001477// Before restarting the layout loop with a new logicalHeight, remove all floats that were added and reset the resolver.
1478inline const InlineIterator& RenderBlock::restartLayoutRunsAndFloatsInRange(LayoutUnit oldLogicalHeight, LayoutUnit newLogicalHeight, FloatingObject* lastFloatFromPreviousLine, InlineBidiResolver& resolver, const InlineIterator& oldEnd)
1479{
1480 removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight);
1481 setLogicalHeight(newLogicalHeight);
1482 resolver.setPositionIgnoringNestedIsolates(oldEnd);
1483 return oldEnd;
1484}
1485
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001486void RenderBlock::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001487{
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00001488 RenderStyle* styleToUse = style();
eric@webkit.org060caf62011-05-03 22:11:39 +00001489 bool paginated = view()->layoutState() && view()->layoutState()->isPaginated();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001490 LineMidpointState& lineMidpointState = resolver.midpointState();
1491 InlineIterator end = resolver.position();
1492 bool checkForEndLineMatch = layoutState.endLine();
mitz@apple.com6a859602012-08-27 15:31:56 +00001493 RenderTextInfo renderTextInfo;
eric@webkit.org060caf62011-05-03 22:11:39 +00001494 VerticalPositionCache verticalPositionCache;
1495
leviw@chromium.org1a508692011-05-05 00:01:11 +00001496 LineBreaker lineBreaker(this);
1497
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +00001498#if ENABLE(CSS_EXCLUSIONS)
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +00001499 LayoutUnit absoluteLogicalTop;
commit-queue@webkit.org3a988eb2012-09-26 19:55:35 +00001500 ExclusionShapeInsideInfo* exclusionShapeInsideInfo = layoutExclusionShapeInsideInfo(this);
1501 if (exclusionShapeInsideInfo) {
commit-queue@webkit.orgca34a192012-12-18 18:43:38 +00001502 ASSERT(exclusionShapeInsideInfo->ownerBlock() == this || allowsExclusionShapeInsideInfoSharing());
commit-queue@webkit.org3a988eb2012-09-26 19:55:35 +00001503 if (exclusionShapeInsideInfo != this->exclusionShapeInsideInfo()) {
commit-queue@webkit.org5fe2dfd2012-10-26 19:57:52 +00001504 // FIXME Bug 100284: If subsequent LayoutStates are pushed, we will have to add
1505 // their offsets from the original shape-inside container.
1506 absoluteLogicalTop = logicalTop();
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +00001507 }
1508 // Begin layout at the logical top of our shape inside.
commit-queue@webkit.org3a988eb2012-09-26 19:55:35 +00001509 if (logicalHeight() + absoluteLogicalTop < exclusionShapeInsideInfo->shapeLogicalTop())
1510 setLogicalHeight(exclusionShapeInsideInfo->shapeLogicalTop() - absoluteLogicalTop);
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +00001511 }
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +00001512#endif
1513
eric@webkit.org060caf62011-05-03 22:11:39 +00001514 while (!end.atEnd()) {
1515 // FIXME: Is this check necessary before the first iteration or can it be moved to the end?
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001516 if (checkForEndLineMatch) {
1517 layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus));
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001518 if (layoutState.endLineMatched()) {
1519 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001520 break;
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001521 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001522 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001523
1524 lineMidpointState.reset();
1525
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001526 layoutState.lineInfo().setEmpty(true);
robert@webkit.org8cbab142011-12-30 20:58:29 +00001527 layoutState.lineInfo().resetRunsFromLeadingWhitespace();
eric@webkit.org060caf62011-05-03 22:11:39 +00001528
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001529 const InlineIterator oldEnd = end;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001530 bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly();
eric@webkit.org060caf62011-05-03 22:11:39 +00001531 FloatingObject* lastFloatFromPreviousLine = (m_floatingObjects && !m_floatingObjects->set().isEmpty()) ? m_floatingObjects->set().last() : 0;
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +00001532#if ENABLE(CSS_EXCLUSIONS)
commit-queue@webkit.org2d53dd52012-09-26 03:38:54 +00001533 // FIXME: Bug 95361: It is possible for a line to grow beyond lineHeight, in which
1534 // case these segments may be incorrect.
commit-queue@webkit.org3a988eb2012-09-26 19:55:35 +00001535 if (exclusionShapeInsideInfo) {
commit-queue@webkit.org2d53dd52012-09-26 03:38:54 +00001536 LayoutUnit lineTop = logicalHeight() + absoluteLogicalTop;
commit-queue@webkit.org849e71b2012-10-22 20:14:09 +00001537 exclusionShapeInsideInfo->computeSegmentsForLine(lineTop, lineHeight(layoutState.lineInfo().isFirstLine(), isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
commit-queue@webkit.org2d53dd52012-09-26 03:38:54 +00001538 }
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +00001539#endif
enrica@apple.com885c84d2012-10-10 05:48:51 +00001540 WordMeasurements wordMeasurements;
1541 end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
eric@webkit.org060caf62011-05-03 22:11:39 +00001542 if (resolver.position().atEnd()) {
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001543 // FIXME: We shouldn't be creating any runs in nextLineBreak to begin with!
eric@webkit.org060caf62011-05-03 22:11:39 +00001544 // Once BidiRunList is separated from BidiResolver this will not be needed.
1545 resolver.runs().deleteRuns();
1546 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001547 layoutState.setCheckForFloatsFromLastLine(true);
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001548 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
eric@webkit.org060caf62011-05-03 22:11:39 +00001549 break;
1550 }
1551 ASSERT(end != resolver.position());
1552
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001553#if ENABLE(CSS_EXCLUSIONS)
1554 if (exclusionShapeInsideInfo && wordMeasurements.size() && exclusionShapeInsideInfo->adjustLogicalLineTop(wordMeasurements[0].width)) {
1555 end = restartLayoutRunsAndFloatsInRange(logicalHeight(), exclusionShapeInsideInfo->logicalLineTop() - absoluteLogicalTop, lastFloatFromPreviousLine, resolver, oldEnd);
1556 continue;
1557 }
1558#endif
1559
eric@webkit.org45e33a52011-05-04 11:51:09 +00001560 // This is a short-cut for empty lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001561 if (layoutState.lineInfo().isEmpty()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001562 if (lastRootBox())
1563 lastRootBox()->setLineBreakInfo(end.m_obj, end.m_pos, resolver.status());
1564 } else {
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00001565 VisualDirectionOverride override = (styleToUse->rtlOrdering() == VisualOrder ? (styleToUse->direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride);
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001566
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00001567 if (isNewUBAParagraph && styleToUse->unicodeBidi() == Plaintext && !resolver.context()->parent()) {
1568 TextDirection direction = styleToUse->direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001569 determineDirectionality(direction, resolver.position());
rniwa@webkit.orgc275acf2012-03-05 23:09:22 +00001570 resolver.setStatus(BidiStatus(direction, isOverride(styleToUse->unicodeBidi())));
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001571 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001572 // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine.
1573 BidiRunList<BidiRun>& bidiRuns = resolver.runs();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001574 constructBidiRunsForLine(this, resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly());
eric@webkit.org060caf62011-05-03 22:11:39 +00001575 ASSERT(resolver.position() == end);
1576
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001577 BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : 0;
eric@webkit.org060caf62011-05-03 22:11:39 +00001578
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001579 if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) {
eric@webkit.org45e33a52011-05-04 11:51:09 +00001580 bidiRuns.logicallyLastRun()->m_hasHyphen = true;
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001581 consecutiveHyphenatedLines++;
1582 } else
1583 consecutiveHyphenatedLines = 0;
eric@webkit.org45e33a52011-05-04 11:51:09 +00001584
eric@webkit.org060caf62011-05-03 22:11:39 +00001585 // Now that the runs have been ordered, we create the line boxes.
1586 // At the same time we figure out where border/padding/margin should be applied for
1587 // inline flow boxes.
1588
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001589 LayoutUnit oldLogicalHeight = logicalHeight();
enrica@apple.com885c84d2012-10-10 05:48:51 +00001590 RootInlineBox* lineBox = createLineBoxesFromBidiRuns(bidiRuns, end, layoutState.lineInfo(), verticalPositionCache, trailingSpaceRun, wordMeasurements);
eric@webkit.org060caf62011-05-03 22:11:39 +00001591
1592 bidiRuns.deleteRuns();
1593 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
1594
1595 if (lineBox) {
1596 lineBox->setLineBreakInfo(end.m_obj, end.m_pos, resolver.status());
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001597 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001598 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001599
1600 if (paginated) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001601 LayoutUnit adjustment = 0;
eric@webkit.org060caf62011-05-03 22:11:39 +00001602 adjustLinePositionForPagination(lineBox, adjustment);
1603 if (adjustment) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001604 LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, layoutState.lineInfo().isFirstLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001605 lineBox->adjustBlockDirectionPosition(adjustment);
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001606 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001607 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001608
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001609 if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, layoutState.lineInfo().isFirstLine()) != oldLineWidth) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001610 // We have to delete this line, remove all floats that got added, and let line layout re-run.
1611 lineBox->deleteLine(renderArena());
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001612 end = restartLayoutRunsAndFloatsInRange(oldLogicalHeight, oldLogicalHeight + adjustment, lastFloatFromPreviousLine, resolver, oldEnd);
eric@webkit.org060caf62011-05-03 22:11:39 +00001613 continue;
1614 }
1615
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001616 setLogicalHeight(lineBox->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001617 }
commit-queue@webkit.orgbe554b22012-11-26 20:00:49 +00001618
1619 if (inRenderFlowThread())
1620 lineBox->setContainingRegion(regionAtBlockOffset(lineBox->lineTopWithLeading()));
eric@webkit.org060caf62011-05-03 22:11:39 +00001621 }
1622 }
1623
leviw@chromium.org1a508692011-05-05 00:01:11 +00001624 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i)
1625 setStaticPositions(this, lineBreaker.positionedObjects()[i]);
eric@webkit.org060caf62011-05-03 22:11:39 +00001626
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001627 layoutState.lineInfo().setFirstLine(false);
leviw@chromium.org1a508692011-05-05 00:01:11 +00001628 newLine(lineBreaker.clear());
eric@webkit.org060caf62011-05-03 22:11:39 +00001629 }
1630
1631 if (m_floatingObjects && lastRootBox()) {
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001632 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
eric@webkit.org060caf62011-05-03 22:11:39 +00001633 FloatingObjectSetIterator it = floatingObjectSet.begin();
1634 FloatingObjectSetIterator end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001635 if (layoutState.lastFloat()) {
1636 FloatingObjectSetIterator lastFloatIterator = floatingObjectSet.find(layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001637 ASSERT(lastFloatIterator != end);
1638 ++lastFloatIterator;
1639 it = lastFloatIterator;
1640 }
1641 for (; it != end; ++it) {
1642 FloatingObject* f = *it;
1643 appendFloatingObjectToLastLine(f);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001644 ASSERT(f->m_renderer == layoutState.floats()[layoutState.floatIndex()].object);
eric@webkit.org060caf62011-05-03 22:11:39 +00001645 // If a float's geometry has changed, give up on syncing with clean lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001646 if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect())
eric@webkit.org060caf62011-05-03 22:11:39 +00001647 checkForEndLineMatch = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001648 layoutState.setFloatIndex(layoutState.floatIndex() + 1);
eric@webkit.org060caf62011-05-03 22:11:39 +00001649 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001650 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last() : 0);
eric@webkit.org060caf62011-05-03 22:11:39 +00001651 }
1652
1653 lineMidpointState.reset();
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001654 resolver.setPosition(end, numberOfIsolateAncestors(end));
eric@webkit.org060caf62011-05-03 22:11:39 +00001655 }
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001656
1657 if (paginated && !style()->hasAutoWidows()) {
1658 // Check the line boxes to make sure we didn't create unacceptable widows.
1659 // However, we'll prioritize orphans - so nothing we do here should create
1660 // a new orphan.
1661
1662 RootInlineBox* lineBox = lastRootBox();
1663
1664 // Count from the end of the block backwards, to see how many hanging
1665 // lines we have.
1666 RootInlineBox* firstLineInBlock = firstRootBox();
1667 int numLinesHanging = 1;
1668 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1669 ++numLinesHanging;
1670 lineBox = lineBox->prevRootBox();
1671 }
1672
1673 // If there were no breaks in the block, we didn't create any widows.
1674 if (!lineBox->isFirstAfterPageBreak() || lineBox == firstLineInBlock)
1675 return;
1676
1677 if (numLinesHanging < style()->widows()) {
1678 // We have detected a widow. Now we need to work out how many
1679 // lines there are on the previous page, and how many we need
1680 // to steal.
1681 int numLinesNeeded = style()->widows() - numLinesHanging;
1682 RootInlineBox* currentFirstLineOfNewPage = lineBox;
1683
1684 // Count the number of lines in the previous page.
1685 lineBox = lineBox->prevRootBox();
1686 int numLinesInPreviousPage = 1;
1687 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1688 ++numLinesInPreviousPage;
1689 lineBox = lineBox->prevRootBox();
1690 }
1691
1692 // If there was an explicit value for orphans, respect that. If not, we still
1693 // shouldn't create a situation where we make an orphan bigger than the initial value.
1694 // This means that setting widows implies we also care about orphans, but given
1695 // the specification says the initial orphan value is non-zero, this is ok. The
1696 // author is always free to set orphans explicitly as well.
1697 int orphans = style()->hasAutoOrphans() ? style()->initialOrphans() : style()->orphans();
1698 int numLinesAvailable = numLinesInPreviousPage - orphans;
1699 if (numLinesAvailable <= 0)
1700 return;
1701
1702 int numLinesToTake = min(numLinesAvailable, numLinesNeeded);
1703 // Wind back from our first widowed line.
1704 lineBox = currentFirstLineOfNewPage;
1705 for (int i = 0; i < numLinesToTake; ++i)
1706 lineBox = lineBox->prevRootBox();
1707
1708 // We now want to break at this line. Remember for next layout and trigger relayout.
1709 setBreakAtLineToAvoidWidow(lineBox);
1710 markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), lineBox->lineBottomWithLeading(), lineBox);
1711 }
1712 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001713}
eric@webkit.org060caf62011-05-03 22:11:39 +00001714
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001715void RenderBlock::linkToEndLineIfNeeded(LineLayoutState& layoutState)
1716{
1717 if (layoutState.endLine()) {
1718 if (layoutState.endLineMatched()) {
1719 bool paginated = view()->layoutState() && view()->layoutState()->isPaginated();
eric@webkit.org060caf62011-05-03 22:11:39 +00001720 // Attach all the remaining lines, and then adjust their y-positions as needed.
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001721 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001722 for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001723 line->attachLine();
1724 if (paginated) {
1725 delta -= line->paginationStrut();
1726 adjustLinePositionForPagination(line, delta);
1727 }
1728 if (delta) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001729 layoutState.updateRepaintRangeFromBox(line, delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001730 line->adjustBlockDirectionPosition(delta);
1731 }
commit-queue@webkit.orgbe554b22012-11-26 20:00:49 +00001732 if (inRenderFlowThread())
1733 line->setContainingRegion(regionAtBlockOffset(line->lineTopWithLeading()));
eric@webkit.org060caf62011-05-03 22:11:39 +00001734 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
1735 Vector<RenderBox*>::iterator end = cleanLineFloats->end();
1736 for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) {
mitz@apple.com0c4ce9f2011-05-04 02:20:02 +00001737 FloatingObject* floatingObject = insertFloatingObject(*f);
1738 ASSERT(!floatingObject->m_originatingLine);
1739 floatingObject->m_originatingLine = line;
eric@webkit.org060caf62011-05-03 22:11:39 +00001740 setLogicalHeight(logicalTopForChild(*f) - marginBeforeForChild(*f) + delta);
1741 positionNewFloats();
1742 }
1743 }
1744 }
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001745 setLogicalHeight(lastRootBox()->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001746 } else {
1747 // Delete all the remaining lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001748 deleteLineRange(layoutState, renderArena(), layoutState.endLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001749 }
1750 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001751
1752 if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001753 // In case we have a float on the last line, it might not be positioned up to now.
1754 // This has to be done before adding in the bottom border/padding, or the float will
1755 // include the padding incorrectly. -dwh
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001756 if (layoutState.checkForFloatsFromLastLine()) {
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001757 LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow();
1758 LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow();
eric@webkit.org060caf62011-05-03 22:11:39 +00001759 TrailingFloatsRootInlineBox* trailingFloatsLineBox = new (renderArena()) TrailingFloatsRootInlineBox(this);
1760 m_lineBoxes.appendLineBox(trailingFloatsLineBox);
1761 trailingFloatsLineBox->setConstructed();
1762 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
1763 VerticalPositionCache verticalPositionCache;
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001764 LayoutUnit blockLogicalHeight = logicalHeight();
hyatt@apple.coma8b5b822011-09-07 18:48:07 +00001765 trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache);
1766 trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight);
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001767 trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight));
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001768 LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight);
1769 LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight);
eric@webkit.org060caf62011-05-03 22:11:39 +00001770 trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom());
commit-queue@webkit.orgbe554b22012-11-26 20:00:49 +00001771 if (inRenderFlowThread())
1772 trailingFloatsLineBox->setContainingRegion(regionAtBlockOffset(trailingFloatsLineBox->lineTopWithLeading()));
eric@webkit.org060caf62011-05-03 22:11:39 +00001773 }
1774
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001775 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
eric@webkit.org060caf62011-05-03 22:11:39 +00001776 FloatingObjectSetIterator it = floatingObjectSet.begin();
1777 FloatingObjectSetIterator end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001778 if (layoutState.lastFloat()) {
1779 FloatingObjectSetIterator lastFloatIterator = floatingObjectSet.find(layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001780 ASSERT(lastFloatIterator != end);
1781 ++lastFloatIterator;
1782 it = lastFloatIterator;
1783 }
1784 for (; it != end; ++it)
1785 appendFloatingObjectToLastLine(*it);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001786 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last() : 0);
eric@webkit.org060caf62011-05-03 22:11:39 +00001787 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001788}
1789
1790void RenderBlock::repaintDirtyFloats(Vector<FloatWithRect>& floats)
1791{
eric@webkit.org060caf62011-05-03 22:11:39 +00001792 size_t floatCount = floats.size();
1793 // Floats that did not have layout did not repaint when we laid them out. They would have
1794 // painted by now if they had moved, but if they stayed at (0, 0), they still need to be
1795 // painted.
1796 for (size_t i = 0; i < floatCount; ++i) {
1797 if (!floats[i].everHadLayout) {
1798 RenderBox* f = floats[i].object;
1799 if (!f->x() && !f->y() && f->checkForRepaintDuringLayout())
1800 f->repaint();
1801 }
1802 }
1803}
1804
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001805void RenderBlock::layoutInlineChildren(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom)
jamesr@google.com19548ad2010-04-02 23:21:35 +00001806{
hyatt@apple.com5dc5a312009-08-18 19:15:19 +00001807 m_overflow.clear();
eric@webkit.org060caf62011-05-03 22:11:39 +00001808
hyatt@apple.com81c1d742010-10-06 21:44:02 +00001809 setLogicalHeight(borderBefore() + paddingBefore());
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001810
1811 // Lay out our hypothetical grid line as though it occurs at the top of the block.
hyatt@apple.com989d2172012-02-09 01:50:05 +00001812 if (view()->layoutState() && view()->layoutState()->lineGrid() == this)
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001813 layoutLineGridBox();
mitz@apple.come1364202008-02-28 01:06:41 +00001814
commit-queue@webkit.org93cdd632012-12-07 00:33:56 +00001815 bool clearLinesForPagination = firstLineBox() && inRenderFlowThread() && !enclosingRenderFlowThread()->hasRegions();
1816
hyatt0c3a9862004-02-23 21:26:26 +00001817 // Figure out if we should clear out our line boxes.
1818 // FIXME: Handle resize eventually!
commit-queue@webkit.org93cdd632012-12-07 00:33:56 +00001819 bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren || clearLinesForPagination;
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001820 LineLayoutState layoutState(isFullLayout, repaintLogicalTop, repaintLogicalBottom);
1821
1822 if (isFullLayout)
inferno@chromium.orgf5af4c42012-02-26 18:06:55 +00001823 lineBoxes()->deleteLineBoxes(renderArena());
mitz@apple.come1364202008-02-28 01:06:41 +00001824
hyatted77ad82004-06-15 07:21:23 +00001825 // Text truncation only kicks in if your overflow isn't visible and your text-overflow-mode isn't
1826 // clip.
1827 // FIXME: CSS3 says that descendants that are clipped must also know how to truncate. This is insanely
1828 // difficult to figure out (especially in the middle of doing layout), and is really an esoteric pile of nonsense
1829 // anyway, so we won't worry about following the draft here.
igor.oliveira@openbossa.orga132c622011-08-25 20:56:55 +00001830 bool hasTextOverflow = style()->textOverflow() && hasOverflowClip();
mitz@apple.come1364202008-02-28 01:06:41 +00001831
hyatted77ad82004-06-15 07:21:23 +00001832 // Walk all the lines and delete our ellipsis line boxes if they exist.
1833 if (hasTextOverflow)
1834 deleteEllipsisLineBoxes();
1835
hyattffe78712003-02-11 01:59:29 +00001836 if (firstChild()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001837 // In full layout mode, clear the line boxes of children upfront. Otherwise,
1838 // siblings can run into stale root lineboxes during layout. Then layout
1839 // the replaced elements later. In partial layout mode, line boxes are not
1840 // deleted and only dirtied. In that case, we can layout the replaced
1841 // elements at the same time.
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001842 bool hasInlineChild = false;
inferno@chromium.org13563122012-08-16 20:50:05 +00001843 Vector<RenderBox*> replacedChildren;
eric@webkit.org33510472011-06-04 19:34:29 +00001844 for (InlineWalker walker(this); !walker.atEnd(); walker.advance()) {
1845 RenderObject* o = walker.current();
commit-queue@webkit.orgcf45df92010-09-14 13:25:06 +00001846 if (!hasInlineChild && o->isInline())
1847 hasInlineChild = true;
1848
simon.fraser@apple.com2f071852012-06-25 00:11:30 +00001849 if (o->isReplaced() || o->isFloating() || o->isOutOfFlowPositioned()) {
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001850 RenderBox* box = toRenderBox(o);
eric@webkit.org060caf62011-05-03 22:11:39 +00001851
commit-queue@webkit.orgb6cbe4f2012-02-28 16:01:19 +00001852 if (relayoutChildren || box->hasRelativeDimensions())
eric@webkit.org218b4e02012-03-28 19:25:02 +00001853 o->setChildNeedsLayout(true, MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001854
zimmermann@webkit.orgac68af42011-06-15 08:02:37 +00001855 // If relayoutChildren is set and the child has percentage padding or an embedded content box, we also need to invalidate the childs pref widths.
1856 if (relayoutChildren && box->needsPreferredWidthsRecalculation())
eric@webkit.org218b4e02012-03-28 19:25:02 +00001857 o->setPreferredLogicalWidthsDirty(true, MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001858
simon.fraser@apple.com2f071852012-06-25 00:11:30 +00001859 if (o->isOutOfFlowPositioned())
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001860 o->containingBlock()->insertPositionedObject(box);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001861 else if (o->isFloating())
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001862 layoutState.floats().append(FloatWithRect(box));
inferno@chromium.org13563122012-08-16 20:50:05 +00001863 else if (isFullLayout || o->needsLayout()) {
1864 // Replaced element.
1865 box->dirtyLineBoxes(isFullLayout);
1866 if (isFullLayout)
1867 replacedChildren.append(box);
1868 else
1869 o->layoutIfNeeded();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001870 }
eric@webkit.org33510472011-06-04 19:34:29 +00001871 } else if (o->isText() || (o->isRenderInline() && !walker.atEndOfInline())) {
hyatt@apple.coma61b8a32011-04-06 18:20:52 +00001872 if (!o->isText())
inferno@chromium.org88a424d2011-08-09 18:18:36 +00001873 toRenderInline(o)->updateAlwaysCreateLineBoxes(layoutState.isFullLayout());
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001874 if (layoutState.isFullLayout() || o->selfNeedsLayout())
1875 dirtyLineBoxesForRenderer(o, layoutState.isFullLayout());
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001876 o->setNeedsLayout(false);
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001877 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001878 }
1879
inferno@chromium.orgba2dceb2012-08-21 00:09:47 +00001880 for (size_t i = 0; i < replacedChildren.size(); i++)
1881 replacedChildren[i]->layoutIfNeeded();
inferno@chromium.org13563122012-08-16 20:50:05 +00001882
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001883 layoutRunsAndFloats(layoutState, hasInlineChild);
kociendabb0c24b2001-08-24 14:24:40 +00001884 }
hyatt85586af2003-02-19 23:22:42 +00001885
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001886 // Expand the last line to accommodate Ruby and emphasis marks.
1887 int lastLineAnnotationsAdjustment = 0;
1888 if (lastRootBox()) {
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001889 LayoutUnit lowestAllowedPosition = max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001890 if (!style()->isFlippedLinesWritingMode())
1891 lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition);
1892 else
1893 lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
hyatt@apple.com5e48ff52010-11-19 00:43:29 +00001894 }
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001895
hyatta70560a2002-11-20 01:53:20 +00001896 // Now add in the bottom border/padding.
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001897 setLogicalHeight(logicalHeight() + lastLineAnnotationsAdjustment + borderAfter() + paddingAfter() + scrollbarLogicalHeight());
kociendabb0c24b2001-08-24 14:24:40 +00001898
adele7a470a72006-04-20 22:22:14 +00001899 if (!firstLineBox() && hasLineIfEmpty())
hyatt@apple.com2a5eb212011-03-22 23:21:54 +00001900 setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
hyatted77ad82004-06-15 07:21:23 +00001901
1902 // See if we have any lines that spill out of our block. If we do, then we will possibly need to
1903 // truncate text.
1904 if (hasTextOverflow)
1905 checkLinesForTextOverflow();
kociendabb0c24b2001-08-24 14:24:40 +00001906}
1907
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001908void RenderBlock::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat)
1909{
1910 Vector<RenderBox*>* cleanLineFloats = line->floatsPtr();
1911 if (!cleanLineFloats)
1912 return;
1913
1914 Vector<RenderBox*>::iterator end = cleanLineFloats->end();
1915 for (Vector<RenderBox*>::iterator it = cleanLineFloats->begin(); it != end; ++it) {
1916 RenderBox* floatingBox = *it;
1917 floatingBox->layoutIfNeeded();
tkent@chromium.orgb27646b2012-03-08 03:31:25 +00001918 LayoutSize newSize(floatingBox->width() + floatingBox->marginWidth(), floatingBox->height() + floatingBox->marginHeight());
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001919 ASSERT(floatIndex < floats.size());
1920 if (floats[floatIndex].object != floatingBox) {
1921 encounteredNewFloat = true;
1922 return;
1923 }
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001924
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001925 if (floats[floatIndex].rect.size() != newSize) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001926 LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x();
1927 LayoutUnit floatHeight = isHorizontalWritingMode() ? max(floats[floatIndex].rect.height(), newSize.height())
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001928 : max(floats[floatIndex].rect.width(), newSize.width());
eae@chromium.org9717cd82012-11-07 18:33:44 +00001929 floatHeight = min(floatHeight, LayoutUnit::max() - floatTop);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001930 line->markDirty();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001931 markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001932 floats[floatIndex].rect.setSize(newSize);
1933 dirtiedByFloat = true;
1934 }
1935 floatIndex++;
1936 }
1937}
1938
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001939RootInlineBox* RenderBlock::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver)
hyatt0c3a9862004-02-23 21:26:26 +00001940{
1941 RootInlineBox* curr = 0;
1942 RootInlineBox* last = 0;
mitz@apple.come1364202008-02-28 01:06:41 +00001943
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001944 // FIXME: This entire float-checking block needs to be broken into a new function.
mitz@apple.com40547b32008-03-18 04:04:34 +00001945 bool dirtiedByFloat = false;
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001946 if (!layoutState.isFullLayout()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001947 // Paginate all of the clean lines.
1948 bool paginated = view()->layoutState() && view()->layoutState()->isPaginated();
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001949 LayoutUnit paginationDelta = 0;
mitz@apple.com40547b32008-03-18 04:04:34 +00001950 size_t floatIndex = 0;
1951 for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001952 if (paginated) {
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001953 if (lineWidthForPaginatedLineChanged(curr)) {
1954 curr->markDirty();
1955 break;
1956 }
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001957 paginationDelta -= curr->paginationStrut();
1958 adjustLinePositionForPagination(curr, paginationDelta);
1959 if (paginationDelta) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001960 if (containsFloats() || !layoutState.floats().isEmpty()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001961 // FIXME: Do better eventually. For now if we ever shift because of pagination and floats are present just go to a full layout.
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001962 layoutState.markForFullLayout();
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001963 break;
1964 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001965
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001966 layoutState.updateRepaintRangeFromBox(curr, paginationDelta);
hyatt@apple.com61bbedf2011-01-26 23:10:57 +00001967 curr->adjustBlockDirectionPosition(paginationDelta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001968 }
commit-queue@webkit.orgbe554b22012-11-26 20:00:49 +00001969 if (inRenderFlowThread())
1970 curr->setContainingRegion(regionAtBlockOffset(curr->lineTopWithLeading()));
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001971 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001972
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001973 // If a new float has been inserted before this line or before its last known float, just do a full layout.
1974 bool encounteredNewFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001975 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001976 if (encounteredNewFloat)
1977 layoutState.markForFullLayout();
1978
1979 if (dirtiedByFloat || layoutState.isFullLayout())
mitz@apple.com40547b32008-03-18 04:04:34 +00001980 break;
1981 }
1982 // Check if a new float has been inserted after the last known float.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001983 if (!curr && floatIndex < layoutState.floats().size())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001984 layoutState.markForFullLayout();
mitz@apple.com40547b32008-03-18 04:04:34 +00001985 }
1986
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001987 if (layoutState.isFullLayout()) {
eric@webkit.orge2532d92011-05-16 23:10:49 +00001988 // FIXME: This should just call deleteLineBoxTree, but that causes
1989 // crashes for fast/repaint tests.
1990 RenderArena* arena = renderArena();
1991 curr = firstRootBox();
1992 while (curr) {
1993 // Note: This uses nextRootBox() insted of nextLineBox() like deleteLineBoxTree does.
1994 RootInlineBox* next = curr->nextRootBox();
1995 curr->deleteLine(arena);
1996 curr = next;
hyatt0c3a9862004-02-23 21:26:26 +00001997 }
eric@webkit.orge2532d92011-05-16 23:10:49 +00001998 ASSERT(!firstLineBox() && !lastLineBox());
eseidel789896f2005-11-27 22:52:09 +00001999 } else {
hyatt0c3a9862004-02-23 21:26:26 +00002000 if (curr) {
2001 // We have a dirty line.
mjs9f78dd92007-02-12 04:06:07 +00002002 if (RootInlineBox* prevRootBox = curr->prevRootBox()) {
hyatt0c3a9862004-02-23 21:26:26 +00002003 // We have a previous line.
tasak@google.comfcfd96f2012-11-26 07:45:38 +00002004 if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= toRenderText(prevRootBox->lineBreakObj())->textLength())))
mjs9f78dd92007-02-12 04:06:07 +00002005 // The previous line didn't break cleanly or broke at a newline
2006 // that has been deleted, so treat it as dirty too.
2007 curr = prevRootBox;
hyatt0c3a9862004-02-23 21:26:26 +00002008 }
eseidel789896f2005-11-27 22:52:09 +00002009 } else {
hyatt0c3a9862004-02-23 21:26:26 +00002010 // No dirty lines were found.
2011 // If the last line didn't break cleanly, treat it as dirty.
2012 if (lastRootBox() && !lastRootBox()->endsWithBreak())
2013 curr = lastRootBox();
2014 }
mitz@apple.come1364202008-02-28 01:06:41 +00002015
hyatt0c3a9862004-02-23 21:26:26 +00002016 // If we have no dirty lines, then last is just the last root box.
2017 last = curr ? curr->prevRootBox() : lastRootBox();
2018 }
mitz@apple.come1364202008-02-28 01:06:41 +00002019
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002020 unsigned numCleanFloats = 0;
2021 if (!layoutState.floats().isEmpty()) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00002022 LayoutUnit savedLogicalHeight = logicalHeight();
mitz@apple.com40547b32008-03-18 04:04:34 +00002023 // Restore floats from clean lines.
2024 RootInlineBox* line = firstRootBox();
2025 while (line != curr) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00002026 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
2027 Vector<RenderBox*>::iterator end = cleanLineFloats->end();
2028 for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) {
mitz@apple.com0c4ce9f2011-05-04 02:20:02 +00002029 FloatingObject* floatingObject = insertFloatingObject(*f);
2030 ASSERT(!floatingObject->m_originatingLine);
2031 floatingObject->m_originatingLine = line;
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00002032 setLogicalHeight(logicalTopForChild(*f) - marginBeforeForChild(*f));
mitz@apple.com40547b32008-03-18 04:04:34 +00002033 positionNewFloats();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002034 ASSERT(layoutState.floats()[numCleanFloats].object == *f);
mitz@apple.com40547b32008-03-18 04:04:34 +00002035 numCleanFloats++;
2036 }
2037 }
2038 line = line->nextRootBox();
2039 }
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00002040 setLogicalHeight(savedLogicalHeight);
mitz@apple.com40547b32008-03-18 04:04:34 +00002041 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002042 layoutState.setFloatIndex(numCleanFloats);
mitz@apple.com40547b32008-03-18 04:04:34 +00002043
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002044 layoutState.lineInfo().setFirstLine(!last);
2045 layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak());
mitz@apple.com1a301772008-03-11 18:30:36 +00002046
hyatt0c3a9862004-02-23 21:26:26 +00002047 if (last) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00002048 setLogicalHeight(last->lineBottomWithLeading());
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00002049 InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos());
2050 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
mitz@apple.com15035e62008-07-05 20:44:44 +00002051 resolver.setStatus(last->lineBreakBidiStatus());
darindde01502005-12-18 22:55:35 +00002052 } else {
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00002053 TextDirection direction = style()->direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +00002054 if (style()->unicodeBidi() == Plaintext)
2055 determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(this), 0));
rniwa@webkit.orgc275acf2012-03-05 23:09:22 +00002056 resolver.setStatus(BidiStatus(direction, isOverride(style()->unicodeBidi())));
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00002057 InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(this, &resolver), 0);
2058 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
darindde01502005-12-18 22:55:35 +00002059 }
hyatt0c3a9862004-02-23 21:26:26 +00002060 return curr;
2061}
2062
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002063void RenderBlock::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus)
hyatt0c3a9862004-02-23 21:26:26 +00002064{
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002065 ASSERT(!layoutState.endLine());
2066 size_t floatIndex = layoutState.floatIndex();
hyatt0c3a9862004-02-23 21:26:26 +00002067 RootInlineBox* last = 0;
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00002068 for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) {
2069 if (!curr->isDirty()) {
2070 bool encounteredNewFloat = false;
2071 bool dirtiedByFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002072 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00002073 if (encounteredNewFloat)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002074 return;
hyatt04420ca2004-07-16 00:05:42 +00002075 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00002076 if (curr->isDirty())
2077 last = 0;
2078 else if (!last)
2079 last = curr;
hyatt0c3a9862004-02-23 21:26:26 +00002080 }
mitz@apple.come1364202008-02-28 01:06:41 +00002081
hyatt0c3a9862004-02-23 21:26:26 +00002082 if (!last)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002083 return;
mitz@apple.come1364202008-02-28 01:06:41 +00002084
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00002085 // At this point, |last| is the first line in a run of clean lines that ends with the last line
2086 // in the block.
2087
eseidel789896f2005-11-27 22:52:09 +00002088 RootInlineBox* prev = last->prevRootBox();
mitz@apple.com15035e62008-07-05 20:44:44 +00002089 cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos());
eseidel789896f2005-11-27 22:52:09 +00002090 cleanLineBidiStatus = prev->lineBreakBidiStatus();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00002091 layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading());
mitz@apple.come1364202008-02-28 01:06:41 +00002092
hyatt0c3a9862004-02-23 21:26:26 +00002093 for (RootInlineBox* line = last; line; line = line->nextRootBox())
2094 line->extractLine(); // Disconnect all line boxes from their render objects while preserving
2095 // their connections to one another.
mitz@apple.come1364202008-02-28 01:06:41 +00002096
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002097 layoutState.setEndLine(last);
hyatt0c3a9862004-02-23 21:26:26 +00002098}
2099
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002100bool RenderBlock::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState)
2101{
2102 LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop();
2103
2104 bool paginated = view()->layoutState() && view()->layoutState()->isPaginated();
hyatt@apple.comd4d3bcf2011-10-04 18:17:04 +00002105 if (paginated && inRenderFlowThread()) {
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002106 // Check all lines from here to the end, and see if the hypothetical new position for the lines will result
2107 // in a different available line width.
2108 for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) {
2109 if (paginated) {
2110 // This isn't the real move we're going to do, so don't update the line box's pagination
2111 // strut yet.
2112 LayoutUnit oldPaginationStrut = lineBox->paginationStrut();
2113 lineDelta -= oldPaginationStrut;
2114 adjustLinePositionForPagination(lineBox, lineDelta);
2115 lineBox->setPaginationStrut(oldPaginationStrut);
2116 }
2117 if (lineWidthForPaginatedLineChanged(lineBox, lineDelta))
2118 return false;
2119 }
2120 }
2121
2122 if (!lineDelta || !m_floatingObjects)
2123 return true;
2124
2125 // See if any floats end in the range along which we want to shift the lines vertically.
eae@chromium.orgee8613e2011-11-12 01:12:58 +00002126 LayoutUnit logicalTop = min(logicalHeight(), layoutState.endLineLogicalTop());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002127
2128 RootInlineBox* lastLine = layoutState.endLine();
2129 while (RootInlineBox* nextLine = lastLine->nextRootBox())
2130 lastLine = nextLine;
2131
leviw@chromium.org3957b452012-05-01 00:06:37 +00002132 LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + absoluteValue(lineDelta);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002133
2134 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
2135 FloatingObjectSetIterator end = floatingObjectSet.end();
2136 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
2137 FloatingObject* f = *it;
2138 if (logicalBottomForFloat(f) >= logicalTop && logicalBottomForFloat(f) < logicalBottom)
2139 return false;
2140 }
2141
2142 return true;
2143}
2144
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00002145bool RenderBlock::matchedEndLine(LineLayoutState& layoutState, const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus)
hyatt0c3a9862004-02-23 21:26:26 +00002146{
mitz@apple.com15035e62008-07-05 20:44:44 +00002147 if (resolver.position() == endLineStart) {
2148 if (resolver.status() != endLineStatus)
mitz@apple.com40547b32008-03-18 04:04:34 +00002149 return false;
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002150 return checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00002151 }
hyatt0c3a9862004-02-23 21:26:26 +00002152
mitz@apple.come1364202008-02-28 01:06:41 +00002153 // The first clean line doesn't match, but we can check a handful of following lines to try
2154 // to match back up.
2155 static int numLines = 8; // The # of lines we're willing to match against.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002156 RootInlineBox* originalEndLine = layoutState.endLine();
2157 RootInlineBox* line = originalEndLine;
mitz@apple.come1364202008-02-28 01:06:41 +00002158 for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) {
eric@webkit.org86a865a2011-03-29 15:30:41 +00002159 if (line->lineBreakObj() == resolver.position().m_obj && line->lineBreakPos() == resolver.position().m_pos) {
mitz@apple.come1364202008-02-28 01:06:41 +00002160 // We have a match.
mitz@apple.com15035e62008-07-05 20:44:44 +00002161 if (line->lineBreakBidiStatus() != resolver.status())
mitz@apple.come1364202008-02-28 01:06:41 +00002162 return false; // ...but the bidi state doesn't match.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002163
2164 bool matched = false;
mitz@apple.come1364202008-02-28 01:06:41 +00002165 RootInlineBox* result = line->nextRootBox();
hyatt@apple.com1fb7d582011-09-23 20:25:11 +00002166 layoutState.setEndLine(result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002167 if (result) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00002168 layoutState.setEndLineLogicalTop(line->lineBottomWithLeading());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002169 matched = checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00002170 }
2171
mitz@apple.come1364202008-02-28 01:06:41 +00002172 // Now delete the lines that we failed to sync.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002173 deleteLineRange(layoutState, renderArena(), originalEndLine, result);
2174 return matched;
hyatt0c3a9862004-02-23 21:26:26 +00002175 }
2176 }
mitz@apple.come1364202008-02-28 01:06:41 +00002177
hyatt0c3a9862004-02-23 21:26:26 +00002178 return false;
2179}
2180
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002181static inline bool skipNonBreakingSpace(const InlineIterator& it, const LineInfo& lineInfo)
kocienda98440082004-10-14 23:51:47 +00002182{
eric@webkit.org8c25a592011-03-29 13:18:11 +00002183 if (it.m_obj->style()->nbspMode() != SPACE || it.current() != noBreakSpace)
kocienda98440082004-10-14 23:51:47 +00002184 return false;
mitz@apple.come1364202008-02-28 01:06:41 +00002185
hyattdca76e92005-11-02 08:52:50 +00002186 // FIXME: This is bad. It makes nbsp inconsistent with space and won't work correctly
2187 // with m_minWidth/m_maxWidth.
kocienda498d1982004-10-15 21:07:24 +00002188 // Do not skip a non-breaking space if it is the first character
hyattdca76e92005-11-02 08:52:50 +00002189 // on a line after a clean line break (or on the first line, since previousLineBrokeCleanly starts off
2190 // |true|).
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002191 if (lineInfo.isEmpty() && lineInfo.previousLineBrokeCleanly())
kocienda498d1982004-10-15 21:07:24 +00002192 return false;
mitz@apple.come1364202008-02-28 01:06:41 +00002193
kocienda498d1982004-10-15 21:07:24 +00002194 return true;
kocienda98440082004-10-14 23:51:47 +00002195}
2196
rniwa@webkit.org40248422011-06-15 00:19:39 +00002197enum WhitespacePosition { LeadingWhitespace, TrailingWhitespace };
2198static inline bool shouldCollapseWhiteSpace(const RenderStyle* style, const LineInfo& lineInfo, WhitespacePosition whitespacePosition)
hyattd9953212005-11-03 21:05:59 +00002199{
rniwa@webkit.org40248422011-06-15 00:19:39 +00002200 // CSS2 16.6.1
2201 // If a space (U+0020) at the beginning of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is removed.
2202 // If a space (U+0020) at the end of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is also removed.
2203 // If spaces (U+0020) or tabs (U+0009) at the end of a line have 'white-space' set to 'pre-wrap', UAs may visually collapse them.
2204 return style->collapseWhiteSpace()
2205 || (whitespacePosition == TrailingWhitespace && style->whiteSpace() == PRE_WRAP && (!lineInfo.isEmpty() || !lineInfo.previousLineBrokeCleanly()));
hyattd9953212005-11-03 21:05:59 +00002206}
2207
robert@webkit.org56e5a9f2012-02-17 21:10:42 +00002208static bool requiresLineBoxForContent(RenderInline* flow, const LineInfo& lineInfo)
2209{
2210 RenderObject* parent = flow->parent();
2211 if (flow->document()->inNoQuirksMode()
2212 && (flow->style(lineInfo.isFirstLine())->lineHeight() != parent->style(lineInfo.isFirstLine())->lineHeight()
2213 || flow->style()->verticalAlign() != parent->style()->verticalAlign()
2214 || !parent->style()->font().fontMetrics().hasIdenticalAscentDescentAndLineGap(flow->style()->font().fontMetrics())))
2215 return true;
2216 return false;
2217}
2218
robert@webkit.orgd9d595e2012-02-17 21:48:09 +00002219static bool alwaysRequiresLineBox(RenderInline* flow)
bdakinf876bee2007-10-30 05:27:09 +00002220{
2221 // FIXME: Right now, we only allow line boxes for inlines that are truly empty.
hyatt@apple.comeb66ef42008-01-18 22:59:29 +00002222 // We need to fix this, though, because at the very least, inlines containing only
eric@webkit.org060caf62011-05-03 22:11:39 +00002223 // ignorable whitespace should should also have line boxes.
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00002224 return !flow->firstChild() && flow->hasInlineDirectionBordersPaddingOrMargin();
bdakinf876bee2007-10-30 05:27:09 +00002225}
2226
rniwa@webkit.org40248422011-06-15 00:19:39 +00002227static bool requiresLineBox(const InlineIterator& it, const LineInfo& lineInfo = LineInfo(), WhitespacePosition whitespacePosition = LeadingWhitespace)
bdashccffb432007-07-13 11:51:40 +00002228{
simon.fraser@apple.com2f071852012-06-25 00:11:30 +00002229 if (it.m_obj->isFloatingOrOutOfFlowPositioned())
bdashccffb432007-07-13 11:51:40 +00002230 return false;
bdakinf876bee2007-10-30 05:27:09 +00002231
robert@webkit.orgd9d595e2012-02-17 21:48:09 +00002232 if (it.m_obj->isRenderInline() && !alwaysRequiresLineBox(toRenderInline(it.m_obj)) && !requiresLineBoxForContent(toRenderInline(it.m_obj), lineInfo))
bdakinf876bee2007-10-30 05:27:09 +00002233 return false;
2234
rniwa@webkit.org40248422011-06-15 00:19:39 +00002235 if (!shouldCollapseWhiteSpace(it.m_obj->style(), lineInfo, whitespacePosition) || it.m_obj->isBR())
bdashccffb432007-07-13 11:51:40 +00002236 return true;
2237
2238 UChar current = it.current();
eric@webkit.org060caf62011-05-03 22:11:39 +00002239 return current != ' ' && current != '\t' && current != softHyphen && (current != '\n' || it.m_obj->preservesNewline())
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002240 && !skipNonBreakingSpace(it, lineInfo);
bdashccffb432007-07-13 11:51:40 +00002241}
2242
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002243bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj)
bdashccffb432007-07-13 11:51:40 +00002244{
2245 ASSERT(inlineObj->parent() == this);
2246
mitz@apple.com15035e62008-07-05 20:44:44 +00002247 InlineIterator it(this, inlineObj, 0);
rniwa@webkit.org40248422011-06-15 00:19:39 +00002248 // FIXME: We should pass correct value for WhitespacePosition.
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002249 while (!it.atEnd() && !requiresLineBox(it))
mitz@apple.com1a301772008-03-11 18:30:36 +00002250 it.increment();
bdashccffb432007-07-13 11:51:40 +00002251
2252 return !it.atEnd();
2253}
2254
mitz@apple.combf6e8d32008-07-25 20:21:06 +00002255// FIXME: The entire concept of the skipTrailingWhitespace function is flawed, since we really need to be building
leviw@chromium.org1a508692011-05-05 00:01:11 +00002256// line boxes even for containers that may ultimately collapse away. Otherwise we'll never get positioned
2257// elements quite right. In other words, we need to build this function's work into the normal line
mitz@apple.com1a301772008-03-11 18:30:36 +00002258// object iteration process.
mitz@apple.combf6e8d32008-07-25 20:21:06 +00002259// NB. this function will insert any floating elements that would otherwise
2260// be skipped but it will not position them.
leviw@chromium.org1a508692011-05-05 00:01:11 +00002261void RenderBlock::LineBreaker::skipTrailingWhitespace(InlineIterator& iterator, const LineInfo& lineInfo)
kociendabb0c24b2001-08-24 14:24:40 +00002262{
rniwa@webkit.org40248422011-06-15 00:19:39 +00002263 while (!iterator.atEnd() && !requiresLineBox(iterator, lineInfo, TrailingWhitespace)) {
eric@webkit.org8c25a592011-03-29 13:18:11 +00002264 RenderObject* object = iterator.m_obj;
simon.fraser@apple.com2f071852012-06-25 00:11:30 +00002265 if (object->isOutOfFlowPositioned())
leviw@chromium.org1a508692011-05-05 00:01:11 +00002266 setStaticPositions(m_block, toRenderBox(object));
mitz@apple.comd67fb212011-12-19 02:51:46 +00002267 else if (object->isFloating())
2268 m_block->insertFloatingObject(toRenderBox(object));
mitz@apple.com1a301772008-03-11 18:30:36 +00002269 iterator.increment();
mjs6f821c82002-03-22 00:31:57 +00002270 }
mitz@apple.com1a301772008-03-11 18:30:36 +00002271}
bdashccffb432007-07-13 11:51:40 +00002272
hyatt@apple.com5950bd42011-09-27 20:39:57 +00002273void RenderBlock::LineBreaker::skipLeadingWhitespace(InlineBidiResolver& resolver, LineInfo& lineInfo,
leviw@chromium.org1a508692011-05-05 00:01:11 +00002274 FloatingObject* lastFloatFromPreviousLine, LineWidth& width)
mitz@apple.com1a301772008-03-11 18:30:36 +00002275{
rniwa@webkit.org40248422011-06-15 00:19:39 +00002276 while (!resolver.position().atEnd() && !requiresLineBox(resolver.position(), lineInfo, LeadingWhitespace)) {
eric@webkit.org8c25a592011-03-29 13:18:11 +00002277 RenderObject* object = resolver.position().m_obj;
simon.fraser@apple.com2f071852012-06-25 00:11:30 +00002278 if (object->isOutOfFlowPositioned()) {
leviw@chromium.org1a508692011-05-05 00:01:11 +00002279 setStaticPositions(m_block, toRenderBox(object));
robert@webkit.org8cbab142011-12-30 20:58:29 +00002280 if (object->style()->isOriginalDisplayInlineType()) {
2281 resolver.runs().addRun(createRun(0, 1, object, resolver));
2282 lineInfo.incrementRunsFromLeadingWhitespace();
2283 }
robert@webkit.org8de78c62012-12-07 19:30:51 +00002284 } else if (object->isFloating()) {
2285 // The top margin edge of a self-collapsing block that clears a float intrudes up into it by the height of the margin,
2286 // so in order to place this child float at the top content edge of the self-collapsing block add the margin back in before placement.
2287 LayoutUnit marginOffset = (m_block->isSelfCollapsingBlock() && m_block->getClearDelta(m_block, LayoutUnit())) ? m_block->collapsedMarginBeforeForChild(m_block) : LayoutUnit();
2288 LayoutUnit oldLogicalHeight = m_block->logicalHeight();
2289 m_block->setLogicalHeight(oldLogicalHeight + marginOffset);
mitz@apple.comd67fb212011-12-19 02:51:46 +00002290 m_block->positionNewFloatOnLine(m_block->insertFloatingObject(toRenderBox(object)), lastFloatFromPreviousLine, lineInfo, width);
robert@webkit.org8de78c62012-12-07 19:30:51 +00002291 m_block->setLogicalHeight(oldLogicalHeight);
2292 } else if (object->isText() && object->style()->hasTextCombine() && object->isCombineText() && !toRenderCombineText(object)->isCombined()) {
commit-queue@webkit.orgf6c35c02012-01-06 20:30:15 +00002293 toRenderCombineText(object)->combineText();
commit-queue@webkit.org8e277fd2012-01-19 18:05:33 +00002294 if (toRenderCombineText(object)->isCombined())
2295 continue;
commit-queue@webkit.orgf6c35c02012-01-06 20:30:15 +00002296 }
mitz@apple.com15035e62008-07-05 20:44:44 +00002297 resolver.increment();
mitz@apple.com1a301772008-03-11 18:30:36 +00002298 }
mitz@apple.com83d2e872008-10-23 21:56:03 +00002299 resolver.commitExplicitEmbedding();
kociendae40cb942004-10-05 20:05:38 +00002300}
2301
eric@webkit.org060caf62011-05-03 22:11:39 +00002302// This is currently just used for list markers and inline flows that have line boxes. Neither should
2303// have an effect on whitespace at the start of the line.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00002304static bool shouldSkipWhitespaceAfterStartObject(RenderBlock* block, RenderObject* o, LineMidpointState& lineMidpointState)
bdakinf876bee2007-10-30 05:27:09 +00002305{
eric@webkit.orgd4b9d772011-08-22 23:34:31 +00002306 RenderObject* next = bidiNextSkippingEmptyInlines(block, o);
darin@apple.com36744d62009-01-25 20:23:04 +00002307 if (next && !next->isBR() && next->isText() && toRenderText(next)->textLength() > 0) {
2308 RenderText* nextText = toRenderText(next);
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002309 UChar nextChar = nextText->characterAt(0);
bdakinf876bee2007-10-30 05:27:09 +00002310 if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) {
hyatt@apple.comb3466af2009-06-13 06:04:40 +00002311 addMidpoint(lineMidpointState, InlineIterator(0, o, 0));
bdakinf876bee2007-10-30 05:27:09 +00002312 return true;
2313 }
2314 }
2315
2316 return false;
2317}
2318
enrica@apple.com885c84d2012-10-10 05:48:51 +00002319static ALWAYS_INLINE float textWidth(RenderText* text, unsigned from, unsigned len, const Font& font, float xPos, bool isFixedPitch, bool collapseWhiteSpace, HashSet<const SimpleFontData*>* fallbackFonts = 0, TextLayout* layout = 0)
mitz@apple.com34106442009-02-01 06:23:39 +00002320{
enrica@apple.com885c84d2012-10-10 05:48:51 +00002321 GlyphOverflow glyphOverflow;
hyatt@apple.com4d046b72011-01-31 20:39:09 +00002322 if (isFixedPitch || (!from && len == text->textLength()) || text->style()->hasTextCombine())
enrica@apple.com885c84d2012-10-10 05:48:51 +00002323 return text->width(from, len, font, xPos, fallbackFonts, &glyphOverflow);
zimmermann@webkit.org544abde2011-06-12 12:40:40 +00002324
mitz@apple.com6a859602012-08-27 15:31:56 +00002325 if (layout)
enrica@apple.com885c84d2012-10-10 05:48:51 +00002326 return Font::width(*layout, from, len, fallbackFonts);
mitz@apple.com6a859602012-08-27 15:31:56 +00002327
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002328 TextRun run = RenderBlock::constructTextRun(text, font, text, from, len, text->style());
zimmermann@webkit.org544abde2011-06-12 12:40:40 +00002329 run.setCharactersLength(text->textLength() - from);
2330 ASSERT(run.charactersLength() >= run.length());
2331
hyatt@apple.comc2fdbe12012-04-12 21:06:50 +00002332 run.setCharacterScanForCodePath(!text->canUseSimpleFontCodePath());
morrita@google.com6e818ec2012-05-11 03:28:46 +00002333 run.setTabSize(!collapseWhiteSpace, text->style()->tabSize());
zimmermann@webkit.org8a7e7ff2011-05-24 15:27:36 +00002334 run.setXPos(xPos);
enrica@apple.com885c84d2012-10-10 05:48:51 +00002335 return font.width(run, fallbackFonts, &glyphOverflow);
mitz@apple.com34106442009-02-01 06:23:39 +00002336}
2337
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002338static void tryHyphenating(RenderText* text, const Font& font, const AtomicString& localeIdentifier, unsigned consecutiveHyphenatedLines, int consecutiveHyphenatedLinesLimit, int minimumPrefixLimit, int minimumSuffixLimit, unsigned lastSpace, unsigned pos, float xPos, int availableWidth, bool isFixedPitch, bool collapseWhiteSpace, int lastSpaceWordSpacing, InlineIterator& lineBreak, int nextBreakable, bool& hyphenated)
mitz@apple.comb2107652010-06-21 16:54:52 +00002339{
mitz@apple.comd56f1082011-03-06 22:44:48 +00002340 // Map 'hyphenate-limit-{before,after}: auto;' to 2.
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002341 unsigned minimumPrefixLength;
2342 unsigned minimumSuffixLength;
mitz@apple.comd56f1082011-03-06 22:44:48 +00002343
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002344 if (minimumPrefixLimit < 0)
2345 minimumPrefixLength = 2;
2346 else
2347 minimumPrefixLength = static_cast<unsigned>(minimumPrefixLimit);
2348
2349 if (minimumSuffixLimit < 0)
mitz@apple.comd56f1082011-03-06 22:44:48 +00002350 minimumSuffixLength = 2;
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002351 else
2352 minimumSuffixLength = static_cast<unsigned>(minimumSuffixLimit);
mitz@apple.comd56f1082011-03-06 22:44:48 +00002353
2354 if (pos - lastSpace <= minimumSuffixLength)
2355 return;
2356
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00002357 if (consecutiveHyphenatedLinesLimit >= 0 && consecutiveHyphenatedLines >= static_cast<unsigned>(consecutiveHyphenatedLinesLimit))
2358 return;
2359
commit-queue@webkit.orge60bb902011-09-08 19:18:43 +00002360 int hyphenWidth = measureHyphenWidth(text, font);
mitz@apple.comb2107652010-06-21 16:54:52 +00002361
hyatt@apple.com0acc9352011-02-17 19:19:07 +00002362 float maxPrefixWidth = availableWidth - xPos - hyphenWidth - lastSpaceWordSpacing;
mitz@apple.com7c67b292010-09-12 23:04:16 +00002363 // If the maximum width available for the prefix before the hyphen is small, then it is very unlikely
2364 // that an hyphenation opportunity exists, so do not bother to look for it.
2365 if (maxPrefixWidth <= font.pixelSize() * 5 / 4)
2366 return;
2367
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002368 TextRun run = RenderBlock::constructTextRun(text, font, text, lastSpace, pos - lastSpace, text->style());
zimmermann@webkit.org544abde2011-06-12 12:40:40 +00002369 run.setCharactersLength(text->textLength() - lastSpace);
2370 ASSERT(run.charactersLength() >= run.length());
2371
morrita@google.com6e818ec2012-05-11 03:28:46 +00002372 run.setTabSize(!collapseWhiteSpace, text->style()->tabSize());
zimmermann@webkit.org8a7e7ff2011-05-24 15:27:36 +00002373 run.setXPos(xPos + lastSpaceWordSpacing);
2374
2375 unsigned prefixLength = font.offsetForPosition(run, maxPrefixWidth, false);
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002376 if (prefixLength < minimumPrefixLength)
mitz@apple.comb2107652010-06-21 16:54:52 +00002377 return;
2378
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002379 prefixLength = lastHyphenLocation(text->characters() + lastSpace, pos - lastSpace, min(prefixLength, pos - lastSpace - minimumSuffixLength) + 1, localeIdentifier);
2380 if (!prefixLength || prefixLength < minimumPrefixLength)
mitz@apple.comb2107652010-06-21 16:54:52 +00002381 return;
2382
mitz@apple.com348878a2011-12-11 19:06:56 +00002383 // When lastSapce is a space, which it always is except sometimes at the beginning of a line or after collapsed
2384 // space, it should not count towards hyphenate-limit-before.
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002385 if (prefixLength == minimumPrefixLength) {
2386 UChar characterAtLastSpace = text->characterAt(lastSpace);
mitz@apple.com348878a2011-12-11 19:06:56 +00002387 if (characterAtLastSpace == ' ' || characterAtLastSpace == '\n' || characterAtLastSpace == '\t' || characterAtLastSpace == noBreakSpace)
2388 return;
2389 }
2390
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002391 ASSERT(pos - lastSpace - prefixLength >= minimumSuffixLength);
mitz@apple.comd56f1082011-03-06 22:44:48 +00002392
mitz@apple.comb2107652010-06-21 16:54:52 +00002393#if !ASSERT_DISABLED
hyatt@apple.com0acc9352011-02-17 19:19:07 +00002394 float prefixWidth = hyphenWidth + textWidth(text, lastSpace, prefixLength, font, xPos, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
mitz@apple.comb2107652010-06-21 16:54:52 +00002395 ASSERT(xPos + prefixWidth <= availableWidth);
mitz@apple.com34b43c72010-06-21 17:21:22 +00002396#else
2397 UNUSED_PARAM(isFixedPitch);
mitz@apple.comb2107652010-06-21 16:54:52 +00002398#endif
2399
eric@webkit.orgbd143592011-03-29 17:44:41 +00002400 lineBreak.moveTo(text, lastSpace + prefixLength, nextBreakable);
mitz@apple.comb2107652010-06-21 16:54:52 +00002401 hyphenated = true;
2402}
2403
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002404class TrailingObjects {
2405public:
2406 TrailingObjects();
2407 void setTrailingWhitespace(RenderText*);
2408 void clear();
2409 void appendBoxIfNeeded(RenderBox*);
mitz@apple.come98acc92011-05-22 04:44:27 +00002410
2411 enum CollapseFirstSpaceOrNot { DoNotCollapseFirstSpace, CollapseFirstSpace };
2412
2413 void updateMidpointsForTrailingBoxes(LineMidpointState&, const InlineIterator& lBreak, CollapseFirstSpaceOrNot);
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002414
2415private:
2416 RenderText* m_whitespace;
2417 Vector<RenderBox*, 4> m_boxes;
2418};
2419
2420TrailingObjects::TrailingObjects()
2421 : m_whitespace(0)
2422{
2423}
2424
2425inline void TrailingObjects::setTrailingWhitespace(RenderText* whitespace)
2426{
2427 ASSERT(whitespace);
2428 m_whitespace = whitespace;
2429}
2430
2431inline void TrailingObjects::clear()
2432{
2433 m_whitespace = 0;
2434 m_boxes.clear();
2435}
2436
2437inline void TrailingObjects::appendBoxIfNeeded(RenderBox* box)
2438{
2439 if (m_whitespace)
2440 m_boxes.append(box);
2441}
2442
mitz@apple.come98acc92011-05-22 04:44:27 +00002443void TrailingObjects::updateMidpointsForTrailingBoxes(LineMidpointState& lineMidpointState, const InlineIterator& lBreak, CollapseFirstSpaceOrNot collapseFirstSpace)
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002444{
2445 if (!m_whitespace)
2446 return;
2447
2448 // This object is either going to be part of the last midpoint, or it is going to be the actual endpoint.
2449 // In both cases we just decrease our pos by 1 level to exclude the space, allowing it to - in effect - collapse into the newline.
2450 if (lineMidpointState.numMidpoints % 2) {
2451 // Find the trailing space object's midpoint.
2452 int trailingSpaceMidpoint = lineMidpointState.numMidpoints - 1;
inferno@chromium.org92ca04e2011-08-01 18:03:03 +00002453 for ( ; trailingSpaceMidpoint > 0 && lineMidpointState.midpoints[trailingSpaceMidpoint].m_obj != m_whitespace; --trailingSpaceMidpoint) { }
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002454 ASSERT(trailingSpaceMidpoint >= 0);
mitz@apple.come98acc92011-05-22 04:44:27 +00002455 if (collapseFirstSpace == CollapseFirstSpace)
2456 lineMidpointState.midpoints[trailingSpaceMidpoint].m_pos--;
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002457
eric@webkit.org060caf62011-05-03 22:11:39 +00002458 // Now make sure every single trailingPositionedBox following the trailingSpaceMidpoint properly stops and starts
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002459 // ignoring spaces.
2460 size_t currentMidpoint = trailingSpaceMidpoint + 1;
2461 for (size_t i = 0; i < m_boxes.size(); ++i) {
2462 if (currentMidpoint >= lineMidpointState.numMidpoints) {
2463 // We don't have a midpoint for this box yet.
2464 InlineIterator ignoreStart(0, m_boxes[i], 0);
2465 addMidpoint(lineMidpointState, ignoreStart); // Stop ignoring.
2466 addMidpoint(lineMidpointState, ignoreStart); // Start ignoring again.
2467 } else {
2468 ASSERT(lineMidpointState.midpoints[currentMidpoint].m_obj == m_boxes[i]);
2469 ASSERT(lineMidpointState.midpoints[currentMidpoint + 1].m_obj == m_boxes[i]);
2470 }
2471 currentMidpoint += 2;
2472 }
2473 } else if (!lBreak.m_obj) {
2474 ASSERT(m_whitespace->isText());
mitz@apple.come98acc92011-05-22 04:44:27 +00002475 ASSERT(collapseFirstSpace == CollapseFirstSpace);
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002476 // Add a new end midpoint that stops right at the very end.
2477 unsigned length = m_whitespace->textLength();
2478 unsigned pos = length >= 2 ? length - 2 : UINT_MAX;
2479 InlineIterator endMid(0, m_whitespace, pos);
2480 addMidpoint(lineMidpointState, endMid);
2481 for (size_t i = 0; i < m_boxes.size(); ++i) {
2482 InlineIterator ignoreStart(0, m_boxes[i], 0);
2483 addMidpoint(lineMidpointState, ignoreStart); // Stop ignoring spaces.
2484 addMidpoint(lineMidpointState, ignoreStart); // Start ignoring again.
2485 }
2486 }
2487}
2488
leviw@chromium.org1a508692011-05-05 00:01:11 +00002489void RenderBlock::LineBreaker::reset()
kociendae40cb942004-10-05 20:05:38 +00002490{
leviw@chromium.org1a508692011-05-05 00:01:11 +00002491 m_positionedObjects.clear();
2492 m_hyphenated = false;
2493 m_clear = CNONE;
2494}
2495
enrica@apple.com885c84d2012-10-10 05:48:51 +00002496InlineIterator RenderBlock::LineBreaker::nextLineBreak(InlineBidiResolver& resolver, LineInfo& lineInfo, RenderTextInfo& renderTextInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements& wordMeasurements)
leviw@chromium.org1a508692011-05-05 00:01:11 +00002497{
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00002498#if !ENABLE(CSS_EXCLUSIONS)
2499 return nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
2500#else
2501 ExclusionShapeInsideInfo* exclusionShapeInsideInfo = layoutExclusionShapeInsideInfo(m_block);
2502 if (!exclusionShapeInsideInfo || !exclusionShapeInsideInfo->hasSegments())
2503 return nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
2504
2505 InlineIterator end = resolver.position();
2506 InlineIterator oldEnd = end;
2507
2508 const SegmentList& segments = exclusionShapeInsideInfo->segments();
2509 SegmentRangeList& segmentRanges = exclusionShapeInsideInfo->segmentRanges();
2510
2511 for (unsigned i = 0; i < segments.size(); i++) {
2512 InlineIterator segmentStart = resolver.position();
2513 end = nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
2514
2515 ASSERT(segmentRanges.size() == i);
2516 if (resolver.position() == end) {
2517 // Nothing fit this segment
2518 segmentRanges.append(LineSegmentRange(segmentStart, segmentStart));
2519 resolver.setPositionIgnoringNestedIsolates(segmentStart);
2520 } else {
2521 // Note that resolver.position is already skipping some of the white space at the beginning of the line,
2522 // so that's why segmentStart might be different than resolver.position().
2523 LineSegmentRange range(resolver.position(), end);
2524 segmentRanges.append(range);
2525 resolver.setPosition(end, numberOfIsolateAncestors(end));
2526
2527 if (lineInfo.previousLineBrokeCleanly()) {
2528 // If we hit a new line break, just stop adding anything to this line.
2529 break;
2530 }
2531 }
2532 }
2533 resolver.setPositionIgnoringNestedIsolates(oldEnd);
2534 return end;
2535#endif
2536}
2537
2538InlineIterator RenderBlock::LineBreaker::nextSegmentBreak(InlineBidiResolver& resolver, LineInfo& lineInfo, RenderTextInfo& renderTextInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements& wordMeasurements)
2539{
leviw@chromium.org1a508692011-05-05 00:01:11 +00002540 reset();
2541
2542 ASSERT(resolver.position().root() == m_block);
mitz@apple.com51017322008-02-26 06:47:43 +00002543
eric@webkit.org86a865a2011-03-29 15:30:41 +00002544 bool appliedStartWidth = resolver.position().m_pos > 0;
yael.aharon@nokia.com1cfbceb2011-06-06 18:32:54 +00002545 bool includeEndWidth = true;
hyatt@apple.comb3466af2009-06-13 06:04:40 +00002546 LineMidpointState& lineMidpointState = resolver.midpointState();
mitz@apple.com1a301772008-03-11 18:30:36 +00002547
leviw@chromium.org1a508692011-05-05 00:01:11 +00002548 LineWidth width(m_block, lineInfo.isFirstLine());
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002549
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002550 skipLeadingWhitespace(resolver, lineInfo, lastFloatFromPreviousLine, width);
kociendae40cb942004-10-05 20:05:38 +00002551
mitz@apple.com15035e62008-07-05 20:44:44 +00002552 if (resolver.position().atEnd())
2553 return resolver.position();
mjs6f821c82002-03-22 00:31:57 +00002554
hyatt33f8d492002-11-12 21:44:52 +00002555 // This variable is used only if whitespace isn't set to PRE, and it tells us whether
2556 // or not we are currently ignoring whitespace.
2557 bool ignoringSpaces = false;
mitz@apple.com15035e62008-07-05 20:44:44 +00002558 InlineIterator ignoreStart;
eric@webkit.org060caf62011-05-03 22:11:39 +00002559
hyatt33f8d492002-11-12 21:44:52 +00002560 // This variable tracks whether the very last character we saw was a space. We use
2561 // this to detect when we encounter a second space so we know we have to terminate
2562 // a run.
rjwc9c257d2003-01-24 03:46:17 +00002563 bool currentCharacterIsSpace = false;
harrisone343c412005-01-18 01:07:26 +00002564 bool currentCharacterIsWS = false;
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002565 TrailingObjects trailingObjects;
hyatt98b16282004-03-31 18:43:12 +00002566
mitz@apple.com15035e62008-07-05 20:44:44 +00002567 InlineIterator lBreak = resolver.position();
mjs6f821c82002-03-22 00:31:57 +00002568
eric@webkit.orgbd143592011-03-29 17:44:41 +00002569 // FIXME: It is error-prone to split the position object out like this.
2570 // Teach this code to work with objects instead of this split tuple.
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002571 InlineIterator current = resolver.position();
2572 RenderObject* last = current.m_obj;
ddkilzere8759ef2007-03-25 06:28:19 +00002573 bool atStart = true;
kociendabb0c24b2001-08-24 14:24:40 +00002574
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002575 bool startingNewParagraph = lineInfo.previousLineBrokeCleanly();
2576 lineInfo.setPreviousLineBrokeCleanly(false);
ddkilzer5d01fa22007-01-29 03:10:37 +00002577
2578 bool autoWrapWasEverTrueOnLine = false;
mitz@apple.com25beac62008-02-24 18:48:27 +00002579 bool floatsFitOnLine = true;
eric@webkit.org060caf62011-05-03 22:11:39 +00002580
hyatt@apple.com69340902008-01-16 21:24:21 +00002581 // Firefox and Opera will allow a table cell to grow to fit an image inside it under
eric@webkit.org060caf62011-05-03 22:11:39 +00002582 // very specific circumstances (in order to match common WinIE renderings).
2583 // Not supporting the quirk has caused us to mis-render some real sites. (See Bugzilla 10517.)
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002584 RenderStyle* blockStyle = m_block->style();
2585 bool allowImagesToBreak = !m_block->document()->inQuirksMode() || !m_block->isTableCell() || !blockStyle->logicalWidth().isIntrinsicOrAuto();
hyatt@apple.com69340902008-01-16 21:24:21 +00002586
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002587 EWhiteSpace currWS = blockStyle->whiteSpace();
hyattb0d9f602007-01-15 01:28:23 +00002588 EWhiteSpace lastWS = currWS;
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002589 while (current.m_obj) {
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002590 RenderStyle* currentStyle = current.m_obj->style();
eric@webkit.orgd4b9d772011-08-22 23:34:31 +00002591 RenderObject* next = bidiNextSkippingEmptyInlines(m_block, current.m_obj);
yael.aharon@nokia.com1cfbceb2011-06-06 18:32:54 +00002592 if (next && next->parent() && !next->parent()->isDescendantOf(current.m_obj->parent()))
2593 includeEndWidth = true;
mitz@apple.comddb59872011-04-05 05:21:16 +00002594
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002595 currWS = current.m_obj->isReplaced() ? current.m_obj->parent()->style()->whiteSpace() : currentStyle->whiteSpace();
hyattb0d9f602007-01-15 01:28:23 +00002596 lastWS = last->isReplaced() ? last->parent()->style()->whiteSpace() : last->style()->whiteSpace();
eric@webkit.org060caf62011-05-03 22:11:39 +00002597
hyattb0d9f602007-01-15 01:28:23 +00002598 bool autoWrap = RenderStyle::autoWrap(currWS);
ddkilzer5d01fa22007-01-29 03:10:37 +00002599 autoWrapWasEverTrueOnLine = autoWrapWasEverTrueOnLine || autoWrap;
zimmermannac3781f2007-02-04 01:25:03 +00002600
mjsd2948ef2007-02-26 19:29:04 +00002601#if ENABLE(SVG)
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002602 bool preserveNewline = current.m_obj->isSVGInlineText() ? false : RenderStyle::preserveNewline(currWS);
zimmermannac3781f2007-02-04 01:25:03 +00002603#else
hyattb0d9f602007-01-15 01:28:23 +00002604 bool preserveNewline = RenderStyle::preserveNewline(currWS);
zimmermannac3781f2007-02-04 01:25:03 +00002605#endif
2606
hyattb0d9f602007-01-15 01:28:23 +00002607 bool collapseWhiteSpace = RenderStyle::collapseWhiteSpace(currWS);
eric@webkit.org060caf62011-05-03 22:11:39 +00002608
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002609 if (current.m_obj->isBR()) {
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00002610 if (width.fitsOnLine()) {
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002611 lBreak.moveToStartOf(current.m_obj);
mitz@apple.com1a301772008-03-11 18:30:36 +00002612 lBreak.increment();
hyatt0c3a9862004-02-23 21:26:26 +00002613
hyatt33f8d492002-11-12 21:44:52 +00002614 // A <br> always breaks a line, so don't let the line be collapsed
2615 // away. Also, the space at the end of a line with a <br> does not
hyatt01eff982003-03-14 20:13:23 +00002616 // get collapsed away. It only does this if the previous line broke
2617 // cleanly. Otherwise the <br> has no effect on whether the line is
2618 // empty or not.
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002619 if (startingNewParagraph)
hyatt@apple.com5950bd42011-09-27 20:39:57 +00002620 lineInfo.setEmpty(false, m_block, &width);
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002621 trailingObjects.clear();
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002622 lineInfo.setPreviousLineBrokeCleanly(true);
hyatt74eec4d2003-03-23 08:02:47 +00002623
robert@webkit.org3c75e502012-10-21 10:27:50 +00002624 // A <br> with clearance always needs a linebox in case the lines below it get dirtied later and
2625 // need to check for floats to clear - so if we're ignoring spaces, stop ignoring them and add a
2626 // run for this object.
2627 if (ignoringSpaces && currentStyle->clear() != CNONE) {
2628 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, 0)); // Stop ignoring spaces.
2629 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, 0)); // Start ignoring again.
2630 }
2631
leviw@chromium.org1a508692011-05-05 00:01:11 +00002632 if (!lineInfo.isEmpty())
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002633 m_clear = currentStyle->clear();
kociendabb0c24b2001-08-24 14:24:40 +00002634 }
2635 goto end;
2636 }
hyattb0d9f602007-01-15 01:28:23 +00002637
simon.fraser@apple.com2f071852012-06-25 00:11:30 +00002638 if (current.m_obj->isOutOfFlowPositioned()) {
rniwa@webkit.org76aa5222011-05-04 13:03:32 +00002639 // If our original display wasn't an inline type, then we can
2640 // go ahead and determine our static inline position now.
2641 RenderBox* box = toRenderBox(current.m_obj);
2642 bool isInlineType = box->style()->isOriginalDisplayInlineType();
2643 if (!isInlineType)
hyatt@apple.coma5cac3f2011-10-12 18:51:17 +00002644 m_block->setStaticInlinePositionForChild(box, m_block->logicalHeight(), m_block->startOffsetForContent(m_block->logicalHeight()));
rniwa@webkit.org76aa5222011-05-04 13:03:32 +00002645 else {
2646 // If our original display was an INLINE type, then we can go ahead
2647 // and determine our static y position now.
leviw@chromium.org1a508692011-05-05 00:01:11 +00002648 box->layer()->setStaticBlockPosition(m_block->logicalHeight());
hyatt98ee7e42003-05-14 01:39:15 +00002649 }
rniwa@webkit.org76aa5222011-05-04 13:03:32 +00002650
2651 // If we're ignoring spaces, we have to stop and include this object and
2652 // then start ignoring spaces again.
2653 if (isInlineType || current.m_obj->container()->isRenderInline()) {
2654 if (ignoringSpaces) {
2655 ignoreStart.m_obj = current.m_obj;
2656 ignoreStart.m_pos = 0;
2657 addMidpoint(lineMidpointState, ignoreStart); // Stop ignoring spaces.
2658 addMidpoint(lineMidpointState, ignoreStart); // Start ignoring again.
2659 }
2660 trailingObjects.appendBoxIfNeeded(box);
2661 } else
leviw@chromium.org1a508692011-05-05 00:01:11 +00002662 m_positionedObjects.append(box);
mitz@apple.comd67fb212011-12-19 02:51:46 +00002663 } else if (current.m_obj->isFloating()) {
2664 RenderBox* floatBox = toRenderBox(current.m_obj);
2665 FloatingObject* f = m_block->insertFloatingObject(floatBox);
2666 // check if it fits in the current line.
2667 // If it does, position it now, otherwise, position
2668 // it after moving to next line (in newLine() func)
2669 if (floatsFitOnLine && width.fitsOnLine(m_block->logicalWidthForFloat(f))) {
2670 m_block->positionNewFloatOnLine(f, lastFloatFromPreviousLine, lineInfo, width);
2671 if (lBreak.m_obj == current.m_obj) {
2672 ASSERT(!lBreak.m_pos);
2673 lBreak.increment();
2674 }
2675 } else
2676 floatsFitOnLine = false;
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002677 } else if (current.m_obj->isRenderInline()) {
bdakinf876bee2007-10-30 05:27:09 +00002678 // Right now, we should only encounter empty inlines here.
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002679 ASSERT(!current.m_obj->firstChild());
eric@webkit.org060caf62011-05-03 22:11:39 +00002680
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002681 RenderInline* flowBox = toRenderInline(current.m_obj);
eric@webkit.org060caf62011-05-03 22:11:39 +00002682
2683 // Now that some inline flows have line boxes, if we are already ignoring spaces, we need
2684 // to make sure that we stop to include this object and then start ignoring spaces again.
2685 // If this object is at the start of the line, we need to behave like list markers and
bdakinf876bee2007-10-30 05:27:09 +00002686 // start ignoring spaces.
robert@webkit.orgd9d595e2012-02-17 21:48:09 +00002687 bool requiresLineBox = alwaysRequiresLineBox(flowBox);
robert@webkit.org56e5a9f2012-02-17 21:10:42 +00002688 if (requiresLineBox || requiresLineBoxForContent(flowBox, lineInfo)) {
2689 // An empty inline that only has line-height, vertical-align or font-metrics will only get a
2690 // line box to affect the height of the line if the rest of the line is not empty.
2691 if (requiresLineBox)
2692 lineInfo.setEmpty(false, m_block, &width);
bdakinf876bee2007-10-30 05:27:09 +00002693 if (ignoringSpaces) {
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002694 trailingObjects.clear();
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002695 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, 0)); // Stop ignoring spaces.
2696 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, 0)); // Start ignoring again.
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002697 } else if (blockStyle->collapseWhiteSpace() && resolver.position().m_obj == current.m_obj
leviw@chromium.org1a508692011-05-05 00:01:11 +00002698 && shouldSkipWhitespaceAfterStartObject(m_block, current.m_obj, lineMidpointState)) {
eric@webkit.org060caf62011-05-03 22:11:39 +00002699 // Like with list markers, we start ignoring spaces to make sure that any
bdakinf876bee2007-10-30 05:27:09 +00002700 // additional spaces we see will be discarded.
2701 currentCharacterIsSpace = true;
2702 currentCharacterIsWS = true;
2703 ignoringSpaces = true;
2704 }
2705 }
2706
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002707 width.addUncommittedWidth(borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox));
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002708 } else if (current.m_obj->isReplaced()) {
2709 RenderBox* replacedBox = toRenderBox(current.m_obj);
hyatt@apple.comd885df72009-01-22 02:31:52 +00002710
robert@webkit.org0903cf52012-12-11 18:14:16 +00002711 if (atStart)
2712 width.updateAvailableWidth(replacedBox->logicalHeight());
2713
hyattde396342003-10-29 08:57:20 +00002714 // Break on replaced elements if either has normal white-space.
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002715 if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!current.m_obj->isImage() || allowImagesToBreak)) {
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002716 width.commit();
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002717 lBreak.moveToStartOf(current.m_obj);
hyatt711fe232002-11-20 21:25:14 +00002718 }
2719
mitz@apple.combfdc9112008-02-21 19:59:40 +00002720 if (ignoringSpaces)
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002721 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, 0));
mitz@apple.combfdc9112008-02-21 19:59:40 +00002722
hyatt@apple.com5950bd42011-09-27 20:39:57 +00002723 lineInfo.setEmpty(false, m_block, &width);
hyatt33f8d492002-11-12 21:44:52 +00002724 ignoringSpaces = false;
rjwc9c257d2003-01-24 03:46:17 +00002725 currentCharacterIsSpace = false;
harrisone343c412005-01-18 01:07:26 +00002726 currentCharacterIsWS = false;
rniwa@webkit.org105350c2011-05-03 20:33:25 +00002727 trailingObjects.clear();
hamaji@chromium.org382642b2009-12-01 07:37:14 +00002728
bdakinf876bee2007-10-30 05:27:09 +00002729 // Optimize for a common case. If we can't find whitespace after the list
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00002730 // item, then this is all moot.
eae@chromium.orgee8613e2011-11-12 01:12:58 +00002731 LayoutUnit replacedLogicalWidth = m_block->logicalWidthForChild(replacedBox) + m_block->marginStartForChild(replacedBox) + m_block->marginEndForChild(replacedBox) + inlineLogicalWidth(current.m_obj);
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002732 if (current.m_obj->isListMarker()) {
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002733 if (blockStyle->collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(m_block, current.m_obj, lineMidpointState)) {
eric@webkit.org060caf62011-05-03 22:11:39 +00002734 // Like with inline flows, we start ignoring spaces to make sure that any
bdakinf876bee2007-10-30 05:27:09 +00002735 // additional spaces we see will be discarded.
2736 currentCharacterIsSpace = true;
2737 currentCharacterIsWS = true;
2738 ignoringSpaces = true;
hyatte85e4a72002-12-08 02:06:16 +00002739 }
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002740 if (toRenderListMarker(current.m_obj)->isInside())
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002741 width.addUncommittedWidth(replacedLogicalWidth);
justing244d3a32006-04-13 01:31:24 +00002742 } else
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002743 width.addUncommittedWidth(replacedLogicalWidth);
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002744 if (current.m_obj->isRubyRun())
2745 width.applyOverhang(toRenderRubyRun(current.m_obj), last, next);
2746 } else if (current.m_obj->isText()) {
2747 if (!current.m_pos)
mitz@apple.com51017322008-02-26 06:47:43 +00002748 appliedStartWidth = false;
2749
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002750 RenderText* t = toRenderText(current.m_obj);
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00002751
zimmermann@webkit.org6e96afd2010-09-10 15:35:50 +00002752#if ENABLE(SVG)
2753 bool isSVGText = t->isSVGInlineText();
2754#endif
2755
commit-queue@webkit.org5047aee2012-08-14 02:52:03 +00002756 if (t->style()->hasTextCombine() && current.m_obj->isCombineText() && !toRenderCombineText(current.m_obj)->isCombined())
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002757 toRenderCombineText(current.m_obj)->combineText();
kociendabb0c24b2001-08-24 14:24:40 +00002758
commit-queue@webkit.org5047aee2012-08-14 02:52:03 +00002759 RenderStyle* style = t->style(lineInfo.isFirstLine());
mitz@apple.comb2107652010-06-21 16:54:52 +00002760 const Font& f = style->font();
mitz@apple.com34106442009-02-01 06:23:39 +00002761 bool isFixedPitch = f.isFixedPitch();
mitz@apple.com6ae88612011-03-03 23:09:11 +00002762 bool canHyphenate = style->hyphens() == HyphensAuto && WebCore::canHyphenate(style->locale());
weinigf28a1c32007-02-14 14:10:31 +00002763
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002764 unsigned lastSpace = current.m_pos;
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002765 float wordSpacing = currentStyle->wordSpacing();
hyatt@apple.com0acc9352011-02-17 19:19:07 +00002766 float lastSpaceWordSpacing = 0;
enrica@apple.com885c84d2012-10-10 05:48:51 +00002767 float wordSpacingForWordMeasurement = 0;
hyattffe78712003-02-11 01:59:29 +00002768
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002769 float wrapW = width.uncommittedWidth() + inlineLogicalWidth(current.m_obj, !appliedStartWidth, true);
hyatt@apple.com0acc9352011-02-17 19:19:07 +00002770 float charWidth = 0;
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002771 bool breakNBSP = autoWrap && currentStyle->nbspMode() == SPACE;
weinigf28a1c32007-02-14 14:10:31 +00002772 // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word,
2773 // which is only possible if the word is the first thing on the line, that is, if |w| is zero.
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002774 bool breakWords = currentStyle->breakWords() && ((autoWrap && !width.committedWidth()) || currWS == PRE);
weinigf28a1c32007-02-14 14:10:31 +00002775 bool midWordBreak = false;
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002776 bool breakAll = currentStyle->wordBreak() == BreakAllWordBreak && autoWrap;
hyatt@apple.com0acc9352011-02-17 19:19:07 +00002777 float hyphenWidth = 0;
hyattea474f72007-04-20 05:02:19 +00002778
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00002779 if (t->isWordBreak()) {
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002780 width.commit();
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002781 lBreak.moveToStartOf(current.m_obj);
2782 ASSERT(current.m_pos == t->textLength());
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00002783 }
2784
commit-queue@webkit.orgd639fb72012-09-01 19:46:16 +00002785 if (renderTextInfo.m_text != t) {
2786 t->updateTextIfNeeded();
mitz@apple.com6a859602012-08-27 15:31:56 +00002787 renderTextInfo.m_text = t;
mitz@apple.comd4c153d2012-09-16 23:36:41 +00002788 renderTextInfo.m_font = &f;
mitz@apple.com6a859602012-08-27 15:31:56 +00002789 renderTextInfo.m_layout = f.createLayout(t, width.currentWidth(), collapseWhiteSpace);
commit-queue@webkit.org81df5c42012-11-06 19:10:09 +00002790 renderTextInfo.m_lineBreakIterator.reset(t->text(), style->locale());
mitz@apple.comd4c153d2012-09-16 23:36:41 +00002791 } else if (renderTextInfo.m_layout && renderTextInfo.m_font != &f) {
2792 renderTextInfo.m_font = &f;
2793 renderTextInfo.m_layout = f.createLayout(t, width.currentWidth(), collapseWhiteSpace);
mitz@apple.com6a859602012-08-27 15:31:56 +00002794 }
mitz@apple.comd4c153d2012-09-16 23:36:41 +00002795
mitz@apple.com6a859602012-08-27 15:31:56 +00002796 TextLayout* textLayout = renderTextInfo.m_layout.get();
2797
mitz@apple.com8520cd82012-09-22 01:00:01 +00002798 // Non-zero only when kerning is enabled and TextLayout isn't used, in which case we measure
2799 // words with their trailing space, then subtract its width.
2800 float wordTrailingSpaceWidth = (f.typesettingFeatures() & Kerning) && !textLayout ? f.width(constructTextRun(t, f, &space, 1, style)) + wordSpacing : 0;
2801
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002802 for (; current.m_pos < t->textLength(); current.fastIncrementInTextNode()) {
rjwc9c257d2003-01-24 03:46:17 +00002803 bool previousCharacterIsSpace = currentCharacterIsSpace;
harrisone343c412005-01-18 01:07:26 +00002804 bool previousCharacterIsWS = currentCharacterIsWS;
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002805 UChar c = current.current();
hyattb0d9f602007-01-15 01:28:23 +00002806 currentCharacterIsSpace = c == ' ' || c == '\t' || (!preserveNewline && (c == '\n'));
darin47ece0d2005-09-04 07:42:31 +00002807
hyattb0d9f602007-01-15 01:28:23 +00002808 if (!collapseWhiteSpace || !currentCharacterIsSpace)
hyatt@apple.com5950bd42011-09-27 20:39:57 +00002809 lineInfo.setEmpty(false, m_block, &width);
mitz@apple.combe429562008-03-07 01:09:51 +00002810
mitz@apple.com20e34452010-09-28 19:38:15 +00002811 if (c == softHyphen && autoWrap && !hyphenWidth && style->hyphens() != HyphensNone) {
commit-queue@webkit.orge60bb902011-09-08 19:18:43 +00002812 hyphenWidth = measureHyphenWidth(t, f);
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002813 width.addUncommittedWidth(hyphenWidth);
hyatt78b85132004-03-29 20:07:45 +00002814 }
mitz@apple.com20e34452010-09-28 19:38:15 +00002815
hyatt3aff2332003-01-23 01:15:28 +00002816 bool applyWordSpacing = false;
eric@webkit.org060caf62011-05-03 22:11:39 +00002817
darinf9e5d6c2007-01-09 14:54:26 +00002818 currentCharacterIsWS = currentCharacterIsSpace || (breakNBSP && c == noBreakSpace);
harrisone343c412005-01-18 01:07:26 +00002819
weiniged111c12007-07-13 22:45:11 +00002820 if ((breakAll || breakWords) && !midWordBreak) {
2821 wrapW += charWidth;
mitz@apple.com880d8e12011-08-17 20:52:31 +00002822 bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && current.m_pos + 1 < t->textLength() && U16_IS_TRAIL(t->characters()[current.m_pos + 1]);
enrica@apple.com885c84d2012-10-10 05:48:51 +00002823 charWidth = textWidth(t, current.m_pos, midWordBreakIsBeforeSurrogatePair ? 2 : 1, f, width.committedWidth() + wrapW, isFixedPitch, collapseWhiteSpace, 0, textLayout);
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00002824 midWordBreak = width.committedWidth() + wrapW + charWidth > width.availableWidth();
weinigf28a1c32007-02-14 14:10:31 +00002825 }
darin47ece0d2005-09-04 07:42:31 +00002826
commit-queue@webkit.org81df5c42012-11-06 19:10:09 +00002827 bool betweenWords = c == '\n' || (currWS != PRE && !atStart && isBreakable(renderTextInfo.m_lineBreakIterator, current.m_pos, current.m_nextBreakablePosition, breakNBSP)
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002828 && (style->hyphens() != HyphensNone || (current.previousInSameNode() != softHyphen)));
mitz@apple.com20e34452010-09-28 19:38:15 +00002829
weiniged111c12007-07-13 22:45:11 +00002830 if (betweenWords || midWordBreak) {
hyatt0c05e102006-04-14 08:15:00 +00002831 bool stoppedIgnoringSpaces = false;
hyatt33f8d492002-11-12 21:44:52 +00002832 if (ignoringSpaces) {
rjwc9c257d2003-01-24 03:46:17 +00002833 if (!currentCharacterIsSpace) {
hyatt33f8d492002-11-12 21:44:52 +00002834 // Stop ignoring spaces and begin at this
2835 // new point.
hyatt48710d62003-08-21 09:17:13 +00002836 ignoringSpaces = false;
eseideld13fe532005-11-30 02:40:29 +00002837 lastSpaceWordSpacing = 0;
enrica@apple.com885c84d2012-10-10 05:48:51 +00002838 wordSpacingForWordMeasurement = 0;
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002839 lastSpace = current.m_pos; // e.g., "Foo goo", don't add in any of the ignored spaces.
2840 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos));
hyatt0c05e102006-04-14 08:15:00 +00002841 stoppedIgnoringSpaces = true;
harrisone343c412005-01-18 01:07:26 +00002842 } else {
hyatt33f8d492002-11-12 21:44:52 +00002843 // Just keep ignoring these spaces.
hyatt33f8d492002-11-12 21:44:52 +00002844 continue;
2845 }
2846 }
rjwc9c257d2003-01-24 03:46:17 +00002847
enrica@apple.com885c84d2012-10-10 05:48:51 +00002848 wordMeasurements.grow(wordMeasurements.size() + 1);
2849 WordMeasurement& wordMeasurement = wordMeasurements.last();
2850
2851 wordMeasurement.renderer = t;
2852 wordMeasurement.endOffset = current.m_pos;
2853 wordMeasurement.startOffset = lastSpace;
2854
hyatt@apple.com0acc9352011-02-17 19:19:07 +00002855 float additionalTmpW;
mitz@apple.comdc33a5f62012-11-28 19:43:24 +00002856 if (wordTrailingSpaceWidth && c == ' ')
enrica@apple.com885c84d2012-10-10 05:48:51 +00002857 additionalTmpW = textWidth(t, lastSpace, current.m_pos + 1 - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace, &wordMeasurement.fallbackFonts, textLayout) - wordTrailingSpaceWidth;
mitz@apple.comfa13fcc2010-01-07 01:41:32 +00002858 else
enrica@apple.com885c84d2012-10-10 05:48:51 +00002859 additionalTmpW = textWidth(t, lastSpace, current.m_pos - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace, &wordMeasurement.fallbackFonts, textLayout);
2860
2861 wordMeasurement.width = additionalTmpW + wordSpacingForWordMeasurement;
2862 additionalTmpW += lastSpaceWordSpacing;
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002863 width.addUncommittedWidth(additionalTmpW);
hyattffe78712003-02-11 01:59:29 +00002864 if (!appliedStartWidth) {
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002865 width.addUncommittedWidth(inlineLogicalWidth(current.m_obj, true, false));
hyattffe78712003-02-11 01:59:29 +00002866 appliedStartWidth = true;
2867 }
eric@webkit.org060caf62011-05-03 22:11:39 +00002868
enrica@apple.com885c84d2012-10-10 05:48:51 +00002869 applyWordSpacing = wordSpacing && currentCharacterIsSpace;
hyatt3aff2332003-01-23 01:15:28 +00002870
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00002871 if (!width.committedWidth() && autoWrap && !width.fitsOnLine())
rniwa@webkit.org44424752011-04-14 00:58:40 +00002872 width.fitBelowFloats();
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00002873
hyattb0d9f602007-01-15 01:28:23 +00002874 if (autoWrap || breakWords) {
hyattdca76e92005-11-02 08:52:50 +00002875 // If we break only after white-space, consider the current character
kociendae4134242004-10-25 18:48:44 +00002876 // as candidate width for this line.
ap932806a2006-10-01 09:06:09 +00002877 bool lineWasTooWide = false;
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002878 if (width.fitsOnLine() && currentCharacterIsWS && currentStyle->breakOnlyAfterWhiteSpace() && !midWordBreak) {
enrica@apple.com885c84d2012-10-10 05:48:51 +00002879 float charWidth = textWidth(t, current.m_pos, 1, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace, &wordMeasurement.fallbackFonts, textLayout) + (applyWordSpacing ? wordSpacing : 0);
ap932806a2006-10-01 09:06:09 +00002880 // Check if line is too big even without the extra space
eric@webkit.org060caf62011-05-03 22:11:39 +00002881 // at the end of the line. If it is not, do nothing.
2882 // If the line needs the extra whitespace to be too long,
2883 // then move the line break to the space and skip all
ap932806a2006-10-01 09:06:09 +00002884 // additional whitespace.
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00002885 if (!width.fitsOnLine(charWidth)) {
ap932806a2006-10-01 09:06:09 +00002886 lineWasTooWide = true;
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002887 lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition);
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002888 skipTrailingWhitespace(lBreak, lineInfo);
kocienda9dbe9b12004-10-22 20:07:05 +00002889 }
ap932806a2006-10-01 09:06:09 +00002890 }
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00002891 if (lineWasTooWide || !width.fitsOnLine()) {
2892 if (canHyphenate && !width.fitsOnLine()) {
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002893 tryHyphenating(t, f, style->locale(), consecutiveHyphenatedLines, blockStyle->hyphenationLimitLines(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTmpW, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated);
leviw@chromium.org1a508692011-05-05 00:01:11 +00002894 if (m_hyphenated)
mitz@apple.com67ed70a2010-06-22 22:10:10 +00002895 goto end;
2896 }
leviw@chromium.orgcee20512011-04-06 12:12:58 +00002897 if (lBreak.atTextParagraphSeparator()) {
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002898 if (!stoppedIgnoringSpaces && current.m_pos > 0) {
hyatt0c05e102006-04-14 08:15:00 +00002899 // We need to stop right before the newline and then start up again.
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002900 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos - 1)); // Stop
2901 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); // Start
hyatt0c05e102006-04-14 08:15:00 +00002902 }
mitz@apple.com1a301772008-03-11 18:30:36 +00002903 lBreak.increment();
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002904 lineInfo.setPreviousLineBrokeCleanly(true);
enrica@apple.com885c84d2012-10-10 05:48:51 +00002905 wordMeasurement.endOffset = lBreak.m_pos;
adele7fc3e832006-02-17 09:31:35 +00002906 }
msaboff@apple.com776c286c72012-10-15 16:56:29 +00002907 if (lBreak.m_obj && lBreak.m_pos && lBreak.m_obj->isText() && toRenderText(lBreak.m_obj)->textLength() && toRenderText(lBreak.m_obj)->characterAt(lBreak.m_pos - 1) == softHyphen && style->hyphens() != HyphensNone)
leviw@chromium.org1a508692011-05-05 00:01:11 +00002908 m_hyphenated = true;
enrica@apple.com885c84d2012-10-10 05:48:51 +00002909 if (lBreak.m_pos && lBreak.m_pos != (unsigned)wordMeasurement.endOffset && !wordMeasurement.width) {
2910 if (charWidth) {
2911 wordMeasurement.endOffset = lBreak.m_pos;
2912 wordMeasurement.width = charWidth;
2913 }
2914 }
commit-queue@webkit.org63cc2d02013-01-02 22:52:58 +00002915 // Didn't fit. Jump to the end unless there's still an opportunity to collapse whitespace.
2916 if (ignoringSpaces || !currentStyle->collapseWhiteSpace() || !currentCharacterIsSpace || !previousCharacterIsSpace)
2917 goto end;
darin54008922006-01-13 16:39:05 +00002918 } else {
weiniged111c12007-07-13 22:45:11 +00002919 if (!betweenWords || (midWordBreak && !autoWrap))
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002920 width.addUncommittedWidth(-additionalTmpW);
mitz@apple.com20e34452010-09-28 19:38:15 +00002921 if (hyphenWidth) {
darin54008922006-01-13 16:39:05 +00002922 // Subtract the width of the soft hyphen out since we fit on a line.
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002923 width.addUncommittedWidth(-hyphenWidth);
mitz@apple.com20e34452010-09-28 19:38:15 +00002924 hyphenWidth = 0;
2925 }
darin54008922006-01-13 16:39:05 +00002926 }
rjwc9c257d2003-01-24 03:46:17 +00002927 }
hyatt33f8d492002-11-12 21:44:52 +00002928
hyattb0d9f602007-01-15 01:28:23 +00002929 if (c == '\n' && preserveNewline) {
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002930 if (!stoppedIgnoringSpaces && current.m_pos > 0) {
hyatt0c05e102006-04-14 08:15:00 +00002931 // We need to stop right before the newline and then start up again.
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002932 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos - 1)); // Stop
2933 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); // Start
hyatt0c05e102006-04-14 08:15:00 +00002934 }
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002935 lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition);
mitz@apple.com1a301772008-03-11 18:30:36 +00002936 lBreak.increment();
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002937 lineInfo.setPreviousLineBrokeCleanly(true);
hyatt33f8d492002-11-12 21:44:52 +00002938 return lBreak;
2939 }
hyatta9f48e32003-02-03 22:48:01 +00002940
weinigf28a1c32007-02-14 14:10:31 +00002941 if (autoWrap && betweenWords) {
rniwa@webkit.org58925e82011-04-12 21:32:58 +00002942 width.commit();
weiniged111c12007-07-13 22:45:11 +00002943 wrapW = 0;
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002944 lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition);
weinigf28a1c32007-02-14 14:10:31 +00002945 // Auto-wrapping text should not wrap in the middle of a word once it has had an
2946 // opportunity to break after a word.
2947 breakWords = false;
hyatta9f48e32003-02-03 22:48:01 +00002948 }
eric@webkit.org060caf62011-05-03 22:11:39 +00002949
mitz@apple.com86877722011-08-19 16:29:32 +00002950 if (midWordBreak && !U16_IS_TRAIL(c) && !(category(c) & (Mark_NonSpacing | Mark_Enclosing | Mark_SpacingCombining))) {
darin54008922006-01-13 16:39:05 +00002951 // Remember this as a breakable position in case
2952 // adding the end width forces a break.
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002953 lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition);
weiniged111c12007-07-13 22:45:11 +00002954 midWordBreak &= (breakWords || breakAll);
2955 }
2956
2957 if (betweenWords) {
darin54008922006-01-13 16:39:05 +00002958 lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0;
enrica@apple.com885c84d2012-10-10 05:48:51 +00002959 wordSpacingForWordMeasurement = (applyWordSpacing && wordMeasurement.width) ? wordSpacing : 0;
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002960 lastSpace = current.m_pos;
darin54008922006-01-13 16:39:05 +00002961 }
eric@webkit.org060caf62011-05-03 22:11:39 +00002962
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00002963 if (!ignoringSpaces && currentStyle->collapseWhiteSpace()) {
hyatt33f8d492002-11-12 21:44:52 +00002964 // If we encounter a newline, or if we encounter a
2965 // second space, we need to go ahead and break up this
2966 // run and enter a mode where we start collapsing spaces.
hyatt98b16282004-03-31 18:43:12 +00002967 if (currentCharacterIsSpace && previousCharacterIsSpace) {
hyatt33f8d492002-11-12 21:44:52 +00002968 ignoringSpaces = true;
eric@webkit.org060caf62011-05-03 22:11:39 +00002969
hyatt33f8d492002-11-12 21:44:52 +00002970 // We just entered a mode where we are ignoring
2971 // spaces. Create a midpoint to terminate the run
eric@webkit.org060caf62011-05-03 22:11:39 +00002972 // before the second space.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00002973 addMidpoint(lineMidpointState, ignoreStart);
mitz@apple.come98acc92011-05-22 04:44:27 +00002974 trailingObjects.updateMidpointsForTrailingBoxes(lineMidpointState, InlineIterator(), TrailingObjects::DoNotCollapseFirstSpace);
hyatt33f8d492002-11-12 21:44:52 +00002975 }
2976 }
eseidel789896f2005-11-27 22:52:09 +00002977 } else if (ignoringSpaces) {
hyatt33f8d492002-11-12 21:44:52 +00002978 // Stop ignoring spaces and begin at this
2979 // new point.
2980 ignoringSpaces = false;
eseideld13fe532005-11-30 02:40:29 +00002981 lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0;
enrica@apple.com885c84d2012-10-10 05:48:51 +00002982 wordSpacingForWordMeasurement = (applyWordSpacing && wordMeasurements.last().width) ? wordSpacing : 0;
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002983 lastSpace = current.m_pos; // e.g., "Foo goo", don't add in any of the ignored spaces.
2984 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos));
hyatt33f8d492002-11-12 21:44:52 +00002985 }
hyatt98b16282004-03-31 18:43:12 +00002986
zimmermann@webkit.orgcea314662011-04-05 16:38:10 +00002987#if ENABLE(SVG)
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002988 if (isSVGText && current.m_pos > 0) {
zimmermann@webkit.orgcea314662011-04-05 16:38:10 +00002989 // Force creation of new InlineBoxes for each absolute positioned character (those that start new text chunks).
jchaffraix@webkit.org3e44dfa2011-06-20 23:14:23 +00002990 if (toRenderSVGInlineText(t)->characterStartsNewTextChunk(current.m_pos)) {
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002991 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos - 1));
2992 addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos));
zimmermann@webkit.orgcea314662011-04-05 16:38:10 +00002993 }
2994 }
2995#endif
2996
hyatt98b16282004-03-31 18:43:12 +00002997 if (currentCharacterIsSpace && !previousCharacterIsSpace) {
rniwa@webkit.org15b91522011-05-04 00:38:05 +00002998 ignoreStart.m_obj = current.m_obj;
2999 ignoreStart.m_pos = current.m_pos;
hyatt98b16282004-03-31 18:43:12 +00003000 }
harrisone343c412005-01-18 01:07:26 +00003001
3002 if (!currentCharacterIsWS && previousCharacterIsWS) {
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00003003 if (autoWrap && currentStyle->breakOnlyAfterWhiteSpace())
rniwa@webkit.org15b91522011-05-04 00:38:05 +00003004 lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition);
harrisone343c412005-01-18 01:07:26 +00003005 }
eric@webkit.org060caf62011-05-03 22:11:39 +00003006
hyattb0d9f602007-01-15 01:28:23 +00003007 if (collapseWhiteSpace && currentCharacterIsSpace && !ignoringSpaces)
jchaffraix@webkit.org3e44dfa2011-06-20 23:14:23 +00003008 trailingObjects.setTrailingWhitespace(toRenderText(current.m_obj));
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00003009 else if (!currentStyle->collapseWhiteSpace() || !currentCharacterIsSpace)
rniwa@webkit.org105350c2011-05-03 20:33:25 +00003010 trailingObjects.clear();
3011
ddkilzere8759ef2007-03-25 06:28:19 +00003012 atStart = false;
hyatt33f8d492002-11-12 21:44:52 +00003013 }
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00003014
enrica@apple.com885c84d2012-10-10 05:48:51 +00003015 wordMeasurements.grow(wordMeasurements.size() + 1);
3016 WordMeasurement& wordMeasurement = wordMeasurements.last();
3017 wordMeasurement.renderer = t;
3018
rniwa@webkit.org15b91522011-05-04 00:38:05 +00003019 // IMPORTANT: current.m_pos is > length here!
enrica@apple.com885c84d2012-10-10 05:48:51 +00003020 float additionalTmpW = ignoringSpaces ? 0 : textWidth(t, lastSpace, current.m_pos - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace, &wordMeasurement.fallbackFonts, textLayout);
3021 wordMeasurement.startOffset = lastSpace;
3022 wordMeasurement.endOffset = current.m_pos;
3023 wordMeasurement.width = ignoringSpaces ? 0 : additionalTmpW + wordSpacingForWordMeasurement;
3024 additionalTmpW += lastSpaceWordSpacing;
yael.aharon@nokia.com1cfbceb2011-06-06 18:32:54 +00003025 width.addUncommittedWidth(additionalTmpW + inlineLogicalWidth(current.m_obj, !appliedStartWidth, includeEndWidth));
3026 includeEndWidth = false;
mitz@apple.comb2107652010-06-21 16:54:52 +00003027
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00003028 if (!width.fitsOnLine()) {
mitz@apple.com96cf46d2011-03-14 01:09:26 +00003029 if (canHyphenate)
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00003030 tryHyphenating(t, f, style->locale(), consecutiveHyphenatedLines, blockStyle->hyphenationLimitLines(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTmpW, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated);
rniwa@webkit.org58925e82011-04-12 21:32:58 +00003031
leviw@chromium.org1a508692011-05-05 00:01:11 +00003032 if (!m_hyphenated && lBreak.previousInSameNode() == softHyphen && style->hyphens() != HyphensNone)
3033 m_hyphenated = true;
rniwa@webkit.org58925e82011-04-12 21:32:58 +00003034
leviw@chromium.org1a508692011-05-05 00:01:11 +00003035 if (m_hyphenated)
mitz@apple.comb2107652010-06-21 16:54:52 +00003036 goto end;
3037 }
kociendabb0c24b2001-08-24 14:24:40 +00003038 } else
weinigf28a1c32007-02-14 14:10:31 +00003039 ASSERT_NOT_REACHED();
kociendabb0c24b2001-08-24 14:24:40 +00003040
robert@webkit.org744e01c2013-01-02 20:18:15 +00003041 bool checkForBreak = autoWrap;
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00003042 if (width.committedWidth() && !width.fitsOnLine() && lBreak.m_obj && currWS == NOWRAP)
hyatt74eec4d2003-03-23 08:02:47 +00003043 checkForBreak = true;
commit-queue@webkit.org63cc2d02013-01-02 22:52:58 +00003044 else if (next && current.m_obj->isText() && next->isText() && !next->isBR() && (autoWrap || next->style()->autoWrap())) {
3045 if (autoWrap && currentCharacterIsSpace)
rniwa@webkit.org76aa5222011-05-04 13:03:32 +00003046 checkForBreak = true;
3047 else {
3048 RenderText* nextText = toRenderText(next);
3049 if (nextText->textLength()) {
msaboff@apple.com776c286c72012-10-15 16:56:29 +00003050 UChar c = nextText->characterAt(0);
rniwa@webkit.org76aa5222011-05-04 13:03:32 +00003051 // If the next item on the line is text, and if we did not end with
3052 // a space, then the next text run continues our word (and so it needs to
commit-queue@webkit.org63cc2d02013-01-02 22:52:58 +00003053 // keep adding to the uncommitted width. Just update and continue.
3054 checkForBreak = !currentCharacterIsSpace && (c == ' ' || c == '\t' || (c == '\n' && !next->preservesNewline()));
rniwa@webkit.org76aa5222011-05-04 13:03:32 +00003055 } else if (nextText->isWordBreak())
hyatta9f48e32003-02-03 22:48:01 +00003056 checkForBreak = true;
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00003057
rniwa@webkit.org76aa5222011-05-04 13:03:32 +00003058 if (!width.fitsOnLine() && !width.committedWidth())
3059 width.fitBelowFloats();
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00003060
rniwa@webkit.org76aa5222011-05-04 13:03:32 +00003061 bool canPlaceOnLine = width.fitsOnLine() || !autoWrapWasEverTrueOnLine;
3062 if (canPlaceOnLine && checkForBreak) {
3063 width.commit();
3064 lBreak.moveToStartOf(next);
hyatta9f48e32003-02-03 22:48:01 +00003065 }
3066 }
3067 }
3068
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00003069 if (checkForBreak && !width.fitsOnLine()) {
kociendabb0c24b2001-08-24 14:24:40 +00003070 // if we have floats, try to get below them.
mihnea@adobe.com3bebbf22012-01-19 09:22:59 +00003071 if (currentCharacterIsSpace && !ignoringSpaces && currentStyle->collapseWhiteSpace())
rniwa@webkit.org105350c2011-05-03 20:33:25 +00003072 trailingObjects.clear();
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00003073
rniwa@webkit.org58925e82011-04-12 21:32:58 +00003074 if (width.committedWidth())
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00003075 goto end;
3076
rniwa@webkit.org44424752011-04-14 00:58:40 +00003077 width.fitBelowFloats();
hyattf14a4a32002-11-21 22:06:32 +00003078
hyatta14d1742003-01-02 20:25:46 +00003079 // |width| may have been adjusted because we got shoved down past a float (thus
3080 // giving us more room), so we need to retest, and only jump to
3081 // the end label if we still don't fit on the line. -dwh
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00003082 if (!width.fitsOnLine())
hyatta14d1742003-01-02 20:25:46 +00003083 goto end;
robert@webkit.org744e01c2013-01-02 20:18:15 +00003084 } else if (blockStyle->autoWrap() && !width.fitsOnLine() && !width.committedWidth()) {
3085 // If the container autowraps but the current child does not then we still need to ensure that it
3086 // wraps and moves below any floats.
3087 width.fitBelowFloats();
kociendabb0c24b2001-08-24 14:24:40 +00003088 }
hyatt1d9e29b2003-04-10 01:48:53 +00003089
simon.fraser@apple.com2f071852012-06-25 00:11:30 +00003090 if (!current.m_obj->isFloatingOrOutOfFlowPositioned()) {
rniwa@webkit.org15b91522011-05-04 00:38:05 +00003091 last = current.m_obj;
darin@apple.comb6cb2562009-08-05 21:25:09 +00003092 if (last->isReplaced() && autoWrap && (!last->isImage() || allowImagesToBreak) && (!last->isListMarker() || toRenderListMarker(last)->isInside())) {
rniwa@webkit.org58925e82011-04-12 21:32:58 +00003093 width.commit();
eric@webkit.orgbd143592011-03-29 17:44:41 +00003094 lBreak.moveToStartOf(next);
mitz@apple.com1a301772008-03-11 18:30:36 +00003095 }
hyatt711fe232002-11-20 21:25:14 +00003096 }
3097
hyatta9f48e32003-02-03 22:48:01 +00003098 // Clear out our character space bool, since inline <pre>s don't collapse whitespace
3099 // with adjacent inline normal/nowrap spans.
hyattb0d9f602007-01-15 01:28:23 +00003100 if (!collapseWhiteSpace)
hyatta9f48e32003-02-03 22:48:01 +00003101 currentCharacterIsSpace = false;
eric@webkit.org060caf62011-05-03 22:11:39 +00003102
rniwa@webkit.org15b91522011-05-04 00:38:05 +00003103 current.moveToStartOf(next);
ddkilzere8759ef2007-03-25 06:28:19 +00003104 atStart = false;
kociendabb0c24b2001-08-24 14:24:40 +00003105 }
eric@webkit.org060caf62011-05-03 22:11:39 +00003106
rniwa@webkit.org5eb8d162011-04-13 02:13:33 +00003107 if (width.fitsOnLine() || lastWS == NOWRAP)
eric@webkit.orgbd143592011-03-29 17:44:41 +00003108 lBreak.clear();
kociendabb0c24b2001-08-24 14:24:40 +00003109
3110 end:
eric@webkit.org8c25a592011-03-29 13:18:11 +00003111 if (lBreak == resolver.position() && (!lBreak.m_obj || !lBreak.m_obj->isBR())) {
kociendabb0c24b2001-08-24 14:24:40 +00003112 // we just add as much as possible
commit-queue@webkit.org63cc2d02013-01-02 22:52:58 +00003113 if (blockStyle->whiteSpace() == PRE && !current.m_pos) {
3114 lBreak.moveTo(last, last->isText() ? last->length() : 0);
eric@webkit.org8c25a592011-03-29 13:18:11 +00003115 } else if (lBreak.m_obj) {
yuzo@google.comc25f62f2010-02-09 09:16:36 +00003116 // Don't ever break in the middle of a word if we can help it.
3117 // There's no room at all. We just have to be on this line,
3118 // even though we'll spill out.
rniwa@webkit.org15b91522011-05-04 00:38:05 +00003119 lBreak.moveTo(current.m_obj, current.m_pos);
kociendabb0c24b2001-08-24 14:24:40 +00003120 }
3121 }
3122
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00003123 // FIXME Bug 100049: We do not need to consume input in a multi-segment line
3124 // unless no segment will.
kociendabb0c24b2001-08-24 14:24:40 +00003125 // make sure we consume at least one char/object.
mitz@apple.com15035e62008-07-05 20:44:44 +00003126 if (lBreak == resolver.position())
mitz@apple.com1a301772008-03-11 18:30:36 +00003127 lBreak.increment();
hyatt33f8d492002-11-12 21:44:52 +00003128
hyattfe99c872003-07-31 22:25:29 +00003129 // Sanity check our midpoints.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00003130 checkMidpoints(lineMidpointState, lBreak);
hyatt@apple.com63a8df32011-03-28 19:44:19 +00003131
mitz@apple.come98acc92011-05-22 04:44:27 +00003132 trailingObjects.updateMidpointsForTrailingBoxes(lineMidpointState, lBreak, TrailingObjects::CollapseFirstSpace);
rjwc9c257d2003-01-24 03:46:17 +00003133
mjs54b64002003-04-02 02:59:02 +00003134 // We might have made lBreak an iterator that points past the end
3135 // of the object. Do this adjustment to make it point to the start
3136 // of the next object instead to avoid confusing the rest of the
3137 // code.
eric@webkit.org86a865a2011-03-29 15:30:41 +00003138 if (lBreak.m_pos > 0) {
3139 lBreak.m_pos--;
mitz@apple.com1a301772008-03-11 18:30:36 +00003140 lBreak.increment();
mjs54b64002003-04-02 02:59:02 +00003141 }
3142
kociendabb0c24b2001-08-24 14:24:40 +00003143 return lBreak;
3144}
3145
hyatt@apple.com5dc5a312009-08-18 19:15:19 +00003146void RenderBlock::addOverflowFromInlineChildren()
hyattb4b20872004-10-20 21:34:01 +00003147{
eae@chromium.org9717cd82012-11-07 18:33:44 +00003148 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit();
hyatt@apple.com592848f2010-12-06 20:03:43 +00003149 // FIXME: Need to find another way to do this, since scrollbars could show when we don't want them to.
commit-queue@webkit.org5f402932012-05-11 20:09:13 +00003150 if (hasOverflowClip() && !endPadding && node() && node()->isRootEditableElement() && style()->isLeftToRightDirection())
hyatt@apple.com592848f2010-12-06 20:03:43 +00003151 endPadding = 1;
hyattb4b20872004-10-20 21:34:01 +00003152 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
hyatt@apple.com592848f2010-12-06 20:03:43 +00003153 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
hyatt@apple.com5dc5a312009-08-18 19:15:19 +00003154 if (!hasOverflowClip())
hyatt@apple.com61f25322011-03-31 20:40:48 +00003155 addVisualOverflow(curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
hyattb4b20872004-10-20 21:34:01 +00003156 }
3157}
3158
hyatted77ad82004-06-15 07:21:23 +00003159void RenderBlock::deleteEllipsisLineBoxes()
3160{
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00003161 ETextAlign textAlign = style()->textAlign();
3162 bool ltr = style()->isLeftToRightDirection();
3163 bool firstLine = true;
3164 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
3165 if (curr->hasEllipsisBox()) {
3166 curr->clearTruncation();
3167
3168 // Shift the line back where it belongs if we cannot accomodate an ellipsis.
3169 float logicalLeft = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine);
3170 float availableLogicalWidth = logicalRightOffsetForLine(curr->lineTop(), false) - logicalLeft;
3171 float totalLogicalWidth = curr->logicalWidth();
3172 updateLogicalWidthForAlignment(textAlign, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
3173
3174 if (ltr)
3175 curr->adjustLogicalPosition((logicalLeft - curr->logicalLeft()), 0);
3176 else
3177 curr->adjustLogicalPosition(-(curr->logicalLeft() - logicalLeft), 0);
3178 }
3179 firstLine = false;
3180 }
hyatted77ad82004-06-15 07:21:23 +00003181}
3182
3183void RenderBlock::checkLinesForTextOverflow()
3184{
3185 // Determine the width of the ellipsis using the current font.
darindbba2bb2007-01-11 12:23:49 +00003186 // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable"
zimmermann@webkit.org8a7e7ff2011-05-24 15:27:36 +00003187 const Font& font = style()->font();
bolsinga@apple.com97e42c42008-11-15 04:47:20 +00003188 DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
hyatt3e99d1c2006-02-24 21:13:08 +00003189 const Font& firstLineFont = firstLineStyle()->font();
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00003190 int firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle()));
3191 int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style()));
hyatted77ad82004-06-15 07:21:23 +00003192
3193 // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see
3194 // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and
3195 // check the left edge of the line box to see if it is less
3196 // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()"
hyatt@apple.comc0fa1632010-09-30 20:01:33 +00003197 bool ltr = style()->isLeftToRightDirection();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00003198 ETextAlign textAlign = style()->textAlign();
3199 bool firstLine = true;
hyatted77ad82004-06-15 07:21:23 +00003200 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
eae@chromium.org275da182012-12-19 23:07:55 +00003201 // FIXME: Use pixelSnappedLogicalRightOffsetForLine instead of snapping it ourselves once the column workaround in said method has been fixed.
3202 // https://bugs.webkit.org/show_bug.cgi?id=105461
3203 int blockRightEdge = snapSizeToPixel(logicalRightOffsetForLine(curr->lineTop(), firstLine), curr->x());
3204 int blockLeftEdge = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine);
eae@chromium.orgc491d962012-12-28 18:32:08 +00003205 int lineBoxEdge = ltr ? snapSizeToPixel(curr->x() + curr->logicalWidth(), curr->x()) : snapSizeToPixel(curr->x(), 0);
dglazkov@chromium.org28434e62009-05-13 22:30:10 +00003206 if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) {
hyattf918d2d2004-06-15 07:24:11 +00003207 // This line spills out of our box in the appropriate direction. Now we need to see if the line
hyatted77ad82004-06-15 07:21:23 +00003208 // can be truncated. In order for truncation to be possible, the line must have sufficient space to
3209 // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis
3210 // space.
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00003211
3212 LayoutUnit width = firstLine ? firstLineEllipsisWidth : ellipsisWidth;
eae@chromium.orgee8613e2011-11-12 01:12:58 +00003213 LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00003214 if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) {
3215 float totalLogicalWidth = curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width);
3216
3217 float logicalLeft = 0; // We are only intersted in the delta from the base position.
3218 float truncatedWidth = pixelSnappedLogicalRightOffsetForLine(curr->lineTop(), firstLine);
3219 updateLogicalWidthForAlignment(textAlign, 0, logicalLeft, totalLogicalWidth, truncatedWidth, 0);
3220 if (ltr)
3221 curr->adjustLogicalPosition(logicalLeft, 0);
3222 else
3223 curr->adjustLogicalPosition(-(truncatedWidth - (logicalLeft + totalLogicalWidth)), 0);
3224 }
hyatted77ad82004-06-15 07:21:23 +00003225 }
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00003226 firstLine = false;
hyatted77ad82004-06-15 07:21:23 +00003227 }
3228}
3229
hyatt@apple.com5950bd42011-09-27 20:39:57 +00003230bool RenderBlock::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003231{
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00003232 if (!positionNewFloats())
3233 return false;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003234
rniwa@webkit.org44424752011-04-14 00:58:40 +00003235 width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003236
hyatt@apple.comdd78df82011-09-27 22:11:41 +00003237 // We only connect floats to lines for pagination purposes if the floats occur at the start of
3238 // the line and the previous line had a hard break (so this line is either the first in the block
3239 // or follows a <br>).
3240 if (!newFloat->m_paginationStrut || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00003241 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003242
hyatt@apple.com46c65b32011-08-09 19:13:45 +00003243 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003244 ASSERT(floatingObjectSet.last() == newFloat);
3245
eae@chromium.orgee8613e2011-11-12 01:12:58 +00003246 LayoutUnit floatLogicalTop = logicalTopForFloat(newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003247 int paginationStrut = newFloat->m_paginationStrut;
3248
hyatt@apple.com5950bd42011-09-27 20:39:57 +00003249 if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00003250 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003251
3252 FloatingObjectSetIterator it = floatingObjectSet.end();
3253 --it; // Last float is newFloat, skip that one.
3254 FloatingObjectSetIterator begin = floatingObjectSet.begin();
3255 while (it != begin) {
3256 --it;
3257 FloatingObject* f = *it;
3258 if (f == lastFloatFromPreviousLine)
3259 break;
hyatt@apple.com5950bd42011-09-27 20:39:57 +00003260 if (logicalTopForFloat(f) == logicalHeight() + lineInfo.floatPaginationStrut()) {
3261 f->m_paginationStrut += paginationStrut;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003262 RenderBox* o = f->m_renderer;
3263 setLogicalTopForChild(o, logicalTopForChild(o) + marginBeforeForChild(o) + paginationStrut);
3264 if (o->isRenderBlock())
eric@webkit.org218b4e02012-03-28 19:25:02 +00003265 toRenderBlock(o)->setChildNeedsLayout(true, MarkOnlyThis);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003266 o->layoutIfNeeded();
hyatt@apple.com46c65b32011-08-09 19:13:45 +00003267 // Save the old logical top before calling removePlacedObject which will set
3268 // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat.
3269 LayoutUnit oldLogicalTop = logicalTopForFloat(f);
3270 m_floatingObjects->removePlacedObject(f);
hyatt@apple.com5950bd42011-09-27 20:39:57 +00003271 setLogicalTopForFloat(f, oldLogicalTop + paginationStrut);
hyatt@apple.com46c65b32011-08-09 19:13:45 +00003272 m_floatingObjects->addPlacedObject(f);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003273 }
3274 }
3275
hyatt@apple.comdd78df82011-09-27 22:11:41 +00003276 // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing
3277 // no content, then we don't want to improperly grow the height of the block.
3278 lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut);
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00003279 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00003280}
3281
robert@webkit.org82903f42012-08-28 19:18:40 +00003282LayoutUnit RenderBlock::startAlignedOffsetForLine(LayoutUnit position, bool firstLine)
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00003283{
3284 ETextAlign textAlign = style()->textAlign();
3285
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +00003286 if (textAlign == TASTART) // FIXME: Handle TAEND here
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00003287 return startOffsetForLine(position, firstLine);
3288
3289 // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here
robert@webkit.org82903f42012-08-28 19:18:40 +00003290 float totalLogicalWidth = 0;
3291 float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false);
3292 float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), false) - logicalLeft;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00003293 updateLogicalWidthForAlignment(textAlign, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
robert@webkit.org7861a102011-09-22 17:16:47 +00003294
3295 if (!style()->isLeftToRightDirection())
robert@webkit.org82903f42012-08-28 19:18:40 +00003296 return logicalWidth() - logicalLeft;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00003297 return logicalLeft;
3298}
3299
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00003300
3301void RenderBlock::layoutLineGridBox()
3302{
3303 if (style()->lineGrid() == RenderStyle::initialLineGrid()) {
3304 setLineGridBox(0);
3305 return;
3306 }
3307
3308 setLineGridBox(0);
3309
3310 RootInlineBox* lineGridBox = new (renderArena()) RootInlineBox(this);
3311 lineGridBox->setHasTextChildren(); // Needed to make the line ascent/descent actually be honored in quirks mode.
3312 lineGridBox->setConstructed();
3313 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
3314 VerticalPositionCache verticalPositionCache;
3315 lineGridBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache);
3316
3317 setLineGridBox(lineGridBox);
3318
3319 // FIXME: If any of the characteristics of the box change compared to the old one, then we need to do a deep dirtying
3320 // (similar to what happens when the page height changes). Ideally, though, we only do this if someone is actually snapping
3321 // to this grid.
3322}
3323
hyattffe78712003-02-11 01:59:29 +00003324}