blob: ff97aca58717858720a803bfea8bf45d10e56c69 [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.comc3c7e902009-01-28 21:48:33 +000032#include "RenderInline.h"
eric@webkit.orgb35848a2010-06-10 08:33:22 +000033#include "RenderLayer.h"
mjsd26b2972007-02-13 13:09:04 +000034#include "RenderListMarker.h"
hyattd8048342006-05-31 01:48:18 +000035#include "RenderView.h"
hyatt@apple.comcc1737c2010-09-16 20:20:02 +000036#include "Settings.h"
mitz@apple.com44fc5132011-02-25 18:34:15 +000037#include "TextBreakIterator.h"
tonyg@chromium.org9c384212011-01-19 23:13:26 +000038#include "TextRun.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
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +000048#if ENABLE(SVG)
zimmermann@webkit.org6e96afd2010-09-10 15:35:50 +000049#include "RenderSVGInlineText.h"
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +000050#include "SVGRootInlineBox.h"
51#endif
52
darin7bd70952006-04-13 07:07:34 +000053using namespace std;
darinf9e5d6c2007-01-09 14:54:26 +000054using namespace WTF;
55using namespace Unicode;
darin7bd70952006-04-13 07:07:34 +000056
darinb9481ed2006-03-20 02:57:59 +000057namespace WebCore {
mjsfe301d72003-10-02 18:46:18 +000058
hyatt1d5d87b2007-04-24 04:55:54 +000059// We don't let our line box tree for a single line get any deeper than this.
60const unsigned cMaxLineDepth = 200;
61
hyatt@apple.com0d4818f2009-02-08 05:39:22 +000062static int getBorderPaddingMargin(RenderBoxModelObject* child, bool endOfInline)
hyattffe78712003-02-11 01:59:29 +000063{
hyatt@apple.com0415e5d2010-10-07 17:40:25 +000064 if (endOfInline)
65 return child->marginEnd() + child->paddingEnd() + child->borderEnd();
66 return child->marginStart() + child->paddingStart() + child->borderStart();
hyattffe78712003-02-11 01:59:29 +000067}
68
hyatt@apple.com0415e5d2010-10-07 17:40:25 +000069static int inlineLogicalWidth(RenderObject* child, bool start = true, bool end = true)
hyattffe78712003-02-11 01:59:29 +000070{
hyatt1d5d87b2007-04-24 04:55:54 +000071 unsigned lineDepth = 1;
hyattffe78712003-02-11 01:59:29 +000072 int extraWidth = 0;
73 RenderObject* parent = child->parent();
hyatt@apple.com0d4818f2009-02-08 05:39:22 +000074 while (parent->isInline() && !parent->isInlineBlockOrInlineTable() && lineDepth++ < cMaxLineDepth) {
hyatt@apple.com40232f82009-02-04 04:26:08 +000075 if (start && !child->previousSibling())
hyatt@apple.com0d4818f2009-02-08 05:39:22 +000076 extraWidth += getBorderPaddingMargin(toRenderBoxModelObject(parent), false);
hyatt@apple.com40232f82009-02-04 04:26:08 +000077 if (end && !child->nextSibling())
hyatt@apple.com0d4818f2009-02-08 05:39:22 +000078 extraWidth += getBorderPaddingMargin(toRenderBoxModelObject(parent), true);
hyattffe78712003-02-11 01:59:29 +000079 child = parent;
80 parent = child->parent();
81 }
82 return extraWidth;
83}
84
hyatt@apple.comb3466af2009-06-13 06:04:40 +000085static void checkMidpoints(LineMidpointState& lineMidpointState, InlineIterator& lBreak)
hyattfe99c872003-07-31 22:25:29 +000086{
87 // Check to see if our last midpoint is a start point beyond the line break. If so,
hyattdca76e92005-11-02 08:52:50 +000088 // shave it off the list, and shave off a trailing space if the previous end point doesn't
89 // preserve whitespace.
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +000090 if (lBreak.obj && lineMidpointState.numMidpoints && !(lineMidpointState.numMidpoints % 2)) {
91 InlineIterator* midpoints = lineMidpointState.midpoints.data();
92 InlineIterator& endpoint = midpoints[lineMidpointState.numMidpoints - 2];
93 const InlineIterator& startpoint = midpoints[lineMidpointState.numMidpoints - 1];
mitz@apple.com15035e62008-07-05 20:44:44 +000094 InlineIterator currpoint = endpoint;
hyattfe99c872003-07-31 22:25:29 +000095 while (!currpoint.atEnd() && currpoint != startpoint && currpoint != lBreak)
mitz@apple.com1a301772008-03-11 18:30:36 +000096 currpoint.increment();
hyattfe99c872003-07-31 22:25:29 +000097 if (currpoint == lBreak) {
98 // We hit the line break before the start point. Shave off the start point.
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +000099 lineMidpointState.numMidpoints--;
mitz@apple.com20e34452010-09-28 19:38:15 +0000100 if (endpoint.obj->style()->collapseWhiteSpace())
hyattfe99c872003-07-31 22:25:29 +0000101 endpoint.pos--;
102 }
103 }
104}
105
hyatt@apple.comb3466af2009-06-13 06:04:40 +0000106static void addMidpoint(LineMidpointState& lineMidpointState, const InlineIterator& midpoint)
hyatt85586af2003-02-19 23:22:42 +0000107{
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000108 if (lineMidpointState.midpoints.size() <= lineMidpointState.numMidpoints)
109 lineMidpointState.midpoints.grow(lineMidpointState.numMidpoints + 10);
hyatt85586af2003-02-19 23:22:42 +0000110
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000111 InlineIterator* midpoints = lineMidpointState.midpoints.data();
112 midpoints[lineMidpointState.numMidpoints++] = midpoint;
hyatt85586af2003-02-19 23:22:42 +0000113}
114
hyatt@apple.com71eeb442010-02-11 20:05:51 +0000115void RenderBlock::appendRunsForObject(int start, int end, RenderObject* obj, InlineBidiResolver& resolver)
hyatt33f8d492002-11-12 21:44:52 +0000116{
hyatt98ee7e42003-05-14 01:39:15 +0000117 if (start > end || obj->isFloating() ||
hyatt@apple.come16585a2011-02-28 23:21:36 +0000118 (obj->isPositioned() && !obj->style()->hasAutoLeftAndRight() && !obj->style()->hasAutoTopAndBottom() && !obj->container()->isRenderInline()))
hyatteb003b82002-11-15 22:35:10 +0000119 return;
hyatt85586af2003-02-19 23:22:42 +0000120
hyatt@apple.comb3466af2009-06-13 06:04:40 +0000121 LineMidpointState& lineMidpointState = resolver.midpointState();
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000122 bool haveNextMidpoint = (lineMidpointState.currentMidpoint < lineMidpointState.numMidpoints);
mitz@apple.com15035e62008-07-05 20:44:44 +0000123 InlineIterator nextMidpoint;
hyatt85586af2003-02-19 23:22:42 +0000124 if (haveNextMidpoint)
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000125 nextMidpoint = lineMidpointState.midpoints[lineMidpointState.currentMidpoint];
126 if (lineMidpointState.betweenMidpoints) {
hyatt85586af2003-02-19 23:22:42 +0000127 if (!(haveNextMidpoint && nextMidpoint.obj == obj))
hyatt33f8d492002-11-12 21:44:52 +0000128 return;
129 // This is a new start point. Stop ignoring objects and
130 // adjust our start.
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000131 lineMidpointState.betweenMidpoints = false;
hyatt85586af2003-02-19 23:22:42 +0000132 start = nextMidpoint.pos;
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000133 lineMidpointState.currentMidpoint++;
hyatt33f8d492002-11-12 21:44:52 +0000134 if (start < end)
mitz@apple.com15035e62008-07-05 20:44:44 +0000135 return appendRunsForObject(start, end, obj, resolver);
136 } else {
mitz@apple.com5c2e0e02008-03-13 00:25:55 +0000137 if (!haveNextMidpoint || (obj != nextMidpoint.obj)) {
mitz@apple.com15035e62008-07-05 20:44:44 +0000138 resolver.addRun(new (obj->renderArena()) BidiRun(start, end, obj, resolver.context(), resolver.dir()));
hyatt33f8d492002-11-12 21:44:52 +0000139 return;
140 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000141
hyatt78b85132004-03-29 20:07:45 +0000142 // An end midpoint has been encountered within our object. We
hyatt33f8d492002-11-12 21:44:52 +0000143 // need to go ahead and append a run with our endpoint.
mitz@apple.com15035e62008-07-05 20:44:44 +0000144 if (static_cast<int>(nextMidpoint.pos + 1) <= end) {
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000145 lineMidpointState.betweenMidpoints = true;
146 lineMidpointState.currentMidpoint++;
hyattc64f9fc2003-03-14 01:25:59 +0000147 if (nextMidpoint.pos != UINT_MAX) { // UINT_MAX means stop at the object and don't include any of it.
mitz@apple.com15035e62008-07-05 20:44:44 +0000148 if (static_cast<int>(nextMidpoint.pos + 1) > start)
149 resolver.addRun(new (obj->renderArena())
150 BidiRun(start, nextMidpoint.pos + 1, obj, resolver.context(), resolver.dir()));
151 return appendRunsForObject(nextMidpoint.pos + 1, end, obj, resolver);
hyattc64f9fc2003-03-14 01:25:59 +0000152 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000153 } else
154 resolver.addRun(new (obj->renderArena()) BidiRun(start, end, obj, resolver.context(), resolver.dir()));
hyatt33f8d492002-11-12 21:44:52 +0000155 }
156}
157
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000158static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRootLineBox, bool isOnlyRun = false)
159{
160 if (isRootLineBox)
eric@webkit.org49b9d952009-07-03 01:29:07 +0000161 return toRenderBlock(obj)->createAndAppendRootInlineBox();
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000162
163 if (obj->isText()) {
164 InlineTextBox* textBox = toRenderText(obj)->createInlineTextBox();
165 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
166 // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.)
167 if (obj->isBR())
hyatt@apple.comce8ee2a2010-08-27 20:29:34 +0000168 textBox->setIsText(isOnlyRun || obj->document()->inNoQuirksMode());
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000169 return textBox;
170 }
171
172 if (obj->isBox())
173 return toRenderBox(obj)->createInlineBox();
174
eric@webkit.org49b9d952009-07-03 01:29:07 +0000175 return toRenderInline(obj)->createAndAppendInlineFlowBox();
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000176}
177
178static inline void dirtyLineBoxesForRenderer(RenderObject* o, bool fullLayout)
179{
180 if (o->isText()) {
carol.szabo@nokia.comeaaf1992011-03-02 19:34:00 +0000181 if (o->preferredLogicalWidthsDirty() && (o->isCounter() || o->isQuote()))
hyatt@apple.com75dad742010-09-24 18:07:44 +0000182 toRenderText(o)->computePreferredLogicalWidths(0); // FIXME: Counters depend on this hack. No clue why. Should be investigated and removed.
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000183 toRenderText(o)->dirtyLineBoxes(fullLayout);
184 } else
185 toRenderInline(o)->dirtyLineBoxes(fullLayout);
186}
187
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000188static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox)
189{
190 do {
191 if (parentBox->isConstructed() || parentBox->nextOnLine())
192 return true;
193 parentBox = parentBox->parent();
194 } while (parentBox);
195 return false;
196}
197
hyatt@apple.comcd6f8952009-01-28 17:30:26 +0000198InlineFlowBox* RenderBlock::createLineBoxes(RenderObject* obj, bool firstLine)
hyattffe78712003-02-11 01:59:29 +0000199{
200 // See if we have an unconstructed line box for this object that is also
201 // the last item on the line.
hyatt1d5d87b2007-04-24 04:55:54 +0000202 unsigned lineDepth = 1;
203 InlineFlowBox* childBox = 0;
204 InlineFlowBox* parentBox = 0;
205 InlineFlowBox* result = 0;
206 do {
hyatt@apple.com415d8de2009-01-26 22:29:19 +0000207 ASSERT(obj->isRenderInline() || obj == this);
hyatt@apple.com76dbdb52009-01-29 22:49:13 +0000208
hyatt1d5d87b2007-04-24 04:55:54 +0000209 // Get the last box we made for this render object.
weinig@apple.com7c50a3b2009-01-30 19:55:45 +0000210 parentBox = obj->isRenderInline() ? toRenderInline(obj)->lastLineBox() : toRenderBlock(obj)->lastLineBox();
hyattffe78712003-02-11 01:59:29 +0000211
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000212 // If this box or its ancestor is constructed then it is from a previous line, and we need
213 // 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 +0000214 // something following it on the line, then we know we have to make a new box
215 // as well. In this situation our inline has actually been split in two on
216 // the same line (this can happen with very fancy language mixtures).
217 bool constructedNewBox = false;
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000218 if (!parentBox || parentIsConstructedOrHaveNext(parentBox)) {
hyatt1d5d87b2007-04-24 04:55:54 +0000219 // We need to make a new box for this render object. Once
220 // made, we need to place it at the end of the current line.
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000221 InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this);
hyatt1d5d87b2007-04-24 04:55:54 +0000222 ASSERT(newBox->isInlineFlowBox());
223 parentBox = static_cast<InlineFlowBox*>(newBox);
hyatt@apple.comcd6f8952009-01-28 17:30:26 +0000224 parentBox->setFirstLineStyleBit(firstLine);
hyatt@apple.com6bd34682010-11-01 21:13:55 +0000225 parentBox->setIsHorizontal(style()->isHorizontalWritingMode());
hyatt1d5d87b2007-04-24 04:55:54 +0000226 constructedNewBox = true;
227 }
mitz@apple.come1364202008-02-28 01:06:41 +0000228
hyatt1d5d87b2007-04-24 04:55:54 +0000229 if (!result)
230 result = parentBox;
231
232 // If we have hit the block itself, then |box| represents the root
hyattffe78712003-02-11 01:59:29 +0000233 // inline box for the line, and it doesn't have to be appended to any parent
234 // inline.
hyatt1d5d87b2007-04-24 04:55:54 +0000235 if (childBox)
236 parentBox->addToLine(childBox);
mitz@apple.come1364202008-02-28 01:06:41 +0000237
hyatt1d5d87b2007-04-24 04:55:54 +0000238 if (!constructedNewBox || obj == this)
239 break;
mitz@apple.come1364202008-02-28 01:06:41 +0000240
hyatt1d5d87b2007-04-24 04:55:54 +0000241 childBox = parentBox;
mitz@apple.come1364202008-02-28 01:06:41 +0000242
hyatt1d5d87b2007-04-24 04:55:54 +0000243 // If we've exceeded our line depth, then jump straight to the root and skip all the remaining
244 // intermediate inline flows.
245 obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent();
hyattffe78712003-02-11 01:59:29 +0000246
hyatt1d5d87b2007-04-24 04:55:54 +0000247 } while (true);
248
249 return result;
hyattffe78712003-02-11 01:59:29 +0000250}
251
hyatt@apple.comcd6f8952009-01-28 17:30:26 +0000252RootInlineBox* RenderBlock::constructLine(unsigned runCount, BidiRun* firstRun, BidiRun* lastRun, bool firstLine, bool lastLine, RenderObject* endObject)
hyattffe78712003-02-11 01:59:29 +0000253{
mitz@apple.com887f3592008-02-25 22:03:08 +0000254 ASSERT(firstRun);
hyattffe78712003-02-11 01:59:29 +0000255
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000256 bool rootHasSelectedChildren = false;
hyattffe78712003-02-11 01:59:29 +0000257 InlineFlowBox* parentBox = 0;
mitz@apple.com887f3592008-02-25 22:03:08 +0000258 for (BidiRun* r = firstRun; r; r = r->next()) {
hyattffe78712003-02-11 01:59:29 +0000259 // Create a box for our object.
mitz@apple.com887f3592008-02-25 22:03:08 +0000260 bool isOnlyRun = (runCount == 1);
mitz@apple.come1364202008-02-28 01:06:41 +0000261 if (runCount == 2 && !r->m_object->isListMarker())
hyatt@apple.comc0fa1632010-09-30 20:01:33 +0000262 isOnlyRun = (!style()->isLeftToRightDirection() ? lastRun : firstRun)->m_object->isListMarker();
mitz@apple.come1364202008-02-28 01:06:41 +0000263
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000264 InlineBox* box = createInlineBoxForRenderer(r->m_object, false, isOnlyRun);
mitz@apple.com576e84e2008-04-24 19:09:48 +0000265 r->m_box = box;
266
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000267 ASSERT(box);
268 if (!box)
269 continue;
hyattffe78712003-02-11 01:59:29 +0000270
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000271 if (!rootHasSelectedChildren && box->renderer()->selectionState() != RenderObject::SelectionNone)
272 rootHasSelectedChildren = true;
273
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000274 // If we have no parent box yet, or if the run is not simply a sibling,
275 // then we need to construct inline boxes as necessary to properly enclose the
276 // run's inline box.
277 if (!parentBox || parentBox->renderer() != r->m_object->parent())
278 // Create new inline boxes all the way back to the appropriate insertion point.
279 parentBox = createLineBoxes(r->m_object->parent(), firstLine);
mitz@apple.com576e84e2008-04-24 19:09:48 +0000280
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000281 // Append the inline box to this line.
282 parentBox->addToLine(box);
mitz@apple.com576e84e2008-04-24 19:09:48 +0000283
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000284 bool visuallyOrdered = r->m_object->style()->visuallyOrdered();
xji@chromium.org6b0c0172011-02-14 19:21:12 +0000285 box->setBidiLevel(r->level());
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000286
287 if (box->isInlineTextBox()) {
288 InlineTextBox* text = static_cast<InlineTextBox*>(box);
289 text->setStart(r->m_start);
290 text->setLen(r->m_stop - r->m_start);
291 text->m_dirOverride = r->dirOverride(visuallyOrdered);
mitz@apple.comb2107652010-06-21 16:54:52 +0000292 if (r->m_hasHyphen)
293 text->setHasHyphen(true);
hyatt0c3a9862004-02-23 21:26:26 +0000294 }
hyattffe78712003-02-11 01:59:29 +0000295 }
296
297 // We should have a root inline box. It should be unconstructed and
298 // be the last continuation of our line list.
ggarenf9f32ae2007-03-26 20:08:53 +0000299 ASSERT(lastLineBox() && !lastLineBox()->isConstructed());
hyattffe78712003-02-11 01:59:29 +0000300
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000301 // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box
302 // from the bidi runs walk above has a selection state.
303 if (rootHasSelectedChildren)
304 lastLineBox()->root()->setHasSelectedChildren(true);
305
hyattffe78712003-02-11 01:59:29 +0000306 // Set bits on our inline flow boxes that indicate which sides should
307 // paint borders/margins/padding. This knowledge will ultimately be used when
308 // we determine the horizontal positions and widths of all the inline boxes on
309 // the line.
hyattffe78712003-02-11 01:59:29 +0000310 lastLineBox()->determineSpacingForFlowBoxes(lastLine, endObject);
311
312 // Now mark the line boxes as being constructed.
313 lastLineBox()->setConstructed();
314
315 // Return the last line.
hyatt0c3a9862004-02-23 21:26:26 +0000316 return lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000317}
318
mitz@apple.com390fa322011-02-24 23:07:06 +0000319ETextAlign RenderBlock::textAlignmentForLine(bool endsWithSoftBreak) const
320{
321 ETextAlign alignment = style()->textAlign();
322 if (!endsWithSoftBreak && alignment == JUSTIFY)
323 alignment = TAAUTO;
324
325 return alignment;
326}
327
hyatt@apple.com44e83c02010-09-23 22:21:30 +0000328void RenderBlock::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, bool firstLine, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
hyattffe78712003-02-11 01:59:29 +0000329{
mitz@apple.com390fa322011-02-24 23:07:06 +0000330 ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
331 float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), firstLine);
332 float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), firstLine) - logicalLeft;
333
darin06dcb9c2005-08-15 04:31:09 +0000334 bool needsWordSpacing = false;
mitz@apple.com390fa322011-02-24 23:07:06 +0000335 float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();
mitz@apple.com86470c82011-01-27 01:39:27 +0000336 unsigned expansionOpportunityCount = 0;
337 bool isAfterExpansion = true;
338 Vector<unsigned, 16> expansionOpportunities;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000339
mitz@apple.come1364202008-02-28 01:06:41 +0000340 for (BidiRun* r = firstRun; r; r = r->next()) {
341 if (!r->m_box || r->m_object->isPositioned() || r->m_box->isLineBreak())
hyatt98ee7e42003-05-14 01:39:15 +0000342 continue; // Positioned objects are only participating to figure out their
343 // correct static x position. They have no effect on the width.
hyatt0c05e102006-04-14 08:15:00 +0000344 // Similarly, line break boxes have no effect on the width.
mitz@apple.come1364202008-02-28 01:06:41 +0000345 if (r->m_object->isText()) {
darin@apple.com36744d62009-01-25 20:23:04 +0000346 RenderText* rt = toRenderText(r->m_object);
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000347
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000348 if (textAlign == JUSTIFY && r != trailingSpaceRun) {
mitz@apple.com1b0578d2011-01-27 08:23:31 +0000349 unsigned opportunitiesInRun = Font::expansionOpportunityCount(rt->characters() + r->m_start, r->m_stop - r->m_start, r->m_box->direction(), isAfterExpansion);
mitz@apple.com86470c82011-01-27 01:39:27 +0000350 expansionOpportunities.append(opportunitiesInRun);
351 expansionOpportunityCount += opportunitiesInRun;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000352 }
353
mitz@apple.come1364202008-02-28 01:06:41 +0000354 if (int length = rt->textLength()) {
hyatt@apple.comd0301a52009-01-26 21:50:57 +0000355 if (!r->m_start && needsWordSpacing && isSpaceOrNewline(rt->characters()[r->m_start]))
hyatt@apple.com546a2482010-10-07 21:16:49 +0000356 totalLogicalWidth += rt->style(firstLine)->font().wordSpacing();
mitz@apple.come1364202008-02-28 01:06:41 +0000357 needsWordSpacing = !isSpaceOrNewline(rt->characters()[r->m_stop - 1]) && r->m_stop == length;
darin06dcb9c2005-08-15 04:31:09 +0000358 }
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000359 HashSet<const SimpleFontData*> fallbackFonts;
enrica@apple.comb9050ed2010-04-07 17:01:52 +0000360 GlyphOverflow glyphOverflow;
mitz@apple.comb2107652010-06-21 16:54:52 +0000361 int hyphenWidth = 0;
362 if (static_cast<InlineTextBox*>(r->m_box)->hasHyphen()) {
363 const AtomicString& hyphenString = rt->style()->hyphenString();
364 hyphenWidth = rt->style(firstLine)->font().width(TextRun(hyphenString.characters(), hyphenString.length()));
365 }
hyatt@apple.com546a2482010-10-07 21:16:49 +0000366 r->m_box->setLogicalWidth(rt->width(r->m_start, r->m_stop - r->m_start, totalLogicalWidth, firstLine, &fallbackFonts, &glyphOverflow) + hyphenWidth);
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +0000367 if (!fallbackFonts.isEmpty()) {
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000368 ASSERT(r->m_box->isText());
mitz@apple.com0cc7bed2010-05-17 01:43:49 +0000369 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(static_cast<InlineTextBox*>(r->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first;
370 ASSERT(it->second.first.isEmpty());
371 copyToVector(fallbackFonts, it->second.first);
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000372 }
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +0000373 if ((glyphOverflow.top || glyphOverflow.bottom || glyphOverflow.left || glyphOverflow.right)) {
enrica@apple.comb9050ed2010-04-07 17:01:52 +0000374 ASSERT(r->m_box->isText());
mitz@apple.com0cc7bed2010-05-17 01:43:49 +0000375 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(static_cast<InlineTextBox*>(r->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first;
376 it->second.second = glyphOverflow;
enrica@apple.comb9050ed2010-04-07 17:01:52 +0000377 }
mitz@apple.com86470c82011-01-27 01:39:27 +0000378 } else {
379 isAfterExpansion = false;
380 if (!r->m_object->isRenderInline()) {
381 RenderBox* renderBox = toRenderBox(r->m_object);
commit-queue@webkit.org5922e732011-02-08 01:02:02 +0000382 renderBox->computeLogicalWidth();
mitz@apple.com86470c82011-01-27 01:39:27 +0000383 r->m_box->setLogicalWidth(logicalWidthForChild(renderBox));
384 totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox);
385 }
hyattffe78712003-02-11 01:59:29 +0000386 }
hyatt4b381692003-03-10 21:11:59 +0000387
hyatt@apple.com546a2482010-10-07 21:16:49 +0000388 totalLogicalWidth += r->m_box->logicalWidth();
hyattffe78712003-02-11 01:59:29 +0000389 }
390
mitz@apple.com86470c82011-01-27 01:39:27 +0000391 if (isAfterExpansion && !expansionOpportunities.isEmpty()) {
392 expansionOpportunities.last()--;
393 expansionOpportunityCount--;
394 }
395
hyattffe78712003-02-11 01:59:29 +0000396 // Armed with the total width of the line (without justification),
397 // we now examine our text-align property in order to determine where to position the
398 // objects horizontally. The total width of the line can be increased if we end up
399 // justifying text.
ddkilzer@apple.comdfdc3fd2009-07-08 13:55:55 +0000400 switch (textAlign) {
hyattffe78712003-02-11 01:59:29 +0000401 case LEFT:
ddkilzer95d2be02007-04-14 01:26:07 +0000402 case WEBKIT_LEFT:
hyatt959a54e2004-09-27 17:52:18 +0000403 // The direction of the block should determine what happens with wide lines. In
404 // particular with RTL blocks, wide lines should still spill out to the left.
hyatt@apple.comc0fa1632010-09-30 20:01:33 +0000405 if (style()->isLeftToRightDirection()) {
hyatt@apple.com546a2482010-10-07 21:16:49 +0000406 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
hyatt@apple.com0acc9352011-02-17 19:19:07 +0000407 trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000408 } else {
409 if (trailingSpaceRun)
hyatt@apple.comc01df9e2010-09-23 19:17:33 +0000410 trailingSpaceRun->m_box->setLogicalWidth(0);
hyatt@apple.com546a2482010-10-07 21:16:49 +0000411 else if (totalLogicalWidth > availableLogicalWidth)
412 logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000413 }
hyattffe78712003-02-11 01:59:29 +0000414 break;
415 case JUSTIFY:
mitz@apple.coma70af822011-02-25 02:21:20 +0000416 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
mitz@apple.com390fa322011-02-24 23:07:06 +0000417 if (expansionOpportunityCount) {
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000418 if (trailingSpaceRun) {
hyatt@apple.com546a2482010-10-07 21:16:49 +0000419 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
hyatt@apple.comc01df9e2010-09-23 19:17:33 +0000420 trailingSpaceRun->m_box->setLogicalWidth(0);
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000421 }
hyattffe78712003-02-11 01:59:29 +0000422 break;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000423 }
hyattffe78712003-02-11 01:59:29 +0000424 // fall through
425 case TAAUTO:
hyattffe78712003-02-11 01:59:29 +0000426 // for right to left fall through to right aligned
hyatt@apple.comc0fa1632010-09-30 20:01:33 +0000427 if (style()->isLeftToRightDirection()) {
hyatt@apple.com546a2482010-10-07 21:16:49 +0000428 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
hyatt@apple.com0acc9352011-02-17 19:19:07 +0000429 trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
hyattffe78712003-02-11 01:59:29 +0000430 break;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000431 }
hyattffe78712003-02-11 01:59:29 +0000432 case RIGHT:
ddkilzer95d2be02007-04-14 01:26:07 +0000433 case WEBKIT_RIGHT:
hyatt959a54e2004-09-27 17:52:18 +0000434 // Wide lines spill out of the block based off direction.
435 // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
436 // side of the block.
hyatt@apple.comc0fa1632010-09-30 20:01:33 +0000437 if (style()->isLeftToRightDirection()) {
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000438 if (trailingSpaceRun) {
hyatt@apple.com546a2482010-10-07 21:16:49 +0000439 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
hyatt@apple.comc01df9e2010-09-23 19:17:33 +0000440 trailingSpaceRun->m_box->setLogicalWidth(0);
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000441 }
hyatt@apple.com546a2482010-10-07 21:16:49 +0000442 if (totalLogicalWidth < availableLogicalWidth)
443 logicalLeft += availableLogicalWidth - totalLogicalWidth;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000444 } else {
hyatt@apple.com546a2482010-10-07 21:16:49 +0000445 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
hyatt@apple.com0acc9352011-02-17 19:19:07 +0000446 trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
hyatt@apple.com546a2482010-10-07 21:16:49 +0000447 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000448 } else
hyatt@apple.com546a2482010-10-07 21:16:49 +0000449 logicalLeft += availableLogicalWidth - totalLogicalWidth;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000450 }
hyattffe78712003-02-11 01:59:29 +0000451 break;
452 case CENTER:
ddkilzer95d2be02007-04-14 01:26:07 +0000453 case WEBKIT_CENTER:
hyatt@apple.com0acc9352011-02-17 19:19:07 +0000454 float trailingSpaceWidth = 0;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000455 if (trailingSpaceRun) {
hyatt@apple.com546a2482010-10-07 21:16:49 +0000456 totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
457 trailingSpaceWidth = min(trailingSpaceRun->m_box->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2);
hyatt@apple.com0acc9352011-02-17 19:19:07 +0000458 trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceWidth));
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000459 }
hyatt@apple.comc0fa1632010-09-30 20:01:33 +0000460 if (style()->isLeftToRightDirection())
hyatt@apple.com0acc9352011-02-17 19:19:07 +0000461 logicalLeft += max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0);
mitz@apple.com37717da2008-02-28 02:23:22 +0000462 else
hyatt@apple.com546a2482010-10-07 21:16:49 +0000463 logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
hyattffe78712003-02-11 01:59:29 +0000464 break;
465 }
466
mitz@apple.com86470c82011-01-27 01:39:27 +0000467 if (expansionOpportunityCount) {
468 size_t i = 0;
mitz@apple.come1364202008-02-28 01:06:41 +0000469 for (BidiRun* r = firstRun; r; r = r->next()) {
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000470 if (!r->m_box || r == trailingSpaceRun)
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000471 continue;
hyatt0c3a9862004-02-23 21:26:26 +0000472
hyatt@apple.comd0301a52009-01-26 21:50:57 +0000473 if (r->m_object->isText()) {
mitz@apple.com86470c82011-01-27 01:39:27 +0000474 unsigned opportunitiesInRun = expansionOpportunities[i++];
hyatt870bdda2003-05-21 23:37:33 +0000475
mitz@apple.com86470c82011-01-27 01:39:27 +0000476 ASSERT(opportunitiesInRun <= expansionOpportunityCount);
hyatt870bdda2003-05-21 23:37:33 +0000477
hyattdca76e92005-11-02 08:52:50 +0000478 // Only justify text if whitespace is collapsed.
mitz@apple.come1364202008-02-28 01:06:41 +0000479 if (r->m_object->style()->collapseWhiteSpace()) {
mitz@apple.com86470c82011-01-27 01:39:27 +0000480 InlineTextBox* textBox = static_cast<InlineTextBox*>(r->m_box);
hyatt@apple.com0acc9352011-02-17 19:19:07 +0000481 float expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
mitz@apple.com86470c82011-01-27 01:39:27 +0000482 textBox->setExpansion(expansion);
483 totalLogicalWidth += expansion;
hyatt870bdda2003-05-21 23:37:33 +0000484 }
mitz@apple.com86470c82011-01-27 01:39:27 +0000485 expansionOpportunityCount -= opportunitiesInRun;
486 if (!expansionOpportunityCount)
mitz@apple.come1364202008-02-28 01:06:41 +0000487 break;
hyattacbb0d42003-04-25 01:32:49 +0000488 }
hyattffe78712003-02-11 01:59:29 +0000489 }
hyattffe78712003-02-11 01:59:29 +0000490 }
mitz@apple.come1364202008-02-28 01:06:41 +0000491
hyattffe78712003-02-11 01:59:29 +0000492 // The widths of all runs are now known. We can now place every inline box (and
493 // compute accurate widths for the inline flow boxes).
darin06dcb9c2005-08-15 04:31:09 +0000494 needsWordSpacing = false;
hyatt@apple.com546a2482010-10-07 21:16:49 +0000495 lineBox->placeBoxesInInlineDirection(logicalLeft, needsWordSpacing, textBoxDataMap);
hyattffe78712003-02-11 01:59:29 +0000496}
497
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000498void RenderBlock::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
499 VerticalPositionCache& verticalPositionCache)
hyattffe78712003-02-11 01:59:29 +0000500{
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000501 setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache));
hyatt@apple.com35d2ad52010-10-20 18:17:36 +0000502 lineBox->setBlockLogicalHeight(logicalHeight());
hyattffe78712003-02-11 01:59:29 +0000503
504 // Now make sure we place replaced render objects correctly.
mitz@apple.com887f3592008-02-25 22:03:08 +0000505 for (BidiRun* r = firstRun; r; r = r->next()) {
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000506 ASSERT(r->m_box);
mitz@apple.come1364202008-02-28 01:06:41 +0000507 if (!r->m_box)
eseidel789896f2005-11-27 22:52:09 +0000508 continue; // Skip runs with no line boxes.
hyatt0c3a9862004-02-23 21:26:26 +0000509
hyatt98ee7e42003-05-14 01:39:15 +0000510 // Align positioned boxes with the top of the line box. This is
511 // a reasonable approximation of an appropriate y position.
mitz@apple.come1364202008-02-28 01:06:41 +0000512 if (r->m_object->isPositioned())
hyatt@apple.com35d2ad52010-10-20 18:17:36 +0000513 r->m_box->setLogicalTop(logicalHeight());
hyatt98ee7e42003-05-14 01:39:15 +0000514
515 // Position is used to properly position both replaced elements and
516 // to update the static normal flow x/y of positioned elements.
hyatt@apple.com6a551ad2009-02-11 22:43:12 +0000517 if (r->m_object->isText())
518 toRenderText(r->m_object)->positionLineBox(r->m_box);
519 else if (r->m_object->isBox())
520 toRenderBox(r->m_object)->positionLineBox(r->m_box);
hyatt98ee7e42003-05-14 01:39:15 +0000521 }
mitz@apple.coma927be62008-03-21 05:30:19 +0000522 // Positioned objects and zero-length text nodes destroy their boxes in
523 // position(), which unnecessarily dirties the line.
524 lineBox->markDirty(false);
hyattffe78712003-02-11 01:59:29 +0000525}
kociendabb0c24b2001-08-24 14:24:40 +0000526
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000527static inline bool isCollapsibleSpace(UChar character, RenderText* renderer)
528{
529 if (character == ' ' || character == '\t' || character == softHyphen)
530 return true;
531 if (character == '\n')
532 return !renderer->style()->preserveNewline();
533 if (character == noBreakSpace)
534 return renderer->style()->nbspMode() == SPACE;
535 return false;
536}
537
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000538void RenderBlock::layoutInlineChildren(bool relayoutChildren, int& repaintLogicalTop, int& repaintLogicalBottom)
jamesr@google.com19548ad2010-04-02 23:21:35 +0000539{
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000540 bool useRepaintBounds = false;
541
hyatt@apple.com5dc5a312009-08-18 19:15:19 +0000542 m_overflow.clear();
hyatt7b41b9d2007-05-30 05:32:40 +0000543
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000544 setLogicalHeight(borderBefore() + paddingBefore());
mitz@apple.come1364202008-02-28 01:06:41 +0000545
hyatt0c3a9862004-02-23 21:26:26 +0000546 // Figure out if we should clear out our line boxes.
547 // FIXME: Handle resize eventually!
eric@webkit.orgc0249422010-01-06 00:07:56 +0000548 bool fullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren;
hyatt0c3a9862004-02-23 21:26:26 +0000549 if (fullLayout)
hyatt@apple.comb83de652009-01-28 20:48:04 +0000550 lineBoxes()->deleteLineBoxes(renderArena());
mitz@apple.come1364202008-02-28 01:06:41 +0000551
hyatted77ad82004-06-15 07:21:23 +0000552 // Text truncation only kicks in if your overflow isn't visible and your text-overflow-mode isn't
553 // clip.
554 // FIXME: CSS3 says that descendants that are clipped must also know how to truncate. This is insanely
555 // difficult to figure out (especially in the middle of doing layout), and is really an esoteric pile of nonsense
556 // anyway, so we won't worry about following the draft here.
557 bool hasTextOverflow = style()->textOverflow() && hasOverflowClip();
mitz@apple.come1364202008-02-28 01:06:41 +0000558
hyatted77ad82004-06-15 07:21:23 +0000559 // Walk all the lines and delete our ellipsis line boxes if they exist.
560 if (hasTextOverflow)
561 deleteEllipsisLineBoxes();
562
hyattffe78712003-02-11 01:59:29 +0000563 if (firstChild()) {
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000564 // layout replaced elements
565 bool endOfInline = false;
566 RenderObject* o = bidiFirst(this, 0, false);
mitz@apple.com40547b32008-03-18 04:04:34 +0000567 Vector<FloatWithRect> floats;
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000568 bool hasInlineChild = false;
569 while (o) {
commit-queue@webkit.orgcf45df92010-09-14 13:25:06 +0000570 if (!hasInlineChild && o->isInline())
571 hasInlineChild = true;
572
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000573 if (o->isReplaced() || o->isFloating() || o->isPositioned()) {
574 RenderBox* box = toRenderBox(o);
575
576 if (relayoutChildren || o->style()->width().isPercent() || o->style()->height().isPercent())
577 o->setChildNeedsLayout(true, false);
578
579 // If relayoutChildren is set and we have percentage padding, we also need to invalidate the child's pref widths.
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000580 if (relayoutChildren && (o->style()->paddingStart().isPercent() || o->style()->paddingEnd().isPercent()))
hyatt@apple.com75dad742010-09-24 18:07:44 +0000581 o->setPreferredLogicalWidthsDirty(true, false);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000582
583 if (o->isPositioned())
584 o->containingBlock()->insertPositionedObject(box);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000585 else if (o->isFloating())
586 floats.append(FloatWithRect(box));
587 else if (fullLayout || o->needsLayout()) {
588 // Replaced elements
589 toRenderBox(o)->dirtyLineBoxes(fullLayout);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000590 o->layoutIfNeeded();
591 }
592 } else if (o->isText() || (o->isRenderInline() && !endOfInline)) {
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000593 if (fullLayout || o->selfNeedsLayout())
594 dirtyLineBoxesForRenderer(o, fullLayout);
595 o->setNeedsLayout(false);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000596 }
597 o = bidiNext(this, o, 0, false, &endOfInline);
598 }
599
600 // We want to skip ahead to the first dirty line
601 InlineBidiResolver resolver;
602 unsigned floatIndex;
603 bool firstLine = true;
604 bool previousLineBrokeCleanly = true;
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000605 RootInlineBox* startLine = determineStartPosition(firstLine, fullLayout, previousLineBrokeCleanly, resolver, floats, floatIndex,
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000606 useRepaintBounds, repaintLogicalTop, repaintLogicalBottom);
mitz@apple.come1364202008-02-28 01:06:41 +0000607
eric@webkit.orgddbec0aa2010-01-06 01:13:11 +0000608 if (fullLayout && hasInlineChild && !selfNeedsLayout()) {
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000609 setNeedsLayout(true, false); // Mark ourselves as needing a full layout. This way we'll repaint like
610 // we're supposed to.
simon.fraser@apple.com6528b502009-01-12 21:42:25 +0000611 RenderView* v = view();
hyatt@apple.com0de4d642009-02-05 22:26:53 +0000612 if (v && !v->doingFullRepaint() && hasLayer()) {
hyatt837eb362004-05-21 22:17:10 +0000613 // Because we waited until we were already inside layout to discover
614 // that the block really needed a full layout, we missed our chance to repaint the layer
615 // before layout started. Luckily the layer has cached the repaint rect for its original
616 // position and size, and so we can use that to make a repaint happen now.
hyatt@apple.com0de4d642009-02-05 22:26:53 +0000617 repaintUsingContainer(containerForRepaint(), layer()->repaintRect());
hyatt837eb362004-05-21 22:17:10 +0000618 }
619 }
hyatt0c3a9862004-02-23 21:26:26 +0000620
commit-queue@webkit.org2984df92011-03-04 23:07:15 +0000621 FloatingObject* lastFloat = (m_floatingObjects && !m_floatingObjects->set().isEmpty()) ? m_floatingObjects->set().last() : 0;
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000622
623 LineMidpointState& lineMidpointState = resolver.midpointState();
624
625 // We also find the first clean line and extract these lines. We will add them back
626 // if we determine that we're able to synchronize after handling all our dirty lines.
627 InlineIterator cleanLineStart;
628 BidiStatus cleanLineBidiStatus;
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000629 int endLineLogicalTop = 0;
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000630 RootInlineBox* endLine = (fullLayout || !startLine) ?
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +0000631 0 : determineEndPosition(startLine, floats, floatIndex, cleanLineStart, cleanLineBidiStatus, endLineLogicalTop);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000632
633 if (startLine) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000634 if (!useRepaintBounds) {
635 useRepaintBounds = true;
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000636 repaintLogicalTop = logicalHeight();
637 repaintLogicalBottom = logicalHeight();
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000638 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000639 RenderArena* arena = renderArena();
640 RootInlineBox* box = startLine;
641 while (box) {
hyatt@apple.com592848f2010-12-06 20:03:43 +0000642 repaintLogicalTop = min(repaintLogicalTop, beforeSideVisualOverflowForLine(box));
643 repaintLogicalBottom = max(repaintLogicalBottom, afterSideVisualOverflowForLine(box));
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000644 RootInlineBox* next = box->nextRootBox();
645 box->deleteLine(arena);
646 box = next;
647 }
648 }
649
650 InlineIterator end = resolver.position();
651
652 if (!fullLayout && lastRootBox() && lastRootBox()->endsWithBreak()) {
653 // If the last line before the start line ends with a line break that clear floats,
654 // adjust the height accordingly.
655 // A line break can be either the first or the last object on a line, depending on its direction.
656 if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) {
657 RenderObject* lastObject = lastLeafChild->renderer();
658 if (!lastObject->isBR())
659 lastObject = lastRootBox()->firstLeafChild()->renderer();
660 if (lastObject->isBR()) {
661 EClear clear = lastObject->style()->clear();
662 if (clear != CNONE)
663 newLine(clear);
664 }
665 }
666 }
667
668 bool endLineMatched = false;
669 bool checkForEndLineMatch = endLine;
670 bool checkForFloatsFromLastLine = false;
671
672 bool isLineEmpty = true;
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000673 bool paginated = view()->layoutState() && view()->layoutState()->isPaginated();
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000674
mitz@apple.com44fc5132011-02-25 18:34:15 +0000675 LineBreakIteratorInfo lineBreakIteratorInfo;
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000676 VerticalPositionCache verticalPositionCache;
677
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000678 while (!end.atEnd()) {
679 // FIXME: Is this check necessary before the first iteration or can it be moved to the end?
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000680 if (checkForEndLineMatch && (endLineMatched = matchedEndLine(resolver, cleanLineStart, cleanLineBidiStatus, endLine, endLineLogicalTop, repaintLogicalBottom, repaintLogicalTop)))
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000681 break;
682
683 lineMidpointState.reset();
684
685 isLineEmpty = true;
686
687 EClear clear = CNONE;
mitz@apple.comb2107652010-06-21 16:54:52 +0000688 bool hyphenated;
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000689
690 InlineIterator oldEnd = end;
commit-queue@webkit.org2984df92011-03-04 23:07:15 +0000691 FloatingObject* lastFloatFromPreviousLine = (m_floatingObjects && !m_floatingObjects->set().isEmpty()) ? m_floatingObjects->set().last() : 0;
mitz@apple.com44fc5132011-02-25 18:34:15 +0000692 end = findNextLineBreak(resolver, firstLine, isLineEmpty, lineBreakIteratorInfo, previousLineBrokeCleanly, hyphenated, &clear, lastFloatFromPreviousLine);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000693 if (resolver.position().atEnd()) {
694 resolver.deleteRuns();
695 checkForFloatsFromLastLine = true;
696 break;
697 }
698 ASSERT(end != resolver.position());
699
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +0000700 if (isLineEmpty) {
701 if (lastRootBox())
702 lastRootBox()->setLineBreakInfo(end.obj, end.pos, resolver.status());
703 } else {
xji@chromium.org6b0c0172011-02-14 19:21:12 +0000704 VisualDirectionOverride override = (style()->visuallyOrdered() ? (style()->direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride);
705 resolver.createBidiRunsForLine(end, override, previousLineBrokeCleanly);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000706 ASSERT(resolver.position() == end);
707
708 BidiRun* trailingSpaceRun = 0;
709 if (!previousLineBrokeCleanly && resolver.runCount() && resolver.logicallyLastRun()->m_object->style()->breakOnlyAfterWhiteSpace()
710 && resolver.logicallyLastRun()->m_object->style()->autoWrap()) {
711 trailingSpaceRun = resolver.logicallyLastRun();
712 RenderObject* lastObject = trailingSpaceRun->m_object;
713 if (lastObject->isText()) {
714 RenderText* lastText = toRenderText(lastObject);
715 const UChar* characters = lastText->characters();
716 int firstSpace = trailingSpaceRun->stop();
717 while (firstSpace > trailingSpaceRun->start()) {
718 UChar current = characters[firstSpace - 1];
719 if (!isCollapsibleSpace(current, lastText))
720 break;
721 firstSpace--;
722 }
723 if (firstSpace == trailingSpaceRun->stop())
724 trailingSpaceRun = 0;
725 else {
726 TextDirection direction = style()->direction();
727 bool shouldReorder = trailingSpaceRun != (direction == LTR ? resolver.lastRun() : resolver.firstRun());
728 if (firstSpace != trailingSpaceRun->start()) {
729 BidiContext* baseContext = resolver.context();
730 while (BidiContext* parent = baseContext->parent())
731 baseContext = parent;
732
733 BidiRun* newTrailingRun = new (renderArena()) BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->m_object, baseContext, OtherNeutral);
734 trailingSpaceRun->m_stop = firstSpace;
735 if (direction == LTR)
736 resolver.addRun(newTrailingRun);
737 else
738 resolver.prependRun(newTrailingRun);
739 trailingSpaceRun = newTrailingRun;
740 shouldReorder = false;
741 }
742 if (shouldReorder) {
743 if (direction == LTR) {
744 resolver.moveRunToEnd(trailingSpaceRun);
745 trailingSpaceRun->m_level = 0;
746 } else {
747 resolver.moveRunToBeginning(trailingSpaceRun);
748 trailingSpaceRun->m_level = 1;
749 }
750 }
751 }
752 } else
753 trailingSpaceRun = 0;
754 }
755
756 // Now that the runs have been ordered, we create the line boxes.
757 // At the same time we figure out where border/padding/margin should be applied for
758 // inline flow boxes.
759
760 RootInlineBox* lineBox = 0;
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000761 int oldLogicalHeight = logicalHeight();
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000762 if (resolver.runCount()) {
mitz@apple.comb2107652010-06-21 16:54:52 +0000763 if (hyphenated)
764 resolver.logicallyLastRun()->m_hasHyphen = true;
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000765 lineBox = constructLine(resolver.runCount(), resolver.firstRun(), resolver.lastRun(), firstLine, !end.obj, end.obj && !end.pos ? end.obj : 0);
766 if (lineBox) {
767 lineBox->setEndsWithBreak(previousLineBrokeCleanly);
768
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +0000769#if ENABLE(SVG)
770 bool isSVGRootInlineBox = lineBox->isSVGRootInlineBox();
771#else
772 bool isSVGRootInlineBox = false;
773#endif
774
mitz@apple.com0cc7bed2010-05-17 01:43:49 +0000775 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +0000776
777 // Now we position all of our text runs horizontally.
778 if (!isSVGRootInlineBox)
hyatt@apple.com44e83c02010-09-23 22:21:30 +0000779 computeInlineDirectionPositionsForLine(lineBox, firstLine, resolver.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000780
781 // Now position our text runs vertically.
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000782 computeBlockDirectionPositionsForLine(lineBox, resolver.firstRun(), textBoxDataMap, verticalPositionCache);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000783
784#if ENABLE(SVG)
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +0000785 // SVG text layout code computes vertical & horizontal positions on its own.
786 // Note that we still need to execute computeVerticalPositionsForLine() as
787 // it calls InlineTextBox::positionLineBox(), which tracks whether the box
788 // contains reversed text or not. If we wouldn't do that editing and thus
789 // text selection in RTL boxes would not work as expected.
790 if (isSVGRootInlineBox) {
791 ASSERT(isSVGText());
792 static_cast<SVGRootInlineBox*>(lineBox)->computePerCharacterLayoutInformation();
793 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000794#endif
795
hyatt@apple.com592848f2010-12-06 20:03:43 +0000796 // Compute our overflow now.
797 lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), document()->inNoQuirksMode(), textBoxDataMap);
798
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000799#if PLATFORM(MAC)
800 // Highlight acts as an overflow inflation.
801 if (style()->highlight() != nullAtom)
802 lineBox->addHighlightOverflow();
803#endif
804 }
805 }
806
807 resolver.deleteRuns();
808
809 if (lineBox) {
810 lineBox->setLineBreakInfo(end.obj, end.pos, resolver.status());
811 if (useRepaintBounds) {
hyatt@apple.com592848f2010-12-06 20:03:43 +0000812 repaintLogicalTop = min(repaintLogicalTop, beforeSideVisualOverflowForLine(lineBox));
813 repaintLogicalBottom = max(repaintLogicalBottom, afterSideVisualOverflowForLine(lineBox));
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000814 }
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000815
816 if (paginated) {
817 int adjustment = 0;
818 adjustLinePositionForPagination(lineBox, adjustment);
819 if (adjustment) {
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000820 int oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, firstLine);
hyatt@apple.com61bbedf2011-01-26 23:10:57 +0000821 lineBox->adjustBlockDirectionPosition(adjustment);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000822 if (useRepaintBounds) // This can only be a positive adjustment, so no need to update repaintTop.
hyatt@apple.com592848f2010-12-06 20:03:43 +0000823 repaintLogicalBottom = max(repaintLogicalBottom, afterSideVisualOverflowForLine(lineBox));
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000824
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000825 if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, firstLine) != oldLineWidth) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000826 // We have to delete this line, remove all floats that got added, and let line layout re-run.
827 lineBox->deleteLine(renderArena());
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000828 removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight);
829 setLogicalHeight(oldLogicalHeight + adjustment);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000830 resolver.setPosition(oldEnd);
831 end = oldEnd;
832 continue;
833 }
834
hyatt@apple.coma956e332010-10-06 20:35:21 +0000835 setLogicalHeight(lineBox->blockLogicalHeight());
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000836 }
837 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000838 }
839
840 firstLine = false;
841 newLine(clear);
842 }
843
844 if (m_floatingObjects && lastRootBox()) {
commit-queue@webkit.org2984df92011-03-04 23:07:15 +0000845 FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
846 FloatingObjectSetIterator it = floatingObjectSet.begin();
847 FloatingObjectSetIterator end = floatingObjectSet.end();
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000848 if (lastFloat) {
commit-queue@webkit.org2984df92011-03-04 23:07:15 +0000849 FloatingObjectSetIterator lastFloatIterator = floatingObjectSet.find(lastFloat);
benjamin.poulain@nokia.coma655ed72011-02-27 15:51:19 +0000850 ASSERT(lastFloatIterator != end);
851 ++lastFloatIterator;
852 it = lastFloatIterator;
853 }
854 for (; it != end; ++it) {
855 FloatingObject* f = *it;
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000856 lastRootBox()->floats().append(f->m_renderer);
857 ASSERT(f->m_renderer == floats[floatIndex].object);
858 // If a float's geometry has changed, give up on syncing with clean lines.
hyatt@apple.comf382f2e2010-10-01 21:25:39 +0000859 if (floats[floatIndex].rect != f->frameRect())
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000860 checkForEndLineMatch = false;
861 floatIndex++;
862 }
commit-queue@webkit.org2984df92011-03-04 23:07:15 +0000863 lastFloat = !floatingObjectSet.isEmpty() ? floatingObjectSet.last() : 0;
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000864 }
865
866 lineMidpointState.reset();
867 resolver.setPosition(end);
868 }
869
870 if (endLine) {
871 if (endLineMatched) {
872 // Attach all the remaining lines, and then adjust their y-positions as needed.
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000873 int delta = logicalHeight() - endLineLogicalTop;
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000874 for (RootInlineBox* line = endLine; line; line = line->nextRootBox()) {
875 line->attachLine();
hyatt@apple.comcc1737c2010-09-16 20:20:02 +0000876 if (paginated) {
877 delta -= line->paginationStrut();
878 adjustLinePositionForPagination(line, delta);
879 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000880 if (delta) {
hyatt@apple.com592848f2010-12-06 20:03:43 +0000881 repaintLogicalTop = min(repaintLogicalTop, beforeSideVisualOverflowForLine(line) + min(delta, 0));
882 repaintLogicalBottom = max(repaintLogicalBottom, afterSideVisualOverflowForLine(line) + max(delta, 0));
hyatt@apple.com61bbedf2011-01-26 23:10:57 +0000883 line->adjustBlockDirectionPosition(delta);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000884 }
885 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
886 Vector<RenderBox*>::iterator end = cleanLineFloats->end();
887 for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) {
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000888 insertFloatingObject(*f);
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000889 setLogicalHeight(logicalTopForChild(*f) - marginBeforeForChild(*f) + delta);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000890 positionNewFloats();
891 }
892 }
893 }
hyatt@apple.coma956e332010-10-06 20:35:21 +0000894 setLogicalHeight(lastRootBox()->blockLogicalHeight());
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000895 } else {
896 // Delete all the remaining lines.
897 RootInlineBox* line = endLine;
898 RenderArena* arena = renderArena();
899 while (line) {
hyatt@apple.com592848f2010-12-06 20:03:43 +0000900 repaintLogicalTop = min(repaintLogicalTop, beforeSideVisualOverflowForLine(line));
901 repaintLogicalBottom = max(repaintLogicalBottom, afterSideVisualOverflowForLine(line));
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000902 RootInlineBox* next = line->nextRootBox();
903 line->deleteLine(arena);
904 line = next;
905 }
906 }
907 }
908 if (m_floatingObjects && (checkForFloatsFromLastLine || positionNewFloats()) && lastRootBox()) {
909 // In case we have a float on the last line, it might not be positioned up to now.
910 // This has to be done before adding in the bottom border/padding, or the float will
911 // include the padding incorrectly. -dwh
912 if (checkForFloatsFromLastLine) {
hyatt@apple.com592848f2010-12-06 20:03:43 +0000913 int bottomVisualOverflow = afterSideVisualOverflowForLine(lastRootBox());
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000914 int bottomLayoutOverflow = afterSideLayoutOverflowForLine(lastRootBox());
dbates@webkit.orgf6f05a92010-05-17 04:58:25 +0000915 TrailingFloatsRootInlineBox* trailingFloatsLineBox = new (renderArena()) TrailingFloatsRootInlineBox(this);
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000916 m_lineBoxes.appendLineBox(trailingFloatsLineBox);
917 trailingFloatsLineBox->setConstructed();
mitz@apple.com0cc7bed2010-05-17 01:43:49 +0000918 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000919 VerticalPositionCache verticalPositionCache;
920 trailingFloatsLineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache);
hyatt@apple.com592848f2010-12-06 20:03:43 +0000921 IntRect logicalLayoutOverflow(0, logicalHeight(), 1, bottomLayoutOverflow);
922 IntRect logicalVisualOverflow(0, logicalHeight(), 1, bottomVisualOverflow);
923 trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow);
hyatt@apple.com81c1d742010-10-06 21:44:02 +0000924 trailingFloatsLineBox->setBlockLogicalHeight(logicalHeight());
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000925 }
benjamin.poulain@nokia.coma655ed72011-02-27 15:51:19 +0000926
commit-queue@webkit.org2984df92011-03-04 23:07:15 +0000927 FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
928 FloatingObjectSetIterator it = floatingObjectSet.begin();
929 FloatingObjectSetIterator end = floatingObjectSet.end();
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000930 if (lastFloat) {
commit-queue@webkit.org2984df92011-03-04 23:07:15 +0000931 FloatingObjectSetIterator lastFloatIterator = floatingObjectSet.find(lastFloat);
benjamin.poulain@nokia.coma655ed72011-02-27 15:51:19 +0000932 ASSERT(lastFloatIterator != end);
933 ++lastFloatIterator;
934 it = lastFloatIterator;
935 }
936 for (; it != end; ++it)
937 lastRootBox()->floats().append((*it)->m_renderer);
commit-queue@webkit.org2984df92011-03-04 23:07:15 +0000938 lastFloat = !floatingObjectSet.isEmpty() ? floatingObjectSet.last() : 0;
abarth@webkit.org31d23df2010-04-05 21:52:09 +0000939 }
940 size_t floatCount = floats.size();
941 // Floats that did not have layout did not repaint when we laid them out. They would have
942 // painted by now if they had moved, but if they stayed at (0, 0), they still need to be
943 // painted.
944 for (size_t i = 0; i < floatCount; ++i) {
945 if (!floats[i].everHadLayout) {
946 RenderBox* f = floats[i].object;
947 if (!f->x() && !f->y() && f->checkForRepaintDuringLayout())
948 f->repaint();
949 }
950 }
kociendabb0c24b2001-08-24 14:24:40 +0000951 }
hyatt85586af2003-02-19 23:22:42 +0000952
mitz@apple.com3672d9e2010-12-17 19:31:16 +0000953 // Expand the last line to accommodate Ruby and emphasis marks.
954 int lastLineAnnotationsAdjustment = 0;
955 if (lastRootBox()) {
hyatt@apple.com5e48ff52010-11-19 00:43:29 +0000956 int lowestAllowedPosition = max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
mitz@apple.com3672d9e2010-12-17 19:31:16 +0000957 if (!style()->isFlippedLinesWritingMode())
958 lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition);
959 else
960 lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
hyatt@apple.com5e48ff52010-11-19 00:43:29 +0000961 }
mitz@apple.com3672d9e2010-12-17 19:31:16 +0000962
hyatta70560a2002-11-20 01:53:20 +0000963 // Now add in the bottom border/padding.
mitz@apple.com3672d9e2010-12-17 19:31:16 +0000964 setLogicalHeight(logicalHeight() + lastLineAnnotationsAdjustment + borderAfter() + paddingAfter() + scrollbarLogicalHeight());
kociendabb0c24b2001-08-24 14:24:40 +0000965
adele7a470a72006-04-20 22:22:14 +0000966 if (!firstLineBox() && hasLineIfEmpty())
hyatt@apple.comddd8c302010-10-19 18:38:14 +0000967 setLogicalHeight(logicalHeight() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
hyatted77ad82004-06-15 07:21:23 +0000968
969 // See if we have any lines that spill out of our block. If we do, then we will possibly need to
970 // truncate text.
971 if (hasTextOverflow)
972 checkLinesForTextOverflow();
kociendabb0c24b2001-08-24 14:24:40 +0000973}
974
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +0000975void RenderBlock::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat)
976{
977 Vector<RenderBox*>* cleanLineFloats = line->floatsPtr();
978 if (!cleanLineFloats)
979 return;
980
981 Vector<RenderBox*>::iterator end = cleanLineFloats->end();
982 for (Vector<RenderBox*>::iterator it = cleanLineFloats->begin(); it != end; ++it) {
983 RenderBox* floatingBox = *it;
984 floatingBox->layoutIfNeeded();
985 IntSize newSize(floatingBox->width() + floatingBox->marginLeft() + floatingBox->marginRight(), floatingBox->height() + floatingBox->marginTop() + floatingBox->marginBottom());
986 ASSERT(floatIndex < floats.size());
987 if (floats[floatIndex].object != floatingBox) {
988 encounteredNewFloat = true;
989 return;
990 }
991 if (floats[floatIndex].rect.size() != newSize) {
992 int floatTop = style()->isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x();
993 int floatHeight = style()->isHorizontalWritingMode() ? max(floats[floatIndex].rect.height(), newSize.height())
994 : max(floats[floatIndex].rect.width(), newSize.width());
995 line->markDirty();
996 markLinesDirtyInBlockRange(line->blockLogicalHeight(), floatTop + floatHeight, line);
997 floats[floatIndex].rect.setSize(newSize);
998 dirtiedByFloat = true;
999 }
1000 floatIndex++;
1001 }
1002}
1003
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001004RootInlineBox* RenderBlock::determineStartPosition(bool& firstLine, bool& fullLayout, bool& previousLineBrokeCleanly,
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001005 InlineBidiResolver& resolver, Vector<FloatWithRect>& floats, unsigned& numCleanFloats,
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001006 bool& useRepaintBounds, int& repaintLogicalTop, int& repaintLogicalBottom)
hyatt0c3a9862004-02-23 21:26:26 +00001007{
1008 RootInlineBox* curr = 0;
1009 RootInlineBox* last = 0;
mitz@apple.come1364202008-02-28 01:06:41 +00001010
mitz@apple.com40547b32008-03-18 04:04:34 +00001011 bool dirtiedByFloat = false;
1012 if (!fullLayout) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001013 // Paginate all of the clean lines.
1014 bool paginated = view()->layoutState() && view()->layoutState()->isPaginated();
1015 int paginationDelta = 0;
mitz@apple.com40547b32008-03-18 04:04:34 +00001016 size_t floatIndex = 0;
1017 for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001018 if (paginated) {
1019 paginationDelta -= curr->paginationStrut();
1020 adjustLinePositionForPagination(curr, paginationDelta);
1021 if (paginationDelta) {
1022 if (containsFloats() || !floats.isEmpty()) {
1023 // FIXME: Do better eventually. For now if we ever shift because of pagination and floats are present just go to a full layout.
1024 fullLayout = true;
1025 break;
1026 }
1027
1028 if (!useRepaintBounds)
1029 useRepaintBounds = true;
1030
hyatt@apple.com592848f2010-12-06 20:03:43 +00001031 repaintLogicalTop = min(repaintLogicalTop, beforeSideVisualOverflowForLine(curr) + min(paginationDelta, 0));
1032 repaintLogicalBottom = max(repaintLogicalBottom, afterSideVisualOverflowForLine(curr) + max(paginationDelta, 0));
hyatt@apple.com61bbedf2011-01-26 23:10:57 +00001033 curr->adjustBlockDirectionPosition(paginationDelta);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001034 }
1035 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001036
1037 // If a new float has been inserted before this line or before its last known float,just do a full layout.
1038 checkFloatsInCleanLine(curr, floats, floatIndex, fullLayout, dirtiedByFloat);
mitz@apple.com40547b32008-03-18 04:04:34 +00001039 if (dirtiedByFloat || fullLayout)
1040 break;
1041 }
1042 // Check if a new float has been inserted after the last known float.
1043 if (!curr && floatIndex < floats.size())
1044 fullLayout = true;
1045 }
1046
hyatt0c3a9862004-02-23 21:26:26 +00001047 if (fullLayout) {
1048 // Nuke all our lines.
1049 if (firstRootBox()) {
1050 RenderArena* arena = renderArena();
1051 curr = firstRootBox();
1052 while (curr) {
1053 RootInlineBox* next = curr->nextRootBox();
1054 curr->deleteLine(arena);
1055 curr = next;
1056 }
darinec375482007-01-06 01:36:24 +00001057 ASSERT(!firstLineBox() && !lastLineBox());
hyatt0c3a9862004-02-23 21:26:26 +00001058 }
eseidel789896f2005-11-27 22:52:09 +00001059 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001060 if (curr) {
1061 // We have a dirty line.
mjs9f78dd92007-02-12 04:06:07 +00001062 if (RootInlineBox* prevRootBox = curr->prevRootBox()) {
hyatt0c3a9862004-02-23 21:26:26 +00001063 // We have a previous line.
staikos@webkit.org19d8c5f2009-03-26 14:24:15 +00001064 if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || (prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= toRenderText(prevRootBox->lineBreakObj())->textLength())))
mjs9f78dd92007-02-12 04:06:07 +00001065 // The previous line didn't break cleanly or broke at a newline
1066 // that has been deleted, so treat it as dirty too.
1067 curr = prevRootBox;
hyatt0c3a9862004-02-23 21:26:26 +00001068 }
eseidel789896f2005-11-27 22:52:09 +00001069 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001070 // No dirty lines were found.
1071 // If the last line didn't break cleanly, treat it as dirty.
1072 if (lastRootBox() && !lastRootBox()->endsWithBreak())
1073 curr = lastRootBox();
1074 }
mitz@apple.come1364202008-02-28 01:06:41 +00001075
hyatt0c3a9862004-02-23 21:26:26 +00001076 // If we have no dirty lines, then last is just the last root box.
1077 last = curr ? curr->prevRootBox() : lastRootBox();
1078 }
mitz@apple.come1364202008-02-28 01:06:41 +00001079
mitz@apple.com40547b32008-03-18 04:04:34 +00001080 numCleanFloats = 0;
1081 if (!floats.isEmpty()) {
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001082 int savedLogicalHeight = logicalHeight();
mitz@apple.com40547b32008-03-18 04:04:34 +00001083 // Restore floats from clean lines.
1084 RootInlineBox* line = firstRootBox();
1085 while (line != curr) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00001086 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
1087 Vector<RenderBox*>::iterator end = cleanLineFloats->end();
1088 for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) {
mitz@apple.com40547b32008-03-18 04:04:34 +00001089 insertFloatingObject(*f);
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001090 setLogicalHeight(logicalTopForChild(*f) - marginBeforeForChild(*f));
mitz@apple.com40547b32008-03-18 04:04:34 +00001091 positionNewFloats();
1092 ASSERT(floats[numCleanFloats].object == *f);
1093 numCleanFloats++;
1094 }
1095 }
1096 line = line->nextRootBox();
1097 }
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001098 setLogicalHeight(savedLogicalHeight);
mitz@apple.com40547b32008-03-18 04:04:34 +00001099 }
1100
hyatt@apple.comcd6f8952009-01-28 17:30:26 +00001101 firstLine = !last;
hyatt0c3a9862004-02-23 21:26:26 +00001102 previousLineBrokeCleanly = !last || last->endsWithBreak();
mitz@apple.com1a301772008-03-11 18:30:36 +00001103
1104 RenderObject* startObj;
1105 int pos = 0;
hyatt0c3a9862004-02-23 21:26:26 +00001106 if (last) {
hyatt@apple.coma956e332010-10-06 20:35:21 +00001107 setLogicalHeight(last->blockLogicalHeight());
hyatt0c3a9862004-02-23 21:26:26 +00001108 startObj = last->lineBreakObj();
1109 pos = last->lineBreakPos();
mitz@apple.com15035e62008-07-05 20:44:44 +00001110 resolver.setStatus(last->lineBreakBidiStatus());
darindde01502005-12-18 22:55:35 +00001111 } else {
hyatt@apple.comc0fa1632010-09-30 20:01:33 +00001112 bool ltr = style()->isLeftToRightDirection()
mitz@apple.com1a301772008-03-11 18:30:36 +00001113 #if ENABLE(SVG)
1114 || (style()->unicodeBidi() == UBNormal && isSVGText())
1115 #endif
1116 ;
mitz@apple.com40547b32008-03-18 04:04:34 +00001117
mitz@apple.com45d9e102009-04-27 16:24:55 +00001118 Direction direction = ltr ? LeftToRight : RightToLeft;
1119 resolver.setLastStrongDir(direction);
1120 resolver.setLastDir(direction);
1121 resolver.setEorDir(direction);
1122 resolver.setContext(BidiContext::create(ltr ? 0 : 1, direction, style()->unicodeBidi() == Override));
mitz@apple.com1a301772008-03-11 18:30:36 +00001123
mitz@apple.com15035e62008-07-05 20:44:44 +00001124 startObj = bidiFirst(this, &resolver);
darindde01502005-12-18 22:55:35 +00001125 }
mitz@apple.come1364202008-02-28 01:06:41 +00001126
mitz@apple.com15035e62008-07-05 20:44:44 +00001127 resolver.setPosition(InlineIterator(this, startObj, pos));
mitz@apple.come1364202008-02-28 01:06:41 +00001128
hyatt0c3a9862004-02-23 21:26:26 +00001129 return curr;
1130}
1131
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001132RootInlineBox* RenderBlock::determineEndPosition(RootInlineBox* startLine, Vector<FloatWithRect>& floats, size_t floatIndex, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus, int& logicalTop)
hyatt0c3a9862004-02-23 21:26:26 +00001133{
1134 RootInlineBox* last = 0;
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001135 for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) {
1136 if (!curr->isDirty()) {
1137 bool encounteredNewFloat = false;
1138 bool dirtiedByFloat = false;
1139 checkFloatsInCleanLine(curr, floats, floatIndex, encounteredNewFloat, dirtiedByFloat);
1140 if (encounteredNewFloat)
1141 return 0;
hyatt04420ca2004-07-16 00:05:42 +00001142 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001143 if (curr->isDirty())
1144 last = 0;
1145 else if (!last)
1146 last = curr;
hyatt0c3a9862004-02-23 21:26:26 +00001147 }
mitz@apple.come1364202008-02-28 01:06:41 +00001148
hyatt0c3a9862004-02-23 21:26:26 +00001149 if (!last)
1150 return 0;
mitz@apple.come1364202008-02-28 01:06:41 +00001151
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001152 // At this point, |last| is the first line in a run of clean lines that ends with the last line
1153 // in the block.
1154
eseidel789896f2005-11-27 22:52:09 +00001155 RootInlineBox* prev = last->prevRootBox();
mitz@apple.com15035e62008-07-05 20:44:44 +00001156 cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos());
eseidel789896f2005-11-27 22:52:09 +00001157 cleanLineBidiStatus = prev->lineBreakBidiStatus();
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001158 logicalTop = prev->blockLogicalHeight();
mitz@apple.come1364202008-02-28 01:06:41 +00001159
hyatt0c3a9862004-02-23 21:26:26 +00001160 for (RootInlineBox* line = last; line; line = line->nextRootBox())
1161 line->extractLine(); // Disconnect all line boxes from their render objects while preserving
1162 // their connections to one another.
mitz@apple.come1364202008-02-28 01:06:41 +00001163
hyatt0c3a9862004-02-23 21:26:26 +00001164 return last;
1165}
1166
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001167bool RenderBlock::matchedEndLine(const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus, RootInlineBox*& endLine,
1168 int& endLogicalTop, int& repaintLogicalBottom, int& repaintLogicalTop)
hyatt0c3a9862004-02-23 21:26:26 +00001169{
mitz@apple.com15035e62008-07-05 20:44:44 +00001170 if (resolver.position() == endLineStart) {
1171 if (resolver.status() != endLineStatus)
mitz@apple.com40547b32008-03-18 04:04:34 +00001172 return false;
1173
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001174 int delta = logicalHeight() - endLogicalTop;
mitz@apple.com40547b32008-03-18 04:04:34 +00001175 if (!delta || !m_floatingObjects)
1176 return true;
1177
1178 // See if any floats end in the range along which we want to shift the lines vertically.
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001179 int logicalTop = min(logicalHeight(), endLogicalTop);
mitz@apple.com40547b32008-03-18 04:04:34 +00001180
1181 RootInlineBox* lastLine = endLine;
1182 while (RootInlineBox* nextLine = lastLine->nextRootBox())
1183 lastLine = nextLine;
1184
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001185 int logicalBottom = lastLine->blockLogicalHeight() + abs(delta);
mitz@apple.com40547b32008-03-18 04:04:34 +00001186
commit-queue@webkit.org2984df92011-03-04 23:07:15 +00001187 FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
1188 FloatingObjectSetIterator end = floatingObjectSet.end();
1189 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
benjamin.poulain@nokia.coma655ed72011-02-27 15:51:19 +00001190 FloatingObject* f = *it;
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001191 if (logicalBottomForFloat(f) >= logicalTop && logicalBottomForFloat(f) < logicalBottom)
mitz@apple.com40547b32008-03-18 04:04:34 +00001192 return false;
1193 }
1194
1195 return true;
1196 }
hyatt0c3a9862004-02-23 21:26:26 +00001197
mitz@apple.come1364202008-02-28 01:06:41 +00001198 // The first clean line doesn't match, but we can check a handful of following lines to try
1199 // to match back up.
1200 static int numLines = 8; // The # of lines we're willing to match against.
1201 RootInlineBox* line = endLine;
1202 for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) {
mitz@apple.com15035e62008-07-05 20:44:44 +00001203 if (line->lineBreakObj() == resolver.position().obj && line->lineBreakPos() == resolver.position().pos) {
mitz@apple.come1364202008-02-28 01:06:41 +00001204 // We have a match.
mitz@apple.com15035e62008-07-05 20:44:44 +00001205 if (line->lineBreakBidiStatus() != resolver.status())
mitz@apple.come1364202008-02-28 01:06:41 +00001206 return false; // ...but the bidi state doesn't match.
1207 RootInlineBox* result = line->nextRootBox();
1208
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001209 // Set our logical top to be the block height of endLine.
mitz@apple.come1364202008-02-28 01:06:41 +00001210 if (result)
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001211 endLogicalTop = line->blockLogicalHeight();
mitz@apple.come1364202008-02-28 01:06:41 +00001212
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001213 int delta = logicalHeight() - endLogicalTop;
mitz@apple.com40547b32008-03-18 04:04:34 +00001214 if (delta && m_floatingObjects) {
1215 // See if any floats end in the range along which we want to shift the lines vertically.
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001216 int logicalTop = min(logicalHeight(), endLogicalTop);
mitz@apple.com40547b32008-03-18 04:04:34 +00001217
1218 RootInlineBox* lastLine = endLine;
1219 while (RootInlineBox* nextLine = lastLine->nextRootBox())
1220 lastLine = nextLine;
1221
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001222 int logicalBottom = lastLine->blockLogicalHeight() + abs(delta);
mitz@apple.com40547b32008-03-18 04:04:34 +00001223
commit-queue@webkit.org2984df92011-03-04 23:07:15 +00001224 FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
1225 FloatingObjectSetIterator end = floatingObjectSet.end();
1226 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
benjamin.poulain@nokia.coma655ed72011-02-27 15:51:19 +00001227 FloatingObject* f = *it;
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001228 if (logicalBottomForFloat(f) >= logicalTop && logicalBottomForFloat(f) < logicalBottom)
mitz@apple.com40547b32008-03-18 04:04:34 +00001229 return false;
1230 }
1231 }
1232
mitz@apple.come1364202008-02-28 01:06:41 +00001233 // Now delete the lines that we failed to sync.
1234 RootInlineBox* boxToDelete = endLine;
1235 RenderArena* arena = renderArena();
1236 while (boxToDelete && boxToDelete != result) {
hyatt@apple.com592848f2010-12-06 20:03:43 +00001237 repaintLogicalTop = min(repaintLogicalTop, beforeSideVisualOverflowForLine(boxToDelete));
1238 repaintLogicalBottom = max(repaintLogicalBottom, afterSideVisualOverflowForLine(boxToDelete));
mitz@apple.come1364202008-02-28 01:06:41 +00001239 RootInlineBox* next = boxToDelete->nextRootBox();
1240 boxToDelete->deleteLine(arena);
1241 boxToDelete = next;
hyatt0c3a9862004-02-23 21:26:26 +00001242 }
mitz@apple.come1364202008-02-28 01:06:41 +00001243
1244 endLine = result;
1245 return result;
hyatt0c3a9862004-02-23 21:26:26 +00001246 }
1247 }
mitz@apple.come1364202008-02-28 01:06:41 +00001248
hyatt0c3a9862004-02-23 21:26:26 +00001249 return false;
1250}
1251
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001252static inline bool skipNonBreakingSpace(const InlineIterator& it, bool isLineEmpty, bool previousLineBrokeCleanly)
kocienda98440082004-10-14 23:51:47 +00001253{
darinf9e5d6c2007-01-09 14:54:26 +00001254 if (it.obj->style()->nbspMode() != SPACE || it.current() != noBreakSpace)
kocienda98440082004-10-14 23:51:47 +00001255 return false;
mitz@apple.come1364202008-02-28 01:06:41 +00001256
hyattdca76e92005-11-02 08:52:50 +00001257 // FIXME: This is bad. It makes nbsp inconsistent with space and won't work correctly
1258 // with m_minWidth/m_maxWidth.
kocienda498d1982004-10-15 21:07:24 +00001259 // Do not skip a non-breaking space if it is the first character
hyattdca76e92005-11-02 08:52:50 +00001260 // on a line after a clean line break (or on the first line, since previousLineBrokeCleanly starts off
1261 // |true|).
1262 if (isLineEmpty && previousLineBrokeCleanly)
kocienda498d1982004-10-15 21:07:24 +00001263 return false;
mitz@apple.come1364202008-02-28 01:06:41 +00001264
kocienda498d1982004-10-15 21:07:24 +00001265 return true;
kocienda98440082004-10-14 23:51:47 +00001266}
1267
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001268static inline bool shouldCollapseWhiteSpace(const RenderStyle* style, bool isLineEmpty, bool previousLineBrokeCleanly)
hyattd9953212005-11-03 21:05:59 +00001269{
1270 return style->collapseWhiteSpace() || (style->whiteSpace() == PRE_WRAP && (!isLineEmpty || !previousLineBrokeCleanly));
1271}
1272
zimmermannac3781f2007-02-04 01:25:03 +00001273static inline bool shouldPreserveNewline(RenderObject* object)
1274{
mjsd2948ef2007-02-26 19:29:04 +00001275#if ENABLE(SVG)
zimmermann@webkit.orge943aaa2010-06-25 10:03:33 +00001276 if (object->isSVGInlineText())
zimmermannac3781f2007-02-04 01:25:03 +00001277 return false;
1278#endif
1279
1280 return object->style()->preserveNewline();
1281}
1282
hyatt@apple.com0d4818f2009-02-08 05:39:22 +00001283static bool inlineFlowRequiresLineBox(RenderInline* flow)
bdakinf876bee2007-10-30 05:27:09 +00001284{
1285 // FIXME: Right now, we only allow line boxes for inlines that are truly empty.
hyatt@apple.comeb66ef42008-01-18 22:59:29 +00001286 // We need to fix this, though, because at the very least, inlines containing only
1287 // ignorable whitespace should should also have line boxes.
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001288 return !flow->firstChild() && flow->hasInlineDirectionBordersPaddingOrMargin();
bdakinf876bee2007-10-30 05:27:09 +00001289}
1290
hyatt@apple.com71eeb442010-02-11 20:05:51 +00001291bool RenderBlock::requiresLineBox(const InlineIterator& it, bool isLineEmpty, bool previousLineBrokeCleanly)
bdashccffb432007-07-13 11:51:40 +00001292{
bdakinf876bee2007-10-30 05:27:09 +00001293 if (it.obj->isFloatingOrPositioned())
bdashccffb432007-07-13 11:51:40 +00001294 return false;
bdakinf876bee2007-10-30 05:27:09 +00001295
hyatt@apple.com0d4818f2009-02-08 05:39:22 +00001296 if (it.obj->isRenderInline() && !inlineFlowRequiresLineBox(toRenderInline(it.obj)))
bdakinf876bee2007-10-30 05:27:09 +00001297 return false;
1298
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001299 if (!shouldCollapseWhiteSpace(it.obj->style(), isLineEmpty, previousLineBrokeCleanly) || it.obj->isBR())
bdashccffb432007-07-13 11:51:40 +00001300 return true;
1301
1302 UChar current = it.current();
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001303 return current != ' ' && current != '\t' && current != softHyphen && (current != '\n' || shouldPreserveNewline(it.obj))
1304 && !skipNonBreakingSpace(it, isLineEmpty, previousLineBrokeCleanly);
bdashccffb432007-07-13 11:51:40 +00001305}
1306
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001307bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj, bool isLineEmpty, bool previousLineBrokeCleanly)
bdashccffb432007-07-13 11:51:40 +00001308{
1309 ASSERT(inlineObj->parent() == this);
1310
mitz@apple.com15035e62008-07-05 20:44:44 +00001311 InlineIterator it(this, inlineObj, 0);
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001312 while (!it.atEnd() && !requiresLineBox(it, isLineEmpty, previousLineBrokeCleanly))
mitz@apple.com1a301772008-03-11 18:30:36 +00001313 it.increment();
bdashccffb432007-07-13 11:51:40 +00001314
1315 return !it.atEnd();
1316}
1317
hyatt@apple.come16585a2011-02-28 23:21:36 +00001318static void setStaticPositions(RenderBlock* block, RenderBox* child)
1319{
1320 // FIXME: The math here is actually not really right. It's a best-guess approximation that
1321 // will work for the common cases
1322 RenderObject* containerBlock = child->container();
1323 if (containerBlock->isRenderInline()) {
1324 // A relative positioned inline encloses us. In this case, we also have to determine our
1325 // position as though we were an inline. Set |staticInlinePosition| and |staticBlockPosition| on the relative positioned
1326 // inline so that we can obtain the value later.
1327 toRenderInline(containerBlock)->layer()->setStaticInlinePosition(block->startOffsetForLine(block->logicalHeight(), false));
1328 toRenderInline(containerBlock)->layer()->setStaticBlockPosition(block->logicalHeight());
1329 }
1330
1331 bool isHorizontal = block->style()->isHorizontalWritingMode();
1332 bool hasStaticInlinePosition = child->style()->hasStaticInlinePosition(isHorizontal);
1333 bool hasStaticBlockPosition = child->style()->hasStaticBlockPosition(isHorizontal);
1334
1335 if (hasStaticInlinePosition) {
1336 if (child->style()->isOriginalDisplayInlineType())
1337 child->layer()->setStaticInlinePosition(block->startOffsetForLine(block->logicalHeight(), false));
1338 else
1339 child->layer()->setStaticInlinePosition(block->borderAndPaddingStart());
1340 }
1341
1342 if (hasStaticBlockPosition)
1343 child->layer()->setStaticBlockPosition(block->logicalHeight());
1344}
1345
mitz@apple.combf6e8d32008-07-25 20:21:06 +00001346// FIXME: The entire concept of the skipTrailingWhitespace function is flawed, since we really need to be building
mitz@apple.com1a301772008-03-11 18:30:36 +00001347// line boxes even for containers that may ultimately collapse away. Otherwise we'll never get positioned
1348// elements quite right. In other words, we need to build this function's work into the normal line
1349// object iteration process.
mitz@apple.combf6e8d32008-07-25 20:21:06 +00001350// NB. this function will insert any floating elements that would otherwise
1351// be skipped but it will not position them.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001352void RenderBlock::skipTrailingWhitespace(InlineIterator& iterator, bool isLineEmpty, bool previousLineBrokeCleanly)
kociendabb0c24b2001-08-24 14:24:40 +00001353{
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001354 while (!iterator.atEnd() && !requiresLineBox(iterator, isLineEmpty, previousLineBrokeCleanly)) {
mitz@apple.com1a301772008-03-11 18:30:36 +00001355 RenderObject* object = iterator.obj;
1356 if (object->isFloating()) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00001357 insertFloatingObject(toRenderBox(object));
hyatt@apple.come16585a2011-02-28 23:21:36 +00001358 } else if (object->isPositioned())
1359 setStaticPositions(this, toRenderBox(object));
mitz@apple.com1a301772008-03-11 18:30:36 +00001360 iterator.increment();
mjs6f821c82002-03-22 00:31:57 +00001361 }
mitz@apple.com1a301772008-03-11 18:30:36 +00001362}
bdashccffb432007-07-13 11:51:40 +00001363
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001364int RenderBlock::skipLeadingWhitespace(InlineBidiResolver& resolver, bool firstLine, bool isLineEmpty, bool previousLineBrokeCleanly,
1365 FloatingObject* lastFloatFromPreviousLine)
mitz@apple.com1a301772008-03-11 18:30:36 +00001366{
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001367 int availableWidth = availableLogicalWidthForLine(logicalHeight(), firstLine);
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001368 while (!resolver.position().atEnd() && !requiresLineBox(resolver.position(), isLineEmpty, previousLineBrokeCleanly)) {
mitz@apple.com15035e62008-07-05 20:44:44 +00001369 RenderObject* object = resolver.position().obj;
mitz@apple.com1a301772008-03-11 18:30:36 +00001370 if (object->isFloating()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001371 positionNewFloatOnLine(insertFloatingObject(toRenderBox(object)), lastFloatFromPreviousLine);
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001372 availableWidth = availableLogicalWidthForLine(logicalHeight(), firstLine);
hyatt@apple.come16585a2011-02-28 23:21:36 +00001373 } else if (object->isPositioned())
1374 setStaticPositions(this, toRenderBox(object));
mitz@apple.com15035e62008-07-05 20:44:44 +00001375 resolver.increment();
mitz@apple.com1a301772008-03-11 18:30:36 +00001376 }
mitz@apple.com83d2e872008-10-23 21:56:03 +00001377 resolver.commitExplicitEmbedding();
mitz@apple.com1a301772008-03-11 18:30:36 +00001378 return availableWidth;
kociendae40cb942004-10-05 20:05:38 +00001379}
1380
bdakinf876bee2007-10-30 05:27:09 +00001381// This is currently just used for list markers and inline flows that have line boxes. Neither should
1382// have an effect on whitespace at the start of the line.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001383static bool shouldSkipWhitespaceAfterStartObject(RenderBlock* block, RenderObject* o, LineMidpointState& lineMidpointState)
bdakinf876bee2007-10-30 05:27:09 +00001384{
mitz@apple.com1a301772008-03-11 18:30:36 +00001385 RenderObject* next = bidiNext(block, o);
darin@apple.com36744d62009-01-25 20:23:04 +00001386 if (next && !next->isBR() && next->isText() && toRenderText(next)->textLength() > 0) {
1387 RenderText* nextText = toRenderText(next);
bdakinf876bee2007-10-30 05:27:09 +00001388 UChar nextChar = nextText->characters()[0];
1389 if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) {
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001390 addMidpoint(lineMidpointState, InlineIterator(0, o, 0));
bdakinf876bee2007-10-30 05:27:09 +00001391 return true;
1392 }
1393 }
1394
1395 return false;
1396}
1397
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001398void RenderBlock::fitBelowFloats(float widthToFit, bool firstLine, float& availableWidth)
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001399{
1400 ASSERT(widthToFit > availableWidth);
1401
hyatt@apple.com2d76a3b2010-10-02 00:13:00 +00001402 int floatLogicalBottom;
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001403 int lastFloatLogicalBottom = logicalHeight();
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001404 float newLineWidth = availableWidth;
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001405 while (true) {
hyatt@apple.com2d76a3b2010-10-02 00:13:00 +00001406 floatLogicalBottom = nextFloatLogicalBottomBelow(lastFloatLogicalBottom);
1407 if (!floatLogicalBottom)
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001408 break;
1409
hyatt@apple.com2d76a3b2010-10-02 00:13:00 +00001410 newLineWidth = availableLogicalWidthForLine(floatLogicalBottom, firstLine);
1411 lastFloatLogicalBottom = floatLogicalBottom;
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001412 if (newLineWidth >= widthToFit)
1413 break;
1414 }
1415
1416 if (newLineWidth > availableWidth) {
hyatt@apple.com2d76a3b2010-10-02 00:13:00 +00001417 setLogicalHeight(lastFloatLogicalBottom);
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001418 availableWidth = newLineWidth;
1419 }
1420}
1421
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001422static inline float textWidth(RenderText* text, unsigned from, unsigned len, const Font& font, float xPos, bool isFixedPitch, bool collapseWhiteSpace)
mitz@apple.com34106442009-02-01 06:23:39 +00001423{
hyatt@apple.com4d046b72011-01-31 20:39:09 +00001424 if (isFixedPitch || (!from && len == text->textLength()) || text->style()->hasTextCombine())
mitz@apple.com34106442009-02-01 06:23:39 +00001425 return text->width(from, len, font, xPos);
1426 return font.width(TextRun(text->characters() + from, len, !collapseWhiteSpace, xPos));
1427}
1428
mitz@apple.comd56f1082011-03-06 22:44:48 +00001429static void tryHyphenating(RenderText* text, const Font& font, const AtomicString& localeIdentifier, int minimumPrefixLength, int minimumSuffixLength, int lastSpace, int 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 +00001430{
mitz@apple.comd56f1082011-03-06 22:44:48 +00001431 // Map 'hyphenate-limit-{before,after}: auto;' to 2.
1432 if (minimumPrefixLength < 0)
1433 minimumPrefixLength = 2;
1434
1435 if (minimumSuffixLength < 0)
1436 minimumSuffixLength = 2;
1437
1438 if (pos - lastSpace <= minimumSuffixLength)
1439 return;
1440
mitz@apple.comb2107652010-06-21 16:54:52 +00001441 const AtomicString& hyphenString = text->style()->hyphenString();
1442 int hyphenWidth = font.width(TextRun(hyphenString.characters(), hyphenString.length()));
1443
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001444 float maxPrefixWidth = availableWidth - xPos - hyphenWidth - lastSpaceWordSpacing;
mitz@apple.com7c67b292010-09-12 23:04:16 +00001445 // If the maximum width available for the prefix before the hyphen is small, then it is very unlikely
1446 // that an hyphenation opportunity exists, so do not bother to look for it.
1447 if (maxPrefixWidth <= font.pixelSize() * 5 / 4)
1448 return;
1449
1450 unsigned prefixLength = font.offsetForPosition(TextRun(text->characters() + lastSpace, pos - lastSpace, !collapseWhiteSpace, xPos + lastSpaceWordSpacing), maxPrefixWidth, false);
mitz@apple.comd56f1082011-03-06 22:44:48 +00001451 if (prefixLength < static_cast<unsigned>(minimumPrefixLength))
mitz@apple.comb2107652010-06-21 16:54:52 +00001452 return;
1453
mitz@apple.comd56f1082011-03-06 22:44:48 +00001454 prefixLength = lastHyphenLocation(text->characters() + lastSpace, pos - lastSpace, min(prefixLength, static_cast<unsigned>(pos - lastSpace - minimumSuffixLength)) + 1, localeIdentifier);
1455 // FIXME: The following assumes that the character at lastSpace is a space (and therefore should not factor
1456 // into hyphenate-limit-before) unless lastSpace is 0. This is wrong in the rare case of hyphenating
1457 // the first word in a text node which has leading whitespace.
mitz@apple.come4bedf32011-03-14 00:54:59 +00001458 if (!prefixLength || prefixLength - (lastSpace ? 1 : 0) < static_cast<unsigned>(minimumPrefixLength))
mitz@apple.comb2107652010-06-21 16:54:52 +00001459 return;
1460
mitz@apple.comd56f1082011-03-06 22:44:48 +00001461 ASSERT(pos - lastSpace - prefixLength >= static_cast<unsigned>(minimumSuffixLength));
1462
mitz@apple.comb2107652010-06-21 16:54:52 +00001463#if !ASSERT_DISABLED
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001464 float prefixWidth = hyphenWidth + textWidth(text, lastSpace, prefixLength, font, xPos, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
mitz@apple.comb2107652010-06-21 16:54:52 +00001465 ASSERT(xPos + prefixWidth <= availableWidth);
mitz@apple.com34b43c72010-06-21 17:21:22 +00001466#else
1467 UNUSED_PARAM(isFixedPitch);
mitz@apple.comb2107652010-06-21 16:54:52 +00001468#endif
1469
1470 lineBreak.obj = text;
1471 lineBreak.pos = lastSpace + prefixLength;
1472 lineBreak.nextBreakablePosition = nextBreakable;
1473 hyphenated = true;
1474}
1475
mitz@apple.com44fc5132011-02-25 18:34:15 +00001476InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool firstLine, bool& isLineEmpty, LineBreakIteratorInfo& lineBreakIteratorInfo, bool& previousLineBrokeCleanly,
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001477 bool& hyphenated, EClear* clear, FloatingObject* lastFloatFromPreviousLine)
kociendae40cb942004-10-05 20:05:38 +00001478{
mitz@apple.com15035e62008-07-05 20:44:44 +00001479 ASSERT(resolver.position().block == this);
mitz@apple.com51017322008-02-26 06:47:43 +00001480
mitz@apple.com15035e62008-07-05 20:44:44 +00001481 bool appliedStartWidth = resolver.position().pos > 0;
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001482 LineMidpointState& lineMidpointState = resolver.midpointState();
1483
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001484 float width = skipLeadingWhitespace(resolver, firstLine, isLineEmpty, previousLineBrokeCleanly, lastFloatFromPreviousLine);
mitz@apple.com1a301772008-03-11 18:30:36 +00001485
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001486 float w = 0;
1487 float tmpW = 0;
kociendae40cb942004-10-05 20:05:38 +00001488
mitz@apple.com15035e62008-07-05 20:44:44 +00001489 if (resolver.position().atEnd())
1490 return resolver.position();
mjs6f821c82002-03-22 00:31:57 +00001491
hyatt33f8d492002-11-12 21:44:52 +00001492 // This variable is used only if whitespace isn't set to PRE, and it tells us whether
1493 // or not we are currently ignoring whitespace.
1494 bool ignoringSpaces = false;
mitz@apple.com15035e62008-07-05 20:44:44 +00001495 InlineIterator ignoreStart;
hyatt33f8d492002-11-12 21:44:52 +00001496
1497 // This variable tracks whether the very last character we saw was a space. We use
1498 // this to detect when we encounter a second space so we know we have to terminate
1499 // a run.
rjwc9c257d2003-01-24 03:46:17 +00001500 bool currentCharacterIsSpace = false;
harrisone343c412005-01-18 01:07:26 +00001501 bool currentCharacterIsWS = false;
hyatt33f8d492002-11-12 21:44:52 +00001502 RenderObject* trailingSpaceObject = 0;
hyatt98b16282004-03-31 18:43:12 +00001503
mitz@apple.com15035e62008-07-05 20:44:44 +00001504 InlineIterator lBreak = resolver.position();
mjs6f821c82002-03-22 00:31:57 +00001505
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001506 RenderObject* o = resolver.position().obj;
1507 RenderObject* last = o;
mitz@apple.com15035e62008-07-05 20:44:44 +00001508 unsigned pos = resolver.position().pos;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001509 int nextBreakable = resolver.position().nextBreakablePosition;
ddkilzere8759ef2007-03-25 06:28:19 +00001510 bool atStart = true;
kociendabb0c24b2001-08-24 14:24:40 +00001511
hyatt0c3a9862004-02-23 21:26:26 +00001512 bool prevLineBrokeCleanly = previousLineBrokeCleanly;
1513 previousLineBrokeCleanly = false;
ddkilzer5d01fa22007-01-29 03:10:37 +00001514
mitz@apple.comb2107652010-06-21 16:54:52 +00001515 hyphenated = false;
1516
ddkilzer5d01fa22007-01-29 03:10:37 +00001517 bool autoWrapWasEverTrueOnLine = false;
mitz@apple.com25beac62008-02-24 18:48:27 +00001518 bool floatsFitOnLine = true;
hyatt01eff982003-03-14 20:13:23 +00001519
hyatt@apple.com69340902008-01-16 21:24:21 +00001520 // Firefox and Opera will allow a table cell to grow to fit an image inside it under
mitz@apple.com25beac62008-02-24 18:48:27 +00001521 // very specific circumstances (in order to match common WinIE renderings).
hyatt@apple.com69340902008-01-16 21:24:21 +00001522 // Not supporting the quirk has caused us to mis-render some real sites. (See Bugzilla 10517.)
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001523 bool allowImagesToBreak = !document()->inQuirksMode() || !isTableCell() || !style()->logicalWidth().isIntrinsicOrAuto();
hyatt@apple.com69340902008-01-16 21:24:21 +00001524
hyattb0d9f602007-01-15 01:28:23 +00001525 EWhiteSpace currWS = style()->whiteSpace();
1526 EWhiteSpace lastWS = currWS;
hyatt275d0702005-11-03 23:53:57 +00001527 while (o) {
hyattb0d9f602007-01-15 01:28:23 +00001528 currWS = o->isReplaced() ? o->parent()->style()->whiteSpace() : o->style()->whiteSpace();
1529 lastWS = last->isReplaced() ? last->parent()->style()->whiteSpace() : last->style()->whiteSpace();
1530
1531 bool autoWrap = RenderStyle::autoWrap(currWS);
ddkilzer5d01fa22007-01-29 03:10:37 +00001532 autoWrapWasEverTrueOnLine = autoWrapWasEverTrueOnLine || autoWrap;
zimmermannac3781f2007-02-04 01:25:03 +00001533
mjsd2948ef2007-02-26 19:29:04 +00001534#if ENABLE(SVG)
zimmermann@webkit.orge943aaa2010-06-25 10:03:33 +00001535 bool preserveNewline = o->isSVGInlineText() ? false : RenderStyle::preserveNewline(currWS);
zimmermannac3781f2007-02-04 01:25:03 +00001536#else
hyattb0d9f602007-01-15 01:28:23 +00001537 bool preserveNewline = RenderStyle::preserveNewline(currWS);
zimmermannac3781f2007-02-04 01:25:03 +00001538#endif
1539
hyattb0d9f602007-01-15 01:28:23 +00001540 bool collapseWhiteSpace = RenderStyle::collapseWhiteSpace(currWS);
1541
hyatt275d0702005-11-03 23:53:57 +00001542 if (o->isBR()) {
hyatt0c3a9862004-02-23 21:26:26 +00001543 if (w + tmpW <= width) {
kociendabb0c24b2001-08-24 14:24:40 +00001544 lBreak.obj = o;
1545 lBreak.pos = 0;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001546 lBreak.nextBreakablePosition = -1;
mitz@apple.com1a301772008-03-11 18:30:36 +00001547 lBreak.increment();
hyatt0c3a9862004-02-23 21:26:26 +00001548
hyatt33f8d492002-11-12 21:44:52 +00001549 // A <br> always breaks a line, so don't let the line be collapsed
1550 // away. Also, the space at the end of a line with a <br> does not
hyatt01eff982003-03-14 20:13:23 +00001551 // get collapsed away. It only does this if the previous line broke
1552 // cleanly. Otherwise the <br> has no effect on whether the line is
1553 // empty or not.
1554 if (prevLineBrokeCleanly)
1555 isLineEmpty = false;
hyatt33f8d492002-11-12 21:44:52 +00001556 trailingSpaceObject = 0;
hyatt0c3a9862004-02-23 21:26:26 +00001557 previousLineBrokeCleanly = true;
hyatt74eec4d2003-03-23 08:02:47 +00001558
mitz@apple.com71e30842008-03-18 16:13:31 +00001559 if (!isLineEmpty && clear)
1560 *clear = o->style()->clear();
kociendabb0c24b2001-08-24 14:24:40 +00001561 }
1562 goto end;
1563 }
hyattb0d9f602007-01-15 01:28:23 +00001564
hyatt275d0702005-11-03 23:53:57 +00001565 if (o->isFloatingOrPositioned()) {
kociendabb0c24b2001-08-24 14:24:40 +00001566 // add to special objects...
hyatt275d0702005-11-03 23:53:57 +00001567 if (o->isFloating()) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00001568 RenderBox* floatBox = toRenderBox(o);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001569 FloatingObject* f = insertFloatingObject(floatBox);
hyatt33f8d492002-11-12 21:44:52 +00001570 // check if it fits in the current line.
1571 // If it does, position it now, otherwise, position
1572 // it after moving to next line (in newLine() func)
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001573 if (floatsFitOnLine && logicalWidthForFloat(f) + w + tmpW <= width) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001574 positionNewFloatOnLine(f, lastFloatFromPreviousLine);
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001575 width = availableLogicalWidthForLine(logicalHeight(), firstLine);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001576 if (lBreak.obj == o) {
1577 ASSERT(!lBreak.pos);
1578 lBreak.increment();
1579 }
mitz@apple.com25beac62008-02-24 18:48:27 +00001580 } else
1581 floatsFitOnLine = false;
hyatt275d0702005-11-03 23:53:57 +00001582 } else if (o->isPositioned()) {
hyatt851816b2003-07-08 07:54:17 +00001583 // If our original display wasn't an inline type, then we can
hyatt@apple.come16585a2011-02-28 23:21:36 +00001584 // go ahead and determine our static inline position now.
hyatt@apple.com0de4d642009-02-05 22:26:53 +00001585 RenderBox* box = toRenderBox(o);
1586 bool isInlineType = box->style()->isOriginalDisplayInlineType();
hyatt@apple.come16585a2011-02-28 23:21:36 +00001587 bool needToSetStaticInlinePosition = box->style()->hasStaticInlinePosition(style()->isHorizontalWritingMode());
1588 if (needToSetStaticInlinePosition && !isInlineType) {
1589 box->layer()->setStaticInlinePosition(borderAndPaddingStart());
1590 needToSetStaticInlinePosition = false;
hyatt98ee7e42003-05-14 01:39:15 +00001591 }
1592
1593 // If our original display was an INLINE type, then we can go ahead
1594 // and determine our static y position now.
hyatt@apple.come16585a2011-02-28 23:21:36 +00001595 bool needToSetStaticBlockPosition = box->style()->hasStaticBlockPosition(style()->isHorizontalWritingMode());
1596 if (needToSetStaticBlockPosition && isInlineType) {
1597 box->layer()->setStaticBlockPosition(logicalHeight());
1598 needToSetStaticBlockPosition = false;
hyatt98ee7e42003-05-14 01:39:15 +00001599 }
1600
hyatt@apple.come16585a2011-02-28 23:21:36 +00001601 bool needToCreateLineBox = needToSetStaticInlinePosition || needToSetStaticBlockPosition;
hyatt853cd7d2004-11-05 02:59:48 +00001602 RenderObject* c = o->container();
hyatt@apple.come16585a2011-02-28 23:21:36 +00001603 if (c->isRenderInline() && (!needToSetStaticInlinePosition || !needToSetStaticBlockPosition))
hyatt853cd7d2004-11-05 02:59:48 +00001604 needToCreateLineBox = true;
1605
hyatt98ee7e42003-05-14 01:39:15 +00001606 // If we're ignoring spaces, we have to stop and include this object and
1607 // then start ignoring spaces again.
hyatt853cd7d2004-11-05 02:59:48 +00001608 if (needToCreateLineBox) {
hyattbc7f07f2003-05-27 20:04:26 +00001609 trailingSpaceObject = 0;
hyatt98b16282004-03-31 18:43:12 +00001610 ignoreStart.obj = o;
1611 ignoreStart.pos = 0;
hyattbc7f07f2003-05-27 20:04:26 +00001612 if (ignoringSpaces) {
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001613 addMidpoint(lineMidpointState, ignoreStart); // Stop ignoring spaces.
1614 addMidpoint(lineMidpointState, ignoreStart); // Start ignoring again.
hyattbc7f07f2003-05-27 20:04:26 +00001615 }
hyatt98b16282004-03-31 18:43:12 +00001616
hyatt851816b2003-07-08 07:54:17 +00001617 }
hyatt98ee7e42003-05-14 01:39:15 +00001618 }
hyatt@apple.com415d8de2009-01-26 22:29:19 +00001619 } else if (o->isRenderInline()) {
bdakinf876bee2007-10-30 05:27:09 +00001620 // Right now, we should only encounter empty inlines here.
ggarenf9f32ae2007-03-26 20:08:53 +00001621 ASSERT(!o->firstChild());
bdakinf876bee2007-10-30 05:27:09 +00001622
hyatt@apple.com0d4818f2009-02-08 05:39:22 +00001623 RenderInline* flowBox = toRenderInline(o);
hyatt@apple.com774bbed2009-01-23 05:13:22 +00001624
bdakinf876bee2007-10-30 05:27:09 +00001625 // Now that some inline flows have line boxes, if we are already ignoring spaces, we need
1626 // to make sure that we stop to include this object and then start ignoring spaces again.
1627 // If this object is at the start of the line, we need to behave like list markers and
1628 // start ignoring spaces.
hyatt@apple.com774bbed2009-01-23 05:13:22 +00001629 if (inlineFlowRequiresLineBox(flowBox)) {
hyatt@apple.comeb66ef42008-01-18 22:59:29 +00001630 isLineEmpty = false;
bdakinf876bee2007-10-30 05:27:09 +00001631 if (ignoringSpaces) {
1632 trailingSpaceObject = 0;
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001633 addMidpoint(lineMidpointState, InlineIterator(0, o, 0)); // Stop ignoring spaces.
1634 addMidpoint(lineMidpointState, InlineIterator(0, o, 0)); // Start ignoring again.
mitz@apple.com15035e62008-07-05 20:44:44 +00001635 } else if (style()->collapseWhiteSpace() && resolver.position().obj == o
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001636 && shouldSkipWhitespaceAfterStartObject(this, o, lineMidpointState)) {
bdakinf876bee2007-10-30 05:27:09 +00001637 // Like with list markers, we start ignoring spaces to make sure that any
1638 // additional spaces we see will be discarded.
1639 currentCharacterIsSpace = true;
1640 currentCharacterIsWS = true;
1641 ignoringSpaces = true;
1642 }
1643 }
1644
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001645 tmpW += flowBox->marginStart() + flowBox->borderStart() + flowBox->paddingStart() +
1646 flowBox->marginEnd() + flowBox->borderEnd() + flowBox->paddingEnd();
hyatt275d0702005-11-03 23:53:57 +00001647 } else if (o->isReplaced()) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00001648 RenderBox* replacedBox = toRenderBox(o);
1649
hyattde396342003-10-29 08:57:20 +00001650 // Break on replaced elements if either has normal white-space.
hyatt@apple.com69340902008-01-16 21:24:21 +00001651 if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!o->isImage() || allowImagesToBreak)) {
hyatt711fe232002-11-20 21:25:14 +00001652 w += tmpW;
1653 tmpW = 0;
hyattf14a4a32002-11-21 22:06:32 +00001654 lBreak.obj = o;
1655 lBreak.pos = 0;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001656 lBreak.nextBreakablePosition = -1;
hyatt711fe232002-11-20 21:25:14 +00001657 }
1658
mitz@apple.combfdc9112008-02-21 19:59:40 +00001659 if (ignoringSpaces)
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001660 addMidpoint(lineMidpointState, InlineIterator(0, o, 0));
mitz@apple.combfdc9112008-02-21 19:59:40 +00001661
hyatt33f8d492002-11-12 21:44:52 +00001662 isLineEmpty = false;
1663 ignoringSpaces = false;
rjwc9c257d2003-01-24 03:46:17 +00001664 currentCharacterIsSpace = false;
harrisone343c412005-01-18 01:07:26 +00001665 currentCharacterIsWS = false;
hyatt33f8d492002-11-12 21:44:52 +00001666 trailingSpaceObject = 0;
hamaji@chromium.org382642b2009-12-01 07:37:14 +00001667
bdakinf876bee2007-10-30 05:27:09 +00001668 // Optimize for a common case. If we can't find whitespace after the list
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001669 // item, then this is all moot.
1670 int replacedLogicalWidth = logicalWidthForChild(replacedBox) + marginStartForChild(replacedBox) + marginEndForChild(replacedBox) + inlineLogicalWidth(o);
hamaji@chromium.org382642b2009-12-01 07:37:14 +00001671 if (o->isListMarker()) {
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001672 if (style()->collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(this, o, lineMidpointState)) {
bdakinf876bee2007-10-30 05:27:09 +00001673 // Like with inline flows, we start ignoring spaces to make sure that any
1674 // additional spaces we see will be discarded.
1675 currentCharacterIsSpace = true;
1676 currentCharacterIsWS = true;
1677 ignoringSpaces = true;
hyatte85e4a72002-12-08 02:06:16 +00001678 }
hamaji@chromium.org382642b2009-12-01 07:37:14 +00001679 if (toRenderListMarker(o)->isInside())
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001680 tmpW += replacedLogicalWidth;
justing244d3a32006-04-13 01:31:24 +00001681 } else
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001682 tmpW += replacedLogicalWidth;
eseidel789896f2005-11-27 22:52:09 +00001683 } else if (o->isText()) {
mitz@apple.com51017322008-02-26 06:47:43 +00001684 if (!pos)
1685 appliedStartWidth = false;
1686
darin@apple.com36744d62009-01-25 20:23:04 +00001687 RenderText* t = toRenderText(o);
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00001688
zimmermann@webkit.org6e96afd2010-09-10 15:35:50 +00001689#if ENABLE(SVG)
1690 bool isSVGText = t->isSVGInlineText();
1691#endif
1692
hyatt@apple.com4d046b72011-01-31 20:39:09 +00001693 RenderStyle* style = t->style(firstLine);
1694 if (style->hasTextCombine())
1695 toRenderCombineText(o)->combineText();
1696
darin42563ac52007-01-22 17:28:57 +00001697 int strlen = t->textLength();
hyatt33f8d492002-11-12 21:44:52 +00001698 int len = strlen - pos;
darin42563ac52007-01-22 17:28:57 +00001699 const UChar* str = t->characters();
kociendabb0c24b2001-08-24 14:24:40 +00001700
mitz@apple.comb2107652010-06-21 16:54:52 +00001701 const Font& f = style->font();
mitz@apple.com34106442009-02-01 06:23:39 +00001702 bool isFixedPitch = f.isFixedPitch();
mitz@apple.com6ae88612011-03-03 23:09:11 +00001703 bool canHyphenate = style->hyphens() == HyphensAuto && WebCore::canHyphenate(style->locale());
weinigf28a1c32007-02-14 14:10:31 +00001704
hyatt33f8d492002-11-12 21:44:52 +00001705 int lastSpace = pos;
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001706 float wordSpacing = o->style()->wordSpacing();
1707 float lastSpaceWordSpacing = 0;
hyattffe78712003-02-11 01:59:29 +00001708
mitz@apple.comfa13fcc2010-01-07 01:41:32 +00001709 // Non-zero only when kerning is enabled, in which case we measure words with their trailing
1710 // space, then subtract its width.
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001711 float wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(TextRun(&space, 1)) + wordSpacing : 0;
mitz@apple.comfa13fcc2010-01-07 01:41:32 +00001712
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001713 float wrapW = tmpW + inlineLogicalWidth(o, !appliedStartWidth, true);
1714 float charWidth = 0;
weinigf28a1c32007-02-14 14:10:31 +00001715 bool breakNBSP = autoWrap && o->style()->nbspMode() == SPACE;
1716 // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word,
1717 // which is only possible if the word is the first thing on the line, that is, if |w| is zero.
hyattea474f72007-04-20 05:02:19 +00001718 bool breakWords = o->style()->breakWords() && ((autoWrap && !w) || currWS == PRE);
weinigf28a1c32007-02-14 14:10:31 +00001719 bool midWordBreak = false;
hyattea474f72007-04-20 05:02:19 +00001720 bool breakAll = o->style()->wordBreak() == BreakAllWordBreak && autoWrap;
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001721 float hyphenWidth = 0;
hyattea474f72007-04-20 05:02:19 +00001722
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00001723 if (t->isWordBreak()) {
1724 w += tmpW;
1725 tmpW = 0;
1726 lBreak.obj = o;
1727 lBreak.pos = 0;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001728 lBreak.nextBreakablePosition = -1;
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00001729 ASSERT(!len);
1730 }
1731
hyatt275d0702005-11-03 23:53:57 +00001732 while (len) {
rjwc9c257d2003-01-24 03:46:17 +00001733 bool previousCharacterIsSpace = currentCharacterIsSpace;
harrisone343c412005-01-18 01:07:26 +00001734 bool previousCharacterIsWS = currentCharacterIsWS;
darin7ab31092006-05-10 04:59:57 +00001735 UChar c = str[pos];
hyattb0d9f602007-01-15 01:28:23 +00001736 currentCharacterIsSpace = c == ' ' || c == '\t' || (!preserveNewline && (c == '\n'));
darin47ece0d2005-09-04 07:42:31 +00001737
hyattb0d9f602007-01-15 01:28:23 +00001738 if (!collapseWhiteSpace || !currentCharacterIsSpace)
hyatt33f8d492002-11-12 21:44:52 +00001739 isLineEmpty = false;
mitz@apple.combe429562008-03-07 01:09:51 +00001740
mitz@apple.com20e34452010-09-28 19:38:15 +00001741 if (c == softHyphen && autoWrap && !hyphenWidth && style->hyphens() != HyphensNone) {
1742 const AtomicString& hyphenString = style->hyphenString();
1743 hyphenWidth = f.width(TextRun(hyphenString.characters(), hyphenString.length()));
1744 tmpW += hyphenWidth;
hyatt78b85132004-03-29 20:07:45 +00001745 }
mitz@apple.com20e34452010-09-28 19:38:15 +00001746
zimmermann@webkit.org6e96afd2010-09-10 15:35:50 +00001747#if ENABLE(SVG)
1748 if (isSVGText) {
1749 RenderSVGInlineText* svgInlineText = static_cast<RenderSVGInlineText*>(t);
1750 if (pos > 0) {
1751 if (svgInlineText->characterStartsNewTextChunk(pos)) {
1752 addMidpoint(lineMidpointState, InlineIterator(0, o, pos - 1));
1753 addMidpoint(lineMidpointState, InlineIterator(0, o, pos));
1754 }
1755 }
1756 }
1757#endif
1758
hyatt3aff2332003-01-23 01:15:28 +00001759 bool applyWordSpacing = false;
hyattdca76e92005-11-02 08:52:50 +00001760
darinf9e5d6c2007-01-09 14:54:26 +00001761 currentCharacterIsWS = currentCharacterIsSpace || (breakNBSP && c == noBreakSpace);
harrisone343c412005-01-18 01:07:26 +00001762
weiniged111c12007-07-13 22:45:11 +00001763 if ((breakAll || breakWords) && !midWordBreak) {
1764 wrapW += charWidth;
mitz@apple.com34106442009-02-01 06:23:39 +00001765 charWidth = textWidth(t, pos, 1, f, w + wrapW, isFixedPitch, collapseWhiteSpace);
weiniged111c12007-07-13 22:45:11 +00001766 midWordBreak = w + wrapW + charWidth > width;
weinigf28a1c32007-02-14 14:10:31 +00001767 }
darin47ece0d2005-09-04 07:42:31 +00001768
mitz@apple.com44fc5132011-02-25 18:34:15 +00001769 if (lineBreakIteratorInfo.first != t) {
1770 lineBreakIteratorInfo.first = t;
1771 lineBreakIteratorInfo.second.reset(str, strlen);
1772 }
1773
1774 bool betweenWords = c == '\n' || (currWS != PRE && !atStart && isBreakable(lineBreakIteratorInfo.second, pos, nextBreakable, breakNBSP) && (style->hyphens() != HyphensNone || (pos && str[pos - 1] != softHyphen)));
mitz@apple.com20e34452010-09-28 19:38:15 +00001775
weiniged111c12007-07-13 22:45:11 +00001776 if (betweenWords || midWordBreak) {
hyatt0c05e102006-04-14 08:15:00 +00001777 bool stoppedIgnoringSpaces = false;
hyatt33f8d492002-11-12 21:44:52 +00001778 if (ignoringSpaces) {
rjwc9c257d2003-01-24 03:46:17 +00001779 if (!currentCharacterIsSpace) {
hyatt33f8d492002-11-12 21:44:52 +00001780 // Stop ignoring spaces and begin at this
1781 // new point.
hyatt48710d62003-08-21 09:17:13 +00001782 ignoringSpaces = false;
eseideld13fe532005-11-30 02:40:29 +00001783 lastSpaceWordSpacing = 0;
hyatt48710d62003-08-21 09:17:13 +00001784 lastSpace = pos; // e.g., "Foo goo", don't add in any of the ignored spaces.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001785 addMidpoint(lineMidpointState, InlineIterator(0, o, pos));
hyatt0c05e102006-04-14 08:15:00 +00001786 stoppedIgnoringSpaces = true;
harrisone343c412005-01-18 01:07:26 +00001787 } else {
hyatt33f8d492002-11-12 21:44:52 +00001788 // Just keep ignoring these spaces.
1789 pos++;
1790 len--;
1791 continue;
1792 }
1793 }
rjwc9c257d2003-01-24 03:46:17 +00001794
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001795 float additionalTmpW;
mitz@apple.comfa13fcc2010-01-07 01:41:32 +00001796 if (wordTrailingSpaceWidth && currentCharacterIsSpace)
1797 additionalTmpW = textWidth(t, lastSpace, pos + 1 - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) - wordTrailingSpaceWidth + lastSpaceWordSpacing;
1798 else
1799 additionalTmpW = textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
darin54008922006-01-13 16:39:05 +00001800 tmpW += additionalTmpW;
hyattffe78712003-02-11 01:59:29 +00001801 if (!appliedStartWidth) {
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001802 tmpW += inlineLogicalWidth(o, true, false);
hyattffe78712003-02-11 01:59:29 +00001803 appliedStartWidth = true;
1804 }
1805
eseideld13fe532005-11-30 02:40:29 +00001806 applyWordSpacing = wordSpacing && currentCharacterIsSpace && !previousCharacterIsSpace;
hyatt3aff2332003-01-23 01:15:28 +00001807
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001808 if (!w && autoWrap && tmpW > width)
hyatt@apple.comcd6f8952009-01-28 17:30:26 +00001809 fitBelowFloats(tmpW, firstLine, width);
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001810
hyattb0d9f602007-01-15 01:28:23 +00001811 if (autoWrap || breakWords) {
hyattdca76e92005-11-02 08:52:50 +00001812 // If we break only after white-space, consider the current character
kociendae4134242004-10-25 18:48:44 +00001813 // as candidate width for this line.
ap932806a2006-10-01 09:06:09 +00001814 bool lineWasTooWide = false;
1815 if (w + tmpW <= width && currentCharacterIsWS && o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak) {
mitz@apple.com34106442009-02-01 06:23:39 +00001816 int charWidth = textWidth(t, pos, 1, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + (applyWordSpacing ? wordSpacing : 0);
ap932806a2006-10-01 09:06:09 +00001817 // Check if line is too big even without the extra space
1818 // at the end of the line. If it is not, do nothing.
1819 // If the line needs the extra whitespace to be too long,
1820 // then move the line break to the space and skip all
1821 // additional whitespace.
1822 if (w + tmpW + charWidth > width) {
1823 lineWasTooWide = true;
1824 lBreak.obj = o;
1825 lBreak.pos = pos;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001826 lBreak.nextBreakablePosition = nextBreakable;
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001827 skipTrailingWhitespace(lBreak, isLineEmpty, previousLineBrokeCleanly);
kocienda9dbe9b12004-10-22 20:07:05 +00001828 }
ap932806a2006-10-01 09:06:09 +00001829 }
1830 if (lineWasTooWide || w + tmpW > width) {
mitz@apple.com67ed70a2010-06-22 22:10:10 +00001831 if (canHyphenate && w + tmpW > width) {
mitz@apple.comd56f1082011-03-06 22:44:48 +00001832 tryHyphenating(t, f, style->locale(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, pos, w + tmpW - additionalTmpW, width, isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, nextBreakable, hyphenated);
mitz@apple.com67ed70a2010-06-22 22:10:10 +00001833 if (hyphenated)
1834 goto end;
1835 }
eric@webkit.org1cb44402009-12-29 06:25:16 +00001836 if (lBreak.obj && shouldPreserveNewline(lBreak.obj) && lBreak.obj->isText() && toRenderText(lBreak.obj)->textLength() && !toRenderText(lBreak.obj)->isWordBreak() && toRenderText(lBreak.obj)->characters()[lBreak.pos] == '\n') {
hyatt0c05e102006-04-14 08:15:00 +00001837 if (!stoppedIgnoringSpaces && pos > 0) {
1838 // We need to stop right before the newline and then start up again.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001839 addMidpoint(lineMidpointState, InlineIterator(0, o, pos - 1)); // Stop
1840 addMidpoint(lineMidpointState, InlineIterator(0, o, pos)); // Start
hyatt0c05e102006-04-14 08:15:00 +00001841 }
mitz@apple.com1a301772008-03-11 18:30:36 +00001842 lBreak.increment();
adele7fc3e832006-02-17 09:31:35 +00001843 previousLineBrokeCleanly = true;
adele7fc3e832006-02-17 09:31:35 +00001844 }
mitz@apple.com20e34452010-09-28 19:38:15 +00001845 if (lBreak.obj && lBreak.pos && lBreak.obj->isText() && toRenderText(lBreak.obj)->textLength() && toRenderText(lBreak.obj)->characters()[lBreak.pos - 1] == softHyphen && style->hyphens() != HyphensNone)
1846 hyphenated = true;
hyatt78b85132004-03-29 20:07:45 +00001847 goto end; // Didn't fit. Jump to the end.
darin54008922006-01-13 16:39:05 +00001848 } else {
weiniged111c12007-07-13 22:45:11 +00001849 if (!betweenWords || (midWordBreak && !autoWrap))
darin54008922006-01-13 16:39:05 +00001850 tmpW -= additionalTmpW;
mitz@apple.com20e34452010-09-28 19:38:15 +00001851 if (hyphenWidth) {
darin54008922006-01-13 16:39:05 +00001852 // Subtract the width of the soft hyphen out since we fit on a line.
mitz@apple.com20e34452010-09-28 19:38:15 +00001853 tmpW -= hyphenWidth;
1854 hyphenWidth = 0;
1855 }
darin54008922006-01-13 16:39:05 +00001856 }
rjwc9c257d2003-01-24 03:46:17 +00001857 }
hyatt33f8d492002-11-12 21:44:52 +00001858
hyattb0d9f602007-01-15 01:28:23 +00001859 if (c == '\n' && preserveNewline) {
hyatt0c05e102006-04-14 08:15:00 +00001860 if (!stoppedIgnoringSpaces && pos > 0) {
1861 // We need to stop right before the newline and then start up again.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001862 addMidpoint(lineMidpointState, InlineIterator(0, o, pos - 1)); // Stop
1863 addMidpoint(lineMidpointState, InlineIterator(0, o, pos)); // Start
hyatt0c05e102006-04-14 08:15:00 +00001864 }
hyatta9f48e32003-02-03 22:48:01 +00001865 lBreak.obj = o;
1866 lBreak.pos = pos;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001867 lBreak.nextBreakablePosition = nextBreakable;
mitz@apple.com1a301772008-03-11 18:30:36 +00001868 lBreak.increment();
adele7fc3e832006-02-17 09:31:35 +00001869 previousLineBrokeCleanly = true;
hyatt33f8d492002-11-12 21:44:52 +00001870 return lBreak;
1871 }
hyatta9f48e32003-02-03 22:48:01 +00001872
weinigf28a1c32007-02-14 14:10:31 +00001873 if (autoWrap && betweenWords) {
hyatta9f48e32003-02-03 22:48:01 +00001874 w += tmpW;
weiniged111c12007-07-13 22:45:11 +00001875 wrapW = 0;
hyatta9f48e32003-02-03 22:48:01 +00001876 tmpW = 0;
1877 lBreak.obj = o;
1878 lBreak.pos = pos;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001879 lBreak.nextBreakablePosition = nextBreakable;
weinigf28a1c32007-02-14 14:10:31 +00001880 // Auto-wrapping text should not wrap in the middle of a word once it has had an
1881 // opportunity to break after a word.
1882 breakWords = false;
hyatta9f48e32003-02-03 22:48:01 +00001883 }
hyatt33f8d492002-11-12 21:44:52 +00001884
darin54008922006-01-13 16:39:05 +00001885 if (midWordBreak) {
1886 // Remember this as a breakable position in case
1887 // adding the end width forces a break.
1888 lBreak.obj = o;
1889 lBreak.pos = pos;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001890 lBreak.nextBreakablePosition = nextBreakable;
weiniged111c12007-07-13 22:45:11 +00001891 midWordBreak &= (breakWords || breakAll);
1892 }
1893
1894 if (betweenWords) {
darin54008922006-01-13 16:39:05 +00001895 lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0;
1896 lastSpace = pos;
1897 }
hyatt33f8d492002-11-12 21:44:52 +00001898
hyattdca76e92005-11-02 08:52:50 +00001899 if (!ignoringSpaces && o->style()->collapseWhiteSpace()) {
hyatt33f8d492002-11-12 21:44:52 +00001900 // If we encounter a newline, or if we encounter a
1901 // second space, we need to go ahead and break up this
1902 // run and enter a mode where we start collapsing spaces.
hyatt98b16282004-03-31 18:43:12 +00001903 if (currentCharacterIsSpace && previousCharacterIsSpace) {
hyatt33f8d492002-11-12 21:44:52 +00001904 ignoringSpaces = true;
hyatt98b16282004-03-31 18:43:12 +00001905
hyatt33f8d492002-11-12 21:44:52 +00001906 // We just entered a mode where we are ignoring
1907 // spaces. Create a midpoint to terminate the run
1908 // before the second space.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001909 addMidpoint(lineMidpointState, ignoreStart);
hyatt33f8d492002-11-12 21:44:52 +00001910 }
1911 }
eseidel789896f2005-11-27 22:52:09 +00001912 } else if (ignoringSpaces) {
hyatt33f8d492002-11-12 21:44:52 +00001913 // Stop ignoring spaces and begin at this
1914 // new point.
1915 ignoringSpaces = false;
eseideld13fe532005-11-30 02:40:29 +00001916 lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0;
hyatt33f8d492002-11-12 21:44:52 +00001917 lastSpace = pos; // e.g., "Foo goo", don't add in any of the ignored spaces.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00001918 addMidpoint(lineMidpointState, InlineIterator(0, o, pos));
hyatt33f8d492002-11-12 21:44:52 +00001919 }
hyatt98b16282004-03-31 18:43:12 +00001920
1921 if (currentCharacterIsSpace && !previousCharacterIsSpace) {
1922 ignoreStart.obj = o;
1923 ignoreStart.pos = pos;
1924 }
harrisone343c412005-01-18 01:07:26 +00001925
1926 if (!currentCharacterIsWS && previousCharacterIsWS) {
hyattb0d9f602007-01-15 01:28:23 +00001927 if (autoWrap && o->style()->breakOnlyAfterWhiteSpace()) {
harrisone343c412005-01-18 01:07:26 +00001928 lBreak.obj = o;
1929 lBreak.pos = pos;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001930 lBreak.nextBreakablePosition = nextBreakable;
harrisone343c412005-01-18 01:07:26 +00001931 }
1932 }
hyatt33f8d492002-11-12 21:44:52 +00001933
hyattb0d9f602007-01-15 01:28:23 +00001934 if (collapseWhiteSpace && currentCharacterIsSpace && !ignoringSpaces)
hyatt33f8d492002-11-12 21:44:52 +00001935 trailingSpaceObject = o;
hyattdca76e92005-11-02 08:52:50 +00001936 else if (!o->style()->collapseWhiteSpace() || !currentCharacterIsSpace)
hyatt33f8d492002-11-12 21:44:52 +00001937 trailingSpaceObject = 0;
1938
1939 pos++;
1940 len--;
ddkilzere8759ef2007-03-25 06:28:19 +00001941 atStart = false;
hyatt33f8d492002-11-12 21:44:52 +00001942 }
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00001943
kociendabb0c24b2001-08-24 14:24:40 +00001944 // IMPORTANT: pos is > length here!
hyatt@apple.com0acc9352011-02-17 19:19:07 +00001945 float additionalTmpW = ignoringSpaces ? 0 : textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
mitz@apple.comb2107652010-06-21 16:54:52 +00001946 tmpW += additionalTmpW;
hyatt@apple.com0415e5d2010-10-07 17:40:25 +00001947 tmpW += inlineLogicalWidth(o, !appliedStartWidth, true);
mitz@apple.comb2107652010-06-21 16:54:52 +00001948
1949 if (canHyphenate && w + tmpW > width) {
mitz@apple.comd56f1082011-03-06 22:44:48 +00001950 tryHyphenating(t, f, style->locale(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, pos, w + tmpW - additionalTmpW, width, isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, nextBreakable, hyphenated);
mitz@apple.comb2107652010-06-21 16:54:52 +00001951 if (hyphenated)
1952 goto end;
1953 }
kociendabb0c24b2001-08-24 14:24:40 +00001954 } else
weinigf28a1c32007-02-14 14:10:31 +00001955 ASSERT_NOT_REACHED();
kociendabb0c24b2001-08-24 14:24:40 +00001956
mitz@apple.com1a301772008-03-11 18:30:36 +00001957 RenderObject* next = bidiNext(this, o);
hyattdca76e92005-11-02 08:52:50 +00001958 bool checkForBreak = autoWrap;
hyattb0d9f602007-01-15 01:28:23 +00001959 if (w && w + tmpW > width && lBreak.obj && currWS == NOWRAP)
hyatt74eec4d2003-03-23 08:02:47 +00001960 checkForBreak = true;
1961 else if (next && o->isText() && next->isText() && !next->isBR()) {
hyattdca76e92005-11-02 08:52:50 +00001962 if (autoWrap || (next->style()->autoWrap())) {
hyatta9f48e32003-02-03 22:48:01 +00001963 if (currentCharacterIsSpace)
1964 checkForBreak = true;
1965 else {
harrison07b5e582005-08-15 23:31:16 +00001966 checkForBreak = false;
darin@apple.com36744d62009-01-25 20:23:04 +00001967 RenderText* nextText = toRenderText(next);
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00001968 if (nextText->textLength()) {
darin42563ac52007-01-22 17:28:57 +00001969 UChar c = nextText->characters()[0];
zimmermannac3781f2007-02-04 01:25:03 +00001970 if (c == ' ' || c == '\t' || (c == '\n' && !shouldPreserveNewline(next)))
eseideld13fe532005-11-30 02:40:29 +00001971 // If the next item on the line is text, and if we did not end with
1972 // a space, then the next text run continues our word (and so it needs to
1973 // keep adding to |tmpW|. Just update and continue.
1974 checkForBreak = true;
mitz@apple.comfb8da4e2008-02-19 21:13:19 +00001975 } else if (nextText->isWordBreak())
1976 checkForBreak = true;
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001977 bool willFitOnLine = w + tmpW <= width;
1978 if (!willFitOnLine && !w) {
hyatt@apple.comcd6f8952009-01-28 17:30:26 +00001979 fitBelowFloats(tmpW, firstLine, width);
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001980 willFitOnLine = tmpW <= width;
1981 }
ddkilzere8759ef2007-03-25 06:28:19 +00001982 bool canPlaceOnLine = willFitOnLine || !autoWrapWasEverTrueOnLine;
hyatta9f48e32003-02-03 22:48:01 +00001983 if (canPlaceOnLine && checkForBreak) {
1984 w += tmpW;
1985 tmpW = 0;
1986 lBreak.obj = next;
1987 lBreak.pos = 0;
mitz@apple.comd17dc392008-09-15 18:48:20 +00001988 lBreak.nextBreakablePosition = -1;
hyatta9f48e32003-02-03 22:48:01 +00001989 }
1990 }
1991 }
1992 }
1993
darin54008922006-01-13 16:39:05 +00001994 if (checkForBreak && (w + tmpW > width)) {
kociendabb0c24b2001-08-24 14:24:40 +00001995 // if we have floats, try to get below them.
hyattdca76e92005-11-02 08:52:50 +00001996 if (currentCharacterIsSpace && !ignoringSpaces && o->style()->collapseWhiteSpace())
hyatt33f8d492002-11-12 21:44:52 +00001997 trailingSpaceObject = 0;
mitz@apple.comcfd9b7b2008-02-24 04:00:21 +00001998
1999 if (w)
2000 goto end;
2001
hyatt@apple.comcd6f8952009-01-28 17:30:26 +00002002 fitBelowFloats(tmpW, firstLine, width);
hyattf14a4a32002-11-21 22:06:32 +00002003
hyatta14d1742003-01-02 20:25:46 +00002004 // |width| may have been adjusted because we got shoved down past a float (thus
2005 // giving us more room), so we need to retest, and only jump to
2006 // the end label if we still don't fit on the line. -dwh
darin54008922006-01-13 16:39:05 +00002007 if (w + tmpW > width)
hyatta14d1742003-01-02 20:25:46 +00002008 goto end;
kociendabb0c24b2001-08-24 14:24:40 +00002009 }
hyatt1d9e29b2003-04-10 01:48:53 +00002010
mitz@apple.com1a301772008-03-11 18:30:36 +00002011 if (!o->isFloatingOrPositioned()) {
2012 last = o;
darin@apple.comb6cb2562009-08-05 21:25:09 +00002013 if (last->isReplaced() && autoWrap && (!last->isImage() || allowImagesToBreak) && (!last->isListMarker() || toRenderListMarker(last)->isInside())) {
mitz@apple.com1a301772008-03-11 18:30:36 +00002014 w += tmpW;
2015 tmpW = 0;
2016 lBreak.obj = next;
2017 lBreak.pos = 0;
mitz@apple.comd17dc392008-09-15 18:48:20 +00002018 lBreak.nextBreakablePosition = -1;
mitz@apple.com1a301772008-03-11 18:30:36 +00002019 }
hyatt711fe232002-11-20 21:25:14 +00002020 }
2021
mitz@apple.com1a301772008-03-11 18:30:36 +00002022 o = next;
mitz@apple.comd17dc392008-09-15 18:48:20 +00002023 nextBreakable = -1;
mitz@apple.com1a301772008-03-11 18:30:36 +00002024
hyatta9f48e32003-02-03 22:48:01 +00002025 // Clear out our character space bool, since inline <pre>s don't collapse whitespace
2026 // with adjacent inline normal/nowrap spans.
hyattb0d9f602007-01-15 01:28:23 +00002027 if (!collapseWhiteSpace)
hyatta9f48e32003-02-03 22:48:01 +00002028 currentCharacterIsSpace = false;
2029
kociendabb0c24b2001-08-24 14:24:40 +00002030 pos = 0;
ddkilzere8759ef2007-03-25 06:28:19 +00002031 atStart = false;
kociendabb0c24b2001-08-24 14:24:40 +00002032 }
2033
hyattb0d9f602007-01-15 01:28:23 +00002034
2035 if (w + tmpW <= width || lastWS == NOWRAP) {
kociendabb0c24b2001-08-24 14:24:40 +00002036 lBreak.obj = 0;
2037 lBreak.pos = 0;
mitz@apple.comd17dc392008-09-15 18:48:20 +00002038 lBreak.nextBreakablePosition = -1;
kociendabb0c24b2001-08-24 14:24:40 +00002039 }
2040
2041 end:
eric@webkit.orgee76f4f2009-03-25 22:14:46 +00002042 if (lBreak == resolver.position() && (!lBreak.obj || !lBreak.obj->isBR())) {
kociendabb0c24b2001-08-24 14:24:40 +00002043 // we just add as much as possible
weinig98726da2007-03-15 01:22:19 +00002044 if (style()->whiteSpace() == PRE) {
hyattdca76e92005-11-02 08:52:50 +00002045 // FIXME: Don't really understand this case.
hyatt275d0702005-11-03 23:53:57 +00002046 if (pos != 0) {
kociendabb0c24b2001-08-24 14:24:40 +00002047 lBreak.obj = o;
2048 lBreak.pos = pos - 1;
2049 } else {
2050 lBreak.obj = last;
hyattc3731d42002-12-12 06:20:22 +00002051 lBreak.pos = last->isText() ? last->length() : 0;
mitz@apple.comd17dc392008-09-15 18:48:20 +00002052 lBreak.nextBreakablePosition = -1;
kociendabb0c24b2001-08-24 14:24:40 +00002053 }
hyatt275d0702005-11-03 23:53:57 +00002054 } else if (lBreak.obj) {
yuzo@google.comc25f62f2010-02-09 09:16:36 +00002055 // Don't ever break in the middle of a word if we can help it.
2056 // There's no room at all. We just have to be on this line,
2057 // even though we'll spill out.
2058 lBreak.obj = o;
2059 lBreak.pos = pos;
2060 lBreak.nextBreakablePosition = -1;
kociendabb0c24b2001-08-24 14:24:40 +00002061 }
2062 }
2063
2064 // make sure we consume at least one char/object.
mitz@apple.com15035e62008-07-05 20:44:44 +00002065 if (lBreak == resolver.position())
mitz@apple.com1a301772008-03-11 18:30:36 +00002066 lBreak.increment();
hyatt33f8d492002-11-12 21:44:52 +00002067
hyattfe99c872003-07-31 22:25:29 +00002068 // Sanity check our midpoints.
hyatt@apple.comb3466af2009-06-13 06:04:40 +00002069 checkMidpoints(lineMidpointState, lBreak);
hyattfe99c872003-07-31 22:25:29 +00002070
hyatt33f8d492002-11-12 21:44:52 +00002071 if (trailingSpaceObject) {
2072 // This object is either going to be part of the last midpoint, or it is going
2073 // to be the actual endpoint. In both cases we just decrease our pos by 1 level to
2074 // exclude the space, allowing it to - in effect - collapse into the newline.
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +00002075 if (lineMidpointState.numMidpoints % 2) {
2076 InlineIterator* midpoints = lineMidpointState.midpoints.data();
2077 midpoints[lineMidpointState.numMidpoints - 1].pos--;
hyatt33f8d492002-11-12 21:44:52 +00002078 }
2079 //else if (lBreak.pos > 0)
2080 // lBreak.pos--;
2081 else if (lBreak.obj == 0 && trailingSpaceObject->isText()) {
hyattd20075d2002-11-16 02:23:32 +00002082 // Add a new end midpoint that stops right at the very end.
darin@apple.com36744d62009-01-25 20:23:04 +00002083 RenderText* text = toRenderText(trailingSpaceObject);
darin42563ac52007-01-22 17:28:57 +00002084 unsigned length = text->textLength();
2085 unsigned pos = length >= 2 ? length - 2 : UINT_MAX;
mitz@apple.com15035e62008-07-05 20:44:44 +00002086 InlineIterator endMid(0, trailingSpaceObject, pos);
hyatt@apple.comb3466af2009-06-13 06:04:40 +00002087 addMidpoint(lineMidpointState, endMid);
hyatt33f8d492002-11-12 21:44:52 +00002088 }
2089 }
rjwc9c257d2003-01-24 03:46:17 +00002090
mjs54b64002003-04-02 02:59:02 +00002091 // We might have made lBreak an iterator that points past the end
2092 // of the object. Do this adjustment to make it point to the start
2093 // of the next object instead to avoid confusing the rest of the
2094 // code.
2095 if (lBreak.pos > 0) {
darin54008922006-01-13 16:39:05 +00002096 lBreak.pos--;
mitz@apple.com1a301772008-03-11 18:30:36 +00002097 lBreak.increment();
mjs54b64002003-04-02 02:59:02 +00002098 }
2099
kociendabb0c24b2001-08-24 14:24:40 +00002100 return lBreak;
2101}
2102
hyatt@apple.com5dc5a312009-08-18 19:15:19 +00002103void RenderBlock::addOverflowFromInlineChildren()
hyattb4b20872004-10-20 21:34:01 +00002104{
hyatt@apple.com592848f2010-12-06 20:03:43 +00002105 int endPadding = hasOverflowClip() ? paddingEnd() : 0;
2106 // FIXME: Need to find another way to do this, since scrollbars could show when we don't want them to.
2107 if (hasOverflowClip() && !endPadding && node() && node()->isContentEditable() && node() == node()->rootEditableElement() && style()->isLeftToRightDirection())
2108 endPadding = 1;
hyattb4b20872004-10-20 21:34:01 +00002109 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
hyatt@apple.com592848f2010-12-06 20:03:43 +00002110 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
hyatt@apple.com5dc5a312009-08-18 19:15:19 +00002111 if (!hasOverflowClip())
2112 addVisualOverflow(curr->visualOverflowRect());
hyattb4b20872004-10-20 21:34:01 +00002113 }
2114}
2115
hyatt@apple.com592848f2010-12-06 20:03:43 +00002116int RenderBlock::beforeSideVisualOverflowForLine(RootInlineBox* line) const
hyatt@apple.com81c1d742010-10-06 21:44:02 +00002117{
hyatt@apple.com173cf722011-02-02 20:19:22 +00002118 // Overflow is in the block's coordinate space, which means it isn't purely physical.
hyatt@apple.com7a97d272010-11-11 22:17:38 +00002119 if (style()->isHorizontalWritingMode())
hyatt@apple.com173cf722011-02-02 20:19:22 +00002120 return line->minYVisualOverflow();
2121 return line->minXVisualOverflow();
hyatt@apple.com81c1d742010-10-06 21:44:02 +00002122}
2123
hyatt@apple.com592848f2010-12-06 20:03:43 +00002124int RenderBlock::afterSideVisualOverflowForLine(RootInlineBox* line) const
hyatt@apple.com81c1d742010-10-06 21:44:02 +00002125{
hyatt@apple.com173cf722011-02-02 20:19:22 +00002126 // Overflow is in the block's coordinate space, which means it isn't purely physical.
hyatt@apple.com7a97d272010-11-11 22:17:38 +00002127 if (style()->isHorizontalWritingMode())
hyatt@apple.com173cf722011-02-02 20:19:22 +00002128 return line->maxYVisualOverflow();
2129 return line->maxXVisualOverflow();
hyatt@apple.com81c1d742010-10-06 21:44:02 +00002130}
2131
2132int RenderBlock::beforeSideLayoutOverflowForLine(RootInlineBox* line) const
2133{
hyatt@apple.com173cf722011-02-02 20:19:22 +00002134 // Overflow is in the block's coordinate space, which means it isn't purely physical.
hyatt@apple.com7a97d272010-11-11 22:17:38 +00002135 if (style()->isHorizontalWritingMode())
hyatt@apple.com173cf722011-02-02 20:19:22 +00002136 return line->minYLayoutOverflow();
2137 return line->minXLayoutOverflow();
hyatt@apple.com81c1d742010-10-06 21:44:02 +00002138}
2139
2140int RenderBlock::afterSideLayoutOverflowForLine(RootInlineBox* line) const
2141{
hyatt@apple.com173cf722011-02-02 20:19:22 +00002142 // Overflow is in the block's coordinate space, which means it isn't purely physical.
hyatt@apple.com7a97d272010-11-11 22:17:38 +00002143 if (style()->isHorizontalWritingMode())
hyatt@apple.com173cf722011-02-02 20:19:22 +00002144 return line->maxYLayoutOverflow();
2145 return line->maxXLayoutOverflow();
hyatt@apple.com81c1d742010-10-06 21:44:02 +00002146}
2147
hyatted77ad82004-06-15 07:21:23 +00002148void RenderBlock::deleteEllipsisLineBoxes()
2149{
hyatted77ad82004-06-15 07:21:23 +00002150 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox())
hyattda77c4b2004-06-17 18:09:49 +00002151 curr->clearTruncation();
hyatted77ad82004-06-15 07:21:23 +00002152}
2153
2154void RenderBlock::checkLinesForTextOverflow()
2155{
2156 // Determine the width of the ellipsis using the current font.
darindbba2bb2007-01-11 12:23:49 +00002157 // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable"
2158 TextRun ellipsisRun(&horizontalEllipsis, 1);
bolsinga@apple.com97e42c42008-11-15 04:47:20 +00002159 DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
hyatt3e99d1c2006-02-24 21:13:08 +00002160 const Font& firstLineFont = firstLineStyle()->font();
2161 const Font& font = style()->font();
hyatt43d6c792006-05-11 10:19:34 +00002162 int firstLineEllipsisWidth = firstLineFont.width(ellipsisRun);
2163 int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(ellipsisRun);
hyatted77ad82004-06-15 07:21:23 +00002164
2165 // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see
2166 // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and
2167 // check the left edge of the line box to see if it is less
2168 // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()"
hyatt@apple.comc0fa1632010-09-30 20:01:33 +00002169 bool ltr = style()->isLeftToRightDirection();
hyatted77ad82004-06-15 07:21:23 +00002170 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
hyatt@apple.com230b2802010-09-24 19:14:27 +00002171 int blockRightEdge = logicalRightOffsetForLine(curr->y(), curr == firstRootBox());
2172 int blockLeftEdge = logicalLeftOffsetForLine(curr->y(), curr == firstRootBox());
hyatt@apple.comc01df9e2010-09-23 19:17:33 +00002173 int lineBoxEdge = ltr ? curr->x() + curr->logicalWidth() : curr->x();
dglazkov@chromium.org28434e62009-05-13 22:30:10 +00002174 if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) {
hyattf918d2d2004-06-15 07:24:11 +00002175 // 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 +00002176 // can be truncated. In order for truncation to be possible, the line must have sufficient space to
2177 // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis
2178 // space.
2179 int width = curr == firstRootBox() ? firstLineEllipsisWidth : ellipsisWidth;
dglazkov@chromium.org28434e62009-05-13 22:30:10 +00002180 int blockEdge = ltr ? blockRightEdge : blockLeftEdge;
thakis@chromium.orga4fcdf32011-02-22 05:51:51 +00002181 if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width))
dglazkov@chromium.org28434e62009-05-13 22:30:10 +00002182 curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width);
hyatted77ad82004-06-15 07:21:23 +00002183 }
2184 }
2185}
2186
hyattffe78712003-02-11 01:59:29 +00002187}