blob: 1a39de774a43b8ac3fc7a21e6f039a0cbc0e6d15 [file] [log] [blame]
darin55ae73e2007-05-11 15:47:28 +00001/*
kociendabb0c24b2001-08-24 14:24:40 +00002 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
mitz@apple.com86470c82011-01-27 01:39:27 +00003 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved.
eric@webkit.orgddbec0aa2010-01-06 01:13:11 +00004 * Copyright (C) 2010 Google Inc. All rights reserved.
commit-queue@webkit.org17761402013-04-17 18:48:56 +00005 * Copyright (C) 2013 ChangSeok Oh <shivamidow@gmail.com>
zoltan@webkit.org64be1222013-11-15 21:40:59 +00006 * Copyright (C) 2013 Adobe Systems Inc. All right reserved.
kociendabb0c24b2001-08-24 14:24:40 +00007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
ddkilzerc8eccec2007-09-26 02:29:57 +000020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
kociendabb0c24b2001-08-24 14:24:40 +000022 *
kociendabb0c24b2001-08-24 14:24:40 +000023 */
darinbe4c67d2005-12-19 19:53:12 +000024
mjsb64c50a2005-10-03 21:13:12 +000025#include "config.h"
darin36d11362006-04-11 16:30:21 +000026
weinig@apple.comcef4e1e2013-10-19 03:14:44 +000027#include "AXObjectCache.h"
mitz@apple.com4c1ff322009-07-13 00:54:12 +000028#include "BidiResolver.h"
zoltan@webkit.org64be1222013-11-15 21:40:59 +000029#include "BreakingContextInlineHeaders.h"
bjonesbe@adobe.com67478092013-09-09 22:18:17 +000030#include "FloatingObjects.h"
akling@apple.comd3ec5ef2013-11-07 03:30:11 +000031#include "InlineElementBox.h"
hyatt@apple.com71eeb442010-02-11 20:05:51 +000032#include "InlineIterator.h"
eseidel3a6d1322006-01-09 03:14:50 +000033#include "InlineTextBox.h"
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"
hyattd8048342006-05-31 01:48:18 +000041#include "RenderView.h"
ossy@webkit.org66d8c0a2014-02-05 11:42:35 +000042#include "SVGRootInlineBox.h"
hyatt@apple.comcc1737c2010-09-16 20:20:02 +000043#include "Settings.h"
antti@apple.com940f5872013-10-24 20:31:11 +000044#include "SimpleLineLayoutFunctions.h"
dbates@webkit.orgf6f05a92010-05-17 04:58:25 +000045#include "TrailingFloatsRootInlineBox.h"
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +000046#include "VerticalPositionCache.h"
slewis@apple.coma7615ca2008-07-12 05:51:33 +000047#include <wtf/RefCountedLeakCounter.h>
bolsinga@apple.com97e42c42008-11-15 04:47:20 +000048#include <wtf/StdLibExtras.h>
commit-queue@webkit.orgb3540512012-08-24 18:48:49 +000049
darinb9481ed2006-03-20 02:57:59 +000050namespace WebCore {
mjsfe301d72003-10-02 18:46:18 +000051
leviw@chromium.orge7812f32012-02-07 23:46:40 +000052static void determineDirectionality(TextDirection& dir, InlineIterator iter)
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000053{
54 while (!iter.atEnd()) {
55 if (iter.atParagraphSeparator())
56 return;
57 if (UChar current = iter.current()) {
darin@apple.com2eb5f4d2013-10-12 04:16:42 +000058 UCharDirection charDirection = u_charDirection(current);
59 if (charDirection == U_LEFT_TO_RIGHT) {
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000060 dir = LTR;
61 return;
62 }
darin@apple.com2eb5f4d2013-10-12 04:16:42 +000063 if (charDirection == U_RIGHT_TO_LEFT || charDirection == U_RIGHT_TO_LEFT_ARABIC) {
leviw@chromium.org7781b6a2011-06-27 22:01:38 +000064 dir = RTL;
65 return;
66 }
67 }
68 iter.increment();
69 }
70}
71
zoltan@webkit.org64be1222013-11-15 21:40:59 +000072inline BidiRun* createRun(int start, int end, RenderObject* obj, InlineBidiResolver& resolver)
eric@webkit.org5bee2942011-04-08 02:12:31 +000073{
akling@apple.com7506fda2013-11-07 10:12:36 +000074 ASSERT(obj);
75 return new BidiRun(start, end, *obj, resolver.context(), resolver.dir());
eric@webkit.org5bee2942011-04-08 02:12:31 +000076}
77
bjonesbe@adobe.com24199752013-10-08 23:20:42 +000078void RenderBlockFlow::appendRunsForObject(BidiRunList<BidiRun>& runs, int start, int end, RenderObject* obj, InlineBidiResolver& resolver)
hyatt33f8d492002-11-12 21:44:52 +000079{
leviw@chromium.orgd8df17d2012-05-24 21:47:47 +000080 if (start > end || shouldSkipCreatingRunsForObject(obj))
hyatteb003b82002-11-15 22:35:10 +000081 return;
hyatt85586af2003-02-19 23:22:42 +000082
hyatt@apple.comb3466af2009-06-13 06:04:40 +000083 LineMidpointState& lineMidpointState = resolver.midpointState();
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000084 bool haveNextMidpoint = (lineMidpointState.currentMidpoint() < lineMidpointState.numMidpoints());
mitz@apple.com15035e62008-07-05 20:44:44 +000085 InlineIterator nextMidpoint;
hyatt85586af2003-02-19 23:22:42 +000086 if (haveNextMidpoint)
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000087 nextMidpoint = lineMidpointState.midpoints()[lineMidpointState.currentMidpoint()];
88 if (lineMidpointState.betweenMidpoints()) {
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +000089 if (!(haveNextMidpoint && nextMidpoint.renderer() == obj))
hyatt33f8d492002-11-12 21:44:52 +000090 return;
eric@webkit.org060caf62011-05-03 22:11:39 +000091 // This is a new start point. Stop ignoring objects and
hyatt33f8d492002-11-12 21:44:52 +000092 // adjust our start.
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000093 lineMidpointState.setBetweenMidpoints(false);
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +000094 start = nextMidpoint.offset();
zoltan@webkit.org7585ad52014-01-21 21:33:22 +000095 lineMidpointState.incrementCurrentMidpoint();
hyatt33f8d492002-11-12 21:44:52 +000096 if (start < end)
eric@webkit.org5bee2942011-04-08 02:12:31 +000097 return appendRunsForObject(runs, start, end, obj, resolver);
mitz@apple.com15035e62008-07-05 20:44:44 +000098 } else {
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +000099 if (!haveNextMidpoint || (obj != nextMidpoint.renderer())) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000100 runs.addRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000101 return;
102 }
mitz@apple.com15035e62008-07-05 20:44:44 +0000103
hyatt78b85132004-03-29 20:07:45 +0000104 // An end midpoint has been encountered within our object. We
hyatt33f8d492002-11-12 21:44:52 +0000105 // need to go ahead and append a run with our endpoint.
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +0000106 if (static_cast<int>(nextMidpoint.offset() + 1) <= end) {
zoltan@webkit.org7585ad52014-01-21 21:33:22 +0000107 lineMidpointState.setBetweenMidpoints(true);
108 lineMidpointState.incrementCurrentMidpoint();
mmaxfield@apple.com0682d512014-03-25 20:15:14 +0000109 // The end of the line is before the object we're inspecting. Skip everything and return
110 if (nextMidpoint.refersToEndOfPreviousNode())
111 return;
112 if (static_cast<int>(nextMidpoint.offset() + 1) > start)
113 runs.addRun(createRun(start, nextMidpoint.offset() + 1, obj, resolver));
114 appendRunsForObject(runs, nextMidpoint.offset() + 1, end, obj, resolver);
mitz@apple.com15035e62008-07-05 20:44:44 +0000115 } else
eric@webkit.org5bee2942011-04-08 02:12:31 +0000116 runs.addRun(createRun(start, end, obj, resolver));
hyatt33f8d492002-11-12 21:44:52 +0000117 }
118}
119
akling@apple.comb5f24642013-11-06 04:47:12 +0000120std::unique_ptr<RootInlineBox> RenderBlockFlow::createRootInlineBox()
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000121{
akling@apple.comb5f24642013-11-06 04:47:12 +0000122 return std::make_unique<RootInlineBox>(*this);
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000123}
124
125RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox()
126{
akling@apple.comb5f24642013-11-06 04:47:12 +0000127 auto newRootBox = createRootInlineBox();
128 RootInlineBox* rootBox = newRootBox.get();
dbates@webkit.org0cefe4f2014-07-03 22:13:54 +0000129 m_lineBoxes.appendLineBox(WTF::move(newRootBox));
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000130
akling@apple.comee3c8df2013-11-06 08:09:44 +0000131 if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && firstRootBox() == rootBox) {
weinig@apple.comcef4e1e2013-10-19 03:14:44 +0000132 if (AXObjectCache* cache = document().existingAXObjectCache())
133 cache->recomputeIsIgnored(this);
134 }
135
136 return rootBox;
137}
138
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000139static inline InlineBox* createInlineBoxForRenderer(RenderObject* renderer, bool isRootLineBox, bool isOnlyRun = false)
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000140{
141 if (isRootLineBox)
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000142 return downcast<RenderBlockFlow>(*renderer).createAndAppendRootInlineBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000143
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000144 if (is<RenderText>(*renderer))
145 return downcast<RenderText>(*renderer).createInlineTextBox();
eric@webkit.org060caf62011-05-03 22:11:39 +0000146
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000147 if (is<RenderBox>(*renderer)) {
akling@apple.comb5f24642013-11-06 04:47:12 +0000148 // FIXME: This is terrible. This branch returns an *owned* pointer!
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000149 return downcast<RenderBox>(*renderer).createInlineBox().release();
akling@apple.comb5f24642013-11-06 04:47:12 +0000150 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000151
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000152 if (is<RenderLineBreak>(*renderer)) {
akling@apple.comb5f24642013-11-06 04:47:12 +0000153 // FIXME: This is terrible. This branch returns an *owned* pointer!
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000154 auto inlineBox = downcast<RenderLineBreak>(*renderer).createInlineBox().release();
antti@apple.com9d8157e2013-09-17 15:13:37 +0000155 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
156 // (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 +0000157 inlineBox->setBehavesLikeText(isOnlyRun || renderer->document().inNoQuirksMode() || renderer->isLineBreakOpportunity());
antti@apple.com9d8157e2013-09-17 15:13:37 +0000158 return inlineBox;
159 }
160
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000161 return downcast<RenderInline>(*renderer).createAndAppendInlineFlowBox();
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000162}
163
weinig@apple.com12840dc2013-10-22 23:59:08 +0000164static inline void dirtyLineBoxesForRenderer(RenderObject& renderer, bool fullLayout)
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000165{
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000166 if (is<RenderText>(renderer)) {
167 RenderText& renderText = downcast<RenderText>(renderer);
esprehn@chromium.org7745ffb2013-02-19 21:51:19 +0000168 updateCounterIfNeeded(renderText);
weinig@apple.com12840dc2013-10-22 23:59:08 +0000169 renderText.dirtyLineBoxes(fullLayout);
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000170 } else if (is<RenderLineBreak>(renderer))
171 downcast<RenderLineBreak>(renderer).dirtyLineBoxes(fullLayout);
antti@apple.com9d8157e2013-09-17 15:13:37 +0000172 else
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000173 downcast<RenderInline>(renderer).dirtyLineBoxes(fullLayout);
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000174}
175
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000176static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox)
177{
178 do {
179 if (parentBox->isConstructed() || parentBox->nextOnLine())
180 return true;
181 parentBox = parentBox->parent();
182 } while (parentBox);
183 return false;
184}
185
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000186InlineFlowBox* RenderBlockFlow::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox)
hyattffe78712003-02-11 01:59:29 +0000187{
188 // See if we have an unconstructed line box for this object that is also
189 // the last item on the line.
hyatt1d5d87b2007-04-24 04:55:54 +0000190 unsigned lineDepth = 1;
hyatt1d5d87b2007-04-24 04:55:54 +0000191 InlineFlowBox* parentBox = 0;
192 InlineFlowBox* result = 0;
akling@apple.com827be9c2013-10-29 02:58:43 +0000193 bool hasDefaultLineBoxContain = style().lineBoxContain() == RenderStyle::initialLineBoxContain();
hyatt1d5d87b2007-04-24 04:55:54 +0000194 do {
inferno@chromium.org14b04142013-02-04 18:43:03 +0000195 ASSERT_WITH_SECURITY_IMPLICATION(obj->isRenderInline() || obj == this);
eric@webkit.org060caf62011-05-03 22:11:39 +0000196
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000197 RenderInline* inlineFlow = (obj != this) ? toRenderInline(obj) : 0;
198
hyatt1d5d87b2007-04-24 04:55:54 +0000199 // Get the last box we made for this render object.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000200 parentBox = inlineFlow ? inlineFlow->lastLineBox() : toRenderBlockFlow(obj)->lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000201
xji@chromium.orgb0ad6eb822011-02-01 20:02:06 +0000202 // If this box or its ancestor is constructed then it is from a previous line, and we need
203 // 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 +0000204 // something following it on the line, then we know we have to make a new box
205 // as well. In this situation our inline has actually been split in two on
206 // the same line (this can happen with very fancy language mixtures).
207 bool constructedNewBox = false;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000208 bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes();
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000209 bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox);
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000210 if (allowedToConstructNewBox && !canUseExistingParentBox) {
hyatt1d5d87b2007-04-24 04:55:54 +0000211 // We need to make a new box for this render object. Once
212 // made, we need to place it at the end of the current line.
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000213 InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this);
inferno@chromium.org14b04142013-02-04 18:43:03 +0000214 ASSERT_WITH_SECURITY_IMPLICATION(newBox->isInlineFlowBox());
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000215 parentBox = toInlineFlowBox(newBox);
antti@apple.comb0608f62013-09-28 18:30:16 +0000216 parentBox->setIsFirstLine(lineInfo.isFirstLine());
hyatt@apple.com2a5eb212011-03-22 23:21:54 +0000217 parentBox->setIsHorizontal(isHorizontalWritingMode());
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000218 if (!hasDefaultLineBoxContain)
219 parentBox->clearDescendantsHaveSameLineHeightAndBaseline();
hyatt1d5d87b2007-04-24 04:55:54 +0000220 constructedNewBox = true;
221 }
mitz@apple.come1364202008-02-28 01:06:41 +0000222
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000223 if (constructedNewBox || canUseExistingParentBox) {
224 if (!result)
225 result = parentBox;
hyatt1d5d87b2007-04-24 04:55:54 +0000226
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000227 // If we have hit the block itself, then |box| represents the root
228 // inline box for the line, and it doesn't have to be appended to any parent
229 // inline.
230 if (childBox)
231 parentBox->addToLine(childBox);
mitz@apple.come1364202008-02-28 01:06:41 +0000232
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000233 if (!constructedNewBox || obj == this)
234 break;
mitz@apple.come1364202008-02-28 01:06:41 +0000235
eric@webkit.org060caf62011-05-03 22:11:39 +0000236 childBox = parentBox;
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000237 }
mitz@apple.come1364202008-02-28 01:06:41 +0000238
hyatt1d5d87b2007-04-24 04:55:54 +0000239 // If we've exceeded our line depth, then jump straight to the root and skip all the remaining
240 // intermediate inline flows.
241 obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent();
hyattffe78712003-02-11 01:59:29 +0000242
hyatt1d5d87b2007-04-24 04:55:54 +0000243 } while (true);
244
245 return result;
hyattffe78712003-02-11 01:59:29 +0000246}
247
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000248template <typename CharacterType>
249static inline bool endsWithASCIISpaces(const CharacterType* characters, unsigned pos, unsigned end)
250{
251 while (isASCIISpace(characters[pos])) {
252 pos++;
253 if (pos >= end)
254 return true;
255 }
256 return false;
257}
258
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000259static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns)
hyattffe78712003-02-11 01:59:29 +0000260{
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000261 BidiRun* run = bidiRuns.logicallyLastRun();
262 if (!run)
263 return true;
msaboff@apple.com776c286c72012-10-15 16:56:29 +0000264 unsigned pos = run->stop();
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();
yael.aharon@nokia.com15c605d2011-04-14 05:35:54 +0000285 for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) {
hyattffe78712003-02-11 01:59:29 +0000286 // Create a box for our object.
robert@webkit.org8cbab142011-12-30 20:58:29 +0000287 bool isOnlyRun = (runCount == 1);
akling@apple.com7506fda2013-11-07 10:12:36 +0000288 if (runCount == 2 && !r->renderer().isListMarker())
289 isOnlyRun = (!style().isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->renderer().isListMarker();
mitz@apple.come1364202008-02-28 01:06:41 +0000290
robert@webkit.org56e5a9f2012-02-17 21:10:42 +0000291 if (lineInfo.isEmpty())
292 continue;
293
akling@apple.com7506fda2013-11-07 10:12:36 +0000294 InlineBox* box = createInlineBoxForRenderer(&r->renderer(), false, isOnlyRun);
295 r->setBox(*box);
hyattffe78712003-02-11 01:59:29 +0000296
akling@apple.com0b8172b72013-08-31 18:34:23 +0000297 if (!rootHasSelectedChildren && box->renderer().selectionState() != RenderObject::SelectionNone)
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000298 rootHasSelectedChildren = true;
299
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000300 // If we have no parent box yet, or if the run is not simply a sibling,
301 // then we need to construct inline boxes as necessary to properly enclose the
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000302 // run's inline box. Segments can only be siblings at the root level, as
303 // they are positioned separately.
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000304 if (!parentBox || &parentBox->renderer() != r->renderer().parent()) {
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000305 // Create new inline boxes all the way back to the appropriate insertion point.
bjonesbe@adobe.comfb6ceac2014-04-15 00:27:13 +0000306 parentBox = createLineBoxes(r->renderer().parent(), lineInfo, box);
307 } else {
hyatt@apple.com7d4066a2011-03-29 17:56:09 +0000308 // Append the inline box to this line.
309 parentBox->addToLine(box);
310 }
mitz@apple.com576e84e2008-04-24 19:09:48 +0000311
akling@apple.com7506fda2013-11-07 10:12:36 +0000312 bool visuallyOrdered = r->renderer().style().rtlOrdering() == VisualOrder;
xji@chromium.org6b0c0172011-02-14 19:21:12 +0000313 box->setBidiLevel(r->level());
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000314
315 if (box->isInlineTextBox()) {
jchaffraix@webkit.org8f1781d2011-06-24 21:22:54 +0000316 InlineTextBox* text = toInlineTextBox(box);
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000317 text->setStart(r->m_start);
318 text->setLen(r->m_stop - r->m_start);
rniwa@webkit.org296fcae2012-03-29 09:48:42 +0000319 text->setDirOverride(r->dirOverride(visuallyOrdered));
mitz@apple.comb2107652010-06-21 16:54:52 +0000320 if (r->m_hasHyphen)
321 text->setHasHyphen(true);
hyatt0c3a9862004-02-23 21:26:26 +0000322 }
hyattffe78712003-02-11 01:59:29 +0000323 }
324
325 // We should have a root inline box. It should be unconstructed and
326 // be the last continuation of our line list.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000327 ASSERT(lastRootBox() && !lastRootBox()->isConstructed());
hyattffe78712003-02-11 01:59:29 +0000328
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000329 // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box
330 // from the bidi runs walk above has a selection state.
331 if (rootHasSelectedChildren)
akling@apple.comee3c8df2013-11-06 08:09:44 +0000332 lastRootBox()->root().setHasSelectedChildren(true);
inferno@chromium.orge29694f2010-10-07 22:00:02 +0000333
hyattffe78712003-02-11 01:59:29 +0000334 // Set bits on our inline flow boxes that indicate which sides should
335 // paint borders/margins/padding. This knowledge will ultimately be used when
336 // we determine the horizontal positions and widths of all the inline boxes on
337 // the line.
akling@apple.com7506fda2013-11-07 10:12:36 +0000338 bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->renderer().isText() ? !reachedEndOfTextRenderer(bidiRuns) : true;
339 lastRootBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, &bidiRuns.logicallyLastRun()->renderer());
hyattffe78712003-02-11 01:59:29 +0000340
341 // Now mark the line boxes as being constructed.
akling@apple.comee3c8df2013-11-06 08:09:44 +0000342 lastRootBox()->setConstructed();
hyattffe78712003-02-11 01:59:29 +0000343
344 // Return the last line.
hyatt0c3a9862004-02-23 21:26:26 +0000345 return lastRootBox();
hyattffe78712003-02-11 01:59:29 +0000346}
347
weinig@apple.com6b4a24142014-01-05 00:28:39 +0000348ETextAlign RenderBlockFlow::textAlignmentForLine(bool endsWithSoftBreak) const
mitz@apple.com390fa322011-02-24 23:07:06 +0000349{
akling@apple.com827be9c2013-10-29 02:58:43 +0000350 ETextAlign alignment = style().textAlign();
zoltan@webkit.orgcb4f0e42014-08-13 18:00:27 +0000351#if ENABLE(CSS3_TEXT)
352 TextJustify textJustify = style().textJustify();
zoltan@webkit.org14989c32014-08-14 21:36:40 +0000353 if (alignment == JUSTIFY && textJustify == TextJustifyNone)
zoltan@webkit.orgcb4f0e42014-08-13 18:00:27 +0000354 return style().direction() == LTR ? LEFT : RIGHT;
355#endif
356
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000357 if (endsWithSoftBreak)
358 return alignment;
mitz@apple.com390fa322011-02-24 23:07:06 +0000359
zoltan@webkit.org14989c32014-08-14 21:36:40 +0000360#if !ENABLE(CSS3_TEXT)
361 return (alignment == JUSTIFY) ? TASTART : alignment;
362#else
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000363 if (alignment != JUSTIFY)
364 return alignment;
365
366 TextAlignLast alignmentLast = style().textAlignLast();
367 switch (alignmentLast) {
368 case TextAlignLastStart:
369 return TASTART;
370 case TextAlignLastEnd:
371 return TAEND;
372 case TextAlignLastLeft:
373 return LEFT;
374 case TextAlignLastRight:
375 return RIGHT;
376 case TextAlignLastCenter:
377 return CENTER;
378 case TextAlignLastJustify:
379 return JUSTIFY;
380 case TextAlignLastAuto:
zoltan@webkit.orgcb4f0e42014-08-13 18:00:27 +0000381 if (textJustify == TextJustifyDistribute)
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000382 return JUSTIFY;
383 return TASTART;
384 }
mitz@apple.com390fa322011-02-24 23:07:06 +0000385 return alignment;
zoltan@webkit.orgcb7f93f2014-01-17 20:33:04 +0000386#endif
mitz@apple.com390fa322011-02-24 23:07:06 +0000387}
388
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000389static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
390{
391 // The direction of the block should determine what happens with wide lines.
392 // In particular with RTL blocks, wide lines should still spill out to the left.
393 if (isLeftToRightDirection) {
394 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
andersca@apple.com86298632013-11-10 19:32:33 +0000395 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000396 return;
397 }
398
399 if (trailingSpaceRun)
akling@apple.com7506fda2013-11-07 10:12:36 +0000400 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000401 else if (totalLogicalWidth > availableLogicalWidth)
402 logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
403}
404
405static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
406{
407 // Wide lines spill out of the block based off direction.
408 // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
409 // side of the block.
410 if (isLeftToRightDirection) {
411 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000412 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
413 trailingSpaceRun->box()->setLogicalWidth(0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000414 }
415 if (totalLogicalWidth < availableLogicalWidth)
416 logicalLeft += availableLogicalWidth - totalLogicalWidth;
417 return;
418 }
419
420 if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
andersca@apple.com86298632013-11-10 19:32:33 +0000421 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
akling@apple.com7506fda2013-11-07 10:12:36 +0000422 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000423 } else
424 logicalLeft += availableLogicalWidth - totalLogicalWidth;
425}
426
427static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
428{
429 float trailingSpaceWidth = 0;
430 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000431 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
andersca@apple.com86298632013-11-10 19:32:33 +0000432 trailingSpaceWidth = std::min(trailingSpaceRun->box()->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2);
433 trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceWidth));
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000434 }
435 if (isLeftToRightDirection)
andersca@apple.com86298632013-11-10 19:32:33 +0000436 logicalLeft += std::max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0);
rniwa@webkit.orgcda6dbd2011-03-28 09:19:50 +0000437 else
438 logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
439}
440
weinig@apple.com12840dc2013-10-22 23:59:08 +0000441void RenderBlockFlow::setMarginsForRubyRun(BidiRun* run, RenderRubyRun& renderer, RenderObject* previousObject, const LineInfo& lineInfo)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000442{
443 int startOverhang;
444 int endOverhang;
445 RenderObject* nextObject = 0;
446 for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000447 if (!runWithNextObject->renderer().isOutOfFlowPositioned() && !runWithNextObject->box()->isLineBreak()) {
448 nextObject = &runWithNextObject->renderer();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000449 break;
450 }
451 }
akling@apple.com827be9c2013-10-29 02:58:43 +0000452 renderer.getOverhang(lineInfo.isFirstLine(), renderer.style().isLeftToRightDirection() ? previousObject : nextObject, renderer.style().isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000453 setMarginStartForChild(renderer, -startOverhang);
454 setMarginEndForChild(renderer, -endOverhang);
455}
456
457static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText* renderer, float xPos, const LineInfo& lineInfo,
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000458 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000459{
460 HashSet<const SimpleFontData*> fallbackFonts;
461 GlyphOverflow glyphOverflow;
antti@apple.comb0608f62013-09-28 18:30:16 +0000462
463 const Font& font = lineStyle(*renderer->parent(), lineInfo).font();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000464 // Always compute glyph overflow if the block's line-box-contain value is "glyphs".
465 if (lineBox->fitsToGlyphs()) {
466 // If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization
467 // will keep us from computing glyph bounds in nearly all cases.
468 bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading();
akling@apple.com7506fda2013-11-07 10:12:36 +0000469 int baselineShift = lineBox->verticalPositionForBox(run->box(), verticalPositionCache);
enrica@apple.com885c84d2012-10-10 05:48:51 +0000470 int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0;
471 int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0;
472 int boxAscent = font.fontMetrics().ascent() - baselineShift;
473 int boxDescent = font.fontMetrics().descent() + baselineShift;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000474 if (boxAscent > rootDescent || boxDescent > rootAscent)
475 glyphOverflow.computeBounds = true;
476 }
477
leviw@chromium.orgd32486e2012-03-16 10:52:56 +0000478 LayoutUnit hyphenWidth = 0;
akling@apple.com7506fda2013-11-07 10:12:36 +0000479 if (toInlineTextBox(run->box())->hasHyphen())
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000480 hyphenWidth = measureHyphenWidth(renderer, font, &fallbackFonts);
antti@apple.comb0608f62013-09-28 18:30:16 +0000481
enrica@apple.com885c84d2012-10-10 05:48:51 +0000482 float measuredWidth = 0;
483
enrica@apple.com885c84d2012-10-10 05:48:51 +0000484 bool kerningIsEnabled = font.typesettingFeatures() & Kerning;
leviw@chromium.orgd70f4cc2013-03-28 21:03:44 +0000485 bool canUseSimpleFontCodePath = renderer->canUseSimpleFontCodePath();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000486
487 // Since we don't cache glyph overflows, we need to re-measure the run if
488 // the style is linebox-contain: glyph.
489
leviw@chromium.orgd70f4cc2013-03-28 21:03:44 +0000490 if (!lineBox->fitsToGlyphs() && canUseSimpleFontCodePath) {
enrica@apple.com885c84d2012-10-10 05:48:51 +0000491 int lastEndOffset = run->m_start;
492 for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOffset < run->m_stop; ++i) {
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000493 WordMeasurement& wordMeasurement = wordMeasurements[i];
494 if (wordMeasurement.width <= 0 || wordMeasurement.startOffset == wordMeasurement.endOffset)
enrica@apple.com885c84d2012-10-10 05:48:51 +0000495 continue;
496 if (wordMeasurement.renderer != renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop)
497 continue;
498
499 lastEndOffset = wordMeasurement.endOffset;
500 if (kerningIsEnabled && lastEndOffset == run->m_stop) {
dino@apple.com7c50e7c2013-03-18 18:01:05 +0000501 int wordLength = lastEndOffset - wordMeasurement.startOffset;
rniwa@webkit.orgfe811f22013-06-07 17:59:01 +0000502 GlyphOverflow overflow;
503 measuredWidth += renderer->width(wordMeasurement.startOffset, wordLength, xPos + measuredWidth, lineInfo.isFirstLine(),
504 &wordMeasurement.fallbackFonts, &overflow);
dino@apple.comd0b89252013-05-10 18:20:28 +0000505 UChar c = renderer->characterAt(wordMeasurement.startOffset);
506 if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t'))
mmaxfield@apple.com516f09b2014-01-11 00:31:19 +0000507 measuredWidth += renderer->style().font().wordSpacing();
enrica@apple.com885c84d2012-10-10 05:48:51 +0000508 } else
509 measuredWidth += wordMeasurement.width;
510 if (!wordMeasurement.fallbackFonts.isEmpty()) {
511 HashSet<const SimpleFontData*>::const_iterator end = wordMeasurement.fallbackFonts.end();
512 for (HashSet<const SimpleFontData*>::const_iterator it = wordMeasurement.fallbackFonts.begin(); it != end; ++it)
513 fallbackFonts.add(*it);
514 }
515 }
516 if (measuredWidth && lastEndOffset != run->m_stop) {
517 // If we don't have enough cached data, we'll measure the run again.
518 measuredWidth = 0;
519 fallbackFonts.clear();
520 }
521 }
enrica@apple.com885c84d2012-10-10 05:48:51 +0000522
523 if (!measuredWidth)
524 measuredWidth = renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow);
525
akling@apple.com7506fda2013-11-07 10:12:36 +0000526 run->box()->setLogicalWidth(measuredWidth + hyphenWidth);
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000527 if (!fallbackFonts.isEmpty()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000528 ASSERT(run->box()->behavesLikeText());
andersca@apple.com86298632013-11-10 19:32:33 +0000529 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->box()), std::make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000530 ASSERT(it->value.first.isEmpty());
531 copyToVector(fallbackFonts, it->value.first);
akling@apple.com7506fda2013-11-07 10:12:36 +0000532 run->box()->parent()->clearDescendantsHaveSameLineHeightAndBaseline();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000533 }
mmaxfield@apple.comf28245e2014-05-20 00:45:52 +0000534
535 // Include text decoration visual overflow as part of the glyph overflow.
536 if (renderer->style().textDecorationsInEffect() != TextDecorationNone)
537 glyphOverflow.extendTo(visualOverflowForDecorations(run->box()->lineStyle(), toInlineTextBox(run->box())));
538
539 if (!glyphOverflow.isEmpty()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000540 ASSERT(run->box()->behavesLikeText());
andersca@apple.com86298632013-11-10 19:32:33 +0000541 GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->box()), std::make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000542 it->value.second = glyphOverflow;
akling@apple.com7506fda2013-11-07 10:12:36 +0000543 run->box()->clearKnownToHaveNoOverflow();
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000544 }
545}
546
547static inline void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth)
548{
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000549 if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth)
550 return;
551
552 size_t i = 0;
553 for (BidiRun* r = firstRun; r; r = r->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000554 if (!r->box() || r == trailingSpaceRun)
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000555 continue;
556
akling@apple.com7506fda2013-11-07 10:12:36 +0000557 if (r->renderer().isText()) {
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000558 unsigned opportunitiesInRun = expansionOpportunities[i++];
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000559
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000560 ASSERT(opportunitiesInRun <= expansionOpportunityCount);
561
562 // Only justify text if whitespace is collapsed.
akling@apple.com7506fda2013-11-07 10:12:36 +0000563 if (r->renderer().style().collapseWhiteSpace()) {
564 InlineTextBox* textBox = toInlineTextBox(r->box());
mmaxfield@apple.coma9f58d02014-10-02 22:25:50 +0000565 float expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000566 textBox->setExpansion(expansion);
567 totalLogicalWidth += expansion;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000568 }
mitz@apple.comc7a1a512011-05-08 16:27:31 +0000569 expansionOpportunityCount -= opportunitiesInRun;
570 if (!expansionOpportunityCount)
571 break;
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000572 }
573 }
574}
575
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000576void 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 +0000577{
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000578 TextDirection direction;
579 if (rootInlineBox && style().unicodeBidi() == Plaintext)
580 direction = rootInlineBox->direction();
581 else
582 direction = style().direction();
583
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000584 // Armed with the total width of the line (without justification),
585 // we now examine our text-align property in order to determine where to position the
586 // objects horizontally. The total width of the line can be increased if we end up
587 // justifying text.
588 switch (textAlign) {
589 case LEFT:
590 case WEBKIT_LEFT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000591 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000592 break;
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000593 case RIGHT:
594 case WEBKIT_RIGHT:
akling@apple.com827be9c2013-10-29 02:58:43 +0000595 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000596 break;
597 case CENTER:
598 case WEBKIT_CENTER:
akling@apple.com827be9c2013-10-29 02:58:43 +0000599 updateLogicalWidthForCenterAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
rniwa@webkit.orgaf7f7a42012-06-15 21:54:44 +0000600 break;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000601 case JUSTIFY:
602 adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
603 if (expansionOpportunityCount) {
604 if (trailingSpaceRun) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000605 totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
606 trailingSpaceRun->box()->setLogicalWidth(0);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000607 }
608 break;
609 }
joepeck@webkit.orgaa676ee52014-01-28 04:04:52 +0000610 FALLTHROUGH;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000611 case TASTART:
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000612 if (direction == LTR)
akling@apple.com827be9c2013-10-29 02:58:43 +0000613 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000614 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000615 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000616 break;
617 case TAEND:
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000618 if (direction == LTR)
akling@apple.com827be9c2013-10-29 02:58:43 +0000619 updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000620 else
akling@apple.com827be9c2013-10-29 02:58:43 +0000621 updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
robert@webkit.orgfc7763c2011-09-03 18:28:57 +0000622 break;
623 }
624}
625
weinig@apple.come9621c32014-01-04 20:53:51 +0000626static void updateLogicalInlinePositions(RenderBlockFlow& block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight)
commit-queue@webkit.orgab781b02013-04-03 01:32:24 +0000627{
weinig@apple.come9621c32014-01-04 20:53:51 +0000628 LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight);
zalan@apple.combfa11952014-05-19 17:37:22 +0000629 lineLogicalLeft = block.logicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
630 lineLogicalRight = block.logicalRightOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
robert@webkit.org0903cf52012-12-11 18:14:16 +0000631 availableLogicalWidth = lineLogicalRight - lineLogicalLeft;
632}
633
weinig@apple.come9621c32014-01-04 20:53:51 +0000634void 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 +0000635{
mitz@apple.com390fa322011-02-24 23:07:06 +0000636 ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
robert@webkit.org4f76df92012-07-03 17:41:35 +0000637
robert@webkit.org328ecd02012-08-09 21:12:44 +0000638 // 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
639 // box is only affected if it is the first child of its parent element."
commit-queue@webkit.orgab781b02013-04-03 01:32:24 +0000640 // CSS3 "text-indent", "-webkit-each-line" affects the first line of the block container as well as each line after a forced line break,
641 // but does not affect lines after a soft wrap break.
642 bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this);
643 bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox()->endsWithBreak();
akling@apple.com827be9c2013-10-29 02:58:43 +0000644 IndentTextOrNot shouldIndentText = requiresIndent(isFirstLine, isAfterHardLineBreak, style());
robert@webkit.org0903cf52012-12-11 18:14:16 +0000645 float lineLogicalLeft;
646 float lineLogicalRight;
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000647 float availableLogicalWidth;
weinig@apple.come9621c32014-01-04 20:53:51 +0000648 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000649 bool needsWordSpacing;
robert@webkit.org0903cf52012-12-11 18:14:16 +0000650
akling@apple.com7506fda2013-11-07 10:12:36 +0000651 if (firstRun && firstRun->renderer().isReplaced()) {
652 RenderBox& renderBox = toRenderBox(firstRun->renderer());
weinig@apple.come9621c32014-01-04 20:53:51 +0000653 updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight());
robert@webkit.org0903cf52012-12-11 18:14:16 +0000654 }
655
656 computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000657 // The widths of all runs are now known. We can now place every inline box (and
658 // compute accurate widths for the inline flow boxes).
659 needsWordSpacing = false;
mmaxfield@apple.comb0a4a3f2014-04-30 00:36:21 +0000660 lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing);
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000661}
mitz@apple.com390fa322011-02-24 23:07:06 +0000662
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000663BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBox* lineBox, const LineInfo& lineInfo, ETextAlign textAlign, float& logicalLeft,
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000664 float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache,
665 WordMeasurements& wordMeasurements)
666{
darin06dcb9c2005-08-15 04:31:09 +0000667 bool needsWordSpacing = false;
mitz@apple.com390fa322011-02-24 23:07:06 +0000668 float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();
mitz@apple.com86470c82011-01-27 01:39:27 +0000669 unsigned expansionOpportunityCount = 0;
670 bool isAfterExpansion = true;
671 Vector<unsigned, 16> expansionOpportunities;
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000672 RenderObject* previousObject = nullptr;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000673
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000674 BidiRun* r = firstRun;
675 for (; r; r = r->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000676 if (!r->box() || r->renderer().isOutOfFlowPositioned() || r->box()->isLineBreak())
hyatt98ee7e42003-05-14 01:39:15 +0000677 continue; // Positioned objects are only participating to figure out their
678 // correct static x position. They have no effect on the width.
hyatt0c05e102006-04-14 08:15:00 +0000679 // Similarly, line break boxes have no effect on the width.
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000680 if (is<RenderText>(r->renderer())) {
681 RenderText& renderText = downcast<RenderText>(r->renderer());
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000682 if (textAlign == JUSTIFY && r != trailingSpaceRun) {
mitz@apple.com80968932011-03-26 00:46:26 +0000683 if (!isAfterExpansion)
akling@apple.com7506fda2013-11-07 10:12:36 +0000684 toInlineTextBox(r->box())->setCanHaveLeadingExpansion(true);
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000685 unsigned opportunitiesInRun = Font::expansionOpportunityCount(renderText.stringView(r->m_start, r->m_stop), r->box()->direction(), isAfterExpansion);
mitz@apple.com86470c82011-01-27 01:39:27 +0000686 expansionOpportunities.append(opportunitiesInRun);
687 expansionOpportunityCount += opportunitiesInRun;
mitz@apple.com815ef2f2008-02-25 17:11:56 +0000688 }
689
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000690 if (int length = renderText.textLength()) {
691 if (!r->m_start && needsWordSpacing && isSpaceOrNewline(renderText.characterAt(r->m_start)))
692 totalLogicalWidth += lineStyle(*renderText.parent(), lineInfo).font().wordSpacing();
693 needsWordSpacing = !isSpaceOrNewline(renderText.characterAt(r->m_stop - 1)) && r->m_stop == length;
darin06dcb9c2005-08-15 04:31:09 +0000694 }
eric@webkit.org060caf62011-05-03 22:11:39 +0000695
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000696 setLogicalWidthForTextRun(lineBox, r, &renderText, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
mitz@apple.com86470c82011-01-27 01:39:27 +0000697 } else {
698 isAfterExpansion = false;
akling@apple.com7506fda2013-11-07 10:12:36 +0000699 if (!r->renderer().isRenderInline()) {
700 RenderBox& renderBox = toRenderBox(r->renderer());
weinig@apple.com12840dc2013-10-22 23:59:08 +0000701 if (renderBox.isRubyRun())
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000702 setMarginsForRubyRun(r, toRenderRubyRun(renderBox), previousObject, lineInfo);
akling@apple.com7506fda2013-11-07 10:12:36 +0000703 r->box()->setLogicalWidth(logicalWidthForChild(renderBox));
mitz@apple.com86470c82011-01-27 01:39:27 +0000704 totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox);
705 }
hyattffe78712003-02-11 01:59:29 +0000706 }
hyatt4b381692003-03-10 21:11:59 +0000707
akling@apple.com7506fda2013-11-07 10:12:36 +0000708 totalLogicalWidth += r->box()->logicalWidth();
709 previousObject = &r->renderer();
hyattffe78712003-02-11 01:59:29 +0000710 }
711
mitz@apple.com86470c82011-01-27 01:39:27 +0000712 if (isAfterExpansion && !expansionOpportunities.isEmpty()) {
713 expansionOpportunities.last()--;
714 expansionOpportunityCount--;
715 }
716
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000717 updateLogicalWidthForAlignment(textAlign, lineBox, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount);
hyattffe78712003-02-11 01:59:29 +0000718
leviw@chromium.orgd70a0072011-05-03 23:28:11 +0000719 computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth);
mitz@apple.come1364202008-02-28 01:06:41 +0000720
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000721 return r;
hyattffe78712003-02-11 01:59:29 +0000722}
723
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000724void RenderBlockFlow::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000725 VerticalPositionCache& verticalPositionCache)
hyattffe78712003-02-11 01:59:29 +0000726{
hyatt@apple.com4a9c625a2010-11-17 20:55:40 +0000727 setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache));
hyattffe78712003-02-11 01:59:29 +0000728
729 // Now make sure we place replaced render objects correctly.
mitz@apple.com887f3592008-02-25 22:03:08 +0000730 for (BidiRun* r = firstRun; r; r = r->next()) {
akling@apple.com7506fda2013-11-07 10:12:36 +0000731 ASSERT(r->box());
732 if (!r->box())
eseidel789896f2005-11-27 22:52:09 +0000733 continue; // Skip runs with no line boxes.
hyatt0c3a9862004-02-23 21:26:26 +0000734
akling@apple.com27e7d142013-11-07 12:04:02 +0000735 InlineBox& box = *r->box();
736
hyatt98ee7e42003-05-14 01:39:15 +0000737 // Align positioned boxes with the top of the line box. This is
738 // a reasonable approximation of an appropriate y position.
akling@apple.com7506fda2013-11-07 10:12:36 +0000739 if (r->renderer().isOutOfFlowPositioned())
akling@apple.com27e7d142013-11-07 12:04:02 +0000740 box.setLogicalTop(logicalHeight());
hyatt98ee7e42003-05-14 01:39:15 +0000741
742 // Position is used to properly position both replaced elements and
743 // to update the static normal flow x/y of positioned elements.
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000744 if (is<RenderText>(r->renderer()))
745 downcast<RenderText>(r->renderer()).positionLineBox(toInlineTextBox(box));
746 else if (is<RenderBox>(r->renderer()))
747 downcast<RenderBox>(r->renderer()).positionLineBox(toInlineElementBox(box));
748 else if (is<RenderLineBreak>(r->renderer()))
749 downcast<RenderLineBreak>(r->renderer()).replaceInlineBoxWrapper(toInlineElementBox(box));
hyatt98ee7e42003-05-14 01:39:15 +0000750 }
mitz@apple.coma927be62008-03-21 05:30:19 +0000751 // Positioned objects and zero-length text nodes destroy their boxes in
752 // position(), which unnecessarily dirties the line.
753 lineBox->markDirty(false);
hyattffe78712003-02-11 01:59:29 +0000754}
kociendabb0c24b2001-08-24 14:24:40 +0000755
akling@apple.com7506fda2013-11-07 10:12:36 +0000756static inline bool isCollapsibleSpace(UChar character, const RenderText& renderer)
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000757{
758 if (character == ' ' || character == '\t' || character == softHyphen)
759 return true;
760 if (character == '\n')
akling@apple.com7506fda2013-11-07 10:12:36 +0000761 return !renderer.style().preserveNewline();
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000762 if (character == noBreakSpace)
akling@apple.com7506fda2013-11-07 10:12:36 +0000763 return renderer.style().nbspMode() == SPACE;
mitz@apple.comc13ea5f2008-04-18 21:18:26 +0000764 return false;
765}
766
msaboff@apple.com142fc202012-10-18 18:03:14 +0000767template <typename CharacterType>
akling@apple.com7506fda2013-11-07 10:12:36 +0000768static inline int findFirstTrailingSpace(const RenderText& lastText, const CharacterType* characters, int start, int stop)
msaboff@apple.com142fc202012-10-18 18:03:14 +0000769{
770 int firstSpace = stop;
771 while (firstSpace > start) {
772 UChar current = characters[firstSpace - 1];
773 if (!isCollapsibleSpace(current, lastText))
774 break;
775 firstSpace--;
776 }
777
778 return firstSpace;
779}
780
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000781inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext)
eric@webkit.org0894bb82011-04-03 08:29:40 +0000782{
eric@webkit.org5bee2942011-04-08 02:12:31 +0000783 if (!bidiRuns.runCount()
akling@apple.com7506fda2013-11-07 10:12:36 +0000784 || !bidiRuns.logicallyLastRun()->renderer().style().breakOnlyAfterWhiteSpace()
785 || !bidiRuns.logicallyLastRun()->renderer().style().autoWrap())
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000786 return nullptr;
eric@webkit.org0894bb82011-04-03 08:29:40 +0000787
eric@webkit.org5bee2942011-04-08 02:12:31 +0000788 BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun();
akling@apple.com7506fda2013-11-07 10:12:36 +0000789 const RenderObject& lastObject = trailingSpaceRun->renderer();
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000790 if (!is<RenderText>(lastObject))
791 return nullptr;
eric@webkit.org0894bb82011-04-03 08:29:40 +0000792
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000793 const RenderText& lastText = downcast<RenderText>(lastObject);
msaboff@apple.com142fc202012-10-18 18:03:14 +0000794 int firstSpace;
akling@apple.com7506fda2013-11-07 10:12:36 +0000795 if (lastText.is8Bit())
796 firstSpace = findFirstTrailingSpace(lastText, lastText.characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +0000797 else
akling@apple.com7506fda2013-11-07 10:12:36 +0000798 firstSpace = findFirstTrailingSpace(lastText, lastText.characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop());
msaboff@apple.com142fc202012-10-18 18:03:14 +0000799
eric@webkit.org0894bb82011-04-03 08:29:40 +0000800 if (firstSpace == trailingSpaceRun->stop())
cdumez@apple.com35094bd2014-10-07 19:33:53 +0000801 return nullptr;
eric@webkit.org0894bb82011-04-03 08:29:40 +0000802
akling@apple.com827be9c2013-10-29 02:58:43 +0000803 TextDirection direction = style().direction();
eric@webkit.org5bee2942011-04-08 02:12:31 +0000804 bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun());
eric@webkit.org0894bb82011-04-03 08:29:40 +0000805 if (firstSpace != trailingSpaceRun->start()) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000806 BidiContext* baseContext = currentContext;
eric@webkit.org0894bb82011-04-03 08:29:40 +0000807 while (BidiContext* parent = baseContext->parent())
808 baseContext = parent;
809
akling@apple.com7506fda2013-11-07 10:12:36 +0000810 BidiRun* newTrailingRun = new BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->renderer(), baseContext, U_OTHER_NEUTRAL);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000811 trailingSpaceRun->m_stop = firstSpace;
812 if (direction == LTR)
eric@webkit.org5bee2942011-04-08 02:12:31 +0000813 bidiRuns.addRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000814 else
eric@webkit.org5bee2942011-04-08 02:12:31 +0000815 bidiRuns.prependRun(newTrailingRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000816 trailingSpaceRun = newTrailingRun;
817 return trailingSpaceRun;
818 }
819 if (!shouldReorder)
820 return trailingSpaceRun;
821
822 if (direction == LTR) {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000823 bidiRuns.moveRunToEnd(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000824 trailingSpaceRun->m_level = 0;
825 } else {
eric@webkit.org5bee2942011-04-08 02:12:31 +0000826 bidiRuns.moveRunToBeginning(trailingSpaceRun);
eric@webkit.org0894bb82011-04-03 08:29:40 +0000827 trailingSpaceRun->m_level = 1;
828 }
829 return trailingSpaceRun;
830}
831
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000832void RenderBlockFlow::appendFloatingObjectToLastLine(FloatingObject* floatingObject)
mitz@apple.comd17e8c02011-04-16 21:59:36 +0000833{
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +0000834 ASSERT(!floatingObject->originatingLine());
835 floatingObject->setOriginatingLine(lastRootBox());
weinig@apple.com12840dc2013-10-22 23:59:08 +0000836 lastRootBox()->appendFloat(floatingObject->renderer());
mitz@apple.comd17e8c02011-04-16 21:59:36 +0000837}
838
mmaxfield@apple.com434c8722014-01-28 22:03:57 +0000839static inline void setUpResolverToResumeInIsolate(InlineBidiResolver& resolver, RenderObject* root, RenderObject* startObject)
mmaxfield@apple.com18782a22014-01-28 21:53:22 +0000840{
841 if (root != startObject) {
842 RenderObject* parent = startObject->parent();
mmaxfield@apple.com434c8722014-01-28 22:03:57 +0000843 setUpResolverToResumeInIsolate(resolver, root, parent);
mmaxfield@apple.com18782a22014-01-28 21:53:22 +0000844 notifyObserverEnteredObject(&resolver, startObject);
845 }
846}
847
eric@webkit.orga26de042011-09-08 18:46:01 +0000848// FIXME: BidiResolver should have this logic.
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000849static inline void constructBidiRunsForSegment(InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfRuns, VisualDirectionOverride override, bool previousLineBrokeCleanly)
eric@webkit.orga26de042011-09-08 18:46:01 +0000850{
851 // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead
852 // of the resolver owning the runs.
853 ASSERT(&topResolver.runs() == &bidiRuns);
betravis@adobe.com9e5e8242013-04-19 23:28:26 +0000854 ASSERT(topResolver.position() != endOfRuns);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000855 RenderObject* currentRoot = topResolver.position().root();
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000856 topResolver.createBidiRunsForLine(endOfRuns, override, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +0000857
858 while (!topResolver.isolatedRuns().isEmpty()) {
859 // It does not matter which order we resolve the runs as long as we resolve them all.
860 BidiRun* isolatedRun = topResolver.isolatedRuns().last();
861 topResolver.isolatedRuns().removeLast();
862
ddkilzer@apple.com42c0af62014-04-17 19:39:22 +0000863 RenderObject& startObject = isolatedRun->renderer();
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000864
eric@webkit.orga26de042011-09-08 18:46:01 +0000865 // Only inlines make sense with unicode-bidi: isolate (blocks are already isolated).
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000866 // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the
867 // tree to see which parent inline is the isolate. We could change enterIsolate
868 // to take a RenderObject and do this logic there, but that would be a layering
869 // violation for BidiResolver (which knows nothing about RenderObject).
ddkilzer@apple.com42c0af62014-04-17 19:39:22 +0000870 RenderInline* isolatedInline = toRenderInline(highestContainingIsolateWithinRoot(startObject, currentRoot));
ddkilzer@apple.comad6ad362014-04-02 17:21:09 +0000871 ASSERT(isolatedInline);
872
eric@webkit.orga26de042011-09-08 18:46:01 +0000873 InlineBidiResolver isolatedResolver;
akling@apple.com827be9c2013-10-29 02:58:43 +0000874 EUnicodeBidi unicodeBidi = isolatedInline->style().unicodeBidi();
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000875 TextDirection direction;
876 if (unicodeBidi == Plaintext)
akling@apple.com7506fda2013-11-07 10:12:36 +0000877 determineDirectionality(direction, InlineIterator(isolatedInline, &isolatedRun->renderer(), 0));
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000878 else {
rniwa@webkit.org4d4bd332012-08-20 21:34:11 +0000879 ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride);
akling@apple.com827be9c2013-10-29 02:58:43 +0000880 direction = isolatedInline->style().direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000881 }
zoltan@webkit.orgd1a97402013-12-08 05:53:33 +0000882 isolatedResolver.setStatus(BidiStatus(direction, isOverride(unicodeBidi)));
eric@webkit.orga26de042011-09-08 18:46:01 +0000883
ddkilzer@apple.com42c0af62014-04-17 19:39:22 +0000884 setUpResolverToResumeInIsolate(isolatedResolver, isolatedInline, &startObject);
leviw@chromium.orge7812f32012-02-07 23:46:40 +0000885
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000886 // The starting position is the beginning of the first run within the isolate that was identified
887 // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the
888 // first run within the isolate.
ddkilzer@apple.com42c0af62014-04-17 19:39:22 +0000889 InlineIterator iter = InlineIterator(isolatedInline, &startObject, isolatedRun->m_start);
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000890 isolatedResolver.setPositionIgnoringNestedIsolates(iter);
eric@webkit.orga26de042011-09-08 18:46:01 +0000891
commit-queue@webkit.org30cc2912011-12-15 04:19:24 +0000892 // 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 +0000893 // FIXME: What should end and previousLineBrokeCleanly be?
894 // rniwa says previousLineBrokeCleanly is just a WinIE hack and could always be false here?
commit-queue@webkit.orgccad9242012-12-05 20:17:30 +0000895 isolatedResolver.createBidiRunsForLine(endOfRuns, NoVisualOverride, previousLineBrokeCleanly);
eric@webkit.orga26de042011-09-08 18:46:01 +0000896 // Note that we do not delete the runs from the resolver.
rniwa@webkit.orgd0ad8882012-05-23 07:37:07 +0000897 // 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 +0000898 // itself to be turned into an InlineBox. We can't remove it here without potentially losing track of
899 // the logically last run.
900 if (isolatedResolver.runs().runCount())
901 bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs());
eric@webkit.orga26de042011-09-08 18:46:01 +0000902
903 // If we encountered any nested isolate runs, just move them
904 // to the top resolver's list for later processing.
905 if (!isolatedResolver.isolatedRuns().isEmpty()) {
andersca@apple.com92012992013-05-05 19:03:49 +0000906 topResolver.isolatedRuns().appendVector(isolatedResolver.isolatedRuns());
eric@webkit.orga26de042011-09-08 18:46:01 +0000907 isolatedResolver.isolatedRuns().clear();
commit-queue@webkit.org1968a432013-09-11 19:23:58 +0000908 currentRoot = isolatedInline;
eric@webkit.orga26de042011-09-08 18:46:01 +0000909 }
910 }
911}
912
eric@webkit.org45e33a52011-05-04 11:51:09 +0000913// 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 +0000914RootInlineBox* 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 +0000915{
916 if (!bidiRuns.runCount())
917 return 0;
918
919 // FIXME: Why is this only done when we had runs?
gyuyoung.kim@samsung.com113fb8b2013-11-28 23:25:19 +0000920 lineInfo.setLastLine(!end.renderer());
eric@webkit.org45e33a52011-05-04 11:51:09 +0000921
922 RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo);
923 if (!lineBox)
924 return 0;
925
mario.prada@samsung.com79397522014-02-28 18:12:52 +0000926 lineBox->setBidiLevel(bidiLevel);
eric@webkit.org45e33a52011-05-04 11:51:09 +0000927 lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly());
928
eric@webkit.org45e33a52011-05-04 11:51:09 +0000929 bool isSVGRootInlineBox = lineBox->isSVGRootInlineBox();
eric@webkit.org45e33a52011-05-04 11:51:09 +0000930
931 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
932
933 // Now we position all of our text runs horizontally.
934 if (!isSVGRootInlineBox)
enrica@apple.com885c84d2012-10-10 05:48:51 +0000935 computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache, wordMeasurements);
eric@webkit.org45e33a52011-05-04 11:51:09 +0000936
937 // Now position our text runs vertically.
938 computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache);
939
eric@webkit.org45e33a52011-05-04 11:51:09 +0000940 // SVG text layout code computes vertical & horizontal positions on its own.
941 // Note that we still need to execute computeVerticalPositionsForLine() as
942 // it calls InlineTextBox::positionLineBox(), which tracks whether the box
943 // contains reversed text or not. If we wouldn't do that editing and thus
944 // text selection in RTL boxes would not work as expected.
945 if (isSVGRootInlineBox) {
akling@apple.com670fea12013-10-12 18:16:42 +0000946 ASSERT_WITH_SECURITY_IMPLICATION(isSVGText());
akling@apple.com0c7d7fe2013-11-07 10:08:04 +0000947 toSVGRootInlineBox(lineBox)->computePerCharacterLayoutInformation();
eric@webkit.org45e33a52011-05-04 11:51:09 +0000948 }
eric@webkit.org45e33a52011-05-04 11:51:09 +0000949
950 // Compute our overflow now.
951 lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap);
952
eric@webkit.org45e33a52011-05-04 11:51:09 +0000953 return lineBox;
954}
955
akling@apple.com31dd4f42013-10-30 22:27:59 +0000956static void deleteLineRange(LineLayoutState& layoutState, RootInlineBox* startLine, RootInlineBox* stopLine = 0)
eric@webkit.org455d90e2011-05-09 22:27:27 +0000957{
958 RootInlineBox* boxToDelete = startLine;
959 while (boxToDelete && boxToDelete != stopLine) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +0000960 layoutState.updateRepaintRangeFromBox(boxToDelete);
akling@apple.com31dd4f42013-10-30 22:27:59 +0000961 // Note: deleteLineRange(firstRootBox()) is not identical to deleteLineBoxTree().
eric@webkit.orge2532d92011-05-16 23:10:49 +0000962 // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing.
eric@webkit.org455d90e2011-05-09 22:27:27 +0000963 RootInlineBox* next = boxToDelete->nextRootBox();
akling@apple.com31dd4f42013-10-30 22:27:59 +0000964 boxToDelete->deleteLine();
eric@webkit.org455d90e2011-05-09 22:27:27 +0000965 boxToDelete = next;
966 }
967}
968
bjonesbe@adobe.com24199752013-10-08 23:20:42 +0000969void RenderBlockFlow::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild)
eric@webkit.org060caf62011-05-03 22:11:39 +0000970{
971 // We want to skip ahead to the first dirty line
972 InlineBidiResolver resolver;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +0000973 RootInlineBox* startLine = determineStartPosition(layoutState, resolver);
eric@webkit.org060caf62011-05-03 22:11:39 +0000974
mitz@apple.com10ed3cb2011-09-07 20:59:39 +0000975 unsigned consecutiveHyphenatedLines = 0;
976 if (startLine) {
977 for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox())
978 consecutiveHyphenatedLines++;
979 }
980
eric@webkit.org060caf62011-05-03 22:11:39 +0000981 // FIXME: This would make more sense outside of this function, but since
982 // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call
983 // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html.
eric@webkit.org59c3c1e2011-05-17 19:45:24 +0000984 if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) {
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000985 setNeedsLayout(MarkOnlyThis); // Mark as needing a full layout to force us to repaint.
akling@apple.com691cf5c2013-08-24 16:33:15 +0000986 if (!view().doingFullRepaint() && hasLayer()) {
eric@webkit.org060caf62011-05-03 22:11:39 +0000987 // Because we waited until we were already inside layout to discover
988 // that the block really needed a full layout, we missed our chance to repaint the layer
989 // before layout started. Luckily the layer has cached the repaint rect for its original
990 // position and size, and so we can use that to make a repaint happen now.
zalan@apple.comc7b20b12014-02-12 04:50:55 +0000991 repaintUsingContainer(containerForRepaint(), layer()->repaintRect());
eric@webkit.org060caf62011-05-03 22:11:39 +0000992 }
993 }
994
mihnea@adobe.com99467792013-03-19 09:09:04 +0000995 if (containsFloats())
darin@apple.com7cad7042013-09-24 05:53:55 +0000996 layoutState.setLastFloat(m_floatingObjects->set().last().get());
eric@webkit.org060caf62011-05-03 22:11:39 +0000997
998 // We also find the first clean line and extract these lines. We will add them back
999 // if we determine that we're able to synchronize after handling all our dirty lines.
1000 InlineIterator cleanLineStart;
1001 BidiStatus cleanLineBidiStatus;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001002 if (!layoutState.isFullLayout() && startLine)
1003 determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus);
eric@webkit.org060caf62011-05-03 22:11:39 +00001004
1005 if (startLine) {
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001006 if (!layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001007 layoutState.setRepaintRange(logicalHeight());
akling@apple.com31dd4f42013-10-30 22:27:59 +00001008 deleteLineRange(layoutState, startLine);
eric@webkit.org060caf62011-05-03 22:11:39 +00001009 }
1010
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001011 if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001012 // If the last line before the start line ends with a line break that clear floats,
1013 // adjust the height accordingly.
1014 // A line break can be either the first or the last object on a line, depending on its direction.
1015 if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) {
akling@apple.com0b8172b72013-08-31 18:34:23 +00001016 RenderObject* lastObject = &lastLeafChild->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001017 if (!lastObject->isBR())
akling@apple.com0b8172b72013-08-31 18:34:23 +00001018 lastObject = &lastRootBox()->firstLeafChild()->renderer();
eric@webkit.org060caf62011-05-03 22:11:39 +00001019 if (lastObject->isBR()) {
akling@apple.com827be9c2013-10-29 02:58:43 +00001020 EClear clear = lastObject->style().clear();
eric@webkit.org060caf62011-05-03 22:11:39 +00001021 if (clear != CNONE)
bjonesbe@adobe.comf9f10402014-02-20 19:40:28 +00001022 clearFloats(clear);
eric@webkit.org060caf62011-05-03 22:11:39 +00001023 }
1024 }
1025 }
1026
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001027 layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001028 linkToEndLineIfNeeded(layoutState);
1029 repaintDirtyFloats(layoutState.floats());
1030}
eric@webkit.org060caf62011-05-03 22:11:39 +00001031
zoltan@webkit.org8b422c82013-09-20 21:17:43 +00001032RenderTextInfo::RenderTextInfo()
mitz@apple.com6a859602012-08-27 15:31:56 +00001033 : m_text(0)
mitz@apple.comd4c153d2012-09-16 23:36:41 +00001034 , m_font(0)
mitz@apple.com6a859602012-08-27 15:31:56 +00001035{
1036}
1037
zoltan@webkit.org8b422c82013-09-20 21:17:43 +00001038RenderTextInfo::~RenderTextInfo()
mitz@apple.com6a859602012-08-27 15:31:56 +00001039{
1040}
1041
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001042// 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 +00001043inline const InlineIterator& RenderBlockFlow::restartLayoutRunsAndFloatsInRange(LayoutUnit oldLogicalHeight, LayoutUnit newLogicalHeight, FloatingObject* lastFloatFromPreviousLine, InlineBidiResolver& resolver, const InlineIterator& oldEnd)
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001044{
1045 removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight);
1046 setLogicalHeight(newLogicalHeight);
1047 resolver.setPositionIgnoringNestedIsolates(oldEnd);
1048 return oldEnd;
1049}
1050
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001051void RenderBlockFlow::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001052{
akling@apple.com827be9c2013-10-29 02:58:43 +00001053 const RenderStyle& styleToUse = style();
akling@apple.com691cf5c2013-08-24 16:33:15 +00001054 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001055 LineMidpointState& lineMidpointState = resolver.midpointState();
1056 InlineIterator end = resolver.position();
1057 bool checkForEndLineMatch = layoutState.endLine();
mitz@apple.com6a859602012-08-27 15:31:56 +00001058 RenderTextInfo renderTextInfo;
eric@webkit.org060caf62011-05-03 22:11:39 +00001059 VerticalPositionCache verticalPositionCache;
1060
weinig@apple.com12840dc2013-10-22 23:59:08 +00001061 LineBreaker lineBreaker(*this);
leviw@chromium.org1a508692011-05-05 00:01:11 +00001062
eric@webkit.org060caf62011-05-03 22:11:39 +00001063 while (!end.atEnd()) {
1064 // 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 +00001065 if (checkForEndLineMatch) {
1066 layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus));
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001067 if (layoutState.endLineMatched()) {
1068 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001069 break;
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001070 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001071 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001072
1073 lineMidpointState.reset();
1074
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001075 layoutState.lineInfo().setEmpty(true);
robert@webkit.org8cbab142011-12-30 20:58:29 +00001076 layoutState.lineInfo().resetRunsFromLeadingWhitespace();
eric@webkit.org060caf62011-05-03 22:11:39 +00001077
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001078 const InlineIterator oldEnd = end;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001079 bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly();
darin@apple.com7cad7042013-09-24 05:53:55 +00001080 FloatingObject* lastFloatFromPreviousLine = (containsFloats()) ? m_floatingObjects->set().last().get() : 0;
zoltan@webkit.org3bd77f52013-04-23 18:23:36 +00001081
enrica@apple.com885c84d2012-10-10 05:48:51 +00001082 WordMeasurements wordMeasurements;
1083 end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements);
glenn@skynav.com61b1abf2013-04-02 23:28:32 +00001084 renderTextInfo.m_lineBreakIterator.resetPriorContext();
eric@webkit.org060caf62011-05-03 22:11:39 +00001085 if (resolver.position().atEnd()) {
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001086 // FIXME: We shouldn't be creating any runs in nextLineBreak to begin with!
eric@webkit.org060caf62011-05-03 22:11:39 +00001087 // Once BidiRunList is separated from BidiResolver this will not be needed.
1088 resolver.runs().deleteRuns();
1089 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001090 layoutState.setCheckForFloatsFromLastLine(true);
rniwa@webkit.org7daa12d2011-12-02 02:39:14 +00001091 resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0);
eric@webkit.org060caf62011-05-03 22:11:39 +00001092 break;
1093 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001094
betravis@adobe.com9e5e8242013-04-19 23:28:26 +00001095 ASSERT(end != resolver.position());
1096
eric@webkit.org45e33a52011-05-04 11:51:09 +00001097 // This is a short-cut for empty lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001098 if (layoutState.lineInfo().isEmpty()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001099 if (lastRootBox())
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001100 lastRootBox()->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
eric@webkit.org060caf62011-05-03 22:11:39 +00001101 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001102 VisualDirectionOverride override = (styleToUse.rtlOrdering() == VisualOrder ? (styleToUse.direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride);
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001103
akling@apple.com827be9c2013-10-29 02:58:43 +00001104 if (isNewUBAParagraph && styleToUse.unicodeBidi() == Plaintext && !resolver.context()->parent()) {
1105 TextDirection direction = styleToUse.direction();
leviw@chromium.orge7812f32012-02-07 23:46:40 +00001106 determineDirectionality(direction, resolver.position());
akling@apple.com827be9c2013-10-29 02:58:43 +00001107 resolver.setStatus(BidiStatus(direction, isOverride(styleToUse.unicodeBidi())));
leviw@chromium.org7781b6a2011-06-27 22:01:38 +00001108 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001109 // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine.
1110 BidiRunList<BidiRun>& bidiRuns = resolver.runs();
zoltan@webkit.org7d4f8cc2014-03-26 18:20:15 +00001111 constructBidiRunsForSegment(resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly());
eric@webkit.org060caf62011-05-03 22:11:39 +00001112 ASSERT(resolver.position() == end);
1113
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001114 BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : 0;
eric@webkit.org060caf62011-05-03 22:11:39 +00001115
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001116 if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) {
eric@webkit.org45e33a52011-05-04 11:51:09 +00001117 bidiRuns.logicallyLastRun()->m_hasHyphen = true;
mitz@apple.com10ed3cb2011-09-07 20:59:39 +00001118 consecutiveHyphenatedLines++;
1119 } else
1120 consecutiveHyphenatedLines = 0;
eric@webkit.org45e33a52011-05-04 11:51:09 +00001121
eric@webkit.org060caf62011-05-03 22:11:39 +00001122 // Now that the runs have been ordered, we create the line boxes.
1123 // At the same time we figure out where border/padding/margin should be applied for
1124 // inline flow boxes.
1125
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001126 LayoutUnit oldLogicalHeight = logicalHeight();
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001127 RootInlineBox* lineBox = createLineBoxesFromBidiRuns(resolver.status().context->level(), bidiRuns, end, layoutState.lineInfo(), verticalPositionCache, trailingSpaceRun, wordMeasurements);
eric@webkit.org060caf62011-05-03 22:11:39 +00001128
1129 bidiRuns.deleteRuns();
1130 resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed).
1131
1132 if (lineBox) {
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001133 lineBox->setLineBreakInfo(end.renderer(), end.offset(), resolver.status());
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001134 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001135 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001136
1137 if (paginated) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001138 LayoutUnit adjustment = 0;
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001139 bool overflowsRegion;
1140 adjustLinePositionForPagination(lineBox, adjustment, overflowsRegion, layoutState.flowThread());
eric@webkit.org060caf62011-05-03 22:11:39 +00001141 if (adjustment) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001142 LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, layoutState.lineInfo().isFirstLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001143 lineBox->adjustBlockDirectionPosition(adjustment);
commit-queue@webkit.org49ad4732011-07-15 07:23:01 +00001144 if (layoutState.usesRepaintBounds())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001145 layoutState.updateRepaintRangeFromBox(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001146
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001147 if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, layoutState.lineInfo().isFirstLine()) != oldLineWidth) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001148 // We have to delete this line, remove all floats that got added, and let line layout re-run.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001149 lineBox->deleteLine();
commit-queue@webkit.org4055b2e2012-12-06 19:05:15 +00001150 end = restartLayoutRunsAndFloatsInRange(oldLogicalHeight, oldLogicalHeight + adjustment, lastFloatFromPreviousLine, resolver, oldEnd);
eric@webkit.org060caf62011-05-03 22:11:39 +00001151 continue;
1152 }
1153
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001154 setLogicalHeight(lineBox->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001155 }
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001156
1157 if (RenderFlowThread* flowThread = flowThreadContainingBlock()) {
1158 if (flowThread->isRenderNamedFlowThread() && overflowsRegion && hasNextPage(lineBox->lineTop())) {
1159 // Limit the height of this block to the end of the current region because
1160 // it is also fragmented into the next region.
1161 LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalTop(), ExcludePageBoundary);
1162 if (logicalHeight() > remainingLogicalHeight)
1163 setLogicalHeight(remainingLogicalHeight);
1164 }
1165 }
commit-queue@webkit.orgbe554b22012-11-26 20:00:49 +00001166
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001167 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001168 updateRegionForLine(lineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001169 }
1170 }
robert@webkit.org402c1512013-02-07 18:48:39 +00001171 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001172
robert@webkit.org402c1512013-02-07 18:48:39 +00001173 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001174 setStaticPositions(*this, *lineBreaker.positionedObjects()[i]);
eric@webkit.org060caf62011-05-03 22:11:39 +00001175
robert@webkit.org402c1512013-02-07 18:48:39 +00001176 if (!layoutState.lineInfo().isEmpty()) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001177 layoutState.lineInfo().setFirstLine(false);
bjonesbe@adobe.comf9f10402014-02-20 19:40:28 +00001178 clearFloats(lineBreaker.clear());
eric@webkit.org060caf62011-05-03 22:11:39 +00001179 }
1180
1181 if (m_floatingObjects && lastRootBox()) {
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001182 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001183 auto it = floatingObjectSet.begin();
1184 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001185 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001186 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001187 ASSERT(lastFloatIterator != end);
1188 ++lastFloatIterator;
1189 it = lastFloatIterator;
1190 }
1191 for (; it != end; ++it) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001192 FloatingObject* f = it->get();
eric@webkit.org060caf62011-05-03 22:11:39 +00001193 appendFloatingObjectToLastLine(f);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001194 ASSERT(&f->renderer() == &layoutState.floats()[layoutState.floatIndex()].object);
eric@webkit.org060caf62011-05-03 22:11:39 +00001195 // If a float's geometry has changed, give up on syncing with clean lines.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001196 if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect())
eric@webkit.org060caf62011-05-03 22:11:39 +00001197 checkForEndLineMatch = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001198 layoutState.setFloatIndex(layoutState.floatIndex() + 1);
eric@webkit.org060caf62011-05-03 22:11:39 +00001199 }
darin@apple.com7cad7042013-09-24 05:53:55 +00001200 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001201 }
1202
1203 lineMidpointState.reset();
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001204 resolver.setPosition(end, numberOfIsolateAncestors(end));
eric@webkit.org060caf62011-05-03 22:11:39 +00001205 }
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001206
abucur@adobe.comfc497132013-10-04 08:49:21 +00001207 // In case we already adjusted the line positions during this layout to avoid widows
1208 // then we need to ignore the possibility of having a new widows situation.
1209 // Otherwise, we risk leaving empty containers which is against the block fragmentation principles.
akling@apple.com827be9c2013-10-29 02:58:43 +00001210 if (paginated && !style().hasAutoWidows() && !didBreakAtLineToAvoidWidow()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001211 // Check the line boxes to make sure we didn't create unacceptable widows.
1212 // However, we'll prioritize orphans - so nothing we do here should create
1213 // a new orphan.
1214
1215 RootInlineBox* lineBox = lastRootBox();
1216
1217 // Count from the end of the block backwards, to see how many hanging
1218 // lines we have.
1219 RootInlineBox* firstLineInBlock = firstRootBox();
1220 int numLinesHanging = 1;
1221 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1222 ++numLinesHanging;
1223 lineBox = lineBox->prevRootBox();
1224 }
1225
1226 // If there were no breaks in the block, we didn't create any widows.
jchaffraix@webkit.org0f225142013-01-28 22:28:21 +00001227 if (!lineBox || !lineBox->isFirstAfterPageBreak() || lineBox == firstLineInBlock)
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001228 return;
1229
akling@apple.com827be9c2013-10-29 02:58:43 +00001230 if (numLinesHanging < style().widows()) {
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001231 // We have detected a widow. Now we need to work out how many
1232 // lines there are on the previous page, and how many we need
1233 // to steal.
akling@apple.com827be9c2013-10-29 02:58:43 +00001234 int numLinesNeeded = style().widows() - numLinesHanging;
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001235 RootInlineBox* currentFirstLineOfNewPage = lineBox;
1236
1237 // Count the number of lines in the previous page.
1238 lineBox = lineBox->prevRootBox();
1239 int numLinesInPreviousPage = 1;
1240 while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) {
1241 ++numLinesInPreviousPage;
1242 lineBox = lineBox->prevRootBox();
1243 }
1244
1245 // If there was an explicit value for orphans, respect that. If not, we still
1246 // shouldn't create a situation where we make an orphan bigger than the initial value.
1247 // This means that setting widows implies we also care about orphans, but given
1248 // the specification says the initial orphan value is non-zero, this is ok. The
1249 // author is always free to set orphans explicitly as well.
akling@apple.com827be9c2013-10-29 02:58:43 +00001250 int orphans = style().hasAutoOrphans() ? style().initialOrphans() : style().orphans();
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001251 int numLinesAvailable = numLinesInPreviousPage - orphans;
1252 if (numLinesAvailable <= 0)
1253 return;
1254
andersca@apple.com86298632013-11-10 19:32:33 +00001255 int numLinesToTake = std::min(numLinesAvailable, numLinesNeeded);
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001256 // Wind back from our first widowed line.
1257 lineBox = currentFirstLineOfNewPage;
1258 for (int i = 0; i < numLinesToTake; ++i)
1259 lineBox = lineBox->prevRootBox();
1260
1261 // We now want to break at this line. Remember for next layout and trigger relayout.
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001262 setBreakAtLineToAvoidWidow(lineCount(lineBox));
dino@apple.comfde5fdf2012-12-10 21:22:44 +00001263 markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), lineBox->lineBottomWithLeading(), lineBox);
1264 }
1265 }
abucur@adobe.comfc497132013-10-04 08:49:21 +00001266
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001267 clearDidBreakAtLineToAvoidWidow();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001268}
eric@webkit.org060caf62011-05-03 22:11:39 +00001269
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001270void RenderBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001271{
1272 if (layoutState.endLine()) {
1273 if (layoutState.endLineMatched()) {
akling@apple.com691cf5c2013-08-24 16:33:15 +00001274 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eric@webkit.org060caf62011-05-03 22:11:39 +00001275 // Attach all the remaining lines, and then adjust their y-positions as needed.
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001276 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001277 for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001278 line->attachLine();
1279 if (paginated) {
1280 delta -= line->paginationStrut();
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001281 bool overflowsRegion;
1282 adjustLinePositionForPagination(line, delta, overflowsRegion, layoutState.flowThread());
eric@webkit.org060caf62011-05-03 22:11:39 +00001283 }
1284 if (delta) {
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001285 layoutState.updateRepaintRangeFromBox(line, delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001286 line->adjustBlockDirectionPosition(delta);
1287 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001288 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001289 updateRegionForLine(line);
eric@webkit.org060caf62011-05-03 22:11:39 +00001290 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001291 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1292 RenderBox* floatingBox = *it;
1293 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001294 ASSERT(!floatingObject->originatingLine());
1295 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001296 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox) + delta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001297 positionNewFloats();
1298 }
1299 }
1300 }
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001301 setLogicalHeight(lastRootBox()->lineBottomWithLeading());
eric@webkit.org060caf62011-05-03 22:11:39 +00001302 } else {
1303 // Delete all the remaining lines.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001304 deleteLineRange(layoutState, layoutState.endLine());
eric@webkit.org060caf62011-05-03 22:11:39 +00001305 }
1306 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001307
1308 if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) {
eric@webkit.org060caf62011-05-03 22:11:39 +00001309 // In case we have a float on the last line, it might not be positioned up to now.
1310 // This has to be done before adding in the bottom border/padding, or the float will
1311 // include the padding incorrectly. -dwh
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001312 if (layoutState.checkForFloatsFromLastLine()) {
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001313 LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow();
1314 LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow();
akling@apple.comb5f24642013-11-06 04:47:12 +00001315 auto newLineBox = std::make_unique<TrailingFloatsRootInlineBox>(*this);
1316 auto trailingFloatsLineBox = newLineBox.get();
dbates@webkit.org0cefe4f2014-07-03 22:13:54 +00001317 m_lineBoxes.appendLineBox(WTF::move(newLineBox));
eric@webkit.org060caf62011-05-03 22:11:39 +00001318 trailingFloatsLineBox->setConstructed();
1319 GlyphOverflowAndFallbackFontsMap textBoxDataMap;
1320 VerticalPositionCache verticalPositionCache;
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001321 LayoutUnit blockLogicalHeight = logicalHeight();
hyatt@apple.coma8b5b822011-09-07 18:48:07 +00001322 trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache);
1323 trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight);
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001324 trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight));
leviw@chromium.orgd32486e2012-03-16 10:52:56 +00001325 LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight);
1326 LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight);
eric@webkit.org060caf62011-05-03 22:11:39 +00001327 trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom());
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001328 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001329 updateRegionForLine(trailingFloatsLineBox);
eric@webkit.org060caf62011-05-03 22:11:39 +00001330 }
1331
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001332 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001333 auto it = floatingObjectSet.begin();
1334 auto end = floatingObjectSet.end();
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001335 if (layoutState.lastFloat()) {
darin@apple.com7cad7042013-09-24 05:53:55 +00001336 auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat());
eric@webkit.org060caf62011-05-03 22:11:39 +00001337 ASSERT(lastFloatIterator != end);
1338 ++lastFloatIterator;
1339 it = lastFloatIterator;
1340 }
1341 for (; it != end; ++it)
darin@apple.com7cad7042013-09-24 05:53:55 +00001342 appendFloatingObjectToLastLine(it->get());
1343 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
eric@webkit.org060caf62011-05-03 22:11:39 +00001344 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001345}
1346
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001347void RenderBlockFlow::repaintDirtyFloats(Vector<FloatWithRect>& floats)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001348{
eric@webkit.org060caf62011-05-03 22:11:39 +00001349 size_t floatCount = floats.size();
1350 // Floats that did not have layout did not repaint when we laid them out. They would have
1351 // painted by now if they had moved, but if they stayed at (0, 0), they still need to be
1352 // painted.
1353 for (size_t i = 0; i < floatCount; ++i) {
1354 if (!floats[i].everHadLayout) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001355 RenderBox& box = floats[i].object;
1356 if (!box.x() && !box.y() && box.checkForRepaintDuringLayout())
1357 box.repaint();
eric@webkit.org060caf62011-05-03 22:11:39 +00001358 }
1359 }
1360}
1361
antti@apple.com940f5872013-10-24 20:31:11 +00001362void RenderBlockFlow::layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom)
jamesr@google.com19548ad2010-04-02 23:21:35 +00001363{
antti@apple.comfea51992013-10-28 13:39:23 +00001364 ASSERT(!m_simpleLineLayout);
antti@apple.com940f5872013-10-24 20:31:11 +00001365
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001366 setLogicalHeight(borderAndPaddingBefore());
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001367
1368 // Lay out our hypothetical grid line as though it occurs at the top of the block.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001369 if (view().layoutState() && view().layoutState()->lineGrid() == this)
hyatt@apple.comee7af1d2012-01-17 19:16:24 +00001370 layoutLineGridBox();
mitz@apple.come1364202008-02-28 01:06:41 +00001371
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001372 RenderFlowThread* flowThread = flowThreadContainingBlock();
akling@apple.comee3c8df2013-11-06 08:09:44 +00001373 bool clearLinesForPagination = firstRootBox() && flowThread && !flowThread->hasRegions();
commit-queue@webkit.org93cdd632012-12-07 00:33:56 +00001374
hyatt0c3a9862004-02-23 21:26:26 +00001375 // Figure out if we should clear out our line boxes.
1376 // FIXME: Handle resize eventually!
akling@apple.comee3c8df2013-11-06 08:09:44 +00001377 bool isFullLayout = !firstRootBox() || selfNeedsLayout() || relayoutChildren || clearLinesForPagination;
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001378 LineLayoutState layoutState(isFullLayout, repaintLogicalTop, repaintLogicalBottom, flowThread);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001379
1380 if (isFullLayout)
akling@apple.com31dd4f42013-10-30 22:27:59 +00001381 lineBoxes().deleteLineBoxes();
mitz@apple.come1364202008-02-28 01:06:41 +00001382
commit-queue@webkit.org07797312013-02-22 18:58:19 +00001383 // Text truncation kicks in in two cases:
1384 // 1) If your overflow isn't visible and your text-overflow-mode isn't clip.
1385 // 2) If you're an anonymous block with a block parent that satisfies #1.
hyatted77ad82004-06-15 07:21:23 +00001386 // 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 +00001387 // difficult to figure out in general (especially in the middle of doing layout), so we only handle the
1388 // simple case of an anonymous block truncating when it's parent is clipped.
akling@apple.com827be9c2013-10-29 02:58:43 +00001389 bool hasTextOverflow = (style().textOverflow() && hasOverflowClip())
1390 || (isAnonymousBlock() && parent() && parent()->isRenderBlock() && parent()->style().textOverflow() && parent()->hasOverflowClip());
mitz@apple.come1364202008-02-28 01:06:41 +00001391
hyatted77ad82004-06-15 07:21:23 +00001392 // Walk all the lines and delete our ellipsis line boxes if they exist.
1393 if (hasTextOverflow)
1394 deleteEllipsisLineBoxes();
1395
hyattffe78712003-02-11 01:59:29 +00001396 if (firstChild()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001397 // In full layout mode, clear the line boxes of children upfront. Otherwise,
1398 // siblings can run into stale root lineboxes during layout. Then layout
1399 // the replaced elements later. In partial layout mode, line boxes are not
1400 // deleted and only dirtied. In that case, we can layout the replaced
1401 // elements at the same time.
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001402 bool hasInlineChild = false;
inferno@chromium.org13563122012-08-16 20:50:05 +00001403 Vector<RenderBox*> replacedChildren;
weinig@apple.com12840dc2013-10-22 23:59:08 +00001404 for (InlineWalker walker(*this); !walker.atEnd(); walker.advance()) {
1405 RenderObject& o = *walker.current();
abucur@adobe.com33159da2013-08-13 07:44:32 +00001406
weinig@apple.com12840dc2013-10-22 23:59:08 +00001407 if (!hasInlineChild && o.isInline())
commit-queue@webkit.orgcf45df92010-09-14 13:25:06 +00001408 hasInlineChild = true;
1409
weinig@apple.com12840dc2013-10-22 23:59:08 +00001410 if (o.isReplaced() || o.isFloating() || o.isOutOfFlowPositioned()) {
1411 RenderBox& box = toRenderBox(o);
eric@webkit.org060caf62011-05-03 22:11:39 +00001412
weinig@apple.com12840dc2013-10-22 23:59:08 +00001413 if (relayoutChildren || box.hasRelativeDimensions())
1414 box.setChildNeedsLayout(MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001415
zimmermann@webkit.orgac68af42011-06-15 08:02:37 +00001416 // 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 +00001417 if (relayoutChildren && box.needsPreferredWidthsRecalculation())
1418 box.setPreferredLogicalWidthsDirty(true, MarkOnlyThis);
eric@webkit.org060caf62011-05-03 22:11:39 +00001419
weinig@apple.com12840dc2013-10-22 23:59:08 +00001420 if (box.isOutOfFlowPositioned())
1421 box.containingBlock()->insertPositionedObject(box);
1422 else if (box.isFloating())
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001423 layoutState.floats().append(FloatWithRect(box));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001424 else if (isFullLayout || box.needsLayout()) {
inferno@chromium.org13563122012-08-16 20:50:05 +00001425 // Replaced element.
weinig@apple.com12840dc2013-10-22 23:59:08 +00001426 box.dirtyLineBoxes(isFullLayout);
inferno@chromium.org13563122012-08-16 20:50:05 +00001427 if (isFullLayout)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001428 replacedChildren.append(&box);
inferno@chromium.org13563122012-08-16 20:50:05 +00001429 else
weinig@apple.com12840dc2013-10-22 23:59:08 +00001430 box.layoutIfNeeded();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001431 }
weinig@apple.com12840dc2013-10-22 23:59:08 +00001432 } else if (o.isTextOrLineBreak() || (o.isRenderInline() && !walker.atEndOfInline())) {
1433 if (o.isRenderInline())
1434 toRenderInline(o).updateAlwaysCreateLineBoxes(layoutState.isFullLayout());
1435 if (layoutState.isFullLayout() || o.selfNeedsLayout())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001436 dirtyLineBoxesForRenderer(o, layoutState.isFullLayout());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001437 o.clearNeedsLayout();
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001438 }
abarth@webkit.org31d23df2010-04-05 21:52:09 +00001439 }
1440
inferno@chromium.orgba2dceb2012-08-21 00:09:47 +00001441 for (size_t i = 0; i < replacedChildren.size(); i++)
1442 replacedChildren[i]->layoutIfNeeded();
inferno@chromium.org13563122012-08-16 20:50:05 +00001443
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001444 layoutRunsAndFloats(layoutState, hasInlineChild);
kociendabb0c24b2001-08-24 14:24:40 +00001445 }
hyatt85586af2003-02-19 23:22:42 +00001446
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001447 // Expand the last line to accommodate Ruby and emphasis marks.
1448 int lastLineAnnotationsAdjustment = 0;
1449 if (lastRootBox()) {
andersca@apple.com86298632013-11-10 19:32:33 +00001450 LayoutUnit lowestAllowedPosition = std::max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
akling@apple.com827be9c2013-10-29 02:58:43 +00001451 if (!style().isFlippedLinesWritingMode())
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001452 lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition);
1453 else
1454 lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition);
hyatt@apple.com5e48ff52010-11-19 00:43:29 +00001455 }
mitz@apple.com3672d9e2010-12-17 19:31:16 +00001456
hyatta70560a2002-11-20 01:53:20 +00001457 // Now add in the bottom border/padding.
zoltan@webkit.org8e79cc22013-06-14 00:39:36 +00001458 setLogicalHeight(logicalHeight() + lastLineAnnotationsAdjustment + borderAndPaddingAfter() + scrollbarLogicalHeight());
kociendabb0c24b2001-08-24 14:24:40 +00001459
akling@apple.comee3c8df2013-11-06 08:09:44 +00001460 if (!firstRootBox() && hasLineIfEmpty())
hyatt@apple.com2a5eb212011-03-22 23:21:54 +00001461 setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
hyatted77ad82004-06-15 07:21:23 +00001462
1463 // See if we have any lines that spill out of our block. If we do, then we will possibly need to
1464 // truncate text.
1465 if (hasTextOverflow)
1466 checkLinesForTextOverflow();
kociendabb0c24b2001-08-24 14:24:40 +00001467}
1468
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001469void RenderBlockFlow::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat)
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001470{
1471 Vector<RenderBox*>* cleanLineFloats = line->floatsPtr();
1472 if (!cleanLineFloats)
1473 return;
stavila@adobe.comf4ef0972014-03-28 21:55:46 +00001474
1475 if (!floats.size()) {
1476 encounteredNewFloat = true;
1477 return;
1478 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001479
weinig@apple.com12840dc2013-10-22 23:59:08 +00001480 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001481 RenderBox* floatingBox = *it;
1482 floatingBox->layoutIfNeeded();
bjonesbe@adobe.com562a50d2014-02-20 20:01:19 +00001483 LayoutSize newSize(floatingBox->width() + floatingBox->horizontalMarginExtent(), floatingBox->height() + floatingBox->verticalMarginExtent());
inferno@chromium.orga227be62013-02-11 08:06:45 +00001484 ASSERT_WITH_SECURITY_IMPLICATION(floatIndex < floats.size());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001485 if (&floats[floatIndex].object != floatingBox) {
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001486 encounteredNewFloat = true;
1487 return;
1488 }
hyatt@apple.comc2e15522014-09-03 19:26:38 +00001489
1490 // 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
1491 // as dirty.
1492 if (floats[floatIndex].rect.size() != newSize || (floatingBox->style().styleType() == FIRST_LETTER && floatingBox->style().initialLetterDrop() > 0)) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001493 LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x();
andersca@apple.com86298632013-11-10 19:32:33 +00001494 LayoutUnit floatHeight = isHorizontalWritingMode() ? std::max(floats[floatIndex].rect.height(), newSize.height()) : std::max(floats[floatIndex].rect.width(), newSize.width());
1495 floatHeight = std::min(floatHeight, LayoutUnit::max() - floatTop);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001496 line->markDirty();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001497 markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001498 floats[floatIndex].rect.setSize(newSize);
1499 dirtiedByFloat = true;
1500 }
1501 floatIndex++;
1502 }
1503}
1504
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001505RootInlineBox* RenderBlockFlow::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver)
hyatt0c3a9862004-02-23 21:26:26 +00001506{
1507 RootInlineBox* curr = 0;
1508 RootInlineBox* last = 0;
mitz@apple.come1364202008-02-28 01:06:41 +00001509
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001510 // FIXME: This entire float-checking block needs to be broken into a new function.
mitz@apple.com40547b32008-03-18 04:04:34 +00001511 bool dirtiedByFloat = false;
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001512 if (!layoutState.isFullLayout()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001513 // Paginate all of the clean lines.
akling@apple.com691cf5c2013-08-24 16:33:15 +00001514 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001515 LayoutUnit paginationDelta = 0;
mitz@apple.com40547b32008-03-18 04:04:34 +00001516 size_t floatIndex = 0;
1517 for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001518 if (paginated) {
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001519 if (lineWidthForPaginatedLineChanged(curr, 0, layoutState.flowThread())) {
hyatt@apple.com0c6cd7a2011-09-22 20:50:41 +00001520 curr->markDirty();
1521 break;
1522 }
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001523 paginationDelta -= curr->paginationStrut();
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001524 bool overflowsRegion;
1525 adjustLinePositionForPagination(curr, paginationDelta, overflowsRegion, layoutState.flowThread());
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001526 if (paginationDelta) {
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001527 if (containsFloats() || !layoutState.floats().isEmpty()) {
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001528 // 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 +00001529 layoutState.markForFullLayout();
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001530 break;
1531 }
eric@webkit.org060caf62011-05-03 22:11:39 +00001532
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001533 layoutState.updateRepaintRangeFromBox(curr, paginationDelta);
hyatt@apple.com61bbedf2011-01-26 23:10:57 +00001534 curr->adjustBlockDirectionPosition(paginationDelta);
eric@webkit.org060caf62011-05-03 22:11:39 +00001535 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001536 if (layoutState.flowThread())
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001537 updateRegionForLine(curr);
hyatt@apple.comcc1737c2010-09-16 20:20:02 +00001538 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001539
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001540 // If a new float has been inserted before this line or before its last known float, just do a full layout.
1541 bool encounteredNewFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001542 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001543 if (encounteredNewFloat)
1544 layoutState.markForFullLayout();
1545
1546 if (dirtiedByFloat || layoutState.isFullLayout())
mitz@apple.com40547b32008-03-18 04:04:34 +00001547 break;
1548 }
1549 // Check if a new float has been inserted after the last known float.
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001550 if (!curr && floatIndex < layoutState.floats().size())
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001551 layoutState.markForFullLayout();
mitz@apple.com40547b32008-03-18 04:04:34 +00001552 }
1553
eric@webkit.org59c3c1e2011-05-17 19:45:24 +00001554 if (layoutState.isFullLayout()) {
akling@apple.com31dd4f42013-10-30 22:27:59 +00001555 m_lineBoxes.deleteLineBoxTree();
igor.o@sisa.samsung.comf6a57df2013-04-15 21:25:35 +00001556 curr = 0;
1557
akling@apple.comee3c8df2013-11-06 08:09:44 +00001558 ASSERT(!firstRootBox() && !lastRootBox());
eseidel789896f2005-11-27 22:52:09 +00001559 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001560 if (curr) {
1561 // We have a dirty line.
mjs9f78dd92007-02-12 04:06:07 +00001562 if (RootInlineBox* prevRootBox = curr->prevRootBox()) {
hyatt0c3a9862004-02-23 21:26:26 +00001563 // We have a previous line.
cdumez@apple.com35094bd2014-10-07 19:33:53 +00001564 if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (is<RenderText>(*prevRootBox->lineBreakObj()) && prevRootBox->lineBreakPos() >= downcast<RenderText>(*prevRootBox->lineBreakObj()).textLength()))) {
mjs9f78dd92007-02-12 04:06:07 +00001565 // The previous line didn't break cleanly or broke at a newline
1566 // that has been deleted, so treat it as dirty too.
1567 curr = prevRootBox;
cdumez@apple.com35094bd2014-10-07 19:33:53 +00001568 }
hyatt0c3a9862004-02-23 21:26:26 +00001569 }
eseidel789896f2005-11-27 22:52:09 +00001570 } else {
hyatt0c3a9862004-02-23 21:26:26 +00001571 // No dirty lines were found.
1572 // If the last line didn't break cleanly, treat it as dirty.
1573 if (lastRootBox() && !lastRootBox()->endsWithBreak())
1574 curr = lastRootBox();
1575 }
mitz@apple.come1364202008-02-28 01:06:41 +00001576
hyatt0c3a9862004-02-23 21:26:26 +00001577 // If we have no dirty lines, then last is just the last root box.
1578 last = curr ? curr->prevRootBox() : lastRootBox();
1579 }
mitz@apple.come1364202008-02-28 01:06:41 +00001580
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001581 unsigned numCleanFloats = 0;
1582 if (!layoutState.floats().isEmpty()) {
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001583 LayoutUnit savedLogicalHeight = logicalHeight();
mitz@apple.com40547b32008-03-18 04:04:34 +00001584 // Restore floats from clean lines.
1585 RootInlineBox* line = firstRootBox();
1586 while (line != curr) {
hyatt@apple.comd885df72009-01-22 02:31:52 +00001587 if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) {
weinig@apple.com12840dc2013-10-22 23:59:08 +00001588 for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) {
1589 RenderBox* floatingBox = *it;
1590 FloatingObject* floatingObject = insertFloatingObject(*floatingBox);
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001591 ASSERT(!floatingObject->originatingLine());
1592 floatingObject->setOriginatingLine(line);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001593 setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox));
mitz@apple.com40547b32008-03-18 04:04:34 +00001594 positionNewFloats();
weinig@apple.com12840dc2013-10-22 23:59:08 +00001595 ASSERT(&layoutState.floats()[numCleanFloats].object == floatingBox);
mitz@apple.com40547b32008-03-18 04:04:34 +00001596 numCleanFloats++;
1597 }
1598 }
1599 line = line->nextRootBox();
1600 }
hyatt@apple.com9a2e7d22010-10-06 22:13:31 +00001601 setLogicalHeight(savedLogicalHeight);
mitz@apple.com40547b32008-03-18 04:04:34 +00001602 }
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001603 layoutState.setFloatIndex(numCleanFloats);
mitz@apple.com40547b32008-03-18 04:04:34 +00001604
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001605 layoutState.lineInfo().setFirstLine(!last);
1606 layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak());
mitz@apple.com1a301772008-03-11 18:30:36 +00001607
hyatt0c3a9862004-02-23 21:26:26 +00001608 if (last) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001609 setLogicalHeight(last->lineBottomWithLeading());
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001610 InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos());
1611 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
mitz@apple.com15035e62008-07-05 20:44:44 +00001612 resolver.setStatus(last->lineBreakBidiStatus());
darindde01502005-12-18 22:55:35 +00001613 } else {
akling@apple.com827be9c2013-10-29 02:58:43 +00001614 TextDirection direction = style().direction();
1615 if (style().unicodeBidi() == Plaintext)
weinig@apple.com12840dc2013-10-22 23:59:08 +00001616 determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(*this), 0));
akling@apple.com827be9c2013-10-29 02:58:43 +00001617 resolver.setStatus(BidiStatus(direction, isOverride(style().unicodeBidi())));
weinig@apple.com12840dc2013-10-22 23:59:08 +00001618 InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(*this, &resolver), 0);
rniwa@webkit.org53d106b2011-11-30 22:33:20 +00001619 resolver.setPosition(iter, numberOfIsolateAncestors(iter));
darindde01502005-12-18 22:55:35 +00001620 }
hyatt0c3a9862004-02-23 21:26:26 +00001621 return curr;
1622}
1623
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001624void RenderBlockFlow::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001625{
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001626 ASSERT(!layoutState.endLine());
1627 size_t floatIndex = layoutState.floatIndex();
hyatt0c3a9862004-02-23 21:26:26 +00001628 RootInlineBox* last = 0;
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001629 for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) {
1630 if (!curr->isDirty()) {
1631 bool encounteredNewFloat = false;
1632 bool dirtiedByFloat = false;
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001633 checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat);
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001634 if (encounteredNewFloat)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001635 return;
hyatt04420ca2004-07-16 00:05:42 +00001636 }
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001637 if (curr->isDirty())
1638 last = 0;
1639 else if (!last)
1640 last = curr;
hyatt0c3a9862004-02-23 21:26:26 +00001641 }
mitz@apple.come1364202008-02-28 01:06:41 +00001642
hyatt0c3a9862004-02-23 21:26:26 +00001643 if (!last)
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001644 return;
mitz@apple.come1364202008-02-28 01:06:41 +00001645
mitz@apple.comd9ccfeb2011-03-10 01:56:27 +00001646 // At this point, |last| is the first line in a run of clean lines that ends with the last line
1647 // in the block.
1648
eseidel789896f2005-11-27 22:52:09 +00001649 RootInlineBox* prev = last->prevRootBox();
mitz@apple.com15035e62008-07-05 20:44:44 +00001650 cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos());
eseidel789896f2005-11-27 22:52:09 +00001651 cleanLineBidiStatus = prev->lineBreakBidiStatus();
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001652 layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading());
mitz@apple.come1364202008-02-28 01:06:41 +00001653
hyatt0c3a9862004-02-23 21:26:26 +00001654 for (RootInlineBox* line = last; line; line = line->nextRootBox())
1655 line->extractLine(); // Disconnect all line boxes from their render objects while preserving
1656 // their connections to one another.
mitz@apple.come1364202008-02-28 01:06:41 +00001657
commit-queue@webkit.orgc979afb2011-08-02 18:07:32 +00001658 layoutState.setEndLine(last);
hyatt0c3a9862004-02-23 21:26:26 +00001659}
1660
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001661bool RenderBlockFlow::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001662{
1663 LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop();
1664
akling@apple.com691cf5c2013-08-24 16:33:15 +00001665 bool paginated = view().layoutState() && view().layoutState()->isPaginated();
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001666 if (paginated && layoutState.flowThread()) {
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001667 // Check all lines from here to the end, and see if the hypothetical new position for the lines will result
1668 // in a different available line width.
1669 for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) {
1670 if (paginated) {
1671 // This isn't the real move we're going to do, so don't update the line box's pagination
1672 // strut yet.
1673 LayoutUnit oldPaginationStrut = lineBox->paginationStrut();
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001674 bool overflowsRegion;
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001675 lineDelta -= oldPaginationStrut;
stavila@adobe.come1efa7f2014-05-20 14:34:56 +00001676 adjustLinePositionForPagination(lineBox, lineDelta, overflowsRegion, layoutState.flowThread());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001677 lineBox->setPaginationStrut(oldPaginationStrut);
1678 }
hyatt@apple.comfd6f22e2013-03-01 21:44:06 +00001679 if (lineWidthForPaginatedLineChanged(lineBox, lineDelta, layoutState.flowThread()))
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001680 return false;
1681 }
1682 }
1683
1684 if (!lineDelta || !m_floatingObjects)
1685 return true;
1686
1687 // 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 +00001688 LayoutUnit logicalTop = std::min(logicalHeight(), layoutState.endLineLogicalTop());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001689
1690 RootInlineBox* lastLine = layoutState.endLine();
1691 while (RootInlineBox* nextLine = lastLine->nextRootBox())
1692 lastLine = nextLine;
1693
leviw@chromium.org3957b452012-05-01 00:06:37 +00001694 LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + absoluteValue(lineDelta);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001695
1696 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001697 auto end = floatingObjectSet.end();
1698 for (auto it = floatingObjectSet.begin(); it != end; ++it) {
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001699 FloatingObject* floatingObject = it->get();
1700 if (logicalBottomForFloat(floatingObject) >= logicalTop && logicalBottomForFloat(floatingObject) < logicalBottom)
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001701 return false;
1702 }
1703
1704 return true;
1705}
1706
weinig@apple.com31324fd2013-10-28 19:22:51 +00001707bool RenderBlockFlow::lineWidthForPaginatedLineChanged(RootInlineBox* rootBox, LayoutUnit lineDelta, RenderFlowThread* flowThread) const
1708{
1709 if (!flowThread)
1710 return false;
1711
1712 RenderRegion* currentRegion = regionAtBlockOffset(rootBox->lineTopWithLeading() + lineDelta);
1713 // Just bail if the region didn't change.
1714 if (rootBox->containingRegion() == currentRegion)
1715 return false;
1716 return rootBox->paginatedLineWidth() != availableLogicalWidthForContent(currentRegion);
1717}
1718
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001719bool RenderBlockFlow::matchedEndLine(LineLayoutState& layoutState, const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus)
hyatt0c3a9862004-02-23 21:26:26 +00001720{
mitz@apple.com15035e62008-07-05 20:44:44 +00001721 if (resolver.position() == endLineStart) {
1722 if (resolver.status() != endLineStatus)
mitz@apple.com40547b32008-03-18 04:04:34 +00001723 return false;
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001724 return checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00001725 }
hyatt0c3a9862004-02-23 21:26:26 +00001726
mitz@apple.come1364202008-02-28 01:06:41 +00001727 // The first clean line doesn't match, but we can check a handful of following lines to try
1728 // to match back up.
1729 static int numLines = 8; // The # of lines we're willing to match against.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001730 RootInlineBox* originalEndLine = layoutState.endLine();
1731 RootInlineBox* line = originalEndLine;
mitz@apple.come1364202008-02-28 01:06:41 +00001732 for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) {
gyuyoung.kim@samsung.com044376f2013-12-26 07:32:04 +00001733 if (line->lineBreakObj() == resolver.position().renderer() && line->lineBreakPos() == resolver.position().offset()) {
mitz@apple.come1364202008-02-28 01:06:41 +00001734 // We have a match.
mitz@apple.com15035e62008-07-05 20:44:44 +00001735 if (line->lineBreakBidiStatus() != resolver.status())
mitz@apple.come1364202008-02-28 01:06:41 +00001736 return false; // ...but the bidi state doesn't match.
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001737
1738 bool matched = false;
mitz@apple.come1364202008-02-28 01:06:41 +00001739 RootInlineBox* result = line->nextRootBox();
hyatt@apple.com1fb7d582011-09-23 20:25:11 +00001740 layoutState.setEndLine(result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001741 if (result) {
hyatt@apple.com7ce0d422011-08-30 16:57:37 +00001742 layoutState.setEndLineLogicalTop(line->lineBottomWithLeading());
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001743 matched = checkPaginationAndFloatsAtEndLine(layoutState);
mitz@apple.com40547b32008-03-18 04:04:34 +00001744 }
1745
mitz@apple.come1364202008-02-28 01:06:41 +00001746 // Now delete the lines that we failed to sync.
akling@apple.com31dd4f42013-10-30 22:27:59 +00001747 deleteLineRange(layoutState, originalEndLine, result);
hyatt@apple.coma10d30e2011-09-22 22:28:21 +00001748 return matched;
hyatt0c3a9862004-02-23 21:26:26 +00001749 }
1750 }
mitz@apple.come1364202008-02-28 01:06:41 +00001751
hyatt0c3a9862004-02-23 21:26:26 +00001752 return false;
1753}
1754
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00001755bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj)
bdashccffb432007-07-13 11:51:40 +00001756{
1757 ASSERT(inlineObj->parent() == this);
1758
mitz@apple.com15035e62008-07-05 20:44:44 +00001759 InlineIterator it(this, inlineObj, 0);
rniwa@webkit.org40248422011-06-15 00:19:39 +00001760 // FIXME: We should pass correct value for WhitespacePosition.
leviw@chromium.orgf009c8e2011-05-03 20:49:15 +00001761 while (!it.atEnd() && !requiresLineBox(it))
mitz@apple.com1a301772008-03-11 18:30:36 +00001762 it.increment();
bdashccffb432007-07-13 11:51:40 +00001763
1764 return !it.atEnd();
1765}
1766
weinig@apple.com611b9292013-10-20 22:57:54 +00001767void RenderBlockFlow::addOverflowFromInlineChildren()
hyattb4b20872004-10-20 21:34:01 +00001768{
antti@apple.comfea51992013-10-28 13:39:23 +00001769 if (auto layout = simpleLineLayout()) {
antti@apple.com940f5872013-10-24 20:31:11 +00001770 ASSERT(!hasOverflowClip());
antti@apple.comfea51992013-10-28 13:39:23 +00001771 SimpleLineLayout::collectFlowOverflow(*this, *layout);
antti@apple.com940f5872013-10-24 20:31:11 +00001772 return;
1773 }
eae@chromium.org9717cd82012-11-07 18:33:44 +00001774 LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit();
hyatt@apple.com592848f2010-12-06 20:03:43 +00001775 // 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 +00001776 if (hasOverflowClip() && !endPadding && element() && element()->isRootEditableElement() && style().isLeftToRightDirection())
hyatt@apple.com592848f2010-12-06 20:03:43 +00001777 endPadding = 1;
hyattb4b20872004-10-20 21:34:01 +00001778 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
hyatt@apple.com592848f2010-12-06 20:03:43 +00001779 addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
abucur@adobe.com4c3580b2014-04-29 12:38:20 +00001780 RenderRegion* region = flowThreadContainingBlock() ? curr->containingRegion() : nullptr;
abucur@adobe.com6585d012013-09-04 08:26:41 +00001781 if (region)
1782 region->addLayoutOverflowForBox(this, curr->paddedLayoutOverflowRect(endPadding));
1783 if (!hasOverflowClip()) {
hyatt@apple.com61f25322011-03-31 20:40:48 +00001784 addVisualOverflow(curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
abucur@adobe.com6585d012013-09-04 08:26:41 +00001785 if (region)
1786 region->addVisualOverflowForBox(this, curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
1787 }
hyattb4b20872004-10-20 21:34:01 +00001788 }
1789}
1790
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001791void RenderBlockFlow::deleteEllipsisLineBoxes()
hyatted77ad82004-06-15 07:21:23 +00001792{
akling@apple.com827be9c2013-10-29 02:58:43 +00001793 ETextAlign textAlign = style().textAlign();
1794 bool ltr = style().isLeftToRightDirection();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001795 bool firstLine = true;
1796 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
1797 if (curr->hasEllipsisBox()) {
1798 curr->clearTruncation();
1799
1800 // Shift the line back where it belongs if we cannot accomodate an ellipsis.
zalan@apple.combfa11952014-05-19 17:37:22 +00001801 float logicalLeft = logicalLeftOffsetForLine(curr->lineTop(), firstLine);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001802 float availableLogicalWidth = logicalRightOffsetForLine(curr->lineTop(), false) - logicalLeft;
1803 float totalLogicalWidth = curr->logicalWidth();
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001804 updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001805
1806 if (ltr)
1807 curr->adjustLogicalPosition((logicalLeft - curr->logicalLeft()), 0);
1808 else
1809 curr->adjustLogicalPosition(-(curr->logicalLeft() - logicalLeft), 0);
1810 }
1811 firstLine = false;
1812 }
hyatted77ad82004-06-15 07:21:23 +00001813}
1814
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001815void RenderBlockFlow::checkLinesForTextOverflow()
hyatted77ad82004-06-15 07:21:23 +00001816{
1817 // Determine the width of the ellipsis using the current font.
darindbba2bb2007-01-11 12:23:49 +00001818 // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable"
akling@apple.com827be9c2013-10-29 02:58:43 +00001819 const Font& font = style().font();
svillar@igalia.com5b31eef2014-03-14 08:30:55 +00001820 DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
akling@apple.com827be9c2013-10-29 02:58:43 +00001821 const Font& firstLineFont = firstLineStyle().font();
zalan@apple.combfa11952014-05-19 17:37:22 +00001822 float firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle()));
1823 float ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style()));
hyatted77ad82004-06-15 07:21:23 +00001824
1825 // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see
1826 // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and
1827 // check the left edge of the line box to see if it is less
1828 // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()"
akling@apple.com827be9c2013-10-29 02:58:43 +00001829 bool ltr = style().isLeftToRightDirection();
1830 ETextAlign textAlign = style().textAlign();
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001831 bool firstLine = true;
hyatted77ad82004-06-15 07:21:23 +00001832 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
zalan@apple.combfa11952014-05-19 17:37:22 +00001833 LayoutUnit blockRightEdge = logicalRightOffsetForLine(curr->lineTop(), firstLine);
1834 LayoutUnit blockLeftEdge = logicalLeftOffsetForLine(curr->lineTop(), firstLine);
1835 LayoutUnit lineBoxEdge = ltr ? curr->x() + curr->logicalWidth() : curr->x();
dglazkov@chromium.org28434e62009-05-13 22:30:10 +00001836 if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) {
hyattf918d2d2004-06-15 07:24:11 +00001837 // 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 +00001838 // can be truncated. In order for truncation to be possible, the line must have sufficient space to
1839 // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis
1840 // space.
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001841
1842 LayoutUnit width = firstLine ? firstLineEllipsisWidth : ellipsisWidth;
eae@chromium.orgee8613e2011-11-12 01:12:58 +00001843 LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge;
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001844 if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) {
1845 float totalLogicalWidth = curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width);
1846
akling@apple.comf294cf02013-07-17 18:46:39 +00001847 float logicalLeft = 0; // We are only interested in the delta from the base position.
zalan@apple.combfa11952014-05-19 17:37:22 +00001848 float truncatedWidth = logicalRightOffsetForLine(curr->lineTop(), firstLine);
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001849 updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, truncatedWidth, 0);
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001850 if (ltr)
1851 curr->adjustLogicalPosition(logicalLeft, 0);
1852 else
1853 curr->adjustLogicalPosition(-(truncatedWidth - (logicalLeft + totalLogicalWidth)), 0);
1854 }
hyatted77ad82004-06-15 07:21:23 +00001855 }
benjamin@webkit.orgf68b1be2012-06-23 02:02:28 +00001856 firstLine = false;
hyatted77ad82004-06-15 07:21:23 +00001857 }
1858}
1859
bjonesbe@adobe.com24199752013-10-08 23:20:42 +00001860bool RenderBlockFlow::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001861{
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00001862 if (!positionNewFloats())
1863 return false;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001864
rniwa@webkit.org44424752011-04-14 00:58:40 +00001865 width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001866
hyatt@apple.comdd78df82011-09-27 22:11:41 +00001867 // We only connect floats to lines for pagination purposes if the floats occur at the start of
1868 // the line and the previous line had a hard break (so this line is either the first in the block
1869 // or follows a <br>).
bjonesbe@adobe.coma9c66662013-08-14 20:30:14 +00001870 if (!newFloat->paginationStrut() || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00001871 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001872
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001873 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
darin@apple.com7cad7042013-09-24 05:53:55 +00001874 ASSERT(floatingObjectSet.last().get() == newFloat);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001875
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001876 LayoutUnit floatLogicalTop = logicalTopForFloat(newFloat);
bjonesbe@adobe.combdee2ce2014-02-07 18:37:55 +00001877 LayoutUnit paginationStrut = newFloat->paginationStrut();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001878
hyatt@apple.com5950bd42011-09-27 20:39:57 +00001879 if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut())
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00001880 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001881
darin@apple.com7cad7042013-09-24 05:53:55 +00001882 auto it = floatingObjectSet.end();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001883 --it; // Last float is newFloat, skip that one.
darin@apple.com7cad7042013-09-24 05:53:55 +00001884 auto begin = floatingObjectSet.begin();
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001885 while (it != begin) {
1886 --it;
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001887 FloatingObject* floatingObject = it->get();
1888 if (floatingObject == lastFloatFromPreviousLine)
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001889 break;
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001890 if (logicalTopForFloat(floatingObject) == logicalHeight() + lineInfo.floatPaginationStrut()) {
1891 floatingObject->setPaginationStrut(paginationStrut + floatingObject->paginationStrut());
weinig@apple.com12840dc2013-10-22 23:59:08 +00001892 RenderBox& floatBox = floatingObject->renderer();
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001893 setLogicalTopForChild(floatBox, logicalTopForChild(floatBox) + marginBeforeForChild(floatBox) + paginationStrut);
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00001894
1895 if (updateRegionRangeForBoxChild(floatingObject->renderer()))
1896 floatBox.setNeedsLayout(MarkOnlyThis);
cdumez@apple.come9437792014-10-08 23:33:43 +00001897 else if (is<RenderBlock>(floatBox))
1898 downcast<RenderBlock>(floatBox).setChildNeedsLayout(MarkOnlyThis);
weinig@apple.com12840dc2013-10-22 23:59:08 +00001899 floatBox.layoutIfNeeded();
stavila@adobe.com6cb976d2013-11-21 06:57:19 +00001900
hyatt@apple.com46c65b32011-08-09 19:13:45 +00001901 // Save the old logical top before calling removePlacedObject which will set
1902 // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat.
bjonesbe@adobe.com1ccd3a12013-10-10 00:35:38 +00001903 LayoutUnit oldLogicalTop = logicalTopForFloat(floatingObject);
1904 m_floatingObjects->removePlacedObject(floatingObject);
1905 setLogicalTopForFloat(floatingObject, oldLogicalTop + paginationStrut);
1906 m_floatingObjects->addPlacedObject(floatingObject);
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001907 }
1908 }
1909
hyatt@apple.comdd78df82011-09-27 22:11:41 +00001910 // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing
1911 // no content, then we don't want to improperly grow the height of the block.
1912 lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut);
rniwa@webkit.org7881ad02011-04-07 13:05:35 +00001913 return true;
rniwa@webkit.org73ce42a2011-04-06 14:10:02 +00001914}
1915
weinig@apple.com6b4a24142014-01-05 00:28:39 +00001916LayoutUnit RenderBlockFlow::startAlignedOffsetForLine(LayoutUnit position, bool firstLine)
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00001917{
akling@apple.com827be9c2013-10-29 02:58:43 +00001918 ETextAlign textAlign = style().textAlign();
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00001919
hyatt@apple.coma5626692013-11-18 23:08:30 +00001920 // <rdar://problem/15427571>
1921 // https://bugs.webkit.org/show_bug.cgi?id=124522
1922 // This quirk is for legacy content that doesn't work properly with the center positioning scheme
1923 // being honored (e.g., epubs).
1924 if (textAlign == TASTART || document().settings()->useLegacyTextAlignPositionedElementBehavior()) // FIXME: Handle TAEND here
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00001925 return startOffsetForLine(position, firstLine);
1926
1927 // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here
robert@webkit.org82903f42012-08-28 19:18:40 +00001928 float totalLogicalWidth = 0;
1929 float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false);
1930 float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), false) - logicalLeft;
mario.prada@samsung.com79397522014-02-28 18:12:52 +00001931
1932 // FIXME: Bug 129311: We need to pass a valid RootInlineBox here, considering the bidi level used to construct the line.
1933 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
robert@webkit.org7861a102011-09-22 17:16:47 +00001934
akling@apple.com827be9c2013-10-29 02:58:43 +00001935 if (!style().isLeftToRightDirection())
robert@webkit.org82903f42012-08-28 19:18:40 +00001936 return logicalWidth() - logicalLeft;
robert@webkit.orgfc7763c2011-09-03 18:28:57 +00001937 return logicalLeft;
1938}
1939
abucur@adobe.comd40287b2013-10-08 17:33:05 +00001940void RenderBlockFlow::updateRegionForLine(RootInlineBox* lineBox) const
1941{
1942 ASSERT(lineBox);
akling@apple.combdf247b2014-01-13 22:33:08 +00001943
abucur@adobe.comc18af352014-05-14 06:33:48 +00001944 if (!hasRegionRangeInFlowThread())
akling@apple.combdf247b2014-01-13 22:33:08 +00001945 lineBox->clearContainingRegion();
abucur@adobe.comc18af352014-05-14 06:33:48 +00001946 else {
1947 if (auto containingRegion = regionAtBlockOffset(lineBox->lineTopWithLeading()))
1948 lineBox->setContainingRegion(*containingRegion);
1949 else
1950 lineBox->clearContainingRegion();
1951 }
abucur@adobe.comd40287b2013-10-08 17:33:05 +00001952
1953 RootInlineBox* prevLineBox = lineBox->prevRootBox();
1954 if (!prevLineBox)
1955 return;
1956
1957 // This check is more accurate than the one in |adjustLinePositionForPagination| because it takes into
1958 // account just the container changes between lines. The before mentioned function doesn't set the flag
1959 // correctly if the line is positioned at the top of the last fragment container.
1960 if (lineBox->containingRegion() != prevLineBox->containingRegion())
1961 lineBox->setIsFirstAfterPageBreak(true);
1962}
1963
hyattffe78712003-02-11 01:59:29 +00001964}