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