blob: 8372be0612bd7d31fc15ba06e42e9ad959f8e1a1 [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.
commit-queue@webkit.org17761402013-04-17 18:48:56 +00005 * Copyright (C) 2013 ChangSeok Oh <shivamidow@gmail.com>
zoltan@webkit.org64be1222013-11-15 21:40:59 +00006 * Copyright (C) 2013 Adobe Systems Inc. All right reserved.
kociendabb0c24b2001-08-24 14:24:40 +00007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
ddkilzerc8eccec2007-09-26 02:29:57 +000020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
kociendabb0c24b2001-08-24 14:24:40 +000022 *
kociendabb0c24b2001-08-24 14:24:40 +000023 */
darinbe4c67d2005-12-19 19:53:12 +000024
mjsb64c50a2005-10-03 21:13:12 +000025#include "config.h"
darin36d11362006-04-11 16:30:21 +000026
weinig@apple.comcef4e1e2013-10-19 03:14:44 +000027#include "AXObjectCache.h"
mitz@apple.com4c1ff322009-07-13 00:54:12 +000028#include "BidiResolver.h"
zoltan@webkit.org64be1222013-11-15 21:40:59 +000029#include "BreakingContextInlineHeaders.h"
bjonesbe@adobe.com67478092013-09-09 22:18:17 +000030#include "FloatingObjects.h"
akling@apple.comd3ec5ef2013-11-07 03:30:11 +000031#include "InlineElementBox.h"
hyatt@apple.com71eeb442010-02-11 20:05:51 +000032#include "InlineIterator.h"
eseidel3a6d1322006-01-09 03:14:50 +000033#include "InlineTextBox.h"
zoltan@webkit.org4c74e8d2013-09-13 17:59:12 +000034#include "LineLayoutState.h"
ggarenec11e5b2007-02-25 02:14:54 +000035#include "Logging.h"
bjonesbe@adobe.com24199752013-10-08 23:20:42 +000036#include "RenderBlockFlow.h"
hyatt@apple.coma10d30e2011-09-22 22:28:21 +000037#include "RenderFlowThread.h"
antti@apple.com8d8ae712013-09-18 18:04:32 +000038#include "RenderLineBreak.h"
zoltan@webkit.orgb7a73462013-02-22 19:53:35 +000039#include "RenderRegion.h"
hyattd8048342006-05-31 01:48:18 +000040#include "RenderView.h"
hyatt@apple.comcc1737c2010-09-16 20:20:02 +000041#include "Settings.h"
antti@apple.com940f5872013-10-24 20:31:11 +000042#include "SimpleLineLayoutFunctions.h"
dbates@webkit.orgf6f05a92010-05-17 04:58:25 +000043#include "TrailingFloatsRootInlineBox.h"
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +000044#include "VerticalPositionCache.h"
slewis@apple.coma7615ca2008-07-12 05:51:33 +000045#include <wtf/RefCountedLeakCounter.h>
bolsinga@apple.com97e42c42008-11-15 04:47:20 +000046#include <wtf/StdLibExtras.h>
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +000047
zimmermann@webkit.orgb40815c2010-06-18 11:18:44 +000048#if ENABLE(SVG)
49#include "SVGRootInlineBox.h"
50#endif
51
darinb9481ed2006-03-20 02:57:59 +000052namespace WebCore {
mjsfe301d72003-10-02 18:46:18 +000053
leviw@chromium.orge7812f32012-02-07 23:46:40 +000054static void determineDirectionality(TextDirection& dir, InlineIterator iter)
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000055{
56 while (!iter.atEnd()) {
57 if (iter.atParagraphSeparator())
58 return;
59 if (UChar current = iter.current()) {
darin@apple.com2eb5f4d2013-10-12 04:16:42 +000060 UCharDirection charDirection = u_charDirection(current);
61 if (charDirection == U_LEFT_TO_RIGHT) {
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000062 dir = LTR;
63 return;
64 }
darin@apple.com2eb5f4d2013-10-12 04:16:42 +000065 if (charDirection == U_RIGHT_TO_LEFT || charDirection == U_RIGHT_TO_LEFT_ARABIC) {
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000066 dir = RTL;
67 return;
68 }
69 }
70 iter.increment();
71 }
72}
73
zoltan@webkit.org64be1222013-11-15 21:40:59 +000074inline BidiRun* createRun(int start, int end, RenderObject* obj, InlineBidiResolver& resolver)
eric@webkit.org5bee2942011-04-08 02:12:31 +000075{
akling@apple.com7506fda2013-11-07 10:12:36 +000076 ASSERT(obj);
77 return new BidiRun(start, end, *obj, resolver.context(), resolver.dir());
eric@webkit.org5bee2942011-04-08 02:12:31 +000078}
79
bjonesbe@adobe.com24199752013-10-08 23:20:42 +000080void RenderBlockFlow::appendRunsForObject(BidiRunList<BidiRun>& runs, int start, int end, RenderObject* obj, InlineBidiResolver& resolver)
hyatt33f8d492002-11-12 21:44:52 +000081{
leviw@chromium.orgd8df17d2012-05-24 21:47:47 +000082 if (start > end || shouldSkipCreatingRunsForObject(obj))
hyatteb003b82002-11-15 22:35:10 +000083 return;
hyatt85586af2003-02-19 23:22:42 +000084
hyatt@apple.comb3466af2009-06-13 06:04:40 +000085 LineMidpointState& lineMidpointState = resolver.midpointState();
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +000086 bool haveNextMidpoint = (lineMidpointState.currentMidpoint < lineMidpointState.numMidpoints);
mitz@apple.com15035e62008-07-05 20:44:44 +000087 InlineIterator nextMidpoint;
hyatt85586af2003-02-19 23:22:42 +000088 if (haveNextMidpoint)
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +000089 nextMidpoint = lineMidpointState.midpoints[lineMidpointState.currentMidpoint];
90 if (lineMidpointState.betweenMidpoints) {
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +000091 if (!(haveNextMidpoint && nextMidpoint.renderer() == obj))
hyatt33f8d492002-11-12 21:44:52 +000092 return;
eric@webkit.org060caf62011-05-03 22:11:39 +000093 // This is a new start point. Stop ignoring objects and
hyatt33f8d492002-11-12 21:44:52 +000094 // adjust our start.
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +000095 lineMidpointState.betweenMidpoints = false;
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +000096 start = nextMidpoint.offset();
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +000097 lineMidpointState.currentMidpoint++;
hyatt33f8d492002-11-12 21:44:52 +000098 if (start < end)
eric@webkit.org5bee2942011-04-08 02:12:31 +000099 return appendRunsForObject(runs, start, end, obj, resolver);
mitz@apple.com15035e62008-07-05 20:44:44 +0000100 } else {
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +0000101 if (!haveNextMidpoint || (obj != nextMidpoint.renderer())) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000102 runs.addRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000103 return;
104 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000105
hyatt78b85132004-03-29 20:07:45 +0000106 // An end midpoint has been encountered within our object. We
hyatt33f8d492002-11-12 21:44:52 +0000107 // need to go ahead and append a run with our endpoint.
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +0000108 if (static_cast<int>(nextMidpoint.offset() + 1) <= end) {
hyatt@apple.com1a5ffd82009-06-13 17:20:30 +0000109 lineMidpointState.betweenMidpoints = true;
110 lineMidpointState.currentMidpoint++;
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +0000111 if (nextMidpoint.offset() != UINT_MAX) { // UINT_MAX means stop at the object and don't include any of it.
112 if (static_cast<int>(nextMidpoint.offset() + 1) > start)
113 runs.addRun(createRun(start, nextMidpoint.offset() + 1, obj, resolver));
114 return appendRunsForObject(runs, nextMidpoint.offset() + 1, end, obj, resolver);
hyattc64f9fc2003-03-14 01:25:59 +0000115 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000116 } else
eric@webkit.org5bee2942011-04-08 02:12:31 +0000117 runs.addRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000118 }
119}
120
akling@apple.comb5f24642013-11-06 04:47:12 +0000121std::unique_ptr<RootInlineBox> RenderBlockFlow::createRootInlineBox()
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000122{
akling@apple.comb5f24642013-11-06 04:47:12 +0000123 return std::make_unique<RootInlineBox>(*this);
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000124}
125
126RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox()
127{
akling@apple.comb5f24642013-11-06 04:47:12 +0000128 auto newRootBox = createRootInlineBox();
129 RootInlineBox* rootBox = newRootBox.get();
130 m_lineBoxes.appendLineBox(std::move(newRootBox));
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000131
akling@apple.comee3c8df2013-11-06 08:09:44 +0000132 if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && firstRootBox() == rootBox) {
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000133 if (AXObjectCache* cache = document().existingAXObjectCache())
134 cache->recomputeIsIgnored(this);
135 }
136
137 return rootBox;
138}
139
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000140static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRootLineBox, bool isOnlyRun = false)
141{
142 if (isRootLineBox)
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000143 return toRenderBlockFlow(obj)->createAndAppendRootInlineBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000144
antti@apple.com9d8157e2013-09-17 15:13:37 +0000145 if (obj->isText())
146 return toRenderText(obj)->createInlineTextBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000147
akling@apple.comb5f24642013-11-06 04:47:12 +0000148 if (obj->isBox()) {
149 // FIXME: This is terrible. This branch returns an *owned* pointer!
150 return toRenderBox(obj)->createInlineBox().release();
151 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000152
antti@apple.com3014ac02013-09-18 14:33:55 +0000153 if (obj->isLineBreak()) {
akling@apple.comb5f24642013-11-06 04:47:12 +0000154 // FIXME: This is terrible. This branch returns an *owned* pointer!
akling@apple.comd3ec5ef2013-11-07 03:30:11 +0000155 auto inlineBox = toRenderLineBreak(obj)->createInlineBox().release();
antti@apple.com9d8157e2013-09-17 15:13:37 +0000156 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
157 // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.)
antti@apple.com3014ac02013-09-18 14:33:55 +0000158 inlineBox->setBehavesLikeText(isOnlyRun || obj->document().inNoQuirksMode() || obj->isLineBreakOpportunity());
antti@apple.com9d8157e2013-09-17 15:13:37 +0000159 return inlineBox;
160 }
161
eric@webkit.org49b9d952009-07-03 01:29:07 +0000162 return toRenderInline(obj)->createAndAppendInlineFlowBox();
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000163}
164
weinig@apple.com12840dc2013-10-22 23:59:08 +0000165static inline void dirtyLineBoxesForRenderer(RenderObject& renderer, bool fullLayout)
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000166{
weinig@apple.com12840dc2013-10-22 23:59:08 +0000167 if (renderer.isText()) {
168 RenderText& renderText = toRenderText(renderer);
esprehn@chromium.org7745ffb2013-02-19 21:51:19 +0000169 updateCounterIfNeeded(renderText);
weinig@apple.com12840dc2013-10-22 23:59:08 +0000170 renderText.dirtyLineBoxes(fullLayout);
171 } else if (renderer.isLineBreak())
172 toRenderLineBreak(renderer).dirtyLineBoxes(fullLayout);
antti@apple.com9d8157e2013-09-17 15:13:37 +0000173 else
weinig@apple.com12840dc2013-10-22 23:59:08 +0000174 toRenderInline(renderer).dirtyLineBoxes(fullLayout);
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000175}
176
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000177static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox)
178{
179 do {
180 if (parentBox->isConstructed() || parentBox->nextOnLine())
181 return true;
182 parentBox = parentBox->parent();
183 } while (parentBox);
184 return false;
185}
186
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000187InlineFlowBox* RenderBlockFlow::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox, bool startNewSegment)
hyattffe78712003-02-11 01:59:29 +0000188{
189 // See if we have an unconstructed line box for this object that is also
190 // the last item on the line.
hyatt1d5d87b2007-04-24 04:55:54 +0000191 unsigned lineDepth = 1;
hyatt1d5d87b2007-04-24 04:55:54 +0000192 InlineFlowBox* parentBox = 0;
193 InlineFlowBox* result = 0;
akling@apple.com827be9c2013-10-29 02:58:43 +0000194 bool hasDefaultLineBoxContain = style().lineBoxContain() == RenderStyle::initialLineBoxContain();
hyatt1d5d87b2007-04-24 04:55:54 +0000195 do {
inferno@chromium.org14b04142013-02-04 18:43:03 +0000196 ASSERT_WITH_SECURITY_IMPLICATION(obj->isRenderInline() || obj == this);
eric@webkit.org060caf62011-05-03 22:11:39 +0000197
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000198 RenderInline* inlineFlow = (obj != this) ? toRenderInline(obj) : 0;
199
hyatt1d5d87b2007-04-24 04:55:54 +0000200 // Get the last box we made for this render object.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000201 parentBox = inlineFlow ? inlineFlow->lastLineBox() : toRenderBlockFlow(obj)->lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000202
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000203 // If this box or its ancestor is constructed then it is from a previous line, and we need
204 // 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 +0000205 // something following it on the line, then we know we have to make a new box
206 // as well. In this situation our inline has actually been split in two on
207 // the same line (this can happen with very fancy language mixtures).
208 bool constructedNewBox = false;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000209 bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000210 bool mustCreateBoxesToRoot = startNewSegment && !(parentBox && parentBox->isRootInlineBox());
211 bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox) && !mustCreateBoxesToRoot;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000212 if (allowedToConstructNewBox && !canUseExistingParentBox) {
hyatt1d5d87b2007-04-24 04:55:54 +0000213 // We need to make a new box for this render object. Once
214 // made, we need to place it at the end of the current line.
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000215 InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this);
inferno@chromium.org14b04142013-02-04 18:43:03 +0000216 ASSERT_WITH_SECURITY_IMPLICATION(newBox->isInlineFlowBox());
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000217 parentBox = toInlineFlowBox(newBox);
antti@apple.comb0608f62013-09-28 18:30:16 +0000218 parentBox->setIsFirstLine(lineInfo.isFirstLine());
hyatt@apple.com2a5eb212011-03-22 23:21:54 +0000219 parentBox->setIsHorizontal(isHorizontalWritingMode());
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000220 if (!hasDefaultLineBoxContain)
221 parentBox->clearDescendantsHaveSameLineHeightAndBaseline();
hyatt1d5d87b2007-04-24 04:55:54 +0000222 constructedNewBox = true;
223 }
mitz@apple.come1364202008-02-28 01:06:41 +0000224
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000225 if (constructedNewBox || canUseExistingParentBox) {
226 if (!result)
227 result = parentBox;
hyatt1d5d87b2007-04-24 04:55:54 +0000228
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000229 // If we have hit the block itself, then |box| represents the root
230 // inline box for the line, and it doesn't have to be appended to any parent
231 // inline.
232 if (childBox)
233 parentBox->addToLine(childBox);
mitz@apple.come1364202008-02-28 01:06:41 +0000234
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000235 if (!constructedNewBox || obj == this)
236 break;
mitz@apple.come1364202008-02-28 01:06:41 +0000237
eric@webkit.org060caf62011-05-03 22:11:39 +0000238 childBox = parentBox;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000239 }
mitz@apple.come1364202008-02-28 01:06:41 +0000240
hyatt1d5d87b2007-04-24 04:55:54 +0000241 // If we've exceeded our line depth, then jump straight to the root and skip all the remaining
242 // intermediate inline flows.
243 obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent();
hyattffe78712003-02-11 01:59:29 +0000244
hyatt1d5d87b2007-04-24 04:55:54 +0000245 } while (true);
246
247 return result;
hyattffe78712003-02-11 01:59:29 +0000248}
249
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000250template <typename CharacterType>
251static inline bool endsWithASCIISpaces(const CharacterType* characters, unsigned pos, unsigned end)
252{
253 while (isASCIISpace(characters[pos])) {
254 pos++;
255 if (pos >= end)
256 return true;
257 }
258 return false;
259}
260
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000261static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns)
hyattffe78712003-02-11 01:59:29 +0000262{
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000263 BidiRun* run = bidiRuns.logicallyLastRun();
264 if (!run)
265 return true;
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000266 unsigned pos = run->stop();
akling@apple.com7506fda2013-11-07 10:12:36 +0000267 const RenderObject& r = run->renderer();
268 if (!r.isText())
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000269 return false;
akling@apple.com7506fda2013-11-07 10:12:36 +0000270 const RenderText& renderText = toRenderText(r);
271 unsigned length = renderText.textLength();
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000272 if (pos >= length)
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000273 return true;
274
akling@apple.com7506fda2013-11-07 10:12:36 +0000275 if (renderText.is8Bit())
276 return endsWithASCIISpaces(renderText.characters8(), pos, length);
277 return endsWithASCIISpaces(renderText.characters16(), pos, length);
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000278}
279
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000280RootInlineBox* RenderBlockFlow::constructLine(BidiRunList<BidiRun>& bidiRuns, const LineInfo& lineInfo)
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000281{
282 ASSERT(bidiRuns.firstRun());
hyattffe78712003-02-11 01:59:29 +0000283
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000284 bool rootHasSelectedChildren = false;
hyattffe78712003-02-11 01:59:29 +0000285 InlineFlowBox* parentBox = 0;
robert@webkit.org8cbab142011-12-30 20:58:29 +0000286 int runCount = bidiRuns.runCount() - lineInfo.runsFromLeadingWhitespace();
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000287 for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) {
hyattffe78712003-02-11 01:59:29 +0000288 // Create a box for our object.
robert@webkit.org8cbab142011-12-30 20:58:29 +0000289 bool isOnlyRun = (runCount == 1);
akling@apple.com7506fda2013-11-07 10:12:36 +0000290 if (runCount == 2 && !r->renderer().isListMarker())
291 isOnlyRun = (!style().isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->renderer().isListMarker();
mitz@apple.come1364202008-02-28 01:06:41 +0000292
robert@webkit.org56e5a9f2012-02-17 21:10:42 +0000293 if (lineInfo.isEmpty())
294 continue;
295
akling@apple.com7506fda2013-11-07 10:12:36 +0000296 InlineBox* box = createInlineBoxForRenderer(&r->renderer(), false, isOnlyRun);
297 r->setBox(*box);
hyattffe78712003-02-11 01:59:29 +0000298
akling@apple.com0b8172b72013-08-31 18:34:23 +0000299 if (!rootHasSelectedChildren && box->renderer().selectionState() != RenderObject::SelectionNone)
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000300 rootHasSelectedChildren = true;
301
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000302 // If we have no parent box yet, or if the run is not simply a sibling,
303 // then we need to construct inline boxes as necessary to properly enclose the
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000304 // run's inline box. Segments can only be siblings at the root level, as
305 // they are positioned separately.
betravis@adobe.comed90c982013-06-05 23:05:57 +0000306#if ENABLE(CSS_SHAPES)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000307 bool runStartsSegment = r->m_startsSegment;
308#else
309 bool runStartsSegment = false;
310#endif
akling@apple.com7506fda2013-11-07 10:12:36 +0000311 if (!parentBox || &parentBox->renderer() != r->renderer().parent() || runStartsSegment)
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000312 // Create new inline boxes all the way back to the appropriate insertion point.
akling@apple.com7506fda2013-11-07 10:12:36 +0000313 parentBox = createLineBoxes(r->renderer().parent(), lineInfo, box, runStartsSegment);
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000314 else {
315 // Append the inline box to this line.
316 parentBox->addToLine(box);
317 }
mitz@apple.com576e84e2008-04-24 19:09:48 +0000318
akling@apple.com7506fda2013-11-07 10:12:36 +0000319 bool visuallyOrdered = r->renderer().style().rtlOrdering() == VisualOrder;
xji@chromium.org6b0c0172011-02-14 19:21:12 +0000320 box->setBidiLevel(r->level());
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000321
322 if (box->isInlineTextBox()) {
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000323 InlineTextBox* text = toInlineTextBox(box);
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000324 text->setStart(r->m_start);
325 text->setLen(r->m_stop - r->m_start);
rniwa@webkit.org296fcae2012-03-29 09:48:42 +0000326 text->setDirOverride(r->dirOverride(visuallyOrdered));
mitz@apple.comb2107652010-06-21 16:54:52 +0000327 if (r->m_hasHyphen)
328 text->setHasHyphen(true);
hyatt0c3a9862004-02-23 21:26:26 +0000329 }
hyattffe78712003-02-11 01:59:29 +0000330 }
331
332 // We should have a root inline box. It should be unconstructed and
333 // be the last continuation of our line list.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000334 ASSERT(lastRootBox() && !lastRootBox()->isConstructed());
hyattffe78712003-02-11 01:59:29 +0000335
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000336 // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box
337 // from the bidi runs walk above has a selection state.
338 if (rootHasSelectedChildren)
akling@apple.comee3c8df2013-11-06 08:09:44 +0000339 lastRootBox()->root().setHasSelectedChildren(true);
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000340
hyattffe78712003-02-11 01:59:29 +0000341 // Set bits on our inline flow boxes that indicate which sides should
342 // paint borders/margins/padding. This knowledge will ultimately be used when
343 // we determine the horizontal positions and widths of all the inline boxes on
344 // the line.
akling@apple.com7506fda2013-11-07 10:12:36 +0000345 bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->renderer().isText() ? !reachedEndOfTextRenderer(bidiRuns) : true;
346 lastRootBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, &bidiRuns.logicallyLastRun()->renderer());
hyattffe78712003-02-11 01:59:29 +0000347
348 // Now mark the line boxes as being constructed.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000349 lastRootBox()->setConstructed();
hyattffe78712003-02-11 01:59:29 +0000350
351 // Return the last line.
hyatt0c3a9862004-02-23 21:26:26 +0000352 return lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000353}
354
mitz@apple.com390fa322011-02-24 23:07:06 +0000355ETextAlign RenderBlock::textAlignmentForLine(bool endsWithSoftBreak) const
356{
akling@apple.com827be9c2013-10-29 02:58:43 +0000357 ETextAlign alignment = style().textAlign();
mitz@apple.com390fa322011-02-24 23:07:06 +0000358 if (!endsWithSoftBreak && alignment == JUSTIFY)
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000359 alignment = TASTART;
mitz@apple.com390fa322011-02-24 23:07:06 +0000360
361 return alignment;
362}
363
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000364static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
365{
366 // The direction of the block should determine what happens with wide lines.
367 // In particular with RTL blocks, wide lines should still spill out to the left.
368 if (isLeftToRightDirection) {
369 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
andersca@apple.com86298632013-11-10 19:32:33 +0000370 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000371 return;
372 }
373
374 if (trailingSpaceRun)
akling@apple.com7506fda2013-11-07 10:12:36 +0000375 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000376 else if (totalLogicalWidth > availableLogicalWidth)
377 logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
378}
379
380static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
381{
382 // Wide lines spill out of the block based off direction.
383 // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
384 // side of the block.
385 if (isLeftToRightDirection) {
386 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000387 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
388 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000389 }
390 if (totalLogicalWidth < availableLogicalWidth)
391 logicalLeft += availableLogicalWidth - totalLogicalWidth;
392 return;
393 }
394
395 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
andersca@apple.com86298632013-11-10 19:32:33 +0000396 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
akling@apple.com7506fda2013-11-07 10:12:36 +0000397 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000398 } else
399 logicalLeft += availableLogicalWidth - totalLogicalWidth;
400}
401
402static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
403{
404 float trailingSpaceWidth = 0;
405 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000406 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
andersca@apple.com86298632013-11-10 19:32:33 +0000407 trailingSpaceWidth = std::min(trailingSpaceRun->box()->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2);
408 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000409 }
410 if (isLeftToRightDirection)
andersca@apple.com86298632013-11-10 19:32:33 +0000411 logicalLeft += std::max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000412 else
413 logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
414}
415
weinig@apple.com12840dc2013-10-22 23:59:08 +0000416void RenderBlockFlow::setMarginsForRubyRun(BidiRun* run, RenderRubyRun& renderer, RenderObject* previousObject, const LineInfo& lineInfo)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000417{
418 int startOverhang;
419 int endOverhang;
420 RenderObject* nextObject = 0;
421 for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000422 if (!runWithNextObject->renderer().isOutOfFlowPositioned() && !runWithNextObject->box()->isLineBreak()) {
423 nextObject = &runWithNextObject->renderer();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000424 break;
425 }
426 }
akling@apple.com827be9c2013-10-29 02:58:43 +0000427 renderer.getOverhang(lineInfo.isFirstLine(), renderer.style().isLeftToRightDirection() ? previousObject : nextObject, renderer.style().isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000428 setMarginStartForChild(renderer, -startOverhang);
429 setMarginEndForChild(renderer, -endOverhang);
430}
431
432static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText* renderer, float xPos, const LineInfo& lineInfo,
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000433 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000434{
435 HashSet<const SimpleFontData*> fallbackFonts;
436 GlyphOverflow glyphOverflow;
antti@apple.comb0608f62013-09-28 18:30:16 +0000437
438 const Font& font = lineStyle(*renderer->parent(), lineInfo).font();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000439 // Always compute glyph overflow if the block's line-box-contain value is "glyphs".
440 if (lineBox->fitsToGlyphs()) {
441 // If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization
442 // will keep us from computing glyph bounds in nearly all cases.
443 bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading();
akling@apple.com7506fda2013-11-07 10:12:36 +0000444 int baselineShift = lineBox->verticalPositionForBox(run->box(), verticalPositionCache);
enrica@apple.com885c84d2012-10-10 05:48:51 +0000445 int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0;
446 int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0;
447 int boxAscent = font.fontMetrics().ascent() - baselineShift;
448 int boxDescent = font.fontMetrics().descent() + baselineShift;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000449 if (boxAscent > rootDescent || boxDescent > rootAscent)
450 glyphOverflow.computeBounds = true;
451 }
452
leviw@chromium.orgd32486e2012-03-16 10:52:56 +0000453 LayoutUnit hyphenWidth = 0;
akling@apple.com7506fda2013-11-07 10:12:36 +0000454 if (toInlineTextBox(run->box())->hasHyphen())
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000455 hyphenWidth = measureHyphenWidth(renderer, font, &fallbackFonts);
antti@apple.comb0608f62013-09-28 18:30:16 +0000456
enrica@apple.com885c84d2012-10-10 05:48:51 +0000457 float measuredWidth = 0;
458
enrica@apple.com885c84d2012-10-10 05:48:51 +0000459 bool kerningIsEnabled = font.typesettingFeatures() & Kerning;
leviw@chromium.orgd70f4cc2013-03-28 21:03:44 +0000460 bool canUseSimpleFontCodePath = renderer->canUseSimpleFontCodePath();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000461
462 // Since we don't cache glyph overflows, we need to re-measure the run if
463 // the style is linebox-contain: glyph.
464
leviw@chromium.orgd70f4cc2013-03-28 21:03:44 +0000465 if (!lineBox->fitsToGlyphs() && canUseSimpleFontCodePath) {
enrica@apple.com885c84d2012-10-10 05:48:51 +0000466 int lastEndOffset = run->m_start;
467 for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOffset < run->m_stop; ++i) {
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000468 WordMeasurement& wordMeasurement = wordMeasurements[i];
469 if (wordMeasurement.width <= 0 || wordMeasurement.startOffset == wordMeasurement.endOffset)
enrica@apple.com885c84d2012-10-10 05:48:51 +0000470 continue;
471 if (wordMeasurement.renderer != renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop)
472 continue;
473
474 lastEndOffset = wordMeasurement.endOffset;
475 if (kerningIsEnabled && lastEndOffset == run->m_stop) {
dino@apple.com7c50e7c2013-03-18 18:01:05 +0000476 int wordLength = lastEndOffset - wordMeasurement.startOffset;
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000477 GlyphOverflow overflow;
478 measuredWidth += renderer->width(wordMeasurement.startOffset, wordLength, xPos + measuredWidth, lineInfo.isFirstLine(),
479 &wordMeasurement.fallbackFonts, &overflow);
dino@apple.comd0b89252013-05-10 18:20:28 +0000480 UChar c = renderer->characterAt(wordMeasurement.startOffset);
481 if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t'))
akling@apple.com827be9c2013-10-29 02:58:43 +0000482 measuredWidth += renderer->style().wordSpacing();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000483 } else
484 measuredWidth += wordMeasurement.width;
485 if (!wordMeasurement.fallbackFonts.isEmpty()) {
486 HashSet<const SimpleFontData*>::const_iterator end = wordMeasurement.fallbackFonts.end();
487 for (HashSet<const SimpleFontData*>::const_iterator it = wordMeasurement.fallbackFonts.begin(); it != end; ++it)
488 fallbackFonts.add(*it);
489 }
490 }
491 if (measuredWidth && lastEndOffset != run->m_stop) {
492 // If we don't have enough cached data, we'll measure the run again.
493 measuredWidth = 0;
494 fallbackFonts.clear();
495 }
496 }
enrica@apple.com885c84d2012-10-10 05:48:51 +0000497
498 if (!measuredWidth)
499 measuredWidth = renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow);
500
akling@apple.com7506fda2013-11-07 10:12:36 +0000501 run->box()->setLogicalWidth(measuredWidth + hyphenWidth);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000502 if (!fallbackFonts.isEmpty()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000503 ASSERT(run->box()->behavesLikeText());
andersca@apple.com86298632013-11-10 19:32:33 +0000504 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->box()), std::make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000505 ASSERT(it->value.first.isEmpty());
506 copyToVector(fallbackFonts, it->value.first);
akling@apple.com7506fda2013-11-07 10:12:36 +0000507 run->box()->parent()->clearDescendantsHaveSameLineHeightAndBaseline();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000508 }
509 if ((glyphOverflow.top || glyphOverflow.bottom || glyphOverflow.left || glyphOverflow.right)) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000510 ASSERT(run->box()->behavesLikeText());
andersca@apple.com86298632013-11-10 19:32:33 +0000511 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->box()), std::make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000512 it->value.second = glyphOverflow;
akling@apple.com7506fda2013-11-07 10:12:36 +0000513 run->box()->clearKnownToHaveNoOverflow();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000514 }
515}
516
517static inline void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth)
518{
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000519 if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth)
520 return;
521
522 size_t i = 0;
523 for (BidiRun* r = firstRun; r; r = r->next()) {
betravis@adobe.comed90c982013-06-05 23:05:57 +0000524#if ENABLE(CSS_SHAPES)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000525 // This method is called once per segment, do not move past the current segment.
526 if (r->m_startsSegment)
527 break;
528#endif
akling@apple.com7506fda2013-11-07 10:12:36 +0000529 if (!r->box() || r == trailingSpaceRun)
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000530 continue;
531
akling@apple.com7506fda2013-11-07 10:12:36 +0000532 if (r->renderer().isText()) {
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000533 unsigned opportunitiesInRun = expansionOpportunities[i++];
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000534
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000535 ASSERT(opportunitiesInRun <= expansionOpportunityCount);
536
537 // Only justify text if whitespace is collapsed.
akling@apple.com7506fda2013-11-07 10:12:36 +0000538 if (r->renderer().style().collapseWhiteSpace()) {
539 InlineTextBox* textBox = toInlineTextBox(r->box());
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000540 int expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
541 textBox->setExpansion(expansion);
542 totalLogicalWidth += expansion;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000543 }
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000544 expansionOpportunityCount -= opportunitiesInRun;
545 if (!expansionOpportunityCount)
546 break;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000547 }
548 }
549}
550
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000551void RenderBlock::updateLogicalWidthForAlignment(const ETextAlign& textAlign, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount)
552{
553 // Armed with the total width of the line (without justification),
554 // we now examine our text-align property in order to determine where to position the
555 // objects horizontally. The total width of the line can be increased if we end up
556 // justifying text.
557 switch (textAlign) {
558 case LEFT:
559 case WEBKIT_LEFT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000560 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000561 break;
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000562 case RIGHT:
563 case WEBKIT_RIGHT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000564 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000565 break;
566 case CENTER:
567 case WEBKIT_CENTER:
akling@apple.com827be9c2013-10-29 02:58:43 +0000568 updateLogicalWidthForCenterAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000569 break;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000570 case JUSTIFY:
571 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
572 if (expansionOpportunityCount) {
573 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000574 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
575 trailingSpaceRun->box()->setLogicalWidth(0);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000576 }
577 break;
578 }
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000579 // Fall through
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000580 case TASTART:
akling@apple.com827be9c2013-10-29 02:58:43 +0000581 if (style().isLeftToRightDirection())
582 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000583 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000584 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000585 break;
586 case TAEND:
akling@apple.com827be9c2013-10-29 02:58:43 +0000587 if (style().isLeftToRightDirection())
588 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000589 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000590 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000591 break;
592 }
593}
594
weinig@apple.come9621c32014-01-04 20:53:51 +0000595static void updateLogicalInlinePositions(RenderBlockFlow& block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight)
commit-queue@webkit.orgab781b02013-04-03 01:32:24 +0000596{
weinig@apple.come9621c32014-01-04 20:53:51 +0000597 LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight);
598 lineLogicalLeft = block.pixelSnappedLogicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
599 lineLogicalRight = block.pixelSnappedLogicalRightOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
robert@webkit.org0903cf52012-12-11 18:14:16 +0000600 availableLogicalWidth = lineLogicalRight - lineLogicalLeft;
601}
602
weinig@apple.come9621c32014-01-04 20:53:51 +0000603void RenderBlockFlow::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, const LineInfo& lineInfo, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
hyattffe78712003-02-11 01:59:29 +0000604{
mitz@apple.com390fa322011-02-24 23:07:06 +0000605 ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
robert@webkit.org4f76df92012-07-03 17:41:35 +0000606
robert@webkit.org328ecd02012-08-09 21:12:44 +0000607 // CSS 2.1: "'Text-indent' only affects a line if it is the first formatted line of an element. For example, the first line of an anonymous block
608 // box is only affected if it is the first child of its parent element."
commit-queue@webkit.orgab781b02013-04-03 01:32:24 +0000609 // CSS3 "text-indent", "-webkit-each-line" affects the first line of the block container as well as each line after a forced line break,
610 // but does not affect lines after a soft wrap break.
611 bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this);
612 bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox()->endsWithBreak();
akling@apple.com827be9c2013-10-29 02:58:43 +0000613 IndentTextOrNot shouldIndentText = requiresIndent(isFirstLine, isAfterHardLineBreak, style());
robert@webkit.org0903cf52012-12-11 18:14:16 +0000614 float lineLogicalLeft;
615 float lineLogicalRight;
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000616 float availableLogicalWidth;
weinig@apple.come9621c32014-01-04 20:53:51 +0000617 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000618 bool needsWordSpacing;
betravis@adobe.comed90c982013-06-05 23:05:57 +0000619#if ENABLE(CSS_SHAPES)
betravis@adobe.comcf7cba62013-06-10 21:23:45 +0000620 ShapeInsideInfo* shapeInsideInfo = layoutShapeInsideInfo();
621 if (shapeInsideInfo && shapeInsideInfo->hasSegments()) {
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000622 BidiRun* segmentStart = firstRun;
betravis@adobe.comcf7cba62013-06-10 21:23:45 +0000623 const SegmentList& segments = shapeInsideInfo->segments();
andersca@apple.com86298632013-11-10 19:32:33 +0000624 float logicalLeft = std::max<float>(roundToInt(segments[0].logicalLeft), lineLogicalLeft);
625 float logicalRight = std::min<float>(floorToInt(segments[0].logicalRight), lineLogicalRight);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000626 float startLogicalLeft = logicalLeft;
627 float endLogicalRight = logicalLeft;
628 float minLogicalLeft = logicalLeft;
629 float maxLogicalRight = logicalLeft;
630 lineBox->beginPlacingBoxRangesInInlineDirection(logicalLeft);
631 for (size_t i = 0; i < segments.size(); i++) {
632 if (i) {
andersca@apple.com86298632013-11-10 19:32:33 +0000633 logicalLeft = std::max<float>(roundToInt(segments[i].logicalLeft), lineLogicalLeft);
634 logicalRight = std::min<float>(floorToInt(segments[i].logicalRight), lineLogicalRight);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000635 }
636 availableLogicalWidth = logicalRight - logicalLeft;
637 BidiRun* newSegmentStart = computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, logicalLeft, availableLogicalWidth, segmentStart, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
638 needsWordSpacing = false;
akling@apple.com7506fda2013-11-07 10:12:36 +0000639 endLogicalRight = lineBox->placeBoxRangeInInlineDirection(segmentStart->box(), newSegmentStart ? newSegmentStart->box() : 0, logicalLeft, minLogicalLeft, maxLogicalRight, needsWordSpacing, textBoxDataMap);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000640 if (!newSegmentStart || !newSegmentStart->next())
641 break;
642 ASSERT(newSegmentStart->m_startsSegment);
643 // Discard the empty segment start marker bidi runs
644 segmentStart = newSegmentStart->next();
645 }
646 lineBox->endPlacingBoxRangesInInlineDirection(startLogicalLeft, endLogicalRight, minLogicalLeft, maxLogicalRight);
647 return;
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +0000648 }
649#endif
robert@webkit.org0903cf52012-12-11 18:14:16 +0000650
akling@apple.com7506fda2013-11-07 10:12:36 +0000651 if (firstRun && firstRun->renderer().isReplaced()) {
652 RenderBox& renderBox = toRenderBox(firstRun->renderer());
weinig@apple.come9621c32014-01-04 20:53:51 +0000653 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight());
robert@webkit.org0903cf52012-12-11 18:14:16 +0000654 }
655
656 computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000657 // The widths of all runs are now known. We can now place every inline box (and
658 // compute accurate widths for the inline flow boxes).
659 needsWordSpacing = false;
660 lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing, textBoxDataMap);
661}
mitz@apple.com390fa322011-02-24 23:07:06 +0000662
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000663BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBox* lineBox, const LineInfo& lineInfo, ETextAlign textAlign, float& logicalLeft,
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000664 float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache,
665 WordMeasurements& wordMeasurements)
666{
darin06dcb9c2005-08-15 04:31:09 +0000667 bool needsWordSpacing = false;
mitz@apple.com390fa322011-02-24 23:07:06 +0000668 float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();
mitz@apple.com86470c82011-01-27 01:39:27 +0000669 unsigned expansionOpportunityCount = 0;
670 bool isAfterExpansion = true;
671 Vector<unsigned, 16> expansionOpportunities;
mitz@apple.comddb59872011-04-05 05:21:16 +0000672 RenderObject* previousObject = 0;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000673
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000674 BidiRun* r = firstRun;
675 for (; r; r = r->next()) {
betravis@adobe.comed90c982013-06-05 23:05:57 +0000676#if ENABLE(CSS_SHAPES)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000677 // Once we have reached the start of the next segment, we have finished
678 // computing the positions for this segment's contents.
679 if (r->m_startsSegment)
680 break;
681#endif
akling@apple.com7506fda2013-11-07 10:12:36 +0000682 if (!r->box() || r->renderer().isOutOfFlowPositioned() || r->box()->isLineBreak())
hyatt98ee7e42003-05-14 01:39:15 +0000683 continue; // Positioned objects are only participating to figure out their
684 // correct static x position. They have no effect on the width.
hyatt0c05e102006-04-14 08:15:00 +0000685 // Similarly, line break boxes have no effect on the width.
akling@apple.com7506fda2013-11-07 10:12:36 +0000686 if (r->renderer().isText()) {
687 RenderText& rt = toRenderText(r->renderer());
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000688 if (textAlign == JUSTIFY && r != trailingSpaceRun) {
mitz@apple.com80968932011-03-26 00:46:26 +0000689 if (!isAfterExpansion)
akling@apple.com7506fda2013-11-07 10:12:36 +0000690 toInlineTextBox(r->box())->setCanHaveLeadingExpansion(true);
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000691 unsigned opportunitiesInRun;
akling@apple.com7506fda2013-11-07 10:12:36 +0000692 if (rt.is8Bit())
693 opportunitiesInRun = Font::expansionOpportunityCount(rt.characters8() + r->m_start, r->m_stop - r->m_start, r->box()->direction(), isAfterExpansion);
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000694 else
akling@apple.com7506fda2013-11-07 10:12:36 +0000695 opportunitiesInRun = Font::expansionOpportunityCount(rt.characters16() + r->m_start, r->m_stop - r->m_start, r->box()->direction(), isAfterExpansion);
mitz@apple.com86470c82011-01-27 01:39:27 +0000696 expansionOpportunities.append(opportunitiesInRun);
697 expansionOpportunityCount += opportunitiesInRun;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000698 }
699
akling@apple.com7506fda2013-11-07 10:12:36 +0000700 if (int length = rt.textLength()) {
701 if (!r->m_start && needsWordSpacing && isSpaceOrNewline(rt.characterAt(r->m_start)))
702 totalLogicalWidth += lineStyle(*rt.parent(), lineInfo).font().wordSpacing();
703 needsWordSpacing = !isSpaceOrNewline(rt.characterAt(r->m_stop - 1)) && r->m_stop == length;
darin06dcb9c2005-08-15 04:31:09 +0000704 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000705
akling@apple.com7506fda2013-11-07 10:12:36 +0000706 setLogicalWidthForTextRun(lineBox, r, &rt, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
mitz@apple.com86470c82011-01-27 01:39:27 +0000707 } else {
708 isAfterExpansion = false;
akling@apple.com7506fda2013-11-07 10:12:36 +0000709 if (!r->renderer().isRenderInline()) {
710 RenderBox& renderBox = toRenderBox(r->renderer());
weinig@apple.com12840dc2013-10-22 23:59:08 +0000711 if (renderBox.isRubyRun())
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000712 setMarginsForRubyRun(r, toRenderRubyRun(renderBox), previousObject, lineInfo);
akling@apple.com7506fda2013-11-07 10:12:36 +0000713 r->box()->setLogicalWidth(logicalWidthForChild(renderBox));
mitz@apple.com86470c82011-01-27 01:39:27 +0000714 totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox);
715 }
hyattffe78712003-02-11 01:59:29 +0000716 }
hyatt4b381692003-03-10 21:11:59 +0000717
akling@apple.com7506fda2013-11-07 10:12:36 +0000718 totalLogicalWidth += r->box()->logicalWidth();
719 previousObject = &r->renderer();
hyattffe78712003-02-11 01:59:29 +0000720 }
721
mitz@apple.com86470c82011-01-27 01:39:27 +0000722 if (isAfterExpansion && !expansionOpportunities.isEmpty()) {
723 expansionOpportunities.last()--;
724 expansionOpportunityCount--;
725 }
726
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000727 updateLogicalWidthForAlignment(textAlign, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount);
hyattffe78712003-02-11 01:59:29 +0000728
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000729 computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth);
mitz@apple.come1364202008-02-28 01:06:41 +0000730
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000731 return r;
hyattffe78712003-02-11 01:59:29 +0000732}
733
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000734void RenderBlockFlow::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000735 VerticalPositionCache& verticalPositionCache)
hyattffe78712003-02-11 01:59:29 +0000736{
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000737 setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache));
hyattffe78712003-02-11 01:59:29 +0000738
739 // Now make sure we place replaced render objects correctly.
mitz@apple.com887f3592008-02-25 22:03:08 +0000740 for (BidiRun* r = firstRun; r; r = r->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000741 ASSERT(r->box());
742 if (!r->box())
eseidel789896f2005-11-27 22:52:09 +0000743 continue; // Skip runs with no line boxes.
hyatt0c3a9862004-02-23 21:26:26 +0000744
akling@apple.com27e7d142013-11-07 12:04:02 +0000745 InlineBox& box = *r->box();
746
hyatt98ee7e42003-05-14 01:39:15 +0000747 // Align positioned boxes with the top of the line box. This is
748 // a reasonable approximation of an appropriate y position.
akling@apple.com7506fda2013-11-07 10:12:36 +0000749 if (r->renderer().isOutOfFlowPositioned())
akling@apple.com27e7d142013-11-07 12:04:02 +0000750 box.setLogicalTop(logicalHeight());
hyatt98ee7e42003-05-14 01:39:15 +0000751
752 // Position is used to properly position both replaced elements and
753 // to update the static normal flow x/y of positioned elements.
akling@apple.com7506fda2013-11-07 10:12:36 +0000754 if (r->renderer().isText())
akling@apple.com27e7d142013-11-07 12:04:02 +0000755 toRenderText(r->renderer()).positionLineBox(toInlineTextBox(box));
akling@apple.com7506fda2013-11-07 10:12:36 +0000756 else if (r->renderer().isBox())
akling@apple.com27e7d142013-11-07 12:04:02 +0000757 toRenderBox(r->renderer()).positionLineBox(toInlineElementBox(box));
akling@apple.com7506fda2013-11-07 10:12:36 +0000758 else if (r->renderer().isLineBreak())
akling@apple.com27e7d142013-11-07 12:04:02 +0000759 toRenderLineBreak(r->renderer()).replaceInlineBoxWrapper(toInlineElementBox(box));
hyatt98ee7e42003-05-14 01:39:15 +0000760 }
mitz@apple.coma927be62008-03-21 05:30:19 +0000761 // Positioned objects and zero-length text nodes destroy their boxes in
762 // position(), which unnecessarily dirties the line.
763 lineBox->markDirty(false);
hyattffe78712003-02-11 01:59:29 +0000764}
kociendabb0c24b2001-08-24 14:24:40 +0000765
akling@apple.com7506fda2013-11-07 10:12:36 +0000766static inline bool isCollapsibleSpace(UChar character, const RenderText& renderer)
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000767{
768 if (character == ' ' || character == '\t' || character == softHyphen)
769 return true;
770 if (character == '\n')
akling@apple.com7506fda2013-11-07 10:12:36 +0000771 return !renderer.style().preserveNewline();
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000772 if (character == noBreakSpace)
akling@apple.com7506fda2013-11-07 10:12:36 +0000773 return renderer.style().nbspMode() == SPACE;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000774 return false;
775}
776
msaboff@apple.com142fc202012-10-18 18:03:14 +0000777template <typename CharacterType>
akling@apple.com7506fda2013-11-07 10:12:36 +0000778static inline int findFirstTrailingSpace(const RenderText& lastText, const CharacterType* characters, int start, int stop)
msaboff@apple.com142fc202012-10-18 18:03:14 +0000779{
780 int firstSpace = stop;
781 while (firstSpace > start) {
782 UChar current = characters[firstSpace - 1];
783 if (!isCollapsibleSpace(current, lastText))
784 break;
785 firstSpace--;
786 }
787
788 return firstSpace;
789}
790
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000791inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext)
eric@webkit.org0894bb82011-04-03 08:29:40 +0000792{
eric@webkit.org5bee2942011-04-08 02:12:31 +0000793 if (!bidiRuns.runCount()
akling@apple.com7506fda2013-11-07 10:12:36 +0000794 || !bidiRuns.logicallyLastRun()->renderer().style().breakOnlyAfterWhiteSpace()
795 || !bidiRuns.logicallyLastRun()->renderer().style().autoWrap())
eric@webkit.org0894bb82011-04-03 08:29:40 +0000796 return 0;
797
eric@webkit.org5bee2942011-04-08 02:12:31 +0000798 BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun();
akling@apple.com7506fda2013-11-07 10:12:36 +0000799 const RenderObject& lastObject = trailingSpaceRun->renderer();
800 if (!lastObject.isText())
eric@webkit.org0894bb82011-04-03 08:29:40 +0000801 return 0;
802
akling@apple.com7506fda2013-11-07 10:12:36 +0000803 const RenderText& lastText = toRenderText(lastObject);
msaboff@apple.com142fc202012-10-18 18:03:14 +0000804 int firstSpace;
akling@apple.com7506fda2013-11-07 10:12:36 +0000805 if (lastText.is8Bit())
806 firstSpace = findFirstTrailingSpace(lastText, lastText.characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +0000807 else
akling@apple.com7506fda2013-11-07 10:12:36 +0000808 firstSpace = findFirstTrailingSpace(lastText, lastText.characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +0000809
eric@webkit.org0894bb82011-04-03 08:29:40 +0000810 if (firstSpace == trailingSpaceRun->stop())
811 return 0;
812
akling@apple.com827be9c2013-10-29 02:58:43 +0000813 TextDirection direction = style().direction();
eric@webkit.org5bee2942011-04-08 02:12:31 +0000814 bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun());
eric@webkit.org0894bb82011-04-03 08:29:40 +0000815 if (firstSpace != trailingSpaceRun->start()) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000816 BidiContext* baseContext = currentContext;
eric@webkit.org0894bb82011-04-03 08:29:40 +0000817 while (BidiContext* parent = baseContext->parent())
818 baseContext = parent;
819
akling@apple.com7506fda2013-11-07 10:12:36 +0000820 BidiRun* newTrailingRun = new BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->renderer(), baseContext, U_OTHER_NEUTRAL);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000821 trailingSpaceRun->m_stop = firstSpace;
822 if (direction == LTR)
eric@webkit.org5bee2942011-04-08 02:12:31 +0000823 bidiRuns.addRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000824 else
eric@webkit.org5bee2942011-04-08 02:12:31 +0000825 bidiRuns.prependRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000826 trailingSpaceRun = newTrailingRun;
827 return trailingSpaceRun;
828 }
829 if (!shouldReorder)
830 return trailingSpaceRun;
831
832 if (direction == LTR) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000833 bidiRuns.moveRunToEnd(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000834 trailingSpaceRun->m_level = 0;
835 } else {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000836 bidiRuns.moveRunToBeginning(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000837 trailingSpaceRun->m_level = 1;
838 }
839 return trailingSpaceRun;
840}
841
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000842void RenderBlockFlow::appendFloatingObjectToLastLine(FloatingObject* floatingObject)
mitz@apple.comd17e8c02011-04-16 21:59:36 +0000843{
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +0000844 ASSERT(!floatingObject->originatingLine());
845 floatingObject->setOriginatingLine(lastRootBox());
weinig@apple.com12840dc2013-10-22 23:59:08 +0000846 lastRootBox()->appendFloat(floatingObject->renderer());
mitz@apple.comd17e8c02011-04-16 21:59:36 +0000847}
848
eric@webkit.orga26de042011-09-08 18:46:01 +0000849// FIXME: BidiResolver should have this logic.
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000850static inline void constructBidiRunsForSegment(InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfRuns, VisualDirectionOverride override, bool previousLineBrokeCleanly)
eric@webkit.orga26de042011-09-08 18:46:01 +0000851{
852 // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead
853 // of the resolver owning the runs.
854 ASSERT(&topResolver.runs() == &bidiRuns);
betravis@adobe.com9e5e8242013-04-19 23:28:26 +0000855 ASSERT(topResolver.position() != endOfRuns);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000856 RenderObject* currentRoot = topResolver.position().root();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000857 topResolver.createBidiRunsForLine(endOfRuns, override, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +0000858
859 while (!topResolver.isolatedRuns().isEmpty()) {
860 // It does not matter which order we resolve the runs as long as we resolve them all.
861 BidiRun* isolatedRun = topResolver.isolatedRuns().last();
862 topResolver.isolatedRuns().removeLast();
863
akling@apple.com7506fda2013-11-07 10:12:36 +0000864 RenderObject& startObj = isolatedRun->renderer();
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000865
eric@webkit.orga26de042011-09-08 18:46:01 +0000866 // Only inlines make sense with unicode-bidi: isolate (blocks are already isolated).
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000867 // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the
868 // tree to see which parent inline is the isolate. We could change enterIsolate
869 // to take a RenderObject and do this logic there, but that would be a layering
870 // violation for BidiResolver (which knows nothing about RenderObject).
akling@apple.com7506fda2013-11-07 10:12:36 +0000871 RenderInline* isolatedInline = toRenderInline(containingIsolate(&startObj, currentRoot));
eric@webkit.orga26de042011-09-08 18:46:01 +0000872 InlineBidiResolver isolatedResolver;
akling@apple.com827be9c2013-10-29 02:58:43 +0000873 EUnicodeBidi unicodeBidi = isolatedInline->style().unicodeBidi();
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000874 TextDirection direction;
875 if (unicodeBidi == Plaintext)
akling@apple.com7506fda2013-11-07 10:12:36 +0000876 determineDirectionality(direction, InlineIterator(isolatedInline, &isolatedRun->renderer(), 0));
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000877 else {
rniwa@webkit.org4d4bd332012-08-20 21:34:11 +0000878 ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride);
akling@apple.com827be9c2013-10-29 02:58:43 +0000879 direction = isolatedInline->style().direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000880 }
zoltan@webkit.orgd1a97402013-12-08 05:53:33 +0000881 isolatedResolver.setStatus(BidiStatus(direction, isOverride(unicodeBidi)));
eric@webkit.orga26de042011-09-08 18:46:01 +0000882
883 // FIXME: The fact that we have to construct an Iterator here
884 // currently prevents this code from moving into BidiResolver.
weinig@apple.com12840dc2013-10-22 23:59:08 +0000885 if (!bidiFirstSkippingEmptyInlines(*isolatedInline, &isolatedResolver))
rniwa@webkit.org2343fab2011-11-25 20:21:06 +0000886 continue;
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000887
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000888 // The starting position is the beginning of the first run within the isolate that was identified
889 // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the
890 // first run within the isolate.
akling@apple.com7506fda2013-11-07 10:12:36 +0000891 InlineIterator iter = InlineIterator(isolatedInline, &startObj, isolatedRun->m_start);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000892 isolatedResolver.setPositionIgnoringNestedIsolates(iter);
eric@webkit.orga26de042011-09-08 18:46:01 +0000893
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000894 // We stop at the next end of line; we may re-enter this isolate in the next call to constructBidiRuns().
eric@webkit.orga26de042011-09-08 18:46:01 +0000895 // FIXME: What should end and previousLineBrokeCleanly be?
896 // rniwa says previousLineBrokeCleanly is just a WinIE hack and could always be false here?
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000897 isolatedResolver.createBidiRunsForLine(endOfRuns, NoVisualOverride, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +0000898 // Note that we do not delete the runs from the resolver.
rniwa@webkit.orgd0ad8882012-05-23 07:37:07 +0000899 // We're not guaranteed to get any BidiRuns in the previous step. If we don't, we allow the placeholder
leviw@chromium.orgf0d6f362012-05-23 04:00:47 +0000900 // itself to be turned into an InlineBox. We can't remove it here without potentially losing track of
901 // the logically last run.
902 if (isolatedResolver.runs().runCount())
903 bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs());
eric@webkit.orga26de042011-09-08 18:46:01 +0000904
905 // If we encountered any nested isolate runs, just move them
906 // to the top resolver's list for later processing.
907 if (!isolatedResolver.isolatedRuns().isEmpty()) {
andersca@apple.com92012992013-05-05 19:03:49 +0000908 topResolver.isolatedRuns().appendVector(isolatedResolver.isolatedRuns());
eric@webkit.orga26de042011-09-08 18:46:01 +0000909 isolatedResolver.isolatedRuns().clear();
commit-queue@webkit.org1968a432013-09-11 19:23:58 +0000910 currentRoot = isolatedInline;
eric@webkit.orga26de042011-09-08 18:46:01 +0000911 }
912 }
913}
914
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000915static inline void constructBidiRunsForLine(const RenderBlockFlow* block, InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfLine, VisualDirectionOverride override, bool previousLineBrokeCleanly)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000916{
betravis@adobe.comed90c982013-06-05 23:05:57 +0000917#if !ENABLE(CSS_SHAPES)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000918 UNUSED_PARAM(block);
919 constructBidiRunsForSegment(topResolver, bidiRuns, endOfLine, override, previousLineBrokeCleanly);
920#else
betravis@adobe.comcf7cba62013-06-10 21:23:45 +0000921 ShapeInsideInfo* shapeInsideInfo = block->layoutShapeInsideInfo();
922 if (!shapeInsideInfo || !shapeInsideInfo->hasSegments()) {
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000923 constructBidiRunsForSegment(topResolver, bidiRuns, endOfLine, override, previousLineBrokeCleanly);
924 return;
925 }
926
betravis@adobe.comcf7cba62013-06-10 21:23:45 +0000927 const SegmentRangeList& segmentRanges = shapeInsideInfo->segmentRanges();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000928 ASSERT(segmentRanges.size());
929
930 for (size_t i = 0; i < segmentRanges.size(); i++) {
betravis@adobe.com28fba072013-03-12 23:27:35 +0000931 LineSegmentIterator iterator = segmentRanges[i].start;
932 InlineIterator segmentStart(iterator.root, iterator.object, iterator.offset);
933 iterator = segmentRanges[i].end;
934 InlineIterator segmentEnd(iterator.root, iterator.object, iterator.offset);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000935 if (i) {
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +0000936 ASSERT(segmentStart.renderer());
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +0000937 BidiRun* segmentMarker = createRun(segmentStart.offset(), segmentStart.offset(), segmentStart.renderer(), topResolver);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000938 segmentMarker->m_startsSegment = true;
939 bidiRuns.addRun(segmentMarker);
940 // Do not collapse midpoints between segments
941 topResolver.midpointState().betweenMidpoints = false;
942 }
betravis@adobe.com9e5e8242013-04-19 23:28:26 +0000943 if (segmentStart == segmentEnd)
944 continue;
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000945 topResolver.setPosition(segmentStart, numberOfIsolateAncestors(segmentStart));
946 constructBidiRunsForSegment(topResolver, bidiRuns, segmentEnd, override, previousLineBrokeCleanly);
947 }
948#endif
949}
950
eric@webkit.org45e33a52011-05-04 11:51:09 +0000951// This function constructs line boxes for all of the text runs in the resolver and computes their position.
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000952RootInlineBox* RenderBlockFlow::createLineBoxesFromBidiRuns(BidiRunList<BidiRun>& bidiRuns, const InlineIterator& end, LineInfo& lineInfo, VerticalPositionCache& verticalPositionCache, BidiRun* trailingSpaceRun, WordMeasurements& wordMeasurements)
eric@webkit.org45e33a52011-05-04 11:51:09 +0000953{
954 if (!bidiRuns.runCount())
955 return 0;
956
957 // FIXME: Why is this only done when we had runs?
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +0000958 lineInfo.setLastLine(!end.renderer());
eric@webkit.org45e33a52011-05-04 11:51:09 +0000959
960 RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo);
961 if (!lineBox)
962 return 0;
963
964 lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly());
965
966#if ENABLE(SVG)
967 bool isSVGRootInlineBox = lineBox->isSVGRootInlineBox();
968#else
969 bool isSVGRootInlineBox = false;
970#endif
971
972 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
973
974 // Now we position all of our text runs horizontally.
975 if (!isSVGRootInlineBox)
enrica@apple.com885c84d2012-10-10 05:48:51 +0000976 computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache, wordMeasurements);
eric@webkit.org45e33a52011-05-04 11:51:09 +0000977
978 // Now position our text runs vertically.
979 computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache);
980
981#if ENABLE(SVG)
982 // SVG text layout code computes vertical & horizontal positions on its own.
983 // Note that we still need to execute computeVerticalPositionsForLine() as
984 // it calls InlineTextBox::positionLineBox(), which tracks whether the box
985 // contains reversed text or not. If we wouldn't do that editing and thus
986 // text selection in RTL boxes would not work as expected.
987 if (isSVGRootInlineBox) {
akling@apple.com670fea12013-10-12 18:16:42 +0000988 ASSERT_WITH_SECURITY_IMPLICATION(isSVGText());
akling@apple.com0c7d7fe2013-11-07 10:08:04 +0000989 toSVGRootInlineBox(lineBox)->computePerCharacterLayoutInformation();
eric@webkit.org45e33a52011-05-04 11:51:09 +0000990 }
991#endif
992
993 // Compute our overflow now.
994 lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap);
995
996#if PLATFORM(MAC)
997 // Highlight acts as an overflow inflation.
akling@apple.com827be9c2013-10-29 02:58:43 +0000998 if (style().highlight() != nullAtom)
eric@webkit.org45e33a52011-05-04 11:51:09 +0000999 lineBox->addHighlightOverflow();
1000#endif
1001 return lineBox;
1002}
1003
akling@apple.com31dd4f42013-10-30 22:27:59 +00001004static void deleteLineRange(LineLayoutState& layoutState, RootInlineBox* startLine, RootInlineBox* stopLine = 0)
eric@webkit.org455d90e2011-05-09 22:27:27 +00001005{
1006 RootInlineBox* boxToDelete = startLine;
1007 while (boxToDelete && boxToDelete != stopLine) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001008 layoutState.updateRepaintRangeFromBox(boxToDelete);
akling@apple.com31dd4f42013-10-30 22:27:59 +00001009 // Note: deleteLineRange(firstRootBox()) is not identical to deleteLineBoxTree().
eric@webkit.orge2532d92011-05-16 23:10:49 +00001010 // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing.
eric@webkit.org455d90e2011-05-09 22:27:27 +00001011 RootInlineBox* next = boxToDelete->nextRootBox();
akling@apple.com31dd4f42013-10-30 22:27:59 +00001012 boxToDelete->deleteLine();
eric@webkit.org455d90e2011-05-09 22:27:27 +00001013 boxToDelete = next;
1014 }
1015}
1016
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001017void RenderBlockFlow::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild)
eric@webkit.org060caf62011-05-03 22:11:39 +00001018{
1019 // We want to skip ahead to the first dirty line
1020 InlineBidiResolver resolver;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001021 RootInlineBox* startLine = determineStartPosition(layoutState, resolver);
eric@webkit.org060caf62011-05-03 22:11:39 +00001022
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001023 unsigned consecutiveHyphenatedLines = 0;
1024 if (startLine) {
1025 for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox())
1026 consecutiveHyphenatedLines++;
1027 }
1028
eric@webkit.org060caf62011-05-03 22:11:39 +00001029 // FIXME: This would make more sense outside of this function, but since
1030 // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call
1031 // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html.
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001032 if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) {
antti@apple.comca2a8ff2013-10-04 04:04:35 +00001033 setNeedsLayout(MarkOnlyThis); // Mark as needing a full layout to force us to repaint.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001034 if (!view().doingFullRepaint() && hasLayer()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001035 // Because we waited until we were already inside layout to discover
1036 // that the block really needed a full layout, we missed our chance to repaint the layer
1037 // before layout started. Luckily the layer has cached the repaint rect for its original
1038 // position and size, and so we can use that to make a repaint happen now.
leviw@chromium.org52066f32012-09-12 19:17:03 +00001039 repaintUsingContainer(containerForRepaint(), pixelSnappedIntRect(layer()->repaintRect()));
eric@webkit.org060caf62011-05-03 22:11:39 +00001040 }
1041 }
1042
mihnea@adobe.com99467792013-03-19 09:09:04 +00001043 if (containsFloats())
darin@apple.com7cad7042013-09-24 05:53:55 +00001044 layoutState.setLastFloat(m_floatingObjects->set().last().get());
eric@webkit.org060caf62011-05-03 22:11:39 +00001045
1046 // We also find the first clean line and extract these lines. We will add them back
1047 // if we determine that we're able to synchronize after handling all our dirty lines.
1048 InlineIterator cleanLineStart;
1049 BidiStatus cleanLineBidiStatus;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001050 if (!layoutState.isFullLayout() && startLine)
1051 determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus);
eric@webkit.org060caf62011-05-03 22:11:39 +00001052
1053 if (startLine) {
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001054 if (!layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001055 layoutState.setRepaintRange(logicalHeight());
akling@apple.com31dd4f42013-10-30 22:27:59 +00001056 deleteLineRange(layoutState, startLine);
eric@webkit.org060caf62011-05-03 22:11:39 +00001057 }
1058
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001059 if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001060 // If the last line before the start line ends with a line break that clear floats,
1061 // adjust the height accordingly.
1062 // A line break can be either the first or the last object on a line, depending on its direction.
1063 if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) {
akling@apple.com0b8172b72013-08-31 18:34:23 +00001064 RenderObject* lastObject = &lastLeafChild->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001065 if (!lastObject->isBR())
akling@apple.com0b8172b72013-08-31 18:34:23 +00001066 lastObject = &lastRootBox()->firstLeafChild()->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001067 if (lastObject->isBR()) {
akling@apple.com827be9c2013-10-29 02:58:43 +00001068 EClear clear = lastObject->style().clear();
eric@webkit.org060caf62011-05-03 22:11:39 +00001069 if (clear != CNONE)
1070 newLine(clear);
1071 }
1072 }
1073 }
1074
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001075 layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001076 linkToEndLineIfNeeded(layoutState);
1077 repaintDirtyFloats(layoutState.floats());
1078}
eric@webkit.org060caf62011-05-03 22:11:39 +00001079
zoltan@webkit.org8b422c82013-09-20 21:17:43 +00001080RenderTextInfo::RenderTextInfo()
mitz@apple.com6a859602012-08-27 15:31:56 +00001081 : m_text(0)
mitz@apple.comd4c153d2012-09-16 23:36:41 +00001082 , m_font(0)
mitz@apple.com6a859602012-08-27 15:31:56 +00001083{
1084}
1085
zoltan@webkit.org8b422c82013-09-20 21:17:43 +00001086RenderTextInfo::~RenderTextInfo()
mitz@apple.com6a859602012-08-27 15:31:56 +00001087{
1088}
1089
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001090// Before restarting the layout loop with a new logicalHeight, remove all floats that were added and reset the resolver.
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001091inline const InlineIterator& RenderBlockFlow::restartLayoutRunsAndFloatsInRange(LayoutUnit oldLogicalHeight, LayoutUnit newLogicalHeight, FloatingObject* lastFloatFromPreviousLine, InlineBidiResolver& resolver, const InlineIterator& oldEnd)
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001092{
1093 removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight);
1094 setLogicalHeight(newLogicalHeight);
1095 resolver.setPositionIgnoringNestedIsolates(oldEnd);
1096 return oldEnd;
1097}
1098
betravis@adobe.comed90c982013-06-05 23:05:57 +00001099#if ENABLE(CSS_SHAPES)
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001100static inline void pushShapeContentOverflowBelowTheContentBox(RenderBlockFlow* block, ShapeInsideInfo* shapeInsideInfo, LayoutUnit lineTop, LayoutUnit lineHeight)
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001101{
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001102 ASSERT(shapeInsideInfo);
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001103
1104 LayoutUnit logicalLineBottom = lineTop + lineHeight;
zoltan@webkit.orgb20fd7c2013-07-19 17:46:08 +00001105 LayoutUnit shapeLogicalBottom = shapeInsideInfo->shapeLogicalBottom();
zoltan@webkit.org22964092013-09-12 22:55:59 +00001106 LayoutUnit shapeContainingBlockLogicalHeight = shapeInsideInfo->shapeContainingBlockLogicalHeight();
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001107
weinig@apple.com12974262013-11-26 05:54:30 +00001108 bool isOverflowPositionedAlready = (shapeContainingBlockLogicalHeight - shapeInsideInfo->owner().borderAndPaddingAfter() + lineHeight) <= lineTop;
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001109
zoltan@webkit.orgb20fd7c2013-07-19 17:46:08 +00001110 // If the last line overlaps with the shape, we don't need the segments anymore
1111 if (lineTop < shapeLogicalBottom && shapeLogicalBottom < logicalLineBottom)
1112 shapeInsideInfo->clearSegments();
1113
zoltan@webkit.org22964092013-09-12 22:55:59 +00001114 if (logicalLineBottom <= shapeLogicalBottom || !shapeContainingBlockLogicalHeight || isOverflowPositionedAlready)
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001115 return;
1116
weinig@apple.com12974262013-11-26 05:54:30 +00001117 LayoutUnit newLogicalHeight = block->logicalHeight() + (shapeContainingBlockLogicalHeight - (lineTop + shapeInsideInfo->owner().borderAndPaddingAfter()));
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001118 block->setLogicalHeight(newLogicalHeight);
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001119}
1120
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001121void RenderBlockFlow::updateShapeAndSegmentsForCurrentLine(ShapeInsideInfo*& shapeInsideInfo, const LayoutSize& logicalOffsetFromShapeContainer, LineLayoutState& layoutState)
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001122{
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001123 if (layoutState.flowThread())
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001124 return updateShapeAndSegmentsForCurrentLineInFlowThread(shapeInsideInfo, layoutState);
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001125
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001126 if (!shapeInsideInfo)
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001127 return;
1128
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001129 LayoutUnit lineTop = logicalHeight() + logicalOffsetFromShapeContainer.height();
1130 LayoutUnit lineLeft = logicalOffsetFromShapeContainer.width();
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001131 LayoutUnit lineHeight = this->lineHeight(layoutState.lineInfo().isFirstLine(), isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes);
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001132
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001133 // FIXME: Bug 95361: It is possible for a line to grow beyond lineHeight, in which case these segments may be incorrect.
zoltan@webkit.orge1a0c952013-09-18 03:27:35 +00001134 shapeInsideInfo->updateSegmentsForLine(LayoutSize(lineLeft, lineTop), lineHeight);
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001135
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001136 pushShapeContentOverflowBelowTheContentBox(this, shapeInsideInfo, lineTop, lineHeight);
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001137}
zoltan@webkit.orgd07fc732013-05-20 19:00:22 +00001138
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001139void RenderBlockFlow::updateShapeAndSegmentsForCurrentLineInFlowThread(ShapeInsideInfo*& shapeInsideInfo, LineLayoutState& layoutState)
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001140{
1141 ASSERT(layoutState.flowThread());
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001142
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001143 RenderRegion* currentRegion = regionAtBlockOffset(logicalHeight());
zoltan@webkit.org1493d302013-10-21 20:18:54 +00001144 if (!currentRegion || !currentRegion->logicalHeight())
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001145 return;
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001146
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001147 shapeInsideInfo = currentRegion->shapeInsideInfo();
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001148
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001149 RenderRegion* nextRegion = 0;
1150 if (!currentRegion->isLastRegion()) {
1151 RenderRegionList regionList = layoutState.flowThread()->renderRegionList();
1152 auto it = regionList.find(currentRegion);
1153 nextRegion = *(++it);
1154 }
1155
1156 // We only want to deal regions with shapes, so we check if the next region has a shape
1157 if (!shapeInsideInfo && nextRegion && !nextRegion->shapeInsideInfo())
1158 return;
1159
1160 LayoutUnit lineHeight = this->lineHeight(layoutState.lineInfo().isFirstLine(), isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes);
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001161 LayoutUnit logicalLineTopInFlowThread = logicalHeight() + offsetFromLogicalTopOfFirstPage();
1162 LayoutUnit logicalLineBottomInFlowThread = logicalLineTopInFlowThread + lineHeight;
1163 LayoutUnit logicalRegionTopInFlowThread = currentRegion->logicalTopForFlowThreadContent();
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001164 LayoutUnit logicalRegionBottomInFlowThread = logicalRegionTopInFlowThread + currentRegion->logicalHeight() - currentRegion->borderAndPaddingBefore() - currentRegion->borderAndPaddingAfter();
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001165
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001166 LayoutUnit shapeBottomInFlowThread = LayoutUnit::max();
1167 if (shapeInsideInfo)
1168 shapeBottomInFlowThread = shapeInsideInfo->shapeLogicalBottom() + currentRegion->logicalTopForFlowThreadContent();
1169
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001170 bool lineOverLapsWithShapeBottom = shapeBottomInFlowThread < logicalLineBottomInFlowThread;
1171 bool lineOverLapsWithRegionBottom = logicalLineBottomInFlowThread > logicalRegionBottomInFlowThread;
1172 bool overFlowsToNextRegion = nextRegion && (lineOverLapsWithShapeBottom || lineOverLapsWithRegionBottom);
1173
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001174 // If the line is between two shapes/regions we position the line to the top of the next shape/region
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001175 if (overFlowsToNextRegion) {
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001176 ASSERT(currentRegion != nextRegion);
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001177 LayoutUnit deltaToNextRegion = logicalRegionBottomInFlowThread - logicalLineTopInFlowThread;
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001178 setLogicalHeight(logicalHeight() + deltaToNextRegion);
1179
1180 currentRegion = nextRegion;
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001181 shapeInsideInfo = currentRegion->shapeInsideInfo();
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001182
1183 logicalLineTopInFlowThread = logicalHeight() + offsetFromLogicalTopOfFirstPage();
1184 logicalLineBottomInFlowThread = logicalLineTopInFlowThread + lineHeight;
1185 logicalRegionTopInFlowThread = currentRegion->logicalTopForFlowThreadContent();
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001186 logicalRegionBottomInFlowThread = logicalRegionTopInFlowThread + currentRegion->logicalHeight() - currentRegion->borderAndPaddingBefore() - currentRegion->borderAndPaddingAfter();
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001187 }
1188
1189 if (!shapeInsideInfo)
1190 return;
1191
zoltan@webkit.orgf04b8722013-10-25 17:26:35 +00001192 bool isFirstLineInRegion = logicalLineBottomInFlowThread <= (logicalRegionTopInFlowThread + lineHeight);
1193 bool isFirstLineAdjusted = (logicalLineTopInFlowThread - logicalRegionTopInFlowThread) < (layoutState.adjustedLogicalLineTop() - currentRegion->borderAndPaddingBefore());
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001194 // We position the first line to the top of the shape in the region or to the previously adjusted position in the shape
zoltan@webkit.orgf04b8722013-10-25 17:26:35 +00001195 if (isFirstLineInRegion || isFirstLineAdjusted) {
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001196 LayoutUnit shapeTopOffset = layoutState.adjustedLogicalLineTop();
zoltan@webkit.org35793312013-10-29 20:44:45 +00001197
1198 if (!shapeTopOffset && (shapeInsideInfo->shapeLogicalTop() > 0))
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001199 shapeTopOffset = shapeInsideInfo->shapeLogicalTop();
1200
1201 LayoutUnit shapePositionInFlowThread = currentRegion->logicalTopForFlowThreadContent() + shapeTopOffset;
1202 LayoutUnit shapeTopLineTopDelta = shapePositionInFlowThread - logicalLineTopInFlowThread - currentRegion->borderAndPaddingBefore();
1203
1204 setLogicalHeight(logicalHeight() + shapeTopLineTopDelta);
1205 logicalLineTopInFlowThread += shapeTopLineTopDelta;
1206 layoutState.setAdjustedLogicalLineTop(0);
1207 }
1208
1209 LayoutUnit lineTop = logicalLineTopInFlowThread - currentRegion->logicalTopForFlowThreadContent() + currentRegion->borderAndPaddingBefore();
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001210
1211 // FIXME: 118571 - Shape inside on a region does not yet take into account its padding for nested flow blocks
zoltan@webkit.orge1a0c952013-09-18 03:27:35 +00001212 shapeInsideInfo->updateSegmentsForLine(LayoutSize(0, lineTop), lineHeight);
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001213
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001214 if (currentRegion->isLastRegion())
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001215 pushShapeContentOverflowBelowTheContentBox(this, shapeInsideInfo, lineTop, lineHeight);
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001216}
1217
zoltan@webkit.org5b173ca2013-10-12 06:03:17 +00001218static inline LayoutUnit adjustLogicalLineTop(ShapeInsideInfo* shapeInsideInfo, InlineIterator start, InlineIterator end, const WordMeasurements& wordMeasurements)
1219{
1220 if (!shapeInsideInfo || end != start)
1221 return 0;
1222
1223 float minWidth = firstPositiveWidth(wordMeasurements);
1224 ASSERT(minWidth || wordMeasurements.isEmpty());
1225 if (minWidth > 0 && shapeInsideInfo->adjustLogicalLineTop(minWidth))
1226 return shapeInsideInfo->logicalLineTop();
1227
1228 return shapeInsideInfo->shapeLogicalBottom();
1229}
1230
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001231bool RenderBlockFlow::adjustLogicalLineTopAndLogicalHeightIfNeeded(ShapeInsideInfo* shapeInsideInfo, LayoutUnit absoluteLogicalTop, LineLayoutState& layoutState, InlineBidiResolver& resolver, FloatingObject* lastFloatFromPreviousLine, InlineIterator& end, WordMeasurements& wordMeasurements)
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001232{
betravis@adobe.comcf7cba62013-06-10 21:23:45 +00001233 LayoutUnit adjustedLogicalLineTop = adjustLogicalLineTop(shapeInsideInfo, resolver.position(), end, wordMeasurements);
zoltan@webkit.org2b977c02013-10-03 18:24:59 +00001234
zoltan@webkit.org397a5272013-10-22 22:07:32 +00001235 if (shapeInsideInfo && containsFloats()) {
zoltan@webkit.org2b977c02013-10-03 18:24:59 +00001236 lastFloatFromPreviousLine = m_floatingObjects->set().last().get();
zoltan@webkit.org397a5272013-10-22 22:07:32 +00001237 if (!wordMeasurements.size()) {
1238 LayoutUnit floatLogicalTopOffset = shapeInsideInfo->computeFirstFitPositionForFloat(logicalSizeForFloat(lastFloatFromPreviousLine));
1239 if (logicalHeight() < floatLogicalTopOffset)
1240 adjustedLogicalLineTop = floatLogicalTopOffset;
1241 }
zoltan@webkit.org2b977c02013-10-03 18:24:59 +00001242 }
1243
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001244 if (!adjustedLogicalLineTop)
1245 return false;
1246
1247 LayoutUnit newLogicalHeight = adjustedLogicalLineTop - absoluteLogicalTop;
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001248
1249 if (layoutState.flowThread()) {
1250 layoutState.setAdjustedLogicalLineTop(adjustedLogicalLineTop);
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001251 newLogicalHeight = logicalHeight();
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001252 }
1253
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001254 end = restartLayoutRunsAndFloatsInRange(logicalHeight(), newLogicalHeight, lastFloatFromPreviousLine, resolver, end);
1255 return true;
1256}
betravis@adobe.com9e5e8242013-04-19 23:28:26 +00001257#endif
1258
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001259void RenderBlockFlow::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001260{
akling@apple.com827be9c2013-10-29 02:58:43 +00001261 const RenderStyle& styleToUse = style();
akling@apple.com691cf5c2013-08-24 16:33:15 +00001262 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001263 LineMidpointState& lineMidpointState = resolver.midpointState();
1264 InlineIterator end = resolver.position();
1265 bool checkForEndLineMatch = layoutState.endLine();
mitz@apple.com6a859602012-08-27 15:31:56 +00001266 RenderTextInfo renderTextInfo;
eric@webkit.org060caf62011-05-03 22:11:39 +00001267 VerticalPositionCache verticalPositionCache;
1268
weinig@apple.com12840dc2013-10-22 23:59:08 +00001269 LineBreaker lineBreaker(*this);
leviw@chromium.org1a508692011-05-05 00:01:11 +00001270
betravis@adobe.comed90c982013-06-05 23:05:57 +00001271#if ENABLE(CSS_SHAPES)
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001272 LayoutSize logicalOffsetFromShapeContainer;
betravis@adobe.comcf7cba62013-06-10 21:23:45 +00001273 ShapeInsideInfo* shapeInsideInfo = layoutShapeInsideInfo();
1274 if (shapeInsideInfo) {
weinig@apple.com12974262013-11-26 05:54:30 +00001275 ASSERT(&shapeInsideInfo->owner() == this || allowsShapeInsideInfoSharing());
betravis@adobe.comcf7cba62013-06-10 21:23:45 +00001276 if (shapeInsideInfo != this->shapeInsideInfo()) {
commit-queue@webkit.org5fe2dfd2012-10-26 19:57:52 +00001277 // FIXME Bug 100284: If subsequent LayoutStates are pushed, we will have to add
1278 // their offsets from the original shape-inside container.
weinig@apple.com12974262013-11-26 05:54:30 +00001279 logicalOffsetFromShapeContainer = logicalOffsetFromShapeAncestorContainer(&shapeInsideInfo->owner());
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +00001280 }
1281 // Begin layout at the logical top of our shape inside.
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001282 if (logicalHeight() + logicalOffsetFromShapeContainer.height() < shapeInsideInfo->shapeLogicalTop()) {
1283 LayoutUnit logicalHeight = shapeInsideInfo->shapeLogicalTop() - logicalOffsetFromShapeContainer.height();
zoltan@webkit.orgd07fc732013-05-20 19:00:22 +00001284 if (layoutState.flowThread())
weinig@apple.com12974262013-11-26 05:54:30 +00001285 logicalHeight -= shapeInsideInfo->owner().borderAndPaddingBefore();
zoltan@webkit.orgd07fc732013-05-20 19:00:22 +00001286 setLogicalHeight(logicalHeight);
1287 }
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +00001288 }
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +00001289#endif
1290
eric@webkit.org060caf62011-05-03 22:11:39 +00001291 while (!end.atEnd()) {
1292 // FIXME: Is this check necessary before the first iteration or can it be moved to the end?
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001293 if (checkForEndLineMatch) {
1294 layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus));
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001295 if (layoutState.endLineMatched()) {
1296 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001297 break;
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001298 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001299 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001300
1301 lineMidpointState.reset();
1302
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001303 layoutState.lineInfo().setEmpty(true);
robert@webkit.org8cbab142011-12-30 20:58:29 +00001304 layoutState.lineInfo().resetRunsFromLeadingWhitespace();
eric@webkit.org060caf62011-05-03 22:11:39 +00001305
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001306 const InlineIterator oldEnd = end;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001307 bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly();
darin@apple.com7cad7042013-09-24 05:53:55 +00001308 FloatingObject* lastFloatFromPreviousLine = (containsFloats()) ? m_floatingObjects->set().last().get() : 0;
zoltan@webkit.org3bd77f52013-04-23 18:23:36 +00001309
betravis@adobe.comed90c982013-06-05 23:05:57 +00001310#if ENABLE(CSS_SHAPES)
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001311 updateShapeAndSegmentsForCurrentLine(shapeInsideInfo, logicalOffsetFromShapeContainer, layoutState);
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +00001312#endif
enrica@apple.com885c84d2012-10-10 05:48:51 +00001313 WordMeasurements wordMeasurements;
1314 end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
glenn@skynav.com61b1abf2013-04-02 23:28:32 +00001315 renderTextInfo.m_lineBreakIterator.resetPriorContext();
eric@webkit.org060caf62011-05-03 22:11:39 +00001316 if (resolver.position().atEnd()) {
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001317 // FIXME: We shouldn't be creating any runs in nextLineBreak to begin with!
eric@webkit.org060caf62011-05-03 22:11:39 +00001318 // Once BidiRunList is separated from BidiResolver this will not be needed.
1319 resolver.runs().deleteRuns();
1320 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001321 layoutState.setCheckForFloatsFromLastLine(true);
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001322 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
eric@webkit.org060caf62011-05-03 22:11:39 +00001323 break;
1324 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001325
betravis@adobe.comed90c982013-06-05 23:05:57 +00001326#if ENABLE(CSS_SHAPES)
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001327 if (adjustLogicalLineTopAndLogicalHeightIfNeeded(shapeInsideInfo, logicalOffsetFromShapeContainer.height(), layoutState, resolver, lastFloatFromPreviousLine, end, wordMeasurements))
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001328 continue;
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001329#endif
betravis@adobe.com9e5e8242013-04-19 23:28:26 +00001330 ASSERT(end != resolver.position());
1331
eric@webkit.org45e33a52011-05-04 11:51:09 +00001332 // This is a short-cut for empty lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001333 if (layoutState.lineInfo().isEmpty()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001334 if (lastRootBox())
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001335 lastRootBox()->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
eric@webkit.org060caf62011-05-03 22:11:39 +00001336 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001337 VisualDirectionOverride override = (styleToUse.rtlOrdering() == VisualOrder ? (styleToUse.direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride);
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001338
akling@apple.com827be9c2013-10-29 02:58:43 +00001339 if (isNewUBAParagraph && styleToUse.unicodeBidi() == Plaintext && !resolver.context()->parent()) {
1340 TextDirection direction = styleToUse.direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001341 determineDirectionality(direction, resolver.position());
akling@apple.com827be9c2013-10-29 02:58:43 +00001342 resolver.setStatus(BidiStatus(direction, isOverride(styleToUse.unicodeBidi())));
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001343 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001344 // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine.
1345 BidiRunList<BidiRun>& bidiRuns = resolver.runs();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001346 constructBidiRunsForLine(this, resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly());
eric@webkit.org060caf62011-05-03 22:11:39 +00001347 ASSERT(resolver.position() == end);
1348
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001349 BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : 0;
eric@webkit.org060caf62011-05-03 22:11:39 +00001350
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001351 if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) {
eric@webkit.org45e33a52011-05-04 11:51:09 +00001352 bidiRuns.logicallyLastRun()->m_hasHyphen = true;
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001353 consecutiveHyphenatedLines++;
1354 } else
1355 consecutiveHyphenatedLines = 0;
eric@webkit.org45e33a52011-05-04 11:51:09 +00001356
eric@webkit.org060caf62011-05-03 22:11:39 +00001357 // Now that the runs have been ordered, we create the line boxes.
1358 // At the same time we figure out where border/padding/margin should be applied for
1359 // inline flow boxes.
1360
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001361 LayoutUnit oldLogicalHeight = logicalHeight();
enrica@apple.com885c84d2012-10-10 05:48:51 +00001362 RootInlineBox* lineBox = createLineBoxesFromBidiRuns(bidiRuns, end, layoutState.lineInfo(), verticalPositionCache, trailingSpaceRun, wordMeasurements);
eric@webkit.org060caf62011-05-03 22:11:39 +00001363
1364 bidiRuns.deleteRuns();
1365 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
1366
1367 if (lineBox) {
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001368 lineBox->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001369 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001370 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001371
1372 if (paginated) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001373 LayoutUnit adjustment = 0;
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001374 adjustLinePositionForPagination(lineBox, adjustment, layoutState.flowThread());
eric@webkit.org060caf62011-05-03 22:11:39 +00001375 if (adjustment) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001376 LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, layoutState.lineInfo().isFirstLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001377 lineBox->adjustBlockDirectionPosition(adjustment);
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001378 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001379 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001380
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001381 if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, layoutState.lineInfo().isFirstLine()) != oldLineWidth) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001382 // We have to delete this line, remove all floats that got added, and let line layout re-run.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001383 lineBox->deleteLine();
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001384 end = restartLayoutRunsAndFloatsInRange(oldLogicalHeight, oldLogicalHeight + adjustment, lastFloatFromPreviousLine, resolver, oldEnd);
eric@webkit.org060caf62011-05-03 22:11:39 +00001385 continue;
1386 }
1387
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001388 setLogicalHeight(lineBox->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001389 }
commit-queue@webkit.orgbe554b22012-11-26 20:00:49 +00001390
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001391 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001392 updateRegionForLine(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001393 }
1394 }
robert@webkit.org402c1512013-02-07 18:48:39 +00001395 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001396
robert@webkit.org402c1512013-02-07 18:48:39 +00001397 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001398 setStaticPositions(*this, *lineBreaker.positionedObjects()[i]);
eric@webkit.org060caf62011-05-03 22:11:39 +00001399
robert@webkit.org402c1512013-02-07 18:48:39 +00001400 if (!layoutState.lineInfo().isEmpty()) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001401 layoutState.lineInfo().setFirstLine(false);
leviw@chromium.org1a508692011-05-05 00:01:11 +00001402 newLine(lineBreaker.clear());
eric@webkit.org060caf62011-05-03 22:11:39 +00001403 }
1404
1405 if (m_floatingObjects && lastRootBox()) {
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001406 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001407 auto it = floatingObjectSet.begin();
1408 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001409 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001410 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001411 ASSERT(lastFloatIterator != end);
1412 ++lastFloatIterator;
1413 it = lastFloatIterator;
1414 }
1415 for (; it != end; ++it) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001416 FloatingObject* f = it->get();
eric@webkit.org060caf62011-05-03 22:11:39 +00001417 appendFloatingObjectToLastLine(f);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001418 ASSERT(&f->renderer() == &layoutState.floats()[layoutState.floatIndex()].object);
eric@webkit.org060caf62011-05-03 22:11:39 +00001419 // If a float's geometry has changed, give up on syncing with clean lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001420 if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect())
eric@webkit.org060caf62011-05-03 22:11:39 +00001421 checkForEndLineMatch = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001422 layoutState.setFloatIndex(layoutState.floatIndex() + 1);
eric@webkit.org060caf62011-05-03 22:11:39 +00001423 }
darin@apple.com7cad7042013-09-24 05:53:55 +00001424 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001425 }
1426
1427 lineMidpointState.reset();
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001428 resolver.setPosition(end, numberOfIsolateAncestors(end));
eric@webkit.org060caf62011-05-03 22:11:39 +00001429 }
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001430
abucur@adobe.comfc497132013-10-04 08:49:21 +00001431 // In case we already adjusted the line positions during this layout to avoid widows
1432 // then we need to ignore the possibility of having a new widows situation.
1433 // Otherwise, we risk leaving empty containers which is against the block fragmentation principles.
akling@apple.com827be9c2013-10-29 02:58:43 +00001434 if (paginated && !style().hasAutoWidows() && !didBreakAtLineToAvoidWidow()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001435 // Check the line boxes to make sure we didn't create unacceptable widows.
1436 // However, we'll prioritize orphans - so nothing we do here should create
1437 // a new orphan.
1438
1439 RootInlineBox* lineBox = lastRootBox();
1440
1441 // Count from the end of the block backwards, to see how many hanging
1442 // lines we have.
1443 RootInlineBox* firstLineInBlock = firstRootBox();
1444 int numLinesHanging = 1;
1445 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1446 ++numLinesHanging;
1447 lineBox = lineBox->prevRootBox();
1448 }
1449
1450 // If there were no breaks in the block, we didn't create any widows.
jchaffraix@webkit.org0f225142013-01-28 22:28:21 +00001451 if (!lineBox || !lineBox->isFirstAfterPageBreak() || lineBox == firstLineInBlock)
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001452 return;
1453
akling@apple.com827be9c2013-10-29 02:58:43 +00001454 if (numLinesHanging < style().widows()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001455 // We have detected a widow. Now we need to work out how many
1456 // lines there are on the previous page, and how many we need
1457 // to steal.
akling@apple.com827be9c2013-10-29 02:58:43 +00001458 int numLinesNeeded = style().widows() - numLinesHanging;
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001459 RootInlineBox* currentFirstLineOfNewPage = lineBox;
1460
1461 // Count the number of lines in the previous page.
1462 lineBox = lineBox->prevRootBox();
1463 int numLinesInPreviousPage = 1;
1464 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1465 ++numLinesInPreviousPage;
1466 lineBox = lineBox->prevRootBox();
1467 }
1468
1469 // If there was an explicit value for orphans, respect that. If not, we still
1470 // shouldn't create a situation where we make an orphan bigger than the initial value.
1471 // This means that setting widows implies we also care about orphans, but given
1472 // the specification says the initial orphan value is non-zero, this is ok. The
1473 // author is always free to set orphans explicitly as well.
akling@apple.com827be9c2013-10-29 02:58:43 +00001474 int orphans = style().hasAutoOrphans() ? style().initialOrphans() : style().orphans();
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001475 int numLinesAvailable = numLinesInPreviousPage - orphans;
1476 if (numLinesAvailable <= 0)
1477 return;
1478
andersca@apple.com86298632013-11-10 19:32:33 +00001479 int numLinesToTake = std::min(numLinesAvailable, numLinesNeeded);
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001480 // Wind back from our first widowed line.
1481 lineBox = currentFirstLineOfNewPage;
1482 for (int i = 0; i < numLinesToTake; ++i)
1483 lineBox = lineBox->prevRootBox();
1484
1485 // We now want to break at this line. Remember for next layout and trigger relayout.
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001486 setBreakAtLineToAvoidWidow(lineCount(lineBox));
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001487 markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), lineBox->lineBottomWithLeading(), lineBox);
1488 }
1489 }
abucur@adobe.comfc497132013-10-04 08:49:21 +00001490
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001491 clearDidBreakAtLineToAvoidWidow();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001492}
eric@webkit.org060caf62011-05-03 22:11:39 +00001493
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001494void RenderBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001495{
1496 if (layoutState.endLine()) {
1497 if (layoutState.endLineMatched()) {
akling@apple.com691cf5c2013-08-24 16:33:15 +00001498 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eric@webkit.org060caf62011-05-03 22:11:39 +00001499 // Attach all the remaining lines, and then adjust their y-positions as needed.
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001500 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001501 for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001502 line->attachLine();
1503 if (paginated) {
1504 delta -= line->paginationStrut();
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001505 adjustLinePositionForPagination(line, delta, layoutState.flowThread());
eric@webkit.org060caf62011-05-03 22:11:39 +00001506 }
1507 if (delta) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001508 layoutState.updateRepaintRangeFromBox(line, delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001509 line->adjustBlockDirectionPosition(delta);
1510 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001511 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001512 updateRegionForLine(line);
eric@webkit.org060caf62011-05-03 22:11:39 +00001513 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001514 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1515 RenderBox* floatingBox = *it;
1516 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001517 ASSERT(!floatingObject->originatingLine());
1518 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001519 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox) + delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001520 positionNewFloats();
1521 }
1522 }
1523 }
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001524 setLogicalHeight(lastRootBox()->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001525 } else {
1526 // Delete all the remaining lines.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001527 deleteLineRange(layoutState, layoutState.endLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001528 }
1529 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001530
1531 if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001532 // In case we have a float on the last line, it might not be positioned up to now.
1533 // This has to be done before adding in the bottom border/padding, or the float will
1534 // include the padding incorrectly. -dwh
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001535 if (layoutState.checkForFloatsFromLastLine()) {
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001536 LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow();
1537 LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow();
akling@apple.comb5f24642013-11-06 04:47:12 +00001538 auto newLineBox = std::make_unique<TrailingFloatsRootInlineBox>(*this);
1539 auto trailingFloatsLineBox = newLineBox.get();
1540 m_lineBoxes.appendLineBox(std::move(newLineBox));
eric@webkit.org060caf62011-05-03 22:11:39 +00001541 trailingFloatsLineBox->setConstructed();
1542 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
1543 VerticalPositionCache verticalPositionCache;
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001544 LayoutUnit blockLogicalHeight = logicalHeight();
hyatt@apple.coma8b5b822011-09-07 18:48:07 +00001545 trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache);
1546 trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight);
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001547 trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight));
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001548 LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight);
1549 LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight);
eric@webkit.org060caf62011-05-03 22:11:39 +00001550 trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom());
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001551 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001552 updateRegionForLine(trailingFloatsLineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001553 }
1554
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001555 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001556 auto it = floatingObjectSet.begin();
1557 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001558 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001559 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001560 ASSERT(lastFloatIterator != end);
1561 ++lastFloatIterator;
1562 it = lastFloatIterator;
1563 }
1564 for (; it != end; ++it)
darin@apple.com7cad7042013-09-24 05:53:55 +00001565 appendFloatingObjectToLastLine(it->get());
1566 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001567 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001568}
1569
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001570void RenderBlockFlow::repaintDirtyFloats(Vector<FloatWithRect>& floats)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001571{
eric@webkit.org060caf62011-05-03 22:11:39 +00001572 size_t floatCount = floats.size();
1573 // Floats that did not have layout did not repaint when we laid them out. They would have
1574 // painted by now if they had moved, but if they stayed at (0, 0), they still need to be
1575 // painted.
1576 for (size_t i = 0; i < floatCount; ++i) {
1577 if (!floats[i].everHadLayout) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001578 RenderBox& box = floats[i].object;
1579 if (!box.x() && !box.y() && box.checkForRepaintDuringLayout())
1580 box.repaint();
eric@webkit.org060caf62011-05-03 22:11:39 +00001581 }
1582 }
1583}
1584
antti@apple.com940f5872013-10-24 20:31:11 +00001585void RenderBlockFlow::layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom)
jamesr@google.com19548ad2010-04-02 23:21:35 +00001586{
antti@apple.comfea51992013-10-28 13:39:23 +00001587 ASSERT(!m_simpleLineLayout);
antti@apple.com940f5872013-10-24 20:31:11 +00001588
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001589 setLogicalHeight(borderAndPaddingBefore());
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001590
1591 // Lay out our hypothetical grid line as though it occurs at the top of the block.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001592 if (view().layoutState() && view().layoutState()->lineGrid() == this)
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001593 layoutLineGridBox();
mitz@apple.come1364202008-02-28 01:06:41 +00001594
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001595 RenderFlowThread* flowThread = flowThreadContainingBlock();
akling@apple.comee3c8df2013-11-06 08:09:44 +00001596 bool clearLinesForPagination = firstRootBox() && flowThread && !flowThread->hasRegions();
commit-queue@webkit.org93cdd632012-12-07 00:33:56 +00001597
hyatt0c3a9862004-02-23 21:26:26 +00001598 // Figure out if we should clear out our line boxes.
1599 // FIXME: Handle resize eventually!
akling@apple.comee3c8df2013-11-06 08:09:44 +00001600 bool isFullLayout = !firstRootBox() || selfNeedsLayout() || relayoutChildren || clearLinesForPagination;
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001601 LineLayoutState layoutState(isFullLayout, repaintLogicalTop, repaintLogicalBottom, flowThread);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001602
1603 if (isFullLayout)
akling@apple.com31dd4f42013-10-30 22:27:59 +00001604 lineBoxes().deleteLineBoxes();
mitz@apple.come1364202008-02-28 01:06:41 +00001605
commit-queue@webkit.org07797312013-02-22 18:58:19 +00001606 // Text truncation kicks in in two cases:
1607 // 1) If your overflow isn't visible and your text-overflow-mode isn't clip.
1608 // 2) If you're an anonymous block with a block parent that satisfies #1.
hyatted77ad82004-06-15 07:21:23 +00001609 // FIXME: CSS3 says that descendants that are clipped must also know how to truncate. This is insanely
commit-queue@webkit.org07797312013-02-22 18:58:19 +00001610 // difficult to figure out in general (especially in the middle of doing layout), so we only handle the
1611 // simple case of an anonymous block truncating when it's parent is clipped.
akling@apple.com827be9c2013-10-29 02:58:43 +00001612 bool hasTextOverflow = (style().textOverflow() && hasOverflowClip())
1613 || (isAnonymousBlock() && parent() && parent()->isRenderBlock() && parent()->style().textOverflow() && parent()->hasOverflowClip());
mitz@apple.come1364202008-02-28 01:06:41 +00001614
hyatted77ad82004-06-15 07:21:23 +00001615 // Walk all the lines and delete our ellipsis line boxes if they exist.
1616 if (hasTextOverflow)
1617 deleteEllipsisLineBoxes();
1618
hyattffe78712003-02-11 01:59:29 +00001619 if (firstChild()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001620 // In full layout mode, clear the line boxes of children upfront. Otherwise,
1621 // siblings can run into stale root lineboxes during layout. Then layout
1622 // the replaced elements later. In partial layout mode, line boxes are not
1623 // deleted and only dirtied. In that case, we can layout the replaced
1624 // elements at the same time.
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001625 bool hasInlineChild = false;
inferno@chromium.org13563122012-08-16 20:50:05 +00001626 Vector<RenderBox*> replacedChildren;
weinig@apple.com12840dc2013-10-22 23:59:08 +00001627 for (InlineWalker walker(*this); !walker.atEnd(); walker.advance()) {
1628 RenderObject& o = *walker.current();
abucur@adobe.com33159da2013-08-13 07:44:32 +00001629
weinig@apple.com12840dc2013-10-22 23:59:08 +00001630 if (!hasInlineChild && o.isInline())
commit-queue@webkit.orgcf45df92010-09-14 13:25:06 +00001631 hasInlineChild = true;
1632
weinig@apple.com12840dc2013-10-22 23:59:08 +00001633 if (o.isReplaced() || o.isFloating() || o.isOutOfFlowPositioned()) {
1634 RenderBox& box = toRenderBox(o);
eric@webkit.org060caf62011-05-03 22:11:39 +00001635
weinig@apple.com12840dc2013-10-22 23:59:08 +00001636 if (relayoutChildren || box.hasRelativeDimensions())
1637 box.setChildNeedsLayout(MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001638
zimmermann@webkit.orgac68af42011-06-15 08:02:37 +00001639 // If relayoutChildren is set and the child has percentage padding or an embedded content box, we also need to invalidate the childs pref widths.
weinig@apple.com12840dc2013-10-22 23:59:08 +00001640 if (relayoutChildren && box.needsPreferredWidthsRecalculation())
1641 box.setPreferredLogicalWidthsDirty(true, MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001642
weinig@apple.com12840dc2013-10-22 23:59:08 +00001643 if (box.isOutOfFlowPositioned())
1644 box.containingBlock()->insertPositionedObject(box);
1645 else if (box.isFloating())
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001646 layoutState.floats().append(FloatWithRect(box));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001647 else if (isFullLayout || box.needsLayout()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001648 // Replaced element.
weinig@apple.com12840dc2013-10-22 23:59:08 +00001649 box.dirtyLineBoxes(isFullLayout);
inferno@chromium.org13563122012-08-16 20:50:05 +00001650 if (isFullLayout)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001651 replacedChildren.append(&box);
inferno@chromium.org13563122012-08-16 20:50:05 +00001652 else
weinig@apple.com12840dc2013-10-22 23:59:08 +00001653 box.layoutIfNeeded();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001654 }
weinig@apple.com12840dc2013-10-22 23:59:08 +00001655 } else if (o.isTextOrLineBreak() || (o.isRenderInline() && !walker.atEndOfInline())) {
1656 if (o.isRenderInline())
1657 toRenderInline(o).updateAlwaysCreateLineBoxes(layoutState.isFullLayout());
1658 if (layoutState.isFullLayout() || o.selfNeedsLayout())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001659 dirtyLineBoxesForRenderer(o, layoutState.isFullLayout());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001660 o.clearNeedsLayout();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001661 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001662 }
1663
inferno@chromium.orgba2dceb2012-08-21 00:09:47 +00001664 for (size_t i = 0; i < replacedChildren.size(); i++)
1665 replacedChildren[i]->layoutIfNeeded();
inferno@chromium.org13563122012-08-16 20:50:05 +00001666
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001667 layoutRunsAndFloats(layoutState, hasInlineChild);
kociendabb0c24b2001-08-24 14:24:40 +00001668 }
hyatt85586af2003-02-19 23:22:42 +00001669
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001670 // Expand the last line to accommodate Ruby and emphasis marks.
1671 int lastLineAnnotationsAdjustment = 0;
1672 if (lastRootBox()) {
andersca@apple.com86298632013-11-10 19:32:33 +00001673 LayoutUnit lowestAllowedPosition = std::max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
akling@apple.com827be9c2013-10-29 02:58:43 +00001674 if (!style().isFlippedLinesWritingMode())
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001675 lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition);
1676 else
1677 lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
hyatt@apple.com5e48ff52010-11-19 00:43:29 +00001678 }
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001679
hyatta70560a2002-11-20 01:53:20 +00001680 // Now add in the bottom border/padding.
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001681 setLogicalHeight(logicalHeight() + lastLineAnnotationsAdjustment + borderAndPaddingAfter() + scrollbarLogicalHeight());
kociendabb0c24b2001-08-24 14:24:40 +00001682
akling@apple.comee3c8df2013-11-06 08:09:44 +00001683 if (!firstRootBox() && hasLineIfEmpty())
hyatt@apple.com2a5eb212011-03-22 23:21:54 +00001684 setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
hyatted77ad82004-06-15 07:21:23 +00001685
1686 // See if we have any lines that spill out of our block. If we do, then we will possibly need to
1687 // truncate text.
1688 if (hasTextOverflow)
1689 checkLinesForTextOverflow();
kociendabb0c24b2001-08-24 14:24:40 +00001690}
1691
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001692void RenderBlockFlow::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat)
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001693{
1694 Vector<RenderBox*>* cleanLineFloats = line->floatsPtr();
1695 if (!cleanLineFloats)
1696 return;
1697
weinig@apple.com12840dc2013-10-22 23:59:08 +00001698 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001699 RenderBox* floatingBox = *it;
1700 floatingBox->layoutIfNeeded();
tkent@chromium.orgb27646b2012-03-08 03:31:25 +00001701 LayoutSize newSize(floatingBox->width() + floatingBox->marginWidth(), floatingBox->height() + floatingBox->marginHeight());
inferno@chromium.orga227be62013-02-11 08:06:45 +00001702 ASSERT_WITH_SECURITY_IMPLICATION(floatIndex < floats.size());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001703 if (&floats[floatIndex].object != floatingBox) {
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001704 encounteredNewFloat = true;
1705 return;
1706 }
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001707
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001708 if (floats[floatIndex].rect.size() != newSize) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001709 LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x();
andersca@apple.com86298632013-11-10 19:32:33 +00001710 LayoutUnit floatHeight = isHorizontalWritingMode() ? std::max(floats[floatIndex].rect.height(), newSize.height()) : std::max(floats[floatIndex].rect.width(), newSize.width());
1711 floatHeight = std::min(floatHeight, LayoutUnit::max() - floatTop);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001712 line->markDirty();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001713 markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001714 floats[floatIndex].rect.setSize(newSize);
1715 dirtiedByFloat = true;
1716 }
1717 floatIndex++;
1718 }
1719}
1720
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001721RootInlineBox* RenderBlockFlow::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver)
hyatt0c3a9862004-02-23 21:26:26 +00001722{
1723 RootInlineBox* curr = 0;
1724 RootInlineBox* last = 0;
mitz@apple.come1364202008-02-28 01:06:41 +00001725
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001726 // FIXME: This entire float-checking block needs to be broken into a new function.
mitz@apple.com40547b32008-03-18 04:04:34 +00001727 bool dirtiedByFloat = false;
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001728 if (!layoutState.isFullLayout()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001729 // Paginate all of the clean lines.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001730 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001731 LayoutUnit paginationDelta = 0;
mitz@apple.com40547b32008-03-18 04:04:34 +00001732 size_t floatIndex = 0;
1733 for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001734 if (paginated) {
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001735 if (lineWidthForPaginatedLineChanged(curr, 0, layoutState.flowThread())) {
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001736 curr->markDirty();
1737 break;
1738 }
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001739 paginationDelta -= curr->paginationStrut();
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001740 adjustLinePositionForPagination(curr, paginationDelta, layoutState.flowThread());
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001741 if (paginationDelta) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001742 if (containsFloats() || !layoutState.floats().isEmpty()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001743 // FIXME: Do better eventually. For now if we ever shift because of pagination and floats are present just go to a full layout.
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001744 layoutState.markForFullLayout();
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001745 break;
1746 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001747
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001748 layoutState.updateRepaintRangeFromBox(curr, paginationDelta);
hyatt@apple.com61bbedf2011-01-26 23:10:57 +00001749 curr->adjustBlockDirectionPosition(paginationDelta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001750 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001751 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001752 updateRegionForLine(curr);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001753 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001754
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001755 // If a new float has been inserted before this line or before its last known float, just do a full layout.
1756 bool encounteredNewFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001757 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001758 if (encounteredNewFloat)
1759 layoutState.markForFullLayout();
1760
1761 if (dirtiedByFloat || layoutState.isFullLayout())
mitz@apple.com40547b32008-03-18 04:04:34 +00001762 break;
1763 }
1764 // Check if a new float has been inserted after the last known float.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001765 if (!curr && floatIndex < layoutState.floats().size())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001766 layoutState.markForFullLayout();
mitz@apple.com40547b32008-03-18 04:04:34 +00001767 }
1768
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001769 if (layoutState.isFullLayout()) {
akling@apple.com31dd4f42013-10-30 22:27:59 +00001770 m_lineBoxes.deleteLineBoxTree();
igor.o@sisa.samsung.comf6a57df2013-04-15 21:25:35 +00001771 curr = 0;
1772
akling@apple.comee3c8df2013-11-06 08:09:44 +00001773 ASSERT(!firstRootBox() && !lastRootBox());
eseidel789896f2005-11-27 22:52:09 +00001774 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001775 if (curr) {
1776 // We have a dirty line.
mjs9f78dd92007-02-12 04:06:07 +00001777 if (RootInlineBox* prevRootBox = curr->prevRootBox()) {
hyatt0c3a9862004-02-23 21:26:26 +00001778 // We have a previous line.
tasak@google.comfcfd96f2012-11-26 07:45:38 +00001779 if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= toRenderText(prevRootBox->lineBreakObj())->textLength())))
mjs9f78dd92007-02-12 04:06:07 +00001780 // The previous line didn't break cleanly or broke at a newline
1781 // that has been deleted, so treat it as dirty too.
1782 curr = prevRootBox;
hyatt0c3a9862004-02-23 21:26:26 +00001783 }
eseidel789896f2005-11-27 22:52:09 +00001784 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001785 // No dirty lines were found.
1786 // If the last line didn't break cleanly, treat it as dirty.
1787 if (lastRootBox() && !lastRootBox()->endsWithBreak())
1788 curr = lastRootBox();
1789 }
mitz@apple.come1364202008-02-28 01:06:41 +00001790
hyatt0c3a9862004-02-23 21:26:26 +00001791 // If we have no dirty lines, then last is just the last root box.
1792 last = curr ? curr->prevRootBox() : lastRootBox();
1793 }
mitz@apple.come1364202008-02-28 01:06:41 +00001794
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001795 unsigned numCleanFloats = 0;
1796 if (!layoutState.floats().isEmpty()) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001797 LayoutUnit savedLogicalHeight = logicalHeight();
mitz@apple.com40547b32008-03-18 04:04:34 +00001798 // Restore floats from clean lines.
1799 RootInlineBox* line = firstRootBox();
1800 while (line != curr) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00001801 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001802 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1803 RenderBox* floatingBox = *it;
1804 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001805 ASSERT(!floatingObject->originatingLine());
1806 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001807 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox));
mitz@apple.com40547b32008-03-18 04:04:34 +00001808 positionNewFloats();
weinig@apple.com12840dc2013-10-22 23:59:08 +00001809 ASSERT(&layoutState.floats()[numCleanFloats].object == floatingBox);
mitz@apple.com40547b32008-03-18 04:04:34 +00001810 numCleanFloats++;
1811 }
1812 }
1813 line = line->nextRootBox();
1814 }
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001815 setLogicalHeight(savedLogicalHeight);
mitz@apple.com40547b32008-03-18 04:04:34 +00001816 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001817 layoutState.setFloatIndex(numCleanFloats);
mitz@apple.com40547b32008-03-18 04:04:34 +00001818
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001819 layoutState.lineInfo().setFirstLine(!last);
1820 layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak());
mitz@apple.com1a301772008-03-11 18:30:36 +00001821
hyatt0c3a9862004-02-23 21:26:26 +00001822 if (last) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001823 setLogicalHeight(last->lineBottomWithLeading());
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001824 InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos());
1825 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
mitz@apple.com15035e62008-07-05 20:44:44 +00001826 resolver.setStatus(last->lineBreakBidiStatus());
darindde01502005-12-18 22:55:35 +00001827 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001828 TextDirection direction = style().direction();
1829 if (style().unicodeBidi() == Plaintext)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001830 determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(*this), 0));
akling@apple.com827be9c2013-10-29 02:58:43 +00001831 resolver.setStatus(BidiStatus(direction, isOverride(style().unicodeBidi())));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001832 InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(*this, &resolver), 0);
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001833 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
darindde01502005-12-18 22:55:35 +00001834 }
hyatt0c3a9862004-02-23 21:26:26 +00001835 return curr;
1836}
1837
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001838void RenderBlockFlow::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001839{
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001840 ASSERT(!layoutState.endLine());
1841 size_t floatIndex = layoutState.floatIndex();
hyatt0c3a9862004-02-23 21:26:26 +00001842 RootInlineBox* last = 0;
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001843 for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) {
1844 if (!curr->isDirty()) {
1845 bool encounteredNewFloat = false;
1846 bool dirtiedByFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001847 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001848 if (encounteredNewFloat)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001849 return;
hyatt04420ca2004-07-16 00:05:42 +00001850 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001851 if (curr->isDirty())
1852 last = 0;
1853 else if (!last)
1854 last = curr;
hyatt0c3a9862004-02-23 21:26:26 +00001855 }
mitz@apple.come1364202008-02-28 01:06:41 +00001856
hyatt0c3a9862004-02-23 21:26:26 +00001857 if (!last)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001858 return;
mitz@apple.come1364202008-02-28 01:06:41 +00001859
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001860 // At this point, |last| is the first line in a run of clean lines that ends with the last line
1861 // in the block.
1862
eseidel789896f2005-11-27 22:52:09 +00001863 RootInlineBox* prev = last->prevRootBox();
mitz@apple.com15035e62008-07-05 20:44:44 +00001864 cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos());
eseidel789896f2005-11-27 22:52:09 +00001865 cleanLineBidiStatus = prev->lineBreakBidiStatus();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001866 layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading());
mitz@apple.come1364202008-02-28 01:06:41 +00001867
hyatt0c3a9862004-02-23 21:26:26 +00001868 for (RootInlineBox* line = last; line; line = line->nextRootBox())
1869 line->extractLine(); // Disconnect all line boxes from their render objects while preserving
1870 // their connections to one another.
mitz@apple.come1364202008-02-28 01:06:41 +00001871
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001872 layoutState.setEndLine(last);
hyatt0c3a9862004-02-23 21:26:26 +00001873}
1874
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001875bool RenderBlockFlow::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001876{
1877 LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop();
1878
akling@apple.com691cf5c2013-08-24 16:33:15 +00001879 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001880 if (paginated && layoutState.flowThread()) {
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001881 // Check all lines from here to the end, and see if the hypothetical new position for the lines will result
1882 // in a different available line width.
1883 for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) {
1884 if (paginated) {
1885 // This isn't the real move we're going to do, so don't update the line box's pagination
1886 // strut yet.
1887 LayoutUnit oldPaginationStrut = lineBox->paginationStrut();
1888 lineDelta -= oldPaginationStrut;
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001889 adjustLinePositionForPagination(lineBox, lineDelta, layoutState.flowThread());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001890 lineBox->setPaginationStrut(oldPaginationStrut);
1891 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001892 if (lineWidthForPaginatedLineChanged(lineBox, lineDelta, layoutState.flowThread()))
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001893 return false;
1894 }
1895 }
1896
1897 if (!lineDelta || !m_floatingObjects)
1898 return true;
1899
1900 // See if any floats end in the range along which we want to shift the lines vertically.
andersca@apple.com86298632013-11-10 19:32:33 +00001901 LayoutUnit logicalTop = std::min(logicalHeight(), layoutState.endLineLogicalTop());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001902
1903 RootInlineBox* lastLine = layoutState.endLine();
1904 while (RootInlineBox* nextLine = lastLine->nextRootBox())
1905 lastLine = nextLine;
1906
leviw@chromium.org3957b452012-05-01 00:06:37 +00001907 LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + absoluteValue(lineDelta);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001908
1909 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001910 auto end = floatingObjectSet.end();
1911 for (auto it = floatingObjectSet.begin(); it != end; ++it) {
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001912 FloatingObject* floatingObject = it->get();
1913 if (logicalBottomForFloat(floatingObject) >= logicalTop && logicalBottomForFloat(floatingObject) < logicalBottom)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001914 return false;
1915 }
1916
1917 return true;
1918}
1919
weinig@apple.com31324fd2013-10-28 19:22:51 +00001920bool RenderBlockFlow::lineWidthForPaginatedLineChanged(RootInlineBox* rootBox, LayoutUnit lineDelta, RenderFlowThread* flowThread) const
1921{
1922 if (!flowThread)
1923 return false;
1924
1925 RenderRegion* currentRegion = regionAtBlockOffset(rootBox->lineTopWithLeading() + lineDelta);
1926 // Just bail if the region didn't change.
1927 if (rootBox->containingRegion() == currentRegion)
1928 return false;
1929 return rootBox->paginatedLineWidth() != availableLogicalWidthForContent(currentRegion);
1930}
1931
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001932bool RenderBlockFlow::matchedEndLine(LineLayoutState& layoutState, const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001933{
mitz@apple.com15035e62008-07-05 20:44:44 +00001934 if (resolver.position() == endLineStart) {
1935 if (resolver.status() != endLineStatus)
mitz@apple.com40547b32008-03-18 04:04:34 +00001936 return false;
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001937 return checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00001938 }
hyatt0c3a9862004-02-23 21:26:26 +00001939
mitz@apple.come1364202008-02-28 01:06:41 +00001940 // The first clean line doesn't match, but we can check a handful of following lines to try
1941 // to match back up.
1942 static int numLines = 8; // The # of lines we're willing to match against.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001943 RootInlineBox* originalEndLine = layoutState.endLine();
1944 RootInlineBox* line = originalEndLine;
mitz@apple.come1364202008-02-28 01:06:41 +00001945 for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) {
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001946 if (line->lineBreakObj() == resolver.position().renderer() && line->lineBreakPos() == resolver.position().offset()) {
mitz@apple.come1364202008-02-28 01:06:41 +00001947 // We have a match.
mitz@apple.com15035e62008-07-05 20:44:44 +00001948 if (line->lineBreakBidiStatus() != resolver.status())
mitz@apple.come1364202008-02-28 01:06:41 +00001949 return false; // ...but the bidi state doesn't match.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001950
1951 bool matched = false;
mitz@apple.come1364202008-02-28 01:06:41 +00001952 RootInlineBox* result = line->nextRootBox();
hyatt@apple.com1fb7d582011-09-23 20:25:11 +00001953 layoutState.setEndLine(result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001954 if (result) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001955 layoutState.setEndLineLogicalTop(line->lineBottomWithLeading());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001956 matched = checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00001957 }
1958
mitz@apple.come1364202008-02-28 01:06:41 +00001959 // Now delete the lines that we failed to sync.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001960 deleteLineRange(layoutState, originalEndLine, result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001961 return matched;
hyatt0c3a9862004-02-23 21:26:26 +00001962 }
1963 }
mitz@apple.come1364202008-02-28 01:06:41 +00001964
hyatt0c3a9862004-02-23 21:26:26 +00001965 return false;
1966}
1967
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00001968bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj)
bdashccffb432007-07-13 11:51:40 +00001969{
1970 ASSERT(inlineObj->parent() == this);
1971
mitz@apple.com15035e62008-07-05 20:44:44 +00001972 InlineIterator it(this, inlineObj, 0);
rniwa@webkit.org40248422011-06-15 00:19:39 +00001973 // FIXME: We should pass correct value for WhitespacePosition.
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00001974 while (!it.atEnd() && !requiresLineBox(it))
mitz@apple.com1a301772008-03-11 18:30:36 +00001975 it.increment();
bdashccffb432007-07-13 11:51:40 +00001976
1977 return !it.atEnd();
1978}
1979
weinig@apple.com611b9292013-10-20 22:57:54 +00001980void RenderBlockFlow::addOverflowFromInlineChildren()
hyattb4b20872004-10-20 21:34:01 +00001981{
antti@apple.comfea51992013-10-28 13:39:23 +00001982 if (auto layout = simpleLineLayout()) {
antti@apple.com940f5872013-10-24 20:31:11 +00001983 ASSERT(!hasOverflowClip());
antti@apple.comfea51992013-10-28 13:39:23 +00001984 SimpleLineLayout::collectFlowOverflow(*this, *layout);
antti@apple.com940f5872013-10-24 20:31:11 +00001985 return;
1986 }
eae@chromium.org9717cd82012-11-07 18:33:44 +00001987 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit();
hyatt@apple.com592848f2010-12-06 20:03:43 +00001988 // FIXME: Need to find another way to do this, since scrollbars could show when we don't want them to.
akling@apple.com827be9c2013-10-29 02:58:43 +00001989 if (hasOverflowClip() && !endPadding && element() && element()->isRootEditableElement() && style().isLeftToRightDirection())
hyatt@apple.com592848f2010-12-06 20:03:43 +00001990 endPadding = 1;
hyattb4b20872004-10-20 21:34:01 +00001991 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
hyatt@apple.com592848f2010-12-06 20:03:43 +00001992 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
abucur@adobe.com6585d012013-09-04 08:26:41 +00001993 RenderRegion* region = curr->containingRegion();
1994 if (region)
1995 region->addLayoutOverflowForBox(this, curr->paddedLayoutOverflowRect(endPadding));
1996 if (!hasOverflowClip()) {
hyatt@apple.com61f25322011-03-31 20:40:48 +00001997 addVisualOverflow(curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
abucur@adobe.com6585d012013-09-04 08:26:41 +00001998 if (region)
1999 region->addVisualOverflowForBox(this, curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
2000 }
hyattb4b20872004-10-20 21:34:01 +00002001 }
2002}
2003
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00002004void RenderBlockFlow::deleteEllipsisLineBoxes()
hyatted77ad82004-06-15 07:21:23 +00002005{
akling@apple.com827be9c2013-10-29 02:58:43 +00002006 ETextAlign textAlign = style().textAlign();
2007 bool ltr = style().isLeftToRightDirection();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002008 bool firstLine = true;
2009 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
2010 if (curr->hasEllipsisBox()) {
2011 curr->clearTruncation();
2012
2013 // Shift the line back where it belongs if we cannot accomodate an ellipsis.
2014 float logicalLeft = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine);
2015 float availableLogicalWidth = logicalRightOffsetForLine(curr->lineTop(), false) - logicalLeft;
2016 float totalLogicalWidth = curr->logicalWidth();
2017 updateLogicalWidthForAlignment(textAlign, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
2018
2019 if (ltr)
2020 curr->adjustLogicalPosition((logicalLeft - curr->logicalLeft()), 0);
2021 else
2022 curr->adjustLogicalPosition(-(curr->logicalLeft() - logicalLeft), 0);
2023 }
2024 firstLine = false;
2025 }
hyatted77ad82004-06-15 07:21:23 +00002026}
2027
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00002028void RenderBlockFlow::checkLinesForTextOverflow()
hyatted77ad82004-06-15 07:21:23 +00002029{
2030 // Determine the width of the ellipsis using the current font.
darindbba2bb2007-01-11 12:23:49 +00002031 // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable"
akling@apple.com827be9c2013-10-29 02:58:43 +00002032 const Font& font = style().font();
bolsinga@apple.com97e42c42008-11-15 04:47:20 +00002033 DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
akling@apple.com827be9c2013-10-29 02:58:43 +00002034 const Font& firstLineFont = firstLineStyle().font();
2035 int firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle()));
2036 int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style()));
hyatted77ad82004-06-15 07:21:23 +00002037
2038 // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see
2039 // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and
2040 // check the left edge of the line box to see if it is less
2041 // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()"
akling@apple.com827be9c2013-10-29 02:58:43 +00002042 bool ltr = style().isLeftToRightDirection();
2043 ETextAlign textAlign = style().textAlign();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002044 bool firstLine = true;
hyatted77ad82004-06-15 07:21:23 +00002045 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
eae@chromium.org275da182012-12-19 23:07:55 +00002046 // FIXME: Use pixelSnappedLogicalRightOffsetForLine instead of snapping it ourselves once the column workaround in said method has been fixed.
2047 // https://bugs.webkit.org/show_bug.cgi?id=105461
commit-queue@webkit.orgbbac21e2013-06-21 15:45:21 +00002048 int blockRightEdge = snapSizeToPixel(logicalRightOffsetForLine(curr->lineTop(), firstLine), curr->x());
2049 int blockLeftEdge = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine);
eae@chromium.orgc491d962012-12-28 18:32:08 +00002050 int lineBoxEdge = ltr ? snapSizeToPixel(curr->x() + curr->logicalWidth(), curr->x()) : snapSizeToPixel(curr->x(), 0);
dglazkov@chromium.org28434e62009-05-13 22:30:10 +00002051 if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) {
hyattf918d2d2004-06-15 07:24:11 +00002052 // 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 +00002053 // can be truncated. In order for truncation to be possible, the line must have sufficient space to
2054 // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis
2055 // space.
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002056
2057 LayoutUnit width = firstLine ? firstLineEllipsisWidth : ellipsisWidth;
eae@chromium.orgee8613e2011-11-12 01:12:58 +00002058 LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002059 if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) {
2060 float totalLogicalWidth = curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width);
2061
akling@apple.comf294cf02013-07-17 18:46:39 +00002062 float logicalLeft = 0; // We are only interested in the delta from the base position.
commit-queue@webkit.orgbbac21e2013-06-21 15:45:21 +00002063 float truncatedWidth = pixelSnappedLogicalRightOffsetForLine(curr->lineTop(), firstLine);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002064 updateLogicalWidthForAlignment(textAlign, 0, logicalLeft, totalLogicalWidth, truncatedWidth, 0);
2065 if (ltr)
2066 curr->adjustLogicalPosition(logicalLeft, 0);
2067 else
2068 curr->adjustLogicalPosition(-(truncatedWidth - (logicalLeft + totalLogicalWidth)), 0);
2069 }
hyatted77ad82004-06-15 07:21:23 +00002070 }
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002071 firstLine = false;
hyatted77ad82004-06-15 07:21:23 +00002072 }
2073}
2074
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00002075bool RenderBlockFlow::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002076{
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002077 if (!positionNewFloats())
2078 return false;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002079
rniwa@webkit.org44424752011-04-14 00:58:40 +00002080 width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002081
hyatt@apple.comdd78df82011-09-27 22:11:41 +00002082 // We only connect floats to lines for pagination purposes if the floats occur at the start of
2083 // the line and the previous line had a hard break (so this line is either the first in the block
2084 // or follows a <br>).
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00002085 if (!newFloat->paginationStrut() || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002086 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002087
hyatt@apple.com46c65b32011-08-09 19:13:45 +00002088 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00002089 ASSERT(floatingObjectSet.last().get() == newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002090
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002091 LayoutUnit floatLogicalTop = logicalTopForFloat(newFloat);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00002092 int paginationStrut = newFloat->paginationStrut();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002093
hyatt@apple.com5950bd42011-09-27 20:39:57 +00002094 if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002095 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002096
darin@apple.com7cad7042013-09-24 05:53:55 +00002097 auto it = floatingObjectSet.end();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002098 --it; // Last float is newFloat, skip that one.
darin@apple.com7cad7042013-09-24 05:53:55 +00002099 auto begin = floatingObjectSet.begin();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002100 while (it != begin) {
2101 --it;
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002102 FloatingObject* floatingObject = it->get();
2103 if (floatingObject == lastFloatFromPreviousLine)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002104 break;
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002105 if (logicalTopForFloat(floatingObject) == logicalHeight() + lineInfo.floatPaginationStrut()) {
2106 floatingObject->setPaginationStrut(paginationStrut + floatingObject->paginationStrut());
weinig@apple.com12840dc2013-10-22 23:59:08 +00002107 RenderBox& floatBox = floatingObject->renderer();
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002108 setLogicalTopForChild(floatBox, logicalTopForChild(floatBox) + marginBeforeForChild(floatBox) + paginationStrut);
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00002109
2110 if (updateRegionRangeForBoxChild(floatingObject->renderer()))
2111 floatBox.setNeedsLayout(MarkOnlyThis);
2112 else if (floatBox.isRenderBlock())
weinig@apple.com12840dc2013-10-22 23:59:08 +00002113 toRenderBlock(floatBox).setChildNeedsLayout(MarkOnlyThis);
2114 floatBox.layoutIfNeeded();
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00002115
hyatt@apple.com46c65b32011-08-09 19:13:45 +00002116 // Save the old logical top before calling removePlacedObject which will set
2117 // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat.
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002118 LayoutUnit oldLogicalTop = logicalTopForFloat(floatingObject);
2119 m_floatingObjects->removePlacedObject(floatingObject);
2120 setLogicalTopForFloat(floatingObject, oldLogicalTop + paginationStrut);
2121 m_floatingObjects->addPlacedObject(floatingObject);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002122 }
2123 }
2124
hyatt@apple.comdd78df82011-09-27 22:11:41 +00002125 // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing
2126 // no content, then we don't want to improperly grow the height of the block.
2127 lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut);
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002128 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002129}
2130
robert@webkit.org82903f42012-08-28 19:18:40 +00002131LayoutUnit RenderBlock::startAlignedOffsetForLine(LayoutUnit position, bool firstLine)
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002132{
akling@apple.com827be9c2013-10-29 02:58:43 +00002133 ETextAlign textAlign = style().textAlign();
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002134
hyatt@apple.coma5626692013-11-18 23:08:30 +00002135 // <rdar://problem/15427571>
2136 // https://bugs.webkit.org/show_bug.cgi?id=124522
2137 // This quirk is for legacy content that doesn't work properly with the center positioning scheme
2138 // being honored (e.g., epubs).
2139 if (textAlign == TASTART || document().settings()->useLegacyTextAlignPositionedElementBehavior()) // FIXME: Handle TAEND here
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002140 return startOffsetForLine(position, firstLine);
2141
2142 // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here
robert@webkit.org82903f42012-08-28 19:18:40 +00002143 float totalLogicalWidth = 0;
2144 float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false);
2145 float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), false) - logicalLeft;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002146 updateLogicalWidthForAlignment(textAlign, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
robert@webkit.org7861a102011-09-22 17:16:47 +00002147
akling@apple.com827be9c2013-10-29 02:58:43 +00002148 if (!style().isLeftToRightDirection())
robert@webkit.org82903f42012-08-28 19:18:40 +00002149 return logicalWidth() - logicalLeft;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002150 return logicalLeft;
2151}
2152
abucur@adobe.comd40287b2013-10-08 17:33:05 +00002153void RenderBlockFlow::updateRegionForLine(RootInlineBox* lineBox) const
2154{
2155 ASSERT(lineBox);
2156 lineBox->setContainingRegion(regionAtBlockOffset(lineBox->lineTopWithLeading()));
2157
2158 RootInlineBox* prevLineBox = lineBox->prevRootBox();
2159 if (!prevLineBox)
2160 return;
2161
2162 // This check is more accurate than the one in |adjustLinePositionForPagination| because it takes into
2163 // account just the container changes between lines. The before mentioned function doesn't set the flag
2164 // correctly if the line is positioned at the top of the last fragment container.
2165 if (lineBox->containingRegion() != prevLineBox->containingRegion())
2166 lineBox->setIsFirstAfterPageBreak(true);
2167}
2168
hyattffe78712003-02-11 01:59:29 +00002169}