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" |
zoltan@webkit.org | 64be122 | 2013-11-15 21:40:59 +0000 | [diff] [blame] | 29 | #include "BreakingContextInlineHeaders.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 | |
zoltan@webkit.org | 64be122 | 2013-11-15 21:40:59 +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 | { |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 76 | ASSERT(obj); |
| 77 | return new BidiRun(start, end, *obj, resolver.context(), resolver.dir()); |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 78 | } |
| 79 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 80 | 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] | 81 | { |
leviw@chromium.org | d8df17d | 2012-05-24 21:47:47 +0000 | [diff] [blame] | 82 | if (start > end || shouldSkipCreatingRunsForObject(obj)) |
hyatt | eb003b8 | 2002-11-15 22:35:10 +0000 | [diff] [blame] | 83 | return; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 84 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 85 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
zoltan@webkit.org | 7585ad5 | 2014-01-21 21:33:22 +0000 | [diff] [blame] | 86 | bool haveNextMidpoint = (lineMidpointState.currentMidpoint() < lineMidpointState.numMidpoints()); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 87 | InlineIterator nextMidpoint; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 88 | if (haveNextMidpoint) |
zoltan@webkit.org | 7585ad5 | 2014-01-21 21:33:22 +0000 | [diff] [blame] | 89 | nextMidpoint = lineMidpointState.midpoints()[lineMidpointState.currentMidpoint()]; |
| 90 | if (lineMidpointState.betweenMidpoints()) { |
gyuyoung.kim@samsung.com | 113fb8b | 2013-11-28 23:25:19 +0000 | [diff] [blame] | 91 | if (!(haveNextMidpoint && nextMidpoint.renderer() == obj)) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 92 | return; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 93 | // This is a new start point. Stop ignoring objects and |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 94 | // adjust our start. |
zoltan@webkit.org | 7585ad5 | 2014-01-21 21:33:22 +0000 | [diff] [blame] | 95 | lineMidpointState.setBetweenMidpoints(false); |
gyuyoung.kim@samsung.com | 044376f | 2013-12-26 07:32:04 +0000 | [diff] [blame] | 96 | start = nextMidpoint.offset(); |
zoltan@webkit.org | 7585ad5 | 2014-01-21 21:33:22 +0000 | [diff] [blame] | 97 | lineMidpointState.incrementCurrentMidpoint(); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 98 | if (start < end) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 99 | return appendRunsForObject(runs, start, end, obj, resolver); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 100 | } else { |
gyuyoung.kim@samsung.com | 113fb8b | 2013-11-28 23:25:19 +0000 | [diff] [blame] | 101 | if (!haveNextMidpoint || (obj != nextMidpoint.renderer())) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 102 | runs.addRun(createRun(start, end, obj, resolver)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 103 | return; |
| 104 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 105 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 106 | // An end midpoint has been encountered within our object. We |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 107 | // need to go ahead and 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.setBetweenMidpoints(true); |
| 110 | lineMidpointState.incrementCurrentMidpoint(); |
mmaxfield@apple.com | 0682d51 | 2014-03-25 20:15:14 +0000 | [diff] [blame] | 111 | // The end of the line is before the object we're inspecting. Skip everything and return |
| 112 | if (nextMidpoint.refersToEndOfPreviousNode()) |
| 113 | return; |
| 114 | if (static_cast<int>(nextMidpoint.offset() + 1) > start) |
| 115 | runs.addRun(createRun(start, nextMidpoint.offset() + 1, obj, resolver)); |
| 116 | appendRunsForObject(runs, nextMidpoint.offset() + 1, end, obj, resolver); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 117 | } else |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 118 | runs.addRun(createRun(start, end, obj, resolver)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 122 | std::unique_ptr<RootInlineBox> RenderBlockFlow::createRootInlineBox() |
weinig@apple.com | cef4e1e | 2013-10-19 03:14:44 +0000 | [diff] [blame] | 123 | { |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 124 | return std::make_unique<RootInlineBox>(*this); |
weinig@apple.com | cef4e1e | 2013-10-19 03:14:44 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox() |
| 128 | { |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 129 | auto newRootBox = createRootInlineBox(); |
| 130 | RootInlineBox* rootBox = newRootBox.get(); |
dbates@webkit.org | 0cefe4f | 2014-07-03 22:13:54 +0000 | [diff] [blame] | 131 | m_lineBoxes.appendLineBox(WTF::move(newRootBox)); |
weinig@apple.com | cef4e1e | 2013-10-19 03:14:44 +0000 | [diff] [blame] | 132 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 133 | if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && firstRootBox() == rootBox) { |
weinig@apple.com | cef4e1e | 2013-10-19 03:14:44 +0000 | [diff] [blame] | 134 | if (AXObjectCache* cache = document().existingAXObjectCache()) |
| 135 | cache->recomputeIsIgnored(this); |
| 136 | } |
| 137 | |
| 138 | return rootBox; |
| 139 | } |
| 140 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 141 | static inline InlineBox* createInlineBoxForRenderer(RenderObject* renderer, bool isRootLineBox, bool isOnlyRun = false) |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 142 | { |
| 143 | if (isRootLineBox) |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 144 | return downcast<RenderBlockFlow>(*renderer).createAndAppendRootInlineBox(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 145 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 146 | if (is<RenderText>(*renderer)) |
| 147 | return downcast<RenderText>(*renderer).createInlineTextBox(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 148 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 149 | if (is<RenderBox>(*renderer)) { |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 150 | // FIXME: This is terrible. This branch returns an *owned* pointer! |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 151 | return downcast<RenderBox>(*renderer).createInlineBox().release(); |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 152 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 153 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 154 | if (is<RenderLineBreak>(*renderer)) { |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 155 | // FIXME: This is terrible. This branch returns an *owned* pointer! |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 156 | auto inlineBox = downcast<RenderLineBreak>(*renderer).createInlineBox().release(); |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 157 | // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode |
| 158 | // (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] | 159 | inlineBox->setBehavesLikeText(isOnlyRun || renderer->document().inNoQuirksMode() || renderer->isLineBreakOpportunity()); |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 160 | return inlineBox; |
| 161 | } |
| 162 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 163 | return downcast<RenderInline>(*renderer).createAndAppendInlineFlowBox(); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 164 | } |
| 165 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 166 | static inline void dirtyLineBoxesForRenderer(RenderObject& renderer, bool fullLayout) |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 167 | { |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 168 | if (is<RenderText>(renderer)) { |
| 169 | RenderText& renderText = downcast<RenderText>(renderer); |
esprehn@chromium.org | 7745ffb | 2013-02-19 21:51:19 +0000 | [diff] [blame] | 170 | updateCounterIfNeeded(renderText); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 171 | renderText.dirtyLineBoxes(fullLayout); |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 172 | } else if (is<RenderLineBreak>(renderer)) |
| 173 | downcast<RenderLineBreak>(renderer).dirtyLineBoxes(fullLayout); |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 174 | else |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 175 | downcast<RenderInline>(renderer).dirtyLineBoxes(fullLayout); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 176 | } |
| 177 | |
xji@chromium.org | b0ad6eb82 | 2011-02-01 20:02:06 +0000 | [diff] [blame] | 178 | static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox) |
| 179 | { |
| 180 | do { |
| 181 | if (parentBox->isConstructed() || parentBox->nextOnLine()) |
| 182 | return true; |
| 183 | parentBox = parentBox->parent(); |
| 184 | } while (parentBox); |
| 185 | return false; |
| 186 | } |
| 187 | |
bjonesbe@adobe.com | fb6ceac | 2014-04-15 00:27:13 +0000 | [diff] [blame] | 188 | InlineFlowBox* RenderBlockFlow::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 189 | { |
| 190 | // See if we have an unconstructed line box for this object that is also |
| 191 | // the last item on the line. |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 192 | unsigned lineDepth = 1; |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 193 | InlineFlowBox* parentBox = nullptr; |
| 194 | InlineFlowBox* result = nullptr; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 195 | bool hasDefaultLineBoxContain = style().lineBoxContain() == RenderStyle::initialLineBoxContain(); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 196 | do { |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 197 | ASSERT_WITH_SECURITY_IMPLICATION(is<RenderInline>(*obj) || obj == this); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 198 | |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 199 | RenderInline* inlineFlow = obj != this ? downcast<RenderInline>(obj) : nullptr; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 200 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 201 | // Get the last box we made for this render object. |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 202 | parentBox = inlineFlow ? inlineFlow->lastLineBox() : downcast<RenderBlockFlow>(*obj).lastRootBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 203 | |
xji@chromium.org | b0ad6eb82 | 2011-02-01 20:02:06 +0000 | [diff] [blame] | 204 | // If this box or its ancestor is constructed then it is from a previous line, and we need |
| 205 | // 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] | 206 | // something following it on the line, then we know we have to make a new box |
| 207 | // as well. In this situation our inline has actually been split in two on |
| 208 | // the same line (this can happen with very fancy language mixtures). |
| 209 | bool constructedNewBox = false; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 210 | bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes(); |
bjonesbe@adobe.com | fb6ceac | 2014-04-15 00:27:13 +0000 | [diff] [blame] | 211 | bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox); |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 212 | if (allowedToConstructNewBox && !canUseExistingParentBox) { |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 213 | // We need to make a new box for this render object. Once |
| 214 | // 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] | 215 | InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this); |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 216 | parentBox = downcast<InlineFlowBox>(newBox); |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 217 | parentBox->setIsFirstLine(lineInfo.isFirstLine()); |
hyatt@apple.com | 2a5eb21 | 2011-03-22 23:21:54 +0000 | [diff] [blame] | 218 | parentBox->setIsHorizontal(isHorizontalWritingMode()); |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 219 | if (!hasDefaultLineBoxContain) |
| 220 | parentBox->clearDescendantsHaveSameLineHeightAndBaseline(); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 221 | constructedNewBox = true; |
| 222 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 223 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 224 | if (constructedNewBox || canUseExistingParentBox) { |
| 225 | if (!result) |
| 226 | result = parentBox; |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 227 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 228 | // If we have hit the block itself, then |box| represents the root |
| 229 | // inline box for the line, and it doesn't have to be appended to any parent |
| 230 | // inline. |
| 231 | if (childBox) |
| 232 | parentBox->addToLine(childBox); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 233 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 234 | if (!constructedNewBox || obj == this) |
| 235 | break; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 236 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 237 | childBox = parentBox; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 238 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 239 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 240 | // If we've exceeded our line depth, then jump straight to the root and skip all the remaining |
| 241 | // intermediate inline flows. |
| 242 | obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 243 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 244 | } while (true); |
| 245 | |
| 246 | return result; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 247 | } |
| 248 | |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 249 | template <typename CharacterType> |
| 250 | static inline bool endsWithASCIISpaces(const CharacterType* characters, unsigned pos, unsigned end) |
| 251 | { |
| 252 | while (isASCIISpace(characters[pos])) { |
| 253 | pos++; |
| 254 | if (pos >= end) |
| 255 | return true; |
| 256 | } |
| 257 | return false; |
| 258 | } |
| 259 | |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 260 | static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 261 | { |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 262 | BidiRun* run = bidiRuns.logicallyLastRun(); |
| 263 | if (!run) |
| 264 | return true; |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 265 | unsigned pos = run->stop(); |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 266 | const RenderObject& renderer = run->renderer(); |
| 267 | if (!is<RenderText>(renderer)) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 268 | return false; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 269 | const RenderText& renderText = downcast<RenderText>(renderer); |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 270 | unsigned length = renderText.textLength(); |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 271 | if (pos >= length) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 272 | return true; |
| 273 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 274 | if (renderText.is8Bit()) |
| 275 | return endsWithASCIISpaces(renderText.characters8(), pos, length); |
| 276 | return endsWithASCIISpaces(renderText.characters16(), pos, length); |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 277 | } |
| 278 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 279 | RootInlineBox* RenderBlockFlow::constructLine(BidiRunList<BidiRun>& bidiRuns, const LineInfo& lineInfo) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 280 | { |
| 281 | ASSERT(bidiRuns.firstRun()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 282 | |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 283 | bool rootHasSelectedChildren = false; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 284 | InlineFlowBox* parentBox = 0; |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 285 | int runCount = bidiRuns.runCount() - lineInfo.runsFromLeadingWhitespace(); |
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; |
| 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. |
bjonesbe@adobe.com | fb6ceac | 2014-04-15 00:27:13 +0000 | [diff] [blame] | 307 | parentBox = createLineBoxes(r->renderer().parent(), lineInfo, box); |
| 308 | } else { |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 309 | // Append the inline box to this line. |
| 310 | parentBox->addToLine(box); |
| 311 | } |
mitz@apple.com | 576e84e | 2008-04-24 19:09:48 +0000 | [diff] [blame] | 312 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 313 | bool visuallyOrdered = r->renderer().style().rtlOrdering() == VisualOrder; |
xji@chromium.org | 6b0c017 | 2011-02-14 19:21:12 +0000 | [diff] [blame] | 314 | box->setBidiLevel(r->level()); |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 315 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 316 | if (is<InlineTextBox>(*box)) { |
| 317 | auto& textBox = downcast<InlineTextBox>(*box); |
| 318 | textBox.setStart(r->m_start); |
| 319 | textBox.setLen(r->m_stop - r->m_start); |
| 320 | textBox.setDirOverride(r->dirOverride(visuallyOrdered)); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 321 | if (r->m_hasHyphen) |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 322 | textBox.setHasHyphen(true); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 323 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | // We should have a root inline box. It should be unconstructed and |
| 327 | // be the last continuation of our line list. |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 328 | ASSERT(lastRootBox() && !lastRootBox()->isConstructed()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 329 | |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 330 | // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box |
| 331 | // from the bidi runs walk above has a selection state. |
| 332 | if (rootHasSelectedChildren) |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 333 | lastRootBox()->root().setHasSelectedChildren(true); |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 334 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 335 | // Set bits on our inline flow boxes that indicate which sides should |
| 336 | // paint borders/margins/padding. This knowledge will ultimately be used when |
| 337 | // we determine the horizontal positions and widths of all the inline boxes on |
| 338 | // the line. |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 339 | bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->renderer().isText() ? !reachedEndOfTextRenderer(bidiRuns) : true; |
| 340 | lastRootBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, &bidiRuns.logicallyLastRun()->renderer()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 341 | |
| 342 | // Now mark the line boxes as being constructed. |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 343 | lastRootBox()->setConstructed(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 344 | |
| 345 | // Return the last line. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 346 | return lastRootBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 347 | } |
| 348 | |
weinig@apple.com | 6b4a2414 | 2014-01-05 00:28:39 +0000 | [diff] [blame] | 349 | ETextAlign RenderBlockFlow::textAlignmentForLine(bool endsWithSoftBreak) const |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 350 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 351 | ETextAlign alignment = style().textAlign(); |
zoltan@webkit.org | cb4f0e4 | 2014-08-13 18:00:27 +0000 | [diff] [blame] | 352 | #if ENABLE(CSS3_TEXT) |
| 353 | TextJustify textJustify = style().textJustify(); |
zoltan@webkit.org | 14989c3 | 2014-08-14 21:36:40 +0000 | [diff] [blame] | 354 | if (alignment == JUSTIFY && textJustify == TextJustifyNone) |
zoltan@webkit.org | cb4f0e4 | 2014-08-13 18:00:27 +0000 | [diff] [blame] | 355 | return style().direction() == LTR ? LEFT : RIGHT; |
| 356 | #endif |
| 357 | |
zoltan@webkit.org | cb7f93f | 2014-01-17 20:33:04 +0000 | [diff] [blame] | 358 | if (endsWithSoftBreak) |
| 359 | return alignment; |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 360 | |
zoltan@webkit.org | 14989c3 | 2014-08-14 21:36:40 +0000 | [diff] [blame] | 361 | #if !ENABLE(CSS3_TEXT) |
| 362 | return (alignment == JUSTIFY) ? TASTART : alignment; |
| 363 | #else |
zoltan@webkit.org | cb7f93f | 2014-01-17 20:33:04 +0000 | [diff] [blame] | 364 | if (alignment != JUSTIFY) |
| 365 | return alignment; |
| 366 | |
| 367 | TextAlignLast alignmentLast = style().textAlignLast(); |
| 368 | switch (alignmentLast) { |
| 369 | case TextAlignLastStart: |
| 370 | return TASTART; |
| 371 | case TextAlignLastEnd: |
| 372 | return TAEND; |
| 373 | case TextAlignLastLeft: |
| 374 | return LEFT; |
| 375 | case TextAlignLastRight: |
| 376 | return RIGHT; |
| 377 | case TextAlignLastCenter: |
| 378 | return CENTER; |
| 379 | case TextAlignLastJustify: |
| 380 | return JUSTIFY; |
| 381 | case TextAlignLastAuto: |
zoltan@webkit.org | cb4f0e4 | 2014-08-13 18:00:27 +0000 | [diff] [blame] | 382 | if (textJustify == TextJustifyDistribute) |
zoltan@webkit.org | cb7f93f | 2014-01-17 20:33:04 +0000 | [diff] [blame] | 383 | return JUSTIFY; |
| 384 | return TASTART; |
| 385 | } |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 386 | return alignment; |
zoltan@webkit.org | cb7f93f | 2014-01-17 20:33:04 +0000 | [diff] [blame] | 387 | #endif |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 388 | } |
| 389 | |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 390 | static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 391 | { |
| 392 | // The direction of the block should determine what happens with wide lines. |
| 393 | // In particular with RTL blocks, wide lines should still spill out to the left. |
| 394 | if (isLeftToRightDirection) { |
| 395 | if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 396 | 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] | 397 | return; |
| 398 | } |
| 399 | |
| 400 | if (trailingSpaceRun) |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 401 | trailingSpaceRun->box()->setLogicalWidth(0); |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 402 | else if (totalLogicalWidth > availableLogicalWidth) |
| 403 | logicalLeft -= (totalLogicalWidth - availableLogicalWidth); |
| 404 | } |
| 405 | |
| 406 | static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 407 | { |
| 408 | // Wide lines spill out of the block based off direction. |
| 409 | // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right |
| 410 | // side of the block. |
| 411 | if (isLeftToRightDirection) { |
| 412 | if (trailingSpaceRun) { |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 413 | totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth(); |
| 414 | trailingSpaceRun->box()->setLogicalWidth(0); |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 415 | } |
| 416 | if (totalLogicalWidth < availableLogicalWidth) |
| 417 | logicalLeft += availableLogicalWidth - totalLogicalWidth; |
| 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 | |
| 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 | |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +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 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 485 | bool kerningIsEnabled = font.typesettingFeatures() & Kerning; |
leviw@chromium.org | d70f4cc | 2013-03-28 21:03:44 +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; |
| 497 | if (wordMeasurement.renderer != renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop) |
| 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; |
| 504 | measuredWidth += renderer->width(wordMeasurement.startOffset, wordLength, xPos + measuredWidth, lineInfo.isFirstLine(), |
| 505 | &wordMeasurement.fallbackFonts, &overflow); |
dino@apple.com | d0b8925 | 2013-05-10 18:20:28 +0000 | [diff] [blame] | 506 | UChar c = renderer->characterAt(wordMeasurement.startOffset); |
| 507 | if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t')) |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +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()) { |
antti@apple.com | 5a8f794 | 2015-01-22 21:57:04 +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) |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 514 | fallbackFonts.add(*it); |
| 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) |
| 525 | measuredWidth = renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow); |
| 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. |
| 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 | |
| 569 | if (totalOpportunitiesInRun) { |
| 570 | ASSERT(!rubyRun.hasOverrideWidth()); |
commit-queue@webkit.org | 01ad584 | 2014-12-16 19:28:57 +0000 | [diff] [blame] | 571 | float newBaseWidth = rubyRun.logicalWidth() + totalExpansion + marginStartForChild(rubyRun) + marginEndForChild(rubyRun); |
| 572 | float newRubyRunWidth = rubyRun.logicalWidth() + totalExpansion; |
| 573 | rubyBase.setInitialOffset((newRubyRunWidth - newBaseWidth) / 2); |
| 574 | rubyRun.setOverrideLogicalContentWidth(newRubyRunWidth); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 575 | rubyRun.setNeedsLayout(MarkOnlyThis); |
commit-queue@webkit.org | 01ad584 | 2014-12-16 19:28:57 +0000 | [diff] [blame] | 576 | rootBox.markDirty(); |
| 577 | if (RenderRubyText* rubyText = rubyRun.rubyText()) { |
| 578 | if (RootInlineBox* textRootBox = rubyText->firstRootBox()) |
| 579 | textRootBox->markDirty(); |
| 580 | } |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 581 | rubyRun.layoutBlock(true); |
| 582 | rubyRun.clearOverrideLogicalContentWidth(); |
commit-queue@webkit.org | 01ad584 | 2014-12-16 19:28:57 +0000 | [diff] [blame] | 583 | r.box()->setExpansion(newRubyRunWidth - r.box()->logicalWidth()); |
| 584 | |
| 585 | // 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 |
| 586 | // RenderRubyRun, make sure that we relayout the RenderRubyBase and RenderRubyText as well. |
| 587 | rubyBase.setNeedsLayout(MarkOnlyThis); |
| 588 | if (RenderRubyText* rubyText = rubyRun.rubyText()) |
| 589 | rubyText->setNeedsLayout(MarkOnlyThis); |
| 590 | if (rubyBase.lastLeafChild() && is<RenderText>(rubyBase.lastLeafChild()) && r.box() && r.box()->nextLeafChild() && !r.box()->nextLeafChild()->isLineBreak()) |
| 591 | downcast<RenderText>(rubyBase.lastLeafChild())->setContentIsKnownToFollow(true); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 592 | |
| 593 | totalLogicalWidth += totalExpansion; |
| 594 | expansionOpportunityCount -= totalOpportunitiesInRun; |
| 595 | } |
| 596 | } |
| 597 | |
mmaxfield@apple.com | b2c6d86 | 2015-02-18 19:39:17 +0000 | [diff] [blame^] | 598 | 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] | 599 | { |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 600 | if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth) |
| 601 | return; |
| 602 | |
| 603 | size_t i = 0; |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 604 | for (BidiRun* run = firstRun; run; run = run->next()) { |
mmaxfield@apple.com | b2c6d86 | 2015-02-18 19:39:17 +0000 | [diff] [blame^] | 605 | if (!run->box() || run == trailingSpaceRun) |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 606 | continue; |
| 607 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 608 | if (is<RenderText>(run->renderer())) { |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 609 | unsigned opportunitiesInRun = expansionOpportunities[i++]; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 610 | |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 611 | ASSERT(opportunitiesInRun <= expansionOpportunityCount); |
| 612 | |
| 613 | // Only justify text if whitespace is collapsed. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 614 | if (run->renderer().style().collapseWhiteSpace()) { |
| 615 | InlineTextBox& textBox = downcast<InlineTextBox>(*run->box()); |
mmaxfield@apple.com | a9f58d0 | 2014-10-02 22:25:50 +0000 | [diff] [blame] | 616 | float expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount; |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 617 | textBox.setExpansion(expansion); |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 618 | totalLogicalWidth += expansion; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 619 | } |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 620 | expansionOpportunityCount -= opportunitiesInRun; |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 621 | } else if (is<RenderRubyRun>(run->renderer())) |
mmaxfield@apple.com | b2c6d86 | 2015-02-18 19:39:17 +0000 | [diff] [blame^] | 622 | updateRubyForJustifiedText(downcast<RenderRubyRun>(run->renderer()), *run, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth, i); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 623 | |
| 624 | if (!expansionOpportunityCount) |
| 625 | break; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 629 | 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] | 630 | { |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 631 | TextDirection direction; |
| 632 | if (rootInlineBox && style().unicodeBidi() == Plaintext) |
| 633 | direction = rootInlineBox->direction(); |
| 634 | else |
| 635 | direction = style().direction(); |
| 636 | |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 637 | // Armed with the total width of the line (without justification), |
| 638 | // we now examine our text-align property in order to determine where to position the |
| 639 | // objects horizontally. The total width of the line can be increased if we end up |
| 640 | // justifying text. |
| 641 | switch (textAlign) { |
| 642 | case LEFT: |
| 643 | case WEBKIT_LEFT: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 644 | updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 645 | break; |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 646 | case RIGHT: |
| 647 | case WEBKIT_RIGHT: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 648 | updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 649 | break; |
| 650 | case CENTER: |
| 651 | case WEBKIT_CENTER: |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 652 | updateLogicalWidthForCenterAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 653 | break; |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 654 | case JUSTIFY: |
| 655 | adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth); |
| 656 | if (expansionOpportunityCount) { |
| 657 | if (trailingSpaceRun) { |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 658 | totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth(); |
| 659 | trailingSpaceRun->box()->setLogicalWidth(0); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 660 | } |
| 661 | break; |
| 662 | } |
joepeck@webkit.org | aa676ee5 | 2014-01-28 04:04:52 +0000 | [diff] [blame] | 663 | FALLTHROUGH; |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 664 | case TASTART: |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 665 | if (direction == LTR) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 666 | updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 667 | else |
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 | break; |
| 670 | case TAEND: |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 671 | if (direction == LTR) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 672 | updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 673 | else |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 674 | updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 675 | break; |
| 676 | } |
| 677 | } |
| 678 | |
weinig@apple.com | e9621c3 | 2014-01-04 20:53:51 +0000 | [diff] [blame] | 679 | static void updateLogicalInlinePositions(RenderBlockFlow& block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight) |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 680 | { |
weinig@apple.com | e9621c3 | 2014-01-04 20:53:51 +0000 | [diff] [blame] | 681 | LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight); |
zalan@apple.com | bfa1195 | 2014-05-19 17:37:22 +0000 | [diff] [blame] | 682 | lineLogicalLeft = block.logicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight); |
| 683 | lineLogicalRight = block.logicalRightOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight); |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 684 | availableLogicalWidth = lineLogicalRight - lineLogicalLeft; |
| 685 | } |
| 686 | |
weinig@apple.com | e9621c3 | 2014-01-04 20:53:51 +0000 | [diff] [blame] | 687 | 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] | 688 | { |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 689 | ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak()); |
robert@webkit.org | 4f76df9 | 2012-07-03 17:41:35 +0000 | [diff] [blame] | 690 | |
robert@webkit.org | 328ecd0 | 2012-08-09 21:12:44 +0000 | [diff] [blame] | 691 | // 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 |
| 692 | // 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] | 693 | // CSS3 "text-indent", "-webkit-each-line" affects the first line of the block container as well as each line after a forced line break, |
| 694 | // but does not affect lines after a soft wrap break. |
| 695 | bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this); |
| 696 | bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox()->endsWithBreak(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 697 | IndentTextOrNot shouldIndentText = requiresIndent(isFirstLine, isAfterHardLineBreak, style()); |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 698 | float lineLogicalLeft; |
| 699 | float lineLogicalRight; |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 700 | float availableLogicalWidth; |
weinig@apple.com | e9621c3 | 2014-01-04 20:53:51 +0000 | [diff] [blame] | 701 | updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 702 | bool needsWordSpacing; |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 703 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 704 | if (firstRun && firstRun->renderer().isReplaced()) { |
cdumez@apple.com | 0abff8b | 2014-10-17 21:25:10 +0000 | [diff] [blame] | 705 | RenderBox& renderBox = downcast<RenderBox>(firstRun->renderer()); |
weinig@apple.com | e9621c3 | 2014-01-04 20:53:51 +0000 | [diff] [blame] | 706 | updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight()); |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | 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] | 710 | // The widths of all runs are now known. We can now place every inline box (and |
| 711 | // compute accurate widths for the inline flow boxes). |
| 712 | needsWordSpacing = false; |
mmaxfield@apple.com | b0a4a3f | 2014-04-30 00:36:21 +0000 | [diff] [blame] | 713 | lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 714 | } |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 715 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 716 | 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] | 717 | float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, |
| 718 | WordMeasurements& wordMeasurements) |
| 719 | { |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 720 | bool needsWordSpacing = false; |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 721 | float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth(); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 722 | unsigned expansionOpportunityCount = 0; |
commit-queue@webkit.org | 01ad584 | 2014-12-16 19:28:57 +0000 | [diff] [blame] | 723 | bool isAfterExpansion = is<RenderRubyBase>(*this) ? downcast<RenderRubyBase>(*this).isAfterExpansion() : true; |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 724 | Vector<unsigned, 16> expansionOpportunities; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 725 | RenderObject* previousObject = nullptr; |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 726 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 727 | BidiRun* run = firstRun; |
| 728 | for (; run; run = run->next()) { |
| 729 | if (!run->box() || run->renderer().isOutOfFlowPositioned() || run->box()->isLineBreak()) { |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 730 | continue; // Positioned objects are only participating to figure out their |
| 731 | // correct static x position. They have no effect on the width. |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 732 | // Similarly, line break boxes have no effect on the width. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 733 | } |
| 734 | if (is<RenderText>(run->renderer())) { |
| 735 | auto& renderText = downcast<RenderText>(run->renderer()); |
| 736 | if (textAlign == JUSTIFY && run != trailingSpaceRun) { |
mitz@apple.com | 8096893 | 2011-03-26 00:46:26 +0000 | [diff] [blame] | 737 | if (!isAfterExpansion) |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 738 | downcast<InlineTextBox>(*run->box()).setCanHaveLeadingExpansion(true); |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +0000 | [diff] [blame] | 739 | unsigned opportunitiesInRun = FontCascade::expansionOpportunityCount(renderText.stringView(run->m_start, run->m_stop), run->box()->direction(), isAfterExpansion); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 740 | expansionOpportunities.append(opportunitiesInRun); |
| 741 | expansionOpportunityCount += opportunitiesInRun; |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 742 | } |
| 743 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 744 | if (int length = renderText.textLength()) { |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 745 | if (!run->m_start && needsWordSpacing && isSpaceOrNewline(renderText.characterAt(run->m_start))) |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +0000 | [diff] [blame] | 746 | totalLogicalWidth += lineStyle(*renderText.parent(), lineInfo).fontCascade().wordSpacing(); |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 747 | needsWordSpacing = !isSpaceOrNewline(renderText.characterAt(run->m_stop - 1)) && run->m_stop == length; |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 748 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 749 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 750 | setLogicalWidthForTextRun(lineBox, run, &renderText, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 751 | } else { |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 752 | bool encounteredJustifiedRuby = false; |
cdumez@apple.com | 3abcc79 | 2014-10-20 03:42:03 +0000 | [diff] [blame] | 753 | 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] | 754 | auto* rubyBase = downcast<RenderRubyRun>(run->renderer()).rubyBase(); |
| 755 | if (rubyBase->firstRootBox() && !rubyBase->firstRootBox()->nextRootBox() && run->renderer().style().collapseWhiteSpace()) { |
commit-queue@webkit.org | 01ad584 | 2014-12-16 19:28:57 +0000 | [diff] [blame] | 756 | rubyBase->setIsAfterExpansion(isAfterExpansion); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 757 | for (auto* leafChild = rubyBase->firstRootBox()->firstLeafChild(); leafChild; leafChild = leafChild->nextLeafChild()) { |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 758 | if (!is<InlineTextBox>(*leafChild)) |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 759 | continue; |
| 760 | if (!isAfterExpansion) |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 761 | downcast<InlineTextBox>(*leafChild).setCanHaveLeadingExpansion(true); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 762 | encounteredJustifiedRuby = true; |
| 763 | auto& renderText = downcast<RenderText>(leafChild->renderer()); |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +0000 | [diff] [blame] | 764 | unsigned opportunitiesInRun = FontCascade::expansionOpportunityCount(renderText.stringView(), leafChild->direction(), isAfterExpansion); |
mmaxfield@apple.com | 8301e83 | 2014-10-09 01:14:30 +0000 | [diff] [blame] | 765 | expansionOpportunities.append(opportunitiesInRun); |
| 766 | expansionOpportunityCount += opportunitiesInRun; |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | if (!encounteredJustifiedRuby) |
| 772 | isAfterExpansion = false; |
| 773 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 774 | if (!is<RenderInline>(run->renderer())) { |
| 775 | auto& renderBox = downcast<RenderBox>(run->renderer()); |
| 776 | if (is<RenderRubyRun>(renderBox)) |
| 777 | setMarginsForRubyRun(run, downcast<RenderRubyRun>(renderBox), previousObject, lineInfo); |
| 778 | run->box()->setLogicalWidth(logicalWidthForChild(renderBox)); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 779 | totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox); |
| 780 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 781 | } |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 782 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 783 | totalLogicalWidth += run->box()->logicalWidth(); |
| 784 | previousObject = &run->renderer(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 785 | } |
| 786 | |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 787 | if (isAfterExpansion && !expansionOpportunities.isEmpty()) { |
commit-queue@webkit.org | 01ad584 | 2014-12-16 19:28:57 +0000 | [diff] [blame] | 788 | bool shouldShareExpansionsWithContainingLine = true; |
| 789 | if (is<RenderRubyBase>(*this)) { |
| 790 | if (RenderRubyRun* rubyRun = downcast<RenderRubyBase>(*this).rubyRun()) { |
| 791 | if (RenderElement* rubyElement = rubyRun->parent()) { |
| 792 | if (rubyElement->style().display() == INLINE) { |
| 793 | if (RenderBlock* containingBlock = rubyElement->containingBlock()) { |
| 794 | if (containingBlock->style().textAlign() == JUSTIFY) |
| 795 | shouldShareExpansionsWithContainingLine = false; |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | if (shouldShareExpansionsWithContainingLine) { |
| 802 | expansionOpportunities.last()--; |
| 803 | expansionOpportunityCount--; |
| 804 | } |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 805 | } |
| 806 | |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 807 | updateLogicalWidthForAlignment(textAlign, lineBox, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 808 | |
mmaxfield@apple.com | b2c6d86 | 2015-02-18 19:39:17 +0000 | [diff] [blame^] | 809 | computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 810 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 811 | return run; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 812 | } |
| 813 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 814 | void RenderBlockFlow::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 815 | VerticalPositionCache& verticalPositionCache) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 816 | { |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 817 | setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache)); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 818 | |
| 819 | // Now make sure we place replaced render objects correctly. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 820 | for (BidiRun* run = firstRun; run; run = run->next()) { |
| 821 | ASSERT(run->box()); |
| 822 | if (!run->box()) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 823 | continue; // Skip runs with no line boxes. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 824 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 825 | InlineBox& box = *run->box(); |
akling@apple.com | 27e7d14 | 2013-11-07 12:04:02 +0000 | [diff] [blame] | 826 | |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 827 | // Align positioned boxes with the top of the line box. This is |
| 828 | // a reasonable approximation of an appropriate y position. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 829 | if (run->renderer().isOutOfFlowPositioned()) |
akling@apple.com | 27e7d14 | 2013-11-07 12:04:02 +0000 | [diff] [blame] | 830 | box.setLogicalTop(logicalHeight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 831 | |
| 832 | // Position is used to properly position both replaced elements and |
| 833 | // to update the static normal flow x/y of positioned elements. |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 834 | if (is<RenderText>(run->renderer())) |
| 835 | downcast<RenderText>(run->renderer()).positionLineBox(downcast<InlineTextBox>(box)); |
| 836 | else if (is<RenderBox>(run->renderer())) |
| 837 | downcast<RenderBox>(run->renderer()).positionLineBox(downcast<InlineElementBox>(box)); |
| 838 | else if (is<RenderLineBreak>(run->renderer())) |
| 839 | downcast<RenderLineBreak>(run->renderer()).replaceInlineBoxWrapper(downcast<InlineElementBox>(box)); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 840 | } |
mitz@apple.com | a927be6 | 2008-03-21 05:30:19 +0000 | [diff] [blame] | 841 | // Positioned objects and zero-length text nodes destroy their boxes in |
| 842 | // position(), which unnecessarily dirties the line. |
| 843 | lineBox->markDirty(false); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 844 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 845 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 846 | static inline bool isCollapsibleSpace(UChar character, const RenderText& renderer) |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 847 | { |
| 848 | if (character == ' ' || character == '\t' || character == softHyphen) |
| 849 | return true; |
| 850 | if (character == '\n') |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 851 | return !renderer.style().preserveNewline(); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 852 | if (character == noBreakSpace) |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 853 | return renderer.style().nbspMode() == SPACE; |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 854 | return false; |
| 855 | } |
| 856 | |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 857 | template <typename CharacterType> |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 858 | 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] | 859 | { |
| 860 | int firstSpace = stop; |
| 861 | while (firstSpace > start) { |
| 862 | UChar current = characters[firstSpace - 1]; |
| 863 | if (!isCollapsibleSpace(current, lastText)) |
| 864 | break; |
| 865 | firstSpace--; |
| 866 | } |
| 867 | |
| 868 | return firstSpace; |
| 869 | } |
| 870 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 871 | inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext) |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 872 | { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 873 | if (!bidiRuns.runCount() |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 874 | || !bidiRuns.logicallyLastRun()->renderer().style().breakOnlyAfterWhiteSpace() |
| 875 | || !bidiRuns.logicallyLastRun()->renderer().style().autoWrap()) |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 876 | return nullptr; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 877 | |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 878 | BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun(); |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 879 | const RenderObject& lastObject = trailingSpaceRun->renderer(); |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 880 | if (!is<RenderText>(lastObject)) |
| 881 | return nullptr; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 882 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 883 | const RenderText& lastText = downcast<RenderText>(lastObject); |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 884 | int firstSpace; |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 885 | if (lastText.is8Bit()) |
| 886 | firstSpace = findFirstTrailingSpace(lastText, lastText.characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop()); |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 887 | else |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 888 | firstSpace = findFirstTrailingSpace(lastText, lastText.characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop()); |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 889 | |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 890 | if (firstSpace == trailingSpaceRun->stop()) |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 891 | return nullptr; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 892 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 893 | TextDirection direction = style().direction(); |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 894 | bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun()); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 895 | if (firstSpace != trailingSpaceRun->start()) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 896 | BidiContext* baseContext = currentContext; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 897 | while (BidiContext* parent = baseContext->parent()) |
| 898 | baseContext = parent; |
| 899 | |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 900 | 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] | 901 | trailingSpaceRun->m_stop = firstSpace; |
| 902 | if (direction == LTR) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 903 | bidiRuns.addRun(newTrailingRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 904 | else |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 905 | bidiRuns.prependRun(newTrailingRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 906 | trailingSpaceRun = newTrailingRun; |
| 907 | return trailingSpaceRun; |
| 908 | } |
| 909 | if (!shouldReorder) |
| 910 | return trailingSpaceRun; |
| 911 | |
| 912 | if (direction == LTR) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 913 | bidiRuns.moveRunToEnd(trailingSpaceRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 914 | trailingSpaceRun->m_level = 0; |
| 915 | } else { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 916 | bidiRuns.moveRunToBeginning(trailingSpaceRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 917 | trailingSpaceRun->m_level = 1; |
| 918 | } |
| 919 | return trailingSpaceRun; |
| 920 | } |
| 921 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 922 | void RenderBlockFlow::appendFloatingObjectToLastLine(FloatingObject* floatingObject) |
mitz@apple.com | d17e8c0 | 2011-04-16 21:59:36 +0000 | [diff] [blame] | 923 | { |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 924 | ASSERT(!floatingObject->originatingLine()); |
| 925 | floatingObject->setOriginatingLine(lastRootBox()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 926 | lastRootBox()->appendFloat(floatingObject->renderer()); |
mitz@apple.com | d17e8c0 | 2011-04-16 21:59:36 +0000 | [diff] [blame] | 927 | } |
| 928 | |
mmaxfield@apple.com | 434c872 | 2014-01-28 22:03:57 +0000 | [diff] [blame] | 929 | static inline void setUpResolverToResumeInIsolate(InlineBidiResolver& resolver, RenderObject* root, RenderObject* startObject) |
mmaxfield@apple.com | 18782a2 | 2014-01-28 21:53:22 +0000 | [diff] [blame] | 930 | { |
| 931 | if (root != startObject) { |
| 932 | RenderObject* parent = startObject->parent(); |
mmaxfield@apple.com | 434c872 | 2014-01-28 22:03:57 +0000 | [diff] [blame] | 933 | setUpResolverToResumeInIsolate(resolver, root, parent); |
mmaxfield@apple.com | 18782a2 | 2014-01-28 21:53:22 +0000 | [diff] [blame] | 934 | notifyObserverEnteredObject(&resolver, startObject); |
| 935 | } |
| 936 | } |
| 937 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 938 | // FIXME: BidiResolver should have this logic. |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 939 | 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] | 940 | { |
| 941 | // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead |
| 942 | // of the resolver owning the runs. |
| 943 | ASSERT(&topResolver.runs() == &bidiRuns); |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 944 | ASSERT(topResolver.position() != endOfRuns); |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 945 | RenderObject* currentRoot = topResolver.position().root(); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 946 | topResolver.createBidiRunsForLine(endOfRuns, override, previousLineBrokeCleanly); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 947 | |
| 948 | while (!topResolver.isolatedRuns().isEmpty()) { |
| 949 | // It does not matter which order we resolve the runs as long as we resolve them all. |
| 950 | BidiRun* isolatedRun = topResolver.isolatedRuns().last(); |
| 951 | topResolver.isolatedRuns().removeLast(); |
| 952 | |
ddkilzer@apple.com | 42c0af6 | 2014-04-17 19:39:22 +0000 | [diff] [blame] | 953 | RenderObject& startObject = isolatedRun->renderer(); |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 954 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 955 | // 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] | 956 | // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the |
| 957 | // tree to see which parent inline is the isolate. We could change enterIsolate |
| 958 | // to take a RenderObject and do this logic there, but that would be a layering |
| 959 | // violation for BidiResolver (which knows nothing about RenderObject). |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 960 | RenderInline* isolatedInline = downcast<RenderInline>(highestContainingIsolateWithinRoot(startObject, currentRoot)); |
ddkilzer@apple.com | ad6ad36 | 2014-04-02 17:21:09 +0000 | [diff] [blame] | 961 | ASSERT(isolatedInline); |
| 962 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 963 | InlineBidiResolver isolatedResolver; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 964 | EUnicodeBidi unicodeBidi = isolatedInline->style().unicodeBidi(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 965 | TextDirection direction; |
| 966 | if (unicodeBidi == Plaintext) |
akling@apple.com | 7506fda | 2013-11-07 10:12:36 +0000 | [diff] [blame] | 967 | determineDirectionality(direction, InlineIterator(isolatedInline, &isolatedRun->renderer(), 0)); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 968 | else { |
rniwa@webkit.org | 4d4bd33 | 2012-08-20 21:34:11 +0000 | [diff] [blame] | 969 | ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 970 | direction = isolatedInline->style().direction(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 971 | } |
zoltan@webkit.org | d1a9740 | 2013-12-08 05:53:33 +0000 | [diff] [blame] | 972 | isolatedResolver.setStatus(BidiStatus(direction, isOverride(unicodeBidi))); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 973 | |
ddkilzer@apple.com | 42c0af6 | 2014-04-17 19:39:22 +0000 | [diff] [blame] | 974 | setUpResolverToResumeInIsolate(isolatedResolver, isolatedInline, &startObject); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 975 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 976 | // The starting position is the beginning of the first run within the isolate that was identified |
| 977 | // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the |
| 978 | // first run within the isolate. |
ddkilzer@apple.com | 42c0af6 | 2014-04-17 19:39:22 +0000 | [diff] [blame] | 979 | InlineIterator iter = InlineIterator(isolatedInline, &startObject, isolatedRun->m_start); |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 980 | isolatedResolver.setPositionIgnoringNestedIsolates(iter); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 981 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 982 | // 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] | 983 | // FIXME: What should end and previousLineBrokeCleanly be? |
| 984 | // 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] | 985 | isolatedResolver.createBidiRunsForLine(endOfRuns, NoVisualOverride, previousLineBrokeCleanly); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 986 | // Note that we do not delete the runs from the resolver. |
rniwa@webkit.org | d0ad888 | 2012-05-23 07:37:07 +0000 | [diff] [blame] | 987 | // 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] | 988 | // itself to be turned into an InlineBox. We can't remove it here without potentially losing track of |
| 989 | // the logically last run. |
| 990 | if (isolatedResolver.runs().runCount()) |
| 991 | bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs()); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 992 | |
| 993 | // If we encountered any nested isolate runs, just move them |
| 994 | // to the top resolver's list for later processing. |
| 995 | if (!isolatedResolver.isolatedRuns().isEmpty()) { |
andersca@apple.com | 9201299 | 2013-05-05 19:03:49 +0000 | [diff] [blame] | 996 | topResolver.isolatedRuns().appendVector(isolatedResolver.isolatedRuns()); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 997 | isolatedResolver.isolatedRuns().clear(); |
commit-queue@webkit.org | 1968a43 | 2013-09-11 19:23:58 +0000 | [diff] [blame] | 998 | currentRoot = isolatedInline; |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1003 | // 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] | 1004 | 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] | 1005 | { |
| 1006 | if (!bidiRuns.runCount()) |
| 1007 | return 0; |
| 1008 | |
| 1009 | // FIXME: Why is this only done when we had runs? |
gyuyoung.kim@samsung.com | 113fb8b | 2013-11-28 23:25:19 +0000 | [diff] [blame] | 1010 | lineInfo.setLastLine(!end.renderer()); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1011 | |
| 1012 | RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo); |
| 1013 | if (!lineBox) |
| 1014 | return 0; |
| 1015 | |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 1016 | lineBox->setBidiLevel(bidiLevel); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1017 | lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly()); |
| 1018 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 1019 | bool isSVGRootInlineBox = is<SVGRootInlineBox>(*lineBox); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1020 | |
| 1021 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1022 | |
| 1023 | // Now we position all of our text runs horizontally. |
| 1024 | if (!isSVGRootInlineBox) |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 1025 | computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache, wordMeasurements); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1026 | |
| 1027 | // Now position our text runs vertically. |
| 1028 | computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache); |
| 1029 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1030 | // SVG text layout code computes vertical & horizontal positions on its own. |
| 1031 | // Note that we still need to execute computeVerticalPositionsForLine() as |
| 1032 | // it calls InlineTextBox::positionLineBox(), which tracks whether the box |
| 1033 | // contains reversed text or not. If we wouldn't do that editing and thus |
| 1034 | // text selection in RTL boxes would not work as expected. |
| 1035 | if (isSVGRootInlineBox) { |
akling@apple.com | 670fea1 | 2013-10-12 18:16:42 +0000 | [diff] [blame] | 1036 | ASSERT_WITH_SECURITY_IMPLICATION(isSVGText()); |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 1037 | downcast<SVGRootInlineBox>(*lineBox).computePerCharacterLayoutInformation(); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1038 | } |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1039 | |
| 1040 | // Compute our overflow now. |
| 1041 | lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap); |
| 1042 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1043 | return lineBox; |
| 1044 | } |
| 1045 | |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1046 | static void deleteLineRange(LineLayoutState& layoutState, RootInlineBox* startLine, RootInlineBox* stopLine = 0) |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1047 | { |
| 1048 | RootInlineBox* boxToDelete = startLine; |
| 1049 | while (boxToDelete && boxToDelete != stopLine) { |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1050 | layoutState.updateRepaintRangeFromBox(boxToDelete); |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1051 | // Note: deleteLineRange(firstRootBox()) is not identical to deleteLineBoxTree(). |
eric@webkit.org | e2532d9 | 2011-05-16 23:10:49 +0000 | [diff] [blame] | 1052 | // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing. |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1053 | RootInlineBox* next = boxToDelete->nextRootBox(); |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1054 | boxToDelete->deleteLine(); |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1055 | boxToDelete = next; |
| 1056 | } |
| 1057 | } |
| 1058 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1059 | void RenderBlockFlow::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild) |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1060 | { |
| 1061 | // We want to skip ahead to the first dirty line |
| 1062 | InlineBidiResolver resolver; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1063 | RootInlineBox* startLine = determineStartPosition(layoutState, resolver); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1064 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1065 | unsigned consecutiveHyphenatedLines = 0; |
| 1066 | if (startLine) { |
| 1067 | for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox()) |
| 1068 | consecutiveHyphenatedLines++; |
| 1069 | } |
| 1070 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1071 | // FIXME: This would make more sense outside of this function, but since |
| 1072 | // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call |
| 1073 | // 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] | 1074 | if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) { |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 1075 | 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] | 1076 | if (!view().doingFullRepaint() && hasLayer()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1077 | // Because we waited until we were already inside layout to discover |
| 1078 | // that the block really needed a full layout, we missed our chance to repaint the layer |
| 1079 | // before layout started. Luckily the layer has cached the repaint rect for its original |
| 1080 | // 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] | 1081 | repaintUsingContainer(containerForRepaint(), layer()->repaintRect()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | |
mihnea@adobe.com | 9946779 | 2013-03-19 09:09:04 +0000 | [diff] [blame] | 1085 | if (containsFloats()) |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1086 | layoutState.setLastFloat(m_floatingObjects->set().last().get()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1087 | |
| 1088 | // We also find the first clean line and extract these lines. We will add them back |
| 1089 | // if we determine that we're able to synchronize after handling all our dirty lines. |
| 1090 | InlineIterator cleanLineStart; |
| 1091 | BidiStatus cleanLineBidiStatus; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1092 | if (!layoutState.isFullLayout() && startLine) |
| 1093 | determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1094 | |
| 1095 | if (startLine) { |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1096 | if (!layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1097 | layoutState.setRepaintRange(logicalHeight()); |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1098 | deleteLineRange(layoutState, startLine); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1101 | if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1102 | // If the last line before the start line ends with a line break that clear floats, |
| 1103 | // adjust the height accordingly. |
| 1104 | // A line break can be either the first or the last object on a line, depending on its direction. |
| 1105 | if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) { |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 1106 | RenderObject* lastObject = &lastLeafChild->renderer(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1107 | if (!lastObject->isBR()) |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 1108 | lastObject = &lastRootBox()->firstLeafChild()->renderer(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1109 | if (lastObject->isBR()) { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1110 | EClear clear = lastObject->style().clear(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1111 | if (clear != CNONE) |
bjonesbe@adobe.com | f9f1040 | 2014-02-20 19:40:28 +0000 | [diff] [blame] | 1112 | clearFloats(clear); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1117 | layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1118 | linkToEndLineIfNeeded(layoutState); |
| 1119 | repaintDirtyFloats(layoutState.floats()); |
| 1120 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1121 | |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 1122 | RenderTextInfo::RenderTextInfo() |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 1123 | : m_text(0) |
mitz@apple.com | d4c153d | 2012-09-16 23:36:41 +0000 | [diff] [blame] | 1124 | , m_font(0) |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 1125 | { |
| 1126 | } |
| 1127 | |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 1128 | RenderTextInfo::~RenderTextInfo() |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 1129 | { |
| 1130 | } |
| 1131 | |
commit-queue@webkit.org | 4055b2e | 2012-12-06 19:05:15 +0000 | [diff] [blame] | 1132 | // 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] | 1133 | 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] | 1134 | { |
| 1135 | removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight); |
| 1136 | setLogicalHeight(newLogicalHeight); |
| 1137 | resolver.setPositionIgnoringNestedIsolates(oldEnd); |
| 1138 | return oldEnd; |
| 1139 | } |
| 1140 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1141 | 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] | 1142 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1143 | const RenderStyle& styleToUse = style(); |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1144 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1145 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
| 1146 | InlineIterator end = resolver.position(); |
| 1147 | bool checkForEndLineMatch = layoutState.endLine(); |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 1148 | RenderTextInfo renderTextInfo; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1149 | VerticalPositionCache verticalPositionCache; |
| 1150 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1151 | LineBreaker lineBreaker(*this); |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1152 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1153 | while (!end.atEnd()) { |
| 1154 | // 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] | 1155 | if (checkForEndLineMatch) { |
| 1156 | layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus)); |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1157 | if (layoutState.endLineMatched()) { |
| 1158 | resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1159 | break; |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1160 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1161 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1162 | |
| 1163 | lineMidpointState.reset(); |
| 1164 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1165 | layoutState.lineInfo().setEmpty(true); |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 1166 | layoutState.lineInfo().resetRunsFromLeadingWhitespace(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1167 | |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1168 | const InlineIterator oldEnd = end; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1169 | bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1170 | FloatingObject* lastFloatFromPreviousLine = (containsFloats()) ? m_floatingObjects->set().last().get() : 0; |
zoltan@webkit.org | 3bd77f5 | 2013-04-23 18:23:36 +0000 | [diff] [blame] | 1171 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 1172 | WordMeasurements wordMeasurements; |
| 1173 | end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements); |
hyatt@apple.com | 85ccaed | 2015-01-29 22:03:40 +0000 | [diff] [blame] | 1174 | cachePriorCharactersIfNeeded(renderTextInfo.m_lineBreakIterator); |
glenn@skynav.com | 61b1abf | 2013-04-02 23:28:32 +0000 | [diff] [blame] | 1175 | renderTextInfo.m_lineBreakIterator.resetPriorContext(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1176 | if (resolver.position().atEnd()) { |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1177 | // 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] | 1178 | // Once BidiRunList is separated from BidiResolver this will not be needed. |
| 1179 | resolver.runs().deleteRuns(); |
| 1180 | 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] | 1181 | layoutState.setCheckForFloatsFromLastLine(true); |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1182 | resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1183 | break; |
| 1184 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1185 | |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1186 | ASSERT(end != resolver.position()); |
| 1187 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1188 | // This is a short-cut for empty lines. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1189 | if (layoutState.lineInfo().isEmpty()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1190 | if (lastRootBox()) |
gyuyoung.kim@samsung.com | 044376f | 2013-12-26 07:32:04 +0000 | [diff] [blame] | 1191 | lastRootBox()->setLineBreakInfo(end.renderer(), end.offset(), resolver.status()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1192 | } else { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1193 | VisualDirectionOverride override = (styleToUse.rtlOrdering() == VisualOrder ? (styleToUse.direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride); |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1194 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1195 | if (isNewUBAParagraph && styleToUse.unicodeBidi() == Plaintext && !resolver.context()->parent()) { |
| 1196 | TextDirection direction = styleToUse.direction(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1197 | determineDirectionality(direction, resolver.position()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1198 | resolver.setStatus(BidiStatus(direction, isOverride(styleToUse.unicodeBidi()))); |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1199 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1200 | // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine. |
| 1201 | BidiRunList<BidiRun>& bidiRuns = resolver.runs(); |
zoltan@webkit.org | 7d4f8cc | 2014-03-26 18:20:15 +0000 | [diff] [blame] | 1202 | constructBidiRunsForSegment(resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1203 | ASSERT(resolver.position() == end); |
| 1204 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1205 | BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : 0; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1206 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1207 | if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) { |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1208 | bidiRuns.logicallyLastRun()->m_hasHyphen = true; |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1209 | consecutiveHyphenatedLines++; |
| 1210 | } else |
| 1211 | consecutiveHyphenatedLines = 0; |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1212 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1213 | // Now that the runs have been ordered, we create the line boxes. |
| 1214 | // At the same time we figure out where border/padding/margin should be applied for |
| 1215 | // inline flow boxes. |
| 1216 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1217 | LayoutUnit oldLogicalHeight = logicalHeight(); |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 1218 | 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] | 1219 | |
| 1220 | bidiRuns.deleteRuns(); |
| 1221 | resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed). |
| 1222 | |
| 1223 | if (lineBox) { |
gyuyoung.kim@samsung.com | 044376f | 2013-12-26 07:32:04 +0000 | [diff] [blame] | 1224 | lineBox->setLineBreakInfo(end.renderer(), end.offset(), resolver.status()); |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1225 | if (layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1226 | layoutState.updateRepaintRangeFromBox(lineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1227 | |
| 1228 | if (paginated) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1229 | LayoutUnit adjustment = 0; |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1230 | bool overflowsRegion; |
| 1231 | adjustLinePositionForPagination(lineBox, adjustment, overflowsRegion, layoutState.flowThread()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1232 | if (adjustment) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1233 | LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, layoutState.lineInfo().isFirstLine()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1234 | lineBox->adjustBlockDirectionPosition(adjustment); |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1235 | if (layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1236 | layoutState.updateRepaintRangeFromBox(lineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1237 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1238 | if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, layoutState.lineInfo().isFirstLine()) != oldLineWidth) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1239 | // We have to delete this line, remove all floats that got added, and let line layout re-run. |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1240 | lineBox->deleteLine(); |
commit-queue@webkit.org | 4055b2e | 2012-12-06 19:05:15 +0000 | [diff] [blame] | 1241 | end = restartLayoutRunsAndFloatsInRange(oldLogicalHeight, oldLogicalHeight + adjustment, lastFloatFromPreviousLine, resolver, oldEnd); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1242 | continue; |
| 1243 | } |
| 1244 | |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1245 | setLogicalHeight(lineBox->lineBottomWithLeading()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1246 | } |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1247 | |
| 1248 | if (RenderFlowThread* flowThread = flowThreadContainingBlock()) { |
| 1249 | if (flowThread->isRenderNamedFlowThread() && overflowsRegion && hasNextPage(lineBox->lineTop())) { |
| 1250 | // Limit the height of this block to the end of the current region because |
| 1251 | // it is also fragmented into the next region. |
| 1252 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalTop(), ExcludePageBoundary); |
| 1253 | if (logicalHeight() > remainingLogicalHeight) |
| 1254 | setLogicalHeight(remainingLogicalHeight); |
| 1255 | } |
| 1256 | } |
commit-queue@webkit.org | be554b2 | 2012-11-26 20:00:49 +0000 | [diff] [blame] | 1257 | |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1258 | if (layoutState.flowThread()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1259 | updateRegionForLine(lineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1260 | } |
| 1261 | } |
robert@webkit.org | 402c151 | 2013-02-07 18:48:39 +0000 | [diff] [blame] | 1262 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1263 | |
robert@webkit.org | 402c151 | 2013-02-07 18:48:39 +0000 | [diff] [blame] | 1264 | for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1265 | setStaticPositions(*this, *lineBreaker.positionedObjects()[i]); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1266 | |
robert@webkit.org | 402c151 | 2013-02-07 18:48:39 +0000 | [diff] [blame] | 1267 | if (!layoutState.lineInfo().isEmpty()) { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1268 | layoutState.lineInfo().setFirstLine(false); |
bjonesbe@adobe.com | f9f1040 | 2014-02-20 19:40:28 +0000 | [diff] [blame] | 1269 | clearFloats(lineBreaker.clear()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | if (m_floatingObjects && lastRootBox()) { |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1273 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1274 | auto it = floatingObjectSet.begin(); |
| 1275 | auto end = floatingObjectSet.end(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1276 | if (layoutState.lastFloat()) { |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1277 | auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1278 | ASSERT(lastFloatIterator != end); |
| 1279 | ++lastFloatIterator; |
| 1280 | it = lastFloatIterator; |
| 1281 | } |
| 1282 | for (; it != end; ++it) { |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1283 | FloatingObject* f = it->get(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1284 | appendFloatingObjectToLastLine(f); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1285 | ASSERT(&f->renderer() == &layoutState.floats()[layoutState.floatIndex()].object); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1286 | // 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] | 1287 | if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect()) |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1288 | checkForEndLineMatch = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1289 | layoutState.setFloatIndex(layoutState.floatIndex() + 1); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1290 | } |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1291 | layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | lineMidpointState.reset(); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1295 | resolver.setPosition(end, numberOfIsolateAncestors(end)); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1296 | } |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1297 | |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1298 | // In case we already adjusted the line positions during this layout to avoid widows |
| 1299 | // then we need to ignore the possibility of having a new widows situation. |
| 1300 | // 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] | 1301 | if (paginated && !style().hasAutoWidows() && !didBreakAtLineToAvoidWidow()) { |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1302 | // Check the line boxes to make sure we didn't create unacceptable widows. |
| 1303 | // However, we'll prioritize orphans - so nothing we do here should create |
| 1304 | // a new orphan. |
| 1305 | |
| 1306 | RootInlineBox* lineBox = lastRootBox(); |
| 1307 | |
| 1308 | // Count from the end of the block backwards, to see how many hanging |
| 1309 | // lines we have. |
| 1310 | RootInlineBox* firstLineInBlock = firstRootBox(); |
| 1311 | int numLinesHanging = 1; |
| 1312 | while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) { |
| 1313 | ++numLinesHanging; |
| 1314 | lineBox = lineBox->prevRootBox(); |
| 1315 | } |
| 1316 | |
| 1317 | // 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] | 1318 | if (!lineBox || !lineBox->isFirstAfterPageBreak() || lineBox == firstLineInBlock) |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1319 | return; |
| 1320 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1321 | if (numLinesHanging < style().widows()) { |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1322 | // We have detected a widow. Now we need to work out how many |
| 1323 | // lines there are on the previous page, and how many we need |
| 1324 | // to steal. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1325 | int numLinesNeeded = style().widows() - numLinesHanging; |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1326 | RootInlineBox* currentFirstLineOfNewPage = lineBox; |
| 1327 | |
| 1328 | // Count the number of lines in the previous page. |
| 1329 | lineBox = lineBox->prevRootBox(); |
| 1330 | int numLinesInPreviousPage = 1; |
| 1331 | while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) { |
| 1332 | ++numLinesInPreviousPage; |
| 1333 | lineBox = lineBox->prevRootBox(); |
| 1334 | } |
| 1335 | |
| 1336 | // If there was an explicit value for orphans, respect that. If not, we still |
| 1337 | // shouldn't create a situation where we make an orphan bigger than the initial value. |
| 1338 | // This means that setting widows implies we also care about orphans, but given |
| 1339 | // the specification says the initial orphan value is non-zero, this is ok. The |
| 1340 | // author is always free to set orphans explicitly as well. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1341 | int orphans = style().hasAutoOrphans() ? style().initialOrphans() : style().orphans(); |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1342 | int numLinesAvailable = numLinesInPreviousPage - orphans; |
| 1343 | if (numLinesAvailable <= 0) |
| 1344 | return; |
| 1345 | |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1346 | int numLinesToTake = std::min(numLinesAvailable, numLinesNeeded); |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1347 | // Wind back from our first widowed line. |
| 1348 | lineBox = currentFirstLineOfNewPage; |
| 1349 | for (int i = 0; i < numLinesToTake; ++i) |
| 1350 | lineBox = lineBox->prevRootBox(); |
| 1351 | |
| 1352 | // 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] | 1353 | setBreakAtLineToAvoidWidow(lineCount(lineBox)); |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1354 | markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), lineBox->lineBottomWithLeading(), lineBox); |
| 1355 | } |
| 1356 | } |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1357 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1358 | clearDidBreakAtLineToAvoidWidow(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1359 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1360 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1361 | void RenderBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1362 | { |
| 1363 | if (layoutState.endLine()) { |
| 1364 | if (layoutState.endLineMatched()) { |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1365 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1366 | // 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] | 1367 | LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1368 | for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1369 | line->attachLine(); |
| 1370 | if (paginated) { |
| 1371 | delta -= line->paginationStrut(); |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1372 | bool overflowsRegion; |
| 1373 | adjustLinePositionForPagination(line, delta, overflowsRegion, layoutState.flowThread()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1374 | } |
| 1375 | if (delta) { |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1376 | layoutState.updateRepaintRangeFromBox(line, delta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1377 | line->adjustBlockDirectionPosition(delta); |
| 1378 | } |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1379 | if (layoutState.flowThread()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1380 | updateRegionForLine(line); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1381 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1382 | for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) { |
| 1383 | RenderBox* floatingBox = *it; |
| 1384 | FloatingObject* floatingObject = insertFloatingObject(*floatingBox); |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 1385 | ASSERT(!floatingObject->originatingLine()); |
| 1386 | floatingObject->setOriginatingLine(line); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1387 | setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox) + delta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1388 | positionNewFloats(); |
| 1389 | } |
| 1390 | } |
| 1391 | } |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1392 | setLogicalHeight(lastRootBox()->lineBottomWithLeading()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1393 | } else { |
| 1394 | // Delete all the remaining lines. |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1395 | deleteLineRange(layoutState, layoutState.endLine()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1396 | } |
| 1397 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1398 | |
| 1399 | if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1400 | // In case we have a float on the last line, it might not be positioned up to now. |
| 1401 | // This has to be done before adding in the bottom border/padding, or the float will |
| 1402 | // include the padding incorrectly. -dwh |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1403 | if (layoutState.checkForFloatsFromLastLine()) { |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1404 | LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow(); |
| 1405 | LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow(); |
akling@apple.com | b5f2464 | 2013-11-06 04:47:12 +0000 | [diff] [blame] | 1406 | auto newLineBox = std::make_unique<TrailingFloatsRootInlineBox>(*this); |
| 1407 | auto trailingFloatsLineBox = newLineBox.get(); |
dbates@webkit.org | 0cefe4f | 2014-07-03 22:13:54 +0000 | [diff] [blame] | 1408 | m_lineBoxes.appendLineBox(WTF::move(newLineBox)); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1409 | trailingFloatsLineBox->setConstructed(); |
| 1410 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1411 | VerticalPositionCache verticalPositionCache; |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1412 | LayoutUnit blockLogicalHeight = logicalHeight(); |
hyatt@apple.com | a8b5b82 | 2011-09-07 18:48:07 +0000 | [diff] [blame] | 1413 | trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache); |
| 1414 | trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight); |
hyatt@apple.com | 0c6cd7a | 2011-09-22 20:50:41 +0000 | [diff] [blame] | 1415 | trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight)); |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1416 | LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight); |
| 1417 | LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1418 | trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom()); |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1419 | if (layoutState.flowThread()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1420 | updateRegionForLine(trailingFloatsLineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1423 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1424 | auto it = floatingObjectSet.begin(); |
| 1425 | auto end = floatingObjectSet.end(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1426 | if (layoutState.lastFloat()) { |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1427 | auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1428 | ASSERT(lastFloatIterator != end); |
| 1429 | ++lastFloatIterator; |
| 1430 | it = lastFloatIterator; |
| 1431 | } |
| 1432 | for (; it != end; ++it) |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1433 | appendFloatingObjectToLastLine(it->get()); |
| 1434 | layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1435 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1438 | void RenderBlockFlow::repaintDirtyFloats(Vector<FloatWithRect>& floats) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1439 | { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1440 | size_t floatCount = floats.size(); |
| 1441 | // Floats that did not have layout did not repaint when we laid them out. They would have |
| 1442 | // painted by now if they had moved, but if they stayed at (0, 0), they still need to be |
| 1443 | // painted. |
| 1444 | for (size_t i = 0; i < floatCount; ++i) { |
| 1445 | if (!floats[i].everHadLayout) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1446 | RenderBox& box = floats[i].object; |
| 1447 | if (!box.x() && !box.y() && box.checkForRepaintDuringLayout()) |
| 1448 | box.repaint(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1453 | void RenderBlockFlow::layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
jamesr@google.com | 19548ad | 2010-04-02 23:21:35 +0000 | [diff] [blame] | 1454 | { |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 1455 | ASSERT(!m_simpleLineLayout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1456 | |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 1457 | setLogicalHeight(borderAndPaddingBefore()); |
hyatt@apple.com | ee7af1d | 2012-01-17 19:16:24 +0000 | [diff] [blame] | 1458 | |
| 1459 | // 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] | 1460 | if (view().layoutState() && view().layoutState()->lineGrid() == this) |
hyatt@apple.com | ee7af1d | 2012-01-17 19:16:24 +0000 | [diff] [blame] | 1461 | layoutLineGridBox(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1462 | |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1463 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 1464 | bool clearLinesForPagination = firstRootBox() && flowThread && !flowThread->hasRegions(); |
commit-queue@webkit.org | 93cdd63 | 2012-12-07 00:33:56 +0000 | [diff] [blame] | 1465 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1466 | // Figure out if we should clear out our line boxes. |
| 1467 | // FIXME: Handle resize eventually! |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 1468 | bool isFullLayout = !firstRootBox() || selfNeedsLayout() || relayoutChildren || clearLinesForPagination; |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1469 | LineLayoutState layoutState(isFullLayout, repaintLogicalTop, repaintLogicalBottom, flowThread); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1470 | |
| 1471 | if (isFullLayout) |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1472 | lineBoxes().deleteLineBoxes(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1473 | |
commit-queue@webkit.org | 0779731 | 2013-02-22 18:58:19 +0000 | [diff] [blame] | 1474 | // Text truncation kicks in in two cases: |
| 1475 | // 1) If your overflow isn't visible and your text-overflow-mode isn't clip. |
| 1476 | // 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] | 1477 | // 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] | 1478 | // difficult to figure out in general (especially in the middle of doing layout), so we only handle the |
| 1479 | // 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] | 1480 | bool hasTextOverflow = (style().textOverflow() && hasOverflowClip()) |
| 1481 | || (isAnonymousBlock() && parent() && parent()->isRenderBlock() && parent()->style().textOverflow() && parent()->hasOverflowClip()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1482 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1483 | // Walk all the lines and delete our ellipsis line boxes if they exist. |
| 1484 | if (hasTextOverflow) |
| 1485 | deleteEllipsisLineBoxes(); |
| 1486 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1487 | if (firstChild()) { |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1488 | // In full layout mode, clear the line boxes of children upfront. Otherwise, |
| 1489 | // siblings can run into stale root lineboxes during layout. Then layout |
| 1490 | // the replaced elements later. In partial layout mode, line boxes are not |
| 1491 | // deleted and only dirtied. In that case, we can layout the replaced |
| 1492 | // elements at the same time. |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1493 | bool hasInlineChild = false; |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1494 | Vector<RenderBox*> replacedChildren; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1495 | for (InlineWalker walker(*this); !walker.atEnd(); walker.advance()) { |
| 1496 | RenderObject& o = *walker.current(); |
abucur@adobe.com | 33159da | 2013-08-13 07:44:32 +0000 | [diff] [blame] | 1497 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1498 | if (!hasInlineChild && o.isInline()) |
commit-queue@webkit.org | cf45df9 | 2010-09-14 13:25:06 +0000 | [diff] [blame] | 1499 | hasInlineChild = true; |
| 1500 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1501 | if (o.isReplaced() || o.isFloating() || o.isOutOfFlowPositioned()) { |
cdumez@apple.com | 0abff8b | 2014-10-17 21:25:10 +0000 | [diff] [blame] | 1502 | RenderBox& box = downcast<RenderBox>(o); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1503 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1504 | if (relayoutChildren || box.hasRelativeDimensions()) |
| 1505 | box.setChildNeedsLayout(MarkOnlyThis); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1506 | |
zimmermann@webkit.org | ac68af4 | 2011-06-15 08:02:37 +0000 | [diff] [blame] | 1507 | // 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] | 1508 | if (relayoutChildren && box.needsPreferredWidthsRecalculation()) |
| 1509 | box.setPreferredLogicalWidthsDirty(true, MarkOnlyThis); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1510 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1511 | if (box.isOutOfFlowPositioned()) |
| 1512 | box.containingBlock()->insertPositionedObject(box); |
| 1513 | else if (box.isFloating()) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1514 | layoutState.floats().append(FloatWithRect(box)); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1515 | else if (isFullLayout || box.needsLayout()) { |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1516 | // Replaced element. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1517 | box.dirtyLineBoxes(isFullLayout); |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1518 | if (isFullLayout) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1519 | replacedChildren.append(&box); |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1520 | else |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1521 | box.layoutIfNeeded(); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1522 | } |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 1523 | } else if (o.isTextOrLineBreak() || (is<RenderInline>(o) && !walker.atEndOfInline())) { |
| 1524 | if (is<RenderInline>(o)) |
| 1525 | downcast<RenderInline>(o).updateAlwaysCreateLineBoxes(layoutState.isFullLayout()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1526 | if (layoutState.isFullLayout() || o.selfNeedsLayout()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1527 | dirtyLineBoxesForRenderer(o, layoutState.isFullLayout()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1528 | o.clearNeedsLayout(); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1529 | } |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
inferno@chromium.org | ba2dceb | 2012-08-21 00:09:47 +0000 | [diff] [blame] | 1532 | for (size_t i = 0; i < replacedChildren.size(); i++) |
| 1533 | replacedChildren[i]->layoutIfNeeded(); |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1534 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1535 | layoutRunsAndFloats(layoutState, hasInlineChild); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1536 | } |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1537 | |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1538 | // Expand the last line to accommodate Ruby and emphasis marks. |
| 1539 | int lastLineAnnotationsAdjustment = 0; |
| 1540 | if (lastRootBox()) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1541 | LayoutUnit lowestAllowedPosition = std::max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1542 | if (!style().isFlippedLinesWritingMode()) |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1543 | lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition); |
| 1544 | else |
| 1545 | lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition); |
hyatt@apple.com | 5e48ff5 | 2010-11-19 00:43:29 +0000 | [diff] [blame] | 1546 | } |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1547 | |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1548 | // Now add in the bottom border/padding. |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 1549 | setLogicalHeight(logicalHeight() + lastLineAnnotationsAdjustment + borderAndPaddingAfter() + scrollbarLogicalHeight()); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1550 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 1551 | if (!firstRootBox() && hasLineIfEmpty()) |
hyatt@apple.com | 2a5eb21 | 2011-03-22 23:21:54 +0000 | [diff] [blame] | 1552 | setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes)); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1553 | |
| 1554 | // See if we have any lines that spill out of our block. If we do, then we will possibly need to |
| 1555 | // truncate text. |
| 1556 | if (hasTextOverflow) |
| 1557 | checkLinesForTextOverflow(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1560 | 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] | 1561 | { |
| 1562 | Vector<RenderBox*>* cleanLineFloats = line->floatsPtr(); |
| 1563 | if (!cleanLineFloats) |
| 1564 | return; |
stavila@adobe.com | f4ef097 | 2014-03-28 21:55:46 +0000 | [diff] [blame] | 1565 | |
| 1566 | if (!floats.size()) { |
| 1567 | encounteredNewFloat = true; |
| 1568 | return; |
| 1569 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1570 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1571 | for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) { |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1572 | RenderBox* floatingBox = *it; |
| 1573 | floatingBox->layoutIfNeeded(); |
bjonesbe@adobe.com | 562a50d | 2014-02-20 20:01:19 +0000 | [diff] [blame] | 1574 | LayoutSize newSize(floatingBox->width() + floatingBox->horizontalMarginExtent(), floatingBox->height() + floatingBox->verticalMarginExtent()); |
inferno@chromium.org | a227be6 | 2013-02-11 08:06:45 +0000 | [diff] [blame] | 1575 | ASSERT_WITH_SECURITY_IMPLICATION(floatIndex < floats.size()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1576 | if (&floats[floatIndex].object != floatingBox) { |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1577 | encounteredNewFloat = true; |
| 1578 | return; |
| 1579 | } |
hyatt@apple.com | c2e1552 | 2014-09-03 19:26:38 +0000 | [diff] [blame] | 1580 | |
| 1581 | // 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 |
| 1582 | // as dirty. |
| 1583 | 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] | 1584 | LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x(); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1585 | LayoutUnit floatHeight = isHorizontalWritingMode() ? std::max(floats[floatIndex].rect.height(), newSize.height()) : std::max(floats[floatIndex].rect.width(), newSize.width()); |
| 1586 | floatHeight = std::min(floatHeight, LayoutUnit::max() - floatTop); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1587 | line->markDirty(); |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1588 | markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1589 | floats[floatIndex].rect.setSize(newSize); |
| 1590 | dirtiedByFloat = true; |
| 1591 | } |
| 1592 | floatIndex++; |
| 1593 | } |
| 1594 | } |
| 1595 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1596 | RootInlineBox* RenderBlockFlow::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1597 | { |
| 1598 | RootInlineBox* curr = 0; |
| 1599 | RootInlineBox* last = 0; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1600 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1601 | // 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] | 1602 | bool dirtiedByFloat = false; |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1603 | if (!layoutState.isFullLayout()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1604 | // Paginate all of the clean lines. |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1605 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1606 | LayoutUnit paginationDelta = 0; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1607 | size_t floatIndex = 0; |
| 1608 | for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1609 | if (paginated) { |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1610 | if (lineWidthForPaginatedLineChanged(curr, 0, layoutState.flowThread())) { |
hyatt@apple.com | 0c6cd7a | 2011-09-22 20:50:41 +0000 | [diff] [blame] | 1611 | curr->markDirty(); |
| 1612 | break; |
| 1613 | } |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1614 | paginationDelta -= curr->paginationStrut(); |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1615 | bool overflowsRegion; |
| 1616 | adjustLinePositionForPagination(curr, paginationDelta, overflowsRegion, layoutState.flowThread()); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1617 | if (paginationDelta) { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1618 | if (containsFloats() || !layoutState.floats().isEmpty()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1619 | // 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] | 1620 | layoutState.markForFullLayout(); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1621 | break; |
| 1622 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1623 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1624 | layoutState.updateRepaintRangeFromBox(curr, paginationDelta); |
hyatt@apple.com | 61bbedf | 2011-01-26 23:10:57 +0000 | [diff] [blame] | 1625 | curr->adjustBlockDirectionPosition(paginationDelta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1626 | } |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1627 | if (layoutState.flowThread()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1628 | updateRegionForLine(curr); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1629 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1630 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1631 | // If a new float has been inserted before this line or before its last known float, just do a full layout. |
| 1632 | bool encounteredNewFloat = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1633 | checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1634 | if (encounteredNewFloat) |
| 1635 | layoutState.markForFullLayout(); |
| 1636 | |
| 1637 | if (dirtiedByFloat || layoutState.isFullLayout()) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1638 | break; |
| 1639 | } |
| 1640 | // 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] | 1641 | if (!curr && floatIndex < layoutState.floats().size()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1642 | layoutState.markForFullLayout(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1645 | if (layoutState.isFullLayout()) { |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1646 | m_lineBoxes.deleteLineBoxTree(); |
igor.o@sisa.samsung.com | f6a57df | 2013-04-15 21:25:35 +0000 | [diff] [blame] | 1647 | curr = 0; |
| 1648 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 1649 | ASSERT(!firstRootBox() && !lastRootBox()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1650 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1651 | if (curr) { |
| 1652 | // We have a dirty line. |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1653 | if (RootInlineBox* prevRootBox = curr->prevRootBox()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1654 | // We have a previous line. |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 1655 | if (!dirtiedByFloat && (!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] | 1656 | // The previous line didn't break cleanly or broke at a newline |
| 1657 | // that has been deleted, so treat it as dirty too. |
| 1658 | curr = prevRootBox; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 1659 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1660 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1661 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1662 | // If we have no dirty lines, then last is just the last root box. |
| 1663 | last = curr ? curr->prevRootBox() : lastRootBox(); |
| 1664 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1665 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1666 | unsigned numCleanFloats = 0; |
| 1667 | if (!layoutState.floats().isEmpty()) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1668 | LayoutUnit savedLogicalHeight = logicalHeight(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1669 | // Restore floats from clean lines. |
| 1670 | RootInlineBox* line = firstRootBox(); |
| 1671 | while (line != curr) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1672 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1673 | for (auto it = cleanLineFloats->begin(), end = cleanLineFloats->end(); it != end; ++it) { |
| 1674 | RenderBox* floatingBox = *it; |
| 1675 | FloatingObject* floatingObject = insertFloatingObject(*floatingBox); |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 1676 | ASSERT(!floatingObject->originatingLine()); |
| 1677 | floatingObject->setOriginatingLine(line); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1678 | setLogicalHeight(logicalTopForChild(*floatingBox) - marginBeforeForChild(*floatingBox)); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1679 | positionNewFloats(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1680 | ASSERT(&layoutState.floats()[numCleanFloats].object == floatingBox); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1681 | numCleanFloats++; |
| 1682 | } |
| 1683 | } |
| 1684 | line = line->nextRootBox(); |
| 1685 | } |
hyatt@apple.com | 9a2e7d2 | 2010-10-06 22:13:31 +0000 | [diff] [blame] | 1686 | setLogicalHeight(savedLogicalHeight); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1687 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1688 | layoutState.setFloatIndex(numCleanFloats); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1689 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1690 | layoutState.lineInfo().setFirstLine(!last); |
| 1691 | layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak()); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1692 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1693 | if (last) { |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1694 | setLogicalHeight(last->lineBottomWithLeading()); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1695 | InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos()); |
| 1696 | resolver.setPosition(iter, numberOfIsolateAncestors(iter)); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1697 | resolver.setStatus(last->lineBreakBidiStatus()); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1698 | } else { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1699 | TextDirection direction = style().direction(); |
| 1700 | if (style().unicodeBidi() == Plaintext) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1701 | determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(*this), 0)); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1702 | resolver.setStatus(BidiStatus(direction, isOverride(style().unicodeBidi()))); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1703 | InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(*this, &resolver), 0); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1704 | resolver.setPosition(iter, numberOfIsolateAncestors(iter)); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1705 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1706 | return curr; |
| 1707 | } |
| 1708 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1709 | void RenderBlockFlow::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1710 | { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1711 | ASSERT(!layoutState.endLine()); |
| 1712 | size_t floatIndex = layoutState.floatIndex(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1713 | RootInlineBox* last = 0; |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1714 | for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) { |
| 1715 | if (!curr->isDirty()) { |
| 1716 | bool encounteredNewFloat = false; |
| 1717 | bool dirtiedByFloat = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1718 | checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1719 | if (encounteredNewFloat) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1720 | return; |
hyatt | 04420ca | 2004-07-16 00:05:42 +0000 | [diff] [blame] | 1721 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1722 | if (curr->isDirty()) |
| 1723 | last = 0; |
| 1724 | else if (!last) |
| 1725 | last = curr; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1726 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1727 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1728 | if (!last) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1729 | return; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1730 | |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1731 | // At this point, |last| is the first line in a run of clean lines that ends with the last line |
| 1732 | // in the block. |
| 1733 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1734 | RootInlineBox* prev = last->prevRootBox(); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1735 | cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1736 | cleanLineBidiStatus = prev->lineBreakBidiStatus(); |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1737 | layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1738 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1739 | for (RootInlineBox* line = last; line; line = line->nextRootBox()) |
| 1740 | line->extractLine(); // Disconnect all line boxes from their render objects while preserving |
| 1741 | // their connections to one another. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1742 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1743 | layoutState.setEndLine(last); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1746 | bool RenderBlockFlow::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState) |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1747 | { |
| 1748 | LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop(); |
| 1749 | |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1750 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1751 | if (paginated && layoutState.flowThread()) { |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1752 | // Check all lines from here to the end, and see if the hypothetical new position for the lines will result |
| 1753 | // in a different available line width. |
| 1754 | for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) { |
| 1755 | if (paginated) { |
| 1756 | // This isn't the real move we're going to do, so don't update the line box's pagination |
| 1757 | // strut yet. |
| 1758 | LayoutUnit oldPaginationStrut = lineBox->paginationStrut(); |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1759 | bool overflowsRegion; |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1760 | lineDelta -= oldPaginationStrut; |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1761 | adjustLinePositionForPagination(lineBox, lineDelta, overflowsRegion, layoutState.flowThread()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1762 | lineBox->setPaginationStrut(oldPaginationStrut); |
| 1763 | } |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1764 | if (lineWidthForPaginatedLineChanged(lineBox, lineDelta, layoutState.flowThread())) |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1765 | return false; |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | if (!lineDelta || !m_floatingObjects) |
| 1770 | return true; |
| 1771 | |
| 1772 | // 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] | 1773 | LayoutUnit logicalTop = std::min(logicalHeight(), layoutState.endLineLogicalTop()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1774 | |
| 1775 | RootInlineBox* lastLine = layoutState.endLine(); |
| 1776 | while (RootInlineBox* nextLine = lastLine->nextRootBox()) |
| 1777 | lastLine = nextLine; |
| 1778 | |
leviw@chromium.org | 3957b45 | 2012-05-01 00:06:37 +0000 | [diff] [blame] | 1779 | LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + absoluteValue(lineDelta); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1780 | |
| 1781 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1782 | auto end = floatingObjectSet.end(); |
| 1783 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 1784 | FloatingObject* floatingObject = it->get(); |
| 1785 | if (logicalBottomForFloat(floatingObject) >= logicalTop && logicalBottomForFloat(floatingObject) < logicalBottom) |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1786 | return false; |
| 1787 | } |
| 1788 | |
| 1789 | return true; |
| 1790 | } |
| 1791 | |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1792 | bool RenderBlockFlow::lineWidthForPaginatedLineChanged(RootInlineBox* rootBox, LayoutUnit lineDelta, RenderFlowThread* flowThread) const |
| 1793 | { |
| 1794 | if (!flowThread) |
| 1795 | return false; |
| 1796 | |
| 1797 | RenderRegion* currentRegion = regionAtBlockOffset(rootBox->lineTopWithLeading() + lineDelta); |
| 1798 | // Just bail if the region didn't change. |
| 1799 | if (rootBox->containingRegion() == currentRegion) |
| 1800 | return false; |
| 1801 | return rootBox->paginatedLineWidth() != availableLogicalWidthForContent(currentRegion); |
| 1802 | } |
| 1803 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1804 | 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] | 1805 | { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1806 | if (resolver.position() == endLineStart) { |
| 1807 | if (resolver.status() != endLineStatus) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1808 | return false; |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1809 | return checkPaginationAndFloatsAtEndLine(layoutState); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1810 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1811 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1812 | // The first clean line doesn't match, but we can check a handful of following lines to try |
| 1813 | // to match back up. |
| 1814 | static 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] | 1815 | RootInlineBox* originalEndLine = layoutState.endLine(); |
| 1816 | RootInlineBox* line = originalEndLine; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1817 | for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) { |
gyuyoung.kim@samsung.com | 044376f | 2013-12-26 07:32:04 +0000 | [diff] [blame] | 1818 | if (line->lineBreakObj() == resolver.position().renderer() && line->lineBreakPos() == resolver.position().offset()) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1819 | // We have a match. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1820 | if (line->lineBreakBidiStatus() != resolver.status()) |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1821 | return false; // ...but the bidi state doesn't match. |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1822 | |
| 1823 | bool matched = false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1824 | RootInlineBox* result = line->nextRootBox(); |
hyatt@apple.com | 1fb7d58 | 2011-09-23 20:25:11 +0000 | [diff] [blame] | 1825 | layoutState.setEndLine(result); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1826 | if (result) { |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1827 | layoutState.setEndLineLogicalTop(line->lineBottomWithLeading()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1828 | matched = checkPaginationAndFloatsAtEndLine(layoutState); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1831 | // Now delete the lines that we failed to sync. |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1832 | deleteLineRange(layoutState, originalEndLine, result); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1833 | return matched; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1834 | } |
| 1835 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1836 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1837 | return false; |
| 1838 | } |
| 1839 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 1840 | bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1841 | { |
| 1842 | ASSERT(inlineObj->parent() == this); |
| 1843 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1844 | InlineIterator it(this, inlineObj, 0); |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 1845 | // FIXME: We should pass correct value for WhitespacePosition. |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 1846 | while (!it.atEnd() && !requiresLineBox(it)) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1847 | it.increment(); |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1848 | |
| 1849 | return !it.atEnd(); |
| 1850 | } |
| 1851 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 1852 | void RenderBlockFlow::addOverflowFromInlineChildren() |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 1853 | { |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 1854 | if (auto layout = simpleLineLayout()) { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1855 | ASSERT(!hasOverflowClip()); |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 1856 | SimpleLineLayout::collectFlowOverflow(*this, *layout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1857 | return; |
| 1858 | } |
eae@chromium.org | 9717cd8 | 2012-11-07 18:33:44 +0000 | [diff] [blame] | 1859 | LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit(); |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 1860 | // 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] | 1861 | if (hasOverflowClip() && !endPadding && element() && element()->isRootEditableElement() && style().isLeftToRightDirection()) |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 1862 | endPadding = 1; |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 1863 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 1864 | addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding)); |
abucur@adobe.com | 4c3580b | 2014-04-29 12:38:20 +0000 | [diff] [blame] | 1865 | RenderRegion* region = flowThreadContainingBlock() ? curr->containingRegion() : nullptr; |
abucur@adobe.com | 6585d01 | 2013-09-04 08:26:41 +0000 | [diff] [blame] | 1866 | if (region) |
| 1867 | region->addLayoutOverflowForBox(this, curr->paddedLayoutOverflowRect(endPadding)); |
| 1868 | if (!hasOverflowClip()) { |
hyatt@apple.com | 61f2532 | 2011-03-31 20:40:48 +0000 | [diff] [blame] | 1869 | addVisualOverflow(curr->visualOverflowRect(curr->lineTop(), curr->lineBottom())); |
abucur@adobe.com | 6585d01 | 2013-09-04 08:26:41 +0000 | [diff] [blame] | 1870 | if (region) |
| 1871 | region->addVisualOverflowForBox(this, curr->visualOverflowRect(curr->lineTop(), curr->lineBottom())); |
| 1872 | } |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1876 | void RenderBlockFlow::deleteEllipsisLineBoxes() |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1877 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1878 | ETextAlign textAlign = style().textAlign(); |
| 1879 | bool ltr = style().isLeftToRightDirection(); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 1880 | bool firstLine = true; |
| 1881 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
| 1882 | if (curr->hasEllipsisBox()) { |
| 1883 | curr->clearTruncation(); |
| 1884 | |
| 1885 | // Shift the line back where it belongs if we cannot accomodate an ellipsis. |
zalan@apple.com | bfa1195 | 2014-05-19 17:37:22 +0000 | [diff] [blame] | 1886 | float logicalLeft = logicalLeftOffsetForLine(curr->lineTop(), firstLine); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 1887 | float availableLogicalWidth = logicalRightOffsetForLine(curr->lineTop(), false) - logicalLeft; |
| 1888 | float totalLogicalWidth = curr->logicalWidth(); |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 1889 | updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 1890 | |
| 1891 | if (ltr) |
| 1892 | curr->adjustLogicalPosition((logicalLeft - curr->logicalLeft()), 0); |
| 1893 | else |
| 1894 | curr->adjustLogicalPosition(-(curr->logicalLeft() - logicalLeft), 0); |
| 1895 | } |
| 1896 | firstLine = false; |
| 1897 | } |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1900 | void RenderBlockFlow::checkLinesForTextOverflow() |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1901 | { |
| 1902 | // Determine the width of the ellipsis using the current font. |
darin | dbba2bb | 2007-01-11 12:23:49 +0000 | [diff] [blame] | 1903 | // 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] | 1904 | const FontCascade& font = style().fontCascade(); |
svillar@igalia.com | 5b31eef | 2014-03-14 08:30:55 +0000 | [diff] [blame] | 1905 | DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1)); |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +0000 | [diff] [blame] | 1906 | const FontCascade& firstLineFont = firstLineStyle().fontCascade(); |
zalan@apple.com | bfa1195 | 2014-05-19 17:37:22 +0000 | [diff] [blame] | 1907 | float firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle())); |
| 1908 | float ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style())); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1909 | |
| 1910 | // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see |
| 1911 | // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and |
| 1912 | // check the left edge of the line box to see if it is less |
| 1913 | // 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] | 1914 | bool ltr = style().isLeftToRightDirection(); |
| 1915 | ETextAlign textAlign = style().textAlign(); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 1916 | bool firstLine = true; |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1917 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
zalan@apple.com | bfa1195 | 2014-05-19 17:37:22 +0000 | [diff] [blame] | 1918 | LayoutUnit blockRightEdge = logicalRightOffsetForLine(curr->lineTop(), firstLine); |
| 1919 | LayoutUnit blockLeftEdge = logicalLeftOffsetForLine(curr->lineTop(), firstLine); |
| 1920 | LayoutUnit lineBoxEdge = ltr ? curr->x() + curr->logicalWidth() : curr->x(); |
dglazkov@chromium.org | 28434e6 | 2009-05-13 22:30:10 +0000 | [diff] [blame] | 1921 | if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) { |
hyatt | f918d2d | 2004-06-15 07:24:11 +0000 | [diff] [blame] | 1922 | // 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] | 1923 | // can be truncated. In order for truncation to be possible, the line must have sufficient space to |
| 1924 | // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis |
| 1925 | // space. |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 1926 | |
| 1927 | LayoutUnit width = firstLine ? firstLineEllipsisWidth : ellipsisWidth; |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1928 | LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge; |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 1929 | if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) { |
| 1930 | float totalLogicalWidth = curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width); |
| 1931 | |
akling@apple.com | f294cf0 | 2013-07-17 18:46:39 +0000 | [diff] [blame] | 1932 | float logicalLeft = 0; // We are only interested in the delta from the base position. |
zalan@apple.com | bfa1195 | 2014-05-19 17:37:22 +0000 | [diff] [blame] | 1933 | float truncatedWidth = logicalRightOffsetForLine(curr->lineTop(), firstLine); |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 1934 | updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, totalLogicalWidth, truncatedWidth, 0); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 1935 | if (ltr) |
| 1936 | curr->adjustLogicalPosition(logicalLeft, 0); |
| 1937 | else |
| 1938 | curr->adjustLogicalPosition(-(truncatedWidth - (logicalLeft + totalLogicalWidth)), 0); |
| 1939 | } |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1940 | } |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 1941 | firstLine = false; |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1945 | bool RenderBlockFlow::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width) |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1946 | { |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 1947 | if (!positionNewFloats()) |
| 1948 | return false; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1949 | |
rniwa@webkit.org | 4442475 | 2011-04-14 00:58:40 +0000 | [diff] [blame] | 1950 | width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1951 | |
hyatt@apple.com | dd78df8 | 2011-09-27 22:11:41 +0000 | [diff] [blame] | 1952 | // We only connect floats to lines for pagination purposes if the floats occur at the start of |
| 1953 | // the line and the previous line had a hard break (so this line is either the first in the block |
| 1954 | // or follows a <br>). |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 1955 | if (!newFloat->paginationStrut() || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty()) |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 1956 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1957 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1958 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1959 | ASSERT(floatingObjectSet.last().get() == newFloat); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1960 | |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 1961 | LayoutUnit floatLogicalTop = logicalTopForFloat(newFloat); |
bjonesbe@adobe.com | bdee2ce | 2014-02-07 18:37:55 +0000 | [diff] [blame] | 1962 | LayoutUnit paginationStrut = newFloat->paginationStrut(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1963 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 1964 | if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut()) |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 1965 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1966 | |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1967 | auto it = floatingObjectSet.end(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1968 | --it; // Last float is newFloat, skip that one. |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1969 | auto begin = floatingObjectSet.begin(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1970 | while (it != begin) { |
| 1971 | --it; |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 1972 | FloatingObject* floatingObject = it->get(); |
| 1973 | if (floatingObject == lastFloatFromPreviousLine) |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1974 | break; |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 1975 | if (logicalTopForFloat(floatingObject) == logicalHeight() + lineInfo.floatPaginationStrut()) { |
| 1976 | floatingObject->setPaginationStrut(paginationStrut + floatingObject->paginationStrut()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1977 | RenderBox& floatBox = floatingObject->renderer(); |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 1978 | setLogicalTopForChild(floatBox, logicalTopForChild(floatBox) + marginBeforeForChild(floatBox) + paginationStrut); |
stavila@adobe.com | 6cb976d | 2013-11-21 06:57:19 +0000 | [diff] [blame] | 1979 | |
| 1980 | if (updateRegionRangeForBoxChild(floatingObject->renderer())) |
| 1981 | floatBox.setNeedsLayout(MarkOnlyThis); |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 1982 | else if (is<RenderBlock>(floatBox)) |
| 1983 | downcast<RenderBlock>(floatBox).setChildNeedsLayout(MarkOnlyThis); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1984 | floatBox.layoutIfNeeded(); |
stavila@adobe.com | 6cb976d | 2013-11-21 06:57:19 +0000 | [diff] [blame] | 1985 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1986 | // Save the old logical top before calling removePlacedObject which will set |
| 1987 | // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat. |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 1988 | LayoutUnit oldLogicalTop = logicalTopForFloat(floatingObject); |
| 1989 | m_floatingObjects->removePlacedObject(floatingObject); |
| 1990 | setLogicalTopForFloat(floatingObject, oldLogicalTop + paginationStrut); |
| 1991 | m_floatingObjects->addPlacedObject(floatingObject); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1992 | } |
| 1993 | } |
| 1994 | |
hyatt@apple.com | dd78df8 | 2011-09-27 22:11:41 +0000 | [diff] [blame] | 1995 | // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing |
| 1996 | // no content, then we don't want to improperly grow the height of the block. |
| 1997 | lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut); |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 1998 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
weinig@apple.com | 6b4a2414 | 2014-01-05 00:28:39 +0000 | [diff] [blame] | 2001 | LayoutUnit RenderBlockFlow::startAlignedOffsetForLine(LayoutUnit position, bool firstLine) |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 2002 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2003 | ETextAlign textAlign = style().textAlign(); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 2004 | |
hyatt@apple.com | a562669 | 2013-11-18 23:08:30 +0000 | [diff] [blame] | 2005 | // <rdar://problem/15427571> |
| 2006 | // https://bugs.webkit.org/show_bug.cgi?id=124522 |
| 2007 | // This quirk is for legacy content that doesn't work properly with the center positioning scheme |
| 2008 | // being honored (e.g., epubs). |
| 2009 | if (textAlign == TASTART || document().settings()->useLegacyTextAlignPositionedElementBehavior()) // FIXME: Handle TAEND here |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 2010 | return startOffsetForLine(position, firstLine); |
| 2011 | |
| 2012 | // 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] | 2013 | float totalLogicalWidth = 0; |
| 2014 | float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false); |
| 2015 | float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), false) - logicalLeft; |
mario.prada@samsung.com | 7939752 | 2014-02-28 18:12:52 +0000 | [diff] [blame] | 2016 | |
| 2017 | // FIXME: Bug 129311: We need to pass a valid RootInlineBox here, considering the bidi level used to construct the line. |
| 2018 | updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0); |
robert@webkit.org | 7861a10 | 2011-09-22 17:16:47 +0000 | [diff] [blame] | 2019 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2020 | if (!style().isLeftToRightDirection()) |
robert@webkit.org | 82903f4 | 2012-08-28 19:18:40 +0000 | [diff] [blame] | 2021 | return logicalWidth() - logicalLeft; |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 2022 | return logicalLeft; |
| 2023 | } |
| 2024 | |
abucur@adobe.com | d40287b | 2013-10-08 17:33:05 +0000 | [diff] [blame] | 2025 | void RenderBlockFlow::updateRegionForLine(RootInlineBox* lineBox) const |
| 2026 | { |
| 2027 | ASSERT(lineBox); |
akling@apple.com | bdf247b | 2014-01-13 22:33:08 +0000 | [diff] [blame] | 2028 | |
abucur@adobe.com | c18af35 | 2014-05-14 06:33:48 +0000 | [diff] [blame] | 2029 | if (!hasRegionRangeInFlowThread()) |
akling@apple.com | bdf247b | 2014-01-13 22:33:08 +0000 | [diff] [blame] | 2030 | lineBox->clearContainingRegion(); |
abucur@adobe.com | c18af35 | 2014-05-14 06:33:48 +0000 | [diff] [blame] | 2031 | else { |
| 2032 | if (auto containingRegion = regionAtBlockOffset(lineBox->lineTopWithLeading())) |
| 2033 | lineBox->setContainingRegion(*containingRegion); |
| 2034 | else |
| 2035 | lineBox->clearContainingRegion(); |
| 2036 | } |
abucur@adobe.com | d40287b | 2013-10-08 17:33:05 +0000 | [diff] [blame] | 2037 | |
| 2038 | RootInlineBox* prevLineBox = lineBox->prevRootBox(); |
| 2039 | if (!prevLineBox) |
| 2040 | return; |
| 2041 | |
| 2042 | // This check is more accurate than the one in |adjustLinePositionForPagination| because it takes into |
| 2043 | // account just the container changes between lines. The before mentioned function doesn't set the flag |
| 2044 | // correctly if the line is positioned at the top of the last fragment container. |
| 2045 | if (lineBox->containingRegion() != prevLineBox->containingRegion()) |
| 2046 | lineBox->setIsFirstAfterPageBreak(true); |
| 2047 | } |
| 2048 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2049 | } |