blob: 07e9c8a6863da6b0dad3db122d78fd0a4047e3e0 [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"
ossy@webkit.org66d8c0a2014-02-05 11:42:35 +000041#include "SVGRootInlineBox.h"
hyatt@apple.comcc1737c2010-09-16 20:20:02 +000042#include "Settings.h"
antti@apple.com940f5872013-10-24 20:31:11 +000043#include "SimpleLineLayoutFunctions.h"
dbates@webkit.orgf6f05a92010-05-17 04:58:25 +000044#include "TrailingFloatsRootInlineBox.h"
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +000045#include "VerticalPositionCache.h"
slewis@apple.coma7615ca2008-07-12 05:51:33 +000046#include <wtf/RefCountedLeakCounter.h>
bolsinga@apple.com97e42c42008-11-15 04:47:20 +000047#include <wtf/StdLibExtras.h>
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +000048
darinb9481ed2006-03-20 02:57:59 +000049namespace WebCore {
mjsfe301d72003-10-02 18:46:18 +000050
leviw@chromium.orge7812f32012-02-07 23:46:40 +000051static void determineDirectionality(TextDirection& dir, InlineIterator iter)
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000052{
53 while (!iter.atEnd()) {
54 if (iter.atParagraphSeparator())
55 return;
56 if (UChar current = iter.current()) {
darin@apple.com2eb5f4d2013-10-12 04:16:42 +000057 UCharDirection charDirection = u_charDirection(current);
58 if (charDirection == U_LEFT_TO_RIGHT) {
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000059 dir = LTR;
60 return;
61 }
darin@apple.com2eb5f4d2013-10-12 04:16:42 +000062 if (charDirection == U_RIGHT_TO_LEFT || charDirection == U_RIGHT_TO_LEFT_ARABIC) {
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000063 dir = RTL;
64 return;
65 }
66 }
67 iter.increment();
68 }
69}
70
zoltan@webkit.org64be1222013-11-15 21:40:59 +000071inline BidiRun* createRun(int start, int end, RenderObject* obj, InlineBidiResolver& resolver)
eric@webkit.org5bee2942011-04-08 02:12:31 +000072{
akling@apple.com7506fda2013-11-07 10:12:36 +000073 ASSERT(obj);
74 return new BidiRun(start, end, *obj, resolver.context(), resolver.dir());
eric@webkit.org5bee2942011-04-08 02:12:31 +000075}
76
bjonesbe@adobe.com24199752013-10-08 23:20:42 +000077void RenderBlockFlow::appendRunsForObject(BidiRunList<BidiRun>& runs, int start, int end, RenderObject* obj, InlineBidiResolver& resolver)
hyatt33f8d492002-11-12 21:44:52 +000078{
leviw@chromium.orgd8df17d2012-05-24 21:47:47 +000079 if (start > end || shouldSkipCreatingRunsForObject(obj))
hyatteb003b82002-11-15 22:35:10 +000080 return;
hyatt85586af2003-02-19 23:22:42 +000081
hyatt@apple.comb3466af2009-06-13 06:04:40 +000082 LineMidpointState& lineMidpointState = resolver.midpointState();
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000083 bool haveNextMidpoint = (lineMidpointState.currentMidpoint() < lineMidpointState.numMidpoints());
mitz@apple.com15035e62008-07-05 20:44:44 +000084 InlineIterator nextMidpoint;
hyatt85586af2003-02-19 23:22:42 +000085 if (haveNextMidpoint)
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000086 nextMidpoint = lineMidpointState.midpoints()[lineMidpointState.currentMidpoint()];
87 if (lineMidpointState.betweenMidpoints()) {
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +000088 if (!(haveNextMidpoint && nextMidpoint.renderer() == obj))
hyatt33f8d492002-11-12 21:44:52 +000089 return;
eric@webkit.org060caf62011-05-03 22:11:39 +000090 // This is a new start point. Stop ignoring objects and
hyatt33f8d492002-11-12 21:44:52 +000091 // adjust our start.
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000092 lineMidpointState.setBetweenMidpoints(false);
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +000093 start = nextMidpoint.offset();
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000094 lineMidpointState.incrementCurrentMidpoint();
hyatt33f8d492002-11-12 21:44:52 +000095 if (start < end)
eric@webkit.org5bee2942011-04-08 02:12:31 +000096 return appendRunsForObject(runs, start, end, obj, resolver);
mitz@apple.com15035e62008-07-05 20:44:44 +000097 } else {
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +000098 if (!haveNextMidpoint || (obj != nextMidpoint.renderer())) {
eric@webkit.org5bee2942011-04-08 02:12:31 +000099 runs.addRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000100 return;
101 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000102
hyatt78b85132004-03-29 20:07:45 +0000103 // An end midpoint has been encountered within our object. We
hyatt33f8d492002-11-12 21:44:52 +0000104 // need to go ahead and append a run with our endpoint.
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +0000105 if (static_cast<int>(nextMidpoint.offset() + 1) <= end) {
zoltan@webkit.org7585ad52014-01-21 21:33:22 +0000106 lineMidpointState.setBetweenMidpoints(true);
107 lineMidpointState.incrementCurrentMidpoint();
mmaxfield@apple.com0682d512014-03-25 20:15:14 +0000108 // The end of the line is before the object we're inspecting. Skip everything and return
109 if (nextMidpoint.refersToEndOfPreviousNode())
110 return;
111 if (static_cast<int>(nextMidpoint.offset() + 1) > start)
112 runs.addRun(createRun(start, nextMidpoint.offset() + 1, obj, resolver));
113 appendRunsForObject(runs, nextMidpoint.offset() + 1, end, obj, resolver);
mitz@apple.com15035e62008-07-05 20:44:44 +0000114 } else
eric@webkit.org5bee2942011-04-08 02:12:31 +0000115 runs.addRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000116 }
117}
118
akling@apple.comb5f24642013-11-06 04:47:12 +0000119std::unique_ptr<RootInlineBox> RenderBlockFlow::createRootInlineBox()
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000120{
akling@apple.comb5f24642013-11-06 04:47:12 +0000121 return std::make_unique<RootInlineBox>(*this);
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000122}
123
124RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox()
125{
akling@apple.comb5f24642013-11-06 04:47:12 +0000126 auto newRootBox = createRootInlineBox();
127 RootInlineBox* rootBox = newRootBox.get();
128 m_lineBoxes.appendLineBox(std::move(newRootBox));
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000129
akling@apple.comee3c8df2013-11-06 08:09:44 +0000130 if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && firstRootBox() == rootBox) {
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000131 if (AXObjectCache* cache = document().existingAXObjectCache())
132 cache->recomputeIsIgnored(this);
133 }
134
135 return rootBox;
136}
137
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000138static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRootLineBox, bool isOnlyRun = false)
139{
140 if (isRootLineBox)
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000141 return toRenderBlockFlow(obj)->createAndAppendRootInlineBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000142
antti@apple.com9d8157e2013-09-17 15:13:37 +0000143 if (obj->isText())
144 return toRenderText(obj)->createInlineTextBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000145
akling@apple.comb5f24642013-11-06 04:47:12 +0000146 if (obj->isBox()) {
147 // FIXME: This is terrible. This branch returns an *owned* pointer!
148 return toRenderBox(obj)->createInlineBox().release();
149 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000150
antti@apple.com3014ac02013-09-18 14:33:55 +0000151 if (obj->isLineBreak()) {
akling@apple.comb5f24642013-11-06 04:47:12 +0000152 // FIXME: This is terrible. This branch returns an *owned* pointer!
akling@apple.comd3ec5ef2013-11-07 03:30:11 +0000153 auto inlineBox = toRenderLineBreak(obj)->createInlineBox().release();
antti@apple.com9d8157e2013-09-17 15:13:37 +0000154 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
155 // (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 +0000156 inlineBox->setBehavesLikeText(isOnlyRun || obj->document().inNoQuirksMode() || obj->isLineBreakOpportunity());
antti@apple.com9d8157e2013-09-17 15:13:37 +0000157 return inlineBox;
158 }
159
eric@webkit.org49b9d952009-07-03 01:29:07 +0000160 return toRenderInline(obj)->createAndAppendInlineFlowBox();
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000161}
162
weinig@apple.com12840dc2013-10-22 23:59:08 +0000163static inline void dirtyLineBoxesForRenderer(RenderObject& renderer, bool fullLayout)
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000164{
weinig@apple.com12840dc2013-10-22 23:59:08 +0000165 if (renderer.isText()) {
166 RenderText& renderText = toRenderText(renderer);
esprehn@chromium.org7745ffb2013-02-19 21:51:19 +0000167 updateCounterIfNeeded(renderText);
weinig@apple.com12840dc2013-10-22 23:59:08 +0000168 renderText.dirtyLineBoxes(fullLayout);
169 } else if (renderer.isLineBreak())
170 toRenderLineBreak(renderer).dirtyLineBoxes(fullLayout);
antti@apple.com9d8157e2013-09-17 15:13:37 +0000171 else
weinig@apple.com12840dc2013-10-22 23:59:08 +0000172 toRenderInline(renderer).dirtyLineBoxes(fullLayout);
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000173}
174
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000175static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox)
176{
177 do {
178 if (parentBox->isConstructed() || parentBox->nextOnLine())
179 return true;
180 parentBox = parentBox->parent();
181 } while (parentBox);
182 return false;
183}
184
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000185InlineFlowBox* RenderBlockFlow::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox)
hyattffe78712003-02-11 01:59:29 +0000186{
187 // See if we have an unconstructed line box for this object that is also
188 // the last item on the line.
hyatt1d5d87b2007-04-24 04:55:54 +0000189 unsigned lineDepth = 1;
hyatt1d5d87b2007-04-24 04:55:54 +0000190 InlineFlowBox* parentBox = 0;
191 InlineFlowBox* result = 0;
akling@apple.com827be9c2013-10-29 02:58:43 +0000192 bool hasDefaultLineBoxContain = style().lineBoxContain() == RenderStyle::initialLineBoxContain();
hyatt1d5d87b2007-04-24 04:55:54 +0000193 do {
inferno@chromium.org14b04142013-02-04 18:43:03 +0000194 ASSERT_WITH_SECURITY_IMPLICATION(obj->isRenderInline() || obj == this);
eric@webkit.org060caf62011-05-03 22:11:39 +0000195
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000196 RenderInline* inlineFlow = (obj != this) ? toRenderInline(obj) : 0;
197
hyatt1d5d87b2007-04-24 04:55:54 +0000198 // Get the last box we made for this render object.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000199 parentBox = inlineFlow ? inlineFlow->lastLineBox() : toRenderBlockFlow(obj)->lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000200
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000201 // If this box or its ancestor is constructed then it is from a previous line, and we need
202 // 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 +0000203 // something following it on the line, then we know we have to make a new box
204 // as well. In this situation our inline has actually been split in two on
205 // the same line (this can happen with very fancy language mixtures).
206 bool constructedNewBox = false;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000207 bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes();
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000208 bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox);
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000209 if (allowedToConstructNewBox && !canUseExistingParentBox) {
hyatt1d5d87b2007-04-24 04:55:54 +0000210 // We need to make a new box for this render object. Once
211 // made, we need to place it at the end of the current line.
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000212 InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this);
inferno@chromium.org14b04142013-02-04 18:43:03 +0000213 ASSERT_WITH_SECURITY_IMPLICATION(newBox->isInlineFlowBox());
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000214 parentBox = toInlineFlowBox(newBox);
antti@apple.comb0608f62013-09-28 18:30:16 +0000215 parentBox->setIsFirstLine(lineInfo.isFirstLine());
hyatt@apple.com2a5eb212011-03-22 23:21:54 +0000216 parentBox->setIsHorizontal(isHorizontalWritingMode());
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000217 if (!hasDefaultLineBoxContain)
218 parentBox->clearDescendantsHaveSameLineHeightAndBaseline();
hyatt1d5d87b2007-04-24 04:55:54 +0000219 constructedNewBox = true;
220 }
mitz@apple.come1364202008-02-28 01:06:41 +0000221
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000222 if (constructedNewBox || canUseExistingParentBox) {
223 if (!result)
224 result = parentBox;
hyatt1d5d87b2007-04-24 04:55:54 +0000225
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000226 // If we have hit the block itself, then |box| represents the root
227 // inline box for the line, and it doesn't have to be appended to any parent
228 // inline.
229 if (childBox)
230 parentBox->addToLine(childBox);
mitz@apple.come1364202008-02-28 01:06:41 +0000231
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000232 if (!constructedNewBox || obj == this)
233 break;
mitz@apple.come1364202008-02-28 01:06:41 +0000234
eric@webkit.org060caf62011-05-03 22:11:39 +0000235 childBox = parentBox;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000236 }
mitz@apple.come1364202008-02-28 01:06:41 +0000237
hyatt1d5d87b2007-04-24 04:55:54 +0000238 // If we've exceeded our line depth, then jump straight to the root and skip all the remaining
239 // intermediate inline flows.
240 obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent();
hyattffe78712003-02-11 01:59:29 +0000241
hyatt1d5d87b2007-04-24 04:55:54 +0000242 } while (true);
243
244 return result;
hyattffe78712003-02-11 01:59:29 +0000245}
246
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000247template <typename CharacterType>
248static inline bool endsWithASCIISpaces(const CharacterType* characters, unsigned pos, unsigned end)
249{
250 while (isASCIISpace(characters[pos])) {
251 pos++;
252 if (pos >= end)
253 return true;
254 }
255 return false;
256}
257
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000258static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns)
hyattffe78712003-02-11 01:59:29 +0000259{
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000260 BidiRun* run = bidiRuns.logicallyLastRun();
261 if (!run)
262 return true;
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000263 unsigned pos = run->stop();
akling@apple.com7506fda2013-11-07 10:12:36 +0000264 const RenderObject& r = run->renderer();
265 if (!r.isText())
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000266 return false;
akling@apple.com7506fda2013-11-07 10:12:36 +0000267 const RenderText& renderText = toRenderText(r);
268 unsigned length = renderText.textLength();
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000269 if (pos >= length)
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000270 return true;
271
akling@apple.com7506fda2013-11-07 10:12:36 +0000272 if (renderText.is8Bit())
273 return endsWithASCIISpaces(renderText.characters8(), pos, length);
274 return endsWithASCIISpaces(renderText.characters16(), pos, length);
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000275}
276
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000277RootInlineBox* RenderBlockFlow::constructLine(BidiRunList<BidiRun>& bidiRuns, const LineInfo& lineInfo)
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000278{
279 ASSERT(bidiRuns.firstRun());
hyattffe78712003-02-11 01:59:29 +0000280
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000281 bool rootHasSelectedChildren = false;
hyattffe78712003-02-11 01:59:29 +0000282 InlineFlowBox* parentBox = 0;
robert@webkit.org8cbab142011-12-30 20:58:29 +0000283 int runCount = bidiRuns.runCount() - lineInfo.runsFromLeadingWhitespace();
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000284 for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) {
hyattffe78712003-02-11 01:59:29 +0000285 // Create a box for our object.
robert@webkit.org8cbab142011-12-30 20:58:29 +0000286 bool isOnlyRun = (runCount == 1);
akling@apple.com7506fda2013-11-07 10:12:36 +0000287 if (runCount == 2 && !r->renderer().isListMarker())
288 isOnlyRun = (!style().isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->renderer().isListMarker();
mitz@apple.come1364202008-02-28 01:06:41 +0000289
robert@webkit.org56e5a9f2012-02-17 21:10:42 +0000290 if (lineInfo.isEmpty())
291 continue;
292
akling@apple.com7506fda2013-11-07 10:12:36 +0000293 InlineBox* box = createInlineBoxForRenderer(&r->renderer(), false, isOnlyRun);
294 r->setBox(*box);
hyattffe78712003-02-11 01:59:29 +0000295
akling@apple.com0b8172b72013-08-31 18:34:23 +0000296 if (!rootHasSelectedChildren && box->renderer().selectionState() != RenderObject::SelectionNone)
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000297 rootHasSelectedChildren = true;
298
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000299 // If we have no parent box yet, or if the run is not simply a sibling,
300 // then we need to construct inline boxes as necessary to properly enclose the
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000301 // run's inline box. Segments can only be siblings at the root level, as
302 // they are positioned separately.
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000303 if (!parentBox || &parentBox->renderer() != r->renderer().parent()) {
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000304 // Create new inline boxes all the way back to the appropriate insertion point.
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000305 parentBox = createLineBoxes(r->renderer().parent(), lineInfo, box);
306 } else {
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000307 // Append the inline box to this line.
308 parentBox->addToLine(box);
309 }
mitz@apple.com576e84e2008-04-24 19:09:48 +0000310
akling@apple.com7506fda2013-11-07 10:12:36 +0000311 bool visuallyOrdered = r->renderer().style().rtlOrdering() == VisualOrder;
xji@chromium.org6b0c0172011-02-14 19:21:12 +0000312 box->setBidiLevel(r->level());
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000313
314 if (box->isInlineTextBox()) {
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000315 InlineTextBox* text = toInlineTextBox(box);
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000316 text->setStart(r->m_start);
317 text->setLen(r->m_stop - r->m_start);
rniwa@webkit.org296fcae2012-03-29 09:48:42 +0000318 text->setDirOverride(r->dirOverride(visuallyOrdered));
mitz@apple.comb2107652010-06-21 16:54:52 +0000319 if (r->m_hasHyphen)
320 text->setHasHyphen(true);
hyatt0c3a9862004-02-23 21:26:26 +0000321 }
hyattffe78712003-02-11 01:59:29 +0000322 }
323
324 // We should have a root inline box. It should be unconstructed and
325 // be the last continuation of our line list.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000326 ASSERT(lastRootBox() && !lastRootBox()->isConstructed());
hyattffe78712003-02-11 01:59:29 +0000327
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000328 // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box
329 // from the bidi runs walk above has a selection state.
330 if (rootHasSelectedChildren)
akling@apple.comee3c8df2013-11-06 08:09:44 +0000331 lastRootBox()->root().setHasSelectedChildren(true);
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000332
hyattffe78712003-02-11 01:59:29 +0000333 // Set bits on our inline flow boxes that indicate which sides should
334 // paint borders/margins/padding. This knowledge will ultimately be used when
335 // we determine the horizontal positions and widths of all the inline boxes on
336 // the line.
akling@apple.com7506fda2013-11-07 10:12:36 +0000337 bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->renderer().isText() ? !reachedEndOfTextRenderer(bidiRuns) : true;
338 lastRootBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, &bidiRuns.logicallyLastRun()->renderer());
hyattffe78712003-02-11 01:59:29 +0000339
340 // Now mark the line boxes as being constructed.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000341 lastRootBox()->setConstructed();
hyattffe78712003-02-11 01:59:29 +0000342
343 // Return the last line.
hyatt0c3a9862004-02-23 21:26:26 +0000344 return lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000345}
346
weinig@apple.com6b4a24142014-01-05 00:28:39 +0000347ETextAlign RenderBlockFlow::textAlignmentForLine(bool endsWithSoftBreak) const
mitz@apple.com390fa322011-02-24 23:07:06 +0000348{
akling@apple.com827be9c2013-10-29 02:58:43 +0000349 ETextAlign alignment = style().textAlign();
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000350 if (endsWithSoftBreak)
351 return alignment;
mitz@apple.com390fa322011-02-24 23:07:06 +0000352
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000353#if !ENABLE(CSS3_TEXT)
354 return (alignment == JUSTIFY) ? TASTART : alignment;
355#else
356 if (alignment != JUSTIFY)
357 return alignment;
358
359 TextAlignLast alignmentLast = style().textAlignLast();
360 switch (alignmentLast) {
361 case TextAlignLastStart:
362 return TASTART;
363 case TextAlignLastEnd:
364 return TAEND;
365 case TextAlignLastLeft:
366 return LEFT;
367 case TextAlignLastRight:
368 return RIGHT;
369 case TextAlignLastCenter:
370 return CENTER;
371 case TextAlignLastJustify:
372 return JUSTIFY;
373 case TextAlignLastAuto:
374 if (style().textJustify() == TextJustifyDistribute)
375 return JUSTIFY;
376 return TASTART;
377 }
mitz@apple.com390fa322011-02-24 23:07:06 +0000378 return alignment;
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000379#endif
mitz@apple.com390fa322011-02-24 23:07:06 +0000380}
381
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000382static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
383{
384 // The direction of the block should determine what happens with wide lines.
385 // In particular with RTL blocks, wide lines should still spill out to the left.
386 if (isLeftToRightDirection) {
387 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
andersca@apple.com86298632013-11-10 19:32:33 +0000388 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000389 return;
390 }
391
392 if (trailingSpaceRun)
akling@apple.com7506fda2013-11-07 10:12:36 +0000393 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000394 else if (totalLogicalWidth > availableLogicalWidth)
395 logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
396}
397
398static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
399{
400 // Wide lines spill out of the block based off direction.
401 // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
402 // side of the block.
403 if (isLeftToRightDirection) {
404 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000405 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
406 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000407 }
408 if (totalLogicalWidth < availableLogicalWidth)
409 logicalLeft += availableLogicalWidth - totalLogicalWidth;
410 return;
411 }
412
413 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
andersca@apple.com86298632013-11-10 19:32:33 +0000414 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
akling@apple.com7506fda2013-11-07 10:12:36 +0000415 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000416 } else
417 logicalLeft += availableLogicalWidth - totalLogicalWidth;
418}
419
420static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
421{
422 float trailingSpaceWidth = 0;
423 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000424 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
andersca@apple.com86298632013-11-10 19:32:33 +0000425 trailingSpaceWidth = std::min(trailingSpaceRun->box()->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2);
426 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000427 }
428 if (isLeftToRightDirection)
andersca@apple.com86298632013-11-10 19:32:33 +0000429 logicalLeft += std::max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000430 else
431 logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
432}
433
weinig@apple.com12840dc2013-10-22 23:59:08 +0000434void RenderBlockFlow::setMarginsForRubyRun(BidiRun* run, RenderRubyRun& renderer, RenderObject* previousObject, const LineInfo& lineInfo)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000435{
436 int startOverhang;
437 int endOverhang;
438 RenderObject* nextObject = 0;
439 for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000440 if (!runWithNextObject->renderer().isOutOfFlowPositioned() && !runWithNextObject->box()->isLineBreak()) {
441 nextObject = &runWithNextObject->renderer();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000442 break;
443 }
444 }
akling@apple.com827be9c2013-10-29 02:58:43 +0000445 renderer.getOverhang(lineInfo.isFirstLine(), renderer.style().isLeftToRightDirection() ? previousObject : nextObject, renderer.style().isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000446 setMarginStartForChild(renderer, -startOverhang);
447 setMarginEndForChild(renderer, -endOverhang);
448}
449
450static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText* renderer, float xPos, const LineInfo& lineInfo,
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000451 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000452{
453 HashSet<const SimpleFontData*> fallbackFonts;
454 GlyphOverflow glyphOverflow;
antti@apple.comb0608f62013-09-28 18:30:16 +0000455
456 const Font& font = lineStyle(*renderer->parent(), lineInfo).font();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000457 // Always compute glyph overflow if the block's line-box-contain value is "glyphs".
458 if (lineBox->fitsToGlyphs()) {
459 // If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization
460 // will keep us from computing glyph bounds in nearly all cases.
461 bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading();
akling@apple.com7506fda2013-11-07 10:12:36 +0000462 int baselineShift = lineBox->verticalPositionForBox(run->box(), verticalPositionCache);
enrica@apple.com885c84d2012-10-10 05:48:51 +0000463 int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0;
464 int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0;
465 int boxAscent = font.fontMetrics().ascent() - baselineShift;
466 int boxDescent = font.fontMetrics().descent() + baselineShift;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000467 if (boxAscent > rootDescent || boxDescent > rootAscent)
468 glyphOverflow.computeBounds = true;
469 }
470
leviw@chromium.orgd32486e2012-03-16 10:52:56 +0000471 LayoutUnit hyphenWidth = 0;
akling@apple.com7506fda2013-11-07 10:12:36 +0000472 if (toInlineTextBox(run->box())->hasHyphen())
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000473 hyphenWidth = measureHyphenWidth(renderer, font, &fallbackFonts);
antti@apple.comb0608f62013-09-28 18:30:16 +0000474
enrica@apple.com885c84d2012-10-10 05:48:51 +0000475 float measuredWidth = 0;
476
enrica@apple.com885c84d2012-10-10 05:48:51 +0000477 bool kerningIsEnabled = font.typesettingFeatures() & Kerning;
leviw@chromium.orgd70f4cc2013-03-28 21:03:44 +0000478 bool canUseSimpleFontCodePath = renderer->canUseSimpleFontCodePath();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000479
480 // Since we don't cache glyph overflows, we need to re-measure the run if
481 // the style is linebox-contain: glyph.
482
leviw@chromium.orgd70f4cc2013-03-28 21:03:44 +0000483 if (!lineBox->fitsToGlyphs() && canUseSimpleFontCodePath) {
enrica@apple.com885c84d2012-10-10 05:48:51 +0000484 int lastEndOffset = run->m_start;
485 for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOffset < run->m_stop; ++i) {
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000486 WordMeasurement& wordMeasurement = wordMeasurements[i];
487 if (wordMeasurement.width <= 0 || wordMeasurement.startOffset == wordMeasurement.endOffset)
enrica@apple.com885c84d2012-10-10 05:48:51 +0000488 continue;
489 if (wordMeasurement.renderer != renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop)
490 continue;
491
492 lastEndOffset = wordMeasurement.endOffset;
493 if (kerningIsEnabled && lastEndOffset == run->m_stop) {
dino@apple.com7c50e7c2013-03-18 18:01:05 +0000494 int wordLength = lastEndOffset - wordMeasurement.startOffset;
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000495 GlyphOverflow overflow;
496 measuredWidth += renderer->width(wordMeasurement.startOffset, wordLength, xPos + measuredWidth, lineInfo.isFirstLine(),
497 &wordMeasurement.fallbackFonts, &overflow);
dino@apple.comd0b89252013-05-10 18:20:28 +0000498 UChar c = renderer->characterAt(wordMeasurement.startOffset);
499 if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t'))
mmaxfield@apple.com516f09b2014-01-11 00:31:19 +0000500 measuredWidth += renderer->style().font().wordSpacing();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000501 } else
502 measuredWidth += wordMeasurement.width;
503 if (!wordMeasurement.fallbackFonts.isEmpty()) {
504 HashSet<const SimpleFontData*>::const_iterator end = wordMeasurement.fallbackFonts.end();
505 for (HashSet<const SimpleFontData*>::const_iterator it = wordMeasurement.fallbackFonts.begin(); it != end; ++it)
506 fallbackFonts.add(*it);
507 }
508 }
509 if (measuredWidth && lastEndOffset != run->m_stop) {
510 // If we don't have enough cached data, we'll measure the run again.
511 measuredWidth = 0;
512 fallbackFonts.clear();
513 }
514 }
enrica@apple.com885c84d2012-10-10 05:48:51 +0000515
516 if (!measuredWidth)
517 measuredWidth = renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow);
518
akling@apple.com7506fda2013-11-07 10:12:36 +0000519 run->box()->setLogicalWidth(measuredWidth + hyphenWidth);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000520 if (!fallbackFonts.isEmpty()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000521 ASSERT(run->box()->behavesLikeText());
andersca@apple.com86298632013-11-10 19:32:33 +0000522 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->box()), std::make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000523 ASSERT(it->value.first.isEmpty());
524 copyToVector(fallbackFonts, it->value.first);
akling@apple.com7506fda2013-11-07 10:12:36 +0000525 run->box()->parent()->clearDescendantsHaveSameLineHeightAndBaseline();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000526 }
527 if ((glyphOverflow.top || glyphOverflow.bottom || glyphOverflow.left || glyphOverflow.right)) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000528 ASSERT(run->box()->behavesLikeText());
andersca@apple.com86298632013-11-10 19:32:33 +0000529 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->box()), std::make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000530 it->value.second = glyphOverflow;
akling@apple.com7506fda2013-11-07 10:12:36 +0000531 run->box()->clearKnownToHaveNoOverflow();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000532 }
533}
534
535static inline void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth)
536{
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000537 if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth)
538 return;
539
540 size_t i = 0;
541 for (BidiRun* r = firstRun; r; r = r->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000542 if (!r->box() || r == trailingSpaceRun)
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000543 continue;
544
akling@apple.com7506fda2013-11-07 10:12:36 +0000545 if (r->renderer().isText()) {
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000546 unsigned opportunitiesInRun = expansionOpportunities[i++];
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000547
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000548 ASSERT(opportunitiesInRun <= expansionOpportunityCount);
549
550 // Only justify text if whitespace is collapsed.
akling@apple.com7506fda2013-11-07 10:12:36 +0000551 if (r->renderer().style().collapseWhiteSpace()) {
552 InlineTextBox* textBox = toInlineTextBox(r->box());
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000553 int expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
554 textBox->setExpansion(expansion);
555 totalLogicalWidth += expansion;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000556 }
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000557 expansionOpportunityCount -= opportunitiesInRun;
558 if (!expansionOpportunityCount)
559 break;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000560 }
561 }
562}
563
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000564void RenderBlockFlow::updateLogicalWidthForAlignment(const ETextAlign& textAlign, const RootInlineBox* rootInlineBox, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount)
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000565{
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000566 TextDirection direction;
567 if (rootInlineBox && style().unicodeBidi() == Plaintext)
568 direction = rootInlineBox->direction();
569 else
570 direction = style().direction();
571
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000572 // Armed with the total width of the line (without justification),
573 // we now examine our text-align property in order to determine where to position the
574 // objects horizontally. The total width of the line can be increased if we end up
575 // justifying text.
576 switch (textAlign) {
577 case LEFT:
578 case WEBKIT_LEFT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000579 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000580 break;
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000581 case RIGHT:
582 case WEBKIT_RIGHT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000583 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000584 break;
585 case CENTER:
586 case WEBKIT_CENTER:
akling@apple.com827be9c2013-10-29 02:58:43 +0000587 updateLogicalWidthForCenterAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000588 break;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000589 case JUSTIFY:
590 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
591 if (expansionOpportunityCount) {
592 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000593 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
594 trailingSpaceRun->box()->setLogicalWidth(0);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000595 }
596 break;
597 }
joepeck@webkit.orgaa676ee52014-01-28 04:04:52 +0000598 FALLTHROUGH;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000599 case TASTART:
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000600 if (direction == LTR)
akling@apple.com827be9c2013-10-29 02:58:43 +0000601 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000602 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000603 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000604 break;
605 case TAEND:
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000606 if (direction == LTR)
akling@apple.com827be9c2013-10-29 02:58:43 +0000607 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000608 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000609 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000610 break;
611 }
612}
613
weinig@apple.come9621c32014-01-04 20:53:51 +0000614static 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 +0000615{
weinig@apple.come9621c32014-01-04 20:53:51 +0000616 LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight);
617 lineLogicalLeft = block.pixelSnappedLogicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
618 lineLogicalRight = block.pixelSnappedLogicalRightOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
robert@webkit.org0903cf52012-12-11 18:14:16 +0000619 availableLogicalWidth = lineLogicalRight - lineLogicalLeft;
620}
621
weinig@apple.come9621c32014-01-04 20:53:51 +0000622void 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 +0000623{
mitz@apple.com390fa322011-02-24 23:07:06 +0000624 ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
robert@webkit.org4f76df92012-07-03 17:41:35 +0000625
robert@webkit.org328ecd02012-08-09 21:12:44 +0000626 // 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
627 // box is only affected if it is the first child of its parent element."
commit-queue@webkit.orgab781b02013-04-03 01:32:24 +0000628 // CSS3 "text-indent", "-webkit-each-line" affects the first line of the block container as well as each line after a forced line break,
629 // but does not affect lines after a soft wrap break.
630 bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this);
631 bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox()->endsWithBreak();
akling@apple.com827be9c2013-10-29 02:58:43 +0000632 IndentTextOrNot shouldIndentText = requiresIndent(isFirstLine, isAfterHardLineBreak, style());
robert@webkit.org0903cf52012-12-11 18:14:16 +0000633 float lineLogicalLeft;
634 float lineLogicalRight;
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000635 float availableLogicalWidth;
weinig@apple.come9621c32014-01-04 20:53:51 +0000636 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000637 bool needsWordSpacing;
robert@webkit.org0903cf52012-12-11 18:14:16 +0000638
akling@apple.com7506fda2013-11-07 10:12:36 +0000639 if (firstRun && firstRun->renderer().isReplaced()) {
640 RenderBox& renderBox = toRenderBox(firstRun->renderer());
weinig@apple.come9621c32014-01-04 20:53:51 +0000641 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight());
robert@webkit.org0903cf52012-12-11 18:14:16 +0000642 }
643
644 computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000645 // The widths of all runs are now known. We can now place every inline box (and
646 // compute accurate widths for the inline flow boxes).
647 needsWordSpacing = false;
648 lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing, textBoxDataMap);
649}
mitz@apple.com390fa322011-02-24 23:07:06 +0000650
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000651BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBox* lineBox, const LineInfo& lineInfo, ETextAlign textAlign, float& logicalLeft,
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000652 float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache,
653 WordMeasurements& wordMeasurements)
654{
darin06dcb9c2005-08-15 04:31:09 +0000655 bool needsWordSpacing = false;
mitz@apple.com390fa322011-02-24 23:07:06 +0000656 float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();
mitz@apple.com86470c82011-01-27 01:39:27 +0000657 unsigned expansionOpportunityCount = 0;
658 bool isAfterExpansion = true;
659 Vector<unsigned, 16> expansionOpportunities;
mitz@apple.comddb59872011-04-05 05:21:16 +0000660 RenderObject* previousObject = 0;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000661
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000662 BidiRun* r = firstRun;
663 for (; r; r = r->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000664 if (!r->box() || r->renderer().isOutOfFlowPositioned() || r->box()->isLineBreak())
hyatt98ee7e42003-05-14 01:39:15 +0000665 continue; // Positioned objects are only participating to figure out their
666 // correct static x position. They have no effect on the width.
hyatt0c05e102006-04-14 08:15:00 +0000667 // Similarly, line break boxes have no effect on the width.
akling@apple.com7506fda2013-11-07 10:12:36 +0000668 if (r->renderer().isText()) {
669 RenderText& rt = toRenderText(r->renderer());
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000670 if (textAlign == JUSTIFY && r != trailingSpaceRun) {
mitz@apple.com80968932011-03-26 00:46:26 +0000671 if (!isAfterExpansion)
akling@apple.com7506fda2013-11-07 10:12:36 +0000672 toInlineTextBox(r->box())->setCanHaveLeadingExpansion(true);
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000673 unsigned opportunitiesInRun;
akling@apple.com7506fda2013-11-07 10:12:36 +0000674 if (rt.is8Bit())
675 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 +0000676 else
akling@apple.com7506fda2013-11-07 10:12:36 +0000677 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 +0000678 expansionOpportunities.append(opportunitiesInRun);
679 expansionOpportunityCount += opportunitiesInRun;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000680 }
681
akling@apple.com7506fda2013-11-07 10:12:36 +0000682 if (int length = rt.textLength()) {
683 if (!r->m_start && needsWordSpacing && isSpaceOrNewline(rt.characterAt(r->m_start)))
684 totalLogicalWidth += lineStyle(*rt.parent(), lineInfo).font().wordSpacing();
685 needsWordSpacing = !isSpaceOrNewline(rt.characterAt(r->m_stop - 1)) && r->m_stop == length;
darin06dcb9c2005-08-15 04:31:09 +0000686 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000687
akling@apple.com7506fda2013-11-07 10:12:36 +0000688 setLogicalWidthForTextRun(lineBox, r, &rt, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
mitz@apple.com86470c82011-01-27 01:39:27 +0000689 } else {
690 isAfterExpansion = false;
akling@apple.com7506fda2013-11-07 10:12:36 +0000691 if (!r->renderer().isRenderInline()) {
692 RenderBox& renderBox = toRenderBox(r->renderer());
weinig@apple.com12840dc2013-10-22 23:59:08 +0000693 if (renderBox.isRubyRun())
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000694 setMarginsForRubyRun(r, toRenderRubyRun(renderBox), previousObject, lineInfo);
akling@apple.com7506fda2013-11-07 10:12:36 +0000695 r->box()->setLogicalWidth(logicalWidthForChild(renderBox));
mitz@apple.com86470c82011-01-27 01:39:27 +0000696 totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox);
697 }
hyattffe78712003-02-11 01:59:29 +0000698 }
hyatt4b381692003-03-10 21:11:59 +0000699
akling@apple.com7506fda2013-11-07 10:12:36 +0000700 totalLogicalWidth += r->box()->logicalWidth();
701 previousObject = &r->renderer();
hyattffe78712003-02-11 01:59:29 +0000702 }
703
mitz@apple.com86470c82011-01-27 01:39:27 +0000704 if (isAfterExpansion && !expansionOpportunities.isEmpty()) {
705 expansionOpportunities.last()--;
706 expansionOpportunityCount--;
707 }
708
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000709 updateLogicalWidthForAlignment(textAlign, lineBox, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount);
hyattffe78712003-02-11 01:59:29 +0000710
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000711 computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth);
mitz@apple.come1364202008-02-28 01:06:41 +0000712
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000713 return r;
hyattffe78712003-02-11 01:59:29 +0000714}
715
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000716void RenderBlockFlow::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000717 VerticalPositionCache& verticalPositionCache)
hyattffe78712003-02-11 01:59:29 +0000718{
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000719 setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache));
hyattffe78712003-02-11 01:59:29 +0000720
721 // Now make sure we place replaced render objects correctly.
mitz@apple.com887f3592008-02-25 22:03:08 +0000722 for (BidiRun* r = firstRun; r; r = r->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000723 ASSERT(r->box());
724 if (!r->box())
eseidel789896f2005-11-27 22:52:09 +0000725 continue; // Skip runs with no line boxes.
hyatt0c3a9862004-02-23 21:26:26 +0000726
akling@apple.com27e7d142013-11-07 12:04:02 +0000727 InlineBox& box = *r->box();
728
hyatt98ee7e42003-05-14 01:39:15 +0000729 // Align positioned boxes with the top of the line box. This is
730 // a reasonable approximation of an appropriate y position.
akling@apple.com7506fda2013-11-07 10:12:36 +0000731 if (r->renderer().isOutOfFlowPositioned())
akling@apple.com27e7d142013-11-07 12:04:02 +0000732 box.setLogicalTop(logicalHeight());
hyatt98ee7e42003-05-14 01:39:15 +0000733
734 // Position is used to properly position both replaced elements and
735 // to update the static normal flow x/y of positioned elements.
akling@apple.com7506fda2013-11-07 10:12:36 +0000736 if (r->renderer().isText())
akling@apple.com27e7d142013-11-07 12:04:02 +0000737 toRenderText(r->renderer()).positionLineBox(toInlineTextBox(box));
akling@apple.com7506fda2013-11-07 10:12:36 +0000738 else if (r->renderer().isBox())
akling@apple.com27e7d142013-11-07 12:04:02 +0000739 toRenderBox(r->renderer()).positionLineBox(toInlineElementBox(box));
akling@apple.com7506fda2013-11-07 10:12:36 +0000740 else if (r->renderer().isLineBreak())
akling@apple.com27e7d142013-11-07 12:04:02 +0000741 toRenderLineBreak(r->renderer()).replaceInlineBoxWrapper(toInlineElementBox(box));
hyatt98ee7e42003-05-14 01:39:15 +0000742 }
mitz@apple.coma927be62008-03-21 05:30:19 +0000743 // Positioned objects and zero-length text nodes destroy their boxes in
744 // position(), which unnecessarily dirties the line.
745 lineBox->markDirty(false);
hyattffe78712003-02-11 01:59:29 +0000746}
kociendabb0c24b2001-08-24 14:24:40 +0000747
akling@apple.com7506fda2013-11-07 10:12:36 +0000748static inline bool isCollapsibleSpace(UChar character, const RenderText& renderer)
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000749{
750 if (character == ' ' || character == '\t' || character == softHyphen)
751 return true;
752 if (character == '\n')
akling@apple.com7506fda2013-11-07 10:12:36 +0000753 return !renderer.style().preserveNewline();
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000754 if (character == noBreakSpace)
akling@apple.com7506fda2013-11-07 10:12:36 +0000755 return renderer.style().nbspMode() == SPACE;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000756 return false;
757}
758
msaboff@apple.com142fc202012-10-18 18:03:14 +0000759template <typename CharacterType>
akling@apple.com7506fda2013-11-07 10:12:36 +0000760static inline int findFirstTrailingSpace(const RenderText& lastText, const CharacterType* characters, int start, int stop)
msaboff@apple.com142fc202012-10-18 18:03:14 +0000761{
762 int firstSpace = stop;
763 while (firstSpace > start) {
764 UChar current = characters[firstSpace - 1];
765 if (!isCollapsibleSpace(current, lastText))
766 break;
767 firstSpace--;
768 }
769
770 return firstSpace;
771}
772
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000773inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext)
eric@webkit.org0894bb82011-04-03 08:29:40 +0000774{
eric@webkit.org5bee2942011-04-08 02:12:31 +0000775 if (!bidiRuns.runCount()
akling@apple.com7506fda2013-11-07 10:12:36 +0000776 || !bidiRuns.logicallyLastRun()->renderer().style().breakOnlyAfterWhiteSpace()
777 || !bidiRuns.logicallyLastRun()->renderer().style().autoWrap())
eric@webkit.org0894bb82011-04-03 08:29:40 +0000778 return 0;
779
eric@webkit.org5bee2942011-04-08 02:12:31 +0000780 BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun();
akling@apple.com7506fda2013-11-07 10:12:36 +0000781 const RenderObject& lastObject = trailingSpaceRun->renderer();
782 if (!lastObject.isText())
eric@webkit.org0894bb82011-04-03 08:29:40 +0000783 return 0;
784
akling@apple.com7506fda2013-11-07 10:12:36 +0000785 const RenderText& lastText = toRenderText(lastObject);
msaboff@apple.com142fc202012-10-18 18:03:14 +0000786 int firstSpace;
akling@apple.com7506fda2013-11-07 10:12:36 +0000787 if (lastText.is8Bit())
788 firstSpace = findFirstTrailingSpace(lastText, lastText.characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +0000789 else
akling@apple.com7506fda2013-11-07 10:12:36 +0000790 firstSpace = findFirstTrailingSpace(lastText, lastText.characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +0000791
eric@webkit.org0894bb82011-04-03 08:29:40 +0000792 if (firstSpace == trailingSpaceRun->stop())
793 return 0;
794
akling@apple.com827be9c2013-10-29 02:58:43 +0000795 TextDirection direction = style().direction();
eric@webkit.org5bee2942011-04-08 02:12:31 +0000796 bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun());
eric@webkit.org0894bb82011-04-03 08:29:40 +0000797 if (firstSpace != trailingSpaceRun->start()) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000798 BidiContext* baseContext = currentContext;
eric@webkit.org0894bb82011-04-03 08:29:40 +0000799 while (BidiContext* parent = baseContext->parent())
800 baseContext = parent;
801
akling@apple.com7506fda2013-11-07 10:12:36 +0000802 BidiRun* newTrailingRun = new BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->renderer(), baseContext, U_OTHER_NEUTRAL);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000803 trailingSpaceRun->m_stop = firstSpace;
804 if (direction == LTR)
eric@webkit.org5bee2942011-04-08 02:12:31 +0000805 bidiRuns.addRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000806 else
eric@webkit.org5bee2942011-04-08 02:12:31 +0000807 bidiRuns.prependRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000808 trailingSpaceRun = newTrailingRun;
809 return trailingSpaceRun;
810 }
811 if (!shouldReorder)
812 return trailingSpaceRun;
813
814 if (direction == LTR) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000815 bidiRuns.moveRunToEnd(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000816 trailingSpaceRun->m_level = 0;
817 } else {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000818 bidiRuns.moveRunToBeginning(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000819 trailingSpaceRun->m_level = 1;
820 }
821 return trailingSpaceRun;
822}
823
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000824void RenderBlockFlow::appendFloatingObjectToLastLine(FloatingObject* floatingObject)
mitz@apple.comd17e8c02011-04-16 21:59:36 +0000825{
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +0000826 ASSERT(!floatingObject->originatingLine());
827 floatingObject->setOriginatingLine(lastRootBox());
weinig@apple.com12840dc2013-10-22 23:59:08 +0000828 lastRootBox()->appendFloat(floatingObject->renderer());
mitz@apple.comd17e8c02011-04-16 21:59:36 +0000829}
830
mmaxfield@apple.com434c8722014-01-28 22:03:57 +0000831static inline void setUpResolverToResumeInIsolate(InlineBidiResolver& resolver, RenderObject* root, RenderObject* startObject)
mmaxfield@apple.com18782a22014-01-28 21:53:22 +0000832{
833 if (root != startObject) {
834 RenderObject* parent = startObject->parent();
mmaxfield@apple.com434c8722014-01-28 22:03:57 +0000835 setUpResolverToResumeInIsolate(resolver, root, parent);
mmaxfield@apple.com18782a22014-01-28 21:53:22 +0000836 notifyObserverEnteredObject(&resolver, startObject);
837 }
838}
839
eric@webkit.orga26de042011-09-08 18:46:01 +0000840// FIXME: BidiResolver should have this logic.
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000841static inline void constructBidiRunsForSegment(InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfRuns, VisualDirectionOverride override, bool previousLineBrokeCleanly)
eric@webkit.orga26de042011-09-08 18:46:01 +0000842{
843 // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead
844 // of the resolver owning the runs.
845 ASSERT(&topResolver.runs() == &bidiRuns);
betravis@adobe.com9e5e8242013-04-19 23:28:26 +0000846 ASSERT(topResolver.position() != endOfRuns);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000847 RenderObject* currentRoot = topResolver.position().root();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000848 topResolver.createBidiRunsForLine(endOfRuns, override, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +0000849
850 while (!topResolver.isolatedRuns().isEmpty()) {
851 // It does not matter which order we resolve the runs as long as we resolve them all.
852 BidiRun* isolatedRun = topResolver.isolatedRuns().last();
853 topResolver.isolatedRuns().removeLast();
854
akling@apple.com7506fda2013-11-07 10:12:36 +0000855 RenderObject& startObj = isolatedRun->renderer();
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000856
eric@webkit.orga26de042011-09-08 18:46:01 +0000857 // Only inlines make sense with unicode-bidi: isolate (blocks are already isolated).
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000858 // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the
859 // tree to see which parent inline is the isolate. We could change enterIsolate
860 // to take a RenderObject and do this logic there, but that would be a layering
861 // violation for BidiResolver (which knows nothing about RenderObject).
ddkilzer@apple.comad6ad362014-04-02 17:21:09 +0000862 RenderInline* isolatedInline = toRenderInline(highestContainingIsolateWithinRoot(&startObj, currentRoot));
863 ASSERT(isolatedInline);
864
eric@webkit.orga26de042011-09-08 18:46:01 +0000865 InlineBidiResolver isolatedResolver;
akling@apple.com827be9c2013-10-29 02:58:43 +0000866 EUnicodeBidi unicodeBidi = isolatedInline->style().unicodeBidi();
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000867 TextDirection direction;
868 if (unicodeBidi == Plaintext)
akling@apple.com7506fda2013-11-07 10:12:36 +0000869 determineDirectionality(direction, InlineIterator(isolatedInline, &isolatedRun->renderer(), 0));
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000870 else {
rniwa@webkit.org4d4bd332012-08-20 21:34:11 +0000871 ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride);
akling@apple.com827be9c2013-10-29 02:58:43 +0000872 direction = isolatedInline->style().direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000873 }
zoltan@webkit.orgd1a97402013-12-08 05:53:33 +0000874 isolatedResolver.setStatus(BidiStatus(direction, isOverride(unicodeBidi)));
eric@webkit.orga26de042011-09-08 18:46:01 +0000875
mmaxfield@apple.com434c8722014-01-28 22:03:57 +0000876 setUpResolverToResumeInIsolate(isolatedResolver, isolatedInline, &startObj);
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000877
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000878 // The starting position is the beginning of the first run within the isolate that was identified
879 // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the
880 // first run within the isolate.
akling@apple.com7506fda2013-11-07 10:12:36 +0000881 InlineIterator iter = InlineIterator(isolatedInline, &startObj, isolatedRun->m_start);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000882 isolatedResolver.setPositionIgnoringNestedIsolates(iter);
eric@webkit.orga26de042011-09-08 18:46:01 +0000883
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000884 // 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 +0000885 // FIXME: What should end and previousLineBrokeCleanly be?
886 // rniwa says previousLineBrokeCleanly is just a WinIE hack and could always be false here?
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000887 isolatedResolver.createBidiRunsForLine(endOfRuns, NoVisualOverride, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +0000888 // Note that we do not delete the runs from the resolver.
rniwa@webkit.orgd0ad8882012-05-23 07:37:07 +0000889 // 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 +0000890 // itself to be turned into an InlineBox. We can't remove it here without potentially losing track of
891 // the logically last run.
892 if (isolatedResolver.runs().runCount())
893 bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs());
eric@webkit.orga26de042011-09-08 18:46:01 +0000894
895 // If we encountered any nested isolate runs, just move them
896 // to the top resolver's list for later processing.
897 if (!isolatedResolver.isolatedRuns().isEmpty()) {
andersca@apple.com92012992013-05-05 19:03:49 +0000898 topResolver.isolatedRuns().appendVector(isolatedResolver.isolatedRuns());
eric@webkit.orga26de042011-09-08 18:46:01 +0000899 isolatedResolver.isolatedRuns().clear();
commit-queue@webkit.org1968a432013-09-11 19:23:58 +0000900 currentRoot = isolatedInline;
eric@webkit.orga26de042011-09-08 18:46:01 +0000901 }
902 }
903}
904
eric@webkit.org45e33a52011-05-04 11:51:09 +0000905// This function constructs line boxes for all of the text runs in the resolver and computes their position.
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000906RootInlineBox* RenderBlockFlow::createLineBoxesFromBidiRuns(unsigned bidiLevel, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& end, LineInfo& lineInfo, VerticalPositionCache& verticalPositionCache, BidiRun* trailingSpaceRun, WordMeasurements& wordMeasurements)
eric@webkit.org45e33a52011-05-04 11:51:09 +0000907{
908 if (!bidiRuns.runCount())
909 return 0;
910
911 // FIXME: Why is this only done when we had runs?
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +0000912 lineInfo.setLastLine(!end.renderer());
eric@webkit.org45e33a52011-05-04 11:51:09 +0000913
914 RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo);
915 if (!lineBox)
916 return 0;
917
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000918 lineBox->setBidiLevel(bidiLevel);
eric@webkit.org45e33a52011-05-04 11:51:09 +0000919 lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly());
920
eric@webkit.org45e33a52011-05-04 11:51:09 +0000921 bool isSVGRootInlineBox = lineBox->isSVGRootInlineBox();
eric@webkit.org45e33a52011-05-04 11:51:09 +0000922
923 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
924
925 // Now we position all of our text runs horizontally.
926 if (!isSVGRootInlineBox)
enrica@apple.com885c84d2012-10-10 05:48:51 +0000927 computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache, wordMeasurements);
eric@webkit.org45e33a52011-05-04 11:51:09 +0000928
929 // Now position our text runs vertically.
930 computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache);
931
eric@webkit.org45e33a52011-05-04 11:51:09 +0000932 // SVG text layout code computes vertical & horizontal positions on its own.
933 // Note that we still need to execute computeVerticalPositionsForLine() as
934 // it calls InlineTextBox::positionLineBox(), which tracks whether the box
935 // contains reversed text or not. If we wouldn't do that editing and thus
936 // text selection in RTL boxes would not work as expected.
937 if (isSVGRootInlineBox) {
akling@apple.com670fea12013-10-12 18:16:42 +0000938 ASSERT_WITH_SECURITY_IMPLICATION(isSVGText());
akling@apple.com0c7d7fe2013-11-07 10:08:04 +0000939 toSVGRootInlineBox(lineBox)->computePerCharacterLayoutInformation();
eric@webkit.org45e33a52011-05-04 11:51:09 +0000940 }
eric@webkit.org45e33a52011-05-04 11:51:09 +0000941
942 // Compute our overflow now.
943 lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap);
944
eric@webkit.org45e33a52011-05-04 11:51:09 +0000945 return lineBox;
946}
947
akling@apple.com31dd4f42013-10-30 22:27:59 +0000948static void deleteLineRange(LineLayoutState& layoutState, RootInlineBox* startLine, RootInlineBox* stopLine = 0)
eric@webkit.org455d90e2011-05-09 22:27:27 +0000949{
950 RootInlineBox* boxToDelete = startLine;
951 while (boxToDelete && boxToDelete != stopLine) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +0000952 layoutState.updateRepaintRangeFromBox(boxToDelete);
akling@apple.com31dd4f42013-10-30 22:27:59 +0000953 // Note: deleteLineRange(firstRootBox()) is not identical to deleteLineBoxTree().
eric@webkit.orge2532d92011-05-16 23:10:49 +0000954 // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing.
eric@webkit.org455d90e2011-05-09 22:27:27 +0000955 RootInlineBox* next = boxToDelete->nextRootBox();
akling@apple.com31dd4f42013-10-30 22:27:59 +0000956 boxToDelete->deleteLine();
eric@webkit.org455d90e2011-05-09 22:27:27 +0000957 boxToDelete = next;
958 }
959}
960
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000961void RenderBlockFlow::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild)
eric@webkit.org060caf62011-05-03 22:11:39 +0000962{
963 // We want to skip ahead to the first dirty line
964 InlineBidiResolver resolver;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +0000965 RootInlineBox* startLine = determineStartPosition(layoutState, resolver);
eric@webkit.org060caf62011-05-03 22:11:39 +0000966
mitz@apple.com10ed3cb2011-09-07 20:59:39 +0000967 unsigned consecutiveHyphenatedLines = 0;
968 if (startLine) {
969 for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox())
970 consecutiveHyphenatedLines++;
971 }
972
eric@webkit.org060caf62011-05-03 22:11:39 +0000973 // FIXME: This would make more sense outside of this function, but since
974 // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call
975 // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html.
eric@webkit.org59c3c1e2011-05-17 19:45:24 +0000976 if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) {
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000977 setNeedsLayout(MarkOnlyThis); // Mark as needing a full layout to force us to repaint.
akling@apple.com691cf5c2013-08-24 16:33:15 +0000978 if (!view().doingFullRepaint() && hasLayer()) {
eric@webkit.org060caf62011-05-03 22:11:39 +0000979 // Because we waited until we were already inside layout to discover
980 // that the block really needed a full layout, we missed our chance to repaint the layer
981 // before layout started. Luckily the layer has cached the repaint rect for its original
982 // position and size, and so we can use that to make a repaint happen now.
zalan@apple.comc7b20b12014-02-12 04:50:55 +0000983 repaintUsingContainer(containerForRepaint(), layer()->repaintRect());
eric@webkit.org060caf62011-05-03 22:11:39 +0000984 }
985 }
986
mihnea@adobe.com99467792013-03-19 09:09:04 +0000987 if (containsFloats())
darin@apple.com7cad7042013-09-24 05:53:55 +0000988 layoutState.setLastFloat(m_floatingObjects->set().last().get());
eric@webkit.org060caf62011-05-03 22:11:39 +0000989
990 // We also find the first clean line and extract these lines. We will add them back
991 // if we determine that we're able to synchronize after handling all our dirty lines.
992 InlineIterator cleanLineStart;
993 BidiStatus cleanLineBidiStatus;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +0000994 if (!layoutState.isFullLayout() && startLine)
995 determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus);
eric@webkit.org060caf62011-05-03 22:11:39 +0000996
997 if (startLine) {
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +0000998 if (!layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +0000999 layoutState.setRepaintRange(logicalHeight());
akling@apple.com31dd4f42013-10-30 22:27:59 +00001000 deleteLineRange(layoutState, startLine);
eric@webkit.org060caf62011-05-03 22:11:39 +00001001 }
1002
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001003 if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001004 // If the last line before the start line ends with a line break that clear floats,
1005 // adjust the height accordingly.
1006 // A line break can be either the first or the last object on a line, depending on its direction.
1007 if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) {
akling@apple.com0b8172b72013-08-31 18:34:23 +00001008 RenderObject* lastObject = &lastLeafChild->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001009 if (!lastObject->isBR())
akling@apple.com0b8172b72013-08-31 18:34:23 +00001010 lastObject = &lastRootBox()->firstLeafChild()->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001011 if (lastObject->isBR()) {
akling@apple.com827be9c2013-10-29 02:58:43 +00001012 EClear clear = lastObject->style().clear();
eric@webkit.org060caf62011-05-03 22:11:39 +00001013 if (clear != CNONE)
bjonesbe@adobe.comf9f10402014-02-20 19:40:28 +00001014 clearFloats(clear);
eric@webkit.org060caf62011-05-03 22:11:39 +00001015 }
1016 }
1017 }
1018
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001019 layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001020 linkToEndLineIfNeeded(layoutState);
1021 repaintDirtyFloats(layoutState.floats());
1022}
eric@webkit.org060caf62011-05-03 22:11:39 +00001023
zoltan@webkit.org8b422c82013-09-20 21:17:43 +00001024RenderTextInfo::RenderTextInfo()
mitz@apple.com6a859602012-08-27 15:31:56 +00001025 : m_text(0)
mitz@apple.comd4c153d2012-09-16 23:36:41 +00001026 , m_font(0)
mitz@apple.com6a859602012-08-27 15:31:56 +00001027{
1028}
1029
zoltan@webkit.org8b422c82013-09-20 21:17:43 +00001030RenderTextInfo::~RenderTextInfo()
mitz@apple.com6a859602012-08-27 15:31:56 +00001031{
1032}
1033
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001034// 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 +00001035inline const InlineIterator& RenderBlockFlow::restartLayoutRunsAndFloatsInRange(LayoutUnit oldLogicalHeight, LayoutUnit newLogicalHeight, FloatingObject* lastFloatFromPreviousLine, InlineBidiResolver& resolver, const InlineIterator& oldEnd)
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001036{
1037 removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight);
1038 setLogicalHeight(newLogicalHeight);
1039 resolver.setPositionIgnoringNestedIsolates(oldEnd);
1040 return oldEnd;
1041}
1042
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001043void RenderBlockFlow::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001044{
akling@apple.com827be9c2013-10-29 02:58:43 +00001045 const RenderStyle& styleToUse = style();
akling@apple.com691cf5c2013-08-24 16:33:15 +00001046 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001047 LineMidpointState& lineMidpointState = resolver.midpointState();
1048 InlineIterator end = resolver.position();
1049 bool checkForEndLineMatch = layoutState.endLine();
mitz@apple.com6a859602012-08-27 15:31:56 +00001050 RenderTextInfo renderTextInfo;
eric@webkit.org060caf62011-05-03 22:11:39 +00001051 VerticalPositionCache verticalPositionCache;
1052
weinig@apple.com12840dc2013-10-22 23:59:08 +00001053 LineBreaker lineBreaker(*this);
leviw@chromium.org1a508692011-05-05 00:01:11 +00001054
eric@webkit.org060caf62011-05-03 22:11:39 +00001055 while (!end.atEnd()) {
1056 // 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 +00001057 if (checkForEndLineMatch) {
1058 layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus));
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001059 if (layoutState.endLineMatched()) {
1060 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001061 break;
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001062 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001063 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001064
1065 lineMidpointState.reset();
1066
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001067 layoutState.lineInfo().setEmpty(true);
robert@webkit.org8cbab142011-12-30 20:58:29 +00001068 layoutState.lineInfo().resetRunsFromLeadingWhitespace();
eric@webkit.org060caf62011-05-03 22:11:39 +00001069
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001070 const InlineIterator oldEnd = end;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001071 bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly();
darin@apple.com7cad7042013-09-24 05:53:55 +00001072 FloatingObject* lastFloatFromPreviousLine = (containsFloats()) ? m_floatingObjects->set().last().get() : 0;
zoltan@webkit.org3bd77f52013-04-23 18:23:36 +00001073
enrica@apple.com885c84d2012-10-10 05:48:51 +00001074 WordMeasurements wordMeasurements;
1075 end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
glenn@skynav.com61b1abf2013-04-02 23:28:32 +00001076 renderTextInfo.m_lineBreakIterator.resetPriorContext();
eric@webkit.org060caf62011-05-03 22:11:39 +00001077 if (resolver.position().atEnd()) {
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001078 // FIXME: We shouldn't be creating any runs in nextLineBreak to begin with!
eric@webkit.org060caf62011-05-03 22:11:39 +00001079 // Once BidiRunList is separated from BidiResolver this will not be needed.
1080 resolver.runs().deleteRuns();
1081 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001082 layoutState.setCheckForFloatsFromLastLine(true);
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001083 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
eric@webkit.org060caf62011-05-03 22:11:39 +00001084 break;
1085 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001086
betravis@adobe.com9e5e8242013-04-19 23:28:26 +00001087 ASSERT(end != resolver.position());
1088
eric@webkit.org45e33a52011-05-04 11:51:09 +00001089 // This is a short-cut for empty lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001090 if (layoutState.lineInfo().isEmpty()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001091 if (lastRootBox())
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001092 lastRootBox()->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
eric@webkit.org060caf62011-05-03 22:11:39 +00001093 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001094 VisualDirectionOverride override = (styleToUse.rtlOrdering() == VisualOrder ? (styleToUse.direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride);
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001095
akling@apple.com827be9c2013-10-29 02:58:43 +00001096 if (isNewUBAParagraph && styleToUse.unicodeBidi() == Plaintext && !resolver.context()->parent()) {
1097 TextDirection direction = styleToUse.direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001098 determineDirectionality(direction, resolver.position());
akling@apple.com827be9c2013-10-29 02:58:43 +00001099 resolver.setStatus(BidiStatus(direction, isOverride(styleToUse.unicodeBidi())));
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001100 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001101 // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine.
1102 BidiRunList<BidiRun>& bidiRuns = resolver.runs();
zoltan@webkit.org7d4f8cc2014-03-26 18:20:15 +00001103 constructBidiRunsForSegment(resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly());
eric@webkit.org060caf62011-05-03 22:11:39 +00001104 ASSERT(resolver.position() == end);
1105
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001106 BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : 0;
eric@webkit.org060caf62011-05-03 22:11:39 +00001107
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001108 if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) {
eric@webkit.org45e33a52011-05-04 11:51:09 +00001109 bidiRuns.logicallyLastRun()->m_hasHyphen = true;
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001110 consecutiveHyphenatedLines++;
1111 } else
1112 consecutiveHyphenatedLines = 0;
eric@webkit.org45e33a52011-05-04 11:51:09 +00001113
eric@webkit.org060caf62011-05-03 22:11:39 +00001114 // Now that the runs have been ordered, we create the line boxes.
1115 // At the same time we figure out where border/padding/margin should be applied for
1116 // inline flow boxes.
1117
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001118 LayoutUnit oldLogicalHeight = logicalHeight();
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001119 RootInlineBox* lineBox = createLineBoxesFromBidiRuns(resolver.status().context->level(), bidiRuns, end, layoutState.lineInfo(), verticalPositionCache, trailingSpaceRun, wordMeasurements);
eric@webkit.org060caf62011-05-03 22:11:39 +00001120
1121 bidiRuns.deleteRuns();
1122 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
1123
1124 if (lineBox) {
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001125 lineBox->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001126 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001127 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001128
1129 if (paginated) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001130 LayoutUnit adjustment = 0;
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001131 adjustLinePositionForPagination(lineBox, adjustment, layoutState.flowThread());
eric@webkit.org060caf62011-05-03 22:11:39 +00001132 if (adjustment) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001133 LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, layoutState.lineInfo().isFirstLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001134 lineBox->adjustBlockDirectionPosition(adjustment);
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001135 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001136 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001137
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001138 if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, layoutState.lineInfo().isFirstLine()) != oldLineWidth) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001139 // 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 +00001140 lineBox->deleteLine();
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001141 end = restartLayoutRunsAndFloatsInRange(oldLogicalHeight, oldLogicalHeight + adjustment, lastFloatFromPreviousLine, resolver, oldEnd);
eric@webkit.org060caf62011-05-03 22:11:39 +00001142 continue;
1143 }
1144
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001145 setLogicalHeight(lineBox->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001146 }
commit-queue@webkit.orgbe554b22012-11-26 20:00:49 +00001147
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001148 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001149 updateRegionForLine(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001150 }
1151 }
robert@webkit.org402c1512013-02-07 18:48:39 +00001152 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001153
robert@webkit.org402c1512013-02-07 18:48:39 +00001154 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001155 setStaticPositions(*this, *lineBreaker.positionedObjects()[i]);
eric@webkit.org060caf62011-05-03 22:11:39 +00001156
robert@webkit.org402c1512013-02-07 18:48:39 +00001157 if (!layoutState.lineInfo().isEmpty()) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001158 layoutState.lineInfo().setFirstLine(false);
bjonesbe@adobe.comf9f10402014-02-20 19:40:28 +00001159 clearFloats(lineBreaker.clear());
eric@webkit.org060caf62011-05-03 22:11:39 +00001160 }
1161
1162 if (m_floatingObjects && lastRootBox()) {
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001163 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001164 auto it = floatingObjectSet.begin();
1165 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001166 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001167 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001168 ASSERT(lastFloatIterator != end);
1169 ++lastFloatIterator;
1170 it = lastFloatIterator;
1171 }
1172 for (; it != end; ++it) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001173 FloatingObject* f = it->get();
eric@webkit.org060caf62011-05-03 22:11:39 +00001174 appendFloatingObjectToLastLine(f);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001175 ASSERT(&f->renderer() == &layoutState.floats()[layoutState.floatIndex()].object);
eric@webkit.org060caf62011-05-03 22:11:39 +00001176 // If a float's geometry has changed, give up on syncing with clean lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001177 if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect())
eric@webkit.org060caf62011-05-03 22:11:39 +00001178 checkForEndLineMatch = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001179 layoutState.setFloatIndex(layoutState.floatIndex() + 1);
eric@webkit.org060caf62011-05-03 22:11:39 +00001180 }
darin@apple.com7cad7042013-09-24 05:53:55 +00001181 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001182 }
1183
1184 lineMidpointState.reset();
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001185 resolver.setPosition(end, numberOfIsolateAncestors(end));
eric@webkit.org060caf62011-05-03 22:11:39 +00001186 }
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001187
abucur@adobe.comfc497132013-10-04 08:49:21 +00001188 // In case we already adjusted the line positions during this layout to avoid widows
1189 // then we need to ignore the possibility of having a new widows situation.
1190 // Otherwise, we risk leaving empty containers which is against the block fragmentation principles.
akling@apple.com827be9c2013-10-29 02:58:43 +00001191 if (paginated && !style().hasAutoWidows() && !didBreakAtLineToAvoidWidow()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001192 // Check the line boxes to make sure we didn't create unacceptable widows.
1193 // However, we'll prioritize orphans - so nothing we do here should create
1194 // a new orphan.
1195
1196 RootInlineBox* lineBox = lastRootBox();
1197
1198 // Count from the end of the block backwards, to see how many hanging
1199 // lines we have.
1200 RootInlineBox* firstLineInBlock = firstRootBox();
1201 int numLinesHanging = 1;
1202 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1203 ++numLinesHanging;
1204 lineBox = lineBox->prevRootBox();
1205 }
1206
1207 // If there were no breaks in the block, we didn't create any widows.
jchaffraix@webkit.org0f225142013-01-28 22:28:21 +00001208 if (!lineBox || !lineBox->isFirstAfterPageBreak() || lineBox == firstLineInBlock)
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001209 return;
1210
akling@apple.com827be9c2013-10-29 02:58:43 +00001211 if (numLinesHanging < style().widows()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001212 // We have detected a widow. Now we need to work out how many
1213 // lines there are on the previous page, and how many we need
1214 // to steal.
akling@apple.com827be9c2013-10-29 02:58:43 +00001215 int numLinesNeeded = style().widows() - numLinesHanging;
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001216 RootInlineBox* currentFirstLineOfNewPage = lineBox;
1217
1218 // Count the number of lines in the previous page.
1219 lineBox = lineBox->prevRootBox();
1220 int numLinesInPreviousPage = 1;
1221 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1222 ++numLinesInPreviousPage;
1223 lineBox = lineBox->prevRootBox();
1224 }
1225
1226 // If there was an explicit value for orphans, respect that. If not, we still
1227 // shouldn't create a situation where we make an orphan bigger than the initial value.
1228 // This means that setting widows implies we also care about orphans, but given
1229 // the specification says the initial orphan value is non-zero, this is ok. The
1230 // author is always free to set orphans explicitly as well.
akling@apple.com827be9c2013-10-29 02:58:43 +00001231 int orphans = style().hasAutoOrphans() ? style().initialOrphans() : style().orphans();
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001232 int numLinesAvailable = numLinesInPreviousPage - orphans;
1233 if (numLinesAvailable <= 0)
1234 return;
1235
andersca@apple.com86298632013-11-10 19:32:33 +00001236 int numLinesToTake = std::min(numLinesAvailable, numLinesNeeded);
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001237 // Wind back from our first widowed line.
1238 lineBox = currentFirstLineOfNewPage;
1239 for (int i = 0; i < numLinesToTake; ++i)
1240 lineBox = lineBox->prevRootBox();
1241
1242 // We now want to break at this line. Remember for next layout and trigger relayout.
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001243 setBreakAtLineToAvoidWidow(lineCount(lineBox));
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001244 markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), lineBox->lineBottomWithLeading(), lineBox);
1245 }
1246 }
abucur@adobe.comfc497132013-10-04 08:49:21 +00001247
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001248 clearDidBreakAtLineToAvoidWidow();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001249}
eric@webkit.org060caf62011-05-03 22:11:39 +00001250
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001251void RenderBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001252{
1253 if (layoutState.endLine()) {
1254 if (layoutState.endLineMatched()) {
akling@apple.com691cf5c2013-08-24 16:33:15 +00001255 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eric@webkit.org060caf62011-05-03 22:11:39 +00001256 // Attach all the remaining lines, and then adjust their y-positions as needed.
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001257 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001258 for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001259 line->attachLine();
1260 if (paginated) {
1261 delta -= line->paginationStrut();
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001262 adjustLinePositionForPagination(line, delta, layoutState.flowThread());
eric@webkit.org060caf62011-05-03 22:11:39 +00001263 }
1264 if (delta) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001265 layoutState.updateRepaintRangeFromBox(line, delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001266 line->adjustBlockDirectionPosition(delta);
1267 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001268 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001269 updateRegionForLine(line);
eric@webkit.org060caf62011-05-03 22:11:39 +00001270 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001271 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1272 RenderBox* floatingBox = *it;
1273 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001274 ASSERT(!floatingObject->originatingLine());
1275 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001276 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox) + delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001277 positionNewFloats();
1278 }
1279 }
1280 }
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001281 setLogicalHeight(lastRootBox()->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001282 } else {
1283 // Delete all the remaining lines.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001284 deleteLineRange(layoutState, layoutState.endLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001285 }
1286 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001287
1288 if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001289 // In case we have a float on the last line, it might not be positioned up to now.
1290 // This has to be done before adding in the bottom border/padding, or the float will
1291 // include the padding incorrectly. -dwh
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001292 if (layoutState.checkForFloatsFromLastLine()) {
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001293 LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow();
1294 LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow();
akling@apple.comb5f24642013-11-06 04:47:12 +00001295 auto newLineBox = std::make_unique<TrailingFloatsRootInlineBox>(*this);
1296 auto trailingFloatsLineBox = newLineBox.get();
1297 m_lineBoxes.appendLineBox(std::move(newLineBox));
eric@webkit.org060caf62011-05-03 22:11:39 +00001298 trailingFloatsLineBox->setConstructed();
1299 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
1300 VerticalPositionCache verticalPositionCache;
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001301 LayoutUnit blockLogicalHeight = logicalHeight();
hyatt@apple.coma8b5b822011-09-07 18:48:07 +00001302 trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache);
1303 trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight);
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001304 trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight));
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001305 LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight);
1306 LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight);
eric@webkit.org060caf62011-05-03 22:11:39 +00001307 trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom());
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001308 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001309 updateRegionForLine(trailingFloatsLineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001310 }
1311
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001312 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001313 auto it = floatingObjectSet.begin();
1314 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001315 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001316 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001317 ASSERT(lastFloatIterator != end);
1318 ++lastFloatIterator;
1319 it = lastFloatIterator;
1320 }
1321 for (; it != end; ++it)
darin@apple.com7cad7042013-09-24 05:53:55 +00001322 appendFloatingObjectToLastLine(it->get());
1323 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001324 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001325}
1326
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001327void RenderBlockFlow::repaintDirtyFloats(Vector<FloatWithRect>& floats)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001328{
eric@webkit.org060caf62011-05-03 22:11:39 +00001329 size_t floatCount = floats.size();
1330 // Floats that did not have layout did not repaint when we laid them out. They would have
1331 // painted by now if they had moved, but if they stayed at (0, 0), they still need to be
1332 // painted.
1333 for (size_t i = 0; i < floatCount; ++i) {
1334 if (!floats[i].everHadLayout) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001335 RenderBox& box = floats[i].object;
1336 if (!box.x() && !box.y() && box.checkForRepaintDuringLayout())
1337 box.repaint();
eric@webkit.org060caf62011-05-03 22:11:39 +00001338 }
1339 }
1340}
1341
antti@apple.com940f5872013-10-24 20:31:11 +00001342void RenderBlockFlow::layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom)
jamesr@google.com19548ad2010-04-02 23:21:35 +00001343{
antti@apple.comfea51992013-10-28 13:39:23 +00001344 ASSERT(!m_simpleLineLayout);
antti@apple.com940f5872013-10-24 20:31:11 +00001345
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001346 setLogicalHeight(borderAndPaddingBefore());
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001347
1348 // Lay out our hypothetical grid line as though it occurs at the top of the block.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001349 if (view().layoutState() && view().layoutState()->lineGrid() == this)
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001350 layoutLineGridBox();
mitz@apple.come1364202008-02-28 01:06:41 +00001351
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001352 RenderFlowThread* flowThread = flowThreadContainingBlock();
akling@apple.comee3c8df2013-11-06 08:09:44 +00001353 bool clearLinesForPagination = firstRootBox() && flowThread && !flowThread->hasRegions();
commit-queue@webkit.org93cdd632012-12-07 00:33:56 +00001354
hyatt0c3a9862004-02-23 21:26:26 +00001355 // Figure out if we should clear out our line boxes.
1356 // FIXME: Handle resize eventually!
akling@apple.comee3c8df2013-11-06 08:09:44 +00001357 bool isFullLayout = !firstRootBox() || selfNeedsLayout() || relayoutChildren || clearLinesForPagination;
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001358 LineLayoutState layoutState(isFullLayout, repaintLogicalTop, repaintLogicalBottom, flowThread);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001359
1360 if (isFullLayout)
akling@apple.com31dd4f42013-10-30 22:27:59 +00001361 lineBoxes().deleteLineBoxes();
mitz@apple.come1364202008-02-28 01:06:41 +00001362
commit-queue@webkit.org07797312013-02-22 18:58:19 +00001363 // Text truncation kicks in in two cases:
1364 // 1) If your overflow isn't visible and your text-overflow-mode isn't clip.
1365 // 2) If you're an anonymous block with a block parent that satisfies #1.
hyatted77ad82004-06-15 07:21:23 +00001366 // 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 +00001367 // difficult to figure out in general (especially in the middle of doing layout), so we only handle the
1368 // simple case of an anonymous block truncating when it's parent is clipped.
akling@apple.com827be9c2013-10-29 02:58:43 +00001369 bool hasTextOverflow = (style().textOverflow() && hasOverflowClip())
1370 || (isAnonymousBlock() && parent() && parent()->isRenderBlock() && parent()->style().textOverflow() && parent()->hasOverflowClip());
mitz@apple.come1364202008-02-28 01:06:41 +00001371
hyatted77ad82004-06-15 07:21:23 +00001372 // Walk all the lines and delete our ellipsis line boxes if they exist.
1373 if (hasTextOverflow)
1374 deleteEllipsisLineBoxes();
1375
hyattffe78712003-02-11 01:59:29 +00001376 if (firstChild()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001377 // In full layout mode, clear the line boxes of children upfront. Otherwise,
1378 // siblings can run into stale root lineboxes during layout. Then layout
1379 // the replaced elements later. In partial layout mode, line boxes are not
1380 // deleted and only dirtied. In that case, we can layout the replaced
1381 // elements at the same time.
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001382 bool hasInlineChild = false;
inferno@chromium.org13563122012-08-16 20:50:05 +00001383 Vector<RenderBox*> replacedChildren;
weinig@apple.com12840dc2013-10-22 23:59:08 +00001384 for (InlineWalker walker(*this); !walker.atEnd(); walker.advance()) {
1385 RenderObject& o = *walker.current();
abucur@adobe.com33159da2013-08-13 07:44:32 +00001386
weinig@apple.com12840dc2013-10-22 23:59:08 +00001387 if (!hasInlineChild && o.isInline())
commit-queue@webkit.orgcf45df92010-09-14 13:25:06 +00001388 hasInlineChild = true;
1389
weinig@apple.com12840dc2013-10-22 23:59:08 +00001390 if (o.isReplaced() || o.isFloating() || o.isOutOfFlowPositioned()) {
1391 RenderBox& box = toRenderBox(o);
eric@webkit.org060caf62011-05-03 22:11:39 +00001392
weinig@apple.com12840dc2013-10-22 23:59:08 +00001393 if (relayoutChildren || box.hasRelativeDimensions())
1394 box.setChildNeedsLayout(MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001395
zimmermann@webkit.orgac68af42011-06-15 08:02:37 +00001396 // 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 +00001397 if (relayoutChildren && box.needsPreferredWidthsRecalculation())
1398 box.setPreferredLogicalWidthsDirty(true, MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001399
weinig@apple.com12840dc2013-10-22 23:59:08 +00001400 if (box.isOutOfFlowPositioned())
1401 box.containingBlock()->insertPositionedObject(box);
1402 else if (box.isFloating())
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001403 layoutState.floats().append(FloatWithRect(box));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001404 else if (isFullLayout || box.needsLayout()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001405 // Replaced element.
weinig@apple.com12840dc2013-10-22 23:59:08 +00001406 box.dirtyLineBoxes(isFullLayout);
inferno@chromium.org13563122012-08-16 20:50:05 +00001407 if (isFullLayout)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001408 replacedChildren.append(&box);
inferno@chromium.org13563122012-08-16 20:50:05 +00001409 else
weinig@apple.com12840dc2013-10-22 23:59:08 +00001410 box.layoutIfNeeded();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001411 }
weinig@apple.com12840dc2013-10-22 23:59:08 +00001412 } else if (o.isTextOrLineBreak() || (o.isRenderInline() && !walker.atEndOfInline())) {
1413 if (o.isRenderInline())
1414 toRenderInline(o).updateAlwaysCreateLineBoxes(layoutState.isFullLayout());
1415 if (layoutState.isFullLayout() || o.selfNeedsLayout())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001416 dirtyLineBoxesForRenderer(o, layoutState.isFullLayout());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001417 o.clearNeedsLayout();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001418 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001419 }
1420
inferno@chromium.orgba2dceb2012-08-21 00:09:47 +00001421 for (size_t i = 0; i < replacedChildren.size(); i++)
1422 replacedChildren[i]->layoutIfNeeded();
inferno@chromium.org13563122012-08-16 20:50:05 +00001423
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001424 layoutRunsAndFloats(layoutState, hasInlineChild);
kociendabb0c24b2001-08-24 14:24:40 +00001425 }
hyatt85586af2003-02-19 23:22:42 +00001426
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001427 // Expand the last line to accommodate Ruby and emphasis marks.
1428 int lastLineAnnotationsAdjustment = 0;
1429 if (lastRootBox()) {
andersca@apple.com86298632013-11-10 19:32:33 +00001430 LayoutUnit lowestAllowedPosition = std::max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
akling@apple.com827be9c2013-10-29 02:58:43 +00001431 if (!style().isFlippedLinesWritingMode())
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001432 lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition);
1433 else
1434 lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
hyatt@apple.com5e48ff52010-11-19 00:43:29 +00001435 }
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001436
hyatta70560a2002-11-20 01:53:20 +00001437 // Now add in the bottom border/padding.
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001438 setLogicalHeight(logicalHeight() + lastLineAnnotationsAdjustment + borderAndPaddingAfter() + scrollbarLogicalHeight());
kociendabb0c24b2001-08-24 14:24:40 +00001439
akling@apple.comee3c8df2013-11-06 08:09:44 +00001440 if (!firstRootBox() && hasLineIfEmpty())
hyatt@apple.com2a5eb212011-03-22 23:21:54 +00001441 setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
hyatted77ad82004-06-15 07:21:23 +00001442
1443 // See if we have any lines that spill out of our block. If we do, then we will possibly need to
1444 // truncate text.
1445 if (hasTextOverflow)
1446 checkLinesForTextOverflow();
kociendabb0c24b2001-08-24 14:24:40 +00001447}
1448
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001449void RenderBlockFlow::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat)
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001450{
1451 Vector<RenderBox*>* cleanLineFloats = line->floatsPtr();
1452 if (!cleanLineFloats)
1453 return;
stavila@adobe.comf4ef0972014-03-28 21:55:46 +00001454
1455 if (!floats.size()) {
1456 encounteredNewFloat = true;
1457 return;
1458 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001459
weinig@apple.com12840dc2013-10-22 23:59:08 +00001460 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001461 RenderBox* floatingBox = *it;
1462 floatingBox->layoutIfNeeded();
bjonesbe@adobe.com562a50d2014-02-20 20:01:19 +00001463 LayoutSize newSize(floatingBox->width() + floatingBox->horizontalMarginExtent(), floatingBox->height() + floatingBox->verticalMarginExtent());
inferno@chromium.orga227be62013-02-11 08:06:45 +00001464 ASSERT_WITH_SECURITY_IMPLICATION(floatIndex < floats.size());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001465 if (&floats[floatIndex].object != floatingBox) {
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001466 encounteredNewFloat = true;
1467 return;
1468 }
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001469
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001470 if (floats[floatIndex].rect.size() != newSize) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001471 LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x();
andersca@apple.com86298632013-11-10 19:32:33 +00001472 LayoutUnit floatHeight = isHorizontalWritingMode() ? std::max(floats[floatIndex].rect.height(), newSize.height()) : std::max(floats[floatIndex].rect.width(), newSize.width());
1473 floatHeight = std::min(floatHeight, LayoutUnit::max() - floatTop);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001474 line->markDirty();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001475 markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001476 floats[floatIndex].rect.setSize(newSize);
1477 dirtiedByFloat = true;
1478 }
1479 floatIndex++;
1480 }
1481}
1482
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001483RootInlineBox* RenderBlockFlow::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver)
hyatt0c3a9862004-02-23 21:26:26 +00001484{
1485 RootInlineBox* curr = 0;
1486 RootInlineBox* last = 0;
mitz@apple.come1364202008-02-28 01:06:41 +00001487
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001488 // FIXME: This entire float-checking block needs to be broken into a new function.
mitz@apple.com40547b32008-03-18 04:04:34 +00001489 bool dirtiedByFloat = false;
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001490 if (!layoutState.isFullLayout()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001491 // Paginate all of the clean lines.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001492 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001493 LayoutUnit paginationDelta = 0;
mitz@apple.com40547b32008-03-18 04:04:34 +00001494 size_t floatIndex = 0;
1495 for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001496 if (paginated) {
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001497 if (lineWidthForPaginatedLineChanged(curr, 0, layoutState.flowThread())) {
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001498 curr->markDirty();
1499 break;
1500 }
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001501 paginationDelta -= curr->paginationStrut();
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001502 adjustLinePositionForPagination(curr, paginationDelta, layoutState.flowThread());
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001503 if (paginationDelta) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001504 if (containsFloats() || !layoutState.floats().isEmpty()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001505 // 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 +00001506 layoutState.markForFullLayout();
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001507 break;
1508 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001509
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001510 layoutState.updateRepaintRangeFromBox(curr, paginationDelta);
hyatt@apple.com61bbedf2011-01-26 23:10:57 +00001511 curr->adjustBlockDirectionPosition(paginationDelta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001512 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001513 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001514 updateRegionForLine(curr);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001515 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001516
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001517 // If a new float has been inserted before this line or before its last known float, just do a full layout.
1518 bool encounteredNewFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001519 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001520 if (encounteredNewFloat)
1521 layoutState.markForFullLayout();
1522
1523 if (dirtiedByFloat || layoutState.isFullLayout())
mitz@apple.com40547b32008-03-18 04:04:34 +00001524 break;
1525 }
1526 // Check if a new float has been inserted after the last known float.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001527 if (!curr && floatIndex < layoutState.floats().size())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001528 layoutState.markForFullLayout();
mitz@apple.com40547b32008-03-18 04:04:34 +00001529 }
1530
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001531 if (layoutState.isFullLayout()) {
akling@apple.com31dd4f42013-10-30 22:27:59 +00001532 m_lineBoxes.deleteLineBoxTree();
igor.o@sisa.samsung.comf6a57df2013-04-15 21:25:35 +00001533 curr = 0;
1534
akling@apple.comee3c8df2013-11-06 08:09:44 +00001535 ASSERT(!firstRootBox() && !lastRootBox());
eseidel789896f2005-11-27 22:52:09 +00001536 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001537 if (curr) {
1538 // We have a dirty line.
mjs9f78dd92007-02-12 04:06:07 +00001539 if (RootInlineBox* prevRootBox = curr->prevRootBox()) {
hyatt0c3a9862004-02-23 21:26:26 +00001540 // We have a previous line.
tasak@google.comfcfd96f2012-11-26 07:45:38 +00001541 if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= toRenderText(prevRootBox->lineBreakObj())->textLength())))
mjs9f78dd92007-02-12 04:06:07 +00001542 // The previous line didn't break cleanly or broke at a newline
1543 // that has been deleted, so treat it as dirty too.
1544 curr = prevRootBox;
hyatt0c3a9862004-02-23 21:26:26 +00001545 }
eseidel789896f2005-11-27 22:52:09 +00001546 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001547 // No dirty lines were found.
1548 // If the last line didn't break cleanly, treat it as dirty.
1549 if (lastRootBox() && !lastRootBox()->endsWithBreak())
1550 curr = lastRootBox();
1551 }
mitz@apple.come1364202008-02-28 01:06:41 +00001552
hyatt0c3a9862004-02-23 21:26:26 +00001553 // If we have no dirty lines, then last is just the last root box.
1554 last = curr ? curr->prevRootBox() : lastRootBox();
1555 }
mitz@apple.come1364202008-02-28 01:06:41 +00001556
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001557 unsigned numCleanFloats = 0;
1558 if (!layoutState.floats().isEmpty()) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001559 LayoutUnit savedLogicalHeight = logicalHeight();
mitz@apple.com40547b32008-03-18 04:04:34 +00001560 // Restore floats from clean lines.
1561 RootInlineBox* line = firstRootBox();
1562 while (line != curr) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00001563 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001564 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1565 RenderBox* floatingBox = *it;
1566 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001567 ASSERT(!floatingObject->originatingLine());
1568 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001569 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox));
mitz@apple.com40547b32008-03-18 04:04:34 +00001570 positionNewFloats();
weinig@apple.com12840dc2013-10-22 23:59:08 +00001571 ASSERT(&layoutState.floats()[numCleanFloats].object == floatingBox);
mitz@apple.com40547b32008-03-18 04:04:34 +00001572 numCleanFloats++;
1573 }
1574 }
1575 line = line->nextRootBox();
1576 }
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001577 setLogicalHeight(savedLogicalHeight);
mitz@apple.com40547b32008-03-18 04:04:34 +00001578 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001579 layoutState.setFloatIndex(numCleanFloats);
mitz@apple.com40547b32008-03-18 04:04:34 +00001580
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001581 layoutState.lineInfo().setFirstLine(!last);
1582 layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak());
mitz@apple.com1a301772008-03-11 18:30:36 +00001583
hyatt0c3a9862004-02-23 21:26:26 +00001584 if (last) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001585 setLogicalHeight(last->lineBottomWithLeading());
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001586 InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos());
1587 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
mitz@apple.com15035e62008-07-05 20:44:44 +00001588 resolver.setStatus(last->lineBreakBidiStatus());
darindde01502005-12-18 22:55:35 +00001589 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001590 TextDirection direction = style().direction();
1591 if (style().unicodeBidi() == Plaintext)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001592 determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(*this), 0));
akling@apple.com827be9c2013-10-29 02:58:43 +00001593 resolver.setStatus(BidiStatus(direction, isOverride(style().unicodeBidi())));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001594 InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(*this, &resolver), 0);
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001595 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
darindde01502005-12-18 22:55:35 +00001596 }
hyatt0c3a9862004-02-23 21:26:26 +00001597 return curr;
1598}
1599
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001600void RenderBlockFlow::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001601{
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001602 ASSERT(!layoutState.endLine());
1603 size_t floatIndex = layoutState.floatIndex();
hyatt0c3a9862004-02-23 21:26:26 +00001604 RootInlineBox* last = 0;
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001605 for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) {
1606 if (!curr->isDirty()) {
1607 bool encounteredNewFloat = false;
1608 bool dirtiedByFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001609 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001610 if (encounteredNewFloat)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001611 return;
hyatt04420ca2004-07-16 00:05:42 +00001612 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001613 if (curr->isDirty())
1614 last = 0;
1615 else if (!last)
1616 last = curr;
hyatt0c3a9862004-02-23 21:26:26 +00001617 }
mitz@apple.come1364202008-02-28 01:06:41 +00001618
hyatt0c3a9862004-02-23 21:26:26 +00001619 if (!last)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001620 return;
mitz@apple.come1364202008-02-28 01:06:41 +00001621
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001622 // At this point, |last| is the first line in a run of clean lines that ends with the last line
1623 // in the block.
1624
eseidel789896f2005-11-27 22:52:09 +00001625 RootInlineBox* prev = last->prevRootBox();
mitz@apple.com15035e62008-07-05 20:44:44 +00001626 cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos());
eseidel789896f2005-11-27 22:52:09 +00001627 cleanLineBidiStatus = prev->lineBreakBidiStatus();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001628 layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading());
mitz@apple.come1364202008-02-28 01:06:41 +00001629
hyatt0c3a9862004-02-23 21:26:26 +00001630 for (RootInlineBox* line = last; line; line = line->nextRootBox())
1631 line->extractLine(); // Disconnect all line boxes from their render objects while preserving
1632 // their connections to one another.
mitz@apple.come1364202008-02-28 01:06:41 +00001633
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001634 layoutState.setEndLine(last);
hyatt0c3a9862004-02-23 21:26:26 +00001635}
1636
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001637bool RenderBlockFlow::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001638{
1639 LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop();
1640
akling@apple.com691cf5c2013-08-24 16:33:15 +00001641 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001642 if (paginated && layoutState.flowThread()) {
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001643 // Check all lines from here to the end, and see if the hypothetical new position for the lines will result
1644 // in a different available line width.
1645 for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) {
1646 if (paginated) {
1647 // This isn't the real move we're going to do, so don't update the line box's pagination
1648 // strut yet.
1649 LayoutUnit oldPaginationStrut = lineBox->paginationStrut();
1650 lineDelta -= oldPaginationStrut;
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001651 adjustLinePositionForPagination(lineBox, lineDelta, layoutState.flowThread());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001652 lineBox->setPaginationStrut(oldPaginationStrut);
1653 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001654 if (lineWidthForPaginatedLineChanged(lineBox, lineDelta, layoutState.flowThread()))
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001655 return false;
1656 }
1657 }
1658
1659 if (!lineDelta || !m_floatingObjects)
1660 return true;
1661
1662 // 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 +00001663 LayoutUnit logicalTop = std::min(logicalHeight(), layoutState.endLineLogicalTop());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001664
1665 RootInlineBox* lastLine = layoutState.endLine();
1666 while (RootInlineBox* nextLine = lastLine->nextRootBox())
1667 lastLine = nextLine;
1668
leviw@chromium.org3957b452012-05-01 00:06:37 +00001669 LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + absoluteValue(lineDelta);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001670
1671 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001672 auto end = floatingObjectSet.end();
1673 for (auto it = floatingObjectSet.begin(); it != end; ++it) {
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001674 FloatingObject* floatingObject = it->get();
1675 if (logicalBottomForFloat(floatingObject) >= logicalTop && logicalBottomForFloat(floatingObject) < logicalBottom)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001676 return false;
1677 }
1678
1679 return true;
1680}
1681
weinig@apple.com31324fd2013-10-28 19:22:51 +00001682bool RenderBlockFlow::lineWidthForPaginatedLineChanged(RootInlineBox* rootBox, LayoutUnit lineDelta, RenderFlowThread* flowThread) const
1683{
1684 if (!flowThread)
1685 return false;
1686
1687 RenderRegion* currentRegion = regionAtBlockOffset(rootBox->lineTopWithLeading() + lineDelta);
1688 // Just bail if the region didn't change.
1689 if (rootBox->containingRegion() == currentRegion)
1690 return false;
1691 return rootBox->paginatedLineWidth() != availableLogicalWidthForContent(currentRegion);
1692}
1693
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001694bool RenderBlockFlow::matchedEndLine(LineLayoutState& layoutState, const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001695{
mitz@apple.com15035e62008-07-05 20:44:44 +00001696 if (resolver.position() == endLineStart) {
1697 if (resolver.status() != endLineStatus)
mitz@apple.com40547b32008-03-18 04:04:34 +00001698 return false;
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001699 return checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00001700 }
hyatt0c3a9862004-02-23 21:26:26 +00001701
mitz@apple.come1364202008-02-28 01:06:41 +00001702 // The first clean line doesn't match, but we can check a handful of following lines to try
1703 // to match back up.
1704 static int numLines = 8; // The # of lines we're willing to match against.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001705 RootInlineBox* originalEndLine = layoutState.endLine();
1706 RootInlineBox* line = originalEndLine;
mitz@apple.come1364202008-02-28 01:06:41 +00001707 for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) {
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001708 if (line->lineBreakObj() == resolver.position().renderer() && line->lineBreakPos() == resolver.position().offset()) {
mitz@apple.come1364202008-02-28 01:06:41 +00001709 // We have a match.
mitz@apple.com15035e62008-07-05 20:44:44 +00001710 if (line->lineBreakBidiStatus() != resolver.status())
mitz@apple.come1364202008-02-28 01:06:41 +00001711 return false; // ...but the bidi state doesn't match.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001712
1713 bool matched = false;
mitz@apple.come1364202008-02-28 01:06:41 +00001714 RootInlineBox* result = line->nextRootBox();
hyatt@apple.com1fb7d582011-09-23 20:25:11 +00001715 layoutState.setEndLine(result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001716 if (result) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001717 layoutState.setEndLineLogicalTop(line->lineBottomWithLeading());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001718 matched = checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00001719 }
1720
mitz@apple.come1364202008-02-28 01:06:41 +00001721 // Now delete the lines that we failed to sync.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001722 deleteLineRange(layoutState, originalEndLine, result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001723 return matched;
hyatt0c3a9862004-02-23 21:26:26 +00001724 }
1725 }
mitz@apple.come1364202008-02-28 01:06:41 +00001726
hyatt0c3a9862004-02-23 21:26:26 +00001727 return false;
1728}
1729
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00001730bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj)
bdashccffb432007-07-13 11:51:40 +00001731{
1732 ASSERT(inlineObj->parent() == this);
1733
mitz@apple.com15035e62008-07-05 20:44:44 +00001734 InlineIterator it(this, inlineObj, 0);
rniwa@webkit.org40248422011-06-15 00:19:39 +00001735 // FIXME: We should pass correct value for WhitespacePosition.
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00001736 while (!it.atEnd() && !requiresLineBox(it))
mitz@apple.com1a301772008-03-11 18:30:36 +00001737 it.increment();
bdashccffb432007-07-13 11:51:40 +00001738
1739 return !it.atEnd();
1740}
1741
weinig@apple.com611b9292013-10-20 22:57:54 +00001742void RenderBlockFlow::addOverflowFromInlineChildren()
hyattb4b20872004-10-20 21:34:01 +00001743{
antti@apple.comfea51992013-10-28 13:39:23 +00001744 if (auto layout = simpleLineLayout()) {
antti@apple.com940f5872013-10-24 20:31:11 +00001745 ASSERT(!hasOverflowClip());
antti@apple.comfea51992013-10-28 13:39:23 +00001746 SimpleLineLayout::collectFlowOverflow(*this, *layout);
antti@apple.com940f5872013-10-24 20:31:11 +00001747 return;
1748 }
eae@chromium.org9717cd82012-11-07 18:33:44 +00001749 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit();
hyatt@apple.com592848f2010-12-06 20:03:43 +00001750 // 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 +00001751 if (hasOverflowClip() && !endPadding && element() && element()->isRootEditableElement() && style().isLeftToRightDirection())
hyatt@apple.com592848f2010-12-06 20:03:43 +00001752 endPadding = 1;
hyattb4b20872004-10-20 21:34:01 +00001753 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
hyatt@apple.com592848f2010-12-06 20:03:43 +00001754 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
abucur@adobe.com6585d012013-09-04 08:26:41 +00001755 RenderRegion* region = curr->containingRegion();
1756 if (region)
1757 region->addLayoutOverflowForBox(this, curr->paddedLayoutOverflowRect(endPadding));
1758 if (!hasOverflowClip()) {
hyatt@apple.com61f25322011-03-31 20:40:48 +00001759 addVisualOverflow(curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
abucur@adobe.com6585d012013-09-04 08:26:41 +00001760 if (region)
1761 region->addVisualOverflowForBox(this, curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
1762 }
hyattb4b20872004-10-20 21:34:01 +00001763 }
1764}
1765
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001766void RenderBlockFlow::deleteEllipsisLineBoxes()
hyatted77ad82004-06-15 07:21:23 +00001767{
akling@apple.com827be9c2013-10-29 02:58:43 +00001768 ETextAlign textAlign = style().textAlign();
1769 bool ltr = style().isLeftToRightDirection();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001770 bool firstLine = true;
1771 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
1772 if (curr->hasEllipsisBox()) {
1773 curr->clearTruncation();
1774
1775 // Shift the line back where it belongs if we cannot accomodate an ellipsis.
1776 float logicalLeft = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine);
1777 float availableLogicalWidth = logicalRightOffsetForLine(curr->lineTop(), false) - logicalLeft;
1778 float totalLogicalWidth = curr->logicalWidth();
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001779 updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001780
1781 if (ltr)
1782 curr->adjustLogicalPosition((logicalLeft - curr->logicalLeft()), 0);
1783 else
1784 curr->adjustLogicalPosition(-(curr->logicalLeft() - logicalLeft), 0);
1785 }
1786 firstLine = false;
1787 }
hyatted77ad82004-06-15 07:21:23 +00001788}
1789
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001790void RenderBlockFlow::checkLinesForTextOverflow()
hyatted77ad82004-06-15 07:21:23 +00001791{
1792 // Determine the width of the ellipsis using the current font.
darindbba2bb2007-01-11 12:23:49 +00001793 // 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 +00001794 const Font& font = style().font();
svillar@igalia.com5b31eef2014-03-14 08:30:55 +00001795 DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
akling@apple.com827be9c2013-10-29 02:58:43 +00001796 const Font& firstLineFont = firstLineStyle().font();
1797 int firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle()));
1798 int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style()));
hyatted77ad82004-06-15 07:21:23 +00001799
1800 // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see
1801 // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and
1802 // check the left edge of the line box to see if it is less
1803 // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()"
akling@apple.com827be9c2013-10-29 02:58:43 +00001804 bool ltr = style().isLeftToRightDirection();
1805 ETextAlign textAlign = style().textAlign();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001806 bool firstLine = true;
hyatted77ad82004-06-15 07:21:23 +00001807 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
eae@chromium.org275da182012-12-19 23:07:55 +00001808 // FIXME: Use pixelSnappedLogicalRightOffsetForLine instead of snapping it ourselves once the column workaround in said method has been fixed.
1809 // https://bugs.webkit.org/show_bug.cgi?id=105461
commit-queue@webkit.orgbbac21e2013-06-21 15:45:21 +00001810 int blockRightEdge = snapSizeToPixel(logicalRightOffsetForLine(curr->lineTop(), firstLine), curr->x());
1811 int blockLeftEdge = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine);
eae@chromium.orgc491d962012-12-28 18:32:08 +00001812 int lineBoxEdge = ltr ? snapSizeToPixel(curr->x() + curr->logicalWidth(), curr->x()) : snapSizeToPixel(curr->x(), 0);
dglazkov@chromium.org28434e62009-05-13 22:30:10 +00001813 if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) {
hyattf918d2d2004-06-15 07:24:11 +00001814 // 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 +00001815 // can be truncated. In order for truncation to be possible, the line must have sufficient space to
1816 // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis
1817 // space.
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001818
1819 LayoutUnit width = firstLine ? firstLineEllipsisWidth : ellipsisWidth;
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001820 LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001821 if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) {
1822 float totalLogicalWidth = curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width);
1823
akling@apple.comf294cf02013-07-17 18:46:39 +00001824 float logicalLeft = 0; // We are only interested in the delta from the base position.
commit-queue@webkit.orgbbac21e2013-06-21 15:45:21 +00001825 float truncatedWidth = pixelSnappedLogicalRightOffsetForLine(curr->lineTop(), firstLine);
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001826 updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, truncatedWidth, 0);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001827 if (ltr)
1828 curr->adjustLogicalPosition(logicalLeft, 0);
1829 else
1830 curr->adjustLogicalPosition(-(truncatedWidth - (logicalLeft + totalLogicalWidth)), 0);
1831 }
hyatted77ad82004-06-15 07:21:23 +00001832 }
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001833 firstLine = false;
hyatted77ad82004-06-15 07:21:23 +00001834 }
1835}
1836
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001837bool RenderBlockFlow::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001838{
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00001839 if (!positionNewFloats())
1840 return false;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001841
rniwa@webkit.org44424752011-04-14 00:58:40 +00001842 width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001843
hyatt@apple.comdd78df82011-09-27 22:11:41 +00001844 // We only connect floats to lines for pagination purposes if the floats occur at the start of
1845 // the line and the previous line had a hard break (so this line is either the first in the block
1846 // or follows a <br>).
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001847 if (!newFloat->paginationStrut() || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00001848 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001849
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001850 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001851 ASSERT(floatingObjectSet.last().get() == newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001852
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001853 LayoutUnit floatLogicalTop = logicalTopForFloat(newFloat);
bjonesbe@adobe.combdee2ce2014-02-07 18:37:55 +00001854 LayoutUnit paginationStrut = newFloat->paginationStrut();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001855
hyatt@apple.com5950bd42011-09-27 20:39:57 +00001856 if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00001857 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001858
darin@apple.com7cad7042013-09-24 05:53:55 +00001859 auto it = floatingObjectSet.end();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001860 --it; // Last float is newFloat, skip that one.
darin@apple.com7cad7042013-09-24 05:53:55 +00001861 auto begin = floatingObjectSet.begin();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001862 while (it != begin) {
1863 --it;
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001864 FloatingObject* floatingObject = it->get();
1865 if (floatingObject == lastFloatFromPreviousLine)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001866 break;
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001867 if (logicalTopForFloat(floatingObject) == logicalHeight() + lineInfo.floatPaginationStrut()) {
1868 floatingObject->setPaginationStrut(paginationStrut + floatingObject->paginationStrut());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001869 RenderBox& floatBox = floatingObject->renderer();
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001870 setLogicalTopForChild(floatBox, logicalTopForChild(floatBox) + marginBeforeForChild(floatBox) + paginationStrut);
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00001871
1872 if (updateRegionRangeForBoxChild(floatingObject->renderer()))
1873 floatBox.setNeedsLayout(MarkOnlyThis);
1874 else if (floatBox.isRenderBlock())
weinig@apple.com12840dc2013-10-22 23:59:08 +00001875 toRenderBlock(floatBox).setChildNeedsLayout(MarkOnlyThis);
1876 floatBox.layoutIfNeeded();
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00001877
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001878 // Save the old logical top before calling removePlacedObject which will set
1879 // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat.
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001880 LayoutUnit oldLogicalTop = logicalTopForFloat(floatingObject);
1881 m_floatingObjects->removePlacedObject(floatingObject);
1882 setLogicalTopForFloat(floatingObject, oldLogicalTop + paginationStrut);
1883 m_floatingObjects->addPlacedObject(floatingObject);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001884 }
1885 }
1886
hyatt@apple.comdd78df82011-09-27 22:11:41 +00001887 // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing
1888 // no content, then we don't want to improperly grow the height of the block.
1889 lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut);
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00001890 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001891}
1892
weinig@apple.com6b4a24142014-01-05 00:28:39 +00001893LayoutUnit RenderBlockFlow::startAlignedOffsetForLine(LayoutUnit position, bool firstLine)
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00001894{
akling@apple.com827be9c2013-10-29 02:58:43 +00001895 ETextAlign textAlign = style().textAlign();
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00001896
hyatt@apple.coma5626692013-11-18 23:08:30 +00001897 // <rdar://problem/15427571>
1898 // https://bugs.webkit.org/show_bug.cgi?id=124522
1899 // This quirk is for legacy content that doesn't work properly with the center positioning scheme
1900 // being honored (e.g., epubs).
1901 if (textAlign == TASTART || document().settings()->useLegacyTextAlignPositionedElementBehavior()) // FIXME: Handle TAEND here
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00001902 return startOffsetForLine(position, firstLine);
1903
1904 // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here
robert@webkit.org82903f42012-08-28 19:18:40 +00001905 float totalLogicalWidth = 0;
1906 float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false);
1907 float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), false) - logicalLeft;
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001908
1909 // FIXME: Bug 129311: We need to pass a valid RootInlineBox here, considering the bidi level used to construct the line.
1910 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
robert@webkit.org7861a102011-09-22 17:16:47 +00001911
akling@apple.com827be9c2013-10-29 02:58:43 +00001912 if (!style().isLeftToRightDirection())
robert@webkit.org82903f42012-08-28 19:18:40 +00001913 return logicalWidth() - logicalLeft;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00001914 return logicalLeft;
1915}
1916
abucur@adobe.comd40287b2013-10-08 17:33:05 +00001917void RenderBlockFlow::updateRegionForLine(RootInlineBox* lineBox) const
1918{
1919 ASSERT(lineBox);
akling@apple.combdf247b2014-01-13 22:33:08 +00001920
1921 if (auto containingRegion = regionAtBlockOffset(lineBox->lineTopWithLeading()))
1922 lineBox->setContainingRegion(*containingRegion);
1923 else
1924 lineBox->clearContainingRegion();
abucur@adobe.comd40287b2013-10-08 17:33:05 +00001925
1926 RootInlineBox* prevLineBox = lineBox->prevRootBox();
1927 if (!prevLineBox)
1928 return;
1929
1930 // This check is more accurate than the one in |adjustLinePositionForPagination| because it takes into
1931 // account just the container changes between lines. The before mentioned function doesn't set the flag
1932 // correctly if the line is positioned at the top of the last fragment container.
1933 if (lineBox->containingRegion() != prevLineBox->containingRegion())
1934 lineBox->setIsFirstAfterPageBreak(true);
1935}
1936
hyattffe78712003-02-11 01:59:29 +00001937}