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