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" |
bjonesbe@adobe.com | 6747809 | 2013-09-09 22:18:17 +0000 | [diff] [blame] | 28 | #include "FloatingObjects.h" |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 29 | #include "Frame.h" |
zalan@apple.com | e36543a | 2014-07-29 01:45:54 +0000 | [diff] [blame] | 30 | #include "FrameSelection.h" |
darin@apple.com | 15708b1 | 2014-03-16 16:38:58 +0000 | [diff] [blame] | 31 | #include "HTMLElement.h" |
cdumez@apple.com | a92c4d6 | 2016-05-20 01:50:51 +0000 | [diff] [blame] | 32 | #include "HTMLInputElement.h" |
| 33 | #include "HTMLTextAreaElement.h" |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 34 | #include "HitTestLocation.h" |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 35 | #include "InlineTextBox.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 36 | #include "LayoutRepainter.h" |
simon.fraser@apple.com | 36676e5 | 2016-05-07 00:05:58 +0000 | [diff] [blame] | 37 | #include "Logging.h" |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 38 | #include "RenderCombineText.h" |
hyatt@apple.com | 531e35d | 2017-04-13 16:37:00 +0000 | [diff] [blame] | 39 | #include "RenderFlexibleBox.h" |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 40 | #include "RenderInline.h" |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 41 | #include "RenderIterator.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 42 | #include "RenderLayer.h" |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 43 | #include "RenderLineBreak.h" |
antti@apple.com | 0b3dffe | 2014-03-24 16:30:52 +0000 | [diff] [blame] | 44 | #include "RenderListItem.h" |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 45 | #include "RenderMarquee.h" |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 46 | #include "RenderMultiColumnFlow.h" |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 47 | #include "RenderMultiColumnSet.h" |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 48 | #include "RenderTableCell.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 49 | #include "RenderText.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 50 | #include "RenderView.h" |
bfulgham@apple.com | b595343 | 2015-02-13 21:56:01 +0000 | [diff] [blame] | 51 | #include "Settings.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 52 | #include "SimpleLineLayoutFunctions.h" |
zalan@apple.com | 5cd09e5 | 2017-02-25 02:14:40 +0000 | [diff] [blame] | 53 | #include "SimpleLineLayoutPagination.h" |
antti@apple.com | 4918b4d | 2017-08-14 13:20:47 +0000 | [diff] [blame] | 54 | #include "TextAutoSizing.h" |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 55 | #include "VerticalPositionCache.h" |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 56 | #include "VisiblePosition.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 57 | |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 58 | namespace WebCore { |
| 59 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 60 | bool RenderBlock::s_canPropagateFloatIntoSibling = false; |
| 61 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 62 | struct SameSizeAsMarginInfo { |
| 63 | uint32_t bitfields : 16; |
| 64 | LayoutUnit margins[2]; |
| 65 | }; |
| 66 | |
| 67 | COMPILE_ASSERT(sizeof(RenderBlockFlow::MarginValues) == sizeof(LayoutUnit[4]), MarginValues_should_stay_small); |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 68 | COMPILE_ASSERT(sizeof(RenderBlockFlow::MarginInfo) == sizeof(SameSizeAsMarginInfo), MarginInfo_should_stay_small); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 69 | |
zalan@apple.com | 6c04c20 | 2017-05-01 00:15:38 +0000 | [diff] [blame] | 70 | class PaginatedLayoutStateMaintainer { |
| 71 | public: |
| 72 | PaginatedLayoutStateMaintainer(RenderBlockFlow& flow) |
| 73 | : m_flow(flow) |
| 74 | , m_pushed(flow.view().pushLayoutStateForPaginationIfNeeded(flow)) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | ~PaginatedLayoutStateMaintainer() |
| 79 | { |
| 80 | if (m_pushed) |
| 81 | m_flow.view().popLayoutState(m_flow); |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | RenderBlockFlow& m_flow; |
| 86 | bool m_pushed { false }; |
| 87 | }; |
| 88 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 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) |
| 96 | , m_discardMargin(false) |
| 97 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 98 | const RenderStyle& blockStyle = block.style(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 99 | ASSERT(block.isRenderView() || block.parent()); |
jfernandez@igalia.com | 136f170 | 2014-12-08 19:13:16 +0000 | [diff] [blame] | 100 | m_canCollapseWithChildren = !block.createsNewFormattingContext() && !block.isRenderView(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 101 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 102 | m_canCollapseMarginBeforeWithChildren = m_canCollapseWithChildren && !beforeBorderPadding && blockStyle.marginBeforeCollapse() != MSEPARATE; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 103 | |
| 104 | // If any height other than auto is specified in CSS, then we don't collapse our bottom |
| 105 | // margins with our children's margins. To do otherwise would be to risk odd visual |
| 106 | // effects when the children overflow out of the parent block and yet still collapse |
| 107 | // with it. We also don't collapse if we have any bottom border/padding. |
| 108 | m_canCollapseMarginAfterWithChildren = m_canCollapseWithChildren && !afterBorderPadding |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 109 | && (blockStyle.logicalHeight().isAuto() && !blockStyle.logicalHeight().value()) && blockStyle.marginAfterCollapse() != MSEPARATE; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 110 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 111 | m_quirkContainer = block.isTableCell() || block.isBody(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 112 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 113 | m_discardMargin = m_canCollapseMarginBeforeWithChildren && block.mustDiscardMarginBefore(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 114 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 115 | m_positiveMargin = (m_canCollapseMarginBeforeWithChildren && !block.mustDiscardMarginBefore()) ? block.maxPositiveMarginBefore() : LayoutUnit(); |
| 116 | m_negativeMargin = (m_canCollapseMarginBeforeWithChildren && !block.mustDiscardMarginBefore()) ? block.maxNegativeMarginBefore() : LayoutUnit(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 117 | } |
| 118 | |
antti@apple.com | 454418f | 2016-04-25 19:49:23 +0000 | [diff] [blame] | 119 | RenderBlockFlow::RenderBlockFlow(Element& element, RenderStyle&& style) |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 120 | : RenderBlock(element, WTFMove(style), RenderBlockFlowFlag) |
dbates@webkit.org | 102013c | 2016-09-26 21:51:25 +0000 | [diff] [blame] | 121 | #if ENABLE(TEXT_AUTOSIZING) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 122 | , m_widthForTextAutosizing(-1) |
| 123 | , m_lineCountForTextAutosizing(NOT_SET) |
| 124 | #endif |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 125 | { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 126 | setChildrenInline(true); |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 127 | } |
| 128 | |
antti@apple.com | 454418f | 2016-04-25 19:49:23 +0000 | [diff] [blame] | 129 | RenderBlockFlow::RenderBlockFlow(Document& document, RenderStyle&& style) |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 130 | : RenderBlock(document, WTFMove(style), RenderBlockFlowFlag) |
dbates@webkit.org | 102013c | 2016-09-26 21:51:25 +0000 | [diff] [blame] | 131 | #if ENABLE(TEXT_AUTOSIZING) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 132 | , m_widthForTextAutosizing(-1) |
| 133 | , m_lineCountForTextAutosizing(NOT_SET) |
| 134 | #endif |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 135 | { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 136 | setChildrenInline(true); |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | RenderBlockFlow::~RenderBlockFlow() |
| 140 | { |
simon.fraser@apple.com | 9812a45 | 2017-03-20 17:28:55 +0000 | [diff] [blame] | 141 | // Do not add any code here. Add it to willBeDestroyed() instead. |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 142 | } |
| 143 | |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 144 | void RenderBlockFlow::insertedIntoTree() |
| 145 | { |
| 146 | RenderBlock::insertedIntoTree(); |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 147 | } |
| 148 | |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 149 | void RenderBlockFlow::willBeDestroyed() |
| 150 | { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 151 | // Make sure to destroy anonymous children first while they are still connected to the rest of the tree, so that they will |
| 152 | // properly dirty line boxes that they are removed from. Effects that do :before/:after only on hover could crash otherwise. |
| 153 | destroyLeftoverChildren(); |
| 154 | |
simon.fraser@apple.com | b59c690 | 2017-03-17 00:20:45 +0000 | [diff] [blame] | 155 | if (!renderTreeBeingDestroyed()) { |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 156 | if (firstRootBox()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 157 | // We can't wait for RenderBox::destroy to clear the selection, |
| 158 | // because by then we will have nuked the line boxes. |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 159 | if (isSelectionBorder()) |
zalan@apple.com | e36543a | 2014-07-29 01:45:54 +0000 | [diff] [blame] | 160 | frame().selection().setNeedsSelectionUpdate(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 161 | |
| 162 | // If we are an anonymous block, then our line boxes might have children |
| 163 | // that will outlast this block. In the non-anonymous block case those |
| 164 | // children will be destroyed by the time we return from this function. |
| 165 | if (isAnonymousBlock()) { |
cdumez@apple.com | c1d54fa | 2015-10-13 19:15:55 +0000 | [diff] [blame] | 166 | for (auto* box = firstRootBox(); box; box = box->nextRootBox()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 167 | while (auto childBox = box->firstChild()) |
| 168 | childBox->removeFromParent(); |
| 169 | } |
| 170 | } |
akling@apple.com | a1986f5 | 2014-12-08 22:17:55 +0000 | [diff] [blame] | 171 | } else if (parent()) |
| 172 | parent()->dirtyLinesFromChangedChild(*this); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 173 | } |
| 174 | |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 175 | m_lineBoxes.deleteLineBoxes(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 176 | |
simon.fraser@apple.com | 9812a45 | 2017-03-20 17:28:55 +0000 | [diff] [blame] | 177 | blockWillBeDestroyed(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 178 | |
| 179 | // NOTE: This jumps down to RenderBox, bypassing RenderBlock since it would do duplicate work. |
| 180 | RenderBox::willBeDestroyed(); |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 181 | } |
| 182 | |
jfernandez@igalia.com | 93f23d2 | 2014-12-09 17:44:40 +0000 | [diff] [blame] | 183 | RenderBlockFlow* RenderBlockFlow::previousSiblingWithOverhangingFloats(bool& parentHasFloats) const |
| 184 | { |
| 185 | // Attempt to locate a previous sibling with overhanging floats. We skip any elements that are |
| 186 | // out of flow (like floating/positioned elements), and we also skip over any objects that may have shifted |
| 187 | // to avoid floats. |
| 188 | parentHasFloats = false; |
| 189 | for (RenderObject* sibling = previousSibling(); sibling; sibling = sibling->previousSibling()) { |
| 190 | if (is<RenderBlockFlow>(*sibling)) { |
| 191 | auto& siblingBlock = downcast<RenderBlockFlow>(*sibling); |
| 192 | if (!siblingBlock.avoidsFloats()) |
| 193 | return &siblingBlock; |
| 194 | } |
| 195 | if (sibling->isFloating()) |
| 196 | parentHasFloats = true; |
| 197 | } |
| 198 | return nullptr; |
| 199 | } |
| 200 | |
bjonesbe@adobe.com | f9f1040 | 2014-02-20 19:40:28 +0000 | [diff] [blame] | 201 | void RenderBlockFlow::rebuildFloatingObjectSetFromIntrudingFloats() |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 202 | { |
| 203 | if (m_floatingObjects) |
| 204 | m_floatingObjects->setHorizontalWritingMode(isHorizontalWritingMode()); |
| 205 | |
| 206 | HashSet<RenderBox*> oldIntrudingFloatSet; |
| 207 | if (!childrenInline() && m_floatingObjects) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 208 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 209 | auto end = floatingObjectSet.end(); |
| 210 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 211 | FloatingObject* floatingObject = it->get(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 212 | if (!floatingObject->isDescendant()) |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 213 | oldIntrudingFloatSet.add(&floatingObject->renderer()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | // Inline blocks are covered by the isReplaced() check in the avoidFloats method. |
simon.fraser@apple.com | f63871d | 2015-10-10 02:20:52 +0000 | [diff] [blame] | 218 | if (avoidsFloats() || isDocumentElementRenderer() || isRenderView() || isFloatingOrOutOfFlowPositioned() || isTableCell()) { |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 219 | if (m_floatingObjects) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 220 | m_floatingObjects->clear(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 221 | if (!oldIntrudingFloatSet.isEmpty()) |
| 222 | markAllDescendantsWithFloatsForLayout(); |
| 223 | return; |
| 224 | } |
| 225 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 226 | RendererToFloatInfoMap floatMap; |
| 227 | |
| 228 | if (m_floatingObjects) { |
bjonesbe@adobe.com | 0434768a | 2013-09-16 22:01:38 +0000 | [diff] [blame] | 229 | if (childrenInline()) |
| 230 | m_floatingObjects->moveAllToFloatInfoMap(floatMap); |
| 231 | else |
| 232 | m_floatingObjects->clear(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | // We should not process floats if the parent node is not a RenderBlock. Otherwise, we will add |
| 236 | // floats in an invalid context. This will cause a crash arising from a bad cast on the parent. |
| 237 | // 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] | 238 | if (!is<RenderBlockFlow>(parent())) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 239 | return; |
| 240 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 241 | // First add in floats from the parent. Self-collapsing blocks let their parent track any floats that intrude into |
| 242 | // 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] | 243 | auto& parentBlock = downcast<RenderBlockFlow>(*parent()); |
| 244 | bool parentHasFloats = false; |
| 245 | RenderBlockFlow* previousBlock = previousSiblingWithOverhangingFloats(parentHasFloats); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 246 | LayoutUnit logicalTopOffset = logicalTop(); |
jfernandez@igalia.com | 93f23d2 | 2014-12-09 17:44:40 +0000 | [diff] [blame] | 247 | if (parentHasFloats || (parentBlock.lowestFloatLogicalBottom() > logicalTopOffset && previousBlock && previousBlock->isSelfCollapsingBlock())) |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 248 | addIntrudingFloats(&parentBlock, &parentBlock, parentBlock.logicalLeftOffsetForContent(), logicalTopOffset); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 249 | |
| 250 | LayoutUnit logicalLeftOffset = 0; |
jfernandez@igalia.com | 93f23d2 | 2014-12-09 17:44:40 +0000 | [diff] [blame] | 251 | if (previousBlock) |
| 252 | logicalTopOffset -= previousBlock->logicalTop(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 253 | else { |
jfernandez@igalia.com | 93f23d2 | 2014-12-09 17:44:40 +0000 | [diff] [blame] | 254 | previousBlock = &parentBlock; |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 255 | logicalLeftOffset += parentBlock.logicalLeftOffsetForContent(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | // 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] | 259 | if (previousBlock->m_floatingObjects && previousBlock->lowestFloatLogicalBottom() > logicalTopOffset) |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 260 | addIntrudingFloats(previousBlock, &parentBlock, logicalLeftOffset, logicalTopOffset); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 261 | |
| 262 | if (childrenInline()) { |
| 263 | LayoutUnit changeLogicalTop = LayoutUnit::max(); |
| 264 | LayoutUnit changeLogicalBottom = LayoutUnit::min(); |
| 265 | if (m_floatingObjects) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 266 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 267 | auto end = floatingObjectSet.end(); |
| 268 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 269 | const auto& floatingObject = *it->get(); |
| 270 | std::unique_ptr<FloatingObject> oldFloatingObject = floatMap.take(&floatingObject.renderer()); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 271 | LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 272 | if (oldFloatingObject) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 273 | LayoutUnit oldLogicalBottom = logicalBottomForFloat(*oldFloatingObject); |
| 274 | if (logicalWidthForFloat(floatingObject) != logicalWidthForFloat(*oldFloatingObject) || logicalLeftForFloat(floatingObject) != logicalLeftForFloat(*oldFloatingObject)) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 275 | changeLogicalTop = 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 276 | changeLogicalBottom = std::max(changeLogicalBottom, std::max(logicalBottom, oldLogicalBottom)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 277 | } else { |
| 278 | if (logicalBottom != oldLogicalBottom) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 279 | changeLogicalTop = std::min(changeLogicalTop, std::min(logicalBottom, oldLogicalBottom)); |
| 280 | changeLogicalBottom = std::max(changeLogicalBottom, std::max(logicalBottom, oldLogicalBottom)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 281 | } |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 282 | LayoutUnit logicalTop = logicalTopForFloat(floatingObject); |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 283 | LayoutUnit oldLogicalTop = logicalTopForFloat(*oldFloatingObject); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 284 | if (logicalTop != oldLogicalTop) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 285 | changeLogicalTop = std::min(changeLogicalTop, std::min(logicalTop, oldLogicalTop)); |
| 286 | changeLogicalBottom = std::max(changeLogicalBottom, std::max(logicalTop, oldLogicalTop)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 290 | if (oldFloatingObject->originatingLine() && !selfNeedsLayout()) { |
| 291 | ASSERT(&oldFloatingObject->originatingLine()->renderer() == this); |
| 292 | oldFloatingObject->originatingLine()->markDirty(); |
| 293 | } |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 294 | } else { |
| 295 | changeLogicalTop = 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 296 | changeLogicalBottom = std::max(changeLogicalBottom, logicalBottom); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 301 | auto end = floatMap.end(); |
| 302 | for (auto it = floatMap.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 303 | const auto& floatingObject = *it->value.get(); |
| 304 | if (!floatingObject.isDescendant()) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 305 | changeLogicalTop = 0; |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 306 | changeLogicalBottom = std::max(changeLogicalBottom, logicalBottomForFloat(floatingObject)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 309 | |
| 310 | markLinesDirtyInBlockRange(changeLogicalTop, changeLogicalBottom); |
| 311 | } else if (!oldIntrudingFloatSet.isEmpty()) { |
| 312 | // If there are previously intruding floats that no longer intrude, then children with floats |
| 313 | // should also get layout because they might need their floating object lists cleared. |
| 314 | if (m_floatingObjects->set().size() < oldIntrudingFloatSet.size()) |
| 315 | markAllDescendantsWithFloatsForLayout(); |
| 316 | else { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 317 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 318 | auto end = floatingObjectSet.end(); |
| 319 | for (auto it = floatingObjectSet.begin(); it != end && !oldIntrudingFloatSet.isEmpty(); ++it) |
| 320 | oldIntrudingFloatSet.remove(&(*it)->renderer()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 321 | if (!oldIntrudingFloatSet.isEmpty()) |
| 322 | markAllDescendantsWithFloatsForLayout(); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 327 | void RenderBlockFlow::adjustIntrinsicLogicalWidthsForColumns(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const |
| 328 | { |
| 329 | if (!style().hasAutoColumnCount() || !style().hasAutoColumnWidth()) { |
| 330 | // The min/max intrinsic widths calculated really tell how much space elements need when |
| 331 | // laid out inside the columns. In order to eventually end up with the desired column width, |
| 332 | // we need to convert them to values pertaining to the multicol container. |
| 333 | int columnCount = style().hasAutoColumnCount() ? 1 : style().columnCount(); |
| 334 | LayoutUnit columnWidth; |
| 335 | LayoutUnit colGap = columnGap(); |
| 336 | LayoutUnit gapExtra = (columnCount - 1) * colGap; |
| 337 | if (style().hasAutoColumnWidth()) |
| 338 | minLogicalWidth = minLogicalWidth * columnCount + gapExtra; |
| 339 | else { |
| 340 | columnWidth = style().columnWidth(); |
| 341 | minLogicalWidth = std::min(minLogicalWidth, columnWidth); |
| 342 | } |
| 343 | // FIXME: If column-count is auto here, we should resolve it to calculate the maximum |
| 344 | // intrinsic width, instead of pretending that it's 1. The only way to do that is by |
| 345 | // performing a layout pass, but this is not an appropriate time or place for layout. The |
| 346 | // good news is that if height is unconstrained and there are no explicit breaks, the |
| 347 | // resolved column-count really should be 1. |
| 348 | maxLogicalWidth = std::max(maxLogicalWidth, columnWidth) * columnCount + gapExtra; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | void RenderBlockFlow::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const |
| 353 | { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 354 | if (childrenInline()) |
| 355 | computeInlinePreferredLogicalWidths(minLogicalWidth, maxLogicalWidth); |
| 356 | else |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 357 | computeBlockPreferredLogicalWidths(minLogicalWidth, maxLogicalWidth); |
| 358 | |
| 359 | maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth); |
| 360 | |
| 361 | adjustIntrinsicLogicalWidthsForColumns(minLogicalWidth, maxLogicalWidth); |
| 362 | |
| 363 | if (!style().autoWrap() && childrenInline()) { |
| 364 | // A horizontal marquee with inline children has no minimum width. |
| 365 | if (layer() && layer()->marquee() && layer()->marquee()->isHorizontal()) |
| 366 | minLogicalWidth = 0; |
| 367 | } |
| 368 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 369 | if (is<RenderTableCell>(*this)) { |
| 370 | Length tableCellWidth = downcast<RenderTableCell>(*this).styleOrColLogicalWidth(); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 371 | if (tableCellWidth.isFixed() && tableCellWidth.value() > 0) |
| 372 | maxLogicalWidth = std::max(minLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(tableCellWidth.value())); |
| 373 | } |
| 374 | |
rego@igalia.com | 76760c7 | 2015-05-14 16:37:27 +0000 | [diff] [blame] | 375 | int scrollbarWidth = intrinsicScrollbarLogicalWidth(); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 376 | maxLogicalWidth += scrollbarWidth; |
| 377 | minLogicalWidth += scrollbarWidth; |
| 378 | } |
| 379 | |
| 380 | bool RenderBlockFlow::recomputeLogicalWidthAndColumnWidth() |
| 381 | { |
| 382 | bool changed = recomputeLogicalWidth(); |
| 383 | |
| 384 | LayoutUnit oldColumnWidth = computedColumnWidth(); |
| 385 | computeColumnCountAndWidth(); |
| 386 | |
| 387 | return changed || oldColumnWidth != computedColumnWidth(); |
| 388 | } |
| 389 | |
| 390 | LayoutUnit RenderBlockFlow::columnGap() const |
| 391 | { |
| 392 | if (style().hasNormalColumnGap()) |
| 393 | return style().fontDescription().computedPixelSize(); // "1em" is recommended as the normal gap setting. Matches <p> margins. |
| 394 | return style().columnGap(); |
| 395 | } |
| 396 | |
| 397 | void RenderBlockFlow::computeColumnCountAndWidth() |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 398 | { |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 399 | // Calculate our column width and column count. |
| 400 | // FIXME: Can overflow on fast/block/float/float-not-removed-from-next-sibling4.html, see https://bugs.webkit.org/show_bug.cgi?id=68744 |
| 401 | unsigned desiredColumnCount = 1; |
| 402 | LayoutUnit desiredColumnWidth = contentLogicalWidth(); |
zalan@apple.com | 08aaba7 | 2016-12-02 23:05:48 +0000 | [diff] [blame] | 403 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 404 | // For now, we don't support multi-column layouts when printing, since we have to do a lot of work for proper pagination. |
| 405 | if (document().paginated() || (style().hasAutoColumnCount() && style().hasAutoColumnWidth()) || !style().hasInlineColumnAxis()) { |
| 406 | setComputedColumnCountAndWidth(desiredColumnCount, desiredColumnWidth); |
| 407 | return; |
| 408 | } |
zalan@apple.com | 08aaba7 | 2016-12-02 23:05:48 +0000 | [diff] [blame] | 409 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 410 | LayoutUnit availWidth = desiredColumnWidth; |
| 411 | LayoutUnit colGap = columnGap(); |
zalan@apple.com | 08aaba7 | 2016-12-02 23:05:48 +0000 | [diff] [blame] | 412 | LayoutUnit colWidth = std::max<LayoutUnit>(1, style().columnWidth()); |
zalan@apple.com | 585798f | 2016-05-18 23:25:47 +0000 | [diff] [blame] | 413 | unsigned colCount = std::max<unsigned>(1, style().columnCount()); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 414 | |
| 415 | if (style().hasAutoColumnWidth() && !style().hasAutoColumnCount()) { |
| 416 | desiredColumnCount = colCount; |
| 417 | desiredColumnWidth = std::max<LayoutUnit>(0, (availWidth - ((desiredColumnCount - 1) * colGap)) / desiredColumnCount); |
| 418 | } else if (!style().hasAutoColumnWidth() && style().hasAutoColumnCount()) { |
zalan@apple.com | 08aaba7 | 2016-12-02 23:05:48 +0000 | [diff] [blame] | 419 | desiredColumnCount = std::max<unsigned>(1, ((availWidth + colGap) / (colWidth + colGap)).toUnsigned()); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 420 | desiredColumnWidth = ((availWidth + colGap) / desiredColumnCount) - colGap; |
| 421 | } else { |
zalan@apple.com | 08aaba7 | 2016-12-02 23:05:48 +0000 | [diff] [blame] | 422 | 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] | 423 | desiredColumnWidth = ((availWidth + colGap) / desiredColumnCount) - colGap; |
| 424 | } |
| 425 | setComputedColumnCountAndWidth(desiredColumnCount, desiredColumnWidth); |
| 426 | } |
| 427 | |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 428 | bool RenderBlockFlow::willCreateColumns(std::optional<unsigned> desiredColumnCount) const |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 429 | { |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 430 | // The following types are not supposed to create multicol context. |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 431 | if (isFileUploadControl() || isTextControl() || isListBox()) |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 432 | return false; |
antti@apple.com | 411949d | 2017-08-30 17:28:10 +0000 | [diff] [blame] | 433 | if (isRenderSVGBlock() || isRenderMathMLBlock() || isRubyRun()) |
| 434 | return false; |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 435 | |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 436 | if (!firstChild()) |
| 437 | return false; |
| 438 | |
antti@apple.com | 411949d | 2017-08-30 17:28:10 +0000 | [diff] [blame] | 439 | if (style().styleType() != NOPSEUDO) |
| 440 | return false; |
| 441 | |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 442 | // 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. |
| 443 | if ((style().overflowY() == OPAGEDX || style().overflowY() == OPAGEDY) && !(isDocumentElementRenderer() || isBody())) |
| 444 | return true; |
| 445 | |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 446 | if (!style().specifiesColumns()) |
| 447 | return false; |
| 448 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 449 | // column-axis with opposite writing direction initiates MultiColumnFlow. |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 450 | if (!style().hasInlineColumnAxis()) |
| 451 | return true; |
| 452 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 453 | // Non-auto column-width always initiates MultiColumnFlow. |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 454 | if (!style().hasAutoColumnWidth()) |
| 455 | return true; |
| 456 | |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 457 | if (desiredColumnCount) |
| 458 | return desiredColumnCount.value() > 1; |
| 459 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 460 | // column-count > 1 always initiates MultiColumnFlow. |
zalan@apple.com | 748d382 | 2016-12-02 21:25:15 +0000 | [diff] [blame] | 461 | if (!style().hasAutoColumnCount()) |
| 462 | return style().columnCount() > 1; |
| 463 | |
| 464 | ASSERT_NOT_REACHED(); |
| 465 | return false; |
| 466 | } |
| 467 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 468 | void RenderBlockFlow::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight) |
| 469 | { |
| 470 | ASSERT(needsLayout()); |
| 471 | |
| 472 | if (!relayoutChildren && simplifiedLayout()) |
| 473 | return; |
| 474 | |
| 475 | LayoutRepainter repainter(*this, checkForRepaintDuringLayout()); |
| 476 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 477 | if (recomputeLogicalWidthAndColumnWidth()) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 478 | relayoutChildren = true; |
| 479 | |
bjonesbe@adobe.com | f9f1040 | 2014-02-20 19:40:28 +0000 | [diff] [blame] | 480 | rebuildFloatingObjectSetFromIntrudingFloats(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 481 | |
| 482 | LayoutUnit previousHeight = logicalHeight(); |
| 483 | // FIXME: should this start out as borderAndPaddingLogicalHeight() + scrollbarLogicalHeight(), |
| 484 | // for consistency with other render classes? |
| 485 | setLogicalHeight(0); |
| 486 | |
| 487 | bool pageLogicalHeightChanged = false; |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 488 | checkForPaginationLogicalHeightChange(relayoutChildren, pageLogicalHeight, pageLogicalHeightChanged); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 489 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 490 | const RenderStyle& styleToUse = style(); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 491 | LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || styleToUse.isFlippedBlocksWritingMode(), pageLogicalHeight, pageLogicalHeightChanged); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 492 | |
zoltan@webkit.org | 7d4f8cc | 2014-03-26 18:20:15 +0000 | [diff] [blame] | 493 | preparePaginationBeforeBlockLayout(relayoutChildren); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 494 | |
| 495 | // We use four values, maxTopPos, maxTopNeg, maxBottomPos, and maxBottomNeg, to track |
| 496 | // our current maximal positive and negative margins. These values are used when we |
| 497 | // are collapsed with adjacent blocks, so for example, if you have block A and B |
| 498 | // collapsing together, then you'd take the maximal positive margin from both A and B |
| 499 | // and subtract it from the maximal negative margin from both A and B to get the |
| 500 | // true collapsed margin. This algorithm is recursive, so when we finish layout() |
| 501 | // our block knows its current maximal positive/negative values. |
| 502 | // |
| 503 | // Start out by setting our margin values to our current margins. Table cells have |
| 504 | // no margins, so we don't fill in the values for table cells. |
| 505 | bool isCell = isTableCell(); |
| 506 | if (!isCell) { |
| 507 | initMaxMarginValues(); |
| 508 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 509 | setHasMarginBeforeQuirk(styleToUse.hasMarginBeforeQuirk()); |
| 510 | setHasMarginAfterQuirk(styleToUse.hasMarginAfterQuirk()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 511 | setPaginationStrut(0); |
| 512 | } |
| 513 | |
| 514 | LayoutUnit repaintLogicalTop = 0; |
| 515 | LayoutUnit repaintLogicalBottom = 0; |
| 516 | LayoutUnit maxFloatLogicalBottom = 0; |
| 517 | if (!firstChild() && !isAnonymousBlock()) |
| 518 | setChildrenInline(true); |
| 519 | if (childrenInline()) |
| 520 | layoutInlineChildren(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
| 521 | else |
| 522 | layoutBlockChildren(relayoutChildren, maxFloatLogicalBottom); |
| 523 | |
| 524 | // Expand our intrinsic height to encompass floats. |
| 525 | LayoutUnit toAdd = borderAndPaddingAfter() + scrollbarLogicalHeight(); |
jfernandez@igalia.com | 136f170 | 2014-12-08 19:13:16 +0000 | [diff] [blame] | 526 | if (lowestFloatLogicalBottom() > (logicalHeight() - toAdd) && createsNewFormattingContext()) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 527 | setLogicalHeight(lowestFloatLogicalBottom() + toAdd); |
| 528 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 529 | if (relayoutForPagination(statePusher) || relayoutToAvoidWidows(statePusher)) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 530 | ASSERT(!shouldBreakAtLineToAvoidWidow()); |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | // Calculate our new height. |
| 535 | LayoutUnit oldHeight = logicalHeight(); |
| 536 | LayoutUnit oldClientAfterEdge = clientLogicalBottom(); |
| 537 | |
| 538 | // Before updating the final size of the flow thread make sure a forced break is applied after the content. |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 539 | // This ensures the size information is correctly computed for the last auto-height fragment receiving content. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 540 | if (is<RenderFragmentedFlow>(*this)) |
| 541 | downcast<RenderFragmentedFlow>(*this).applyBreakAfterContent(oldClientAfterEdge); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 542 | |
| 543 | updateLogicalHeight(); |
| 544 | LayoutUnit newHeight = logicalHeight(); |
| 545 | if (oldHeight != newHeight) { |
| 546 | if (oldHeight > newHeight && maxFloatLogicalBottom > newHeight && !childrenInline()) { |
| 547 | // One of our children's floats may have become an overhanging float for us. We need to look for it. |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 548 | for (auto& blockFlow : childrenOfType<RenderBlockFlow>(*this)) { |
| 549 | if (blockFlow.isFloatingOrOutOfFlowPositioned()) |
| 550 | continue; |
| 551 | if (blockFlow.lowestFloatLogicalBottom() + blockFlow.logicalTop() > newHeight) |
| 552 | addOverhangingFloats(blockFlow, false); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | bool heightChanged = (previousHeight != newHeight); |
| 558 | if (heightChanged) |
| 559 | relayoutChildren = true; |
| 560 | |
simon.fraser@apple.com | f63871d | 2015-10-10 02:20:52 +0000 | [diff] [blame] | 561 | layoutPositionedObjects(relayoutChildren || isDocumentElementRenderer()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 562 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 563 | // Add overflow from children (unless we're multi-column, since in that case all our child overflow is clipped anyway). |
| 564 | computeOverflow(oldClientAfterEdge); |
| 565 | |
| 566 | statePusher.pop(); |
| 567 | |
| 568 | fitBorderToLinesIfNeeded(); |
| 569 | |
| 570 | if (view().layoutState()->m_pageLogicalHeight) |
| 571 | setPageLogicalOffset(view().layoutState()->pageLogicalOffset(this, logicalTop())); |
| 572 | |
| 573 | updateLayerTransform(); |
| 574 | |
| 575 | // Update our scroll information if we're overflow:auto/scroll/hidden now that we know if |
| 576 | // we overflow or not. |
| 577 | updateScrollInfoAfterLayout(); |
| 578 | |
| 579 | // FIXME: This repaint logic should be moved into a separate helper function! |
| 580 | // Repaint with our new bounds if they are different from our old bounds. |
| 581 | bool didFullRepaint = repainter.repaintAfterLayout(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 582 | if (!didFullRepaint && repaintLogicalTop != repaintLogicalBottom && (styleToUse.visibility() == VISIBLE || enclosingLayer()->hasVisibleContent())) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 583 | // FIXME: We could tighten up the left and right invalidation points if we let layoutInlineChildren fill them in based off the particular lines |
| 584 | // it had to lay out. We wouldn't need the hasOverflowClip() hack in that case either. |
| 585 | LayoutUnit repaintLogicalLeft = logicalLeftVisualOverflow(); |
| 586 | LayoutUnit repaintLogicalRight = logicalRightVisualOverflow(); |
| 587 | if (hasOverflowClip()) { |
| 588 | // 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. |
| 589 | // Note the old code did this as well but even for overflow:visible. The addition of hasOverflowClip() at least tightens up the hack a bit. |
| 590 | // layoutInlineChildren should be patched to compute the entire repaint rect. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 591 | repaintLogicalLeft = std::min(repaintLogicalLeft, logicalLeftLayoutOverflow()); |
| 592 | repaintLogicalRight = std::max(repaintLogicalRight, logicalRightLayoutOverflow()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | LayoutRect repaintRect; |
| 596 | if (isHorizontalWritingMode()) |
| 597 | repaintRect = LayoutRect(repaintLogicalLeft, repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft, repaintLogicalBottom - repaintLogicalTop); |
| 598 | else |
| 599 | repaintRect = LayoutRect(repaintLogicalTop, repaintLogicalLeft, repaintLogicalBottom - repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft); |
| 600 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 601 | if (hasOverflowClip()) { |
| 602 | // Adjust repaint rect for scroll offset |
simon.fraser@apple.com | 24e03ba | 2016-05-11 04:48:08 +0000 | [diff] [blame] | 603 | repaintRect.moveBy(-scrollPosition()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 604 | |
| 605 | // Don't allow this rect to spill out of our overflow box. |
| 606 | repaintRect.intersect(LayoutRect(LayoutPoint(), size())); |
| 607 | } |
| 608 | |
| 609 | // Make sure the rect is still non-empty after intersecting for overflow above |
| 610 | if (!repaintRect.isEmpty()) { |
| 611 | repaintRectangle(repaintRect); // We need to do a partial repaint of our content. |
| 612 | if (hasReflection()) |
| 613 | repaintRectangle(reflectedRect(repaintRect)); |
| 614 | } |
| 615 | } |
| 616 | |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 617 | clearNeedsLayout(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void RenderBlockFlow::layoutBlockChildren(bool relayoutChildren, LayoutUnit& maxFloatLogicalBottom) |
| 621 | { |
| 622 | dirtyForLayoutFromPercentageHeightDescendants(); |
| 623 | |
| 624 | LayoutUnit beforeEdge = borderAndPaddingBefore(); |
| 625 | LayoutUnit afterEdge = borderAndPaddingAfter() + scrollbarLogicalHeight(); |
| 626 | |
| 627 | setLogicalHeight(beforeEdge); |
| 628 | |
| 629 | // Lay out our hypothetical grid line as though it occurs at the top of the block. |
| 630 | if (view().layoutState()->lineGrid() == this) |
| 631 | layoutLineGridBox(); |
| 632 | |
| 633 | // The margin struct caches all our current margin collapsing state. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 634 | MarginInfo marginInfo(*this, beforeEdge, afterEdge); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 635 | |
| 636 | // Fieldsets need to find their legend and position it inside the border of the object. |
| 637 | // The legend then gets skipped during normal layout. The same is true for ruby text. |
| 638 | // 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] | 639 | layoutExcludedChildren(relayoutChildren); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 640 | |
| 641 | LayoutUnit previousFloatLogicalBottom = 0; |
| 642 | maxFloatLogicalBottom = 0; |
| 643 | |
| 644 | RenderBox* next = firstChildBox(); |
| 645 | |
| 646 | while (next) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 647 | RenderBox& child = *next; |
| 648 | next = child.nextSiblingBox(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 649 | |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 650 | if (child.isExcludedFromNormalLayout()) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 651 | continue; // Skip this child, since it will be positioned by the specialized subclass (fieldsets and ruby runs). |
| 652 | |
| 653 | updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child); |
| 654 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 655 | if (child.isOutOfFlowPositioned()) { |
| 656 | child.containingBlock()->insertPositionedObject(child); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 657 | adjustPositionedBlock(child, marginInfo); |
| 658 | continue; |
| 659 | } |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 660 | if (child.isFloating()) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 661 | insertFloatingObject(child); |
| 662 | adjustFloatingBlock(marginInfo); |
| 663 | continue; |
| 664 | } |
| 665 | |
| 666 | // Lay out the child. |
| 667 | layoutBlockChild(child, marginInfo, previousFloatLogicalBottom, maxFloatLogicalBottom); |
| 668 | } |
| 669 | |
| 670 | // Now do the handling of the bottom of the block, adding in our bottom border/padding and |
| 671 | // determining the correct collapsed bottom margin information. |
| 672 | handleAfterSideOfBlock(beforeEdge, afterEdge, marginInfo); |
| 673 | } |
| 674 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 675 | void RenderBlockFlow::layoutInlineChildren(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
| 676 | { |
akling@apple.com | a12fee2 | 2015-02-01 02:58:13 +0000 | [diff] [blame] | 677 | if (lineLayoutPath() == UndeterminedPath) |
| 678 | setLineLayoutPath(SimpleLineLayout::canUseFor(*this) ? SimpleLinesPath : LineBoxesPath); |
antti@apple.com | 42fb53d | 2013-10-25 02:33:11 +0000 | [diff] [blame] | 679 | |
akling@apple.com | a12fee2 | 2015-02-01 02:58:13 +0000 | [diff] [blame] | 680 | if (lineLayoutPath() == SimpleLinesPath) { |
zalan@apple.com | e37da96 | 2014-12-11 03:29:29 +0000 | [diff] [blame] | 681 | layoutSimpleLines(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 682 | return; |
| 683 | } |
| 684 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 685 | m_simpleLineLayout = nullptr; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 686 | layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
| 687 | } |
| 688 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 689 | void RenderBlockFlow::layoutBlockChild(RenderBox& child, MarginInfo& marginInfo, LayoutUnit& previousFloatLogicalBottom, LayoutUnit& maxFloatLogicalBottom) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 690 | { |
| 691 | LayoutUnit oldPosMarginBefore = maxPositiveMarginBefore(); |
| 692 | LayoutUnit oldNegMarginBefore = maxNegativeMarginBefore(); |
| 693 | |
| 694 | // 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] | 695 | child.computeAndSetBlockDirectionMargins(*this); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 696 | |
| 697 | // Try to guess our correct logical top position. In most cases this guess will |
| 698 | // be correct. Only if we're wrong (when we compute the real logical top position) |
| 699 | // will we have to potentially relayout. |
| 700 | LayoutUnit estimateWithoutPagination; |
| 701 | LayoutUnit logicalTopEstimate = estimateLogicalTopPosition(child, marginInfo, estimateWithoutPagination); |
| 702 | |
| 703 | // 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] | 704 | LayoutRect oldRect = child.frameRect(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 705 | LayoutUnit oldLogicalTop = logicalTopForChild(child); |
| 706 | |
| 707 | #if !ASSERT_DISABLED |
| 708 | LayoutSize oldLayoutDelta = view().layoutDelta(); |
| 709 | #endif |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 710 | // 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] | 711 | setLogicalTopForChild(child, logicalTopEstimate, ApplyLayoutDelta); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 712 | estimateFragmentRangeForBoxChild(child); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 713 | |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 714 | RenderBlockFlow* childBlockFlow = is<RenderBlockFlow>(child) ? &downcast<RenderBlockFlow>(child) : nullptr; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 715 | bool markDescendantsWithFloats = false; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 716 | if (logicalTopEstimate != oldLogicalTop && !child.avoidsFloats() && childBlockFlow && childBlockFlow->containsFloats()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 717 | markDescendantsWithFloats = true; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 718 | else if (UNLIKELY(logicalTopEstimate.mightBeSaturated())) |
| 719 | // logicalTopEstimate, returned by estimateLogicalTopPosition, might be saturated for |
| 720 | // very large elements. If it does the comparison with oldLogicalTop might yield a |
| 721 | // false negative as adding and removing margins, borders etc from a saturated number |
| 722 | // might yield incorrect results. If this is the case always mark for layout. |
| 723 | markDescendantsWithFloats = true; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 724 | else if (!child.avoidsFloats() || child.shrinkToAvoidFloats()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 725 | // If an element might be affected by the presence of floats, then always mark it for |
| 726 | // layout. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 727 | LayoutUnit fb = std::max(previousFloatLogicalBottom, lowestFloatLogicalBottom()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 728 | if (fb > logicalTopEstimate) |
| 729 | markDescendantsWithFloats = true; |
| 730 | } |
| 731 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 732 | if (childBlockFlow) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 733 | if (markDescendantsWithFloats) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 734 | childBlockFlow->markAllDescendantsWithFloatsForLayout(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 735 | if (!child.isWritingModeRoot()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 736 | previousFloatLogicalBottom = std::max(previousFloatLogicalBottom, oldLogicalTop + childBlockFlow->lowestFloatLogicalBottom()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 737 | } |
| 738 | |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 739 | child.markForPaginationRelayoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 740 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 741 | bool childHadLayout = child.everHadLayout(); |
| 742 | bool childNeededLayout = child.needsLayout(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 743 | if (childNeededLayout) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 744 | child.layout(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 745 | |
| 746 | // Cache if we are at the top of the block right now. |
| 747 | bool atBeforeSideOfBlock = marginInfo.atBeforeSideOfBlock(); |
| 748 | |
| 749 | // Now determine the correct ypos based off examination of collapsing margin |
| 750 | // values. |
| 751 | LayoutUnit logicalTopBeforeClear = collapseMargins(child, marginInfo); |
| 752 | |
| 753 | // Now check for clear. |
| 754 | LayoutUnit logicalTopAfterClear = clearFloatsIfNeeded(child, marginInfo, oldPosMarginBefore, oldNegMarginBefore, logicalTopBeforeClear); |
| 755 | |
| 756 | bool paginated = view().layoutState()->isPaginated(); |
| 757 | if (paginated) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 758 | logicalTopAfterClear = adjustBlockChildForPagination(logicalTopAfterClear, estimateWithoutPagination, child, atBeforeSideOfBlock && logicalTopBeforeClear == logicalTopAfterClear); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 759 | |
| 760 | setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta); |
| 761 | |
| 762 | // Now we have a final top position. See if it really does end up being different from our estimate. |
| 763 | // clearFloatsIfNeeded can also mark the child as needing a layout even though we didn't move. This happens |
| 764 | // 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] | 765 | if (logicalTopAfterClear != logicalTopEstimate || child.needsLayout() || (paginated && childBlockFlow && childBlockFlow->shouldBreakAtLineToAvoidWidow())) { |
| 766 | if (child.shrinkToAvoidFloats()) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 767 | // The child's width depends on the line width. When the child shifts to clear an item, its width can |
| 768 | // 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] | 769 | child.setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 770 | } |
| 771 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 772 | if (childBlockFlow) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 773 | if (!child.avoidsFloats() && childBlockFlow->containsFloats()) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 774 | childBlockFlow->markAllDescendantsWithFloatsForLayout(); |
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 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 777 | } |
| 778 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 779 | if (updateFragmentRangeForBoxChild(child)) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 780 | child.setNeedsLayout(MarkOnlyThis); |
abucur@adobe.com | eaf5e22 | 2014-05-14 14:35:07 +0000 | [diff] [blame] | 781 | |
| 782 | // In case our guess was wrong, relayout the child. |
| 783 | child.layoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 784 | |
| 785 | // We are no longer at the top of the block if we encounter a non-empty child. |
| 786 | // 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] | 787 | if (marginInfo.atBeforeSideOfBlock() && !child.isSelfCollapsingBlock()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 788 | marginInfo.setAtBeforeSideOfBlock(false); |
| 789 | |
| 790 | // Now place the child in the correct left position |
| 791 | determineLogicalLeftPositionForChild(child, ApplyLayoutDelta); |
| 792 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 793 | // 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] | 794 | setLogicalHeight(logicalHeight() + logicalHeightForChildForFragmentation(child)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 795 | if (mustSeparateMarginAfterForChild(child)) { |
| 796 | setLogicalHeight(logicalHeight() + marginAfterForChild(child)); |
| 797 | marginInfo.clearMargin(); |
| 798 | } |
| 799 | // If the child has overhanging floats that intrude into following siblings (or possibly out |
| 800 | // 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] | 801 | if (childBlockFlow && childBlockFlow->containsFloats()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 802 | maxFloatLogicalBottom = std::max(maxFloatLogicalBottom, addOverhangingFloats(*childBlockFlow, !childNeededLayout)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 803 | |
zoltan@webkit.org | 7d4f8cc | 2014-03-26 18:20:15 +0000 | [diff] [blame] | 804 | LayoutSize childOffset = child.location() - oldRect.location(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 805 | if (childOffset.width() || childOffset.height()) { |
| 806 | view().addLayoutDelta(childOffset); |
| 807 | |
| 808 | // If the child moved, we have to repaint it as well as any floating/positioned |
| 809 | // descendants. An exception is if we need a layout. In this case, we know we're going to |
| 810 | // repaint ourselves (and the child) anyway. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 811 | if (childHadLayout && !selfNeedsLayout() && child.checkForRepaintDuringLayout()) |
| 812 | child.repaintDuringLayoutIfMoved(oldRect); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 813 | } |
| 814 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 815 | if (!childHadLayout && child.checkForRepaintDuringLayout()) { |
| 816 | child.repaint(); |
| 817 | child.repaintOverhangingFloats(true); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | if (paginated) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 821 | if (RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow()) |
| 822 | fragmentedFlow->fragmentedFlowDescendantBoxLaidOut(&child); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 823 | // Check for an after page/column break. |
| 824 | LayoutUnit newHeight = applyAfterBreak(child, logicalHeight(), marginInfo); |
| 825 | if (newHeight != height()) |
| 826 | setLogicalHeight(newHeight); |
| 827 | } |
| 828 | |
| 829 | ASSERT(view().layoutDeltaMatches(oldLayoutDelta)); |
| 830 | } |
| 831 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 832 | void RenderBlockFlow::adjustPositionedBlock(RenderBox& child, const MarginInfo& marginInfo) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 833 | { |
| 834 | bool isHorizontal = isHorizontalWritingMode(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 835 | bool hasStaticBlockPosition = child.style().hasStaticBlockPosition(isHorizontal); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 836 | |
| 837 | LayoutUnit logicalTop = logicalHeight(); |
zalan@apple.com | 4d97a00 | 2016-02-24 17:13:33 +0000 | [diff] [blame] | 838 | updateStaticInlinePositionForChild(child, logicalTop, DoNotIndentText); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 839 | |
| 840 | if (!marginInfo.canCollapseWithMarginBefore()) { |
| 841 | // Positioned blocks don't collapse margins, so add the margin provided by |
| 842 | // the container now. The child's own margin is added later when calculating its logical top. |
| 843 | LayoutUnit collapsedBeforePos = marginInfo.positiveMargin(); |
| 844 | LayoutUnit collapsedBeforeNeg = marginInfo.negativeMargin(); |
| 845 | logicalTop += collapsedBeforePos - collapsedBeforeNeg; |
| 846 | } |
| 847 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 848 | RenderLayer* childLayer = child.layer(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 849 | if (childLayer->staticBlockPosition() != logicalTop) { |
| 850 | childLayer->setStaticBlockPosition(logicalTop); |
| 851 | if (hasStaticBlockPosition) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 852 | child.setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 856 | LayoutUnit RenderBlockFlow::marginOffsetForSelfCollapsingBlock() |
| 857 | { |
| 858 | ASSERT(isSelfCollapsingBlock()); |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 859 | RenderBlockFlow* parentBlock = downcast<RenderBlockFlow>(parent()); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 860 | if (parentBlock && style().clear() && parentBlock->getClearDelta(*this, logicalHeight())) |
| 861 | return marginValuesForChild(*this).positiveMarginBefore(); |
| 862 | return LayoutUnit(); |
| 863 | } |
| 864 | |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 865 | void RenderBlockFlow::determineLogicalLeftPositionForChild(RenderBox& child, ApplyLayoutDeltaMode applyDelta) |
| 866 | { |
| 867 | LayoutUnit startPosition = borderStart() + paddingStart(); |
mmaxfield@apple.com | 4195a70 | 2016-04-27 01:25:26 +0000 | [diff] [blame] | 868 | if (shouldPlaceBlockDirectionScrollbarOnLeft()) |
mmaxfield@apple.com | af573be | 2016-03-12 21:18:25 +0000 | [diff] [blame] | 869 | startPosition += (style().isLeftToRightDirection() ? 1 : -1) * verticalScrollbarWidth(); |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 870 | LayoutUnit totalAvailableLogicalWidth = borderAndPaddingLogicalWidth() + availableLogicalWidth(); |
| 871 | |
| 872 | // Add in our start margin. |
| 873 | LayoutUnit childMarginStart = marginStartForChild(child); |
| 874 | LayoutUnit newPosition = startPosition + childMarginStart; |
| 875 | |
| 876 | // Some objects (e.g., tables, horizontal rules, overflow:auto blocks) avoid floats. They need |
| 877 | // 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] | 878 | if (child.avoidsFloats() && containsFloats()) |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 879 | newPosition += computeStartPositionDeltaForChildAvoidingFloats(child, marginStartForChild(child)); |
| 880 | |
| 881 | setLogicalLeftForChild(child, style().isLeftToRightDirection() ? newPosition : totalAvailableLogicalWidth - newPosition - logicalWidthForChild(child), applyDelta); |
| 882 | } |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 883 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 884 | void RenderBlockFlow::adjustFloatingBlock(const MarginInfo& marginInfo) |
| 885 | { |
| 886 | // The float should be positioned taking into account the bottom margin |
| 887 | // of the previous flow. We add that margin into the height, get the |
| 888 | // float positioned properly, and then subtract the margin out of the |
| 889 | // height again. In the case of self-collapsing blocks, we always just |
| 890 | // use the top margins, since the self-collapsing block collapsed its |
| 891 | // own bottom margin into its top margin. |
| 892 | // |
| 893 | // Note also that the previous flow may collapse its margin into the top of |
| 894 | // our block. If this is the case, then we do not add the margin in to our |
| 895 | // height when computing the position of the float. This condition can be tested |
| 896 | // for by simply calling canCollapseWithMarginBefore. See |
| 897 | // http://www.hixie.ch/tests/adhoc/css/box/block/margin-collapse/046.html for |
| 898 | // an example of this scenario. |
| 899 | LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? LayoutUnit() : marginInfo.margin(); |
| 900 | setLogicalHeight(logicalHeight() + marginOffset); |
| 901 | positionNewFloats(); |
| 902 | setLogicalHeight(logicalHeight() - marginOffset); |
| 903 | } |
| 904 | |
zalan@apple.com | 4d97a00 | 2016-02-24 17:13:33 +0000 | [diff] [blame] | 905 | void RenderBlockFlow::updateStaticInlinePositionForChild(RenderBox& child, LayoutUnit logicalTop, IndentTextOrNot shouldIndentText) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 906 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 907 | if (child.style().isOriginalDisplayInlineType()) |
zalan@apple.com | 4d97a00 | 2016-02-24 17:13:33 +0000 | [diff] [blame] | 908 | setStaticInlinePositionForChild(child, logicalTop, startAlignedOffsetForLine(logicalTop, shouldIndentText)); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 909 | else |
| 910 | setStaticInlinePositionForChild(child, logicalTop, startOffsetForContent(logicalTop)); |
| 911 | } |
| 912 | |
| 913 | void RenderBlockFlow::setStaticInlinePositionForChild(RenderBox& child, LayoutUnit blockOffset, LayoutUnit inlinePosition) |
| 914 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 915 | if (enclosingFragmentedFlow()) { |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 916 | // Shift the inline position to exclude the fragment offset. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 917 | inlinePosition += startOffsetForContent() - startOffsetForContent(blockOffset); |
| 918 | } |
| 919 | child.layer()->setStaticInlinePosition(inlinePosition); |
| 920 | } |
| 921 | |
| 922 | RenderBlockFlow::MarginValues RenderBlockFlow::marginValuesForChild(RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 923 | { |
| 924 | LayoutUnit childBeforePositive = 0; |
| 925 | LayoutUnit childBeforeNegative = 0; |
| 926 | LayoutUnit childAfterPositive = 0; |
| 927 | LayoutUnit childAfterNegative = 0; |
| 928 | |
| 929 | LayoutUnit beforeMargin = 0; |
| 930 | LayoutUnit afterMargin = 0; |
| 931 | |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 932 | RenderBlockFlow* childRenderBlock = is<RenderBlockFlow>(child) ? &downcast<RenderBlockFlow>(child) : nullptr; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 933 | |
| 934 | // If the child has the same directionality as we do, then we can just return its |
| 935 | // margins in the same direction. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 936 | if (!child.isWritingModeRoot()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 937 | if (childRenderBlock) { |
| 938 | childBeforePositive = childRenderBlock->maxPositiveMarginBefore(); |
| 939 | childBeforeNegative = childRenderBlock->maxNegativeMarginBefore(); |
| 940 | childAfterPositive = childRenderBlock->maxPositiveMarginAfter(); |
| 941 | childAfterNegative = childRenderBlock->maxNegativeMarginAfter(); |
| 942 | } else { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 943 | beforeMargin = child.marginBefore(); |
| 944 | afterMargin = child.marginAfter(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 945 | } |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 946 | } else if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 947 | // The child has a different directionality. If the child is parallel, then it's just |
| 948 | // flipped relative to us. We can use the margins for the opposite edges. |
| 949 | if (childRenderBlock) { |
| 950 | childBeforePositive = childRenderBlock->maxPositiveMarginAfter(); |
| 951 | childBeforeNegative = childRenderBlock->maxNegativeMarginAfter(); |
| 952 | childAfterPositive = childRenderBlock->maxPositiveMarginBefore(); |
| 953 | childAfterNegative = childRenderBlock->maxNegativeMarginBefore(); |
| 954 | } else { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 955 | beforeMargin = child.marginAfter(); |
| 956 | afterMargin = child.marginBefore(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 957 | } |
| 958 | } else { |
| 959 | // The child is perpendicular to us, which means its margins don't collapse but are on the |
| 960 | // "logical left/right" sides of the child box. We can just return the raw margin in this case. |
| 961 | beforeMargin = marginBeforeForChild(child); |
| 962 | afterMargin = marginAfterForChild(child); |
| 963 | } |
| 964 | |
| 965 | // Resolve uncollapsing margins into their positive/negative buckets. |
| 966 | if (beforeMargin) { |
| 967 | if (beforeMargin > 0) |
| 968 | childBeforePositive = beforeMargin; |
| 969 | else |
| 970 | childBeforeNegative = -beforeMargin; |
| 971 | } |
| 972 | if (afterMargin) { |
| 973 | if (afterMargin > 0) |
| 974 | childAfterPositive = afterMargin; |
| 975 | else |
| 976 | childAfterNegative = -afterMargin; |
| 977 | } |
| 978 | |
| 979 | return MarginValues(childBeforePositive, childBeforeNegative, childAfterPositive, childAfterNegative); |
| 980 | } |
| 981 | |
hyatt@apple.com | 72311dc | 2015-09-10 22:15:46 +0000 | [diff] [blame] | 982 | bool RenderBlockFlow::childrenPreventSelfCollapsing() const |
| 983 | { |
| 984 | if (!childrenInline()) |
| 985 | return RenderBlock::childrenPreventSelfCollapsing(); |
| 986 | |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 987 | return hasLines(); |
hyatt@apple.com | 72311dc | 2015-09-10 22:15:46 +0000 | [diff] [blame] | 988 | } |
| 989 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 990 | LayoutUnit RenderBlockFlow::collapseMargins(RenderBox& child, MarginInfo& marginInfo) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 991 | { |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 992 | return collapseMarginsWithChildInfo(&child, child.previousSibling(), marginInfo); |
| 993 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 994 | |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 995 | LayoutUnit RenderBlockFlow::collapseMarginsWithChildInfo(RenderBox* child, RenderObject* prevSibling, MarginInfo& marginInfo) |
| 996 | { |
| 997 | bool childDiscardMarginBefore = child ? mustDiscardMarginBeforeForChild(*child) : false; |
| 998 | bool childDiscardMarginAfter = child ? mustDiscardMarginAfterForChild(*child) : false; |
| 999 | bool childIsSelfCollapsing = child ? child->isSelfCollapsingBlock() : false; |
| 1000 | bool beforeQuirk = child ? hasMarginBeforeQuirk(*child) : false; |
| 1001 | bool afterQuirk = child ? hasMarginAfterQuirk(*child) : false; |
| 1002 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1003 | // The child discards the before margin when the the after margin has discard in the case of a self collapsing block. |
| 1004 | childDiscardMarginBefore = childDiscardMarginBefore || (childDiscardMarginAfter && childIsSelfCollapsing); |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1005 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1006 | // Get the four margin values for the child and cache them. |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1007 | const MarginValues childMargins = child ? marginValuesForChild(*child) : MarginValues(0, 0, 0, 0); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1008 | |
| 1009 | // Get our max pos and neg top margins. |
| 1010 | LayoutUnit posTop = childMargins.positiveMarginBefore(); |
| 1011 | LayoutUnit negTop = childMargins.negativeMarginBefore(); |
| 1012 | |
| 1013 | // For self-collapsing blocks, collapse our bottom margins into our |
| 1014 | // top to get new posTop and negTop values. |
| 1015 | if (childIsSelfCollapsing) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1016 | posTop = std::max(posTop, childMargins.positiveMarginAfter()); |
| 1017 | negTop = std::max(negTop, childMargins.negativeMarginAfter()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1020 | if (marginInfo.canCollapseWithMarginBefore()) { |
| 1021 | if (!childDiscardMarginBefore && !marginInfo.discardMargin()) { |
| 1022 | // This child is collapsing with the top of the |
| 1023 | // block. If it has larger margin values, then we need to update |
| 1024 | // our own maximal values. |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1025 | if (!document().inQuirksMode() || !marginInfo.quirkContainer() || !beforeQuirk) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1026 | setMaxMarginBeforeValues(std::max(posTop, maxPositiveMarginBefore()), std::max(negTop, maxNegativeMarginBefore())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1027 | |
| 1028 | // The minute any of the margins involved isn't a quirk, don't |
| 1029 | // collapse it away, even if the margin is smaller (www.webreference.com |
| 1030 | // has an example of this, a <dt> with 0.8em author-specified inside |
| 1031 | // a <dl> inside a <td>. |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1032 | if (!marginInfo.determinedMarginBeforeQuirk() && !beforeQuirk && (posTop - negTop)) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1033 | setHasMarginBeforeQuirk(false); |
| 1034 | marginInfo.setDeterminedMarginBeforeQuirk(true); |
| 1035 | } |
| 1036 | |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1037 | if (!marginInfo.determinedMarginBeforeQuirk() && beforeQuirk && !marginBefore()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1038 | // We have no top margin and our top child has a quirky margin. |
| 1039 | // We will pick up this quirky margin and pass it through. |
| 1040 | // This deals with the <td><div><p> case. |
| 1041 | // Don't do this for a block that split two inlines though. You do |
| 1042 | // still apply margins in this case. |
| 1043 | setHasMarginBeforeQuirk(true); |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1044 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1045 | } else |
| 1046 | // The before margin of the container will also discard all the margins it is collapsing with. |
| 1047 | setMustDiscardMarginBefore(); |
| 1048 | } |
| 1049 | |
| 1050 | // Once we find a child with discardMarginBefore all the margins collapsing with us must also discard. |
| 1051 | if (childDiscardMarginBefore) { |
| 1052 | marginInfo.setDiscardMargin(true); |
| 1053 | marginInfo.clearMargin(); |
| 1054 | } |
| 1055 | |
| 1056 | if (marginInfo.quirkContainer() && marginInfo.atBeforeSideOfBlock() && (posTop - negTop)) |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1057 | marginInfo.setHasMarginBeforeQuirk(beforeQuirk); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1058 | |
| 1059 | LayoutUnit beforeCollapseLogicalTop = logicalHeight(); |
| 1060 | LayoutUnit logicalTop = beforeCollapseLogicalTop; |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1061 | |
| 1062 | LayoutUnit clearanceForSelfCollapsingBlock; |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1063 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1064 | // 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 |
| 1065 | // 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 |
| 1066 | // 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] | 1067 | if (!marginInfo.canCollapseWithMarginBefore() && is<RenderBlockFlow>(prevSibling) && downcast<RenderBlockFlow>(*prevSibling).isSelfCollapsingBlock()) { |
| 1068 | clearanceForSelfCollapsingBlock = downcast<RenderBlockFlow>(*prevSibling).marginOffsetForSelfCollapsingBlock(); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1069 | setLogicalHeight(logicalHeight() - clearanceForSelfCollapsingBlock); |
| 1070 | } |
| 1071 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1072 | if (childIsSelfCollapsing) { |
| 1073 | // For a self collapsing block both the before and after margins get discarded. The block doesn't contribute anything to the height of the block. |
| 1074 | // Also, the child's top position equals the logical height of the container. |
| 1075 | if (!childDiscardMarginBefore && !marginInfo.discardMargin()) { |
| 1076 | // This child has no height. We need to compute our |
| 1077 | // position before we collapse the child's margins together, |
| 1078 | // so that we can get an accurate position for the zero-height block. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1079 | LayoutUnit collapsedBeforePos = std::max(marginInfo.positiveMargin(), childMargins.positiveMarginBefore()); |
| 1080 | LayoutUnit collapsedBeforeNeg = std::max(marginInfo.negativeMargin(), childMargins.negativeMarginBefore()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1081 | marginInfo.setMargin(collapsedBeforePos, collapsedBeforeNeg); |
| 1082 | |
| 1083 | // Now collapse the child's margins together, which means examining our |
| 1084 | // bottom margin values as well. |
| 1085 | marginInfo.setPositiveMarginIfLarger(childMargins.positiveMarginAfter()); |
| 1086 | marginInfo.setNegativeMarginIfLarger(childMargins.negativeMarginAfter()); |
| 1087 | |
| 1088 | if (!marginInfo.canCollapseWithMarginBefore()) |
| 1089 | // We need to make sure that the position of the self-collapsing block |
| 1090 | // is correct, since it could have overflowing content |
| 1091 | // that needs to be positioned correctly (e.g., a block that |
| 1092 | // had a specified height of 0 but that actually had subcontent). |
| 1093 | logicalTop = logicalHeight() + collapsedBeforePos - collapsedBeforeNeg; |
| 1094 | } |
| 1095 | } else { |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1096 | if (child && mustSeparateMarginBeforeForChild(*child)) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1097 | ASSERT(!marginInfo.discardMargin() || (marginInfo.discardMargin() && !marginInfo.margin())); |
| 1098 | // If we are at the before side of the block and we collapse, ignore the computed margin |
| 1099 | // and just add the child margin to the container height. This will correctly position |
| 1100 | // the child inside the container. |
zalan@apple.com | a4d0055 | 2014-01-25 00:21:59 +0000 | [diff] [blame] | 1101 | LayoutUnit separateMargin = !marginInfo.canCollapseWithMarginBefore() ? marginInfo.margin() : LayoutUnit::fromPixel(0); |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1102 | setLogicalHeight(logicalHeight() + separateMargin + marginBeforeForChild(*child)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1103 | logicalTop = logicalHeight(); |
| 1104 | } else if (!marginInfo.discardMargin() && (!marginInfo.atBeforeSideOfBlock() |
| 1105 | || (!marginInfo.canCollapseMarginBeforeWithChildren() |
| 1106 | && (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginBeforeQuirk())))) { |
| 1107 | // We're collapsing with a previous sibling's margins and not |
| 1108 | // with the top of the block. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1109 | 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] | 1110 | logicalTop = logicalHeight(); |
| 1111 | } |
| 1112 | |
| 1113 | marginInfo.setDiscardMargin(childDiscardMarginAfter); |
| 1114 | |
| 1115 | if (!marginInfo.discardMargin()) { |
| 1116 | marginInfo.setPositiveMargin(childMargins.positiveMarginAfter()); |
| 1117 | marginInfo.setNegativeMargin(childMargins.negativeMarginAfter()); |
| 1118 | } else |
| 1119 | marginInfo.clearMargin(); |
| 1120 | |
| 1121 | if (marginInfo.margin()) |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1122 | marginInfo.setHasMarginAfterQuirk(afterQuirk); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | // If margins would pull us past the top of the next page, then we need to pull back and pretend like the margins |
| 1126 | // collapsed into the page edge. |
| 1127 | LayoutState* layoutState = view().layoutState(); |
| 1128 | if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTop > beforeCollapseLogicalTop |
| 1129 | && hasNextPage(beforeCollapseLogicalTop)) { |
| 1130 | LayoutUnit oldLogicalTop = logicalTop; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1131 | logicalTop = std::min(logicalTop, nextPageLogicalTop(beforeCollapseLogicalTop)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1132 | setLogicalHeight(logicalHeight() + (logicalTop - oldLogicalTop)); |
| 1133 | } |
| 1134 | |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1135 | if (is<RenderBlockFlow>(prevSibling) && !prevSibling->isFloatingOrOutOfFlowPositioned()) { |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1136 | // 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 |
| 1137 | // any floats from the parent will now overhang. |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1138 | RenderBlockFlow& block = downcast<RenderBlockFlow>(*prevSibling); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1139 | LayoutUnit oldLogicalHeight = logicalHeight(); |
| 1140 | setLogicalHeight(logicalTop); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1141 | if (block.containsFloats() && !block.avoidsFloats() && (block.logicalTop() + block.lowestFloatLogicalBottom()) > logicalTop) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1142 | addOverhangingFloats(block, false); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1143 | setLogicalHeight(oldLogicalHeight); |
| 1144 | |
| 1145 | // If |child|'s previous sibling is a self-collapsing block that cleared a float and margin collapsing resulted in |child| moving up |
| 1146 | // 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 |
| 1147 | // floats in the parent that overhang |child|'s new logical top. |
| 1148 | bool logicalTopIntrudesIntoFloat = clearanceForSelfCollapsingBlock > 0 && logicalTop < beforeCollapseLogicalTop; |
hyatt@apple.com | 9a79c62 | 2015-09-15 18:38:18 +0000 | [diff] [blame] | 1149 | if (child && logicalTopIntrudesIntoFloat && containsFloats() && !child->avoidsFloats() && lowestFloatLogicalBottom() > logicalTop) |
| 1150 | child->setNeedsLayout(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1151 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1152 | |
| 1153 | return logicalTop; |
| 1154 | } |
| 1155 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1156 | 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] | 1157 | { |
| 1158 | LayoutUnit heightIncrease = getClearDelta(child, yPos); |
| 1159 | if (!heightIncrease) |
| 1160 | return yPos; |
| 1161 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1162 | if (child.isSelfCollapsingBlock()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1163 | bool childDiscardMargin = mustDiscardMarginBeforeForChild(child) || mustDiscardMarginAfterForChild(child); |
| 1164 | |
| 1165 | // For self-collapsing blocks that clear, they can still collapse their |
| 1166 | // margins with following siblings. Reset the current margins to represent |
| 1167 | // the self-collapsing block's margins only. |
| 1168 | // If DISCARD is specified for -webkit-margin-collapse, reset the margin values. |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1169 | MarginValues childMargins = marginValuesForChild(child); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1170 | if (!childDiscardMargin) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1171 | marginInfo.setPositiveMargin(std::max(childMargins.positiveMarginBefore(), childMargins.positiveMarginAfter())); |
| 1172 | marginInfo.setNegativeMargin(std::max(childMargins.negativeMarginBefore(), childMargins.negativeMarginAfter())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1173 | } else |
| 1174 | marginInfo.clearMargin(); |
| 1175 | marginInfo.setDiscardMargin(childDiscardMargin); |
| 1176 | |
| 1177 | // CSS2.1 states: |
| 1178 | // "If the top and bottom margins of an element with clearance are adjoining, its margins collapse with |
| 1179 | // the adjoining margins of following siblings but that resulting margin does not collapse with the bottom margin of the parent block." |
| 1180 | // So the parent's bottom margin cannot collapse through this block or any subsequent self-collapsing blocks. Check subsequent siblings |
| 1181 | // for a block with height - if none is found then don't allow the margins to collapse with the parent. |
| 1182 | bool wouldCollapseMarginsWithParent = marginInfo.canCollapseMarginAfterWithChildren(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1183 | for (RenderBox* curr = child.nextSiblingBox(); curr && wouldCollapseMarginsWithParent; curr = curr->nextSiblingBox()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1184 | if (!curr->isFloatingOrOutOfFlowPositioned() && !curr->isSelfCollapsingBlock()) |
| 1185 | wouldCollapseMarginsWithParent = false; |
| 1186 | } |
| 1187 | if (wouldCollapseMarginsWithParent) |
| 1188 | marginInfo.setCanCollapseMarginAfterWithChildren(false); |
| 1189 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1190 | // 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 |
| 1191 | // its own at the correct vertical position. If subsequent siblings attempt to collapse with |child|'s margins in |collapseMargins| we will |
| 1192 | // 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 |
| 1193 | // margins can collapse at the correct vertical position. |
| 1194 | // 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 |
| 1195 | // (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], |
| 1196 | // i.e., clearance = [height of float] - margin-top". |
| 1197 | setLogicalHeight(child.logicalTop() + childMargins.negativeMarginBefore()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1198 | } else |
| 1199 | // Increase our height by the amount we had to clear. |
| 1200 | setLogicalHeight(logicalHeight() + heightIncrease); |
| 1201 | |
| 1202 | if (marginInfo.canCollapseWithMarginBefore()) { |
| 1203 | // We can no longer collapse with the top of the block since a clear |
| 1204 | // occurred. The empty blocks collapse into the cleared block. |
| 1205 | // FIXME: This isn't quite correct. Need clarification for what to do |
| 1206 | // if the height the cleared block is offset by is smaller than the |
| 1207 | // margins involved. |
| 1208 | setMaxMarginBeforeValues(oldTopPosMargin, oldTopNegMargin); |
| 1209 | marginInfo.setAtBeforeSideOfBlock(false); |
| 1210 | |
| 1211 | // In case the child discarded the before margin of the block we need to reset the mustDiscardMarginBefore flag to the initial value. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1212 | setMustDiscardMarginBefore(style().marginBeforeCollapse() == MDISCARD); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1215 | return yPos + heightIncrease; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1218 | void RenderBlockFlow::marginBeforeEstimateForChild(RenderBox& child, LayoutUnit& positiveMarginBefore, LayoutUnit& negativeMarginBefore, bool& discardMarginBefore) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1219 | { |
| 1220 | // Give up if in quirks mode and we're a body/table cell and the top margin of the child box is quirky. |
| 1221 | // Give up if the child specified -webkit-margin-collapse: separate that prevents collapsing. |
| 1222 | // FIXME: Use writing mode independent accessor for marginBeforeCollapse. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1223 | if ((document().inQuirksMode() && hasMarginAfterQuirk(child) && (isTableCell() || isBody())) || child.style().marginBeforeCollapse() == MSEPARATE) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1224 | return; |
| 1225 | |
| 1226 | // The margins are discarded by a child that specified -webkit-margin-collapse: discard. |
| 1227 | // FIXME: Use writing mode independent accessor for marginBeforeCollapse. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1228 | if (child.style().marginBeforeCollapse() == MDISCARD) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1229 | positiveMarginBefore = 0; |
| 1230 | negativeMarginBefore = 0; |
| 1231 | discardMarginBefore = true; |
| 1232 | return; |
| 1233 | } |
| 1234 | |
| 1235 | LayoutUnit beforeChildMargin = marginBeforeForChild(child); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1236 | positiveMarginBefore = std::max(positiveMarginBefore, beforeChildMargin); |
| 1237 | negativeMarginBefore = std::max(negativeMarginBefore, -beforeChildMargin); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1238 | |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1239 | if (!is<RenderBlockFlow>(child)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1240 | return; |
| 1241 | |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1242 | RenderBlockFlow& childBlock = downcast<RenderBlockFlow>(child); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1243 | if (childBlock.childrenInline() || childBlock.isWritingModeRoot()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1244 | return; |
| 1245 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1246 | MarginInfo childMarginInfo(childBlock, childBlock.borderAndPaddingBefore(), childBlock.borderAndPaddingAfter()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1247 | if (!childMarginInfo.canCollapseMarginBeforeWithChildren()) |
| 1248 | return; |
| 1249 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1250 | RenderBox* grandchildBox = childBlock.firstChildBox(); |
| 1251 | for (; grandchildBox; grandchildBox = grandchildBox->nextSiblingBox()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1252 | if (!grandchildBox->isFloatingOrOutOfFlowPositioned()) |
| 1253 | break; |
| 1254 | } |
| 1255 | |
| 1256 | // Give up if there is clearance on the box, since it probably won't collapse into us. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1257 | if (!grandchildBox || grandchildBox->style().clear() != CNONE) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1258 | return; |
| 1259 | |
| 1260 | // Make sure to update the block margins now for the grandchild box so that we're looking at current values. |
| 1261 | if (grandchildBox->needsLayout()) { |
mmaxfield@apple.com | 09804f4 | 2016-03-23 00:58:34 +0000 | [diff] [blame] | 1262 | grandchildBox->computeAndSetBlockDirectionMargins(*this); |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 1263 | if (is<RenderBlock>(*grandchildBox)) { |
| 1264 | RenderBlock& grandchildBlock = downcast<RenderBlock>(*grandchildBox); |
| 1265 | grandchildBlock.setHasMarginBeforeQuirk(grandchildBox->style().hasMarginBeforeQuirk()); |
| 1266 | grandchildBlock.setHasMarginAfterQuirk(grandchildBox->style().hasMarginAfterQuirk()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | // Collapse the margin of the grandchild box with our own to produce an estimate. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1271 | childBlock.marginBeforeEstimateForChild(*grandchildBox, positiveMarginBefore, negativeMarginBefore, discardMarginBefore); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1274 | LayoutUnit RenderBlockFlow::estimateLogicalTopPosition(RenderBox& child, const MarginInfo& marginInfo, LayoutUnit& estimateWithoutPagination) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1275 | { |
| 1276 | // FIXME: We need to eliminate the estimation of vertical position, because when it's wrong we sometimes trigger a pathological |
| 1277 | // relayout if there are intruding floats. |
| 1278 | LayoutUnit logicalTopEstimate = logicalHeight(); |
| 1279 | if (!marginInfo.canCollapseWithMarginBefore()) { |
| 1280 | LayoutUnit positiveMarginBefore = 0; |
| 1281 | LayoutUnit negativeMarginBefore = 0; |
| 1282 | bool discardMarginBefore = false; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1283 | if (child.selfNeedsLayout()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1284 | // Try to do a basic estimation of how the collapse is going to go. |
| 1285 | marginBeforeEstimateForChild(child, positiveMarginBefore, negativeMarginBefore, discardMarginBefore); |
| 1286 | } else { |
| 1287 | // Use the cached collapsed margin values from a previous layout. Most of the time they |
| 1288 | // will be right. |
| 1289 | MarginValues marginValues = marginValuesForChild(child); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1290 | positiveMarginBefore = std::max(positiveMarginBefore, marginValues.positiveMarginBefore()); |
| 1291 | negativeMarginBefore = std::max(negativeMarginBefore, marginValues.negativeMarginBefore()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1292 | discardMarginBefore = mustDiscardMarginBeforeForChild(child); |
| 1293 | } |
| 1294 | |
| 1295 | // Collapse the result with our current margins. |
| 1296 | if (!discardMarginBefore) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1297 | logicalTopEstimate += std::max(marginInfo.positiveMargin(), positiveMarginBefore) - std::max(marginInfo.negativeMargin(), negativeMarginBefore); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | // Adjust logicalTopEstimate down to the next page if the margins are so large that we don't fit on the current |
| 1301 | // page. |
| 1302 | LayoutState* layoutState = view().layoutState(); |
| 1303 | if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTopEstimate > logicalHeight() |
| 1304 | && hasNextPage(logicalHeight())) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1305 | logicalTopEstimate = std::min(logicalTopEstimate, nextPageLogicalTop(logicalHeight())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1306 | |
| 1307 | logicalTopEstimate += getClearDelta(child, logicalTopEstimate); |
| 1308 | |
| 1309 | estimateWithoutPagination = logicalTopEstimate; |
| 1310 | |
| 1311 | if (layoutState->isPaginated()) { |
| 1312 | // If the object has a page or column break value of "before", then we should shift to the top of the next page. |
| 1313 | logicalTopEstimate = applyBeforeBreak(child, logicalTopEstimate); |
| 1314 | |
| 1315 | // For replaced elements and scrolled elements, we want to shift them to the next page if they don't fit on the current one. |
| 1316 | logicalTopEstimate = adjustForUnsplittableChild(child, logicalTopEstimate); |
| 1317 | |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 1318 | if (!child.selfNeedsLayout() && is<RenderBlock>(child)) |
| 1319 | logicalTopEstimate += downcast<RenderBlock>(child).paginationStrut(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | return logicalTopEstimate; |
| 1323 | } |
| 1324 | |
| 1325 | void RenderBlockFlow::setCollapsedBottomMargin(const MarginInfo& marginInfo) |
| 1326 | { |
| 1327 | if (marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore()) { |
| 1328 | // Update the after side margin of the container to discard if the after margin of the last child also discards and we collapse with it. |
| 1329 | // Don't update the max margin values because we won't need them anyway. |
| 1330 | if (marginInfo.discardMargin()) { |
| 1331 | setMustDiscardMarginAfter(); |
| 1332 | return; |
| 1333 | } |
| 1334 | |
| 1335 | // Update our max pos/neg bottom margins, since we collapsed our bottom margins |
| 1336 | // with our children. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1337 | setMaxMarginAfterValues(std::max(maxPositiveMarginAfter(), marginInfo.positiveMargin()), std::max(maxNegativeMarginAfter(), marginInfo.negativeMargin())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1338 | |
| 1339 | if (!marginInfo.hasMarginAfterQuirk()) |
| 1340 | setHasMarginAfterQuirk(false); |
| 1341 | |
| 1342 | if (marginInfo.hasMarginAfterQuirk() && !marginAfter()) |
| 1343 | // We have no bottom margin and our last child has a quirky margin. |
| 1344 | // We will pick up this quirky margin and pass it through. |
| 1345 | // This deals with the <td><div><p> case. |
| 1346 | setHasMarginAfterQuirk(true); |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | void RenderBlockFlow::handleAfterSideOfBlock(LayoutUnit beforeSide, LayoutUnit afterSide, MarginInfo& marginInfo) |
| 1351 | { |
| 1352 | marginInfo.setAtAfterSideOfBlock(true); |
| 1353 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1354 | // If our last child was a self-collapsing block with clearance then our logical height is flush with the |
| 1355 | // bottom edge of the float that the child clears. The correct vertical position for the margin-collapsing we want |
| 1356 | // to perform now is at the child's margin-top - so adjust our height to that position. |
| 1357 | RenderObject* lastBlock = lastChild(); |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1358 | if (is<RenderBlockFlow>(lastBlock) && downcast<RenderBlockFlow>(*lastBlock).isSelfCollapsingBlock()) |
| 1359 | setLogicalHeight(logicalHeight() - downcast<RenderBlockFlow>(*lastBlock).marginOffsetForSelfCollapsingBlock()); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1360 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 1361 | // If we can't collapse with children then add in the bottom margin. |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1362 | if (!marginInfo.discardMargin() && (!marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore() |
| 1363 | && (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginAfterQuirk()))) |
| 1364 | setLogicalHeight(logicalHeight() + marginInfo.margin()); |
| 1365 | |
| 1366 | // Now add in our bottom border/padding. |
| 1367 | setLogicalHeight(logicalHeight() + afterSide); |
| 1368 | |
| 1369 | // Negative margins can cause our height to shrink below our minimal height (border/padding). |
| 1370 | // 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] | 1371 | setLogicalHeight(std::max(logicalHeight(), beforeSide + afterSide)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1372 | |
| 1373 | // Update our bottom collapsed margin info. |
| 1374 | setCollapsedBottomMargin(marginInfo); |
| 1375 | } |
| 1376 | |
| 1377 | void RenderBlockFlow::setMaxMarginBeforeValues(LayoutUnit pos, LayoutUnit neg) |
| 1378 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1379 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1380 | if (pos == RenderBlockFlowRareData::positiveMarginBeforeDefault(*this) && neg == RenderBlockFlowRareData::negativeMarginBeforeDefault(*this)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1381 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1382 | materializeRareBlockFlowData(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1383 | } |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1384 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1385 | rareBlockFlowData()->m_margins.setPositiveMarginBefore(pos); |
| 1386 | rareBlockFlowData()->m_margins.setNegativeMarginBefore(neg); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | void RenderBlockFlow::setMaxMarginAfterValues(LayoutUnit pos, LayoutUnit neg) |
| 1390 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1391 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1392 | if (pos == RenderBlockFlowRareData::positiveMarginAfterDefault(*this) && neg == RenderBlockFlowRareData::negativeMarginAfterDefault(*this)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1393 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1394 | materializeRareBlockFlowData(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1395 | } |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1396 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1397 | rareBlockFlowData()->m_margins.setPositiveMarginAfter(pos); |
| 1398 | rareBlockFlowData()->m_margins.setNegativeMarginAfter(neg); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | void RenderBlockFlow::setMustDiscardMarginBefore(bool value) |
| 1402 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1403 | if (style().marginBeforeCollapse() == MDISCARD) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1404 | ASSERT(value); |
| 1405 | return; |
| 1406 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1407 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1408 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1409 | if (!value) |
| 1410 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1411 | materializeRareBlockFlowData(); |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1412 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1413 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1414 | rareBlockFlowData()->m_discardMarginBefore = value; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | void RenderBlockFlow::setMustDiscardMarginAfter(bool value) |
| 1418 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1419 | if (style().marginAfterCollapse() == MDISCARD) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1420 | ASSERT(value); |
| 1421 | return; |
| 1422 | } |
| 1423 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1424 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1425 | if (!value) |
| 1426 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1427 | materializeRareBlockFlowData(); |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1428 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1429 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1430 | rareBlockFlowData()->m_discardMarginAfter = value; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | bool RenderBlockFlow::mustDiscardMarginBefore() const |
| 1434 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1435 | return style().marginBeforeCollapse() == MDISCARD || (hasRareBlockFlowData() && rareBlockFlowData()->m_discardMarginBefore); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | bool RenderBlockFlow::mustDiscardMarginAfter() const |
| 1439 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1440 | return style().marginAfterCollapse() == MDISCARD || (hasRareBlockFlowData() && rareBlockFlowData()->m_discardMarginAfter); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1443 | bool RenderBlockFlow::mustDiscardMarginBeforeForChild(const RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1444 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1445 | ASSERT(!child.selfNeedsLayout()); |
| 1446 | if (!child.isWritingModeRoot()) |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1447 | return is<RenderBlockFlow>(child) ? downcast<RenderBlockFlow>(child).mustDiscardMarginBefore() : (child.style().marginBeforeCollapse() == MDISCARD); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1448 | if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1449 | return is<RenderBlockFlow>(child) ? downcast<RenderBlockFlow>(child).mustDiscardMarginAfter() : (child.style().marginAfterCollapse() == MDISCARD); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1450 | |
| 1451 | // FIXME: We return false here because the implementation is not geometrically complete. We have values only for before/after, not start/end. |
| 1452 | // In case the boxes are perpendicular we assume the property is not specified. |
| 1453 | return false; |
| 1454 | } |
| 1455 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1456 | bool RenderBlockFlow::mustDiscardMarginAfterForChild(const RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1457 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1458 | ASSERT(!child.selfNeedsLayout()); |
| 1459 | if (!child.isWritingModeRoot()) |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1460 | return is<RenderBlockFlow>(child) ? downcast<RenderBlockFlow>(child).mustDiscardMarginAfter() : (child.style().marginAfterCollapse() == MDISCARD); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1461 | if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1462 | return is<RenderBlockFlow>(child) ? downcast<RenderBlockFlow>(child).mustDiscardMarginBefore() : (child.style().marginBeforeCollapse() == MDISCARD); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1463 | |
| 1464 | // FIXME: See |mustDiscardMarginBeforeForChild| above. |
| 1465 | return false; |
| 1466 | } |
| 1467 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1468 | bool RenderBlockFlow::mustSeparateMarginBeforeForChild(const RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1469 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1470 | ASSERT(!child.selfNeedsLayout()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1471 | const RenderStyle& childStyle = child.style(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1472 | if (!child.isWritingModeRoot()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1473 | return childStyle.marginBeforeCollapse() == MSEPARATE; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1474 | if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1475 | return childStyle.marginAfterCollapse() == MSEPARATE; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1476 | |
| 1477 | // FIXME: See |mustDiscardMarginBeforeForChild| above. |
| 1478 | return false; |
| 1479 | } |
| 1480 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1481 | bool RenderBlockFlow::mustSeparateMarginAfterForChild(const RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1482 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1483 | ASSERT(!child.selfNeedsLayout()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1484 | const RenderStyle& childStyle = child.style(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1485 | if (!child.isWritingModeRoot()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1486 | return childStyle.marginAfterCollapse() == MSEPARATE; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1487 | if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1488 | return childStyle.marginBeforeCollapse() == MSEPARATE; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1489 | |
| 1490 | // FIXME: See |mustDiscardMarginBeforeForChild| above. |
| 1491 | return false; |
| 1492 | } |
| 1493 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1494 | static bool inNormalFlow(RenderBox& child) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1495 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1496 | RenderBlock* curr = child.containingBlock(); |
| 1497 | while (curr && curr != &child.view()) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1498 | if (curr->isRenderFragmentedFlow()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1499 | return true; |
| 1500 | if (curr->isFloatingOrOutOfFlowPositioned()) |
| 1501 | return false; |
| 1502 | curr = curr->containingBlock(); |
| 1503 | } |
| 1504 | return true; |
| 1505 | } |
| 1506 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1507 | LayoutUnit RenderBlockFlow::applyBeforeBreak(RenderBox& child, LayoutUnit logicalOffset) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1508 | { |
| 1509 | // FIXME: Add page break checking here when we support printing. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1510 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1511 | bool isInsideMulticolFlow = fragmentedFlow; |
| 1512 | bool checkColumnBreaks = fragmentedFlow && fragmentedFlow->shouldCheckColumnBreaks(); |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1513 | bool checkPageBreaks = !checkColumnBreaks && view().layoutState()->m_pageLogicalHeight; // FIXME: Once columns can print we have to check this. |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1514 | bool checkFragmentBreaks = false; |
hyatt@apple.com | 441ab1d | 2016-01-30 15:28:48 +0000 | [diff] [blame] | 1515 | bool checkBeforeAlways = (checkColumnBreaks && child.style().breakBefore() == ColumnBreakBetween) |
antti@apple.com | 52d8383 | 2017-09-20 12:58:45 +0000 | [diff] [blame] | 1516 | || (checkPageBreaks && alwaysPageBreak(child.style().breakBefore())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1517 | if (checkBeforeAlways && inNormalFlow(child) && hasNextPage(logicalOffset, IncludePageBoundary)) { |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1518 | if (checkColumnBreaks) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1519 | if (isInsideMulticolFlow) |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1520 | checkFragmentBreaks = true; |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1521 | } |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1522 | if (checkFragmentBreaks) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1523 | LayoutUnit offsetBreakAdjustment = 0; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1524 | if (fragmentedFlow->addForcedFragmentBreak(this, offsetFromLogicalTopOfFirstPage() + logicalOffset, &child, true, &offsetBreakAdjustment)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1525 | return logicalOffset + offsetBreakAdjustment; |
| 1526 | } |
| 1527 | return nextPageLogicalTop(logicalOffset, IncludePageBoundary); |
| 1528 | } |
| 1529 | return logicalOffset; |
| 1530 | } |
| 1531 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1532 | LayoutUnit RenderBlockFlow::applyAfterBreak(RenderBox& child, LayoutUnit logicalOffset, MarginInfo& marginInfo) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1533 | { |
| 1534 | // FIXME: Add page break checking here when we support printing. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1535 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1536 | bool isInsideMulticolFlow = fragmentedFlow; |
| 1537 | bool checkColumnBreaks = fragmentedFlow && fragmentedFlow->shouldCheckColumnBreaks(); |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1538 | bool checkPageBreaks = !checkColumnBreaks && view().layoutState()->m_pageLogicalHeight; // FIXME: Once columns can print we have to check this. |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1539 | bool checkFragmentBreaks = false; |
hyatt@apple.com | 441ab1d | 2016-01-30 15:28:48 +0000 | [diff] [blame] | 1540 | bool checkAfterAlways = (checkColumnBreaks && child.style().breakAfter() == ColumnBreakBetween) |
antti@apple.com | 52d8383 | 2017-09-20 12:58:45 +0000 | [diff] [blame] | 1541 | || (checkPageBreaks && alwaysPageBreak(child.style().breakAfter())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1542 | if (checkAfterAlways && inNormalFlow(child) && hasNextPage(logicalOffset, IncludePageBoundary)) { |
| 1543 | LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? LayoutUnit() : marginInfo.margin(); |
| 1544 | |
| 1545 | // So our margin doesn't participate in the next collapsing steps. |
| 1546 | marginInfo.clearMargin(); |
| 1547 | |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1548 | if (checkColumnBreaks) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1549 | if (isInsideMulticolFlow) |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1550 | checkFragmentBreaks = true; |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1551 | } |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1552 | if (checkFragmentBreaks) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1553 | LayoutUnit offsetBreakAdjustment = 0; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1554 | if (fragmentedFlow->addForcedFragmentBreak(this, offsetFromLogicalTopOfFirstPage() + logicalOffset + marginOffset, &child, false, &offsetBreakAdjustment)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1555 | return logicalOffset + marginOffset + offsetBreakAdjustment; |
| 1556 | } |
| 1557 | return nextPageLogicalTop(logicalOffset, IncludePageBoundary); |
| 1558 | } |
| 1559 | return logicalOffset; |
| 1560 | } |
| 1561 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1562 | LayoutUnit RenderBlockFlow::adjustBlockChildForPagination(LayoutUnit logicalTopAfterClear, LayoutUnit estimateWithoutPagination, RenderBox& child, bool atBeforeSideOfBlock) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1563 | { |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 1564 | RenderBlock* childRenderBlock = is<RenderBlock>(child) ? &downcast<RenderBlock>(child) : nullptr; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1565 | |
| 1566 | if (estimateWithoutPagination != logicalTopAfterClear) { |
| 1567 | // Our guess prior to pagination movement was wrong. Before we attempt to paginate, let's try again at the new |
| 1568 | // position. |
| 1569 | setLogicalHeight(logicalTopAfterClear); |
| 1570 | setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta); |
| 1571 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1572 | if (child.shrinkToAvoidFloats()) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 1573 | // The child's width depends on the line width. When the child shifts to clear an item, its width can |
| 1574 | // 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] | 1575 | child.setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | if (childRenderBlock) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1579 | if (!child.avoidsFloats() && childRenderBlock->containsFloats()) |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 1580 | downcast<RenderBlockFlow>(*childRenderBlock).markAllDescendantsWithFloatsForLayout(); |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 1581 | child.markForPaginationRelayoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | // Our guess was wrong. Make the child lay itself out again. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1585 | child.layoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | LayoutUnit oldTop = logicalTopAfterClear; |
| 1589 | |
| 1590 | // If the object has a page or column break value of "before", then we should shift to the top of the next page. |
| 1591 | LayoutUnit result = applyBeforeBreak(child, logicalTopAfterClear); |
| 1592 | |
| 1593 | if (pageLogicalHeightForOffset(result)) { |
| 1594 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(result, ExcludePageBoundary); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1595 | LayoutUnit spaceShortage = child.logicalHeight() - remainingLogicalHeight; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1596 | if (spaceShortage > 0) { |
| 1597 | // If the child crosses a column boundary, report a break, in case nothing inside it has already |
| 1598 | // done so. The column balancer needs to know how much it has to stretch the columns to make more |
| 1599 | // content fit. If no breaks are reported (but do occur), the balancer will have no clue. FIXME: |
| 1600 | // This should be improved, though, because here we just pretend that the child is |
| 1601 | // unsplittable. A splittable child, on the other hand, has break opportunities at every position |
| 1602 | // where there's no child content, border or padding. In other words, we risk stretching more |
| 1603 | // than necessary. |
| 1604 | setPageBreak(result, spaceShortage); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | // For replaced elements and scrolled elements, we want to shift them to the next page if they don't fit on the current one. |
| 1609 | LayoutUnit logicalTopBeforeUnsplittableAdjustment = result; |
| 1610 | LayoutUnit logicalTopAfterUnsplittableAdjustment = adjustForUnsplittableChild(child, result); |
| 1611 | |
| 1612 | LayoutUnit paginationStrut = 0; |
| 1613 | LayoutUnit unsplittableAdjustmentDelta = logicalTopAfterUnsplittableAdjustment - logicalTopBeforeUnsplittableAdjustment; |
| 1614 | if (unsplittableAdjustmentDelta) |
| 1615 | paginationStrut = unsplittableAdjustmentDelta; |
| 1616 | else if (childRenderBlock && childRenderBlock->paginationStrut()) |
| 1617 | paginationStrut = childRenderBlock->paginationStrut(); |
| 1618 | |
| 1619 | if (paginationStrut) { |
| 1620 | // We are willing to propagate out to our parent block as long as we were at the top of the block prior |
| 1621 | // to collapsing our margins, and as long as we didn't clear or move as a result of other pagination. |
| 1622 | if (atBeforeSideOfBlock && oldTop == result && !isOutOfFlowPositioned() && !isTableCell()) { |
| 1623 | // FIXME: Should really check if we're exceeding the page height before propagating the strut, but we don't |
| 1624 | // have all the information to do so (the strut only has the remaining amount to push). Gecko gets this wrong too |
| 1625 | // and pushes to the next page anyway, so not too concerned about it. |
| 1626 | setPaginationStrut(result + paginationStrut); |
| 1627 | if (childRenderBlock) |
| 1628 | childRenderBlock->setPaginationStrut(0); |
| 1629 | } else |
| 1630 | result += paginationStrut; |
| 1631 | } |
| 1632 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 1633 | // 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] | 1634 | setLogicalHeight(logicalHeight() + (result - oldTop)); |
| 1635 | |
| 1636 | // Return the final adjusted logical top. |
| 1637 | return result; |
| 1638 | } |
| 1639 | |
antti@apple.com | 5c4302b | 2016-04-26 18:20:09 +0000 | [diff] [blame] | 1640 | static inline LayoutUnit calculateMinimumPageHeight(const RenderStyle& renderStyle, RootInlineBox& lastLine, LayoutUnit lineTop, LayoutUnit lineBottom) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1641 | { |
| 1642 | // We may require a certain minimum number of lines per page in order to satisfy |
| 1643 | // orphans and widows, and that may affect the minimum page height. |
mmaxfield@apple.com | f8e26e7 | 2014-10-30 21:39:27 +0000 | [diff] [blame] | 1644 | 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] | 1645 | if (lineCount > 1) { |
mmaxfield@apple.com | f8e26e7 | 2014-10-30 21:39:27 +0000 | [diff] [blame] | 1646 | RootInlineBox* line = &lastLine; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1647 | for (unsigned i = 1; i < lineCount && line->prevRootBox(); i++) |
| 1648 | line = line->prevRootBox(); |
| 1649 | |
| 1650 | // FIXME: Paginating using line overflow isn't all fine. See FIXME in |
| 1651 | // adjustLinePositionForPagination() for more details. |
| 1652 | LayoutRect overflow = line->logicalVisualOverflowRect(line->lineTop(), line->lineBottom()); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1653 | lineTop = std::min(line->lineTopWithLeading(), overflow.y()); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1654 | } |
| 1655 | return lineBottom - lineTop; |
| 1656 | } |
| 1657 | |
bfulgham@apple.com | b595343 | 2015-02-13 21:56:01 +0000 | [diff] [blame] | 1658 | static inline bool needsAppleMailPaginationQuirk(RootInlineBox& lineBox) |
| 1659 | { |
zalan@apple.com | a1cff3a | 2017-01-14 18:45:20 +0000 | [diff] [blame] | 1660 | auto& renderer = lineBox.renderer(); |
bfulgham@apple.com | 6272977 | 2015-04-29 02:26:07 +0000 | [diff] [blame] | 1661 | |
zalan@apple.com | a1cff3a | 2017-01-14 18:45:20 +0000 | [diff] [blame] | 1662 | if (!renderer.settings().appleMailPaginationQuirkEnabled()) |
bfulgham@apple.com | 6272977 | 2015-04-29 02:26:07 +0000 | [diff] [blame] | 1663 | return false; |
| 1664 | |
cdumez@apple.com | bee81ac | 2016-04-21 23:28:48 +0000 | [diff] [blame] | 1665 | if (renderer.element() && renderer.element()->idForStyleResolution() == "messageContentContainer") |
bfulgham@apple.com | b595343 | 2015-02-13 21:56:01 +0000 | [diff] [blame] | 1666 | return true; |
| 1667 | |
| 1668 | return false; |
| 1669 | } |
zalan@apple.com | e031dfb | 2016-08-25 18:41:22 +0000 | [diff] [blame] | 1670 | |
| 1671 | static void clearShouldBreakAtLineToAvoidWidowIfNeeded(RenderBlockFlow& blockFlow) |
| 1672 | { |
| 1673 | if (!blockFlow.shouldBreakAtLineToAvoidWidow()) |
| 1674 | return; |
| 1675 | blockFlow.clearShouldBreakAtLineToAvoidWidow(); |
| 1676 | blockFlow.setDidBreakAtLineToAvoidWidow(); |
| 1677 | } |
| 1678 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1679 | void RenderBlockFlow::adjustLinePositionForPagination(RootInlineBox* lineBox, LayoutUnit& delta, bool& overflowsFragment, RenderFragmentedFlow* fragmentedFlow) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1680 | { |
| 1681 | // FIXME: For now we paginate using line overflow. This ensures that lines don't overlap at all when we |
| 1682 | // put a strut between them for pagination purposes. However, this really isn't the desired rendering, since |
| 1683 | // the line on the top of the next page will appear too far down relative to the same kind of line at the top |
| 1684 | // of the first column. |
| 1685 | // |
| 1686 | // The rendering we would like to see is one where the lineTopWithLeading is at the top of the column, and any line overflow |
| 1687 | // simply spills out above the top of the column. This effect would match what happens at the top of the first column. |
| 1688 | // We can't achieve this rendering, however, until we stop columns from clipping to the column bounds (thus allowing |
| 1689 | // for overflow to occur), and then cache visible overflow for each column rect. |
| 1690 | // |
| 1691 | // Furthermore, the paint we have to do when a column has overflow has to be special. We need to exclude |
| 1692 | // content that paints in a previous column (and content that paints in the following column). |
| 1693 | // |
| 1694 | // For now we'll at least honor the lineTopWithLeading when paginating if it is above the logical top overflow. This will |
| 1695 | // at least make positive leading work in typical cases. |
| 1696 | // |
| 1697 | // FIXME: Another problem with simply moving lines is that the available line width may change (because of floats). |
| 1698 | // Technically if the location we move the line to has a different line width than our old position, then we need to dirty the |
| 1699 | // line and all following lines. |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1700 | overflowsFragment = false; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1701 | LayoutRect logicalVisualOverflow = lineBox->logicalVisualOverflowRect(lineBox->lineTop(), lineBox->lineBottom()); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1702 | LayoutUnit logicalOffset = std::min(lineBox->lineTopWithLeading(), logicalVisualOverflow.y()); |
| 1703 | LayoutUnit logicalBottom = std::max(lineBox->lineBottomWithLeading(), logicalVisualOverflow.maxY()); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1704 | LayoutUnit lineHeight = logicalBottom - logicalOffset; |
mmaxfield@apple.com | f8e26e7 | 2014-10-30 21:39:27 +0000 | [diff] [blame] | 1705 | updateMinimumPageHeight(logicalOffset, calculateMinimumPageHeight(style(), *lineBox, logicalOffset, logicalBottom)); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1706 | logicalOffset += delta; |
| 1707 | lineBox->setPaginationStrut(0); |
| 1708 | lineBox->setIsFirstAfterPageBreak(false); |
| 1709 | LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1710 | bool hasUniformPageLogicalHeight = !fragmentedFlow || fragmentedFlow->fragmentsHaveUniformLogicalHeight(); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1711 | // If lineHeight is greater than pageLogicalHeight, but logicalVisualOverflow.height() still fits, we are |
| 1712 | // 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] | 1713 | if (!pageLogicalHeight || !hasNextPage(logicalOffset)) { |
abucur@adobe.com | d40287b | 2013-10-08 17:33:05 +0000 | [diff] [blame] | 1714 | // 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. |
| 1715 | // 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. |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1716 | return; |
hyatt@apple.com | cb5ab70 | 2014-11-19 23:40:23 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | if (hasUniformPageLogicalHeight && logicalVisualOverflow.height() > pageLogicalHeight) { |
| 1720 | // 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 |
| 1721 | // line and computing a new height that excludes anything we consider "blank space". We will discard margins, descent, and even overflow. If we are |
| 1722 | // 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 |
| 1723 | // top of the page. |
| 1724 | // 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 |
| 1725 | // this will be a real-world issue. For now we don't try to deal with this problem. |
| 1726 | logicalOffset = intMaxForLayoutUnit; |
| 1727 | logicalBottom = intMinForLayoutUnit; |
| 1728 | lineBox->computeReplacedAndTextLineTopAndBottom(logicalOffset, logicalBottom); |
| 1729 | lineHeight = logicalBottom - logicalOffset; |
zalan@apple.com | e031dfb | 2016-08-25 18:41:22 +0000 | [diff] [blame] | 1730 | if (logicalOffset == intMaxForLayoutUnit || lineHeight > pageLogicalHeight) { |
| 1731 | // Give up. We're genuinely too big even after excluding blank space and overflow. |
| 1732 | clearShouldBreakAtLineToAvoidWidowIfNeeded(*this); |
| 1733 | return; |
| 1734 | } |
hyatt@apple.com | cb5ab70 | 2014-11-19 23:40:23 +0000 | [diff] [blame] | 1735 | pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
| 1736 | } |
| 1737 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1738 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalOffset, ExcludePageBoundary); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1739 | overflowsFragment = (lineHeight > remainingLogicalHeight); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1740 | |
| 1741 | int lineIndex = lineCount(lineBox); |
| 1742 | if (remainingLogicalHeight < lineHeight || (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIndex)) { |
zalan@apple.com | e031dfb | 2016-08-25 18:41:22 +0000 | [diff] [blame] | 1743 | if (lineBreakToAvoidWidow() == lineIndex) |
| 1744 | clearShouldBreakAtLineToAvoidWidowIfNeeded(*this); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1745 | // If we have a non-uniform page height, then we have to shift further possibly. |
| 1746 | if (!hasUniformPageLogicalHeight && !pushToNextPageWithMinimumLogicalHeight(remainingLogicalHeight, logicalOffset, lineHeight)) |
| 1747 | return; |
| 1748 | if (lineHeight > pageLogicalHeight) { |
| 1749 | // Split the top margin in order to avoid splitting the visible part of the line. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1750 | remainingLogicalHeight -= std::min(lineHeight - pageLogicalHeight, std::max<LayoutUnit>(0, logicalVisualOverflow.y() - lineBox->lineTopWithLeading())); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1751 | } |
stavila@adobe.com | e1efa7f | 2014-05-20 14:34:56 +0000 | [diff] [blame] | 1752 | LayoutUnit remainingLogicalHeightAtNewOffset = pageRemainingLogicalHeightForOffset(logicalOffset + remainingLogicalHeight, ExcludePageBoundary); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1753 | overflowsFragment = (lineHeight > remainingLogicalHeightAtNewOffset); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1754 | LayoutUnit totalLogicalHeight = lineHeight + std::max<LayoutUnit>(0, logicalOffset); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1755 | LayoutUnit pageLogicalHeightAtNewOffset = hasUniformPageLogicalHeight ? pageLogicalHeight : pageLogicalHeightForOffset(logicalOffset + remainingLogicalHeight); |
| 1756 | setPageBreak(logicalOffset, lineHeight - remainingLogicalHeight); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1757 | if (((lineBox == firstRootBox() && totalLogicalHeight < pageLogicalHeightAtNewOffset) || (!style().hasAutoOrphans() && style().orphans() >= lineIndex)) |
mmaxfield@apple.com | 4d7e9a2 | 2014-11-18 22:40:29 +0000 | [diff] [blame] | 1758 | && !isOutOfFlowPositioned() && !isTableCell()) { |
| 1759 | auto firstRootBox = this->firstRootBox(); |
| 1760 | auto firstRootBoxOverflowRect = firstRootBox->logicalVisualOverflowRect(firstRootBox->lineTop(), firstRootBox->lineBottom()); |
| 1761 | auto firstLineUpperOverhang = std::max(-firstRootBoxOverflowRect.y(), LayoutUnit()); |
bfulgham@apple.com | b595343 | 2015-02-13 21:56:01 +0000 | [diff] [blame] | 1762 | if (needsAppleMailPaginationQuirk(*lineBox)) |
| 1763 | return; |
mmaxfield@apple.com | 4d7e9a2 | 2014-11-18 22:40:29 +0000 | [diff] [blame] | 1764 | setPaginationStrut(remainingLogicalHeight + logicalOffset + firstLineUpperOverhang); |
| 1765 | } else { |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1766 | delta += remainingLogicalHeight; |
| 1767 | lineBox->setPaginationStrut(remainingLogicalHeight); |
| 1768 | lineBox->setIsFirstAfterPageBreak(true); |
| 1769 | } |
commit-queue@webkit.org | 883b01c | 2014-01-20 08:58:36 +0000 | [diff] [blame] | 1770 | } else if (remainingLogicalHeight == pageLogicalHeight) { |
| 1771 | // We're at the very top of a page or column. |
| 1772 | if (lineBox != firstRootBox()) |
| 1773 | lineBox->setIsFirstAfterPageBreak(true); |
| 1774 | if (lineBox != firstRootBox() || offsetFromLogicalTopOfFirstPage()) |
| 1775 | setPageBreak(logicalOffset, lineHeight); |
| 1776 | } |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void RenderBlockFlow::setBreakAtLineToAvoidWidow(int lineToBreak) |
| 1780 | { |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1781 | ASSERT(lineToBreak >= 0); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1782 | ASSERT(!ensureRareBlockFlowData().m_didBreakAtLineToAvoidWidow); |
| 1783 | ensureRareBlockFlowData().m_lineBreakToAvoidWidow = lineToBreak; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1786 | void RenderBlockFlow::setDidBreakAtLineToAvoidWidow() |
| 1787 | { |
| 1788 | ASSERT(!shouldBreakAtLineToAvoidWidow()); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1789 | if (!hasRareBlockFlowData()) |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1790 | return; |
| 1791 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1792 | rareBlockFlowData()->m_didBreakAtLineToAvoidWidow = true; |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | void RenderBlockFlow::clearDidBreakAtLineToAvoidWidow() |
| 1796 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1797 | if (!hasRareBlockFlowData()) |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1798 | return; |
| 1799 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1800 | rareBlockFlowData()->m_didBreakAtLineToAvoidWidow = false; |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1803 | void RenderBlockFlow::clearShouldBreakAtLineToAvoidWidow() const |
| 1804 | { |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1805 | ASSERT(shouldBreakAtLineToAvoidWidow()); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1806 | if (!hasRareBlockFlowData()) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1807 | return; |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1808 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1809 | rareBlockFlowData()->m_lineBreakToAvoidWidow = -1; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | bool RenderBlockFlow::relayoutToAvoidWidows(LayoutStateMaintainer& statePusher) |
| 1813 | { |
| 1814 | if (!shouldBreakAtLineToAvoidWidow()) |
| 1815 | return false; |
| 1816 | |
| 1817 | statePusher.pop(); |
| 1818 | setEverHadLayout(true); |
| 1819 | layoutBlock(false); |
| 1820 | return true; |
| 1821 | } |
| 1822 | |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1823 | bool RenderBlockFlow::hasNextPage(LayoutUnit logicalOffset, PageBoundaryRule pageBoundaryRule) const |
| 1824 | { |
| 1825 | ASSERT(view().layoutState() && view().layoutState()->isPaginated()); |
| 1826 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1827 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1828 | if (!fragmentedFlow) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1829 | return true; // Printing and multi-column both make new pages to accommodate content. |
| 1830 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1831 | // See if we're in the last fragment. |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1832 | LayoutUnit pageOffset = offsetFromLogicalTopOfFirstPage() + logicalOffset; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1833 | RenderFragmentContainer* fragment = fragmentedFlow->fragmentAtBlockOffset(this, pageOffset, true); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1834 | if (!fragment) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1835 | return false; |
mihnea@adobe.com | c191b0a | 2014-03-19 12:38:51 +0000 | [diff] [blame] | 1836 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1837 | if (fragment->isLastFragment()) |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1838 | return fragment->isRenderFragmentContainerSet() || (pageBoundaryRule == IncludePageBoundary && pageOffset == fragment->logicalTopForFragmentedFlowContent()); |
stavila@adobe.com | 6cb976d | 2013-11-21 06:57:19 +0000 | [diff] [blame] | 1839 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1840 | RenderFragmentContainer* startFragment = nullptr; |
| 1841 | RenderFragmentContainer* endFragment = nullptr; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1842 | fragmentedFlow->getFragmentRangeForBox(this, startFragment, endFragment); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1843 | return (endFragment && fragment != endFragment); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 1846 | LayoutUnit RenderBlockFlow::adjustForUnsplittableChild(RenderBox& child, LayoutUnit logicalOffset, LayoutUnit childBeforeMargin, LayoutUnit childAfterMargin) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1847 | { |
hyatt@apple.com | 531e35d | 2017-04-13 16:37:00 +0000 | [diff] [blame] | 1848 | // When flexboxes are embedded inside a block flow, they don't perform any adjustments for unsplittable |
| 1849 | // children. We'll treat flexboxes themselves as unsplittable just to get them to paginate properly inside |
| 1850 | // a block flow. |
| 1851 | bool isUnsplittable = childBoxIsUnsplittableForFragmentation(child); |
| 1852 | if (!isUnsplittable && !(child.isFlexibleBox() && !downcast<RenderFlexibleBox>(child).isFlexibleBoxImpl())) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1853 | return logicalOffset; |
hyatt@apple.com | 531e35d | 2017-04-13 16:37:00 +0000 | [diff] [blame] | 1854 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1855 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 1856 | LayoutUnit childLogicalHeight = logicalHeightForChild(child) + childBeforeMargin + childAfterMargin; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1857 | LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1858 | bool hasUniformPageLogicalHeight = !fragmentedFlow || fragmentedFlow->fragmentsHaveUniformLogicalHeight(); |
hyatt@apple.com | 531e35d | 2017-04-13 16:37:00 +0000 | [diff] [blame] | 1859 | if (isUnsplittable) |
| 1860 | updateMinimumPageHeight(logicalOffset, childLogicalHeight); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1861 | if (!pageLogicalHeight || (hasUniformPageLogicalHeight && childLogicalHeight > pageLogicalHeight) |
| 1862 | || !hasNextPage(logicalOffset)) |
| 1863 | return logicalOffset; |
| 1864 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalOffset, ExcludePageBoundary); |
| 1865 | if (remainingLogicalHeight < childLogicalHeight) { |
| 1866 | if (!hasUniformPageLogicalHeight && !pushToNextPageWithMinimumLogicalHeight(remainingLogicalHeight, logicalOffset, childLogicalHeight)) |
| 1867 | return logicalOffset; |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 1868 | auto result = logicalOffset + remainingLogicalHeight; |
| 1869 | bool isInitialLetter = child.isFloating() && child.style().styleType() == FIRST_LETTER && child.style().initialLetterDrop() > 0; |
| 1870 | if (isInitialLetter) { |
| 1871 | // Increase our logical height to ensure that lines all get pushed along with the letter. |
| 1872 | setLogicalHeight(logicalOffset + remainingLogicalHeight); |
| 1873 | } |
| 1874 | return result; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1875 | } |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 1876 | |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1877 | return logicalOffset; |
| 1878 | } |
| 1879 | |
| 1880 | bool RenderBlockFlow::pushToNextPageWithMinimumLogicalHeight(LayoutUnit& adjustment, LayoutUnit logicalOffset, LayoutUnit minimumLogicalHeight) const |
| 1881 | { |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1882 | bool checkFragment = false; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1883 | for (LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset + adjustment); pageLogicalHeight; |
| 1884 | pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset + adjustment)) { |
| 1885 | if (minimumLogicalHeight <= pageLogicalHeight) |
| 1886 | return true; |
| 1887 | if (!hasNextPage(logicalOffset + adjustment)) |
| 1888 | return false; |
| 1889 | adjustment += pageLogicalHeight; |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1890 | checkFragment = true; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1891 | } |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 1892 | return !checkFragment; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | void RenderBlockFlow::setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) |
| 1896 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1897 | if (RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow()) |
| 1898 | fragmentedFlow->setPageBreak(this, offsetFromLogicalTopOfFirstPage() + offset, spaceShortage); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | void RenderBlockFlow::updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight) |
| 1902 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1903 | if (RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow()) |
| 1904 | fragmentedFlow->updateMinimumPageHeight(this, offsetFromLogicalTopOfFirstPage() + offset, minHeight); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | LayoutUnit RenderBlockFlow::nextPageLogicalTop(LayoutUnit logicalOffset, PageBoundaryRule pageBoundaryRule) const |
| 1908 | { |
| 1909 | LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
| 1910 | if (!pageLogicalHeight) |
| 1911 | return logicalOffset; |
| 1912 | |
| 1913 | // The logicalOffset is in our coordinate space. We can add in our pushed offset. |
| 1914 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalOffset); |
| 1915 | if (pageBoundaryRule == ExcludePageBoundary) |
| 1916 | return logicalOffset + (remainingLogicalHeight ? remainingLogicalHeight : pageLogicalHeight); |
| 1917 | return logicalOffset + remainingLogicalHeight; |
| 1918 | } |
| 1919 | |
| 1920 | LayoutUnit RenderBlockFlow::pageLogicalTopForOffset(LayoutUnit offset) const |
| 1921 | { |
hyatt@apple.com | 6c9d5d3 | 2015-02-19 21:42:21 +0000 | [diff] [blame] | 1922 | // Unsplittable objects clear out the pageLogicalHeight in the layout state as a way of signaling that no |
| 1923 | // pagination should occur. Therefore we have to check this first and bail if the value has been set to 0. |
| 1924 | LayoutUnit pageLogicalHeight = view().layoutState()->m_pageLogicalHeight; |
| 1925 | if (!pageLogicalHeight) |
| 1926 | return 0; |
| 1927 | |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1928 | LayoutUnit firstPageLogicalTop = isHorizontalWritingMode() ? view().layoutState()->m_pageOffset.height() : view().layoutState()->m_pageOffset.width(); |
| 1929 | LayoutUnit blockLogicalTop = isHorizontalWritingMode() ? view().layoutState()->m_layoutOffset.height() : view().layoutState()->m_layoutOffset.width(); |
| 1930 | |
| 1931 | LayoutUnit cumulativeOffset = offset + blockLogicalTop; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1932 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1933 | if (!fragmentedFlow) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1934 | return cumulativeOffset - roundToInt(cumulativeOffset - firstPageLogicalTop) % roundToInt(pageLogicalHeight); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1935 | return firstPageLogicalTop + fragmentedFlow->pageLogicalTopForOffset(cumulativeOffset - firstPageLogicalTop); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | LayoutUnit RenderBlockFlow::pageLogicalHeightForOffset(LayoutUnit offset) const |
| 1939 | { |
hyatt@apple.com | 6c9d5d3 | 2015-02-19 21:42:21 +0000 | [diff] [blame] | 1940 | // Unsplittable objects clear out the pageLogicalHeight in the layout state as a way of signaling that no |
| 1941 | // pagination should occur. Therefore we have to check this first and bail if the value has been set to 0. |
| 1942 | LayoutUnit pageLogicalHeight = view().layoutState()->m_pageLogicalHeight; |
| 1943 | if (!pageLogicalHeight) |
| 1944 | return 0; |
| 1945 | |
| 1946 | // Now check for a flow thread. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1947 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1948 | if (!fragmentedFlow) |
hyatt@apple.com | 6c9d5d3 | 2015-02-19 21:42:21 +0000 | [diff] [blame] | 1949 | return pageLogicalHeight; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1950 | return fragmentedFlow->pageLogicalHeightForOffset(offset + offsetFromLogicalTopOfFirstPage()); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | LayoutUnit RenderBlockFlow::pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule pageBoundaryRule) const |
| 1954 | { |
| 1955 | offset += offsetFromLogicalTopOfFirstPage(); |
| 1956 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1957 | RenderFragmentedFlow* fragmentedFlow = enclosingFragmentedFlow(); |
| 1958 | if (!fragmentedFlow) { |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1959 | LayoutUnit pageLogicalHeight = view().layoutState()->m_pageLogicalHeight; |
| 1960 | LayoutUnit remainingHeight = pageLogicalHeight - intMod(offset, pageLogicalHeight); |
| 1961 | if (pageBoundaryRule == IncludePageBoundary) { |
| 1962 | // If includeBoundaryPoint is true the line exactly on the top edge of a |
| 1963 | // column will act as being part of the previous column. |
| 1964 | remainingHeight = intMod(remainingHeight, pageLogicalHeight); |
| 1965 | } |
| 1966 | return remainingHeight; |
| 1967 | } |
| 1968 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 1969 | return fragmentedFlow->pageRemainingLogicalHeightForOffset(offset, pageBoundaryRule); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
stavila@adobe.com | b0d86c4 | 2014-04-09 17:07:50 +0000 | [diff] [blame] | 1972 | LayoutUnit RenderBlockFlow::logicalHeightForChildForFragmentation(const RenderBox& child) const |
| 1973 | { |
antti@apple.com | eae7612 | 2017-09-20 15:37:23 +0000 | [diff] [blame] | 1974 | return logicalHeightForChild(child); |
stavila@adobe.com | b0d86c4 | 2014-04-09 17:07:50 +0000 | [diff] [blame] | 1975 | } |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1976 | |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1977 | void RenderBlockFlow::layoutLineGridBox() |
| 1978 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1979 | if (style().lineGrid() == RenderStyle::initialLineGrid()) { |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1980 | setLineGridBox(0); |
| 1981 | return; |
| 1982 | } |
| 1983 | |
| 1984 | setLineGridBox(0); |
| 1985 | |
akling@apple.com | 1aa97b0 | 2013-10-31 21:59:49 +0000 | [diff] [blame] | 1986 | auto lineGridBox = std::make_unique<RootInlineBox>(*this); |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1987 | lineGridBox->setHasTextChildren(); // Needed to make the line ascent/descent actually be honored in quirks mode. |
| 1988 | lineGridBox->setConstructed(); |
| 1989 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1990 | VerticalPositionCache verticalPositionCache; |
| 1991 | lineGridBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache); |
| 1992 | |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 1993 | setLineGridBox(WTFMove(lineGridBox)); |
akling@apple.com | 1aa97b0 | 2013-10-31 21:59:49 +0000 | [diff] [blame] | 1994 | |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1995 | // FIXME: If any of the characteristics of the box change compared to the old one, then we need to do a deep dirtying |
| 1996 | // (similar to what happens when the page height changes). Ideally, though, we only do this if someone is actually snapping |
| 1997 | // to this grid. |
| 1998 | } |
| 1999 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2000 | bool RenderBlockFlow::containsFloat(RenderBox& renderer) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2001 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2002 | return m_floatingObjects && m_floatingObjects->set().contains<RenderBox&, FloatingObjectHashTranslator>(renderer); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | void RenderBlockFlow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
| 2006 | { |
| 2007 | RenderBlock::styleDidChange(diff, oldStyle); |
| 2008 | |
| 2009 | // After our style changed, if we lose our ability to propagate floats into next sibling |
| 2010 | // blocks, then we need to find the top most parent containing that overhanging float and |
| 2011 | // then mark its descendants with floats for layout and clear all floats from its next |
| 2012 | // sibling blocks that exist in our floating objects list. See bug 56299 and 62875. |
| 2013 | bool canPropagateFloatIntoSibling = !isFloatingOrOutOfFlowPositioned() && !avoidsFloats(); |
| 2014 | if (diff == StyleDifferenceLayout && s_canPropagateFloatIntoSibling && !canPropagateFloatIntoSibling && hasOverhangingFloats()) { |
| 2015 | RenderBlockFlow* parentBlock = this; |
| 2016 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2017 | |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 2018 | for (auto& ancestor : ancestorsOfType<RenderBlockFlow>(*this)) { |
| 2019 | if (ancestor.isRenderView()) |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 2020 | break; |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 2021 | if (ancestor.hasOverhangingFloats()) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2022 | for (auto it = floatingObjectSet.begin(), end = floatingObjectSet.end(); it != end; ++it) { |
| 2023 | RenderBox& renderer = (*it)->renderer(); |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 2024 | if (ancestor.hasOverhangingFloat(renderer)) { |
| 2025 | parentBlock = &ancestor; |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 2026 | break; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2027 | } |
| 2028 | } |
| 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | parentBlock->markAllDescendantsWithFloatsForLayout(); |
| 2033 | parentBlock->markSiblingsWithFloatsForLayout(); |
| 2034 | } |
zalan@apple.com | 07a1ebc | 2017-03-16 01:56:57 +0000 | [diff] [blame] | 2035 | // Fresh floats need to be reparented if they actually belong to the previous anonymous block. |
| 2036 | // It copies the logic of RenderBlock::addChildIgnoringContinuation |
| 2037 | if (noLongerAffectsParentBlock() && style().isFloating() && previousSibling() && previousSibling()->isAnonymousBlock()) |
| 2038 | downcast<RenderBoxModelObject>(*parent()).moveChildTo(&downcast<RenderBoxModelObject>(*previousSibling()), this); |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 2039 | |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 2040 | if (diff >= StyleDifferenceRepaint) { |
| 2041 | // FIXME: This could use a cheaper style-only test instead of SimpleLineLayout::canUseFor. |
| 2042 | if (selfNeedsLayout() || !m_simpleLineLayout || !SimpleLineLayout::canUseFor(*this)) |
| 2043 | invalidateLineLayoutPath(); |
| 2044 | } |
| 2045 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2046 | if (multiColumnFlow()) |
hyatt@apple.com | fdb1281 | 2014-06-23 18:56:52 +0000 | [diff] [blame] | 2047 | updateStylesForColumnChildren(); |
| 2048 | } |
| 2049 | |
| 2050 | void RenderBlockFlow::updateStylesForColumnChildren() |
| 2051 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2052 | for (auto* child = firstChildBox(); child && (child->isInFlowRenderFragmentedFlow() || child->isRenderMultiColumnSet()); child = child->nextSiblingBox()) |
antti@apple.com | 454418f | 2016-04-25 19:49:23 +0000 | [diff] [blame] | 2053 | child->setStyle(RenderStyle::createAnonymousStyleWithDisplay(style(), BLOCK)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
akling@apple.com | bdae4324 | 2013-10-25 12:00:20 +0000 | [diff] [blame] | 2056 | void RenderBlockFlow::styleWillChange(StyleDifference diff, const RenderStyle& newStyle) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2057 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2058 | const RenderStyle* oldStyle = hasInitializedStyle() ? &style() : nullptr; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2059 | s_canPropagateFloatIntoSibling = oldStyle ? !isFloatingOrOutOfFlowPositioned() && !avoidsFloats() : false; |
| 2060 | |
stavila@adobe.com | d40a2dc | 2014-06-23 14:59:48 +0000 | [diff] [blame] | 2061 | if (oldStyle) { |
| 2062 | EPosition oldPosition = oldStyle->position(); |
| 2063 | EPosition newPosition = newStyle.position(); |
abucur@adobe.com | c0a88a6 | 2014-10-16 06:50:30 +0000 | [diff] [blame] | 2064 | |
stavila@adobe.com | d40a2dc | 2014-06-23 14:59:48 +0000 | [diff] [blame] | 2065 | if (parent() && diff == StyleDifferenceLayout && oldPosition != newPosition) { |
| 2066 | if (containsFloats() && !isFloating() && !isOutOfFlowPositioned() && newStyle.hasOutOfFlowPosition()) |
| 2067 | markAllDescendantsWithFloatsForLayout(); |
stavila@adobe.com | d40a2dc | 2014-06-23 14:59:48 +0000 | [diff] [blame] | 2068 | } |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | RenderBlock::styleWillChange(diff, newStyle); |
| 2072 | } |
| 2073 | |
antti@apple.com | a2c7f24 | 2013-10-22 22:37:25 +0000 | [diff] [blame] | 2074 | void RenderBlockFlow::deleteLines() |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2075 | { |
| 2076 | if (containsFloats()) |
| 2077 | m_floatingObjects->clearLineBoxTreePointers(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2078 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 2079 | if (m_simpleLineLayout) { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2080 | ASSERT(!m_lineBoxes.firstLineBox()); |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 2081 | m_simpleLineLayout = nullptr; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2082 | } else |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 2083 | m_lineBoxes.deleteLineBoxTree(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2084 | |
antti@apple.com | a2c7f24 | 2013-10-22 22:37:25 +0000 | [diff] [blame] | 2085 | RenderBlock::deleteLines(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2088 | void RenderBlockFlow::addFloatsToNewParent(RenderBlockFlow& toBlockFlow) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2089 | { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2090 | // When a portion of the render tree is being detached, anonymous blocks |
| 2091 | // will be combined as their children are deleted. In this process, the |
| 2092 | // anonymous block later in the tree is merged into the one preceeding it. |
| 2093 | // It can happen that the later block (this) contains floats that the |
| 2094 | // previous block (toBlockFlow) did not contain, and thus are not in the |
| 2095 | // floating objects list for toBlockFlow. This can result in toBlockFlow |
| 2096 | // containing floats that are not in it's floating objects list, but are in |
| 2097 | // the floating objects lists of siblings and parents. This can cause |
| 2098 | // problems when the float itself is deleted, since the deletion code |
| 2099 | // assumes that if a float is not in it's containing block's floating |
| 2100 | // objects list, it isn't in any floating objects list. In order to |
| 2101 | // preserve this condition (removing it has serious performance |
| 2102 | // implications), we need to copy the floating objects from the old block |
| 2103 | // (this) to the new block (toBlockFlow). The float's metrics will likely |
| 2104 | // all be wrong, but since toBlockFlow is already marked for layout, this |
| 2105 | // will get fixed before anything gets displayed. |
| 2106 | // See bug https://bugs.webkit.org/show_bug.cgi?id=115566 |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2107 | if (!m_floatingObjects) |
| 2108 | return; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2109 | |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2110 | if (!toBlockFlow.m_floatingObjects) |
| 2111 | toBlockFlow.createFloatingObjects(); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2112 | |
zalan@apple.com | 2601854 | 2017-03-30 01:25:00 +0000 | [diff] [blame] | 2113 | for (auto& floatingObject : m_floatingObjects->set()) { |
| 2114 | if (toBlockFlow.containsFloat(floatingObject->renderer())) |
| 2115 | continue; |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2116 | toBlockFlow.m_floatingObjects->add(floatingObject->cloneForNewParent()); |
zalan@apple.com | 2601854 | 2017-03-30 01:25:00 +0000 | [diff] [blame] | 2117 | } |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 2120 | void RenderBlockFlow::moveAllChildrenIncludingFloatsTo(RenderBlock& toBlock, bool fullRemoveInsert) |
jhoneycutt@apple.com | 5ad8220 | 2014-02-18 22:55:39 +0000 | [diff] [blame] | 2121 | { |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2122 | auto& toBlockFlow = downcast<RenderBlockFlow>(toBlock); |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 2123 | moveAllChildrenTo(&toBlockFlow, fullRemoveInsert); |
zalan@apple.com | 232b093 | 2016-12-24 18:00:00 +0000 | [diff] [blame] | 2124 | addFloatsToNewParent(toBlockFlow); |
jhoneycutt@apple.com | 5ad8220 | 2014-02-18 22:55:39 +0000 | [diff] [blame] | 2125 | } |
| 2126 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2127 | void RenderBlockFlow::addOverflowFromFloats() |
| 2128 | { |
| 2129 | if (!m_floatingObjects) |
| 2130 | return; |
| 2131 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2132 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2133 | auto end = floatingObjectSet.end(); |
| 2134 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2135 | const auto& floatingObject = *it->get(); |
| 2136 | if (floatingObject.isDescendant()) |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2137 | addOverflowFromChild(&floatingObject.renderer(), floatingObject.locationOffsetOfBorderBox()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | void RenderBlockFlow::computeOverflow(LayoutUnit oldClientAfterEdge, bool recomputeFloats) |
| 2142 | { |
| 2143 | RenderBlock::computeOverflow(oldClientAfterEdge, recomputeFloats); |
| 2144 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2145 | if (!multiColumnFlow() && (recomputeFloats || createsNewFormattingContext() || hasSelfPaintingLayer())) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2146 | addOverflowFromFloats(); |
| 2147 | } |
| 2148 | |
| 2149 | void RenderBlockFlow::repaintOverhangingFloats(bool paintAllDescendants) |
| 2150 | { |
| 2151 | // Repaint any overhanging floats (if we know we're the one to paint them). |
| 2152 | // Otherwise, bail out. |
| 2153 | if (!hasOverhangingFloats()) |
| 2154 | return; |
| 2155 | |
| 2156 | // FIXME: Avoid disabling LayoutState. At the very least, don't disable it for floats originating |
| 2157 | // in this block. Better yet would be to push extra state for the containers of other floats. |
zalan@apple.com | 163bc1c | 2015-08-12 03:41:40 +0000 | [diff] [blame] | 2158 | LayoutStateDisabler layoutStateDisabler(view()); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2159 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2160 | auto end = floatingObjectSet.end(); |
| 2161 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2162 | const auto& floatingObject = *it->get(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2163 | // Only repaint the object if it is overhanging, is not in its own layer, and |
| 2164 | // is our responsibility to paint (m_shouldPaint is set). When paintAllDescendants is true, the latter |
| 2165 | // condition is replaced with being a descendant of us. |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2166 | auto& renderer = floatingObject.renderer(); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2167 | if (logicalBottomForFloat(floatingObject) > logicalHeight() |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2168 | && !renderer.hasSelfPaintingLayer() |
| 2169 | && (floatingObject.shouldPaint() || (paintAllDescendants && renderer.isDescendantOf(this)))) { |
| 2170 | renderer.repaint(); |
| 2171 | renderer.repaintOverhangingFloats(false); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2172 | } |
| 2173 | } |
| 2174 | } |
| 2175 | |
hyatt@apple.com | c9021b7 | 2014-04-25 21:05:59 +0000 | [diff] [blame] | 2176 | void RenderBlockFlow::paintColumnRules(PaintInfo& paintInfo, const LayoutPoint& point) |
hyatt@apple.com | 58b5ecc | 2014-04-17 23:06:02 +0000 | [diff] [blame] | 2177 | { |
hyatt@apple.com | c9021b7 | 2014-04-25 21:05:59 +0000 | [diff] [blame] | 2178 | RenderBlock::paintColumnRules(paintInfo, point); |
hyatt@apple.com | 58b5ecc | 2014-04-17 23:06:02 +0000 | [diff] [blame] | 2179 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2180 | if (!multiColumnFlow() || paintInfo.context().paintingDisabled()) |
hyatt@apple.com | 58b5ecc | 2014-04-17 23:06:02 +0000 | [diff] [blame] | 2181 | return; |
hyatt@apple.com | c9021b7 | 2014-04-25 21:05:59 +0000 | [diff] [blame] | 2182 | |
hyatt@apple.com | 58b5ecc | 2014-04-17 23:06:02 +0000 | [diff] [blame] | 2183 | // Iterate over our children and paint the column rules as needed. |
| 2184 | for (auto& columnSet : childrenOfType<RenderMultiColumnSet>(*this)) { |
| 2185 | LayoutPoint childPoint = columnSet.location() + flipForWritingModeForChild(&columnSet, point); |
| 2186 | columnSet.paintColumnRules(paintInfo, childPoint); |
| 2187 | } |
| 2188 | } |
| 2189 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2190 | void RenderBlockFlow::paintFloats(PaintInfo& paintInfo, const LayoutPoint& paintOffset, bool preservePhase) |
| 2191 | { |
| 2192 | if (!m_floatingObjects) |
| 2193 | return; |
| 2194 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2195 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2196 | auto end = floatingObjectSet.end(); |
| 2197 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2198 | const auto& floatingObject = *it->get(); |
| 2199 | auto& renderer = floatingObject.renderer(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2200 | // Only paint the object if our m_shouldPaint flag is set. |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2201 | if (floatingObject.shouldPaint() && !renderer.hasSelfPaintingLayer()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2202 | PaintInfo currentPaintInfo(paintInfo); |
| 2203 | currentPaintInfo.phase = preservePhase ? paintInfo.phase : PaintPhaseBlockBackground; |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2204 | LayoutPoint childPoint = flipFloatForWritingModeForChild(floatingObject, paintOffset + floatingObject.translationOffsetToAncestor()); |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2205 | renderer.paint(currentPaintInfo, childPoint); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2206 | if (!preservePhase) { |
| 2207 | currentPaintInfo.phase = PaintPhaseChildBlockBackgrounds; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2208 | renderer.paint(currentPaintInfo, childPoint); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2209 | currentPaintInfo.phase = PaintPhaseFloat; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2210 | renderer.paint(currentPaintInfo, childPoint); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2211 | currentPaintInfo.phase = PaintPhaseForeground; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2212 | renderer.paint(currentPaintInfo, childPoint); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2213 | currentPaintInfo.phase = PaintPhaseOutline; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2214 | renderer.paint(currentPaintInfo, childPoint); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2215 | } |
| 2216 | } |
| 2217 | } |
| 2218 | } |
| 2219 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2220 | 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] | 2221 | { |
| 2222 | if (m_floatingObjects) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2223 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2224 | auto end = floatingObjectSet.end(); |
| 2225 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2226 | const auto& floatingObject = *it->get(); |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2227 | LayoutRect floatBox(offsetFromRootBlock.width(), offsetFromRootBlock.height(), floatingObject.renderer().width(), floatingObject.renderer().height()); |
| 2228 | floatBox.move(floatingObject.locationOffsetOfBorderBox()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2229 | rootBlock.flipForWritingMode(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2230 | floatBox.move(rootBlockPhysicalPosition.x(), rootBlockPhysicalPosition.y()); |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 2231 | paintInfo->context().clipOut(snappedIntRect(floatBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2232 | } |
| 2233 | } |
| 2234 | } |
| 2235 | |
| 2236 | void RenderBlockFlow::createFloatingObjects() |
| 2237 | { |
zandobersek@gmail.com | 31dae99 | 2014-03-31 10:12:49 +0000 | [diff] [blame] | 2238 | m_floatingObjects = std::make_unique<FloatingObjects>(*this); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | void RenderBlockFlow::removeFloatingObjects() |
| 2242 | { |
| 2243 | if (!m_floatingObjects) |
| 2244 | return; |
| 2245 | |
bjonesbe@adobe.com | 0b2195a | 2014-04-11 22:46:02 +0000 | [diff] [blame] | 2246 | markSiblingsWithFloatsForLayout(); |
| 2247 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2248 | m_floatingObjects->clear(); |
| 2249 | } |
| 2250 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2251 | FloatingObject* RenderBlockFlow::insertFloatingObject(RenderBox& floatBox) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2252 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2253 | ASSERT(floatBox.isFloating()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2254 | |
| 2255 | // Create the list of special objects if we don't aleady have one |
| 2256 | if (!m_floatingObjects) |
| 2257 | createFloatingObjects(); |
| 2258 | else { |
| 2259 | // Don't insert the floatingObject again if it's already in the list |
| 2260 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2261 | auto it = floatingObjectSet.find<RenderBox&, FloatingObjectHashTranslator>(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2262 | if (it != floatingObjectSet.end()) |
| 2263 | return it->get(); |
| 2264 | } |
| 2265 | |
| 2266 | // Create the special floatingObject entry & append it to the list |
| 2267 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2268 | std::unique_ptr<FloatingObject> floatingObject = FloatingObject::create(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2269 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 2270 | // 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] | 2271 | bool isChildRenderBlock = floatBox.isRenderBlock(); |
| 2272 | if (isChildRenderBlock && !floatBox.needsLayout() && view().layoutState()->pageLogicalHeightChanged()) |
| 2273 | floatBox.setChildNeedsLayout(MarkOnlyThis); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2274 | |
| 2275 | bool needsBlockDirectionLocationSetBeforeLayout = isChildRenderBlock && view().layoutState()->needsBlockDirectionLocationSetBeforeLayout(); |
bjonesbe@adobe.com | 9c29e69 | 2014-12-10 00:57:10 +0000 | [diff] [blame] | 2276 | if (!needsBlockDirectionLocationSetBeforeLayout || isWritingModeRoot()) { |
| 2277 | // We are unsplittable if we're a block flow root. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2278 | floatBox.layoutIfNeeded(); |
bjonesbe@adobe.com | 9c29e69 | 2014-12-10 00:57:10 +0000 | [diff] [blame] | 2279 | floatingObject->setShouldPaint(!floatBox.hasSelfPaintingLayer()); |
| 2280 | } |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2281 | else { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2282 | floatBox.updateLogicalWidth(); |
mmaxfield@apple.com | 09804f4 | 2016-03-23 00:58:34 +0000 | [diff] [blame] | 2283 | floatBox.computeAndSetBlockDirectionMargins(*this); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2286 | setLogicalWidthForFloat(*floatingObject, logicalWidthForChild(floatBox) + marginStartForChild(floatBox) + marginEndForChild(floatBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2287 | |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 2288 | return m_floatingObjects->add(WTFMove(floatingObject)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2291 | void RenderBlockFlow::removeFloatingObject(RenderBox& floatBox) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2292 | { |
| 2293 | if (m_floatingObjects) { |
| 2294 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2295 | auto it = floatingObjectSet.find<RenderBox&, FloatingObjectHashTranslator>(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2296 | if (it != floatingObjectSet.end()) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2297 | auto& floatingObject = *it->get(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2298 | if (childrenInline()) { |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2299 | LayoutUnit logicalTop = logicalTopForFloat(floatingObject); |
| 2300 | LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2301 | |
| 2302 | // Fix for https://bugs.webkit.org/show_bug.cgi?id=54995. |
| 2303 | if (logicalBottom < 0 || logicalBottom < logicalTop || logicalTop == LayoutUnit::max()) |
| 2304 | logicalBottom = LayoutUnit::max(); |
| 2305 | else { |
| 2306 | // Special-case zero- and less-than-zero-height floats: those don't touch |
| 2307 | // the line that they're on, but it still needs to be dirtied. This is |
| 2308 | // accomplished by pretending they have a height of 1. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2309 | logicalBottom = std::max(logicalBottom, logicalTop + 1); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2310 | } |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2311 | if (floatingObject.originatingLine()) { |
| 2312 | floatingObject.originatingLine()->removeFloat(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2313 | if (!selfNeedsLayout()) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2314 | ASSERT(&floatingObject.originatingLine()->renderer() == this); |
| 2315 | floatingObject.originatingLine()->markDirty(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2316 | } |
| 2317 | #if !ASSERT_DISABLED |
zalan@apple.com | d2acead | 2017-09-20 22:03:06 +0000 | [diff] [blame] | 2318 | floatingObject.clearOriginatingLine(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2319 | #endif |
| 2320 | } |
| 2321 | markLinesDirtyInBlockRange(0, logicalBottom); |
| 2322 | } |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2323 | m_floatingObjects->remove(&floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2324 | } |
| 2325 | } |
| 2326 | } |
| 2327 | |
| 2328 | void RenderBlockFlow::removeFloatingObjectsBelow(FloatingObject* lastFloat, int logicalOffset) |
| 2329 | { |
| 2330 | if (!containsFloats()) |
| 2331 | return; |
| 2332 | |
| 2333 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2334 | FloatingObject* curr = floatingObjectSet.last().get(); |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2335 | while (curr != lastFloat && (!curr->isPlaced() || logicalTopForFloat(*curr) >= logicalOffset)) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2336 | m_floatingObjects->remove(curr); |
| 2337 | if (floatingObjectSet.isEmpty()) |
| 2338 | break; |
| 2339 | curr = floatingObjectSet.last().get(); |
| 2340 | } |
| 2341 | } |
| 2342 | |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2343 | LayoutUnit RenderBlockFlow::logicalLeftOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const |
| 2344 | { |
| 2345 | LayoutUnit offset = fixedOffset; |
| 2346 | if (m_floatingObjects && m_floatingObjects->hasLeftObjects()) |
| 2347 | offset = m_floatingObjects->logicalLeftOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining); |
| 2348 | return adjustLogicalLeftOffsetForLine(offset, applyTextIndent); |
| 2349 | } |
| 2350 | |
| 2351 | LayoutUnit RenderBlockFlow::logicalRightOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const |
| 2352 | { |
| 2353 | LayoutUnit offset = fixedOffset; |
| 2354 | if (m_floatingObjects && m_floatingObjects->hasRightObjects()) |
| 2355 | offset = m_floatingObjects->logicalRightOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining); |
| 2356 | return adjustLogicalRightOffsetForLine(offset, applyTextIndent); |
| 2357 | } |
| 2358 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2359 | void RenderBlockFlow::computeLogicalLocationForFloat(FloatingObject& floatingObject, LayoutUnit& logicalTopOffset) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2360 | { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2361 | auto& childBox = floatingObject.renderer(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2362 | LayoutUnit logicalLeftOffset = logicalLeftOffsetForContent(logicalTopOffset); // Constant part of left offset. |
zoltan@webkit.org | 7d4f8cc | 2014-03-26 18:20:15 +0000 | [diff] [blame] | 2363 | LayoutUnit logicalRightOffset = logicalRightOffsetForContent(logicalTopOffset); // Constant part of right offset. |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2364 | |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2365 | 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] | 2366 | |
| 2367 | LayoutUnit floatLogicalLeft; |
| 2368 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2369 | bool insideFragmentedFlow = enclosingFragmentedFlow(); |
hyatt@apple.com | 8751526 | 2014-09-04 21:20:12 +0000 | [diff] [blame] | 2370 | bool isInitialLetter = childBox.style().styleType() == FIRST_LETTER && childBox.style().initialLetterDrop() > 0; |
| 2371 | |
| 2372 | if (isInitialLetter) { |
| 2373 | int letterClearance = lowestInitialLetterLogicalBottom() - logicalTopOffset; |
| 2374 | if (letterClearance > 0) { |
| 2375 | logicalTopOffset += letterClearance; |
| 2376 | setLogicalHeight(logicalHeight() + letterClearance); |
| 2377 | } |
| 2378 | } |
| 2379 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2380 | if (childBox.style().floating() == LeftFloat) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2381 | LayoutUnit heightRemainingLeft = 1; |
| 2382 | LayoutUnit heightRemainingRight = 1; |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2383 | floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft); |
| 2384 | while (logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight) - floatLogicalLeft < floatLogicalWidth) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2385 | logicalTopOffset += std::min(heightRemainingLeft, heightRemainingRight); |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2386 | floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2387 | if (insideFragmentedFlow) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2388 | // Have to re-evaluate all of our offsets, since they may have changed. |
| 2389 | logicalRightOffset = logicalRightOffsetForContent(logicalTopOffset); // Constant part of right offset. |
| 2390 | logicalLeftOffset = logicalLeftOffsetForContent(logicalTopOffset); // Constant part of left offset. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2391 | floatLogicalWidth = std::min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2392 | } |
| 2393 | } |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2394 | floatLogicalLeft = std::max(logicalLeftOffset - borderAndPaddingLogicalLeft(), floatLogicalLeft); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2395 | } else { |
| 2396 | LayoutUnit heightRemainingLeft = 1; |
| 2397 | LayoutUnit heightRemainingRight = 1; |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2398 | floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight); |
| 2399 | while (floatLogicalLeft - logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft) < floatLogicalWidth) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2400 | logicalTopOffset += std::min(heightRemainingLeft, heightRemainingRight); |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2401 | floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 2402 | if (insideFragmentedFlow) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2403 | // Have to re-evaluate all of our offsets, since they may have changed. |
| 2404 | logicalRightOffset = logicalRightOffsetForContent(logicalTopOffset); // Constant part of right offset. |
| 2405 | logicalLeftOffset = logicalLeftOffsetForContent(logicalTopOffset); // Constant part of left offset. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2406 | floatLogicalWidth = std::min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | // Use the original width of the float here, since the local variable |
| 2410 | // |floatLogicalWidth| was capped to the available line width. See |
| 2411 | // fast/block/float/clamped-right-float.html. |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2412 | floatLogicalLeft -= logicalWidthForFloat(floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2413 | } |
| 2414 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2415 | LayoutUnit childLogicalLeftMargin = style().isLeftToRightDirection() ? marginStartForChild(childBox) : marginEndForChild(childBox); |
| 2416 | LayoutUnit childBeforeMargin = marginBeforeForChild(childBox); |
hyatt@apple.com | c2e1552 | 2014-09-03 19:26:38 +0000 | [diff] [blame] | 2417 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2418 | if (isInitialLetter) |
| 2419 | adjustInitialLetterPosition(childBox, logicalTopOffset, childBeforeMargin); |
| 2420 | |
| 2421 | setLogicalLeftForFloat(floatingObject, floatLogicalLeft); |
| 2422 | setLogicalLeftForChild(childBox, floatLogicalLeft + childLogicalLeftMargin); |
| 2423 | |
| 2424 | setLogicalTopForFloat(floatingObject, logicalTopOffset); |
| 2425 | setLogicalTopForChild(childBox, logicalTopOffset + childBeforeMargin); |
| 2426 | |
| 2427 | setLogicalMarginsForFloat(floatingObject, childLogicalLeftMargin, childBeforeMargin); |
| 2428 | } |
| 2429 | |
| 2430 | void RenderBlockFlow::adjustInitialLetterPosition(RenderBox& childBox, LayoutUnit& logicalTopOffset, LayoutUnit& marginBeforeOffset) |
| 2431 | { |
| 2432 | const RenderStyle& style = firstLineStyle(); |
| 2433 | const FontMetrics& fontMetrics = style.fontMetrics(); |
| 2434 | if (!fontMetrics.hasCapHeight()) |
| 2435 | return; |
| 2436 | |
| 2437 | LayoutUnit heightOfLine = lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
| 2438 | LayoutUnit beforeMarginBorderPadding = childBox.borderAndPaddingBefore() + childBox.marginBefore(); |
| 2439 | |
| 2440 | // Make an adjustment to align with the cap height of a theoretical block line. |
| 2441 | LayoutUnit adjustment = fontMetrics.ascent() + (heightOfLine - fontMetrics.height()) / 2 - fontMetrics.capHeight() - beforeMarginBorderPadding; |
| 2442 | logicalTopOffset += adjustment; |
| 2443 | |
| 2444 | // For sunken and raised caps, we have to make some adjustments. Test if we're sunken or raised (dropHeightDelta will be |
| 2445 | // positive for raised and negative for sunken). |
| 2446 | int dropHeightDelta = childBox.style().initialLetterHeight() - childBox.style().initialLetterDrop(); |
| 2447 | |
| 2448 | // 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. |
| 2449 | if (dropHeightDelta < 0) |
| 2450 | marginBeforeOffset += -dropHeightDelta * heightOfLine; |
| 2451 | |
| 2452 | // 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 |
| 2453 | // empty lines beside the first letter. |
| 2454 | if (dropHeightDelta > 0) |
| 2455 | setLogicalHeight(logicalHeight() + dropHeightDelta * heightOfLine); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | bool RenderBlockFlow::positionNewFloats() |
| 2459 | { |
| 2460 | if (!m_floatingObjects) |
| 2461 | return false; |
| 2462 | |
| 2463 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2464 | if (floatingObjectSet.isEmpty()) |
| 2465 | return false; |
| 2466 | |
| 2467 | // If all floats have already been positioned, then we have no work to do. |
| 2468 | if (floatingObjectSet.last()->isPlaced()) |
| 2469 | return false; |
| 2470 | |
| 2471 | // Move backwards through our floating object list until we find a float that has |
| 2472 | // already been positioned. Then we'll be able to move forward, positioning all of |
| 2473 | // the new floats that need it. |
| 2474 | auto it = floatingObjectSet.end(); |
| 2475 | --it; // Go to last item. |
| 2476 | auto begin = floatingObjectSet.begin(); |
| 2477 | FloatingObject* lastPlacedFloatingObject = 0; |
| 2478 | while (it != begin) { |
| 2479 | --it; |
| 2480 | if ((*it)->isPlaced()) { |
| 2481 | lastPlacedFloatingObject = it->get(); |
| 2482 | ++it; |
| 2483 | break; |
| 2484 | } |
| 2485 | } |
| 2486 | |
| 2487 | LayoutUnit logicalTop = logicalHeight(); |
| 2488 | |
| 2489 | // The float cannot start above the top position of the last positioned float. |
| 2490 | if (lastPlacedFloatingObject) |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2491 | logicalTop = std::max(logicalTopForFloat(*lastPlacedFloatingObject), logicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2492 | |
| 2493 | auto end = floatingObjectSet.end(); |
| 2494 | // Now walk through the set of unpositioned floats and place them. |
| 2495 | for (; it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2496 | auto& floatingObject = *it->get(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2497 | // The containing block is responsible for positioning floats, so if we have floats in our |
| 2498 | // 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] | 2499 | auto& childBox = floatingObject.renderer(); |
| 2500 | if (childBox.containingBlock() != this) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2501 | continue; |
| 2502 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2503 | LayoutRect oldRect = childBox.frameRect(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2504 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2505 | if (childBox.style().clear() & CLEFT) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2506 | logicalTop = std::max(lowestFloatLogicalBottom(FloatingObject::FloatLeft), logicalTop); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2507 | if (childBox.style().clear() & CRIGHT) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2508 | logicalTop = std::max(lowestFloatLogicalBottom(FloatingObject::FloatRight), logicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2509 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2510 | computeLogicalLocationForFloat(floatingObject, logicalTop); |
| 2511 | LayoutUnit childLogicalTop = logicalTopForChild(childBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2512 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 2513 | estimateFragmentRangeForBoxChild(childBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2514 | |
hyatt@apple.com | ccad374 | 2015-02-04 21:39:00 +0000 | [diff] [blame] | 2515 | childBox.markForPaginationRelayoutIfNeeded(); |
| 2516 | childBox.layoutIfNeeded(); |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2517 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2518 | LayoutState* layoutState = view().layoutState(); |
| 2519 | bool isPaginated = layoutState->isPaginated(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2520 | if (isPaginated) { |
| 2521 | // If we are unsplittable and don't fit, then we need to move down. |
| 2522 | // We include our margins as part of the unsplittable area. |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2523 | LayoutUnit newLogicalTop = adjustForUnsplittableChild(childBox, logicalTop, childLogicalTop - logicalTop, marginAfterForChild(childBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2524 | |
| 2525 | // 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] | 2526 | // Note that an unsplittable child can't also have a pagination strut, so this |
| 2527 | // is exclusive with the case above. |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 2528 | RenderBlock* childBlock = is<RenderBlock>(childBox) ? &downcast<RenderBlock>(childBox) : nullptr; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2529 | if (childBlock && childBlock->paginationStrut()) { |
| 2530 | newLogicalTop += childBlock->paginationStrut(); |
| 2531 | childBlock->setPaginationStrut(0); |
| 2532 | } |
| 2533 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2534 | if (newLogicalTop != logicalTop) { |
| 2535 | floatingObject.setPaginationStrut(newLogicalTop - logicalTop); |
| 2536 | computeLogicalLocationForFloat(floatingObject, newLogicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2537 | if (childBlock) |
| 2538 | childBlock->setChildNeedsLayout(MarkOnlyThis); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2539 | childBox.layoutIfNeeded(); |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2540 | logicalTop = newLogicalTop; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2541 | } |
| 2542 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 2543 | if (updateFragmentRangeForBoxChild(childBox)) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2544 | childBox.setNeedsLayout(MarkOnlyThis); |
| 2545 | childBox.layoutIfNeeded(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2549 | setLogicalHeightForFloat(floatingObject, logicalHeightForChildForFragmentation(childBox) + (logicalTopForChild(childBox) - logicalTop) + marginAfterForChild(childBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2550 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2551 | m_floatingObjects->addPlacedObject(&floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2552 | |
zoltan@webkit.org | 0faf572 | 2013-11-05 02:34:16 +0000 | [diff] [blame] | 2553 | if (ShapeOutsideInfo* shapeOutside = childBox.shapeOutsideInfo()) |
bjonesbe@adobe.com | 029f74e | 2014-02-13 03:02:53 +0000 | [diff] [blame] | 2554 | shapeOutside->setReferenceBoxLogicalSize(logicalSizeForChild(childBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2555 | // If the child moved, we have to repaint it. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2556 | if (childBox.checkForRepaintDuringLayout()) |
| 2557 | childBox.repaintDuringLayoutIfMoved(oldRect); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2558 | } |
| 2559 | return true; |
| 2560 | } |
| 2561 | |
bjonesbe@adobe.com | f9f1040 | 2014-02-20 19:40:28 +0000 | [diff] [blame] | 2562 | void RenderBlockFlow::clearFloats(EClear clear) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2563 | { |
| 2564 | positionNewFloats(); |
| 2565 | // set y position |
| 2566 | LayoutUnit newY = 0; |
| 2567 | switch (clear) { |
| 2568 | case CLEFT: |
| 2569 | newY = lowestFloatLogicalBottom(FloatingObject::FloatLeft); |
| 2570 | break; |
| 2571 | case CRIGHT: |
| 2572 | newY = lowestFloatLogicalBottom(FloatingObject::FloatRight); |
| 2573 | break; |
| 2574 | case CBOTH: |
| 2575 | newY = lowestFloatLogicalBottom(); |
joepeck@webkit.org | aa676ee5 | 2014-01-28 04:04:52 +0000 | [diff] [blame] | 2576 | break; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2577 | default: |
| 2578 | break; |
| 2579 | } |
| 2580 | if (height() < newY) |
| 2581 | setLogicalHeight(newY); |
| 2582 | } |
| 2583 | |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2584 | LayoutUnit RenderBlockFlow::logicalLeftFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2585 | { |
| 2586 | if (m_floatingObjects && m_floatingObjects->hasLeftObjects()) |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2587 | return m_floatingObjects->logicalLeftOffset(fixedOffset, logicalTop, logicalHeight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2588 | |
| 2589 | return fixedOffset; |
| 2590 | } |
| 2591 | |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2592 | LayoutUnit RenderBlockFlow::logicalRightFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2593 | { |
| 2594 | if (m_floatingObjects && m_floatingObjects->hasRightObjects()) |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2595 | return m_floatingObjects->logicalRightOffset(fixedOffset, logicalTop, logicalHeight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2596 | |
| 2597 | return fixedOffset; |
| 2598 | } |
| 2599 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2600 | LayoutUnit RenderBlockFlow::nextFloatLogicalBottomBelow(LayoutUnit logicalHeight) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2601 | { |
| 2602 | if (!m_floatingObjects) |
| 2603 | return logicalHeight; |
| 2604 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2605 | return m_floatingObjects->findNextFloatLogicalBottomBelow(logicalHeight); |
| 2606 | } |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2607 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2608 | LayoutUnit RenderBlockFlow::nextFloatLogicalBottomBelowForBlock(LayoutUnit logicalHeight) const |
| 2609 | { |
| 2610 | if (!m_floatingObjects) |
| 2611 | return logicalHeight; |
| 2612 | |
| 2613 | return m_floatingObjects->findNextFloatLogicalBottomBelowForBlock(logicalHeight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | LayoutUnit RenderBlockFlow::lowestFloatLogicalBottom(FloatingObject::Type floatType) const |
| 2617 | { |
| 2618 | if (!m_floatingObjects) |
| 2619 | return 0; |
| 2620 | LayoutUnit lowestFloatBottom = 0; |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2621 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2622 | auto end = floatingObjectSet.end(); |
| 2623 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2624 | const auto& floatingObject = *it->get(); |
| 2625 | if (floatingObject.isPlaced() && floatingObject.type() & floatType) |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2626 | lowestFloatBottom = std::max(lowestFloatBottom, logicalBottomForFloat(floatingObject)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2627 | } |
| 2628 | return lowestFloatBottom; |
| 2629 | } |
| 2630 | |
hyatt@apple.com | 8751526 | 2014-09-04 21:20:12 +0000 | [diff] [blame] | 2631 | LayoutUnit RenderBlockFlow::lowestInitialLetterLogicalBottom() const |
| 2632 | { |
| 2633 | if (!m_floatingObjects) |
| 2634 | return 0; |
| 2635 | LayoutUnit lowestFloatBottom = 0; |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2636 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2637 | auto end = floatingObjectSet.end(); |
| 2638 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2639 | const auto& floatingObject = *it->get(); |
| 2640 | if (floatingObject.isPlaced() && floatingObject.renderer().style().styleType() == FIRST_LETTER && floatingObject.renderer().style().initialLetterDrop() > 0) |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2641 | lowestFloatBottom = std::max(lowestFloatBottom, logicalBottomForFloat(floatingObject)); |
hyatt@apple.com | 8751526 | 2014-09-04 21:20:12 +0000 | [diff] [blame] | 2642 | } |
| 2643 | return lowestFloatBottom; |
| 2644 | } |
| 2645 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2646 | LayoutUnit RenderBlockFlow::addOverhangingFloats(RenderBlockFlow& child, bool makeChildPaintOtherFloats) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2647 | { |
| 2648 | // 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] | 2649 | if (!child.containsFloats() || child.createsNewFormattingContext()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2650 | return 0; |
| 2651 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2652 | LayoutUnit childLogicalTop = child.logicalTop(); |
| 2653 | LayoutUnit childLogicalLeft = child.logicalLeft(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2654 | LayoutUnit lowestFloatLogicalBottom = 0; |
| 2655 | |
| 2656 | // Floats that will remain the child's responsibility to paint should factor into its |
| 2657 | // overflow. |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2658 | auto childEnd = child.m_floatingObjects->set().end(); |
| 2659 | for (auto childIt = child.m_floatingObjects->set().begin(); childIt != childEnd; ++childIt) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2660 | auto& floatingObject = *childIt->get(); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2661 | LayoutUnit floatLogicalBottom = std::min(logicalBottomForFloat(floatingObject), LayoutUnit::max() - childLogicalTop); |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2662 | LayoutUnit logicalBottom = childLogicalTop + floatLogicalBottom; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2663 | lowestFloatLogicalBottom = std::max(lowestFloatLogicalBottom, logicalBottom); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2664 | |
| 2665 | if (logicalBottom > logicalHeight()) { |
| 2666 | // 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] | 2667 | if (!containsFloat(floatingObject.renderer())) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2668 | LayoutSize offset = isHorizontalWritingMode() ? LayoutSize(-childLogicalLeft, -childLogicalTop) : LayoutSize(-childLogicalTop, -childLogicalLeft); |
| 2669 | bool shouldPaint = false; |
| 2670 | |
| 2671 | // The nearest enclosing layer always paints the float (so that zindex and stacking |
| 2672 | // behaves properly). We always want to propagate the desire to paint the float as |
| 2673 | // far out as we can, to the outermost block that overlaps the float, stopping only |
| 2674 | // if we hit a self-painting layer boundary. |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2675 | if (floatingObject.renderer().enclosingFloatPaintingLayer() == enclosingFloatPaintingLayer()) { |
| 2676 | floatingObject.setShouldPaint(false); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2677 | shouldPaint = true; |
| 2678 | } |
| 2679 | // We create the floating object list lazily. |
| 2680 | if (!m_floatingObjects) |
| 2681 | createFloatingObjects(); |
| 2682 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2683 | m_floatingObjects->add(floatingObject.copyToNewContainer(offset, shouldPaint, true)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2684 | } |
| 2685 | } else { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2686 | const auto& renderer = floatingObject.renderer(); |
| 2687 | if (makeChildPaintOtherFloats && !floatingObject.shouldPaint() && !renderer.hasSelfPaintingLayer() |
| 2688 | && renderer.isDescendantOf(&child) && renderer.enclosingFloatPaintingLayer() == child.enclosingFloatPaintingLayer()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2689 | // The float is not overhanging from this block, so if it is a descendant of the child, the child should |
| 2690 | // paint it (the other case is that it is intruding into the child), unless it has its own layer or enclosing |
| 2691 | // layer. |
| 2692 | // If makeChildPaintOtherFloats is false, it means that the child must already know about all the floats |
| 2693 | // it should paint. |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2694 | floatingObject.setShouldPaint(true); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2695 | } |
| 2696 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 2697 | // 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] | 2698 | if (floatingObject.isDescendant()) |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2699 | child.addOverflowFromChild(&renderer, floatingObject.locationOffsetOfBorderBox()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2700 | } |
| 2701 | } |
| 2702 | return lowestFloatLogicalBottom; |
| 2703 | } |
| 2704 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2705 | bool RenderBlockFlow::hasOverhangingFloat(RenderBox& renderer) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2706 | { |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 2707 | if (!m_floatingObjects || !parent()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2708 | return false; |
| 2709 | |
| 2710 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2711 | const auto it = floatingObjectSet.find<RenderBox&, FloatingObjectHashTranslator>(renderer); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2712 | if (it == floatingObjectSet.end()) |
| 2713 | return false; |
| 2714 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2715 | return logicalBottomForFloat(*it->get()) > logicalHeight(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 2718 | void RenderBlockFlow::addIntrudingFloats(RenderBlockFlow* prev, RenderBlockFlow* container, LayoutUnit logicalLeftOffset, LayoutUnit logicalTopOffset) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2719 | { |
| 2720 | ASSERT(!avoidsFloats()); |
| 2721 | |
jfernandez@igalia.com | 7065868 | 2014-12-15 21:07:30 +0000 | [diff] [blame] | 2722 | // If we create our own block formatting context then our contents don't interact with floats outside it, even those from our parent. |
| 2723 | if (createsNewFormattingContext()) |
| 2724 | return; |
| 2725 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2726 | // If the parent or previous sibling doesn't have any floats to add, don't bother. |
| 2727 | if (!prev->m_floatingObjects) |
| 2728 | return; |
| 2729 | |
| 2730 | logicalLeftOffset += marginLogicalLeft(); |
| 2731 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2732 | const FloatingObjectSet& prevSet = prev->m_floatingObjects->set(); |
| 2733 | auto prevEnd = prevSet.end(); |
| 2734 | for (auto prevIt = prevSet.begin(); prevIt != prevEnd; ++prevIt) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2735 | auto& floatingObject = *prevIt->get(); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2736 | if (logicalBottomForFloat(floatingObject) > logicalTopOffset) { |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2737 | if (!m_floatingObjects || !m_floatingObjects->set().contains<FloatingObject&, FloatingObjectHashTranslator>(floatingObject)) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2738 | // We create the floating object list lazily. |
| 2739 | if (!m_floatingObjects) |
| 2740 | createFloatingObjects(); |
| 2741 | |
| 2742 | // Applying the child's margin makes no sense in the case where the child was passed in. |
| 2743 | // since this margin was added already through the modification of the |logicalLeftOffset| variable |
| 2744 | // above. |logicalLeftOffset| will equal the margin in this case, so it's already been taken |
| 2745 | // into account. Only apply this code if prev is the parent, since otherwise the left margin |
| 2746 | // will get applied twice. |
| 2747 | LayoutSize offset = isHorizontalWritingMode() |
hyatt@apple.com | 21c6080 | 2015-04-01 18:10:32 +0000 | [diff] [blame] | 2748 | ? LayoutSize(logicalLeftOffset - (prev != container ? prev->marginLeft() : LayoutUnit()), logicalTopOffset) |
| 2749 | : LayoutSize(logicalTopOffset, logicalLeftOffset - (prev != container ? prev->marginTop() : LayoutUnit())); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2750 | |
zalan@apple.com | 84ccfa1 | 2015-10-17 03:36:56 +0000 | [diff] [blame] | 2751 | m_floatingObjects->add(floatingObject.copyToNewContainer(offset)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2752 | } |
| 2753 | } |
| 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | void RenderBlockFlow::markAllDescendantsWithFloatsForLayout(RenderBox* floatToRemove, bool inLayout) |
| 2758 | { |
| 2759 | if (!everHadLayout() && !containsFloats()) |
| 2760 | return; |
| 2761 | |
| 2762 | MarkingBehavior markParents = inLayout ? MarkOnlyThis : MarkContainingBlockChain; |
| 2763 | setChildNeedsLayout(markParents); |
| 2764 | |
| 2765 | if (floatToRemove) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2766 | removeFloatingObject(*floatToRemove); |
hyatt@apple.com | 11a5e5c | 2016-05-19 21:51:31 +0000 | [diff] [blame] | 2767 | else if (childrenInline()) |
hyatt@apple.com | 00e9314 | 2016-05-18 18:59:40 +0000 | [diff] [blame] | 2768 | return; |
| 2769 | |
zalan@apple.com | 5d7ffdf | 2014-10-29 21:13:12 +0000 | [diff] [blame] | 2770 | // Iterate over our block children and mark them as needed. |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2771 | for (auto& block : childrenOfType<RenderBlock>(*this)) { |
| 2772 | if (!floatToRemove && block.isFloatingOrOutOfFlowPositioned()) |
| 2773 | continue; |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 2774 | if (!is<RenderBlockFlow>(block)) { |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2775 | if (block.shrinkToAvoidFloats() && block.everHadLayout()) |
| 2776 | block.setChildNeedsLayout(markParents); |
| 2777 | continue; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2778 | } |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 2779 | auto& blockFlow = downcast<RenderBlockFlow>(block); |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2780 | if ((floatToRemove ? blockFlow.containsFloat(*floatToRemove) : blockFlow.containsFloats()) || blockFlow.shrinkToAvoidFloats()) |
| 2781 | blockFlow.markAllDescendantsWithFloatsForLayout(floatToRemove, inLayout); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | void RenderBlockFlow::markSiblingsWithFloatsForLayout(RenderBox* floatToRemove) |
| 2786 | { |
| 2787 | if (!m_floatingObjects) |
| 2788 | return; |
| 2789 | |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2790 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2791 | auto end = floatingObjectSet.end(); |
| 2792 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2793 | for (RenderObject* next = nextSibling(); next; next = next->nextSibling()) { |
zalan@apple.com | c2472ea | 2015-05-26 22:59:40 +0000 | [diff] [blame] | 2794 | if (!is<RenderBlockFlow>(*next) || next->isFloatingOrOutOfFlowPositioned()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2795 | continue; |
| 2796 | |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 2797 | RenderBlockFlow& nextBlock = downcast<RenderBlockFlow>(*next); |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2798 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 2799 | RenderBox& floatingBox = (*it)->renderer(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2800 | if (floatToRemove && &floatingBox != floatToRemove) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2801 | continue; |
cdumez@apple.com | e943779 | 2014-10-08 23:33:43 +0000 | [diff] [blame] | 2802 | if (nextBlock.containsFloat(floatingBox)) |
| 2803 | nextBlock.markAllDescendantsWithFloatsForLayout(&floatingBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2804 | } |
| 2805 | } |
| 2806 | } |
| 2807 | |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2808 | LayoutPoint RenderBlockFlow::flipFloatForWritingModeForChild(const FloatingObject& child, const LayoutPoint& point) const |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 2809 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2810 | if (!style().isFlippedBlocksWritingMode()) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 2811 | return point; |
| 2812 | |
| 2813 | // This is similar to RenderBox::flipForWritingModeForChild. We have to subtract out our left/top offsets twice, since |
| 2814 | // it's going to get added back in. We hide this complication here so that the calling code looks normal for the unflipped |
| 2815 | // case. |
| 2816 | if (isHorizontalWritingMode()) |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2817 | return LayoutPoint(point.x(), point.y() + height() - child.renderer().height() - 2 * child.locationOffsetOfBorderBox().height()); |
| 2818 | 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] | 2819 | } |
| 2820 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2821 | LayoutUnit RenderBlockFlow::getClearDelta(RenderBox& child, LayoutUnit logicalTop) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2822 | { |
| 2823 | // There is no need to compute clearance if we have no floats. |
| 2824 | if (!containsFloats()) |
| 2825 | return 0; |
| 2826 | |
| 2827 | // At least one float is present. We need to perform the clearance computation. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2828 | bool clearSet = child.style().clear() != CNONE; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2829 | LayoutUnit logicalBottom = 0; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2830 | switch (child.style().clear()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2831 | case CNONE: |
| 2832 | break; |
| 2833 | case CLEFT: |
| 2834 | logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatLeft); |
| 2835 | break; |
| 2836 | case CRIGHT: |
| 2837 | logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatRight); |
| 2838 | break; |
| 2839 | case CBOTH: |
| 2840 | logicalBottom = lowestFloatLogicalBottom(); |
| 2841 | break; |
| 2842 | } |
| 2843 | |
| 2844 | // 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). |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2845 | LayoutUnit result = clearSet ? std::max<LayoutUnit>(0, logicalBottom - logicalTop) : LayoutUnit(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2846 | if (!result && child.avoidsFloats()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2847 | LayoutUnit newLogicalTop = logicalTop; |
| 2848 | while (true) { |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 2849 | LayoutUnit availableLogicalWidthAtNewLogicalTopOffset = availableLogicalWidthForLine(newLogicalTop, DoNotIndentText, logicalHeightForChild(child)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2850 | if (availableLogicalWidthAtNewLogicalTopOffset == availableLogicalWidthForContent(newLogicalTop)) |
| 2851 | return newLogicalTop - logicalTop; |
| 2852 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 2853 | RenderFragmentContainer* fragment = fragmentAtBlockOffset(logicalTopForChild(child)); |
| 2854 | LayoutRect borderBox = child.borderBoxRectInFragment(fragment, DoNotCacheRenderBoxFragmentInfo); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2855 | LayoutUnit childLogicalWidthAtOldLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height(); |
| 2856 | |
| 2857 | // FIXME: None of this is right for perpendicular writing-mode children. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2858 | LayoutUnit childOldLogicalWidth = child.logicalWidth(); |
| 2859 | LayoutUnit childOldMarginLeft = child.marginLeft(); |
| 2860 | LayoutUnit childOldMarginRight = child.marginRight(); |
| 2861 | LayoutUnit childOldLogicalTop = child.logicalTop(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2862 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2863 | child.setLogicalTop(newLogicalTop); |
| 2864 | child.updateLogicalWidth(); |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 2865 | fragment = fragmentAtBlockOffset(logicalTopForChild(child)); |
| 2866 | borderBox = child.borderBoxRectInFragment(fragment, DoNotCacheRenderBoxFragmentInfo); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2867 | LayoutUnit childLogicalWidthAtNewLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height(); |
| 2868 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2869 | child.setLogicalTop(childOldLogicalTop); |
| 2870 | child.setLogicalWidth(childOldLogicalWidth); |
| 2871 | child.setMarginLeft(childOldMarginLeft); |
| 2872 | child.setMarginRight(childOldMarginRight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2873 | |
| 2874 | if (childLogicalWidthAtNewLogicalTopOffset <= availableLogicalWidthAtNewLogicalTopOffset) { |
| 2875 | // Even though we may not be moving, if the logical width did shrink because of the presence of new floats, then |
| 2876 | // we need to force a relayout as though we shifted. This happens because of the dynamic addition of overhanging floats |
| 2877 | // from previous siblings when negative margins exist on a child (see the addOverhangingFloats call at the end of collapseMargins). |
| 2878 | if (childLogicalWidthAtOldLogicalTopOffset != childLogicalWidthAtNewLogicalTopOffset) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2879 | child.setChildNeedsLayout(MarkOnlyThis); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2880 | return newLogicalTop - logicalTop; |
| 2881 | } |
| 2882 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2883 | newLogicalTop = nextFloatLogicalBottomBelowForBlock(newLogicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2884 | ASSERT(newLogicalTop >= logicalTop); |
| 2885 | if (newLogicalTop < logicalTop) |
| 2886 | break; |
| 2887 | } |
| 2888 | ASSERT_NOT_REACHED(); |
| 2889 | } |
| 2890 | return result; |
| 2891 | } |
| 2892 | |
| 2893 | bool RenderBlockFlow::hitTestFloats(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset) |
| 2894 | { |
| 2895 | if (!m_floatingObjects) |
| 2896 | return false; |
| 2897 | |
| 2898 | LayoutPoint adjustedLocation = accumulatedOffset; |
cdumez@apple.com | 3abcc79 | 2014-10-20 03:42:03 +0000 | [diff] [blame] | 2899 | if (is<RenderView>(*this)) |
| 2900 | adjustedLocation += toLayoutSize(downcast<RenderView>(*this).frameView().scrollPosition()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2901 | |
| 2902 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2903 | auto begin = floatingObjectSet.begin(); |
| 2904 | for (auto it = floatingObjectSet.end(); it != begin;) { |
| 2905 | --it; |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2906 | const auto& floatingObject = *it->get(); |
| 2907 | auto& renderer = floatingObject.renderer(); |
| 2908 | if (floatingObject.shouldPaint() && !renderer.hasSelfPaintingLayer()) { |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2909 | LayoutPoint childPoint = flipFloatForWritingModeForChild(floatingObject, adjustedLocation + floatingObject.translationOffsetToAncestor()); |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2910 | if (renderer.hitTest(request, result, locationInContainer, childPoint)) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2911 | updateHitTestResult(result, locationInContainer.point() - toLayoutSize(childPoint)); |
| 2912 | return true; |
| 2913 | } |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | return false; |
| 2918 | } |
| 2919 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2920 | bool RenderBlockFlow::hitTestInlineChildren(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction) |
| 2921 | { |
| 2922 | ASSERT(childrenInline()); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2923 | |
darin@apple.com | e1be6ca | 2014-04-28 04:19:10 +0000 | [diff] [blame] | 2924 | if (auto simpleLineLayout = this->simpleLineLayout()) |
| 2925 | return SimpleLineLayout::hitTestFlow(*this, *simpleLineLayout, request, result, locationInContainer, accumulatedOffset, hitTestAction); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2926 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2927 | return m_lineBoxes.hitTest(this, request, result, locationInContainer, accumulatedOffset, hitTestAction); |
| 2928 | } |
| 2929 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2930 | void RenderBlockFlow::adjustForBorderFit(LayoutUnit x, LayoutUnit& left, LayoutUnit& right) const |
| 2931 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2932 | if (style().visibility() != VISIBLE) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2933 | return; |
| 2934 | |
| 2935 | // We don't deal with relative positioning. Our assumption is that you shrink to fit the lines without accounting |
| 2936 | // for either overflow or translations via relative positioning. |
| 2937 | if (childrenInline()) { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2938 | const_cast<RenderBlockFlow&>(*this).ensureLineBoxes(); |
| 2939 | |
cdumez@apple.com | c1d54fa | 2015-10-13 19:15:55 +0000 | [diff] [blame] | 2940 | for (auto* box = firstRootBox(); box; box = box->nextRootBox()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2941 | if (box->firstChild()) |
zalan@apple.com | 390064f | 2014-02-26 06:23:03 +0000 | [diff] [blame] | 2942 | left = std::min(left, x + LayoutUnit(box->firstChild()->x())); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2943 | if (box->lastChild()) |
zalan@apple.com | 390064f | 2014-02-26 06:23:03 +0000 | [diff] [blame] | 2944 | right = std::max(right, x + LayoutUnit(ceilf(box->lastChild()->logicalRight()))); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2945 | } |
| 2946 | } else { |
| 2947 | for (RenderBox* obj = firstChildBox(); obj; obj = obj->nextSiblingBox()) { |
| 2948 | if (!obj->isFloatingOrOutOfFlowPositioned()) { |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 2949 | if (is<RenderBlockFlow>(*obj) && !obj->hasOverflowClip()) |
| 2950 | downcast<RenderBlockFlow>(*obj).adjustForBorderFit(x + obj->x(), left, right); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2951 | else if (obj->style().visibility() == VISIBLE) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2952 | // We are a replaced element or some kind of non-block-flow object. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2953 | left = std::min(left, x + obj->x()); |
| 2954 | right = std::max(right, x + obj->x() + obj->width()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | } |
| 2958 | } |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2959 | |
| 2960 | if (m_floatingObjects) { |
commit-queue@webkit.org | 6ad70c2 | 2015-06-12 18:43:01 +0000 | [diff] [blame] | 2961 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2962 | auto end = floatingObjectSet.end(); |
| 2963 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2964 | const auto& floatingObject = *it->get(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2965 | // Only examine the object if our m_shouldPaint flag is set. |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2966 | if (floatingObject.shouldPaint()) { |
hyatt@apple.com | b618b2a | 2017-03-17 18:54:47 +0000 | [diff] [blame] | 2967 | LayoutUnit floatLeft = floatingObject.translationOffsetToAncestor().width(); |
zalan@apple.com | 6816b13 | 2015-10-17 19:14:53 +0000 | [diff] [blame] | 2968 | LayoutUnit floatRight = floatLeft + floatingObject.renderer().width(); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2969 | left = std::min(left, floatLeft); |
| 2970 | right = std::max(right, floatRight); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2971 | } |
| 2972 | } |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | void RenderBlockFlow::fitBorderToLinesIfNeeded() |
| 2977 | { |
rego@igalia.com | f7d624c | 2015-04-22 10:31:24 +0000 | [diff] [blame] | 2978 | if (style().borderFit() == BorderFitBorder || hasOverrideLogicalContentWidth()) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2979 | return; |
| 2980 | |
| 2981 | // Walk any normal flow lines to snugly fit. |
| 2982 | LayoutUnit left = LayoutUnit::max(); |
| 2983 | LayoutUnit right = LayoutUnit::min(); |
| 2984 | LayoutUnit oldWidth = contentWidth(); |
| 2985 | adjustForBorderFit(0, left, right); |
| 2986 | |
| 2987 | // Clamp to our existing edges. We can never grow. We only shrink. |
| 2988 | LayoutUnit leftEdge = borderLeft() + paddingLeft(); |
| 2989 | LayoutUnit rightEdge = leftEdge + oldWidth; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2990 | left = std::min(rightEdge, std::max(leftEdge, left)); |
| 2991 | right = std::max(leftEdge, std::min(rightEdge, right)); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2992 | |
| 2993 | LayoutUnit newContentWidth = right - left; |
| 2994 | if (newContentWidth == oldWidth) |
| 2995 | return; |
| 2996 | |
| 2997 | setOverrideLogicalContentWidth(newContentWidth); |
| 2998 | layoutBlock(false); |
| 2999 | clearOverrideLogicalContentWidth(); |
| 3000 | } |
| 3001 | |
| 3002 | void RenderBlockFlow::markLinesDirtyInBlockRange(LayoutUnit logicalTop, LayoutUnit logicalBottom, RootInlineBox* highest) |
| 3003 | { |
| 3004 | if (logicalTop >= logicalBottom) |
| 3005 | return; |
| 3006 | |
antti@apple.com | be9d3e1 | 2014-05-11 09:42:47 +0000 | [diff] [blame] | 3007 | // Floats currently affect the choice whether to use simple line layout path. |
| 3008 | if (m_simpleLineLayout) { |
| 3009 | invalidateLineLayoutPath(); |
| 3010 | return; |
| 3011 | } |
| 3012 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3013 | RootInlineBox* lowestDirtyLine = lastRootBox(); |
| 3014 | RootInlineBox* afterLowest = lowestDirtyLine; |
| 3015 | while (lowestDirtyLine && lowestDirtyLine->lineBottomWithLeading() >= logicalBottom && logicalBottom < LayoutUnit::max()) { |
| 3016 | afterLowest = lowestDirtyLine; |
| 3017 | lowestDirtyLine = lowestDirtyLine->prevRootBox(); |
| 3018 | } |
| 3019 | |
| 3020 | while (afterLowest && afterLowest != highest && (afterLowest->lineBottomWithLeading() >= logicalTop || afterLowest->lineBottomWithLeading() < 0)) { |
| 3021 | afterLowest->markDirty(); |
| 3022 | afterLowest = afterLowest->prevRootBox(); |
| 3023 | } |
| 3024 | } |
| 3025 | |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3026 | std::optional<int> RenderBlockFlow::firstLineBaseline() const |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3027 | { |
| 3028 | if (isWritingModeRoot() && !isRubyRun()) |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3029 | return std::optional<int>(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3030 | |
| 3031 | if (!childrenInline()) |
antti@apple.com | 0e632aa | 2013-10-22 21:03:38 +0000 | [diff] [blame] | 3032 | return RenderBlock::firstLineBaseline(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3033 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3034 | if (!hasLines()) |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3035 | return std::optional<int>(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3036 | |
darin@apple.com | e1be6ca | 2014-04-28 04:19:10 +0000 | [diff] [blame] | 3037 | if (auto simpleLineLayout = this->simpleLineLayout()) |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3038 | return std::optional<int>(SimpleLineLayout::computeFlowFirstLineBaseline(*this, *simpleLineLayout)); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3039 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 3040 | ASSERT(firstRootBox()); |
| 3041 | return firstRootBox()->logicalTop() + firstLineStyle().fontMetrics().ascent(firstRootBox()->baselineType()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3044 | std::optional<int> RenderBlockFlow::inlineBlockBaseline(LineDirectionMode lineDirection) const |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3045 | { |
| 3046 | if (isWritingModeRoot() && !isRubyRun()) |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3047 | return std::optional<int>(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3048 | |
mmaxfield@apple.com | 9f4af63 | 2015-03-09 23:43:34 +0000 | [diff] [blame] | 3049 | // Note that here we only take the left and bottom into consideration. Our caller takes the right and top into consideration. |
| 3050 | float boxHeight = lineDirection == HorizontalLine ? height() + m_marginBox.bottom() : width() + m_marginBox.left(); |
| 3051 | float lastBaseline; |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 3052 | if (!childrenInline()) { |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3053 | std::optional<int> inlineBlockBaseline = RenderBlock::inlineBlockBaseline(lineDirection); |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 3054 | if (!inlineBlockBaseline) |
| 3055 | return inlineBlockBaseline; |
| 3056 | lastBaseline = inlineBlockBaseline.value(); |
| 3057 | } else { |
mmaxfield@apple.com | a52ab46 | 2015-03-11 14:41:01 +0000 | [diff] [blame] | 3058 | if (!hasLines()) { |
| 3059 | if (!hasLineIfEmpty()) |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3060 | return std::optional<int>(); |
mmaxfield@apple.com | a52ab46 | 2015-03-11 14:41:01 +0000 | [diff] [blame] | 3061 | const auto& fontMetrics = firstLineStyle().fontMetrics(); |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3062 | return std::optional<int>(fontMetrics.ascent() |
mmaxfield@apple.com | a52ab46 | 2015-03-11 14:41:01 +0000 | [diff] [blame] | 3063 | + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - fontMetrics.height()) / 2 |
mmaxfield@apple.com | 5f90774 | 2015-03-11 18:22:06 +0000 | [diff] [blame] | 3064 | + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : borderRight() + paddingRight())); |
mmaxfield@apple.com | a52ab46 | 2015-03-11 14:41:01 +0000 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | if (auto simpleLineLayout = this->simpleLineLayout()) |
| 3068 | lastBaseline = SimpleLineLayout::computeFlowLastLineBaseline(*this, *simpleLineLayout); |
| 3069 | else { |
| 3070 | bool isFirstLine = lastRootBox() == firstRootBox(); |
| 3071 | const auto& style = isFirstLine ? firstLineStyle() : this->style(); |
| 3072 | lastBaseline = lastRootBox()->logicalTop() + style.fontMetrics().ascent(lastRootBox()->baselineType()); |
| 3073 | } |
mmaxfield@apple.com | 9f4af63 | 2015-03-09 23:43:34 +0000 | [diff] [blame] | 3074 | } |
| 3075 | // According to the CSS spec http://www.w3.org/TR/CSS21/visudet.html, we shouldn't be performing this min, but should |
| 3076 | // instead be returning boxHeight directly. However, we feel that a min here is better behavior (and is consistent |
| 3077 | // enough with the spec to not cause tons of breakages). |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 3078 | return std::optional<int>(style().overflowY() == OVISIBLE ? lastBaseline : std::min(boxHeight, lastBaseline)); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3079 | } |
| 3080 | |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 3081 | void RenderBlockFlow::setSelectionState(SelectionState state) |
| 3082 | { |
| 3083 | if (state != SelectionNone) |
| 3084 | ensureLineBoxes(); |
| 3085 | RenderBoxModelObject::setSelectionState(state); |
| 3086 | } |
| 3087 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 3088 | GapRects RenderBlockFlow::inlineSelectionGaps(RenderBlock& rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3089 | LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const LogicalSelectionOffsetCaches& cache, const PaintInfo* paintInfo) |
| 3090 | { |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3091 | ASSERT(!m_simpleLineLayout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3092 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3093 | GapRects result; |
| 3094 | |
| 3095 | bool containsStart = selectionState() == SelectionStart || selectionState() == SelectionBoth; |
| 3096 | |
antti@apple.com | 0e632aa | 2013-10-22 21:03:38 +0000 | [diff] [blame] | 3097 | if (!hasLines()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3098 | if (containsStart) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 3099 | // 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] | 3100 | lastLogicalTop = blockDirectionOffset(rootBlock, offsetFromRootBlock) + logicalHeight(); |
| 3101 | lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, logicalHeight(), cache); |
| 3102 | lastLogicalRight = logicalRightSelectionOffset(rootBlock, logicalHeight(), cache); |
| 3103 | } |
| 3104 | return result; |
| 3105 | } |
| 3106 | |
| 3107 | RootInlineBox* lastSelectedLine = 0; |
| 3108 | RootInlineBox* curr; |
| 3109 | for (curr = firstRootBox(); curr && !curr->hasSelectedChildren(); curr = curr->nextRootBox()) { } |
| 3110 | |
| 3111 | // Now paint the gaps for the lines. |
| 3112 | for (; curr && curr->hasSelectedChildren(); curr = curr->nextRootBox()) { |
| 3113 | LayoutUnit selTop = curr->selectionTopAdjustedForPrecedingBlock(); |
| 3114 | LayoutUnit selHeight = curr->selectionHeightAdjustedForPrecedingBlock(); |
| 3115 | |
| 3116 | if (!containsStart && !lastSelectedLine && |
hyatt@apple.com | 90a4204 | 2014-11-18 17:54:52 +0000 | [diff] [blame] | 3117 | selectionState() != SelectionStart && selectionState() != SelectionBoth && !isRubyBase()) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3118 | result.uniteCenter(blockSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, lastLogicalTop, lastLogicalLeft, lastLogicalRight, selTop, cache, paintInfo)); |
| 3119 | |
| 3120 | LayoutRect logicalRect(curr->logicalLeft(), selTop, curr->logicalWidth(), selTop + selHeight); |
| 3121 | logicalRect.move(isHorizontalWritingMode() ? offsetFromRootBlock : offsetFromRootBlock.transposedSize()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 3122 | LayoutRect physicalRect = rootBlock.logicalRectToPhysicalRect(rootBlockPhysicalPosition, logicalRect); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3123 | if (!paintInfo || (isHorizontalWritingMode() && physicalRect.y() < paintInfo->rect.maxY() && physicalRect.maxY() > paintInfo->rect.y()) |
| 3124 | || (!isHorizontalWritingMode() && physicalRect.x() < paintInfo->rect.maxX() && physicalRect.maxX() > paintInfo->rect.x())) |
| 3125 | result.unite(curr->lineSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, selTop, selHeight, cache, paintInfo)); |
| 3126 | |
| 3127 | lastSelectedLine = curr; |
| 3128 | } |
| 3129 | |
| 3130 | if (containsStart && !lastSelectedLine) |
| 3131 | // VisibleSelection must start just after our last line. |
| 3132 | lastSelectedLine = lastRootBox(); |
| 3133 | |
| 3134 | if (lastSelectedLine && selectionState() != SelectionEnd && selectionState() != SelectionBoth) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 3135 | // Update our lastY to be the bottom of the last selected line. |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3136 | lastLogicalTop = blockDirectionOffset(rootBlock, offsetFromRootBlock) + lastSelectedLine->selectionBottom(); |
| 3137 | lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, lastSelectedLine->selectionBottom(), cache); |
| 3138 | lastLogicalRight = logicalRightSelectionOffset(rootBlock, lastSelectedLine->selectionBottom(), cache); |
| 3139 | } |
| 3140 | return result; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 3141 | } |
| 3142 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 3143 | bool RenderBlockFlow::needsLayoutAfterFragmentRangeChange() const |
abucur@adobe.com | eaf5e22 | 2014-05-14 14:35:07 +0000 | [diff] [blame] | 3144 | { |
| 3145 | // 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] | 3146 | // after a fragment range change. There is no overflow content needing relayout |
| 3147 | // 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] | 3148 | if (!containsFloats() || createsNewFormattingContext()) |
abucur@adobe.com | eaf5e22 | 2014-05-14 14:35:07 +0000 | [diff] [blame] | 3149 | return false; |
| 3150 | |
| 3151 | return true; |
| 3152 | } |
| 3153 | |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 3154 | void RenderBlockFlow::updateLogicalHeight() |
| 3155 | { |
| 3156 | RenderBlock::updateLogicalHeight(); |
abucur@adobe.com | 0e81bc7 | 2013-10-22 14:50:37 +0000 | [diff] [blame] | 3157 | } |
| 3158 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3159 | void RenderBlockFlow::setMultiColumnFlow(RenderMultiColumnFlow* fragmentedFlow) |
hyatt@apple.com | e9fe3d3 | 2014-01-24 17:14:22 +0000 | [diff] [blame] | 3160 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3161 | if (fragmentedFlow || hasRareBlockFlowData()) { |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3162 | RenderBlockFlowRareData& rareData = ensureRareBlockFlowData(); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3163 | rareData.m_multiColumnFlow = fragmentedFlow; |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3164 | } |
hyatt@apple.com | e9fe3d3 | 2014-01-24 17:14:22 +0000 | [diff] [blame] | 3165 | } |
| 3166 | |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 3167 | static bool shouldCheckLines(const RenderBlockFlow& blockFlow) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3168 | { |
akling@apple.com | 38f0a65 | 2014-02-06 21:24:17 +0000 | [diff] [blame] | 3169 | return !blockFlow.isFloatingOrOutOfFlowPositioned() && blockFlow.style().height().isAuto(); |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | RootInlineBox* RenderBlockFlow::lineAtIndex(int i) const |
| 3173 | { |
| 3174 | ASSERT(i >= 0); |
| 3175 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 3176 | if (style().visibility() != VISIBLE) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3177 | return nullptr; |
| 3178 | |
| 3179 | if (childrenInline()) { |
cdumez@apple.com | c1d54fa | 2015-10-13 19:15:55 +0000 | [diff] [blame] | 3180 | for (auto* box = firstRootBox(); box; box = box->nextRootBox()) { |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3181 | if (!i--) |
| 3182 | return box; |
| 3183 | } |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 3184 | return nullptr; |
| 3185 | } |
| 3186 | |
| 3187 | for (auto& blockFlow : childrenOfType<RenderBlockFlow>(*this)) { |
| 3188 | if (!shouldCheckLines(blockFlow)) |
| 3189 | continue; |
| 3190 | if (RootInlineBox* box = blockFlow.lineAtIndex(i)) |
| 3191 | return box; |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | return nullptr; |
| 3195 | } |
| 3196 | |
| 3197 | int RenderBlockFlow::lineCount(const RootInlineBox* stopRootInlineBox, bool* found) const |
| 3198 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 3199 | if (style().visibility() != VISIBLE) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3200 | return 0; |
| 3201 | |
| 3202 | int count = 0; |
| 3203 | |
| 3204 | if (childrenInline()) { |
darin@apple.com | e1be6ca | 2014-04-28 04:19:10 +0000 | [diff] [blame] | 3205 | if (auto simpleLineLayout = this->simpleLineLayout()) { |
antti@apple.com | 0b3dffe | 2014-03-24 16:30:52 +0000 | [diff] [blame] | 3206 | ASSERT(!stopRootInlineBox); |
darin@apple.com | e1be6ca | 2014-04-28 04:19:10 +0000 | [diff] [blame] | 3207 | return simpleLineLayout->lineCount(); |
antti@apple.com | 0b3dffe | 2014-03-24 16:30:52 +0000 | [diff] [blame] | 3208 | } |
cdumez@apple.com | c1d54fa | 2015-10-13 19:15:55 +0000 | [diff] [blame] | 3209 | for (auto* box = firstRootBox(); box; box = box->nextRootBox()) { |
| 3210 | ++count; |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3211 | if (box == stopRootInlineBox) { |
| 3212 | if (found) |
| 3213 | *found = true; |
| 3214 | break; |
| 3215 | } |
| 3216 | } |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 3217 | return count; |
| 3218 | } |
| 3219 | |
| 3220 | for (auto& blockFlow : childrenOfType<RenderBlockFlow>(*this)) { |
| 3221 | if (!shouldCheckLines(blockFlow)) |
| 3222 | continue; |
| 3223 | bool recursiveFound = false; |
| 3224 | count += blockFlow.lineCount(stopRootInlineBox, &recursiveFound); |
| 3225 | if (recursiveFound) { |
| 3226 | if (found) |
| 3227 | *found = true; |
| 3228 | break; |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3229 | } |
| 3230 | } |
| 3231 | |
| 3232 | return count; |
| 3233 | } |
| 3234 | |
| 3235 | static int getHeightForLineCount(const RenderBlockFlow& block, int lineCount, bool includeBottom, int& count) |
| 3236 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 3237 | if (block.style().visibility() != VISIBLE) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3238 | return -1; |
| 3239 | |
| 3240 | if (block.childrenInline()) { |
cdumez@apple.com | c1d54fa | 2015-10-13 19:15:55 +0000 | [diff] [blame] | 3241 | for (auto* box = block.firstRootBox(); box; box = box->nextRootBox()) { |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3242 | if (++count == lineCount) |
| 3243 | return box->lineBottom() + (includeBottom ? (block.borderBottom() + block.paddingBottom()) : LayoutUnit()); |
| 3244 | } |
| 3245 | } else { |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 3246 | RenderBox* normalFlowChildWithoutLines = nullptr; |
cdumez@apple.com | c1d54fa | 2015-10-13 19:15:55 +0000 | [diff] [blame] | 3247 | for (auto* obj = block.firstChildBox(); obj; obj = obj->nextSiblingBox()) { |
cdumez@apple.com | 34e77ab | 2014-10-09 16:17:06 +0000 | [diff] [blame] | 3248 | if (is<RenderBlockFlow>(*obj) && shouldCheckLines(downcast<RenderBlockFlow>(*obj))) { |
| 3249 | int result = getHeightForLineCount(downcast<RenderBlockFlow>(*obj), lineCount, false, count); |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3250 | if (result != -1) |
| 3251 | return result + obj->y() + (includeBottom ? (block.borderBottom() + block.paddingBottom()) : LayoutUnit()); |
akling@apple.com | 38f0a65 | 2014-02-06 21:24:17 +0000 | [diff] [blame] | 3252 | } else if (!obj->isFloatingOrOutOfFlowPositioned()) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3253 | normalFlowChildWithoutLines = obj; |
| 3254 | } |
| 3255 | if (normalFlowChildWithoutLines && !lineCount) |
| 3256 | return normalFlowChildWithoutLines->y() + normalFlowChildWithoutLines->height(); |
| 3257 | } |
| 3258 | |
| 3259 | return -1; |
| 3260 | } |
| 3261 | |
| 3262 | int RenderBlockFlow::heightForLineCount(int lineCount) |
| 3263 | { |
| 3264 | int count = 0; |
| 3265 | return getHeightForLineCount(*this, lineCount, true, count); |
| 3266 | } |
| 3267 | |
| 3268 | void RenderBlockFlow::clearTruncation() |
| 3269 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 3270 | if (style().visibility() != VISIBLE) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3271 | return; |
| 3272 | |
| 3273 | if (childrenInline() && hasMarkupTruncation()) { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3274 | ensureLineBoxes(); |
| 3275 | |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3276 | setHasMarkupTruncation(false); |
cdumez@apple.com | c1d54fa | 2015-10-13 19:15:55 +0000 | [diff] [blame] | 3277 | for (auto* box = firstRootBox(); box; box = box->nextRootBox()) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3278 | box->clearTruncation(); |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 3279 | return; |
| 3280 | } |
| 3281 | |
| 3282 | for (auto& blockFlow : childrenOfType<RenderBlockFlow>(*this)) { |
| 3283 | if (shouldCheckLines(blockFlow)) |
| 3284 | blockFlow.clearTruncation(); |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3285 | } |
| 3286 | } |
| 3287 | |
weinig@apple.com | 3f23b38 | 2013-10-19 20:26:58 +0000 | [diff] [blame] | 3288 | bool RenderBlockFlow::containsNonZeroBidiLevel() const |
| 3289 | { |
cdumez@apple.com | c1d54fa | 2015-10-13 19:15:55 +0000 | [diff] [blame] | 3290 | for (auto* root = firstRootBox(); root; root = root->nextRootBox()) { |
| 3291 | for (auto* box = root->firstLeafChild(); box; box = box->nextLeafChild()) { |
weinig@apple.com | 3f23b38 | 2013-10-19 20:26:58 +0000 | [diff] [blame] | 3292 | if (box->bidiLevel()) |
| 3293 | return true; |
| 3294 | } |
| 3295 | } |
| 3296 | return false; |
| 3297 | } |
| 3298 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3299 | Position RenderBlockFlow::positionForBox(InlineBox *box, bool start) const |
| 3300 | { |
| 3301 | if (!box) |
| 3302 | return Position(); |
| 3303 | |
| 3304 | if (!box->renderer().nonPseudoNode()) |
| 3305 | return createLegacyEditingPosition(nonPseudoElement(), start ? caretMinOffset() : caretMaxOffset()); |
| 3306 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 3307 | if (!is<InlineTextBox>(*box)) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3308 | return createLegacyEditingPosition(box->renderer().nonPseudoNode(), start ? box->renderer().caretMinOffset() : box->renderer().caretMaxOffset()); |
| 3309 | |
cdumez@apple.com | 57d544c | 2014-10-16 00:05:37 +0000 | [diff] [blame] | 3310 | auto& textBox = downcast<InlineTextBox>(*box); |
| 3311 | return createLegacyEditingPosition(textBox.renderer().nonPseudoNode(), start ? textBox.start() : textBox.start() + textBox.len()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
enrica@apple.com | 0db51a6 | 2016-04-27 23:53:08 +0000 | [diff] [blame] | 3314 | RenderText* RenderBlockFlow::findClosestTextAtAbsolutePoint(const FloatPoint& point) |
| 3315 | { |
| 3316 | // A light, non-recursive version of RenderBlock::positionForCoordinates that looks at |
| 3317 | // whether a point lies within the gaps between its root line boxes, to be called against |
| 3318 | // a node returned from elementAtPoint. We make the assumption that either the node or one |
| 3319 | // of its immediate children contains the root line boxes in question. |
| 3320 | // See <rdar://problem/6824650> for context. |
| 3321 | |
| 3322 | RenderBlock* block = this; |
| 3323 | |
| 3324 | FloatPoint localPoint = block->absoluteToLocal(point); |
| 3325 | |
| 3326 | if (!block->childrenInline()) { |
| 3327 | // Look among our immediate children for an alternate box that contains the point. |
| 3328 | for (RenderBox* child = block->firstChildBox(); child; child = child->nextSiblingBox()) { |
| 3329 | if (!child->height() || child->style().visibility() != WebCore::VISIBLE || child->isFloatingOrOutOfFlowPositioned()) |
| 3330 | continue; |
| 3331 | float top = child->y(); |
| 3332 | |
| 3333 | RenderBox* nextChild = child->nextSiblingBox(); |
| 3334 | while (nextChild && nextChild->isFloatingOrOutOfFlowPositioned()) |
| 3335 | nextChild = nextChild->nextSiblingBox(); |
| 3336 | if (!nextChild) { |
| 3337 | if (localPoint.y() >= top) { |
| 3338 | block = downcast<RenderBlock>(child); |
| 3339 | break; |
| 3340 | } |
| 3341 | continue; |
| 3342 | } |
| 3343 | |
| 3344 | float bottom = nextChild->y(); |
| 3345 | |
| 3346 | if (localPoint.y() >= top && localPoint.y() < bottom && is<RenderBlock>(*child)) { |
| 3347 | block = downcast<RenderBlock>(child); |
| 3348 | break; |
| 3349 | } |
| 3350 | } |
| 3351 | |
| 3352 | if (!block->childrenInline()) |
| 3353 | return nullptr; |
| 3354 | |
| 3355 | localPoint = block->absoluteToLocal(point); |
| 3356 | } |
| 3357 | |
| 3358 | RenderBlockFlow& blockFlow = downcast<RenderBlockFlow>(*block); |
| 3359 | |
| 3360 | // Only check the gaps between the root line boxes. We deliberately ignore overflow because |
| 3361 | // 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] | 3362 | // overflow fragment. |
enrica@apple.com | 0db51a6 | 2016-04-27 23:53:08 +0000 | [diff] [blame] | 3363 | for (RootInlineBox* current = blockFlow.firstRootBox(); current && current != blockFlow.lastRootBox(); current = current->nextRootBox()) { |
| 3364 | float currentBottom = current->y() + current->logicalHeight(); |
| 3365 | if (localPoint.y() < currentBottom) |
| 3366 | return nullptr; |
| 3367 | |
| 3368 | RootInlineBox* next = current->nextRootBox(); |
| 3369 | float nextTop = next->y(); |
| 3370 | if (localPoint.y() < nextTop) { |
| 3371 | InlineBox* inlineBox = current->closestLeafChildForLogicalLeftPosition(localPoint.x()); |
| 3372 | if (inlineBox && inlineBox->behavesLikeText() && is<RenderText>(inlineBox->renderer())) |
| 3373 | return &downcast<RenderText>(inlineBox->renderer()); |
| 3374 | } |
| 3375 | } |
| 3376 | return nullptr; |
| 3377 | } |
| 3378 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 3379 | VisiblePosition RenderBlockFlow::positionForPointWithInlineChildren(const LayoutPoint& pointInLogicalContents, const RenderFragmentContainer* fragment) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3380 | { |
| 3381 | ASSERT(childrenInline()); |
| 3382 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3383 | ensureLineBoxes(); |
| 3384 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3385 | if (!firstRootBox()) |
| 3386 | return createVisiblePosition(0, DOWNSTREAM); |
| 3387 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 3388 | bool linesAreFlipped = style().isFlippedLinesWritingMode(); |
| 3389 | bool blocksAreFlipped = style().isFlippedBlocksWritingMode(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3390 | |
| 3391 | // look for the closest line box in the root box which is at the passed-in y coordinate |
| 3392 | InlineBox* closestBox = 0; |
| 3393 | RootInlineBox* firstRootBoxWithChildren = 0; |
| 3394 | RootInlineBox* lastRootBoxWithChildren = 0; |
| 3395 | for (RootInlineBox* root = firstRootBox(); root; root = root->nextRootBox()) { |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 3396 | if (fragment && root->containingFragment() != fragment) |
stavila@adobe.com | 4ce2fff | 2014-04-25 13:56:12 +0000 | [diff] [blame] | 3397 | continue; |
| 3398 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3399 | if (!root->firstLeafChild()) |
| 3400 | continue; |
| 3401 | if (!firstRootBoxWithChildren) |
| 3402 | firstRootBoxWithChildren = root; |
| 3403 | |
| 3404 | if (!linesAreFlipped && root->isFirstAfterPageBreak() && (pointInLogicalContents.y() < root->lineTopWithLeading() |
| 3405 | || (blocksAreFlipped && pointInLogicalContents.y() == root->lineTopWithLeading()))) |
| 3406 | break; |
| 3407 | |
| 3408 | lastRootBoxWithChildren = root; |
| 3409 | |
| 3410 | // check if this root line box is located at this y coordinate |
| 3411 | if (pointInLogicalContents.y() < root->selectionBottom() || (blocksAreFlipped && pointInLogicalContents.y() == root->selectionBottom())) { |
| 3412 | if (linesAreFlipped) { |
| 3413 | RootInlineBox* nextRootBoxWithChildren = root->nextRootBox(); |
| 3414 | while (nextRootBoxWithChildren && !nextRootBoxWithChildren->firstLeafChild()) |
| 3415 | nextRootBoxWithChildren = nextRootBoxWithChildren->nextRootBox(); |
| 3416 | |
| 3417 | if (nextRootBoxWithChildren && nextRootBoxWithChildren->isFirstAfterPageBreak() && (pointInLogicalContents.y() > nextRootBoxWithChildren->lineTopWithLeading() |
| 3418 | || (!blocksAreFlipped && pointInLogicalContents.y() == nextRootBoxWithChildren->lineTopWithLeading()))) |
| 3419 | continue; |
| 3420 | } |
| 3421 | closestBox = root->closestLeafChildForLogicalLeftPosition(pointInLogicalContents.x()); |
| 3422 | if (closestBox) |
| 3423 | break; |
| 3424 | } |
| 3425 | } |
| 3426 | |
| 3427 | bool moveCaretToBoundary = frame().editor().behavior().shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom(); |
| 3428 | |
| 3429 | if (!moveCaretToBoundary && !closestBox && lastRootBoxWithChildren) { |
| 3430 | // y coordinate is below last root line box, pretend we hit it |
| 3431 | closestBox = lastRootBoxWithChildren->closestLeafChildForLogicalLeftPosition(pointInLogicalContents.x()); |
| 3432 | } |
| 3433 | |
| 3434 | if (closestBox) { |
| 3435 | if (moveCaretToBoundary) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 3436 | LayoutUnit firstRootBoxWithChildrenTop = std::min<LayoutUnit>(firstRootBoxWithChildren->selectionTop(), firstRootBoxWithChildren->logicalTop()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3437 | if (pointInLogicalContents.y() < firstRootBoxWithChildrenTop |
| 3438 | || (blocksAreFlipped && pointInLogicalContents.y() == firstRootBoxWithChildrenTop)) { |
| 3439 | InlineBox* box = firstRootBoxWithChildren->firstLeafChild(); |
| 3440 | if (box->isLineBreak()) { |
| 3441 | if (InlineBox* newBox = box->nextLeafChildIgnoringLineBreak()) |
| 3442 | box = newBox; |
| 3443 | } |
| 3444 | // y coordinate is above first root line box, so return the start of the first |
| 3445 | return VisiblePosition(positionForBox(box, true), DOWNSTREAM); |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | // pass the box a top position that is inside it |
| 3450 | LayoutPoint point(pointInLogicalContents.x(), closestBox->root().blockDirectionPointInLine()); |
| 3451 | if (!isHorizontalWritingMode()) |
| 3452 | point = point.transposedPoint(); |
| 3453 | if (closestBox->renderer().isReplaced()) |
cdumez@apple.com | 0abff8b | 2014-10-17 21:25:10 +0000 | [diff] [blame] | 3454 | return positionForPointRespectingEditingBoundaries(*this, downcast<RenderBox>(closestBox->renderer()), point); |
stavila@adobe.com | 4ce2fff | 2014-04-25 13:56:12 +0000 | [diff] [blame] | 3455 | return closestBox->renderer().positionForPoint(point, nullptr); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | if (lastRootBoxWithChildren) { |
| 3459 | // We hit this case for Mac behavior when the Y coordinate is below the last box. |
| 3460 | ASSERT(moveCaretToBoundary); |
| 3461 | InlineBox* logicallyLastBox; |
| 3462 | if (lastRootBoxWithChildren->getLogicalEndBoxWithNode(logicallyLastBox)) |
| 3463 | return VisiblePosition(positionForBox(logicallyLastBox, false), DOWNSTREAM); |
| 3464 | } |
| 3465 | |
| 3466 | // Can't reach this. We have a root line box, but it has no kids. |
| 3467 | // FIXME: This should ASSERT_NOT_REACHED(), but clicking on placeholder text |
| 3468 | // seems to hit this code path. |
| 3469 | return createVisiblePosition(0, DOWNSTREAM); |
| 3470 | } |
| 3471 | |
zalan@apple.com | 0d5951b | 2017-02-19 16:24:20 +0000 | [diff] [blame] | 3472 | Position RenderBlockFlow::positionForPoint(const LayoutPoint& point) |
| 3473 | { |
| 3474 | // FIXME: It supports single text child only (which is the majority of simple line layout supported content at this point). |
| 3475 | if (!simpleLineLayout() || firstChild() != lastChild() || !is<RenderText>(firstChild())) |
| 3476 | return positionForPoint(point, nullptr).deepEquivalent(); |
| 3477 | return downcast<RenderText>(*firstChild()).positionForPoint(point); |
| 3478 | } |
| 3479 | |
hyatt@apple.com | e0d2e0f | 2017-09-27 16:19:08 +0000 | [diff] [blame] | 3480 | VisiblePosition RenderBlockFlow::positionForPoint(const LayoutPoint& point, const RenderFragmentContainer*) |
commit-queue@webkit.org | 5ce6c90 | 2013-11-11 18:21:05 +0000 | [diff] [blame] | 3481 | { |
antti@apple.com | e0e8a56 | 2017-09-21 18:29:47 +0000 | [diff] [blame] | 3482 | return RenderBlock::positionForPoint(point, nullptr); |
commit-queue@webkit.org | 5ce6c90 | 2013-11-11 18:21:05 +0000 | [diff] [blame] | 3483 | } |
| 3484 | |
zalan@apple.com | 8ee1af5 | 2016-02-11 22:15:45 +0000 | [diff] [blame] | 3485 | void RenderBlockFlow::addFocusRingRectsForInlineChildren(Vector<LayoutRect>& rects, const LayoutPoint& additionalOffset, const RenderLayerModelObject*) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3486 | { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3487 | ASSERT(childrenInline()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3488 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 3489 | LayoutUnit top = std::max<LayoutUnit>(curr->lineTop(), curr->top()); |
| 3490 | LayoutUnit bottom = std::min<LayoutUnit>(curr->lineBottom(), curr->top() + curr->height()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3491 | LayoutRect rect(additionalOffset.x() + curr->x(), additionalOffset.y() + top, curr->width(), bottom - top); |
| 3492 | if (!rect.isEmpty()) |
zalan@apple.com | 8ee1af5 | 2016-02-11 22:15:45 +0000 | [diff] [blame] | 3493 | rects.append(rect); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | void RenderBlockFlow::paintInlineChildren(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| 3498 | { |
| 3499 | ASSERT(childrenInline()); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3500 | |
darin@apple.com | e1be6ca | 2014-04-28 04:19:10 +0000 | [diff] [blame] | 3501 | if (auto simpleLineLayout = this->simpleLineLayout()) { |
| 3502 | SimpleLineLayout::paintFlow(*this, *simpleLineLayout, paintInfo, paintOffset); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3503 | return; |
| 3504 | } |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3505 | m_lineBoxes.paint(this, paintInfo, paintOffset); |
| 3506 | } |
| 3507 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 3508 | bool RenderBlockFlow::relayoutForPagination(LayoutStateMaintainer& statePusher) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3509 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3510 | if (!multiColumnFlow() || !multiColumnFlow()->shouldRelayoutForPagination()) |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3511 | return false; |
| 3512 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3513 | multiColumnFlow()->setNeedsHeightsRecalculation(false); |
| 3514 | 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] | 3515 | |
| 3516 | bool needsRelayout; |
| 3517 | bool neededRelayout = false; |
| 3518 | bool firstPass = true; |
| 3519 | do { |
| 3520 | // Column heights may change here because of balancing. We may have to do multiple layout |
| 3521 | // passes, depending on how the contents is fitted to the changed column heights. In most |
| 3522 | // cases, laying out again twice or even just once will suffice. Sometimes we need more |
| 3523 | // passes than that, though, but the number of retries should not exceed the number of |
| 3524 | // columns, unless we have a bug. |
| 3525 | needsRelayout = false; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3526 | for (RenderMultiColumnSet* multicolSet = multiColumnFlow()->firstMultiColumnSet(); multicolSet; multicolSet = multicolSet->nextSiblingMultiColumnSet()) { |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3527 | if (multicolSet->recalculateColumnHeight(firstPass)) |
| 3528 | needsRelayout = true; |
| 3529 | if (needsRelayout) { |
| 3530 | // Once a column set gets a new column height, that column set and all successive column |
| 3531 | // sets need to be laid out over again, since their logical top will be affected by |
| 3532 | // this, and therefore their column heights may change as well, at least if the multicol |
| 3533 | // height is constrained. |
| 3534 | multicolSet->setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3535 | } |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3536 | } |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3537 | if (needsRelayout) { |
| 3538 | // Layout again. Column balancing resulted in a new height. |
| 3539 | neededRelayout = true; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3540 | multiColumnFlow()->setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3541 | setChildNeedsLayout(MarkOnlyThis); |
| 3542 | if (firstPass) |
| 3543 | statePusher.pop(); |
| 3544 | layoutBlock(false); |
| 3545 | } |
| 3546 | firstPass = false; |
| 3547 | } while (needsRelayout); |
| 3548 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3549 | multiColumnFlow()->setInBalancingPass(false); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3550 | |
| 3551 | return neededRelayout; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3552 | } |
| 3553 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3554 | bool RenderBlockFlow::hasLines() const |
| 3555 | { |
zalan@apple.com | a2fe176 | 2016-08-24 18:33:43 +0000 | [diff] [blame] | 3556 | if (!childrenInline()) |
| 3557 | return false; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3558 | |
darin@apple.com | e1be6ca | 2014-04-28 04:19:10 +0000 | [diff] [blame] | 3559 | if (auto simpleLineLayout = this->simpleLineLayout()) |
| 3560 | return simpleLineLayout->lineCount(); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3561 | |
| 3562 | return lineBoxes().firstLineBox(); |
| 3563 | } |
| 3564 | |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3565 | void RenderBlockFlow::invalidateLineLayoutPath() |
| 3566 | { |
akling@apple.com | a12fee2 | 2015-02-01 02:58:13 +0000 | [diff] [blame] | 3567 | switch (lineLayoutPath()) { |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3568 | case UndeterminedPath: |
| 3569 | case ForceLineBoxesPath: |
| 3570 | ASSERT(!m_simpleLineLayout); |
| 3571 | return; |
| 3572 | case LineBoxesPath: |
| 3573 | ASSERT(!m_simpleLineLayout); |
akling@apple.com | a12fee2 | 2015-02-01 02:58:13 +0000 | [diff] [blame] | 3574 | setLineLayoutPath(UndeterminedPath); |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3575 | return; |
| 3576 | case SimpleLinesPath: |
| 3577 | // The simple line layout may have become invalid. |
| 3578 | m_simpleLineLayout = nullptr; |
akling@apple.com | a12fee2 | 2015-02-01 02:58:13 +0000 | [diff] [blame] | 3579 | setLineLayoutPath(UndeterminedPath); |
zalan@apple.com | de19104 | 2017-06-06 19:35:56 +0000 | [diff] [blame] | 3580 | if (needsLayout()) |
| 3581 | return; |
| 3582 | // FIXME: We should just kick off a subtree layout here (if needed at all) see webkit.org/b/172947. |
| 3583 | setNeedsLayout(); |
antti@apple.com | 9e891c8 | 2014-05-22 06:12:34 +0000 | [diff] [blame] | 3584 | return; |
| 3585 | } |
| 3586 | ASSERT_NOT_REACHED(); |
| 3587 | } |
| 3588 | |
zalan@apple.com | e37da96 | 2014-12-11 03:29:29 +0000 | [diff] [blame] | 3589 | void RenderBlockFlow::layoutSimpleLines(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3590 | { |
zalan@apple.com | e37da96 | 2014-12-11 03:29:29 +0000 | [diff] [blame] | 3591 | bool needsLayout = selfNeedsLayout() || relayoutChildren || !m_simpleLineLayout; |
| 3592 | if (needsLayout) { |
| 3593 | deleteLineBoxesBeforeSimpleLineLayout(); |
| 3594 | m_simpleLineLayout = SimpleLineLayout::create(*this); |
| 3595 | } |
zalan@apple.com | 5cd09e5 | 2017-02-25 02:14:40 +0000 | [diff] [blame] | 3596 | if (view().layoutState() && view().layoutState()->isPaginated()) { |
| 3597 | m_simpleLineLayout->setIsPaginated(); |
| 3598 | SimpleLineLayout::adjustLinePositionsForPagination(*m_simpleLineLayout, *this); |
| 3599 | } |
zalan@apple.com | d6ab7b5 | 2016-11-01 05:35:48 +0000 | [diff] [blame] | 3600 | for (auto& renderer : childrenOfType<RenderObject>(*this)) |
| 3601 | renderer.clearNeedsLayout(); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3602 | ASSERT(!m_lineBoxes.firstLineBox()); |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3603 | LayoutUnit lineLayoutHeight = SimpleLineLayout::computeFlowHeight(*this, *m_simpleLineLayout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3604 | LayoutUnit lineLayoutTop = borderAndPaddingBefore(); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3605 | repaintLogicalTop = lineLayoutTop; |
zalan@apple.com | e37da96 | 2014-12-11 03:29:29 +0000 | [diff] [blame] | 3606 | repaintLogicalBottom = needsLayout ? repaintLogicalTop + lineLayoutHeight : repaintLogicalTop; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3607 | setLogicalHeight(lineLayoutTop + lineLayoutHeight + borderAndPaddingAfter()); |
| 3608 | } |
| 3609 | |
| 3610 | void RenderBlockFlow::deleteLineBoxesBeforeSimpleLineLayout() |
| 3611 | { |
akling@apple.com | a12fee2 | 2015-02-01 02:58:13 +0000 | [diff] [blame] | 3612 | ASSERT(lineLayoutPath() == SimpleLinesPath); |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 3613 | lineBoxes().deleteLineBoxes(); |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 3614 | for (auto& renderer : childrenOfType<RenderObject>(*this)) { |
| 3615 | if (is<RenderText>(renderer)) |
| 3616 | downcast<RenderText>(renderer).deleteLineBoxesBeforeSimpleLineLayout(); |
| 3617 | else if (is<RenderLineBreak>(renderer)) |
| 3618 | downcast<RenderLineBreak>(renderer).deleteLineBoxesBeforeSimpleLineLayout(); |
| 3619 | else |
| 3620 | ASSERT_NOT_REACHED(); |
| 3621 | } |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | void RenderBlockFlow::ensureLineBoxes() |
| 3625 | { |
akling@apple.com | a12fee2 | 2015-02-01 02:58:13 +0000 | [diff] [blame] | 3626 | setLineLayoutPath(ForceLineBoxesPath); |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3627 | if (!m_simpleLineLayout) |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3628 | return; |
zalan@apple.com | fa5add6 | 2017-02-22 19:33:02 +0000 | [diff] [blame] | 3629 | bool isPaginated = m_simpleLineLayout->isPaginated(); |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3630 | m_simpleLineLayout = nullptr; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3631 | |
| 3632 | #if !ASSERT_DISABLED |
| 3633 | LayoutUnit oldHeight = logicalHeight(); |
| 3634 | #endif |
| 3635 | bool didNeedLayout = needsLayout(); |
| 3636 | |
| 3637 | bool relayoutChildren = false; |
| 3638 | LayoutUnit repaintLogicalTop; |
| 3639 | LayoutUnit repaintLogicalBottom; |
zalan@apple.com | fa5add6 | 2017-02-22 19:33:02 +0000 | [diff] [blame] | 3640 | if (isPaginated) { |
zalan@apple.com | 6c04c20 | 2017-05-01 00:15:38 +0000 | [diff] [blame] | 3641 | PaginatedLayoutStateMaintainer state(*this); |
zalan@apple.com | fa5add6 | 2017-02-22 19:33:02 +0000 | [diff] [blame] | 3642 | layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
zalan@apple.com | e9f0821 | 2017-04-27 11:02:09 +0000 | [diff] [blame] | 3643 | // This matches relayoutToAvoidWidows. |
| 3644 | if (shouldBreakAtLineToAvoidWidow()) |
| 3645 | layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
zalan@apple.com | b16bcdc | 2017-07-21 21:04:43 +0000 | [diff] [blame] | 3646 | // FIXME: This is needed as long as simple and normal line layout produce different line breakings. |
| 3647 | repaint(); |
zalan@apple.com | fa5add6 | 2017-02-22 19:33:02 +0000 | [diff] [blame] | 3648 | } else |
| 3649 | layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3650 | |
| 3651 | updateLogicalHeight(); |
| 3652 | ASSERT(didNeedLayout || logicalHeight() == oldHeight); |
| 3653 | |
| 3654 | if (!didNeedLayout) |
| 3655 | clearNeedsLayout(); |
| 3656 | } |
| 3657 | |
simon.fraser@apple.com | c9f9613 | 2015-03-06 18:20:40 +0000 | [diff] [blame] | 3658 | #if ENABLE(TREE_DEBUGGING) |
don.olmstead@sony.com | d57eb47 | 2017-08-10 01:15:14 +0000 | [diff] [blame] | 3659 | void RenderBlockFlow::outputLineTreeAndMark(WTF::TextStream& stream, const InlineBox* markedBox, int depth) const |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3660 | { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3661 | for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRootBox()) |
zalan@apple.com | 360de75 | 2017-07-06 21:13:24 +0000 | [diff] [blame] | 3662 | root->outputLineTreeAndMark(stream, markedBox, depth); |
simon.fraser@apple.com | 3518b14 | 2014-09-03 21:18:05 +0000 | [diff] [blame] | 3663 | |
| 3664 | if (auto simpleLineLayout = this->simpleLineLayout()) |
zalan@apple.com | 360de75 | 2017-07-06 21:13:24 +0000 | [diff] [blame] | 3665 | SimpleLineLayout::outputLineLayoutForFlow(stream, *this, *simpleLineLayout, depth); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3666 | } |
| 3667 | #endif |
| 3668 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 3669 | RenderBlockFlow::RenderBlockFlowRareData& RenderBlockFlow::ensureRareBlockFlowData() |
| 3670 | { |
| 3671 | if (hasRareBlockFlowData()) |
| 3672 | return *m_rareBlockFlowData; |
| 3673 | materializeRareBlockFlowData(); |
| 3674 | return *m_rareBlockFlowData; |
| 3675 | } |
| 3676 | |
| 3677 | void RenderBlockFlow::materializeRareBlockFlowData() |
| 3678 | { |
| 3679 | ASSERT(!hasRareBlockFlowData()); |
| 3680 | m_rareBlockFlowData = std::make_unique<RenderBlockFlow::RenderBlockFlowRareData>(*this); |
| 3681 | } |
| 3682 | |
dbates@webkit.org | 102013c | 2016-09-26 21:51:25 +0000 | [diff] [blame] | 3683 | #if ENABLE(TEXT_AUTOSIZING) |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3684 | static inline bool isVisibleRenderText(const RenderObject& renderer) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3685 | { |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3686 | if (!is<RenderText>(renderer)) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3687 | return false; |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3688 | |
| 3689 | auto& renderText = downcast<RenderText>(renderer); |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 3690 | return !renderText.linesBoundingBox().isEmpty() && !renderText.text()->containsOnlyWhitespace(); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3691 | } |
| 3692 | |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3693 | static inline bool resizeTextPermitted(const RenderObject& renderer) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3694 | { |
| 3695 | // 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] | 3696 | for (auto* ancestor = renderer.parent(); ancestor; ancestor = ancestor->parent()) { |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3697 | // 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] | 3698 | if (is<HTMLElement>(ancestor->element()) && !ancestor->element()->isInShadowTree()) { |
| 3699 | auto& element = downcast<HTMLElement>(*ancestor->element()); |
cdumez@apple.com | 59fdc8a | 2014-09-24 21:25:22 +0000 | [diff] [blame] | 3700 | return !is<HTMLInputElement>(element) && !is<HTMLTextAreaElement>(element); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3701 | } |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3702 | } |
| 3703 | return true; |
| 3704 | } |
| 3705 | |
antti@apple.com | 0b3dffe | 2014-03-24 16:30:52 +0000 | [diff] [blame] | 3706 | int RenderBlockFlow::lineCountForTextAutosizing() |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3707 | { |
antti@apple.com | 0b3dffe | 2014-03-24 16:30:52 +0000 | [diff] [blame] | 3708 | if (style().visibility() != VISIBLE) |
| 3709 | return 0; |
| 3710 | if (childrenInline()) |
| 3711 | return lineCount(); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3712 | // Only descend into list items. |
| 3713 | int count = 0; |
antti@apple.com | 0b3dffe | 2014-03-24 16:30:52 +0000 | [diff] [blame] | 3714 | for (auto& listItem : childrenOfType<RenderListItem>(*this)) |
| 3715 | count += listItem.lineCount(); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3716 | return count; |
| 3717 | } |
| 3718 | |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3719 | static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject& renderer) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3720 | { |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3721 | if (!renderer.isRenderBlock()) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3722 | return true; |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3723 | if (renderer.isListItem()) |
| 3724 | return renderer.style().height().type() != Fixed; |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3725 | return false; |
| 3726 | } |
| 3727 | |
| 3728 | // For now, we auto size single lines of text the same as multiple lines. |
| 3729 | // We've been experimenting with low values for single lines of text. |
| 3730 | static inline float oneLineTextMultiplier(float specifiedSize) |
| 3731 | { |
| 3732 | return std::max((1.0f / log10f(specifiedSize) * 1.7f), 1.0f); |
| 3733 | } |
| 3734 | |
| 3735 | static inline float textMultiplier(float specifiedSize) |
| 3736 | { |
| 3737 | return std::max((1.0f / log10f(specifiedSize) * 1.95f), 1.0f); |
| 3738 | } |
| 3739 | |
| 3740 | void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth) |
| 3741 | { |
simon.fraser@apple.com | 36676e5 | 2016-05-07 00:05:58 +0000 | [diff] [blame] | 3742 | LOG(TextAutosizing, "RenderBlockFlow %p adjustComputedFontSizes, size=%f visibleWidth=%f, width()=%f. Bailing: %d", this, size, visibleWidth, width().toFloat(), visibleWidth >= width()); |
| 3743 | |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3744 | // Don't do any work if the block is smaller than the visible area. |
| 3745 | if (visibleWidth >= width()) |
| 3746 | return; |
| 3747 | |
| 3748 | unsigned lineCount; |
| 3749 | if (m_lineCountForTextAutosizing == NOT_SET) { |
antti@apple.com | 0b3dffe | 2014-03-24 16:30:52 +0000 | [diff] [blame] | 3750 | int count = lineCountForTextAutosizing(); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3751 | if (!count) |
| 3752 | lineCount = NO_LINE; |
| 3753 | else if (count == 1) |
| 3754 | lineCount = ONE_LINE; |
| 3755 | else |
| 3756 | lineCount = MULTI_LINE; |
| 3757 | } else |
| 3758 | lineCount = m_lineCountForTextAutosizing; |
| 3759 | |
| 3760 | ASSERT(lineCount != NOT_SET); |
| 3761 | if (lineCount == NO_LINE) |
| 3762 | return; |
| 3763 | |
| 3764 | float actualWidth = m_widthForTextAutosizing != -1 ? static_cast<float>(m_widthForTextAutosizing) : static_cast<float>(width()); |
| 3765 | float scale = visibleWidth / actualWidth; |
| 3766 | float minFontSize = roundf(size / scale); |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3767 | |
| 3768 | for (auto* descendant = RenderObjectTraversal::firstChild(*this); descendant; ) { |
| 3769 | if (!isNonBlocksOrNonFixedHeightListItems(*descendant)) { |
| 3770 | descendant = RenderObjectTraversal::nextSkippingChildren(*descendant, this); |
| 3771 | continue; |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3772 | } |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3773 | if (!isVisibleRenderText(*descendant) || !resizeTextPermitted(*descendant)) { |
| 3774 | descendant = RenderObjectTraversal::next(*descendant, this); |
| 3775 | continue; |
| 3776 | } |
| 3777 | |
| 3778 | auto& text = downcast<RenderText>(*descendant); |
| 3779 | auto& oldStyle = text.style(); |
| 3780 | auto& fontDescription = oldStyle.fontDescription(); |
| 3781 | float specifiedSize = fontDescription.specifiedSize(); |
| 3782 | float scaledSize = roundf(specifiedSize * scale); |
| 3783 | if (scaledSize > 0 && scaledSize < minFontSize) { |
| 3784 | // 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. |
| 3785 | // This makes text resizing consistent even if the block's width or line count changes (which can be caused by text resizing itself 5159915). |
| 3786 | if (m_lineCountForTextAutosizing == NOT_SET) |
| 3787 | m_lineCountForTextAutosizing = lineCount; |
| 3788 | if (m_widthForTextAutosizing == -1) |
| 3789 | m_widthForTextAutosizing = actualWidth; |
| 3790 | |
| 3791 | float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(specifiedSize) : textMultiplier(specifiedSize); |
| 3792 | float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier)); |
| 3793 | if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto()) |
antti@apple.com | 4918b4d | 2017-08-14 13:20:47 +0000 | [diff] [blame] | 3794 | document().textAutoSizing().addTextNode(*text.textNode(), candidateNewSize); |
cdumez@apple.com | 83102df | 2016-05-19 19:09:41 +0000 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | descendant = RenderObjectTraversal::nextSkippingChildren(text, this); |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3798 | } |
| 3799 | } |
dbates@webkit.org | 102013c | 2016-09-26 21:51:25 +0000 | [diff] [blame] | 3800 | #endif // ENABLE(TEXT_AUTOSIZING) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3801 | |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 3802 | void RenderBlockFlow::layoutExcludedChildren(bool relayoutChildren) |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3803 | { |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 3804 | RenderBlock::layoutExcludedChildren(relayoutChildren); |
| 3805 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3806 | auto* fragmentedFlow = multiColumnFlow(); |
| 3807 | if (!fragmentedFlow) |
hyatt@apple.com | 8091486 | 2017-03-06 18:00:35 +0000 | [diff] [blame] | 3808 | return; |
| 3809 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3810 | fragmentedFlow->setIsExcludedFromNormalLayout(true); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3811 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3812 | setLogicalTopForChild(*fragmentedFlow, borderAndPaddingBefore()); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3813 | |
| 3814 | if (relayoutChildren) |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3815 | fragmentedFlow->setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3816 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3817 | if (fragmentedFlow->needsLayout()) { |
| 3818 | for (RenderMultiColumnSet* columnSet = fragmentedFlow->firstMultiColumnSet(); columnSet; columnSet = columnSet->nextSiblingMultiColumnSet()) |
| 3819 | columnSet->prepareForLayout(!fragmentedFlow->inBalancingPass()); |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3820 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3821 | fragmentedFlow->invalidateFragments(MarkOnlyThis); |
| 3822 | fragmentedFlow->setNeedsHeightsRecalculation(true); |
| 3823 | fragmentedFlow->layout(); |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3824 | } else { |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3825 | // At the end of multicol layout, relayoutForPagination() is called unconditionally, but if |
| 3826 | // no children are to be laid out (e.g. fixed width with layout already being up-to-date), |
| 3827 | // we want to prevent it from doing any work, so that the column balancing machinery doesn't |
| 3828 | // kick in and trigger additional unnecessary layout passes. Actually, it's not just a good |
| 3829 | // idea in general to not waste time on balancing content that hasn't been re-laid out; we |
| 3830 | // are actually required to guarantee this. The calculation of implicit breaks needs to be |
| 3831 | // preceded by a proper layout pass, since it's layout that sets up content runs, and the |
| 3832 | // runs get deleted right after every pass. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3833 | fragmentedFlow->setNeedsHeightsRecalculation(false); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3834 | } |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3835 | determineLogicalLeftPositionForChild(*fragmentedFlow); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3836 | } |
| 3837 | |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3838 | void RenderBlockFlow::addChild(RenderObject* newChild, RenderObject* beforeChild) |
| 3839 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3840 | if (multiColumnFlow() && (!isFieldset() || !newChild->isLegend())) |
| 3841 | return multiColumnFlow()->addChild(newChild, beforeChild); |
zalan@apple.com | ba6049c | 2017-01-28 16:26:48 +0000 | [diff] [blame] | 3842 | auto* beforeChildOrPlaceholder = beforeChild; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3843 | if (auto* containingFragmentedFlow = enclosingFragmentedFlow()) |
| 3844 | beforeChildOrPlaceholder = containingFragmentedFlow->resolveMovedChild(beforeChild); |
zalan@apple.com | ba6049c | 2017-01-28 16:26:48 +0000 | [diff] [blame] | 3845 | RenderBlock::addChild(newChild, beforeChildOrPlaceholder); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
akling@apple.com | d0fd8ee | 2014-11-21 23:39:16 +0000 | [diff] [blame] | 3848 | void RenderBlockFlow::removeChild(RenderObject& oldChild) |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3849 | { |
simon.fraser@apple.com | b59c690 | 2017-03-17 00:20:45 +0000 | [diff] [blame] | 3850 | if (!renderTreeBeingDestroyed()) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3851 | RenderFragmentedFlow* fragmentedFlow = multiColumnFlow(); |
| 3852 | if (fragmentedFlow && fragmentedFlow != &oldChild) |
| 3853 | fragmentedFlow->fragmentedFlowRelativeWillBeRemoved(oldChild); |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3854 | } |
akling@apple.com | d0fd8ee | 2014-11-21 23:39:16 +0000 | [diff] [blame] | 3855 | RenderBlock::removeChild(oldChild); |
hyatt@apple.com | c1c3903 | 2014-04-15 23:25:58 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 3858 | void RenderBlockFlow::checkForPaginationLogicalHeightChange(bool& relayoutChildren, LayoutUnit& pageLogicalHeight, bool& pageLogicalHeightChanged) |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3859 | { |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 3860 | // If we don't use columns or flow threads, then bail. |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3861 | if (!isRenderFragmentedFlow() && !multiColumnFlow()) |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3862 | return; |
| 3863 | |
| 3864 | // 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] | 3865 | if (RenderMultiColumnFlow* fragmentedFlow = multiColumnFlow()) { |
zalan@apple.com | 53e7907 | 2016-12-12 20:17:50 +0000 | [diff] [blame] | 3866 | LayoutUnit newColumnHeight; |
| 3867 | if (hasDefiniteLogicalHeight() || view().frameView().pagination().mode != Pagination::Unpaginated) { |
zalan@apple.com | cca4b69 | 2016-12-16 04:37:28 +0000 | [diff] [blame] | 3868 | auto computedValues = computeLogicalHeight(LayoutUnit(), logicalTop()); |
zalan@apple.com | 53e7907 | 2016-12-12 20:17:50 +0000 | [diff] [blame] | 3869 | newColumnHeight = std::max<LayoutUnit>(computedValues.m_extent - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight(), 0); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3870 | if (fragmentedFlow->columnHeightAvailable() != newColumnHeight) |
zalan@apple.com | 53e7907 | 2016-12-12 20:17:50 +0000 | [diff] [blame] | 3871 | relayoutChildren = true; |
| 3872 | } |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3873 | fragmentedFlow->setColumnHeightAvailable(newColumnHeight); |
| 3874 | } else if (is<RenderFragmentedFlow>(*this)) { |
| 3875 | RenderFragmentedFlow& fragmentedFlow = downcast<RenderFragmentedFlow>(*this); |
commit-queue@webkit.org | 3d0f60b | 2014-04-08 18:19:47 +0000 | [diff] [blame] | 3876 | |
| 3877 | // FIXME: This is a hack to always make sure we have a page logical height, if said height |
| 3878 | // is known. The page logical height thing in LayoutState is meaningless for flow |
| 3879 | // thread-based pagination (page height isn't necessarily uniform throughout the flow |
| 3880 | // thread), but as long as it is used universally as a means to determine whether page |
| 3881 | // height is known or not, we need this. Page height is unknown when column balancing is |
| 3882 | // enabled and flow thread height is still unknown (i.e. during the first layout pass). When |
| 3883 | // it's unknown, we need to prevent the pagination code from assuming page breaks everywhere |
| 3884 | // 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] | 3885 | // hack once the old multicol implementation is gone (see also RenderView::pushLayoutStateForPagination). |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3886 | pageLogicalHeight = fragmentedFlow.isPageLogicalHeightKnown() ? LayoutUnit(1) : LayoutUnit(0); |
commit-queue@webkit.org | 3d0f60b | 2014-04-08 18:19:47 +0000 | [diff] [blame] | 3887 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3888 | pageLogicalHeightChanged = fragmentedFlow.pageLogicalSizeChanged(); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3889 | } |
| 3890 | } |
| 3891 | |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 3892 | bool RenderBlockFlow::requiresColumns(int desiredColumnCount) const |
zalan@apple.com | 809f487 | 2016-12-08 18:20:01 +0000 | [diff] [blame] | 3893 | { |
| 3894 | return willCreateColumns(desiredColumnCount); |
hyatt@apple.com | 73715ca | 2014-05-06 21:35:52 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3897 | void RenderBlockFlow::setComputedColumnCountAndWidth(int count, LayoutUnit width) |
| 3898 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3899 | ASSERT(!!multiColumnFlow() == requiresColumns(count)); |
| 3900 | if (!multiColumnFlow()) |
antti@apple.com | 411949d | 2017-08-30 17:28:10 +0000 | [diff] [blame] | 3901 | return; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3902 | multiColumnFlow()->setColumnCountAndWidth(count, width); |
| 3903 | multiColumnFlow()->setProgressionIsInline(style().hasInlineColumnAxis()); |
| 3904 | multiColumnFlow()->setProgressionIsReversed(style().columnProgression() == ReverseColumnProgression); |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3905 | } |
| 3906 | |
cdumez@apple.com | 7814173 | 2014-11-04 23:00:48 +0000 | [diff] [blame] | 3907 | void RenderBlockFlow::updateColumnProgressionFromStyle(RenderStyle& style) |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3908 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3909 | if (!multiColumnFlow()) |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3910 | return; |
| 3911 | |
| 3912 | bool needsLayout = false; |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3913 | bool oldProgressionIsInline = multiColumnFlow()->progressionIsInline(); |
cdumez@apple.com | 7814173 | 2014-11-04 23:00:48 +0000 | [diff] [blame] | 3914 | bool newProgressionIsInline = style.hasInlineColumnAxis(); |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3915 | if (oldProgressionIsInline != newProgressionIsInline) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3916 | multiColumnFlow()->setProgressionIsInline(newProgressionIsInline); |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3917 | needsLayout = true; |
| 3918 | } |
| 3919 | |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3920 | bool oldProgressionIsReversed = multiColumnFlow()->progressionIsReversed(); |
cdumez@apple.com | 7814173 | 2014-11-04 23:00:48 +0000 | [diff] [blame] | 3921 | bool newProgressionIsReversed = style.columnProgression() == ReverseColumnProgression; |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3922 | if (oldProgressionIsReversed != newProgressionIsReversed) { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3923 | multiColumnFlow()->setProgressionIsReversed(newProgressionIsReversed); |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3924 | needsLayout = true; |
| 3925 | } |
| 3926 | |
| 3927 | if (needsLayout) |
| 3928 | setNeedsLayoutAndPrefWidthsRecalc(); |
| 3929 | } |
| 3930 | |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3931 | LayoutUnit RenderBlockFlow::computedColumnWidth() const |
| 3932 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3933 | if (multiColumnFlow()) |
| 3934 | return multiColumnFlow()->computedColumnWidth(); |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3935 | return contentLogicalWidth(); |
| 3936 | } |
| 3937 | |
| 3938 | unsigned RenderBlockFlow::computedColumnCount() const |
| 3939 | { |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3940 | if (multiColumnFlow()) |
| 3941 | return multiColumnFlow()->computedColumnCount(); |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3942 | |
| 3943 | return 1; |
| 3944 | } |
| 3945 | |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 3946 | bool RenderBlockFlow::isTopLayoutOverflowAllowed() const |
| 3947 | { |
| 3948 | bool hasTopOverflow = RenderBlock::isTopLayoutOverflowAllowed(); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3949 | if (!multiColumnFlow() || style().columnProgression() == NormalColumnProgression) |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 3950 | return hasTopOverflow; |
| 3951 | |
| 3952 | if (!(isHorizontalWritingMode() ^ !style().hasInlineColumnAxis())) |
| 3953 | hasTopOverflow = !hasTopOverflow; |
| 3954 | |
| 3955 | return hasTopOverflow; |
| 3956 | } |
| 3957 | |
| 3958 | bool RenderBlockFlow::isLeftLayoutOverflowAllowed() const |
| 3959 | { |
| 3960 | bool hasLeftOverflow = RenderBlock::isLeftLayoutOverflowAllowed(); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 3961 | if (!multiColumnFlow() || style().columnProgression() == NormalColumnProgression) |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 3962 | return hasLeftOverflow; |
| 3963 | |
| 3964 | if (isHorizontalWritingMode() ^ !style().hasInlineColumnAxis()) |
| 3965 | hasLeftOverflow = !hasLeftOverflow; |
| 3966 | |
| 3967 | return hasLeftOverflow; |
| 3968 | } |
| 3969 | |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 3970 | struct InlineMinMaxIterator { |
| 3971 | /* InlineMinMaxIterator is a class that will iterate over all render objects that contribute to |
| 3972 | inline min/max width calculations. Note the following about the way it walks: |
| 3973 | (1) Positioned content is skipped (since it does not contribute to min/max width of a block) |
| 3974 | (2) We do not drill into the children of floats or replaced elements, since you can't break |
| 3975 | in the middle of such an element. |
| 3976 | (3) Inline flows (e.g., <a>, <span>, <i>) are walked twice, since each side can have |
| 3977 | distinct borders/margin/padding that contribute to the min/max width. |
| 3978 | */ |
| 3979 | const RenderBlockFlow& parent; |
| 3980 | RenderObject* current; |
| 3981 | bool endOfInline; |
| 3982 | bool initial; |
| 3983 | |
| 3984 | InlineMinMaxIterator(const RenderBlockFlow& p) |
| 3985 | : parent(p) |
| 3986 | , current(nullptr) |
| 3987 | , endOfInline(false) |
| 3988 | , initial(true) |
| 3989 | { } |
| 3990 | |
| 3991 | RenderObject* next(); |
| 3992 | }; |
| 3993 | |
| 3994 | RenderObject* InlineMinMaxIterator::next() |
| 3995 | { |
| 3996 | RenderObject* result = nullptr; |
| 3997 | bool oldEndOfInline = endOfInline; |
| 3998 | endOfInline = false; |
| 3999 | do { |
| 4000 | if (!oldEndOfInline && (current && !current->isFloating() && !current->isReplaced() && !current->isOutOfFlowPositioned())) |
| 4001 | result = current->firstChildSlow(); |
| 4002 | else if (initial) { |
| 4003 | result = parent.firstChild(); |
| 4004 | initial = false; |
| 4005 | } |
| 4006 | |
| 4007 | if (!result) { |
| 4008 | // We hit the end of our inline. (It was empty, e.g., <span></span>.) |
| 4009 | if (!oldEndOfInline && current && current->isRenderInline()) { |
| 4010 | result = current; |
| 4011 | endOfInline = true; |
| 4012 | break; |
| 4013 | } |
| 4014 | |
| 4015 | while (current && current != &parent) { |
| 4016 | result = current->nextSibling(); |
| 4017 | if (result) |
| 4018 | break; |
| 4019 | current = current->parent(); |
| 4020 | if (current && current != &parent && current->isRenderInline()) { |
| 4021 | result = current; |
| 4022 | endOfInline = true; |
| 4023 | break; |
| 4024 | } |
| 4025 | } |
| 4026 | } |
| 4027 | |
| 4028 | if (!result) |
| 4029 | break; |
| 4030 | |
| 4031 | if (!result->isOutOfFlowPositioned() && (result->isTextOrLineBreak() || result->isFloating() || result->isReplaced() || result->isRenderInline())) |
| 4032 | break; |
| 4033 | |
| 4034 | current = result; |
| 4035 | result = nullptr; |
| 4036 | } while (current || current == &parent); |
| 4037 | // Update our position. |
| 4038 | current = result; |
| 4039 | return result; |
| 4040 | } |
| 4041 | |
| 4042 | static LayoutUnit getBPMWidth(LayoutUnit childValue, Length cssUnit) |
| 4043 | { |
| 4044 | if (cssUnit.type() != Auto) |
| 4045 | return (cssUnit.isFixed() ? LayoutUnit(cssUnit.value()) : childValue); |
| 4046 | return 0; |
| 4047 | } |
| 4048 | |
| 4049 | static LayoutUnit getBorderPaddingMargin(const RenderBoxModelObject& child, bool endOfInline) |
| 4050 | { |
| 4051 | const RenderStyle& childStyle = child.style(); |
| 4052 | if (endOfInline) { |
| 4053 | return getBPMWidth(child.marginEnd(), childStyle.marginEnd()) + |
| 4054 | getBPMWidth(child.paddingEnd(), childStyle.paddingEnd()) + |
| 4055 | child.borderEnd(); |
| 4056 | } |
| 4057 | return getBPMWidth(child.marginStart(), childStyle.marginStart()) + |
| 4058 | getBPMWidth(child.paddingStart(), childStyle.paddingStart()) + |
| 4059 | child.borderStart(); |
| 4060 | } |
| 4061 | |
| 4062 | static inline void stripTrailingSpace(float& inlineMax, float& inlineMin, RenderObject* trailingSpaceChild) |
| 4063 | { |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4064 | if (is<RenderText>(trailingSpaceChild)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4065 | // Collapse away the trailing space at the end of a block. |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4066 | RenderText& renderText = downcast<RenderText>(*trailingSpaceChild); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4067 | const UChar space = ' '; |
antti@apple.com | c54cbc9 | 2015-01-15 14:19:56 +0000 | [diff] [blame] | 4068 | const FontCascade& font = renderText.style().fontCascade(); // FIXME: This ignores first-line. |
mmaxfield@apple.com | 21a4dcb | 2016-03-13 00:36:59 +0000 | [diff] [blame] | 4069 | float spaceWidth = font.width(RenderBlock::constructTextRun(&space, 1, renderText.style())); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4070 | inlineMax -= spaceWidth + font.wordSpacing(); |
| 4071 | if (inlineMin > inlineMax) |
| 4072 | inlineMin = inlineMax; |
| 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | static inline LayoutUnit preferredWidth(LayoutUnit preferredWidth, float result) |
| 4077 | { |
| 4078 | return std::max(preferredWidth, LayoutUnit::fromFloatCeil(result)); |
| 4079 | } |
| 4080 | |
| 4081 | void RenderBlockFlow::computeInlinePreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const |
| 4082 | { |
| 4083 | float inlineMax = 0; |
| 4084 | float inlineMin = 0; |
| 4085 | |
| 4086 | const RenderStyle& styleToUse = style(); |
| 4087 | RenderBlock* containingBlock = this->containingBlock(); |
| 4088 | LayoutUnit cw = containingBlock ? containingBlock->contentLogicalWidth() : LayoutUnit(); |
| 4089 | |
| 4090 | // If we are at the start of a line, we want to ignore all white-space. |
| 4091 | // Also strip spaces if we previously had text that ended in a trailing space. |
| 4092 | bool stripFrontSpaces = true; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4093 | RenderObject* trailingSpaceChild = nullptr; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4094 | |
| 4095 | // Firefox and Opera will allow a table cell to grow to fit an image inside it under |
| 4096 | // very specific cirucumstances (in order to match common WinIE renderings). |
| 4097 | // Not supporting the quirk has caused us to mis-render some real sites. (See Bugzilla 10517.) |
| 4098 | bool allowImagesToBreak = !document().inQuirksMode() || !isTableCell() || !styleToUse.logicalWidth().isIntrinsicOrAuto(); |
| 4099 | |
cdumez@apple.com | c28103d5 | 2014-10-31 23:25:05 +0000 | [diff] [blame] | 4100 | bool oldAutoWrap = styleToUse.autoWrap(); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4101 | |
| 4102 | InlineMinMaxIterator childIterator(*this); |
| 4103 | |
| 4104 | // Only gets added to the max preffered width once. |
| 4105 | bool addedTextIndent = false; |
| 4106 | // Signals the text indent was more negative than the min preferred width |
| 4107 | bool hasRemainingNegativeTextIndent = false; |
| 4108 | |
| 4109 | LayoutUnit textIndent = minimumValueForLength(styleToUse.textIndent(), cw); |
| 4110 | RenderObject* prevFloat = 0; |
| 4111 | bool isPrevChildInlineFlow = false; |
| 4112 | bool shouldBreakLineAfterText = false; |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4113 | bool canHangPunctuationAtStart = styleToUse.hangingPunctuation() & FirstHangingPunctuation; |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4114 | bool canHangPunctuationAtEnd = styleToUse.hangingPunctuation() & LastHangingPunctuation; |
| 4115 | RenderText* lastText = nullptr; |
| 4116 | |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4117 | bool addedStartPunctuationHang = false; |
| 4118 | |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4119 | while (RenderObject* child = childIterator.next()) { |
cdumez@apple.com | c28103d5 | 2014-10-31 23:25:05 +0000 | [diff] [blame] | 4120 | bool autoWrap = child->isReplaced() ? child->parent()->style().autoWrap() : |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4121 | child->style().autoWrap(); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4122 | if (!child->isBR()) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4123 | // Step One: determine whether or not we need to terminate our current line. |
| 4124 | // Each discrete chunk can become the new min-width, if it is the widest chunk |
| 4125 | // seen so far, and it can also become the max-width. |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4126 | |
| 4127 | // Children fall into three categories: |
| 4128 | // (1) An inline flow object. These objects always have a min/max of 0, |
| 4129 | // and are included in the iteration solely so that their margins can |
| 4130 | // be added in. |
| 4131 | // |
| 4132 | // (2) An inline non-text non-flow object, e.g., an inline replaced element. |
| 4133 | // 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] | 4134 | // we need to break the current line, and then add in our own margins and min/max |
| 4135 | // width on its own line, and then terminate the line. |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4136 | // |
| 4137 | // (3) A text object. Text runs can have breakable characters at the start, |
| 4138 | // the middle or the end. They may also lose whitespace off the front if |
| 4139 | // we're already ignoring whitespace. In order to compute accurate min-width |
| 4140 | // information, we need three pieces of information. |
| 4141 | // (a) the min-width of the first non-breakable run. Should be 0 if the text string |
| 4142 | // starts with whitespace. |
| 4143 | // (b) the min-width of the last non-breakable run. Should be 0 if the text string |
| 4144 | // ends with whitespace. |
| 4145 | // (c) the min/max width of the string (trimmed for whitespace). |
| 4146 | // |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4147 | // If the text string starts with whitespace, then we need to terminate our current line |
| 4148 | // (unless we're already in a whitespace stripping mode. |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4149 | // |
| 4150 | // If the text string has a breakable character in the middle, but didn't start |
| 4151 | // with whitespace, then we add the width of the first non-breakable run and |
| 4152 | // then end the current line. We then need to use the intermediate min/max width |
| 4153 | // values (if any of them are larger than our current min/max). We then look at |
| 4154 | // the width of the last non-breakable run and use that to start a new line |
| 4155 | // (unless we end in whitespace). |
| 4156 | const RenderStyle& childStyle = child->style(); |
| 4157 | float childMin = 0; |
| 4158 | float childMax = 0; |
| 4159 | |
| 4160 | if (!child->isText()) { |
| 4161 | if (child->isLineBreakOpportunity()) { |
| 4162 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4163 | inlineMin = 0; |
| 4164 | continue; |
| 4165 | } |
| 4166 | // Case (1) and (2). Inline replaced and inline flow elements. |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 4167 | if (is<RenderInline>(*child)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4168 | // Add in padding/border/margin from the appropriate side of |
| 4169 | // the element. |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 4170 | float bpm = getBorderPaddingMargin(downcast<RenderInline>(*child), childIterator.endOfInline); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4171 | childMin += bpm; |
| 4172 | childMax += bpm; |
| 4173 | |
| 4174 | inlineMin += childMin; |
| 4175 | inlineMax += childMax; |
| 4176 | |
| 4177 | child->setPreferredLogicalWidthsDirty(false); |
| 4178 | } else { |
| 4179 | // 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] | 4180 | if (!child->isFloating()) |
| 4181 | lastText = nullptr; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4182 | LayoutUnit margins = 0; |
| 4183 | Length startMargin = childStyle.marginStart(); |
| 4184 | Length endMargin = childStyle.marginEnd(); |
| 4185 | if (startMargin.isFixed()) |
| 4186 | margins += LayoutUnit::fromFloatCeil(startMargin.value()); |
| 4187 | if (endMargin.isFixed()) |
| 4188 | margins += LayoutUnit::fromFloatCeil(endMargin.value()); |
| 4189 | childMin += margins.ceilToFloat(); |
| 4190 | childMax += margins.ceilToFloat(); |
| 4191 | } |
| 4192 | } |
| 4193 | |
cdumez@apple.com | f802215 | 2014-10-15 00:29:51 +0000 | [diff] [blame] | 4194 | if (!is<RenderInline>(*child) && !is<RenderText>(*child)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4195 | // Case (2). Inline replaced elements and floats. |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4196 | // Terminate the current line as far as minwidth is concerned. |
hyatt@apple.com | 247170f | 2017-02-28 16:23:15 +0000 | [diff] [blame] | 4197 | LayoutUnit childMinPreferredLogicalWidth, childMaxPreferredLogicalWidth; |
| 4198 | computeChildPreferredLogicalWidths(*child, childMinPreferredLogicalWidth, childMaxPreferredLogicalWidth); |
| 4199 | childMin += childMinPreferredLogicalWidth.ceilToFloat(); |
| 4200 | childMax += childMaxPreferredLogicalWidth.ceilToFloat(); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4201 | |
| 4202 | bool clearPreviousFloat; |
| 4203 | if (child->isFloating()) { |
| 4204 | clearPreviousFloat = (prevFloat |
| 4205 | && ((prevFloat->style().floating() == LeftFloat && (childStyle.clear() & CLEFT)) |
| 4206 | || (prevFloat->style().floating() == RightFloat && (childStyle.clear() & CRIGHT)))); |
| 4207 | prevFloat = child; |
| 4208 | } else |
| 4209 | clearPreviousFloat = false; |
| 4210 | |
| 4211 | bool canBreakReplacedElement = !child->isImage() || allowImagesToBreak; |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4212 | if (((canBreakReplacedElement && (autoWrap || oldAutoWrap) && (!isPrevChildInlineFlow || shouldBreakLineAfterText)) || clearPreviousFloat)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4213 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4214 | inlineMin = 0; |
| 4215 | } |
| 4216 | |
| 4217 | // 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] | 4218 | if (clearPreviousFloat) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4219 | maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax); |
| 4220 | inlineMax = 0; |
| 4221 | } |
| 4222 | |
| 4223 | // Add in text-indent. This is added in only once. |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4224 | if (!addedTextIndent && !child->isFloating()) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4225 | LayoutUnit ceiledIndent = textIndent.ceilToFloat(); |
| 4226 | childMin += ceiledIndent; |
| 4227 | childMax += ceiledIndent; |
| 4228 | |
| 4229 | if (childMin < 0) |
| 4230 | textIndent = LayoutUnit::fromFloatCeil(childMin); |
| 4231 | else |
| 4232 | addedTextIndent = true; |
| 4233 | } |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4234 | |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4235 | if (canHangPunctuationAtStart && !addedStartPunctuationHang && !child->isFloating()) |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4236 | addedStartPunctuationHang = true; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4237 | |
| 4238 | // Add our width to the max. |
| 4239 | inlineMax += std::max<float>(0, childMax); |
| 4240 | |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4241 | if ((!autoWrap || !canBreakReplacedElement || (isPrevChildInlineFlow && !shouldBreakLineAfterText))) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4242 | if (child->isFloating()) |
| 4243 | minLogicalWidth = preferredWidth(minLogicalWidth, childMin); |
| 4244 | else |
| 4245 | inlineMin += childMin; |
| 4246 | } else { |
| 4247 | // Now check our line. |
| 4248 | minLogicalWidth = preferredWidth(minLogicalWidth, childMin); |
| 4249 | |
| 4250 | // Now start a new line. |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4251 | inlineMin = 0; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | if (autoWrap && canBreakReplacedElement && isPrevChildInlineFlow) { |
| 4255 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4256 | inlineMin = 0; |
| 4257 | } |
| 4258 | |
| 4259 | // We are no longer stripping whitespace at the start of a line. |
| 4260 | if (!child->isFloating()) { |
| 4261 | stripFrontSpaces = false; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4262 | trailingSpaceChild = nullptr; |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4263 | lastText = nullptr; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4264 | } |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4265 | } else if (is<RenderText>(*child)) { |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4266 | // Case (3). Text. |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4267 | RenderText& renderText = downcast<RenderText>(*child); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4268 | |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4269 | if (renderText.style().hasTextCombine() && renderText.isCombineText()) |
zalan@apple.com | 6cad78f | 2017-09-19 20:28:29 +0000 | [diff] [blame] | 4270 | downcast<RenderCombineText>(renderText).combineTextIfNeeded(); |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4271 | |
| 4272 | // Determine if we have a breakable character. Pass in |
| 4273 | // whether or not we should ignore any spaces at the front |
| 4274 | // of the string. If those are going to be stripped out, |
| 4275 | // then they shouldn't be considered in the breakable char |
| 4276 | // check. |
| 4277 | bool hasBreakableChar, hasBreak; |
| 4278 | float beginMin, endMin; |
| 4279 | bool beginWS, endWS; |
| 4280 | float beginMax, endMax; |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4281 | bool strippingBeginWS = stripFrontSpaces; |
cdumez@apple.com | 35094bd | 2014-10-07 19:33:53 +0000 | [diff] [blame] | 4282 | renderText.trimmedPrefWidths(inlineMax, beginMin, beginWS, endMin, endWS, |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4283 | hasBreakableChar, hasBreak, beginMax, endMax, |
| 4284 | childMin, childMax, stripFrontSpaces); |
| 4285 | |
| 4286 | // This text object will not be rendered, but it may still provide a breaking opportunity. |
| 4287 | if (!hasBreak && !childMax) { |
| 4288 | if (autoWrap && (beginWS || endWS)) { |
| 4289 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4290 | inlineMin = 0; |
| 4291 | } |
| 4292 | continue; |
| 4293 | } |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4294 | |
| 4295 | lastText = &renderText; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4296 | |
| 4297 | if (stripFrontSpaces) |
| 4298 | trailingSpaceChild = child; |
| 4299 | else |
| 4300 | trailingSpaceChild = 0; |
| 4301 | |
| 4302 | // Add in text-indent. This is added in only once. |
| 4303 | float ti = 0; |
| 4304 | if (!addedTextIndent || hasRemainingNegativeTextIndent) { |
| 4305 | ti = textIndent.ceilToFloat(); |
| 4306 | childMin += ti; |
| 4307 | beginMin += ti; |
| 4308 | |
| 4309 | // It the text indent negative and larger than the child minimum, we re-use the remainder |
| 4310 | // in future minimum calculations, but using the negative value again on the maximum |
| 4311 | // will lead to under-counting the max pref width. |
| 4312 | if (!addedTextIndent) { |
| 4313 | childMax += ti; |
| 4314 | beginMax += ti; |
| 4315 | addedTextIndent = true; |
| 4316 | } |
| 4317 | |
| 4318 | if (childMin < 0) { |
| 4319 | textIndent = childMin; |
| 4320 | hasRemainingNegativeTextIndent = true; |
| 4321 | } |
| 4322 | } |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4323 | |
| 4324 | // See if we have a hanging punctuation situation at the start. |
| 4325 | if (canHangPunctuationAtStart && !addedStartPunctuationHang) { |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4326 | unsigned startIndex = strippingBeginWS ? renderText.firstCharacterIndexStrippingSpaces() : 0; |
| 4327 | float hangStartWidth = renderText.hangablePunctuationStartWidth(startIndex); |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4328 | childMin -= hangStartWidth; |
| 4329 | beginMin -= hangStartWidth; |
| 4330 | childMax -= hangStartWidth; |
| 4331 | beginMax -= hangStartWidth; |
| 4332 | addedStartPunctuationHang = true; |
| 4333 | } |
| 4334 | |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4335 | // If we have no breakable characters at all, |
| 4336 | // then this is the easy case. We add ourselves to the current |
| 4337 | // min and max and continue. |
| 4338 | if (!hasBreakableChar) |
| 4339 | inlineMin += childMin; |
| 4340 | else { |
| 4341 | // We have a breakable character. Now we need to know if |
| 4342 | // we start and end with whitespace. |
| 4343 | if (beginWS) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4344 | // End the current line. |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4345 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4346 | } else { |
| 4347 | inlineMin += beginMin; |
| 4348 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4349 | childMin -= ti; |
| 4350 | } |
| 4351 | |
| 4352 | inlineMin = childMin; |
| 4353 | |
| 4354 | if (endWS) { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 4355 | // 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] | 4356 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4357 | inlineMin = 0; |
| 4358 | shouldBreakLineAfterText = false; |
| 4359 | } else { |
| 4360 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4361 | inlineMin = endMin; |
| 4362 | shouldBreakLineAfterText = true; |
| 4363 | } |
| 4364 | } |
| 4365 | |
| 4366 | if (hasBreak) { |
| 4367 | inlineMax += beginMax; |
| 4368 | maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax); |
| 4369 | maxLogicalWidth = preferredWidth(maxLogicalWidth, childMax); |
| 4370 | inlineMax = endMax; |
| 4371 | addedTextIndent = true; |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4372 | addedStartPunctuationHang = true; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4373 | } else |
| 4374 | inlineMax += std::max<float>(0, childMax); |
| 4375 | } |
| 4376 | |
antti@apple.com | ae85e11 | 2017-08-31 23:27:02 +0000 | [diff] [blame] | 4377 | // Ignore spaces after a list marker. |
| 4378 | if (child->isListMarker()) |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4379 | stripFrontSpaces = true; |
| 4380 | } else { |
| 4381 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4382 | maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax); |
| 4383 | inlineMin = inlineMax = 0; |
| 4384 | stripFrontSpaces = true; |
| 4385 | trailingSpaceChild = 0; |
| 4386 | addedTextIndent = true; |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 4387 | addedStartPunctuationHang = true; |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | if (!child->isText() && child->isRenderInline()) |
| 4391 | isPrevChildInlineFlow = true; |
| 4392 | else |
| 4393 | isPrevChildInlineFlow = false; |
| 4394 | |
| 4395 | oldAutoWrap = autoWrap; |
| 4396 | } |
| 4397 | |
| 4398 | if (styleToUse.collapseWhiteSpace()) |
| 4399 | stripTrailingSpace(inlineMax, inlineMin, trailingSpaceChild); |
hyatt@apple.com | 6b422a7 | 2016-03-03 21:49:32 +0000 | [diff] [blame] | 4400 | |
| 4401 | if (canHangPunctuationAtEnd && lastText && lastText->textLength() > 0) { |
| 4402 | unsigned endIndex = trailingSpaceChild == lastText ? lastText->lastCharacterIndexStrippingSpaces() : lastText->textLength() - 1; |
| 4403 | float endHangWidth = lastText->hangablePunctuationEndWidth(endIndex); |
| 4404 | inlineMin -= endHangWidth; |
| 4405 | inlineMax -= endHangWidth; |
| 4406 | } |
zalan@apple.com | ac6956c | 2014-09-05 14:18:06 +0000 | [diff] [blame] | 4407 | |
| 4408 | minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin); |
| 4409 | maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax); |
| 4410 | } |
| 4411 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 4412 | } |
| 4413 | // namespace WebCore |