darin | 55ae73e | 2007-05-11 15:47:28 +0000 | [diff] [blame] | 1 | /* |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2 | * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved. |
eric@webkit.org | ddbec0aa | 2010-01-06 01:13:11 +0000 | [diff] [blame] | 4 | * Copyright (C) 2010 Google Inc. All rights reserved. |
commit-queue@webkit.org | 1776140 | 2013-04-17 18:48:56 +0000 | [diff] [blame] | 5 | * Copyright (C) 2013 ChangSeok Oh <shivamidow@gmail.com> |
zoltan@webkit.org | 64be122 | 2013-11-15 21:40:59 +0000 | [diff] [blame] | 6 | * Copyright (C) 2013 Adobe Systems Inc. All right reserved. |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 7 | * |
| 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 |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | * Boston, MA 02110-1301, USA. |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 22 | * |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 23 | */ |
darin | be4c67d | 2005-12-19 19:53:12 +0000 | [diff] [blame] | 24 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 25 | #include "config.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 26 | |
weinig@apple.com | cef4e1e | 2013-10-19 03:14:44 +0000 | [diff] [blame] | 27 | #include "AXObjectCache.h" |
mitz@apple.com | 4c1ff32 | 2009-07-13 00:54:12 +0000 | [diff] [blame] | 28 | #include "BidiResolver.h" |
mmaxfield@apple.com | 167a0e9 | 2015-03-06 19:06:30 +0000 | [diff] [blame] | 29 | #include "BreakingContext.h" |
bjonesbe@adobe.com | 6747809 | 2013-09-09 22:18:17 +0000 | [diff] [blame] | 30 | #include "FloatingObjects.h" |
akling@apple.com | d3ec5ef | 2013-11-07 03:30:11 +0000 | [diff] [blame] | 31 | #include "InlineElementBox.h" |
hyatt@apple.com | 71eeb44 | 2010-02-11 20:05:51 +0000 | [diff] [blame] | 32 | #include "InlineIterator.h" |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 33 | #include "InlineTextBox.h" |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 34 | #include "InlineTextBoxStyle.h" |
zoltan@webkit.org | 4c74e8d | 2013-09-13 17:59:12 +0000 | [diff] [blame] | 35 | #include "LineLayoutState.h" |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 36 | #include "Logging.h" |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 37 | #include "RenderBlockFlow.h" |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 38 | #include "RenderFlowThread.h" |
antti@apple.com | 8d8ae71 | 2013-09-18 18:04:32 +0000 | [diff] [blame] | 39 | #include "RenderLineBreak.h" |
zoltan@webkit.org | b7a7346 | 2013-02-22 19:53:35 +0000 | [diff] [blame] | 40 | #include "RenderRegion.h" |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 41 | #include "RenderRubyBase.h" |
| 42 | #include "RenderRubyText.h" |
hyatt | d804834 | 2006-05-31 01:48:18 +0000 | [diff] [blame] | 43 | #include "RenderView.h" |
ossy@webkit.org | 66d8c0a | 2014-02-05 11:42:35 +0000 | [diff] [blame] | 44 | #include "SVGRootInlineBox.h" |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 45 | #include "Settings.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 46 | #include "SimpleLineLayoutFunctions.h" |
dbates@webkit.org | f6f05a9 | 2010-05-17 04:58:25 +0000 | [diff] [blame] | 47 | #include "TrailingFloatsRootInlineBox.h" |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 48 | #include "VerticalPositionCache.h" |
slewis@apple.com | a7615ca | 2008-07-12 05:51:33 +0000 | [diff] [blame] | 49 | #include <wtf/RefCountedLeakCounter.h> |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 50 | #include <wtf/StdLibExtras.h> |
commit-queue@webkit.org | b354051 | 2012-08-24 18:48:49 +0000 | [diff] [blame] | 51 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 52 | namespace WebCore { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 53 | |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 54 | static void determineDirectionality(TextDirection& dir, InlineIterator iter) |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 55 | { |
| 56 | while (!iter.atEnd()) { |
| 57 | if (iter.atParagraphSeparator()) |
| 58 | return; |
| 59 | if (UChar current = iter.current()) { |
darin@apple.com | 2eb5f4d | 2013-10-12 04:16:42 +0000 | [diff] [blame] | 60 | UCharDirection charDirection = u_charDirection(current); |
| 61 | if (charDirection == U_LEFT_TO_RIGHT) { |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 62 | dir = LTR; |
| 63 | return; |
| 64 | } |
darin@apple.com | 2eb5f4d | 2013-10-12 04:16:42 +0000 | [diff] [blame] | 65 | if (charDirection == U_RIGHT_TO_LEFT || charDirection == U_RIGHT_TO_LEFT_ARABIC) { |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 66 | dir = RTL; |
| 67 | return; |
| 68 | } |
| 69 | } |
| 70 | iter.increment(); |
| 71 | } |
| 72 | } |
| 73 | |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 74 | inline BidiRun* createRun(int start, int end, RenderObject& obj, InlineBidiResolver& resolver) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 75 | { |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 76 | return new BidiRun(start, end, obj, resolver.context(), resolver.dir()); |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 77 | } |
| 78 | |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 79 | void RenderBlockFlow::appendRunsForObject(BidiRunList<BidiRun>* runs, int start, int end, RenderObject& obj, InlineBidiResolver& resolver) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 80 | { |
leviw@chromium.org | d8df17d | 2012-05-24 21:47:47 +0000 | [diff] [blame] | 81 | if (start > end || shouldSkipCreatingRunsForObject(obj)) |
hyatt | eb003b8 | 2002-11-15 22:35:10 +0000 | [diff] [blame] | 82 | return; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 83 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 84 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
zoltan@webkit.org | 7585ad5 | 2014-01-21 21:33:22 +0000 | [diff] [blame] | 85 | bool haveNextMidpoint = (lineMidpointState.currentMidpoint() < lineMidpointState.numMidpoints()); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 86 | InlineIterator nextMidpoint; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 87 | if (haveNextMidpoint) |
zoltan@webkit.org | 7585ad5 | 2014-01-21 21:33:22 +0000 | [diff] [blame] | 88 | nextMidpoint = lineMidpointState.midpoints()[lineMidpointState.currentMidpoint()]; |
| 89 | if (lineMidpointState.betweenMidpoints()) { |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 90 | if (!haveNextMidpoint || (&obj != nextMidpoint.renderer())) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 91 | return; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 92 | // This is a new start point. Stop ignoring objects and |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 93 | // adjust our start. |
gyuyoung.kim@samsung.com | 044376f | 2013-12-26 07:32:04 +0000 | [diff] [blame] | 94 | start = nextMidpoint.offset(); |
zoltan@webkit.org | 7585ad5 | 2014-01-21 21:33:22 +0000 | [diff] [blame] | 95 | lineMidpointState.incrementCurrentMidpoint(); |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 96 | if (start < end) { |
| 97 | appendRunsForObject(runs, start, end, obj, resolver); |
| 98 | return; |
| 99 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 100 | } else { |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 101 | if (!haveNextMidpoint || (&obj != nextMidpoint.renderer())) { |
| 102 | if (runs) |
| 103 | runs->addRun(createRun(start, end, obj, resolver)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 104 | return; |
| 105 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 106 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 107 | // An end midpoint has been encountered within our object. We need to append a run with our endpoint. |
gyuyoung.kim@samsung.com | 044376f | 2013-12-26 07:32:04 +0000 | [diff] [blame] | 108 | if (static_cast<int>(nextMidpoint.offset() + 1) <= end) { |
zoltan@webkit.org | 7585ad5 | 2014-01-21 21:33:22 +0000 | [diff] [blame] | 109 | lineMidpointState.incrementCurrentMidpoint(); |
mmaxfield@apple.com | 0682d51 | 2014-03-25 20:15:14 +0000 | [diff] [blame] | 110 | // The end of the line is before the object we're inspecting. Skip everything and return |
| 111 | if (nextMidpoint.refersToEndOfPreviousNode()) |
| 112 | return; |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 113 | if (static_cast<int>(nextMidpoint.offset() + 1) > start && runs) |
| 114 | runs->addRun(createRun(start, nextMidpoint.offset() + 1, obj, resolver)); |
mmaxfield@apple.com | 0682d51 | 2014-03-25 20:15:14 +0000 | [diff] [blame] | 115 | appendRunsForObject(runs, nextMidpoint.offset() + 1, end, obj, resolver); |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 116 | } else if (runs) |
| 117 | runs->addRun(createRun(start, end, obj, resolver)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 121 | std::unique_ptr<RootInlineBox> RenderBlockFlow::createRootInlineBox() |
weinig@apple.com | cef4e1e | 2013-10-19 03:14:44 +0000 | [diff] [blame] | 122 | { |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 123 | return std::make_unique<RootInlineBox>(*this); |
weinig@apple.com | cef4e1e | 2013-10-19 03:14:44 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox() |
| 127 | { |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 128 | auto newRootBox = createRootInlineBox(); |
| 129 | RootInlineBox* rootBox = newRootBox.get(); |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 130 | m_lineBoxes.appendLineBox(WTFMove(newRootBox)); |
weinig@apple.com | cef4e1e | 2013-10-19 03:14:44 +0000 | [diff] [blame] | 131 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 132 | if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && firstRootBox() == rootBox) { |
weinig@apple.com | cef4e1e | 2013-10-19 03:14:44 +0000 | [diff] [blame] | 133 | if (AXObjectCache* cache = document().existingAXObjectCache()) |
| 134 | cache->recomputeIsIgnored(this); |
| 135 | } |
| 136 | |
| 137 | return rootBox; |
| 138 | } |
| 139 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 140 | static inline InlineBox* createInlineBoxForRenderer(RenderObject* renderer, bool isRootLineBox, bool isOnlyRun = false) |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 141 | { |
| 142 | if (isRootLineBox) |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 143 | return downcast<RenderBlockFlow>(*renderer).createAndAppendRootInlineBox(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 144 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 145 | if (is<RenderText>(*renderer)) |
| 146 | return downcast<RenderText>(*renderer).createInlineTextBox(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 147 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 148 | if (is<RenderBox>(*renderer)) { |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 149 | // FIXME: This is terrible. This branch returns an *owned* pointer! |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 150 | return downcast<RenderBox>(*renderer).createInlineBox().release(); |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 151 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 152 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 153 | if (is<RenderLineBreak>(*renderer)) { |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 154 | // FIXME: This is terrible. This branch returns an *owned* pointer! |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 155 | auto inlineBox = downcast<RenderLineBreak>(*renderer).createInlineBox().release(); |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 156 | // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode |
| 157 | // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.) |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 158 | inlineBox->setBehavesLikeText(isOnlyRun || renderer->document().inNoQuirksMode() || renderer->isLineBreakOpportunity()); |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 159 | return inlineBox; |
| 160 | } |
| 161 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 162 | return downcast<RenderInline>(*renderer).createAndAppendInlineFlowBox(); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 163 | } |
| 164 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 165 | static inline void dirtyLineBoxesForRenderer(RenderObject& renderer, bool fullLayout) |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 166 | { |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 167 | if (is<RenderText>(renderer)) { |
| 168 | RenderText& renderText = downcast<RenderText>(renderer); |
esprehn@chromium.org | 7745ffb | 2013-02-19 21:51:19 +0000 | [diff] [blame] | 169 | updateCounterIfNeeded(renderText); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 170 | renderText.dirtyLineBoxes(fullLayout); |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 171 | } else if (is<RenderLineBreak>(renderer)) |
| 172 | downcast<RenderLineBreak>(renderer).dirtyLineBoxes(fullLayout); |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 173 | else |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 174 | downcast<RenderInline>(renderer).dirtyLineBoxes(fullLayout); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 175 | } |
| 176 | |
xji@chromium.org | b0ad6eb82 | 2011-02-01 20:02:06 +0000 | [diff] [blame] | 177 | static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox) |
| 178 | { |
| 179 | do { |
| 180 | if (parentBox->isConstructed() || parentBox->nextOnLine()) |
| 181 | return true; |
| 182 | parentBox = parentBox->parent(); |
| 183 | } while (parentBox); |
| 184 | return false; |
| 185 | } |
| 186 | |
bjonesbe@adobe.com | fb6ceac | 2014-04-15 00:27:13 +0000 | [diff] [blame] | 187 | InlineFlowBox* RenderBlockFlow::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 188 | { |
| 189 | // See if we have an unconstructed line box for this object that is also |
| 190 | // the last item on the line. |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 191 | unsigned lineDepth = 1; |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 192 | InlineFlowBox* parentBox = nullptr; |
| 193 | InlineFlowBox* result = nullptr; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 194 | bool hasDefaultLineBoxContain = style().lineBoxContain() == RenderStyle::initialLineBoxContain(); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 195 | do { |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 196 | ASSERT_WITH_SECURITY_IMPLICATION(is<RenderInline>(*obj) || obj == this); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 197 | |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 198 | RenderInline* inlineFlow = obj != this ? downcast<RenderInline>(obj) : nullptr; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 199 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 200 | // Get the last box we made for this render object. |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 201 | parentBox = inlineFlow ? inlineFlow->lastLineBox() : downcast<RenderBlockFlow>(*obj).lastRootBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 202 | |
xji@chromium.org | b0ad6eb82 | 2011-02-01 20:02:06 +0000 | [diff] [blame] | 203 | // If this box or its ancestor is constructed then it is from a previous line, and we need |
| 204 | // to make a new box for our line. If this box or its ancestor is unconstructed but it has |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 205 | // something following it on the line, then we know we have to make a new box |
| 206 | // as well. In this situation our inline has actually been split in two on |
| 207 | // the same line (this can happen with very fancy language mixtures). |
| 208 | bool constructedNewBox = false; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 209 | bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes(); |
bjonesbe@adobe.com | fb6ceac | 2014-04-15 00:27:13 +0000 | [diff] [blame] | 210 | bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox); |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 211 | if (allowedToConstructNewBox && !canUseExistingParentBox) { |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 212 | // We need to make a new box for this render object. Once |
| 213 | // made, we need to place it at the end of the current line. |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 214 | InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this); |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 215 | parentBox = downcast<InlineFlowBox>(newBox); |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 216 | parentBox->setIsFirstLine(lineInfo.isFirstLine()); |
hyatt@apple.com | 2a5eb21 | 2011-03-22 23:21:54 +0000 | [diff] [blame] | 217 | parentBox->setIsHorizontal(isHorizontalWritingMode()); |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 218 | if (!hasDefaultLineBoxContain) |
| 219 | parentBox->clearDescendantsHaveSameLineHeightAndBaseline(); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 220 | constructedNewBox = true; |
| 221 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 222 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 223 | if (constructedNewBox || canUseExistingParentBox) { |
| 224 | if (!result) |
| 225 | result = parentBox; |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 226 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 227 | // 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.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 232 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 233 | if (!constructedNewBox || obj == this) |
| 234 | break; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 235 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 236 | childBox = parentBox; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 237 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 238 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 239 | // 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(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 242 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 243 | } while (true); |
| 244 | |
| 245 | return result; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 246 | } |
| 247 | |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 248 | template <typename CharacterType> |
| 249 | static 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.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 259 | static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 260 | { |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 261 | BidiRun* run = bidiRuns.logicallyLastRun(); |
| 262 | if (!run) |
| 263 | return true; |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 264 | unsigned pos = run->stop(); |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 265 | const RenderObject& renderer = run->renderer(); |
| 266 | if (!is<RenderText>(renderer)) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 267 | return false; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 268 | const RenderText& renderText = downcast<RenderText>(renderer); |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 269 | unsigned length = renderText.textLength(); |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 270 | if (pos >= length) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 271 | return true; |
| 272 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 273 | if (renderText.is8Bit()) |
| 274 | return endsWithASCIISpaces(renderText.characters8(), pos, length); |
| 275 | return endsWithASCIISpaces(renderText.characters16(), pos, length); |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 276 | } |
| 277 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 278 | RootInlineBox* RenderBlockFlow::constructLine(BidiRunList<BidiRun>& bidiRuns, const LineInfo& lineInfo) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 279 | { |
| 280 | ASSERT(bidiRuns.firstRun()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 281 | |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 282 | bool rootHasSelectedChildren = false; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 283 | InlineFlowBox* parentBox = 0; |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 284 | int runCount = bidiRuns.runCount() - lineInfo.runsFromLeadingWhitespace(); |
hyatt@apple.com | dafe597 | 2015-03-31 17:42:24 +0000 | [diff] [blame] | 285 | |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 286 | for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 287 | // Create a box for our object. |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 288 | bool isOnlyRun = (runCount == 1); |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 289 | if (runCount == 2 && !r->renderer().isListMarker()) |
| 290 | isOnlyRun = (!style().isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->renderer().isListMarker(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 291 | |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame] | 292 | if (lineInfo.isEmpty()) |
| 293 | continue; |
| 294 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 295 | InlineBox* box = createInlineBoxForRenderer(&r->renderer(), false, isOnlyRun); |
| 296 | r->setBox(*box); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 297 | |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 298 | if (!rootHasSelectedChildren && box->renderer().selectionState() != RenderObject::SelectionNone) |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 299 | rootHasSelectedChildren = true; |
hyatt@apple.com | dafe597 | 2015-03-31 17:42:24 +0000 | [diff] [blame] | 300 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 301 | // If we have no parent box yet, or if the run is not simply a sibling, |
| 302 | // then we need to construct inline boxes as necessary to properly enclose the |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 303 | // run's inline box. Segments can only be siblings at the root level, as |
| 304 | // they are positioned separately. |
bjonesbe@adobe.com | fb6ceac | 2014-04-15 00:27:13 +0000 | [diff] [blame] | 305 | if (!parentBox || &parentBox->renderer() != r->renderer().parent()) { |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 306 | // Create new inline boxes all the way back to the appropriate insertion point. |
hyatt@apple.com | 8e8cd25 | 2015-04-02 18:34:57 +0000 | [diff] [blame] | 307 | RenderObject* parentToUse = r->renderer().parent(); |
hyatt@apple.com | dafe597 | 2015-03-31 17:42:24 +0000 | [diff] [blame] | 308 | parentBox = createLineBoxes(parentToUse, lineInfo, box); |
bjonesbe@adobe.com | fb6ceac | 2014-04-15 00:27:13 +0000 | [diff] [blame] | 309 | } else { |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 310 | // Append the inline box to this line. |
| 311 | parentBox->addToLine(box); |
| 312 | } |
mitz@apple.com | 576e84e | 2008-04-24 19:09:48 +0000 | [diff] [blame] | 313 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 314 | bool visuallyOrdered = r->renderer().style().rtlOrdering() == VisualOrder; |
xji@chromium.org | 6b0c017 | 2011-02-14 19:21:12 +0000 | [diff] [blame] | 315 | box->setBidiLevel(r->level()); |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 316 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 317 | if (is<InlineTextBox>(*box)) { |
| 318 | auto& textBox = downcast<InlineTextBox>(*box); |
| 319 | textBox.setStart(r->m_start); |
| 320 | textBox.setLen(r->m_stop - r->m_start); |
| 321 | textBox.setDirOverride(r->dirOverride(visuallyOrdered)); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 322 | if (r->m_hasHyphen) |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 323 | textBox.setHasHyphen(true); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 324 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // We should have a root inline box. It should be unconstructed and |
| 328 | // be the last continuation of our line list. |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 329 | ASSERT(lastRootBox() && !lastRootBox()->isConstructed()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 330 | |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 331 | // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box |
| 332 | // from the bidi runs walk above has a selection state. |
| 333 | if (rootHasSelectedChildren) |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 334 | lastRootBox()->root().setHasSelectedChildren(true); |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 335 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 336 | // Set bits on our inline flow boxes that indicate which sides should |
| 337 | // paint borders/margins/padding. This knowledge will ultimately be used when |
| 338 | // we determine the horizontal positions and widths of all the inline boxes on |
| 339 | // the line. |
hyatt@apple.com | 3ab5f73 | 2016-03-25 19:25:05 +0000 | [diff] [blame^] | 340 | bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->renderer().isText() ? !reachedEndOfTextRenderer(bidiRuns) : !is<RenderInline>(bidiRuns.logicallyLastRun()->renderer()); |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 341 | lastRootBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, &bidiRuns.logicallyLastRun()->renderer()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 342 | |
| 343 | // Now mark the line boxes as being constructed. |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 344 | lastRootBox()->setConstructed(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 345 | |
| 346 | // Return the last line. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 347 | return lastRootBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 348 | } |
| 349 | |
weinig@apple.com | 6b4a2414 | 2014-01-05 00:28:39 +0000 | [diff] [blame] | 350 | ETextAlign RenderBlockFlow::textAlignmentForLine(bool endsWithSoftBreak) const |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 351 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 352 | ETextAlign alignment = style().textAlign(); |
zoltan@webkit.org | cb4f0e4 | 2014-08-13 18:00:27 +0000 | [diff] [blame] | 353 | #if ENABLE(CSS3_TEXT) |
| 354 | TextJustify textJustify = style().textJustify(); |
zoltan@webkit.org | 14989c3 | 2014-08-14 21:36:40 +0000 | [diff] [blame] | 355 | if (alignment == JUSTIFY && textJustify == TextJustifyNone) |
zoltan@webkit.org | cb4f0e4 | 2014-08-13 18:00:27 +0000 | [diff] [blame] | 356 | return style().direction() == LTR ? LEFT : RIGHT; |
| 357 | #endif |
| 358 | |
zoltan@webkit.org | cb7f93f | 2014-01-17 20:33:04 +0000 | [diff] [blame] | 359 | if (endsWithSoftBreak) |
| 360 | return alignment; |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 361 | |
zoltan@webkit.org | 14989c3 | 2014-08-14 21:36:40 +0000 | [diff] [blame] | 362 | #if !ENABLE(CSS3_TEXT) |
| 363 | return (alignment == JUSTIFY) ? TASTART : alignment; |
| 364 | #else |
zoltan@webkit.org | cb7f93f | 2014-01-17 20:33:04 +0000 | [diff] [blame] | 365 | if (alignment != JUSTIFY) |
| 366 | return alignment; |
| 367 | |
| 368 | TextAlignLast alignmentLast = style().textAlignLast(); |
| 369 | switch (alignmentLast) { |
| 370 | case TextAlignLastStart: |
| 371 | return TASTART; |
| 372 | case TextAlignLastEnd: |
| 373 | return TAEND; |
| 374 | case TextAlignLastLeft: |
| 375 | return LEFT; |
| 376 | case TextAlignLastRight: |
| 377 | return RIGHT; |
| 378 | case TextAlignLastCenter: |
| 379 | return CENTER; |
| 380 | case TextAlignLastJustify: |
| 381 | return JUSTIFY; |
| 382 | case TextAlignLastAuto: |
zoltan@webkit.org | cb4f0e4 | 2014-08-13 18:00:27 +0000 | [diff] [blame] | 383 | if (textJustify == TextJustifyDistribute) |
zoltan@webkit.org | cb7f93f | 2014-01-17 20:33:04 +0000 | [diff] [blame] | 384 | return JUSTIFY; |
| 385 | return TASTART; |
| 386 | } |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 387 | return alignment; |
zoltan@webkit.org | cb7f93f | 2014-01-17 20:33:04 +0000 | [diff] [blame] | 388 | #endif |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 389 | } |
| 390 | |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 391 | static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 392 | { |
| 393 | // The direction of the block should determine what happens with wide lines. |
| 394 | // In particular with RTL blocks, wide lines should still spill out to the left. |
| 395 | if (isLeftToRightDirection) { |
| 396 | if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 397 | trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth)); |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 398 | return; |
| 399 | } |
| 400 | |
| 401 | if (trailingSpaceRun) |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 402 | trailingSpaceRun->box()->setLogicalWidth(0); |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 403 | else if (totalLogicalWidth > availableLogicalWidth) |
| 404 | logicalLeft -= (totalLogicalWidth - availableLogicalWidth); |
| 405 | } |
| 406 | |
| 407 | static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 408 | { |
| 409 | // Wide lines spill out of the block based off direction. |
| 410 | // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right |
| 411 | // side of the block. |
| 412 | if (isLeftToRightDirection) { |
| 413 | if (trailingSpaceRun) { |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 414 | totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth(); |
| 415 | trailingSpaceRun->box()->setLogicalWidth(0); |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 416 | } |
mmaxfield@apple.com | e6da30e | 2015-07-25 03:51:06 +0000 | [diff] [blame] | 417 | logicalLeft += std::max(0.f, availableLogicalWidth - totalLogicalWidth); |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 418 | return; |
| 419 | } |
| 420 | |
| 421 | if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 422 | trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth)); |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 423 | totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth(); |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 424 | } else |
| 425 | logicalLeft += availableLogicalWidth - totalLogicalWidth; |
| 426 | } |
| 427 | |
| 428 | static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 429 | { |
| 430 | float trailingSpaceWidth = 0; |
| 431 | if (trailingSpaceRun) { |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 432 | totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth(); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 433 | trailingSpaceWidth = std::min(trailingSpaceRun->box()->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2); |
| 434 | trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceWidth)); |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 435 | } |
| 436 | if (isLeftToRightDirection) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 437 | logicalLeft += std::max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0); |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 438 | else |
| 439 | logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth; |
| 440 | } |
| 441 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 442 | void RenderBlockFlow::setMarginsForRubyRun(BidiRun* run, RenderRubyRun& renderer, RenderObject* previousObject, const LineInfo& lineInfo) |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 443 | { |
mmaxfield@apple.com | 3273fd7 | 2014-12-16 22:53:19 +0000 | [diff] [blame] | 444 | float startOverhang; |
| 445 | float endOverhang; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 446 | RenderObject* nextObject = 0; |
| 447 | for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) { |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 448 | if (!runWithNextObject->renderer().isOutOfFlowPositioned() && !runWithNextObject->box()->isLineBreak()) { |
| 449 | nextObject = &runWithNextObject->renderer(); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 450 | break; |
| 451 | } |
| 452 | } |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 453 | renderer.getOverhang(lineInfo.isFirstLine(), renderer.style().isLeftToRightDirection() ? previousObject : nextObject, renderer.style().isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 454 | setMarginStartForChild(renderer, -startOverhang); |
| 455 | setMarginEndForChild(renderer, -endOverhang); |
| 456 | } |
| 457 | |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 458 | static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText& renderer, float xPos, const LineInfo& lineInfo, |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 459 | GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements) |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 460 | { |
antti@apple.com | 5a8f794 | 2015-01-22 21:57:04 +0000 | [diff] [blame] | 461 | HashSet<const Font*> fallbackFonts; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 462 | GlyphOverflow glyphOverflow; |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 463 | |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 464 | const FontCascade& font = lineStyle(*renderer.parent(), lineInfo).fontCascade(); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 465 | // Always compute glyph overflow if the block's line-box-contain value is "glyphs". |
| 466 | if (lineBox->fitsToGlyphs()) { |
| 467 | // If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization |
| 468 | // will keep us from computing glyph bounds in nearly all cases. |
| 469 | bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading(); |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 470 | int baselineShift = lineBox->verticalPositionForBox(run->box(), verticalPositionCache); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 471 | int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0; |
| 472 | int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0; |
| 473 | int boxAscent = font.fontMetrics().ascent() - baselineShift; |
| 474 | int boxDescent = font.fontMetrics().descent() + baselineShift; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 475 | if (boxAscent > rootDescent || boxDescent > rootAscent) |
| 476 | glyphOverflow.computeBounds = true; |
| 477 | } |
| 478 | |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 479 | LayoutUnit hyphenWidth = 0; |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 480 | if (downcast<InlineTextBox>(*run->box()).hasHyphen()) |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 481 | hyphenWidth = measureHyphenWidth(renderer, font, &fallbackFonts); |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 482 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 483 | float measuredWidth = 0; |
| 484 | |
mmaxfield@apple.com | 2ef57ea | 2015-10-13 23:40:38 +0000 | [diff] [blame] | 485 | bool kerningIsEnabled = font.enableKerning(); |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 486 | bool canUseSimpleFontCodePath = renderer.canUseSimpleFontCodePath(); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 487 | |
| 488 | // Since we don't cache glyph overflows, we need to re-measure the run if |
| 489 | // the style is linebox-contain: glyph. |
| 490 | |
leviw@chromium.org | d70f4cc | 2013-03-28 21:03:44 +0000 | [diff] [blame] | 491 | if (!lineBox->fitsToGlyphs() && canUseSimpleFontCodePath) { |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 492 | int lastEndOffset = run->m_start; |
| 493 | for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOffset < run->m_stop; ++i) { |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 494 | WordMeasurement& wordMeasurement = wordMeasurements[i]; |
| 495 | if (wordMeasurement.width <= 0 || wordMeasurement.startOffset == wordMeasurement.endOffset) |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 496 | continue; |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 497 | if (wordMeasurement.renderer != &renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop) |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 498 | continue; |
| 499 | |
| 500 | lastEndOffset = wordMeasurement.endOffset; |
| 501 | if (kerningIsEnabled && lastEndOffset == run->m_stop) { |
dino@apple.com | 7c50e7c | 2013-03-18 18:01:05 +0000 | [diff] [blame] | 502 | int wordLength = lastEndOffset - wordMeasurement.startOffset; |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 503 | GlyphOverflow overflow; |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 504 | measuredWidth += renderer.width(wordMeasurement.startOffset, wordLength, xPos + measuredWidth, lineInfo.isFirstLine(), |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 505 | &wordMeasurement.fallbackFonts, &overflow); |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 506 | UChar c = renderer.characterAt(wordMeasurement.startOffset); |
dino@apple.com | d0b8925 | 2013-05-10 18:20:28 +0000 | [diff] [blame] | 507 | if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t')) |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 508 | measuredWidth += renderer.style().fontCascade().wordSpacing(); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 509 | } else |
| 510 | measuredWidth += wordMeasurement.width; |
| 511 | if (!wordMeasurement.fallbackFonts.isEmpty()) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 512 | HashSet<const Font*>::const_iterator end = wordMeasurement.fallbackFonts.end(); |
| 513 | for (HashSet<const Font*>::const_iterator it = wordMeasurement.fallbackFonts.begin(); it != end; ++it) |
| 514 | fallbackFonts.add(*it); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | if (measuredWidth && lastEndOffset != run->m_stop) { |
| 518 | // If we don't have enough cached data, we'll measure the run again. |
| 519 | measuredWidth = 0; |
| 520 | fallbackFonts.clear(); |
| 521 | } |
| 522 | } |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 523 | |
| 524 | if (!measuredWidth) |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 525 | measuredWidth = renderer.width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 526 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 527 | run->box()->setLogicalWidth(measuredWidth + hyphenWidth); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 528 | if (!fallbackFonts.isEmpty()) { |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 529 | ASSERT(run->box()->behavesLikeText()); |
antti@apple.com | 5a8f794 | 2015-01-22 21:57:04 +0000 | [diff] [blame] | 530 | GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(downcast<InlineTextBox>(run->box()), std::make_pair(Vector<const Font*>(), GlyphOverflow())).iterator; |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 531 | ASSERT(it->value.first.isEmpty()); |
| 532 | copyToVector(fallbackFonts, it->value.first); |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 533 | run->box()->parent()->clearDescendantsHaveSameLineHeightAndBaseline(); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 534 | } |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 535 | |
| 536 | // Include text decoration visual overflow as part of the glyph overflow. |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 537 | if (renderer.style().textDecorationsInEffect() != TextDecorationNone) |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 538 | glyphOverflow.extendTo(visualOverflowForDecorations(run->box()->lineStyle(), downcast<InlineTextBox>(run->box()))); |
mmaxfield@apple.com | f28245e | 2014-05-20 00:45:52 +0000 | [diff] [blame] | 539 | |
| 540 | if (!glyphOverflow.isEmpty()) { |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 541 | ASSERT(run->box()->behavesLikeText()); |
antti@apple.com | 5a8f794 | 2015-01-22 21:57:04 +0000 | [diff] [blame] | 542 | GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(downcast<InlineTextBox>(run->box()), std::make_pair(Vector<const Font*>(), GlyphOverflow())).iterator; |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 543 | it->value.second = glyphOverflow; |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 544 | run->box()->clearKnownToHaveNoOverflow(); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | |
mmaxfield@apple.com | b2c6d86 | 2015-02-18 19:39:17 +0000 | [diff] [blame] | 548 | void RenderBlockFlow::updateRubyForJustifiedText(RenderRubyRun& rubyRun, BidiRun& r, const Vector<unsigned, 16>& expansionOpportunities, unsigned& expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth, size_t& i) |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 549 | { |
| 550 | if (!rubyRun.rubyBase() || !rubyRun.rubyBase()->firstRootBox() || rubyRun.rubyBase()->firstRootBox()->nextRootBox() || !r.renderer().style().collapseWhiteSpace()) |
| 551 | return; |
| 552 | |
| 553 | auto& rubyBase = *rubyRun.rubyBase(); |
| 554 | auto& rootBox = *rubyBase.firstRootBox(); |
| 555 | |
| 556 | float totalExpansion = 0; |
| 557 | unsigned totalOpportunitiesInRun = 0; |
| 558 | for (auto* leafChild = rootBox.firstLeafChild(); leafChild; leafChild = leafChild->nextLeafChild()) { |
| 559 | if (!leafChild->isInlineTextBox()) |
| 560 | continue; |
| 561 | |
| 562 | unsigned opportunitiesInRun = expansionOpportunities[i++]; |
| 563 | ASSERT(opportunitiesInRun <= expansionOpportunityCount); |
| 564 | auto expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount; |
| 565 | totalExpansion += expansion; |
| 566 | totalOpportunitiesInRun += opportunitiesInRun; |
| 567 | } |
| 568 | |
rego@igalia.com | f7d624c | 2015-04-22 10:31:24 +0000 | [diff] [blame] | 569 | ASSERT(!rubyRun.hasOverrideLogicalContentWidth()); |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 570 | float newBaseWidth = rubyRun.logicalWidth() + totalExpansion + marginStartForChild(rubyRun) + marginEndForChild(rubyRun); |
| 571 | float newRubyRunWidth = rubyRun.logicalWidth() + totalExpansion; |
| 572 | rubyBase.setInitialOffset((newRubyRunWidth - newBaseWidth) / 2); |
| 573 | rubyRun.setOverrideLogicalContentWidth(newRubyRunWidth); |
| 574 | rubyRun.setNeedsLayout(MarkOnlyThis); |
| 575 | rootBox.markDirty(); |
| 576 | if (RenderRubyText* rubyText = rubyRun.rubyText()) { |
| 577 | if (RootInlineBox* textRootBox = rubyText->firstRootBox()) |
| 578 | textRootBox->markDirty(); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 579 | } |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 580 | rubyRun.layoutBlock(true); |
| 581 | rubyRun.clearOverrideLogicalContentWidth(); |
| 582 | r.box()->setExpansion(newRubyRunWidth - r.box()->logicalWidth()); |
| 583 | |
| 584 | // This relayout caused the size of the RenderRubyText and the RenderRubyBase to change, dependent on the line's current expansion. Next time we relayout the |
| 585 | // RenderRubyRun, make sure that we relayout the RenderRubyBase and RenderRubyText as well. |
| 586 | rubyBase.setNeedsLayout(MarkOnlyThis); |
| 587 | if (RenderRubyText* rubyText = rubyRun.rubyText()) |
| 588 | rubyText->setNeedsLayout(MarkOnlyThis); |
| 589 | |
| 590 | totalLogicalWidth += totalExpansion; |
| 591 | expansionOpportunityCount -= totalOpportunitiesInRun; |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 592 | } |
| 593 | |
mmaxfield@apple.com | b2c6d86 | 2015-02-18 19:39:17 +0000 | [diff] [blame] | 594 | void RenderBlockFlow::computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, const Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float totalLogicalWidth, float availableLogicalWidth) |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 595 | { |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 596 | if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth) |
| 597 | return; |
| 598 | |
| 599 | size_t i = 0; |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 600 | for (BidiRun* run = firstRun; run; run = run->next()) { |
mmaxfield@apple.com | b2c6d86 | 2015-02-18 19:39:17 +0000 | [diff] [blame] | 601 | if (!run->box() || run == trailingSpaceRun) |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 602 | continue; |
| 603 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 604 | if (is<RenderText>(run->renderer())) { |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 605 | unsigned opportunitiesInRun = expansionOpportunities[i++]; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 606 | |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 607 | ASSERT(opportunitiesInRun <= expansionOpportunityCount); |
| 608 | |
| 609 | // Only justify text if whitespace is collapsed. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 610 | if (run->renderer().style().collapseWhiteSpace()) { |
| 611 | InlineTextBox& textBox = downcast<InlineTextBox>(*run->box()); |
mmaxfield@apple.com | a9f58d0 | 2014-10-02 22:25:50 +0000 | [diff] [blame] | 612 | float expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount; |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 613 | textBox.setExpansion(expansion); |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 614 | totalLogicalWidth += expansion; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 615 | } |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 616 | expansionOpportunityCount -= opportunitiesInRun; |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 617 | } else if (is<RenderRubyRun>(run->renderer())) |
mmaxfield@apple.com | b2c6d86 | 2015-02-18 19:39:17 +0000 | [diff] [blame] | 618 | updateRubyForJustifiedText(downcast<RenderRubyRun>(run->renderer()), *run, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth, i); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 619 | |
| 620 | if (!expansionOpportunityCount) |
| 621 | break; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 625 | void RenderBlockFlow::updateLogicalWidthForAlignment(const ETextAlign& textAlign, const RootInlineBox* rootInlineBox, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount) |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 626 | { |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 627 | TextDirection direction; |
| 628 | if (rootInlineBox && style().unicodeBidi() == Plaintext) |
| 629 | direction = rootInlineBox->direction(); |
| 630 | else |
| 631 | direction = style().direction(); |
| 632 | |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 633 | // Armed with the total width of the line (without justification), |
| 634 | // we now examine our text-align property in order to determine where to position the |
| 635 | // objects horizontally. The total width of the line can be increased if we end up |
| 636 | // justifying text. |
| 637 | switch (textAlign) { |
| 638 | case LEFT: |
| 639 | case WEBKIT_LEFT: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 640 | updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 641 | break; |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 642 | case RIGHT: |
| 643 | case WEBKIT_RIGHT: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 644 | updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 645 | break; |
| 646 | case CENTER: |
| 647 | case WEBKIT_CENTER: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 648 | updateLogicalWidthForCenterAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 649 | break; |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 650 | case JUSTIFY: |
| 651 | adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth); |
| 652 | if (expansionOpportunityCount) { |
| 653 | if (trailingSpaceRun) { |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 654 | totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth(); |
| 655 | trailingSpaceRun->box()->setLogicalWidth(0); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 656 | } |
| 657 | break; |
| 658 | } |
joepeck@webkit.org | aa676ee5 | 2014-01-28 04:04:52 +0000 | [diff] [blame] | 659 | FALLTHROUGH; |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 660 | case TASTART: |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 661 | if (direction == LTR) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 662 | updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 663 | else |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 664 | updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 665 | break; |
| 666 | case TAEND: |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 667 | if (direction == LTR) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 668 | updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 669 | else |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 670 | updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 671 | break; |
| 672 | } |
| 673 | } |
| 674 | |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 675 | static void updateLogicalInlinePositions(RenderBlockFlow& block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, |
| 676 | IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight, RootInlineBox* rootBox) |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 677 | { |
weinig@apple.com | e9621c3 | 2014-01-04 20:53:51 +0000 | [diff] [blame] | 678 | LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight); |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 679 | if (rootBox->hasAnonymousInlineBlock()) { |
| 680 | lineLogicalLeft = block.logicalLeftOffsetForContent(block.logicalHeight()); |
| 681 | lineLogicalRight = block.logicalRightOffsetForContent(block.logicalHeight()); |
| 682 | } else { |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 683 | lineLogicalLeft = block.logicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText, lineLogicalHeight); |
| 684 | lineLogicalRight = block.logicalRightOffsetForLine(block.logicalHeight(), shouldIndentText, lineLogicalHeight); |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 685 | } |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 686 | availableLogicalWidth = lineLogicalRight - lineLogicalLeft; |
| 687 | } |
| 688 | |
weinig@apple.com | e9621c3 | 2014-01-04 20:53:51 +0000 | [diff] [blame] | 689 | void RenderBlockFlow::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, const LineInfo& lineInfo, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 690 | { |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 691 | ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak()); |
robert@webkit.org | 4f76df9 | 2012-07-03 17:41:35 +0000 | [diff] [blame] | 692 | |
robert@webkit.org | 328ecd0 | 2012-08-09 21:12:44 +0000 | [diff] [blame] | 693 | // CSS 2.1: "'Text-indent' only affects a line if it is the first formatted line of an element. For example, the first line of an anonymous block |
| 694 | // box is only affected if it is the first child of its parent element." |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 695 | // CSS3 "text-indent", "-webkit-each-line" affects the first line of the block container as well as each line after a forced line break, |
| 696 | // but does not affect lines after a soft wrap break. |
| 697 | bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this); |
| 698 | bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox()->endsWithBreak(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 699 | IndentTextOrNot shouldIndentText = requiresIndent(isFirstLine, isAfterHardLineBreak, style()); |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 700 | float lineLogicalLeft; |
| 701 | float lineLogicalRight; |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 702 | float availableLogicalWidth; |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 703 | updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0, lineBox); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 704 | bool needsWordSpacing; |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 705 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 706 | if (firstRun && firstRun->renderer().isReplaced()) { |
cdumez@apple.com | 0abff8b | 2014-10-17 21:25:10 +0000 | [diff] [blame] | 707 | RenderBox& renderBox = downcast<RenderBox>(firstRun->renderer()); |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 708 | updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight(), lineBox); |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 712 | // The widths of all runs are now known. We can now place every inline box (and |
| 713 | // compute accurate widths for the inline flow boxes). |
| 714 | needsWordSpacing = false; |
mmaxfield@apple.com | b0a4a3f | 2014-04-30 00:36:21 +0000 | [diff] [blame] | 715 | lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 716 | } |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 717 | |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 718 | static inline ExpansionBehavior expansionBehaviorForInlineTextBox(RenderBlockFlow& block, InlineTextBox& textBox, BidiRun* previousRun, BidiRun* nextRun, ETextAlign textAlign, bool isAfterExpansion) |
mmaxfield@apple.com | 43761a7 | 2015-04-01 16:58:20 +0000 | [diff] [blame] | 719 | { |
mmaxfield@apple.com | 5a572b1 | 2015-11-06 23:20:12 +0000 | [diff] [blame] | 720 | // Tatechuyoko is modeled as the Object Replacement Character (U+FFFC), which can never have expansion opportunities inside nor intrinsically adjacent to it. |
| 721 | if (textBox.renderer().style().textCombine() == TextCombineHorizontal) |
| 722 | return ForbidLeadingExpansion | ForbidTrailingExpansion; |
| 723 | |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 724 | ExpansionBehavior result = 0; |
| 725 | bool setLeadingExpansion = false; |
| 726 | bool setTrailingExpansion = false; |
| 727 | if (textAlign == JUSTIFY) { |
mmaxfield@apple.com | 5a572b1 | 2015-11-06 23:20:12 +0000 | [diff] [blame] | 728 | // If the next box is ruby, and we're justifying, and the first box in the ruby base has a leading expansion, and we are a text box, then force a trailing expansion. |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 729 | if (nextRun && is<RenderRubyRun>(nextRun->renderer()) && downcast<RenderRubyRun>(nextRun->renderer()).rubyBase() && nextRun->renderer().style().collapseWhiteSpace()) { |
| 730 | auto& rubyBase = *downcast<RenderRubyRun>(nextRun->renderer()).rubyBase(); |
| 731 | if (rubyBase.firstRootBox() && !rubyBase.firstRootBox()->nextRootBox()) { |
| 732 | if (auto* leafChild = rubyBase.firstRootBox()->firstLeafChild()) { |
| 733 | if (is<InlineTextBox>(*leafChild)) { |
| 734 | // FIXME: This leadingExpansionOpportunity doesn't actually work because it doesn't perform the UBA |
| 735 | if (FontCascade::leadingExpansionOpportunity(downcast<RenderText>(leafChild->renderer()).stringView(), leafChild->direction())) { |
| 736 | setTrailingExpansion = true; |
| 737 | result |= ForceTrailingExpansion; |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | // Same thing, except if we're following a ruby |
| 744 | if (previousRun && is<RenderRubyRun>(previousRun->renderer()) && downcast<RenderRubyRun>(previousRun->renderer()).rubyBase() && previousRun->renderer().style().collapseWhiteSpace()) { |
| 745 | auto& rubyBase = *downcast<RenderRubyRun>(previousRun->renderer()).rubyBase(); |
| 746 | if (rubyBase.firstRootBox() && !rubyBase.firstRootBox()->nextRootBox()) { |
| 747 | if (auto* leafChild = rubyBase.firstRootBox()->lastLeafChild()) { |
| 748 | if (is<InlineTextBox>(*leafChild)) { |
| 749 | // FIXME: This leadingExpansionOpportunity doesn't actually work because it doesn't perform the UBA |
| 750 | if (FontCascade::trailingExpansionOpportunity(downcast<RenderText>(leafChild->renderer()).stringView(), leafChild->direction())) { |
| 751 | setLeadingExpansion = true; |
| 752 | result |= ForceLeadingExpansion; |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | // If we're the first box inside a ruby base, forbid a leading expansion, and vice-versa |
| 759 | if (is<RenderRubyBase>(block)) { |
| 760 | RenderRubyBase& rubyBase = downcast<RenderRubyBase>(block); |
| 761 | if (&textBox == rubyBase.firstRootBox()->firstLeafChild()) { |
| 762 | setLeadingExpansion = true; |
| 763 | result |= ForbidLeadingExpansion; |
| 764 | } if (&textBox == rubyBase.firstRootBox()->lastLeafChild()) { |
| 765 | setTrailingExpansion = true; |
| 766 | result |= ForbidTrailingExpansion; |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | if (!setLeadingExpansion) |
| 771 | result |= isAfterExpansion ? ForbidLeadingExpansion : AllowLeadingExpansion; |
| 772 | if (!setTrailingExpansion) |
| 773 | result |= AllowTrailingExpansion; |
mmaxfield@apple.com | 43761a7 | 2015-04-01 16:58:20 +0000 | [diff] [blame] | 774 | return result; |
| 775 | } |
| 776 | |
| 777 | static inline void applyExpansionBehavior(InlineTextBox& textBox, ExpansionBehavior expansionBehavior) |
| 778 | { |
| 779 | switch (expansionBehavior & LeadingExpansionMask) { |
| 780 | case ForceLeadingExpansion: |
| 781 | textBox.setForceLeadingExpansion(); |
| 782 | break; |
| 783 | case ForbidLeadingExpansion: |
| 784 | textBox.setCanHaveLeadingExpansion(false); |
| 785 | break; |
| 786 | case AllowLeadingExpansion: |
| 787 | textBox.setCanHaveLeadingExpansion(true); |
| 788 | break; |
| 789 | default: |
| 790 | ASSERT_NOT_REACHED(); |
| 791 | break; |
| 792 | } |
| 793 | switch (expansionBehavior & TrailingExpansionMask) { |
| 794 | case ForceTrailingExpansion: |
| 795 | textBox.setForceTrailingExpansion(); |
| 796 | break; |
| 797 | case ForbidTrailingExpansion: |
| 798 | textBox.setCanHaveTrailingExpansion(false); |
| 799 | break; |
| 800 | case AllowTrailingExpansion: |
| 801 | textBox.setCanHaveTrailingExpansion(true); |
| 802 | break; |
| 803 | default: |
| 804 | ASSERT_NOT_REACHED(); |
| 805 | break; |
| 806 | } |
| 807 | } |
| 808 | |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 809 | static bool inlineAncestorHasStartBorderPaddingOrMargin(const RenderBlockFlow& block, const InlineBox& box) |
| 810 | { |
| 811 | bool isLTR = block.style().isLeftToRightDirection(); |
| 812 | for (auto* currentBox = box.parent(); currentBox; currentBox = currentBox->parent()) { |
| 813 | if ((isLTR && currentBox->marginBorderPaddingLogicalLeft() > 0) |
| 814 | || (!isLTR && currentBox->marginBorderPaddingLogicalRight() > 0)) |
| 815 | return true; |
| 816 | } |
| 817 | return false; |
| 818 | } |
| 819 | |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 820 | static bool inlineAncestorHasEndBorderPaddingOrMargin(const RenderBlockFlow& block, const InlineBox& box) |
| 821 | { |
| 822 | bool isLTR = block.style().isLeftToRightDirection(); |
| 823 | for (auto* currentBox = box.parent(); currentBox; currentBox = currentBox->parent()) { |
| 824 | if ((isLTR && currentBox->marginBorderPaddingLogicalRight() > 0) |
| 825 | || (!isLTR && currentBox->marginBorderPaddingLogicalLeft() > 0)) |
| 826 | return true; |
| 827 | } |
| 828 | return false; |
| 829 | } |
| 830 | |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 831 | static bool isLastInFlowRun(BidiRun& runToCheck) |
| 832 | { |
| 833 | for (auto* run = runToCheck.next(); run; run = run->next()) { |
| 834 | if (!run->box() || run->renderer().isOutOfFlowPositioned() || run->box()->isLineBreak()) |
| 835 | continue; |
| 836 | return false; |
| 837 | } |
| 838 | return true; |
| 839 | } |
| 840 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 841 | BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBox* lineBox, const LineInfo& lineInfo, ETextAlign textAlign, float& logicalLeft, |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 842 | float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, |
| 843 | WordMeasurements& wordMeasurements) |
| 844 | { |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 845 | bool needsWordSpacing = false; |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 846 | bool canHangPunctuationAtStart = style().hangingPunctuation() & FirstHangingPunctuation; |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 847 | bool canHangPunctuationAtEnd = style().hangingPunctuation() & LastHangingPunctuation; |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 848 | bool isLTR = style().isLeftToRightDirection(); |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 849 | float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth(); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 850 | unsigned expansionOpportunityCount = 0; |
commit-queue@webkit.org | 01ad584 | 2014-12-16 19:28:57 +0000 | [diff] [blame] | 851 | bool isAfterExpansion = is<RenderRubyBase>(*this) ? downcast<RenderRubyBase>(*this).isAfterExpansion() : true; |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 852 | Vector<unsigned, 16> expansionOpportunities; |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 853 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 854 | BidiRun* run = firstRun; |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 855 | BidiRun* previousRun = nullptr; |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 856 | for (; run; run = run->next()) { |
| 857 | if (!run->box() || run->renderer().isOutOfFlowPositioned() || run->box()->isLineBreak()) { |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 858 | continue; // Positioned objects are only participating to figure out their |
| 859 | // correct static x position. They have no effect on the width. |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 860 | // Similarly, line break boxes have no effect on the width. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 861 | } |
| 862 | if (is<RenderText>(run->renderer())) { |
| 863 | auto& renderText = downcast<RenderText>(run->renderer()); |
mmaxfield@apple.com | 43761a7 | 2015-04-01 16:58:20 +0000 | [diff] [blame] | 864 | auto& textBox = downcast<InlineTextBox>(*run->box()); |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 865 | if (canHangPunctuationAtStart && lineInfo.isFirstLine() && (isLTR || isLastInFlowRun(*run)) |
| 866 | && !inlineAncestorHasStartBorderPaddingOrMargin(*this, *run->box())) { |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 867 | float hangStartWidth = renderText.hangablePunctuationStartWidth(run->m_start); |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 868 | availableLogicalWidth += hangStartWidth; |
| 869 | if (style().isLeftToRightDirection()) |
| 870 | logicalLeft -= hangStartWidth; |
| 871 | canHangPunctuationAtStart = false; |
| 872 | } |
| 873 | |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 874 | if (canHangPunctuationAtEnd && lineInfo.isLastLine() && run->m_stop > 0 && (!isLTR || isLastInFlowRun(*run)) |
| 875 | && !inlineAncestorHasEndBorderPaddingOrMargin(*this, *run->box())) { |
| 876 | float hangEndWidth = renderText.hangablePunctuationEndWidth(run->m_stop - 1); |
| 877 | availableLogicalWidth += hangEndWidth; |
| 878 | if (!style().isLeftToRightDirection()) |
| 879 | logicalLeft -= hangEndWidth; |
| 880 | canHangPunctuationAtEnd = false; |
| 881 | } |
| 882 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 883 | if (textAlign == JUSTIFY && run != trailingSpaceRun) { |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 884 | ExpansionBehavior expansionBehavior = expansionBehaviorForInlineTextBox(*this, textBox, previousRun, run->next(), textAlign, isAfterExpansion); |
mmaxfield@apple.com | 43761a7 | 2015-04-01 16:58:20 +0000 | [diff] [blame] | 885 | applyExpansionBehavior(textBox, expansionBehavior); |
| 886 | unsigned opportunitiesInRun; |
| 887 | std::tie(opportunitiesInRun, isAfterExpansion) = FontCascade::expansionOpportunityCount(renderText.stringView(run->m_start, run->m_stop), run->box()->direction(), expansionBehavior); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 888 | expansionOpportunities.append(opportunitiesInRun); |
| 889 | expansionOpportunityCount += opportunitiesInRun; |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 890 | } |
| 891 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 892 | if (int length = renderText.textLength()) { |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 893 | if (!run->m_start && needsWordSpacing && isSpaceOrNewline(renderText.characterAt(run->m_start))) |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +0000 | [diff] [blame] | 894 | totalLogicalWidth += lineStyle(*renderText.parent(), lineInfo).fontCascade().wordSpacing(); |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 895 | needsWordSpacing = !isSpaceOrNewline(renderText.characterAt(run->m_stop - 1)) && run->m_stop == length; |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 896 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 897 | |
mmaxfield@apple.com | 16fc17b | 2015-03-05 19:51:05 +0000 | [diff] [blame] | 898 | setLogicalWidthForTextRun(lineBox, run, renderText, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 899 | } else { |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 900 | canHangPunctuationAtStart = false; |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 901 | bool encounteredJustifiedRuby = false; |
cdumez@apple.com | 3abcc79 | 2014-10-20 03:42:03 +0000 | [diff] [blame] | 902 | if (is<RenderRubyRun>(run->renderer()) && textAlign == JUSTIFY && run != trailingSpaceRun && downcast<RenderRubyRun>(run->renderer()).rubyBase()) { |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 903 | auto* rubyBase = downcast<RenderRubyRun>(run->renderer()).rubyBase(); |
| 904 | if (rubyBase->firstRootBox() && !rubyBase->firstRootBox()->nextRootBox() && run->renderer().style().collapseWhiteSpace()) { |
commit-queue@webkit.org | 01ad584 | 2014-12-16 19:28:57 +0000 | [diff] [blame] | 905 | rubyBase->setIsAfterExpansion(isAfterExpansion); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 906 | for (auto* leafChild = rubyBase->firstRootBox()->firstLeafChild(); leafChild; leafChild = leafChild->nextLeafChild()) { |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 907 | if (!is<InlineTextBox>(*leafChild)) |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 908 | continue; |
mmaxfield@apple.com | 43761a7 | 2015-04-01 16:58:20 +0000 | [diff] [blame] | 909 | auto& textBox = downcast<InlineTextBox>(*leafChild); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 910 | encounteredJustifiedRuby = true; |
| 911 | auto& renderText = downcast<RenderText>(leafChild->renderer()); |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 912 | ExpansionBehavior expansionBehavior = expansionBehaviorForInlineTextBox(*rubyBase, textBox, nullptr, nullptr, textAlign, isAfterExpansion); |
mmaxfield@apple.com | 43761a7 | 2015-04-01 16:58:20 +0000 | [diff] [blame] | 913 | applyExpansionBehavior(textBox, expansionBehavior); |
| 914 | unsigned opportunitiesInRun; |
| 915 | std::tie(opportunitiesInRun, isAfterExpansion) = FontCascade::expansionOpportunityCount(renderText.stringView(), leafChild->direction(), expansionBehavior); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 916 | expansionOpportunities.append(opportunitiesInRun); |
| 917 | expansionOpportunityCount += opportunitiesInRun; |
| 918 | } |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | if (!encounteredJustifiedRuby) |
| 923 | isAfterExpansion = false; |
| 924 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 925 | if (!is<RenderInline>(run->renderer())) { |
| 926 | auto& renderBox = downcast<RenderBox>(run->renderer()); |
| 927 | if (is<RenderRubyRun>(renderBox)) |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 928 | setMarginsForRubyRun(run, downcast<RenderRubyRun>(renderBox), previousRun ? &previousRun->renderer() : nullptr, lineInfo); |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 929 | run->box()->setLogicalWidth(logicalWidthForChild(renderBox)); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 930 | totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox); |
| 931 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 932 | } |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 933 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 934 | totalLogicalWidth += run->box()->logicalWidth(); |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 935 | previousRun = run; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 936 | } |
| 937 | |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 938 | if (isAfterExpansion && !expansionOpportunities.isEmpty()) { |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 939 | expansionOpportunities.last()--; |
| 940 | expansionOpportunityCount--; |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 941 | } |
| 942 | |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 943 | if (is<RenderRubyBase>(*this) && !expansionOpportunityCount) |
| 944 | textAlign = CENTER; |
| 945 | |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 946 | updateLogicalWidthForAlignment(textAlign, lineBox, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 947 | |
mmaxfield@apple.com | b2c6d86 | 2015-02-18 19:39:17 +0000 | [diff] [blame] | 948 | computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 949 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 950 | return run; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 951 | } |
| 952 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 953 | void RenderBlockFlow::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 954 | VerticalPositionCache& verticalPositionCache) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 955 | { |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 956 | setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache)); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 957 | |
| 958 | // Now make sure we place replaced render objects correctly. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 959 | for (BidiRun* run = firstRun; run; run = run->next()) { |
| 960 | ASSERT(run->box()); |
| 961 | if (!run->box()) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 962 | continue; // Skip runs with no line boxes. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 963 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 964 | InlineBox& box = *run->box(); |
akling@apple.com | 27e7d14 | 2013-11-07 12:04:02 +0000 | [diff] [blame] | 965 | |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 966 | // Align positioned boxes with the top of the line box. This is |
| 967 | // a reasonable approximation of an appropriate y position. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 968 | if (run->renderer().isOutOfFlowPositioned()) |
akling@apple.com | 27e7d14 | 2013-11-07 12:04:02 +0000 | [diff] [blame] | 969 | box.setLogicalTop(logicalHeight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 970 | |
| 971 | // Position is used to properly position both replaced elements and |
| 972 | // to update the static normal flow x/y of positioned elements. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 973 | if (is<RenderText>(run->renderer())) |
| 974 | downcast<RenderText>(run->renderer()).positionLineBox(downcast<InlineTextBox>(box)); |
| 975 | else if (is<RenderBox>(run->renderer())) |
| 976 | downcast<RenderBox>(run->renderer()).positionLineBox(downcast<InlineElementBox>(box)); |
| 977 | else if (is<RenderLineBreak>(run->renderer())) |
| 978 | downcast<RenderLineBreak>(run->renderer()).replaceInlineBoxWrapper(downcast<InlineElementBox>(box)); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 979 | } |
mitz@apple.com | a927be6 | 2008-03-21 05:30:19 +0000 | [diff] [blame] | 980 | // Positioned objects and zero-length text nodes destroy their boxes in |
| 981 | // position(), which unnecessarily dirties the line. |
| 982 | lineBox->markDirty(false); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 983 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 984 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 985 | static inline bool isCollapsibleSpace(UChar character, const RenderText& renderer) |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 986 | { |
| 987 | if (character == ' ' || character == '\t' || character == softHyphen) |
| 988 | return true; |
| 989 | if (character == '\n') |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 990 | return !renderer.style().preserveNewline(); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 991 | if (character == noBreakSpace) |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 992 | return renderer.style().nbspMode() == SPACE; |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 993 | return false; |
| 994 | } |
| 995 | |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 996 | template <typename CharacterType> |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 997 | static inline int findFirstTrailingSpace(const RenderText& lastText, const CharacterType* characters, int start, int stop) |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 998 | { |
| 999 | int firstSpace = stop; |
| 1000 | while (firstSpace > start) { |
| 1001 | UChar current = characters[firstSpace - 1]; |
| 1002 | if (!isCollapsibleSpace(current, lastText)) |
| 1003 | break; |
| 1004 | firstSpace--; |
| 1005 | } |
| 1006 | |
| 1007 | return firstSpace; |
| 1008 | } |
| 1009 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1010 | inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext) |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1011 | { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1012 | if (!bidiRuns.runCount() |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 1013 | || !bidiRuns.logicallyLastRun()->renderer().style().breakOnlyAfterWhiteSpace() |
| 1014 | || !bidiRuns.logicallyLastRun()->renderer().style().autoWrap()) |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 1015 | return nullptr; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1016 | |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1017 | BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun(); |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 1018 | const RenderObject& lastObject = trailingSpaceRun->renderer(); |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 1019 | if (!is<RenderText>(lastObject)) |
| 1020 | return nullptr; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1021 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 1022 | const RenderText& lastText = downcast<RenderText>(lastObject); |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 1023 | int firstSpace; |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 1024 | if (lastText.is8Bit()) |
| 1025 | firstSpace = findFirstTrailingSpace(lastText, lastText.characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop()); |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 1026 | else |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 1027 | firstSpace = findFirstTrailingSpace(lastText, lastText.characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop()); |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 1028 | |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1029 | if (firstSpace == trailingSpaceRun->stop()) |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 1030 | return nullptr; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1031 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1032 | TextDirection direction = style().direction(); |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1033 | bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun()); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1034 | if (firstSpace != trailingSpaceRun->start()) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1035 | BidiContext* baseContext = currentContext; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1036 | while (BidiContext* parent = baseContext->parent()) |
| 1037 | baseContext = parent; |
| 1038 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 1039 | BidiRun* newTrailingRun = new BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->renderer(), baseContext, U_OTHER_NEUTRAL); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1040 | trailingSpaceRun->m_stop = firstSpace; |
| 1041 | if (direction == LTR) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1042 | bidiRuns.addRun(newTrailingRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1043 | else |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1044 | bidiRuns.prependRun(newTrailingRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1045 | trailingSpaceRun = newTrailingRun; |
| 1046 | return trailingSpaceRun; |
| 1047 | } |
| 1048 | if (!shouldReorder) |
| 1049 | return trailingSpaceRun; |
| 1050 | |
| 1051 | if (direction == LTR) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1052 | bidiRuns.moveRunToEnd(trailingSpaceRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1053 | trailingSpaceRun->m_level = 0; |
| 1054 | } else { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1055 | bidiRuns.moveRunToBeginning(trailingSpaceRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1056 | trailingSpaceRun->m_level = 1; |
| 1057 | } |
| 1058 | return trailingSpaceRun; |
| 1059 | } |
| 1060 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1061 | void RenderBlockFlow::appendFloatingObjectToLastLine(FloatingObject* floatingObject) |
mitz@apple.com | d17e8c0 | 2011-04-16 21:59:36 +0000 | [diff] [blame] | 1062 | { |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 1063 | ASSERT(!floatingObject->originatingLine()); |
| 1064 | floatingObject->setOriginatingLine(lastRootBox()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1065 | lastRootBox()->appendFloat(floatingObject->renderer()); |
mitz@apple.com | d17e8c0 | 2011-04-16 21:59:36 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 1068 | static inline void notifyResolverToResumeInIsolate(InlineBidiResolver& resolver, RenderObject* root, RenderObject* startObject) |
mmaxfield@apple.com | 18782a2 | 2014-01-28 21:53:22 +0000 | [diff] [blame] | 1069 | { |
| 1070 | if (root != startObject) { |
| 1071 | RenderObject* parent = startObject->parent(); |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 1072 | notifyResolverToResumeInIsolate(resolver, root, parent); |
mmaxfield@apple.com | 18782a2 | 2014-01-28 21:53:22 +0000 | [diff] [blame] | 1073 | notifyObserverEnteredObject(&resolver, startObject); |
| 1074 | } |
| 1075 | } |
| 1076 | |
mmaxfield@apple.com | 0fba19a | 2015-09-16 00:30:38 +0000 | [diff] [blame] | 1077 | static inline void setUpResolverToResumeInIsolate(InlineBidiResolver& resolver, InlineBidiResolver& topResolver, BidiRun& isolatedRun, RenderObject* root, RenderObject* startObject) |
mmaxfield@apple.com | ff5b7ac | 2015-07-10 20:39:16 +0000 | [diff] [blame] | 1078 | { |
| 1079 | // Set up m_midpointState |
| 1080 | resolver.midpointState() = topResolver.midpointState(); |
| 1081 | resolver.midpointState().setCurrentMidpoint(topResolver.midpointForIsolatedRun(isolatedRun)); |
| 1082 | |
| 1083 | // Set up m_nestedIsolateCount |
| 1084 | notifyResolverToResumeInIsolate(resolver, root, startObject); |
| 1085 | } |
| 1086 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1087 | // FIXME: BidiResolver should have this logic. |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1088 | static inline void constructBidiRunsForSegment(InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfRuns, VisualDirectionOverride override, bool previousLineBrokeCleanly) |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1089 | { |
| 1090 | // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead |
| 1091 | // of the resolver owning the runs. |
| 1092 | ASSERT(&topResolver.runs() == &bidiRuns); |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1093 | ASSERT(topResolver.position() != endOfRuns); |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1094 | RenderObject* currentRoot = topResolver.position().root(); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1095 | topResolver.createBidiRunsForLine(endOfRuns, override, previousLineBrokeCleanly); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1096 | |
| 1097 | while (!topResolver.isolatedRuns().isEmpty()) { |
| 1098 | // It does not matter which order we resolve the runs as long as we resolve them all. |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 1099 | auto isolatedRun = WTFMove(topResolver.isolatedRuns().last()); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1100 | topResolver.isolatedRuns().removeLast(); |
mmaxfield@apple.com | 0fba19a | 2015-09-16 00:30:38 +0000 | [diff] [blame] | 1101 | currentRoot = &isolatedRun.root; |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1102 | |
mmaxfield@apple.com | 0fba19a | 2015-09-16 00:30:38 +0000 | [diff] [blame] | 1103 | RenderObject& startObject = isolatedRun.object; |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1104 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1105 | // Only inlines make sense with unicode-bidi: isolate (blocks are already isolated). |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1106 | // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the |
| 1107 | // tree to see which parent inline is the isolate. We could change enterIsolate |
| 1108 | // to take a RenderObject and do this logic there, but that would be a layering |
| 1109 | // violation for BidiResolver (which knows nothing about RenderObject). |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 1110 | RenderInline* isolatedInline = downcast<RenderInline>(highestContainingIsolateWithinRoot(startObject, currentRoot)); |
ddkilzer@apple.com | ad6ad36 | 2014-04-02 17:21:09 +0000 | [diff] [blame] | 1111 | ASSERT(isolatedInline); |
| 1112 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1113 | InlineBidiResolver isolatedResolver; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1114 | EUnicodeBidi unicodeBidi = isolatedInline->style().unicodeBidi(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1115 | TextDirection direction; |
| 1116 | if (unicodeBidi == Plaintext) |
mmaxfield@apple.com | 0fba19a | 2015-09-16 00:30:38 +0000 | [diff] [blame] | 1117 | determineDirectionality(direction, InlineIterator(isolatedInline, &isolatedRun.object, 0)); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1118 | else { |
rniwa@webkit.org | 4d4bd33 | 2012-08-20 21:34:11 +0000 | [diff] [blame] | 1119 | ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1120 | direction = isolatedInline->style().direction(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1121 | } |
zoltan@webkit.org | d1a9740 | 2013-12-08 05:53:33 +0000 | [diff] [blame] | 1122 | isolatedResolver.setStatus(BidiStatus(direction, isOverride(unicodeBidi))); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1123 | |
mmaxfield@apple.com | 0fba19a | 2015-09-16 00:30:38 +0000 | [diff] [blame] | 1124 | setUpResolverToResumeInIsolate(isolatedResolver, topResolver, isolatedRun.runToReplace, isolatedInline, &startObject); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1125 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1126 | // The starting position is the beginning of the first run within the isolate that was identified |
| 1127 | // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the |
| 1128 | // first run within the isolate. |
mmaxfield@apple.com | 0fba19a | 2015-09-16 00:30:38 +0000 | [diff] [blame] | 1129 | InlineIterator iter = InlineIterator(isolatedInline, &startObject, isolatedRun.position); |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1130 | isolatedResolver.setPositionIgnoringNestedIsolates(iter); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1131 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1132 | // We stop at the next end of line; we may re-enter this isolate in the next call to constructBidiRuns(). |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1133 | // FIXME: What should end and previousLineBrokeCleanly be? |
| 1134 | // rniwa says previousLineBrokeCleanly is just a WinIE hack and could always be false here? |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1135 | isolatedResolver.createBidiRunsForLine(endOfRuns, NoVisualOverride, previousLineBrokeCleanly); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1136 | // Note that we do not delete the runs from the resolver. |
rniwa@webkit.org | d0ad888 | 2012-05-23 07:37:07 +0000 | [diff] [blame] | 1137 | // We're not guaranteed to get any BidiRuns in the previous step. If we don't, we allow the placeholder |
leviw@chromium.org | f0d6f36 | 2012-05-23 04:00:47 +0000 | [diff] [blame] | 1138 | // itself to be turned into an InlineBox. We can't remove it here without potentially losing track of |
| 1139 | // the logically last run. |
| 1140 | if (isolatedResolver.runs().runCount()) |
mmaxfield@apple.com | 0fba19a | 2015-09-16 00:30:38 +0000 | [diff] [blame] | 1141 | bidiRuns.replaceRunWithRuns(&isolatedRun.runToReplace, isolatedResolver.runs()); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1142 | |
| 1143 | // If we encountered any nested isolate runs, just move them |
| 1144 | // to the top resolver's list for later processing. |
mmaxfield@apple.com | 0fba19a | 2015-09-16 00:30:38 +0000 | [diff] [blame] | 1145 | while (!isolatedResolver.isolatedRuns().isEmpty()) { |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 1146 | auto runWithContext = WTFMove(isolatedResolver.isolatedRuns().last()); |
mmaxfield@apple.com | 0fba19a | 2015-09-16 00:30:38 +0000 | [diff] [blame] | 1147 | isolatedResolver.isolatedRuns().removeLast(); |
| 1148 | topResolver.setMidpointForIsolatedRun(runWithContext.runToReplace, isolatedResolver.midpointForIsolatedRun(runWithContext.runToReplace)); |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 1149 | topResolver.isolatedRuns().append(WTFMove(runWithContext)); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1154 | // This function constructs line boxes for all of the text runs in the resolver and computes their position. |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 1155 | RootInlineBox* RenderBlockFlow::createLineBoxesFromBidiRuns(unsigned bidiLevel, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& end, LineInfo& lineInfo, VerticalPositionCache& verticalPositionCache, BidiRun* trailingSpaceRun, WordMeasurements& wordMeasurements) |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1156 | { |
| 1157 | if (!bidiRuns.runCount()) |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 1158 | return nullptr; |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1159 | |
| 1160 | // FIXME: Why is this only done when we had runs? |
gyuyoung.kim@samsung.com | 113fb8b | 2013-11-28 23:25:19 +0000 | [diff] [blame] | 1161 | lineInfo.setLastLine(!end.renderer()); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1162 | |
| 1163 | RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo); |
| 1164 | if (!lineBox) |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 1165 | return nullptr; |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1166 | |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 1167 | lineBox->setBidiLevel(bidiLevel); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1168 | lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly()); |
| 1169 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 1170 | bool isSVGRootInlineBox = is<SVGRootInlineBox>(*lineBox); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1171 | |
| 1172 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1173 | |
| 1174 | // Now we position all of our text runs horizontally. |
| 1175 | if (!isSVGRootInlineBox) |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 1176 | computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache, wordMeasurements); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1177 | |
| 1178 | // Now position our text runs vertically. |
| 1179 | computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache); |
| 1180 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1181 | // SVG text layout code computes vertical & horizontal positions on its own. |
| 1182 | // Note that we still need to execute computeVerticalPositionsForLine() as |
| 1183 | // it calls InlineTextBox::positionLineBox(), which tracks whether the box |
| 1184 | // contains reversed text or not. If we wouldn't do that editing and thus |
| 1185 | // text selection in RTL boxes would not work as expected. |
| 1186 | if (isSVGRootInlineBox) { |
akling@apple.com | 670fea1 | 2013-10-12 18:16:42 +0000 | [diff] [blame] | 1187 | ASSERT_WITH_SECURITY_IMPLICATION(isSVGText()); |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 1188 | downcast<SVGRootInlineBox>(*lineBox).computePerCharacterLayoutInformation(); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1189 | } |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1190 | |
| 1191 | // Compute our overflow now. |
| 1192 | lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap); |
| 1193 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1194 | return lineBox; |
| 1195 | } |
| 1196 | |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1197 | static void deleteLineRange(LineLayoutState& layoutState, RootInlineBox* startLine, RootInlineBox* stopLine = 0) |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1198 | { |
| 1199 | RootInlineBox* boxToDelete = startLine; |
| 1200 | while (boxToDelete && boxToDelete != stopLine) { |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1201 | layoutState.updateRepaintRangeFromBox(boxToDelete); |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1202 | // Note: deleteLineRange(firstRootBox()) is not identical to deleteLineBoxTree(). |
eric@webkit.org | e2532d9 | 2011-05-16 23:10:49 +0000 | [diff] [blame] | 1203 | // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing. |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1204 | RootInlineBox* next = boxToDelete->nextRootBox(); |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1205 | boxToDelete->deleteLine(); |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1206 | boxToDelete = next; |
| 1207 | } |
| 1208 | } |
| 1209 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1210 | void RenderBlockFlow::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild) |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1211 | { |
| 1212 | // We want to skip ahead to the first dirty line |
| 1213 | InlineBidiResolver resolver; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1214 | RootInlineBox* startLine = determineStartPosition(layoutState, resolver); |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1215 | |
| 1216 | if (startLine) |
| 1217 | marginCollapseLinesFromStart(layoutState, startLine); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1218 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1219 | unsigned consecutiveHyphenatedLines = 0; |
| 1220 | if (startLine) { |
| 1221 | for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox()) |
| 1222 | consecutiveHyphenatedLines++; |
| 1223 | } |
| 1224 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1225 | // FIXME: This would make more sense outside of this function, but since |
| 1226 | // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call |
| 1227 | // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html. |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1228 | if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) { |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 1229 | setNeedsLayout(MarkOnlyThis); // Mark as needing a full layout to force us to repaint. |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1230 | if (!view().doingFullRepaint() && hasLayer()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1231 | // Because we waited until we were already inside layout to discover |
| 1232 | // that the block really needed a full layout, we missed our chance to repaint the layer |
| 1233 | // before layout started. Luckily the layer has cached the repaint rect for its original |
| 1234 | // position and size, and so we can use that to make a repaint happen now. |
zalan@apple.com | c7b20b1 | 2014-02-12 04:50:55 +0000 | [diff] [blame] | 1235 | repaintUsingContainer(containerForRepaint(), layer()->repaintRect()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1236 | } |
| 1237 | } |
| 1238 | |
mihnea@adobe.com | 9946779 | 2013-03-19 09:09:04 +0000 | [diff] [blame] | 1239 | if (containsFloats()) |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1240 | layoutState.setLastFloat(m_floatingObjects->set().last().get()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1241 | |
| 1242 | // We also find the first clean line and extract these lines. We will add them back |
| 1243 | // if we determine that we're able to synchronize after handling all our dirty lines. |
| 1244 | InlineIterator cleanLineStart; |
| 1245 | BidiStatus cleanLineBidiStatus; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1246 | if (!layoutState.isFullLayout() && startLine) |
| 1247 | determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1248 | |
| 1249 | if (startLine) { |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1250 | if (!layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1251 | layoutState.setRepaintRange(logicalHeight()); |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1252 | deleteLineRange(layoutState, startLine); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1255 | if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1256 | // If the last line before the start line ends with a line break that clear floats, |
| 1257 | // adjust the height accordingly. |
| 1258 | // A line break can be either the first or the last object on a line, depending on its direction. |
| 1259 | if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) { |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 1260 | RenderObject* lastObject = &lastLeafChild->renderer(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1261 | if (!lastObject->isBR()) |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 1262 | lastObject = &lastRootBox()->firstLeafChild()->renderer(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1263 | if (lastObject->isBR()) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1264 | EClear clear = lastObject->style().clear(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1265 | if (clear != CNONE) |
bjonesbe@adobe.com | f9f1040 | 2014-02-20 19:40:28 +0000 | [diff] [blame] | 1266 | clearFloats(clear); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1271 | layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1272 | linkToEndLineIfNeeded(layoutState); |
| 1273 | repaintDirtyFloats(layoutState.floats()); |
| 1274 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1275 | |
commit-queue@webkit.org | 4055b2e | 2012-12-06 19:05:15 +0000 | [diff] [blame] | 1276 | // Before restarting the layout loop with a new logicalHeight, remove all floats that were added and reset the resolver. |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1277 | inline const InlineIterator& RenderBlockFlow::restartLayoutRunsAndFloatsInRange(LayoutUnit oldLogicalHeight, LayoutUnit newLogicalHeight, FloatingObject* lastFloatFromPreviousLine, InlineBidiResolver& resolver, const InlineIterator& oldEnd) |
commit-queue@webkit.org | 4055b2e | 2012-12-06 19:05:15 +0000 | [diff] [blame] | 1278 | { |
| 1279 | removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight); |
| 1280 | setLogicalHeight(newLogicalHeight); |
| 1281 | resolver.setPositionIgnoringNestedIsolates(oldEnd); |
| 1282 | return oldEnd; |
| 1283 | } |
| 1284 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1285 | void RenderBlockFlow::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1286 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1287 | const RenderStyle& styleToUse = style(); |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1288 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1289 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
| 1290 | InlineIterator end = resolver.position(); |
| 1291 | bool checkForEndLineMatch = layoutState.endLine(); |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 1292 | RenderTextInfo renderTextInfo; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1293 | VerticalPositionCache verticalPositionCache; |
| 1294 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1295 | LineBreaker lineBreaker(*this); |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1296 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1297 | while (!end.atEnd()) { |
| 1298 | // FIXME: Is this check necessary before the first iteration or can it be moved to the end? |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1299 | if (checkForEndLineMatch) { |
| 1300 | layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus)); |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1301 | if (layoutState.endLineMatched()) { |
| 1302 | resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0); |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1303 | layoutState.marginInfo().clearMargin(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1304 | break; |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1305 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1306 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1307 | |
| 1308 | lineMidpointState.reset(); |
| 1309 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1310 | layoutState.lineInfo().setEmpty(true); |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 1311 | layoutState.lineInfo().resetRunsFromLeadingWhitespace(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1312 | |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1313 | const InlineIterator oldEnd = end; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1314 | bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly(); |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 1315 | FloatingObject* lastFloatFromPreviousLine = (containsFloats()) ? m_floatingObjects->set().last().get() : nullptr; |
zoltan@webkit.org | 3bd77f5 | 2013-04-23 18:23:36 +0000 | [diff] [blame] | 1316 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 1317 | WordMeasurements wordMeasurements; |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1318 | end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), layoutState, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements); |
darin@apple.com | 3d1d5fc | 2015-04-23 05:20:23 +0000 | [diff] [blame] | 1319 | cachePriorCharactersIfNeeded(renderTextInfo.lineBreakIterator); |
| 1320 | renderTextInfo.lineBreakIterator.resetPriorContext(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1321 | if (resolver.position().atEnd()) { |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1322 | // FIXME: We shouldn't be creating any runs in nextLineBreak to begin with! |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1323 | // Once BidiRunList is separated from BidiResolver this will not be needed. |
| 1324 | resolver.runs().deleteRuns(); |
| 1325 | resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed). |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1326 | layoutState.setCheckForFloatsFromLastLine(true); |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1327 | resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1328 | break; |
| 1329 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1330 | |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1331 | ASSERT(end != resolver.position()); |
| 1332 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1333 | // This is a short-cut for empty lines. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1334 | if (layoutState.lineInfo().isEmpty()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1335 | if (lastRootBox()) |
gyuyoung.kim@samsung.com | 044376f | 2013-12-26 07:32:04 +0000 | [diff] [blame] | 1336 | lastRootBox()->setLineBreakInfo(end.renderer(), end.offset(), resolver.status()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1337 | } else { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1338 | VisualDirectionOverride override = (styleToUse.rtlOrdering() == VisualOrder ? (styleToUse.direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride); |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1339 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1340 | if (isNewUBAParagraph && styleToUse.unicodeBidi() == Plaintext && !resolver.context()->parent()) { |
| 1341 | TextDirection direction = styleToUse.direction(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1342 | determineDirectionality(direction, resolver.position()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1343 | resolver.setStatus(BidiStatus(direction, isOverride(styleToUse.unicodeBidi()))); |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1344 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1345 | // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine. |
| 1346 | BidiRunList<BidiRun>& bidiRuns = resolver.runs(); |
zoltan@webkit.org | 7d4f8cc | 2014-03-26 18:20:15 +0000 | [diff] [blame] | 1347 | constructBidiRunsForSegment(resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1348 | ASSERT(resolver.position() == end); |
| 1349 | |
mmaxfield@apple.com | 08b380d | 2015-04-02 20:29:23 +0000 | [diff] [blame] | 1350 | BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : nullptr; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1351 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1352 | if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) { |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1353 | bidiRuns.logicallyLastRun()->m_hasHyphen = true; |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1354 | consecutiveHyphenatedLines++; |
| 1355 | } else |
| 1356 | consecutiveHyphenatedLines = 0; |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1357 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1358 | // Now that the runs have been ordered, we create the line boxes. |
| 1359 | // At the same time we figure out where border/padding/margin should be applied for |
| 1360 | // inline flow boxes. |
| 1361 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1362 | LayoutUnit oldLogicalHeight = logicalHeight(); |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 1363 | RootInlineBox* lineBox = createLineBoxesFromBidiRuns(resolver.status().context->level(), bidiRuns, end, layoutState.lineInfo(), verticalPositionCache, trailingSpaceRun, wordMeasurements); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1364 | |
| 1365 | bidiRuns.deleteRuns(); |
| 1366 | resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed). |
| 1367 | |
| 1368 | if (lineBox) { |
gyuyoung.kim@samsung.com | 044376f | 2013-12-26 07:32:04 +0000 | [diff] [blame] | 1369 | lineBox->setLineBreakInfo(end.renderer(), end.offset(), resolver.status()); |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1370 | if (layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1371 | layoutState.updateRepaintRangeFromBox(lineBox); |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1372 | |
| 1373 | LayoutUnit adjustment = 0; |
| 1374 | bool overflowsRegion = false; |
| 1375 | |
| 1376 | // If our previous line was an anonymous block and we are not an anonymous block, |
| 1377 | // simulate a margin collapse now so that we get the proper |
| 1378 | // increased height. We also have to simulate a margin collapse to propagate margins |
| 1379 | // through to the top of our block. |
| 1380 | if (!lineBox->hasAnonymousInlineBlock()) { |
| 1381 | RootInlineBox* prevRoot = lineBox->prevRootBox(); |
| 1382 | if (prevRoot && prevRoot->hasAnonymousInlineBlock()) { |
| 1383 | LayoutUnit currentLogicalHeight = logicalHeight(); |
| 1384 | setLogicalHeight(oldLogicalHeight); |
| 1385 | collapseMarginsWithChildInfo(nullptr, nullptr, layoutState.marginInfo()); |
| 1386 | adjustment = logicalHeight() - oldLogicalHeight; |
| 1387 | setLogicalHeight(currentLogicalHeight); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1388 | } |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1389 | layoutState.marginInfo().setAtBeforeSideOfBlock(false); |
| 1390 | } |
| 1391 | |
| 1392 | if (paginated) |
| 1393 | adjustLinePositionForPagination(lineBox, adjustment, overflowsRegion, layoutState.flowThread()); |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1394 | if (adjustment) { |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 1395 | IndentTextOrNot shouldIndentText = layoutState.lineInfo().isFirstLine() ? IndentText : DoNotIndentText; |
| 1396 | LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, shouldIndentText); |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1397 | lineBox->adjustBlockDirectionPosition(adjustment); |
| 1398 | if (layoutState.usesRepaintBounds()) |
| 1399 | layoutState.updateRepaintRangeFromBox(lineBox); |
| 1400 | |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 1401 | if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, shouldIndentText) != oldLineWidth) { |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1402 | // We have to delete this line, remove all floats that got added, and let line layout re-run. |
| 1403 | lineBox->deleteLine(); |
| 1404 | end = restartLayoutRunsAndFloatsInRange(oldLogicalHeight, oldLogicalHeight + adjustment, lastFloatFromPreviousLine, resolver, oldEnd); |
| 1405 | continue; |
| 1406 | } |
| 1407 | |
| 1408 | setLogicalHeight(lineBox->lineBottomWithLeading()); |
| 1409 | } |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1410 | |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1411 | if (paginated) { |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1412 | if (RenderFlowThread* flowThread = flowThreadContainingBlock()) { |
| 1413 | if (flowThread->isRenderNamedFlowThread() && overflowsRegion && hasNextPage(lineBox->lineTop())) { |
| 1414 | // Limit the height of this block to the end of the current region because |
| 1415 | // it is also fragmented into the next region. |
| 1416 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalTop(), ExcludePageBoundary); |
| 1417 | if (logicalHeight() > remainingLogicalHeight) |
| 1418 | setLogicalHeight(remainingLogicalHeight); |
| 1419 | } |
| 1420 | } |
commit-queue@webkit.org | be554b2 | 2012-11-26 20:00:49 +0000 | [diff] [blame] | 1421 | |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1422 | if (layoutState.flowThread()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1423 | updateRegionForLine(lineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1424 | } |
| 1425 | } |
robert@webkit.org | 402c151 | 2013-02-07 18:48:39 +0000 | [diff] [blame] | 1426 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1427 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1428 | for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i) |
zalan@apple.com | 4d97a00 | 2016-02-24 17:13:33 +0000 | [diff] [blame] | 1429 | setStaticPositions(*this, *lineBreaker.positionedObjects()[i], DoNotIndentText); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1430 | |
robert@webkit.org | 402c151 | 2013-02-07 18:48:39 +0000 | [diff] [blame] | 1431 | if (!layoutState.lineInfo().isEmpty()) { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1432 | layoutState.lineInfo().setFirstLine(false); |
bjonesbe@adobe.com | f9f1040 | 2014-02-20 19:40:28 +0000 | [diff] [blame] | 1433 | clearFloats(lineBreaker.clear()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | if (m_floatingObjects && lastRootBox()) { |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1437 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1438 | auto it = floatingObjectSet.begin(); |
| 1439 | auto end = floatingObjectSet.end(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1440 | if (layoutState.lastFloat()) { |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1441 | auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1442 | ASSERT(lastFloatIterator != end); |
| 1443 | ++lastFloatIterator; |
| 1444 | it = lastFloatIterator; |
| 1445 | } |
| 1446 | for (; it != end; ++it) { |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1447 | FloatingObject* f = it->get(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1448 | appendFloatingObjectToLastLine(f); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1449 | ASSERT(&f->renderer() == &layoutState.floats()[layoutState.floatIndex()].object); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1450 | // If a float's geometry has changed, give up on syncing with clean lines. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1451 | if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect()) |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1452 | checkForEndLineMatch = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1453 | layoutState.setFloatIndex(layoutState.floatIndex() + 1); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1454 | } |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1455 | layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | lineMidpointState.reset(); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1459 | resolver.setPosition(end, numberOfIsolateAncestors(end)); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1460 | } |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1461 | |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1462 | // In case we already adjusted the line positions during this layout to avoid widows |
| 1463 | // then we need to ignore the possibility of having a new widows situation. |
| 1464 | // Otherwise, we risk leaving empty containers which is against the block fragmentation principles. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1465 | if (paginated && !style().hasAutoWidows() && !didBreakAtLineToAvoidWidow()) { |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1466 | // Check the line boxes to make sure we didn't create unacceptable widows. |
| 1467 | // However, we'll prioritize orphans - so nothing we do here should create |
| 1468 | // a new orphan. |
| 1469 | |
| 1470 | RootInlineBox* lineBox = lastRootBox(); |
| 1471 | |
| 1472 | // Count from the end of the block backwards, to see how many hanging |
| 1473 | // lines we have. |
| 1474 | RootInlineBox* firstLineInBlock = firstRootBox(); |
| 1475 | int numLinesHanging = 1; |
| 1476 | while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) { |
| 1477 | ++numLinesHanging; |
| 1478 | lineBox = lineBox->prevRootBox(); |
| 1479 | } |
| 1480 | |
| 1481 | // If there were no breaks in the block, we didn't create any widows. |
jchaffraix@webkit.org | 0f22514 | 2013-01-28 22:28:21 +0000 | [diff] [blame] | 1482 | if (!lineBox || !lineBox->isFirstAfterPageBreak() || lineBox == firstLineInBlock) |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1483 | return; |
| 1484 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1485 | if (numLinesHanging < style().widows()) { |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1486 | // We have detected a widow. Now we need to work out how many |
| 1487 | // lines there are on the previous page, and how many we need |
| 1488 | // to steal. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1489 | int numLinesNeeded = style().widows() - numLinesHanging; |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1490 | RootInlineBox* currentFirstLineOfNewPage = lineBox; |
| 1491 | |
| 1492 | // Count the number of lines in the previous page. |
| 1493 | lineBox = lineBox->prevRootBox(); |
| 1494 | int numLinesInPreviousPage = 1; |
| 1495 | while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) { |
| 1496 | ++numLinesInPreviousPage; |
| 1497 | lineBox = lineBox->prevRootBox(); |
| 1498 | } |
| 1499 | |
| 1500 | // If there was an explicit value for orphans, respect that. If not, we still |
| 1501 | // shouldn't create a situation where we make an orphan bigger than the initial value. |
| 1502 | // This means that setting widows implies we also care about orphans, but given |
| 1503 | // the specification says the initial orphan value is non-zero, this is ok. The |
| 1504 | // author is always free to set orphans explicitly as well. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1505 | int orphans = style().hasAutoOrphans() ? style().initialOrphans() : style().orphans(); |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1506 | int numLinesAvailable = numLinesInPreviousPage - orphans; |
| 1507 | if (numLinesAvailable <= 0) |
| 1508 | return; |
| 1509 | |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1510 | int numLinesToTake = std::min(numLinesAvailable, numLinesNeeded); |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1511 | // Wind back from our first widowed line. |
| 1512 | lineBox = currentFirstLineOfNewPage; |
| 1513 | for (int i = 0; i < numLinesToTake; ++i) |
| 1514 | lineBox = lineBox->prevRootBox(); |
| 1515 | |
| 1516 | // We now want to break at this line. Remember for next layout and trigger relayout. |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1517 | setBreakAtLineToAvoidWidow(lineCount(lineBox)); |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1518 | markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), lineBox->lineBottomWithLeading(), lineBox); |
| 1519 | } |
| 1520 | } |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1521 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1522 | clearDidBreakAtLineToAvoidWidow(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1523 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1524 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1525 | void RenderBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1526 | { |
| 1527 | if (layoutState.endLine()) { |
| 1528 | if (layoutState.endLineMatched()) { |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1529 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1530 | // Attach all the remaining lines, and then adjust their y-positions as needed. |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1531 | LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1532 | for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1533 | line->attachLine(); |
| 1534 | if (paginated) { |
| 1535 | delta -= line->paginationStrut(); |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1536 | bool overflowsRegion; |
| 1537 | adjustLinePositionForPagination(line, delta, overflowsRegion, layoutState.flowThread()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1538 | } |
| 1539 | if (delta) { |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1540 | layoutState.updateRepaintRangeFromBox(line, delta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1541 | line->adjustBlockDirectionPosition(delta); |
| 1542 | } |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1543 | if (layoutState.flowThread()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1544 | updateRegionForLine(line); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1545 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1546 | for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) { |
| 1547 | RenderBox* floatingBox = *it; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1548 | FloatingObject* floatingObject = insertFloatingObject(*floatingBox); |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 1549 | ASSERT(!floatingObject->originatingLine()); |
| 1550 | floatingObject->setOriginatingLine(line); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1551 | setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox) + delta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1552 | positionNewFloats(); |
| 1553 | } |
| 1554 | } |
| 1555 | } |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1556 | setLogicalHeight(lastRootBox()->lineBottomWithLeading()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1557 | } else { |
| 1558 | // Delete all the remaining lines. |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1559 | deleteLineRange(layoutState, layoutState.endLine()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1560 | } |
| 1561 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1562 | |
| 1563 | if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1564 | // In case we have a float on the last line, it might not be positioned up to now. |
| 1565 | // This has to be done before adding in the bottom border/padding, or the float will |
| 1566 | // include the padding incorrectly. -dwh |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1567 | if (layoutState.checkForFloatsFromLastLine()) { |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1568 | LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow(); |
| 1569 | LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow(); |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 1570 | auto newLineBox = std::make_unique<TrailingFloatsRootInlineBox>(*this); |
| 1571 | auto trailingFloatsLineBox = newLineBox.get(); |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 1572 | m_lineBoxes.appendLineBox(WTFMove(newLineBox)); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1573 | trailingFloatsLineBox->setConstructed(); |
| 1574 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1575 | VerticalPositionCache verticalPositionCache; |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1576 | LayoutUnit blockLogicalHeight = logicalHeight(); |
hyatt@apple.com | a8b5b82 | 2011-09-07 18:48:07 +0000 | [diff] [blame] | 1577 | trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache); |
| 1578 | trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight); |
hyatt@apple.com | 0c6cd7a | 2011-09-22 20:50:41 +0000 | [diff] [blame] | 1579 | trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight)); |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1580 | LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight); |
| 1581 | LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1582 | trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom()); |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1583 | if (layoutState.flowThread()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1584 | updateRegionForLine(trailingFloatsLineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1587 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1588 | auto it = floatingObjectSet.begin(); |
| 1589 | auto end = floatingObjectSet.end(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1590 | if (layoutState.lastFloat()) { |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1591 | auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1592 | ASSERT(lastFloatIterator != end); |
| 1593 | ++lastFloatIterator; |
| 1594 | it = lastFloatIterator; |
| 1595 | } |
| 1596 | for (; it != end; ++it) |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1597 | appendFloatingObjectToLastLine(it->get()); |
| 1598 | layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1599 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1602 | void RenderBlockFlow::repaintDirtyFloats(Vector<FloatWithRect>& floats) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1603 | { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1604 | size_t floatCount = floats.size(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1605 | // Floats that did not have layout did not repaint when we laid them out. They would have |
| 1606 | // painted by now if they had moved, but if they stayed at (0, 0), they still need to be |
| 1607 | // painted. |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1608 | for (size_t i = 0; i < floatCount; ++i) { |
| 1609 | if (!floats[i].everHadLayout) { |
| 1610 | RenderBox& box = floats[i].object; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1611 | if (!box.x() && !box.y() && box.checkForRepaintDuringLayout()) |
| 1612 | box.repaint(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1613 | } |
| 1614 | } |
| 1615 | } |
| 1616 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1617 | void RenderBlockFlow::layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
jamesr@google.com | 19548ad | 2010-04-02 23:21:35 +0000 | [diff] [blame] | 1618 | { |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 1619 | ASSERT(!m_simpleLineLayout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1620 | |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 1621 | setLogicalHeight(borderAndPaddingBefore()); |
hyatt@apple.com | ee7af1d | 2012-01-17 19:16:24 +0000 | [diff] [blame] | 1622 | |
| 1623 | // Lay out our hypothetical grid line as though it occurs at the top of the block. |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1624 | if (view().layoutState() && view().layoutState()->lineGrid() == this) |
hyatt@apple.com | ee7af1d | 2012-01-17 19:16:24 +0000 | [diff] [blame] | 1625 | layoutLineGridBox(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1626 | |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1627 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 1628 | bool clearLinesForPagination = firstRootBox() && flowThread && !flowThread->hasRegions(); |
commit-queue@webkit.org | 93cdd63 | 2012-12-07 00:33:56 +0000 | [diff] [blame] | 1629 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1630 | // Figure out if we should clear out our line boxes. |
| 1631 | // FIXME: Handle resize eventually! |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 1632 | bool isFullLayout = !firstRootBox() || selfNeedsLayout() || relayoutChildren || clearLinesForPagination; |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1633 | LineLayoutState layoutState(*this, isFullLayout, repaintLogicalTop, repaintLogicalBottom, flowThread); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1634 | |
| 1635 | if (isFullLayout) |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1636 | lineBoxes().deleteLineBoxes(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1637 | |
commit-queue@webkit.org | 0779731 | 2013-02-22 18:58:19 +0000 | [diff] [blame] | 1638 | // Text truncation kicks in in two cases: |
| 1639 | // 1) If your overflow isn't visible and your text-overflow-mode isn't clip. |
| 1640 | // 2) If you're an anonymous block with a block parent that satisfies #1. |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1641 | // FIXME: CSS3 says that descendants that are clipped must also know how to truncate. This is insanely |
commit-queue@webkit.org | 0779731 | 2013-02-22 18:58:19 +0000 | [diff] [blame] | 1642 | // difficult to figure out in general (especially in the middle of doing layout), so we only handle the |
| 1643 | // simple case of an anonymous block truncating when it's parent is clipped. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1644 | bool hasTextOverflow = (style().textOverflow() && hasOverflowClip()) |
| 1645 | || (isAnonymousBlock() && parent() && parent()->isRenderBlock() && parent()->style().textOverflow() && parent()->hasOverflowClip()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1646 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1647 | // Walk all the lines and delete our ellipsis line boxes if they exist. |
| 1648 | if (hasTextOverflow) |
| 1649 | deleteEllipsisLineBoxes(); |
| 1650 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1651 | if (firstChild()) { |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1652 | // In full layout mode, clear the line boxes of children upfront. Otherwise, |
| 1653 | // siblings can run into stale root lineboxes during layout. Then layout |
| 1654 | // the replaced elements later. In partial layout mode, line boxes are not |
| 1655 | // deleted and only dirtied. In that case, we can layout the replaced |
| 1656 | // elements at the same time. |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1657 | bool hasInlineChild = false; |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1658 | Vector<RenderBox*> replacedChildren; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1659 | for (InlineWalker walker(*this); !walker.atEnd(); walker.advance()) { |
| 1660 | RenderObject& o = *walker.current(); |
abucur@adobe.com | 33159da | 2013-08-13 07:44:32 +0000 | [diff] [blame] | 1661 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1662 | if (!hasInlineChild && o.isInline()) |
commit-queue@webkit.org | cf45df9 | 2010-09-14 13:25:06 +0000 | [diff] [blame] | 1663 | hasInlineChild = true; |
| 1664 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1665 | if (o.isReplaced() || o.isFloating() || o.isOutOfFlowPositioned()) { |
cdumez@apple.com | 0abff8b | 2014-10-17 21:25:10 +0000 | [diff] [blame] | 1666 | RenderBox& box = downcast<RenderBox>(o); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1667 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1668 | if (relayoutChildren || box.hasRelativeDimensions()) |
| 1669 | box.setChildNeedsLayout(MarkOnlyThis); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1670 | |
zimmermann@webkit.org | ac68af4 | 2011-06-15 08:02:37 +0000 | [diff] [blame] | 1671 | // 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.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1672 | if (relayoutChildren && box.needsPreferredWidthsRecalculation()) |
| 1673 | box.setPreferredLogicalWidthsDirty(true, MarkOnlyThis); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1674 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1675 | if (box.isOutOfFlowPositioned()) |
| 1676 | box.containingBlock()->insertPositionedObject(box); |
| 1677 | else if (box.isFloating()) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1678 | layoutState.floats().append(FloatWithRect(box)); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1679 | else if (isFullLayout || box.needsLayout()) { |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1680 | // Replaced element. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1681 | box.dirtyLineBoxes(isFullLayout); |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 1682 | if (!o.isAnonymousInlineBlock()) { |
| 1683 | if (isFullLayout) |
| 1684 | replacedChildren.append(&box); |
| 1685 | else |
| 1686 | box.layoutIfNeeded(); |
| 1687 | } |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1688 | } |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 1689 | } else if (o.isTextOrLineBreak() || (is<RenderInline>(o) && !walker.atEndOfInline())) { |
| 1690 | if (is<RenderInline>(o)) |
| 1691 | downcast<RenderInline>(o).updateAlwaysCreateLineBoxes(layoutState.isFullLayout()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1692 | if (layoutState.isFullLayout() || o.selfNeedsLayout()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1693 | dirtyLineBoxesForRenderer(o, layoutState.isFullLayout()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1694 | o.clearNeedsLayout(); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1695 | } |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1698 | for (size_t i = 0; i < replacedChildren.size(); i++) |
| 1699 | replacedChildren[i]->layoutIfNeeded(); |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1700 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1701 | layoutRunsAndFloats(layoutState, hasInlineChild); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1702 | } |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1703 | |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1704 | // Expand the last line to accommodate Ruby and emphasis marks. |
| 1705 | int lastLineAnnotationsAdjustment = 0; |
| 1706 | if (lastRootBox()) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1707 | LayoutUnit lowestAllowedPosition = std::max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1708 | if (!style().isFlippedLinesWritingMode()) |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1709 | lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition); |
| 1710 | else |
| 1711 | lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition); |
hyatt@apple.com | 5e48ff5 | 2010-11-19 00:43:29 +0000 | [diff] [blame] | 1712 | } |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1713 | |
| 1714 | // Now do the handling of the bottom of the block, adding in our bottom border/padding and |
| 1715 | // determining the correct collapsed bottom margin information. This collapse is only necessary |
| 1716 | // if our last child was an anonymous inline block that might need to propagate margin information out to |
| 1717 | // us. |
| 1718 | LayoutUnit beforeEdge = borderAndPaddingBefore(); |
| 1719 | LayoutUnit afterEdge = borderAndPaddingAfter() + scrollbarLogicalHeight() + lastLineAnnotationsAdjustment; |
| 1720 | if (lastRootBox() && lastRootBox()->hasAnonymousInlineBlock()) |
| 1721 | handleAfterSideOfBlock(beforeEdge, afterEdge, layoutState.marginInfo()); |
| 1722 | else |
| 1723 | setLogicalHeight(logicalHeight() + afterEdge); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1724 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 1725 | if (!firstRootBox() && hasLineIfEmpty()) |
hyatt@apple.com | 2a5eb21 | 2011-03-22 23:21:54 +0000 | [diff] [blame] | 1726 | setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes)); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1727 | |
| 1728 | // See if we have any lines that spill out of our block. If we do, then we will possibly need to |
| 1729 | // truncate text. |
| 1730 | if (hasTextOverflow) |
| 1731 | checkLinesForTextOverflow(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1734 | void RenderBlockFlow::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat) |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1735 | { |
| 1736 | Vector<RenderBox*>* cleanLineFloats = line->floatsPtr(); |
| 1737 | if (!cleanLineFloats) |
| 1738 | return; |
stavila@adobe.com | f4ef097 | 2014-03-28 21:55:46 +0000 | [diff] [blame] | 1739 | |
| 1740 | if (!floats.size()) { |
| 1741 | encounteredNewFloat = true; |
| 1742 | return; |
| 1743 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1744 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1745 | for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) { |
| 1746 | RenderBox* floatingBox = *it; |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1747 | floatingBox->layoutIfNeeded(); |
bjonesbe@adobe.com | 562a50d | 2014-02-20 20:01:19 +0000 | [diff] [blame] | 1748 | LayoutSize newSize(floatingBox->width() + floatingBox->horizontalMarginExtent(), floatingBox->height() + floatingBox->verticalMarginExtent()); |
inferno@chromium.org | a227be6 | 2013-02-11 08:06:45 +0000 | [diff] [blame] | 1749 | ASSERT_WITH_SECURITY_IMPLICATION(floatIndex < floats.size()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1750 | if (&floats[floatIndex].object != floatingBox) { |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1751 | encounteredNewFloat = true; |
| 1752 | return; |
| 1753 | } |
hyatt@apple.com | c2e1552 | 2014-09-03 19:26:38 +0000 | [diff] [blame] | 1754 | |
| 1755 | // We have to reset the cap-height alignment done by the first-letter floats when initial-letter is set, so just always treat first-letter floats |
| 1756 | // as dirty. |
| 1757 | if (floats[floatIndex].rect.size() != newSize || (floatingBox->style().styleType() == FIRST_LETTER && floatingBox->style().initialLetterDrop() > 0)) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1758 | LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x(); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1759 | LayoutUnit floatHeight = isHorizontalWritingMode() ? std::max(floats[floatIndex].rect.height(), newSize.height()) : std::max(floats[floatIndex].rect.width(), newSize.width()); |
| 1760 | floatHeight = std::min(floatHeight, LayoutUnit::max() - floatTop); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1761 | line->markDirty(); |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1762 | markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1763 | floats[floatIndex].rect.setSize(newSize); |
| 1764 | dirtiedByFloat = true; |
| 1765 | } |
| 1766 | floatIndex++; |
| 1767 | } |
| 1768 | } |
| 1769 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1770 | RootInlineBox* RenderBlockFlow::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1771 | { |
| 1772 | RootInlineBox* curr = 0; |
| 1773 | RootInlineBox* last = 0; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1774 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1775 | // FIXME: This entire float-checking block needs to be broken into a new function. |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1776 | bool dirtiedByFloat = false; |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1777 | if (!layoutState.isFullLayout()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1778 | // Paginate all of the clean lines. |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1779 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1780 | LayoutUnit paginationDelta = 0; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1781 | size_t floatIndex = 0; |
| 1782 | for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1783 | if (paginated) { |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1784 | if (lineWidthForPaginatedLineChanged(curr, 0, layoutState.flowThread())) { |
hyatt@apple.com | 0c6cd7a | 2011-09-22 20:50:41 +0000 | [diff] [blame] | 1785 | curr->markDirty(); |
| 1786 | break; |
| 1787 | } |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1788 | paginationDelta -= curr->paginationStrut(); |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1789 | bool overflowsRegion; |
| 1790 | adjustLinePositionForPagination(curr, paginationDelta, overflowsRegion, layoutState.flowThread()); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1791 | if (paginationDelta) { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1792 | if (containsFloats() || !layoutState.floats().isEmpty()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1793 | // 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.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1794 | layoutState.markForFullLayout(); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1795 | break; |
| 1796 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1797 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1798 | layoutState.updateRepaintRangeFromBox(curr, paginationDelta); |
hyatt@apple.com | 61bbedf | 2011-01-26 23:10:57 +0000 | [diff] [blame] | 1799 | curr->adjustBlockDirectionPosition(paginationDelta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1800 | } |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1801 | if (layoutState.flowThread()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1802 | updateRegionForLine(curr); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1803 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1804 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1805 | // If a new float has been inserted before this line or before its last known float, just do a full layout. |
| 1806 | bool encounteredNewFloat = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1807 | checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1808 | if (encounteredNewFloat) |
| 1809 | layoutState.markForFullLayout(); |
| 1810 | |
| 1811 | if (dirtiedByFloat || layoutState.isFullLayout()) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | } |
| 1814 | // Check if a new float has been inserted after the last known float. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1815 | if (!curr && floatIndex < layoutState.floats().size()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1816 | layoutState.markForFullLayout(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1819 | if (layoutState.isFullLayout()) { |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1820 | m_lineBoxes.deleteLineBoxTree(); |
igor.o@sisa.samsung.com | f6a57df | 2013-04-15 21:25:35 +0000 | [diff] [blame] | 1821 | curr = 0; |
| 1822 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 1823 | ASSERT(!firstRootBox() && !lastRootBox()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1824 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1825 | if (curr) { |
| 1826 | // We have a dirty line. |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1827 | if (RootInlineBox* prevRootBox = curr->prevRootBox()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1828 | // We have a previous line. |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1829 | if (!dirtiedByFloat && !curr->hasAnonymousInlineBlock() && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (is<RenderText>(*prevRootBox->lineBreakObj()) && prevRootBox->lineBreakPos() >= downcast<RenderText>(*prevRootBox->lineBreakObj()).textLength()))) { |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1830 | // The previous line didn't break cleanly or broke at a newline |
| 1831 | // that has been deleted, so treat it as dirty too. |
| 1832 | curr = prevRootBox; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 1833 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1834 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1835 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1836 | // If we have no dirty lines, then last is just the last root box. |
| 1837 | last = curr ? curr->prevRootBox() : lastRootBox(); |
| 1838 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1839 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1840 | unsigned numCleanFloats = 0; |
| 1841 | if (!layoutState.floats().isEmpty()) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1842 | LayoutUnit savedLogicalHeight = logicalHeight(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1843 | // Restore floats from clean lines. |
| 1844 | RootInlineBox* line = firstRootBox(); |
| 1845 | while (line != curr) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1846 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1847 | for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) { |
| 1848 | RenderBox* floatingBox = *it; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1849 | FloatingObject* floatingObject = insertFloatingObject(*floatingBox); |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 1850 | ASSERT(!floatingObject->originatingLine()); |
| 1851 | floatingObject->setOriginatingLine(line); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1852 | setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox)); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1853 | positionNewFloats(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1854 | ASSERT(&layoutState.floats()[numCleanFloats].object == floatingBox); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1855 | numCleanFloats++; |
| 1856 | } |
| 1857 | } |
| 1858 | line = line->nextRootBox(); |
| 1859 | } |
hyatt@apple.com | 9a2e7d2 | 2010-10-06 22:13:31 +0000 | [diff] [blame] | 1860 | setLogicalHeight(savedLogicalHeight); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1861 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1862 | layoutState.setFloatIndex(numCleanFloats); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1863 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1864 | layoutState.lineInfo().setFirstLine(!last); |
| 1865 | layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak()); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1866 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1867 | if (last) { |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1868 | setLogicalHeight(last->lineBottomWithLeading()); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1869 | InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos()); |
| 1870 | resolver.setPosition(iter, numberOfIsolateAncestors(iter)); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1871 | resolver.setStatus(last->lineBreakBidiStatus()); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1872 | } else { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1873 | TextDirection direction = style().direction(); |
| 1874 | if (style().unicodeBidi() == Plaintext) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1875 | determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(*this), 0)); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1876 | resolver.setStatus(BidiStatus(direction, isOverride(style().unicodeBidi()))); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1877 | InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(*this, &resolver), 0); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1878 | resolver.setPosition(iter, numberOfIsolateAncestors(iter)); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1879 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1880 | return curr; |
| 1881 | } |
| 1882 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1883 | void RenderBlockFlow::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1884 | { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1885 | ASSERT(!layoutState.endLine()); |
| 1886 | size_t floatIndex = layoutState.floatIndex(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1887 | RootInlineBox* last = 0; |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1888 | for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) { |
| 1889 | if (!curr->isDirty()) { |
| 1890 | bool encounteredNewFloat = false; |
| 1891 | bool dirtiedByFloat = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1892 | checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1893 | if (encounteredNewFloat) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1894 | return; |
hyatt | 04420ca | 2004-07-16 00:05:42 +0000 | [diff] [blame] | 1895 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1896 | if (curr->isDirty()) |
| 1897 | last = 0; |
| 1898 | else if (!last) |
| 1899 | last = curr; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1900 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1901 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1902 | if (!last) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1903 | return; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1904 | |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1905 | // At this point, |last| is the first line in a run of clean lines that ends with the last line |
| 1906 | // in the block. |
| 1907 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1908 | RootInlineBox* prev = last->prevRootBox(); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1909 | cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1910 | cleanLineBidiStatus = prev->lineBreakBidiStatus(); |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1911 | layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1912 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1913 | for (RootInlineBox* line = last; line; line = line->nextRootBox()) |
| 1914 | line->extractLine(); // Disconnect all line boxes from their render objects while preserving |
| 1915 | // their connections to one another. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1916 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1917 | layoutState.setEndLine(last); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1920 | bool RenderBlockFlow::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState) |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1921 | { |
| 1922 | LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop(); |
| 1923 | |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1924 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1925 | if (paginated && layoutState.flowThread()) { |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1926 | // Check all lines from here to the end, and see if the hypothetical new position for the lines will result |
| 1927 | // in a different available line width. |
| 1928 | for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) { |
| 1929 | if (paginated) { |
| 1930 | // This isn't the real move we're going to do, so don't update the line box's pagination |
| 1931 | // strut yet. |
| 1932 | LayoutUnit oldPaginationStrut = lineBox->paginationStrut(); |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1933 | bool overflowsRegion; |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1934 | lineDelta -= oldPaginationStrut; |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1935 | adjustLinePositionForPagination(lineBox, lineDelta, overflowsRegion, layoutState.flowThread()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1936 | lineBox->setPaginationStrut(oldPaginationStrut); |
| 1937 | } |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1938 | if (lineWidthForPaginatedLineChanged(lineBox, lineDelta, layoutState.flowThread())) |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1939 | return false; |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | if (!lineDelta || !m_floatingObjects) |
| 1944 | return true; |
| 1945 | |
| 1946 | // See if any floats end in the range along which we want to shift the lines vertically. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1947 | LayoutUnit logicalTop = std::min(logicalHeight(), layoutState.endLineLogicalTop()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1948 | |
| 1949 | RootInlineBox* lastLine = layoutState.endLine(); |
| 1950 | while (RootInlineBox* nextLine = lastLine->nextRootBox()) |
| 1951 | lastLine = nextLine; |
| 1952 | |
leviw@chromium.org | 3957b45 | 2012-05-01 00:06:37 +0000 | [diff] [blame] | 1953 | LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + absoluteValue(lineDelta); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1954 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1955 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 1956 | auto end = floatingObjectSet.end(); |
| 1957 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 1958 | const auto& floatingObject = *it->get(); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1959 | if (logicalBottomForFloat(floatingObject) >= logicalTop && logicalBottomForFloat(floatingObject) < logicalBottom) |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1960 | return false; |
| 1961 | } |
| 1962 | |
| 1963 | return true; |
| 1964 | } |
| 1965 | |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1966 | bool RenderBlockFlow::lineWidthForPaginatedLineChanged(RootInlineBox* rootBox, LayoutUnit lineDelta, RenderFlowThread* flowThread) const |
| 1967 | { |
| 1968 | if (!flowThread) |
| 1969 | return false; |
| 1970 | |
| 1971 | RenderRegion* currentRegion = regionAtBlockOffset(rootBox->lineTopWithLeading() + lineDelta); |
| 1972 | // Just bail if the region didn't change. |
| 1973 | if (rootBox->containingRegion() == currentRegion) |
| 1974 | return false; |
| 1975 | return rootBox->paginatedLineWidth() != availableLogicalWidthForContent(currentRegion); |
| 1976 | } |
| 1977 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1978 | bool RenderBlockFlow::matchedEndLine(LineLayoutState& layoutState, const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1979 | { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1980 | if (resolver.position() == endLineStart) { |
| 1981 | if (resolver.status() != endLineStatus) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1982 | return false; |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1983 | return checkPaginationAndFloatsAtEndLine(layoutState); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1984 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1985 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1986 | // The first clean line doesn't match, but we can check a handful of following lines to try |
| 1987 | // to match back up. |
cdumez@apple.com | 4bf983a | 2015-05-19 07:22:36 +0000 | [diff] [blame] | 1988 | static const int numLines = 8; // The # of lines we're willing to match against. |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1989 | RootInlineBox* originalEndLine = layoutState.endLine(); |
| 1990 | RootInlineBox* line = originalEndLine; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1991 | for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) { |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1992 | if (line->lineBreakObj() == resolver.position().renderer() && line->lineBreakPos() == resolver.position().offset() && !line->hasAnonymousInlineBlock()) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1993 | // We have a match. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1994 | if (line->lineBreakBidiStatus() != resolver.status()) |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1995 | return false; // ...but the bidi state doesn't match. |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1996 | |
| 1997 | bool matched = false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1998 | RootInlineBox* result = line->nextRootBox(); |
hyatt@apple.com | 1fb7d58 | 2011-09-23 20:25:11 +0000 | [diff] [blame] | 1999 | layoutState.setEndLine(result); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2000 | if (result) { |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 2001 | layoutState.setEndLineLogicalTop(line->lineBottomWithLeading()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2002 | matched = checkPaginationAndFloatsAtEndLine(layoutState); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2003 | } |
| 2004 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2005 | // Now delete the lines that we failed to sync. |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 2006 | deleteLineRange(layoutState, originalEndLine, result); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2007 | return matched; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2008 | } |
| 2009 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2010 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2011 | return false; |
| 2012 | } |
| 2013 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2014 | bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 2015 | { |
| 2016 | ASSERT(inlineObj->parent() == this); |
| 2017 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2018 | InlineIterator it(this, inlineObj, 0); |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 2019 | // FIXME: We should pass correct value for WhitespacePosition. |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2020 | while (!it.atEnd() && !requiresLineBox(it)) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2021 | it.increment(); |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 2022 | |
| 2023 | return !it.atEnd(); |
| 2024 | } |
| 2025 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2026 | void RenderBlockFlow::addOverflowFromInlineChildren() |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2027 | { |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 2028 | if (auto layout = simpleLineLayout()) { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2029 | ASSERT(!hasOverflowClip()); |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 2030 | SimpleLineLayout::collectFlowOverflow(*this, *layout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2031 | return; |
| 2032 | } |
eae@chromium.org | 9717cd8 | 2012-11-07 18:33:44 +0000 | [diff] [blame] | 2033 | LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit(); |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 2034 | // FIXME: Need to find another way to do this, since scrollbars could show when we don't want them to. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2035 | if (hasOverflowClip() && !endPadding && element() && element()->isRootEditableElement() && style().isLeftToRightDirection()) |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 2036 | endPadding = 1; |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2037 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 2038 | addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding)); |
abucur@adobe.com | 4c3580b | 2014-04-29 12:38:20 +0000 | [diff] [blame] | 2039 | RenderRegion* region = flowThreadContainingBlock() ? curr->containingRegion() : nullptr; |
abucur@adobe.com | 6585d01 | 2013-09-04 08:26:41 +0000 | [diff] [blame] | 2040 | if (region) |
| 2041 | region->addLayoutOverflowForBox(this, curr->paddedLayoutOverflowRect(endPadding)); |
| 2042 | if (!hasOverflowClip()) { |
zalan@apple.com | d423bcc | 2016-02-06 23:07:54 +0000 | [diff] [blame] | 2043 | LayoutRect childVisualOverflowRect = curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()); |
| 2044 | addVisualOverflow(childVisualOverflowRect); |
abucur@adobe.com | 6585d01 | 2013-09-04 08:26:41 +0000 | [diff] [blame] | 2045 | if (region) |
zalan@apple.com | d423bcc | 2016-02-06 23:07:54 +0000 | [diff] [blame] | 2046 | region->addVisualOverflowForBox(this, childVisualOverflowRect); |
abucur@adobe.com | 6585d01 | 2013-09-04 08:26:41 +0000 | [diff] [blame] | 2047 | } |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2048 | } |
| 2049 | } |
| 2050 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2051 | void RenderBlockFlow::deleteEllipsisLineBoxes() |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2052 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2053 | ETextAlign textAlign = style().textAlign(); |
| 2054 | bool ltr = style().isLeftToRightDirection(); |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 2055 | IndentTextOrNot shouldIndentText = IndentText; |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 2056 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
| 2057 | if (curr->hasEllipsisBox()) { |
| 2058 | curr->clearTruncation(); |
| 2059 | |
| 2060 | // Shift the line back where it belongs if we cannot accomodate an ellipsis. |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 2061 | float logicalLeft = logicalLeftOffsetForLine(curr->lineTop(), shouldIndentText); |
| 2062 | float availableLogicalWidth = logicalRightOffsetForLine(curr->lineTop(), DoNotIndentText) - logicalLeft; |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 2063 | float totalLogicalWidth = curr->logicalWidth(); |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 2064 | updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 2065 | |
| 2066 | if (ltr) |
| 2067 | curr->adjustLogicalPosition((logicalLeft - curr->logicalLeft()), 0); |
| 2068 | else |
| 2069 | curr->adjustLogicalPosition(-(curr->logicalLeft() - logicalLeft), 0); |
| 2070 | } |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 2071 | shouldIndentText = DoNotIndentText; |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 2072 | } |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2075 | void RenderBlockFlow::checkLinesForTextOverflow() |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2076 | { |
| 2077 | // Determine the width of the ellipsis using the current font. |
darin | dbba2bb | 2007-01-11 12:23:49 +0000 | [diff] [blame] | 2078 | // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable" |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +0000 | [diff] [blame] | 2079 | const FontCascade& font = style().fontCascade(); |
mmaxfield@apple.com | e6da30e | 2015-07-25 03:51:06 +0000 | [diff] [blame] | 2080 | static NeverDestroyed<AtomicString> ellipsisStr(&horizontalEllipsis, 1); |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +0000 | [diff] [blame] | 2081 | const FontCascade& firstLineFont = firstLineStyle().fontCascade(); |
mmaxfield@apple.com | 21a4dcb | 2016-03-13 00:36:59 +0000 | [diff] [blame] | 2082 | float firstLineEllipsisWidth = firstLineFont.width(constructTextRun(&horizontalEllipsis, 1, firstLineStyle())); |
| 2083 | float ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(&horizontalEllipsis, 1, style())); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2084 | |
| 2085 | // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see |
| 2086 | // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and |
| 2087 | // check the left edge of the line box to see if it is less |
| 2088 | // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()" |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2089 | bool ltr = style().isLeftToRightDirection(); |
| 2090 | ETextAlign textAlign = style().textAlign(); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 2091 | bool firstLine = true; |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2092 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 2093 | IndentTextOrNot shouldIndentText = firstLine ? IndentText : DoNotIndentText; |
| 2094 | LayoutUnit blockRightEdge = logicalRightOffsetForLine(curr->lineTop(), shouldIndentText); |
| 2095 | LayoutUnit blockLeftEdge = logicalLeftOffsetForLine(curr->lineTop(), shouldIndentText); |
zalan@apple.com | bfa1195 | 2014-05-19 17:37:22 +0000 | [diff] [blame] | 2096 | LayoutUnit lineBoxEdge = ltr ? curr->x() + curr->logicalWidth() : curr->x(); |
dglazkov@chromium.org | 28434e6 | 2009-05-13 22:30:10 +0000 | [diff] [blame] | 2097 | if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) { |
hyatt | f918d2d | 2004-06-15 07:24:11 +0000 | [diff] [blame] | 2098 | // This line spills out of our box in the appropriate direction. Now we need to see if the line |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2099 | // can be truncated. In order for truncation to be possible, the line must have sufficient space to |
| 2100 | // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis |
| 2101 | // space. |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 2102 | LayoutUnit width = firstLine ? firstLineEllipsisWidth : ellipsisWidth; |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 2103 | LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge; |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 2104 | if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) { |
| 2105 | float totalLogicalWidth = curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width); |
| 2106 | |
akling@apple.com | f294cf0 | 2013-07-17 18:46:39 +0000 | [diff] [blame] | 2107 | float logicalLeft = 0; // We are only interested in the delta from the base position. |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 2108 | float truncatedWidth = availableLogicalWidthForLine(curr->lineTop(), shouldIndentText); |
mmaxfield@apple.com | e6da30e | 2015-07-25 03:51:06 +0000 | [diff] [blame] | 2109 | updateLogicalWidthForAlignment(textAlign, curr, nullptr, logicalLeft, totalLogicalWidth, truncatedWidth, 0); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 2110 | if (ltr) |
| 2111 | curr->adjustLogicalPosition(logicalLeft, 0); |
| 2112 | else |
| 2113 | curr->adjustLogicalPosition(-(truncatedWidth - (logicalLeft + totalLogicalWidth)), 0); |
| 2114 | } |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2115 | } |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 2116 | firstLine = false; |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2117 | } |
| 2118 | } |
| 2119 | |
zalan@apple.com | 48ea283 | 2015-10-16 19:53:04 +0000 | [diff] [blame] | 2120 | bool RenderBlockFlow::positionNewFloatOnLine(const FloatingObject& newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width) |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2121 | { |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2122 | if (!positionNewFloats()) |
| 2123 | return false; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2124 | |
rniwa@webkit.org | 4442475 | 2011-04-14 00:58:40 +0000 | [diff] [blame] | 2125 | width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2126 | |
hyatt@apple.com | dd78df8 | 2011-09-27 22:11:41 +0000 | [diff] [blame] | 2127 | // We only connect floats to lines for pagination purposes if the floats occur at the start of |
| 2128 | // the line and the previous line had a hard break (so this line is either the first in the block |
| 2129 | // or follows a <br>). |
zalan@apple.com | 48ea283 | 2015-10-16 19:53:04 +0000 | [diff] [blame] | 2130 | if (!newFloat.paginationStrut() || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty()) |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2131 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2132 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 2133 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
zalan@apple.com | 48ea283 | 2015-10-16 19:53:04 +0000 | [diff] [blame] | 2134 | ASSERT(floatingObjectSet.last().get() == &newFloat); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2135 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2136 | LayoutUnit floatLogicalTop = logicalTopForFloat(newFloat); |
zalan@apple.com | 48ea283 | 2015-10-16 19:53:04 +0000 | [diff] [blame] | 2137 | LayoutUnit paginationStrut = newFloat.paginationStrut(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2138 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2139 | if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut()) |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2140 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2141 | |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 2142 | auto it = floatingObjectSet.end(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2143 | --it; // Last float is newFloat, skip that one. |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 2144 | auto begin = floatingObjectSet.begin(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2145 | while (it != begin) { |
| 2146 | --it; |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2147 | auto& floatingObject = *it->get(); |
| 2148 | if (&floatingObject == lastFloatFromPreviousLine) |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2149 | break; |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2150 | if (logicalTopForFloat(floatingObject) == logicalHeight() + lineInfo.floatPaginationStrut()) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2151 | floatingObject.setPaginationStrut(paginationStrut + floatingObject.paginationStrut()); |
| 2152 | RenderBox& floatBox = floatingObject.renderer(); |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2153 | setLogicalTopForChild(floatBox, logicalTopForChild(floatBox) + marginBeforeForChild(floatBox) + paginationStrut); |
stavila@adobe.com | 6cb976d | 2013-11-21 06:57:19 +0000 | [diff] [blame] | 2154 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2155 | if (updateRegionRangeForBoxChild(floatBox)) |
stavila@adobe.com | 6cb976d | 2013-11-21 06:57:19 +0000 | [diff] [blame] | 2156 | floatBox.setNeedsLayout(MarkOnlyThis); |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 2157 | else if (is<RenderBlock>(floatBox)) |
| 2158 | downcast<RenderBlock>(floatBox).setChildNeedsLayout(MarkOnlyThis); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2159 | floatBox.layoutIfNeeded(); |
stavila@adobe.com | 6cb976d | 2013-11-21 06:57:19 +0000 | [diff] [blame] | 2160 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 2161 | // Save the old logical top before calling removePlacedObject which will set |
| 2162 | // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat. |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2163 | LayoutUnit oldLogicalTop = logicalTopForFloat(floatingObject); |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2164 | m_floatingObjects->removePlacedObject(&floatingObject); |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2165 | setLogicalTopForFloat(floatingObject, oldLogicalTop + paginationStrut); |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2166 | m_floatingObjects->addPlacedObject(&floatingObject); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2167 | } |
| 2168 | } |
| 2169 | |
hyatt@apple.com | dd78df8 | 2011-09-27 22:11:41 +0000 | [diff] [blame] | 2170 | // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing |
| 2171 | // no content, then we don't want to improperly grow the height of the block. |
| 2172 | lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut); |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2173 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
zalan@apple.com | 4d97a00 | 2016-02-24 17:13:33 +0000 | [diff] [blame] | 2176 | LayoutUnit RenderBlockFlow::startAlignedOffsetForLine(LayoutUnit position, IndentTextOrNot shouldIndentText) |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 2177 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2178 | ETextAlign textAlign = style().textAlign(); |
zalan@apple.com | 4d97a00 | 2016-02-24 17:13:33 +0000 | [diff] [blame] | 2179 | bool shouldApplyIndentText = false; |
| 2180 | switch (textAlign) { |
| 2181 | case LEFT: |
| 2182 | case WEBKIT_LEFT: |
| 2183 | shouldApplyIndentText = style().isLeftToRightDirection(); |
| 2184 | break; |
| 2185 | case RIGHT: |
| 2186 | case WEBKIT_RIGHT: |
| 2187 | shouldApplyIndentText = !style().isLeftToRightDirection(); |
| 2188 | break; |
| 2189 | case TASTART: |
| 2190 | shouldApplyIndentText = true; |
| 2191 | break; |
| 2192 | default: |
| 2193 | shouldApplyIndentText = false; |
| 2194 | } |
hyatt@apple.com | a562669 | 2013-11-18 23:08:30 +0000 | [diff] [blame] | 2195 | // <rdar://problem/15427571> |
| 2196 | // https://bugs.webkit.org/show_bug.cgi?id=124522 |
| 2197 | // This quirk is for legacy content that doesn't work properly with the center positioning scheme |
| 2198 | // being honored (e.g., epubs). |
zalan@apple.com | 4d97a00 | 2016-02-24 17:13:33 +0000 | [diff] [blame] | 2199 | if (shouldApplyIndentText || document().settings()->useLegacyTextAlignPositionedElementBehavior()) // FIXME: Handle TAEND here |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 2200 | return startOffsetForLine(position, shouldIndentText); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 2201 | |
| 2202 | // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here |
robert@webkit.org | 82903f4 | 2012-08-28 19:18:40 +0000 | [diff] [blame] | 2203 | float totalLogicalWidth = 0; |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 2204 | float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), DoNotIndentText); |
| 2205 | float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), DoNotIndentText) - logicalLeft; |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 2206 | |
| 2207 | // FIXME: Bug 129311: We need to pass a valid RootInlineBox here, considering the bidi level used to construct the line. |
| 2208 | updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0); |
robert@webkit.org | 7861a10 | 2011-09-22 17:16:47 +0000 | [diff] [blame] | 2209 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2210 | if (!style().isLeftToRightDirection()) |
robert@webkit.org | 82903f4 | 2012-08-28 19:18:40 +0000 | [diff] [blame] | 2211 | return logicalWidth() - logicalLeft; |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 2212 | return logicalLeft; |
| 2213 | } |
| 2214 | |
abucur@adobe.com | d40287b | 2013-10-08 17:33:05 +0000 | [diff] [blame] | 2215 | void RenderBlockFlow::updateRegionForLine(RootInlineBox* lineBox) const |
| 2216 | { |
| 2217 | ASSERT(lineBox); |
akling@apple.com | bdf247b | 2014-01-13 22:33:08 +0000 | [diff] [blame] | 2218 | |
abucur@adobe.com | c18af35 | 2014-05-14 06:33:48 +0000 | [diff] [blame] | 2219 | if (!hasRegionRangeInFlowThread()) |
akling@apple.com | bdf247b | 2014-01-13 22:33:08 +0000 | [diff] [blame] | 2220 | lineBox->clearContainingRegion(); |
abucur@adobe.com | c18af35 | 2014-05-14 06:33:48 +0000 | [diff] [blame] | 2221 | else { |
| 2222 | if (auto containingRegion = regionAtBlockOffset(lineBox->lineTopWithLeading())) |
| 2223 | lineBox->setContainingRegion(*containingRegion); |
| 2224 | else |
| 2225 | lineBox->clearContainingRegion(); |
| 2226 | } |
abucur@adobe.com | d40287b | 2013-10-08 17:33:05 +0000 | [diff] [blame] | 2227 | |
| 2228 | RootInlineBox* prevLineBox = lineBox->prevRootBox(); |
| 2229 | if (!prevLineBox) |
| 2230 | return; |
| 2231 | |
| 2232 | // This check is more accurate than the one in |adjustLinePositionForPagination| because it takes into |
| 2233 | // account just the container changes between lines. The before mentioned function doesn't set the flag |
| 2234 | // correctly if the line is positioned at the top of the last fragment container. |
| 2235 | if (lineBox->containingRegion() != prevLineBox->containingRegion()) |
| 2236 | lineBox->setIsFirstAfterPageBreak(true); |
| 2237 | } |
| 2238 | |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 2239 | void RenderBlockFlow::marginCollapseLinesFromStart(LineLayoutState& layoutState, RootInlineBox* stopLine) |
| 2240 | { |
| 2241 | // We have to handle an anonymous inline block streak at the start of the block in order to make sure our own margins are |
| 2242 | // correct. We only have to do this if the children can propagate margins out to us. |
| 2243 | bool resetLogicalHeight = false; |
| 2244 | if (layoutState.marginInfo().canCollapseWithMarginBefore()) { |
| 2245 | RootInlineBox* startLine = firstRootBox(); |
| 2246 | RootInlineBox* curr; |
| 2247 | for (curr = startLine; curr && curr->hasAnonymousInlineBlock() && layoutState.marginInfo().canCollapseWithMarginBefore(); curr = curr->nextRootBox()) { |
| 2248 | if (curr == stopLine) |
| 2249 | return; |
| 2250 | if (!resetLogicalHeight) { |
| 2251 | setLogicalHeight(borderAndPaddingBefore()); |
| 2252 | resetLogicalHeight = true; |
| 2253 | } |
| 2254 | layoutBlockChild(*curr->anonymousInlineBlock(), layoutState.marginInfo(), |
| 2255 | layoutState.prevFloatBottomFromAnonymousInlineBlock(), layoutState.maxFloatBottomFromAnonymousInlineBlock()); |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | // Now that we've handled the top of the block, if the stopLine isn't an anonymous block, then we're done. |
| 2260 | if (!stopLine->hasAnonymousInlineBlock()) |
| 2261 | return; |
| 2262 | |
| 2263 | // Re-run margin collapsing on the block sequence that stopLine is a part of. |
| 2264 | // First go backwards to get the entire sequence. |
| 2265 | RootInlineBox* prev = stopLine; |
| 2266 | for ( ; prev->hasAnonymousInlineBlock(); prev = prev->prevRootBox()) { |
| 2267 | }; |
| 2268 | |
| 2269 | // Update the block height to the correct state. |
| 2270 | setLogicalHeight(prev->lineBottomWithLeading()); |
| 2271 | |
| 2272 | // Now run margin collapsing on those lines. |
| 2273 | for (prev = prev->nextRootBox(); prev != stopLine; prev = prev->nextRootBox()) |
| 2274 | layoutBlockChild(*prev->anonymousInlineBlock(), layoutState.marginInfo(), layoutState.prevFloatBottomFromAnonymousInlineBlock(), layoutState.maxFloatBottomFromAnonymousInlineBlock()); |
| 2275 | } |
| 2276 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2277 | } |