blob: 8ed5be328917e5259452508b3e12c88197593707 [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"
mmaxfield@apple.com167a0e92015-03-06 19:06:30 +000029#include "BreakingContext.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"
mmaxfield@apple.comf28245e2014-05-20 00:45:52 +000034#include "InlineTextBoxStyle.h"
zoltan@webkit.org4c74e8d2013-09-13 17:59:12 +000035#include "LineLayoutState.h"
ggarenec11e5b2007-02-25 02:14:54 +000036#include "Logging.h"
bjonesbe@adobe.com24199752013-10-08 23:20:42 +000037#include "RenderBlockFlow.h"
hyatt@apple.coma10d30e2011-09-22 22:28:21 +000038#include "RenderFlowThread.h"
antti@apple.com8d8ae712013-09-18 18:04:32 +000039#include "RenderLineBreak.h"
zoltan@webkit.orgb7a73462013-02-22 19:53:35 +000040#include "RenderRegion.h"
mmaxfield@apple.com8301e832014-10-09 01:14:30 +000041#include "RenderRubyBase.h"
42#include "RenderRubyText.h"
hyattd8048342006-05-31 01:48:18 +000043#include "RenderView.h"
ossy@webkit.org66d8c0a2014-02-05 11:42:35 +000044#include "SVGRootInlineBox.h"
hyatt@apple.comcc1737c2010-09-16 20:20:02 +000045#include "Settings.h"
antti@apple.com940f5872013-10-24 20:31:11 +000046#include "SimpleLineLayoutFunctions.h"
dbates@webkit.orgf6f05a92010-05-17 04:58:25 +000047#include "TrailingFloatsRootInlineBox.h"
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +000048#include "VerticalPositionCache.h"
slewis@apple.coma7615ca2008-07-12 05:51:33 +000049#include <wtf/RefCountedLeakCounter.h>
bolsinga@apple.com97e42c42008-11-15 04:47:20 +000050#include <wtf/StdLibExtras.h>
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +000051
darinb9481ed2006-03-20 02:57:59 +000052namespace WebCore {
mjsfe301d72003-10-02 18:46:18 +000053
leviw@chromium.orge7812f32012-02-07 23:46:40 +000054static void determineDirectionality(TextDirection& dir, InlineIterator iter)
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000055{
56 while (!iter.atEnd()) {
57 if (iter.atParagraphSeparator())
58 return;
59 if (UChar current = iter.current()) {
darin@apple.com2eb5f4d2013-10-12 04:16:42 +000060 UCharDirection charDirection = u_charDirection(current);
61 if (charDirection == U_LEFT_TO_RIGHT) {
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000062 dir = LTR;
63 return;
64 }
darin@apple.com2eb5f4d2013-10-12 04:16:42 +000065 if (charDirection == U_RIGHT_TO_LEFT || charDirection == U_RIGHT_TO_LEFT_ARABIC) {
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000066 dir = RTL;
67 return;
68 }
69 }
70 iter.increment();
71 }
72}
73
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +000074inline std::unique_ptr<BidiRun> createRun(int start, int end, RenderObject& obj, InlineBidiResolver& resolver)
eric@webkit.org5bee2942011-04-08 02:12:31 +000075{
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +000076 return std::make_unique<BidiRun>(start, end, obj, resolver.context(), resolver.dir());
eric@webkit.org5bee2942011-04-08 02:12:31 +000077}
78
mmaxfield@apple.comff5b7ac2015-07-10 20:39:16 +000079void RenderBlockFlow::appendRunsForObject(BidiRunList<BidiRun>* runs, int start, int end, RenderObject& obj, InlineBidiResolver& resolver)
hyatt33f8d492002-11-12 21:44:52 +000080{
leviw@chromium.orgd8df17d2012-05-24 21:47:47 +000081 if (start > end || shouldSkipCreatingRunsForObject(obj))
hyatteb003b82002-11-15 22:35:10 +000082 return;
hyatt85586af2003-02-19 23:22:42 +000083
hyatt@apple.comb3466af2009-06-13 06:04:40 +000084 LineMidpointState& lineMidpointState = resolver.midpointState();
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000085 bool haveNextMidpoint = (lineMidpointState.currentMidpoint() < lineMidpointState.numMidpoints());
mitz@apple.com15035e62008-07-05 20:44:44 +000086 InlineIterator nextMidpoint;
hyatt85586af2003-02-19 23:22:42 +000087 if (haveNextMidpoint)
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000088 nextMidpoint = lineMidpointState.midpoints()[lineMidpointState.currentMidpoint()];
89 if (lineMidpointState.betweenMidpoints()) {
mmaxfield@apple.comff5b7ac2015-07-10 20:39:16 +000090 if (!haveNextMidpoint || (&obj != nextMidpoint.renderer()))
hyatt33f8d492002-11-12 21:44:52 +000091 return;
eric@webkit.org060caf62011-05-03 22:11:39 +000092 // This is a new start point. Stop ignoring objects and
hyatt33f8d492002-11-12 21:44:52 +000093 // adjust our start.
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +000094 start = nextMidpoint.offset();
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000095 lineMidpointState.incrementCurrentMidpoint();
mmaxfield@apple.comff5b7ac2015-07-10 20:39:16 +000096 if (start < end) {
97 appendRunsForObject(runs, start, end, obj, resolver);
98 return;
99 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000100 } else {
mmaxfield@apple.comff5b7ac2015-07-10 20:39:16 +0000101 if (!haveNextMidpoint || (&obj != nextMidpoint.renderer())) {
102 if (runs)
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +0000103 runs->appendRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000104 return;
105 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000106
simon.fraser@apple.com03e61032015-04-05 20:17:11 +0000107 // An end midpoint has been encountered within our object. We need to append a run with our endpoint.
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +0000108 if (static_cast<int>(nextMidpoint.offset() + 1) <= end) {
zoltan@webkit.org7585ad52014-01-21 21:33:22 +0000109 lineMidpointState.incrementCurrentMidpoint();
mmaxfield@apple.com0682d512014-03-25 20:15:14 +0000110 // The end of the line is before the object we're inspecting. Skip everything and return
111 if (nextMidpoint.refersToEndOfPreviousNode())
112 return;
mmaxfield@apple.comff5b7ac2015-07-10 20:39:16 +0000113 if (static_cast<int>(nextMidpoint.offset() + 1) > start && runs)
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +0000114 runs->appendRun(createRun(start, nextMidpoint.offset() + 1, obj, resolver));
mmaxfield@apple.com0682d512014-03-25 20:15:14 +0000115 appendRunsForObject(runs, nextMidpoint.offset() + 1, end, obj, resolver);
mmaxfield@apple.comff5b7ac2015-07-10 20:39:16 +0000116 } else if (runs)
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +0000117 runs->appendRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000118 }
119}
120
akling@apple.comb5f24642013-11-06 04:47:12 +0000121std::unique_ptr<RootInlineBox> RenderBlockFlow::createRootInlineBox()
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000122{
akling@apple.comb5f24642013-11-06 04:47:12 +0000123 return std::make_unique<RootInlineBox>(*this);
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000124}
125
126RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox()
127{
akling@apple.comb5f24642013-11-06 04:47:12 +0000128 auto newRootBox = createRootInlineBox();
129 RootInlineBox* rootBox = newRootBox.get();
aestes@apple.com13aae082016-01-02 08:03:08 +0000130 m_lineBoxes.appendLineBox(WTFMove(newRootBox));
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000131
akling@apple.comee3c8df2013-11-06 08:09:44 +0000132 if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && firstRootBox() == rootBox) {
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000133 if (AXObjectCache* cache = document().existingAXObjectCache())
134 cache->recomputeIsIgnored(this);
135 }
136
137 return rootBox;
138}
139
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000140static inline InlineBox* createInlineBoxForRenderer(RenderObject* renderer, bool isRootLineBox, bool isOnlyRun = false)
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000141{
142 if (isRootLineBox)
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000143 return downcast<RenderBlockFlow>(*renderer).createAndAppendRootInlineBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000144
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000145 if (is<RenderText>(*renderer))
146 return downcast<RenderText>(*renderer).createInlineTextBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000147
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000148 if (is<RenderBox>(*renderer)) {
akling@apple.comb5f24642013-11-06 04:47:12 +0000149 // FIXME: This is terrible. This branch returns an *owned* pointer!
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000150 return downcast<RenderBox>(*renderer).createInlineBox().release();
akling@apple.comb5f24642013-11-06 04:47:12 +0000151 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000152
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000153 if (is<RenderLineBreak>(*renderer)) {
akling@apple.comb5f24642013-11-06 04:47:12 +0000154 // FIXME: This is terrible. This branch returns an *owned* pointer!
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000155 auto inlineBox = downcast<RenderLineBreak>(*renderer).createInlineBox().release();
antti@apple.com9d8157e2013-09-17 15:13:37 +0000156 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
157 // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.)
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000158 inlineBox->setBehavesLikeText(isOnlyRun || renderer->document().inNoQuirksMode() || renderer->isLineBreakOpportunity());
antti@apple.com9d8157e2013-09-17 15:13:37 +0000159 return inlineBox;
160 }
161
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000162 return downcast<RenderInline>(*renderer).createAndAppendInlineFlowBox();
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000163}
164
weinig@apple.com12840dc2013-10-22 23:59:08 +0000165static inline void dirtyLineBoxesForRenderer(RenderObject& renderer, bool fullLayout)
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000166{
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000167 if (is<RenderText>(renderer)) {
168 RenderText& renderText = downcast<RenderText>(renderer);
esprehn@chromium.org7745ffb2013-02-19 21:51:19 +0000169 updateCounterIfNeeded(renderText);
weinig@apple.com12840dc2013-10-22 23:59:08 +0000170 renderText.dirtyLineBoxes(fullLayout);
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000171 } else if (is<RenderLineBreak>(renderer))
172 downcast<RenderLineBreak>(renderer).dirtyLineBoxes(fullLayout);
antti@apple.com9d8157e2013-09-17 15:13:37 +0000173 else
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000174 downcast<RenderInline>(renderer).dirtyLineBoxes(fullLayout);
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000175}
176
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000177static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox)
178{
179 do {
180 if (parentBox->isConstructed() || parentBox->nextOnLine())
181 return true;
182 parentBox = parentBox->parent();
183 } while (parentBox);
184 return false;
185}
186
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000187InlineFlowBox* RenderBlockFlow::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox)
hyattffe78712003-02-11 01:59:29 +0000188{
189 // See if we have an unconstructed line box for this object that is also
190 // the last item on the line.
hyatt1d5d87b2007-04-24 04:55:54 +0000191 unsigned lineDepth = 1;
cdumez@apple.com34e77ab2014-10-09 16:17:06 +0000192 InlineFlowBox* parentBox = nullptr;
193 InlineFlowBox* result = nullptr;
akling@apple.com827be9c2013-10-29 02:58:43 +0000194 bool hasDefaultLineBoxContain = style().lineBoxContain() == RenderStyle::initialLineBoxContain();
hyatt1d5d87b2007-04-24 04:55:54 +0000195 do {
cdumez@apple.com34e77ab2014-10-09 16:17:06 +0000196 ASSERT_WITH_SECURITY_IMPLICATION(is<RenderInline>(*obj) || obj == this);
eric@webkit.org060caf62011-05-03 22:11:39 +0000197
cdumez@apple.com34e77ab2014-10-09 16:17:06 +0000198 RenderInline* inlineFlow = obj != this ? downcast<RenderInline>(obj) : nullptr;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000199
hyatt1d5d87b2007-04-24 04:55:54 +0000200 // Get the last box we made for this render object.
cdumez@apple.com34e77ab2014-10-09 16:17:06 +0000201 parentBox = inlineFlow ? inlineFlow->lastLineBox() : downcast<RenderBlockFlow>(*obj).lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000202
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000203 // If this box or its ancestor is constructed then it is from a previous line, and we need
204 // to make a new box for our line. If this box or its ancestor is unconstructed but it has
hyatt1d5d87b2007-04-24 04:55:54 +0000205 // something following it on the line, then we know we have to make a new box
206 // as well. In this situation our inline has actually been split in two on
207 // the same line (this can happen with very fancy language mixtures).
208 bool constructedNewBox = false;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000209 bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes();
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000210 bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox);
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000211 if (allowedToConstructNewBox && !canUseExistingParentBox) {
hyatt1d5d87b2007-04-24 04:55:54 +0000212 // We need to make a new box for this render object. Once
213 // made, we need to place it at the end of the current line.
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000214 InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this);
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000215 parentBox = downcast<InlineFlowBox>(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();
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000265 const RenderObject& renderer = run->renderer();
266 if (!is<RenderText>(renderer))
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000267 return false;
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000268 const RenderText& renderText = downcast<RenderText>(renderer);
akling@apple.com7506fda2013-11-07 10:12:36 +0000269 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();
hyatt@apple.comdafe5972015-03-31 17:42:24 +0000285
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000286 for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) {
hyattffe78712003-02-11 01:59:29 +0000287 // Create a box for our object.
robert@webkit.org8cbab142011-12-30 20:58:29 +0000288 bool isOnlyRun = (runCount == 1);
akling@apple.com7506fda2013-11-07 10:12:36 +0000289 if (runCount == 2 && !r->renderer().isListMarker())
290 isOnlyRun = (!style().isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->renderer().isListMarker();
mitz@apple.come1364202008-02-28 01:06:41 +0000291
robert@webkit.org56e5a9f2012-02-17 21:10:42 +0000292 if (lineInfo.isEmpty())
293 continue;
294
akling@apple.com7506fda2013-11-07 10:12:36 +0000295 InlineBox* box = createInlineBoxForRenderer(&r->renderer(), false, isOnlyRun);
296 r->setBox(*box);
hyattffe78712003-02-11 01:59:29 +0000297
akling@apple.com0b8172b72013-08-31 18:34:23 +0000298 if (!rootHasSelectedChildren && box->renderer().selectionState() != RenderObject::SelectionNone)
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000299 rootHasSelectedChildren = true;
hyatt@apple.comdafe5972015-03-31 17:42:24 +0000300
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000301 // If we have no parent box yet, or if the run is not simply a sibling,
302 // then we need to construct inline boxes as necessary to properly enclose the
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000303 // run's inline box. Segments can only be siblings at the root level, as
304 // they are positioned separately.
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000305 if (!parentBox || &parentBox->renderer() != r->renderer().parent()) {
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000306 // Create new inline boxes all the way back to the appropriate insertion point.
hyatt@apple.com8e8cd252015-04-02 18:34:57 +0000307 RenderObject* parentToUse = r->renderer().parent();
hyatt@apple.comdafe5972015-03-31 17:42:24 +0000308 parentBox = createLineBoxes(parentToUse, lineInfo, box);
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000309 } else {
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000310 // Append the inline box to this line.
311 parentBox->addToLine(box);
312 }
mitz@apple.com576e84e2008-04-24 19:09:48 +0000313
akling@apple.com7506fda2013-11-07 10:12:36 +0000314 bool visuallyOrdered = r->renderer().style().rtlOrdering() == VisualOrder;
xji@chromium.org6b0c0172011-02-14 19:21:12 +0000315 box->setBidiLevel(r->level());
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000316
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000317 if (is<InlineTextBox>(*box)) {
318 auto& textBox = downcast<InlineTextBox>(*box);
319 textBox.setStart(r->m_start);
320 textBox.setLen(r->m_stop - r->m_start);
321 textBox.setDirOverride(r->dirOverride(visuallyOrdered));
mitz@apple.comb2107652010-06-21 16:54:52 +0000322 if (r->m_hasHyphen)
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000323 textBox.setHasHyphen(true);
hyatt0c3a9862004-02-23 21:26:26 +0000324 }
hyattffe78712003-02-11 01:59:29 +0000325 }
326
327 // We should have a root inline box. It should be unconstructed and
328 // be the last continuation of our line list.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000329 ASSERT(lastRootBox() && !lastRootBox()->isConstructed());
hyattffe78712003-02-11 01:59:29 +0000330
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000331 // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box
332 // from the bidi runs walk above has a selection state.
333 if (rootHasSelectedChildren)
akling@apple.comee3c8df2013-11-06 08:09:44 +0000334 lastRootBox()->root().setHasSelectedChildren(true);
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000335
hyattffe78712003-02-11 01:59:29 +0000336 // Set bits on our inline flow boxes that indicate which sides should
337 // paint borders/margins/padding. This knowledge will ultimately be used when
338 // we determine the horizontal positions and widths of all the inline boxes on
339 // the line.
hyatt@apple.com3ab5f732016-03-25 19:25:05 +0000340 bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->renderer().isText() ? !reachedEndOfTextRenderer(bidiRuns) : !is<RenderInline>(bidiRuns.logicallyLastRun()->renderer());
akling@apple.com7506fda2013-11-07 10:12:36 +0000341 lastRootBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, &bidiRuns.logicallyLastRun()->renderer());
hyattffe78712003-02-11 01:59:29 +0000342
343 // Now mark the line boxes as being constructed.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000344 lastRootBox()->setConstructed();
hyattffe78712003-02-11 01:59:29 +0000345
346 // Return the last line.
hyatt0c3a9862004-02-23 21:26:26 +0000347 return lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000348}
349
weinig@apple.com6b4a24142014-01-05 00:28:39 +0000350ETextAlign RenderBlockFlow::textAlignmentForLine(bool endsWithSoftBreak) const
mitz@apple.com390fa322011-02-24 23:07:06 +0000351{
akling@apple.com827be9c2013-10-29 02:58:43 +0000352 ETextAlign alignment = style().textAlign();
zoltan@webkit.orgcb4f0e42014-08-13 18:00:27 +0000353#if ENABLE(CSS3_TEXT)
354 TextJustify textJustify = style().textJustify();
zoltan@webkit.org14989c32014-08-14 21:36:40 +0000355 if (alignment == JUSTIFY && textJustify == TextJustifyNone)
zoltan@webkit.orgcb4f0e42014-08-13 18:00:27 +0000356 return style().direction() == LTR ? LEFT : RIGHT;
357#endif
358
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000359 if (endsWithSoftBreak)
360 return alignment;
mitz@apple.com390fa322011-02-24 23:07:06 +0000361
zoltan@webkit.org14989c32014-08-14 21:36:40 +0000362#if !ENABLE(CSS3_TEXT)
363 return (alignment == JUSTIFY) ? TASTART : alignment;
364#else
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000365 if (alignment != JUSTIFY)
366 return alignment;
367
368 TextAlignLast alignmentLast = style().textAlignLast();
369 switch (alignmentLast) {
370 case TextAlignLastStart:
371 return TASTART;
372 case TextAlignLastEnd:
373 return TAEND;
374 case TextAlignLastLeft:
375 return LEFT;
376 case TextAlignLastRight:
377 return RIGHT;
378 case TextAlignLastCenter:
379 return CENTER;
380 case TextAlignLastJustify:
381 return JUSTIFY;
382 case TextAlignLastAuto:
zoltan@webkit.orgcb4f0e42014-08-13 18:00:27 +0000383 if (textJustify == TextJustifyDistribute)
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000384 return JUSTIFY;
385 return TASTART;
386 }
mitz@apple.com390fa322011-02-24 23:07:06 +0000387 return alignment;
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000388#endif
mitz@apple.com390fa322011-02-24 23:07:06 +0000389}
390
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000391static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
392{
393 // The direction of the block should determine what happens with wide lines.
394 // In particular with RTL blocks, wide lines should still spill out to the left.
395 if (isLeftToRightDirection) {
396 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
andersca@apple.com86298632013-11-10 19:32:33 +0000397 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000398 return;
399 }
400
401 if (trailingSpaceRun)
akling@apple.com7506fda2013-11-07 10:12:36 +0000402 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000403 else if (totalLogicalWidth > availableLogicalWidth)
404 logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
405}
406
407static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
408{
409 // Wide lines spill out of the block based off direction.
410 // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
411 // side of the block.
412 if (isLeftToRightDirection) {
413 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000414 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
415 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000416 }
mmaxfield@apple.come6da30e2015-07-25 03:51:06 +0000417 logicalLeft += std::max(0.f, availableLogicalWidth - totalLogicalWidth);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000418 return;
419 }
420
421 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
andersca@apple.com86298632013-11-10 19:32:33 +0000422 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
akling@apple.com7506fda2013-11-07 10:12:36 +0000423 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000424 } else
425 logicalLeft += availableLogicalWidth - totalLogicalWidth;
426}
427
428static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
429{
430 float trailingSpaceWidth = 0;
431 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000432 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
andersca@apple.com86298632013-11-10 19:32:33 +0000433 trailingSpaceWidth = std::min(trailingSpaceRun->box()->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2);
434 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000435 }
436 if (isLeftToRightDirection)
andersca@apple.com86298632013-11-10 19:32:33 +0000437 logicalLeft += std::max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000438 else
439 logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
440}
441
weinig@apple.com12840dc2013-10-22 23:59:08 +0000442void RenderBlockFlow::setMarginsForRubyRun(BidiRun* run, RenderRubyRun& renderer, RenderObject* previousObject, const LineInfo& lineInfo)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000443{
mmaxfield@apple.com3273fd72014-12-16 22:53:19 +0000444 float startOverhang;
445 float endOverhang;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000446 RenderObject* nextObject = 0;
447 for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000448 if (!runWithNextObject->renderer().isOutOfFlowPositioned() && !runWithNextObject->box()->isLineBreak()) {
449 nextObject = &runWithNextObject->renderer();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000450 break;
451 }
452 }
akling@apple.com827be9c2013-10-29 02:58:43 +0000453 renderer.getOverhang(lineInfo.isFirstLine(), renderer.style().isLeftToRightDirection() ? previousObject : nextObject, renderer.style().isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000454 setMarginStartForChild(renderer, -startOverhang);
455 setMarginEndForChild(renderer, -endOverhang);
456}
457
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000458static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText& renderer, float xPos, const LineInfo& lineInfo,
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000459 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000460{
antti@apple.com5a8f7942015-01-22 21:57:04 +0000461 HashSet<const Font*> fallbackFonts;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000462 GlyphOverflow glyphOverflow;
antti@apple.comb0608f62013-09-28 18:30:16 +0000463
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000464 const FontCascade& font = lineStyle(*renderer.parent(), lineInfo).fontCascade();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000465 // Always compute glyph overflow if the block's line-box-contain value is "glyphs".
466 if (lineBox->fitsToGlyphs()) {
467 // If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization
468 // will keep us from computing glyph bounds in nearly all cases.
469 bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading();
akling@apple.com7506fda2013-11-07 10:12:36 +0000470 int baselineShift = lineBox->verticalPositionForBox(run->box(), verticalPositionCache);
enrica@apple.com885c84d2012-10-10 05:48:51 +0000471 int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0;
472 int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0;
473 int boxAscent = font.fontMetrics().ascent() - baselineShift;
474 int boxDescent = font.fontMetrics().descent() + baselineShift;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000475 if (boxAscent > rootDescent || boxDescent > rootAscent)
476 glyphOverflow.computeBounds = true;
477 }
478
leviw@chromium.orgd32486e2012-03-16 10:52:56 +0000479 LayoutUnit hyphenWidth = 0;
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000480 if (downcast<InlineTextBox>(*run->box()).hasHyphen())
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000481 hyphenWidth = measureHyphenWidth(renderer, font, &fallbackFonts);
antti@apple.comb0608f62013-09-28 18:30:16 +0000482
enrica@apple.com885c84d2012-10-10 05:48:51 +0000483 float measuredWidth = 0;
484
mmaxfield@apple.com2ef57ea2015-10-13 23:40:38 +0000485 bool kerningIsEnabled = font.enableKerning();
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000486 bool canUseSimpleFontCodePath = renderer.canUseSimpleFontCodePath();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000487
488 // Since we don't cache glyph overflows, we need to re-measure the run if
489 // the style is linebox-contain: glyph.
490
leviw@chromium.orgd70f4cc2013-03-28 21:03:44 +0000491 if (!lineBox->fitsToGlyphs() && canUseSimpleFontCodePath) {
enrica@apple.com885c84d2012-10-10 05:48:51 +0000492 int lastEndOffset = run->m_start;
493 for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOffset < run->m_stop; ++i) {
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000494 WordMeasurement& wordMeasurement = wordMeasurements[i];
495 if (wordMeasurement.width <= 0 || wordMeasurement.startOffset == wordMeasurement.endOffset)
enrica@apple.com885c84d2012-10-10 05:48:51 +0000496 continue;
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000497 if (wordMeasurement.renderer != &renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop)
enrica@apple.com885c84d2012-10-10 05:48:51 +0000498 continue;
499
500 lastEndOffset = wordMeasurement.endOffset;
501 if (kerningIsEnabled && lastEndOffset == run->m_stop) {
dino@apple.com7c50e7c2013-03-18 18:01:05 +0000502 int wordLength = lastEndOffset - wordMeasurement.startOffset;
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000503 GlyphOverflow overflow;
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000504 measuredWidth += renderer.width(wordMeasurement.startOffset, wordLength, xPos + measuredWidth, lineInfo.isFirstLine(),
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000505 &wordMeasurement.fallbackFonts, &overflow);
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000506 UChar c = renderer.characterAt(wordMeasurement.startOffset);
dino@apple.comd0b89252013-05-10 18:20:28 +0000507 if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t'))
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000508 measuredWidth += renderer.style().fontCascade().wordSpacing();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000509 } else
510 measuredWidth += wordMeasurement.width;
511 if (!wordMeasurement.fallbackFonts.isEmpty()) {
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +0000512 HashSet<const Font*>::const_iterator end = wordMeasurement.fallbackFonts.end();
513 for (HashSet<const Font*>::const_iterator it = wordMeasurement.fallbackFonts.begin(); it != end; ++it)
514 fallbackFonts.add(*it);
enrica@apple.com885c84d2012-10-10 05:48:51 +0000515 }
516 }
517 if (measuredWidth && lastEndOffset != run->m_stop) {
518 // If we don't have enough cached data, we'll measure the run again.
519 measuredWidth = 0;
520 fallbackFonts.clear();
521 }
522 }
enrica@apple.com885c84d2012-10-10 05:48:51 +0000523
524 if (!measuredWidth)
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000525 measuredWidth = renderer.width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow);
enrica@apple.com885c84d2012-10-10 05:48:51 +0000526
akling@apple.com7506fda2013-11-07 10:12:36 +0000527 run->box()->setLogicalWidth(measuredWidth + hyphenWidth);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000528 if (!fallbackFonts.isEmpty()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000529 ASSERT(run->box()->behavesLikeText());
antti@apple.com5a8f7942015-01-22 21:57:04 +0000530 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(downcast<InlineTextBox>(run->box()), std::make_pair(Vector<const Font*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000531 ASSERT(it->value.first.isEmpty());
532 copyToVector(fallbackFonts, it->value.first);
akling@apple.com7506fda2013-11-07 10:12:36 +0000533 run->box()->parent()->clearDescendantsHaveSameLineHeightAndBaseline();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000534 }
mmaxfield@apple.comf28245e2014-05-20 00:45:52 +0000535
536 // Include text decoration visual overflow as part of the glyph overflow.
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000537 if (renderer.style().textDecorationsInEffect() != TextDecorationNone)
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000538 glyphOverflow.extendTo(visualOverflowForDecorations(run->box()->lineStyle(), downcast<InlineTextBox>(run->box())));
mmaxfield@apple.comf28245e2014-05-20 00:45:52 +0000539
540 if (!glyphOverflow.isEmpty()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000541 ASSERT(run->box()->behavesLikeText());
antti@apple.com5a8f7942015-01-22 21:57:04 +0000542 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(downcast<InlineTextBox>(run->box()), std::make_pair(Vector<const Font*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000543 it->value.second = glyphOverflow;
akling@apple.com7506fda2013-11-07 10:12:36 +0000544 run->box()->clearKnownToHaveNoOverflow();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000545 }
546}
547
mmaxfield@apple.comb2c6d862015-02-18 19:39:17 +0000548void RenderBlockFlow::updateRubyForJustifiedText(RenderRubyRun& rubyRun, BidiRun& r, const Vector<unsigned, 16>& expansionOpportunities, unsigned& expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth, size_t& i)
mmaxfield@apple.com8301e832014-10-09 01:14:30 +0000549{
550 if (!rubyRun.rubyBase() || !rubyRun.rubyBase()->firstRootBox() || rubyRun.rubyBase()->firstRootBox()->nextRootBox() || !r.renderer().style().collapseWhiteSpace())
551 return;
552
553 auto& rubyBase = *rubyRun.rubyBase();
554 auto& rootBox = *rubyBase.firstRootBox();
555
556 float totalExpansion = 0;
557 unsigned totalOpportunitiesInRun = 0;
558 for (auto* leafChild = rootBox.firstLeafChild(); leafChild; leafChild = leafChild->nextLeafChild()) {
559 if (!leafChild->isInlineTextBox())
560 continue;
561
562 unsigned opportunitiesInRun = expansionOpportunities[i++];
563 ASSERT(opportunitiesInRun <= expansionOpportunityCount);
564 auto expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
565 totalExpansion += expansion;
566 totalOpportunitiesInRun += opportunitiesInRun;
567 }
568
rego@igalia.comf7d624c2015-04-22 10:31:24 +0000569 ASSERT(!rubyRun.hasOverrideLogicalContentWidth());
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000570 float newBaseWidth = rubyRun.logicalWidth() + totalExpansion + marginStartForChild(rubyRun) + marginEndForChild(rubyRun);
571 float newRubyRunWidth = rubyRun.logicalWidth() + totalExpansion;
572 rubyBase.setInitialOffset((newRubyRunWidth - newBaseWidth) / 2);
573 rubyRun.setOverrideLogicalContentWidth(newRubyRunWidth);
574 rubyRun.setNeedsLayout(MarkOnlyThis);
575 rootBox.markDirty();
576 if (RenderRubyText* rubyText = rubyRun.rubyText()) {
577 if (RootInlineBox* textRootBox = rubyText->firstRootBox())
578 textRootBox->markDirty();
mmaxfield@apple.com8301e832014-10-09 01:14:30 +0000579 }
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000580 rubyRun.layoutBlock(true);
581 rubyRun.clearOverrideLogicalContentWidth();
582 r.box()->setExpansion(newRubyRunWidth - r.box()->logicalWidth());
583
584 // This relayout caused the size of the RenderRubyText and the RenderRubyBase to change, dependent on the line's current expansion. Next time we relayout the
585 // RenderRubyRun, make sure that we relayout the RenderRubyBase and RenderRubyText as well.
586 rubyBase.setNeedsLayout(MarkOnlyThis);
587 if (RenderRubyText* rubyText = rubyRun.rubyText())
588 rubyText->setNeedsLayout(MarkOnlyThis);
589
590 totalLogicalWidth += totalExpansion;
591 expansionOpportunityCount -= totalOpportunitiesInRun;
mmaxfield@apple.com8301e832014-10-09 01:14:30 +0000592}
593
mmaxfield@apple.comb2c6d862015-02-18 19:39:17 +0000594void RenderBlockFlow::computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, const Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float totalLogicalWidth, float availableLogicalWidth)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000595{
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000596 if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth)
597 return;
598
599 size_t i = 0;
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000600 for (BidiRun* run = firstRun; run; run = run->next()) {
mmaxfield@apple.comb2c6d862015-02-18 19:39:17 +0000601 if (!run->box() || run == trailingSpaceRun)
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000602 continue;
603
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000604 if (is<RenderText>(run->renderer())) {
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000605 unsigned opportunitiesInRun = expansionOpportunities[i++];
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000606
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000607 ASSERT(opportunitiesInRun <= expansionOpportunityCount);
608
609 // Only justify text if whitespace is collapsed.
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000610 if (run->renderer().style().collapseWhiteSpace()) {
611 InlineTextBox& textBox = downcast<InlineTextBox>(*run->box());
mmaxfield@apple.coma9f58d02014-10-02 22:25:50 +0000612 float expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000613 textBox.setExpansion(expansion);
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000614 totalLogicalWidth += expansion;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000615 }
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000616 expansionOpportunityCount -= opportunitiesInRun;
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000617 } else if (is<RenderRubyRun>(run->renderer()))
mmaxfield@apple.comb2c6d862015-02-18 19:39:17 +0000618 updateRubyForJustifiedText(downcast<RenderRubyRun>(run->renderer()), *run, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth, i);
mmaxfield@apple.com8301e832014-10-09 01:14:30 +0000619
620 if (!expansionOpportunityCount)
621 break;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000622 }
623}
624
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000625void 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 +0000626{
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000627 TextDirection direction;
628 if (rootInlineBox && style().unicodeBidi() == Plaintext)
629 direction = rootInlineBox->direction();
630 else
631 direction = style().direction();
632
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000633 // Armed with the total width of the line (without justification),
634 // we now examine our text-align property in order to determine where to position the
635 // objects horizontally. The total width of the line can be increased if we end up
636 // justifying text.
637 switch (textAlign) {
638 case LEFT:
639 case WEBKIT_LEFT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000640 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000641 break;
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000642 case RIGHT:
643 case WEBKIT_RIGHT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000644 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000645 break;
646 case CENTER:
647 case WEBKIT_CENTER:
akling@apple.com827be9c2013-10-29 02:58:43 +0000648 updateLogicalWidthForCenterAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000649 break;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000650 case JUSTIFY:
651 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
652 if (expansionOpportunityCount) {
653 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000654 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
655 trailingSpaceRun->box()->setLogicalWidth(0);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000656 }
657 break;
658 }
joepeck@webkit.orgaa676ee52014-01-28 04:04:52 +0000659 FALLTHROUGH;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000660 case TASTART:
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000661 if (direction == LTR)
akling@apple.com827be9c2013-10-29 02:58:43 +0000662 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000663 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000664 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000665 break;
666 case TAEND:
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000667 if (direction == LTR)
akling@apple.com827be9c2013-10-29 02:58:43 +0000668 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000669 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000670 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000671 break;
672 }
673}
674
zalan@apple.com64761fe2016-03-02 21:42:22 +0000675static void updateLogicalInlinePositions(RenderBlockFlow& block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine,
676 IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight, RootInlineBox* rootBox)
commit-queue@webkit.orgab781b02013-04-03 01:32:24 +0000677{
weinig@apple.come9621c32014-01-04 20:53:51 +0000678 LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight);
hyatt@apple.com21c60802015-04-01 18:10:32 +0000679 if (rootBox->hasAnonymousInlineBlock()) {
680 lineLogicalLeft = block.logicalLeftOffsetForContent(block.logicalHeight());
681 lineLogicalRight = block.logicalRightOffsetForContent(block.logicalHeight());
682 } else {
zalan@apple.com64761fe2016-03-02 21:42:22 +0000683 lineLogicalLeft = block.logicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText, lineLogicalHeight);
684 lineLogicalRight = block.logicalRightOffsetForLine(block.logicalHeight(), shouldIndentText, lineLogicalHeight);
hyatt@apple.com21c60802015-04-01 18:10:32 +0000685 }
robert@webkit.org0903cf52012-12-11 18:14:16 +0000686 availableLogicalWidth = lineLogicalRight - lineLogicalLeft;
687}
688
weinig@apple.come9621c32014-01-04 20:53:51 +0000689void 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 +0000690{
mitz@apple.com390fa322011-02-24 23:07:06 +0000691 ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
robert@webkit.org4f76df92012-07-03 17:41:35 +0000692
robert@webkit.org328ecd02012-08-09 21:12:44 +0000693 // 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
694 // box is only affected if it is the first child of its parent element."
commit-queue@webkit.orgab781b02013-04-03 01:32:24 +0000695 // CSS3 "text-indent", "-webkit-each-line" affects the first line of the block container as well as each line after a forced line break,
696 // but does not affect lines after a soft wrap break.
697 bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this);
698 bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox()->endsWithBreak();
akling@apple.com827be9c2013-10-29 02:58:43 +0000699 IndentTextOrNot shouldIndentText = requiresIndent(isFirstLine, isAfterHardLineBreak, style());
robert@webkit.org0903cf52012-12-11 18:14:16 +0000700 float lineLogicalLeft;
701 float lineLogicalRight;
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000702 float availableLogicalWidth;
hyatt@apple.com21c60802015-04-01 18:10:32 +0000703 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0, lineBox);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000704 bool needsWordSpacing;
robert@webkit.org0903cf52012-12-11 18:14:16 +0000705
akling@apple.com7506fda2013-11-07 10:12:36 +0000706 if (firstRun && firstRun->renderer().isReplaced()) {
cdumez@apple.com0abff8b2014-10-17 21:25:10 +0000707 RenderBox& renderBox = downcast<RenderBox>(firstRun->renderer());
hyatt@apple.com21c60802015-04-01 18:10:32 +0000708 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight(), lineBox);
robert@webkit.org0903cf52012-12-11 18:14:16 +0000709 }
710
711 computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000712 // The widths of all runs are now known. We can now place every inline box (and
713 // compute accurate widths for the inline flow boxes).
714 needsWordSpacing = false;
mmaxfield@apple.comb0a4a3f2014-04-30 00:36:21 +0000715 lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000716}
mitz@apple.com390fa322011-02-24 23:07:06 +0000717
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000718static inline ExpansionBehavior expansionBehaviorForInlineTextBox(RenderBlockFlow& block, InlineTextBox& textBox, BidiRun* previousRun, BidiRun* nextRun, ETextAlign textAlign, bool isAfterExpansion)
mmaxfield@apple.com43761a72015-04-01 16:58:20 +0000719{
mmaxfield@apple.com5a572b12015-11-06 23:20:12 +0000720 // Tatechuyoko is modeled as the Object Replacement Character (U+FFFC), which can never have expansion opportunities inside nor intrinsically adjacent to it.
721 if (textBox.renderer().style().textCombine() == TextCombineHorizontal)
722 return ForbidLeadingExpansion | ForbidTrailingExpansion;
723
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000724 ExpansionBehavior result = 0;
725 bool setLeadingExpansion = false;
726 bool setTrailingExpansion = false;
727 if (textAlign == JUSTIFY) {
mmaxfield@apple.com5a572b12015-11-06 23:20:12 +0000728 // If the next box is ruby, and we're justifying, and the first box in the ruby base has a leading expansion, and we are a text box, then force a trailing expansion.
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000729 if (nextRun && is<RenderRubyRun>(nextRun->renderer()) && downcast<RenderRubyRun>(nextRun->renderer()).rubyBase() && nextRun->renderer().style().collapseWhiteSpace()) {
730 auto& rubyBase = *downcast<RenderRubyRun>(nextRun->renderer()).rubyBase();
731 if (rubyBase.firstRootBox() && !rubyBase.firstRootBox()->nextRootBox()) {
732 if (auto* leafChild = rubyBase.firstRootBox()->firstLeafChild()) {
733 if (is<InlineTextBox>(*leafChild)) {
734 // FIXME: This leadingExpansionOpportunity doesn't actually work because it doesn't perform the UBA
735 if (FontCascade::leadingExpansionOpportunity(downcast<RenderText>(leafChild->renderer()).stringView(), leafChild->direction())) {
736 setTrailingExpansion = true;
737 result |= ForceTrailingExpansion;
738 }
739 }
740 }
741 }
742 }
743 // Same thing, except if we're following a ruby
744 if (previousRun && is<RenderRubyRun>(previousRun->renderer()) && downcast<RenderRubyRun>(previousRun->renderer()).rubyBase() && previousRun->renderer().style().collapseWhiteSpace()) {
745 auto& rubyBase = *downcast<RenderRubyRun>(previousRun->renderer()).rubyBase();
746 if (rubyBase.firstRootBox() && !rubyBase.firstRootBox()->nextRootBox()) {
747 if (auto* leafChild = rubyBase.firstRootBox()->lastLeafChild()) {
748 if (is<InlineTextBox>(*leafChild)) {
749 // FIXME: This leadingExpansionOpportunity doesn't actually work because it doesn't perform the UBA
750 if (FontCascade::trailingExpansionOpportunity(downcast<RenderText>(leafChild->renderer()).stringView(), leafChild->direction())) {
751 setLeadingExpansion = true;
752 result |= ForceLeadingExpansion;
753 }
754 }
755 }
756 }
757 }
758 // If we're the first box inside a ruby base, forbid a leading expansion, and vice-versa
759 if (is<RenderRubyBase>(block)) {
760 RenderRubyBase& rubyBase = downcast<RenderRubyBase>(block);
761 if (&textBox == rubyBase.firstRootBox()->firstLeafChild()) {
762 setLeadingExpansion = true;
763 result |= ForbidLeadingExpansion;
764 } if (&textBox == rubyBase.firstRootBox()->lastLeafChild()) {
765 setTrailingExpansion = true;
766 result |= ForbidTrailingExpansion;
767 }
768 }
769 }
770 if (!setLeadingExpansion)
771 result |= isAfterExpansion ? ForbidLeadingExpansion : AllowLeadingExpansion;
772 if (!setTrailingExpansion)
773 result |= AllowTrailingExpansion;
mmaxfield@apple.com43761a72015-04-01 16:58:20 +0000774 return result;
775}
776
777static inline void applyExpansionBehavior(InlineTextBox& textBox, ExpansionBehavior expansionBehavior)
778{
779 switch (expansionBehavior & LeadingExpansionMask) {
780 case ForceLeadingExpansion:
781 textBox.setForceLeadingExpansion();
782 break;
783 case ForbidLeadingExpansion:
784 textBox.setCanHaveLeadingExpansion(false);
785 break;
786 case AllowLeadingExpansion:
787 textBox.setCanHaveLeadingExpansion(true);
788 break;
789 default:
790 ASSERT_NOT_REACHED();
791 break;
792 }
793 switch (expansionBehavior & TrailingExpansionMask) {
794 case ForceTrailingExpansion:
795 textBox.setForceTrailingExpansion();
796 break;
797 case ForbidTrailingExpansion:
798 textBox.setCanHaveTrailingExpansion(false);
799 break;
800 case AllowTrailingExpansion:
801 textBox.setCanHaveTrailingExpansion(true);
802 break;
803 default:
804 ASSERT_NOT_REACHED();
805 break;
806 }
807}
808
hyatt@apple.com41c12c92016-03-02 22:29:26 +0000809static bool inlineAncestorHasStartBorderPaddingOrMargin(const RenderBlockFlow& block, const InlineBox& box)
810{
811 bool isLTR = block.style().isLeftToRightDirection();
812 for (auto* currentBox = box.parent(); currentBox; currentBox = currentBox->parent()) {
813 if ((isLTR && currentBox->marginBorderPaddingLogicalLeft() > 0)
814 || (!isLTR && currentBox->marginBorderPaddingLogicalRight() > 0))
815 return true;
816 }
817 return false;
818}
819
hyatt@apple.com6b422a72016-03-03 21:49:32 +0000820static bool inlineAncestorHasEndBorderPaddingOrMargin(const RenderBlockFlow& block, const InlineBox& box)
821{
822 bool isLTR = block.style().isLeftToRightDirection();
823 for (auto* currentBox = box.parent(); currentBox; currentBox = currentBox->parent()) {
824 if ((isLTR && currentBox->marginBorderPaddingLogicalRight() > 0)
825 || (!isLTR && currentBox->marginBorderPaddingLogicalLeft() > 0))
826 return true;
827 }
828 return false;
829}
830
hyatt@apple.com41c12c92016-03-02 22:29:26 +0000831static bool isLastInFlowRun(BidiRun& runToCheck)
832{
833 for (auto* run = runToCheck.next(); run; run = run->next()) {
834 if (!run->box() || run->renderer().isOutOfFlowPositioned() || run->box()->isLineBreak())
835 continue;
836 return false;
837 }
838 return true;
839}
840
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000841BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBox* lineBox, const LineInfo& lineInfo, ETextAlign textAlign, float& logicalLeft,
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000842 float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache,
843 WordMeasurements& wordMeasurements)
844{
darin06dcb9c2005-08-15 04:31:09 +0000845 bool needsWordSpacing = false;
hyatt@apple.com41c12c92016-03-02 22:29:26 +0000846 bool canHangPunctuationAtStart = style().hangingPunctuation() & FirstHangingPunctuation;
hyatt@apple.com6b422a72016-03-03 21:49:32 +0000847 bool canHangPunctuationAtEnd = style().hangingPunctuation() & LastHangingPunctuation;
hyatt@apple.com41c12c92016-03-02 22:29:26 +0000848 bool isLTR = style().isLeftToRightDirection();
mitz@apple.com390fa322011-02-24 23:07:06 +0000849 float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();
mitz@apple.com86470c82011-01-27 01:39:27 +0000850 unsigned expansionOpportunityCount = 0;
commit-queue@webkit.org01ad5842014-12-16 19:28:57 +0000851 bool isAfterExpansion = is<RenderRubyBase>(*this) ? downcast<RenderRubyBase>(*this).isAfterExpansion() : true;
mitz@apple.com86470c82011-01-27 01:39:27 +0000852 Vector<unsigned, 16> expansionOpportunities;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000853
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000854 BidiRun* run = firstRun;
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000855 BidiRun* previousRun = nullptr;
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000856 for (; run; run = run->next()) {
857 if (!run->box() || run->renderer().isOutOfFlowPositioned() || run->box()->isLineBreak()) {
hyatt98ee7e42003-05-14 01:39:15 +0000858 continue; // Positioned objects are only participating to figure out their
859 // correct static x position. They have no effect on the width.
hyatt0c05e102006-04-14 08:15:00 +0000860 // Similarly, line break boxes have no effect on the width.
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000861 }
862 if (is<RenderText>(run->renderer())) {
863 auto& renderText = downcast<RenderText>(run->renderer());
mmaxfield@apple.com43761a72015-04-01 16:58:20 +0000864 auto& textBox = downcast<InlineTextBox>(*run->box());
hyatt@apple.com41c12c92016-03-02 22:29:26 +0000865 if (canHangPunctuationAtStart && lineInfo.isFirstLine() && (isLTR || isLastInFlowRun(*run))
866 && !inlineAncestorHasStartBorderPaddingOrMargin(*this, *run->box())) {
hyatt@apple.com6b422a72016-03-03 21:49:32 +0000867 float hangStartWidth = renderText.hangablePunctuationStartWidth(run->m_start);
hyatt@apple.com41c12c92016-03-02 22:29:26 +0000868 availableLogicalWidth += hangStartWidth;
869 if (style().isLeftToRightDirection())
870 logicalLeft -= hangStartWidth;
871 canHangPunctuationAtStart = false;
872 }
873
hyatt@apple.com6b422a72016-03-03 21:49:32 +0000874 if (canHangPunctuationAtEnd && lineInfo.isLastLine() && run->m_stop > 0 && (!isLTR || isLastInFlowRun(*run))
875 && !inlineAncestorHasEndBorderPaddingOrMargin(*this, *run->box())) {
876 float hangEndWidth = renderText.hangablePunctuationEndWidth(run->m_stop - 1);
877 availableLogicalWidth += hangEndWidth;
878 if (!style().isLeftToRightDirection())
879 logicalLeft -= hangEndWidth;
880 canHangPunctuationAtEnd = false;
881 }
882
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000883 if (textAlign == JUSTIFY && run != trailingSpaceRun) {
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000884 ExpansionBehavior expansionBehavior = expansionBehaviorForInlineTextBox(*this, textBox, previousRun, run->next(), textAlign, isAfterExpansion);
mmaxfield@apple.com43761a72015-04-01 16:58:20 +0000885 applyExpansionBehavior(textBox, expansionBehavior);
886 unsigned opportunitiesInRun;
887 std::tie(opportunitiesInRun, isAfterExpansion) = FontCascade::expansionOpportunityCount(renderText.stringView(run->m_start, run->m_stop), run->box()->direction(), expansionBehavior);
mitz@apple.com86470c82011-01-27 01:39:27 +0000888 expansionOpportunities.append(opportunitiesInRun);
889 expansionOpportunityCount += opportunitiesInRun;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000890 }
891
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000892 if (int length = renderText.textLength()) {
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000893 if (!run->m_start && needsWordSpacing && isSpaceOrNewline(renderText.characterAt(run->m_start)))
antti@apple.comc54cbc92015-01-15 14:19:56 +0000894 totalLogicalWidth += lineStyle(*renderText.parent(), lineInfo).fontCascade().wordSpacing();
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000895 needsWordSpacing = !isSpaceOrNewline(renderText.characterAt(run->m_stop - 1)) && run->m_stop == length;
darin06dcb9c2005-08-15 04:31:09 +0000896 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000897
mmaxfield@apple.com16fc17b2015-03-05 19:51:05 +0000898 setLogicalWidthForTextRun(lineBox, run, renderText, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
mitz@apple.com86470c82011-01-27 01:39:27 +0000899 } else {
hyatt@apple.com41c12c92016-03-02 22:29:26 +0000900 canHangPunctuationAtStart = false;
mmaxfield@apple.com8301e832014-10-09 01:14:30 +0000901 bool encounteredJustifiedRuby = false;
cdumez@apple.com3abcc792014-10-20 03:42:03 +0000902 if (is<RenderRubyRun>(run->renderer()) && textAlign == JUSTIFY && run != trailingSpaceRun && downcast<RenderRubyRun>(run->renderer()).rubyBase()) {
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000903 auto* rubyBase = downcast<RenderRubyRun>(run->renderer()).rubyBase();
904 if (rubyBase->firstRootBox() && !rubyBase->firstRootBox()->nextRootBox() && run->renderer().style().collapseWhiteSpace()) {
commit-queue@webkit.org01ad5842014-12-16 19:28:57 +0000905 rubyBase->setIsAfterExpansion(isAfterExpansion);
mmaxfield@apple.com8301e832014-10-09 01:14:30 +0000906 for (auto* leafChild = rubyBase->firstRootBox()->firstLeafChild(); leafChild; leafChild = leafChild->nextLeafChild()) {
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000907 if (!is<InlineTextBox>(*leafChild))
mmaxfield@apple.com8301e832014-10-09 01:14:30 +0000908 continue;
mmaxfield@apple.com43761a72015-04-01 16:58:20 +0000909 auto& textBox = downcast<InlineTextBox>(*leafChild);
mmaxfield@apple.com8301e832014-10-09 01:14:30 +0000910 encounteredJustifiedRuby = true;
911 auto& renderText = downcast<RenderText>(leafChild->renderer());
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000912 ExpansionBehavior expansionBehavior = expansionBehaviorForInlineTextBox(*rubyBase, textBox, nullptr, nullptr, textAlign, isAfterExpansion);
mmaxfield@apple.com43761a72015-04-01 16:58:20 +0000913 applyExpansionBehavior(textBox, expansionBehavior);
914 unsigned opportunitiesInRun;
915 std::tie(opportunitiesInRun, isAfterExpansion) = FontCascade::expansionOpportunityCount(renderText.stringView(), leafChild->direction(), expansionBehavior);
mmaxfield@apple.com8301e832014-10-09 01:14:30 +0000916 expansionOpportunities.append(opportunitiesInRun);
917 expansionOpportunityCount += opportunitiesInRun;
918 }
919 }
920 }
921
922 if (!encounteredJustifiedRuby)
923 isAfterExpansion = false;
924
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000925 if (!is<RenderInline>(run->renderer())) {
926 auto& renderBox = downcast<RenderBox>(run->renderer());
927 if (is<RenderRubyRun>(renderBox))
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000928 setMarginsForRubyRun(run, downcast<RenderRubyRun>(renderBox), previousRun ? &previousRun->renderer() : nullptr, lineInfo);
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000929 run->box()->setLogicalWidth(logicalWidthForChild(renderBox));
mitz@apple.com86470c82011-01-27 01:39:27 +0000930 totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox);
931 }
hyattffe78712003-02-11 01:59:29 +0000932 }
hyatt4b381692003-03-10 21:11:59 +0000933
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000934 totalLogicalWidth += run->box()->logicalWidth();
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000935 previousRun = run;
hyattffe78712003-02-11 01:59:29 +0000936 }
937
mitz@apple.com86470c82011-01-27 01:39:27 +0000938 if (isAfterExpansion && !expansionOpportunities.isEmpty()) {
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000939 expansionOpportunities.last()--;
940 expansionOpportunityCount--;
mitz@apple.com86470c82011-01-27 01:39:27 +0000941 }
942
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +0000943 if (is<RenderRubyBase>(*this) && !expansionOpportunityCount)
944 textAlign = CENTER;
945
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000946 updateLogicalWidthForAlignment(textAlign, lineBox, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount);
hyattffe78712003-02-11 01:59:29 +0000947
mmaxfield@apple.comb2c6d862015-02-18 19:39:17 +0000948 computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth);
mitz@apple.come1364202008-02-28 01:06:41 +0000949
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000950 return run;
hyattffe78712003-02-11 01:59:29 +0000951}
952
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000953void RenderBlockFlow::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000954 VerticalPositionCache& verticalPositionCache)
hyattffe78712003-02-11 01:59:29 +0000955{
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000956 setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache));
hyattffe78712003-02-11 01:59:29 +0000957
958 // Now make sure we place replaced render objects correctly.
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000959 for (BidiRun* run = firstRun; run; run = run->next()) {
960 ASSERT(run->box());
961 if (!run->box())
eseidel789896f2005-11-27 22:52:09 +0000962 continue; // Skip runs with no line boxes.
hyatt0c3a9862004-02-23 21:26:26 +0000963
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000964 InlineBox& box = *run->box();
akling@apple.com27e7d142013-11-07 12:04:02 +0000965
hyatt98ee7e42003-05-14 01:39:15 +0000966 // Align positioned boxes with the top of the line box. This is
967 // a reasonable approximation of an appropriate y position.
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000968 if (run->renderer().isOutOfFlowPositioned())
akling@apple.com27e7d142013-11-07 12:04:02 +0000969 box.setLogicalTop(logicalHeight());
hyatt98ee7e42003-05-14 01:39:15 +0000970
971 // Position is used to properly position both replaced elements and
972 // to update the static normal flow x/y of positioned elements.
cdumez@apple.com57d544c2014-10-16 00:05:37 +0000973 if (is<RenderText>(run->renderer()))
974 downcast<RenderText>(run->renderer()).positionLineBox(downcast<InlineTextBox>(box));
975 else if (is<RenderBox>(run->renderer()))
976 downcast<RenderBox>(run->renderer()).positionLineBox(downcast<InlineElementBox>(box));
977 else if (is<RenderLineBreak>(run->renderer()))
978 downcast<RenderLineBreak>(run->renderer()).replaceInlineBoxWrapper(downcast<InlineElementBox>(box));
hyatt98ee7e42003-05-14 01:39:15 +0000979 }
mitz@apple.coma927be62008-03-21 05:30:19 +0000980 // Positioned objects and zero-length text nodes destroy their boxes in
981 // position(), which unnecessarily dirties the line.
982 lineBox->markDirty(false);
hyattffe78712003-02-11 01:59:29 +0000983}
kociendabb0c24b2001-08-24 14:24:40 +0000984
akling@apple.com7506fda2013-11-07 10:12:36 +0000985static inline bool isCollapsibleSpace(UChar character, const RenderText& renderer)
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000986{
987 if (character == ' ' || character == '\t' || character == softHyphen)
988 return true;
989 if (character == '\n')
akling@apple.com7506fda2013-11-07 10:12:36 +0000990 return !renderer.style().preserveNewline();
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000991 if (character == noBreakSpace)
akling@apple.com7506fda2013-11-07 10:12:36 +0000992 return renderer.style().nbspMode() == SPACE;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000993 return false;
994}
995
msaboff@apple.com142fc202012-10-18 18:03:14 +0000996template <typename CharacterType>
akling@apple.com7506fda2013-11-07 10:12:36 +0000997static inline int findFirstTrailingSpace(const RenderText& lastText, const CharacterType* characters, int start, int stop)
msaboff@apple.com142fc202012-10-18 18:03:14 +0000998{
999 int firstSpace = stop;
1000 while (firstSpace > start) {
1001 UChar current = characters[firstSpace - 1];
1002 if (!isCollapsibleSpace(current, lastText))
1003 break;
1004 firstSpace--;
1005 }
1006
1007 return firstSpace;
1008}
1009
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001010inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext)
eric@webkit.org0894bb82011-04-03 08:29:40 +00001011{
eric@webkit.org5bee2942011-04-08 02:12:31 +00001012 if (!bidiRuns.runCount()
akling@apple.com7506fda2013-11-07 10:12:36 +00001013 || !bidiRuns.logicallyLastRun()->renderer().style().breakOnlyAfterWhiteSpace()
1014 || !bidiRuns.logicallyLastRun()->renderer().style().autoWrap())
cdumez@apple.com35094bd2014-10-07 19:33:53 +00001015 return nullptr;
eric@webkit.org0894bb82011-04-03 08:29:40 +00001016
eric@webkit.org5bee2942011-04-08 02:12:31 +00001017 BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun();
akling@apple.com7506fda2013-11-07 10:12:36 +00001018 const RenderObject& lastObject = trailingSpaceRun->renderer();
cdumez@apple.com35094bd2014-10-07 19:33:53 +00001019 if (!is<RenderText>(lastObject))
1020 return nullptr;
eric@webkit.org0894bb82011-04-03 08:29:40 +00001021
cdumez@apple.com35094bd2014-10-07 19:33:53 +00001022 const RenderText& lastText = downcast<RenderText>(lastObject);
msaboff@apple.com142fc202012-10-18 18:03:14 +00001023 int firstSpace;
akling@apple.com7506fda2013-11-07 10:12:36 +00001024 if (lastText.is8Bit())
1025 firstSpace = findFirstTrailingSpace(lastText, lastText.characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +00001026 else
akling@apple.com7506fda2013-11-07 10:12:36 +00001027 firstSpace = findFirstTrailingSpace(lastText, lastText.characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +00001028
eric@webkit.org0894bb82011-04-03 08:29:40 +00001029 if (firstSpace == trailingSpaceRun->stop())
cdumez@apple.com35094bd2014-10-07 19:33:53 +00001030 return nullptr;
eric@webkit.org0894bb82011-04-03 08:29:40 +00001031
akling@apple.com827be9c2013-10-29 02:58:43 +00001032 TextDirection direction = style().direction();
eric@webkit.org5bee2942011-04-08 02:12:31 +00001033 bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun());
eric@webkit.org0894bb82011-04-03 08:29:40 +00001034 if (firstSpace != trailingSpaceRun->start()) {
eric@webkit.org5bee2942011-04-08 02:12:31 +00001035 BidiContext* baseContext = currentContext;
eric@webkit.org0894bb82011-04-03 08:29:40 +00001036 while (BidiContext* parent = baseContext->parent())
1037 baseContext = parent;
1038
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +00001039 std::unique_ptr<BidiRun> newTrailingRun = std::make_unique<BidiRun>(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->renderer(), baseContext, U_OTHER_NEUTRAL);
eric@webkit.org0894bb82011-04-03 08:29:40 +00001040 trailingSpaceRun->m_stop = firstSpace;
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +00001041 trailingSpaceRun = newTrailingRun.get();
eric@webkit.org0894bb82011-04-03 08:29:40 +00001042 if (direction == LTR)
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +00001043 bidiRuns.appendRun(WTFMove(newTrailingRun));
eric@webkit.org0894bb82011-04-03 08:29:40 +00001044 else
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +00001045 bidiRuns.prependRun(WTFMove(newTrailingRun));
eric@webkit.org0894bb82011-04-03 08:29:40 +00001046 return trailingSpaceRun;
1047 }
1048 if (!shouldReorder)
1049 return trailingSpaceRun;
1050
1051 if (direction == LTR) {
eric@webkit.org5bee2942011-04-08 02:12:31 +00001052 bidiRuns.moveRunToEnd(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +00001053 trailingSpaceRun->m_level = 0;
1054 } else {
eric@webkit.org5bee2942011-04-08 02:12:31 +00001055 bidiRuns.moveRunToBeginning(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +00001056 trailingSpaceRun->m_level = 1;
1057 }
1058 return trailingSpaceRun;
1059}
1060
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001061void RenderBlockFlow::appendFloatingObjectToLastLine(FloatingObject* floatingObject)
mitz@apple.comd17e8c02011-04-16 21:59:36 +00001062{
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001063 ASSERT(!floatingObject->originatingLine());
1064 floatingObject->setOriginatingLine(lastRootBox());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001065 lastRootBox()->appendFloat(floatingObject->renderer());
mitz@apple.comd17e8c02011-04-16 21:59:36 +00001066}
1067
mmaxfield@apple.comff5b7ac2015-07-10 20:39:16 +00001068static inline void notifyResolverToResumeInIsolate(InlineBidiResolver& resolver, RenderObject* root, RenderObject* startObject)
mmaxfield@apple.com18782a22014-01-28 21:53:22 +00001069{
1070 if (root != startObject) {
1071 RenderObject* parent = startObject->parent();
mmaxfield@apple.comff5b7ac2015-07-10 20:39:16 +00001072 notifyResolverToResumeInIsolate(resolver, root, parent);
mmaxfield@apple.com18782a22014-01-28 21:53:22 +00001073 notifyObserverEnteredObject(&resolver, startObject);
1074 }
1075}
1076
mmaxfield@apple.com0fba19a2015-09-16 00:30:38 +00001077static inline void setUpResolverToResumeInIsolate(InlineBidiResolver& resolver, InlineBidiResolver& topResolver, BidiRun& isolatedRun, RenderObject* root, RenderObject* startObject)
mmaxfield@apple.comff5b7ac2015-07-10 20:39:16 +00001078{
1079 // Set up m_midpointState
1080 resolver.midpointState() = topResolver.midpointState();
1081 resolver.midpointState().setCurrentMidpoint(topResolver.midpointForIsolatedRun(isolatedRun));
1082
1083 // Set up m_nestedIsolateCount
1084 notifyResolverToResumeInIsolate(resolver, root, startObject);
1085}
1086
eric@webkit.orga26de042011-09-08 18:46:01 +00001087// FIXME: BidiResolver should have this logic.
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001088static inline void constructBidiRunsForSegment(InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfRuns, VisualDirectionOverride override, bool previousLineBrokeCleanly)
eric@webkit.orga26de042011-09-08 18:46:01 +00001089{
1090 // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead
1091 // of the resolver owning the runs.
1092 ASSERT(&topResolver.runs() == &bidiRuns);
betravis@adobe.com9e5e8242013-04-19 23:28:26 +00001093 ASSERT(topResolver.position() != endOfRuns);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001094 RenderObject* currentRoot = topResolver.position().root();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001095 topResolver.createBidiRunsForLine(endOfRuns, override, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +00001096
1097 while (!topResolver.isolatedRuns().isEmpty()) {
1098 // It does not matter which order we resolve the runs as long as we resolve them all.
aestes@apple.com13aae082016-01-02 08:03:08 +00001099 auto isolatedRun = WTFMove(topResolver.isolatedRuns().last());
eric@webkit.orga26de042011-09-08 18:46:01 +00001100 topResolver.isolatedRuns().removeLast();
mmaxfield@apple.com0fba19a2015-09-16 00:30:38 +00001101 currentRoot = &isolatedRun.root;
eric@webkit.orga26de042011-09-08 18:46:01 +00001102
mmaxfield@apple.com0fba19a2015-09-16 00:30:38 +00001103 RenderObject& startObject = isolatedRun.object;
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001104
eric@webkit.orga26de042011-09-08 18:46:01 +00001105 // Only inlines make sense with unicode-bidi: isolate (blocks are already isolated).
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001106 // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the
1107 // tree to see which parent inline is the isolate. We could change enterIsolate
1108 // to take a RenderObject and do this logic there, but that would be a layering
1109 // violation for BidiResolver (which knows nothing about RenderObject).
cdumez@apple.comf8022152014-10-15 00:29:51 +00001110 RenderInline* isolatedInline = downcast<RenderInline>(highestContainingIsolateWithinRoot(startObject, currentRoot));
ddkilzer@apple.comad6ad362014-04-02 17:21:09 +00001111 ASSERT(isolatedInline);
1112
eric@webkit.orga26de042011-09-08 18:46:01 +00001113 InlineBidiResolver isolatedResolver;
akling@apple.com827be9c2013-10-29 02:58:43 +00001114 EUnicodeBidi unicodeBidi = isolatedInline->style().unicodeBidi();
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001115 TextDirection direction;
1116 if (unicodeBidi == Plaintext)
mmaxfield@apple.com0fba19a2015-09-16 00:30:38 +00001117 determineDirectionality(direction, InlineIterator(isolatedInline, &isolatedRun.object, 0));
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001118 else {
rniwa@webkit.org4d4bd332012-08-20 21:34:11 +00001119 ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride);
akling@apple.com827be9c2013-10-29 02:58:43 +00001120 direction = isolatedInline->style().direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001121 }
zoltan@webkit.orgd1a97402013-12-08 05:53:33 +00001122 isolatedResolver.setStatus(BidiStatus(direction, isOverride(unicodeBidi)));
eric@webkit.orga26de042011-09-08 18:46:01 +00001123
mmaxfield@apple.com0fba19a2015-09-16 00:30:38 +00001124 setUpResolverToResumeInIsolate(isolatedResolver, topResolver, isolatedRun.runToReplace, isolatedInline, &startObject);
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001125
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001126 // The starting position is the beginning of the first run within the isolate that was identified
1127 // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the
1128 // first run within the isolate.
mmaxfield@apple.com0fba19a2015-09-16 00:30:38 +00001129 InlineIterator iter = InlineIterator(isolatedInline, &startObject, isolatedRun.position);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001130 isolatedResolver.setPositionIgnoringNestedIsolates(iter);
eric@webkit.orga26de042011-09-08 18:46:01 +00001131
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +00001132 // 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 +00001133 // FIXME: What should end and previousLineBrokeCleanly be?
1134 // rniwa says previousLineBrokeCleanly is just a WinIE hack and could always be false here?
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +00001135 isolatedResolver.createBidiRunsForLine(endOfRuns, NoVisualOverride, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +00001136 // Note that we do not delete the runs from the resolver.
rniwa@webkit.orgd0ad8882012-05-23 07:37:07 +00001137 // 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 +00001138 // itself to be turned into an InlineBox. We can't remove it here without potentially losing track of
1139 // the logically last run.
1140 if (isolatedResolver.runs().runCount())
mmaxfield@apple.com0fba19a2015-09-16 00:30:38 +00001141 bidiRuns.replaceRunWithRuns(&isolatedRun.runToReplace, isolatedResolver.runs());
eric@webkit.orga26de042011-09-08 18:46:01 +00001142
1143 // If we encountered any nested isolate runs, just move them
1144 // to the top resolver's list for later processing.
mmaxfield@apple.com0fba19a2015-09-16 00:30:38 +00001145 while (!isolatedResolver.isolatedRuns().isEmpty()) {
aestes@apple.com13aae082016-01-02 08:03:08 +00001146 auto runWithContext = WTFMove(isolatedResolver.isolatedRuns().last());
mmaxfield@apple.com0fba19a2015-09-16 00:30:38 +00001147 isolatedResolver.isolatedRuns().removeLast();
1148 topResolver.setMidpointForIsolatedRun(runWithContext.runToReplace, isolatedResolver.midpointForIsolatedRun(runWithContext.runToReplace));
aestes@apple.com13aae082016-01-02 08:03:08 +00001149 topResolver.isolatedRuns().append(WTFMove(runWithContext));
eric@webkit.orga26de042011-09-08 18:46:01 +00001150 }
1151 }
1152}
1153
eric@webkit.org45e33a52011-05-04 11:51:09 +00001154// 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 +00001155RootInlineBox* 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 +00001156{
1157 if (!bidiRuns.runCount())
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +00001158 return nullptr;
eric@webkit.org45e33a52011-05-04 11:51:09 +00001159
1160 // FIXME: Why is this only done when we had runs?
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +00001161 lineInfo.setLastLine(!end.renderer());
eric@webkit.org45e33a52011-05-04 11:51:09 +00001162
1163 RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo);
1164 if (!lineBox)
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +00001165 return nullptr;
eric@webkit.org45e33a52011-05-04 11:51:09 +00001166
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001167 lineBox->setBidiLevel(bidiLevel);
eric@webkit.org45e33a52011-05-04 11:51:09 +00001168 lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly());
1169
cdumez@apple.com57d544c2014-10-16 00:05:37 +00001170 bool isSVGRootInlineBox = is<SVGRootInlineBox>(*lineBox);
eric@webkit.org45e33a52011-05-04 11:51:09 +00001171
1172 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
1173
1174 // Now we position all of our text runs horizontally.
1175 if (!isSVGRootInlineBox)
enrica@apple.com885c84d2012-10-10 05:48:51 +00001176 computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache, wordMeasurements);
eric@webkit.org45e33a52011-05-04 11:51:09 +00001177
1178 // Now position our text runs vertically.
1179 computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache);
1180
eric@webkit.org45e33a52011-05-04 11:51:09 +00001181 // SVG text layout code computes vertical & horizontal positions on its own.
1182 // Note that we still need to execute computeVerticalPositionsForLine() as
1183 // it calls InlineTextBox::positionLineBox(), which tracks whether the box
1184 // contains reversed text or not. If we wouldn't do that editing and thus
1185 // text selection in RTL boxes would not work as expected.
1186 if (isSVGRootInlineBox) {
akling@apple.com670fea12013-10-12 18:16:42 +00001187 ASSERT_WITH_SECURITY_IMPLICATION(isSVGText());
cdumez@apple.com57d544c2014-10-16 00:05:37 +00001188 downcast<SVGRootInlineBox>(*lineBox).computePerCharacterLayoutInformation();
eric@webkit.org45e33a52011-05-04 11:51:09 +00001189 }
eric@webkit.org45e33a52011-05-04 11:51:09 +00001190
1191 // Compute our overflow now.
1192 lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap);
1193
eric@webkit.org45e33a52011-05-04 11:51:09 +00001194 return lineBox;
1195}
1196
akling@apple.com31dd4f42013-10-30 22:27:59 +00001197static void deleteLineRange(LineLayoutState& layoutState, RootInlineBox* startLine, RootInlineBox* stopLine = 0)
eric@webkit.org455d90e2011-05-09 22:27:27 +00001198{
1199 RootInlineBox* boxToDelete = startLine;
1200 while (boxToDelete && boxToDelete != stopLine) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001201 layoutState.updateRepaintRangeFromBox(boxToDelete);
akling@apple.com31dd4f42013-10-30 22:27:59 +00001202 // Note: deleteLineRange(firstRootBox()) is not identical to deleteLineBoxTree().
eric@webkit.orge2532d92011-05-16 23:10:49 +00001203 // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing.
eric@webkit.org455d90e2011-05-09 22:27:27 +00001204 RootInlineBox* next = boxToDelete->nextRootBox();
akling@apple.com31dd4f42013-10-30 22:27:59 +00001205 boxToDelete->deleteLine();
eric@webkit.org455d90e2011-05-09 22:27:27 +00001206 boxToDelete = next;
1207 }
1208}
1209
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001210void RenderBlockFlow::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild)
eric@webkit.org060caf62011-05-03 22:11:39 +00001211{
1212 // We want to skip ahead to the first dirty line
1213 InlineBidiResolver resolver;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001214 RootInlineBox* startLine = determineStartPosition(layoutState, resolver);
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001215
1216 if (startLine)
1217 marginCollapseLinesFromStart(layoutState, startLine);
eric@webkit.org060caf62011-05-03 22:11:39 +00001218
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001219 unsigned consecutiveHyphenatedLines = 0;
1220 if (startLine) {
1221 for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox())
1222 consecutiveHyphenatedLines++;
1223 }
1224
eric@webkit.org060caf62011-05-03 22:11:39 +00001225 // FIXME: This would make more sense outside of this function, but since
1226 // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call
1227 // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html.
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001228 if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) {
antti@apple.comca2a8ff2013-10-04 04:04:35 +00001229 setNeedsLayout(MarkOnlyThis); // Mark as needing a full layout to force us to repaint.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001230 if (!view().doingFullRepaint() && hasLayer()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001231 // Because we waited until we were already inside layout to discover
1232 // that the block really needed a full layout, we missed our chance to repaint the layer
1233 // before layout started. Luckily the layer has cached the repaint rect for its original
1234 // position and size, and so we can use that to make a repaint happen now.
zalan@apple.comc7b20b12014-02-12 04:50:55 +00001235 repaintUsingContainer(containerForRepaint(), layer()->repaintRect());
eric@webkit.org060caf62011-05-03 22:11:39 +00001236 }
1237 }
1238
mihnea@adobe.com99467792013-03-19 09:09:04 +00001239 if (containsFloats())
darin@apple.com7cad7042013-09-24 05:53:55 +00001240 layoutState.setLastFloat(m_floatingObjects->set().last().get());
eric@webkit.org060caf62011-05-03 22:11:39 +00001241
1242 // We also find the first clean line and extract these lines. We will add them back
1243 // if we determine that we're able to synchronize after handling all our dirty lines.
1244 InlineIterator cleanLineStart;
1245 BidiStatus cleanLineBidiStatus;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001246 if (!layoutState.isFullLayout() && startLine)
1247 determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus);
eric@webkit.org060caf62011-05-03 22:11:39 +00001248
1249 if (startLine) {
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001250 if (!layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001251 layoutState.setRepaintRange(logicalHeight());
akling@apple.com31dd4f42013-10-30 22:27:59 +00001252 deleteLineRange(layoutState, startLine);
eric@webkit.org060caf62011-05-03 22:11:39 +00001253 }
1254
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001255 if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001256 // If the last line before the start line ends with a line break that clear floats,
1257 // adjust the height accordingly.
1258 // A line break can be either the first or the last object on a line, depending on its direction.
1259 if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) {
akling@apple.com0b8172b72013-08-31 18:34:23 +00001260 RenderObject* lastObject = &lastLeafChild->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001261 if (!lastObject->isBR())
akling@apple.com0b8172b72013-08-31 18:34:23 +00001262 lastObject = &lastRootBox()->firstLeafChild()->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001263 if (lastObject->isBR()) {
akling@apple.com827be9c2013-10-29 02:58:43 +00001264 EClear clear = lastObject->style().clear();
eric@webkit.org060caf62011-05-03 22:11:39 +00001265 if (clear != CNONE)
bjonesbe@adobe.comf9f10402014-02-20 19:40:28 +00001266 clearFloats(clear);
eric@webkit.org060caf62011-05-03 22:11:39 +00001267 }
1268 }
1269 }
1270
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001271 layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001272 linkToEndLineIfNeeded(layoutState);
1273 repaintDirtyFloats(layoutState.floats());
1274}
eric@webkit.org060caf62011-05-03 22:11:39 +00001275
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001276// 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 +00001277inline const InlineIterator& RenderBlockFlow::restartLayoutRunsAndFloatsInRange(LayoutUnit oldLogicalHeight, LayoutUnit newLogicalHeight, FloatingObject* lastFloatFromPreviousLine, InlineBidiResolver& resolver, const InlineIterator& oldEnd)
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001278{
1279 removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight);
1280 setLogicalHeight(newLogicalHeight);
1281 resolver.setPositionIgnoringNestedIsolates(oldEnd);
1282 return oldEnd;
1283}
1284
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001285void RenderBlockFlow::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001286{
akling@apple.com827be9c2013-10-29 02:58:43 +00001287 const RenderStyle& styleToUse = style();
akling@apple.com691cf5c2013-08-24 16:33:15 +00001288 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001289 LineMidpointState& lineMidpointState = resolver.midpointState();
1290 InlineIterator end = resolver.position();
1291 bool checkForEndLineMatch = layoutState.endLine();
mitz@apple.com6a859602012-08-27 15:31:56 +00001292 RenderTextInfo renderTextInfo;
eric@webkit.org060caf62011-05-03 22:11:39 +00001293 VerticalPositionCache verticalPositionCache;
1294
weinig@apple.com12840dc2013-10-22 23:59:08 +00001295 LineBreaker lineBreaker(*this);
leviw@chromium.org1a508692011-05-05 00:01:11 +00001296
eric@webkit.org060caf62011-05-03 22:11:39 +00001297 while (!end.atEnd()) {
1298 // 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 +00001299 if (checkForEndLineMatch) {
1300 layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus));
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001301 if (layoutState.endLineMatched()) {
1302 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001303 layoutState.marginInfo().clearMargin();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001304 break;
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001305 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001306 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001307
1308 lineMidpointState.reset();
1309
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001310 layoutState.lineInfo().setEmpty(true);
robert@webkit.org8cbab142011-12-30 20:58:29 +00001311 layoutState.lineInfo().resetRunsFromLeadingWhitespace();
eric@webkit.org060caf62011-05-03 22:11:39 +00001312
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001313 const InlineIterator oldEnd = end;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001314 bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly();
zalan@apple.com84ccfa12015-10-17 03:36:56 +00001315 FloatingObject* lastFloatFromPreviousLine = (containsFloats()) ? m_floatingObjects->set().last().get() : nullptr;
zoltan@webkit.org3bd77f52013-04-23 18:23:36 +00001316
enrica@apple.com885c84d2012-10-10 05:48:51 +00001317 WordMeasurements wordMeasurements;
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001318 end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), layoutState, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
darin@apple.com3d1d5fc2015-04-23 05:20:23 +00001319 cachePriorCharactersIfNeeded(renderTextInfo.lineBreakIterator);
1320 renderTextInfo.lineBreakIterator.resetPriorContext();
eric@webkit.org060caf62011-05-03 22:11:39 +00001321 if (resolver.position().atEnd()) {
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001322 // FIXME: We shouldn't be creating any runs in nextLineBreak to begin with!
eric@webkit.org060caf62011-05-03 22:11:39 +00001323 // Once BidiRunList is separated from BidiResolver this will not be needed.
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +00001324 resolver.runs().clear();
eric@webkit.org060caf62011-05-03 22:11:39 +00001325 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001326 layoutState.setCheckForFloatsFromLastLine(true);
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001327 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
eric@webkit.org060caf62011-05-03 22:11:39 +00001328 break;
1329 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001330
betravis@adobe.com9e5e8242013-04-19 23:28:26 +00001331 ASSERT(end != resolver.position());
1332
eric@webkit.org45e33a52011-05-04 11:51:09 +00001333 // This is a short-cut for empty lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001334 if (layoutState.lineInfo().isEmpty()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001335 if (lastRootBox())
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001336 lastRootBox()->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
eric@webkit.org060caf62011-05-03 22:11:39 +00001337 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001338 VisualDirectionOverride override = (styleToUse.rtlOrdering() == VisualOrder ? (styleToUse.direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride);
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001339
akling@apple.com827be9c2013-10-29 02:58:43 +00001340 if (isNewUBAParagraph && styleToUse.unicodeBidi() == Plaintext && !resolver.context()->parent()) {
1341 TextDirection direction = styleToUse.direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001342 determineDirectionality(direction, resolver.position());
akling@apple.com827be9c2013-10-29 02:58:43 +00001343 resolver.setStatus(BidiStatus(direction, isOverride(styleToUse.unicodeBidi())));
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001344 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001345 // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine.
1346 BidiRunList<BidiRun>& bidiRuns = resolver.runs();
zoltan@webkit.org7d4f8cc2014-03-26 18:20:15 +00001347 constructBidiRunsForSegment(resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly());
eric@webkit.org060caf62011-05-03 22:11:39 +00001348 ASSERT(resolver.position() == end);
1349
mmaxfield@apple.com08b380d2015-04-02 20:29:23 +00001350 BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : nullptr;
eric@webkit.org060caf62011-05-03 22:11:39 +00001351
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001352 if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) {
eric@webkit.org45e33a52011-05-04 11:51:09 +00001353 bidiRuns.logicallyLastRun()->m_hasHyphen = true;
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001354 consecutiveHyphenatedLines++;
1355 } else
1356 consecutiveHyphenatedLines = 0;
eric@webkit.org45e33a52011-05-04 11:51:09 +00001357
eric@webkit.org060caf62011-05-03 22:11:39 +00001358 // Now that the runs have been ordered, we create the line boxes.
1359 // At the same time we figure out where border/padding/margin should be applied for
1360 // inline flow boxes.
1361
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001362 LayoutUnit oldLogicalHeight = logicalHeight();
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001363 RootInlineBox* lineBox = createLineBoxesFromBidiRuns(resolver.status().context->level(), bidiRuns, end, layoutState.lineInfo(), verticalPositionCache, trailingSpaceRun, wordMeasurements);
eric@webkit.org060caf62011-05-03 22:11:39 +00001364
mmaxfield@apple.com9ccce672016-04-02 07:01:43 +00001365 bidiRuns.clear();
eric@webkit.org060caf62011-05-03 22:11:39 +00001366 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
1367
1368 if (lineBox) {
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001369 lineBox->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001370 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001371 layoutState.updateRepaintRangeFromBox(lineBox);
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001372
1373 LayoutUnit adjustment = 0;
1374 bool overflowsRegion = false;
1375
1376 // If our previous line was an anonymous block and we are not an anonymous block,
1377 // simulate a margin collapse now so that we get the proper
1378 // increased height. We also have to simulate a margin collapse to propagate margins
1379 // through to the top of our block.
1380 if (!lineBox->hasAnonymousInlineBlock()) {
1381 RootInlineBox* prevRoot = lineBox->prevRootBox();
1382 if (prevRoot && prevRoot->hasAnonymousInlineBlock()) {
1383 LayoutUnit currentLogicalHeight = logicalHeight();
1384 setLogicalHeight(oldLogicalHeight);
1385 collapseMarginsWithChildInfo(nullptr, nullptr, layoutState.marginInfo());
1386 adjustment = logicalHeight() - oldLogicalHeight;
1387 setLogicalHeight(currentLogicalHeight);
eric@webkit.org060caf62011-05-03 22:11:39 +00001388 }
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001389 layoutState.marginInfo().setAtBeforeSideOfBlock(false);
1390 }
1391
1392 if (paginated)
1393 adjustLinePositionForPagination(lineBox, adjustment, overflowsRegion, layoutState.flowThread());
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001394 if (adjustment) {
zalan@apple.com64761fe2016-03-02 21:42:22 +00001395 IndentTextOrNot shouldIndentText = layoutState.lineInfo().isFirstLine() ? IndentText : DoNotIndentText;
1396 LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, shouldIndentText);
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001397 lineBox->adjustBlockDirectionPosition(adjustment);
1398 if (layoutState.usesRepaintBounds())
1399 layoutState.updateRepaintRangeFromBox(lineBox);
1400
zalan@apple.com64761fe2016-03-02 21:42:22 +00001401 if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, shouldIndentText) != oldLineWidth) {
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001402 // We have to delete this line, remove all floats that got added, and let line layout re-run.
1403 lineBox->deleteLine();
1404 end = restartLayoutRunsAndFloatsInRange(oldLogicalHeight, oldLogicalHeight + adjustment, lastFloatFromPreviousLine, resolver, oldEnd);
1405 continue;
1406 }
1407
1408 setLogicalHeight(lineBox->lineBottomWithLeading());
1409 }
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001410
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001411 if (paginated) {
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001412 if (RenderFlowThread* flowThread = flowThreadContainingBlock()) {
1413 if (flowThread->isRenderNamedFlowThread() && overflowsRegion && hasNextPage(lineBox->lineTop())) {
1414 // Limit the height of this block to the end of the current region because
1415 // it is also fragmented into the next region.
1416 LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalTop(), ExcludePageBoundary);
1417 if (logicalHeight() > remainingLogicalHeight)
1418 setLogicalHeight(remainingLogicalHeight);
1419 }
1420 }
commit-queue@webkit.orgbe554b22012-11-26 20:00:49 +00001421
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001422 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001423 updateRegionForLine(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001424 }
1425 }
robert@webkit.org402c1512013-02-07 18:48:39 +00001426 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001427
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +00001428 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i)
zalan@apple.com4d97a002016-02-24 17:13:33 +00001429 setStaticPositions(*this, *lineBreaker.positionedObjects()[i], DoNotIndentText);
eric@webkit.org060caf62011-05-03 22:11:39 +00001430
robert@webkit.org402c1512013-02-07 18:48:39 +00001431 if (!layoutState.lineInfo().isEmpty()) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001432 layoutState.lineInfo().setFirstLine(false);
bjonesbe@adobe.comf9f10402014-02-20 19:40:28 +00001433 clearFloats(lineBreaker.clear());
eric@webkit.org060caf62011-05-03 22:11:39 +00001434 }
1435
1436 if (m_floatingObjects && lastRootBox()) {
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001437 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001438 auto it = floatingObjectSet.begin();
1439 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001440 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001441 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001442 ASSERT(lastFloatIterator != end);
1443 ++lastFloatIterator;
1444 it = lastFloatIterator;
1445 }
1446 for (; it != end; ++it) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001447 FloatingObject* f = it->get();
eric@webkit.org060caf62011-05-03 22:11:39 +00001448 appendFloatingObjectToLastLine(f);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001449 ASSERT(&f->renderer() == &layoutState.floats()[layoutState.floatIndex()].object);
eric@webkit.org060caf62011-05-03 22:11:39 +00001450 // If a float's geometry has changed, give up on syncing with clean lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001451 if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect())
eric@webkit.org060caf62011-05-03 22:11:39 +00001452 checkForEndLineMatch = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001453 layoutState.setFloatIndex(layoutState.floatIndex() + 1);
eric@webkit.org060caf62011-05-03 22:11:39 +00001454 }
darin@apple.com7cad7042013-09-24 05:53:55 +00001455 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001456 }
1457
1458 lineMidpointState.reset();
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001459 resolver.setPosition(end, numberOfIsolateAncestors(end));
eric@webkit.org060caf62011-05-03 22:11:39 +00001460 }
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001461
abucur@adobe.comfc497132013-10-04 08:49:21 +00001462 // In case we already adjusted the line positions during this layout to avoid widows
1463 // then we need to ignore the possibility of having a new widows situation.
1464 // Otherwise, we risk leaving empty containers which is against the block fragmentation principles.
akling@apple.com827be9c2013-10-29 02:58:43 +00001465 if (paginated && !style().hasAutoWidows() && !didBreakAtLineToAvoidWidow()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001466 // Check the line boxes to make sure we didn't create unacceptable widows.
1467 // However, we'll prioritize orphans - so nothing we do here should create
1468 // a new orphan.
1469
1470 RootInlineBox* lineBox = lastRootBox();
1471
1472 // Count from the end of the block backwards, to see how many hanging
1473 // lines we have.
1474 RootInlineBox* firstLineInBlock = firstRootBox();
1475 int numLinesHanging = 1;
1476 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1477 ++numLinesHanging;
1478 lineBox = lineBox->prevRootBox();
1479 }
1480
1481 // If there were no breaks in the block, we didn't create any widows.
jchaffraix@webkit.org0f225142013-01-28 22:28:21 +00001482 if (!lineBox || !lineBox->isFirstAfterPageBreak() || lineBox == firstLineInBlock)
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001483 return;
1484
akling@apple.com827be9c2013-10-29 02:58:43 +00001485 if (numLinesHanging < style().widows()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001486 // We have detected a widow. Now we need to work out how many
1487 // lines there are on the previous page, and how many we need
1488 // to steal.
akling@apple.com827be9c2013-10-29 02:58:43 +00001489 int numLinesNeeded = style().widows() - numLinesHanging;
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001490 RootInlineBox* currentFirstLineOfNewPage = lineBox;
1491
1492 // Count the number of lines in the previous page.
1493 lineBox = lineBox->prevRootBox();
1494 int numLinesInPreviousPage = 1;
1495 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1496 ++numLinesInPreviousPage;
1497 lineBox = lineBox->prevRootBox();
1498 }
1499
1500 // If there was an explicit value for orphans, respect that. If not, we still
1501 // shouldn't create a situation where we make an orphan bigger than the initial value.
1502 // This means that setting widows implies we also care about orphans, but given
1503 // the specification says the initial orphan value is non-zero, this is ok. The
1504 // author is always free to set orphans explicitly as well.
akling@apple.com827be9c2013-10-29 02:58:43 +00001505 int orphans = style().hasAutoOrphans() ? style().initialOrphans() : style().orphans();
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001506 int numLinesAvailable = numLinesInPreviousPage - orphans;
1507 if (numLinesAvailable <= 0)
1508 return;
1509
andersca@apple.com86298632013-11-10 19:32:33 +00001510 int numLinesToTake = std::min(numLinesAvailable, numLinesNeeded);
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001511 // Wind back from our first widowed line.
1512 lineBox = currentFirstLineOfNewPage;
1513 for (int i = 0; i < numLinesToTake; ++i)
1514 lineBox = lineBox->prevRootBox();
1515
1516 // We now want to break at this line. Remember for next layout and trigger relayout.
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001517 setBreakAtLineToAvoidWidow(lineCount(lineBox));
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001518 markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), lineBox->lineBottomWithLeading(), lineBox);
1519 }
1520 }
abucur@adobe.comfc497132013-10-04 08:49:21 +00001521
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001522 clearDidBreakAtLineToAvoidWidow();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001523}
eric@webkit.org060caf62011-05-03 22:11:39 +00001524
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001525void RenderBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001526{
1527 if (layoutState.endLine()) {
1528 if (layoutState.endLineMatched()) {
akling@apple.com691cf5c2013-08-24 16:33:15 +00001529 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eric@webkit.org060caf62011-05-03 22:11:39 +00001530 // Attach all the remaining lines, and then adjust their y-positions as needed.
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001531 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001532 for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001533 line->attachLine();
1534 if (paginated) {
1535 delta -= line->paginationStrut();
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001536 bool overflowsRegion;
1537 adjustLinePositionForPagination(line, delta, overflowsRegion, layoutState.flowThread());
eric@webkit.org060caf62011-05-03 22:11:39 +00001538 }
1539 if (delta) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001540 layoutState.updateRepaintRangeFromBox(line, delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001541 line->adjustBlockDirectionPosition(delta);
1542 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001543 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001544 updateRegionForLine(line);
eric@webkit.org060caf62011-05-03 22:11:39 +00001545 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +00001546 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1547 RenderBox* floatingBox = *it;
weinig@apple.com12840dc2013-10-22 23:59:08 +00001548 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001549 ASSERT(!floatingObject->originatingLine());
1550 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001551 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox) + delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001552 positionNewFloats();
1553 }
1554 }
1555 }
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001556 setLogicalHeight(lastRootBox()->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001557 } else {
1558 // Delete all the remaining lines.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001559 deleteLineRange(layoutState, layoutState.endLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001560 }
1561 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001562
1563 if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001564 // In case we have a float on the last line, it might not be positioned up to now.
1565 // This has to be done before adding in the bottom border/padding, or the float will
1566 // include the padding incorrectly. -dwh
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001567 if (layoutState.checkForFloatsFromLastLine()) {
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001568 LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow();
1569 LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow();
akling@apple.comb5f24642013-11-06 04:47:12 +00001570 auto newLineBox = std::make_unique<TrailingFloatsRootInlineBox>(*this);
1571 auto trailingFloatsLineBox = newLineBox.get();
aestes@apple.com13aae082016-01-02 08:03:08 +00001572 m_lineBoxes.appendLineBox(WTFMove(newLineBox));
eric@webkit.org060caf62011-05-03 22:11:39 +00001573 trailingFloatsLineBox->setConstructed();
1574 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
1575 VerticalPositionCache verticalPositionCache;
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001576 LayoutUnit blockLogicalHeight = logicalHeight();
hyatt@apple.coma8b5b822011-09-07 18:48:07 +00001577 trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache);
1578 trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight);
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001579 trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight));
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001580 LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight);
1581 LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight);
eric@webkit.org060caf62011-05-03 22:11:39 +00001582 trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom());
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001583 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001584 updateRegionForLine(trailingFloatsLineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001585 }
1586
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001587 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001588 auto it = floatingObjectSet.begin();
1589 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001590 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001591 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001592 ASSERT(lastFloatIterator != end);
1593 ++lastFloatIterator;
1594 it = lastFloatIterator;
1595 }
1596 for (; it != end; ++it)
darin@apple.com7cad7042013-09-24 05:53:55 +00001597 appendFloatingObjectToLastLine(it->get());
1598 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001599 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001600}
1601
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001602void RenderBlockFlow::repaintDirtyFloats(Vector<FloatWithRect>& floats)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001603{
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +00001604 size_t floatCount = floats.size();
eric@webkit.org060caf62011-05-03 22:11:39 +00001605 // Floats that did not have layout did not repaint when we laid them out. They would have
1606 // painted by now if they had moved, but if they stayed at (0, 0), they still need to be
1607 // painted.
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +00001608 for (size_t i = 0; i < floatCount; ++i) {
1609 if (!floats[i].everHadLayout) {
1610 RenderBox& box = floats[i].object;
weinig@apple.com12840dc2013-10-22 23:59:08 +00001611 if (!box.x() && !box.y() && box.checkForRepaintDuringLayout())
1612 box.repaint();
eric@webkit.org060caf62011-05-03 22:11:39 +00001613 }
1614 }
1615}
1616
antti@apple.com940f5872013-10-24 20:31:11 +00001617void RenderBlockFlow::layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom)
jamesr@google.com19548ad2010-04-02 23:21:35 +00001618{
antti@apple.comfea51992013-10-28 13:39:23 +00001619 ASSERT(!m_simpleLineLayout);
antti@apple.com940f5872013-10-24 20:31:11 +00001620
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001621 setLogicalHeight(borderAndPaddingBefore());
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001622
1623 // Lay out our hypothetical grid line as though it occurs at the top of the block.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001624 if (view().layoutState() && view().layoutState()->lineGrid() == this)
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001625 layoutLineGridBox();
mitz@apple.come1364202008-02-28 01:06:41 +00001626
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001627 RenderFlowThread* flowThread = flowThreadContainingBlock();
akling@apple.comee3c8df2013-11-06 08:09:44 +00001628 bool clearLinesForPagination = firstRootBox() && flowThread && !flowThread->hasRegions();
commit-queue@webkit.org93cdd632012-12-07 00:33:56 +00001629
hyatt0c3a9862004-02-23 21:26:26 +00001630 // Figure out if we should clear out our line boxes.
1631 // FIXME: Handle resize eventually!
akling@apple.comee3c8df2013-11-06 08:09:44 +00001632 bool isFullLayout = !firstRootBox() || selfNeedsLayout() || relayoutChildren || clearLinesForPagination;
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001633 LineLayoutState layoutState(*this, isFullLayout, repaintLogicalTop, repaintLogicalBottom, flowThread);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001634
1635 if (isFullLayout)
akling@apple.com31dd4f42013-10-30 22:27:59 +00001636 lineBoxes().deleteLineBoxes();
mitz@apple.come1364202008-02-28 01:06:41 +00001637
commit-queue@webkit.org07797312013-02-22 18:58:19 +00001638 // Text truncation kicks in in two cases:
1639 // 1) If your overflow isn't visible and your text-overflow-mode isn't clip.
1640 // 2) If you're an anonymous block with a block parent that satisfies #1.
hyatted77ad82004-06-15 07:21:23 +00001641 // 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 +00001642 // difficult to figure out in general (especially in the middle of doing layout), so we only handle the
1643 // simple case of an anonymous block truncating when it's parent is clipped.
akling@apple.com827be9c2013-10-29 02:58:43 +00001644 bool hasTextOverflow = (style().textOverflow() && hasOverflowClip())
1645 || (isAnonymousBlock() && parent() && parent()->isRenderBlock() && parent()->style().textOverflow() && parent()->hasOverflowClip());
mitz@apple.come1364202008-02-28 01:06:41 +00001646
hyatted77ad82004-06-15 07:21:23 +00001647 // Walk all the lines and delete our ellipsis line boxes if they exist.
1648 if (hasTextOverflow)
1649 deleteEllipsisLineBoxes();
1650
hyattffe78712003-02-11 01:59:29 +00001651 if (firstChild()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001652 // In full layout mode, clear the line boxes of children upfront. Otherwise,
1653 // siblings can run into stale root lineboxes during layout. Then layout
1654 // the replaced elements later. In partial layout mode, line boxes are not
1655 // deleted and only dirtied. In that case, we can layout the replaced
1656 // elements at the same time.
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001657 bool hasInlineChild = false;
inferno@chromium.org13563122012-08-16 20:50:05 +00001658 Vector<RenderBox*> replacedChildren;
weinig@apple.com12840dc2013-10-22 23:59:08 +00001659 for (InlineWalker walker(*this); !walker.atEnd(); walker.advance()) {
1660 RenderObject& o = *walker.current();
abucur@adobe.com33159da2013-08-13 07:44:32 +00001661
weinig@apple.com12840dc2013-10-22 23:59:08 +00001662 if (!hasInlineChild && o.isInline())
commit-queue@webkit.orgcf45df92010-09-14 13:25:06 +00001663 hasInlineChild = true;
1664
weinig@apple.com12840dc2013-10-22 23:59:08 +00001665 if (o.isReplaced() || o.isFloating() || o.isOutOfFlowPositioned()) {
cdumez@apple.com0abff8b2014-10-17 21:25:10 +00001666 RenderBox& box = downcast<RenderBox>(o);
eric@webkit.org060caf62011-05-03 22:11:39 +00001667
weinig@apple.com12840dc2013-10-22 23:59:08 +00001668 if (relayoutChildren || box.hasRelativeDimensions())
1669 box.setChildNeedsLayout(MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001670
zimmermann@webkit.orgac68af42011-06-15 08:02:37 +00001671 // 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 +00001672 if (relayoutChildren && box.needsPreferredWidthsRecalculation())
1673 box.setPreferredLogicalWidthsDirty(true, MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001674
weinig@apple.com12840dc2013-10-22 23:59:08 +00001675 if (box.isOutOfFlowPositioned())
1676 box.containingBlock()->insertPositionedObject(box);
1677 else if (box.isFloating())
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001678 layoutState.floats().append(FloatWithRect(box));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001679 else if (isFullLayout || box.needsLayout()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001680 // Replaced element.
weinig@apple.com12840dc2013-10-22 23:59:08 +00001681 box.dirtyLineBoxes(isFullLayout);
hyatt@apple.com21c60802015-04-01 18:10:32 +00001682 if (!o.isAnonymousInlineBlock()) {
1683 if (isFullLayout)
1684 replacedChildren.append(&box);
1685 else
1686 box.layoutIfNeeded();
1687 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001688 }
cdumez@apple.comf8022152014-10-15 00:29:51 +00001689 } else if (o.isTextOrLineBreak() || (is<RenderInline>(o) && !walker.atEndOfInline())) {
1690 if (is<RenderInline>(o))
1691 downcast<RenderInline>(o).updateAlwaysCreateLineBoxes(layoutState.isFullLayout());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001692 if (layoutState.isFullLayout() || o.selfNeedsLayout())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001693 dirtyLineBoxesForRenderer(o, layoutState.isFullLayout());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001694 o.clearNeedsLayout();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001695 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001696 }
1697
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +00001698 for (size_t i = 0; i < replacedChildren.size(); i++)
1699 replacedChildren[i]->layoutIfNeeded();
inferno@chromium.org13563122012-08-16 20:50:05 +00001700
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001701 layoutRunsAndFloats(layoutState, hasInlineChild);
kociendabb0c24b2001-08-24 14:24:40 +00001702 }
hyatt85586af2003-02-19 23:22:42 +00001703
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001704 // Expand the last line to accommodate Ruby and emphasis marks.
1705 int lastLineAnnotationsAdjustment = 0;
1706 if (lastRootBox()) {
andersca@apple.com86298632013-11-10 19:32:33 +00001707 LayoutUnit lowestAllowedPosition = std::max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
akling@apple.com827be9c2013-10-29 02:58:43 +00001708 if (!style().isFlippedLinesWritingMode())
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001709 lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition);
1710 else
1711 lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
hyatt@apple.com5e48ff52010-11-19 00:43:29 +00001712 }
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001713
1714 // Now do the handling of the bottom of the block, adding in our bottom border/padding and
1715 // determining the correct collapsed bottom margin information. This collapse is only necessary
1716 // if our last child was an anonymous inline block that might need to propagate margin information out to
1717 // us.
1718 LayoutUnit beforeEdge = borderAndPaddingBefore();
1719 LayoutUnit afterEdge = borderAndPaddingAfter() + scrollbarLogicalHeight() + lastLineAnnotationsAdjustment;
1720 if (lastRootBox() && lastRootBox()->hasAnonymousInlineBlock())
1721 handleAfterSideOfBlock(beforeEdge, afterEdge, layoutState.marginInfo());
1722 else
1723 setLogicalHeight(logicalHeight() + afterEdge);
kociendabb0c24b2001-08-24 14:24:40 +00001724
akling@apple.comee3c8df2013-11-06 08:09:44 +00001725 if (!firstRootBox() && hasLineIfEmpty())
hyatt@apple.com2a5eb212011-03-22 23:21:54 +00001726 setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
hyatted77ad82004-06-15 07:21:23 +00001727
1728 // See if we have any lines that spill out of our block. If we do, then we will possibly need to
1729 // truncate text.
1730 if (hasTextOverflow)
1731 checkLinesForTextOverflow();
kociendabb0c24b2001-08-24 14:24:40 +00001732}
1733
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001734void RenderBlockFlow::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat)
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001735{
1736 Vector<RenderBox*>* cleanLineFloats = line->floatsPtr();
1737 if (!cleanLineFloats)
1738 return;
stavila@adobe.comf4ef0972014-03-28 21:55:46 +00001739
1740 if (!floats.size()) {
1741 encounteredNewFloat = true;
1742 return;
1743 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001744
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +00001745 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1746 RenderBox* floatingBox = *it;
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001747 floatingBox->layoutIfNeeded();
bjonesbe@adobe.com562a50d2014-02-20 20:01:19 +00001748 LayoutSize newSize(floatingBox->width() + floatingBox->horizontalMarginExtent(), floatingBox->height() + floatingBox->verticalMarginExtent());
inferno@chromium.orga227be62013-02-11 08:06:45 +00001749 ASSERT_WITH_SECURITY_IMPLICATION(floatIndex < floats.size());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001750 if (&floats[floatIndex].object != floatingBox) {
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001751 encounteredNewFloat = true;
1752 return;
1753 }
hyatt@apple.comc2e15522014-09-03 19:26:38 +00001754
1755 // We have to reset the cap-height alignment done by the first-letter floats when initial-letter is set, so just always treat first-letter floats
1756 // as dirty.
1757 if (floats[floatIndex].rect.size() != newSize || (floatingBox->style().styleType() == FIRST_LETTER && floatingBox->style().initialLetterDrop() > 0)) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001758 LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x();
andersca@apple.com86298632013-11-10 19:32:33 +00001759 LayoutUnit floatHeight = isHorizontalWritingMode() ? std::max(floats[floatIndex].rect.height(), newSize.height()) : std::max(floats[floatIndex].rect.width(), newSize.width());
1760 floatHeight = std::min(floatHeight, LayoutUnit::max() - floatTop);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001761 line->markDirty();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001762 markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001763 floats[floatIndex].rect.setSize(newSize);
1764 dirtiedByFloat = true;
1765 }
1766 floatIndex++;
1767 }
1768}
1769
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001770RootInlineBox* RenderBlockFlow::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver)
hyatt0c3a9862004-02-23 21:26:26 +00001771{
1772 RootInlineBox* curr = 0;
1773 RootInlineBox* last = 0;
mitz@apple.come1364202008-02-28 01:06:41 +00001774
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001775 // FIXME: This entire float-checking block needs to be broken into a new function.
mitz@apple.com40547b32008-03-18 04:04:34 +00001776 bool dirtiedByFloat = false;
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001777 if (!layoutState.isFullLayout()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001778 // Paginate all of the clean lines.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001779 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001780 LayoutUnit paginationDelta = 0;
mitz@apple.com40547b32008-03-18 04:04:34 +00001781 size_t floatIndex = 0;
1782 for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001783 if (paginated) {
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001784 if (lineWidthForPaginatedLineChanged(curr, 0, layoutState.flowThread())) {
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001785 curr->markDirty();
1786 break;
1787 }
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001788 paginationDelta -= curr->paginationStrut();
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001789 bool overflowsRegion;
1790 adjustLinePositionForPagination(curr, paginationDelta, overflowsRegion, layoutState.flowThread());
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001791 if (paginationDelta) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001792 if (containsFloats() || !layoutState.floats().isEmpty()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001793 // 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 +00001794 layoutState.markForFullLayout();
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001795 break;
1796 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001797
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001798 layoutState.updateRepaintRangeFromBox(curr, paginationDelta);
hyatt@apple.com61bbedf2011-01-26 23:10:57 +00001799 curr->adjustBlockDirectionPosition(paginationDelta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001800 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001801 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001802 updateRegionForLine(curr);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001803 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001804
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001805 // If a new float has been inserted before this line or before its last known float, just do a full layout.
1806 bool encounteredNewFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001807 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001808 if (encounteredNewFloat)
1809 layoutState.markForFullLayout();
1810
1811 if (dirtiedByFloat || layoutState.isFullLayout())
mitz@apple.com40547b32008-03-18 04:04:34 +00001812 break;
1813 }
1814 // Check if a new float has been inserted after the last known float.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001815 if (!curr && floatIndex < layoutState.floats().size())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001816 layoutState.markForFullLayout();
mitz@apple.com40547b32008-03-18 04:04:34 +00001817 }
1818
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001819 if (layoutState.isFullLayout()) {
akling@apple.com31dd4f42013-10-30 22:27:59 +00001820 m_lineBoxes.deleteLineBoxTree();
igor.o@sisa.samsung.comf6a57df2013-04-15 21:25:35 +00001821 curr = 0;
1822
akling@apple.comee3c8df2013-11-06 08:09:44 +00001823 ASSERT(!firstRootBox() && !lastRootBox());
eseidel789896f2005-11-27 22:52:09 +00001824 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001825 if (curr) {
1826 // We have a dirty line.
mjs9f78dd92007-02-12 04:06:07 +00001827 if (RootInlineBox* prevRootBox = curr->prevRootBox()) {
hyatt0c3a9862004-02-23 21:26:26 +00001828 // We have a previous line.
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001829 if (!dirtiedByFloat && !curr->hasAnonymousInlineBlock() && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (is<RenderText>(*prevRootBox->lineBreakObj()) && prevRootBox->lineBreakPos() >= downcast<RenderText>(*prevRootBox->lineBreakObj()).textLength()))) {
mjs9f78dd92007-02-12 04:06:07 +00001830 // The previous line didn't break cleanly or broke at a newline
1831 // that has been deleted, so treat it as dirty too.
1832 curr = prevRootBox;
cdumez@apple.com35094bd2014-10-07 19:33:53 +00001833 }
hyatt0c3a9862004-02-23 21:26:26 +00001834 }
hyatt0c3a9862004-02-23 21:26:26 +00001835 }
hyatt0c3a9862004-02-23 21:26:26 +00001836 // If we have no dirty lines, then last is just the last root box.
1837 last = curr ? curr->prevRootBox() : lastRootBox();
1838 }
mitz@apple.come1364202008-02-28 01:06:41 +00001839
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001840 unsigned numCleanFloats = 0;
1841 if (!layoutState.floats().isEmpty()) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001842 LayoutUnit savedLogicalHeight = logicalHeight();
mitz@apple.com40547b32008-03-18 04:04:34 +00001843 // Restore floats from clean lines.
1844 RootInlineBox* line = firstRootBox();
1845 while (line != curr) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00001846 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +00001847 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1848 RenderBox* floatingBox = *it;
weinig@apple.com12840dc2013-10-22 23:59:08 +00001849 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001850 ASSERT(!floatingObject->originatingLine());
1851 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001852 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox));
mitz@apple.com40547b32008-03-18 04:04:34 +00001853 positionNewFloats();
weinig@apple.com12840dc2013-10-22 23:59:08 +00001854 ASSERT(&layoutState.floats()[numCleanFloats].object == floatingBox);
mitz@apple.com40547b32008-03-18 04:04:34 +00001855 numCleanFloats++;
1856 }
1857 }
1858 line = line->nextRootBox();
1859 }
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001860 setLogicalHeight(savedLogicalHeight);
mitz@apple.com40547b32008-03-18 04:04:34 +00001861 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001862 layoutState.setFloatIndex(numCleanFloats);
mitz@apple.com40547b32008-03-18 04:04:34 +00001863
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001864 layoutState.lineInfo().setFirstLine(!last);
1865 layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak());
mitz@apple.com1a301772008-03-11 18:30:36 +00001866
hyatt0c3a9862004-02-23 21:26:26 +00001867 if (last) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001868 setLogicalHeight(last->lineBottomWithLeading());
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001869 InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos());
1870 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
mitz@apple.com15035e62008-07-05 20:44:44 +00001871 resolver.setStatus(last->lineBreakBidiStatus());
darindde01502005-12-18 22:55:35 +00001872 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001873 TextDirection direction = style().direction();
1874 if (style().unicodeBidi() == Plaintext)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001875 determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(*this), 0));
akling@apple.com827be9c2013-10-29 02:58:43 +00001876 resolver.setStatus(BidiStatus(direction, isOverride(style().unicodeBidi())));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001877 InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(*this, &resolver), 0);
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001878 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
darindde01502005-12-18 22:55:35 +00001879 }
hyatt0c3a9862004-02-23 21:26:26 +00001880 return curr;
1881}
1882
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001883void RenderBlockFlow::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001884{
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001885 ASSERT(!layoutState.endLine());
1886 size_t floatIndex = layoutState.floatIndex();
hyatt0c3a9862004-02-23 21:26:26 +00001887 RootInlineBox* last = 0;
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001888 for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) {
1889 if (!curr->isDirty()) {
1890 bool encounteredNewFloat = false;
1891 bool dirtiedByFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001892 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001893 if (encounteredNewFloat)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001894 return;
hyatt04420ca2004-07-16 00:05:42 +00001895 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001896 if (curr->isDirty())
1897 last = 0;
1898 else if (!last)
1899 last = curr;
hyatt0c3a9862004-02-23 21:26:26 +00001900 }
mitz@apple.come1364202008-02-28 01:06:41 +00001901
hyatt0c3a9862004-02-23 21:26:26 +00001902 if (!last)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001903 return;
mitz@apple.come1364202008-02-28 01:06:41 +00001904
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001905 // At this point, |last| is the first line in a run of clean lines that ends with the last line
1906 // in the block.
1907
eseidel789896f2005-11-27 22:52:09 +00001908 RootInlineBox* prev = last->prevRootBox();
mitz@apple.com15035e62008-07-05 20:44:44 +00001909 cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos());
eseidel789896f2005-11-27 22:52:09 +00001910 cleanLineBidiStatus = prev->lineBreakBidiStatus();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001911 layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading());
mitz@apple.come1364202008-02-28 01:06:41 +00001912
hyatt0c3a9862004-02-23 21:26:26 +00001913 for (RootInlineBox* line = last; line; line = line->nextRootBox())
1914 line->extractLine(); // Disconnect all line boxes from their render objects while preserving
1915 // their connections to one another.
mitz@apple.come1364202008-02-28 01:06:41 +00001916
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001917 layoutState.setEndLine(last);
hyatt0c3a9862004-02-23 21:26:26 +00001918}
1919
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001920bool RenderBlockFlow::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001921{
1922 LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop();
1923
akling@apple.com691cf5c2013-08-24 16:33:15 +00001924 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001925 if (paginated && layoutState.flowThread()) {
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001926 // Check all lines from here to the end, and see if the hypothetical new position for the lines will result
1927 // in a different available line width.
1928 for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) {
1929 if (paginated) {
1930 // This isn't the real move we're going to do, so don't update the line box's pagination
1931 // strut yet.
1932 LayoutUnit oldPaginationStrut = lineBox->paginationStrut();
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001933 bool overflowsRegion;
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001934 lineDelta -= oldPaginationStrut;
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001935 adjustLinePositionForPagination(lineBox, lineDelta, overflowsRegion, layoutState.flowThread());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001936 lineBox->setPaginationStrut(oldPaginationStrut);
1937 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001938 if (lineWidthForPaginatedLineChanged(lineBox, lineDelta, layoutState.flowThread()))
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001939 return false;
1940 }
1941 }
1942
1943 if (!lineDelta || !m_floatingObjects)
1944 return true;
1945
1946 // 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 +00001947 LayoutUnit logicalTop = std::min(logicalHeight(), layoutState.endLineLogicalTop());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001948
1949 RootInlineBox* lastLine = layoutState.endLine();
1950 while (RootInlineBox* nextLine = lastLine->nextRootBox())
1951 lastLine = nextLine;
1952
leviw@chromium.org3957b452012-05-01 00:06:37 +00001953 LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + absoluteValue(lineDelta);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001954
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +00001955 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
1956 auto end = floatingObjectSet.end();
1957 for (auto it = floatingObjectSet.begin(); it != end; ++it) {
zalan@apple.com84ccfa12015-10-17 03:36:56 +00001958 const auto& floatingObject = *it->get();
commit-queue@webkit.org6ad70c22015-06-12 18:43:01 +00001959 if (logicalBottomForFloat(floatingObject) >= logicalTop && logicalBottomForFloat(floatingObject) < logicalBottom)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001960 return false;
1961 }
1962
1963 return true;
1964}
1965
weinig@apple.com31324fd2013-10-28 19:22:51 +00001966bool RenderBlockFlow::lineWidthForPaginatedLineChanged(RootInlineBox* rootBox, LayoutUnit lineDelta, RenderFlowThread* flowThread) const
1967{
1968 if (!flowThread)
1969 return false;
1970
1971 RenderRegion* currentRegion = regionAtBlockOffset(rootBox->lineTopWithLeading() + lineDelta);
1972 // Just bail if the region didn't change.
1973 if (rootBox->containingRegion() == currentRegion)
1974 return false;
1975 return rootBox->paginatedLineWidth() != availableLogicalWidthForContent(currentRegion);
1976}
1977
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001978bool RenderBlockFlow::matchedEndLine(LineLayoutState& layoutState, const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001979{
mitz@apple.com15035e62008-07-05 20:44:44 +00001980 if (resolver.position() == endLineStart) {
1981 if (resolver.status() != endLineStatus)
mitz@apple.com40547b32008-03-18 04:04:34 +00001982 return false;
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001983 return checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00001984 }
hyatt0c3a9862004-02-23 21:26:26 +00001985
mitz@apple.come1364202008-02-28 01:06:41 +00001986 // The first clean line doesn't match, but we can check a handful of following lines to try
1987 // to match back up.
cdumez@apple.com4bf983a2015-05-19 07:22:36 +00001988 static const int numLines = 8; // The # of lines we're willing to match against.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001989 RootInlineBox* originalEndLine = layoutState.endLine();
1990 RootInlineBox* line = originalEndLine;
mitz@apple.come1364202008-02-28 01:06:41 +00001991 for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) {
hyatt@apple.com9a79c622015-09-15 18:38:18 +00001992 if (line->lineBreakObj() == resolver.position().renderer() && line->lineBreakPos() == resolver.position().offset() && !line->hasAnonymousInlineBlock()) {
mitz@apple.come1364202008-02-28 01:06:41 +00001993 // We have a match.
mitz@apple.com15035e62008-07-05 20:44:44 +00001994 if (line->lineBreakBidiStatus() != resolver.status())
mitz@apple.come1364202008-02-28 01:06:41 +00001995 return false; // ...but the bidi state doesn't match.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001996
1997 bool matched = false;
mitz@apple.come1364202008-02-28 01:06:41 +00001998 RootInlineBox* result = line->nextRootBox();
hyatt@apple.com1fb7d582011-09-23 20:25:11 +00001999 layoutState.setEndLine(result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002000 if (result) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00002001 layoutState.setEndLineLogicalTop(line->lineBottomWithLeading());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002002 matched = checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00002003 }
2004
mitz@apple.come1364202008-02-28 01:06:41 +00002005 // Now delete the lines that we failed to sync.
akling@apple.com31dd4f42013-10-30 22:27:59 +00002006 deleteLineRange(layoutState, originalEndLine, result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00002007 return matched;
hyatt0c3a9862004-02-23 21:26:26 +00002008 }
2009 }
mitz@apple.come1364202008-02-28 01:06:41 +00002010
hyatt0c3a9862004-02-23 21:26:26 +00002011 return false;
2012}
2013
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002014bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj)
bdashccffb432007-07-13 11:51:40 +00002015{
2016 ASSERT(inlineObj->parent() == this);
2017
mitz@apple.com15035e62008-07-05 20:44:44 +00002018 InlineIterator it(this, inlineObj, 0);
rniwa@webkit.org40248422011-06-15 00:19:39 +00002019 // FIXME: We should pass correct value for WhitespacePosition.
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00002020 while (!it.atEnd() && !requiresLineBox(it))
mitz@apple.com1a301772008-03-11 18:30:36 +00002021 it.increment();
bdashccffb432007-07-13 11:51:40 +00002022
2023 return !it.atEnd();
2024}
2025
weinig@apple.com611b9292013-10-20 22:57:54 +00002026void RenderBlockFlow::addOverflowFromInlineChildren()
hyattb4b20872004-10-20 21:34:01 +00002027{
antti@apple.comfea51992013-10-28 13:39:23 +00002028 if (auto layout = simpleLineLayout()) {
antti@apple.com940f5872013-10-24 20:31:11 +00002029 ASSERT(!hasOverflowClip());
antti@apple.comfea51992013-10-28 13:39:23 +00002030 SimpleLineLayout::collectFlowOverflow(*this, *layout);
antti@apple.com940f5872013-10-24 20:31:11 +00002031 return;
2032 }
eae@chromium.org9717cd82012-11-07 18:33:44 +00002033 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit();
hyatt@apple.com592848f2010-12-06 20:03:43 +00002034 // 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 +00002035 if (hasOverflowClip() && !endPadding && element() && element()->isRootEditableElement() && style().isLeftToRightDirection())
hyatt@apple.com592848f2010-12-06 20:03:43 +00002036 endPadding = 1;
hyattb4b20872004-10-20 21:34:01 +00002037 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
hyatt@apple.com592848f2010-12-06 20:03:43 +00002038 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
abucur@adobe.com4c3580b2014-04-29 12:38:20 +00002039 RenderRegion* region = flowThreadContainingBlock() ? curr->containingRegion() : nullptr;
abucur@adobe.com6585d012013-09-04 08:26:41 +00002040 if (region)
2041 region->addLayoutOverflowForBox(this, curr->paddedLayoutOverflowRect(endPadding));
2042 if (!hasOverflowClip()) {
zalan@apple.comd423bcc2016-02-06 23:07:54 +00002043 LayoutRect childVisualOverflowRect = curr->visualOverflowRect(curr->lineTop(), curr->lineBottom());
2044 addVisualOverflow(childVisualOverflowRect);
abucur@adobe.com6585d012013-09-04 08:26:41 +00002045 if (region)
zalan@apple.comd423bcc2016-02-06 23:07:54 +00002046 region->addVisualOverflowForBox(this, childVisualOverflowRect);
abucur@adobe.com6585d012013-09-04 08:26:41 +00002047 }
hyattb4b20872004-10-20 21:34:01 +00002048 }
2049}
2050
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00002051void RenderBlockFlow::deleteEllipsisLineBoxes()
hyatted77ad82004-06-15 07:21:23 +00002052{
akling@apple.com827be9c2013-10-29 02:58:43 +00002053 ETextAlign textAlign = style().textAlign();
2054 bool ltr = style().isLeftToRightDirection();
zalan@apple.com64761fe2016-03-02 21:42:22 +00002055 IndentTextOrNot shouldIndentText = IndentText;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002056 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
2057 if (curr->hasEllipsisBox()) {
2058 curr->clearTruncation();
2059
2060 // Shift the line back where it belongs if we cannot accomodate an ellipsis.
zalan@apple.com64761fe2016-03-02 21:42:22 +00002061 float logicalLeft = logicalLeftOffsetForLine(curr->lineTop(), shouldIndentText);
2062 float availableLogicalWidth = logicalRightOffsetForLine(curr->lineTop(), DoNotIndentText) - logicalLeft;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002063 float totalLogicalWidth = curr->logicalWidth();
mario.prada@samsung.com79397522014-02-28 18:12:52 +00002064 updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002065
2066 if (ltr)
2067 curr->adjustLogicalPosition((logicalLeft - curr->logicalLeft()), 0);
2068 else
2069 curr->adjustLogicalPosition(-(curr->logicalLeft() - logicalLeft), 0);
2070 }
zalan@apple.com64761fe2016-03-02 21:42:22 +00002071 shouldIndentText = DoNotIndentText;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002072 }
hyatted77ad82004-06-15 07:21:23 +00002073}
2074
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00002075void RenderBlockFlow::checkLinesForTextOverflow()
hyatted77ad82004-06-15 07:21:23 +00002076{
2077 // Determine the width of the ellipsis using the current font.
darindbba2bb2007-01-11 12:23:49 +00002078 // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable"
antti@apple.comc54cbc92015-01-15 14:19:56 +00002079 const FontCascade& font = style().fontCascade();
mmaxfield@apple.come6da30e2015-07-25 03:51:06 +00002080 static NeverDestroyed<AtomicString> ellipsisStr(&horizontalEllipsis, 1);
antti@apple.comc54cbc92015-01-15 14:19:56 +00002081 const FontCascade& firstLineFont = firstLineStyle().fontCascade();
mmaxfield@apple.com21a4dcb2016-03-13 00:36:59 +00002082 float firstLineEllipsisWidth = firstLineFont.width(constructTextRun(&horizontalEllipsis, 1, firstLineStyle()));
2083 float ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(&horizontalEllipsis, 1, style()));
hyatted77ad82004-06-15 07:21:23 +00002084
2085 // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see
2086 // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and
2087 // check the left edge of the line box to see if it is less
2088 // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()"
akling@apple.com827be9c2013-10-29 02:58:43 +00002089 bool ltr = style().isLeftToRightDirection();
2090 ETextAlign textAlign = style().textAlign();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002091 bool firstLine = true;
hyatted77ad82004-06-15 07:21:23 +00002092 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
zalan@apple.com64761fe2016-03-02 21:42:22 +00002093 IndentTextOrNot shouldIndentText = firstLine ? IndentText : DoNotIndentText;
2094 LayoutUnit blockRightEdge = logicalRightOffsetForLine(curr->lineTop(), shouldIndentText);
2095 LayoutUnit blockLeftEdge = logicalLeftOffsetForLine(curr->lineTop(), shouldIndentText);
zalan@apple.combfa11952014-05-19 17:37:22 +00002096 LayoutUnit lineBoxEdge = ltr ? curr->x() + curr->logicalWidth() : curr->x();
dglazkov@chromium.org28434e62009-05-13 22:30:10 +00002097 if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) {
hyattf918d2d2004-06-15 07:24:11 +00002098 // 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 +00002099 // can be truncated. In order for truncation to be possible, the line must have sufficient space to
2100 // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis
2101 // space.
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002102 LayoutUnit width = firstLine ? firstLineEllipsisWidth : ellipsisWidth;
eae@chromium.orgee8613e2011-11-12 01:12:58 +00002103 LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002104 if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) {
2105 float totalLogicalWidth = curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width);
2106
akling@apple.comf294cf02013-07-17 18:46:39 +00002107 float logicalLeft = 0; // We are only interested in the delta from the base position.
zalan@apple.com64761fe2016-03-02 21:42:22 +00002108 float truncatedWidth = availableLogicalWidthForLine(curr->lineTop(), shouldIndentText);
mmaxfield@apple.come6da30e2015-07-25 03:51:06 +00002109 updateLogicalWidthForAlignment(textAlign, curr, nullptr, logicalLeft, totalLogicalWidth, truncatedWidth, 0);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002110 if (ltr)
2111 curr->adjustLogicalPosition(logicalLeft, 0);
2112 else
2113 curr->adjustLogicalPosition(-(truncatedWidth - (logicalLeft + totalLogicalWidth)), 0);
2114 }
hyatted77ad82004-06-15 07:21:23 +00002115 }
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00002116 firstLine = false;
hyatted77ad82004-06-15 07:21:23 +00002117 }
2118}
2119
zalan@apple.com48ea2832015-10-16 19:53:04 +00002120bool RenderBlockFlow::positionNewFloatOnLine(const FloatingObject& newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002121{
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002122 if (!positionNewFloats())
2123 return false;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002124
rniwa@webkit.org44424752011-04-14 00:58:40 +00002125 width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002126
hyatt@apple.comdd78df82011-09-27 22:11:41 +00002127 // We only connect floats to lines for pagination purposes if the floats occur at the start of
2128 // the line and the previous line had a hard break (so this line is either the first in the block
2129 // or follows a <br>).
zalan@apple.com48ea2832015-10-16 19:53:04 +00002130 if (!newFloat.paginationStrut() || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002131 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002132
hyatt@apple.com46c65b32011-08-09 19:13:45 +00002133 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
zalan@apple.com48ea2832015-10-16 19:53:04 +00002134 ASSERT(floatingObjectSet.last().get() == &newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002135
zalan@apple.com84ccfa12015-10-17 03:36:56 +00002136 LayoutUnit floatLogicalTop = logicalTopForFloat(newFloat);
zalan@apple.com48ea2832015-10-16 19:53:04 +00002137 LayoutUnit paginationStrut = newFloat.paginationStrut();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002138
hyatt@apple.com5950bd42011-09-27 20:39:57 +00002139 if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002140 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002141
darin@apple.com7cad7042013-09-24 05:53:55 +00002142 auto it = floatingObjectSet.end();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002143 --it; // Last float is newFloat, skip that one.
darin@apple.com7cad7042013-09-24 05:53:55 +00002144 auto begin = floatingObjectSet.begin();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002145 while (it != begin) {
2146 --it;
zalan@apple.com84ccfa12015-10-17 03:36:56 +00002147 auto& floatingObject = *it->get();
2148 if (&floatingObject == lastFloatFromPreviousLine)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002149 break;
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002150 if (logicalTopForFloat(floatingObject) == logicalHeight() + lineInfo.floatPaginationStrut()) {
zalan@apple.com84ccfa12015-10-17 03:36:56 +00002151 floatingObject.setPaginationStrut(paginationStrut + floatingObject.paginationStrut());
2152 RenderBox& floatBox = floatingObject.renderer();
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002153 setLogicalTopForChild(floatBox, logicalTopForChild(floatBox) + marginBeforeForChild(floatBox) + paginationStrut);
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00002154
zalan@apple.com84ccfa12015-10-17 03:36:56 +00002155 if (updateRegionRangeForBoxChild(floatBox))
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00002156 floatBox.setNeedsLayout(MarkOnlyThis);
cdumez@apple.come9437792014-10-08 23:33:43 +00002157 else if (is<RenderBlock>(floatBox))
2158 downcast<RenderBlock>(floatBox).setChildNeedsLayout(MarkOnlyThis);
weinig@apple.com12840dc2013-10-22 23:59:08 +00002159 floatBox.layoutIfNeeded();
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00002160
hyatt@apple.com46c65b32011-08-09 19:13:45 +00002161 // Save the old logical top before calling removePlacedObject which will set
2162 // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat.
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002163 LayoutUnit oldLogicalTop = logicalTopForFloat(floatingObject);
zalan@apple.com84ccfa12015-10-17 03:36:56 +00002164 m_floatingObjects->removePlacedObject(&floatingObject);
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00002165 setLogicalTopForFloat(floatingObject, oldLogicalTop + paginationStrut);
zalan@apple.com84ccfa12015-10-17 03:36:56 +00002166 m_floatingObjects->addPlacedObject(&floatingObject);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002167 }
2168 }
2169
hyatt@apple.comdd78df82011-09-27 22:11:41 +00002170 // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing
2171 // no content, then we don't want to improperly grow the height of the block.
2172 lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut);
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00002173 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00002174}
2175
zalan@apple.com4d97a002016-02-24 17:13:33 +00002176LayoutUnit RenderBlockFlow::startAlignedOffsetForLine(LayoutUnit position, IndentTextOrNot shouldIndentText)
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002177{
akling@apple.com827be9c2013-10-29 02:58:43 +00002178 ETextAlign textAlign = style().textAlign();
zalan@apple.com4d97a002016-02-24 17:13:33 +00002179 bool shouldApplyIndentText = false;
2180 switch (textAlign) {
2181 case LEFT:
2182 case WEBKIT_LEFT:
2183 shouldApplyIndentText = style().isLeftToRightDirection();
2184 break;
2185 case RIGHT:
2186 case WEBKIT_RIGHT:
2187 shouldApplyIndentText = !style().isLeftToRightDirection();
2188 break;
2189 case TASTART:
2190 shouldApplyIndentText = true;
2191 break;
2192 default:
2193 shouldApplyIndentText = false;
2194 }
hyatt@apple.coma5626692013-11-18 23:08:30 +00002195 // <rdar://problem/15427571>
2196 // https://bugs.webkit.org/show_bug.cgi?id=124522
2197 // This quirk is for legacy content that doesn't work properly with the center positioning scheme
2198 // being honored (e.g., epubs).
zalan@apple.com4d97a002016-02-24 17:13:33 +00002199 if (shouldApplyIndentText || document().settings()->useLegacyTextAlignPositionedElementBehavior()) // FIXME: Handle TAEND here
zalan@apple.com64761fe2016-03-02 21:42:22 +00002200 return startOffsetForLine(position, shouldIndentText);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002201
2202 // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here
robert@webkit.org82903f42012-08-28 19:18:40 +00002203 float totalLogicalWidth = 0;
zalan@apple.com64761fe2016-03-02 21:42:22 +00002204 float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), DoNotIndentText);
2205 float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), DoNotIndentText) - logicalLeft;
mario.prada@samsung.com79397522014-02-28 18:12:52 +00002206
2207 // FIXME: Bug 129311: We need to pass a valid RootInlineBox here, considering the bidi level used to construct the line.
2208 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
robert@webkit.org7861a102011-09-22 17:16:47 +00002209
akling@apple.com827be9c2013-10-29 02:58:43 +00002210 if (!style().isLeftToRightDirection())
robert@webkit.org82903f42012-08-28 19:18:40 +00002211 return logicalWidth() - logicalLeft;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00002212 return logicalLeft;
2213}
2214
abucur@adobe.comd40287b2013-10-08 17:33:05 +00002215void RenderBlockFlow::updateRegionForLine(RootInlineBox* lineBox) const
2216{
2217 ASSERT(lineBox);
akling@apple.combdf247b2014-01-13 22:33:08 +00002218
abucur@adobe.comc18af352014-05-14 06:33:48 +00002219 if (!hasRegionRangeInFlowThread())
akling@apple.combdf247b2014-01-13 22:33:08 +00002220 lineBox->clearContainingRegion();
abucur@adobe.comc18af352014-05-14 06:33:48 +00002221 else {
2222 if (auto containingRegion = regionAtBlockOffset(lineBox->lineTopWithLeading()))
2223 lineBox->setContainingRegion(*containingRegion);
2224 else
2225 lineBox->clearContainingRegion();
2226 }
abucur@adobe.comd40287b2013-10-08 17:33:05 +00002227
2228 RootInlineBox* prevLineBox = lineBox->prevRootBox();
2229 if (!prevLineBox)
2230 return;
2231
2232 // This check is more accurate than the one in |adjustLinePositionForPagination| because it takes into
2233 // account just the container changes between lines. The before mentioned function doesn't set the flag
2234 // correctly if the line is positioned at the top of the last fragment container.
2235 if (lineBox->containingRegion() != prevLineBox->containingRegion())
2236 lineBox->setIsFirstAfterPageBreak(true);
2237}
2238
hyatt@apple.com9a79c622015-09-15 18:38:18 +00002239void RenderBlockFlow::marginCollapseLinesFromStart(LineLayoutState& layoutState, RootInlineBox* stopLine)
2240{
2241 // We have to handle an anonymous inline block streak at the start of the block in order to make sure our own margins are
2242 // correct. We only have to do this if the children can propagate margins out to us.
2243 bool resetLogicalHeight = false;
2244 if (layoutState.marginInfo().canCollapseWithMarginBefore()) {
2245 RootInlineBox* startLine = firstRootBox();
2246 RootInlineBox* curr;
2247 for (curr = startLine; curr && curr->hasAnonymousInlineBlock() && layoutState.marginInfo().canCollapseWithMarginBefore(); curr = curr->nextRootBox()) {
2248 if (curr == stopLine)
2249 return;
2250 if (!resetLogicalHeight) {
2251 setLogicalHeight(borderAndPaddingBefore());
2252 resetLogicalHeight = true;
2253 }
2254 layoutBlockChild(*curr->anonymousInlineBlock(), layoutState.marginInfo(),
2255 layoutState.prevFloatBottomFromAnonymousInlineBlock(), layoutState.maxFloatBottomFromAnonymousInlineBlock());
2256 }
2257 }
2258
2259 // Now that we've handled the top of the block, if the stopLine isn't an anonymous block, then we're done.
2260 if (!stopLine->hasAnonymousInlineBlock())
2261 return;
2262
2263 // Re-run margin collapsing on the block sequence that stopLine is a part of.
2264 // First go backwards to get the entire sequence.
2265 RootInlineBox* prev = stopLine;
2266 for ( ; prev->hasAnonymousInlineBlock(); prev = prev->prevRootBox()) {
2267 };
2268
2269 // Update the block height to the correct state.
2270 setLogicalHeight(prev->lineBottomWithLeading());
2271
2272 // Now run margin collapsing on those lines.
2273 for (prev = prev->nextRootBox(); prev != stopLine; prev = prev->nextRootBox())
2274 layoutBlockChild(*prev->anonymousInlineBlock(), layoutState.marginInfo(), layoutState.prevFloatBottomFromAnonymousInlineBlock(), layoutState.maxFloatBottomFromAnonymousInlineBlock());
2275}
2276
hyattffe78712003-02-11 01:59:29 +00002277}