blob: eb3d728f4fbbd60cf6bac1518d20011102d53bb7 [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.com24199752013-10-08 23:20:42 +0000185InlineFlowBox* RenderBlockFlow::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox, bool startNewSegment)
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();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000208 bool mustCreateBoxesToRoot = startNewSegment && !(parentBox && parentBox->isRootInlineBox());
209 bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox) && !mustCreateBoxesToRoot;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000210 if (allowedToConstructNewBox && !canUseExistingParentBox) {
hyatt1d5d87b2007-04-24 04:55:54 +0000211 // We need to make a new box for this render object. Once
212 // made, we need to place it at the end of the current line.
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000213 InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this);
inferno@chromium.org14b04142013-02-04 18:43:03 +0000214 ASSERT_WITH_SECURITY_IMPLICATION(newBox->isInlineFlowBox());
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000215 parentBox = toInlineFlowBox(newBox);
antti@apple.comb0608f62013-09-28 18:30:16 +0000216 parentBox->setIsFirstLine(lineInfo.isFirstLine());
hyatt@apple.com2a5eb212011-03-22 23:21:54 +0000217 parentBox->setIsHorizontal(isHorizontalWritingMode());
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000218 if (!hasDefaultLineBoxContain)
219 parentBox->clearDescendantsHaveSameLineHeightAndBaseline();
hyatt1d5d87b2007-04-24 04:55:54 +0000220 constructedNewBox = true;
221 }
mitz@apple.come1364202008-02-28 01:06:41 +0000222
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000223 if (constructedNewBox || canUseExistingParentBox) {
224 if (!result)
225 result = parentBox;
hyatt1d5d87b2007-04-24 04:55:54 +0000226
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000227 // If we have hit the block itself, then |box| represents the root
228 // inline box for the line, and it doesn't have to be appended to any parent
229 // inline.
230 if (childBox)
231 parentBox->addToLine(childBox);
mitz@apple.come1364202008-02-28 01:06:41 +0000232
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000233 if (!constructedNewBox || obj == this)
234 break;
mitz@apple.come1364202008-02-28 01:06:41 +0000235
eric@webkit.org060caf62011-05-03 22:11:39 +0000236 childBox = parentBox;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000237 }
mitz@apple.come1364202008-02-28 01:06:41 +0000238
hyatt1d5d87b2007-04-24 04:55:54 +0000239 // If we've exceeded our line depth, then jump straight to the root and skip all the remaining
240 // intermediate inline flows.
241 obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent();
hyattffe78712003-02-11 01:59:29 +0000242
hyatt1d5d87b2007-04-24 04:55:54 +0000243 } while (true);
244
245 return result;
hyattffe78712003-02-11 01:59:29 +0000246}
247
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000248template <typename CharacterType>
249static inline bool endsWithASCIISpaces(const CharacterType* characters, unsigned pos, unsigned end)
250{
251 while (isASCIISpace(characters[pos])) {
252 pos++;
253 if (pos >= end)
254 return true;
255 }
256 return false;
257}
258
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000259static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns)
hyattffe78712003-02-11 01:59:29 +0000260{
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000261 BidiRun* run = bidiRuns.logicallyLastRun();
262 if (!run)
263 return true;
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000264 unsigned pos = run->stop();
akling@apple.com7506fda2013-11-07 10:12:36 +0000265 const RenderObject& r = run->renderer();
266 if (!r.isText())
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000267 return false;
akling@apple.com7506fda2013-11-07 10:12:36 +0000268 const RenderText& renderText = toRenderText(r);
269 unsigned length = renderText.textLength();
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000270 if (pos >= length)
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000271 return true;
272
akling@apple.com7506fda2013-11-07 10:12:36 +0000273 if (renderText.is8Bit())
274 return endsWithASCIISpaces(renderText.characters8(), pos, length);
275 return endsWithASCIISpaces(renderText.characters16(), pos, length);
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000276}
277
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000278RootInlineBox* RenderBlockFlow::constructLine(BidiRunList<BidiRun>& bidiRuns, const LineInfo& lineInfo)
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000279{
280 ASSERT(bidiRuns.firstRun());
hyattffe78712003-02-11 01:59:29 +0000281
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000282 bool rootHasSelectedChildren = false;
hyattffe78712003-02-11 01:59:29 +0000283 InlineFlowBox* parentBox = 0;
robert@webkit.org8cbab142011-12-30 20:58:29 +0000284 int runCount = bidiRuns.runCount() - lineInfo.runsFromLeadingWhitespace();
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000285 for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) {
hyattffe78712003-02-11 01:59:29 +0000286 // Create a box for our object.
robert@webkit.org8cbab142011-12-30 20:58:29 +0000287 bool isOnlyRun = (runCount == 1);
akling@apple.com7506fda2013-11-07 10:12:36 +0000288 if (runCount == 2 && !r->renderer().isListMarker())
289 isOnlyRun = (!style().isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->renderer().isListMarker();
mitz@apple.come1364202008-02-28 01:06:41 +0000290
robert@webkit.org56e5a9f2012-02-17 21:10:42 +0000291 if (lineInfo.isEmpty())
292 continue;
293
akling@apple.com7506fda2013-11-07 10:12:36 +0000294 InlineBox* box = createInlineBoxForRenderer(&r->renderer(), false, isOnlyRun);
295 r->setBox(*box);
hyattffe78712003-02-11 01:59:29 +0000296
akling@apple.com0b8172b72013-08-31 18:34:23 +0000297 if (!rootHasSelectedChildren && box->renderer().selectionState() != RenderObject::SelectionNone)
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000298 rootHasSelectedChildren = true;
299
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000300 // If we have no parent box yet, or if the run is not simply a sibling,
301 // then we need to construct inline boxes as necessary to properly enclose the
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000302 // run's inline box. Segments can only be siblings at the root level, as
303 // they are positioned separately.
betravis@adobe.comed90c982013-06-05 23:05:57 +0000304#if ENABLE(CSS_SHAPES)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000305 bool runStartsSegment = r->m_startsSegment;
306#else
307 bool runStartsSegment = false;
308#endif
akling@apple.com7506fda2013-11-07 10:12:36 +0000309 if (!parentBox || &parentBox->renderer() != r->renderer().parent() || runStartsSegment)
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000310 // Create new inline boxes all the way back to the appropriate insertion point.
akling@apple.com7506fda2013-11-07 10:12:36 +0000311 parentBox = createLineBoxes(r->renderer().parent(), lineInfo, box, runStartsSegment);
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000312 else {
313 // Append the inline box to this line.
314 parentBox->addToLine(box);
315 }
mitz@apple.com576e84e2008-04-24 19:09:48 +0000316
akling@apple.com7506fda2013-11-07 10:12:36 +0000317 bool visuallyOrdered = r->renderer().style().rtlOrdering() == VisualOrder;
xji@chromium.org6b0c0172011-02-14 19:21:12 +0000318 box->setBidiLevel(r->level());
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000319
320 if (box->isInlineTextBox()) {
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000321 InlineTextBox* text = toInlineTextBox(box);
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000322 text->setStart(r->m_start);
323 text->setLen(r->m_stop - r->m_start);
rniwa@webkit.org296fcae2012-03-29 09:48:42 +0000324 text->setDirOverride(r->dirOverride(visuallyOrdered));
mitz@apple.comb2107652010-06-21 16:54:52 +0000325 if (r->m_hasHyphen)
326 text->setHasHyphen(true);
hyatt0c3a9862004-02-23 21:26:26 +0000327 }
hyattffe78712003-02-11 01:59:29 +0000328 }
329
330 // We should have a root inline box. It should be unconstructed and
331 // be the last continuation of our line list.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000332 ASSERT(lastRootBox() && !lastRootBox()->isConstructed());
hyattffe78712003-02-11 01:59:29 +0000333
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000334 // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box
335 // from the bidi runs walk above has a selection state.
336 if (rootHasSelectedChildren)
akling@apple.comee3c8df2013-11-06 08:09:44 +0000337 lastRootBox()->root().setHasSelectedChildren(true);
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000338
hyattffe78712003-02-11 01:59:29 +0000339 // Set bits on our inline flow boxes that indicate which sides should
340 // paint borders/margins/padding. This knowledge will ultimately be used when
341 // we determine the horizontal positions and widths of all the inline boxes on
342 // the line.
akling@apple.com7506fda2013-11-07 10:12:36 +0000343 bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->renderer().isText() ? !reachedEndOfTextRenderer(bidiRuns) : true;
344 lastRootBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, &bidiRuns.logicallyLastRun()->renderer());
hyattffe78712003-02-11 01:59:29 +0000345
346 // Now mark the line boxes as being constructed.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000347 lastRootBox()->setConstructed();
hyattffe78712003-02-11 01:59:29 +0000348
349 // Return the last line.
hyatt0c3a9862004-02-23 21:26:26 +0000350 return lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000351}
352
weinig@apple.com6b4a24142014-01-05 00:28:39 +0000353ETextAlign RenderBlockFlow::textAlignmentForLine(bool endsWithSoftBreak) const
mitz@apple.com390fa322011-02-24 23:07:06 +0000354{
akling@apple.com827be9c2013-10-29 02:58:43 +0000355 ETextAlign alignment = style().textAlign();
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000356 if (endsWithSoftBreak)
357 return alignment;
mitz@apple.com390fa322011-02-24 23:07:06 +0000358
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000359#if !ENABLE(CSS3_TEXT)
360 return (alignment == JUSTIFY) ? TASTART : alignment;
361#else
362 if (alignment != JUSTIFY)
363 return alignment;
364
365 TextAlignLast alignmentLast = style().textAlignLast();
366 switch (alignmentLast) {
367 case TextAlignLastStart:
368 return TASTART;
369 case TextAlignLastEnd:
370 return TAEND;
371 case TextAlignLastLeft:
372 return LEFT;
373 case TextAlignLastRight:
374 return RIGHT;
375 case TextAlignLastCenter:
376 return CENTER;
377 case TextAlignLastJustify:
378 return JUSTIFY;
379 case TextAlignLastAuto:
380 if (style().textJustify() == TextJustifyDistribute)
381 return JUSTIFY;
382 return TASTART;
383 }
mitz@apple.com390fa322011-02-24 23:07:06 +0000384 return alignment;
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000385#endif
mitz@apple.com390fa322011-02-24 23:07:06 +0000386}
387
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000388static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
389{
390 // The direction of the block should determine what happens with wide lines.
391 // In particular with RTL blocks, wide lines should still spill out to the left.
392 if (isLeftToRightDirection) {
393 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
andersca@apple.com86298632013-11-10 19:32:33 +0000394 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000395 return;
396 }
397
398 if (trailingSpaceRun)
akling@apple.com7506fda2013-11-07 10:12:36 +0000399 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000400 else if (totalLogicalWidth > availableLogicalWidth)
401 logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
402}
403
404static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
405{
406 // Wide lines spill out of the block based off direction.
407 // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
408 // side of the block.
409 if (isLeftToRightDirection) {
410 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000411 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
412 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000413 }
414 if (totalLogicalWidth < availableLogicalWidth)
415 logicalLeft += availableLogicalWidth - totalLogicalWidth;
416 return;
417 }
418
419 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
andersca@apple.com86298632013-11-10 19:32:33 +0000420 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
akling@apple.com7506fda2013-11-07 10:12:36 +0000421 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000422 } else
423 logicalLeft += availableLogicalWidth - totalLogicalWidth;
424}
425
426static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
427{
428 float trailingSpaceWidth = 0;
429 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000430 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
andersca@apple.com86298632013-11-10 19:32:33 +0000431 trailingSpaceWidth = std::min(trailingSpaceRun->box()->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2);
432 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000433 }
434 if (isLeftToRightDirection)
andersca@apple.com86298632013-11-10 19:32:33 +0000435 logicalLeft += std::max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000436 else
437 logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
438}
439
weinig@apple.com12840dc2013-10-22 23:59:08 +0000440void RenderBlockFlow::setMarginsForRubyRun(BidiRun* run, RenderRubyRun& renderer, RenderObject* previousObject, const LineInfo& lineInfo)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000441{
442 int startOverhang;
443 int endOverhang;
444 RenderObject* nextObject = 0;
445 for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000446 if (!runWithNextObject->renderer().isOutOfFlowPositioned() && !runWithNextObject->box()->isLineBreak()) {
447 nextObject = &runWithNextObject->renderer();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000448 break;
449 }
450 }
akling@apple.com827be9c2013-10-29 02:58:43 +0000451 renderer.getOverhang(lineInfo.isFirstLine(), renderer.style().isLeftToRightDirection() ? previousObject : nextObject, renderer.style().isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000452 setMarginStartForChild(renderer, -startOverhang);
453 setMarginEndForChild(renderer, -endOverhang);
454}
455
456static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText* renderer, float xPos, const LineInfo& lineInfo,
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000457 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000458{
459 HashSet<const SimpleFontData*> fallbackFonts;
460 GlyphOverflow glyphOverflow;
antti@apple.comb0608f62013-09-28 18:30:16 +0000461
462 const Font& font = lineStyle(*renderer->parent(), lineInfo).font();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000463 // Always compute glyph overflow if the block's line-box-contain value is "glyphs".
464 if (lineBox->fitsToGlyphs()) {
465 // If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization
466 // will keep us from computing glyph bounds in nearly all cases.
467 bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading();
akling@apple.com7506fda2013-11-07 10:12:36 +0000468 int baselineShift = lineBox->verticalPositionForBox(run->box(), verticalPositionCache);
enrica@apple.com885c84d2012-10-10 05:48:51 +0000469 int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0;
470 int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0;
471 int boxAscent = font.fontMetrics().ascent() - baselineShift;
472 int boxDescent = font.fontMetrics().descent() + baselineShift;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000473 if (boxAscent > rootDescent || boxDescent > rootAscent)
474 glyphOverflow.computeBounds = true;
475 }
476
leviw@chromium.orgd32486e2012-03-16 10:52:56 +0000477 LayoutUnit hyphenWidth = 0;
akling@apple.com7506fda2013-11-07 10:12:36 +0000478 if (toInlineTextBox(run->box())->hasHyphen())
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000479 hyphenWidth = measureHyphenWidth(renderer, font, &fallbackFonts);
antti@apple.comb0608f62013-09-28 18:30:16 +0000480
enrica@apple.com885c84d2012-10-10 05:48:51 +0000481 float measuredWidth = 0;
482
enrica@apple.com885c84d2012-10-10 05:48:51 +0000483 bool kerningIsEnabled = font.typesettingFeatures() & Kerning;
leviw@chromium.orgd70f4cc2013-03-28 21:03:44 +0000484 bool canUseSimpleFontCodePath = renderer->canUseSimpleFontCodePath();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000485
486 // Since we don't cache glyph overflows, we need to re-measure the run if
487 // the style is linebox-contain: glyph.
488
leviw@chromium.orgd70f4cc2013-03-28 21:03:44 +0000489 if (!lineBox->fitsToGlyphs() && canUseSimpleFontCodePath) {
enrica@apple.com885c84d2012-10-10 05:48:51 +0000490 int lastEndOffset = run->m_start;
491 for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOffset < run->m_stop; ++i) {
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000492 WordMeasurement& wordMeasurement = wordMeasurements[i];
493 if (wordMeasurement.width <= 0 || wordMeasurement.startOffset == wordMeasurement.endOffset)
enrica@apple.com885c84d2012-10-10 05:48:51 +0000494 continue;
495 if (wordMeasurement.renderer != renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop)
496 continue;
497
498 lastEndOffset = wordMeasurement.endOffset;
499 if (kerningIsEnabled && lastEndOffset == run->m_stop) {
dino@apple.com7c50e7c2013-03-18 18:01:05 +0000500 int wordLength = lastEndOffset - wordMeasurement.startOffset;
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000501 GlyphOverflow overflow;
502 measuredWidth += renderer->width(wordMeasurement.startOffset, wordLength, xPos + measuredWidth, lineInfo.isFirstLine(),
503 &wordMeasurement.fallbackFonts, &overflow);
dino@apple.comd0b89252013-05-10 18:20:28 +0000504 UChar c = renderer->characterAt(wordMeasurement.startOffset);
505 if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t'))
mmaxfield@apple.com516f09b2014-01-11 00:31:19 +0000506 measuredWidth += renderer->style().font().wordSpacing();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000507 } else
508 measuredWidth += wordMeasurement.width;
509 if (!wordMeasurement.fallbackFonts.isEmpty()) {
510 HashSet<const SimpleFontData*>::const_iterator end = wordMeasurement.fallbackFonts.end();
511 for (HashSet<const SimpleFontData*>::const_iterator it = wordMeasurement.fallbackFonts.begin(); it != end; ++it)
512 fallbackFonts.add(*it);
513 }
514 }
515 if (measuredWidth && lastEndOffset != run->m_stop) {
516 // If we don't have enough cached data, we'll measure the run again.
517 measuredWidth = 0;
518 fallbackFonts.clear();
519 }
520 }
enrica@apple.com885c84d2012-10-10 05:48:51 +0000521
522 if (!measuredWidth)
523 measuredWidth = renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow);
524
akling@apple.com7506fda2013-11-07 10:12:36 +0000525 run->box()->setLogicalWidth(measuredWidth + hyphenWidth);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000526 if (!fallbackFonts.isEmpty()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000527 ASSERT(run->box()->behavesLikeText());
andersca@apple.com86298632013-11-10 19:32:33 +0000528 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->box()), std::make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000529 ASSERT(it->value.first.isEmpty());
530 copyToVector(fallbackFonts, it->value.first);
akling@apple.com7506fda2013-11-07 10:12:36 +0000531 run->box()->parent()->clearDescendantsHaveSameLineHeightAndBaseline();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000532 }
533 if ((glyphOverflow.top || glyphOverflow.bottom || glyphOverflow.left || glyphOverflow.right)) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000534 ASSERT(run->box()->behavesLikeText());
andersca@apple.com86298632013-11-10 19:32:33 +0000535 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->box()), std::make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000536 it->value.second = glyphOverflow;
akling@apple.com7506fda2013-11-07 10:12:36 +0000537 run->box()->clearKnownToHaveNoOverflow();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000538 }
539}
540
541static inline void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth)
542{
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000543 if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth)
544 return;
545
546 size_t i = 0;
547 for (BidiRun* r = firstRun; r; r = r->next()) {
betravis@adobe.comed90c982013-06-05 23:05:57 +0000548#if ENABLE(CSS_SHAPES)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000549 // This method is called once per segment, do not move past the current segment.
550 if (r->m_startsSegment)
551 break;
552#endif
akling@apple.com7506fda2013-11-07 10:12:36 +0000553 if (!r->box() || r == trailingSpaceRun)
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000554 continue;
555
akling@apple.com7506fda2013-11-07 10:12:36 +0000556 if (r->renderer().isText()) {
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000557 unsigned opportunitiesInRun = expansionOpportunities[i++];
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000558
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000559 ASSERT(opportunitiesInRun <= expansionOpportunityCount);
560
561 // Only justify text if whitespace is collapsed.
akling@apple.com7506fda2013-11-07 10:12:36 +0000562 if (r->renderer().style().collapseWhiteSpace()) {
563 InlineTextBox* textBox = toInlineTextBox(r->box());
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000564 int expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
565 textBox->setExpansion(expansion);
566 totalLogicalWidth += expansion;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000567 }
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000568 expansionOpportunityCount -= opportunitiesInRun;
569 if (!expansionOpportunityCount)
570 break;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000571 }
572 }
573}
574
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000575void 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 +0000576{
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000577 TextDirection direction;
578 if (rootInlineBox && style().unicodeBidi() == Plaintext)
579 direction = rootInlineBox->direction();
580 else
581 direction = style().direction();
582
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000583 // Armed with the total width of the line (without justification),
584 // we now examine our text-align property in order to determine where to position the
585 // objects horizontally. The total width of the line can be increased if we end up
586 // justifying text.
587 switch (textAlign) {
588 case LEFT:
589 case WEBKIT_LEFT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000590 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000591 break;
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000592 case RIGHT:
593 case WEBKIT_RIGHT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000594 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000595 break;
596 case CENTER:
597 case WEBKIT_CENTER:
akling@apple.com827be9c2013-10-29 02:58:43 +0000598 updateLogicalWidthForCenterAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000599 break;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000600 case JUSTIFY:
601 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
602 if (expansionOpportunityCount) {
603 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000604 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
605 trailingSpaceRun->box()->setLogicalWidth(0);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000606 }
607 break;
608 }
joepeck@webkit.orgaa676ee52014-01-28 04:04:52 +0000609 FALLTHROUGH;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000610 case TASTART:
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000611 if (direction == LTR)
akling@apple.com827be9c2013-10-29 02:58:43 +0000612 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000613 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000614 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000615 break;
616 case TAEND:
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000617 if (direction == LTR)
akling@apple.com827be9c2013-10-29 02:58:43 +0000618 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000619 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000620 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000621 break;
622 }
623}
624
weinig@apple.come9621c32014-01-04 20:53:51 +0000625static 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 +0000626{
weinig@apple.come9621c32014-01-04 20:53:51 +0000627 LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight);
628 lineLogicalLeft = block.pixelSnappedLogicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
629 lineLogicalRight = block.pixelSnappedLogicalRightOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
robert@webkit.org0903cf52012-12-11 18:14:16 +0000630 availableLogicalWidth = lineLogicalRight - lineLogicalLeft;
631}
632
weinig@apple.come9621c32014-01-04 20:53:51 +0000633void 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 +0000634{
mitz@apple.com390fa322011-02-24 23:07:06 +0000635 ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
robert@webkit.org4f76df92012-07-03 17:41:35 +0000636
robert@webkit.org328ecd02012-08-09 21:12:44 +0000637 // 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
638 // box is only affected if it is the first child of its parent element."
commit-queue@webkit.orgab781b02013-04-03 01:32:24 +0000639 // CSS3 "text-indent", "-webkit-each-line" affects the first line of the block container as well as each line after a forced line break,
640 // but does not affect lines after a soft wrap break.
641 bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this);
642 bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox()->endsWithBreak();
akling@apple.com827be9c2013-10-29 02:58:43 +0000643 IndentTextOrNot shouldIndentText = requiresIndent(isFirstLine, isAfterHardLineBreak, style());
robert@webkit.org0903cf52012-12-11 18:14:16 +0000644 float lineLogicalLeft;
645 float lineLogicalRight;
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000646 float availableLogicalWidth;
weinig@apple.come9621c32014-01-04 20:53:51 +0000647 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000648 bool needsWordSpacing;
dino@apple.comc133a8c2014-02-03 23:35:34 +0000649#if ENABLE(CSS_SHAPES) && ENABLE(CSS_SHAPE_INSIDE)
betravis@adobe.comcf7cba62013-06-10 21:23:45 +0000650 ShapeInsideInfo* shapeInsideInfo = layoutShapeInsideInfo();
651 if (shapeInsideInfo && shapeInsideInfo->hasSegments()) {
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000652 BidiRun* segmentStart = firstRun;
betravis@adobe.comcf7cba62013-06-10 21:23:45 +0000653 const SegmentList& segments = shapeInsideInfo->segments();
andersca@apple.com86298632013-11-10 19:32:33 +0000654 float logicalLeft = std::max<float>(roundToInt(segments[0].logicalLeft), lineLogicalLeft);
655 float logicalRight = std::min<float>(floorToInt(segments[0].logicalRight), lineLogicalRight);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000656 float startLogicalLeft = logicalLeft;
657 float endLogicalRight = logicalLeft;
658 float minLogicalLeft = logicalLeft;
659 float maxLogicalRight = logicalLeft;
660 lineBox->beginPlacingBoxRangesInInlineDirection(logicalLeft);
661 for (size_t i = 0; i < segments.size(); i++) {
662 if (i) {
andersca@apple.com86298632013-11-10 19:32:33 +0000663 logicalLeft = std::max<float>(roundToInt(segments[i].logicalLeft), lineLogicalLeft);
664 logicalRight = std::min<float>(floorToInt(segments[i].logicalRight), lineLogicalRight);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000665 }
666 availableLogicalWidth = logicalRight - logicalLeft;
667 BidiRun* newSegmentStart = computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, logicalLeft, availableLogicalWidth, segmentStart, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
668 needsWordSpacing = false;
akling@apple.com7506fda2013-11-07 10:12:36 +0000669 endLogicalRight = lineBox->placeBoxRangeInInlineDirection(segmentStart->box(), newSegmentStart ? newSegmentStart->box() : 0, logicalLeft, minLogicalLeft, maxLogicalRight, needsWordSpacing, textBoxDataMap);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000670 if (!newSegmentStart || !newSegmentStart->next())
671 break;
672 ASSERT(newSegmentStart->m_startsSegment);
673 // Discard the empty segment start marker bidi runs
674 segmentStart = newSegmentStart->next();
675 }
676 lineBox->endPlacingBoxRangesInInlineDirection(startLogicalLeft, endLogicalRight, minLogicalLeft, maxLogicalRight);
677 return;
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +0000678 }
679#endif
robert@webkit.org0903cf52012-12-11 18:14:16 +0000680
akling@apple.com7506fda2013-11-07 10:12:36 +0000681 if (firstRun && firstRun->renderer().isReplaced()) {
682 RenderBox& renderBox = toRenderBox(firstRun->renderer());
weinig@apple.come9621c32014-01-04 20:53:51 +0000683 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight());
robert@webkit.org0903cf52012-12-11 18:14:16 +0000684 }
685
686 computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000687 // The widths of all runs are now known. We can now place every inline box (and
688 // compute accurate widths for the inline flow boxes).
689 needsWordSpacing = false;
690 lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing, textBoxDataMap);
691}
mitz@apple.com390fa322011-02-24 23:07:06 +0000692
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000693BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBox* lineBox, const LineInfo& lineInfo, ETextAlign textAlign, float& logicalLeft,
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000694 float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache,
695 WordMeasurements& wordMeasurements)
696{
darin06dcb9c2005-08-15 04:31:09 +0000697 bool needsWordSpacing = false;
mitz@apple.com390fa322011-02-24 23:07:06 +0000698 float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();
mitz@apple.com86470c82011-01-27 01:39:27 +0000699 unsigned expansionOpportunityCount = 0;
700 bool isAfterExpansion = true;
701 Vector<unsigned, 16> expansionOpportunities;
mitz@apple.comddb59872011-04-05 05:21:16 +0000702 RenderObject* previousObject = 0;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000703
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000704 BidiRun* r = firstRun;
705 for (; r; r = r->next()) {
betravis@adobe.comed90c982013-06-05 23:05:57 +0000706#if ENABLE(CSS_SHAPES)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000707 // Once we have reached the start of the next segment, we have finished
708 // computing the positions for this segment's contents.
709 if (r->m_startsSegment)
710 break;
711#endif
akling@apple.com7506fda2013-11-07 10:12:36 +0000712 if (!r->box() || r->renderer().isOutOfFlowPositioned() || r->box()->isLineBreak())
hyatt98ee7e42003-05-14 01:39:15 +0000713 continue; // Positioned objects are only participating to figure out their
714 // correct static x position. They have no effect on the width.
hyatt0c05e102006-04-14 08:15:00 +0000715 // Similarly, line break boxes have no effect on the width.
akling@apple.com7506fda2013-11-07 10:12:36 +0000716 if (r->renderer().isText()) {
717 RenderText& rt = toRenderText(r->renderer());
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000718 if (textAlign == JUSTIFY && r != trailingSpaceRun) {
mitz@apple.com80968932011-03-26 00:46:26 +0000719 if (!isAfterExpansion)
akling@apple.com7506fda2013-11-07 10:12:36 +0000720 toInlineTextBox(r->box())->setCanHaveLeadingExpansion(true);
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000721 unsigned opportunitiesInRun;
akling@apple.com7506fda2013-11-07 10:12:36 +0000722 if (rt.is8Bit())
723 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 +0000724 else
akling@apple.com7506fda2013-11-07 10:12:36 +0000725 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 +0000726 expansionOpportunities.append(opportunitiesInRun);
727 expansionOpportunityCount += opportunitiesInRun;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000728 }
729
akling@apple.com7506fda2013-11-07 10:12:36 +0000730 if (int length = rt.textLength()) {
731 if (!r->m_start && needsWordSpacing && isSpaceOrNewline(rt.characterAt(r->m_start)))
732 totalLogicalWidth += lineStyle(*rt.parent(), lineInfo).font().wordSpacing();
733 needsWordSpacing = !isSpaceOrNewline(rt.characterAt(r->m_stop - 1)) && r->m_stop == length;
darin06dcb9c2005-08-15 04:31:09 +0000734 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000735
akling@apple.com7506fda2013-11-07 10:12:36 +0000736 setLogicalWidthForTextRun(lineBox, r, &rt, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
mitz@apple.com86470c82011-01-27 01:39:27 +0000737 } else {
738 isAfterExpansion = false;
akling@apple.com7506fda2013-11-07 10:12:36 +0000739 if (!r->renderer().isRenderInline()) {
740 RenderBox& renderBox = toRenderBox(r->renderer());
weinig@apple.com12840dc2013-10-22 23:59:08 +0000741 if (renderBox.isRubyRun())
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000742 setMarginsForRubyRun(r, toRenderRubyRun(renderBox), previousObject, lineInfo);
akling@apple.com7506fda2013-11-07 10:12:36 +0000743 r->box()->setLogicalWidth(logicalWidthForChild(renderBox));
mitz@apple.com86470c82011-01-27 01:39:27 +0000744 totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox);
745 }
hyattffe78712003-02-11 01:59:29 +0000746 }
hyatt4b381692003-03-10 21:11:59 +0000747
akling@apple.com7506fda2013-11-07 10:12:36 +0000748 totalLogicalWidth += r->box()->logicalWidth();
749 previousObject = &r->renderer();
hyattffe78712003-02-11 01:59:29 +0000750 }
751
mitz@apple.com86470c82011-01-27 01:39:27 +0000752 if (isAfterExpansion && !expansionOpportunities.isEmpty()) {
753 expansionOpportunities.last()--;
754 expansionOpportunityCount--;
755 }
756
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000757 updateLogicalWidthForAlignment(textAlign, lineBox, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount);
hyattffe78712003-02-11 01:59:29 +0000758
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000759 computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth);
mitz@apple.come1364202008-02-28 01:06:41 +0000760
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000761 return r;
hyattffe78712003-02-11 01:59:29 +0000762}
763
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000764void RenderBlockFlow::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000765 VerticalPositionCache& verticalPositionCache)
hyattffe78712003-02-11 01:59:29 +0000766{
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000767 setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache));
hyattffe78712003-02-11 01:59:29 +0000768
769 // Now make sure we place replaced render objects correctly.
mitz@apple.com887f3592008-02-25 22:03:08 +0000770 for (BidiRun* r = firstRun; r; r = r->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000771 ASSERT(r->box());
772 if (!r->box())
eseidel789896f2005-11-27 22:52:09 +0000773 continue; // Skip runs with no line boxes.
hyatt0c3a9862004-02-23 21:26:26 +0000774
akling@apple.com27e7d142013-11-07 12:04:02 +0000775 InlineBox& box = *r->box();
776
hyatt98ee7e42003-05-14 01:39:15 +0000777 // Align positioned boxes with the top of the line box. This is
778 // a reasonable approximation of an appropriate y position.
akling@apple.com7506fda2013-11-07 10:12:36 +0000779 if (r->renderer().isOutOfFlowPositioned())
akling@apple.com27e7d142013-11-07 12:04:02 +0000780 box.setLogicalTop(logicalHeight());
hyatt98ee7e42003-05-14 01:39:15 +0000781
782 // Position is used to properly position both replaced elements and
783 // to update the static normal flow x/y of positioned elements.
akling@apple.com7506fda2013-11-07 10:12:36 +0000784 if (r->renderer().isText())
akling@apple.com27e7d142013-11-07 12:04:02 +0000785 toRenderText(r->renderer()).positionLineBox(toInlineTextBox(box));
akling@apple.com7506fda2013-11-07 10:12:36 +0000786 else if (r->renderer().isBox())
akling@apple.com27e7d142013-11-07 12:04:02 +0000787 toRenderBox(r->renderer()).positionLineBox(toInlineElementBox(box));
akling@apple.com7506fda2013-11-07 10:12:36 +0000788 else if (r->renderer().isLineBreak())
akling@apple.com27e7d142013-11-07 12:04:02 +0000789 toRenderLineBreak(r->renderer()).replaceInlineBoxWrapper(toInlineElementBox(box));
hyatt98ee7e42003-05-14 01:39:15 +0000790 }
mitz@apple.coma927be62008-03-21 05:30:19 +0000791 // Positioned objects and zero-length text nodes destroy their boxes in
792 // position(), which unnecessarily dirties the line.
793 lineBox->markDirty(false);
hyattffe78712003-02-11 01:59:29 +0000794}
kociendabb0c24b2001-08-24 14:24:40 +0000795
akling@apple.com7506fda2013-11-07 10:12:36 +0000796static inline bool isCollapsibleSpace(UChar character, const RenderText& renderer)
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000797{
798 if (character == ' ' || character == '\t' || character == softHyphen)
799 return true;
800 if (character == '\n')
akling@apple.com7506fda2013-11-07 10:12:36 +0000801 return !renderer.style().preserveNewline();
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000802 if (character == noBreakSpace)
akling@apple.com7506fda2013-11-07 10:12:36 +0000803 return renderer.style().nbspMode() == SPACE;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000804 return false;
805}
806
msaboff@apple.com142fc202012-10-18 18:03:14 +0000807template <typename CharacterType>
akling@apple.com7506fda2013-11-07 10:12:36 +0000808static inline int findFirstTrailingSpace(const RenderText& lastText, const CharacterType* characters, int start, int stop)
msaboff@apple.com142fc202012-10-18 18:03:14 +0000809{
810 int firstSpace = stop;
811 while (firstSpace > start) {
812 UChar current = characters[firstSpace - 1];
813 if (!isCollapsibleSpace(current, lastText))
814 break;
815 firstSpace--;
816 }
817
818 return firstSpace;
819}
820
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000821inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext)
eric@webkit.org0894bb82011-04-03 08:29:40 +0000822{
eric@webkit.org5bee2942011-04-08 02:12:31 +0000823 if (!bidiRuns.runCount()
akling@apple.com7506fda2013-11-07 10:12:36 +0000824 || !bidiRuns.logicallyLastRun()->renderer().style().breakOnlyAfterWhiteSpace()
825 || !bidiRuns.logicallyLastRun()->renderer().style().autoWrap())
eric@webkit.org0894bb82011-04-03 08:29:40 +0000826 return 0;
827
eric@webkit.org5bee2942011-04-08 02:12:31 +0000828 BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun();
akling@apple.com7506fda2013-11-07 10:12:36 +0000829 const RenderObject& lastObject = trailingSpaceRun->renderer();
830 if (!lastObject.isText())
eric@webkit.org0894bb82011-04-03 08:29:40 +0000831 return 0;
832
akling@apple.com7506fda2013-11-07 10:12:36 +0000833 const RenderText& lastText = toRenderText(lastObject);
msaboff@apple.com142fc202012-10-18 18:03:14 +0000834 int firstSpace;
akling@apple.com7506fda2013-11-07 10:12:36 +0000835 if (lastText.is8Bit())
836 firstSpace = findFirstTrailingSpace(lastText, lastText.characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +0000837 else
akling@apple.com7506fda2013-11-07 10:12:36 +0000838 firstSpace = findFirstTrailingSpace(lastText, lastText.characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +0000839
eric@webkit.org0894bb82011-04-03 08:29:40 +0000840 if (firstSpace == trailingSpaceRun->stop())
841 return 0;
842
akling@apple.com827be9c2013-10-29 02:58:43 +0000843 TextDirection direction = style().direction();
eric@webkit.org5bee2942011-04-08 02:12:31 +0000844 bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun());
eric@webkit.org0894bb82011-04-03 08:29:40 +0000845 if (firstSpace != trailingSpaceRun->start()) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000846 BidiContext* baseContext = currentContext;
eric@webkit.org0894bb82011-04-03 08:29:40 +0000847 while (BidiContext* parent = baseContext->parent())
848 baseContext = parent;
849
akling@apple.com7506fda2013-11-07 10:12:36 +0000850 BidiRun* newTrailingRun = new BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->renderer(), baseContext, U_OTHER_NEUTRAL);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000851 trailingSpaceRun->m_stop = firstSpace;
852 if (direction == LTR)
eric@webkit.org5bee2942011-04-08 02:12:31 +0000853 bidiRuns.addRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000854 else
eric@webkit.org5bee2942011-04-08 02:12:31 +0000855 bidiRuns.prependRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000856 trailingSpaceRun = newTrailingRun;
857 return trailingSpaceRun;
858 }
859 if (!shouldReorder)
860 return trailingSpaceRun;
861
862 if (direction == LTR) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000863 bidiRuns.moveRunToEnd(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000864 trailingSpaceRun->m_level = 0;
865 } else {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000866 bidiRuns.moveRunToBeginning(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000867 trailingSpaceRun->m_level = 1;
868 }
869 return trailingSpaceRun;
870}
871
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000872void RenderBlockFlow::appendFloatingObjectToLastLine(FloatingObject* floatingObject)
mitz@apple.comd17e8c02011-04-16 21:59:36 +0000873{
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +0000874 ASSERT(!floatingObject->originatingLine());
875 floatingObject->setOriginatingLine(lastRootBox());
weinig@apple.com12840dc2013-10-22 23:59:08 +0000876 lastRootBox()->appendFloat(floatingObject->renderer());
mitz@apple.comd17e8c02011-04-16 21:59:36 +0000877}
878
mmaxfield@apple.com434c8722014-01-28 22:03:57 +0000879static inline void setUpResolverToResumeInIsolate(InlineBidiResolver& resolver, RenderObject* root, RenderObject* startObject)
mmaxfield@apple.com18782a22014-01-28 21:53:22 +0000880{
881 if (root != startObject) {
882 RenderObject* parent = startObject->parent();
mmaxfield@apple.com434c8722014-01-28 22:03:57 +0000883 setUpResolverToResumeInIsolate(resolver, root, parent);
mmaxfield@apple.com18782a22014-01-28 21:53:22 +0000884 notifyObserverEnteredObject(&resolver, startObject);
885 }
886}
887
eric@webkit.orga26de042011-09-08 18:46:01 +0000888// FIXME: BidiResolver should have this logic.
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000889static inline void constructBidiRunsForSegment(InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfRuns, VisualDirectionOverride override, bool previousLineBrokeCleanly)
eric@webkit.orga26de042011-09-08 18:46:01 +0000890{
891 // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead
892 // of the resolver owning the runs.
893 ASSERT(&topResolver.runs() == &bidiRuns);
betravis@adobe.com9e5e8242013-04-19 23:28:26 +0000894 ASSERT(topResolver.position() != endOfRuns);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000895 RenderObject* currentRoot = topResolver.position().root();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000896 topResolver.createBidiRunsForLine(endOfRuns, override, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +0000897
898 while (!topResolver.isolatedRuns().isEmpty()) {
899 // It does not matter which order we resolve the runs as long as we resolve them all.
900 BidiRun* isolatedRun = topResolver.isolatedRuns().last();
901 topResolver.isolatedRuns().removeLast();
902
akling@apple.com7506fda2013-11-07 10:12:36 +0000903 RenderObject& startObj = isolatedRun->renderer();
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000904
eric@webkit.orga26de042011-09-08 18:46:01 +0000905 // Only inlines make sense with unicode-bidi: isolate (blocks are already isolated).
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000906 // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the
907 // tree to see which parent inline is the isolate. We could change enterIsolate
908 // to take a RenderObject and do this logic there, but that would be a layering
909 // violation for BidiResolver (which knows nothing about RenderObject).
akling@apple.com7506fda2013-11-07 10:12:36 +0000910 RenderInline* isolatedInline = toRenderInline(containingIsolate(&startObj, currentRoot));
eric@webkit.orga26de042011-09-08 18:46:01 +0000911 InlineBidiResolver isolatedResolver;
akling@apple.com827be9c2013-10-29 02:58:43 +0000912 EUnicodeBidi unicodeBidi = isolatedInline->style().unicodeBidi();
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000913 TextDirection direction;
914 if (unicodeBidi == Plaintext)
akling@apple.com7506fda2013-11-07 10:12:36 +0000915 determineDirectionality(direction, InlineIterator(isolatedInline, &isolatedRun->renderer(), 0));
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000916 else {
rniwa@webkit.org4d4bd332012-08-20 21:34:11 +0000917 ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride);
akling@apple.com827be9c2013-10-29 02:58:43 +0000918 direction = isolatedInline->style().direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000919 }
zoltan@webkit.orgd1a97402013-12-08 05:53:33 +0000920 isolatedResolver.setStatus(BidiStatus(direction, isOverride(unicodeBidi)));
eric@webkit.orga26de042011-09-08 18:46:01 +0000921
mmaxfield@apple.com434c8722014-01-28 22:03:57 +0000922 setUpResolverToResumeInIsolate(isolatedResolver, isolatedInline, &startObj);
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000923
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000924 // The starting position is the beginning of the first run within the isolate that was identified
925 // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the
926 // first run within the isolate.
akling@apple.com7506fda2013-11-07 10:12:36 +0000927 InlineIterator iter = InlineIterator(isolatedInline, &startObj, isolatedRun->m_start);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000928 isolatedResolver.setPositionIgnoringNestedIsolates(iter);
eric@webkit.orga26de042011-09-08 18:46:01 +0000929
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000930 // 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 +0000931 // FIXME: What should end and previousLineBrokeCleanly be?
932 // rniwa says previousLineBrokeCleanly is just a WinIE hack and could always be false here?
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000933 isolatedResolver.createBidiRunsForLine(endOfRuns, NoVisualOverride, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +0000934 // Note that we do not delete the runs from the resolver.
rniwa@webkit.orgd0ad8882012-05-23 07:37:07 +0000935 // 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 +0000936 // itself to be turned into an InlineBox. We can't remove it here without potentially losing track of
937 // the logically last run.
938 if (isolatedResolver.runs().runCount())
939 bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs());
eric@webkit.orga26de042011-09-08 18:46:01 +0000940
941 // If we encountered any nested isolate runs, just move them
942 // to the top resolver's list for later processing.
943 if (!isolatedResolver.isolatedRuns().isEmpty()) {
andersca@apple.com92012992013-05-05 19:03:49 +0000944 topResolver.isolatedRuns().appendVector(isolatedResolver.isolatedRuns());
eric@webkit.orga26de042011-09-08 18:46:01 +0000945 isolatedResolver.isolatedRuns().clear();
commit-queue@webkit.org1968a432013-09-11 19:23:58 +0000946 currentRoot = isolatedInline;
eric@webkit.orga26de042011-09-08 18:46:01 +0000947 }
948 }
949}
950
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000951static inline void constructBidiRunsForLine(const RenderBlockFlow* block, InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfLine, VisualDirectionOverride override, bool previousLineBrokeCleanly)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000952{
dino@apple.comc133a8c2014-02-03 23:35:34 +0000953#if !ENABLE(CSS_SHAPES) || !ENABLE(CSS_SHAPE_INSIDE)
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000954 UNUSED_PARAM(block);
955 constructBidiRunsForSegment(topResolver, bidiRuns, endOfLine, override, previousLineBrokeCleanly);
956#else
betravis@adobe.comcf7cba62013-06-10 21:23:45 +0000957 ShapeInsideInfo* shapeInsideInfo = block->layoutShapeInsideInfo();
958 if (!shapeInsideInfo || !shapeInsideInfo->hasSegments()) {
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000959 constructBidiRunsForSegment(topResolver, bidiRuns, endOfLine, override, previousLineBrokeCleanly);
960 return;
961 }
962
betravis@adobe.comcf7cba62013-06-10 21:23:45 +0000963 const SegmentRangeList& segmentRanges = shapeInsideInfo->segmentRanges();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000964 ASSERT(segmentRanges.size());
965
966 for (size_t i = 0; i < segmentRanges.size(); i++) {
betravis@adobe.com28fba072013-03-12 23:27:35 +0000967 LineSegmentIterator iterator = segmentRanges[i].start;
968 InlineIterator segmentStart(iterator.root, iterator.object, iterator.offset);
969 iterator = segmentRanges[i].end;
970 InlineIterator segmentEnd(iterator.root, iterator.object, iterator.offset);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000971 if (i) {
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +0000972 ASSERT(segmentStart.renderer());
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +0000973 BidiRun* segmentMarker = createRun(segmentStart.offset(), segmentStart.offset(), segmentStart.renderer(), topResolver);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000974 segmentMarker->m_startsSegment = true;
975 bidiRuns.addRun(segmentMarker);
976 // Do not collapse midpoints between segments
zoltan@webkit.org7585ad52014-01-21 21:33:22 +0000977 topResolver.midpointState().setBetweenMidpoints(false);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000978 }
betravis@adobe.com9e5e8242013-04-19 23:28:26 +0000979 if (segmentStart == segmentEnd)
980 continue;
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000981 topResolver.setPosition(segmentStart, numberOfIsolateAncestors(segmentStart));
982 constructBidiRunsForSegment(topResolver, bidiRuns, segmentEnd, override, previousLineBrokeCleanly);
983 }
984#endif
985}
986
eric@webkit.org45e33a52011-05-04 11:51:09 +0000987// 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 +0000988RootInlineBox* 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 +0000989{
990 if (!bidiRuns.runCount())
991 return 0;
992
993 // FIXME: Why is this only done when we had runs?
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +0000994 lineInfo.setLastLine(!end.renderer());
eric@webkit.org45e33a52011-05-04 11:51:09 +0000995
996 RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo);
997 if (!lineBox)
998 return 0;
999
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001000 lineBox->setBidiLevel(bidiLevel);
eric@webkit.org45e33a52011-05-04 11:51:09 +00001001 lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly());
1002
eric@webkit.org45e33a52011-05-04 11:51:09 +00001003 bool isSVGRootInlineBox = lineBox->isSVGRootInlineBox();
eric@webkit.org45e33a52011-05-04 11:51:09 +00001004
1005 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
1006
1007 // Now we position all of our text runs horizontally.
1008 if (!isSVGRootInlineBox)
enrica@apple.com885c84d2012-10-10 05:48:51 +00001009 computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache, wordMeasurements);
eric@webkit.org45e33a52011-05-04 11:51:09 +00001010
1011 // Now position our text runs vertically.
1012 computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache);
1013
eric@webkit.org45e33a52011-05-04 11:51:09 +00001014 // SVG text layout code computes vertical & horizontal positions on its own.
1015 // Note that we still need to execute computeVerticalPositionsForLine() as
1016 // it calls InlineTextBox::positionLineBox(), which tracks whether the box
1017 // contains reversed text or not. If we wouldn't do that editing and thus
1018 // text selection in RTL boxes would not work as expected.
1019 if (isSVGRootInlineBox) {
akling@apple.com670fea12013-10-12 18:16:42 +00001020 ASSERT_WITH_SECURITY_IMPLICATION(isSVGText());
akling@apple.com0c7d7fe2013-11-07 10:08:04 +00001021 toSVGRootInlineBox(lineBox)->computePerCharacterLayoutInformation();
eric@webkit.org45e33a52011-05-04 11:51:09 +00001022 }
eric@webkit.org45e33a52011-05-04 11:51:09 +00001023
1024 // Compute our overflow now.
1025 lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap);
1026
eric@webkit.org45e33a52011-05-04 11:51:09 +00001027 return lineBox;
1028}
1029
akling@apple.com31dd4f42013-10-30 22:27:59 +00001030static void deleteLineRange(LineLayoutState& layoutState, RootInlineBox* startLine, RootInlineBox* stopLine = 0)
eric@webkit.org455d90e2011-05-09 22:27:27 +00001031{
1032 RootInlineBox* boxToDelete = startLine;
1033 while (boxToDelete && boxToDelete != stopLine) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001034 layoutState.updateRepaintRangeFromBox(boxToDelete);
akling@apple.com31dd4f42013-10-30 22:27:59 +00001035 // Note: deleteLineRange(firstRootBox()) is not identical to deleteLineBoxTree().
eric@webkit.orge2532d92011-05-16 23:10:49 +00001036 // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing.
eric@webkit.org455d90e2011-05-09 22:27:27 +00001037 RootInlineBox* next = boxToDelete->nextRootBox();
akling@apple.com31dd4f42013-10-30 22:27:59 +00001038 boxToDelete->deleteLine();
eric@webkit.org455d90e2011-05-09 22:27:27 +00001039 boxToDelete = next;
1040 }
1041}
1042
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001043void RenderBlockFlow::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild)
eric@webkit.org060caf62011-05-03 22:11:39 +00001044{
1045 // We want to skip ahead to the first dirty line
1046 InlineBidiResolver resolver;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001047 RootInlineBox* startLine = determineStartPosition(layoutState, resolver);
eric@webkit.org060caf62011-05-03 22:11:39 +00001048
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001049 unsigned consecutiveHyphenatedLines = 0;
1050 if (startLine) {
1051 for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox())
1052 consecutiveHyphenatedLines++;
1053 }
1054
eric@webkit.org060caf62011-05-03 22:11:39 +00001055 // FIXME: This would make more sense outside of this function, but since
1056 // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call
1057 // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html.
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001058 if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) {
antti@apple.comca2a8ff2013-10-04 04:04:35 +00001059 setNeedsLayout(MarkOnlyThis); // Mark as needing a full layout to force us to repaint.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001060 if (!view().doingFullRepaint() && hasLayer()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001061 // Because we waited until we were already inside layout to discover
1062 // that the block really needed a full layout, we missed our chance to repaint the layer
1063 // before layout started. Luckily the layer has cached the repaint rect for its original
1064 // position and size, and so we can use that to make a repaint happen now.
zalan@apple.comc7b20b12014-02-12 04:50:55 +00001065 repaintUsingContainer(containerForRepaint(), layer()->repaintRect());
eric@webkit.org060caf62011-05-03 22:11:39 +00001066 }
1067 }
1068
mihnea@adobe.com99467792013-03-19 09:09:04 +00001069 if (containsFloats())
darin@apple.com7cad7042013-09-24 05:53:55 +00001070 layoutState.setLastFloat(m_floatingObjects->set().last().get());
eric@webkit.org060caf62011-05-03 22:11:39 +00001071
1072 // We also find the first clean line and extract these lines. We will add them back
1073 // if we determine that we're able to synchronize after handling all our dirty lines.
1074 InlineIterator cleanLineStart;
1075 BidiStatus cleanLineBidiStatus;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001076 if (!layoutState.isFullLayout() && startLine)
1077 determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus);
eric@webkit.org060caf62011-05-03 22:11:39 +00001078
1079 if (startLine) {
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001080 if (!layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001081 layoutState.setRepaintRange(logicalHeight());
akling@apple.com31dd4f42013-10-30 22:27:59 +00001082 deleteLineRange(layoutState, startLine);
eric@webkit.org060caf62011-05-03 22:11:39 +00001083 }
1084
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001085 if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001086 // If the last line before the start line ends with a line break that clear floats,
1087 // adjust the height accordingly.
1088 // A line break can be either the first or the last object on a line, depending on its direction.
1089 if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) {
akling@apple.com0b8172b72013-08-31 18:34:23 +00001090 RenderObject* lastObject = &lastLeafChild->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001091 if (!lastObject->isBR())
akling@apple.com0b8172b72013-08-31 18:34:23 +00001092 lastObject = &lastRootBox()->firstLeafChild()->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001093 if (lastObject->isBR()) {
akling@apple.com827be9c2013-10-29 02:58:43 +00001094 EClear clear = lastObject->style().clear();
eric@webkit.org060caf62011-05-03 22:11:39 +00001095 if (clear != CNONE)
bjonesbe@adobe.comf9f10402014-02-20 19:40:28 +00001096 clearFloats(clear);
eric@webkit.org060caf62011-05-03 22:11:39 +00001097 }
1098 }
1099 }
1100
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001101 layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001102 linkToEndLineIfNeeded(layoutState);
1103 repaintDirtyFloats(layoutState.floats());
1104}
eric@webkit.org060caf62011-05-03 22:11:39 +00001105
zoltan@webkit.org8b422c82013-09-20 21:17:43 +00001106RenderTextInfo::RenderTextInfo()
mitz@apple.com6a859602012-08-27 15:31:56 +00001107 : m_text(0)
mitz@apple.comd4c153d2012-09-16 23:36:41 +00001108 , m_font(0)
mitz@apple.com6a859602012-08-27 15:31:56 +00001109{
1110}
1111
zoltan@webkit.org8b422c82013-09-20 21:17:43 +00001112RenderTextInfo::~RenderTextInfo()
mitz@apple.com6a859602012-08-27 15:31:56 +00001113{
1114}
1115
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001116// 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 +00001117inline const InlineIterator& RenderBlockFlow::restartLayoutRunsAndFloatsInRange(LayoutUnit oldLogicalHeight, LayoutUnit newLogicalHeight, FloatingObject* lastFloatFromPreviousLine, InlineBidiResolver& resolver, const InlineIterator& oldEnd)
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001118{
1119 removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight);
1120 setLogicalHeight(newLogicalHeight);
1121 resolver.setPositionIgnoringNestedIsolates(oldEnd);
1122 return oldEnd;
1123}
1124
dino@apple.comc133a8c2014-02-03 23:35:34 +00001125#if ENABLE(CSS_SHAPES) && ENABLE(CSS_SHAPE_INSIDE)
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001126static inline void pushShapeContentOverflowBelowTheContentBox(RenderBlockFlow* block, ShapeInsideInfo* shapeInsideInfo, LayoutUnit lineTop, LayoutUnit lineHeight)
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001127{
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001128 ASSERT(shapeInsideInfo);
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001129
1130 LayoutUnit logicalLineBottom = lineTop + lineHeight;
zoltan@webkit.orgb20fd7c2013-07-19 17:46:08 +00001131 LayoutUnit shapeLogicalBottom = shapeInsideInfo->shapeLogicalBottom();
zoltan@webkit.org22964092013-09-12 22:55:59 +00001132 LayoutUnit shapeContainingBlockLogicalHeight = shapeInsideInfo->shapeContainingBlockLogicalHeight();
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001133
weinig@apple.com12974262013-11-26 05:54:30 +00001134 bool isOverflowPositionedAlready = (shapeContainingBlockLogicalHeight - shapeInsideInfo->owner().borderAndPaddingAfter() + lineHeight) <= lineTop;
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001135
zoltan@webkit.orgb20fd7c2013-07-19 17:46:08 +00001136 // If the last line overlaps with the shape, we don't need the segments anymore
1137 if (lineTop < shapeLogicalBottom && shapeLogicalBottom < logicalLineBottom)
1138 shapeInsideInfo->clearSegments();
1139
zoltan@webkit.org22964092013-09-12 22:55:59 +00001140 if (logicalLineBottom <= shapeLogicalBottom || !shapeContainingBlockLogicalHeight || isOverflowPositionedAlready)
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001141 return;
1142
weinig@apple.com12974262013-11-26 05:54:30 +00001143 LayoutUnit newLogicalHeight = block->logicalHeight() + (shapeContainingBlockLogicalHeight - (lineTop + shapeInsideInfo->owner().borderAndPaddingAfter()));
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001144 block->setLogicalHeight(newLogicalHeight);
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001145}
1146
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001147void RenderBlockFlow::updateShapeAndSegmentsForCurrentLine(ShapeInsideInfo*& shapeInsideInfo, const LayoutSize& logicalOffsetFromShapeContainer, LineLayoutState& layoutState)
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001148{
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001149 if (layoutState.flowThread())
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001150 return updateShapeAndSegmentsForCurrentLineInFlowThread(shapeInsideInfo, layoutState);
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001151
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001152 if (!shapeInsideInfo)
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001153 return;
1154
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001155 LayoutUnit lineTop = logicalHeight() + logicalOffsetFromShapeContainer.height();
1156 LayoutUnit lineLeft = logicalOffsetFromShapeContainer.width();
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001157 LayoutUnit lineHeight = this->lineHeight(layoutState.lineInfo().isFirstLine(), isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes);
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001158
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001159 // FIXME: Bug 95361: It is possible for a line to grow beyond lineHeight, in which case these segments may be incorrect.
zoltan@webkit.orge1a0c952013-09-18 03:27:35 +00001160 shapeInsideInfo->updateSegmentsForLine(LayoutSize(lineLeft, lineTop), lineHeight);
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001161
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001162 pushShapeContentOverflowBelowTheContentBox(this, shapeInsideInfo, lineTop, lineHeight);
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001163}
zoltan@webkit.orgd07fc732013-05-20 19:00:22 +00001164
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001165void RenderBlockFlow::updateShapeAndSegmentsForCurrentLineInFlowThread(ShapeInsideInfo*& shapeInsideInfo, LineLayoutState& layoutState)
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001166{
1167 ASSERT(layoutState.flowThread());
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001168
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001169 RenderRegion* currentRegion = regionAtBlockOffset(logicalHeight());
zoltan@webkit.org1493d302013-10-21 20:18:54 +00001170 if (!currentRegion || !currentRegion->logicalHeight())
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001171 return;
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001172
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001173 shapeInsideInfo = currentRegion->shapeInsideInfo();
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001174
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001175 RenderRegion* nextRegion = 0;
1176 if (!currentRegion->isLastRegion()) {
1177 RenderRegionList regionList = layoutState.flowThread()->renderRegionList();
1178 auto it = regionList.find(currentRegion);
1179 nextRegion = *(++it);
1180 }
1181
1182 // We only want to deal regions with shapes, so we check if the next region has a shape
1183 if (!shapeInsideInfo && nextRegion && !nextRegion->shapeInsideInfo())
1184 return;
1185
1186 LayoutUnit lineHeight = this->lineHeight(layoutState.lineInfo().isFirstLine(), isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes);
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001187 LayoutUnit logicalLineTopInFlowThread = logicalHeight() + offsetFromLogicalTopOfFirstPage();
1188 LayoutUnit logicalLineBottomInFlowThread = logicalLineTopInFlowThread + lineHeight;
1189 LayoutUnit logicalRegionTopInFlowThread = currentRegion->logicalTopForFlowThreadContent();
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001190 LayoutUnit logicalRegionBottomInFlowThread = logicalRegionTopInFlowThread + currentRegion->logicalHeight() - currentRegion->borderAndPaddingBefore() - currentRegion->borderAndPaddingAfter();
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001191
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001192 LayoutUnit shapeBottomInFlowThread = LayoutUnit::max();
1193 if (shapeInsideInfo)
1194 shapeBottomInFlowThread = shapeInsideInfo->shapeLogicalBottom() + currentRegion->logicalTopForFlowThreadContent();
1195
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001196 bool lineOverLapsWithShapeBottom = shapeBottomInFlowThread < logicalLineBottomInFlowThread;
zoltan@webkit.org78f06e42014-01-07 00:42:41 +00001197 bool lineTopAdjustedIntoNextRegion = layoutState.adjustedLogicalLineTop() >= currentRegion->logicalHeight();
1198 bool lineOverLapsWithRegionBottom = logicalLineBottomInFlowThread > logicalRegionBottomInFlowThread || lineTopAdjustedIntoNextRegion;
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001199 bool overFlowsToNextRegion = nextRegion && (lineOverLapsWithShapeBottom || lineOverLapsWithRegionBottom);
1200
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001201 // If the line is between two shapes/regions we position the line to the top of the next shape/region
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001202 if (overFlowsToNextRegion) {
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001203 ASSERT(currentRegion != nextRegion);
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001204 LayoutUnit deltaToNextRegion = logicalRegionBottomInFlowThread - logicalLineTopInFlowThread;
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001205 setLogicalHeight(logicalHeight() + deltaToNextRegion);
1206
1207 currentRegion = nextRegion;
zoltan@webkit.orge8396b52013-10-25 17:27:42 +00001208 shapeInsideInfo = currentRegion->shapeInsideInfo();
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001209
1210 logicalLineTopInFlowThread = logicalHeight() + offsetFromLogicalTopOfFirstPage();
1211 logicalLineBottomInFlowThread = logicalLineTopInFlowThread + lineHeight;
1212 logicalRegionTopInFlowThread = currentRegion->logicalTopForFlowThreadContent();
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001213 logicalRegionBottomInFlowThread = logicalRegionTopInFlowThread + currentRegion->logicalHeight() - currentRegion->borderAndPaddingBefore() - currentRegion->borderAndPaddingAfter();
zoltan@webkit.org78f06e42014-01-07 00:42:41 +00001214
1215 if (lineTopAdjustedIntoNextRegion)
1216 layoutState.setAdjustedLogicalLineTop(0);
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001217 }
1218
1219 if (!shapeInsideInfo)
1220 return;
1221
zoltan@webkit.orgf04b8722013-10-25 17:26:35 +00001222 bool isFirstLineInRegion = logicalLineBottomInFlowThread <= (logicalRegionTopInFlowThread + lineHeight);
1223 bool isFirstLineAdjusted = (logicalLineTopInFlowThread - logicalRegionTopInFlowThread) < (layoutState.adjustedLogicalLineTop() - currentRegion->borderAndPaddingBefore());
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001224 // We position the first line to the top of the shape in the region or to the previously adjusted position in the shape
zoltan@webkit.orgf04b8722013-10-25 17:26:35 +00001225 if (isFirstLineInRegion || isFirstLineAdjusted) {
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001226 LayoutUnit shapeTopOffset = layoutState.adjustedLogicalLineTop();
zoltan@webkit.org35793312013-10-29 20:44:45 +00001227
1228 if (!shapeTopOffset && (shapeInsideInfo->shapeLogicalTop() > 0))
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001229 shapeTopOffset = shapeInsideInfo->shapeLogicalTop();
1230
1231 LayoutUnit shapePositionInFlowThread = currentRegion->logicalTopForFlowThreadContent() + shapeTopOffset;
1232 LayoutUnit shapeTopLineTopDelta = shapePositionInFlowThread - logicalLineTopInFlowThread - currentRegion->borderAndPaddingBefore();
1233
1234 setLogicalHeight(logicalHeight() + shapeTopLineTopDelta);
1235 logicalLineTopInFlowThread += shapeTopLineTopDelta;
1236 layoutState.setAdjustedLogicalLineTop(0);
1237 }
1238
1239 LayoutUnit lineTop = logicalLineTopInFlowThread - currentRegion->logicalTopForFlowThreadContent() + currentRegion->borderAndPaddingBefore();
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001240
1241 // FIXME: 118571 - Shape inside on a region does not yet take into account its padding for nested flow blocks
zoltan@webkit.orge1a0c952013-09-18 03:27:35 +00001242 shapeInsideInfo->updateSegmentsForLine(LayoutSize(0, lineTop), lineHeight);
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001243
zoltan@webkit.org3a337ba2013-06-17 20:23:58 +00001244 if (currentRegion->isLastRegion())
zoltan@webkit.org758f6ce2013-06-18 22:31:57 +00001245 pushShapeContentOverflowBelowTheContentBox(this, shapeInsideInfo, lineTop, lineHeight);
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001246}
1247
zoltan@webkit.org5b173ca2013-10-12 06:03:17 +00001248static inline LayoutUnit adjustLogicalLineTop(ShapeInsideInfo* shapeInsideInfo, InlineIterator start, InlineIterator end, const WordMeasurements& wordMeasurements)
1249{
1250 if (!shapeInsideInfo || end != start)
1251 return 0;
1252
1253 float minWidth = firstPositiveWidth(wordMeasurements);
1254 ASSERT(minWidth || wordMeasurements.isEmpty());
1255 if (minWidth > 0 && shapeInsideInfo->adjustLogicalLineTop(minWidth))
1256 return shapeInsideInfo->logicalLineTop();
1257
1258 return shapeInsideInfo->shapeLogicalBottom();
1259}
1260
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001261bool RenderBlockFlow::adjustLogicalLineTopAndLogicalHeightIfNeeded(ShapeInsideInfo* shapeInsideInfo, LayoutUnit absoluteLogicalTop, LineLayoutState& layoutState, InlineBidiResolver& resolver, FloatingObject* lastFloatFromPreviousLine, InlineIterator& end, WordMeasurements& wordMeasurements)
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001262{
betravis@adobe.comcf7cba62013-06-10 21:23:45 +00001263 LayoutUnit adjustedLogicalLineTop = adjustLogicalLineTop(shapeInsideInfo, resolver.position(), end, wordMeasurements);
zoltan@webkit.org2b977c02013-10-03 18:24:59 +00001264
zoltan@webkit.org397a5272013-10-22 22:07:32 +00001265 if (shapeInsideInfo && containsFloats()) {
zoltan@webkit.org2b977c02013-10-03 18:24:59 +00001266 lastFloatFromPreviousLine = m_floatingObjects->set().last().get();
zoltan@webkit.org397a5272013-10-22 22:07:32 +00001267 if (!wordMeasurements.size()) {
1268 LayoutUnit floatLogicalTopOffset = shapeInsideInfo->computeFirstFitPositionForFloat(logicalSizeForFloat(lastFloatFromPreviousLine));
1269 if (logicalHeight() < floatLogicalTopOffset)
1270 adjustedLogicalLineTop = floatLogicalTopOffset;
1271 }
zoltan@webkit.org2b977c02013-10-03 18:24:59 +00001272 }
1273
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001274 if (!adjustedLogicalLineTop)
1275 return false;
1276
1277 LayoutUnit newLogicalHeight = adjustedLogicalLineTop - absoluteLogicalTop;
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001278
1279 if (layoutState.flowThread()) {
1280 layoutState.setAdjustedLogicalLineTop(adjustedLogicalLineTop);
zoltan@webkit.orgee0f4072013-05-21 21:04:27 +00001281 newLogicalHeight = logicalHeight();
zoltan@webkit.org758bf022013-06-13 21:09:43 +00001282 }
1283
zoltan@webkit.orgbd3dabd2013-05-13 19:11:33 +00001284 end = restartLayoutRunsAndFloatsInRange(logicalHeight(), newLogicalHeight, lastFloatFromPreviousLine, resolver, end);
1285 return true;
1286}
betravis@adobe.com9e5e8242013-04-19 23:28:26 +00001287#endif
1288
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001289void RenderBlockFlow::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001290{
akling@apple.com827be9c2013-10-29 02:58:43 +00001291 const RenderStyle& styleToUse = style();
akling@apple.com691cf5c2013-08-24 16:33:15 +00001292 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001293 LineMidpointState& lineMidpointState = resolver.midpointState();
1294 InlineIterator end = resolver.position();
1295 bool checkForEndLineMatch = layoutState.endLine();
mitz@apple.com6a859602012-08-27 15:31:56 +00001296 RenderTextInfo renderTextInfo;
eric@webkit.org060caf62011-05-03 22:11:39 +00001297 VerticalPositionCache verticalPositionCache;
1298
weinig@apple.com12840dc2013-10-22 23:59:08 +00001299 LineBreaker lineBreaker(*this);
leviw@chromium.org1a508692011-05-05 00:01:11 +00001300
dino@apple.comc133a8c2014-02-03 23:35:34 +00001301#if ENABLE(CSS_SHAPES) && ENABLE(CSS_SHAPE_INSIDE)
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001302 LayoutSize logicalOffsetFromShapeContainer;
betravis@adobe.comcf7cba62013-06-10 21:23:45 +00001303 ShapeInsideInfo* shapeInsideInfo = layoutShapeInsideInfo();
1304 if (shapeInsideInfo) {
weinig@apple.com12974262013-11-26 05:54:30 +00001305 ASSERT(&shapeInsideInfo->owner() == this || allowsShapeInsideInfoSharing());
betravis@adobe.comcf7cba62013-06-10 21:23:45 +00001306 if (shapeInsideInfo != this->shapeInsideInfo()) {
commit-queue@webkit.org5fe2dfd2012-10-26 19:57:52 +00001307 // FIXME Bug 100284: If subsequent LayoutStates are pushed, we will have to add
1308 // their offsets from the original shape-inside container.
weinig@apple.com12974262013-11-26 05:54:30 +00001309 logicalOffsetFromShapeContainer = logicalOffsetFromShapeAncestorContainer(&shapeInsideInfo->owner());
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +00001310 }
1311 // Begin layout at the logical top of our shape inside.
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001312 if (logicalHeight() + logicalOffsetFromShapeContainer.height() < shapeInsideInfo->shapeLogicalTop()) {
1313 LayoutUnit logicalHeight = shapeInsideInfo->shapeLogicalTop() - logicalOffsetFromShapeContainer.height();
zoltan@webkit.orgd07fc732013-05-20 19:00:22 +00001314 if (layoutState.flowThread())
weinig@apple.com12974262013-11-26 05:54:30 +00001315 logicalHeight -= shapeInsideInfo->owner().borderAndPaddingBefore();
zoltan@webkit.orgd07fc732013-05-20 19:00:22 +00001316 setLogicalHeight(logicalHeight);
1317 }
commit-queue@webkit.org3b26f3d2012-09-25 18:22:39 +00001318 }
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +00001319#endif
1320
eric@webkit.org060caf62011-05-03 22:11:39 +00001321 while (!end.atEnd()) {
1322 // 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 +00001323 if (checkForEndLineMatch) {
1324 layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus));
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001325 if (layoutState.endLineMatched()) {
1326 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001327 break;
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001328 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001329 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001330
1331 lineMidpointState.reset();
1332
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001333 layoutState.lineInfo().setEmpty(true);
robert@webkit.org8cbab142011-12-30 20:58:29 +00001334 layoutState.lineInfo().resetRunsFromLeadingWhitespace();
eric@webkit.org060caf62011-05-03 22:11:39 +00001335
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001336 const InlineIterator oldEnd = end;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001337 bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly();
darin@apple.com7cad7042013-09-24 05:53:55 +00001338 FloatingObject* lastFloatFromPreviousLine = (containsFloats()) ? m_floatingObjects->set().last().get() : 0;
zoltan@webkit.org3bd77f52013-04-23 18:23:36 +00001339
dino@apple.comc133a8c2014-02-03 23:35:34 +00001340#if ENABLE(CSS_SHAPES) && ENABLE(CSS_SHAPE_INSIDE)
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001341 updateShapeAndSegmentsForCurrentLine(shapeInsideInfo, logicalOffsetFromShapeContainer, layoutState);
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +00001342#endif
enrica@apple.com885c84d2012-10-10 05:48:51 +00001343 WordMeasurements wordMeasurements;
1344 end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
glenn@skynav.com61b1abf2013-04-02 23:28:32 +00001345 renderTextInfo.m_lineBreakIterator.resetPriorContext();
eric@webkit.org060caf62011-05-03 22:11:39 +00001346 if (resolver.position().atEnd()) {
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001347 // FIXME: We shouldn't be creating any runs in nextLineBreak to begin with!
eric@webkit.org060caf62011-05-03 22:11:39 +00001348 // Once BidiRunList is separated from BidiResolver this will not be needed.
1349 resolver.runs().deleteRuns();
1350 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001351 layoutState.setCheckForFloatsFromLastLine(true);
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001352 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
eric@webkit.org060caf62011-05-03 22:11:39 +00001353 break;
1354 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001355
dino@apple.comc133a8c2014-02-03 23:35:34 +00001356#if ENABLE(CSS_SHAPES) && ENABLE(CSS_SHAPE_INSIDE)
betravis@adobe.com5fd027a2013-09-03 22:14:51 +00001357 if (adjustLogicalLineTopAndLogicalHeightIfNeeded(shapeInsideInfo, logicalOffsetFromShapeContainer.height(), layoutState, resolver, lastFloatFromPreviousLine, end, wordMeasurements))
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001358 continue;
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001359#endif
betravis@adobe.com9e5e8242013-04-19 23:28:26 +00001360 ASSERT(end != resolver.position());
1361
eric@webkit.org45e33a52011-05-04 11:51:09 +00001362 // This is a short-cut for empty lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001363 if (layoutState.lineInfo().isEmpty()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001364 if (lastRootBox())
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001365 lastRootBox()->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
eric@webkit.org060caf62011-05-03 22:11:39 +00001366 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001367 VisualDirectionOverride override = (styleToUse.rtlOrdering() == VisualOrder ? (styleToUse.direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride);
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001368
akling@apple.com827be9c2013-10-29 02:58:43 +00001369 if (isNewUBAParagraph && styleToUse.unicodeBidi() == Plaintext && !resolver.context()->parent()) {
1370 TextDirection direction = styleToUse.direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001371 determineDirectionality(direction, resolver.position());
akling@apple.com827be9c2013-10-29 02:58:43 +00001372 resolver.setStatus(BidiStatus(direction, isOverride(styleToUse.unicodeBidi())));
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001373 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001374 // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine.
1375 BidiRunList<BidiRun>& bidiRuns = resolver.runs();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001376 constructBidiRunsForLine(this, resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly());
eric@webkit.org060caf62011-05-03 22:11:39 +00001377 ASSERT(resolver.position() == end);
1378
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001379 BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : 0;
eric@webkit.org060caf62011-05-03 22:11:39 +00001380
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001381 if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) {
eric@webkit.org45e33a52011-05-04 11:51:09 +00001382 bidiRuns.logicallyLastRun()->m_hasHyphen = true;
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001383 consecutiveHyphenatedLines++;
1384 } else
1385 consecutiveHyphenatedLines = 0;
eric@webkit.org45e33a52011-05-04 11:51:09 +00001386
eric@webkit.org060caf62011-05-03 22:11:39 +00001387 // Now that the runs have been ordered, we create the line boxes.
1388 // At the same time we figure out where border/padding/margin should be applied for
1389 // inline flow boxes.
1390
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001391 LayoutUnit oldLogicalHeight = logicalHeight();
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001392 RootInlineBox* lineBox = createLineBoxesFromBidiRuns(resolver.status().context->level(), bidiRuns, end, layoutState.lineInfo(), verticalPositionCache, trailingSpaceRun, wordMeasurements);
eric@webkit.org060caf62011-05-03 22:11:39 +00001393
1394 bidiRuns.deleteRuns();
1395 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
1396
1397 if (lineBox) {
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001398 lineBox->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001399 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001400 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001401
1402 if (paginated) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001403 LayoutUnit adjustment = 0;
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001404 adjustLinePositionForPagination(lineBox, adjustment, layoutState.flowThread());
eric@webkit.org060caf62011-05-03 22:11:39 +00001405 if (adjustment) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001406 LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, layoutState.lineInfo().isFirstLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001407 lineBox->adjustBlockDirectionPosition(adjustment);
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001408 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001409 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001410
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001411 if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, layoutState.lineInfo().isFirstLine()) != oldLineWidth) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001412 // 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 +00001413 lineBox->deleteLine();
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001414 end = restartLayoutRunsAndFloatsInRange(oldLogicalHeight, oldLogicalHeight + adjustment, lastFloatFromPreviousLine, resolver, oldEnd);
eric@webkit.org060caf62011-05-03 22:11:39 +00001415 continue;
1416 }
1417
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001418 setLogicalHeight(lineBox->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001419 }
commit-queue@webkit.orgbe554b22012-11-26 20:00:49 +00001420
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001421 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001422 updateRegionForLine(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001423 }
1424 }
robert@webkit.org402c1512013-02-07 18:48:39 +00001425 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001426
robert@webkit.org402c1512013-02-07 18:48:39 +00001427 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001428 setStaticPositions(*this, *lineBreaker.positionedObjects()[i]);
eric@webkit.org060caf62011-05-03 22:11:39 +00001429
robert@webkit.org402c1512013-02-07 18:48:39 +00001430 if (!layoutState.lineInfo().isEmpty()) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001431 layoutState.lineInfo().setFirstLine(false);
bjonesbe@adobe.comf9f10402014-02-20 19:40:28 +00001432 clearFloats(lineBreaker.clear());
eric@webkit.org060caf62011-05-03 22:11:39 +00001433 }
1434
1435 if (m_floatingObjects && lastRootBox()) {
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001436 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001437 auto it = floatingObjectSet.begin();
1438 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001439 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001440 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001441 ASSERT(lastFloatIterator != end);
1442 ++lastFloatIterator;
1443 it = lastFloatIterator;
1444 }
1445 for (; it != end; ++it) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001446 FloatingObject* f = it->get();
eric@webkit.org060caf62011-05-03 22:11:39 +00001447 appendFloatingObjectToLastLine(f);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001448 ASSERT(&f->renderer() == &layoutState.floats()[layoutState.floatIndex()].object);
eric@webkit.org060caf62011-05-03 22:11:39 +00001449 // If a float's geometry has changed, give up on syncing with clean lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001450 if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect())
eric@webkit.org060caf62011-05-03 22:11:39 +00001451 checkForEndLineMatch = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001452 layoutState.setFloatIndex(layoutState.floatIndex() + 1);
eric@webkit.org060caf62011-05-03 22:11:39 +00001453 }
darin@apple.com7cad7042013-09-24 05:53:55 +00001454 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001455 }
1456
1457 lineMidpointState.reset();
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001458 resolver.setPosition(end, numberOfIsolateAncestors(end));
eric@webkit.org060caf62011-05-03 22:11:39 +00001459 }
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001460
abucur@adobe.comfc497132013-10-04 08:49:21 +00001461 // In case we already adjusted the line positions during this layout to avoid widows
1462 // then we need to ignore the possibility of having a new widows situation.
1463 // Otherwise, we risk leaving empty containers which is against the block fragmentation principles.
akling@apple.com827be9c2013-10-29 02:58:43 +00001464 if (paginated && !style().hasAutoWidows() && !didBreakAtLineToAvoidWidow()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001465 // Check the line boxes to make sure we didn't create unacceptable widows.
1466 // However, we'll prioritize orphans - so nothing we do here should create
1467 // a new orphan.
1468
1469 RootInlineBox* lineBox = lastRootBox();
1470
1471 // Count from the end of the block backwards, to see how many hanging
1472 // lines we have.
1473 RootInlineBox* firstLineInBlock = firstRootBox();
1474 int numLinesHanging = 1;
1475 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1476 ++numLinesHanging;
1477 lineBox = lineBox->prevRootBox();
1478 }
1479
1480 // If there were no breaks in the block, we didn't create any widows.
jchaffraix@webkit.org0f225142013-01-28 22:28:21 +00001481 if (!lineBox || !lineBox->isFirstAfterPageBreak() || lineBox == firstLineInBlock)
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001482 return;
1483
akling@apple.com827be9c2013-10-29 02:58:43 +00001484 if (numLinesHanging < style().widows()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001485 // We have detected a widow. Now we need to work out how many
1486 // lines there are on the previous page, and how many we need
1487 // to steal.
akling@apple.com827be9c2013-10-29 02:58:43 +00001488 int numLinesNeeded = style().widows() - numLinesHanging;
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001489 RootInlineBox* currentFirstLineOfNewPage = lineBox;
1490
1491 // Count the number of lines in the previous page.
1492 lineBox = lineBox->prevRootBox();
1493 int numLinesInPreviousPage = 1;
1494 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1495 ++numLinesInPreviousPage;
1496 lineBox = lineBox->prevRootBox();
1497 }
1498
1499 // If there was an explicit value for orphans, respect that. If not, we still
1500 // shouldn't create a situation where we make an orphan bigger than the initial value.
1501 // This means that setting widows implies we also care about orphans, but given
1502 // the specification says the initial orphan value is non-zero, this is ok. The
1503 // author is always free to set orphans explicitly as well.
akling@apple.com827be9c2013-10-29 02:58:43 +00001504 int orphans = style().hasAutoOrphans() ? style().initialOrphans() : style().orphans();
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001505 int numLinesAvailable = numLinesInPreviousPage - orphans;
1506 if (numLinesAvailable <= 0)
1507 return;
1508
andersca@apple.com86298632013-11-10 19:32:33 +00001509 int numLinesToTake = std::min(numLinesAvailable, numLinesNeeded);
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001510 // Wind back from our first widowed line.
1511 lineBox = currentFirstLineOfNewPage;
1512 for (int i = 0; i < numLinesToTake; ++i)
1513 lineBox = lineBox->prevRootBox();
1514
1515 // We now want to break at this line. Remember for next layout and trigger relayout.
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001516 setBreakAtLineToAvoidWidow(lineCount(lineBox));
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001517 markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), lineBox->lineBottomWithLeading(), lineBox);
1518 }
1519 }
abucur@adobe.comfc497132013-10-04 08:49:21 +00001520
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001521 clearDidBreakAtLineToAvoidWidow();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001522}
eric@webkit.org060caf62011-05-03 22:11:39 +00001523
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001524void RenderBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001525{
1526 if (layoutState.endLine()) {
1527 if (layoutState.endLineMatched()) {
akling@apple.com691cf5c2013-08-24 16:33:15 +00001528 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eric@webkit.org060caf62011-05-03 22:11:39 +00001529 // Attach all the remaining lines, and then adjust their y-positions as needed.
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001530 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001531 for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001532 line->attachLine();
1533 if (paginated) {
1534 delta -= line->paginationStrut();
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001535 adjustLinePositionForPagination(line, delta, layoutState.flowThread());
eric@webkit.org060caf62011-05-03 22:11:39 +00001536 }
1537 if (delta) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001538 layoutState.updateRepaintRangeFromBox(line, delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001539 line->adjustBlockDirectionPosition(delta);
1540 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001541 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001542 updateRegionForLine(line);
eric@webkit.org060caf62011-05-03 22:11:39 +00001543 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001544 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1545 RenderBox* floatingBox = *it;
1546 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001547 ASSERT(!floatingObject->originatingLine());
1548 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001549 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox) + delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001550 positionNewFloats();
1551 }
1552 }
1553 }
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001554 setLogicalHeight(lastRootBox()->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001555 } else {
1556 // Delete all the remaining lines.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001557 deleteLineRange(layoutState, layoutState.endLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001558 }
1559 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001560
1561 if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001562 // In case we have a float on the last line, it might not be positioned up to now.
1563 // This has to be done before adding in the bottom border/padding, or the float will
1564 // include the padding incorrectly. -dwh
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001565 if (layoutState.checkForFloatsFromLastLine()) {
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001566 LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow();
1567 LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow();
akling@apple.comb5f24642013-11-06 04:47:12 +00001568 auto newLineBox = std::make_unique<TrailingFloatsRootInlineBox>(*this);
1569 auto trailingFloatsLineBox = newLineBox.get();
1570 m_lineBoxes.appendLineBox(std::move(newLineBox));
eric@webkit.org060caf62011-05-03 22:11:39 +00001571 trailingFloatsLineBox->setConstructed();
1572 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
1573 VerticalPositionCache verticalPositionCache;
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001574 LayoutUnit blockLogicalHeight = logicalHeight();
hyatt@apple.coma8b5b822011-09-07 18:48:07 +00001575 trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache);
1576 trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight);
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001577 trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight));
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001578 LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight);
1579 LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight);
eric@webkit.org060caf62011-05-03 22:11:39 +00001580 trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom());
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001581 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001582 updateRegionForLine(trailingFloatsLineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001583 }
1584
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001585 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001586 auto it = floatingObjectSet.begin();
1587 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001588 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001589 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001590 ASSERT(lastFloatIterator != end);
1591 ++lastFloatIterator;
1592 it = lastFloatIterator;
1593 }
1594 for (; it != end; ++it)
darin@apple.com7cad7042013-09-24 05:53:55 +00001595 appendFloatingObjectToLastLine(it->get());
1596 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001597 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001598}
1599
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001600void RenderBlockFlow::repaintDirtyFloats(Vector<FloatWithRect>& floats)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001601{
eric@webkit.org060caf62011-05-03 22:11:39 +00001602 size_t floatCount = floats.size();
1603 // Floats that did not have layout did not repaint when we laid them out. They would have
1604 // painted by now if they had moved, but if they stayed at (0, 0), they still need to be
1605 // painted.
1606 for (size_t i = 0; i < floatCount; ++i) {
1607 if (!floats[i].everHadLayout) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001608 RenderBox& box = floats[i].object;
1609 if (!box.x() && !box.y() && box.checkForRepaintDuringLayout())
1610 box.repaint();
eric@webkit.org060caf62011-05-03 22:11:39 +00001611 }
1612 }
1613}
1614
antti@apple.com940f5872013-10-24 20:31:11 +00001615void RenderBlockFlow::layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom)
jamesr@google.com19548ad2010-04-02 23:21:35 +00001616{
antti@apple.comfea51992013-10-28 13:39:23 +00001617 ASSERT(!m_simpleLineLayout);
antti@apple.com940f5872013-10-24 20:31:11 +00001618
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001619 setLogicalHeight(borderAndPaddingBefore());
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001620
1621 // Lay out our hypothetical grid line as though it occurs at the top of the block.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001622 if (view().layoutState() && view().layoutState()->lineGrid() == this)
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001623 layoutLineGridBox();
mitz@apple.come1364202008-02-28 01:06:41 +00001624
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001625 RenderFlowThread* flowThread = flowThreadContainingBlock();
akling@apple.comee3c8df2013-11-06 08:09:44 +00001626 bool clearLinesForPagination = firstRootBox() && flowThread && !flowThread->hasRegions();
commit-queue@webkit.org93cdd632012-12-07 00:33:56 +00001627
hyatt0c3a9862004-02-23 21:26:26 +00001628 // Figure out if we should clear out our line boxes.
1629 // FIXME: Handle resize eventually!
akling@apple.comee3c8df2013-11-06 08:09:44 +00001630 bool isFullLayout = !firstRootBox() || selfNeedsLayout() || relayoutChildren || clearLinesForPagination;
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001631 LineLayoutState layoutState(isFullLayout, repaintLogicalTop, repaintLogicalBottom, flowThread);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001632
1633 if (isFullLayout)
akling@apple.com31dd4f42013-10-30 22:27:59 +00001634 lineBoxes().deleteLineBoxes();
mitz@apple.come1364202008-02-28 01:06:41 +00001635
commit-queue@webkit.org07797312013-02-22 18:58:19 +00001636 // Text truncation kicks in in two cases:
1637 // 1) If your overflow isn't visible and your text-overflow-mode isn't clip.
1638 // 2) If you're an anonymous block with a block parent that satisfies #1.
hyatted77ad82004-06-15 07:21:23 +00001639 // 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 +00001640 // difficult to figure out in general (especially in the middle of doing layout), so we only handle the
1641 // simple case of an anonymous block truncating when it's parent is clipped.
akling@apple.com827be9c2013-10-29 02:58:43 +00001642 bool hasTextOverflow = (style().textOverflow() && hasOverflowClip())
1643 || (isAnonymousBlock() && parent() && parent()->isRenderBlock() && parent()->style().textOverflow() && parent()->hasOverflowClip());
mitz@apple.come1364202008-02-28 01:06:41 +00001644
hyatted77ad82004-06-15 07:21:23 +00001645 // Walk all the lines and delete our ellipsis line boxes if they exist.
1646 if (hasTextOverflow)
1647 deleteEllipsisLineBoxes();
1648
hyattffe78712003-02-11 01:59:29 +00001649 if (firstChild()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001650 // In full layout mode, clear the line boxes of children upfront. Otherwise,
1651 // siblings can run into stale root lineboxes during layout. Then layout
1652 // the replaced elements later. In partial layout mode, line boxes are not
1653 // deleted and only dirtied. In that case, we can layout the replaced
1654 // elements at the same time.
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001655 bool hasInlineChild = false;
inferno@chromium.org13563122012-08-16 20:50:05 +00001656 Vector<RenderBox*> replacedChildren;
weinig@apple.com12840dc2013-10-22 23:59:08 +00001657 for (InlineWalker walker(*this); !walker.atEnd(); walker.advance()) {
1658 RenderObject& o = *walker.current();
abucur@adobe.com33159da2013-08-13 07:44:32 +00001659
weinig@apple.com12840dc2013-10-22 23:59:08 +00001660 if (!hasInlineChild && o.isInline())
commit-queue@webkit.orgcf45df92010-09-14 13:25:06 +00001661 hasInlineChild = true;
1662
weinig@apple.com12840dc2013-10-22 23:59:08 +00001663 if (o.isReplaced() || o.isFloating() || o.isOutOfFlowPositioned()) {
1664 RenderBox& box = toRenderBox(o);
eric@webkit.org060caf62011-05-03 22:11:39 +00001665
weinig@apple.com12840dc2013-10-22 23:59:08 +00001666 if (relayoutChildren || box.hasRelativeDimensions())
1667 box.setChildNeedsLayout(MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001668
zimmermann@webkit.orgac68af42011-06-15 08:02:37 +00001669 // 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 +00001670 if (relayoutChildren && box.needsPreferredWidthsRecalculation())
1671 box.setPreferredLogicalWidthsDirty(true, MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001672
weinig@apple.com12840dc2013-10-22 23:59:08 +00001673 if (box.isOutOfFlowPositioned())
1674 box.containingBlock()->insertPositionedObject(box);
1675 else if (box.isFloating())
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001676 layoutState.floats().append(FloatWithRect(box));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001677 else if (isFullLayout || box.needsLayout()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001678 // Replaced element.
weinig@apple.com12840dc2013-10-22 23:59:08 +00001679 box.dirtyLineBoxes(isFullLayout);
inferno@chromium.org13563122012-08-16 20:50:05 +00001680 if (isFullLayout)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001681 replacedChildren.append(&box);
inferno@chromium.org13563122012-08-16 20:50:05 +00001682 else
weinig@apple.com12840dc2013-10-22 23:59:08 +00001683 box.layoutIfNeeded();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001684 }
weinig@apple.com12840dc2013-10-22 23:59:08 +00001685 } else if (o.isTextOrLineBreak() || (o.isRenderInline() && !walker.atEndOfInline())) {
1686 if (o.isRenderInline())
1687 toRenderInline(o).updateAlwaysCreateLineBoxes(layoutState.isFullLayout());
1688 if (layoutState.isFullLayout() || o.selfNeedsLayout())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001689 dirtyLineBoxesForRenderer(o, layoutState.isFullLayout());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001690 o.clearNeedsLayout();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001691 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001692 }
1693
inferno@chromium.orgba2dceb2012-08-21 00:09:47 +00001694 for (size_t i = 0; i < replacedChildren.size(); i++)
1695 replacedChildren[i]->layoutIfNeeded();
inferno@chromium.org13563122012-08-16 20:50:05 +00001696
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001697 layoutRunsAndFloats(layoutState, hasInlineChild);
kociendabb0c24b2001-08-24 14:24:40 +00001698 }
hyatt85586af2003-02-19 23:22:42 +00001699
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001700 // Expand the last line to accommodate Ruby and emphasis marks.
1701 int lastLineAnnotationsAdjustment = 0;
1702 if (lastRootBox()) {
andersca@apple.com86298632013-11-10 19:32:33 +00001703 LayoutUnit lowestAllowedPosition = std::max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
akling@apple.com827be9c2013-10-29 02:58:43 +00001704 if (!style().isFlippedLinesWritingMode())
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001705 lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition);
1706 else
1707 lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
hyatt@apple.com5e48ff52010-11-19 00:43:29 +00001708 }
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001709
hyatta70560a2002-11-20 01:53:20 +00001710 // Now add in the bottom border/padding.
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001711 setLogicalHeight(logicalHeight() + lastLineAnnotationsAdjustment + borderAndPaddingAfter() + scrollbarLogicalHeight());
kociendabb0c24b2001-08-24 14:24:40 +00001712
akling@apple.comee3c8df2013-11-06 08:09:44 +00001713 if (!firstRootBox() && hasLineIfEmpty())
hyatt@apple.com2a5eb212011-03-22 23:21:54 +00001714 setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
hyatted77ad82004-06-15 07:21:23 +00001715
1716 // See if we have any lines that spill out of our block. If we do, then we will possibly need to
1717 // truncate text.
1718 if (hasTextOverflow)
1719 checkLinesForTextOverflow();
kociendabb0c24b2001-08-24 14:24:40 +00001720}
1721
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001722void RenderBlockFlow::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat)
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001723{
1724 Vector<RenderBox*>* cleanLineFloats = line->floatsPtr();
1725 if (!cleanLineFloats)
1726 return;
1727
weinig@apple.com12840dc2013-10-22 23:59:08 +00001728 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001729 RenderBox* floatingBox = *it;
1730 floatingBox->layoutIfNeeded();
bjonesbe@adobe.com562a50d2014-02-20 20:01:19 +00001731 LayoutSize newSize(floatingBox->width() + floatingBox->horizontalMarginExtent(), floatingBox->height() + floatingBox->verticalMarginExtent());
inferno@chromium.orga227be62013-02-11 08:06:45 +00001732 ASSERT_WITH_SECURITY_IMPLICATION(floatIndex < floats.size());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001733 if (&floats[floatIndex].object != floatingBox) {
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001734 encounteredNewFloat = true;
1735 return;
1736 }
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001737
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001738 if (floats[floatIndex].rect.size() != newSize) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001739 LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x();
andersca@apple.com86298632013-11-10 19:32:33 +00001740 LayoutUnit floatHeight = isHorizontalWritingMode() ? std::max(floats[floatIndex].rect.height(), newSize.height()) : std::max(floats[floatIndex].rect.width(), newSize.width());
1741 floatHeight = std::min(floatHeight, LayoutUnit::max() - floatTop);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001742 line->markDirty();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001743 markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001744 floats[floatIndex].rect.setSize(newSize);
1745 dirtiedByFloat = true;
1746 }
1747 floatIndex++;
1748 }
1749}
1750
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001751RootInlineBox* RenderBlockFlow::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver)
hyatt0c3a9862004-02-23 21:26:26 +00001752{
1753 RootInlineBox* curr = 0;
1754 RootInlineBox* last = 0;
mitz@apple.come1364202008-02-28 01:06:41 +00001755
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001756 // FIXME: This entire float-checking block needs to be broken into a new function.
mitz@apple.com40547b32008-03-18 04:04:34 +00001757 bool dirtiedByFloat = false;
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001758 if (!layoutState.isFullLayout()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001759 // Paginate all of the clean lines.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001760 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001761 LayoutUnit paginationDelta = 0;
mitz@apple.com40547b32008-03-18 04:04:34 +00001762 size_t floatIndex = 0;
1763 for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001764 if (paginated) {
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001765 if (lineWidthForPaginatedLineChanged(curr, 0, layoutState.flowThread())) {
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001766 curr->markDirty();
1767 break;
1768 }
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001769 paginationDelta -= curr->paginationStrut();
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001770 adjustLinePositionForPagination(curr, paginationDelta, layoutState.flowThread());
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001771 if (paginationDelta) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001772 if (containsFloats() || !layoutState.floats().isEmpty()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001773 // 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 +00001774 layoutState.markForFullLayout();
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001775 break;
1776 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001777
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001778 layoutState.updateRepaintRangeFromBox(curr, paginationDelta);
hyatt@apple.com61bbedf2011-01-26 23:10:57 +00001779 curr->adjustBlockDirectionPosition(paginationDelta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001780 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001781 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001782 updateRegionForLine(curr);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001783 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001784
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001785 // If a new float has been inserted before this line or before its last known float, just do a full layout.
1786 bool encounteredNewFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001787 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001788 if (encounteredNewFloat)
1789 layoutState.markForFullLayout();
1790
1791 if (dirtiedByFloat || layoutState.isFullLayout())
mitz@apple.com40547b32008-03-18 04:04:34 +00001792 break;
1793 }
1794 // Check if a new float has been inserted after the last known float.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001795 if (!curr && floatIndex < layoutState.floats().size())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001796 layoutState.markForFullLayout();
mitz@apple.com40547b32008-03-18 04:04:34 +00001797 }
1798
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001799 if (layoutState.isFullLayout()) {
akling@apple.com31dd4f42013-10-30 22:27:59 +00001800 m_lineBoxes.deleteLineBoxTree();
igor.o@sisa.samsung.comf6a57df2013-04-15 21:25:35 +00001801 curr = 0;
1802
akling@apple.comee3c8df2013-11-06 08:09:44 +00001803 ASSERT(!firstRootBox() && !lastRootBox());
eseidel789896f2005-11-27 22:52:09 +00001804 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001805 if (curr) {
1806 // We have a dirty line.
mjs9f78dd92007-02-12 04:06:07 +00001807 if (RootInlineBox* prevRootBox = curr->prevRootBox()) {
hyatt0c3a9862004-02-23 21:26:26 +00001808 // We have a previous line.
tasak@google.comfcfd96f2012-11-26 07:45:38 +00001809 if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= toRenderText(prevRootBox->lineBreakObj())->textLength())))
mjs9f78dd92007-02-12 04:06:07 +00001810 // The previous line didn't break cleanly or broke at a newline
1811 // that has been deleted, so treat it as dirty too.
1812 curr = prevRootBox;
hyatt0c3a9862004-02-23 21:26:26 +00001813 }
eseidel789896f2005-11-27 22:52:09 +00001814 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001815 // No dirty lines were found.
1816 // If the last line didn't break cleanly, treat it as dirty.
1817 if (lastRootBox() && !lastRootBox()->endsWithBreak())
1818 curr = lastRootBox();
1819 }
mitz@apple.come1364202008-02-28 01:06:41 +00001820
hyatt0c3a9862004-02-23 21:26:26 +00001821 // If we have no dirty lines, then last is just the last root box.
1822 last = curr ? curr->prevRootBox() : lastRootBox();
1823 }
mitz@apple.come1364202008-02-28 01:06:41 +00001824
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001825 unsigned numCleanFloats = 0;
1826 if (!layoutState.floats().isEmpty()) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001827 LayoutUnit savedLogicalHeight = logicalHeight();
mitz@apple.com40547b32008-03-18 04:04:34 +00001828 // Restore floats from clean lines.
1829 RootInlineBox* line = firstRootBox();
1830 while (line != curr) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00001831 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001832 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1833 RenderBox* floatingBox = *it;
1834 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001835 ASSERT(!floatingObject->originatingLine());
1836 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001837 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox));
mitz@apple.com40547b32008-03-18 04:04:34 +00001838 positionNewFloats();
weinig@apple.com12840dc2013-10-22 23:59:08 +00001839 ASSERT(&layoutState.floats()[numCleanFloats].object == floatingBox);
mitz@apple.com40547b32008-03-18 04:04:34 +00001840 numCleanFloats++;
1841 }
1842 }
1843 line = line->nextRootBox();
1844 }
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001845 setLogicalHeight(savedLogicalHeight);
mitz@apple.com40547b32008-03-18 04:04:34 +00001846 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001847 layoutState.setFloatIndex(numCleanFloats);
mitz@apple.com40547b32008-03-18 04:04:34 +00001848
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001849 layoutState.lineInfo().setFirstLine(!last);
1850 layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak());
mitz@apple.com1a301772008-03-11 18:30:36 +00001851
hyatt0c3a9862004-02-23 21:26:26 +00001852 if (last) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001853 setLogicalHeight(last->lineBottomWithLeading());
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001854 InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos());
1855 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
mitz@apple.com15035e62008-07-05 20:44:44 +00001856 resolver.setStatus(last->lineBreakBidiStatus());
darindde01502005-12-18 22:55:35 +00001857 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001858 TextDirection direction = style().direction();
1859 if (style().unicodeBidi() == Plaintext)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001860 determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(*this), 0));
akling@apple.com827be9c2013-10-29 02:58:43 +00001861 resolver.setStatus(BidiStatus(direction, isOverride(style().unicodeBidi())));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001862 InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(*this, &resolver), 0);
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001863 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
darindde01502005-12-18 22:55:35 +00001864 }
hyatt0c3a9862004-02-23 21:26:26 +00001865 return curr;
1866}
1867
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001868void RenderBlockFlow::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001869{
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001870 ASSERT(!layoutState.endLine());
1871 size_t floatIndex = layoutState.floatIndex();
hyatt0c3a9862004-02-23 21:26:26 +00001872 RootInlineBox* last = 0;
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001873 for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) {
1874 if (!curr->isDirty()) {
1875 bool encounteredNewFloat = false;
1876 bool dirtiedByFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001877 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001878 if (encounteredNewFloat)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001879 return;
hyatt04420ca2004-07-16 00:05:42 +00001880 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001881 if (curr->isDirty())
1882 last = 0;
1883 else if (!last)
1884 last = curr;
hyatt0c3a9862004-02-23 21:26:26 +00001885 }
mitz@apple.come1364202008-02-28 01:06:41 +00001886
hyatt0c3a9862004-02-23 21:26:26 +00001887 if (!last)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001888 return;
mitz@apple.come1364202008-02-28 01:06:41 +00001889
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001890 // At this point, |last| is the first line in a run of clean lines that ends with the last line
1891 // in the block.
1892
eseidel789896f2005-11-27 22:52:09 +00001893 RootInlineBox* prev = last->prevRootBox();
mitz@apple.com15035e62008-07-05 20:44:44 +00001894 cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos());
eseidel789896f2005-11-27 22:52:09 +00001895 cleanLineBidiStatus = prev->lineBreakBidiStatus();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001896 layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading());
mitz@apple.come1364202008-02-28 01:06:41 +00001897
hyatt0c3a9862004-02-23 21:26:26 +00001898 for (RootInlineBox* line = last; line; line = line->nextRootBox())
1899 line->extractLine(); // Disconnect all line boxes from their render objects while preserving
1900 // their connections to one another.
mitz@apple.come1364202008-02-28 01:06:41 +00001901
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001902 layoutState.setEndLine(last);
hyatt0c3a9862004-02-23 21:26:26 +00001903}
1904
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001905bool RenderBlockFlow::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001906{
1907 LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop();
1908
akling@apple.com691cf5c2013-08-24 16:33:15 +00001909 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001910 if (paginated && layoutState.flowThread()) {
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001911 // Check all lines from here to the end, and see if the hypothetical new position for the lines will result
1912 // in a different available line width.
1913 for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) {
1914 if (paginated) {
1915 // This isn't the real move we're going to do, so don't update the line box's pagination
1916 // strut yet.
1917 LayoutUnit oldPaginationStrut = lineBox->paginationStrut();
1918 lineDelta -= oldPaginationStrut;
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001919 adjustLinePositionForPagination(lineBox, lineDelta, layoutState.flowThread());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001920 lineBox->setPaginationStrut(oldPaginationStrut);
1921 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001922 if (lineWidthForPaginatedLineChanged(lineBox, lineDelta, layoutState.flowThread()))
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001923 return false;
1924 }
1925 }
1926
1927 if (!lineDelta || !m_floatingObjects)
1928 return true;
1929
1930 // 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 +00001931 LayoutUnit logicalTop = std::min(logicalHeight(), layoutState.endLineLogicalTop());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001932
1933 RootInlineBox* lastLine = layoutState.endLine();
1934 while (RootInlineBox* nextLine = lastLine->nextRootBox())
1935 lastLine = nextLine;
1936
leviw@chromium.org3957b452012-05-01 00:06:37 +00001937 LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + absoluteValue(lineDelta);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001938
1939 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001940 auto end = floatingObjectSet.end();
1941 for (auto it = floatingObjectSet.begin(); it != end; ++it) {
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001942 FloatingObject* floatingObject = it->get();
1943 if (logicalBottomForFloat(floatingObject) >= logicalTop && logicalBottomForFloat(floatingObject) < logicalBottom)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001944 return false;
1945 }
1946
1947 return true;
1948}
1949
weinig@apple.com31324fd2013-10-28 19:22:51 +00001950bool RenderBlockFlow::lineWidthForPaginatedLineChanged(RootInlineBox* rootBox, LayoutUnit lineDelta, RenderFlowThread* flowThread) const
1951{
1952 if (!flowThread)
1953 return false;
1954
1955 RenderRegion* currentRegion = regionAtBlockOffset(rootBox->lineTopWithLeading() + lineDelta);
1956 // Just bail if the region didn't change.
1957 if (rootBox->containingRegion() == currentRegion)
1958 return false;
1959 return rootBox->paginatedLineWidth() != availableLogicalWidthForContent(currentRegion);
1960}
1961
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001962bool RenderBlockFlow::matchedEndLine(LineLayoutState& layoutState, const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001963{
mitz@apple.com15035e62008-07-05 20:44:44 +00001964 if (resolver.position() == endLineStart) {
1965 if (resolver.status() != endLineStatus)
mitz@apple.com40547b32008-03-18 04:04:34 +00001966 return false;
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001967 return checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00001968 }
hyatt0c3a9862004-02-23 21:26:26 +00001969
mitz@apple.come1364202008-02-28 01:06:41 +00001970 // The first clean line doesn't match, but we can check a handful of following lines to try
1971 // to match back up.
1972 static int numLines = 8; // The # of lines we're willing to match against.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001973 RootInlineBox* originalEndLine = layoutState.endLine();
1974 RootInlineBox* line = originalEndLine;
mitz@apple.come1364202008-02-28 01:06:41 +00001975 for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) {
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001976 if (line->lineBreakObj() == resolver.position().renderer() && line->lineBreakPos() == resolver.position().offset()) {
mitz@apple.come1364202008-02-28 01:06:41 +00001977 // We have a match.
mitz@apple.com15035e62008-07-05 20:44:44 +00001978 if (line->lineBreakBidiStatus() != resolver.status())
mitz@apple.come1364202008-02-28 01:06:41 +00001979 return false; // ...but the bidi state doesn't match.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001980
1981 bool matched = false;
mitz@apple.come1364202008-02-28 01:06:41 +00001982 RootInlineBox* result = line->nextRootBox();
hyatt@apple.com1fb7d582011-09-23 20:25:11 +00001983 layoutState.setEndLine(result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001984 if (result) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001985 layoutState.setEndLineLogicalTop(line->lineBottomWithLeading());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001986 matched = checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00001987 }
1988
mitz@apple.come1364202008-02-28 01:06:41 +00001989 // Now delete the lines that we failed to sync.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001990 deleteLineRange(layoutState, originalEndLine, result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001991 return matched;
hyatt0c3a9862004-02-23 21:26:26 +00001992 }
1993 }
mitz@apple.come1364202008-02-28 01:06:41 +00001994
hyatt0c3a9862004-02-23 21:26:26 +00001995 return false;
1996}
1997
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00001998bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj)
bdashccffb432007-07-13 11:51:40 +00001999{
2000 ASSERT(inlineObj->parent() == this);
2001
mitz@apple.com15035e62008-07-05 20:44:44 +00002002 InlineIterator it(this, inlineObj, 0);
rniwa@webkit.org40248422011-06-15 00:19:39 +00002003 // FIXME: We should pass correct value for WhitespacePosition.
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002004 while (!it.atEnd() && !requiresLineBox(it))
mitz@apple.com1a301772008-03-11 18:30:36 +00002005 it.increment();
bdashccffb432007-07-13 11:51:40 +00002006
2007 return !it.atEnd();
2008}
2009
weinig@apple.com611b9292013-10-20 22:57:54 +00002010void RenderBlockFlow::addOverflowFromInlineChildren()
hyattb4b20872004-10-20 21:34:01 +00002011{
antti@apple.comfea51992013-10-28 13:39:23 +00002012 if (auto layout = simpleLineLayout()) {
antti@apple.com940f5872013-10-24 20:31:11 +00002013 ASSERT(!hasOverflowClip());
antti@apple.comfea51992013-10-28 13:39:23 +00002014 SimpleLineLayout::collectFlowOverflow(*this, *layout);
antti@apple.com940f5872013-10-24 20:31:11 +00002015 return;
2016 }
eae@chromium.org9717cd82012-11-07 18:33:44 +00002017 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit();
hyatt@apple.com592848f2010-12-06 20:03:43 +00002018 // 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 +00002019 if (hasOverflowClip() && !endPadding && element() && element()->isRootEditableElement() && style().isLeftToRightDirection())
hyatt@apple.com592848f2010-12-06 20:03:43 +00002020 endPadding = 1;
hyattb4b20872004-10-20 21:34:01 +00002021 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
hyatt@apple.com592848f2010-12-06 20:03:43 +00002022 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
abucur@adobe.com6585d012013-09-04 08:26:41 +00002023 RenderRegion* region = curr->containingRegion();
2024 if (region)
2025 region->addLayoutOverflowForBox(this, curr->paddedLayoutOverflowRect(endPadding));
2026 if (!hasOverflowClip()) {
hyatt@apple.com61f25322011-03-31 20:40:48 +00002027 addVisualOverflow(curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
abucur@adobe.com6585d012013-09-04 08:26:41 +00002028 if (region)
2029 region->addVisualOverflowForBox(this, curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
2030 }
hyattb4b20872004-10-20 21:34:01 +00002031 }
2032}
2033
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00002034void RenderBlockFlow::deleteEllipsisLineBoxes()
hyatted77ad82004-06-15 07:21:23 +00002035{
akling@apple.com827be9c2013-10-29 02:58:43 +00002036 ETextAlign textAlign = style().textAlign();
2037 bool ltr = style().isLeftToRightDirection();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002038 bool firstLine = true;
2039 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
2040 if (curr->hasEllipsisBox()) {
2041 curr->clearTruncation();
2042
2043 // Shift the line back where it belongs if we cannot accomodate an ellipsis.
2044 float logicalLeft = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine);
2045 float availableLogicalWidth = logicalRightOffsetForLine(curr->lineTop(), false) - logicalLeft;
2046 float totalLogicalWidth = curr->logicalWidth();
mario.prada@samsung.com79397522014-02-28 18:12:52 +00002047 updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002048
2049 if (ltr)
2050 curr->adjustLogicalPosition((logicalLeft - curr->logicalLeft()), 0);
2051 else
2052 curr->adjustLogicalPosition(-(curr->logicalLeft() - logicalLeft), 0);
2053 }
2054 firstLine = false;
2055 }
hyatted77ad82004-06-15 07:21:23 +00002056}
2057
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00002058void RenderBlockFlow::checkLinesForTextOverflow()
hyatted77ad82004-06-15 07:21:23 +00002059{
2060 // Determine the width of the ellipsis using the current font.
darindbba2bb2007-01-11 12:23:49 +00002061 // 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 +00002062 const Font& font = style().font();
svillar@igalia.com5b31eef2014-03-14 08:30:55 +00002063 DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
akling@apple.com827be9c2013-10-29 02:58:43 +00002064 const Font& firstLineFont = firstLineStyle().font();
2065 int firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle()));
2066 int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style()));
hyatted77ad82004-06-15 07:21:23 +00002067
2068 // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see
2069 // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and
2070 // check the left edge of the line box to see if it is less
2071 // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()"
akling@apple.com827be9c2013-10-29 02:58:43 +00002072 bool ltr = style().isLeftToRightDirection();
2073 ETextAlign textAlign = style().textAlign();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002074 bool firstLine = true;
hyatted77ad82004-06-15 07:21:23 +00002075 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
eae@chromium.org275da182012-12-19 23:07:55 +00002076 // FIXME: Use pixelSnappedLogicalRightOffsetForLine instead of snapping it ourselves once the column workaround in said method has been fixed.
2077 // https://bugs.webkit.org/show_bug.cgi?id=105461
commit-queue@webkit.orgbbac21e2013-06-21 15:45:21 +00002078 int blockRightEdge = snapSizeToPixel(logicalRightOffsetForLine(curr->lineTop(), firstLine), curr->x());
2079 int blockLeftEdge = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine);
eae@chromium.orgc491d962012-12-28 18:32:08 +00002080 int lineBoxEdge = ltr ? snapSizeToPixel(curr->x() + curr->logicalWidth(), curr->x()) : snapSizeToPixel(curr->x(), 0);
dglazkov@chromium.org28434e62009-05-13 22:30:10 +00002081 if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) {
hyattf918d2d2004-06-15 07:24:11 +00002082 // 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 +00002083 // can be truncated. In order for truncation to be possible, the line must have sufficient space to
2084 // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis
2085 // space.
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002086
2087 LayoutUnit width = firstLine ? firstLineEllipsisWidth : ellipsisWidth;
eae@chromium.orgee8613e2011-11-12 01:12:58 +00002088 LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002089 if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) {
2090 float totalLogicalWidth = curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width);
2091
akling@apple.comf294cf02013-07-17 18:46:39 +00002092 float logicalLeft = 0; // We are only interested in the delta from the base position.
commit-queue@webkit.orgbbac21e2013-06-21 15:45:21 +00002093 float truncatedWidth = pixelSnappedLogicalRightOffsetForLine(curr->lineTop(), firstLine);
mario.prada@samsung.com79397522014-02-28 18:12:52 +00002094 updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, truncatedWidth, 0);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002095 if (ltr)
2096 curr->adjustLogicalPosition(logicalLeft, 0);
2097 else
2098 curr->adjustLogicalPosition(-(truncatedWidth - (logicalLeft + totalLogicalWidth)), 0);
2099 }
hyatted77ad82004-06-15 07:21:23 +00002100 }
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002101 firstLine = false;
hyatted77ad82004-06-15 07:21:23 +00002102 }
2103}
2104
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00002105bool RenderBlockFlow::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002106{
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002107 if (!positionNewFloats())
2108 return false;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002109
rniwa@webkit.org44424752011-04-14 00:58:40 +00002110 width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002111
hyatt@apple.comdd78df82011-09-27 22:11:41 +00002112 // We only connect floats to lines for pagination purposes if the floats occur at the start of
2113 // the line and the previous line had a hard break (so this line is either the first in the block
2114 // or follows a <br>).
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00002115 if (!newFloat->paginationStrut() || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002116 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002117
hyatt@apple.com46c65b32011-08-09 19:13:45 +00002118 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00002119 ASSERT(floatingObjectSet.last().get() == newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002120
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002121 LayoutUnit floatLogicalTop = logicalTopForFloat(newFloat);
bjonesbe@adobe.combdee2ce2014-02-07 18:37:55 +00002122 LayoutUnit paginationStrut = newFloat->paginationStrut();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002123
hyatt@apple.com5950bd42011-09-27 20:39:57 +00002124 if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002125 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002126
darin@apple.com7cad7042013-09-24 05:53:55 +00002127 auto it = floatingObjectSet.end();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002128 --it; // Last float is newFloat, skip that one.
darin@apple.com7cad7042013-09-24 05:53:55 +00002129 auto begin = floatingObjectSet.begin();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002130 while (it != begin) {
2131 --it;
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002132 FloatingObject* floatingObject = it->get();
2133 if (floatingObject == lastFloatFromPreviousLine)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002134 break;
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002135 if (logicalTopForFloat(floatingObject) == logicalHeight() + lineInfo.floatPaginationStrut()) {
2136 floatingObject->setPaginationStrut(paginationStrut + floatingObject->paginationStrut());
weinig@apple.com12840dc2013-10-22 23:59:08 +00002137 RenderBox& floatBox = floatingObject->renderer();
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002138 setLogicalTopForChild(floatBox, logicalTopForChild(floatBox) + marginBeforeForChild(floatBox) + paginationStrut);
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00002139
2140 if (updateRegionRangeForBoxChild(floatingObject->renderer()))
2141 floatBox.setNeedsLayout(MarkOnlyThis);
2142 else if (floatBox.isRenderBlock())
weinig@apple.com12840dc2013-10-22 23:59:08 +00002143 toRenderBlock(floatBox).setChildNeedsLayout(MarkOnlyThis);
2144 floatBox.layoutIfNeeded();
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00002145
hyatt@apple.com46c65b32011-08-09 19:13:45 +00002146 // Save the old logical top before calling removePlacedObject which will set
2147 // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat.
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002148 LayoutUnit oldLogicalTop = logicalTopForFloat(floatingObject);
2149 m_floatingObjects->removePlacedObject(floatingObject);
2150 setLogicalTopForFloat(floatingObject, oldLogicalTop + paginationStrut);
2151 m_floatingObjects->addPlacedObject(floatingObject);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002152 }
2153 }
2154
hyatt@apple.comdd78df82011-09-27 22:11:41 +00002155 // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing
2156 // no content, then we don't want to improperly grow the height of the block.
2157 lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut);
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002158 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002159}
2160
weinig@apple.com6b4a24142014-01-05 00:28:39 +00002161LayoutUnit RenderBlockFlow::startAlignedOffsetForLine(LayoutUnit position, bool firstLine)
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002162{
akling@apple.com827be9c2013-10-29 02:58:43 +00002163 ETextAlign textAlign = style().textAlign();
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002164
hyatt@apple.coma5626692013-11-18 23:08:30 +00002165 // <rdar://problem/15427571>
2166 // https://bugs.webkit.org/show_bug.cgi?id=124522
2167 // This quirk is for legacy content that doesn't work properly with the center positioning scheme
2168 // being honored (e.g., epubs).
2169 if (textAlign == TASTART || document().settings()->useLegacyTextAlignPositionedElementBehavior()) // FIXME: Handle TAEND here
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002170 return startOffsetForLine(position, firstLine);
2171
2172 // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here
robert@webkit.org82903f42012-08-28 19:18:40 +00002173 float totalLogicalWidth = 0;
2174 float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false);
2175 float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), false) - logicalLeft;
mario.prada@samsung.com79397522014-02-28 18:12:52 +00002176
2177 // FIXME: Bug 129311: We need to pass a valid RootInlineBox here, considering the bidi level used to construct the line.
2178 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
robert@webkit.org7861a102011-09-22 17:16:47 +00002179
akling@apple.com827be9c2013-10-29 02:58:43 +00002180 if (!style().isLeftToRightDirection())
robert@webkit.org82903f42012-08-28 19:18:40 +00002181 return logicalWidth() - logicalLeft;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002182 return logicalLeft;
2183}
2184
abucur@adobe.comd40287b2013-10-08 17:33:05 +00002185void RenderBlockFlow::updateRegionForLine(RootInlineBox* lineBox) const
2186{
2187 ASSERT(lineBox);
akling@apple.combdf247b2014-01-13 22:33:08 +00002188
2189 if (auto containingRegion = regionAtBlockOffset(lineBox->lineTopWithLeading()))
2190 lineBox->setContainingRegion(*containingRegion);
2191 else
2192 lineBox->clearContainingRegion();
abucur@adobe.comd40287b2013-10-08 17:33:05 +00002193
2194 RootInlineBox* prevLineBox = lineBox->prevRootBox();
2195 if (!prevLineBox)
2196 return;
2197
2198 // This check is more accurate than the one in |adjustLinePositionForPagination| because it takes into
2199 // account just the container changes between lines. The before mentioned function doesn't set the flag
2200 // correctly if the line is positioned at the top of the last fragment container.
2201 if (lineBox->containingRegion() != prevLineBox->containingRegion())
2202 lineBox->setIsFirstAfterPageBreak(true);
2203}
2204
hyattffe78712003-02-11 01:59:29 +00002205}