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