hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 | * (C) 2007 David Smith (catfish.man@gmail.com) |
bfulgham@apple.com | b595343 | 2015-02-13 21:56:01 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003-2015 Apple Inc. All rights reserved. |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 6 | * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 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 |
| 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | * Boston, MA 02110-1301, USA. |
| 22 | */ |
| 23 | |
| 24 | #include "config.h" |
| 25 | #include "RenderBlockFlow.h" |
| 26 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 27 | #include "Editor.h" |
jer.noble@apple.com | 872903d | 2021-10-08 23:31:51 +0000 | [diff] [blame] | 28 | #include "ElementInlines.h" |
bjonesbe@adobe.com | 6747809 | 2013-09-09 22:18:17 +0000 | [diff] [blame] | 29 | #include "FloatingObjects.h" |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 30 | #include "Frame.h" |
zalan@apple.com | e36543a | 2014-07-29 01:45:54 +0000 | [diff] [blame] | 31 | #include "FrameSelection.h" |
darin@apple.com | 15708b1 | 2014-03-16 16:38:58 +0000 | [diff] [blame] | 32 | #include "HTMLElement.h" |
cdumez@apple.com | a92c4d6 | 2016-05-20 01:50:51 +0000 | [diff] [blame] | 33 | #include "HTMLInputElement.h" |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 34 | #include "HTMLParserIdioms.h" |
cdumez@apple.com | a92c4d6 | 2016-05-20 01:50:51 +0000 | [diff] [blame] | 35 | #include "HTMLTextAreaElement.h" |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 36 | #include "HitTestLocation.h" |
antti@apple.com | 633f18b | 2021-10-02 14:01:35 +0000 | [diff] [blame] | 37 | #include "InlineIteratorBox.h" |
psaavedra@igalia.com | 6c7a18e | 2022-02-02 20:40:59 +0000 | [diff] [blame] | 38 | #include "InlineIteratorInlineBox.h" |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 39 | #include "InlineIteratorLineBox.h" |
antti@apple.com | 36b223a | 2021-10-15 20:29:15 +0000 | [diff] [blame] | 40 | #include "InlineIteratorLogicalOrderTraversal.h" |
lmoura@igalia.com | a81facf | 2021-10-04 14:50:57 +0000 | [diff] [blame] | 41 | #include "InlineIteratorTextBox.h" |
don.olmstead@sony.com | 208385f | 2021-10-03 23:00:17 +0000 | [diff] [blame] | 42 | #include "InlineWalker.h" |
antti@apple.com | d4dda74 | 2019-12-03 15:41:43 +0000 | [diff] [blame] | 43 | #include "LayoutIntegrationLineLayout.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 44 | #include "LayoutRepainter.h" |
antti@apple.com | 6233f16 | 2021-06-05 12:19:10 +0000 | [diff] [blame] | 45 | #include "LegacyInlineTextBox.h" |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 46 | #include "LegacyLineLayout.h" |
zalan@apple.com | 928aaf9 | 2022-03-18 02:30:52 +0000 | [diff] [blame] | 47 | #include "LineSelection.h" |
simon.fraser@apple.com | 36676e5 | 2016-05-07 00:05:58 +0000 | [diff] [blame] | 48 | #include "Logging.h" |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 49 | #include "RenderCombineText.h" |
zalan@apple.com | a861dc7 | 2021-08-20 12:49:48 +0000 | [diff] [blame] | 50 | #include "RenderDeprecatedFlexibleBox.h" |
hyatt@apple.com | 531e35d | 2017-04-13 16:37:00 +0000 | [diff] [blame] | 51 | #include "RenderFlexibleBox.h" |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 52 | #include "RenderInline.h" |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 53 | #include "RenderIterator.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 54 | #include "RenderLayer.h" |
aperez@igalia.com | fb063c8 | 2021-02-02 08:34:53 +0000 | [diff] [blame] | 55 | #include "RenderLayerScrollableArea.h" |
antti@apple.com | f41183e | 2018-12-07 20:10:14 +0000 | [diff] [blame] | 56 | #include "RenderLayoutState.h" |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 57 | #include "RenderLineBreak.h" |
antti@apple.com | 0b3dffe | 2014-03-24 16:30:52 +0000 | [diff] [blame] | 58 | #include "RenderListItem.h" |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 59 | #include "RenderMarquee.h" |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 60 | #include "RenderMultiColumnFlow.h" |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 61 | #include "RenderMultiColumnSet.h" |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 62 | #include "RenderTableCell.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 63 | #include "RenderText.h" |
antti@apple.com | 89b8fff | 2017-12-16 19:07:55 +0000 | [diff] [blame] | 64 | #include "RenderTreeBuilder.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 65 | #include "RenderView.h" |
bfulgham@apple.com | b595343 | 2015-02-13 21:56:01 +0000 | [diff] [blame] | 66 | #include "Settings.h" |
antti@apple.com | 4918b4d | 2017-08-14 13:20:47 +0000 | [diff] [blame] | 67 | #include "TextAutoSizing.h" |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 68 | #include "VerticalPositionCache.h" |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 69 | #include "VisiblePosition.h" |
fpizlo@apple.com | d03c594 | 2017-11-07 19:21:52 +0000 | [diff] [blame] | 70 | #include <wtf/IsoMallocInlines.h> |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 71 | |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 72 | namespace WebCore { |
| 73 | |
antti@apple.com | 8782b5c | 2021-11-22 23:32:20 +0000 | [diff] [blame] | 74 | #define ENABLE_MODERN_PREFERRED_WIDTH_COMPUTATION 1 |
zalan@apple.com | 51fcd92 | 2022-01-19 00:13:13 +0000 | [diff] [blame] | 75 | #define ENABLE_MODERN_PREFERRED_WIDTH_COMPUTATION_FOR_INLINE_BOXES 1 |
antti@apple.com | 5072de9 | 2021-11-02 16:01:26 +0000 | [diff] [blame] | 76 | |
fpizlo@apple.com | d03c594 | 2017-11-07 19:21:52 +0000 | [diff] [blame] | 77 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderBlockFlow); |
| 78 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 79 | bool RenderBlock::s_canPropagateFloatIntoSibling = false; |
| 80 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 81 | struct SameSizeAsMarginInfo { |
| 82 | uint32_t bitfields : 16; |
| 83 | LayoutUnit margins[2]; |
| 84 | }; |
| 85 | |
ysuzuki@apple.com | 82d570e | 2022-03-26 22:19:31 +0000 | [diff] [blame] | 86 | static_assert(sizeof(RenderBlockFlow::MarginValues) == sizeof(LayoutUnit[4]), "MarginValues should stay small"); |
| 87 | static_assert(sizeof(RenderBlockFlow::MarginInfo) == sizeof(SameSizeAsMarginInfo), "MarginInfo should stay small"); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 88 | |
| 89 | // Our MarginInfo state used when laying out block children. |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 90 | RenderBlockFlow::MarginInfo::MarginInfo(const RenderBlockFlow& block, LayoutUnit beforeBorderPadding, LayoutUnit afterBorderPadding) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 91 | : m_atBeforeSideOfBlock(true) |
| 92 | , m_atAfterSideOfBlock(false) |
| 93 | , m_hasMarginBeforeQuirk(false) |
| 94 | , m_hasMarginAfterQuirk(false) |
| 95 | , m_determinedMarginBeforeQuirk(false) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 96 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 97 | const RenderStyle& blockStyle = block.style(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 98 | ASSERT(block.isRenderView() || block.parent()); |
jfernandez@igalia.com | 136f170 | 2014-12-08 19:13:16 +0000 | [diff] [blame] | 99 | m_canCollapseWithChildren = !block.createsNewFormattingContext() && !block.isRenderView(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 100 | |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 101 | m_canCollapseMarginBeforeWithChildren = m_canCollapseWithChildren && !beforeBorderPadding; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 102 | |
| 103 | // If any height other than auto is specified in CSS, then we don't collapse our bottom |
| 104 | // margins with our children's margins. To do otherwise would be to risk odd visual |
| 105 | // effects when the children overflow out of the parent block and yet still collapse |
| 106 | // with it. We also don't collapse if we have any bottom border/padding. |
| 107 | m_canCollapseMarginAfterWithChildren = m_canCollapseWithChildren && !afterBorderPadding |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 108 | && blockStyle.logicalHeight().isAuto() && !blockStyle.logicalHeight().value(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 109 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 110 | m_quirkContainer = block.isTableCell() || block.isBody(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 111 | |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 112 | m_positiveMargin = m_canCollapseMarginBeforeWithChildren ? block.maxPositiveMarginBefore() : 0_lu; |
| 113 | m_negativeMargin = m_canCollapseMarginBeforeWithChildren ? block.maxNegativeMarginBefore() : 0_lu; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 114 | } |
| 115 | |
antti@apple.com | 454418f | 2016-04-25 19:49:23 +0000 | [diff] [blame] | 116 | RenderBlockFlow::RenderBlockFlow(Element& element, RenderStyle&& style) |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 117 | : RenderBlock(element, WTFMove(style), RenderBlockFlowFlag) |
dbates@webkit.org | 102013c | 2016-09-26 21:51:25 +0000 | [diff] [blame] | 118 | #if ENABLE(TEXT_AUTOSIZING) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 119 | , m_widthForTextAutosizing(-1) |
| 120 | , m_lineCountForTextAutosizing(NOT_SET) |
| 121 | #endif |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 122 | { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 123 | setChildrenInline(true); |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 124 | } |
| 125 | |
antti@apple.com | 454418f | 2016-04-25 19:49:23 +0000 | [diff] [blame] | 126 | RenderBlockFlow::RenderBlockFlow(Document& document, RenderStyle&& style) |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 127 | : RenderBlock(document, WTFMove(style), RenderBlockFlowFlag) |
dbates@webkit.org | 102013c | 2016-09-26 21:51:25 +0000 | [diff] [blame] | 128 | #if ENABLE(TEXT_AUTOSIZING) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 129 | , m_widthForTextAutosizing(-1) |
| 130 | , m_lineCountForTextAutosizing(NOT_SET) |
| 131 | #endif |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 132 | { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 133 | setChildrenInline(true); |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | RenderBlockFlow::~RenderBlockFlow() |
| 137 | { |
simon.fraser@apple.com | 9812a45 | 2017-03-20 17:28:55 +0000 | [diff] [blame] | 138 | // Do not add any code here. Add it to willBeDestroyed() instead. |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 139 | } |
| 140 | |
zalan@apple.com | fde57e4 | 2018-02-22 00:20:40 +0000 | [diff] [blame] | 141 | void RenderBlockFlow::willBeDestroyed() |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 142 | { |
simon.fraser@apple.com | b59c690 | 2017-03-17 00:20:45 +0000 | [diff] [blame] | 143 | if (!renderTreeBeingDestroyed()) { |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 144 | if (firstRootBox()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 145 | // We can't wait for RenderBox::destroy to clear the selection, |
| 146 | // because by then we will have nuked the line boxes. |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 147 | if (isSelectionBorder()) |
jacob_uphoff@apple.com | 5a6faad | 2020-03-30 21:13:50 +0000 | [diff] [blame] | 148 | frame().selection().setNeedsSelectionUpdate(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 149 | |
| 150 | // If we are an anonymous block, then our line boxes might have children |
| 151 | // that will outlast this block. In the non-anonymous block case those |
| 152 | // children will be destroyed by the time we return from this function. |
| 153 | if (isAnonymousBlock()) { |
cdumez@apple.com | c1d54fa | 2015-10-13 19:15:55 +0000 | [diff] [blame] | 154 | for (auto* box = firstRootBox(); box; box = box->nextRootBox()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 155 | while (auto childBox = box->firstChild()) |
| 156 | childBox->removeFromParent(); |
| 157 | } |
| 158 | } |
akling@apple.com | a1986f5 | 2014-12-08 22:17:55 +0000 | [diff] [blame] | 159 | } else if (parent()) |
| 160 | parent()->dirtyLinesFromChangedChild(*this); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 161 | } |
| 162 | |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 163 | if (legacyLineLayout()) |
| 164 | legacyLineLayout()->lineBoxes().deleteLineBoxes(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 165 | |
simon.fraser@apple.com | 9812a45 | 2017-03-20 17:28:55 +0000 | [diff] [blame] | 166 | blockWillBeDestroyed(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 167 | |
| 168 | // NOTE: This jumps down to RenderBox, bypassing RenderBlock since it would do duplicate work. |
zalan@apple.com | fde57e4 | 2018-02-22 00:20:40 +0000 | [diff] [blame] | 169 | RenderBox::willBeDestroyed(); |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 170 | } |
| 171 | |
ggaren@apple.com | 91592ea | 2019-05-29 21:15:54 +0000 | [diff] [blame] | 172 | RenderMultiColumnFlow* RenderBlockFlow::multiColumnFlowSlowCase() const |
| 173 | { |
| 174 | return rareBlockFlowData()->m_multiColumnFlow.get(); |
| 175 | } |
| 176 | |
jfernandez@igalia.com | 93f23d2 | 2014-12-09 17:44:40 +0000 | [diff] [blame] | 177 | RenderBlockFlow* RenderBlockFlow::previousSiblingWithOverhangingFloats(bool& parentHasFloats) const |
| 178 | { |
| 179 | // Attempt to locate a previous sibling with overhanging floats. We skip any elements that are |
| 180 | // out of flow (like floating/positioned elements), and we also skip over any objects that may have shifted |
| 181 | // to avoid floats. |
| 182 | parentHasFloats = false; |
| 183 | for (RenderObject* sibling = previousSibling(); sibling; sibling = sibling->previousSibling()) { |
| 184 | if (is<RenderBlockFlow>(*sibling)) { |
| 185 | auto& siblingBlock = downcast<RenderBlockFlow>(*sibling); |
| 186 | if (!siblingBlock.avoidsFloats()) |
| 187 | return &siblingBlock; |
| 188 | } |
| 189 | if (sibling->isFloating()) |
| 190 | parentHasFloats = true; |
| 191 | } |
| 192 | return nullptr; |
| 193 | } |
| 194 | |
bjonesbe@adobe.com | f9f1040 | 2014-02-20 19:40:28 +0000 | [diff] [blame] | 195 | void RenderBlockFlow::rebuildFloatingObjectSetFromIntrudingFloats() |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 196 | { |
| 197 | if (m_floatingObjects) |
| 198 | m_floatingObjects->setHorizontalWritingMode(isHorizontalWritingMode()); |
| 199 | |
| 200 | HashSet<RenderBox*> oldIntrudingFloatSet; |
| 201 | if (!childrenInline() && m_floatingObjects) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 202 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 203 | auto end = floatingObjectSet.end(); |
| 204 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 205 | FloatingObject* floatingObject = it->get(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 206 | if (!floatingObject->isDescendant()) |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 207 | oldIntrudingFloatSet.add(&floatingObject->renderer()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
darin@apple.com | 8152c8ba | 2022-01-15 22:29:21 +0000 | [diff] [blame] | 211 | // Inline blocks are covered by the isReplacedOrInlineBlock() check in the avoidFloats method. |
simon.fraser@apple.com | f63871d | 2015-10-10 02:20:52 +0000 | [diff] [blame] | 212 | if (avoidsFloats() || isDocumentElementRenderer() || isRenderView() || isFloatingOrOutOfFlowPositioned() || isTableCell()) { |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 213 | if (m_floatingObjects) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 214 | m_floatingObjects->clear(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 215 | if (!oldIntrudingFloatSet.isEmpty()) |
| 216 | markAllDescendantsWithFloatsForLayout(); |
| 217 | return; |
| 218 | } |
| 219 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 220 | RendererToFloatInfoMap floatMap; |
| 221 | |
| 222 | if (m_floatingObjects) { |
bjonesbe@adobe.com | 0434768a | 2013-09-16 22:01:38 +0000 | [diff] [blame] | 223 | if (childrenInline()) |
| 224 | m_floatingObjects->moveAllToFloatInfoMap(floatMap); |
| 225 | else |
| 226 | m_floatingObjects->clear(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // We should not process floats if the parent node is not a RenderBlock. Otherwise, we will add |
| 230 | // floats in an invalid context. This will cause a crash arising from a bad cast on the parent. |
| 231 | // See <rdar://problem/8049753>, where float property is applied on a text node in a SVG. |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 232 | if (!is<RenderBlockFlow>(parent())) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 233 | return; |
| 234 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 235 | // First add in floats from the parent. Self-collapsing blocks let their parent track any floats that intrude into |
| 236 | // them (as opposed to floats they contain themselves) so check for those here too. |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 237 | auto& parentBlock = downcast<RenderBlockFlow>(*parent()); |
| 238 | bool parentHasFloats = false; |
| 239 | RenderBlockFlow* previousBlock = previousSiblingWithOverhangingFloats(parentHasFloats); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 240 | LayoutUnit logicalTopOffset = logicalTop(); |
jfernandez@igalia.com | 93f23d2 | 2014-12-09 17:44:40 +0000 | [diff] [blame] | 241 | if (parentHasFloats || (parentBlock.lowestFloatLogicalBottom() > logicalTopOffset && previousBlock && previousBlock->isSelfCollapsingBlock())) |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 242 | addIntrudingFloats(&parentBlock, &parentBlock, parentBlock.logicalLeftOffsetForContent(), logicalTopOffset); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 243 | |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 244 | LayoutUnit logicalLeftOffset; |
jfernandez@igalia.com | 93f23d2 | 2014-12-09 17:44:40 +0000 | [diff] [blame] | 245 | if (previousBlock) |
| 246 | logicalTopOffset -= previousBlock->logicalTop(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 247 | else { |
jfernandez@igalia.com | 93f23d2 | 2014-12-09 17:44:40 +0000 | [diff] [blame] | 248 | previousBlock = &parentBlock; |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 249 | logicalLeftOffset += parentBlock.logicalLeftOffsetForContent(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // Add overhanging floats from the previous RenderBlock, but only if it has a float that intrudes into our space. |
jfernandez@igalia.com | 93f23d2 | 2014-12-09 17:44:40 +0000 | [diff] [blame] | 253 | if (previousBlock->m_floatingObjects && previousBlock->lowestFloatLogicalBottom() > logicalTopOffset) |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 254 | addIntrudingFloats(previousBlock, &parentBlock, logicalLeftOffset, logicalTopOffset); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 255 | |
| 256 | if (childrenInline()) { |
| 257 | LayoutUnit changeLogicalTop = LayoutUnit::max(); |
| 258 | LayoutUnit changeLogicalBottom = LayoutUnit::min(); |
| 259 | if (m_floatingObjects) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 260 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 261 | auto end = floatingObjectSet.end(); |
| 262 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 263 | const auto& floatingObject = *it->get(); |
| 264 | std::unique_ptr<FloatingObject> oldFloatingObject = floatMap.take(&floatingObject.renderer()); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 265 | LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 266 | if (oldFloatingObject) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 267 | LayoutUnit oldLogicalBottom = logicalBottomForFloat(*oldFloatingObject); |
| 268 | if (logicalWidthForFloat(floatingObject) != logicalWidthForFloat(*oldFloatingObject) || logicalLeftForFloat(floatingObject) != logicalLeftForFloat(*oldFloatingObject)) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 269 | changeLogicalTop = 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 270 | changeLogicalBottom = std::max(changeLogicalBottom, std::max(logicalBottom, oldLogicalBottom)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 271 | } else { |
| 272 | if (logicalBottom != oldLogicalBottom) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 273 | changeLogicalTop = std::min(changeLogicalTop, std::min(logicalBottom, oldLogicalBottom)); |
| 274 | changeLogicalBottom = std::max(changeLogicalBottom, std::max(logicalBottom, oldLogicalBottom)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 275 | } |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 276 | LayoutUnit logicalTop = logicalTopForFloat(floatingObject); |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 277 | LayoutUnit oldLogicalTop = logicalTopForFloat(*oldFloatingObject); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 278 | if (logicalTop != oldLogicalTop) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 279 | changeLogicalTop = std::min(changeLogicalTop, std::min(logicalTop, oldLogicalTop)); |
| 280 | changeLogicalBottom = std::max(changeLogicalBottom, std::max(logicalTop, oldLogicalTop)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 284 | if (oldFloatingObject->originatingLine() && !selfNeedsLayout()) { |
| 285 | ASSERT(&oldFloatingObject->originatingLine()->renderer() == this); |
| 286 | oldFloatingObject->originatingLine()->markDirty(); |
| 287 | } |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 288 | } else { |
| 289 | changeLogicalTop = 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 290 | changeLogicalBottom = std::max(changeLogicalBottom, logicalBottom); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 295 | auto end = floatMap.end(); |
| 296 | for (auto it = floatMap.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 297 | const auto& floatingObject = *it->value.get(); |
| 298 | if (!floatingObject.isDescendant()) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 299 | changeLogicalTop = 0; |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 300 | changeLogicalBottom = std::max(changeLogicalBottom, logicalBottomForFloat(floatingObject)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 301 | } |
| 302 | } |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 303 | |
| 304 | markLinesDirtyInBlockRange(changeLogicalTop, changeLogicalBottom); |
| 305 | } else if (!oldIntrudingFloatSet.isEmpty()) { |
| 306 | // If there are previously intruding floats that no longer intrude, then children with floats |
| 307 | // should also get layout because they might need their floating object lists cleared. |
| 308 | if (m_floatingObjects->set().size() < oldIntrudingFloatSet.size()) |
| 309 | markAllDescendantsWithFloatsForLayout(); |
| 310 | else { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 311 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 312 | auto end = floatingObjectSet.end(); |
| 313 | for (auto it = floatingObjectSet.begin(); it != end && !oldIntrudingFloatSet.isEmpty(); ++it) |
| 314 | oldIntrudingFloatSet.remove(&(*it)->renderer()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 315 | if (!oldIntrudingFloatSet.isEmpty()) |
| 316 | markAllDescendantsWithFloatsForLayout(); |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 321 | void RenderBlockFlow::adjustIntrinsicLogicalWidthsForColumns(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const |
| 322 | { |
| 323 | if (!style().hasAutoColumnCount() || !style().hasAutoColumnWidth()) { |
| 324 | // The min/max intrinsic widths calculated really tell how much space elements need when |
| 325 | // laid out inside the columns. In order to eventually end up with the desired column width, |
| 326 | // we need to convert them to values pertaining to the multicol container. |
| 327 | int columnCount = style().hasAutoColumnCount() ? 1 : style().columnCount(); |
| 328 | LayoutUnit columnWidth; |
| 329 | LayoutUnit colGap = columnGap(); |
| 330 | LayoutUnit gapExtra = (columnCount - 1) * colGap; |
| 331 | if (style().hasAutoColumnWidth()) |
| 332 | minLogicalWidth = minLogicalWidth * columnCount + gapExtra; |
| 333 | else { |
| 334 | columnWidth = style().columnWidth(); |
| 335 | minLogicalWidth = std::min(minLogicalWidth, columnWidth); |
| 336 | } |
| 337 | // FIXME: If column-count is auto here, we should resolve it to calculate the maximum |
| 338 | // intrinsic width, instead of pretending that it's 1. The only way to do that is by |
| 339 | // performing a layout pass, but this is not an appropriate time or place for layout. The |
| 340 | // good news is that if height is unconstrained and there are no explicit breaks, the |
| 341 | // resolved column-count really should be 1. |
| 342 | maxLogicalWidth = std::max(maxLogicalWidth, columnWidth) * columnCount + gapExtra; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | void RenderBlockFlow::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const |
| 347 | { |
simon.fraser@apple.com | 45a5d9a | 2022-05-07 02:07:00 +0000 | [diff] [blame] | 348 | auto shouldIgnoreDescendantContentForLogicalWidth = shouldApplySizeOrStyleContainment({ Containment::Size, Containment::InlineSize }); |
zalan@apple.com | 0b73b01 | 2022-04-05 15:44:42 +0000 | [diff] [blame] | 349 | if (!shouldIgnoreDescendantContentForLogicalWidth) { |
cathiechen@igalia.com | e80ce68 | 2021-05-11 12:49:46 +0000 | [diff] [blame] | 350 | if (childrenInline()) |
| 351 | computeInlinePreferredLogicalWidths(minLogicalWidth, maxLogicalWidth); |
| 352 | else |
| 353 | computeBlockPreferredLogicalWidths(minLogicalWidth, maxLogicalWidth); |
| 354 | } |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 355 | |
| 356 | maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth); |
| 357 | |
| 358 | adjustIntrinsicLogicalWidthsForColumns(minLogicalWidth, maxLogicalWidth); |
| 359 | |
| 360 | if (!style().autoWrap() && childrenInline()) { |
| 361 | // A horizontal marquee with inline children has no minimum width. |
zimmermann@webkit.org | e056524 | 2021-01-25 21:37:54 +0000 | [diff] [blame] | 362 | auto* scrollableArea = layer() ? layer()->scrollableArea() : nullptr; |
| 363 | if (scrollableArea && scrollableArea->marquee() && scrollableArea->marquee()->isHorizontal()) |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 364 | minLogicalWidth = 0; |
| 365 | } |
| 366 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 367 | if (is<RenderTableCell>(*this)) { |
| 368 | Length tableCellWidth = downcast<RenderTableCell>(*this).styleOrColLogicalWidth(); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 369 | if (tableCellWidth.isFixed() && tableCellWidth.value() > 0) |
zalan@apple.com | a4d4f36 | 2020-12-19 22:10:14 +0000 | [diff] [blame] | 370 | maxLogicalWidth = std::max(minLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(tableCellWidth)); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 371 | } |
| 372 | |
rego@igalia.com | 76760c7 | 2015-05-14 16:37:27 +0000 | [diff] [blame] | 373 | int scrollbarWidth = intrinsicScrollbarLogicalWidth(); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 374 | maxLogicalWidth += scrollbarWidth; |
| 375 | minLogicalWidth += scrollbarWidth; |
| 376 | } |
| 377 | |
| 378 | bool RenderBlockFlow::recomputeLogicalWidthAndColumnWidth() |
| 379 | { |
| 380 | bool changed = recomputeLogicalWidth(); |
| 381 | |
| 382 | LayoutUnit oldColumnWidth = computedColumnWidth(); |
| 383 | computeColumnCountAndWidth(); |
| 384 | |
| 385 | return changed || oldColumnWidth != computedColumnWidth(); |
| 386 | } |
| 387 | |
| 388 | LayoutUnit RenderBlockFlow::columnGap() const |
| 389 | { |
rego@igalia.com | fcd8dd0 | 2018-01-26 14:57:47 +0000 | [diff] [blame] | 390 | if (style().columnGap().isNormal()) |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 391 | return style().fontDescription().computedPixelSize(); // "1em" is recommended as the normal gap setting. Matches <p> margins. |
rego@igalia.com | fcd8dd0 | 2018-01-26 14:57:47 +0000 | [diff] [blame] | 392 | return valueForLength(style().columnGap().length(), availableLogicalWidth()); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | void RenderBlockFlow::computeColumnCountAndWidth() |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 396 | { |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 397 | // Calculate our column width and column count. |
| 398 | // FIXME: Can overflow on fast/block/float/float-not-removed-from-next-sibling4.html, see https://bugs.webkit.org/show_bug.cgi?id=68744 |
| 399 | unsigned desiredColumnCount = 1; |
| 400 | LayoutUnit desiredColumnWidth = contentLogicalWidth(); |
zalan@apple.com | 08aaba7 | 2016-12-02 23:05:48 +0000 | [diff] [blame] | 401 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 402 | // For now, we don't support multi-column layouts when printing, since we have to do a lot of work for proper pagination. |
| 403 | if (document().paginated() || (style().hasAutoColumnCount() && style().hasAutoColumnWidth()) || !style().hasInlineColumnAxis()) { |
| 404 | setComputedColumnCountAndWidth(desiredColumnCount, desiredColumnWidth); |
| 405 | return; |
| 406 | } |
zalan@apple.com | 08aaba7 | 2016-12-02 23:05:48 +0000 | [diff] [blame] | 407 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 408 | LayoutUnit availWidth = desiredColumnWidth; |
| 409 | LayoutUnit colGap = columnGap(); |
ross.kirsling@sony.com | 8041465 | 2019-05-21 01:36:11 +0000 | [diff] [blame] | 410 | LayoutUnit colWidth = std::max(1_lu, LayoutUnit(style().columnWidth())); |
zalan@apple.com | 585798f | 2016-05-18 23:25:47 +0000 | [diff] [blame] | 411 | unsigned colCount = std::max<unsigned>(1, style().columnCount()); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 412 | |
| 413 | if (style().hasAutoColumnWidth() && !style().hasAutoColumnCount()) { |
| 414 | desiredColumnCount = colCount; |
| 415 | desiredColumnWidth = std::max<LayoutUnit>(0, (availWidth - ((desiredColumnCount - 1) * colGap)) / desiredColumnCount); |
| 416 | } else if (!style().hasAutoColumnWidth() && style().hasAutoColumnCount()) { |
zalan@apple.com | 08aaba7 | 2016-12-02 23:05:48 +0000 | [diff] [blame] | 417 | desiredColumnCount = std::max<unsigned>(1, ((availWidth + colGap) / (colWidth + colGap)).toUnsigned()); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 418 | desiredColumnWidth = ((availWidth + colGap) / desiredColumnCount) - colGap; |
| 419 | } else { |
zalan@apple.com | 08aaba7 | 2016-12-02 23:05:48 +0000 | [diff] [blame] | 420 | desiredColumnCount = std::max<unsigned>(std::min(colCount, ((availWidth + colGap) / (colWidth + colGap)).toUnsigned()), 1); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 421 | desiredColumnWidth = ((availWidth + colGap) / desiredColumnCount) - colGap; |
| 422 | } |
| 423 | setComputedColumnCountAndWidth(desiredColumnCount, desiredColumnWidth); |
| 424 | } |
| 425 | |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 426 | bool RenderBlockFlow::willCreateColumns(std::optional<unsigned> desiredColumnCount) const |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 427 | { |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 428 | // The following types are not supposed to create multicol context. |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 429 | if (isFileUploadControl() || isTextControl() || isListBox()) |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 430 | return false; |
commit-queue@webkit.org | 875cdb3 | 2017-10-02 17:59:36 +0000 | [diff] [blame] | 431 | if (isRenderSVGBlock() || isRubyRun()) |
antti@apple.com | 411949d | 2017-08-30 17:28:10 +0000 | [diff] [blame] | 432 | return false; |
commit-queue@webkit.org | 875cdb3 | 2017-10-02 17:59:36 +0000 | [diff] [blame] | 433 | #if ENABLE(MATHML) |
| 434 | if (isRenderMathMLBlock()) |
| 435 | return false; |
| 436 | #endif // ENABLE(MATHML) |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 437 | |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 438 | if (!firstChild()) |
| 439 | return false; |
| 440 | |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 441 | if (style().styleType() != PseudoId::None) |
antti@apple.com | 411949d | 2017-08-30 17:28:10 +0000 | [diff] [blame] | 442 | return false; |
| 443 | |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 444 | // If overflow-y is set to paged-x or paged-y on the body or html element, we'll handle the paginating in the RenderView instead. |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 445 | if ((style().overflowY() == Overflow::PagedX || style().overflowY() == Overflow::PagedY) && !(isDocumentElementRenderer() || isBody())) |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 446 | return true; |
zalan@apple.com | 2b9b610 | 2018-07-25 22:44:48 +0000 | [diff] [blame] | 447 | |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 448 | if (!style().specifiesColumns()) |
| 449 | return false; |
| 450 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 451 | // column-axis with opposite writing direction initiates MultiColumnFlow. |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 452 | if (!style().hasInlineColumnAxis()) |
| 453 | return true; |
| 454 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 455 | // Non-auto column-width always initiates MultiColumnFlow. |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 456 | if (!style().hasAutoColumnWidth()) |
| 457 | return true; |
| 458 | |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 459 | if (desiredColumnCount) |
| 460 | return desiredColumnCount.value() > 1; |
| 461 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 462 | // column-count > 1 always initiates MultiColumnFlow. |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 463 | if (!style().hasAutoColumnCount()) |
| 464 | return style().columnCount() > 1; |
| 465 | |
| 466 | ASSERT_NOT_REACHED(); |
| 467 | return false; |
| 468 | } |
| 469 | |
antti@apple.com | 0f90b2a | 2020-12-22 18:11:42 +0000 | [diff] [blame] | 470 | void RenderBlockFlow::setChildrenInline(bool value) |
| 471 | { |
| 472 | if (childrenInline() && !value) { |
| 473 | setLineLayoutPath(UndeterminedPath); |
commit-queue@webkit.org | 1acd723 | 2021-10-12 20:43:49 +0000 | [diff] [blame] | 474 | m_lineLayout = std::monostate(); |
antti@apple.com | 0f90b2a | 2020-12-22 18:11:42 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | RenderBlock::setChildrenInline(value); |
| 478 | } |
| 479 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 480 | void RenderBlockFlow::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight) |
| 481 | { |
| 482 | ASSERT(needsLayout()); |
| 483 | |
| 484 | if (!relayoutChildren && simplifiedLayout()) |
| 485 | return; |
| 486 | |
| 487 | LayoutRepainter repainter(*this, checkForRepaintDuringLayout()); |
| 488 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 489 | if (recomputeLogicalWidthAndColumnWidth()) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 490 | relayoutChildren = true; |
| 491 | |
bjonesbe@adobe.com | f9f1040 | 2014-02-20 19:40:28 +0000 | [diff] [blame] | 492 | rebuildFloatingObjectSetFromIntrudingFloats(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 493 | |
| 494 | LayoutUnit previousHeight = logicalHeight(); |
| 495 | // FIXME: should this start out as borderAndPaddingLogicalHeight() + scrollbarLogicalHeight(), |
| 496 | // for consistency with other render classes? |
zalan@apple.com | ad3d6b7 | 2019-11-20 23:52:40 +0000 | [diff] [blame] | 497 | resetLogicalHeightBeforeLayoutIfNeeded(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 498 | |
| 499 | bool pageLogicalHeightChanged = false; |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 500 | checkForPaginationLogicalHeightChange(relayoutChildren, pageLogicalHeight, pageLogicalHeightChanged); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 501 | |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 502 | LayoutUnit repaintLogicalTop; |
| 503 | LayoutUnit repaintLogicalBottom; |
| 504 | LayoutUnit maxFloatLogicalBottom; |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 505 | const RenderStyle& styleToUse = style(); |
commit-queue@webkit.org | 795b46f | 2022-02-28 22:09:24 +0000 | [diff] [blame] | 506 | do { |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 507 | LayoutStateMaintainer statePusher(*this, locationOffset(), hasTransform() || hasReflection() || styleToUse.isFlippedBlocksWritingMode(), pageLogicalHeight, pageLogicalHeightChanged); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 508 | |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 509 | preparePaginationBeforeBlockLayout(relayoutChildren); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 510 | |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 511 | // We use four values, maxTopPos, maxTopNeg, maxBottomPos, and maxBottomNeg, to track |
| 512 | // our current maximal positive and negative margins. These values are used when we |
| 513 | // are collapsed with adjacent blocks, so for example, if you have block A and B |
| 514 | // collapsing together, then you'd take the maximal positive margin from both A and B |
| 515 | // and subtract it from the maximal negative margin from both A and B to get the |
| 516 | // true collapsed margin. This algorithm is recursive, so when we finish layout() |
| 517 | // our block knows its current maximal positive/negative values. |
| 518 | // |
| 519 | // Start out by setting our margin values to our current margins. Table cells have |
| 520 | // no margins, so we don't fill in the values for table cells. |
| 521 | bool isCell = isTableCell(); |
| 522 | if (!isCell) { |
| 523 | initMaxMarginValues(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 524 | |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 525 | setHasMarginBeforeQuirk(styleToUse.hasMarginBeforeQuirk()); |
| 526 | setHasMarginAfterQuirk(styleToUse.hasMarginAfterQuirk()); |
| 527 | setPaginationStrut(0); |
| 528 | } |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 529 | if (!firstChild() && !isAnonymousBlock()) |
| 530 | setChildrenInline(true); |
commit-queue@webkit.org | 344bd0c | 2021-10-15 06:24:33 +0000 | [diff] [blame] | 531 | dirtyForLayoutFromPercentageHeightDescendants(); |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 532 | if (childrenInline()) |
| 533 | layoutInlineChildren(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
| 534 | else |
| 535 | layoutBlockChildren(relayoutChildren, maxFloatLogicalBottom); |
commit-queue@webkit.org | 795b46f | 2022-02-28 22:09:24 +0000 | [diff] [blame] | 536 | // Expand our intrinsic height to encompass floats. |
| 537 | LayoutUnit toAdd = borderAndPaddingAfter() + scrollbarLogicalHeight(); |
| 538 | if (lowestFloatLogicalBottom() > (logicalHeight() - toAdd) && createsNewFormattingContext()) |
| 539 | setLogicalHeight(lowestFloatLogicalBottom() + toAdd); |
| 540 | if (shouldBreakAtLineToAvoidWidow()) { |
| 541 | setEverHadLayout(true); |
| 542 | continue; |
| 543 | } |
| 544 | break; |
| 545 | } while (true); |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 546 | |
commit-queue@webkit.org | 795b46f | 2022-02-28 22:09:24 +0000 | [diff] [blame] | 547 | if (relayoutForPagination()) { |
zalan@apple.com | 4a44032 | 2017-11-10 00:31:24 +0000 | [diff] [blame] | 548 | ASSERT(!shouldBreakAtLineToAvoidWidow()); |
| 549 | return; |
| 550 | } |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 551 | |
zalan@apple.com | 4a44032 | 2017-11-10 00:31:24 +0000 | [diff] [blame] | 552 | // Calculate our new height. |
| 553 | LayoutUnit oldHeight = logicalHeight(); |
| 554 | LayoutUnit oldClientAfterEdge = clientLogicalBottom(); |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 555 | |
zalan@apple.com | 4a44032 | 2017-11-10 00:31:24 +0000 | [diff] [blame] | 556 | // Before updating the final size of the flow thread make sure a forced break is applied after the content. |
| 557 | // This ensures the size information is correctly computed for the last auto-height fragment receiving content. |
| 558 | if (is<RenderFragmentedFlow>(*this)) |
| 559 | downcast<RenderFragmentedFlow>(*this).applyBreakAfterContent(oldClientAfterEdge); |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 560 | |
zalan@apple.com | 4a44032 | 2017-11-10 00:31:24 +0000 | [diff] [blame] | 561 | updateLogicalHeight(); |
| 562 | LayoutUnit newHeight = logicalHeight(); |
| 563 | { |
commit-queue@webkit.org | 795b46f | 2022-02-28 22:09:24 +0000 | [diff] [blame] | 564 | // FIXME: This could be removed once relayoutForPagination() either stop recursing or we manage to |
zalan@apple.com | 4a44032 | 2017-11-10 00:31:24 +0000 | [diff] [blame] | 565 | // re-order them. |
| 566 | LayoutStateMaintainer statePusher(*this, locationOffset(), hasTransform() || hasReflection() || styleToUse.isFlippedBlocksWritingMode(), pageLogicalHeight, pageLogicalHeightChanged); |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 567 | |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 568 | if (oldHeight != newHeight) { |
| 569 | if (oldHeight > newHeight && maxFloatLogicalBottom > newHeight && !childrenInline()) { |
| 570 | // One of our children's floats may have become an overhanging float for us. We need to look for it. |
| 571 | for (auto& blockFlow : childrenOfType<RenderBlockFlow>(*this)) { |
| 572 | if (blockFlow.isFloatingOrOutOfFlowPositioned()) |
| 573 | continue; |
| 574 | if (blockFlow.lowestFloatLogicalBottom() + blockFlow.logicalTop() > newHeight) |
| 575 | addOverhangingFloats(blockFlow, false); |
| 576 | } |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 577 | } |
| 578 | } |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 579 | |
| 580 | bool heightChanged = (previousHeight != newHeight); |
| 581 | if (heightChanged) |
| 582 | relayoutChildren = true; |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 583 | layoutPositionedObjects(relayoutChildren || isDocumentElementRenderer()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 584 | } |
zalan@apple.com | 4a44032 | 2017-11-10 00:31:24 +0000 | [diff] [blame] | 585 | // Add overflow from children (unless we're multi-column, since in that case all our child overflow is clipped anyway). |
| 586 | computeOverflow(oldClientAfterEdge); |
| 587 | |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 588 | auto* state = view().frameView().layoutContext().layoutState(); |
zalan@apple.com | 7fd79ce | 2017-11-08 15:02:10 +0000 | [diff] [blame] | 589 | if (state && state->pageLogicalHeight()) |
zalan@apple.com | 85ab1ec | 2017-11-07 21:36:07 +0000 | [diff] [blame] | 590 | setPageLogicalOffset(state->pageLogicalOffset(this, logicalTop())); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 591 | |
| 592 | updateLayerTransform(); |
| 593 | |
| 594 | // Update our scroll information if we're overflow:auto/scroll/hidden now that we know if |
| 595 | // we overflow or not. |
| 596 | updateScrollInfoAfterLayout(); |
| 597 | |
| 598 | // FIXME: This repaint logic should be moved into a separate helper function! |
| 599 | // Repaint with our new bounds if they are different from our old bounds. |
| 600 | bool didFullRepaint = repainter.repaintAfterLayout(); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 601 | if (!didFullRepaint && repaintLogicalTop != repaintLogicalBottom && (styleToUse.visibility() == Visibility::Visible || enclosingLayer()->hasVisibleContent())) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 602 | // FIXME: We could tighten up the left and right invalidation points if we let layoutInlineChildren fill them in based off the particular lines |
commit-queue@webkit.org | 922b5ea | 2021-07-14 20:40:50 +0000 | [diff] [blame] | 603 | // it had to lay out. We wouldn't need the hasNonVisibleOverflow() hack in that case either. |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 604 | LayoutUnit repaintLogicalLeft = logicalLeftVisualOverflow(); |
| 605 | LayoutUnit repaintLogicalRight = logicalRightVisualOverflow(); |
commit-queue@webkit.org | 922b5ea | 2021-07-14 20:40:50 +0000 | [diff] [blame] | 606 | if (hasNonVisibleOverflow()) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 607 | // If we have clipped overflow, we should use layout overflow as well, since visual overflow from lines didn't propagate to our block's overflow. |
commit-queue@webkit.org | 922b5ea | 2021-07-14 20:40:50 +0000 | [diff] [blame] | 608 | // Note the old code did this as well but even for overflow:visible. The addition of hasNonVisibleOverflow() at least tightens up the hack a bit. |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 609 | // layoutInlineChildren should be patched to compute the entire repaint rect. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 610 | repaintLogicalLeft = std::min(repaintLogicalLeft, logicalLeftLayoutOverflow()); |
| 611 | repaintLogicalRight = std::max(repaintLogicalRight, logicalRightLayoutOverflow()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | LayoutRect repaintRect; |
| 615 | if (isHorizontalWritingMode()) |
| 616 | repaintRect = LayoutRect(repaintLogicalLeft, repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft, repaintLogicalBottom - repaintLogicalTop); |
| 617 | else |
| 618 | repaintRect = LayoutRect(repaintLogicalTop, repaintLogicalLeft, repaintLogicalBottom - repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft); |
| 619 | |
commit-queue@webkit.org | 922b5ea | 2021-07-14 20:40:50 +0000 | [diff] [blame] | 620 | if (hasNonVisibleOverflow()) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 621 | // Adjust repaint rect for scroll offset |
simon.fraser@apple.com | 24e03ba | 2016-05-11 04:48:08 +0000 | [diff] [blame] | 622 | repaintRect.moveBy(-scrollPosition()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 623 | |
| 624 | // Don't allow this rect to spill out of our overflow box. |
| 625 | repaintRect.intersect(LayoutRect(LayoutPoint(), size())); |
| 626 | } |
| 627 | |
| 628 | // Make sure the rect is still non-empty after intersecting for overflow above |
| 629 | if (!repaintRect.isEmpty()) { |
| 630 | repaintRectangle(repaintRect); // We need to do a partial repaint of our content. |
| 631 | if (hasReflection()) |
| 632 | repaintRectangle(reflectedRect(repaintRect)); |
| 633 | } |
| 634 | } |
| 635 | |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 636 | clearNeedsLayout(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | void RenderBlockFlow::layoutBlockChildren(bool relayoutChildren, LayoutUnit& maxFloatLogicalBottom) |
| 640 | { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 641 | LayoutUnit beforeEdge = borderAndPaddingBefore(); |
| 642 | LayoutUnit afterEdge = borderAndPaddingAfter() + scrollbarLogicalHeight(); |
| 643 | |
| 644 | setLogicalHeight(beforeEdge); |
| 645 | |
| 646 | // Lay out our hypothetical grid line as though it occurs at the top of the block. |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 647 | if (view().frameView().layoutContext().layoutState()->lineGrid() == this) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 648 | layoutLineGridBox(); |
| 649 | |
| 650 | // The margin struct caches all our current margin collapsing state. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 651 | MarginInfo marginInfo(*this, beforeEdge, afterEdge); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 652 | |
| 653 | // Fieldsets need to find their legend and position it inside the border of the object. |
| 654 | // The legend then gets skipped during normal layout. The same is true for ruby text. |
| 655 | // It doesn't get included in the normal layout process but is instead skipped. |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 656 | layoutExcludedChildren(relayoutChildren); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 657 | |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 658 | LayoutUnit previousFloatLogicalBottom; |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 659 | maxFloatLogicalBottom = 0; |
| 660 | |
| 661 | RenderBox* next = firstChildBox(); |
| 662 | |
| 663 | while (next) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 664 | RenderBox& child = *next; |
| 665 | next = child.nextSiblingBox(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 666 | |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 667 | if (child.isExcludedFromNormalLayout()) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 668 | continue; // Skip this child, since it will be positioned by the specialized subclass (fieldsets and ruby runs). |
| 669 | |
| 670 | updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child); |
| 671 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 672 | if (child.isOutOfFlowPositioned()) { |
| 673 | child.containingBlock()->insertPositionedObject(child); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 674 | adjustPositionedBlock(child, marginInfo); |
| 675 | continue; |
| 676 | } |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 677 | if (child.isFloating()) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 678 | insertFloatingObject(child); |
| 679 | adjustFloatingBlock(marginInfo); |
| 680 | continue; |
| 681 | } |
| 682 | |
| 683 | // Lay out the child. |
| 684 | layoutBlockChild(child, marginInfo, previousFloatLogicalBottom, maxFloatLogicalBottom); |
| 685 | } |
| 686 | |
| 687 | // Now do the handling of the bottom of the block, adding in our bottom border/padding and |
| 688 | // determining the correct collapsed bottom margin information. |
| 689 | handleAfterSideOfBlock(beforeEdge, afterEdge, marginInfo); |
| 690 | } |
| 691 | |
antti@apple.com | 5072de9 | 2021-11-02 16:01:26 +0000 | [diff] [blame] | 692 | void RenderBlockFlow::computeAndSetLineLayoutPath() |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 693 | { |
antti@apple.com | 5072de9 | 2021-11-02 16:01:26 +0000 | [diff] [blame] | 694 | if (lineLayoutPath() != UndeterminedPath) |
| 695 | return; |
| 696 | |
| 697 | auto compute = [&] { |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 698 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | f7ac1cc | 2020-09-23 12:03:57 +0000 | [diff] [blame] | 699 | if (LayoutIntegration::LineLayout::canUseFor(*this)) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 700 | return ModernPath; |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 701 | #endif |
zalan@apple.com | 515e370 | 2021-10-11 15:55:01 +0000 | [diff] [blame] | 702 | return LegacyPath; |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 703 | }; |
| 704 | |
antti@apple.com | 5072de9 | 2021-11-02 16:01:26 +0000 | [diff] [blame] | 705 | setLineLayoutPath(compute()); |
| 706 | } |
| 707 | |
| 708 | void RenderBlockFlow::layoutInlineChildren(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
| 709 | { |
| 710 | computeAndSetLineLayoutPath(); |
antti@apple.com | 42fb53d | 2013-10-25 02:33:11 +0000 | [diff] [blame] | 711 | |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 712 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 713 | if (lineLayoutPath() == ModernPath) { |
| 714 | layoutModernLines(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 715 | return; |
| 716 | } |
| 717 | #endif |
| 718 | |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 719 | if (!legacyLineLayout()) |
| 720 | m_lineLayout = makeUnique<LegacyLineLayout>(*this); |
antti@apple.com | c6a9c73 | 2019-08-12 15:31:34 +0000 | [diff] [blame] | 721 | |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 722 | legacyLineLayout()->layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 723 | } |
| 724 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 725 | void RenderBlockFlow::layoutBlockChild(RenderBox& child, MarginInfo& marginInfo, LayoutUnit& previousFloatLogicalBottom, LayoutUnit& maxFloatLogicalBottom) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 726 | { |
| 727 | LayoutUnit oldPosMarginBefore = maxPositiveMarginBefore(); |
| 728 | LayoutUnit oldNegMarginBefore = maxNegativeMarginBefore(); |
| 729 | |
| 730 | // The child is a normal flow object. Compute the margins we will use for collapsing now. |
mmaxfield@apple.com | 09804f4 | 2016-03-23 00:58:34 +0000 | [diff] [blame] | 731 | child.computeAndSetBlockDirectionMargins(*this); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 732 | |
| 733 | // Try to guess our correct logical top position. In most cases this guess will |
| 734 | // be correct. Only if we're wrong (when we compute the real logical top position) |
| 735 | // will we have to potentially relayout. |
| 736 | LayoutUnit estimateWithoutPagination; |
| 737 | LayoutUnit logicalTopEstimate = estimateLogicalTopPosition(child, marginInfo, estimateWithoutPagination); |
| 738 | |
| 739 | // Cache our old rect so that we can dirty the proper repaint rects if the child moves. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 740 | LayoutRect oldRect = child.frameRect(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 741 | LayoutUnit oldLogicalTop = logicalTopForChild(child); |
| 742 | |
mark.lam@apple.com | 6572436 | 2020-01-06 22:24:50 +0000 | [diff] [blame] | 743 | #if ASSERT_ENABLED |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 744 | LayoutSize oldLayoutDelta = view().frameView().layoutContext().layoutDelta(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 745 | #endif |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 746 | // Position the child as though it didn't collapse with the top. |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 747 | setLogicalTopForChild(child, logicalTopEstimate, ApplyLayoutDelta); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 748 | estimateFragmentRangeForBoxChild(child); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 749 | |
cdumez@apple.com | 5f02e63 | 2022-01-16 01:33:25 +0000 | [diff] [blame] | 750 | auto* childBlockFlow = dynamicDowncast<RenderBlockFlow>(child); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 751 | bool markDescendantsWithFloats = false; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 752 | if (logicalTopEstimate != oldLogicalTop && !child.avoidsFloats() && childBlockFlow && childBlockFlow->containsFloats()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 753 | markDescendantsWithFloats = true; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 754 | else if (UNLIKELY(logicalTopEstimate.mightBeSaturated())) |
| 755 | // logicalTopEstimate, returned by estimateLogicalTopPosition, might be saturated for |
| 756 | // very large elements. If it does the comparison with oldLogicalTop might yield a |
| 757 | // false negative as adding and removing margins, borders etc from a saturated number |
| 758 | // might yield incorrect results. If this is the case always mark for layout. |
| 759 | markDescendantsWithFloats = true; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 760 | else if (!child.avoidsFloats() || child.shrinkToAvoidFloats()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 761 | // If an element might be affected by the presence of floats, then always mark it for |
| 762 | // layout. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 763 | LayoutUnit fb = std::max(previousFloatLogicalBottom, lowestFloatLogicalBottom()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 764 | if (fb > logicalTopEstimate) |
| 765 | markDescendantsWithFloats = true; |
| 766 | } |
| 767 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 768 | if (childBlockFlow) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 769 | if (markDescendantsWithFloats) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 770 | childBlockFlow->markAllDescendantsWithFloatsForLayout(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 771 | if (!child.isWritingModeRoot()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 772 | previousFloatLogicalBottom = std::max(previousFloatLogicalBottom, oldLogicalTop + childBlockFlow->lowestFloatLogicalBottom()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 773 | } |
| 774 | |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 775 | child.markForPaginationRelayoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 776 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 777 | bool childHadLayout = child.everHadLayout(); |
| 778 | bool childNeededLayout = child.needsLayout(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 779 | if (childNeededLayout) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 780 | child.layout(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 781 | |
| 782 | // Cache if we are at the top of the block right now. |
| 783 | bool atBeforeSideOfBlock = marginInfo.atBeforeSideOfBlock(); |
| 784 | |
| 785 | // Now determine the correct ypos based off examination of collapsing margin |
| 786 | // values. |
| 787 | LayoutUnit logicalTopBeforeClear = collapseMargins(child, marginInfo); |
| 788 | |
| 789 | // Now check for clear. |
| 790 | LayoutUnit logicalTopAfterClear = clearFloatsIfNeeded(child, marginInfo, oldPosMarginBefore, oldNegMarginBefore, logicalTopBeforeClear); |
| 791 | |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 792 | bool paginated = view().frameView().layoutContext().layoutState()->isPaginated(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 793 | if (paginated) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 794 | logicalTopAfterClear = adjustBlockChildForPagination(logicalTopAfterClear, estimateWithoutPagination, child, atBeforeSideOfBlock && logicalTopBeforeClear == logicalTopAfterClear); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 795 | |
| 796 | setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta); |
| 797 | |
| 798 | // Now we have a final top position. See if it really does end up being different from our estimate. |
| 799 | // clearFloatsIfNeeded can also mark the child as needing a layout even though we didn't move. This happens |
| 800 | // when collapseMargins dynamically adds overhanging floats because of a child with negative margins. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 801 | if (logicalTopAfterClear != logicalTopEstimate || child.needsLayout() || (paginated && childBlockFlow && childBlockFlow->shouldBreakAtLineToAvoidWidow())) { |
| 802 | if (child.shrinkToAvoidFloats()) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 803 | // The child's width depends on the line width. When the child shifts to clear an item, its width can |
| 804 | // change (because it has more available line width). So mark the item as dirty. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 805 | child.setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 806 | } |
| 807 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 808 | if (childBlockFlow) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 809 | if (!child.avoidsFloats() && childBlockFlow->containsFloats()) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 810 | childBlockFlow->markAllDescendantsWithFloatsForLayout(); |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 811 | child.markForPaginationRelayoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 812 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 813 | } |
| 814 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 815 | if (updateFragmentRangeForBoxChild(child)) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 816 | child.setNeedsLayout(MarkOnlyThis); |
abucur@adobe.com | eaf5e22 | 2014-05-14 14:35:07 +0000 | [diff] [blame] | 817 | |
| 818 | // In case our guess was wrong, relayout the child. |
| 819 | child.layoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 820 | |
| 821 | // We are no longer at the top of the block if we encounter a non-empty child. |
| 822 | // This has to be done after checking for clear, so that margins can be reset if a clear occurred. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 823 | if (marginInfo.atBeforeSideOfBlock() && !child.isSelfCollapsingBlock()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 824 | marginInfo.setAtBeforeSideOfBlock(false); |
| 825 | |
| 826 | // Now place the child in the correct left position |
| 827 | determineLogicalLeftPositionForChild(child, ApplyLayoutDelta); |
| 828 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 829 | // Update our height now that the child has been placed in the correct position. |
stavila@adobe.com | b0d86c4 | 2014-04-09 17:07:50 +0000 | [diff] [blame] | 830 | setLogicalHeight(logicalHeight() + logicalHeightForChildForFragmentation(child)); |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 831 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 832 | // If the child has overhanging floats that intrude into following siblings (or possibly out |
| 833 | // of this block), then the parent gets notified of the floats now. |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 834 | if (childBlockFlow && childBlockFlow->containsFloats()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 835 | maxFloatLogicalBottom = std::max(maxFloatLogicalBottom, addOverhangingFloats(*childBlockFlow, !childNeededLayout)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 836 | |
zoltan@webkit.org | 7d4f8cc | 2014-03-26 18:20:15 +0000 | [diff] [blame] | 837 | LayoutSize childOffset = child.location() - oldRect.location(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 838 | if (childOffset.width() || childOffset.height()) { |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 839 | view().frameView().layoutContext().addLayoutDelta(childOffset); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 840 | |
| 841 | // If the child moved, we have to repaint it as well as any floating/positioned |
| 842 | // descendants. An exception is if we need a layout. In this case, we know we're going to |
| 843 | // repaint ourselves (and the child) anyway. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 844 | if (childHadLayout && !selfNeedsLayout() && child.checkForRepaintDuringLayout()) |
| 845 | child.repaintDuringLayoutIfMoved(oldRect); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 846 | } |
| 847 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 848 | if (!childHadLayout && child.checkForRepaintDuringLayout()) { |
| 849 | child.repaint(); |
| 850 | child.repaintOverhangingFloats(true); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | if (paginated) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 854 | if (RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow()) |
| 855 | fragmentedFlow->fragmentedFlowDescendantBoxLaidOut(&child); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 856 | // Check for an after page/column break. |
| 857 | LayoutUnit newHeight = applyAfterBreak(child, logicalHeight(), marginInfo); |
| 858 | if (newHeight != height()) |
| 859 | setLogicalHeight(newHeight); |
| 860 | } |
| 861 | |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 862 | ASSERT(view().frameView().layoutContext().layoutDeltaMatches(oldLayoutDelta)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 863 | } |
| 864 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 865 | void RenderBlockFlow::adjustPositionedBlock(RenderBox& child, const MarginInfo& marginInfo) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 866 | { |
| 867 | bool isHorizontal = isHorizontalWritingMode(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 868 | bool hasStaticBlockPosition = child.style().hasStaticBlockPosition(isHorizontal); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 869 | |
| 870 | LayoutUnit logicalTop = logicalHeight(); |
zalan@apple.com | 4d97a00 | 2016-02-24 17:13:33 +0000 | [diff] [blame] | 871 | updateStaticInlinePositionForChild(child, logicalTop, DoNotIndentText); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 872 | |
| 873 | if (!marginInfo.canCollapseWithMarginBefore()) { |
| 874 | // Positioned blocks don't collapse margins, so add the margin provided by |
| 875 | // the container now. The child's own margin is added later when calculating its logical top. |
| 876 | LayoutUnit collapsedBeforePos = marginInfo.positiveMargin(); |
| 877 | LayoutUnit collapsedBeforeNeg = marginInfo.negativeMargin(); |
| 878 | logicalTop += collapsedBeforePos - collapsedBeforeNeg; |
| 879 | } |
| 880 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 881 | RenderLayer* childLayer = child.layer(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 882 | if (childLayer->staticBlockPosition() != logicalTop) { |
| 883 | childLayer->setStaticBlockPosition(logicalTop); |
| 884 | if (hasStaticBlockPosition) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 885 | child.setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 889 | LayoutUnit RenderBlockFlow::marginOffsetForSelfCollapsingBlock() |
| 890 | { |
| 891 | ASSERT(isSelfCollapsingBlock()); |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 892 | RenderBlockFlow* parentBlock = downcast<RenderBlockFlow>(parent()); |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 893 | if (parentBlock && RenderStyle::usedClear(*this) != UsedClear::None && parentBlock->getClearDelta(*this, logicalHeight())) |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 894 | return marginValuesForChild(*this).positiveMarginBefore(); |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 895 | return 0_lu; |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 896 | } |
| 897 | |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 898 | void RenderBlockFlow::determineLogicalLeftPositionForChild(RenderBox& child, ApplyLayoutDeltaMode applyDelta) |
| 899 | { |
| 900 | LayoutUnit startPosition = borderStart() + paddingStart(); |
heycam@apple.com | e5cd283 | 2021-04-16 23:55:14 +0000 | [diff] [blame] | 901 | if (shouldPlaceVerticalScrollbarOnLeft() && isHorizontalWritingMode()) |
mmaxfield@apple.com | af573be | 2016-03-12 21:18:25 +0000 | [diff] [blame] | 902 | startPosition += (style().isLeftToRightDirection() ? 1 : -1) * verticalScrollbarWidth(); |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 903 | LayoutUnit totalAvailableLogicalWidth = borderAndPaddingLogicalWidth() + availableLogicalWidth(); |
| 904 | |
| 905 | // Add in our start margin. |
| 906 | LayoutUnit childMarginStart = marginStartForChild(child); |
| 907 | LayoutUnit newPosition = startPosition + childMarginStart; |
| 908 | |
| 909 | // Some objects (e.g., tables, horizontal rules, overflow:auto blocks) avoid floats. They need |
| 910 | // to shift over as necessary to dodge any floats that might get in the way. |
antti@apple.com | eae7612 | 2017-09-20 15:37:23 +0000 | [diff] [blame] | 911 | if (child.avoidsFloats() && containsFloats()) |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 912 | newPosition += computeStartPositionDeltaForChildAvoidingFloats(child, marginStartForChild(child)); |
| 913 | |
| 914 | setLogicalLeftForChild(child, style().isLeftToRightDirection() ? newPosition : totalAvailableLogicalWidth - newPosition - logicalWidthForChild(child), applyDelta); |
| 915 | } |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 916 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 917 | void RenderBlockFlow::adjustFloatingBlock(const MarginInfo& marginInfo) |
| 918 | { |
| 919 | // The float should be positioned taking into account the bottom margin |
| 920 | // of the previous flow. We add that margin into the height, get the |
| 921 | // float positioned properly, and then subtract the margin out of the |
| 922 | // height again. In the case of self-collapsing blocks, we always just |
| 923 | // use the top margins, since the self-collapsing block collapsed its |
| 924 | // own bottom margin into its top margin. |
| 925 | // |
| 926 | // Note also that the previous flow may collapse its margin into the top of |
| 927 | // our block. If this is the case, then we do not add the margin in to our |
| 928 | // height when computing the position of the float. This condition can be tested |
| 929 | // for by simply calling canCollapseWithMarginBefore. See |
| 930 | // http://www.hixie.ch/tests/adhoc/css/box/block/margin-collapse/046.html for |
| 931 | // an example of this scenario. |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 932 | LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? 0_lu : marginInfo.margin(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 933 | setLogicalHeight(logicalHeight() + marginOffset); |
| 934 | positionNewFloats(); |
| 935 | setLogicalHeight(logicalHeight() - marginOffset); |
| 936 | } |
| 937 | |
zalan@apple.com | 4d97a00 | 2016-02-24 17:13:33 +0000 | [diff] [blame] | 938 | void RenderBlockFlow::updateStaticInlinePositionForChild(RenderBox& child, LayoutUnit logicalTop, IndentTextOrNot shouldIndentText) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 939 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 940 | if (child.style().isOriginalDisplayInlineType()) |
antti@apple.com | c6a9c73 | 2019-08-12 15:31:34 +0000 | [diff] [blame] | 941 | setStaticInlinePositionForChild(child, logicalTop, startAlignedOffsetForLine(logicalTop, shouldIndentText)); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 942 | else |
| 943 | setStaticInlinePositionForChild(child, logicalTop, startOffsetForContent(logicalTop)); |
| 944 | } |
| 945 | |
| 946 | void RenderBlockFlow::setStaticInlinePositionForChild(RenderBox& child, LayoutUnit blockOffset, LayoutUnit inlinePosition) |
| 947 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 948 | if (enclosingFragmentedFlow()) { |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 949 | // Shift the inline position to exclude the fragment offset. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 950 | inlinePosition += startOffsetForContent() - startOffsetForContent(blockOffset); |
| 951 | } |
| 952 | child.layer()->setStaticInlinePosition(inlinePosition); |
| 953 | } |
| 954 | |
antti@apple.com | c6a9c73 | 2019-08-12 15:31:34 +0000 | [diff] [blame] | 955 | LayoutUnit RenderBlockFlow::startAlignedOffsetForLine(LayoutUnit position, IndentTextOrNot shouldIndentText) |
| 956 | { |
| 957 | TextAlignMode textAlign = style().textAlign(); |
| 958 | bool shouldApplyIndentText = false; |
| 959 | switch (textAlign) { |
| 960 | case TextAlignMode::Left: |
| 961 | case TextAlignMode::WebKitLeft: |
| 962 | shouldApplyIndentText = style().isLeftToRightDirection(); |
| 963 | break; |
| 964 | case TextAlignMode::Right: |
| 965 | case TextAlignMode::WebKitRight: |
| 966 | shouldApplyIndentText = !style().isLeftToRightDirection(); |
| 967 | break; |
| 968 | case TextAlignMode::Start: |
| 969 | shouldApplyIndentText = true; |
| 970 | break; |
| 971 | default: |
| 972 | shouldApplyIndentText = false; |
| 973 | } |
| 974 | // <rdar://problem/15427571> |
| 975 | // https://bugs.webkit.org/show_bug.cgi?id=124522 |
| 976 | // This quirk is for legacy content that doesn't work properly with the center positioning scheme |
| 977 | // being honored (e.g., epubs). |
| 978 | if (shouldApplyIndentText || settings().useLegacyTextAlignPositionedElementBehavior()) // FIXME: Handle TextAlignMode::End here |
| 979 | return startOffsetForLine(position, shouldIndentText); |
| 980 | |
| 981 | // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here |
| 982 | float totalLogicalWidth = 0; |
| 983 | float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), DoNotIndentText); |
| 984 | float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), DoNotIndentText) - logicalLeft; |
| 985 | |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 986 | LegacyLineLayout::updateLogicalWidthForAlignment(*this, textAlign, nullptr, nullptr, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0); |
antti@apple.com | c6a9c73 | 2019-08-12 15:31:34 +0000 | [diff] [blame] | 987 | |
| 988 | if (!style().isLeftToRightDirection()) |
| 989 | return LayoutUnit(logicalWidth() - logicalLeft); |
| 990 | |
| 991 | return LayoutUnit(logicalLeft); |
| 992 | } |
| 993 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 994 | RenderBlockFlow::MarginValues RenderBlockFlow::marginValuesForChild(RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 995 | { |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 996 | LayoutUnit childBeforePositive; |
| 997 | LayoutUnit childBeforeNegative; |
| 998 | LayoutUnit childAfterPositive; |
| 999 | LayoutUnit childAfterNegative; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1000 | |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 1001 | LayoutUnit beforeMargin; |
| 1002 | LayoutUnit afterMargin; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1003 | |
cdumez@apple.com | 5f02e63 | 2022-01-16 01:33:25 +0000 | [diff] [blame] | 1004 | auto* childRenderBlock = dynamicDowncast<RenderBlockFlow>(child); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1005 | |
| 1006 | // If the child has the same directionality as we do, then we can just return its |
| 1007 | // margins in the same direction. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1008 | if (!child.isWritingModeRoot()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1009 | if (childRenderBlock) { |
| 1010 | childBeforePositive = childRenderBlock->maxPositiveMarginBefore(); |
| 1011 | childBeforeNegative = childRenderBlock->maxNegativeMarginBefore(); |
| 1012 | childAfterPositive = childRenderBlock->maxPositiveMarginAfter(); |
| 1013 | childAfterNegative = childRenderBlock->maxNegativeMarginAfter(); |
| 1014 | } else { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1015 | beforeMargin = child.marginBefore(); |
| 1016 | afterMargin = child.marginAfter(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1017 | } |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1018 | } else if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1019 | // The child has a different directionality. If the child is parallel, then it's just |
| 1020 | // flipped relative to us. We can use the margins for the opposite edges. |
| 1021 | if (childRenderBlock) { |
| 1022 | childBeforePositive = childRenderBlock->maxPositiveMarginAfter(); |
| 1023 | childBeforeNegative = childRenderBlock->maxNegativeMarginAfter(); |
| 1024 | childAfterPositive = childRenderBlock->maxPositiveMarginBefore(); |
| 1025 | childAfterNegative = childRenderBlock->maxNegativeMarginBefore(); |
| 1026 | } else { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1027 | beforeMargin = child.marginAfter(); |
| 1028 | afterMargin = child.marginBefore(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1029 | } |
| 1030 | } else { |
| 1031 | // The child is perpendicular to us, which means its margins don't collapse but are on the |
| 1032 | // "logical left/right" sides of the child box. We can just return the raw margin in this case. |
| 1033 | beforeMargin = marginBeforeForChild(child); |
| 1034 | afterMargin = marginAfterForChild(child); |
| 1035 | } |
| 1036 | |
| 1037 | // Resolve uncollapsing margins into their positive/negative buckets. |
| 1038 | if (beforeMargin) { |
| 1039 | if (beforeMargin > 0) |
| 1040 | childBeforePositive = beforeMargin; |
| 1041 | else |
| 1042 | childBeforeNegative = -beforeMargin; |
| 1043 | } |
| 1044 | if (afterMargin) { |
| 1045 | if (afterMargin > 0) |
| 1046 | childAfterPositive = afterMargin; |
| 1047 | else |
| 1048 | childAfterNegative = -afterMargin; |
| 1049 | } |
| 1050 | |
| 1051 | return MarginValues(childBeforePositive, childBeforeNegative, childAfterPositive, childAfterNegative); |
| 1052 | } |
| 1053 | |
hyatt@apple.com | 72311dc | 2015-09-10 22:15:46 +0000 | [diff] [blame] | 1054 | bool RenderBlockFlow::childrenPreventSelfCollapsing() const |
| 1055 | { |
| 1056 | if (!childrenInline()) |
| 1057 | return RenderBlock::childrenPreventSelfCollapsing(); |
| 1058 | |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 1059 | return hasLines(); |
hyatt@apple.com | 72311dc | 2015-09-10 22:15:46 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1062 | LayoutUnit RenderBlockFlow::collapseMargins(RenderBox& child, MarginInfo& marginInfo) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1063 | { |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1064 | return collapseMarginsWithChildInfo(&child, child.previousSibling(), marginInfo); |
| 1065 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1066 | |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1067 | LayoutUnit RenderBlockFlow::collapseMarginsWithChildInfo(RenderBox* child, RenderObject* prevSibling, MarginInfo& marginInfo) |
| 1068 | { |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1069 | bool childIsSelfCollapsing = child ? child->isSelfCollapsingBlock() : false; |
| 1070 | bool beforeQuirk = child ? hasMarginBeforeQuirk(*child) : false; |
| 1071 | bool afterQuirk = child ? hasMarginAfterQuirk(*child) : false; |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1072 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1073 | // Get the four margin values for the child and cache them. |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1074 | const MarginValues childMargins = child ? marginValuesForChild(*child) : MarginValues(0, 0, 0, 0); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1075 | |
| 1076 | // Get our max pos and neg top margins. |
| 1077 | LayoutUnit posTop = childMargins.positiveMarginBefore(); |
| 1078 | LayoutUnit negTop = childMargins.negativeMarginBefore(); |
| 1079 | |
| 1080 | // For self-collapsing blocks, collapse our bottom margins into our |
| 1081 | // top to get new posTop and negTop values. |
| 1082 | if (childIsSelfCollapsing) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1083 | posTop = std::max(posTop, childMargins.positiveMarginAfter()); |
| 1084 | negTop = std::max(negTop, childMargins.negativeMarginAfter()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1085 | } |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1086 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1087 | if (marginInfo.canCollapseWithMarginBefore()) { |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1088 | // This child is collapsing with the top of the |
| 1089 | // block. If it has larger margin values, then we need to update |
| 1090 | // our own maximal values. |
| 1091 | if (!document().inQuirksMode() || !marginInfo.quirkContainer() || !beforeQuirk) |
| 1092 | setMaxMarginBeforeValues(std::max(posTop, maxPositiveMarginBefore()), std::max(negTop, maxNegativeMarginBefore())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1093 | |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1094 | // The minute any of the margins involved isn't a quirk, don't |
| 1095 | // collapse it away, even if the margin is smaller (www.webreference.com |
| 1096 | // has an example of this, a <dt> with 0.8em author-specified inside |
| 1097 | // a <dl> inside a <td>. |
| 1098 | if (!marginInfo.determinedMarginBeforeQuirk() && !beforeQuirk && (posTop - negTop)) { |
| 1099 | setHasMarginBeforeQuirk(false); |
| 1100 | marginInfo.setDeterminedMarginBeforeQuirk(true); |
| 1101 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1102 | |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1103 | if (!marginInfo.determinedMarginBeforeQuirk() && beforeQuirk && !marginBefore()) { |
| 1104 | // We have no top margin and our top child has a quirky margin. |
| 1105 | // We will pick up this quirky margin and pass it through. |
| 1106 | // This deals with the <td><div><p> case. |
| 1107 | // Don't do this for a block that split two inlines though. You do |
| 1108 | // still apply margins in this case. |
| 1109 | setHasMarginBeforeQuirk(true); |
| 1110 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | if (marginInfo.quirkContainer() && marginInfo.atBeforeSideOfBlock() && (posTop - negTop)) |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1114 | marginInfo.setHasMarginBeforeQuirk(beforeQuirk); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1115 | |
| 1116 | LayoutUnit beforeCollapseLogicalTop = logicalHeight(); |
| 1117 | LayoutUnit logicalTop = beforeCollapseLogicalTop; |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1118 | |
| 1119 | LayoutUnit clearanceForSelfCollapsingBlock; |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1120 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1121 | // If the child's previous sibling is a self-collapsing block that cleared a float then its top border edge has been set at the bottom border edge |
| 1122 | // of the float. Since we want to collapse the child's top margin with the self-collapsing block's top and bottom margins we need to adjust our parent's height to match the |
| 1123 | // margin top of the self-collapsing block. If the resulting collapsed margin leaves the child still intruding into the float then we will want to clear it. |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1124 | if (!marginInfo.canCollapseWithMarginBefore() && is<RenderBlockFlow>(prevSibling) && downcast<RenderBlockFlow>(*prevSibling).isSelfCollapsingBlock()) { |
| 1125 | clearanceForSelfCollapsingBlock = downcast<RenderBlockFlow>(*prevSibling).marginOffsetForSelfCollapsingBlock(); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1126 | setLogicalHeight(logicalHeight() - clearanceForSelfCollapsingBlock); |
| 1127 | } |
| 1128 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1129 | if (childIsSelfCollapsing) { |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1130 | // This child has no height. We need to compute our |
| 1131 | // position before we collapse the child's margins together, |
| 1132 | // so that we can get an accurate position for the zero-height block. |
| 1133 | LayoutUnit collapsedBeforePos = std::max(marginInfo.positiveMargin(), childMargins.positiveMarginBefore()); |
| 1134 | LayoutUnit collapsedBeforeNeg = std::max(marginInfo.negativeMargin(), childMargins.negativeMarginBefore()); |
| 1135 | marginInfo.setMargin(collapsedBeforePos, collapsedBeforeNeg); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1136 | |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1137 | // Now collapse the child's margins together, which means examining our |
| 1138 | // bottom margin values as well. |
| 1139 | marginInfo.setPositiveMarginIfLarger(childMargins.positiveMarginAfter()); |
| 1140 | marginInfo.setNegativeMarginIfLarger(childMargins.negativeMarginAfter()); |
| 1141 | |
| 1142 | if (!marginInfo.canCollapseWithMarginBefore()) { |
| 1143 | // We need to make sure that the position of the self-collapsing block |
| 1144 | // is correct, since it could have overflowing content |
| 1145 | // that needs to be positioned correctly (e.g., a block that |
| 1146 | // had a specified height of 0 but that actually had subcontent). |
| 1147 | logicalTop = logicalHeight() + collapsedBeforePos - collapsedBeforeNeg; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } else { |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1150 | if (!marginInfo.atBeforeSideOfBlock() || (!marginInfo.canCollapseMarginBeforeWithChildren() |
| 1151 | && (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginBeforeQuirk()))) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1152 | // We're collapsing with a previous sibling's margins and not |
| 1153 | // with the top of the block. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1154 | setLogicalHeight(logicalHeight() + std::max(marginInfo.positiveMargin(), posTop) - std::max(marginInfo.negativeMargin(), negTop)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1155 | logicalTop = logicalHeight(); |
| 1156 | } |
| 1157 | |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1158 | marginInfo.setPositiveMargin(childMargins.positiveMarginAfter()); |
| 1159 | marginInfo.setNegativeMargin(childMargins.negativeMarginAfter()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1160 | |
| 1161 | if (marginInfo.margin()) |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1162 | marginInfo.setHasMarginAfterQuirk(afterQuirk); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1163 | } |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1164 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1165 | // If margins would pull us past the top of the next page, then we need to pull back and pretend like the margins |
| 1166 | // collapsed into the page edge. |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 1167 | auto* layoutState = view().frameView().layoutContext().layoutState(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1168 | if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTop > beforeCollapseLogicalTop |
| 1169 | && hasNextPage(beforeCollapseLogicalTop)) { |
| 1170 | LayoutUnit oldLogicalTop = logicalTop; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1171 | logicalTop = std::min(logicalTop, nextPageLogicalTop(beforeCollapseLogicalTop)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1172 | setLogicalHeight(logicalHeight() + (logicalTop - oldLogicalTop)); |
| 1173 | } |
| 1174 | |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1175 | if (is<RenderBlockFlow>(prevSibling) && !prevSibling->isFloatingOrOutOfFlowPositioned()) { |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1176 | // If |child| is a self-collapsing block it may have collapsed into a previous sibling and although it hasn't reduced the height of the parent yet |
| 1177 | // any floats from the parent will now overhang. |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1178 | RenderBlockFlow& block = downcast<RenderBlockFlow>(*prevSibling); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1179 | LayoutUnit oldLogicalHeight = logicalHeight(); |
| 1180 | setLogicalHeight(logicalTop); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1181 | if (block.containsFloats() && !block.avoidsFloats() && (block.logicalTop() + block.lowestFloatLogicalBottom()) > logicalTop) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1182 | addOverhangingFloats(block, false); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1183 | setLogicalHeight(oldLogicalHeight); |
| 1184 | |
| 1185 | // If |child|'s previous sibling is a self-collapsing block that cleared a float and margin collapsing resulted in |child| moving up |
| 1186 | // into the margin area of the self-collapsing block then the float it clears is now intruding into |child|. Layout again so that we can look for |
| 1187 | // floats in the parent that overhang |child|'s new logical top. |
| 1188 | bool logicalTopIntrudesIntoFloat = clearanceForSelfCollapsingBlock > 0 && logicalTop < beforeCollapseLogicalTop; |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1189 | if (child && logicalTopIntrudesIntoFloat && containsFloats() && !child->avoidsFloats() && lowestFloatLogicalBottom() > logicalTop) |
| 1190 | child->setNeedsLayout(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1191 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1192 | |
| 1193 | return logicalTop; |
| 1194 | } |
| 1195 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1196 | LayoutUnit RenderBlockFlow::clearFloatsIfNeeded(RenderBox& child, MarginInfo& marginInfo, LayoutUnit oldTopPosMargin, LayoutUnit oldTopNegMargin, LayoutUnit yPos) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1197 | { |
| 1198 | LayoutUnit heightIncrease = getClearDelta(child, yPos); |
| 1199 | if (!heightIncrease) |
| 1200 | return yPos; |
| 1201 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1202 | if (child.isSelfCollapsingBlock()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1203 | // For self-collapsing blocks that clear, they can still collapse their |
| 1204 | // margins with following siblings. Reset the current margins to represent |
| 1205 | // the self-collapsing block's margins only. |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1206 | MarginValues childMargins = marginValuesForChild(child); |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1207 | marginInfo.setPositiveMargin(std::max(childMargins.positiveMarginBefore(), childMargins.positiveMarginAfter())); |
| 1208 | marginInfo.setNegativeMargin(std::max(childMargins.negativeMarginBefore(), childMargins.negativeMarginAfter())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1209 | |
| 1210 | // CSS2.1 states: |
| 1211 | // "If the top and bottom margins of an element with clearance are adjoining, its margins collapse with |
| 1212 | // the adjoining margins of following siblings but that resulting margin does not collapse with the bottom margin of the parent block." |
| 1213 | // So the parent's bottom margin cannot collapse through this block or any subsequent self-collapsing blocks. Check subsequent siblings |
| 1214 | // for a block with height - if none is found then don't allow the margins to collapse with the parent. |
| 1215 | bool wouldCollapseMarginsWithParent = marginInfo.canCollapseMarginAfterWithChildren(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1216 | for (RenderBox* curr = child.nextSiblingBox(); curr && wouldCollapseMarginsWithParent; curr = curr->nextSiblingBox()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1217 | if (!curr->isFloatingOrOutOfFlowPositioned() && !curr->isSelfCollapsingBlock()) |
| 1218 | wouldCollapseMarginsWithParent = false; |
| 1219 | } |
| 1220 | if (wouldCollapseMarginsWithParent) |
| 1221 | marginInfo.setCanCollapseMarginAfterWithChildren(false); |
| 1222 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1223 | // For now set the border-top of |child| flush with the bottom border-edge of the float so it can layout any floating or positioned children of |
| 1224 | // its own at the correct vertical position. If subsequent siblings attempt to collapse with |child|'s margins in |collapseMargins| we will |
| 1225 | // adjust the height of the parent to |child|'s margin top (which if it is positive sits up 'inside' the float it's clearing) so that all three |
| 1226 | // margins can collapse at the correct vertical position. |
| 1227 | // Per CSS2.1 we need to ensure that any negative margin-top clears |child| beyond the bottom border-edge of the float so that the top border edge of the child |
| 1228 | // (i.e. its clearance) is at a position that satisfies the equation: "the amount of clearance is set so that clearance + margin-top = [height of float], |
| 1229 | // i.e., clearance = [height of float] - margin-top". |
| 1230 | setLogicalHeight(child.logicalTop() + childMargins.negativeMarginBefore()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1231 | } else |
| 1232 | // Increase our height by the amount we had to clear. |
| 1233 | setLogicalHeight(logicalHeight() + heightIncrease); |
| 1234 | |
| 1235 | if (marginInfo.canCollapseWithMarginBefore()) { |
| 1236 | // We can no longer collapse with the top of the block since a clear |
| 1237 | // occurred. The empty blocks collapse into the cleared block. |
| 1238 | // FIXME: This isn't quite correct. Need clarification for what to do |
| 1239 | // if the height the cleared block is offset by is smaller than the |
| 1240 | // margins involved. |
| 1241 | setMaxMarginBeforeValues(oldTopPosMargin, oldTopNegMargin); |
| 1242 | marginInfo.setAtBeforeSideOfBlock(false); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1245 | return yPos + heightIncrease; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1248 | void RenderBlockFlow::marginBeforeEstimateForChild(RenderBox& child, LayoutUnit& positiveMarginBefore, LayoutUnit& negativeMarginBefore) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1249 | { |
| 1250 | // Give up if in quirks mode and we're a body/table cell and the top margin of the child box is quirky. |
| 1251 | // Give up if the child specified -webkit-margin-collapse: separate that prevents collapsing. |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1252 | if (document().inQuirksMode() && hasMarginAfterQuirk(child) && (isTableCell() || isBody())) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1253 | return; |
| 1254 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1255 | LayoutUnit beforeChildMargin = marginBeforeForChild(child); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1256 | positiveMarginBefore = std::max(positiveMarginBefore, beforeChildMargin); |
| 1257 | negativeMarginBefore = std::max(negativeMarginBefore, -beforeChildMargin); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1258 | |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1259 | if (!is<RenderBlockFlow>(child)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1260 | return; |
| 1261 | |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1262 | RenderBlockFlow& childBlock = downcast<RenderBlockFlow>(child); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1263 | if (childBlock.childrenInline() || childBlock.isWritingModeRoot()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1264 | return; |
| 1265 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1266 | MarginInfo childMarginInfo(childBlock, childBlock.borderAndPaddingBefore(), childBlock.borderAndPaddingAfter()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1267 | if (!childMarginInfo.canCollapseMarginBeforeWithChildren()) |
| 1268 | return; |
| 1269 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1270 | RenderBox* grandchildBox = childBlock.firstChildBox(); |
| 1271 | for (; grandchildBox; grandchildBox = grandchildBox->nextSiblingBox()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1272 | if (!grandchildBox->isFloatingOrOutOfFlowPositioned()) |
| 1273 | break; |
| 1274 | } |
| 1275 | |
| 1276 | // Give up if there is clearance on the box, since it probably won't collapse into us. |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 1277 | if (!grandchildBox || RenderStyle::usedClear(*grandchildBox) != UsedClear::None) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1278 | return; |
| 1279 | |
| 1280 | // Make sure to update the block margins now for the grandchild box so that we're looking at current values. |
| 1281 | if (grandchildBox->needsLayout()) { |
mmaxfield@apple.com | 09804f4 | 2016-03-23 00:58:34 +0000 | [diff] [blame] | 1282 | grandchildBox->computeAndSetBlockDirectionMargins(*this); |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 1283 | if (is<RenderBlock>(*grandchildBox)) { |
| 1284 | RenderBlock& grandchildBlock = downcast<RenderBlock>(*grandchildBox); |
| 1285 | grandchildBlock.setHasMarginBeforeQuirk(grandchildBox->style().hasMarginBeforeQuirk()); |
| 1286 | grandchildBlock.setHasMarginAfterQuirk(grandchildBox->style().hasMarginAfterQuirk()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | // Collapse the margin of the grandchild box with our own to produce an estimate. |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1291 | childBlock.marginBeforeEstimateForChild(*grandchildBox, positiveMarginBefore, negativeMarginBefore); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1294 | LayoutUnit RenderBlockFlow::estimateLogicalTopPosition(RenderBox& child, const MarginInfo& marginInfo, LayoutUnit& estimateWithoutPagination) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1295 | { |
| 1296 | // FIXME: We need to eliminate the estimation of vertical position, because when it's wrong we sometimes trigger a pathological |
| 1297 | // relayout if there are intruding floats. |
| 1298 | LayoutUnit logicalTopEstimate = logicalHeight(); |
| 1299 | if (!marginInfo.canCollapseWithMarginBefore()) { |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 1300 | LayoutUnit positiveMarginBefore; |
| 1301 | LayoutUnit negativeMarginBefore; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1302 | if (child.selfNeedsLayout()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1303 | // Try to do a basic estimation of how the collapse is going to go. |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1304 | marginBeforeEstimateForChild(child, positiveMarginBefore, negativeMarginBefore); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1305 | } else { |
| 1306 | // Use the cached collapsed margin values from a previous layout. Most of the time they |
| 1307 | // will be right. |
| 1308 | MarginValues marginValues = marginValuesForChild(child); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1309 | positiveMarginBefore = std::max(positiveMarginBefore, marginValues.positiveMarginBefore()); |
| 1310 | negativeMarginBefore = std::max(negativeMarginBefore, marginValues.negativeMarginBefore()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | // Collapse the result with our current margins. |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1314 | logicalTopEstimate += std::max(marginInfo.positiveMargin(), positiveMarginBefore) - std::max(marginInfo.negativeMargin(), negativeMarginBefore); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | // Adjust logicalTopEstimate down to the next page if the margins are so large that we don't fit on the current |
| 1318 | // page. |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 1319 | auto* layoutState = view().frameView().layoutContext().layoutState(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1320 | if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTopEstimate > logicalHeight() |
| 1321 | && hasNextPage(logicalHeight())) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1322 | logicalTopEstimate = std::min(logicalTopEstimate, nextPageLogicalTop(logicalHeight())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1323 | |
| 1324 | logicalTopEstimate += getClearDelta(child, logicalTopEstimate); |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1325 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1326 | estimateWithoutPagination = logicalTopEstimate; |
| 1327 | |
| 1328 | if (layoutState->isPaginated()) { |
| 1329 | // If the object has a page or column break value of "before", then we should shift to the top of the next page. |
| 1330 | logicalTopEstimate = applyBeforeBreak(child, logicalTopEstimate); |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1331 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1332 | // For replaced elements and scrolled elements, we want to shift them to the next page if they don't fit on the current one. |
| 1333 | logicalTopEstimate = adjustForUnsplittableChild(child, logicalTopEstimate); |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1334 | |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 1335 | if (!child.selfNeedsLayout() && is<RenderBlock>(child)) |
| 1336 | logicalTopEstimate += downcast<RenderBlock>(child).paginationStrut(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | return logicalTopEstimate; |
| 1340 | } |
| 1341 | |
| 1342 | void RenderBlockFlow::setCollapsedBottomMargin(const MarginInfo& marginInfo) |
| 1343 | { |
| 1344 | if (marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1345 | // Update our max pos/neg bottom margins, since we collapsed our bottom margins |
| 1346 | // with our children. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1347 | setMaxMarginAfterValues(std::max(maxPositiveMarginAfter(), marginInfo.positiveMargin()), std::max(maxNegativeMarginAfter(), marginInfo.negativeMargin())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1348 | |
| 1349 | if (!marginInfo.hasMarginAfterQuirk()) |
| 1350 | setHasMarginAfterQuirk(false); |
| 1351 | |
| 1352 | if (marginInfo.hasMarginAfterQuirk() && !marginAfter()) |
| 1353 | // We have no bottom margin and our last child has a quirky margin. |
| 1354 | // We will pick up this quirky margin and pass it through. |
| 1355 | // This deals with the <td><div><p> case. |
| 1356 | setHasMarginAfterQuirk(true); |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | void RenderBlockFlow::handleAfterSideOfBlock(LayoutUnit beforeSide, LayoutUnit afterSide, MarginInfo& marginInfo) |
| 1361 | { |
| 1362 | marginInfo.setAtAfterSideOfBlock(true); |
| 1363 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1364 | // If our last child was a self-collapsing block with clearance then our logical height is flush with the |
| 1365 | // bottom edge of the float that the child clears. The correct vertical position for the margin-collapsing we want |
| 1366 | // to perform now is at the child's margin-top - so adjust our height to that position. |
| 1367 | RenderObject* lastBlock = lastChild(); |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1368 | if (is<RenderBlockFlow>(lastBlock) && downcast<RenderBlockFlow>(*lastBlock).isSelfCollapsingBlock()) |
| 1369 | setLogicalHeight(logicalHeight() - downcast<RenderBlockFlow>(*lastBlock).marginOffsetForSelfCollapsingBlock()); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1370 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 1371 | // If we can't collapse with children then add in the bottom margin. |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1372 | if (!marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore() |
| 1373 | && (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginAfterQuirk())) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1374 | setLogicalHeight(logicalHeight() + marginInfo.margin()); |
ntim@apple.com | acb16d4 | 2021-12-24 18:55:35 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1377 | // Now add in our bottom border/padding. |
| 1378 | setLogicalHeight(logicalHeight() + afterSide); |
| 1379 | |
| 1380 | // Negative margins can cause our height to shrink below our minimal height (border/padding). |
| 1381 | // If this happens, ensure that the computed height is increased to the minimal height. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1382 | setLogicalHeight(std::max(logicalHeight(), beforeSide + afterSide)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1383 | |
| 1384 | // Update our bottom collapsed margin info. |
| 1385 | setCollapsedBottomMargin(marginInfo); |
| 1386 | } |
| 1387 | |
| 1388 | void RenderBlockFlow::setMaxMarginBeforeValues(LayoutUnit pos, LayoutUnit neg) |
| 1389 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1390 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1391 | if (pos == RenderBlockFlowRareData::positiveMarginBeforeDefault(*this) && neg == RenderBlockFlowRareData::negativeMarginBeforeDefault(*this)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1392 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1393 | materializeRareBlockFlowData(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1394 | } |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1395 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1396 | rareBlockFlowData()->m_margins.setPositiveMarginBefore(pos); |
| 1397 | rareBlockFlowData()->m_margins.setNegativeMarginBefore(neg); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | void RenderBlockFlow::setMaxMarginAfterValues(LayoutUnit pos, LayoutUnit neg) |
| 1401 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1402 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1403 | if (pos == RenderBlockFlowRareData::positiveMarginAfterDefault(*this) && neg == RenderBlockFlowRareData::negativeMarginAfterDefault(*this)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1404 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1405 | materializeRareBlockFlowData(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1406 | } |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1407 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1408 | rareBlockFlowData()->m_margins.setPositiveMarginAfter(pos); |
| 1409 | rareBlockFlowData()->m_margins.setNegativeMarginAfter(neg); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1412 | static bool inNormalFlow(RenderBox& child) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1413 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1414 | RenderBlock* curr = child.containingBlock(); |
| 1415 | while (curr && curr != &child.view()) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1416 | if (curr->isRenderFragmentedFlow()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1417 | return true; |
| 1418 | if (curr->isFloatingOrOutOfFlowPositioned()) |
| 1419 | return false; |
| 1420 | curr = curr->containingBlock(); |
| 1421 | } |
| 1422 | return true; |
| 1423 | } |
| 1424 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1425 | LayoutUnit RenderBlockFlow::applyBeforeBreak(RenderBox& child, LayoutUnit logicalOffset) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1426 | { |
| 1427 | // FIXME: Add page break checking here when we support printing. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1428 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1429 | bool isInsideMulticolFlow = fragmentedFlow; |
| 1430 | bool checkColumnBreaks = fragmentedFlow && fragmentedFlow->shouldCheckColumnBreaks(); |
zalan@apple.com | 7fd79ce | 2017-11-08 15:02:10 +0000 | [diff] [blame] | 1431 | bool checkPageBreaks = !checkColumnBreaks && view().frameView().layoutContext().layoutState()->pageLogicalHeight(); // FIXME: Once columns can print we have to check this. |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1432 | bool checkFragmentBreaks = false; |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 1433 | bool checkBeforeAlways = (checkColumnBreaks && child.style().breakBefore() == BreakBetween::Column) |
antti@apple.com | 52d8383 | 2017-09-20 12:58:45 +0000 | [diff] [blame] | 1434 | || (checkPageBreaks && alwaysPageBreak(child.style().breakBefore())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1435 | if (checkBeforeAlways && inNormalFlow(child) && hasNextPage(logicalOffset, IncludePageBoundary)) { |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1436 | if (checkColumnBreaks) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1437 | if (isInsideMulticolFlow) |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1438 | checkFragmentBreaks = true; |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1439 | } |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1440 | if (checkFragmentBreaks) { |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 1441 | LayoutUnit offsetBreakAdjustment; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1442 | if (fragmentedFlow->addForcedFragmentBreak(this, offsetFromLogicalTopOfFirstPage() + logicalOffset, &child, true, &offsetBreakAdjustment)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1443 | return logicalOffset + offsetBreakAdjustment; |
| 1444 | } |
| 1445 | return nextPageLogicalTop(logicalOffset, IncludePageBoundary); |
| 1446 | } |
| 1447 | return logicalOffset; |
| 1448 | } |
| 1449 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1450 | LayoutUnit RenderBlockFlow::applyAfterBreak(RenderBox& child, LayoutUnit logicalOffset, MarginInfo& marginInfo) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1451 | { |
| 1452 | // FIXME: Add page break checking here when we support printing. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1453 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1454 | bool isInsideMulticolFlow = fragmentedFlow; |
| 1455 | bool checkColumnBreaks = fragmentedFlow && fragmentedFlow->shouldCheckColumnBreaks(); |
zalan@apple.com | 7fd79ce | 2017-11-08 15:02:10 +0000 | [diff] [blame] | 1456 | bool checkPageBreaks = !checkColumnBreaks && view().frameView().layoutContext().layoutState()->pageLogicalHeight(); // FIXME: Once columns can print we have to check this. |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1457 | bool checkFragmentBreaks = false; |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 1458 | bool checkAfterAlways = (checkColumnBreaks && child.style().breakAfter() == BreakBetween::Column) |
antti@apple.com | 52d8383 | 2017-09-20 12:58:45 +0000 | [diff] [blame] | 1459 | || (checkPageBreaks && alwaysPageBreak(child.style().breakAfter())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1460 | if (checkAfterAlways && inNormalFlow(child) && hasNextPage(logicalOffset, IncludePageBoundary)) { |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 1461 | LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? 0_lu : marginInfo.margin(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1462 | |
| 1463 | // So our margin doesn't participate in the next collapsing steps. |
| 1464 | marginInfo.clearMargin(); |
| 1465 | |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1466 | if (checkColumnBreaks) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1467 | if (isInsideMulticolFlow) |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1468 | checkFragmentBreaks = true; |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1469 | } |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1470 | if (checkFragmentBreaks) { |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 1471 | LayoutUnit offsetBreakAdjustment; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1472 | if (fragmentedFlow->addForcedFragmentBreak(this, offsetFromLogicalTopOfFirstPage() + logicalOffset + marginOffset, &child, false, &offsetBreakAdjustment)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1473 | return logicalOffset + marginOffset + offsetBreakAdjustment; |
| 1474 | } |
| 1475 | return nextPageLogicalTop(logicalOffset, IncludePageBoundary); |
| 1476 | } |
| 1477 | return logicalOffset; |
| 1478 | } |
| 1479 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1480 | LayoutUnit RenderBlockFlow::adjustBlockChildForPagination(LayoutUnit logicalTopAfterClear, LayoutUnit estimateWithoutPagination, RenderBox& child, bool atBeforeSideOfBlock) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1481 | { |
cdumez@apple.com | 5f02e63 | 2022-01-16 01:33:25 +0000 | [diff] [blame] | 1482 | auto* childRenderBlock = dynamicDowncast<RenderBlock>(child); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1483 | |
| 1484 | if (estimateWithoutPagination != logicalTopAfterClear) { |
| 1485 | // Our guess prior to pagination movement was wrong. Before we attempt to paginate, let's try again at the new |
| 1486 | // position. |
| 1487 | setLogicalHeight(logicalTopAfterClear); |
| 1488 | setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta); |
| 1489 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1490 | if (child.shrinkToAvoidFloats()) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 1491 | // The child's width depends on the line width. When the child shifts to clear an item, its width can |
| 1492 | // change (because it has more available line width). So mark the item as dirty. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1493 | child.setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | if (childRenderBlock) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1497 | if (!child.avoidsFloats() && childRenderBlock->containsFloats()) |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1498 | downcast<RenderBlockFlow>(*childRenderBlock).markAllDescendantsWithFloatsForLayout(); |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 1499 | child.markForPaginationRelayoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | // Our guess was wrong. Make the child lay itself out again. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1503 | child.layoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | LayoutUnit oldTop = logicalTopAfterClear; |
| 1507 | |
| 1508 | // If the object has a page or column break value of "before", then we should shift to the top of the next page. |
| 1509 | LayoutUnit result = applyBeforeBreak(child, logicalTopAfterClear); |
| 1510 | |
| 1511 | if (pageLogicalHeightForOffset(result)) { |
| 1512 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(result, ExcludePageBoundary); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1513 | LayoutUnit spaceShortage = child.logicalHeight() - remainingLogicalHeight; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1514 | if (spaceShortage > 0) { |
| 1515 | // If the child crosses a column boundary, report a break, in case nothing inside it has already |
| 1516 | // done so. The column balancer needs to know how much it has to stretch the columns to make more |
| 1517 | // content fit. If no breaks are reported (but do occur), the balancer will have no clue. FIXME: |
| 1518 | // This should be improved, though, because here we just pretend that the child is |
| 1519 | // unsplittable. A splittable child, on the other hand, has break opportunities at every position |
| 1520 | // where there's no child content, border or padding. In other words, we risk stretching more |
| 1521 | // than necessary. |
| 1522 | setPageBreak(result, spaceShortage); |
| 1523 | } |
| 1524 | } |
| 1525 | |
simon.fraser@apple.com | e8ee49b | 2022-05-06 17:10:31 +0000 | [diff] [blame] | 1526 | if (child.shouldApplySizeContainment()) |
cathiechen@igalia.com | e80ce68 | 2021-05-11 12:49:46 +0000 | [diff] [blame] | 1527 | adjustSizeContainmentChildForPagination(child, result); |
| 1528 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1529 | // For replaced elements and scrolled elements, we want to shift them to the next page if they don't fit on the current one. |
| 1530 | LayoutUnit logicalTopBeforeUnsplittableAdjustment = result; |
| 1531 | LayoutUnit logicalTopAfterUnsplittableAdjustment = adjustForUnsplittableChild(child, result); |
| 1532 | |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 1533 | LayoutUnit paginationStrut; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1534 | LayoutUnit unsplittableAdjustmentDelta = logicalTopAfterUnsplittableAdjustment - logicalTopBeforeUnsplittableAdjustment; |
| 1535 | if (unsplittableAdjustmentDelta) |
| 1536 | paginationStrut = unsplittableAdjustmentDelta; |
| 1537 | else if (childRenderBlock && childRenderBlock->paginationStrut()) |
| 1538 | paginationStrut = childRenderBlock->paginationStrut(); |
| 1539 | |
| 1540 | if (paginationStrut) { |
| 1541 | // We are willing to propagate out to our parent block as long as we were at the top of the block prior |
| 1542 | // to collapsing our margins, and as long as we didn't clear or move as a result of other pagination. |
| 1543 | if (atBeforeSideOfBlock && oldTop == result && !isOutOfFlowPositioned() && !isTableCell()) { |
| 1544 | // FIXME: Should really check if we're exceeding the page height before propagating the strut, but we don't |
| 1545 | // have all the information to do so (the strut only has the remaining amount to push). Gecko gets this wrong too |
| 1546 | // and pushes to the next page anyway, so not too concerned about it. |
| 1547 | setPaginationStrut(result + paginationStrut); |
| 1548 | if (childRenderBlock) |
| 1549 | childRenderBlock->setPaginationStrut(0); |
| 1550 | } else |
| 1551 | result += paginationStrut; |
| 1552 | } |
| 1553 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 1554 | // Similar to how we apply clearance. Boost height() to be the place where we're going to position the child. |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1555 | setLogicalHeight(logicalHeight() + (result - oldTop)); |
| 1556 | |
| 1557 | // Return the final adjusted logical top. |
| 1558 | return result; |
| 1559 | } |
| 1560 | |
antti@apple.com | 903292a | 2021-06-02 16:20:15 +0000 | [diff] [blame] | 1561 | static inline LayoutUnit calculateMinimumPageHeight(const RenderStyle& renderStyle, LegacyRootInlineBox& lastLine, LayoutUnit lineTop, LayoutUnit lineBottom) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1562 | { |
| 1563 | // We may require a certain minimum number of lines per page in order to satisfy |
| 1564 | // orphans and widows, and that may affect the minimum page height. |
mmaxfield@apple.com | f8e26e7 | 2014-10-30 21:39:27 +0000 | [diff] [blame] | 1565 | unsigned lineCount = std::max<unsigned>(renderStyle.hasAutoOrphans() ? 1 : renderStyle.orphans(), renderStyle.hasAutoWidows() ? 1 : renderStyle.widows()); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1566 | if (lineCount > 1) { |
antti@apple.com | 903292a | 2021-06-02 16:20:15 +0000 | [diff] [blame] | 1567 | LegacyRootInlineBox* line = &lastLine; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1568 | for (unsigned i = 1; i < lineCount && line->prevRootBox(); i++) |
| 1569 | line = line->prevRootBox(); |
| 1570 | |
| 1571 | // FIXME: Paginating using line overflow isn't all fine. See FIXME in |
| 1572 | // adjustLinePositionForPagination() for more details. |
| 1573 | LayoutRect overflow = line->logicalVisualOverflowRect(line->lineTop(), line->lineBottom()); |
antti@apple.com | 657a14e | 2020-10-29 15:51:07 +0000 | [diff] [blame] | 1574 | lineTop = std::min(line->lineBoxTop(), overflow.y()); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1575 | } |
| 1576 | return lineBottom - lineTop; |
| 1577 | } |
| 1578 | |
antti@apple.com | 903292a | 2021-06-02 16:20:15 +0000 | [diff] [blame] | 1579 | static inline bool needsAppleMailPaginationQuirk(LegacyRootInlineBox& lineBox) |
bfulgham@apple.com | b595343 | 2015-02-13 21:56:01 +0000 | [diff] [blame] | 1580 | { |
zalan@apple.com | a1cff3a | 2017-01-14 18:45:20 +0000 | [diff] [blame] | 1581 | auto& renderer = lineBox.renderer(); |
bfulgham@apple.com | 6272977 | 2015-04-29 02:26:07 +0000 | [diff] [blame] | 1582 | |
zalan@apple.com | a1cff3a | 2017-01-14 18:45:20 +0000 | [diff] [blame] | 1583 | if (!renderer.settings().appleMailPaginationQuirkEnabled()) |
bfulgham@apple.com | 6272977 | 2015-04-29 02:26:07 +0000 | [diff] [blame] | 1584 | return false; |
| 1585 | |
cdumez@apple.com | 19105c1 | 2022-06-05 06:59:51 +0000 | [diff] [blame] | 1586 | if (renderer.element() && renderer.element()->idForStyleResolution() == "messageContentContainer"_s) |
bfulgham@apple.com | b595343 | 2015-02-13 21:56:01 +0000 | [diff] [blame] | 1587 | return true; |
| 1588 | |
| 1589 | return false; |
| 1590 | } |
zalan@apple.com | e031dfb | 2016-08-25 18:41:22 +0000 | [diff] [blame] | 1591 | |
| 1592 | static void clearShouldBreakAtLineToAvoidWidowIfNeeded(RenderBlockFlow& blockFlow) |
| 1593 | { |
| 1594 | if (!blockFlow.shouldBreakAtLineToAvoidWidow()) |
| 1595 | return; |
| 1596 | blockFlow.clearShouldBreakAtLineToAvoidWidow(); |
| 1597 | blockFlow.setDidBreakAtLineToAvoidWidow(); |
| 1598 | } |
| 1599 | |
antti@apple.com | 903292a | 2021-06-02 16:20:15 +0000 | [diff] [blame] | 1600 | void RenderBlockFlow::adjustLinePositionForPagination(LegacyRootInlineBox* lineBox, LayoutUnit& delta, bool& overflowsFragment, RenderFragmentedFlow* fragmentedFlow) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1601 | { |
| 1602 | // FIXME: For now we paginate using line overflow. This ensures that lines don't overlap at all when we |
| 1603 | // put a strut between them for pagination purposes. However, this really isn't the desired rendering, since |
| 1604 | // the line on the top of the next page will appear too far down relative to the same kind of line at the top |
| 1605 | // of the first column. |
| 1606 | // |
| 1607 | // The rendering we would like to see is one where the lineTopWithLeading is at the top of the column, and any line overflow |
| 1608 | // simply spills out above the top of the column. This effect would match what happens at the top of the first column. |
| 1609 | // We can't achieve this rendering, however, until we stop columns from clipping to the column bounds (thus allowing |
| 1610 | // for overflow to occur), and then cache visible overflow for each column rect. |
| 1611 | // |
| 1612 | // Furthermore, the paint we have to do when a column has overflow has to be special. We need to exclude |
| 1613 | // content that paints in a previous column (and content that paints in the following column). |
| 1614 | // |
| 1615 | // For now we'll at least honor the lineTopWithLeading when paginating if it is above the logical top overflow. This will |
| 1616 | // at least make positive leading work in typical cases. |
| 1617 | // |
| 1618 | // FIXME: Another problem with simply moving lines is that the available line width may change (because of floats). |
| 1619 | // Technically if the location we move the line to has a different line width than our old position, then we need to dirty the |
| 1620 | // line and all following lines. |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1621 | overflowsFragment = false; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1622 | LayoutRect logicalVisualOverflow = lineBox->logicalVisualOverflowRect(lineBox->lineTop(), lineBox->lineBottom()); |
antti@apple.com | 657a14e | 2020-10-29 15:51:07 +0000 | [diff] [blame] | 1623 | LayoutUnit logicalOffset = std::min(lineBox->lineBoxTop(), logicalVisualOverflow.y()); |
| 1624 | LayoutUnit logicalBottom = std::max(lineBox->lineBoxBottom(), logicalVisualOverflow.maxY()); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1625 | LayoutUnit lineHeight = logicalBottom - logicalOffset; |
mmaxfield@apple.com | f8e26e7 | 2014-10-30 21:39:27 +0000 | [diff] [blame] | 1626 | updateMinimumPageHeight(logicalOffset, calculateMinimumPageHeight(style(), *lineBox, logicalOffset, logicalBottom)); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1627 | logicalOffset += delta; |
| 1628 | lineBox->setPaginationStrut(0); |
| 1629 | lineBox->setIsFirstAfterPageBreak(false); |
| 1630 | LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1631 | bool hasUniformPageLogicalHeight = !fragmentedFlow || fragmentedFlow->fragmentsHaveUniformLogicalHeight(); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1632 | // If lineHeight is greater than pageLogicalHeight, but logicalVisualOverflow.height() still fits, we are |
| 1633 | // still going to add a strut, so that the visible overflow fits on a single page. |
hyatt@apple.com | cb5ab70 | 2014-11-19 23:40:23 +0000 | [diff] [blame] | 1634 | if (!pageLogicalHeight || !hasNextPage(logicalOffset)) { |
abucur@adobe.com | d40287b | 2013-10-08 17:33:05 +0000 | [diff] [blame] | 1635 | // FIXME: In case the line aligns with the top of the page (or it's slightly shifted downwards) it will not be marked as the first line in the page. |
| 1636 | // From here, the fix is not straightforward because it's not easy to always determine when the current line is the first in the page. |
zalan@apple.com | 3b1271d | 2020-03-25 01:46:09 +0000 | [diff] [blame] | 1637 | // With no valid page height, we can't possibly accommodate the widow rules. |
| 1638 | clearShouldBreakAtLineToAvoidWidowIfNeeded(*this); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1639 | return; |
hyatt@apple.com | cb5ab70 | 2014-11-19 23:40:23 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | if (hasUniformPageLogicalHeight && logicalVisualOverflow.height() > pageLogicalHeight) { |
| 1643 | // We are so tall that we are bigger than a page. Before we give up and just leave the line where it is, try drilling into the |
| 1644 | // line and computing a new height that excludes anything we consider "blank space". We will discard margins, descent, and even overflow. If we are |
| 1645 | // able to fit with the blank space and overflow excluded, we will give the line its own page with the highest non-blank element being aligned with the |
| 1646 | // top of the page. |
| 1647 | // FIXME: We are still honoring gigantic margins, which does leave open the possibility of blank pages caused by this heuristic. It remains to be seen whether or not |
| 1648 | // this will be a real-world issue. For now we don't try to deal with this problem. |
basuke.suzuki@sony.com | 5ecd975 | 2021-04-21 01:42:52 +0000 | [diff] [blame] | 1649 | logicalOffset = static_cast<float>(intMaxForLayoutUnit); |
| 1650 | logicalBottom = static_cast<float>(intMinForLayoutUnit); |
hyatt@apple.com | cb5ab70 | 2014-11-19 23:40:23 +0000 | [diff] [blame] | 1651 | lineBox->computeReplacedAndTextLineTopAndBottom(logicalOffset, logicalBottom); |
| 1652 | lineHeight = logicalBottom - logicalOffset; |
zalan@apple.com | e031dfb | 2016-08-25 18:41:22 +0000 | [diff] [blame] | 1653 | if (logicalOffset == intMaxForLayoutUnit || lineHeight > pageLogicalHeight) { |
| 1654 | // Give up. We're genuinely too big even after excluding blank space and overflow. |
| 1655 | clearShouldBreakAtLineToAvoidWidowIfNeeded(*this); |
| 1656 | return; |
| 1657 | } |
hyatt@apple.com | cb5ab70 | 2014-11-19 23:40:23 +0000 | [diff] [blame] | 1658 | pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
| 1659 | } |
| 1660 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1661 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalOffset, ExcludePageBoundary); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1662 | overflowsFragment = (lineHeight > remainingLogicalHeight); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1663 | |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 1664 | int lineIndex = legacyLineLayout()->lineCountUntil(lineBox); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1665 | if (remainingLogicalHeight < lineHeight || (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIndex)) { |
zalan@apple.com | e031dfb | 2016-08-25 18:41:22 +0000 | [diff] [blame] | 1666 | if (lineBreakToAvoidWidow() == lineIndex) |
| 1667 | clearShouldBreakAtLineToAvoidWidowIfNeeded(*this); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1668 | // If we have a non-uniform page height, then we have to shift further possibly. |
| 1669 | if (!hasUniformPageLogicalHeight && !pushToNextPageWithMinimumLogicalHeight(remainingLogicalHeight, logicalOffset, lineHeight)) |
| 1670 | return; |
| 1671 | if (lineHeight > pageLogicalHeight) { |
| 1672 | // Split the top margin in order to avoid splitting the visible part of the line. |
antti@apple.com | 657a14e | 2020-10-29 15:51:07 +0000 | [diff] [blame] | 1673 | remainingLogicalHeight -= std::min(lineHeight - pageLogicalHeight, std::max<LayoutUnit>(0, logicalVisualOverflow.y() - lineBox->lineBoxTop())); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1674 | } |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1675 | LayoutUnit remainingLogicalHeightAtNewOffset = pageRemainingLogicalHeightForOffset(logicalOffset + remainingLogicalHeight, ExcludePageBoundary); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1676 | overflowsFragment = (lineHeight > remainingLogicalHeightAtNewOffset); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1677 | LayoutUnit totalLogicalHeight = lineHeight + std::max<LayoutUnit>(0, logicalOffset); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1678 | LayoutUnit pageLogicalHeightAtNewOffset = hasUniformPageLogicalHeight ? pageLogicalHeight : pageLogicalHeightForOffset(logicalOffset + remainingLogicalHeight); |
| 1679 | setPageBreak(logicalOffset, lineHeight - remainingLogicalHeight); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1680 | if (((lineBox == firstRootBox() && totalLogicalHeight < pageLogicalHeightAtNewOffset) || (!style().hasAutoOrphans() && style().orphans() >= lineIndex)) |
mmaxfield@apple.com | 4d7e9a2 | 2014-11-18 22:40:29 +0000 | [diff] [blame] | 1681 | && !isOutOfFlowPositioned() && !isTableCell()) { |
| 1682 | auto firstRootBox = this->firstRootBox(); |
commit-queue@webkit.org | e2d17aa | 2020-01-30 18:07:10 +0000 | [diff] [blame] | 1683 | if (!firstRootBox) { |
| 1684 | setPaginationStrut(remainingLogicalHeight + logicalOffset); |
| 1685 | return; |
| 1686 | } |
mmaxfield@apple.com | 4d7e9a2 | 2014-11-18 22:40:29 +0000 | [diff] [blame] | 1687 | auto firstRootBoxOverflowRect = firstRootBox->logicalVisualOverflowRect(firstRootBox->lineTop(), firstRootBox->lineBottom()); |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 1688 | auto firstLineUpperOverhang = std::max(-firstRootBoxOverflowRect.y(), 0_lu); |
bfulgham@apple.com | b595343 | 2015-02-13 21:56:01 +0000 | [diff] [blame] | 1689 | if (needsAppleMailPaginationQuirk(*lineBox)) |
| 1690 | return; |
mmaxfield@apple.com | 4d7e9a2 | 2014-11-18 22:40:29 +0000 | [diff] [blame] | 1691 | setPaginationStrut(remainingLogicalHeight + logicalOffset + firstLineUpperOverhang); |
| 1692 | } else { |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1693 | delta += remainingLogicalHeight; |
| 1694 | lineBox->setPaginationStrut(remainingLogicalHeight); |
| 1695 | lineBox->setIsFirstAfterPageBreak(true); |
| 1696 | } |
commit-queue@webkit.org | 883b01c | 2014-01-20 08:58:36 +0000 | [diff] [blame] | 1697 | } else if (remainingLogicalHeight == pageLogicalHeight) { |
| 1698 | // We're at the very top of a page or column. |
| 1699 | if (lineBox != firstRootBox()) |
| 1700 | lineBox->setIsFirstAfterPageBreak(true); |
| 1701 | if (lineBox != firstRootBox() || offsetFromLogicalTopOfFirstPage()) |
| 1702 | setPageBreak(logicalOffset, lineHeight); |
| 1703 | } |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | void RenderBlockFlow::setBreakAtLineToAvoidWidow(int lineToBreak) |
| 1707 | { |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1708 | ASSERT(lineToBreak >= 0); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1709 | ASSERT(!ensureRareBlockFlowData().m_didBreakAtLineToAvoidWidow); |
| 1710 | ensureRareBlockFlowData().m_lineBreakToAvoidWidow = lineToBreak; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1713 | void RenderBlockFlow::setDidBreakAtLineToAvoidWidow() |
| 1714 | { |
| 1715 | ASSERT(!shouldBreakAtLineToAvoidWidow()); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1716 | if (!hasRareBlockFlowData()) |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1717 | return; |
| 1718 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1719 | rareBlockFlowData()->m_didBreakAtLineToAvoidWidow = true; |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | void RenderBlockFlow::clearDidBreakAtLineToAvoidWidow() |
| 1723 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1724 | if (!hasRareBlockFlowData()) |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1725 | return; |
| 1726 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1727 | rareBlockFlowData()->m_didBreakAtLineToAvoidWidow = false; |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1728 | } |
| 1729 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1730 | void RenderBlockFlow::clearShouldBreakAtLineToAvoidWidow() const |
| 1731 | { |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1732 | ASSERT(shouldBreakAtLineToAvoidWidow()); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1733 | if (!hasRareBlockFlowData()) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1734 | return; |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1735 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1736 | rareBlockFlowData()->m_lineBreakToAvoidWidow = -1; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1739 | bool RenderBlockFlow::hasNextPage(LayoutUnit logicalOffset, PageBoundaryRule pageBoundaryRule) const |
| 1740 | { |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 1741 | ASSERT(view().frameView().layoutContext().layoutState() && view().frameView().layoutContext().layoutState()->isPaginated()); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1742 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1743 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1744 | if (!fragmentedFlow) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1745 | return true; // Printing and multi-column both make new pages to accommodate content. |
| 1746 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1747 | // See if we're in the last fragment. |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1748 | LayoutUnit pageOffset = offsetFromLogicalTopOfFirstPage() + logicalOffset; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1749 | RenderFragmentContainer* fragment = fragmentedFlow->fragmentAtBlockOffset(this, pageOffset, true); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1750 | if (!fragment) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1751 | return false; |
mihnea@adobe.com | c191b0a | 2014-03-19 12:38:51 +0000 | [diff] [blame] | 1752 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1753 | if (fragment->isLastFragment()) |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1754 | return fragment->isRenderFragmentContainerSet() || (pageBoundaryRule == IncludePageBoundary && pageOffset == fragment->logicalTopForFragmentedFlowContent()); |
stavila@adobe.com | 6cb976d | 2013-11-21 06:57:19 +0000 | [diff] [blame] | 1755 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1756 | RenderFragmentContainer* startFragment = nullptr; |
| 1757 | RenderFragmentContainer* endFragment = nullptr; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1758 | fragmentedFlow->getFragmentRangeForBox(this, startFragment, endFragment); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1759 | return (endFragment && fragment != endFragment); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 1762 | LayoutUnit RenderBlockFlow::adjustForUnsplittableChild(RenderBox& child, LayoutUnit logicalOffset, LayoutUnit childBeforeMargin, LayoutUnit childAfterMargin) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1763 | { |
hyatt@apple.com | 531e35d | 2017-04-13 16:37:00 +0000 | [diff] [blame] | 1764 | // When flexboxes are embedded inside a block flow, they don't perform any adjustments for unsplittable |
| 1765 | // children. We'll treat flexboxes themselves as unsplittable just to get them to paginate properly inside |
| 1766 | // a block flow. |
| 1767 | bool isUnsplittable = childBoxIsUnsplittableForFragmentation(child); |
| 1768 | if (!isUnsplittable && !(child.isFlexibleBox() && !downcast<RenderFlexibleBox>(child).isFlexibleBoxImpl())) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1769 | return logicalOffset; |
hyatt@apple.com | 531e35d | 2017-04-13 16:37:00 +0000 | [diff] [blame] | 1770 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1771 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 1772 | LayoutUnit childLogicalHeight = logicalHeightForChild(child) + childBeforeMargin + childAfterMargin; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1773 | LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1774 | bool hasUniformPageLogicalHeight = !fragmentedFlow || fragmentedFlow->fragmentsHaveUniformLogicalHeight(); |
hyatt@apple.com | 531e35d | 2017-04-13 16:37:00 +0000 | [diff] [blame] | 1775 | if (isUnsplittable) |
| 1776 | updateMinimumPageHeight(logicalOffset, childLogicalHeight); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1777 | if (!pageLogicalHeight || (hasUniformPageLogicalHeight && childLogicalHeight > pageLogicalHeight) |
| 1778 | || !hasNextPage(logicalOffset)) |
| 1779 | return logicalOffset; |
| 1780 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalOffset, ExcludePageBoundary); |
| 1781 | if (remainingLogicalHeight < childLogicalHeight) { |
| 1782 | if (!hasUniformPageLogicalHeight && !pushToNextPageWithMinimumLogicalHeight(remainingLogicalHeight, logicalOffset, childLogicalHeight)) |
| 1783 | return logicalOffset; |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 1784 | auto result = logicalOffset + remainingLogicalHeight; |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 1785 | bool isInitialLetter = child.isFloating() && child.style().styleType() == PseudoId::FirstLetter && child.style().initialLetterDrop() > 0; |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 1786 | if (isInitialLetter) { |
| 1787 | // Increase our logical height to ensure that lines all get pushed along with the letter. |
| 1788 | setLogicalHeight(logicalOffset + remainingLogicalHeight); |
| 1789 | } |
| 1790 | return result; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1791 | } |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 1792 | |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1793 | return logicalOffset; |
| 1794 | } |
| 1795 | |
| 1796 | bool RenderBlockFlow::pushToNextPageWithMinimumLogicalHeight(LayoutUnit& adjustment, LayoutUnit logicalOffset, LayoutUnit minimumLogicalHeight) const |
| 1797 | { |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1798 | bool checkFragment = false; |
zalan@apple.com | 065b9d0 | 2020-04-03 13:56:32 +0000 | [diff] [blame] | 1799 | auto* fragmentedFlow = enclosingFragmentedFlow(); |
| 1800 | RenderFragmentContainer* currentFragmentContainer = nullptr; |
| 1801 | for (auto pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset + adjustment); pageLogicalHeight; pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset + adjustment)) { |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1802 | if (minimumLogicalHeight <= pageLogicalHeight) |
| 1803 | return true; |
zalan@apple.com | 065b9d0 | 2020-04-03 13:56:32 +0000 | [diff] [blame] | 1804 | auto adjustedOffset = logicalOffset + adjustment; |
| 1805 | if (!hasNextPage(adjustedOffset)) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1806 | return false; |
zalan@apple.com | 065b9d0 | 2020-04-03 13:56:32 +0000 | [diff] [blame] | 1807 | if (fragmentedFlow) { |
| 1808 | // While in layout and the columnsets are not balanced yet, we keep finding the same (infinite tall) column over and over again. |
| 1809 | auto* nextFragmentContainer = fragmentedFlow->fragmentAtBlockOffset(this, adjustedOffset, true); |
| 1810 | ASSERT(nextFragmentContainer); |
| 1811 | if (nextFragmentContainer == currentFragmentContainer) |
| 1812 | return false; |
| 1813 | currentFragmentContainer = nextFragmentContainer; |
| 1814 | } |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1815 | adjustment += pageLogicalHeight; |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1816 | checkFragment = true; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1817 | } |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1818 | return !checkFragment; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void RenderBlockFlow::setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) |
| 1822 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1823 | if (RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow()) |
| 1824 | fragmentedFlow->setPageBreak(this, offsetFromLogicalTopOfFirstPage() + offset, spaceShortage); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | void RenderBlockFlow::updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight) |
| 1828 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1829 | if (RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow()) |
| 1830 | fragmentedFlow->updateMinimumPageHeight(this, offsetFromLogicalTopOfFirstPage() + offset, minHeight); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | LayoutUnit RenderBlockFlow::nextPageLogicalTop(LayoutUnit logicalOffset, PageBoundaryRule pageBoundaryRule) const |
| 1834 | { |
| 1835 | LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
| 1836 | if (!pageLogicalHeight) |
| 1837 | return logicalOffset; |
| 1838 | |
| 1839 | // The logicalOffset is in our coordinate space. We can add in our pushed offset. |
| 1840 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalOffset); |
| 1841 | if (pageBoundaryRule == ExcludePageBoundary) |
| 1842 | return logicalOffset + (remainingLogicalHeight ? remainingLogicalHeight : pageLogicalHeight); |
| 1843 | return logicalOffset + remainingLogicalHeight; |
| 1844 | } |
| 1845 | |
| 1846 | LayoutUnit RenderBlockFlow::pageLogicalTopForOffset(LayoutUnit offset) const |
| 1847 | { |
hyatt@apple.com | 6c9d5d3 | 2015-02-19 21:42:21 +0000 | [diff] [blame] | 1848 | // Unsplittable objects clear out the pageLogicalHeight in the layout state as a way of signaling that no |
| 1849 | // pagination should occur. Therefore we have to check this first and bail if the value has been set to 0. |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 1850 | auto* layoutState = view().frameView().layoutContext().layoutState(); |
zalan@apple.com | 7fd79ce | 2017-11-08 15:02:10 +0000 | [diff] [blame] | 1851 | LayoutUnit pageLogicalHeight = layoutState->pageLogicalHeight(); |
hyatt@apple.com | 6c9d5d3 | 2015-02-19 21:42:21 +0000 | [diff] [blame] | 1852 | if (!pageLogicalHeight) |
| 1853 | return 0; |
| 1854 | |
zalan@apple.com | 7fd79ce | 2017-11-08 15:02:10 +0000 | [diff] [blame] | 1855 | LayoutUnit firstPageLogicalTop = isHorizontalWritingMode() ? layoutState->pageOffset().height() : layoutState->pageOffset().width(); |
| 1856 | LayoutUnit blockLogicalTop = isHorizontalWritingMode() ? layoutState->layoutOffset().height() : layoutState->layoutOffset().width(); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1857 | |
| 1858 | LayoutUnit cumulativeOffset = offset + blockLogicalTop; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1859 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1860 | if (!fragmentedFlow) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1861 | return cumulativeOffset - roundToInt(cumulativeOffset - firstPageLogicalTop) % roundToInt(pageLogicalHeight); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1862 | return firstPageLogicalTop + fragmentedFlow->pageLogicalTopForOffset(cumulativeOffset - firstPageLogicalTop); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | LayoutUnit RenderBlockFlow::pageLogicalHeightForOffset(LayoutUnit offset) const |
| 1866 | { |
hyatt@apple.com | 6c9d5d3 | 2015-02-19 21:42:21 +0000 | [diff] [blame] | 1867 | // Unsplittable objects clear out the pageLogicalHeight in the layout state as a way of signaling that no |
| 1868 | // pagination should occur. Therefore we have to check this first and bail if the value has been set to 0. |
zalan@apple.com | 7fd79ce | 2017-11-08 15:02:10 +0000 | [diff] [blame] | 1869 | LayoutUnit pageLogicalHeight = view().frameView().layoutContext().layoutState()->pageLogicalHeight(); |
hyatt@apple.com | 6c9d5d3 | 2015-02-19 21:42:21 +0000 | [diff] [blame] | 1870 | if (!pageLogicalHeight) |
| 1871 | return 0; |
| 1872 | |
| 1873 | // Now check for a flow thread. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1874 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1875 | if (!fragmentedFlow) |
hyatt@apple.com | 6c9d5d3 | 2015-02-19 21:42:21 +0000 | [diff] [blame] | 1876 | return pageLogicalHeight; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1877 | return fragmentedFlow->pageLogicalHeightForOffset(offset + offsetFromLogicalTopOfFirstPage()); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | LayoutUnit RenderBlockFlow::pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule pageBoundaryRule) const |
| 1881 | { |
| 1882 | offset += offsetFromLogicalTopOfFirstPage(); |
| 1883 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1884 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1885 | if (!fragmentedFlow) { |
zalan@apple.com | 7fd79ce | 2017-11-08 15:02:10 +0000 | [diff] [blame] | 1886 | LayoutUnit pageLogicalHeight = view().frameView().layoutContext().layoutState()->pageLogicalHeight(); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1887 | LayoutUnit remainingHeight = pageLogicalHeight - intMod(offset, pageLogicalHeight); |
| 1888 | if (pageBoundaryRule == IncludePageBoundary) { |
| 1889 | // If includeBoundaryPoint is true the line exactly on the top edge of a |
| 1890 | // column will act as being part of the previous column. |
| 1891 | remainingHeight = intMod(remainingHeight, pageLogicalHeight); |
| 1892 | } |
| 1893 | return remainingHeight; |
| 1894 | } |
| 1895 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1896 | return fragmentedFlow->pageRemainingLogicalHeightForOffset(offset, pageBoundaryRule); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
stavila@adobe.com | b0d86c4 | 2014-04-09 17:07:50 +0000 | [diff] [blame] | 1899 | LayoutUnit RenderBlockFlow::logicalHeightForChildForFragmentation(const RenderBox& child) const |
| 1900 | { |
antti@apple.com | eae7612 | 2017-09-20 15:37:23 +0000 | [diff] [blame] | 1901 | return logicalHeightForChild(child); |
stavila@adobe.com | b0d86c4 | 2014-04-09 17:07:50 +0000 | [diff] [blame] | 1902 | } |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1903 | |
cathiechen@igalia.com | e80ce68 | 2021-05-11 12:49:46 +0000 | [diff] [blame] | 1904 | void RenderBlockFlow::adjustSizeContainmentChildForPagination(RenderBox& child, LayoutUnit offset) |
| 1905 | { |
simon.fraser@apple.com | e8ee49b | 2022-05-06 17:10:31 +0000 | [diff] [blame] | 1906 | if (!child.shouldApplySizeContainment()) |
cathiechen@igalia.com | e80ce68 | 2021-05-11 12:49:46 +0000 | [diff] [blame] | 1907 | return; |
| 1908 | |
| 1909 | LayoutUnit childOverflowHeight = child.isHorizontalWritingMode() ? child.layoutOverflowRect().maxY() : child.layoutOverflowRect().maxX(); |
| 1910 | LayoutUnit childLogicalHeight = std::max(child.logicalHeight(), childOverflowHeight); |
| 1911 | |
| 1912 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(offset, ExcludePageBoundary); |
| 1913 | |
| 1914 | LayoutUnit spaceShortage = childLogicalHeight - remainingLogicalHeight; |
| 1915 | if (spaceShortage <= 0) |
| 1916 | return; |
| 1917 | |
| 1918 | if (RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow()) |
| 1919 | fragmentedFlow->updateSpaceShortageForSizeContainment(this, offsetFromLogicalTopOfFirstPage() + offset, spaceShortage); |
| 1920 | } |
| 1921 | |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1922 | void RenderBlockFlow::layoutLineGridBox() |
| 1923 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1924 | if (style().lineGrid() == RenderStyle::initialLineGrid()) { |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1925 | setLineGridBox(0); |
| 1926 | return; |
| 1927 | } |
| 1928 | |
| 1929 | setLineGridBox(0); |
| 1930 | |
antti@apple.com | 903292a | 2021-06-02 16:20:15 +0000 | [diff] [blame] | 1931 | auto lineGridBox = makeUnique<LegacyRootInlineBox>(*this); |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1932 | lineGridBox->setHasTextChildren(); // Needed to make the line ascent/descent actually be honored in quirks mode. |
| 1933 | lineGridBox->setConstructed(); |
| 1934 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1935 | VerticalPositionCache verticalPositionCache; |
| 1936 | lineGridBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache); |
| 1937 | |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 1938 | setLineGridBox(WTFMove(lineGridBox)); |
akling@apple.com | 1aa97b0 | 2013-10-31 21:59:49 +0000 | [diff] [blame] | 1939 | |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1940 | // FIXME: If any of the characteristics of the box change compared to the old one, then we need to do a deep dirtying |
| 1941 | // (similar to what happens when the page height changes). Ideally, though, we only do this if someone is actually snapping |
| 1942 | // to this grid. |
| 1943 | } |
| 1944 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1945 | bool RenderBlockFlow::containsFloat(RenderBox& renderer) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1946 | { |
commit-queue@webkit.org | c27f5ca | 2018-11-26 19:29:23 +0000 | [diff] [blame] | 1947 | return m_floatingObjects && m_floatingObjects->set().contains<FloatingObjectHashTranslator>(renderer); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
commit-queue@webkit.org | f3910b4 | 2021-12-10 19:37:38 +0000 | [diff] [blame] | 1950 | bool RenderBlockFlow::subtreeContainsFloat(RenderBox& renderer) const |
| 1951 | { |
commit-queue@webkit.org | 7fa28a6 | 2022-01-07 19:34:59 +0000 | [diff] [blame] | 1952 | if (containsFloat(renderer)) |
| 1953 | return true; |
| 1954 | |
| 1955 | for (auto& block : descendantsOfType<RenderBlock>(const_cast<RenderBlockFlow&>(*this))) { |
commit-queue@webkit.org | f3910b4 | 2021-12-10 19:37:38 +0000 | [diff] [blame] | 1956 | if (!is<RenderBlockFlow>(block)) |
| 1957 | continue; |
| 1958 | auto& blockFlow = downcast<RenderBlockFlow>(block); |
commit-queue@webkit.org | 7fa28a6 | 2022-01-07 19:34:59 +0000 | [diff] [blame] | 1959 | if (blockFlow.containsFloat(renderer)) |
| 1960 | return true; |
commit-queue@webkit.org | f3910b4 | 2021-12-10 19:37:38 +0000 | [diff] [blame] | 1961 | } |
commit-queue@webkit.org | 7fa28a6 | 2022-01-07 19:34:59 +0000 | [diff] [blame] | 1962 | |
| 1963 | return false; |
commit-queue@webkit.org | f3910b4 | 2021-12-10 19:37:38 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | bool RenderBlockFlow::subtreeContainsFloats() const |
| 1967 | { |
commit-queue@webkit.org | 7fa28a6 | 2022-01-07 19:34:59 +0000 | [diff] [blame] | 1968 | if (containsFloats()) |
| 1969 | return true; |
| 1970 | |
| 1971 | for (auto& block : descendantsOfType<RenderBlock>(const_cast<RenderBlockFlow&>(*this))) { |
commit-queue@webkit.org | f3910b4 | 2021-12-10 19:37:38 +0000 | [diff] [blame] | 1972 | if (!is<RenderBlockFlow>(block)) |
| 1973 | continue; |
| 1974 | auto& blockFlow = downcast<RenderBlockFlow>(block); |
commit-queue@webkit.org | 7fa28a6 | 2022-01-07 19:34:59 +0000 | [diff] [blame] | 1975 | if (blockFlow.containsFloats()) |
| 1976 | return true; |
commit-queue@webkit.org | f3910b4 | 2021-12-10 19:37:38 +0000 | [diff] [blame] | 1977 | } |
commit-queue@webkit.org | 7fa28a6 | 2022-01-07 19:34:59 +0000 | [diff] [blame] | 1978 | |
| 1979 | return false; |
commit-queue@webkit.org | f3910b4 | 2021-12-10 19:37:38 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1982 | void RenderBlockFlow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
| 1983 | { |
| 1984 | RenderBlock::styleDidChange(diff, oldStyle); |
| 1985 | |
| 1986 | // After our style changed, if we lose our ability to propagate floats into next sibling |
| 1987 | // blocks, then we need to find the top most parent containing that overhanging float and |
| 1988 | // then mark its descendants with floats for layout and clear all floats from its next |
| 1989 | // sibling blocks that exist in our floating objects list. See bug 56299 and 62875. |
| 1990 | bool canPropagateFloatIntoSibling = !isFloatingOrOutOfFlowPositioned() && !avoidsFloats(); |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 1991 | if (diff == StyleDifference::Layout && s_canPropagateFloatIntoSibling && !canPropagateFloatIntoSibling && hasOverhangingFloats()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1992 | RenderBlockFlow* parentBlock = this; |
| 1993 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1994 | |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 1995 | for (auto& ancestor : ancestorsOfType<RenderBlockFlow>(*this)) { |
| 1996 | if (ancestor.isRenderView()) |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 1997 | break; |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 1998 | if (ancestor.hasOverhangingFloats()) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 1999 | for (auto it = floatingObjectSet.begin(), end = floatingObjectSet.end(); it != end; ++it) { |
| 2000 | RenderBox& renderer = (*it)->renderer(); |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 2001 | if (ancestor.hasOverhangingFloat(renderer)) { |
| 2002 | parentBlock = &ancestor; |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 2003 | break; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2004 | } |
| 2005 | } |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | parentBlock->markAllDescendantsWithFloatsForLayout(); |
| 2010 | parentBlock->markSiblingsWithFloatsForLayout(); |
| 2011 | } |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 2012 | |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 2013 | if (diff >= StyleDifference::Repaint) { |
zalan@apple.com | d4880dc | 2020-01-05 15:13:08 +0000 | [diff] [blame] | 2014 | auto shouldInvalidateLineLayoutPath = [&] { |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 2015 | if (selfNeedsLayout() || legacyLineLayout()) |
zalan@apple.com | d4880dc | 2020-01-05 15:13:08 +0000 | [diff] [blame] | 2016 | return true; |
zalan@apple.com | d4880dc | 2020-01-05 15:13:08 +0000 | [diff] [blame] | 2017 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 2018 | if (modernLineLayout() && !LayoutIntegration::LineLayout::canUseForAfterStyleChange(*this, diff)) |
zalan@apple.com | d4880dc | 2020-01-05 15:13:08 +0000 | [diff] [blame] | 2019 | return true; |
| 2020 | #endif |
| 2021 | return false; |
| 2022 | }; |
| 2023 | if (shouldInvalidateLineLayoutPath()) |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 2024 | invalidateLineLayoutPath(); |
antti@apple.com | af90731 | 2021-09-04 13:20:39 +0000 | [diff] [blame] | 2025 | } |
antti@apple.com | 2943bef | 2020-10-21 16:21:04 +0000 | [diff] [blame] | 2026 | |
| 2027 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | af90731 | 2021-09-04 13:20:39 +0000 | [diff] [blame] | 2028 | if (auto* lineLayout = modernLineLayout()) |
zalan@apple.com | 0afc633 | 2021-09-17 15:03:12 +0000 | [diff] [blame] | 2029 | lineLayout->updateStyle(*this, *oldStyle); |
antti@apple.com | 2943bef | 2020-10-21 16:21:04 +0000 | [diff] [blame] | 2030 | #endif |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 2031 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2032 | if (multiColumnFlow()) |
hyatt@apple.com | fdb1281 | 2014-06-23 18:56:52 +0000 | [diff] [blame] | 2033 | updateStylesForColumnChildren(); |
| 2034 | } |
| 2035 | |
| 2036 | void RenderBlockFlow::updateStylesForColumnChildren() |
| 2037 | { |
zalan@apple.com | cffcdb4 | 2021-04-28 16:54:01 +0000 | [diff] [blame] | 2038 | for (auto* child = firstChildBox(); child && (child->isRenderFragmentedFlow() || child->isRenderMultiColumnSet()); child = child->nextSiblingBox()) |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 2039 | child->setStyle(RenderStyle::createAnonymousStyleWithDisplay(style(), DisplayType::Block)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
akling@apple.com | bdae4324 | 2013-10-25 12:00:20 +0000 | [diff] [blame] | 2042 | void RenderBlockFlow::styleWillChange(StyleDifference diff, const RenderStyle& newStyle) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2043 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2044 | const RenderStyle* oldStyle = hasInitializedStyle() ? &style() : nullptr; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2045 | s_canPropagateFloatIntoSibling = oldStyle ? !isFloatingOrOutOfFlowPositioned() && !avoidsFloats() : false; |
| 2046 | |
stavila@adobe.com | d40a2dc | 2014-06-23 14:59:48 +0000 | [diff] [blame] | 2047 | if (oldStyle) { |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 2048 | auto oldPosition = oldStyle->position(); |
| 2049 | auto newPosition = newStyle.position(); |
abucur@adobe.com | c0a88a6 | 2014-10-16 06:50:30 +0000 | [diff] [blame] | 2050 | |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 2051 | if (parent() && diff == StyleDifference::Layout && oldPosition != newPosition) { |
stavila@adobe.com | d40a2dc | 2014-06-23 14:59:48 +0000 | [diff] [blame] | 2052 | if (containsFloats() && !isFloating() && !isOutOfFlowPositioned() && newStyle.hasOutOfFlowPosition()) |
| 2053 | markAllDescendantsWithFloatsForLayout(); |
stavila@adobe.com | d40a2dc | 2014-06-23 14:59:48 +0000 | [diff] [blame] | 2054 | } |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | RenderBlock::styleWillChange(diff, newStyle); |
| 2058 | } |
| 2059 | |
antti@apple.com | a2c7f24 | 2013-10-22 22:37:25 +0000 | [diff] [blame] | 2060 | void RenderBlockFlow::deleteLines() |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2061 | { |
commit-queue@webkit.org | 1acd723 | 2021-10-12 20:43:49 +0000 | [diff] [blame] | 2062 | m_lineLayout = std::monostate(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2063 | |
antti@apple.com | a2c7f24 | 2013-10-22 22:37:25 +0000 | [diff] [blame] | 2064 | RenderBlock::deleteLines(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2067 | void RenderBlockFlow::addFloatsToNewParent(RenderBlockFlow& toBlockFlow) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2068 | { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2069 | // When a portion of the render tree is being detached, anonymous blocks |
| 2070 | // will be combined as their children are deleted. In this process, the |
| 2071 | // anonymous block later in the tree is merged into the one preceeding it. |
| 2072 | // It can happen that the later block (this) contains floats that the |
| 2073 | // previous block (toBlockFlow) did not contain, and thus are not in the |
| 2074 | // floating objects list for toBlockFlow. This can result in toBlockFlow |
| 2075 | // containing floats that are not in it's floating objects list, but are in |
| 2076 | // the floating objects lists of siblings and parents. This can cause |
| 2077 | // problems when the float itself is deleted, since the deletion code |
| 2078 | // assumes that if a float is not in it's containing block's floating |
| 2079 | // objects list, it isn't in any floating objects list. In order to |
| 2080 | // preserve this condition (removing it has serious performance |
| 2081 | // implications), we need to copy the floating objects from the old block |
| 2082 | // (this) to the new block (toBlockFlow). The float's metrics will likely |
| 2083 | // all be wrong, but since toBlockFlow is already marked for layout, this |
| 2084 | // will get fixed before anything gets displayed. |
| 2085 | // See bug https://bugs.webkit.org/show_bug.cgi?id=115566 |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2086 | if (!m_floatingObjects) |
| 2087 | return; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2088 | |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2089 | if (!toBlockFlow.m_floatingObjects) |
| 2090 | toBlockFlow.createFloatingObjects(); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2091 | |
zalan@apple.com | 2601854 | 2017-03-30 01:25:00 +0000 | [diff] [blame] | 2092 | for (auto& floatingObject : m_floatingObjects->set()) { |
| 2093 | if (toBlockFlow.containsFloat(floatingObject->renderer())) |
| 2094 | continue; |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2095 | toBlockFlow.m_floatingObjects->add(floatingObject->cloneForNewParent()); |
zalan@apple.com | 2601854 | 2017-03-30 01:25:00 +0000 | [diff] [blame] | 2096 | } |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | void RenderBlockFlow::addOverflowFromFloats() |
| 2100 | { |
| 2101 | if (!m_floatingObjects) |
| 2102 | return; |
| 2103 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2104 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2105 | auto end = floatingObjectSet.end(); |
| 2106 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2107 | const auto& floatingObject = *it->get(); |
| 2108 | if (floatingObject.isDescendant()) |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2109 | addOverflowFromChild(&floatingObject.renderer(), floatingObject.locationOffsetOfBorderBox()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | void RenderBlockFlow::computeOverflow(LayoutUnit oldClientAfterEdge, bool recomputeFloats) |
| 2114 | { |
| 2115 | RenderBlock::computeOverflow(oldClientAfterEdge, recomputeFloats); |
| 2116 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2117 | if (!multiColumnFlow() && (recomputeFloats || createsNewFormattingContext() || hasSelfPaintingLayer())) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2118 | addOverflowFromFloats(); |
| 2119 | } |
| 2120 | |
| 2121 | void RenderBlockFlow::repaintOverhangingFloats(bool paintAllDescendants) |
| 2122 | { |
| 2123 | // Repaint any overhanging floats (if we know we're the one to paint them). |
| 2124 | // Otherwise, bail out. |
| 2125 | if (!hasOverhangingFloats()) |
| 2126 | return; |
| 2127 | |
| 2128 | // FIXME: Avoid disabling LayoutState. At the very least, don't disable it for floats originating |
| 2129 | // in this block. Better yet would be to push extra state for the containers of other floats. |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 2130 | LayoutStateDisabler layoutStateDisabler(view().frameView().layoutContext()); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2131 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2132 | auto end = floatingObjectSet.end(); |
| 2133 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2134 | const auto& floatingObject = *it->get(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2135 | // Only repaint the object if it is overhanging, is not in its own layer, and |
| 2136 | // is our responsibility to paint (m_shouldPaint is set). When paintAllDescendants is true, the latter |
| 2137 | // condition is replaced with being a descendant of us. |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2138 | auto& renderer = floatingObject.renderer(); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2139 | if (logicalBottomForFloat(floatingObject) > logicalHeight() |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2140 | && !renderer.hasSelfPaintingLayer() |
simon.fraser@apple.com | bc9d13c | 2021-01-27 04:56:57 +0000 | [diff] [blame] | 2141 | && (floatingObject.paintsFloat() || (paintAllDescendants && renderer.isDescendantOf(this)))) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2142 | renderer.repaint(); |
| 2143 | renderer.repaintOverhangingFloats(false); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2144 | } |
| 2145 | } |
| 2146 | } |
| 2147 | |
hyatt@apple.com | c9021b7 | 2014-04-25 21:05:59 +0000 | [diff] [blame] | 2148 | void RenderBlockFlow::paintColumnRules(PaintInfo& paintInfo, const LayoutPoint& point) |
hyatt@apple.com | 58b5ecc | 2014-04-17 23:06:02 +0000 | [diff] [blame] | 2149 | { |
hyatt@apple.com | c9021b7 | 2014-04-25 21:05:59 +0000 | [diff] [blame] | 2150 | RenderBlock::paintColumnRules(paintInfo, point); |
hyatt@apple.com | 58b5ecc | 2014-04-17 23:06:02 +0000 | [diff] [blame] | 2151 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2152 | if (!multiColumnFlow() || paintInfo.context().paintingDisabled()) |
hyatt@apple.com | 58b5ecc | 2014-04-17 23:06:02 +0000 | [diff] [blame] | 2153 | return; |
hyatt@apple.com | c9021b7 | 2014-04-25 21:05:59 +0000 | [diff] [blame] | 2154 | |
hyatt@apple.com | 58b5ecc | 2014-04-17 23:06:02 +0000 | [diff] [blame] | 2155 | // Iterate over our children and paint the column rules as needed. |
| 2156 | for (auto& columnSet : childrenOfType<RenderMultiColumnSet>(*this)) { |
zalan@apple.com | 16a404e | 2022-02-20 14:17:30 +0000 | [diff] [blame] | 2157 | LayoutPoint childPoint = columnSet.location() + flipForWritingModeForChild(columnSet, point); |
hyatt@apple.com | 58b5ecc | 2014-04-17 23:06:02 +0000 | [diff] [blame] | 2158 | columnSet.paintColumnRules(paintInfo, childPoint); |
| 2159 | } |
| 2160 | } |
| 2161 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2162 | void RenderBlockFlow::paintFloats(PaintInfo& paintInfo, const LayoutPoint& paintOffset, bool preservePhase) |
| 2163 | { |
| 2164 | if (!m_floatingObjects) |
| 2165 | return; |
| 2166 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2167 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2168 | auto end = floatingObjectSet.end(); |
| 2169 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2170 | const auto& floatingObject = *it->get(); |
| 2171 | auto& renderer = floatingObject.renderer(); |
simon.fraser@apple.com | bc9d13c | 2021-01-27 04:56:57 +0000 | [diff] [blame] | 2172 | if (floatingObject.shouldPaint()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2173 | PaintInfo currentPaintInfo(paintInfo); |
achristensen@apple.com | 9a618a9 | 2018-08-06 20:41:05 +0000 | [diff] [blame] | 2174 | currentPaintInfo.phase = preservePhase ? paintInfo.phase : PaintPhase::BlockBackground; |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2175 | LayoutPoint childPoint = flipFloatForWritingModeForChild(floatingObject, paintOffset + floatingObject.translationOffsetToAncestor()); |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2176 | renderer.paint(currentPaintInfo, childPoint); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2177 | if (!preservePhase) { |
achristensen@apple.com | 9a618a9 | 2018-08-06 20:41:05 +0000 | [diff] [blame] | 2178 | currentPaintInfo.phase = PaintPhase::ChildBlockBackgrounds; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2179 | renderer.paint(currentPaintInfo, childPoint); |
achristensen@apple.com | 9a618a9 | 2018-08-06 20:41:05 +0000 | [diff] [blame] | 2180 | currentPaintInfo.phase = PaintPhase::Float; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2181 | renderer.paint(currentPaintInfo, childPoint); |
achristensen@apple.com | 9a618a9 | 2018-08-06 20:41:05 +0000 | [diff] [blame] | 2182 | currentPaintInfo.phase = PaintPhase::Foreground; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2183 | renderer.paint(currentPaintInfo, childPoint); |
achristensen@apple.com | 9a618a9 | 2018-08-06 20:41:05 +0000 | [diff] [blame] | 2184 | currentPaintInfo.phase = PaintPhase::Outline; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2185 | renderer.paint(currentPaintInfo, childPoint); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | } |
| 2189 | } |
| 2190 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2191 | void RenderBlockFlow::clipOutFloatingObjects(RenderBlock& rootBlock, const PaintInfo* paintInfo, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2192 | { |
| 2193 | if (m_floatingObjects) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2194 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2195 | auto end = floatingObjectSet.end(); |
| 2196 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2197 | const auto& floatingObject = *it->get(); |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2198 | LayoutRect floatBox(offsetFromRootBlock.width(), offsetFromRootBlock.height(), floatingObject.renderer().width(), floatingObject.renderer().height()); |
| 2199 | floatBox.move(floatingObject.locationOffsetOfBorderBox()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2200 | rootBlock.flipForWritingMode(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2201 | floatBox.move(rootBlockPhysicalPosition.x(), rootBlockPhysicalPosition.y()); |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 2202 | paintInfo->context().clipOut(snappedIntRect(floatBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2203 | } |
| 2204 | } |
| 2205 | } |
| 2206 | |
| 2207 | void RenderBlockFlow::createFloatingObjects() |
| 2208 | { |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 2209 | m_floatingObjects = makeUnique<FloatingObjects>(*this); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | void RenderBlockFlow::removeFloatingObjects() |
| 2213 | { |
| 2214 | if (!m_floatingObjects) |
| 2215 | return; |
| 2216 | |
bjonesbe@adobe.com | 0b2195a | 2014-04-11 22:46:02 +0000 | [diff] [blame] | 2217 | markSiblingsWithFloatsForLayout(); |
| 2218 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2219 | m_floatingObjects->clear(); |
| 2220 | } |
| 2221 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2222 | FloatingObject* RenderBlockFlow::insertFloatingObject(RenderBox& floatBox) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2223 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2224 | ASSERT(floatBox.isFloating()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2225 | |
| 2226 | // Create the list of special objects if we don't aleady have one |
| 2227 | if (!m_floatingObjects) |
| 2228 | createFloatingObjects(); |
| 2229 | else { |
| 2230 | // Don't insert the floatingObject again if it's already in the list |
| 2231 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
commit-queue@webkit.org | c27f5ca | 2018-11-26 19:29:23 +0000 | [diff] [blame] | 2232 | auto it = floatingObjectSet.find<FloatingObjectHashTranslator>(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2233 | if (it != floatingObjectSet.end()) |
| 2234 | return it->get(); |
| 2235 | } |
| 2236 | |
| 2237 | // Create the special floatingObject entry & append it to the list |
| 2238 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2239 | std::unique_ptr<FloatingObject> floatingObject = FloatingObject::create(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2240 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 2241 | // Our location is irrelevant if we're unsplittable or no pagination is in effect. Just lay out the float. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2242 | bool isChildRenderBlock = floatBox.isRenderBlock(); |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 2243 | if (isChildRenderBlock && !floatBox.needsLayout() && view().frameView().layoutContext().layoutState()->pageLogicalHeightChanged()) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2244 | floatBox.setChildNeedsLayout(MarkOnlyThis); |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 2245 | |
| 2246 | bool needsBlockDirectionLocationSetBeforeLayout = isChildRenderBlock && view().frameView().layoutContext().layoutState()->needsBlockDirectionLocationSetBeforeLayout(); |
bjonesbe@adobe.com | 9c29e69 | 2014-12-10 00:57:10 +0000 | [diff] [blame] | 2247 | if (!needsBlockDirectionLocationSetBeforeLayout || isWritingModeRoot()) { |
| 2248 | // We are unsplittable if we're a block flow root. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2249 | floatBox.layoutIfNeeded(); |
simon.fraser@apple.com | bc9d13c | 2021-01-27 04:56:57 +0000 | [diff] [blame] | 2250 | } else { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2251 | floatBox.updateLogicalWidth(); |
mmaxfield@apple.com | 09804f4 | 2016-03-23 00:58:34 +0000 | [diff] [blame] | 2252 | floatBox.computeAndSetBlockDirectionMargins(*this); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2255 | setLogicalWidthForFloat(*floatingObject, logicalWidthForChild(floatBox) + marginStartForChild(floatBox) + marginEndForChild(floatBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2256 | |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 2257 | return m_floatingObjects->add(WTFMove(floatingObject)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2260 | void RenderBlockFlow::removeFloatingObject(RenderBox& floatBox) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2261 | { |
| 2262 | if (m_floatingObjects) { |
| 2263 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
commit-queue@webkit.org | c27f5ca | 2018-11-26 19:29:23 +0000 | [diff] [blame] | 2264 | auto it = floatingObjectSet.find<FloatingObjectHashTranslator>(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2265 | if (it != floatingObjectSet.end()) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2266 | auto& floatingObject = *it->get(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2267 | if (childrenInline()) { |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2268 | LayoutUnit logicalTop = logicalTopForFloat(floatingObject); |
| 2269 | LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2270 | |
| 2271 | // Fix for https://bugs.webkit.org/show_bug.cgi?id=54995. |
| 2272 | if (logicalBottom < 0 || logicalBottom < logicalTop || logicalTop == LayoutUnit::max()) |
| 2273 | logicalBottom = LayoutUnit::max(); |
| 2274 | else { |
| 2275 | // Special-case zero- and less-than-zero-height floats: those don't touch |
| 2276 | // the line that they're on, but it still needs to be dirtied. This is |
| 2277 | // accomplished by pretending they have a height of 1. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2278 | logicalBottom = std::max(logicalBottom, logicalTop + 1); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2279 | } |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2280 | if (floatingObject.originatingLine()) { |
| 2281 | floatingObject.originatingLine()->removeFloat(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2282 | if (!selfNeedsLayout()) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2283 | ASSERT(&floatingObject.originatingLine()->renderer() == this); |
| 2284 | floatingObject.originatingLine()->markDirty(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2285 | } |
mark.lam@apple.com | 6572436 | 2020-01-06 22:24:50 +0000 | [diff] [blame] | 2286 | #if ASSERT_ENABLED |
zalan@apple.com | d2acead | 2017-09-20 22:03:06 +0000 | [diff] [blame] | 2287 | floatingObject.clearOriginatingLine(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2288 | #endif |
| 2289 | } |
| 2290 | markLinesDirtyInBlockRange(0, logicalBottom); |
| 2291 | } |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2292 | m_floatingObjects->remove(&floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2293 | } |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | void RenderBlockFlow::removeFloatingObjectsBelow(FloatingObject* lastFloat, int logicalOffset) |
| 2298 | { |
| 2299 | if (!containsFloats()) |
| 2300 | return; |
| 2301 | |
| 2302 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2303 | FloatingObject* curr = floatingObjectSet.last().get(); |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2304 | while (curr != lastFloat && (!curr->isPlaced() || logicalTopForFloat(*curr) >= logicalOffset)) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2305 | m_floatingObjects->remove(curr); |
| 2306 | if (floatingObjectSet.isEmpty()) |
| 2307 | break; |
| 2308 | curr = floatingObjectSet.last().get(); |
| 2309 | } |
| 2310 | } |
| 2311 | |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2312 | LayoutUnit RenderBlockFlow::logicalLeftOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const |
| 2313 | { |
| 2314 | LayoutUnit offset = fixedOffset; |
| 2315 | if (m_floatingObjects && m_floatingObjects->hasLeftObjects()) |
| 2316 | offset = m_floatingObjects->logicalLeftOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining); |
| 2317 | return adjustLogicalLeftOffsetForLine(offset, applyTextIndent); |
| 2318 | } |
| 2319 | |
| 2320 | LayoutUnit RenderBlockFlow::logicalRightOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const |
| 2321 | { |
| 2322 | LayoutUnit offset = fixedOffset; |
| 2323 | if (m_floatingObjects && m_floatingObjects->hasRightObjects()) |
| 2324 | offset = m_floatingObjects->logicalRightOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining); |
| 2325 | return adjustLogicalRightOffsetForLine(offset, applyTextIndent); |
| 2326 | } |
| 2327 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2328 | void RenderBlockFlow::computeLogicalLocationForFloat(FloatingObject& floatingObject, LayoutUnit& logicalTopOffset) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2329 | { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2330 | auto& childBox = floatingObject.renderer(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2331 | LayoutUnit logicalLeftOffset = logicalLeftOffsetForContent(logicalTopOffset); // Constant part of left offset. |
zoltan@webkit.org | 7d4f8cc | 2014-03-26 18:20:15 +0000 | [diff] [blame] | 2332 | LayoutUnit logicalRightOffset = logicalRightOffsetForContent(logicalTopOffset); // Constant part of right offset. |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2333 | |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2334 | LayoutUnit floatLogicalWidth = std::min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); // The width we look for. |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2335 | |
| 2336 | LayoutUnit floatLogicalLeft; |
| 2337 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2338 | bool insideFragmentedFlow = enclosingFragmentedFlow(); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 2339 | bool isInitialLetter = childBox.style().styleType() == PseudoId::FirstLetter && childBox.style().initialLetterDrop() > 0; |
hyatt@apple.com | 8751526 | 2014-09-04 21:20:12 +0000 | [diff] [blame] | 2340 | |
| 2341 | if (isInitialLetter) { |
| 2342 | int letterClearance = lowestInitialLetterLogicalBottom() - logicalTopOffset; |
| 2343 | if (letterClearance > 0) { |
| 2344 | logicalTopOffset += letterClearance; |
| 2345 | setLogicalHeight(logicalHeight() + letterClearance); |
| 2346 | } |
| 2347 | } |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2348 | |
| 2349 | if (RenderStyle::usedFloat(childBox) == UsedFloat::Left) { |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 2350 | LayoutUnit heightRemainingLeft = 1_lu; |
| 2351 | LayoutUnit heightRemainingRight = 1_lu; |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2352 | floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft); |
| 2353 | while (logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight) - floatLogicalLeft < floatLogicalWidth) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2354 | logicalTopOffset += std::min(heightRemainingLeft, heightRemainingRight); |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2355 | floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2356 | if (insideFragmentedFlow) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2357 | // Have to re-evaluate all of our offsets, since they may have changed. |
| 2358 | logicalRightOffset = logicalRightOffsetForContent(logicalTopOffset); // Constant part of right offset. |
| 2359 | logicalLeftOffset = logicalLeftOffsetForContent(logicalTopOffset); // Constant part of left offset. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2360 | floatLogicalWidth = std::min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2361 | } |
| 2362 | } |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2363 | floatLogicalLeft = std::max(logicalLeftOffset - borderAndPaddingLogicalLeft(), floatLogicalLeft); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2364 | } else { |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 2365 | LayoutUnit heightRemainingLeft = 1_lu; |
| 2366 | LayoutUnit heightRemainingRight = 1_lu; |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2367 | floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight); |
| 2368 | while (floatLogicalLeft - logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft) < floatLogicalWidth) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2369 | logicalTopOffset += std::min(heightRemainingLeft, heightRemainingRight); |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2370 | floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2371 | if (insideFragmentedFlow) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2372 | // Have to re-evaluate all of our offsets, since they may have changed. |
| 2373 | logicalRightOffset = logicalRightOffsetForContent(logicalTopOffset); // Constant part of right offset. |
| 2374 | logicalLeftOffset = logicalLeftOffsetForContent(logicalTopOffset); // Constant part of left offset. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2375 | floatLogicalWidth = std::min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2376 | } |
| 2377 | } |
| 2378 | // Use the original width of the float here, since the local variable |
| 2379 | // |floatLogicalWidth| was capped to the available line width. See |
| 2380 | // fast/block/float/clamped-right-float.html. |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2381 | floatLogicalLeft -= logicalWidthForFloat(floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2382 | } |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2383 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2384 | LayoutUnit childLogicalLeftMargin = style().isLeftToRightDirection() ? marginStartForChild(childBox) : marginEndForChild(childBox); |
| 2385 | LayoutUnit childBeforeMargin = marginBeforeForChild(childBox); |
hyatt@apple.com | c2e1552 | 2014-09-03 19:26:38 +0000 | [diff] [blame] | 2386 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2387 | if (isInitialLetter) |
| 2388 | adjustInitialLetterPosition(childBox, logicalTopOffset, childBeforeMargin); |
| 2389 | |
| 2390 | setLogicalLeftForFloat(floatingObject, floatLogicalLeft); |
| 2391 | setLogicalLeftForChild(childBox, floatLogicalLeft + childLogicalLeftMargin); |
| 2392 | |
| 2393 | setLogicalTopForFloat(floatingObject, logicalTopOffset); |
| 2394 | setLogicalTopForChild(childBox, logicalTopOffset + childBeforeMargin); |
| 2395 | |
| 2396 | setLogicalMarginsForFloat(floatingObject, childLogicalLeftMargin, childBeforeMargin); |
| 2397 | } |
| 2398 | |
| 2399 | void RenderBlockFlow::adjustInitialLetterPosition(RenderBox& childBox, LayoutUnit& logicalTopOffset, LayoutUnit& marginBeforeOffset) |
| 2400 | { |
| 2401 | const RenderStyle& style = firstLineStyle(); |
mmaxfield@apple.com | 881a936 | 2022-02-02 05:12:47 +0000 | [diff] [blame] | 2402 | const FontMetrics& fontMetrics = style.metricsOfPrimaryFont(); |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2403 | if (!fontMetrics.hasCapHeight()) |
| 2404 | return; |
| 2405 | |
| 2406 | LayoutUnit heightOfLine = lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
| 2407 | LayoutUnit beforeMarginBorderPadding = childBox.borderAndPaddingBefore() + childBox.marginBefore(); |
| 2408 | |
| 2409 | // Make an adjustment to align with the cap height of a theoretical block line. |
| 2410 | LayoutUnit adjustment = fontMetrics.ascent() + (heightOfLine - fontMetrics.height()) / 2 - fontMetrics.capHeight() - beforeMarginBorderPadding; |
| 2411 | logicalTopOffset += adjustment; |
| 2412 | |
| 2413 | // For sunken and raised caps, we have to make some adjustments. Test if we're sunken or raised (dropHeightDelta will be |
| 2414 | // positive for raised and negative for sunken). |
| 2415 | int dropHeightDelta = childBox.style().initialLetterHeight() - childBox.style().initialLetterDrop(); |
| 2416 | |
| 2417 | // If we're sunken, the float needs to shift down but lines still need to avoid it. In order to do that we increase the float's margin. |
| 2418 | if (dropHeightDelta < 0) |
| 2419 | marginBeforeOffset += -dropHeightDelta * heightOfLine; |
| 2420 | |
| 2421 | // If we're raised, then we actually have to grow the height of the block, since the lines have to be pushed down as though we're placing |
| 2422 | // empty lines beside the first letter. |
| 2423 | if (dropHeightDelta > 0) |
| 2424 | setLogicalHeight(logicalHeight() + dropHeightDelta * heightOfLine); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | bool RenderBlockFlow::positionNewFloats() |
| 2428 | { |
| 2429 | if (!m_floatingObjects) |
| 2430 | return false; |
| 2431 | |
| 2432 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2433 | if (floatingObjectSet.isEmpty()) |
| 2434 | return false; |
| 2435 | |
| 2436 | // If all floats have already been positioned, then we have no work to do. |
| 2437 | if (floatingObjectSet.last()->isPlaced()) |
| 2438 | return false; |
| 2439 | |
| 2440 | // Move backwards through our floating object list until we find a float that has |
| 2441 | // already been positioned. Then we'll be able to move forward, positioning all of |
| 2442 | // the new floats that need it. |
| 2443 | auto it = floatingObjectSet.end(); |
| 2444 | --it; // Go to last item. |
| 2445 | auto begin = floatingObjectSet.begin(); |
| 2446 | FloatingObject* lastPlacedFloatingObject = 0; |
| 2447 | while (it != begin) { |
| 2448 | --it; |
| 2449 | if ((*it)->isPlaced()) { |
| 2450 | lastPlacedFloatingObject = it->get(); |
| 2451 | ++it; |
| 2452 | break; |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | LayoutUnit logicalTop = logicalHeight(); |
| 2457 | |
| 2458 | // The float cannot start above the top position of the last positioned float. |
| 2459 | if (lastPlacedFloatingObject) |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2460 | logicalTop = std::max(logicalTopForFloat(*lastPlacedFloatingObject), logicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2461 | |
| 2462 | auto end = floatingObjectSet.end(); |
| 2463 | // Now walk through the set of unpositioned floats and place them. |
| 2464 | for (; it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2465 | auto& floatingObject = *it->get(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2466 | // The containing block is responsible for positioning floats, so if we have floats in our |
| 2467 | // list that come from somewhere else, do not attempt to position them. |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2468 | auto& childBox = floatingObject.renderer(); |
| 2469 | if (childBox.containingBlock() != this) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2470 | continue; |
| 2471 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2472 | LayoutRect oldRect = childBox.frameRect(); |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2473 | auto childBoxUsedClear = RenderStyle::usedClear(childBox); |
| 2474 | if (childBoxUsedClear == UsedClear::Left || childBoxUsedClear == UsedClear::Both) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2475 | logicalTop = std::max(lowestFloatLogicalBottom(FloatingObject::FloatLeft), logicalTop); |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2476 | if (childBoxUsedClear == UsedClear::Right || childBoxUsedClear == UsedClear::Both) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2477 | logicalTop = std::max(lowestFloatLogicalBottom(FloatingObject::FloatRight), logicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2478 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2479 | computeLogicalLocationForFloat(floatingObject, logicalTop); |
| 2480 | LayoutUnit childLogicalTop = logicalTopForChild(childBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2481 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 2482 | estimateFragmentRangeForBoxChild(childBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2483 | |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 2484 | childBox.markForPaginationRelayoutIfNeeded(); |
| 2485 | childBox.layoutIfNeeded(); |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2486 | |
zalan@apple.com | 4de96c5 | 2017-11-07 04:09:59 +0000 | [diff] [blame] | 2487 | auto* layoutState = view().frameView().layoutContext().layoutState(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2488 | bool isPaginated = layoutState->isPaginated(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2489 | if (isPaginated) { |
| 2490 | // If we are unsplittable and don't fit, then we need to move down. |
| 2491 | // We include our margins as part of the unsplittable area. |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2492 | LayoutUnit newLogicalTop = adjustForUnsplittableChild(childBox, logicalTop, childLogicalTop - logicalTop, marginAfterForChild(childBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2493 | |
| 2494 | // See if we have a pagination strut that is making us move down further. |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2495 | // Note that an unsplittable child can't also have a pagination strut, so this |
| 2496 | // is exclusive with the case above. |
cdumez@apple.com | 5f02e63 | 2022-01-16 01:33:25 +0000 | [diff] [blame] | 2497 | auto* childBlock = dynamicDowncast<RenderBlock>(childBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2498 | if (childBlock && childBlock->paginationStrut()) { |
| 2499 | newLogicalTop += childBlock->paginationStrut(); |
| 2500 | childBlock->setPaginationStrut(0); |
| 2501 | } |
| 2502 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2503 | if (newLogicalTop != logicalTop) { |
| 2504 | floatingObject.setPaginationStrut(newLogicalTop - logicalTop); |
| 2505 | computeLogicalLocationForFloat(floatingObject, newLogicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2506 | if (childBlock) |
| 2507 | childBlock->setChildNeedsLayout(MarkOnlyThis); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2508 | childBox.layoutIfNeeded(); |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2509 | logicalTop = newLogicalTop; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 2512 | if (updateFragmentRangeForBoxChild(childBox)) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2513 | childBox.setNeedsLayout(MarkOnlyThis); |
| 2514 | childBox.layoutIfNeeded(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2515 | } |
| 2516 | } |
| 2517 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2518 | setLogicalHeightForFloat(floatingObject, logicalHeightForChildForFragmentation(childBox) + (logicalTopForChild(childBox) - logicalTop) + marginAfterForChild(childBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2519 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2520 | m_floatingObjects->addPlacedObject(&floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2521 | |
zoltan@webkit.org | 0faf572 | 2013-11-05 02:34:16 +0000 | [diff] [blame] | 2522 | if (ShapeOutsideInfo* shapeOutside = childBox.shapeOutsideInfo()) |
bjonesbe@adobe.com | 029f74e | 2014-02-13 03:02:53 +0000 | [diff] [blame] | 2523 | shapeOutside->setReferenceBoxLogicalSize(logicalSizeForChild(childBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2524 | // If the child moved, we have to repaint it. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2525 | if (childBox.checkForRepaintDuringLayout()) |
| 2526 | childBox.repaintDuringLayoutIfMoved(oldRect); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2527 | } |
| 2528 | return true; |
| 2529 | } |
| 2530 | |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2531 | void RenderBlockFlow::clearFloats(UsedClear usedClear) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2532 | { |
| 2533 | positionNewFloats(); |
| 2534 | // set y position |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 2535 | LayoutUnit newY; |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2536 | switch (usedClear) { |
| 2537 | case UsedClear::Left: |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2538 | newY = lowestFloatLogicalBottom(FloatingObject::FloatLeft); |
| 2539 | break; |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2540 | case UsedClear::Right: |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2541 | newY = lowestFloatLogicalBottom(FloatingObject::FloatRight); |
| 2542 | break; |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2543 | case UsedClear::Both: |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2544 | newY = lowestFloatLogicalBottom(); |
joepeck@webkit.org | aa676ee5 | 2014-01-28 04:04:52 +0000 | [diff] [blame] | 2545 | break; |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2546 | case UsedClear::None: |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2547 | break; |
| 2548 | } |
zalan@apple.com | 681bd25 | 2020-10-08 19:29:23 +0000 | [diff] [blame] | 2549 | // FIXME: The float search tree has floored float box position (see FloatingObjects::intervalForFloatingObject). |
| 2550 | newY = newY.floor(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2551 | if (height() < newY) |
| 2552 | setLogicalHeight(newY); |
| 2553 | } |
| 2554 | |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2555 | LayoutUnit RenderBlockFlow::logicalLeftFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2556 | { |
| 2557 | if (m_floatingObjects && m_floatingObjects->hasLeftObjects()) |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2558 | return m_floatingObjects->logicalLeftOffset(fixedOffset, logicalTop, logicalHeight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2559 | |
| 2560 | return fixedOffset; |
| 2561 | } |
| 2562 | |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2563 | LayoutUnit RenderBlockFlow::logicalRightFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2564 | { |
| 2565 | if (m_floatingObjects && m_floatingObjects->hasRightObjects()) |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2566 | return m_floatingObjects->logicalRightOffset(fixedOffset, logicalTop, logicalHeight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2567 | |
| 2568 | return fixedOffset; |
| 2569 | } |
| 2570 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2571 | LayoutUnit RenderBlockFlow::nextFloatLogicalBottomBelow(LayoutUnit logicalHeight) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2572 | { |
| 2573 | if (!m_floatingObjects) |
| 2574 | return logicalHeight; |
| 2575 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2576 | return m_floatingObjects->findNextFloatLogicalBottomBelow(logicalHeight); |
| 2577 | } |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2578 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2579 | LayoutUnit RenderBlockFlow::nextFloatLogicalBottomBelowForBlock(LayoutUnit logicalHeight) const |
| 2580 | { |
| 2581 | if (!m_floatingObjects) |
| 2582 | return logicalHeight; |
| 2583 | |
| 2584 | return m_floatingObjects->findNextFloatLogicalBottomBelowForBlock(logicalHeight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | LayoutUnit RenderBlockFlow::lowestFloatLogicalBottom(FloatingObject::Type floatType) const |
| 2588 | { |
| 2589 | if (!m_floatingObjects) |
| 2590 | return 0; |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 2591 | LayoutUnit lowestFloatBottom; |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2592 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2593 | auto end = floatingObjectSet.end(); |
| 2594 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2595 | const auto& floatingObject = *it->get(); |
| 2596 | if (floatingObject.isPlaced() && floatingObject.type() & floatType) |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2597 | lowestFloatBottom = std::max(lowestFloatBottom, logicalBottomForFloat(floatingObject)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2598 | } |
| 2599 | return lowestFloatBottom; |
| 2600 | } |
| 2601 | |
hyatt@apple.com | 8751526 | 2014-09-04 21:20:12 +0000 | [diff] [blame] | 2602 | LayoutUnit RenderBlockFlow::lowestInitialLetterLogicalBottom() const |
| 2603 | { |
| 2604 | if (!m_floatingObjects) |
| 2605 | return 0; |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 2606 | LayoutUnit lowestFloatBottom; |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2607 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2608 | auto end = floatingObjectSet.end(); |
| 2609 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2610 | const auto& floatingObject = *it->get(); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 2611 | if (floatingObject.isPlaced() && floatingObject.renderer().style().styleType() == PseudoId::FirstLetter && floatingObject.renderer().style().initialLetterDrop() > 0) |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2612 | lowestFloatBottom = std::max(lowestFloatBottom, logicalBottomForFloat(floatingObject)); |
hyatt@apple.com | 8751526 | 2014-09-04 21:20:12 +0000 | [diff] [blame] | 2613 | } |
| 2614 | return lowestFloatBottom; |
| 2615 | } |
| 2616 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2617 | LayoutUnit RenderBlockFlow::addOverhangingFloats(RenderBlockFlow& child, bool makeChildPaintOtherFloats) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2618 | { |
| 2619 | // Prevent floats from being added to the canvas by the root element, e.g., <html>. |
jfernandez@igalia.com | 136f170 | 2014-12-08 19:13:16 +0000 | [diff] [blame] | 2620 | if (!child.containsFloats() || child.createsNewFormattingContext()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2621 | return 0; |
| 2622 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2623 | LayoutUnit childLogicalTop = child.logicalTop(); |
| 2624 | LayoutUnit childLogicalLeft = child.logicalLeft(); |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 2625 | LayoutUnit lowestFloatLogicalBottom; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2626 | |
| 2627 | // Floats that will remain the child's responsibility to paint should factor into its |
| 2628 | // overflow. |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2629 | auto childEnd = child.m_floatingObjects->set().end(); |
| 2630 | for (auto childIt = child.m_floatingObjects->set().begin(); childIt != childEnd; ++childIt) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2631 | auto& floatingObject = *childIt->get(); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2632 | LayoutUnit floatLogicalBottom = std::min(logicalBottomForFloat(floatingObject), LayoutUnit::max() - childLogicalTop); |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2633 | LayoutUnit logicalBottom = childLogicalTop + floatLogicalBottom; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2634 | lowestFloatLogicalBottom = std::max(lowestFloatLogicalBottom, logicalBottom); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2635 | |
| 2636 | if (logicalBottom > logicalHeight()) { |
| 2637 | // If the object is not in the list, we add it now. |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2638 | if (!containsFloat(floatingObject.renderer())) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2639 | LayoutSize offset = isHorizontalWritingMode() ? LayoutSize(-childLogicalLeft, -childLogicalTop) : LayoutSize(-childLogicalTop, -childLogicalLeft); |
| 2640 | bool shouldPaint = false; |
| 2641 | |
| 2642 | // The nearest enclosing layer always paints the float (so that zindex and stacking |
| 2643 | // behaves properly). We always want to propagate the desire to paint the float as |
| 2644 | // far out as we can, to the outermost block that overlaps the float, stopping only |
| 2645 | // if we hit a self-painting layer boundary. |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2646 | if (floatingObject.renderer().enclosingFloatPaintingLayer() == enclosingFloatPaintingLayer()) { |
simon.fraser@apple.com | bc9d13c | 2021-01-27 04:56:57 +0000 | [diff] [blame] | 2647 | floatingObject.setPaintsFloat(false); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2648 | shouldPaint = true; |
| 2649 | } |
| 2650 | // We create the floating object list lazily. |
| 2651 | if (!m_floatingObjects) |
| 2652 | createFloatingObjects(); |
| 2653 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2654 | m_floatingObjects->add(floatingObject.copyToNewContainer(offset, shouldPaint, true)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2655 | } |
| 2656 | } else { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2657 | const auto& renderer = floatingObject.renderer(); |
simon.fraser@apple.com | bc9d13c | 2021-01-27 04:56:57 +0000 | [diff] [blame] | 2658 | if (makeChildPaintOtherFloats && !floatingObject.paintsFloat() && !renderer.hasSelfPaintingLayer() |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2659 | && renderer.isDescendantOf(&child) && renderer.enclosingFloatPaintingLayer() == child.enclosingFloatPaintingLayer()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2660 | // The float is not overhanging from this block, so if it is a descendant of the child, the child should |
| 2661 | // paint it (the other case is that it is intruding into the child), unless it has its own layer or enclosing |
| 2662 | // layer. |
| 2663 | // If makeChildPaintOtherFloats is false, it means that the child must already know about all the floats |
| 2664 | // it should paint. |
simon.fraser@apple.com | bc9d13c | 2021-01-27 04:56:57 +0000 | [diff] [blame] | 2665 | floatingObject.setPaintsFloat(true); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2666 | } |
| 2667 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 2668 | // Since the float doesn't overhang, it didn't get put into our list. We need to add its overflow in to the child now. |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2669 | if (floatingObject.isDescendant()) |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2670 | child.addOverflowFromChild(&renderer, floatingObject.locationOffsetOfBorderBox()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2671 | } |
| 2672 | } |
| 2673 | return lowestFloatLogicalBottom; |
| 2674 | } |
| 2675 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2676 | bool RenderBlockFlow::hasOverhangingFloat(RenderBox& renderer) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2677 | { |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 2678 | if (!m_floatingObjects || !parent()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2679 | return false; |
| 2680 | |
| 2681 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
commit-queue@webkit.org | c27f5ca | 2018-11-26 19:29:23 +0000 | [diff] [blame] | 2682 | const auto it = floatingObjectSet.find<FloatingObjectHashTranslator>(renderer); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2683 | if (it == floatingObjectSet.end()) |
| 2684 | return false; |
| 2685 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2686 | return logicalBottomForFloat(*it->get()) > logicalHeight(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 2689 | void RenderBlockFlow::addIntrudingFloats(RenderBlockFlow* prev, RenderBlockFlow* container, LayoutUnit logicalLeftOffset, LayoutUnit logicalTopOffset) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2690 | { |
| 2691 | ASSERT(!avoidsFloats()); |
| 2692 | |
jfernandez@igalia.com | 7065868 | 2014-12-15 21:07:30 +0000 | [diff] [blame] | 2693 | // If we create our own block formatting context then our contents don't interact with floats outside it, even those from our parent. |
| 2694 | if (createsNewFormattingContext()) |
| 2695 | return; |
| 2696 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2697 | // If the parent or previous sibling doesn't have any floats to add, don't bother. |
| 2698 | if (!prev->m_floatingObjects) |
| 2699 | return; |
| 2700 | |
| 2701 | logicalLeftOffset += marginLogicalLeft(); |
| 2702 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2703 | const FloatingObjectSet& prevSet = prev->m_floatingObjects->set(); |
| 2704 | auto prevEnd = prevSet.end(); |
| 2705 | for (auto prevIt = prevSet.begin(); prevIt != prevEnd; ++prevIt) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2706 | auto& floatingObject = *prevIt->get(); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2707 | if (logicalBottomForFloat(floatingObject) > logicalTopOffset) { |
commit-queue@webkit.org | c27f5ca | 2018-11-26 19:29:23 +0000 | [diff] [blame] | 2708 | if (!m_floatingObjects || !m_floatingObjects->set().contains(&floatingObject)) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2709 | // We create the floating object list lazily. |
| 2710 | if (!m_floatingObjects) |
| 2711 | createFloatingObjects(); |
| 2712 | |
| 2713 | // Applying the child's margin makes no sense in the case where the child was passed in. |
| 2714 | // since this margin was added already through the modification of the |logicalLeftOffset| variable |
| 2715 | // above. |logicalLeftOffset| will equal the margin in this case, so it's already been taken |
| 2716 | // into account. Only apply this code if prev is the parent, since otherwise the left margin |
| 2717 | // will get applied twice. |
| 2718 | LayoutSize offset = isHorizontalWritingMode() |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 2719 | ? LayoutSize(logicalLeftOffset - (prev != container ? prev->marginLeft() : 0_lu), logicalTopOffset) |
| 2720 | : LayoutSize(logicalTopOffset, logicalLeftOffset - (prev != container ? prev->marginTop() : 0_lu)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2721 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2722 | m_floatingObjects->add(floatingObject.copyToNewContainer(offset)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2723 | } |
| 2724 | } |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | void RenderBlockFlow::markAllDescendantsWithFloatsForLayout(RenderBox* floatToRemove, bool inLayout) |
| 2729 | { |
| 2730 | if (!everHadLayout() && !containsFloats()) |
| 2731 | return; |
| 2732 | |
| 2733 | MarkingBehavior markParents = inLayout ? MarkOnlyThis : MarkContainingBlockChain; |
| 2734 | setChildNeedsLayout(markParents); |
| 2735 | |
| 2736 | if (floatToRemove) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2737 | removeFloatingObject(*floatToRemove); |
hyatt@apple.com | 11a5e5c | 2016-05-19 21:51:31 +0000 | [diff] [blame] | 2738 | else if (childrenInline()) |
hyatt@apple.com | 00e9314 | 2016-05-18 18:59:40 +0000 | [diff] [blame] | 2739 | return; |
| 2740 | |
zalan@apple.com | 5d7ffdf | 2014-10-29 21:13:12 +0000 | [diff] [blame] | 2741 | // Iterate over our block children and mark them as needed. |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2742 | for (auto& block : childrenOfType<RenderBlock>(*this)) { |
| 2743 | if (!floatToRemove && block.isFloatingOrOutOfFlowPositioned()) |
| 2744 | continue; |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 2745 | if (!is<RenderBlockFlow>(block)) { |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2746 | if (block.shrinkToAvoidFloats() && block.everHadLayout()) |
| 2747 | block.setChildNeedsLayout(markParents); |
| 2748 | continue; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2749 | } |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 2750 | auto& blockFlow = downcast<RenderBlockFlow>(block); |
commit-queue@webkit.org | f3910b4 | 2021-12-10 19:37:38 +0000 | [diff] [blame] | 2751 | if ((floatToRemove ? blockFlow.subtreeContainsFloat(*floatToRemove) : blockFlow.subtreeContainsFloats()) || blockFlow.shrinkToAvoidFloats()) |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2752 | blockFlow.markAllDescendantsWithFloatsForLayout(floatToRemove, inLayout); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | void RenderBlockFlow::markSiblingsWithFloatsForLayout(RenderBox* floatToRemove) |
| 2757 | { |
| 2758 | if (!m_floatingObjects) |
| 2759 | return; |
| 2760 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2761 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2762 | auto end = floatingObjectSet.end(); |
| 2763 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2764 | for (RenderObject* next = nextSibling(); next; next = next->nextSibling()) { |
zalan@apple.com | c2472ea | 2015-05-26 22:59:40 +0000 | [diff] [blame] | 2765 | if (!is<RenderBlockFlow>(*next) || next->isFloatingOrOutOfFlowPositioned()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2766 | continue; |
| 2767 | |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 2768 | RenderBlockFlow& nextBlock = downcast<RenderBlockFlow>(*next); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2769 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 2770 | RenderBox& floatingBox = (*it)->renderer(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2771 | if (floatToRemove && &floatingBox != floatToRemove) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2772 | continue; |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 2773 | if (nextBlock.containsFloat(floatingBox)) |
| 2774 | nextBlock.markAllDescendantsWithFloatsForLayout(&floatingBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2775 | } |
| 2776 | } |
| 2777 | } |
| 2778 | |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2779 | LayoutPoint RenderBlockFlow::flipFloatForWritingModeForChild(const FloatingObject& child, const LayoutPoint& point) const |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 2780 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2781 | if (!style().isFlippedBlocksWritingMode()) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 2782 | return point; |
| 2783 | |
| 2784 | // This is similar to RenderBox::flipForWritingModeForChild. We have to subtract out our left/top offsets twice, since |
| 2785 | // it's going to get added back in. We hide this complication here so that the calling code looks normal for the unflipped |
| 2786 | // case. |
| 2787 | if (isHorizontalWritingMode()) |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2788 | return LayoutPoint(point.x(), point.y() + height() - child.renderer().height() - 2 * child.locationOffsetOfBorderBox().height()); |
| 2789 | return LayoutPoint(point.x() + width() - child.renderer().width() - 2 * child.locationOffsetOfBorderBox().width(), point.y()); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 2790 | } |
| 2791 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2792 | LayoutUnit RenderBlockFlow::getClearDelta(RenderBox& child, LayoutUnit logicalTop) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2793 | { |
| 2794 | // There is no need to compute clearance if we have no floats. |
| 2795 | if (!containsFloats()) |
| 2796 | return 0; |
| 2797 | |
| 2798 | // At least one float is present. We need to perform the clearance computation. |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2799 | UsedClear usedClear = RenderStyle::usedClear(child); |
| 2800 | bool clearSet = usedClear != UsedClear::None; |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 2801 | LayoutUnit logicalBottom; |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2802 | switch (usedClear) { |
| 2803 | case UsedClear::None: |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2804 | break; |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2805 | case UsedClear::Left: |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2806 | logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatLeft); |
| 2807 | break; |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2808 | case UsedClear::Right: |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2809 | logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatRight); |
| 2810 | break; |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 2811 | case UsedClear::Both: |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2812 | logicalBottom = lowestFloatLogicalBottom(); |
| 2813 | break; |
| 2814 | } |
| 2815 | |
| 2816 | // We also clear floats if we are too big to sit on the same line as a float (and wish to avoid floats by default). |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 2817 | LayoutUnit result = clearSet ? std::max<LayoutUnit>(0, logicalBottom - logicalTop) : 0_lu; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2818 | if (!result && child.avoidsFloats()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2819 | LayoutUnit newLogicalTop = logicalTop; |
| 2820 | while (true) { |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 2821 | LayoutUnit availableLogicalWidthAtNewLogicalTopOffset = availableLogicalWidthForLine(newLogicalTop, DoNotIndentText, logicalHeightForChild(child)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2822 | if (availableLogicalWidthAtNewLogicalTopOffset == availableLogicalWidthForContent(newLogicalTop)) |
| 2823 | return newLogicalTop - logicalTop; |
| 2824 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 2825 | RenderFragmentContainer* fragment = fragmentAtBlockOffset(logicalTopForChild(child)); |
| 2826 | LayoutRect borderBox = child.borderBoxRectInFragment(fragment, DoNotCacheRenderBoxFragmentInfo); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2827 | LayoutUnit childLogicalWidthAtOldLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height(); |
| 2828 | |
| 2829 | // FIXME: None of this is right for perpendicular writing-mode children. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2830 | LayoutUnit childOldLogicalWidth = child.logicalWidth(); |
| 2831 | LayoutUnit childOldMarginLeft = child.marginLeft(); |
| 2832 | LayoutUnit childOldMarginRight = child.marginRight(); |
| 2833 | LayoutUnit childOldLogicalTop = child.logicalTop(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2834 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2835 | child.setLogicalTop(newLogicalTop); |
| 2836 | child.updateLogicalWidth(); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 2837 | fragment = fragmentAtBlockOffset(logicalTopForChild(child)); |
| 2838 | borderBox = child.borderBoxRectInFragment(fragment, DoNotCacheRenderBoxFragmentInfo); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2839 | LayoutUnit childLogicalWidthAtNewLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height(); |
| 2840 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2841 | child.setLogicalTop(childOldLogicalTop); |
| 2842 | child.setLogicalWidth(childOldLogicalWidth); |
| 2843 | child.setMarginLeft(childOldMarginLeft); |
| 2844 | child.setMarginRight(childOldMarginRight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2845 | |
zalan@apple.com | 05c9d8e | 2022-05-24 18:48:31 +0000 | [diff] [blame] | 2846 | if (childLogicalWidthAtNewLogicalTopOffset <= availableLogicalWidthAtNewLogicalTopOffset) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2847 | // Even though we may not be moving, if the logical width did shrink because of the presence of new floats, then |
| 2848 | // we need to force a relayout as though we shifted. This happens because of the dynamic addition of overhanging floats |
| 2849 | // from previous siblings when negative margins exist on a child (see the addOverhangingFloats call at the end of collapseMargins). |
| 2850 | if (childLogicalWidthAtOldLogicalTopOffset != childLogicalWidthAtNewLogicalTopOffset) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2851 | child.setChildNeedsLayout(MarkOnlyThis); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2852 | return newLogicalTop - logicalTop; |
| 2853 | } |
| 2854 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2855 | newLogicalTop = nextFloatLogicalBottomBelowForBlock(newLogicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2856 | ASSERT(newLogicalTop >= logicalTop); |
| 2857 | if (newLogicalTop < logicalTop) |
| 2858 | break; |
| 2859 | } |
| 2860 | ASSERT_NOT_REACHED(); |
| 2861 | } |
| 2862 | return result; |
| 2863 | } |
| 2864 | |
| 2865 | bool RenderBlockFlow::hitTestFloats(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset) |
| 2866 | { |
| 2867 | if (!m_floatingObjects) |
| 2868 | return false; |
| 2869 | |
| 2870 | LayoutPoint adjustedLocation = accumulatedOffset; |
cdumez@apple.com | 3abcc79 | 2014-10-20 03:42:03 +0000 | [diff] [blame] | 2871 | if (is<RenderView>(*this)) |
| 2872 | adjustedLocation += toLayoutSize(downcast<RenderView>(*this).frameView().scrollPosition()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2873 | |
| 2874 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2875 | auto begin = floatingObjectSet.begin(); |
| 2876 | for (auto it = floatingObjectSet.end(); it != begin;) { |
| 2877 | --it; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2878 | const auto& floatingObject = *it->get(); |
| 2879 | auto& renderer = floatingObject.renderer(); |
simon.fraser@apple.com | bc9d13c | 2021-01-27 04:56:57 +0000 | [diff] [blame] | 2880 | if (floatingObject.shouldPaint()) { |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2881 | LayoutPoint childPoint = flipFloatForWritingModeForChild(floatingObject, adjustedLocation + floatingObject.translationOffsetToAncestor()); |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2882 | if (renderer.hitTest(request, result, locationInContainer, childPoint)) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2883 | updateHitTestResult(result, locationInContainer.point() - toLayoutSize(childPoint)); |
| 2884 | return true; |
| 2885 | } |
| 2886 | } |
| 2887 | } |
| 2888 | |
| 2889 | return false; |
| 2890 | } |
| 2891 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2892 | bool RenderBlockFlow::hitTestInlineChildren(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction) |
| 2893 | { |
| 2894 | ASSERT(childrenInline()); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2895 | |
antti@apple.com | 04bca45 | 2019-12-09 15:28:48 +0000 | [diff] [blame] | 2896 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 2897 | if (modernLineLayout()) |
| 2898 | return modernLineLayout()->hitTest(request, result, locationInContainer, accumulatedOffset, hitTestAction); |
antti@apple.com | 04bca45 | 2019-12-09 15:28:48 +0000 | [diff] [blame] | 2899 | #endif |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2900 | |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 2901 | return legacyLineLayout() && legacyLineLayout()->lineBoxes().hitTest(this, request, result, locationInContainer, accumulatedOffset, hitTestAction); |
antti@apple.com | 50b36fde | 2019-08-11 11:02:01 +0000 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | void RenderBlockFlow::addOverflowFromInlineChildren() |
| 2905 | { |
antti@apple.com | 4789a08 | 2019-12-08 15:30:50 +0000 | [diff] [blame] | 2906 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 2907 | if (modernLineLayout()) { |
| 2908 | modernLineLayout()->collectOverflow(); |
antti@apple.com | 4789a08 | 2019-12-08 15:30:50 +0000 | [diff] [blame] | 2909 | return; |
| 2910 | } |
| 2911 | #endif |
| 2912 | |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 2913 | if (legacyLineLayout()) |
| 2914 | legacyLineLayout()->addOverflowFromInlineChildren(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
antti@apple.com | 903292a | 2021-06-02 16:20:15 +0000 | [diff] [blame] | 2917 | void RenderBlockFlow::markLinesDirtyInBlockRange(LayoutUnit logicalTop, LayoutUnit logicalBottom, LegacyRootInlineBox* highest) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2918 | { |
| 2919 | if (logicalTop >= logicalBottom) |
| 2920 | return; |
| 2921 | |
antti@apple.com | d685c41 | 2019-12-07 13:56:51 +0000 | [diff] [blame] | 2922 | // Floats currently affect the choice of layout path. |
antti@apple.com | d685c41 | 2019-12-07 13:56:51 +0000 | [diff] [blame] | 2923 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 2924 | if (modernLineLayout()) { |
antti@apple.com | d685c41 | 2019-12-07 13:56:51 +0000 | [diff] [blame] | 2925 | invalidateLineLayoutPath(); |
| 2926 | return; |
| 2927 | } |
| 2928 | #endif |
| 2929 | |
antti@apple.com | 903292a | 2021-06-02 16:20:15 +0000 | [diff] [blame] | 2930 | LegacyRootInlineBox* lowestDirtyLine = lastRootBox(); |
| 2931 | LegacyRootInlineBox* afterLowest = lowestDirtyLine; |
antti@apple.com | 657a14e | 2020-10-29 15:51:07 +0000 | [diff] [blame] | 2932 | while (lowestDirtyLine && lowestDirtyLine->lineBoxBottom() >= logicalBottom && logicalBottom < LayoutUnit::max()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2933 | afterLowest = lowestDirtyLine; |
| 2934 | lowestDirtyLine = lowestDirtyLine->prevRootBox(); |
| 2935 | } |
| 2936 | |
antti@apple.com | 657a14e | 2020-10-29 15:51:07 +0000 | [diff] [blame] | 2937 | while (afterLowest && afterLowest != highest && (afterLowest->lineBoxBottom() >= logicalTop || afterLowest->lineBoxBottom() < 0)) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2938 | afterLowest->markDirty(); |
| 2939 | afterLowest = afterLowest->prevRootBox(); |
| 2940 | } |
| 2941 | } |
| 2942 | |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 2943 | std::optional<LayoutUnit> RenderBlockFlow::firstLineBaseline() const |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2944 | { |
jfernandez@igalia.com | f119ec1 | 2018-11-23 11:04:23 +0000 | [diff] [blame] | 2945 | if (isWritingModeRoot() && !isRubyRun() && !isGridItem()) |
darin@apple.com | 7c840b6 | 2021-05-28 01:26:23 +0000 | [diff] [blame] | 2946 | return std::nullopt; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2947 | |
simon.fraser@apple.com | e8ee49b | 2022-05-06 17:10:31 +0000 | [diff] [blame] | 2948 | if (shouldApplyLayoutContainment()) |
darin@apple.com | 7c840b6 | 2021-05-28 01:26:23 +0000 | [diff] [blame] | 2949 | return std::nullopt; |
commit-queue@webkit.org | 71fc28e | 2021-04-19 06:13:38 +0000 | [diff] [blame] | 2950 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2951 | if (!childrenInline()) |
antti@apple.com | 0e632aa | 2013-10-22 21:03:38 +0000 | [diff] [blame] | 2952 | return RenderBlock::firstLineBaseline(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2953 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2954 | if (!hasLines()) |
darin@apple.com | 7c840b6 | 2021-05-28 01:26:23 +0000 | [diff] [blame] | 2955 | return std::nullopt; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2956 | |
antti@apple.com | d685c41 | 2019-12-07 13:56:51 +0000 | [diff] [blame] | 2957 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 2958 | if (modernLineLayout()) |
zalan@apple.com | 7474118 | 2022-02-16 17:29:44 +0000 | [diff] [blame] | 2959 | return LayoutUnit { floorToInt(modernLineLayout()->firstLinePhysicalBaseline()) }; |
antti@apple.com | d685c41 | 2019-12-07 13:56:51 +0000 | [diff] [blame] | 2960 | #endif |
| 2961 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 2962 | ASSERT(firstRootBox()); |
jfernandez@igalia.com | be5a04c | 2018-11-22 08:45:48 +0000 | [diff] [blame] | 2963 | if (style().isFlippedLinesWritingMode()) |
mmaxfield@apple.com | 881a936 | 2022-02-02 05:12:47 +0000 | [diff] [blame] | 2964 | return LayoutUnit { firstRootBox()->logicalTop() + firstLineStyle().metricsOfPrimaryFont().descent(firstRootBox()->baselineType()) }; |
| 2965 | return LayoutUnit { firstRootBox()->logicalTop() + firstLineStyle().metricsOfPrimaryFont().ascent(firstRootBox()->baselineType()) }; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2966 | } |
| 2967 | |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 2968 | std::optional<LayoutUnit> RenderBlockFlow::inlineBlockBaseline(LineDirectionMode lineDirection) const |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2969 | { |
| 2970 | if (isWritingModeRoot() && !isRubyRun()) |
darin@apple.com | 7c840b6 | 2021-05-28 01:26:23 +0000 | [diff] [blame] | 2971 | return std::nullopt; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2972 | |
simon.fraser@apple.com | e8ee49b | 2022-05-06 17:10:31 +0000 | [diff] [blame] | 2973 | if (shouldApplyLayoutContainment()) |
commit-queue@webkit.org | 71fc28e | 2021-04-19 06:13:38 +0000 | [diff] [blame] | 2974 | return RenderBlock::inlineBlockBaseline(lineDirection); |
| 2975 | |
zalan@apple.com | 7b0eeb4 | 2021-01-09 13:14:18 +0000 | [diff] [blame] | 2976 | if (style().display() == DisplayType::InlineBlock) { |
| 2977 | // The baseline of an 'inline-block' is the baseline of its last line box in the normal flow, unless it has either no in-flow line boxes or if its 'overflow' |
| 2978 | // property has a computed value other than 'visible'. see https://www.w3.org/TR/CSS22/visudet.html |
| 2979 | auto shouldSynthesizeBaseline = !style().isOverflowVisible() && !is<HTMLFormControlElement>(element()); |
| 2980 | if (shouldSynthesizeBaseline) |
darin@apple.com | 7c840b6 | 2021-05-28 01:26:23 +0000 | [diff] [blame] | 2981 | return std::nullopt; |
zalan@apple.com | 7b0eeb4 | 2021-01-09 13:14:18 +0000 | [diff] [blame] | 2982 | } |
mmaxfield@apple.com | 9f4af63 | 2015-03-09 23:43:34 +0000 | [diff] [blame] | 2983 | // Note that here we only take the left and bottom into consideration. Our caller takes the right and top into consideration. |
commit-queue@webkit.org | 7b557b4 | 2021-04-06 08:37:33 +0000 | [diff] [blame] | 2984 | float boxHeight = synthesizedBaselineFromBorderBox(*this, lineDirection) + (lineDirection == HorizontalLine ? m_marginBox.bottom() : m_marginBox.left()); |
antti@apple.com | 55d5afa | 2020-09-25 13:16:23 +0000 | [diff] [blame] | 2985 | float lastBaseline = 0; |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 2986 | if (!childrenInline()) { |
commit-queue@webkit.org | e93d4f0 | 2021-04-02 09:07:41 +0000 | [diff] [blame] | 2987 | auto inlineBlockBaseline = RenderBlock::inlineBlockBaseline(lineDirection); |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 2988 | if (!inlineBlockBaseline) |
| 2989 | return inlineBlockBaseline; |
| 2990 | lastBaseline = inlineBlockBaseline.value(); |
| 2991 | } else { |
mmaxfield@apple.com | a52ab46 | 2015-03-11 14:41:01 +0000 | [diff] [blame] | 2992 | if (!hasLines()) { |
| 2993 | if (!hasLineIfEmpty()) |
darin@apple.com | 7c840b6 | 2021-05-28 01:26:23 +0000 | [diff] [blame] | 2994 | return std::nullopt; |
mmaxfield@apple.com | 881a936 | 2022-02-02 05:12:47 +0000 | [diff] [blame] | 2995 | const auto& fontMetrics = firstLineStyle().metricsOfPrimaryFont(); |
commit-queue@webkit.org | e93d4f0 | 2021-04-02 09:07:41 +0000 | [diff] [blame] | 2996 | return LayoutUnit { LayoutUnit(fontMetrics.ascent() |
mmaxfield@apple.com | a52ab46 | 2015-03-11 14:41:01 +0000 | [diff] [blame] | 2997 | + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - fontMetrics.height()) / 2 |
commit-queue@webkit.org | e93d4f0 | 2021-04-02 09:07:41 +0000 | [diff] [blame] | 2998 | + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : borderRight() + paddingRight())).toInt() }; |
mmaxfield@apple.com | a52ab46 | 2015-03-11 14:41:01 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 3001 | if (legacyLineLayout()) { |
mmaxfield@apple.com | a52ab46 | 2015-03-11 14:41:01 +0000 | [diff] [blame] | 3002 | bool isFirstLine = lastRootBox() == firstRootBox(); |
| 3003 | const auto& style = isFirstLine ? firstLineStyle() : this->style(); |
antti@apple.com | b1ddc66 | 2021-06-03 13:39:56 +0000 | [diff] [blame] | 3004 | // LegacyInlineFlowBox::placeBoxesInBlockDirection will flip lines in case of verticalLR mode, so we can assume verticalRL for now. |
mmaxfield@apple.com | 881a936 | 2022-02-02 05:12:47 +0000 | [diff] [blame] | 3005 | lastBaseline = style.metricsOfPrimaryFont().ascent(lastRootBox()->baselineType()) |
jfernandez@igalia.com | 7e696b9 | 2018-02-01 01:56:52 +0000 | [diff] [blame] | 3006 | + (style.isFlippedLinesWritingMode() ? logicalHeight() - lastRootBox()->logicalBottom() : lastRootBox()->logicalTop()); |
mmaxfield@apple.com | a52ab46 | 2015-03-11 14:41:01 +0000 | [diff] [blame] | 3007 | } |
antti@apple.com | 55d5afa | 2020-09-25 13:16:23 +0000 | [diff] [blame] | 3008 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 3009 | else if (modernLineLayout()) |
zalan@apple.com | 7474118 | 2022-02-16 17:29:44 +0000 | [diff] [blame] | 3010 | lastBaseline = floorToInt(modernLineLayout()->lastLineLogicalBaseline()); |
antti@apple.com | 55d5afa | 2020-09-25 13:16:23 +0000 | [diff] [blame] | 3011 | #endif |
mmaxfield@apple.com | 9f4af63 | 2015-03-09 23:43:34 +0000 | [diff] [blame] | 3012 | } |
| 3013 | // According to the CSS spec http://www.w3.org/TR/CSS21/visudet.html, we shouldn't be performing this min, but should |
| 3014 | // instead be returning boxHeight directly. However, we feel that a min here is better behavior (and is consistent |
| 3015 | // enough with the spec to not cause tons of breakages). |
commit-queue@webkit.org | e93d4f0 | 2021-04-02 09:07:41 +0000 | [diff] [blame] | 3016 | return LayoutUnit { style().overflowY() == Overflow::Visible ? lastBaseline : std::min(boxHeight, lastBaseline) }; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3017 | } |
| 3018 | |
zalan@apple.com | c6d5b44 | 2022-03-15 21:17:33 +0000 | [diff] [blame] | 3019 | LayoutUnit RenderBlockFlow::adjustEnclosingTopForPrecedingBlock(LayoutUnit top) const |
antti@apple.com | 9081c9f | 2021-09-16 19:19:39 +0000 | [diff] [blame] | 3020 | { |
| 3021 | if (selectionState() != RenderObject::HighlightState::Inside && selectionState() != RenderObject::HighlightState::End) |
| 3022 | return top; |
| 3023 | |
| 3024 | if (isSelectionRoot()) |
| 3025 | return top; |
| 3026 | |
| 3027 | LayoutSize offsetToBlockBefore; |
| 3028 | |
| 3029 | auto blockBeforeWithinSelectionRoot = [&]() -> const RenderBlockFlow* { |
| 3030 | const RenderElement* object = this; |
| 3031 | const RenderObject* sibling = nullptr; |
| 3032 | do { |
| 3033 | sibling = object->previousSibling(); |
| 3034 | while (sibling && (!is<RenderBlock>(*sibling) || downcast<RenderBlock>(*sibling).isSelectionRoot())) |
| 3035 | sibling = sibling->previousSibling(); |
| 3036 | |
| 3037 | offsetToBlockBefore -= LayoutSize(downcast<RenderBlock>(*object).logicalLeft(), downcast<RenderBlock>(*object).logicalTop()); |
| 3038 | object = object->parent(); |
| 3039 | } while (!sibling && is<RenderBlock>(object) && !downcast<RenderBlock>(*object).isSelectionRoot()); |
| 3040 | |
| 3041 | if (!sibling) |
| 3042 | return nullptr; |
| 3043 | |
| 3044 | auto* beforeBlock = downcast<RenderBlock>(sibling); |
| 3045 | |
| 3046 | offsetToBlockBefore += LayoutSize(beforeBlock->logicalLeft(), beforeBlock->logicalTop()); |
| 3047 | |
| 3048 | auto* child = beforeBlock->lastChild(); |
| 3049 | while (is<RenderBlock>(child)) { |
| 3050 | beforeBlock = downcast<RenderBlock>(child); |
| 3051 | offsetToBlockBefore += LayoutSize(beforeBlock->logicalLeft(), beforeBlock->logicalTop()); |
| 3052 | child = beforeBlock->lastChild(); |
| 3053 | } |
| 3054 | return is<RenderBlockFlow>(beforeBlock) ? downcast<RenderBlockFlow>(beforeBlock) : nullptr; |
| 3055 | }; |
| 3056 | |
| 3057 | auto* blockBefore = blockBeforeWithinSelectionRoot(); |
| 3058 | if (!blockBefore) |
| 3059 | return top; |
| 3060 | |
| 3061 | // Do not adjust blocks sharing the same line. |
| 3062 | if (!offsetToBlockBefore.height()) |
| 3063 | return top; |
| 3064 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3065 | if (auto lastLineBox = InlineIterator::lastLineBoxFor(*blockBefore)) { |
| 3066 | auto lastLineSelectionState = LineSelection::selectionState(*lastLineBox); |
antti@apple.com | 9081c9f | 2021-09-16 19:19:39 +0000 | [diff] [blame] | 3067 | if (lastLineSelectionState != RenderObject::HighlightState::Inside && lastLineSelectionState != RenderObject::HighlightState::Start) |
| 3068 | return top; |
| 3069 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3070 | auto lastLineSelectionBottom = LineSelection::logicalBottom(*lastLineBox) + offsetToBlockBefore.height(); |
zalan@apple.com | c7af235 | 2022-03-20 00:45:31 +0000 | [diff] [blame] | 3071 | top = std::max(top, LayoutUnit { lastLineSelectionBottom }); |
antti@apple.com | 9081c9f | 2021-09-16 19:19:39 +0000 | [diff] [blame] | 3072 | } |
| 3073 | return top; |
| 3074 | } |
| 3075 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 3076 | GapRects RenderBlockFlow::inlineSelectionGaps(RenderBlock& rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3077 | LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const LogicalSelectionOffsetCaches& cache, const PaintInfo* paintInfo) |
| 3078 | { |
megan_gardner@apple.com | c66f2b8 | 2020-02-10 19:32:19 +0000 | [diff] [blame] | 3079 | bool containsStart = selectionState() == HighlightState::Start || selectionState() == HighlightState::Both; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3080 | |
antti@apple.com | 0e632aa | 2013-10-22 21:03:38 +0000 | [diff] [blame] | 3081 | if (!hasLines()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3082 | if (containsStart) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 3083 | // Update our lastLogicalTop to be the bottom of the block. <hr>s or empty blocks with height can trip this case. |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3084 | lastLogicalTop = blockDirectionOffset(rootBlock, offsetFromRootBlock) + logicalHeight(); |
| 3085 | lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, logicalHeight(), cache); |
| 3086 | lastLogicalRight = logicalRightSelectionOffset(rootBlock, logicalHeight(), cache); |
| 3087 | } |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3088 | return { }; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3089 | } |
| 3090 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3091 | auto hasSelectedChildren = [&](const InlineIterator::LineBoxIterator& lineBox) { |
| 3092 | return LineSelection::selectionState(*lineBox) != RenderObject::HighlightState::None; |
antti@apple.com | 40042cf | 2021-01-10 12:04:02 +0000 | [diff] [blame] | 3093 | }; |
| 3094 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3095 | auto lineSelectionGap = [&](const InlineIterator::LineBoxIterator& lineBox, LayoutUnit selTop, LayoutUnit selHeight) -> GapRects { |
| 3096 | auto lineState = LineSelection::selectionState(*lineBox); |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3097 | |
| 3098 | bool leftGap, rightGap; |
| 3099 | getSelectionGapInfo(lineState, leftGap, rightGap); |
| 3100 | |
| 3101 | GapRects result; |
| 3102 | |
zalan@apple.com | 8bcfa32 | 2022-03-16 14:41:56 +0000 | [diff] [blame] | 3103 | auto firstSelectedBox = [&]() -> InlineIterator::LeafBoxIterator { |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3104 | for (auto box = lineBox->firstLeafBox(); box; box.traverseNextOnLine()) { |
zalan@apple.com | 8bcfa32 | 2022-03-16 14:41:56 +0000 | [diff] [blame] | 3105 | if (box->selectionState() != RenderObject::HighlightState::None) |
| 3106 | return box; |
| 3107 | } |
| 3108 | return { }; |
| 3109 | }(); |
| 3110 | |
| 3111 | auto lastSelectedBox = [&]() -> InlineIterator::LeafBoxIterator { |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3112 | for (auto box = lineBox->lastLeafBox(); box; box.traversePreviousOnLine()) { |
zalan@apple.com | 8bcfa32 | 2022-03-16 14:41:56 +0000 | [diff] [blame] | 3113 | if (box->selectionState() != RenderObject::HighlightState::None) |
| 3114 | return box; |
| 3115 | } |
| 3116 | return { }; |
| 3117 | }(); |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3118 | |
| 3119 | if (leftGap) { |
zalan@apple.com | 8bcfa32 | 2022-03-16 14:41:56 +0000 | [diff] [blame] | 3120 | result.uniteLeft(logicalLeftSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, firstSelectedBox->renderer().parent(), LayoutUnit(firstSelectedBox->logicalLeft()), |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3121 | selTop, selHeight, cache, paintInfo)); |
| 3122 | } |
| 3123 | if (rightGap) { |
zalan@apple.com | 8bcfa32 | 2022-03-16 14:41:56 +0000 | [diff] [blame] | 3124 | result.uniteRight(logicalRightSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, lastSelectedBox->renderer().parent(), LayoutUnit(lastSelectedBox->logicalRight()), |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3125 | selTop, selHeight, cache, paintInfo)); |
| 3126 | } |
| 3127 | |
| 3128 | // When dealing with bidi text, a non-contiguous selection region is possible. |
| 3129 | // e.g. The logical text aaaAAAbbb (capitals denote RTL text and non-capitals LTR) is layed out |
| 3130 | // visually as 3 text runs |aaa|bbb|AAA| if we select 4 characters from the start of the text the |
| 3131 | // selection will look like (underline denotes selection): |
| 3132 | // |aaa|bbb|AAA| |
| 3133 | // ___ _ |
| 3134 | // We can see that the |bbb| run is not part of the selection while the runs around it are. |
zalan@apple.com | 8bcfa32 | 2022-03-16 14:41:56 +0000 | [diff] [blame] | 3135 | if (firstSelectedBox && firstSelectedBox != lastSelectedBox) { |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3136 | // Now fill in any gaps on the line that occurred between two selected elements. |
zalan@apple.com | 8bcfa32 | 2022-03-16 14:41:56 +0000 | [diff] [blame] | 3137 | LayoutUnit lastLogicalLeft { firstSelectedBox->logicalRight() }; |
| 3138 | bool isPreviousBoxSelected = firstSelectedBox->selectionState() != RenderObject::HighlightState::None; |
| 3139 | for (auto box = firstSelectedBox; box; box.traverseNextOnLine()) { |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3140 | if (box->selectionState() != RenderObject::HighlightState::None) { |
| 3141 | LayoutRect logicalRect { lastLogicalLeft, selTop, LayoutUnit(box->logicalLeft() - lastLogicalLeft), selHeight }; |
| 3142 | logicalRect.move(isHorizontalWritingMode() ? offsetFromRootBlock : LayoutSize(offsetFromRootBlock.height(), offsetFromRootBlock.width())); |
| 3143 | LayoutRect gapRect = rootBlock.logicalRectToPhysicalRect(rootBlockPhysicalPosition, logicalRect); |
| 3144 | if (isPreviousBoxSelected && gapRect.width() > 0 && gapRect.height() > 0) { |
| 3145 | if (paintInfo && box->renderer().parent()->style().visibility() == Visibility::Visible) |
| 3146 | paintInfo->context().fillRect(gapRect, box->renderer().parent()->selectionBackgroundColor()); |
| 3147 | // VisibleSelection may be non-contiguous, see comment above. |
| 3148 | result.uniteCenter(gapRect); |
| 3149 | } |
| 3150 | lastLogicalLeft = box->logicalRight(); |
| 3151 | } |
zalan@apple.com | 8bcfa32 | 2022-03-16 14:41:56 +0000 | [diff] [blame] | 3152 | if (box == lastSelectedBox) |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3153 | break; |
| 3154 | isPreviousBoxSelected = box->selectionState() != RenderObject::HighlightState::None; |
| 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | return result; |
| 3159 | }; |
| 3160 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3161 | InlineIterator::LineBoxIterator lastSelectedLineBox; |
| 3162 | auto lineBox = InlineIterator::firstLineBoxFor(*this); |
| 3163 | for (; lineBox && !hasSelectedChildren(lineBox); lineBox.traverseNext()) { } |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3164 | |
| 3165 | GapRects result; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3166 | |
| 3167 | // Now paint the gaps for the lines. |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3168 | for (; lineBox && hasSelectedChildren(lineBox); lineBox.traverseNext()) { |
| 3169 | auto selectionTop = LayoutUnit { LineSelection::logicalTopAdjustedForPrecedingBlock(*lineBox) }; |
| 3170 | auto selectionHeight = LayoutUnit { std::max(0.f, LineSelection::logicalBottom(*lineBox) - selectionTop) }; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3171 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3172 | if (!containsStart && !lastSelectedLineBox |
| 3173 | && selectionState() != HighlightState::Start |
| 3174 | && selectionState() != HighlightState::Both && !isRubyBase()) |
zalan@apple.com | 928aaf9 | 2022-03-18 02:30:52 +0000 | [diff] [blame] | 3175 | result.uniteCenter(blockSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, lastLogicalTop, lastLogicalLeft, lastLogicalRight, selectionTop, cache, paintInfo)); |
antti@apple.com | f8a9ad8 | 2021-09-19 16:42:57 +0000 | [diff] [blame] | 3176 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3177 | LayoutRect logicalRect { LayoutUnit(lineBox->contentLogicalLeft()), selectionTop, LayoutUnit(lineBox->contentLogicalWidth()), selectionTop + selectionHeight }; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3178 | logicalRect.move(isHorizontalWritingMode() ? offsetFromRootBlock : offsetFromRootBlock.transposedSize()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 3179 | LayoutRect physicalRect = rootBlock.logicalRectToPhysicalRect(rootBlockPhysicalPosition, logicalRect); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3180 | if (!paintInfo || (isHorizontalWritingMode() && physicalRect.y() < paintInfo->rect.maxY() && physicalRect.maxY() > paintInfo->rect.y()) |
| 3181 | || (!isHorizontalWritingMode() && physicalRect.x() < paintInfo->rect.maxX() && physicalRect.maxX() > paintInfo->rect.x())) |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3182 | result.unite(lineSelectionGap(lineBox, selectionTop, selectionHeight)); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3183 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3184 | lastSelectedLineBox = lineBox; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3185 | } |
| 3186 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3187 | if (containsStart && !lastSelectedLineBox) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3188 | // VisibleSelection must start just after our last line. |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3189 | lastSelectedLineBox = InlineIterator::lastLineBoxFor(*this); |
| 3190 | } |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3191 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3192 | if (lastSelectedLineBox && selectionState() != HighlightState::End && selectionState() != HighlightState::Both) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 3193 | // Update our lastY to be the bottom of the last selected line. |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3194 | auto lastLineSelectionBottom = LayoutUnit { LineSelection::logicalBottom(*lastSelectedLineBox) }; |
zalan@apple.com | cebeed7 | 2022-03-17 15:24:31 +0000 | [diff] [blame] | 3195 | lastLogicalTop = blockDirectionOffset(rootBlock, offsetFromRootBlock) + lastLineSelectionBottom; |
| 3196 | lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, lastLineSelectionBottom, cache); |
| 3197 | lastLogicalRight = logicalRightSelectionOffset(rootBlock, lastLineSelectionBottom, cache); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3198 | } |
| 3199 | return result; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 3202 | bool RenderBlockFlow::needsLayoutAfterFragmentRangeChange() const |
abucur@adobe.com | eaf5e22 | 2014-05-14 14:35:07 +0000 | [diff] [blame] | 3203 | { |
| 3204 | // A block without floats or that expands to enclose them won't need a relayout |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 3205 | // after a fragment range change. There is no overflow content needing relayout |
| 3206 | // in the fragment chain because the fragment range can only shrink after the estimation. |
jfernandez@igalia.com | 136f170 | 2014-12-08 19:13:16 +0000 | [diff] [blame] | 3207 | if (!containsFloats() || createsNewFormattingContext()) |
abucur@adobe.com | eaf5e22 | 2014-05-14 14:35:07 +0000 | [diff] [blame] | 3208 | return false; |
| 3209 | |
| 3210 | return true; |
| 3211 | } |
| 3212 | |
zalan@apple.com | 624c264 | 2017-10-05 14:04:27 +0000 | [diff] [blame] | 3213 | void RenderBlockFlow::setMultiColumnFlow(RenderMultiColumnFlow& fragmentedFlow) |
hyatt@apple.com | e9fe3d3 | 2014-01-24 17:14:22 +0000 | [diff] [blame] | 3214 | { |
zalan@apple.com | 624c264 | 2017-10-05 14:04:27 +0000 | [diff] [blame] | 3215 | ASSERT(!hasRareBlockFlowData() || !rareBlockFlowData()->m_multiColumnFlow); |
cdumez@apple.com | f440d4c | 2021-10-13 15:37:52 +0000 | [diff] [blame] | 3216 | ensureRareBlockFlowData().m_multiColumnFlow = fragmentedFlow; |
zalan@apple.com | 624c264 | 2017-10-05 14:04:27 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | void RenderBlockFlow::clearMultiColumnFlow() |
| 3220 | { |
| 3221 | ASSERT(hasRareBlockFlowData()); |
| 3222 | ASSERT(rareBlockFlowData()->m_multiColumnFlow); |
| 3223 | rareBlockFlowData()->m_multiColumnFlow.clear(); |
hyatt@apple.com | e9fe3d3 | 2014-01-24 17:14:22 +0000 | [diff] [blame] | 3224 | } |
| 3225 | |
antti@apple.com | 702ef7d | 2019-12-06 14:37:43 +0000 | [diff] [blame] | 3226 | int RenderBlockFlow::lineCount() const |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3227 | { |
zalan@apple.com | 93658f6 | 2022-04-10 21:56:21 +0000 | [diff] [blame] | 3228 | if (!childrenInline()) { |
| 3229 | ASSERT_NOT_REACHED(); |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3230 | return 0; |
zalan@apple.com | 93658f6 | 2022-04-10 21:56:21 +0000 | [diff] [blame] | 3231 | } |
antti@apple.com | 702ef7d | 2019-12-06 14:37:43 +0000 | [diff] [blame] | 3232 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
zalan@apple.com | 93658f6 | 2022-04-10 21:56:21 +0000 | [diff] [blame] | 3233 | if (modernLineLayout()) |
| 3234 | return modernLineLayout()->lineCount(); |
antti@apple.com | 702ef7d | 2019-12-06 14:37:43 +0000 | [diff] [blame] | 3235 | #endif |
zalan@apple.com | 93658f6 | 2022-04-10 21:56:21 +0000 | [diff] [blame] | 3236 | if (legacyLineLayout()) |
| 3237 | return legacyLineLayout()->lineCount(); |
antti@apple.com | 702ef7d | 2019-12-06 14:37:43 +0000 | [diff] [blame] | 3238 | |
zalan@apple.com | 93658f6 | 2022-04-10 21:56:21 +0000 | [diff] [blame] | 3239 | return 0; |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3240 | } |
| 3241 | |
weinig@apple.com | 3f23b38 | 2013-10-19 20:26:58 +0000 | [diff] [blame] | 3242 | bool RenderBlockFlow::containsNonZeroBidiLevel() const |
| 3243 | { |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3244 | for (auto lineBox = InlineIterator::firstLineBoxFor(*this); lineBox; lineBox.traverseNext()) { |
| 3245 | for (auto box = lineBox->firstLeafBox(); box; box = box.traverseNextOnLine()) { |
weinig@apple.com | 3f23b38 | 2013-10-19 20:26:58 +0000 | [diff] [blame] | 3246 | if (box->bidiLevel()) |
| 3247 | return true; |
| 3248 | } |
| 3249 | } |
| 3250 | return false; |
| 3251 | } |
| 3252 | |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3253 | static Position positionForRun(const RenderBlockFlow& flow, InlineIterator::BoxIterator box, bool start) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3254 | { |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3255 | if (!box) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3256 | return Position(); |
| 3257 | |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3258 | if (!box->renderer().nonPseudoNode()) |
antti@apple.com | 4c0c397 | 2020-10-29 14:21:34 +0000 | [diff] [blame] | 3259 | return makeDeprecatedLegacyPosition(flow.nonPseudoElement(), start ? flow.caretMinOffset() : flow.caretMaxOffset()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3260 | |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3261 | if (!is<InlineIterator::TextBoxIterator>(box)) |
| 3262 | return makeDeprecatedLegacyPosition(box->renderer().nonPseudoNode(), start ? box->renderer().caretMinOffset() : box->renderer().caretMaxOffset()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3263 | |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3264 | auto& textBox = downcast<InlineIterator::TextBoxIterator>(box); |
| 3265 | return makeDeprecatedLegacyPosition(textBox->renderer().nonPseudoNode(), start ? textBox->start() : textBox->end()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3266 | } |
| 3267 | |
enrica@apple.com | 0db51a6 | 2016-04-27 23:53:08 +0000 | [diff] [blame] | 3268 | RenderText* RenderBlockFlow::findClosestTextAtAbsolutePoint(const FloatPoint& point) |
| 3269 | { |
| 3270 | // A light, non-recursive version of RenderBlock::positionForCoordinates that looks at |
| 3271 | // whether a point lies within the gaps between its root line boxes, to be called against |
| 3272 | // a node returned from elementAtPoint. We make the assumption that either the node or one |
| 3273 | // of its immediate children contains the root line boxes in question. |
| 3274 | // See <rdar://problem/6824650> for context. |
| 3275 | |
| 3276 | RenderBlock* block = this; |
| 3277 | |
| 3278 | FloatPoint localPoint = block->absoluteToLocal(point); |
| 3279 | |
| 3280 | if (!block->childrenInline()) { |
| 3281 | // Look among our immediate children for an alternate box that contains the point. |
| 3282 | for (RenderBox* child = block->firstChildBox(); child; child = child->nextSiblingBox()) { |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 3283 | if (!child->height() || child->style().visibility() != WebCore::Visibility::Visible || child->isFloatingOrOutOfFlowPositioned()) |
enrica@apple.com | 0db51a6 | 2016-04-27 23:53:08 +0000 | [diff] [blame] | 3284 | continue; |
| 3285 | float top = child->y(); |
| 3286 | |
| 3287 | RenderBox* nextChild = child->nextSiblingBox(); |
| 3288 | while (nextChild && nextChild->isFloatingOrOutOfFlowPositioned()) |
| 3289 | nextChild = nextChild->nextSiblingBox(); |
| 3290 | if (!nextChild) { |
| 3291 | if (localPoint.y() >= top) { |
| 3292 | block = downcast<RenderBlock>(child); |
| 3293 | break; |
| 3294 | } |
| 3295 | continue; |
| 3296 | } |
| 3297 | |
| 3298 | float bottom = nextChild->y(); |
| 3299 | |
| 3300 | if (localPoint.y() >= top && localPoint.y() < bottom && is<RenderBlock>(*child)) { |
| 3301 | block = downcast<RenderBlock>(child); |
| 3302 | break; |
| 3303 | } |
| 3304 | } |
| 3305 | |
| 3306 | if (!block->childrenInline()) |
| 3307 | return nullptr; |
| 3308 | |
| 3309 | localPoint = block->absoluteToLocal(point); |
| 3310 | } |
| 3311 | |
| 3312 | RenderBlockFlow& blockFlow = downcast<RenderBlockFlow>(*block); |
| 3313 | |
| 3314 | // Only check the gaps between the root line boxes. We deliberately ignore overflow because |
| 3315 | // experience has shown that hit tests on an exploded text node can fail when within the |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 3316 | // overflow fragment. |
zalan@apple.com | fa6423d | 2022-03-12 14:30:45 +0000 | [diff] [blame] | 3317 | auto previousRootInlineBoxBottom = std::optional<float> { }; |
| 3318 | for (auto box = InlineIterator::firstRootInlineBoxFor(blockFlow); box; box.traverseNextInlineBox()) { |
| 3319 | if (previousRootInlineBoxBottom) { |
| 3320 | if (localPoint.y() < *previousRootInlineBoxBottom) |
| 3321 | return nullptr; |
| 3322 | |
| 3323 | if (localPoint.y() > *previousRootInlineBoxBottom && localPoint.y() < box->logicalTop()) { |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3324 | auto closestBox = closestBoxForHorizontalPosition(*box->lineBox(), localPoint.x()); |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3325 | if (closestBox && is<RenderText>(closestBox->renderer())) |
| 3326 | return const_cast<RenderText*>(&downcast<RenderText>(closestBox->renderer())); |
zalan@apple.com | fa6423d | 2022-03-12 14:30:45 +0000 | [diff] [blame] | 3327 | } |
enrica@apple.com | 0db51a6 | 2016-04-27 23:53:08 +0000 | [diff] [blame] | 3328 | } |
zalan@apple.com | fa6423d | 2022-03-12 14:30:45 +0000 | [diff] [blame] | 3329 | previousRootInlineBoxBottom = box->logicalBottom(); |
enrica@apple.com | 0db51a6 | 2016-04-27 23:53:08 +0000 | [diff] [blame] | 3330 | } |
| 3331 | return nullptr; |
| 3332 | } |
| 3333 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 3334 | VisiblePosition RenderBlockFlow::positionForPointWithInlineChildren(const LayoutPoint& pointInLogicalContents, const RenderFragmentContainer* fragment) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3335 | { |
| 3336 | ASSERT(childrenInline()); |
| 3337 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3338 | auto firstLineBox = InlineIterator::firstLineBoxFor(*this); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3339 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3340 | if (!firstLineBox) |
darin@apple.com | c8d8b55 | 2020-09-03 21:38:50 +0000 | [diff] [blame] | 3341 | return createVisiblePosition(0, Affinity::Downstream); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3342 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 3343 | bool linesAreFlipped = style().isFlippedLinesWritingMode(); |
| 3344 | bool blocksAreFlipped = style().isFlippedBlocksWritingMode(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3345 | |
| 3346 | // look for the closest line box in the root box which is at the passed-in y coordinate |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3347 | InlineIterator::LeafBoxIterator closestBox; |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3348 | InlineIterator::LineBoxIterator firstLineBoxWithChildren; |
| 3349 | InlineIterator::LineBoxIterator lastLineBoxWithChildren; |
| 3350 | for (auto lineBox = firstLineBox; lineBox; lineBox.traverseNext()) { |
| 3351 | if (fragment && lineBox->containingFragment() != fragment) |
stavila@adobe.com | 4ce2fff | 2014-04-25 13:56:12 +0000 | [diff] [blame] | 3352 | continue; |
| 3353 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3354 | if (!lineBox->firstLeafBox()) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3355 | continue; |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3356 | if (!firstLineBoxWithChildren) |
| 3357 | firstLineBoxWithChildren = lineBox; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3358 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3359 | if (!linesAreFlipped && lineBox->isFirstAfterPageBreak() |
| 3360 | && (pointInLogicalContents.y() < lineBox->top() || (blocksAreFlipped && pointInLogicalContents.y() == lineBox->top()))) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3361 | break; |
| 3362 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3363 | lastLineBoxWithChildren = lineBox; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3364 | |
| 3365 | // check if this root line box is located at this y coordinate |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3366 | auto selectionBottom = LineSelection::logicalBottom(*lineBox); |
zalan@apple.com | cebeed7 | 2022-03-17 15:24:31 +0000 | [diff] [blame] | 3367 | if (pointInLogicalContents.y() < selectionBottom || (blocksAreFlipped && pointInLogicalContents.y() == selectionBottom)) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3368 | if (linesAreFlipped) { |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3369 | auto nextLineBoxWithChildren = lineBox->next(); |
| 3370 | while (nextLineBoxWithChildren && !nextLineBoxWithChildren->firstLeafBox()) |
| 3371 | nextLineBoxWithChildren.traverseNext(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3372 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3373 | if (nextLineBoxWithChildren && nextLineBoxWithChildren->isFirstAfterPageBreak() |
| 3374 | && (pointInLogicalContents.y() > nextLineBoxWithChildren->top() || (!blocksAreFlipped && pointInLogicalContents.y() == nextLineBoxWithChildren->top()))) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3375 | continue; |
| 3376 | } |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3377 | closestBox = closestBoxForHorizontalPosition(*lineBox, pointInLogicalContents.x()); |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3378 | if (closestBox) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3379 | break; |
| 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | bool moveCaretToBoundary = frame().editor().behavior().shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom(); |
| 3384 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3385 | if (!moveCaretToBoundary && !closestBox && lastLineBoxWithChildren) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3386 | // y coordinate is below last root line box, pretend we hit it |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3387 | closestBox = closestBoxForHorizontalPosition(*lastLineBoxWithChildren, pointInLogicalContents.x()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3390 | if (closestBox) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3391 | if (moveCaretToBoundary) { |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3392 | auto firstLineWithChildrenTop = LayoutUnit { std::min(previousLineBoxContentBottomOrBorderAndPadding(*firstLineBoxWithChildren), firstLineBoxWithChildren->contentLogicalTop()) }; |
antti@apple.com | 4c0c397 | 2020-10-29 14:21:34 +0000 | [diff] [blame] | 3393 | if (pointInLogicalContents.y() < firstLineWithChildrenTop |
| 3394 | || (blocksAreFlipped && pointInLogicalContents.y() == firstLineWithChildrenTop)) { |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3395 | auto box = firstLineBoxWithChildren->firstLeafBox(); |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3396 | if (box->isLineBreak()) { |
| 3397 | if (auto next = box->nextOnLineIgnoringLineBreak()) |
| 3398 | box = next; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3399 | } |
| 3400 | // y coordinate is above first root line box, so return the start of the first |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3401 | return positionForRun(*this, box, true); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | // pass the box a top position that is inside it |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3406 | auto point = LayoutPoint { pointInLogicalContents.x(), contentStartInBlockDirection(*closestBox->lineBox()) }; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3407 | if (!isHorizontalWritingMode()) |
| 3408 | point = point.transposedPoint(); |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3409 | if (closestBox->renderer().isReplacedOrInlineBlock()) |
| 3410 | return positionForPointRespectingEditingBoundaries(*this, const_cast<RenderBox&>(downcast<RenderBox>(closestBox->renderer())), point); |
| 3411 | return const_cast<RenderObject&>(closestBox->renderer()).positionForPoint(point, nullptr); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3412 | } |
| 3413 | |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3414 | if (lastLineBoxWithChildren) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3415 | // We hit this case for Mac behavior when the Y coordinate is below the last box. |
| 3416 | ASSERT(moveCaretToBoundary); |
antti@apple.com | 36b223a | 2021-10-15 20:29:15 +0000 | [diff] [blame] | 3417 | InlineIterator::LineLogicalOrderCache orderCache; |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3418 | if (auto logicallyLastBox = InlineIterator::lastLeafOnLineInLogicalOrderWithNode(lastLineBoxWithChildren, orderCache)) |
zalan@apple.com | 0c2712d | 2022-03-18 13:49:15 +0000 | [diff] [blame] | 3419 | return positionForRun(*this, logicallyLastBox, false); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3420 | } |
| 3421 | |
| 3422 | // Can't reach this. We have a root line box, but it has no kids. |
| 3423 | // FIXME: This should ASSERT_NOT_REACHED(), but clicking on placeholder text |
| 3424 | // seems to hit this code path. |
darin@apple.com | c8d8b55 | 2020-09-03 21:38:50 +0000 | [diff] [blame] | 3425 | return createVisiblePosition(0, Affinity::Downstream); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3426 | } |
| 3427 | |
zalan@apple.com | 0d5951b | 2017-02-19 16:24:20 +0000 | [diff] [blame] | 3428 | Position RenderBlockFlow::positionForPoint(const LayoutPoint& point) |
| 3429 | { |
antti@apple.com | 55d5afa | 2020-09-25 13:16:23 +0000 | [diff] [blame] | 3430 | return positionForPoint(point, nullptr).deepEquivalent(); |
zalan@apple.com | 0d5951b | 2017-02-19 16:24:20 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 3433 | VisiblePosition RenderBlockFlow::positionForPoint(const LayoutPoint& point, const RenderFragmentContainer*) |
commit-queue@webkit.org | 5ce6c90 | 2013-11-11 18:21:05 +0000 | [diff] [blame] | 3434 | { |
antti@apple.com | e0e8a56 | 2017-09-21 18:29:47 +0000 | [diff] [blame] | 3435 | return RenderBlock::positionForPoint(point, nullptr); |
commit-queue@webkit.org | 5ce6c90 | 2013-11-11 18:21:05 +0000 | [diff] [blame] | 3436 | } |
| 3437 | |
zalan@apple.com | 8ee1af5 | 2016-02-11 22:15:45 +0000 | [diff] [blame] | 3438 | void RenderBlockFlow::addFocusRingRectsForInlineChildren(Vector<LayoutRect>& rects, const LayoutPoint& additionalOffset, const RenderLayerModelObject*) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3439 | { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3440 | ASSERT(childrenInline()); |
antti@apple.com | 631a476 | 2022-01-02 18:30:52 +0000 | [diff] [blame] | 3441 | for (auto box = InlineIterator::firstRootInlineBoxFor(*this); box; box.traverseNextInlineBox()) { |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3442 | auto lineBox = box->lineBox(); |
antti@apple.com | 631a476 | 2022-01-02 18:30:52 +0000 | [diff] [blame] | 3443 | // FIXME: This is mixing physical and logical coordinates. |
zalan@apple.com | 6a25405 | 2022-03-01 16:19:30 +0000 | [diff] [blame] | 3444 | auto unflippedVisualRect = box->visualRectIgnoringBlockDirection(); |
zalan@apple.com | 1ae704f | 2022-03-21 00:59:06 +0000 | [diff] [blame] | 3445 | auto top = std::max(lineBox->contentLogicalTop(), unflippedVisualRect.y()); |
| 3446 | auto bottom = std::min(lineBox->contentLogicalBottom(), unflippedVisualRect.maxY()); |
zalan@apple.com | 6a25405 | 2022-03-01 16:19:30 +0000 | [diff] [blame] | 3447 | auto rect = LayoutRect { LayoutUnit { additionalOffset.x() + unflippedVisualRect.x() } |
| 3448 | , additionalOffset.y() + top |
| 3449 | , LayoutUnit { unflippedVisualRect.width() } |
| 3450 | , bottom - top }; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3451 | if (!rect.isEmpty()) |
zalan@apple.com | 8ee1af5 | 2016-02-11 22:15:45 +0000 | [diff] [blame] | 3452 | rects.append(rect); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3453 | } |
| 3454 | } |
| 3455 | |
| 3456 | void RenderBlockFlow::paintInlineChildren(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| 3457 | { |
| 3458 | ASSERT(childrenInline()); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3459 | |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3460 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 3461 | if (modernLineLayout()) { |
| 3462 | modernLineLayout()->paint(paintInfo, paintOffset); |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3463 | return; |
| 3464 | } |
| 3465 | #endif |
| 3466 | |
antti@apple.com | 443deba | 2021-06-01 13:58:23 +0000 | [diff] [blame] | 3467 | if (legacyLineLayout()) |
| 3468 | legacyLineLayout()->lineBoxes().paint(this, paintInfo, paintOffset); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
zalan@apple.com | 4a44032 | 2017-11-10 00:31:24 +0000 | [diff] [blame] | 3471 | bool RenderBlockFlow::relayoutForPagination() |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3472 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3473 | if (!multiColumnFlow() || !multiColumnFlow()->shouldRelayoutForPagination()) |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3474 | return false; |
| 3475 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3476 | multiColumnFlow()->setNeedsHeightsRecalculation(false); |
| 3477 | multiColumnFlow()->setInBalancingPass(true); // Prevent re-entering this method (and recursion into layout). |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3478 | |
| 3479 | bool needsRelayout; |
| 3480 | bool neededRelayout = false; |
| 3481 | bool firstPass = true; |
| 3482 | do { |
| 3483 | // Column heights may change here because of balancing. We may have to do multiple layout |
| 3484 | // passes, depending on how the contents is fitted to the changed column heights. In most |
| 3485 | // cases, laying out again twice or even just once will suffice. Sometimes we need more |
| 3486 | // passes than that, though, but the number of retries should not exceed the number of |
| 3487 | // columns, unless we have a bug. |
| 3488 | needsRelayout = false; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3489 | for (RenderMultiColumnSet* multicolSet = multiColumnFlow()->firstMultiColumnSet(); multicolSet; multicolSet = multicolSet->nextSiblingMultiColumnSet()) { |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3490 | if (multicolSet->recalculateColumnHeight(firstPass)) |
| 3491 | needsRelayout = true; |
| 3492 | if (needsRelayout) { |
| 3493 | // Once a column set gets a new column height, that column set and all successive column |
| 3494 | // sets need to be laid out over again, since their logical top will be affected by |
| 3495 | // this, and therefore their column heights may change as well, at least if the multicol |
| 3496 | // height is constrained. |
| 3497 | multicolSet->setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3498 | } |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3499 | } |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3500 | if (needsRelayout) { |
| 3501 | // Layout again. Column balancing resulted in a new height. |
| 3502 | neededRelayout = true; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3503 | multiColumnFlow()->setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3504 | setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3505 | layoutBlock(false); |
| 3506 | } |
| 3507 | firstPass = false; |
| 3508 | } while (needsRelayout); |
| 3509 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3510 | multiColumnFlow()->setInBalancingPass(false); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3511 | |
| 3512 | return neededRelayout; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3513 | } |
| 3514 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3515 | bool RenderBlockFlow::hasLines() const |
| 3516 | { |
zalan@apple.com | 93658f6 | 2022-04-10 21:56:21 +0000 | [diff] [blame] | 3517 | return childrenInline() ? lineCount() : false; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3518 | } |
| 3519 | |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3520 | void RenderBlockFlow::invalidateLineLayoutPath() |
| 3521 | { |
akling@apple.com | a12fee2 | 2015-02-01 02:58:13 +0000 | [diff] [blame] | 3522 | switch (lineLayoutPath()) { |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3523 | case UndeterminedPath: |
zalan@apple.com | 515e370 | 2021-10-11 15:55:01 +0000 | [diff] [blame] | 3524 | case ForcedLegacyPath: |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3525 | return; |
zalan@apple.com | 515e370 | 2021-10-11 15:55:01 +0000 | [diff] [blame] | 3526 | case LegacyPath: |
akling@apple.com | a12fee2 | 2015-02-01 02:58:13 +0000 | [diff] [blame] | 3527 | setLineLayoutPath(UndeterminedPath); |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3528 | return; |
antti@apple.com | 467972e | 2021-02-22 15:30:26 +0000 | [diff] [blame] | 3529 | case ModernPath: { |
| 3530 | // FIXME: Implement partial invalidation. |
dpino@igalia.com | 3b24f650 | 2021-02-23 15:05:07 +0000 | [diff] [blame] | 3531 | auto path = UndeterminedPath; |
| 3532 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
| 3533 | if (modernLineLayout() && modernLineLayout()->shouldSwitchToLegacyOnInvalidation()) |
zalan@apple.com | 515e370 | 2021-10-11 15:55:01 +0000 | [diff] [blame] | 3534 | path = ForcedLegacyPath; |
dpino@igalia.com | 3b24f650 | 2021-02-23 15:05:07 +0000 | [diff] [blame] | 3535 | #endif |
zalan@apple.com | 713445c | 2021-11-18 21:14:07 +0000 | [diff] [blame] | 3536 | #if ENABLE_MODERN_PREFERRED_WIDTH_COMPUTATION |
| 3537 | for (auto walker = InlineWalker(*this); !walker.atEnd(); walker.advance()) |
| 3538 | walker.current()->setPreferredLogicalWidthsDirty(true); |
| 3539 | #endif |
commit-queue@webkit.org | 1acd723 | 2021-10-12 20:43:49 +0000 | [diff] [blame] | 3540 | m_lineLayout = std::monostate(); |
antti@apple.com | 467972e | 2021-02-22 15:30:26 +0000 | [diff] [blame] | 3541 | setLineLayoutPath(path); |
zalan@apple.com | fbd3dc8f | 2022-01-11 03:21:20 +0000 | [diff] [blame] | 3542 | if (selfNeedsLayout() || normalChildNeedsLayout()) |
zalan@apple.com | de19104 | 2017-06-06 19:35:56 +0000 | [diff] [blame] | 3543 | return; |
| 3544 | // FIXME: We should just kick off a subtree layout here (if needed at all) see webkit.org/b/172947. |
| 3545 | setNeedsLayout(); |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3546 | return; |
| 3547 | } |
antti@apple.com | 467972e | 2021-02-22 15:30:26 +0000 | [diff] [blame] | 3548 | } |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3549 | ASSERT_NOT_REACHED(); |
| 3550 | } |
| 3551 | |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3552 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 3553 | void RenderBlockFlow::layoutModernLines(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3554 | { |
antti@apple.com | 3da1695 | 2020-10-24 13:46:57 +0000 | [diff] [blame] | 3555 | bool needsUpdateReplacedDimensions = false; |
| 3556 | |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 3557 | if (!modernLineLayout()) { |
antti@apple.com | d4dda74 | 2019-12-03 15:41:43 +0000 | [diff] [blame] | 3558 | m_lineLayout = makeUnique<LayoutIntegration::LineLayout>(*this); |
antti@apple.com | 3da1695 | 2020-10-24 13:46:57 +0000 | [diff] [blame] | 3559 | needsUpdateReplacedDimensions = true; |
| 3560 | } |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3561 | |
antti@apple.com | 561f2f7 | 2020-10-26 20:23:48 +0000 | [diff] [blame] | 3562 | auto& layoutFormattingContextLineLayout = *this->modernLineLayout(); |
zalan@apple.com | c432575 | 2022-03-10 22:51:11 +0000 | [diff] [blame] | 3563 | layoutFormattingContextLineLayout.updateFormattingRootGeometryAndInvalidate(); |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3564 | |
antti@apple.com | 554f9dc | 2020-11-27 16:52:48 +0000 | [diff] [blame] | 3565 | for (auto walker = InlineWalker(*this); !walker.atEnd(); walker.advance()) { |
| 3566 | auto& renderer = *walker.current(); |
zalan@apple.com | ddc3e19 | 2021-08-21 01:45:09 +0000 | [diff] [blame] | 3567 | if (relayoutChildren || (is<RenderBox>(renderer) && downcast<RenderBox>(renderer).hasRelativeDimensions())) |
antti@apple.com | 3da1695 | 2020-10-24 13:46:57 +0000 | [diff] [blame] | 3568 | renderer.setNeedsLayout(MarkOnlyThis); |
zalan@apple.com | ddc3e19 | 2021-08-21 01:45:09 +0000 | [diff] [blame] | 3569 | |
antti@apple.com | 3da1695 | 2020-10-24 13:46:57 +0000 | [diff] [blame] | 3570 | if (!renderer.needsLayout() && !needsUpdateReplacedDimensions) |
antti@apple.com | 1f20ffe | 2020-10-16 17:52:20 +0000 | [diff] [blame] | 3571 | continue; |
antti@apple.com | 3da1695 | 2020-10-24 13:46:57 +0000 | [diff] [blame] | 3572 | |
antti@apple.com | 1f20ffe | 2020-10-16 17:52:20 +0000 | [diff] [blame] | 3573 | if (is<RenderReplaced>(renderer)) { |
| 3574 | auto& replaced = downcast<RenderReplaced>(renderer); |
| 3575 | replaced.layoutIfNeeded(); |
| 3576 | layoutFormattingContextLineLayout.updateReplacedDimensions(replaced); |
| 3577 | continue; |
| 3578 | } |
zalan@apple.com | 9983d5e | 2022-03-11 16:44:43 +0000 | [diff] [blame] | 3579 | if (is<RenderTable>(renderer)) { |
| 3580 | auto& inlineTable = downcast<RenderTable>(renderer); |
| 3581 | inlineTable.layoutIfNeeded(); |
| 3582 | layoutFormattingContextLineLayout.updateInlineTableDimensions(inlineTable); |
| 3583 | continue; |
| 3584 | } |
zalan@apple.com | c432575 | 2022-03-10 22:51:11 +0000 | [diff] [blame] | 3585 | if (is<RenderListMarker>(renderer)) { |
| 3586 | auto& marker = downcast<RenderListMarker>(renderer); |
| 3587 | marker.layoutIfNeeded(); |
| 3588 | layoutFormattingContextLineLayout.updateListMarkerDimensions(marker); |
| 3589 | continue; |
| 3590 | } |
| 3591 | if (is<RenderListItem>(renderer)) { |
| 3592 | auto& listItem = downcast<RenderListItem>(renderer); |
| 3593 | listItem.layoutIfNeeded(); |
| 3594 | layoutFormattingContextLineLayout.updateListItemDimensions(listItem); |
| 3595 | continue; |
| 3596 | } |
antti@apple.com | bb78d9a | 2020-10-26 13:58:58 +0000 | [diff] [blame] | 3597 | if (is<RenderBlock>(renderer)) { |
| 3598 | auto& block = downcast<RenderBlock>(renderer); |
| 3599 | block.layoutIfNeeded(); |
zalan@apple.com | 24f44fd | 2020-11-14 17:38:37 +0000 | [diff] [blame] | 3600 | ASSERT(block.style().display() == DisplayType::InlineBlock); |
| 3601 | layoutFormattingContextLineLayout.updateInlineBlockDimensions(block); |
antti@apple.com | bb78d9a | 2020-10-26 13:58:58 +0000 | [diff] [blame] | 3602 | continue; |
| 3603 | } |
| 3604 | |
zalan@apple.com | 6e32660 | 2020-12-25 21:46:14 +0000 | [diff] [blame] | 3605 | if (is<RenderLineBreak>(renderer)) { |
| 3606 | layoutFormattingContextLineLayout.updateLineBreakBoxDimensions(downcast<RenderLineBreak>(renderer)); |
| 3607 | renderer.clearNeedsLayout(); |
| 3608 | continue; |
| 3609 | } |
| 3610 | |
zalan@apple.com | 7023f03 | 2020-12-26 15:22:08 +0000 | [diff] [blame] | 3611 | if (is<RenderInline>(renderer)) { |
| 3612 | layoutFormattingContextLineLayout.updateInlineBoxDimensions(downcast<RenderInline>(renderer)); |
| 3613 | renderer.clearNeedsLayout(); |
| 3614 | continue; |
| 3615 | } |
| 3616 | |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3617 | renderer.clearNeedsLayout(); |
zalan@apple.com | 02a0c95 | 2020-04-06 23:34:51 +0000 | [diff] [blame] | 3618 | } |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3619 | |
antti@apple.com | beb0498 | 2021-08-17 14:11:22 +0000 | [diff] [blame] | 3620 | auto contentBoxTop = borderAndPaddingBefore(); |
| 3621 | |
| 3622 | auto computeContentHeight = [&] { |
| 3623 | if (!hasLines() && hasLineIfEmpty()) |
| 3624 | return lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
| 3625 | |
| 3626 | return layoutFormattingContextLineLayout.contentLogicalHeight(); |
| 3627 | }; |
| 3628 | |
| 3629 | auto computeBorderBoxBottom = [&] { |
| 3630 | auto contentBoxBottom = contentBoxTop + computeContentHeight(); |
| 3631 | return contentBoxBottom + borderAndPaddingAfter(); |
| 3632 | }; |
| 3633 | |
| 3634 | auto oldBorderBoxBottom = computeBorderBoxBottom(); |
| 3635 | |
antti@apple.com | d4dda74 | 2019-12-03 15:41:43 +0000 | [diff] [blame] | 3636 | layoutFormattingContextLineLayout.layout(); |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3637 | |
antti@apple.com | 67db9ea | 2020-09-23 04:39:06 +0000 | [diff] [blame] | 3638 | if (view().frameView().layoutContext().layoutState()->isPaginated()) |
antti@apple.com | 2943bef | 2020-10-21 16:21:04 +0000 | [diff] [blame] | 3639 | layoutFormattingContextLineLayout.adjustForPagination(); |
antti@apple.com | 67db9ea | 2020-09-23 04:39:06 +0000 | [diff] [blame] | 3640 | |
antti@apple.com | beb0498 | 2021-08-17 14:11:22 +0000 | [diff] [blame] | 3641 | auto newBorderBoxBottom = computeBorderBoxBottom(); |
antti@apple.com | 1ebf7e1 | 2019-12-03 10:51:46 +0000 | [diff] [blame] | 3642 | |
zalan@apple.com | 7b374f8 | 2020-01-05 14:50:08 +0000 | [diff] [blame] | 3643 | repaintLogicalTop = contentBoxTop; |
antti@apple.com | beb0498 | 2021-08-17 14:11:22 +0000 | [diff] [blame] | 3644 | repaintLogicalBottom = std::max(oldBorderBoxBottom, newBorderBoxBottom); |
| 3645 | |
zalan@apple.com | 33b5dc6 | 2022-04-09 17:55:18 +0000 | [diff] [blame] | 3646 | auto inflateRepaintTopAndBottomWithInkOverflow = [&] { |
zalan@apple.com | 27da259 | 2022-04-12 01:30:11 +0000 | [diff] [blame] | 3647 | if (!layoutFormattingContextLineLayout.hasVisualOverflow()) |
zalan@apple.com | 33b5dc6 | 2022-04-09 17:55:18 +0000 | [diff] [blame] | 3648 | return; |
zalan@apple.com | 27da259 | 2022-04-12 01:30:11 +0000 | [diff] [blame] | 3649 | for (auto lineBox = InlineIterator::firstLineBoxFor(*this); lineBox; lineBox.traverseNext()) { |
| 3650 | repaintLogicalTop = std::min(repaintLogicalTop, LayoutUnit { lineBox->inkOverflowTop() }); |
| 3651 | repaintLogicalBottom = std::max(repaintLogicalBottom, LayoutUnit { lineBox->inkOverflowBottom() }); |
zalan@apple.com | 33b5dc6 | 2022-04-09 17:55:18 +0000 | [diff] [blame] | 3652 | } |
| 3653 | }; |
| 3654 | inflateRepaintTopAndBottomWithInkOverflow(); |
| 3655 | |
antti@apple.com | beb0498 | 2021-08-17 14:11:22 +0000 | [diff] [blame] | 3656 | setLogicalHeight(newBorderBoxBottom); |
antti@apple.com | 1880e71 | 2019-11-26 20:15:39 +0000 | [diff] [blame] | 3657 | } |
| 3658 | #endif |
| 3659 | |
simon.fraser@apple.com | c9f9613 | 2015-03-06 18:20:40 +0000 | [diff] [blame] | 3660 | #if ENABLE(TREE_DEBUGGING) |
simon.fraser@apple.com | 10335f5 | 2021-01-26 22:20:09 +0000 | [diff] [blame] | 3661 | void RenderBlockFlow::outputFloatingObjects(WTF::TextStream& stream, int depth) const |
| 3662 | { |
| 3663 | if (!floatingObjectSet()) |
| 3664 | return; |
| 3665 | |
| 3666 | for (auto& floatingObject : *floatingObjectSet()) { |
| 3667 | int printedCharacters = 0; |
| 3668 | while (++printedCharacters <= depth * 2) |
| 3669 | stream << " "; |
| 3670 | |
| 3671 | stream << " "; |
| 3672 | stream << "floating object " << *floatingObject; |
| 3673 | stream.nextLine(); |
| 3674 | } |
| 3675 | } |
| 3676 | |
antti@apple.com | 379e81d | 2021-06-01 17:22:45 +0000 | [diff] [blame] | 3677 | void RenderBlockFlow::outputLineTreeAndMark(WTF::TextStream& stream, const LegacyInlineBox* markedBox, int depth) const |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3678 | { |
zalan@apple.com | 385d249 | 2020-10-29 13:17:05 +0000 | [diff] [blame] | 3679 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
| 3680 | if (auto* modernLineLayout = this->modernLineLayout()) { |
| 3681 | modernLineLayout->outputLineTree(stream, depth); |
| 3682 | return; |
| 3683 | } |
| 3684 | #endif |
antti@apple.com | 903292a | 2021-06-02 16:20:15 +0000 | [diff] [blame] | 3685 | for (const LegacyRootInlineBox* root = firstRootBox(); root; root = root->nextRootBox()) |
zalan@apple.com | 360de75 | 2017-07-06 21:13:24 +0000 | [diff] [blame] | 3686 | root->outputLineTreeAndMark(stream, markedBox, depth); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3687 | } |
| 3688 | #endif |
| 3689 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 3690 | RenderBlockFlow::RenderBlockFlowRareData& RenderBlockFlow::ensureRareBlockFlowData() |
| 3691 | { |
| 3692 | if (hasRareBlockFlowData()) |
| 3693 | return *m_rareBlockFlowData; |
| 3694 | materializeRareBlockFlowData(); |
| 3695 | return *m_rareBlockFlowData; |
| 3696 | } |
| 3697 | |
| 3698 | void RenderBlockFlow::materializeRareBlockFlowData() |
| 3699 | { |
| 3700 | ASSERT(!hasRareBlockFlowData()); |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 3701 | m_rareBlockFlowData = makeUnique<RenderBlockFlow::RenderBlockFlowRareData>(*this); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 3702 | } |
| 3703 | |
dbates@webkit.org | 102013c | 2016-09-26 21:51:25 +0000 | [diff] [blame] | 3704 | #if ENABLE(TEXT_AUTOSIZING) |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 3705 | |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3706 | static inline bool isVisibleRenderText(const RenderObject& renderer) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3707 | { |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3708 | if (!is<RenderText>(renderer)) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3709 | return false; |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3710 | |
| 3711 | auto& renderText = downcast<RenderText>(renderer); |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 3712 | return !renderText.linesBoundingBox().isEmpty() && !renderText.text().isAllSpecialCharacters<isHTMLSpace>(); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3713 | } |
| 3714 | |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3715 | static inline bool resizeTextPermitted(const RenderObject& renderer) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3716 | { |
| 3717 | // We disallow resizing for text input fields and textarea to address <rdar://problem/5792987> and <rdar://problem/8021123> |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3718 | for (auto* ancestor = renderer.parent(); ancestor; ancestor = ancestor->parent()) { |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3719 | // Get the first non-shadow HTMLElement and see if it's an input. |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3720 | if (is<HTMLElement>(ancestor->element()) && !ancestor->element()->isInShadowTree()) { |
| 3721 | auto& element = downcast<HTMLElement>(*ancestor->element()); |
cdumez@apple.com | 59fdc8a | 2014-09-24 21:25:22 +0000 | [diff] [blame] | 3722 | return !is<HTMLInputElement>(element) && !is<HTMLTextAreaElement>(element); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3723 | } |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3724 | } |
| 3725 | return true; |
| 3726 | } |
| 3727 | |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3728 | static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject& renderer) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3729 | { |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3730 | if (!renderer.isRenderBlock()) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3731 | return true; |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3732 | if (renderer.isListItem()) |
mmaxfield@apple.com | 87d31e0 | 2021-02-12 21:31:41 +0000 | [diff] [blame] | 3733 | return renderer.style().height().type() != LengthType::Fixed; |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3734 | return false; |
| 3735 | } |
| 3736 | |
timothy_horton@apple.com | 117a5f8 | 2018-02-19 18:47:30 +0000 | [diff] [blame] | 3737 | // For now, we auto size single lines of text the same as multiple lines. |
| 3738 | // We've been experimenting with low values for single lines of text. |
| 3739 | static inline float oneLineTextMultiplier(RenderObject& renderer, float specifiedSize) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3740 | { |
timothy_horton@apple.com | 117a5f8 | 2018-02-19 18:47:30 +0000 | [diff] [blame] | 3741 | const float coefficient = renderer.settings().oneLineTextMultiplierCoefficient(); |
| 3742 | return std::max((1.0f / log10f(specifiedSize) * coefficient), 1.0f); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3743 | } |
| 3744 | |
timothy_horton@apple.com | 117a5f8 | 2018-02-19 18:47:30 +0000 | [diff] [blame] | 3745 | static inline float textMultiplier(RenderObject& renderer, float specifiedSize) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3746 | { |
timothy_horton@apple.com | 117a5f8 | 2018-02-19 18:47:30 +0000 | [diff] [blame] | 3747 | const float coefficient = renderer.settings().multiLineTextMultiplierCoefficient(); |
| 3748 | return std::max((1.0f / log10f(specifiedSize) * coefficient), 1.0f); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3749 | } |
| 3750 | |
mmaxfield@apple.com | 59146a7 | 2019-05-29 02:27:20 +0000 | [diff] [blame] | 3751 | void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3752 | { |
simon.fraser@apple.com | 36676e5 | 2016-05-07 00:05:58 +0000 | [diff] [blame] | 3753 | LOG(TextAutosizing, "RenderBlockFlow %p adjustComputedFontSizes, size=%f visibleWidth=%f, width()=%f. Bailing: %d", this, size, visibleWidth, width().toFloat(), visibleWidth >= width()); |
| 3754 | |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3755 | // Don't do any work if the block is smaller than the visible area. |
mmaxfield@apple.com | 59146a7 | 2019-05-29 02:27:20 +0000 | [diff] [blame] | 3756 | if (visibleWidth >= width()) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3757 | return; |
| 3758 | |
zalan@apple.com | 00b1fee | 2022-04-10 02:59:35 +0000 | [diff] [blame] | 3759 | unsigned lineCount = m_lineCountForTextAutosizing; |
| 3760 | if (lineCount == NOT_SET) { |
| 3761 | if (style().visibility() != Visibility::Visible) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3762 | lineCount = NO_LINE; |
zalan@apple.com | 00b1fee | 2022-04-10 02:59:35 +0000 | [diff] [blame] | 3763 | else { |
| 3764 | size_t lineCountInBlock = 0; |
| 3765 | if (childrenInline()) |
| 3766 | lineCountInBlock = this->lineCount(); |
| 3767 | else { |
| 3768 | for (auto& listItem : childrenOfType<RenderListItem>(*this)) { |
zalan@apple.com | 93658f6 | 2022-04-10 21:56:21 +0000 | [diff] [blame] | 3769 | if (!listItem.childrenInline() || listItem.style().visibility() != Visibility::Visible) |
| 3770 | continue; |
zalan@apple.com | 00b1fee | 2022-04-10 02:59:35 +0000 | [diff] [blame] | 3771 | lineCountInBlock += listItem.lineCount(); |
| 3772 | if (lineCountInBlock > 1) |
| 3773 | break; |
| 3774 | } |
| 3775 | } |
| 3776 | lineCount = !lineCountInBlock ? NO_LINE : lineCountInBlock == 1 ? ONE_LINE : MULTI_LINE; |
| 3777 | } |
| 3778 | } |
| 3779 | |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3780 | ASSERT(lineCount != NOT_SET); |
| 3781 | if (lineCount == NO_LINE) |
| 3782 | return; |
| 3783 | |
| 3784 | float actualWidth = m_widthForTextAutosizing != -1 ? static_cast<float>(m_widthForTextAutosizing) : static_cast<float>(width()); |
| 3785 | float scale = visibleWidth / actualWidth; |
| 3786 | float minFontSize = roundf(size / scale); |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3787 | |
| 3788 | for (auto* descendant = RenderObjectTraversal::firstChild(*this); descendant; ) { |
| 3789 | if (!isNonBlocksOrNonFixedHeightListItems(*descendant)) { |
| 3790 | descendant = RenderObjectTraversal::nextSkippingChildren(*descendant, this); |
| 3791 | continue; |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3792 | } |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3793 | if (!isVisibleRenderText(*descendant) || !resizeTextPermitted(*descendant)) { |
| 3794 | descendant = RenderObjectTraversal::next(*descendant, this); |
| 3795 | continue; |
| 3796 | } |
| 3797 | |
| 3798 | auto& text = downcast<RenderText>(*descendant); |
| 3799 | auto& oldStyle = text.style(); |
| 3800 | auto& fontDescription = oldStyle.fontDescription(); |
| 3801 | float specifiedSize = fontDescription.specifiedSize(); |
| 3802 | float scaledSize = roundf(specifiedSize * scale); |
mmaxfield@apple.com | 59146a7 | 2019-05-29 02:27:20 +0000 | [diff] [blame] | 3803 | if (scaledSize > 0 && scaledSize < minFontSize) { |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3804 | // Record the width of the block and the line count the first time we resize text and use it from then on for text resizing. |
| 3805 | // This makes text resizing consistent even if the block's width or line count changes (which can be caused by text resizing itself 5159915). |
| 3806 | if (m_lineCountForTextAutosizing == NOT_SET) |
| 3807 | m_lineCountForTextAutosizing = lineCount; |
| 3808 | if (m_widthForTextAutosizing == -1) |
| 3809 | m_widthForTextAutosizing = actualWidth; |
| 3810 | |
mmaxfield@apple.com | 59146a7 | 2019-05-29 02:27:20 +0000 | [diff] [blame] | 3811 | float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(text, specifiedSize) : textMultiplier(text, specifiedSize); |
| 3812 | float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier)); |
mmaxfield@apple.com | ac71afa | 2019-04-26 06:33:56 +0000 | [diff] [blame] | 3813 | |
commit-queue@webkit.org | f287237 | 2019-04-26 18:32:41 +0000 | [diff] [blame] | 3814 | if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto()) |
antti@apple.com | 4918b4d | 2017-08-14 13:20:47 +0000 | [diff] [blame] | 3815 | document().textAutoSizing().addTextNode(*text.textNode(), candidateNewSize); |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | descendant = RenderObjectTraversal::nextSkippingChildren(text, this); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3819 | } |
| 3820 | } |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 3821 | |
dbates@webkit.org | 102013c | 2016-09-26 21:51:25 +0000 | [diff] [blame] | 3822 | #endif // ENABLE(TEXT_AUTOSIZING) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3823 | |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 3824 | void RenderBlockFlow::layoutExcludedChildren(bool relayoutChildren) |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3825 | { |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 3826 | RenderBlock::layoutExcludedChildren(relayoutChildren); |
| 3827 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3828 | auto* fragmentedFlow = multiColumnFlow(); |
| 3829 | if (!fragmentedFlow) |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 3830 | return; |
| 3831 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3832 | fragmentedFlow->setIsExcludedFromNormalLayout(true); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3833 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3834 | setLogicalTopForChild(*fragmentedFlow, borderAndPaddingBefore()); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3835 | |
| 3836 | if (relayoutChildren) |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3837 | fragmentedFlow->setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3838 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3839 | if (fragmentedFlow->needsLayout()) { |
| 3840 | for (RenderMultiColumnSet* columnSet = fragmentedFlow->firstMultiColumnSet(); columnSet; columnSet = columnSet->nextSiblingMultiColumnSet()) |
| 3841 | columnSet->prepareForLayout(!fragmentedFlow->inBalancingPass()); |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3842 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3843 | fragmentedFlow->invalidateFragments(MarkOnlyThis); |
| 3844 | fragmentedFlow->setNeedsHeightsRecalculation(true); |
| 3845 | fragmentedFlow->layout(); |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3846 | } else { |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3847 | // At the end of multicol layout, relayoutForPagination() is called unconditionally, but if |
| 3848 | // no children are to be laid out (e.g. fixed width with layout already being up-to-date), |
| 3849 | // we want to prevent it from doing any work, so that the column balancing machinery doesn't |
| 3850 | // kick in and trigger additional unnecessary layout passes. Actually, it's not just a good |
| 3851 | // idea in general to not waste time on balancing content that hasn't been re-laid out; we |
| 3852 | // are actually required to guarantee this. The calculation of implicit breaks needs to be |
| 3853 | // preceded by a proper layout pass, since it's layout that sets up content runs, and the |
| 3854 | // runs get deleted right after every pass. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3855 | fragmentedFlow->setNeedsHeightsRecalculation(false); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3856 | } |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3857 | determineLogicalLeftPositionForChild(*fragmentedFlow); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3858 | } |
| 3859 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 3860 | void RenderBlockFlow::checkForPaginationLogicalHeightChange(bool& relayoutChildren, LayoutUnit& pageLogicalHeight, bool& pageLogicalHeightChanged) |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3861 | { |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 3862 | // If we don't use columns or flow threads, then bail. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3863 | if (!isRenderFragmentedFlow() && !multiColumnFlow()) |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3864 | return; |
| 3865 | |
| 3866 | // We don't actually update any of the variables. We just subclassed to adjust our column height. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3867 | if (RenderMultiColumnFlow* fragmentedFlow = multiColumnFlow()) { |
zalan@apple.com | 53e7907 | 2016-12-12 20:17:50 +0000 | [diff] [blame] | 3868 | LayoutUnit newColumnHeight; |
| 3869 | if (hasDefiniteLogicalHeight() || view().frameView().pagination().mode != Pagination::Unpaginated) { |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 3870 | auto computedValues = computeLogicalHeight(0_lu, logicalTop()); |
zalan@apple.com | 53e7907 | 2016-12-12 20:17:50 +0000 | [diff] [blame] | 3871 | newColumnHeight = std::max<LayoutUnit>(computedValues.m_extent - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight(), 0); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3872 | if (fragmentedFlow->columnHeightAvailable() != newColumnHeight) |
zalan@apple.com | 53e7907 | 2016-12-12 20:17:50 +0000 | [diff] [blame] | 3873 | relayoutChildren = true; |
| 3874 | } |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3875 | fragmentedFlow->setColumnHeightAvailable(newColumnHeight); |
| 3876 | } else if (is<RenderFragmentedFlow>(*this)) { |
| 3877 | RenderFragmentedFlow& fragmentedFlow = downcast<RenderFragmentedFlow>(*this); |
commit-queue@webkit.org | 3d0f60b | 2014-04-08 18:19:47 +0000 | [diff] [blame] | 3878 | |
| 3879 | // FIXME: This is a hack to always make sure we have a page logical height, if said height |
antti@apple.com | f41183e | 2018-12-07 20:10:14 +0000 | [diff] [blame] | 3880 | // is known. The page logical height thing in RenderLayoutState is meaningless for flow |
commit-queue@webkit.org | 3d0f60b | 2014-04-08 18:19:47 +0000 | [diff] [blame] | 3881 | // thread-based pagination (page height isn't necessarily uniform throughout the flow |
| 3882 | // thread), but as long as it is used universally as a means to determine whether page |
| 3883 | // height is known or not, we need this. Page height is unknown when column balancing is |
| 3884 | // enabled and flow thread height is still unknown (i.e. during the first layout pass). When |
| 3885 | // it's unknown, we need to prevent the pagination code from assuming page breaks everywhere |
| 3886 | // and thereby eating every top margin. It should be trivial to clean up and get rid of this |
zalan@apple.com | fa5add6 | 2017-02-22 19:33:02 +0000 | [diff] [blame] | 3887 | // hack once the old multicol implementation is gone (see also RenderView::pushLayoutStateForPagination). |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 3888 | pageLogicalHeight = fragmentedFlow.isPageLogicalHeightKnown() ? 1_lu : 0_lu; |
commit-queue@webkit.org | 3d0f60b | 2014-04-08 18:19:47 +0000 | [diff] [blame] | 3889 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3890 | pageLogicalHeightChanged = fragmentedFlow.pageLogicalSizeChanged(); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3891 | } |
| 3892 | } |
| 3893 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 3894 | bool RenderBlockFlow::requiresColumns(int desiredColumnCount) const |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 3895 | { |
| 3896 | return willCreateColumns(desiredColumnCount); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 3897 | } |
| 3898 | |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3899 | void RenderBlockFlow::setComputedColumnCountAndWidth(int count, LayoutUnit width) |
| 3900 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3901 | ASSERT(!!multiColumnFlow() == requiresColumns(count)); |
| 3902 | if (!multiColumnFlow()) |
antti@apple.com | 411949d | 2017-08-30 17:28:10 +0000 | [diff] [blame] | 3903 | return; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3904 | multiColumnFlow()->setColumnCountAndWidth(count, width); |
| 3905 | multiColumnFlow()->setProgressionIsInline(style().hasInlineColumnAxis()); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 3906 | multiColumnFlow()->setProgressionIsReversed(style().columnProgression() == ColumnProgression::Reverse); |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
cdumez@apple.com | 7814173 | 2014-11-04 23:00:48 +0000 | [diff] [blame] | 3909 | void RenderBlockFlow::updateColumnProgressionFromStyle(RenderStyle& style) |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3910 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3911 | if (!multiColumnFlow()) |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3912 | return; |
| 3913 | |
| 3914 | bool needsLayout = false; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3915 | bool oldProgressionIsInline = multiColumnFlow()->progressionIsInline(); |
cdumez@apple.com | 7814173 | 2014-11-04 23:00:48 +0000 | [diff] [blame] | 3916 | bool newProgressionIsInline = style.hasInlineColumnAxis(); |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3917 | if (oldProgressionIsInline != newProgressionIsInline) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3918 | multiColumnFlow()->setProgressionIsInline(newProgressionIsInline); |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3919 | needsLayout = true; |
| 3920 | } |
| 3921 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3922 | bool oldProgressionIsReversed = multiColumnFlow()->progressionIsReversed(); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 3923 | bool newProgressionIsReversed = style.columnProgression() == ColumnProgression::Reverse; |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3924 | if (oldProgressionIsReversed != newProgressionIsReversed) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3925 | multiColumnFlow()->setProgressionIsReversed(newProgressionIsReversed); |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3926 | needsLayout = true; |
| 3927 | } |
| 3928 | |
| 3929 | if (needsLayout) |
| 3930 | setNeedsLayoutAndPrefWidthsRecalc(); |
| 3931 | } |
| 3932 | |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3933 | LayoutUnit RenderBlockFlow::computedColumnWidth() const |
| 3934 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3935 | if (multiColumnFlow()) |
| 3936 | return multiColumnFlow()->computedColumnWidth(); |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3937 | return contentLogicalWidth(); |
| 3938 | } |
| 3939 | |
| 3940 | unsigned RenderBlockFlow::computedColumnCount() const |
| 3941 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3942 | if (multiColumnFlow()) |
| 3943 | return multiColumnFlow()->computedColumnCount(); |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3944 | |
| 3945 | return 1; |
| 3946 | } |
| 3947 | |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 3948 | bool RenderBlockFlow::isTopLayoutOverflowAllowed() const |
| 3949 | { |
| 3950 | bool hasTopOverflow = RenderBlock::isTopLayoutOverflowAllowed(); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 3951 | if (!multiColumnFlow() || style().columnProgression() == ColumnProgression::Normal) |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 3952 | return hasTopOverflow; |
| 3953 | |
| 3954 | if (!(isHorizontalWritingMode() ^ !style().hasInlineColumnAxis())) |
| 3955 | hasTopOverflow = !hasTopOverflow; |
| 3956 | |
| 3957 | return hasTopOverflow; |
| 3958 | } |
| 3959 | |
| 3960 | bool RenderBlockFlow::isLeftLayoutOverflowAllowed() const |
| 3961 | { |
| 3962 | bool hasLeftOverflow = RenderBlock::isLeftLayoutOverflowAllowed(); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 3963 | if (!multiColumnFlow() || style().columnProgression() == ColumnProgression::Normal) |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 3964 | return hasLeftOverflow; |
| 3965 | |
| 3966 | if (isHorizontalWritingMode() ^ !style().hasInlineColumnAxis()) |
| 3967 | hasLeftOverflow = !hasLeftOverflow; |
| 3968 | |
| 3969 | return hasLeftOverflow; |
| 3970 | } |
| 3971 | |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 3972 | struct InlineMinMaxIterator { |
| 3973 | /* InlineMinMaxIterator is a class that will iterate over all render objects that contribute to |
| 3974 | inline min/max width calculations. Note the following about the way it walks: |
| 3975 | (1) Positioned content is skipped (since it does not contribute to min/max width of a block) |
| 3976 | (2) We do not drill into the children of floats or replaced elements, since you can't break |
| 3977 | in the middle of such an element. |
| 3978 | (3) Inline flows (e.g., <a>, <span>, <i>) are walked twice, since each side can have |
| 3979 | distinct borders/margin/padding that contribute to the min/max width. |
| 3980 | */ |
| 3981 | const RenderBlockFlow& parent; |
| 3982 | RenderObject* current; |
| 3983 | bool endOfInline; |
| 3984 | bool initial; |
| 3985 | |
| 3986 | InlineMinMaxIterator(const RenderBlockFlow& p) |
| 3987 | : parent(p) |
| 3988 | , current(nullptr) |
| 3989 | , endOfInline(false) |
| 3990 | , initial(true) |
| 3991 | { } |
| 3992 | |
| 3993 | RenderObject* next(); |
| 3994 | }; |
| 3995 | |
| 3996 | RenderObject* InlineMinMaxIterator::next() |
| 3997 | { |
| 3998 | RenderObject* result = nullptr; |
| 3999 | bool oldEndOfInline = endOfInline; |
| 4000 | endOfInline = false; |
| 4001 | do { |
darin@apple.com | 8152c8ba | 2022-01-15 22:29:21 +0000 | [diff] [blame] | 4002 | if (!oldEndOfInline && (current && !current->isFloating() && !current->isReplacedOrInlineBlock() && !current->isOutOfFlowPositioned())) |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4003 | result = current->firstChildSlow(); |
| 4004 | else if (initial) { |
| 4005 | result = parent.firstChild(); |
| 4006 | initial = false; |
| 4007 | } |
| 4008 | |
| 4009 | if (!result) { |
| 4010 | // We hit the end of our inline. (It was empty, e.g., <span></span>.) |
| 4011 | if (!oldEndOfInline && current && current->isRenderInline()) { |
| 4012 | result = current; |
| 4013 | endOfInline = true; |
| 4014 | break; |
| 4015 | } |
| 4016 | |
| 4017 | while (current && current != &parent) { |
| 4018 | result = current->nextSibling(); |
| 4019 | if (result) |
| 4020 | break; |
| 4021 | current = current->parent(); |
| 4022 | if (current && current != &parent && current->isRenderInline()) { |
| 4023 | result = current; |
| 4024 | endOfInline = true; |
| 4025 | break; |
| 4026 | } |
| 4027 | } |
| 4028 | } |
| 4029 | |
| 4030 | if (!result) |
| 4031 | break; |
| 4032 | |
darin@apple.com | 8152c8ba | 2022-01-15 22:29:21 +0000 | [diff] [blame] | 4033 | if (!result->isOutOfFlowPositioned() && (result->isTextOrLineBreak() || result->isFloating() || result->isReplacedOrInlineBlock() || result->isRenderInline())) |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4034 | break; |
| 4035 | |
| 4036 | current = result; |
| 4037 | result = nullptr; |
| 4038 | } while (current || current == &parent); |
| 4039 | // Update our position. |
| 4040 | current = result; |
| 4041 | return result; |
| 4042 | } |
| 4043 | |
| 4044 | static LayoutUnit getBPMWidth(LayoutUnit childValue, Length cssUnit) |
| 4045 | { |
mmaxfield@apple.com | 87d31e0 | 2021-02-12 21:31:41 +0000 | [diff] [blame] | 4046 | if (cssUnit.type() != LengthType::Auto) |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4047 | return (cssUnit.isFixed() ? LayoutUnit(cssUnit.value()) : childValue); |
| 4048 | return 0; |
| 4049 | } |
| 4050 | |
| 4051 | static LayoutUnit getBorderPaddingMargin(const RenderBoxModelObject& child, bool endOfInline) |
| 4052 | { |
| 4053 | const RenderStyle& childStyle = child.style(); |
| 4054 | if (endOfInline) { |
| 4055 | return getBPMWidth(child.marginEnd(), childStyle.marginEnd()) + |
| 4056 | getBPMWidth(child.paddingEnd(), childStyle.paddingEnd()) + |
| 4057 | child.borderEnd(); |
| 4058 | } |
| 4059 | return getBPMWidth(child.marginStart(), childStyle.marginStart()) + |
| 4060 | getBPMWidth(child.paddingStart(), childStyle.paddingStart()) + |
| 4061 | child.borderStart(); |
| 4062 | } |
| 4063 | |
| 4064 | static inline void stripTrailingSpace(float& inlineMax, float& inlineMin, RenderObject* trailingSpaceChild) |
| 4065 | { |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4066 | if (is<RenderText>(trailingSpaceChild)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4067 | // Collapse away the trailing space at the end of a block. |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4068 | RenderText& renderText = downcast<RenderText>(*trailingSpaceChild); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4069 | const UChar space = ' '; |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +0000 | [diff] [blame] | 4070 | const FontCascade& font = renderText.style().fontCascade(); // FIXME: This ignores first-line. |
mmaxfield@apple.com | 21a4dcb | 2016-03-13 00:36:59 +0000 | [diff] [blame] | 4071 | float spaceWidth = font.width(RenderBlock::constructTextRun(&space, 1, renderText.style())); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4072 | inlineMax -= spaceWidth + font.wordSpacing(); |
| 4073 | if (inlineMin > inlineMax) |
| 4074 | inlineMin = inlineMax; |
| 4075 | } |
| 4076 | } |
| 4077 | |
| 4078 | static inline LayoutUnit preferredWidth(LayoutUnit preferredWidth, float result) |
| 4079 | { |
| 4080 | return std::max(preferredWidth, LayoutUnit::fromFloatCeil(result)); |
| 4081 | } |
| 4082 | |
| 4083 | void RenderBlockFlow::computeInlinePreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const |
| 4084 | { |
simon.fraser@apple.com | e8ee49b | 2022-05-06 17:10:31 +0000 | [diff] [blame] | 4085 | ASSERT(!shouldApplyInlineSizeContainment()); |
antti@apple.com | 38fd60c | 2022-02-09 12:42:22 +0000 | [diff] [blame] | 4086 | |
antti@apple.com | 5072de9 | 2021-11-02 16:01:26 +0000 | [diff] [blame] | 4087 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
| 4088 | if (const_cast<RenderBlockFlow&>(*this).tryComputePreferredWidthsUsingModernPath(minLogicalWidth, maxLogicalWidth)) |
| 4089 | return; |
| 4090 | #endif |
| 4091 | |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4092 | float inlineMax = 0; |
| 4093 | float inlineMin = 0; |
| 4094 | |
| 4095 | const RenderStyle& styleToUse = style(); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4096 | // If we are at the start of a line, we want to ignore all white-space. |
| 4097 | // Also strip spaces if we previously had text that ended in a trailing space. |
| 4098 | bool stripFrontSpaces = true; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4099 | RenderObject* trailingSpaceChild = nullptr; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4100 | |
| 4101 | // Firefox and Opera will allow a table cell to grow to fit an image inside it under |
| 4102 | // very specific cirucumstances (in order to match common WinIE renderings). |
| 4103 | // Not supporting the quirk has caused us to mis-render some real sites. (See Bugzilla 10517.) |
| 4104 | bool allowImagesToBreak = !document().inQuirksMode() || !isTableCell() || !styleToUse.logicalWidth().isIntrinsicOrAuto(); |
| 4105 | |
cdumez@apple.com | c28103d5 | 2014-10-31 23:25:05 +0000 | [diff] [blame] | 4106 | bool oldAutoWrap = styleToUse.autoWrap(); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4107 | |
| 4108 | InlineMinMaxIterator childIterator(*this); |
| 4109 | |
| 4110 | // Only gets added to the max preffered width once. |
| 4111 | bool addedTextIndent = false; |
| 4112 | // Signals the text indent was more negative than the min preferred width |
| 4113 | bool hasRemainingNegativeTextIndent = false; |
| 4114 | |
zalan@apple.com | 4624e14 | 2020-04-29 17:52:30 +0000 | [diff] [blame] | 4115 | auto textIndent = LayoutUnit { }; |
| 4116 | if (styleToUse.textIndent().isFixed()) |
| 4117 | textIndent = LayoutUnit { styleToUse.textIndent().value() }; |
| 4118 | else if (auto* containingBlock = this->containingBlock(); containingBlock && containingBlock->style().logicalWidth().isFixed()) { |
| 4119 | // At this point of the shrink-to-fit computatation, we don't have a used value for the containing block width |
| 4120 | // (that's exactly to what we try to contribute here) unless the computed value is fixed. |
| 4121 | textIndent = minimumValueForLength(styleToUse.textIndent(), containingBlock->style().logicalWidth().value()); |
| 4122 | } |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 4123 | RenderObject* previousFloat = 0; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4124 | bool isPrevChildInlineFlow = false; |
| 4125 | bool shouldBreakLineAfterText = false; |
commit-queue@webkit.org | 02cb000 | 2018-05-28 00:49:21 +0000 | [diff] [blame] | 4126 | bool canHangPunctuationAtStart = styleToUse.hangingPunctuation().contains(HangingPunctuation::First); |
| 4127 | bool canHangPunctuationAtEnd = styleToUse.hangingPunctuation().contains(HangingPunctuation::Last); |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4128 | RenderText* lastText = nullptr; |
| 4129 | |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4130 | bool addedStartPunctuationHang = false; |
| 4131 | |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4132 | while (RenderObject* child = childIterator.next()) { |
darin@apple.com | 8152c8ba | 2022-01-15 22:29:21 +0000 | [diff] [blame] | 4133 | bool autoWrap = child->isReplacedOrInlineBlock() ? child->parent()->style().autoWrap() : |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4134 | child->style().autoWrap(); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4135 | if (!child->isBR()) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4136 | // Step One: determine whether or not we need to terminate our current line. |
| 4137 | // Each discrete chunk can become the new min-width, if it is the widest chunk |
| 4138 | // seen so far, and it can also become the max-width. |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4139 | |
| 4140 | // Children fall into three categories: |
| 4141 | // (1) An inline flow object. These objects always have a min/max of 0, |
| 4142 | // and are included in the iteration solely so that their margins can |
| 4143 | // be added in. |
| 4144 | // |
| 4145 | // (2) An inline non-text non-flow object, e.g., an inline replaced element. |
| 4146 | // These objects can always be on a line by themselves, so in this situation |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4147 | // we need to break the current line, and then add in our own margins and min/max |
| 4148 | // width on its own line, and then terminate the line. |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4149 | // |
| 4150 | // (3) A text object. Text runs can have breakable characters at the start, |
| 4151 | // the middle or the end. They may also lose whitespace off the front if |
| 4152 | // we're already ignoring whitespace. In order to compute accurate min-width |
| 4153 | // information, we need three pieces of information. |
| 4154 | // (a) the min-width of the first non-breakable run. Should be 0 if the text string |
| 4155 | // starts with whitespace. |
| 4156 | // (b) the min-width of the last non-breakable run. Should be 0 if the text string |
| 4157 | // ends with whitespace. |
| 4158 | // (c) the min/max width of the string (trimmed for whitespace). |
| 4159 | // |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4160 | // If the text string starts with whitespace, then we need to terminate our current line |
| 4161 | // (unless we're already in a whitespace stripping mode. |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4162 | // |
| 4163 | // If the text string has a breakable character in the middle, but didn't start |
| 4164 | // with whitespace, then we add the width of the first non-breakable run and |
| 4165 | // then end the current line. We then need to use the intermediate min/max width |
| 4166 | // values (if any of them are larger than our current min/max). We then look at |
| 4167 | // the width of the last non-breakable run and use that to start a new line |
| 4168 | // (unless we end in whitespace). |
| 4169 | const RenderStyle& childStyle = child->style(); |
| 4170 | float childMin = 0; |
| 4171 | float childMax = 0; |
| 4172 | |
| 4173 | if (!child->isText()) { |
| 4174 | if (child->isLineBreakOpportunity()) { |
| 4175 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4176 | inlineMin = 0; |
| 4177 | continue; |
| 4178 | } |
| 4179 | // Case (1) and (2). Inline replaced and inline flow elements. |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 4180 | if (is<RenderInline>(*child)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4181 | // Add in padding/border/margin from the appropriate side of |
| 4182 | // the element. |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 4183 | float bpm = getBorderPaddingMargin(downcast<RenderInline>(*child), childIterator.endOfInline); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4184 | childMin += bpm; |
| 4185 | childMax += bpm; |
| 4186 | |
| 4187 | inlineMin += childMin; |
| 4188 | inlineMax += childMax; |
| 4189 | |
| 4190 | child->setPreferredLogicalWidthsDirty(false); |
| 4191 | } else { |
| 4192 | // Inline replaced elts add in their margins to their min/max values. |
hyatt@apple.com | 14520e4 | 2016-04-20 18:01:40 +0000 | [diff] [blame] | 4193 | if (!child->isFloating()) |
| 4194 | lastText = nullptr; |
ross.kirsling@sony.com | bd74428 | 2018-11-18 03:14:31 +0000 | [diff] [blame] | 4195 | LayoutUnit margins; |
svillar@igalia.com | 18bfb8f | 2021-12-13 17:19:12 +0000 | [diff] [blame] | 4196 | Length startMargin = childStyle.marginStartUsing(&style()); |
| 4197 | Length endMargin = childStyle.marginEndUsing(&style()); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4198 | if (startMargin.isFixed()) |
| 4199 | margins += LayoutUnit::fromFloatCeil(startMargin.value()); |
| 4200 | if (endMargin.isFixed()) |
| 4201 | margins += LayoutUnit::fromFloatCeil(endMargin.value()); |
| 4202 | childMin += margins.ceilToFloat(); |
| 4203 | childMax += margins.ceilToFloat(); |
| 4204 | } |
| 4205 | } |
| 4206 | |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 4207 | if (!is<RenderInline>(*child) && !is<RenderText>(*child)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4208 | // Case (2). Inline replaced elements and floats. |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4209 | // Terminate the current line as far as minwidth is concerned. |
hyatt@apple.com | 247170f | 2017-02-28 16:23:15 +0000 | [diff] [blame] | 4210 | LayoutUnit childMinPreferredLogicalWidth, childMaxPreferredLogicalWidth; |
| 4211 | computeChildPreferredLogicalWidths(*child, childMinPreferredLogicalWidth, childMaxPreferredLogicalWidth); |
| 4212 | childMin += childMinPreferredLogicalWidth.ceilToFloat(); |
| 4213 | childMax += childMaxPreferredLogicalWidth.ceilToFloat(); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4214 | |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 4215 | bool clearPreviousFloat = false; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4216 | if (child->isFloating()) { |
commit-queue@webkit.org | dfd8c4d | 2021-04-18 01:03:18 +0000 | [diff] [blame] | 4217 | auto childClearValue = RenderStyle::usedClear(*child); |
| 4218 | if (previousFloat) { |
| 4219 | auto previousFloatValue = RenderStyle::usedFloat(*previousFloat); |
| 4220 | clearPreviousFloat = |
| 4221 | (previousFloatValue == UsedFloat::Left && (childClearValue == UsedClear::Left || childClearValue == UsedClear::Both)) |
| 4222 | || (previousFloatValue == UsedFloat::Right && (childClearValue == UsedClear::Right || childClearValue == UsedClear::Both)); |
| 4223 | } |
| 4224 | previousFloat = child; |
| 4225 | } |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4226 | |
| 4227 | bool canBreakReplacedElement = !child->isImage() || allowImagesToBreak; |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4228 | if (((canBreakReplacedElement && (autoWrap || oldAutoWrap) && (!isPrevChildInlineFlow || shouldBreakLineAfterText)) || clearPreviousFloat)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4229 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4230 | inlineMin = 0; |
| 4231 | } |
| 4232 | |
| 4233 | // If we're supposed to clear the previous float, then terminate maxwidth as well. |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4234 | if (clearPreviousFloat) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4235 | maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax); |
| 4236 | inlineMax = 0; |
| 4237 | } |
| 4238 | |
| 4239 | // Add in text-indent. This is added in only once. |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4240 | if (!addedTextIndent && !child->isFloating()) { |
ross.kirsling@sony.com | 8041465 | 2019-05-21 01:36:11 +0000 | [diff] [blame] | 4241 | LayoutUnit ceiledIndent { textIndent.ceilToFloat() }; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4242 | childMin += ceiledIndent; |
| 4243 | childMax += ceiledIndent; |
| 4244 | |
| 4245 | if (childMin < 0) |
| 4246 | textIndent = LayoutUnit::fromFloatCeil(childMin); |
| 4247 | else |
| 4248 | addedTextIndent = true; |
| 4249 | } |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4250 | |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4251 | if (canHangPunctuationAtStart && !addedStartPunctuationHang && !child->isFloating()) |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4252 | addedStartPunctuationHang = true; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4253 | |
| 4254 | // Add our width to the max. |
| 4255 | inlineMax += std::max<float>(0, childMax); |
| 4256 | |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4257 | if ((!autoWrap || !canBreakReplacedElement || (isPrevChildInlineFlow && !shouldBreakLineAfterText))) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4258 | if (child->isFloating()) |
| 4259 | minLogicalWidth = preferredWidth(minLogicalWidth, childMin); |
| 4260 | else |
| 4261 | inlineMin += childMin; |
| 4262 | } else { |
| 4263 | // Now check our line. |
| 4264 | minLogicalWidth = preferredWidth(minLogicalWidth, childMin); |
| 4265 | |
| 4266 | // Now start a new line. |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4267 | inlineMin = 0; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | if (autoWrap && canBreakReplacedElement && isPrevChildInlineFlow) { |
| 4271 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4272 | inlineMin = 0; |
| 4273 | } |
| 4274 | |
| 4275 | // We are no longer stripping whitespace at the start of a line. |
| 4276 | if (!child->isFloating()) { |
| 4277 | stripFrontSpaces = false; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4278 | trailingSpaceChild = nullptr; |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4279 | lastText = nullptr; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4280 | } |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4281 | } else if (is<RenderText>(*child)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4282 | // Case (3). Text. |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4283 | RenderText& renderText = downcast<RenderText>(*child); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4284 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4285 | if (renderText.style().hasTextCombine() && renderText.isCombineText()) |
zalan@apple.com | 6cad78f | 2017-09-19 20:28:29 +0000 | [diff] [blame] | 4286 | downcast<RenderCombineText>(renderText).combineTextIfNeeded(); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4287 | |
| 4288 | // Determine if we have a breakable character. Pass in |
| 4289 | // whether or not we should ignore any spaces at the front |
| 4290 | // of the string. If those are going to be stripped out, |
| 4291 | // then they shouldn't be considered in the breakable char |
| 4292 | // check. |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4293 | bool strippingBeginWS = stripFrontSpaces; |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4294 | auto widths = renderText.trimmedPreferredWidths(inlineMax, stripFrontSpaces); |
| 4295 | |
| 4296 | childMin = widths.min; |
| 4297 | childMax = widths.max; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4298 | |
| 4299 | // This text object will not be rendered, but it may still provide a breaking opportunity. |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4300 | if (!widths.hasBreak && !childMax) { |
| 4301 | if (autoWrap && (widths.beginWS || widths.endWS)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4302 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4303 | inlineMin = 0; |
| 4304 | } |
| 4305 | continue; |
| 4306 | } |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4307 | |
| 4308 | lastText = &renderText; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4309 | |
| 4310 | if (stripFrontSpaces) |
| 4311 | trailingSpaceChild = child; |
| 4312 | else |
| 4313 | trailingSpaceChild = 0; |
| 4314 | |
| 4315 | // Add in text-indent. This is added in only once. |
| 4316 | float ti = 0; |
| 4317 | if (!addedTextIndent || hasRemainingNegativeTextIndent) { |
| 4318 | ti = textIndent.ceilToFloat(); |
| 4319 | childMin += ti; |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4320 | widths.beginMin += ti; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4321 | |
| 4322 | // It the text indent negative and larger than the child minimum, we re-use the remainder |
| 4323 | // in future minimum calculations, but using the negative value again on the maximum |
| 4324 | // will lead to under-counting the max pref width. |
| 4325 | if (!addedTextIndent) { |
| 4326 | childMax += ti; |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4327 | widths.beginMax += ti; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4328 | addedTextIndent = true; |
| 4329 | } |
| 4330 | |
| 4331 | if (childMin < 0) { |
| 4332 | textIndent = childMin; |
| 4333 | hasRemainingNegativeTextIndent = true; |
| 4334 | } |
| 4335 | } |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4336 | |
| 4337 | // See if we have a hanging punctuation situation at the start. |
| 4338 | if (canHangPunctuationAtStart && !addedStartPunctuationHang) { |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4339 | unsigned startIndex = strippingBeginWS ? renderText.firstCharacterIndexStrippingSpaces() : 0; |
| 4340 | float hangStartWidth = renderText.hangablePunctuationStartWidth(startIndex); |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4341 | childMin -= hangStartWidth; |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4342 | widths.beginMin -= hangStartWidth; |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4343 | childMax -= hangStartWidth; |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4344 | widths.beginMax -= hangStartWidth; |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4345 | addedStartPunctuationHang = true; |
| 4346 | } |
| 4347 | |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4348 | // If we have no breakable characters at all, |
| 4349 | // then this is the easy case. We add ourselves to the current |
| 4350 | // min and max and continue. |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4351 | if (!widths.hasBreakableChar) |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4352 | inlineMin += childMin; |
| 4353 | else { |
| 4354 | // We have a breakable character. Now we need to know if |
| 4355 | // we start and end with whitespace. |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4356 | if (widths.beginWS) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4357 | // End the current line. |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4358 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4359 | } else { |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4360 | inlineMin += widths.beginMin; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4361 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4362 | childMin -= ti; |
| 4363 | } |
| 4364 | |
| 4365 | inlineMin = childMin; |
| 4366 | |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4367 | if (widths.endWS) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4368 | // We end in whitespace, which means we can end our current line. |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4369 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4370 | inlineMin = 0; |
| 4371 | shouldBreakLineAfterText = false; |
| 4372 | } else { |
| 4373 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4374 | inlineMin = widths.endMin; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4375 | shouldBreakLineAfterText = true; |
| 4376 | } |
| 4377 | } |
| 4378 | |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4379 | if (widths.hasBreak) { |
| 4380 | inlineMax += widths.beginMax; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4381 | maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax); |
| 4382 | maxLogicalWidth = preferredWidth(maxLogicalWidth, childMax); |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4383 | inlineMax = widths.endMax; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4384 | addedTextIndent = true; |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4385 | addedStartPunctuationHang = true; |
zalan@apple.com | a46001c | 2021-10-03 21:57:12 +0000 | [diff] [blame] | 4386 | if (widths.endsWithBreak) |
| 4387 | stripFrontSpaces = true; |
| 4388 | |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4389 | } else |
| 4390 | inlineMax += std::max<float>(0, childMax); |
| 4391 | } |
| 4392 | |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4393 | // Ignore spaces after a list marker. |
| 4394 | if (child->isListMarker()) |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4395 | stripFrontSpaces = true; |
| 4396 | } else { |
zalan@apple.com | 37144e6 | 2020-11-01 22:03:36 +0000 | [diff] [blame] | 4397 | if (styleToUse.collapseWhiteSpace()) |
| 4398 | stripTrailingSpace(inlineMax, inlineMin, trailingSpaceChild); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4399 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4400 | maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax); |
| 4401 | inlineMin = inlineMax = 0; |
| 4402 | stripFrontSpaces = true; |
| 4403 | trailingSpaceChild = 0; |
| 4404 | addedTextIndent = true; |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4405 | addedStartPunctuationHang = true; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4406 | } |
| 4407 | |
| 4408 | if (!child->isText() && child->isRenderInline()) |
| 4409 | isPrevChildInlineFlow = true; |
| 4410 | else |
| 4411 | isPrevChildInlineFlow = false; |
| 4412 | |
| 4413 | oldAutoWrap = autoWrap; |
| 4414 | } |
| 4415 | |
| 4416 | if (styleToUse.collapseWhiteSpace()) |
| 4417 | stripTrailingSpace(inlineMax, inlineMin, trailingSpaceChild); |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4418 | |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 4419 | if (canHangPunctuationAtEnd && lastText && lastText->text().length() > 0) { |
| 4420 | unsigned endIndex = trailingSpaceChild == lastText ? lastText->lastCharacterIndexStrippingSpaces() : lastText->text().length() - 1; |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4421 | float endHangWidth = lastText->hangablePunctuationEndWidth(endIndex); |
| 4422 | inlineMin -= endHangWidth; |
| 4423 | inlineMax -= endHangWidth; |
| 4424 | } |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4425 | |
| 4426 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4427 | maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax); |
| 4428 | } |
| 4429 | |
antti@apple.com | 5072de9 | 2021-11-02 16:01:26 +0000 | [diff] [blame] | 4430 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
| 4431 | bool RenderBlockFlow::tryComputePreferredWidthsUsingModernPath(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) |
| 4432 | { |
| 4433 | #if ENABLE_MODERN_PREFERRED_WIDTH_COMPUTATION |
| 4434 | computeAndSetLineLayoutPath(); |
| 4435 | |
| 4436 | // FIXME: Pass the replaced and inline block constrainst to IFC. |
| 4437 | auto canUseModernPathForPreferredWidthComputation = [&] { |
| 4438 | if (lineLayoutPath() != ModernPath) |
| 4439 | return false; |
| 4440 | for (auto walker = InlineWalker(*this); !walker.atEnd(); walker.advance()) { |
| 4441 | auto& renderer = *walker.current(); |
| 4442 | if (renderer.isText()) |
| 4443 | continue; |
| 4444 | if (is<RenderLineBreak>(renderer)) |
| 4445 | continue; |
| 4446 | #if ENABLE_MODERN_PREFERRED_WIDTH_COMPUTATION_FOR_INLINE_BOXES |
| 4447 | if (is<RenderInline>(renderer)) |
| 4448 | continue; |
| 4449 | #endif |
| 4450 | return false; |
| 4451 | } |
| 4452 | return true; |
| 4453 | }; |
| 4454 | |
| 4455 | if (!canUseModernPathForPreferredWidthComputation()) |
| 4456 | return false; |
| 4457 | |
| 4458 | if (!modernLineLayout()) |
| 4459 | m_lineLayout = makeUnique<LayoutIntegration::LineLayout>(*this); |
| 4460 | |
zalan@apple.com | cc71250 | 2021-11-20 14:43:28 +0000 | [diff] [blame] | 4461 | #if ENABLE_MODERN_PREFERRED_WIDTH_COMPUTATION_FOR_INLINE_BOXES |
| 4462 | auto& layoutFormattingContextLineLayout = *this->modernLineLayout(); |
| 4463 | for (auto walker = InlineWalker(*this); !walker.atEnd(); walker.advance()) { |
| 4464 | auto& renderer = *walker.current(); |
| 4465 | if (renderer.isText() || is<RenderLineBreak>(renderer)) |
| 4466 | continue; |
| 4467 | if (is<RenderInline>(renderer)) { |
| 4468 | layoutFormattingContextLineLayout.updateInlineBoxDimensions(downcast<RenderInline>(renderer)); |
| 4469 | continue; |
| 4470 | } |
| 4471 | // FIXME: Add other, inline level box cases. |
| 4472 | ASSERT_NOT_IMPLEMENTED_YET(); |
| 4473 | } |
| 4474 | #endif |
| 4475 | |
antti@apple.com | 5072de9 | 2021-11-02 16:01:26 +0000 | [diff] [blame] | 4476 | std::tie(minLogicalWidth, maxLogicalWidth) = modernLineLayout()->computeIntrinsicWidthConstraints(); |
zalan@apple.com | adb2ec8 | 2021-11-17 14:19:54 +0000 | [diff] [blame] | 4477 | for (auto walker = InlineWalker(*this); !walker.atEnd(); walker.advance()) |
| 4478 | walker.current()->setPreferredLogicalWidthsDirty(false); |
| 4479 | return true; |
antti@apple.com | 5072de9 | 2021-11-02 16:01:26 +0000 | [diff] [blame] | 4480 | #else |
| 4481 | UNUSED_PARAM(minLogicalWidth); |
| 4482 | UNUSED_PARAM(maxLogicalWidth); |
| 4483 | return false; |
| 4484 | #endif |
| 4485 | } |
| 4486 | #endif |
| 4487 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 4488 | } |
| 4489 | // namespace WebCore |