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) |
| 5 | * Copyright (C) 2003-2013 Apple Inc. All rights reserved. |
| 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" |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 30 | #include "HitTestLocation.h" |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 31 | #include "InlineTextBox.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 32 | #include "LayoutRepainter.h" |
| 33 | #include "RenderFlowThread.h" |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 34 | #include "RenderIterator.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 35 | #include "RenderLayer.h" |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 36 | #include "RenderMultiColumnFlowThread.h" |
| 37 | #include "RenderMultiColumnSet.h" |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 38 | #include "RenderNamedFlowFragment.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 39 | #include "RenderText.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 40 | #include "RenderView.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 41 | #include "SimpleLineLayoutFunctions.h" |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 42 | #include "VerticalPositionCache.h" |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 43 | #include "VisiblePosition.h" |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 44 | |
dino@apple.com | c133a8c | 2014-02-03 23:35:34 +0000 | [diff] [blame] | 45 | #if ENABLE(CSS_SHAPES) && ENABLE(CSS_SHAPE_INSIDE) |
zoltan@webkit.org | 7b4eb62 | 2013-12-06 19:31:50 +0000 | [diff] [blame] | 46 | #include "ShapeInsideInfo.h" |
| 47 | #endif |
| 48 | |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 49 | #if ENABLE(IOS_TEXT_AUTOSIZING) |
| 50 | #include "HTMLElement.h" |
| 51 | #endif |
| 52 | |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 53 | namespace WebCore { |
| 54 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 55 | bool RenderBlock::s_canPropagateFloatIntoSibling = false; |
| 56 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 57 | struct SameSizeAsMarginInfo { |
| 58 | uint32_t bitfields : 16; |
| 59 | LayoutUnit margins[2]; |
| 60 | }; |
| 61 | |
| 62 | 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] | 63 | COMPILE_ASSERT(sizeof(RenderBlockFlow::MarginInfo) == sizeof(SameSizeAsMarginInfo), MarginInfo_should_stay_small); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 64 | |
| 65 | // Our MarginInfo state used when laying out block children. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 66 | RenderBlockFlow::MarginInfo::MarginInfo(RenderBlockFlow& block, LayoutUnit beforeBorderPadding, LayoutUnit afterBorderPadding) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 67 | : m_atBeforeSideOfBlock(true) |
| 68 | , m_atAfterSideOfBlock(false) |
| 69 | , m_hasMarginBeforeQuirk(false) |
| 70 | , m_hasMarginAfterQuirk(false) |
| 71 | , m_determinedMarginBeforeQuirk(false) |
| 72 | , m_discardMargin(false) |
| 73 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 74 | const RenderStyle& blockStyle = block.style(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 75 | ASSERT(block.isRenderView() || block.parent()); |
| 76 | m_canCollapseWithChildren = !block.isRenderView() && !block.isRoot() && !block.isOutOfFlowPositioned() |
| 77 | && !block.isFloating() && !block.isTableCell() && !block.hasOverflowClip() && !block.isInlineBlockOrInlineTable() |
| 78 | && !block.isRenderFlowThread() && !block.isWritingModeRoot() && !block.parent()->isFlexibleBox() |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 79 | && blockStyle.hasAutoColumnCount() && blockStyle.hasAutoColumnWidth() && !blockStyle.columnSpan(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 80 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 81 | m_canCollapseMarginBeforeWithChildren = m_canCollapseWithChildren && !beforeBorderPadding && blockStyle.marginBeforeCollapse() != MSEPARATE; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 82 | |
| 83 | // If any height other than auto is specified in CSS, then we don't collapse our bottom |
| 84 | // margins with our children's margins. To do otherwise would be to risk odd visual |
| 85 | // effects when the children overflow out of the parent block and yet still collapse |
| 86 | // with it. We also don't collapse if we have any bottom border/padding. |
| 87 | m_canCollapseMarginAfterWithChildren = m_canCollapseWithChildren && !afterBorderPadding |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 88 | && (blockStyle.logicalHeight().isAuto() && !blockStyle.logicalHeight().value()) && blockStyle.marginAfterCollapse() != MSEPARATE; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 89 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 90 | m_quirkContainer = block.isTableCell() || block.isBody(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 91 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 92 | m_discardMargin = m_canCollapseMarginBeforeWithChildren && block.mustDiscardMarginBefore(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 93 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 94 | m_positiveMargin = (m_canCollapseMarginBeforeWithChildren && !block.mustDiscardMarginBefore()) ? block.maxPositiveMarginBefore() : LayoutUnit(); |
| 95 | m_negativeMargin = (m_canCollapseMarginBeforeWithChildren && !block.mustDiscardMarginBefore()) ? block.maxNegativeMarginBefore() : LayoutUnit(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 96 | } |
| 97 | |
akling@apple.com | 8f40c5b | 2013-10-27 22:54:07 +0000 | [diff] [blame] | 98 | RenderBlockFlow::RenderBlockFlow(Element& element, PassRef<RenderStyle> style) |
| 99 | : RenderBlock(element, std::move(style), RenderBlockFlowFlag) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 100 | #if ENABLE(IOS_TEXT_AUTOSIZING) |
| 101 | , m_widthForTextAutosizing(-1) |
| 102 | , m_lineCountForTextAutosizing(NOT_SET) |
| 103 | #endif |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 104 | { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 105 | setChildrenInline(true); |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 106 | } |
| 107 | |
akling@apple.com | 8f40c5b | 2013-10-27 22:54:07 +0000 | [diff] [blame] | 108 | RenderBlockFlow::RenderBlockFlow(Document& document, PassRef<RenderStyle> style) |
| 109 | : RenderBlock(document, std::move(style), RenderBlockFlowFlag) |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 110 | #if ENABLE(IOS_TEXT_AUTOSIZING) |
| 111 | , m_widthForTextAutosizing(-1) |
| 112 | , m_lineCountForTextAutosizing(NOT_SET) |
| 113 | #endif |
akling@apple.com | 42e1063 | 2013-10-14 17:55:52 +0000 | [diff] [blame] | 114 | { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 115 | setChildrenInline(true); |
hyatt@apple.com | 5388e67 | 2013-09-06 20:54:47 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | RenderBlockFlow::~RenderBlockFlow() |
| 119 | { |
| 120 | } |
| 121 | |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 122 | void RenderBlockFlow::createMultiColumnFlowThread() |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 123 | { |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 124 | RenderMultiColumnFlowThread* flowThread = new RenderMultiColumnFlowThread(document(), RenderStyle::createAnonymousStyleWithDisplay(&style(), BLOCK)); |
| 125 | flowThread->initializeStyle(); |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 126 | moveAllChildrenTo(flowThread, true); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 127 | RenderBlock::addChild(flowThread); |
| 128 | setMultiColumnFlowThread(flowThread); |
| 129 | } |
| 130 | |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 131 | void RenderBlockFlow::destroyMultiColumnFlowThread() |
| 132 | { |
| 133 | // Get the flow thread out of our list. |
| 134 | multiColumnFlowThread()->removeFromParent(); |
| 135 | |
| 136 | // Destroy all the multicolumn sets. |
| 137 | destroyLeftoverChildren(); |
| 138 | |
| 139 | // Move all the children of the flow thread into our block. |
| 140 | multiColumnFlowThread()->moveAllChildrenTo(this, true); |
| 141 | |
| 142 | // Now destroy the flow thread. |
| 143 | multiColumnFlowThread()->destroy(); |
| 144 | |
| 145 | // Clear the multi-column flow thread pointer. |
| 146 | setMultiColumnFlowThread(nullptr); |
| 147 | } |
| 148 | |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 149 | void RenderBlockFlow::insertedIntoTree() |
| 150 | { |
| 151 | RenderBlock::insertedIntoTree(); |
| 152 | createRenderNamedFlowFragmentIfNeeded(); |
| 153 | } |
| 154 | |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 155 | void RenderBlockFlow::willBeDestroyed() |
| 156 | { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 157 | // Mark as being destroyed to avoid trouble with merges in removeChild(). |
| 158 | m_beingDestroyed = true; |
| 159 | |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 160 | if (renderNamedFlowFragment()) |
| 161 | setRenderNamedFlowFragment(0); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 162 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 163 | // Make sure to destroy anonymous children first while they are still connected to the rest of the tree, so that they will |
| 164 | // properly dirty line boxes that they are removed from. Effects that do :before/:after only on hover could crash otherwise. |
| 165 | destroyLeftoverChildren(); |
| 166 | |
| 167 | // Destroy our continuation before anything other than anonymous children. |
| 168 | // The reason we don't destroy it before anonymous children is that they may |
| 169 | // have continuations of their own that are anonymous children of our continuation. |
| 170 | RenderBoxModelObject* continuation = this->continuation(); |
| 171 | if (continuation) { |
| 172 | continuation->destroy(); |
| 173 | setContinuation(0); |
| 174 | } |
| 175 | |
| 176 | if (!documentBeingDestroyed()) { |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 177 | if (firstRootBox()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 178 | // We can't wait for RenderBox::destroy to clear the selection, |
| 179 | // because by then we will have nuked the line boxes. |
| 180 | // FIXME: The FrameSelection should be responsible for this when it |
| 181 | // is notified of DOM mutations. |
| 182 | if (isSelectionBorder()) |
| 183 | view().clearSelection(); |
| 184 | |
| 185 | // If we are an anonymous block, then our line boxes might have children |
| 186 | // that will outlast this block. In the non-anonymous block case those |
| 187 | // children will be destroyed by the time we return from this function. |
| 188 | if (isAnonymousBlock()) { |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 189 | for (auto box = firstRootBox(); box; box = box->nextRootBox()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 190 | while (auto childBox = box->firstChild()) |
| 191 | childBox->removeFromParent(); |
| 192 | } |
| 193 | } |
| 194 | } else if (parent()) |
| 195 | parent()->dirtyLinesFromChangedChild(this); |
| 196 | } |
| 197 | |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 198 | m_lineBoxes.deleteLineBoxes(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 199 | |
| 200 | removeFromDelayedUpdateScrollInfoSet(); |
| 201 | |
| 202 | // NOTE: This jumps down to RenderBox, bypassing RenderBlock since it would do duplicate work. |
| 203 | RenderBox::willBeDestroyed(); |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 204 | } |
| 205 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 206 | void RenderBlockFlow::clearFloats() |
| 207 | { |
| 208 | if (m_floatingObjects) |
| 209 | m_floatingObjects->setHorizontalWritingMode(isHorizontalWritingMode()); |
| 210 | |
| 211 | HashSet<RenderBox*> oldIntrudingFloatSet; |
| 212 | if (!childrenInline() && m_floatingObjects) { |
| 213 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 214 | auto end = floatingObjectSet.end(); |
| 215 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 216 | FloatingObject* floatingObject = it->get(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 217 | if (!floatingObject->isDescendant()) |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 218 | oldIntrudingFloatSet.add(&floatingObject->renderer()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | // Inline blocks are covered by the isReplaced() check in the avoidFloats method. |
| 223 | if (avoidsFloats() || isRoot() || isRenderView() || isFloatingOrOutOfFlowPositioned() || isTableCell()) { |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 224 | if (m_floatingObjects) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 225 | m_floatingObjects->clear(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 226 | if (!oldIntrudingFloatSet.isEmpty()) |
| 227 | markAllDescendantsWithFloatsForLayout(); |
| 228 | return; |
| 229 | } |
| 230 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 231 | RendererToFloatInfoMap floatMap; |
| 232 | |
| 233 | if (m_floatingObjects) { |
bjonesbe@adobe.com | 0434768a | 2013-09-16 22:01:38 +0000 | [diff] [blame] | 234 | if (childrenInline()) |
| 235 | m_floatingObjects->moveAllToFloatInfoMap(floatMap); |
| 236 | else |
| 237 | m_floatingObjects->clear(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | // We should not process floats if the parent node is not a RenderBlock. Otherwise, we will add |
| 241 | // floats in an invalid context. This will cause a crash arising from a bad cast on the parent. |
| 242 | // See <rdar://problem/8049753>, where float property is applied on a text node in a SVG. |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 243 | if (!parent() || !parent()->isRenderBlockFlow()) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 244 | return; |
| 245 | |
| 246 | // Attempt to locate a previous sibling with overhanging floats. We skip any elements that are |
| 247 | // out of flow (like floating/positioned elements), and we also skip over any objects that may have shifted |
| 248 | // to avoid floats. |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 249 | RenderBlockFlow* parentBlock = toRenderBlockFlow(parent()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 250 | bool parentHasFloats = false; |
| 251 | RenderObject* prev = previousSibling(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 252 | while (prev && (prev->isFloatingOrOutOfFlowPositioned() || !prev->isBox() || !prev->isRenderBlockFlow() || toRenderBlockFlow(prev)->avoidsFloats())) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 253 | if (prev->isFloating()) |
| 254 | parentHasFloats = true; |
| 255 | prev = prev->previousSibling(); |
| 256 | } |
| 257 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 258 | // First add in floats from the parent. Self-collapsing blocks let their parent track any floats that intrude into |
| 259 | // them (as opposed to floats they contain themselves) so check for those here too. |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 260 | LayoutUnit logicalTopOffset = logicalTop(); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 261 | if (parentHasFloats || (parentBlock->lowestFloatLogicalBottom() > logicalTopOffset && prev && toRenderBlockFlow(prev)->isSelfCollapsingBlock())) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 262 | addIntrudingFloats(parentBlock, parentBlock->logicalLeftOffsetForContent(), logicalTopOffset); |
| 263 | |
| 264 | LayoutUnit logicalLeftOffset = 0; |
| 265 | if (prev) |
| 266 | logicalTopOffset -= toRenderBox(prev)->logicalTop(); |
| 267 | else { |
| 268 | prev = parentBlock; |
| 269 | logicalLeftOffset += parentBlock->logicalLeftOffsetForContent(); |
| 270 | } |
| 271 | |
| 272 | // Add overhanging floats from the previous RenderBlock, but only if it has a float that intrudes into our space. |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 273 | RenderBlockFlow* block = toRenderBlockFlow(prev); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 274 | if (block->m_floatingObjects && block->lowestFloatLogicalBottom() > logicalTopOffset) |
| 275 | addIntrudingFloats(block, logicalLeftOffset, logicalTopOffset); |
| 276 | |
| 277 | if (childrenInline()) { |
| 278 | LayoutUnit changeLogicalTop = LayoutUnit::max(); |
| 279 | LayoutUnit changeLogicalBottom = LayoutUnit::min(); |
| 280 | if (m_floatingObjects) { |
| 281 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 282 | auto end = floatingObjectSet.end(); |
| 283 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 284 | FloatingObject* floatingObject = it->get(); |
| 285 | std::unique_ptr<FloatingObject> oldFloatingObject = floatMap.take(&floatingObject->renderer()); |
| 286 | LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 287 | if (oldFloatingObject) { |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 288 | LayoutUnit oldLogicalBottom = logicalBottomForFloat(oldFloatingObject.get()); |
| 289 | if (logicalWidthForFloat(floatingObject) != logicalWidthForFloat(oldFloatingObject.get()) || logicalLeftForFloat(floatingObject) != logicalLeftForFloat(oldFloatingObject.get())) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 290 | changeLogicalTop = 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 291 | changeLogicalBottom = std::max(changeLogicalBottom, std::max(logicalBottom, oldLogicalBottom)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 292 | } else { |
| 293 | if (logicalBottom != oldLogicalBottom) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 294 | changeLogicalTop = std::min(changeLogicalTop, std::min(logicalBottom, oldLogicalBottom)); |
| 295 | changeLogicalBottom = std::max(changeLogicalBottom, std::max(logicalBottom, oldLogicalBottom)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 296 | } |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 297 | LayoutUnit logicalTop = logicalTopForFloat(floatingObject); |
| 298 | LayoutUnit oldLogicalTop = logicalTopForFloat(oldFloatingObject.get()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 299 | if (logicalTop != oldLogicalTop) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 300 | changeLogicalTop = std::min(changeLogicalTop, std::min(logicalTop, oldLogicalTop)); |
| 301 | changeLogicalBottom = std::max(changeLogicalBottom, std::max(logicalTop, oldLogicalTop)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 305 | if (oldFloatingObject->originatingLine() && !selfNeedsLayout()) { |
| 306 | ASSERT(&oldFloatingObject->originatingLine()->renderer() == this); |
| 307 | oldFloatingObject->originatingLine()->markDirty(); |
| 308 | } |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 309 | } else { |
| 310 | changeLogicalTop = 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 311 | changeLogicalBottom = std::max(changeLogicalBottom, logicalBottom); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 316 | auto end = floatMap.end(); |
| 317 | for (auto it = floatMap.begin(); it != end; ++it) { |
| 318 | FloatingObject* floatingObject = it->value.get(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 319 | if (!floatingObject->isDescendant()) { |
| 320 | changeLogicalTop = 0; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 321 | changeLogicalBottom = std::max(changeLogicalBottom, logicalBottomForFloat(floatingObject)); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 322 | } |
| 323 | } |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 324 | |
| 325 | markLinesDirtyInBlockRange(changeLogicalTop, changeLogicalBottom); |
| 326 | } else if (!oldIntrudingFloatSet.isEmpty()) { |
| 327 | // If there are previously intruding floats that no longer intrude, then children with floats |
| 328 | // should also get layout because they might need their floating object lists cleared. |
| 329 | if (m_floatingObjects->set().size() < oldIntrudingFloatSet.size()) |
| 330 | markAllDescendantsWithFloatsForLayout(); |
| 331 | else { |
| 332 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 333 | auto end = floatingObjectSet.end(); |
| 334 | for (auto it = floatingObjectSet.begin(); it != end && !oldIntrudingFloatSet.isEmpty(); ++it) |
| 335 | oldIntrudingFloatSet.remove(&(*it)->renderer()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 336 | if (!oldIntrudingFloatSet.isEmpty()) |
| 337 | markAllDescendantsWithFloatsForLayout(); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | void RenderBlockFlow::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight) |
| 343 | { |
| 344 | ASSERT(needsLayout()); |
| 345 | |
| 346 | if (!relayoutChildren && simplifiedLayout()) |
| 347 | return; |
| 348 | |
| 349 | LayoutRepainter repainter(*this, checkForRepaintDuringLayout()); |
| 350 | |
| 351 | if (updateLogicalWidthAndColumnWidth()) |
| 352 | relayoutChildren = true; |
| 353 | |
| 354 | clearFloats(); |
| 355 | |
| 356 | LayoutUnit previousHeight = logicalHeight(); |
| 357 | // FIXME: should this start out as borderAndPaddingLogicalHeight() + scrollbarLogicalHeight(), |
| 358 | // for consistency with other render classes? |
| 359 | setLogicalHeight(0); |
| 360 | |
| 361 | bool pageLogicalHeightChanged = false; |
| 362 | bool hasSpecifiedPageLogicalHeight = false; |
| 363 | checkForPaginationLogicalHeightChange(pageLogicalHeight, pageLogicalHeightChanged, hasSpecifiedPageLogicalHeight); |
| 364 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 365 | const RenderStyle& styleToUse = style(); |
weinig@apple.com | f8d77f3 | 2013-11-18 01:12:17 +0000 | [diff] [blame] | 366 | LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasColumns() || hasTransform() || hasReflection() || styleToUse.isFlippedBlocksWritingMode(), pageLogicalHeight, pageLogicalHeightChanged, columnInfo()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 367 | |
abucur@adobe.com | 0e81bc7 | 2013-10-22 14:50:37 +0000 | [diff] [blame] | 368 | prepareShapesAndPaginationBeforeBlockLayout(relayoutChildren); |
| 369 | if (!relayoutChildren) |
| 370 | relayoutChildren = namedFlowFragmentNeedsUpdate(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 371 | |
| 372 | // We use four values, maxTopPos, maxTopNeg, maxBottomPos, and maxBottomNeg, to track |
| 373 | // our current maximal positive and negative margins. These values are used when we |
| 374 | // are collapsed with adjacent blocks, so for example, if you have block A and B |
| 375 | // collapsing together, then you'd take the maximal positive margin from both A and B |
| 376 | // and subtract it from the maximal negative margin from both A and B to get the |
| 377 | // true collapsed margin. This algorithm is recursive, so when we finish layout() |
| 378 | // our block knows its current maximal positive/negative values. |
| 379 | // |
| 380 | // Start out by setting our margin values to our current margins. Table cells have |
| 381 | // no margins, so we don't fill in the values for table cells. |
| 382 | bool isCell = isTableCell(); |
| 383 | if (!isCell) { |
| 384 | initMaxMarginValues(); |
| 385 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 386 | setHasMarginBeforeQuirk(styleToUse.hasMarginBeforeQuirk()); |
| 387 | setHasMarginAfterQuirk(styleToUse.hasMarginAfterQuirk()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 388 | setPaginationStrut(0); |
| 389 | } |
| 390 | |
| 391 | LayoutUnit repaintLogicalTop = 0; |
| 392 | LayoutUnit repaintLogicalBottom = 0; |
| 393 | LayoutUnit maxFloatLogicalBottom = 0; |
| 394 | if (!firstChild() && !isAnonymousBlock()) |
| 395 | setChildrenInline(true); |
| 396 | if (childrenInline()) |
| 397 | layoutInlineChildren(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
| 398 | else |
| 399 | layoutBlockChildren(relayoutChildren, maxFloatLogicalBottom); |
| 400 | |
| 401 | // Expand our intrinsic height to encompass floats. |
| 402 | LayoutUnit toAdd = borderAndPaddingAfter() + scrollbarLogicalHeight(); |
| 403 | if (lowestFloatLogicalBottom() > (logicalHeight() - toAdd) && expandsToEncloseOverhangingFloats()) |
| 404 | setLogicalHeight(lowestFloatLogicalBottom() + toAdd); |
| 405 | |
| 406 | if (relayoutForPagination(hasSpecifiedPageLogicalHeight, pageLogicalHeight, statePusher) || relayoutToAvoidWidows(statePusher)) { |
| 407 | ASSERT(!shouldBreakAtLineToAvoidWidow()); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | // Calculate our new height. |
| 412 | LayoutUnit oldHeight = logicalHeight(); |
| 413 | LayoutUnit oldClientAfterEdge = clientLogicalBottom(); |
| 414 | |
| 415 | // Before updating the final size of the flow thread make sure a forced break is applied after the content. |
| 416 | // This ensures the size information is correctly computed for the last auto-height region receiving content. |
| 417 | if (isRenderFlowThread()) |
| 418 | toRenderFlowThread(this)->applyBreakAfterContent(oldClientAfterEdge); |
| 419 | |
| 420 | updateLogicalHeight(); |
| 421 | LayoutUnit newHeight = logicalHeight(); |
| 422 | if (oldHeight != newHeight) { |
| 423 | if (oldHeight > newHeight && maxFloatLogicalBottom > newHeight && !childrenInline()) { |
| 424 | // 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] | 425 | for (auto& blockFlow : childrenOfType<RenderBlockFlow>(*this)) { |
| 426 | if (blockFlow.isFloatingOrOutOfFlowPositioned()) |
| 427 | continue; |
| 428 | if (blockFlow.lowestFloatLogicalBottom() + blockFlow.logicalTop() > newHeight) |
| 429 | addOverhangingFloats(blockFlow, false); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | bool heightChanged = (previousHeight != newHeight); |
| 435 | if (heightChanged) |
| 436 | relayoutChildren = true; |
| 437 | |
| 438 | layoutPositionedObjects(relayoutChildren || isRoot()); |
| 439 | |
| 440 | updateShapesAfterBlockLayout(heightChanged); |
| 441 | |
| 442 | // Add overflow from children (unless we're multi-column, since in that case all our child overflow is clipped anyway). |
| 443 | computeOverflow(oldClientAfterEdge); |
| 444 | |
| 445 | statePusher.pop(); |
| 446 | |
| 447 | fitBorderToLinesIfNeeded(); |
| 448 | |
| 449 | if (view().layoutState()->m_pageLogicalHeight) |
| 450 | setPageLogicalOffset(view().layoutState()->pageLogicalOffset(this, logicalTop())); |
| 451 | |
| 452 | updateLayerTransform(); |
| 453 | |
| 454 | // Update our scroll information if we're overflow:auto/scroll/hidden now that we know if |
| 455 | // we overflow or not. |
| 456 | updateScrollInfoAfterLayout(); |
| 457 | |
| 458 | // FIXME: This repaint logic should be moved into a separate helper function! |
| 459 | // Repaint with our new bounds if they are different from our old bounds. |
| 460 | bool didFullRepaint = repainter.repaintAfterLayout(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 461 | if (!didFullRepaint && repaintLogicalTop != repaintLogicalBottom && (styleToUse.visibility() == VISIBLE || enclosingLayer()->hasVisibleContent())) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 462 | // FIXME: We could tighten up the left and right invalidation points if we let layoutInlineChildren fill them in based off the particular lines |
| 463 | // it had to lay out. We wouldn't need the hasOverflowClip() hack in that case either. |
| 464 | LayoutUnit repaintLogicalLeft = logicalLeftVisualOverflow(); |
| 465 | LayoutUnit repaintLogicalRight = logicalRightVisualOverflow(); |
| 466 | if (hasOverflowClip()) { |
| 467 | // 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. |
| 468 | // 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. |
| 469 | // layoutInlineChildren should be patched to compute the entire repaint rect. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 470 | repaintLogicalLeft = std::min(repaintLogicalLeft, logicalLeftLayoutOverflow()); |
| 471 | repaintLogicalRight = std::max(repaintLogicalRight, logicalRightLayoutOverflow()); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | LayoutRect repaintRect; |
| 475 | if (isHorizontalWritingMode()) |
| 476 | repaintRect = LayoutRect(repaintLogicalLeft, repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft, repaintLogicalBottom - repaintLogicalTop); |
| 477 | else |
| 478 | repaintRect = LayoutRect(repaintLogicalTop, repaintLogicalLeft, repaintLogicalBottom - repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft); |
| 479 | |
| 480 | // The repaint rect may be split across columns, in which case adjustRectForColumns() will return the union. |
| 481 | adjustRectForColumns(repaintRect); |
| 482 | |
| 483 | repaintRect.inflate(maximalOutlineSize(PaintPhaseOutline)); |
| 484 | |
| 485 | if (hasOverflowClip()) { |
| 486 | // Adjust repaint rect for scroll offset |
| 487 | repaintRect.move(-scrolledContentOffset()); |
| 488 | |
| 489 | // Don't allow this rect to spill out of our overflow box. |
| 490 | repaintRect.intersect(LayoutRect(LayoutPoint(), size())); |
| 491 | } |
| 492 | |
| 493 | // Make sure the rect is still non-empty after intersecting for overflow above |
| 494 | if (!repaintRect.isEmpty()) { |
| 495 | repaintRectangle(repaintRect); // We need to do a partial repaint of our content. |
| 496 | if (hasReflection()) |
| 497 | repaintRectangle(reflectedRect(repaintRect)); |
| 498 | } |
| 499 | } |
| 500 | |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 501 | clearNeedsLayout(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | void RenderBlockFlow::layoutBlockChildren(bool relayoutChildren, LayoutUnit& maxFloatLogicalBottom) |
| 505 | { |
| 506 | dirtyForLayoutFromPercentageHeightDescendants(); |
| 507 | |
| 508 | LayoutUnit beforeEdge = borderAndPaddingBefore(); |
| 509 | LayoutUnit afterEdge = borderAndPaddingAfter() + scrollbarLogicalHeight(); |
| 510 | |
| 511 | setLogicalHeight(beforeEdge); |
| 512 | |
| 513 | // Lay out our hypothetical grid line as though it occurs at the top of the block. |
| 514 | if (view().layoutState()->lineGrid() == this) |
| 515 | layoutLineGridBox(); |
| 516 | |
| 517 | // The margin struct caches all our current margin collapsing state. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 518 | MarginInfo marginInfo(*this, beforeEdge, afterEdge); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 519 | |
| 520 | // Fieldsets need to find their legend and position it inside the border of the object. |
| 521 | // The legend then gets skipped during normal layout. The same is true for ruby text. |
| 522 | // It doesn't get included in the normal layout process but is instead skipped. |
| 523 | RenderObject* childToExclude = layoutSpecialExcludedChild(relayoutChildren); |
| 524 | |
| 525 | LayoutUnit previousFloatLogicalBottom = 0; |
| 526 | maxFloatLogicalBottom = 0; |
| 527 | |
| 528 | RenderBox* next = firstChildBox(); |
| 529 | |
| 530 | while (next) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 531 | RenderBox& child = *next; |
| 532 | next = child.nextSiblingBox(); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 533 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 534 | if (childToExclude == &child) |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 535 | continue; // Skip this child, since it will be positioned by the specialized subclass (fieldsets and ruby runs). |
| 536 | |
| 537 | updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child); |
| 538 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 539 | if (child.isOutOfFlowPositioned()) { |
| 540 | child.containingBlock()->insertPositionedObject(child); |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 541 | adjustPositionedBlock(child, marginInfo); |
| 542 | continue; |
| 543 | } |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 544 | if (child.isFloating()) { |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 545 | insertFloatingObject(child); |
| 546 | adjustFloatingBlock(marginInfo); |
| 547 | continue; |
| 548 | } |
| 549 | |
| 550 | // Lay out the child. |
| 551 | layoutBlockChild(child, marginInfo, previousFloatLogicalBottom, maxFloatLogicalBottom); |
| 552 | } |
| 553 | |
| 554 | // Now do the handling of the bottom of the block, adding in our bottom border/padding and |
| 555 | // determining the correct collapsed bottom margin information. |
| 556 | handleAfterSideOfBlock(beforeEdge, afterEdge, marginInfo); |
| 557 | } |
| 558 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 559 | void RenderBlockFlow::layoutInlineChildren(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
| 560 | { |
antti@apple.com | 42fb53d | 2013-10-25 02:33:11 +0000 | [diff] [blame] | 561 | if (m_lineLayoutPath == UndeterminedPath) |
| 562 | m_lineLayoutPath = SimpleLineLayout::canUseFor(*this) ? SimpleLinesPath : LineBoxesPath; |
| 563 | |
| 564 | if (m_lineLayoutPath == SimpleLinesPath) { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 565 | deleteLineBoxesBeforeSimpleLineLayout(); |
| 566 | layoutSimpleLines(repaintLogicalTop, repaintLogicalBottom); |
| 567 | return; |
| 568 | } |
| 569 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 570 | m_simpleLineLayout = nullptr; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 571 | layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
| 572 | } |
| 573 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 574 | void RenderBlockFlow::layoutBlockChild(RenderBox& child, MarginInfo& marginInfo, LayoutUnit& previousFloatLogicalBottom, LayoutUnit& maxFloatLogicalBottom) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 575 | { |
| 576 | LayoutUnit oldPosMarginBefore = maxPositiveMarginBefore(); |
| 577 | LayoutUnit oldNegMarginBefore = maxNegativeMarginBefore(); |
| 578 | |
| 579 | // The child is a normal flow object. Compute the margins we will use for collapsing now. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 580 | child.computeAndSetBlockDirectionMargins(this); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 581 | |
| 582 | // Try to guess our correct logical top position. In most cases this guess will |
| 583 | // be correct. Only if we're wrong (when we compute the real logical top position) |
| 584 | // will we have to potentially relayout. |
| 585 | LayoutUnit estimateWithoutPagination; |
| 586 | LayoutUnit logicalTopEstimate = estimateLogicalTopPosition(child, marginInfo, estimateWithoutPagination); |
| 587 | |
| 588 | // 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] | 589 | LayoutRect oldRect = child.frameRect(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 590 | LayoutUnit oldLogicalTop = logicalTopForChild(child); |
| 591 | |
| 592 | #if !ASSERT_DISABLED |
| 593 | LayoutSize oldLayoutDelta = view().layoutDelta(); |
| 594 | #endif |
| 595 | // Go ahead and position the child as though it didn't collapse with the top. |
| 596 | setLogicalTopForChild(child, logicalTopEstimate, ApplyLayoutDelta); |
| 597 | estimateRegionRangeForBoxChild(child); |
| 598 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 599 | RenderBlockFlow* childBlockFlow = child.isRenderBlockFlow() ? toRenderBlockFlow(&child) : nullptr; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 600 | bool markDescendantsWithFloats = false; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 601 | if (logicalTopEstimate != oldLogicalTop && !child.avoidsFloats() && childBlockFlow && childBlockFlow->containsFloats()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 602 | markDescendantsWithFloats = true; |
| 603 | #if ENABLE(SUBPIXEL_LAYOUT) |
| 604 | else if (UNLIKELY(logicalTopEstimate.mightBeSaturated())) |
| 605 | // logicalTopEstimate, returned by estimateLogicalTopPosition, might be saturated for |
| 606 | // very large elements. If it does the comparison with oldLogicalTop might yield a |
| 607 | // false negative as adding and removing margins, borders etc from a saturated number |
| 608 | // might yield incorrect results. If this is the case always mark for layout. |
| 609 | markDescendantsWithFloats = true; |
| 610 | #endif |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 611 | else if (!child.avoidsFloats() || child.shrinkToAvoidFloats()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 612 | // If an element might be affected by the presence of floats, then always mark it for |
| 613 | // layout. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 614 | LayoutUnit fb = std::max(previousFloatLogicalBottom, lowestFloatLogicalBottom()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 615 | if (fb > logicalTopEstimate) |
| 616 | markDescendantsWithFloats = true; |
| 617 | } |
| 618 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 619 | if (childBlockFlow) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 620 | if (markDescendantsWithFloats) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 621 | childBlockFlow->markAllDescendantsWithFloatsForLayout(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 622 | if (!child.isWritingModeRoot()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 623 | previousFloatLogicalBottom = std::max(previousFloatLogicalBottom, oldLogicalTop + childBlockFlow->lowestFloatLogicalBottom()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 624 | } |
| 625 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 626 | if (!child.needsLayout()) |
| 627 | child.markForPaginationRelayoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 628 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 629 | bool childHadLayout = child.everHadLayout(); |
| 630 | bool childNeededLayout = child.needsLayout(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 631 | if (childNeededLayout) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 632 | child.layout(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 633 | |
| 634 | // Cache if we are at the top of the block right now. |
| 635 | bool atBeforeSideOfBlock = marginInfo.atBeforeSideOfBlock(); |
| 636 | |
| 637 | // Now determine the correct ypos based off examination of collapsing margin |
| 638 | // values. |
| 639 | LayoutUnit logicalTopBeforeClear = collapseMargins(child, marginInfo); |
| 640 | |
| 641 | // Now check for clear. |
| 642 | LayoutUnit logicalTopAfterClear = clearFloatsIfNeeded(child, marginInfo, oldPosMarginBefore, oldNegMarginBefore, logicalTopBeforeClear); |
| 643 | |
| 644 | bool paginated = view().layoutState()->isPaginated(); |
| 645 | if (paginated) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 646 | logicalTopAfterClear = adjustBlockChildForPagination(logicalTopAfterClear, estimateWithoutPagination, child, atBeforeSideOfBlock && logicalTopBeforeClear == logicalTopAfterClear); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 647 | |
| 648 | setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta); |
| 649 | |
| 650 | // Now we have a final top position. See if it really does end up being different from our estimate. |
| 651 | // clearFloatsIfNeeded can also mark the child as needing a layout even though we didn't move. This happens |
| 652 | // 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] | 653 | if (logicalTopAfterClear != logicalTopEstimate || child.needsLayout() || (paginated && childBlockFlow && childBlockFlow->shouldBreakAtLineToAvoidWidow())) { |
| 654 | if (child.shrinkToAvoidFloats()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 655 | // The child's width depends on the line width. |
| 656 | // When the child shifts to clear an item, its width can |
| 657 | // change (because it has more available line width). |
| 658 | // So go ahead and mark the item as dirty. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 659 | child.setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 660 | } |
| 661 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 662 | if (childBlockFlow) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 663 | if (!child.avoidsFloats() && childBlockFlow->containsFloats()) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 664 | childBlockFlow->markAllDescendantsWithFloatsForLayout(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 665 | if (!child.needsLayout()) |
| 666 | child.markForPaginationRelayoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | // Our guess was wrong. Make the child lay itself out again. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 670 | child.layoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | if (updateRegionRangeForBoxChild(child)) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 674 | child.setNeedsLayout(MarkOnlyThis); |
| 675 | child.layoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | // We are no longer at the top of the block if we encounter a non-empty child. |
| 679 | // 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] | 680 | if (marginInfo.atBeforeSideOfBlock() && !child.isSelfCollapsingBlock()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 681 | marginInfo.setAtBeforeSideOfBlock(false); |
| 682 | |
| 683 | // Now place the child in the correct left position |
| 684 | determineLogicalLeftPositionForChild(child, ApplyLayoutDelta); |
| 685 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 686 | LayoutSize childOffset = child.location() - oldRect.location(); |
dino@apple.com | c133a8c | 2014-02-03 23:35:34 +0000 | [diff] [blame] | 687 | #if ENABLE(CSS_SHAPES) && ENABLE(CSS_SHAPE_INSIDE) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 688 | relayoutShapeDescendantIfMoved(child.isRenderBlock() ? toRenderBlock(&child) : nullptr, childOffset); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 689 | #endif |
| 690 | |
| 691 | // Update our height now that the child has been placed in the correct position. |
| 692 | setLogicalHeight(logicalHeight() + logicalHeightForChild(child)); |
| 693 | if (mustSeparateMarginAfterForChild(child)) { |
| 694 | setLogicalHeight(logicalHeight() + marginAfterForChild(child)); |
| 695 | marginInfo.clearMargin(); |
| 696 | } |
| 697 | // If the child has overhanging floats that intrude into following siblings (or possibly out |
| 698 | // 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] | 699 | if (childBlockFlow && childBlockFlow->containsFloats()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 700 | maxFloatLogicalBottom = std::max(maxFloatLogicalBottom, addOverhangingFloats(*childBlockFlow, !childNeededLayout)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 701 | |
| 702 | if (childOffset.width() || childOffset.height()) { |
| 703 | view().addLayoutDelta(childOffset); |
| 704 | |
| 705 | // If the child moved, we have to repaint it as well as any floating/positioned |
| 706 | // descendants. An exception is if we need a layout. In this case, we know we're going to |
| 707 | // repaint ourselves (and the child) anyway. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 708 | if (childHadLayout && !selfNeedsLayout() && child.checkForRepaintDuringLayout()) |
| 709 | child.repaintDuringLayoutIfMoved(oldRect); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 710 | } |
| 711 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 712 | if (!childHadLayout && child.checkForRepaintDuringLayout()) { |
| 713 | child.repaint(); |
| 714 | child.repaintOverhangingFloats(true); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | if (paginated) { |
| 718 | // Check for an after page/column break. |
| 719 | LayoutUnit newHeight = applyAfterBreak(child, logicalHeight(), marginInfo); |
| 720 | if (newHeight != height()) |
| 721 | setLogicalHeight(newHeight); |
| 722 | } |
| 723 | |
| 724 | ASSERT(view().layoutDeltaMatches(oldLayoutDelta)); |
| 725 | } |
| 726 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 727 | void RenderBlockFlow::adjustPositionedBlock(RenderBox& child, const MarginInfo& marginInfo) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 728 | { |
| 729 | bool isHorizontal = isHorizontalWritingMode(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 730 | bool hasStaticBlockPosition = child.style().hasStaticBlockPosition(isHorizontal); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 731 | |
| 732 | LayoutUnit logicalTop = logicalHeight(); |
| 733 | updateStaticInlinePositionForChild(child, logicalTop); |
| 734 | |
| 735 | if (!marginInfo.canCollapseWithMarginBefore()) { |
| 736 | // Positioned blocks don't collapse margins, so add the margin provided by |
| 737 | // the container now. The child's own margin is added later when calculating its logical top. |
| 738 | LayoutUnit collapsedBeforePos = marginInfo.positiveMargin(); |
| 739 | LayoutUnit collapsedBeforeNeg = marginInfo.negativeMargin(); |
| 740 | logicalTop += collapsedBeforePos - collapsedBeforeNeg; |
| 741 | } |
| 742 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 743 | RenderLayer* childLayer = child.layer(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 744 | if (childLayer->staticBlockPosition() != logicalTop) { |
| 745 | childLayer->setStaticBlockPosition(logicalTop); |
| 746 | if (hasStaticBlockPosition) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 747 | child.setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 751 | LayoutUnit RenderBlockFlow::marginOffsetForSelfCollapsingBlock() |
| 752 | { |
| 753 | ASSERT(isSelfCollapsingBlock()); |
| 754 | RenderBlockFlow* parentBlock = toRenderBlockFlow(parent()); |
| 755 | if (parentBlock && style().clear() && parentBlock->getClearDelta(*this, logicalHeight())) |
| 756 | return marginValuesForChild(*this).positiveMarginBefore(); |
| 757 | return LayoutUnit(); |
| 758 | } |
| 759 | |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 760 | void RenderBlockFlow::determineLogicalLeftPositionForChild(RenderBox& child, ApplyLayoutDeltaMode applyDelta) |
| 761 | { |
| 762 | LayoutUnit startPosition = borderStart() + paddingStart(); |
| 763 | if (style().shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) |
| 764 | startPosition -= verticalScrollbarWidth(); |
| 765 | LayoutUnit totalAvailableLogicalWidth = borderAndPaddingLogicalWidth() + availableLogicalWidth(); |
| 766 | |
| 767 | // Add in our start margin. |
| 768 | LayoutUnit childMarginStart = marginStartForChild(child); |
| 769 | LayoutUnit newPosition = startPosition + childMarginStart; |
| 770 | |
| 771 | // Some objects (e.g., tables, horizontal rules, overflow:auto blocks) avoid floats. They need |
| 772 | // to shift over as necessary to dodge any floats that might get in the way. |
| 773 | if (child.avoidsFloats() && containsFloats() && !flowThreadContainingBlock()) |
| 774 | newPosition += computeStartPositionDeltaForChildAvoidingFloats(child, marginStartForChild(child)); |
| 775 | |
| 776 | setLogicalLeftForChild(child, style().isLeftToRightDirection() ? newPosition : totalAvailableLogicalWidth - newPosition - logicalWidthForChild(child), applyDelta); |
| 777 | } |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 778 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 779 | void RenderBlockFlow::adjustFloatingBlock(const MarginInfo& marginInfo) |
| 780 | { |
| 781 | // The float should be positioned taking into account the bottom margin |
| 782 | // of the previous flow. We add that margin into the height, get the |
| 783 | // float positioned properly, and then subtract the margin out of the |
| 784 | // height again. In the case of self-collapsing blocks, we always just |
| 785 | // use the top margins, since the self-collapsing block collapsed its |
| 786 | // own bottom margin into its top margin. |
| 787 | // |
| 788 | // Note also that the previous flow may collapse its margin into the top of |
| 789 | // our block. If this is the case, then we do not add the margin in to our |
| 790 | // height when computing the position of the float. This condition can be tested |
| 791 | // for by simply calling canCollapseWithMarginBefore. See |
| 792 | // http://www.hixie.ch/tests/adhoc/css/box/block/margin-collapse/046.html for |
| 793 | // an example of this scenario. |
| 794 | LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? LayoutUnit() : marginInfo.margin(); |
| 795 | setLogicalHeight(logicalHeight() + marginOffset); |
| 796 | positionNewFloats(); |
| 797 | setLogicalHeight(logicalHeight() - marginOffset); |
| 798 | } |
| 799 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 800 | void RenderBlockFlow::updateStaticInlinePositionForChild(RenderBox& child, LayoutUnit logicalTop) |
| 801 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 802 | if (child.style().isOriginalDisplayInlineType()) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 803 | setStaticInlinePositionForChild(child, logicalTop, startAlignedOffsetForLine(logicalTop, false)); |
| 804 | else |
| 805 | setStaticInlinePositionForChild(child, logicalTop, startOffsetForContent(logicalTop)); |
| 806 | } |
| 807 | |
| 808 | void RenderBlockFlow::setStaticInlinePositionForChild(RenderBox& child, LayoutUnit blockOffset, LayoutUnit inlinePosition) |
| 809 | { |
| 810 | if (flowThreadContainingBlock()) { |
| 811 | // Shift the inline position to exclude the region offset. |
| 812 | inlinePosition += startOffsetForContent() - startOffsetForContent(blockOffset); |
| 813 | } |
| 814 | child.layer()->setStaticInlinePosition(inlinePosition); |
| 815 | } |
| 816 | |
| 817 | RenderBlockFlow::MarginValues RenderBlockFlow::marginValuesForChild(RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 818 | { |
| 819 | LayoutUnit childBeforePositive = 0; |
| 820 | LayoutUnit childBeforeNegative = 0; |
| 821 | LayoutUnit childAfterPositive = 0; |
| 822 | LayoutUnit childAfterNegative = 0; |
| 823 | |
| 824 | LayoutUnit beforeMargin = 0; |
| 825 | LayoutUnit afterMargin = 0; |
| 826 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 827 | RenderBlockFlow* childRenderBlock = child.isRenderBlockFlow() ? toRenderBlockFlow(&child) : nullptr; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 828 | |
| 829 | // If the child has the same directionality as we do, then we can just return its |
| 830 | // margins in the same direction. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 831 | if (!child.isWritingModeRoot()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 832 | if (childRenderBlock) { |
| 833 | childBeforePositive = childRenderBlock->maxPositiveMarginBefore(); |
| 834 | childBeforeNegative = childRenderBlock->maxNegativeMarginBefore(); |
| 835 | childAfterPositive = childRenderBlock->maxPositiveMarginAfter(); |
| 836 | childAfterNegative = childRenderBlock->maxNegativeMarginAfter(); |
| 837 | } else { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 838 | beforeMargin = child.marginBefore(); |
| 839 | afterMargin = child.marginAfter(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 840 | } |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 841 | } else if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 842 | // The child has a different directionality. If the child is parallel, then it's just |
| 843 | // flipped relative to us. We can use the margins for the opposite edges. |
| 844 | if (childRenderBlock) { |
| 845 | childBeforePositive = childRenderBlock->maxPositiveMarginAfter(); |
| 846 | childBeforeNegative = childRenderBlock->maxNegativeMarginAfter(); |
| 847 | childAfterPositive = childRenderBlock->maxPositiveMarginBefore(); |
| 848 | childAfterNegative = childRenderBlock->maxNegativeMarginBefore(); |
| 849 | } else { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 850 | beforeMargin = child.marginAfter(); |
| 851 | afterMargin = child.marginBefore(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 852 | } |
| 853 | } else { |
| 854 | // The child is perpendicular to us, which means its margins don't collapse but are on the |
| 855 | // "logical left/right" sides of the child box. We can just return the raw margin in this case. |
| 856 | beforeMargin = marginBeforeForChild(child); |
| 857 | afterMargin = marginAfterForChild(child); |
| 858 | } |
| 859 | |
| 860 | // Resolve uncollapsing margins into their positive/negative buckets. |
| 861 | if (beforeMargin) { |
| 862 | if (beforeMargin > 0) |
| 863 | childBeforePositive = beforeMargin; |
| 864 | else |
| 865 | childBeforeNegative = -beforeMargin; |
| 866 | } |
| 867 | if (afterMargin) { |
| 868 | if (afterMargin > 0) |
| 869 | childAfterPositive = afterMargin; |
| 870 | else |
| 871 | childAfterNegative = -afterMargin; |
| 872 | } |
| 873 | |
| 874 | return MarginValues(childBeforePositive, childBeforeNegative, childAfterPositive, childAfterNegative); |
| 875 | } |
| 876 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 877 | LayoutUnit RenderBlockFlow::collapseMargins(RenderBox& child, MarginInfo& marginInfo) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 878 | { |
| 879 | bool childDiscardMarginBefore = mustDiscardMarginBeforeForChild(child); |
| 880 | bool childDiscardMarginAfter = mustDiscardMarginAfterForChild(child); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 881 | bool childIsSelfCollapsing = child.isSelfCollapsingBlock(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 882 | |
| 883 | // The child discards the before margin when the the after margin has discard in the case of a self collapsing block. |
| 884 | childDiscardMarginBefore = childDiscardMarginBefore || (childDiscardMarginAfter && childIsSelfCollapsing); |
| 885 | |
| 886 | // Get the four margin values for the child and cache them. |
| 887 | const MarginValues childMargins = marginValuesForChild(child); |
| 888 | |
| 889 | // Get our max pos and neg top margins. |
| 890 | LayoutUnit posTop = childMargins.positiveMarginBefore(); |
| 891 | LayoutUnit negTop = childMargins.negativeMarginBefore(); |
| 892 | |
| 893 | // For self-collapsing blocks, collapse our bottom margins into our |
| 894 | // top to get new posTop and negTop values. |
| 895 | if (childIsSelfCollapsing) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 896 | posTop = std::max(posTop, childMargins.positiveMarginAfter()); |
| 897 | negTop = std::max(negTop, childMargins.negativeMarginAfter()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | // See if the top margin is quirky. We only care if this child has |
| 901 | // margins that will collapse with us. |
| 902 | bool topQuirk = hasMarginBeforeQuirk(child); |
| 903 | |
| 904 | if (marginInfo.canCollapseWithMarginBefore()) { |
| 905 | if (!childDiscardMarginBefore && !marginInfo.discardMargin()) { |
| 906 | // This child is collapsing with the top of the |
| 907 | // block. If it has larger margin values, then we need to update |
| 908 | // our own maximal values. |
| 909 | if (!document().inQuirksMode() || !marginInfo.quirkContainer() || !topQuirk) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 910 | setMaxMarginBeforeValues(std::max(posTop, maxPositiveMarginBefore()), std::max(negTop, maxNegativeMarginBefore())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 911 | |
| 912 | // The minute any of the margins involved isn't a quirk, don't |
| 913 | // collapse it away, even if the margin is smaller (www.webreference.com |
| 914 | // has an example of this, a <dt> with 0.8em author-specified inside |
| 915 | // a <dl> inside a <td>. |
| 916 | if (!marginInfo.determinedMarginBeforeQuirk() && !topQuirk && (posTop - negTop)) { |
| 917 | setHasMarginBeforeQuirk(false); |
| 918 | marginInfo.setDeterminedMarginBeforeQuirk(true); |
| 919 | } |
| 920 | |
| 921 | if (!marginInfo.determinedMarginBeforeQuirk() && topQuirk && !marginBefore()) |
| 922 | // We have no top margin and our top child has a quirky margin. |
| 923 | // We will pick up this quirky margin and pass it through. |
| 924 | // This deals with the <td><div><p> case. |
| 925 | // Don't do this for a block that split two inlines though. You do |
| 926 | // still apply margins in this case. |
| 927 | setHasMarginBeforeQuirk(true); |
| 928 | } else |
| 929 | // The before margin of the container will also discard all the margins it is collapsing with. |
| 930 | setMustDiscardMarginBefore(); |
| 931 | } |
| 932 | |
| 933 | // Once we find a child with discardMarginBefore all the margins collapsing with us must also discard. |
| 934 | if (childDiscardMarginBefore) { |
| 935 | marginInfo.setDiscardMargin(true); |
| 936 | marginInfo.clearMargin(); |
| 937 | } |
| 938 | |
| 939 | if (marginInfo.quirkContainer() && marginInfo.atBeforeSideOfBlock() && (posTop - negTop)) |
| 940 | marginInfo.setHasMarginBeforeQuirk(topQuirk); |
| 941 | |
| 942 | LayoutUnit beforeCollapseLogicalTop = logicalHeight(); |
| 943 | LayoutUnit logicalTop = beforeCollapseLogicalTop; |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 944 | |
| 945 | LayoutUnit clearanceForSelfCollapsingBlock; |
| 946 | RenderObject* prev = child.previousSibling(); |
| 947 | // 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 |
| 948 | // 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 |
| 949 | // 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. |
| 950 | if (!marginInfo.canCollapseWithMarginBefore() && prev && prev->isRenderBlockFlow() && toRenderBlockFlow(prev)->isSelfCollapsingBlock()) { |
| 951 | clearanceForSelfCollapsingBlock = toRenderBlockFlow(prev)->marginOffsetForSelfCollapsingBlock(); |
| 952 | setLogicalHeight(logicalHeight() - clearanceForSelfCollapsingBlock); |
| 953 | } |
| 954 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 955 | if (childIsSelfCollapsing) { |
| 956 | // 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. |
| 957 | // Also, the child's top position equals the logical height of the container. |
| 958 | if (!childDiscardMarginBefore && !marginInfo.discardMargin()) { |
| 959 | // This child has no height. We need to compute our |
| 960 | // position before we collapse the child's margins together, |
| 961 | // 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] | 962 | LayoutUnit collapsedBeforePos = std::max(marginInfo.positiveMargin(), childMargins.positiveMarginBefore()); |
| 963 | LayoutUnit collapsedBeforeNeg = std::max(marginInfo.negativeMargin(), childMargins.negativeMarginBefore()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 964 | marginInfo.setMargin(collapsedBeforePos, collapsedBeforeNeg); |
| 965 | |
| 966 | // Now collapse the child's margins together, which means examining our |
| 967 | // bottom margin values as well. |
| 968 | marginInfo.setPositiveMarginIfLarger(childMargins.positiveMarginAfter()); |
| 969 | marginInfo.setNegativeMarginIfLarger(childMargins.negativeMarginAfter()); |
| 970 | |
| 971 | if (!marginInfo.canCollapseWithMarginBefore()) |
| 972 | // We need to make sure that the position of the self-collapsing block |
| 973 | // is correct, since it could have overflowing content |
| 974 | // that needs to be positioned correctly (e.g., a block that |
| 975 | // had a specified height of 0 but that actually had subcontent). |
| 976 | logicalTop = logicalHeight() + collapsedBeforePos - collapsedBeforeNeg; |
| 977 | } |
| 978 | } else { |
| 979 | if (mustSeparateMarginBeforeForChild(child)) { |
| 980 | ASSERT(!marginInfo.discardMargin() || (marginInfo.discardMargin() && !marginInfo.margin())); |
| 981 | // If we are at the before side of the block and we collapse, ignore the computed margin |
| 982 | // and just add the child margin to the container height. This will correctly position |
| 983 | // the child inside the container. |
zalan@apple.com | a4d0055 | 2014-01-25 00:21:59 +0000 | [diff] [blame] | 984 | LayoutUnit separateMargin = !marginInfo.canCollapseWithMarginBefore() ? marginInfo.margin() : LayoutUnit::fromPixel(0); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 985 | setLogicalHeight(logicalHeight() + separateMargin + marginBeforeForChild(child)); |
| 986 | logicalTop = logicalHeight(); |
| 987 | } else if (!marginInfo.discardMargin() && (!marginInfo.atBeforeSideOfBlock() |
| 988 | || (!marginInfo.canCollapseMarginBeforeWithChildren() |
| 989 | && (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginBeforeQuirk())))) { |
| 990 | // We're collapsing with a previous sibling's margins and not |
| 991 | // with the top of the block. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 992 | 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] | 993 | logicalTop = logicalHeight(); |
| 994 | } |
| 995 | |
| 996 | marginInfo.setDiscardMargin(childDiscardMarginAfter); |
| 997 | |
| 998 | if (!marginInfo.discardMargin()) { |
| 999 | marginInfo.setPositiveMargin(childMargins.positiveMarginAfter()); |
| 1000 | marginInfo.setNegativeMargin(childMargins.negativeMarginAfter()); |
| 1001 | } else |
| 1002 | marginInfo.clearMargin(); |
| 1003 | |
| 1004 | if (marginInfo.margin()) |
| 1005 | marginInfo.setHasMarginAfterQuirk(hasMarginAfterQuirk(child)); |
| 1006 | } |
| 1007 | |
| 1008 | // If margins would pull us past the top of the next page, then we need to pull back and pretend like the margins |
| 1009 | // collapsed into the page edge. |
| 1010 | LayoutState* layoutState = view().layoutState(); |
| 1011 | if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTop > beforeCollapseLogicalTop |
| 1012 | && hasNextPage(beforeCollapseLogicalTop)) { |
| 1013 | LayoutUnit oldLogicalTop = logicalTop; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1014 | logicalTop = std::min(logicalTop, nextPageLogicalTop(beforeCollapseLogicalTop)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1015 | setLogicalHeight(logicalHeight() + (logicalTop - oldLogicalTop)); |
| 1016 | } |
| 1017 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1018 | if (prev && prev->isRenderBlockFlow() && !prev->isFloatingOrOutOfFlowPositioned()) { |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1019 | // 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 |
| 1020 | // any floats from the parent will now overhang. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1021 | RenderBlockFlow& block = toRenderBlockFlow(*prev); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1022 | LayoutUnit oldLogicalHeight = logicalHeight(); |
| 1023 | setLogicalHeight(logicalTop); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1024 | if (block.containsFloats() && !block.avoidsFloats() && (block.logicalTop() + block.lowestFloatLogicalBottom()) > logicalTop) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1025 | addOverhangingFloats(block, false); |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1026 | setLogicalHeight(oldLogicalHeight); |
| 1027 | |
| 1028 | // If |child|'s previous sibling is a self-collapsing block that cleared a float and margin collapsing resulted in |child| moving up |
| 1029 | // 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 |
| 1030 | // floats in the parent that overhang |child|'s new logical top. |
| 1031 | bool logicalTopIntrudesIntoFloat = clearanceForSelfCollapsingBlock > 0 && logicalTop < beforeCollapseLogicalTop; |
| 1032 | if (logicalTopIntrudesIntoFloat && containsFloats() && !child.avoidsFloats() && lowestFloatLogicalBottom() > logicalTop) |
| 1033 | child.setNeedsLayout(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1034 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1035 | |
| 1036 | return logicalTop; |
| 1037 | } |
| 1038 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1039 | 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] | 1040 | { |
| 1041 | LayoutUnit heightIncrease = getClearDelta(child, yPos); |
| 1042 | if (!heightIncrease) |
| 1043 | return yPos; |
| 1044 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1045 | if (child.isSelfCollapsingBlock()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1046 | bool childDiscardMargin = mustDiscardMarginBeforeForChild(child) || mustDiscardMarginAfterForChild(child); |
| 1047 | |
| 1048 | // For self-collapsing blocks that clear, they can still collapse their |
| 1049 | // margins with following siblings. Reset the current margins to represent |
| 1050 | // the self-collapsing block's margins only. |
| 1051 | // 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] | 1052 | MarginValues childMargins = marginValuesForChild(child); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1053 | if (!childDiscardMargin) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1054 | marginInfo.setPositiveMargin(std::max(childMargins.positiveMarginBefore(), childMargins.positiveMarginAfter())); |
| 1055 | marginInfo.setNegativeMargin(std::max(childMargins.negativeMarginBefore(), childMargins.negativeMarginAfter())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1056 | } else |
| 1057 | marginInfo.clearMargin(); |
| 1058 | marginInfo.setDiscardMargin(childDiscardMargin); |
| 1059 | |
| 1060 | // CSS2.1 states: |
| 1061 | // "If the top and bottom margins of an element with clearance are adjoining, its margins collapse with |
| 1062 | // the adjoining margins of following siblings but that resulting margin does not collapse with the bottom margin of the parent block." |
| 1063 | // So the parent's bottom margin cannot collapse through this block or any subsequent self-collapsing blocks. Check subsequent siblings |
| 1064 | // for a block with height - if none is found then don't allow the margins to collapse with the parent. |
| 1065 | bool wouldCollapseMarginsWithParent = marginInfo.canCollapseMarginAfterWithChildren(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1066 | for (RenderBox* curr = child.nextSiblingBox(); curr && wouldCollapseMarginsWithParent; curr = curr->nextSiblingBox()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1067 | if (!curr->isFloatingOrOutOfFlowPositioned() && !curr->isSelfCollapsingBlock()) |
| 1068 | wouldCollapseMarginsWithParent = false; |
| 1069 | } |
| 1070 | if (wouldCollapseMarginsWithParent) |
| 1071 | marginInfo.setCanCollapseMarginAfterWithChildren(false); |
| 1072 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1073 | // 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 |
| 1074 | // its own at the correct vertical position. If subsequent siblings attempt to collapse with |child|'s margins in |collapseMargins| we will |
| 1075 | // 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 |
| 1076 | // margins can collapse at the correct vertical position. |
| 1077 | // 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 |
| 1078 | // (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], |
| 1079 | // i.e., clearance = [height of float] - margin-top". |
| 1080 | setLogicalHeight(child.logicalTop() + childMargins.negativeMarginBefore()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1081 | } else |
| 1082 | // Increase our height by the amount we had to clear. |
| 1083 | setLogicalHeight(logicalHeight() + heightIncrease); |
| 1084 | |
| 1085 | if (marginInfo.canCollapseWithMarginBefore()) { |
| 1086 | // We can no longer collapse with the top of the block since a clear |
| 1087 | // occurred. The empty blocks collapse into the cleared block. |
| 1088 | // FIXME: This isn't quite correct. Need clarification for what to do |
| 1089 | // if the height the cleared block is offset by is smaller than the |
| 1090 | // margins involved. |
| 1091 | setMaxMarginBeforeValues(oldTopPosMargin, oldTopNegMargin); |
| 1092 | marginInfo.setAtBeforeSideOfBlock(false); |
| 1093 | |
| 1094 | // 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] | 1095 | setMustDiscardMarginBefore(style().marginBeforeCollapse() == MDISCARD); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1098 | return yPos + heightIncrease; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1101 | 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] | 1102 | { |
| 1103 | // Give up if in quirks mode and we're a body/table cell and the top margin of the child box is quirky. |
| 1104 | // Give up if the child specified -webkit-margin-collapse: separate that prevents collapsing. |
| 1105 | // FIXME: Use writing mode independent accessor for marginBeforeCollapse. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1106 | if ((document().inQuirksMode() && hasMarginAfterQuirk(child) && (isTableCell() || isBody())) || child.style().marginBeforeCollapse() == MSEPARATE) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1107 | return; |
| 1108 | |
| 1109 | // The margins are discarded by a child that specified -webkit-margin-collapse: discard. |
| 1110 | // FIXME: Use writing mode independent accessor for marginBeforeCollapse. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1111 | if (child.style().marginBeforeCollapse() == MDISCARD) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1112 | positiveMarginBefore = 0; |
| 1113 | negativeMarginBefore = 0; |
| 1114 | discardMarginBefore = true; |
| 1115 | return; |
| 1116 | } |
| 1117 | |
| 1118 | LayoutUnit beforeChildMargin = marginBeforeForChild(child); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1119 | positiveMarginBefore = std::max(positiveMarginBefore, beforeChildMargin); |
| 1120 | negativeMarginBefore = std::max(negativeMarginBefore, -beforeChildMargin); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1121 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1122 | if (!child.isRenderBlockFlow()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1123 | return; |
| 1124 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1125 | RenderBlockFlow& childBlock = toRenderBlockFlow(child); |
| 1126 | if (childBlock.childrenInline() || childBlock.isWritingModeRoot()) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1127 | return; |
| 1128 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1129 | MarginInfo childMarginInfo(childBlock, childBlock.borderAndPaddingBefore(), childBlock.borderAndPaddingAfter()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1130 | if (!childMarginInfo.canCollapseMarginBeforeWithChildren()) |
| 1131 | return; |
| 1132 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1133 | RenderBox* grandchildBox = childBlock.firstChildBox(); |
| 1134 | for (; grandchildBox; grandchildBox = grandchildBox->nextSiblingBox()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1135 | if (!grandchildBox->isFloatingOrOutOfFlowPositioned()) |
| 1136 | break; |
| 1137 | } |
| 1138 | |
| 1139 | // 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] | 1140 | if (!grandchildBox || grandchildBox->style().clear() != CNONE) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1141 | return; |
| 1142 | |
| 1143 | // Make sure to update the block margins now for the grandchild box so that we're looking at current values. |
| 1144 | if (grandchildBox->needsLayout()) { |
| 1145 | grandchildBox->computeAndSetBlockDirectionMargins(this); |
| 1146 | if (grandchildBox->isRenderBlock()) { |
| 1147 | RenderBlock* grandchildBlock = toRenderBlock(grandchildBox); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1148 | grandchildBlock->setHasMarginBeforeQuirk(grandchildBox->style().hasMarginBeforeQuirk()); |
| 1149 | grandchildBlock->setHasMarginAfterQuirk(grandchildBox->style().hasMarginAfterQuirk()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | // 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] | 1154 | childBlock.marginBeforeEstimateForChild(*grandchildBox, positiveMarginBefore, negativeMarginBefore, discardMarginBefore); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1157 | LayoutUnit RenderBlockFlow::estimateLogicalTopPosition(RenderBox& child, const MarginInfo& marginInfo, LayoutUnit& estimateWithoutPagination) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1158 | { |
| 1159 | // FIXME: We need to eliminate the estimation of vertical position, because when it's wrong we sometimes trigger a pathological |
| 1160 | // relayout if there are intruding floats. |
| 1161 | LayoutUnit logicalTopEstimate = logicalHeight(); |
| 1162 | if (!marginInfo.canCollapseWithMarginBefore()) { |
| 1163 | LayoutUnit positiveMarginBefore = 0; |
| 1164 | LayoutUnit negativeMarginBefore = 0; |
| 1165 | bool discardMarginBefore = false; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1166 | if (child.selfNeedsLayout()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1167 | // Try to do a basic estimation of how the collapse is going to go. |
| 1168 | marginBeforeEstimateForChild(child, positiveMarginBefore, negativeMarginBefore, discardMarginBefore); |
| 1169 | } else { |
| 1170 | // Use the cached collapsed margin values from a previous layout. Most of the time they |
| 1171 | // will be right. |
| 1172 | MarginValues marginValues = marginValuesForChild(child); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1173 | positiveMarginBefore = std::max(positiveMarginBefore, marginValues.positiveMarginBefore()); |
| 1174 | negativeMarginBefore = std::max(negativeMarginBefore, marginValues.negativeMarginBefore()); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1175 | discardMarginBefore = mustDiscardMarginBeforeForChild(child); |
| 1176 | } |
| 1177 | |
| 1178 | // Collapse the result with our current margins. |
| 1179 | if (!discardMarginBefore) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1180 | logicalTopEstimate += std::max(marginInfo.positiveMargin(), positiveMarginBefore) - std::max(marginInfo.negativeMargin(), negativeMarginBefore); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | // Adjust logicalTopEstimate down to the next page if the margins are so large that we don't fit on the current |
| 1184 | // page. |
| 1185 | LayoutState* layoutState = view().layoutState(); |
| 1186 | if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTopEstimate > logicalHeight() |
| 1187 | && hasNextPage(logicalHeight())) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1188 | logicalTopEstimate = std::min(logicalTopEstimate, nextPageLogicalTop(logicalHeight())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1189 | |
| 1190 | logicalTopEstimate += getClearDelta(child, logicalTopEstimate); |
| 1191 | |
| 1192 | estimateWithoutPagination = logicalTopEstimate; |
| 1193 | |
| 1194 | if (layoutState->isPaginated()) { |
| 1195 | // If the object has a page or column break value of "before", then we should shift to the top of the next page. |
| 1196 | logicalTopEstimate = applyBeforeBreak(child, logicalTopEstimate); |
| 1197 | |
| 1198 | // For replaced elements and scrolled elements, we want to shift them to the next page if they don't fit on the current one. |
| 1199 | logicalTopEstimate = adjustForUnsplittableChild(child, logicalTopEstimate); |
| 1200 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1201 | if (!child.selfNeedsLayout() && child.isRenderBlock()) |
| 1202 | logicalTopEstimate += toRenderBlock(child).paginationStrut(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | return logicalTopEstimate; |
| 1206 | } |
| 1207 | |
| 1208 | void RenderBlockFlow::setCollapsedBottomMargin(const MarginInfo& marginInfo) |
| 1209 | { |
| 1210 | if (marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore()) { |
| 1211 | // 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. |
| 1212 | // Don't update the max margin values because we won't need them anyway. |
| 1213 | if (marginInfo.discardMargin()) { |
| 1214 | setMustDiscardMarginAfter(); |
| 1215 | return; |
| 1216 | } |
| 1217 | |
| 1218 | // Update our max pos/neg bottom margins, since we collapsed our bottom margins |
| 1219 | // with our children. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1220 | setMaxMarginAfterValues(std::max(maxPositiveMarginAfter(), marginInfo.positiveMargin()), std::max(maxNegativeMarginAfter(), marginInfo.negativeMargin())); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1221 | |
| 1222 | if (!marginInfo.hasMarginAfterQuirk()) |
| 1223 | setHasMarginAfterQuirk(false); |
| 1224 | |
| 1225 | if (marginInfo.hasMarginAfterQuirk() && !marginAfter()) |
| 1226 | // We have no bottom margin and our last child has a quirky margin. |
| 1227 | // We will pick up this quirky margin and pass it through. |
| 1228 | // This deals with the <td><div><p> case. |
| 1229 | setHasMarginAfterQuirk(true); |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | void RenderBlockFlow::handleAfterSideOfBlock(LayoutUnit beforeSide, LayoutUnit afterSide, MarginInfo& marginInfo) |
| 1234 | { |
| 1235 | marginInfo.setAtAfterSideOfBlock(true); |
| 1236 | |
robert@webkit.org | 97037ef | 2013-11-20 19:26:10 +0000 | [diff] [blame] | 1237 | // If our last child was a self-collapsing block with clearance then our logical height is flush with the |
| 1238 | // bottom edge of the float that the child clears. The correct vertical position for the margin-collapsing we want |
| 1239 | // to perform now is at the child's margin-top - so adjust our height to that position. |
| 1240 | RenderObject* lastBlock = lastChild(); |
| 1241 | if (lastBlock && lastBlock->isRenderBlockFlow() && toRenderBlockFlow(lastBlock)->isSelfCollapsingBlock()) |
| 1242 | setLogicalHeight(logicalHeight() - toRenderBlockFlow(lastBlock)->marginOffsetForSelfCollapsingBlock()); |
| 1243 | |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1244 | // If we can't collapse with children then go ahead and add in the bottom margin. |
| 1245 | if (!marginInfo.discardMargin() && (!marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore() |
| 1246 | && (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginAfterQuirk()))) |
| 1247 | setLogicalHeight(logicalHeight() + marginInfo.margin()); |
| 1248 | |
| 1249 | // Now add in our bottom border/padding. |
| 1250 | setLogicalHeight(logicalHeight() + afterSide); |
| 1251 | |
| 1252 | // Negative margins can cause our height to shrink below our minimal height (border/padding). |
| 1253 | // 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] | 1254 | setLogicalHeight(std::max(logicalHeight(), beforeSide + afterSide)); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1255 | |
| 1256 | // Update our bottom collapsed margin info. |
| 1257 | setCollapsedBottomMargin(marginInfo); |
| 1258 | } |
| 1259 | |
| 1260 | void RenderBlockFlow::setMaxMarginBeforeValues(LayoutUnit pos, LayoutUnit neg) |
| 1261 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1262 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1263 | if (pos == RenderBlockFlowRareData::positiveMarginBeforeDefault(*this) && neg == RenderBlockFlowRareData::negativeMarginBeforeDefault(*this)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1264 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1265 | materializeRareBlockFlowData(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1266 | } |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1267 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1268 | rareBlockFlowData()->m_margins.setPositiveMarginBefore(pos); |
| 1269 | rareBlockFlowData()->m_margins.setNegativeMarginBefore(neg); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | void RenderBlockFlow::setMaxMarginAfterValues(LayoutUnit pos, LayoutUnit neg) |
| 1273 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1274 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1275 | if (pos == RenderBlockFlowRareData::positiveMarginAfterDefault(*this) && neg == RenderBlockFlowRareData::negativeMarginAfterDefault(*this)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1276 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1277 | materializeRareBlockFlowData(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1278 | } |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1279 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1280 | rareBlockFlowData()->m_margins.setPositiveMarginAfter(pos); |
| 1281 | rareBlockFlowData()->m_margins.setNegativeMarginAfter(neg); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | void RenderBlockFlow::setMustDiscardMarginBefore(bool value) |
| 1285 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1286 | if (style().marginBeforeCollapse() == MDISCARD) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1287 | ASSERT(value); |
| 1288 | return; |
| 1289 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1290 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1291 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1292 | if (!value) |
| 1293 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1294 | materializeRareBlockFlowData(); |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1295 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1296 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1297 | rareBlockFlowData()->m_discardMarginBefore = value; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | void RenderBlockFlow::setMustDiscardMarginAfter(bool value) |
| 1301 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1302 | if (style().marginAfterCollapse() == MDISCARD) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1303 | ASSERT(value); |
| 1304 | return; |
| 1305 | } |
| 1306 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1307 | if (!hasRareBlockFlowData()) { |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1308 | if (!value) |
| 1309 | return; |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1310 | materializeRareBlockFlowData(); |
weinig@apple.com | 924a77a | 2013-11-11 00:22:38 +0000 | [diff] [blame] | 1311 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1312 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1313 | rareBlockFlowData()->m_discardMarginAfter = value; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | bool RenderBlockFlow::mustDiscardMarginBefore() const |
| 1317 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1318 | return style().marginBeforeCollapse() == MDISCARD || (hasRareBlockFlowData() && rareBlockFlowData()->m_discardMarginBefore); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | bool RenderBlockFlow::mustDiscardMarginAfter() const |
| 1322 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1323 | return style().marginAfterCollapse() == MDISCARD || (hasRareBlockFlowData() && rareBlockFlowData()->m_discardMarginAfter); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1326 | bool RenderBlockFlow::mustDiscardMarginBeforeForChild(const RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1327 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1328 | ASSERT(!child.selfNeedsLayout()); |
| 1329 | if (!child.isWritingModeRoot()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1330 | return child.isRenderBlockFlow() ? toRenderBlockFlow(child).mustDiscardMarginBefore() : (child.style().marginBeforeCollapse() == MDISCARD); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1331 | if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1332 | return child.isRenderBlockFlow() ? toRenderBlockFlow(child).mustDiscardMarginAfter() : (child.style().marginAfterCollapse() == MDISCARD); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1333 | |
| 1334 | // FIXME: We return false here because the implementation is not geometrically complete. We have values only for before/after, not start/end. |
| 1335 | // In case the boxes are perpendicular we assume the property is not specified. |
| 1336 | return false; |
| 1337 | } |
| 1338 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1339 | bool RenderBlockFlow::mustDiscardMarginAfterForChild(const RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1340 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1341 | ASSERT(!child.selfNeedsLayout()); |
| 1342 | if (!child.isWritingModeRoot()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1343 | return child.isRenderBlockFlow() ? toRenderBlockFlow(child).mustDiscardMarginAfter() : (child.style().marginAfterCollapse() == MDISCARD); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1344 | if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1345 | return child.isRenderBlockFlow() ? toRenderBlockFlow(child).mustDiscardMarginBefore() : (child.style().marginBeforeCollapse() == MDISCARD); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1346 | |
| 1347 | // FIXME: See |mustDiscardMarginBeforeForChild| above. |
| 1348 | return false; |
| 1349 | } |
| 1350 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1351 | bool RenderBlockFlow::mustSeparateMarginBeforeForChild(const RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1352 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1353 | ASSERT(!child.selfNeedsLayout()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1354 | const RenderStyle& childStyle = child.style(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1355 | if (!child.isWritingModeRoot()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1356 | return childStyle.marginBeforeCollapse() == MSEPARATE; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1357 | if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1358 | return childStyle.marginAfterCollapse() == MSEPARATE; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1359 | |
| 1360 | // FIXME: See |mustDiscardMarginBeforeForChild| above. |
| 1361 | return false; |
| 1362 | } |
| 1363 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1364 | bool RenderBlockFlow::mustSeparateMarginAfterForChild(const RenderBox& child) const |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1365 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1366 | ASSERT(!child.selfNeedsLayout()); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1367 | const RenderStyle& childStyle = child.style(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1368 | if (!child.isWritingModeRoot()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1369 | return childStyle.marginAfterCollapse() == MSEPARATE; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1370 | if (child.isHorizontalWritingMode() == isHorizontalWritingMode()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1371 | return childStyle.marginBeforeCollapse() == MSEPARATE; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1372 | |
| 1373 | // FIXME: See |mustDiscardMarginBeforeForChild| above. |
| 1374 | return false; |
| 1375 | } |
| 1376 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1377 | static bool inNormalFlow(RenderBox& child) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1378 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1379 | RenderBlock* curr = child.containingBlock(); |
| 1380 | while (curr && curr != &child.view()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1381 | if (curr->hasColumns() || curr->isRenderFlowThread()) |
| 1382 | return true; |
| 1383 | if (curr->isFloatingOrOutOfFlowPositioned()) |
| 1384 | return false; |
| 1385 | curr = curr->containingBlock(); |
| 1386 | } |
| 1387 | return true; |
| 1388 | } |
| 1389 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1390 | LayoutUnit RenderBlockFlow::applyBeforeBreak(RenderBox& child, LayoutUnit logicalOffset) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1391 | { |
| 1392 | // FIXME: Add page break checking here when we support printing. |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1393 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1394 | bool isInsideMulticolFlowThread = flowThread && !flowThread->isRenderNamedFlowThread(); |
| 1395 | bool checkColumnBreaks = isInsideMulticolFlowThread || view().layoutState()->isPaginatingColumns(); |
| 1396 | bool checkPageBreaks = !checkColumnBreaks && view().layoutState()->m_pageLogicalHeight; // FIXME: Once columns can print we have to check this. |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1397 | bool checkRegionBreaks = flowThread && flowThread->isRenderNamedFlowThread(); |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1398 | bool checkBeforeAlways = (checkColumnBreaks && child.style().columnBreakBefore() == PBALWAYS) |
| 1399 | || (checkPageBreaks && child.style().pageBreakBefore() == PBALWAYS) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1400 | || (checkRegionBreaks && child.style().regionBreakBefore() == PBALWAYS); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1401 | if (checkBeforeAlways && inNormalFlow(child) && hasNextPage(logicalOffset, IncludePageBoundary)) { |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1402 | if (checkColumnBreaks) { |
| 1403 | if (isInsideMulticolFlowThread) |
| 1404 | checkRegionBreaks = true; |
| 1405 | else |
| 1406 | view().layoutState()->addForcedColumnBreak(&child, logicalOffset); |
| 1407 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1408 | if (checkRegionBreaks) { |
| 1409 | LayoutUnit offsetBreakAdjustment = 0; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1410 | if (flowThread->addForcedRegionBreak(this, offsetFromLogicalTopOfFirstPage() + logicalOffset, &child, true, &offsetBreakAdjustment)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1411 | return logicalOffset + offsetBreakAdjustment; |
| 1412 | } |
| 1413 | return nextPageLogicalTop(logicalOffset, IncludePageBoundary); |
| 1414 | } |
| 1415 | return logicalOffset; |
| 1416 | } |
| 1417 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1418 | LayoutUnit RenderBlockFlow::applyAfterBreak(RenderBox& child, LayoutUnit logicalOffset, MarginInfo& marginInfo) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1419 | { |
| 1420 | // FIXME: Add page break checking here when we support printing. |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1421 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1422 | bool isInsideMulticolFlowThread = flowThread && !flowThread->isRenderNamedFlowThread(); |
| 1423 | bool checkColumnBreaks = isInsideMulticolFlowThread || view().layoutState()->isPaginatingColumns(); |
| 1424 | bool checkPageBreaks = !checkColumnBreaks && view().layoutState()->m_pageLogicalHeight; // FIXME: Once columns can print we have to check this. |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1425 | bool checkRegionBreaks = flowThread && flowThread->isRenderNamedFlowThread(); |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1426 | bool checkAfterAlways = (checkColumnBreaks && child.style().columnBreakAfter() == PBALWAYS) |
| 1427 | || (checkPageBreaks && child.style().pageBreakAfter() == PBALWAYS) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1428 | || (checkRegionBreaks && child.style().regionBreakAfter() == PBALWAYS); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1429 | if (checkAfterAlways && inNormalFlow(child) && hasNextPage(logicalOffset, IncludePageBoundary)) { |
| 1430 | LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? LayoutUnit() : marginInfo.margin(); |
| 1431 | |
| 1432 | // So our margin doesn't participate in the next collapsing steps. |
| 1433 | marginInfo.clearMargin(); |
| 1434 | |
commit-queue@webkit.org | fd8f1a2 | 2014-01-20 19:55:59 +0000 | [diff] [blame] | 1435 | if (checkColumnBreaks) { |
| 1436 | if (isInsideMulticolFlowThread) |
| 1437 | checkRegionBreaks = true; |
| 1438 | else |
| 1439 | view().layoutState()->addForcedColumnBreak(&child, logicalOffset); |
| 1440 | } |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1441 | if (checkRegionBreaks) { |
| 1442 | LayoutUnit offsetBreakAdjustment = 0; |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1443 | if (flowThread->addForcedRegionBreak(this, offsetFromLogicalTopOfFirstPage() + logicalOffset + marginOffset, &child, false, &offsetBreakAdjustment)) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1444 | return logicalOffset + marginOffset + offsetBreakAdjustment; |
| 1445 | } |
| 1446 | return nextPageLogicalTop(logicalOffset, IncludePageBoundary); |
| 1447 | } |
| 1448 | return logicalOffset; |
| 1449 | } |
| 1450 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1451 | LayoutUnit RenderBlockFlow::adjustBlockChildForPagination(LayoutUnit logicalTopAfterClear, LayoutUnit estimateWithoutPagination, RenderBox& child, bool atBeforeSideOfBlock) |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1452 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1453 | RenderBlock* childRenderBlock = child.isRenderBlock() ? toRenderBlock(&child) : nullptr; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1454 | |
| 1455 | if (estimateWithoutPagination != logicalTopAfterClear) { |
| 1456 | // Our guess prior to pagination movement was wrong. Before we attempt to paginate, let's try again at the new |
| 1457 | // position. |
| 1458 | setLogicalHeight(logicalTopAfterClear); |
| 1459 | setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta); |
| 1460 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1461 | if (child.shrinkToAvoidFloats()) { |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1462 | // The child's width depends on the line width. |
| 1463 | // When the child shifts to clear an item, its width can |
| 1464 | // change (because it has more available line width). |
| 1465 | // So go ahead and mark the item as dirty. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1466 | child.setChildNeedsLayout(MarkOnlyThis); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | if (childRenderBlock) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1470 | if (!child.avoidsFloats() && childRenderBlock->containsFloats()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1471 | toRenderBlockFlow(childRenderBlock)->markAllDescendantsWithFloatsForLayout(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1472 | if (!child.needsLayout()) |
| 1473 | child.markForPaginationRelayoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | // Our guess was wrong. Make the child lay itself out again. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1477 | child.layoutIfNeeded(); |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | LayoutUnit oldTop = logicalTopAfterClear; |
| 1481 | |
| 1482 | // If the object has a page or column break value of "before", then we should shift to the top of the next page. |
| 1483 | LayoutUnit result = applyBeforeBreak(child, logicalTopAfterClear); |
| 1484 | |
| 1485 | if (pageLogicalHeightForOffset(result)) { |
| 1486 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(result, ExcludePageBoundary); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1487 | LayoutUnit spaceShortage = child.logicalHeight() - remainingLogicalHeight; |
hyatt@apple.com | 1807b5b | 2013-09-11 19:50:03 +0000 | [diff] [blame] | 1488 | if (spaceShortage > 0) { |
| 1489 | // If the child crosses a column boundary, report a break, in case nothing inside it has already |
| 1490 | // done so. The column balancer needs to know how much it has to stretch the columns to make more |
| 1491 | // content fit. If no breaks are reported (but do occur), the balancer will have no clue. FIXME: |
| 1492 | // This should be improved, though, because here we just pretend that the child is |
| 1493 | // unsplittable. A splittable child, on the other hand, has break opportunities at every position |
| 1494 | // where there's no child content, border or padding. In other words, we risk stretching more |
| 1495 | // than necessary. |
| 1496 | setPageBreak(result, spaceShortage); |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | // For replaced elements and scrolled elements, we want to shift them to the next page if they don't fit on the current one. |
| 1501 | LayoutUnit logicalTopBeforeUnsplittableAdjustment = result; |
| 1502 | LayoutUnit logicalTopAfterUnsplittableAdjustment = adjustForUnsplittableChild(child, result); |
| 1503 | |
| 1504 | LayoutUnit paginationStrut = 0; |
| 1505 | LayoutUnit unsplittableAdjustmentDelta = logicalTopAfterUnsplittableAdjustment - logicalTopBeforeUnsplittableAdjustment; |
| 1506 | if (unsplittableAdjustmentDelta) |
| 1507 | paginationStrut = unsplittableAdjustmentDelta; |
| 1508 | else if (childRenderBlock && childRenderBlock->paginationStrut()) |
| 1509 | paginationStrut = childRenderBlock->paginationStrut(); |
| 1510 | |
| 1511 | if (paginationStrut) { |
| 1512 | // We are willing to propagate out to our parent block as long as we were at the top of the block prior |
| 1513 | // to collapsing our margins, and as long as we didn't clear or move as a result of other pagination. |
| 1514 | if (atBeforeSideOfBlock && oldTop == result && !isOutOfFlowPositioned() && !isTableCell()) { |
| 1515 | // FIXME: Should really check if we're exceeding the page height before propagating the strut, but we don't |
| 1516 | // have all the information to do so (the strut only has the remaining amount to push). Gecko gets this wrong too |
| 1517 | // and pushes to the next page anyway, so not too concerned about it. |
| 1518 | setPaginationStrut(result + paginationStrut); |
| 1519 | if (childRenderBlock) |
| 1520 | childRenderBlock->setPaginationStrut(0); |
| 1521 | } else |
| 1522 | result += paginationStrut; |
| 1523 | } |
| 1524 | |
| 1525 | // Similar to how we apply clearance. Go ahead and boost height() to be the place where we're going to position the child. |
| 1526 | setLogicalHeight(logicalHeight() + (result - oldTop)); |
| 1527 | |
| 1528 | // Return the final adjusted logical top. |
| 1529 | return result; |
| 1530 | } |
| 1531 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1532 | static inline LayoutUnit calculateMinimumPageHeight(RenderStyle* renderStyle, RootInlineBox* lastLine, LayoutUnit lineTop, LayoutUnit lineBottom) |
| 1533 | { |
| 1534 | // We may require a certain minimum number of lines per page in order to satisfy |
| 1535 | // orphans and widows, and that may affect the minimum page height. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1536 | 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] | 1537 | if (lineCount > 1) { |
| 1538 | RootInlineBox* line = lastLine; |
| 1539 | for (unsigned i = 1; i < lineCount && line->prevRootBox(); i++) |
| 1540 | line = line->prevRootBox(); |
| 1541 | |
| 1542 | // FIXME: Paginating using line overflow isn't all fine. See FIXME in |
| 1543 | // adjustLinePositionForPagination() for more details. |
| 1544 | LayoutRect overflow = line->logicalVisualOverflowRect(line->lineTop(), line->lineBottom()); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1545 | lineTop = std::min(line->lineTopWithLeading(), overflow.y()); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1546 | } |
| 1547 | return lineBottom - lineTop; |
| 1548 | } |
| 1549 | |
| 1550 | void RenderBlockFlow::adjustLinePositionForPagination(RootInlineBox* lineBox, LayoutUnit& delta, RenderFlowThread* flowThread) |
| 1551 | { |
| 1552 | // FIXME: For now we paginate using line overflow. This ensures that lines don't overlap at all when we |
| 1553 | // put a strut between them for pagination purposes. However, this really isn't the desired rendering, since |
| 1554 | // the line on the top of the next page will appear too far down relative to the same kind of line at the top |
| 1555 | // of the first column. |
| 1556 | // |
| 1557 | // The rendering we would like to see is one where the lineTopWithLeading is at the top of the column, and any line overflow |
| 1558 | // simply spills out above the top of the column. This effect would match what happens at the top of the first column. |
| 1559 | // We can't achieve this rendering, however, until we stop columns from clipping to the column bounds (thus allowing |
| 1560 | // for overflow to occur), and then cache visible overflow for each column rect. |
| 1561 | // |
| 1562 | // Furthermore, the paint we have to do when a column has overflow has to be special. We need to exclude |
| 1563 | // content that paints in a previous column (and content that paints in the following column). |
| 1564 | // |
| 1565 | // For now we'll at least honor the lineTopWithLeading when paginating if it is above the logical top overflow. This will |
| 1566 | // at least make positive leading work in typical cases. |
| 1567 | // |
| 1568 | // FIXME: Another problem with simply moving lines is that the available line width may change (because of floats). |
| 1569 | // Technically if the location we move the line to has a different line width than our old position, then we need to dirty the |
| 1570 | // line and all following lines. |
| 1571 | LayoutRect logicalVisualOverflow = lineBox->logicalVisualOverflowRect(lineBox->lineTop(), lineBox->lineBottom()); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1572 | LayoutUnit logicalOffset = std::min(lineBox->lineTopWithLeading(), logicalVisualOverflow.y()); |
| 1573 | LayoutUnit logicalBottom = std::max(lineBox->lineBottomWithLeading(), logicalVisualOverflow.maxY()); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1574 | LayoutUnit lineHeight = logicalBottom - logicalOffset; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1575 | updateMinimumPageHeight(logicalOffset, calculateMinimumPageHeight(&style(), lineBox, logicalOffset, logicalBottom)); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1576 | logicalOffset += delta; |
| 1577 | lineBox->setPaginationStrut(0); |
| 1578 | lineBox->setIsFirstAfterPageBreak(false); |
| 1579 | LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
| 1580 | bool hasUniformPageLogicalHeight = !flowThread || flowThread->regionsHaveUniformLogicalHeight(); |
| 1581 | // If lineHeight is greater than pageLogicalHeight, but logicalVisualOverflow.height() still fits, we are |
| 1582 | // still going to add a strut, so that the visible overflow fits on a single page. |
| 1583 | if (!pageLogicalHeight || (hasUniformPageLogicalHeight && logicalVisualOverflow.height() > pageLogicalHeight) |
| 1584 | || !hasNextPage(logicalOffset)) |
abucur@adobe.com | d40287b | 2013-10-08 17:33:05 +0000 | [diff] [blame] | 1585 | // 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. |
| 1586 | // 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] | 1587 | return; |
| 1588 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalOffset, ExcludePageBoundary); |
| 1589 | |
| 1590 | int lineIndex = lineCount(lineBox); |
| 1591 | if (remainingLogicalHeight < lineHeight || (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIndex)) { |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1592 | if (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIndex) { |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1593 | clearShouldBreakAtLineToAvoidWidow(); |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1594 | setDidBreakAtLineToAvoidWidow(); |
| 1595 | } |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1596 | // If we have a non-uniform page height, then we have to shift further possibly. |
| 1597 | if (!hasUniformPageLogicalHeight && !pushToNextPageWithMinimumLogicalHeight(remainingLogicalHeight, logicalOffset, lineHeight)) |
| 1598 | return; |
| 1599 | if (lineHeight > pageLogicalHeight) { |
| 1600 | // 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] | 1601 | 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] | 1602 | } |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1603 | LayoutUnit totalLogicalHeight = lineHeight + std::max<LayoutUnit>(0, logicalOffset); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1604 | LayoutUnit pageLogicalHeightAtNewOffset = hasUniformPageLogicalHeight ? pageLogicalHeight : pageLogicalHeightForOffset(logicalOffset + remainingLogicalHeight); |
| 1605 | setPageBreak(logicalOffset, lineHeight - remainingLogicalHeight); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1606 | if (((lineBox == firstRootBox() && totalLogicalHeight < pageLogicalHeightAtNewOffset) || (!style().hasAutoOrphans() && style().orphans() >= lineIndex)) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1607 | && !isOutOfFlowPositioned() && !isTableCell()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 1608 | setPaginationStrut(remainingLogicalHeight + std::max<LayoutUnit>(0, logicalOffset)); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1609 | else { |
| 1610 | delta += remainingLogicalHeight; |
| 1611 | lineBox->setPaginationStrut(remainingLogicalHeight); |
| 1612 | lineBox->setIsFirstAfterPageBreak(true); |
| 1613 | } |
commit-queue@webkit.org | 883b01c | 2014-01-20 08:58:36 +0000 | [diff] [blame] | 1614 | } else if (remainingLogicalHeight == pageLogicalHeight) { |
| 1615 | // We're at the very top of a page or column. |
| 1616 | if (lineBox != firstRootBox()) |
| 1617 | lineBox->setIsFirstAfterPageBreak(true); |
| 1618 | if (lineBox != firstRootBox() || offsetFromLogicalTopOfFirstPage()) |
| 1619 | setPageBreak(logicalOffset, lineHeight); |
| 1620 | } |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | void RenderBlockFlow::setBreakAtLineToAvoidWidow(int lineToBreak) |
| 1624 | { |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1625 | ASSERT(lineToBreak >= 0); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1626 | ASSERT(!ensureRareBlockFlowData().m_didBreakAtLineToAvoidWidow); |
| 1627 | ensureRareBlockFlowData().m_lineBreakToAvoidWidow = lineToBreak; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1630 | void RenderBlockFlow::setDidBreakAtLineToAvoidWidow() |
| 1631 | { |
| 1632 | ASSERT(!shouldBreakAtLineToAvoidWidow()); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1633 | if (!hasRareBlockFlowData()) |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1634 | return; |
| 1635 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1636 | rareBlockFlowData()->m_didBreakAtLineToAvoidWidow = true; |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | void RenderBlockFlow::clearDidBreakAtLineToAvoidWidow() |
| 1640 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1641 | if (!hasRareBlockFlowData()) |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1642 | return; |
| 1643 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1644 | rareBlockFlowData()->m_didBreakAtLineToAvoidWidow = false; |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1647 | void RenderBlockFlow::clearShouldBreakAtLineToAvoidWidow() const |
| 1648 | { |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1649 | ASSERT(shouldBreakAtLineToAvoidWidow()); |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1650 | if (!hasRareBlockFlowData()) |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1651 | return; |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame] | 1652 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 1653 | rareBlockFlowData()->m_lineBreakToAvoidWidow = -1; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | bool RenderBlockFlow::relayoutToAvoidWidows(LayoutStateMaintainer& statePusher) |
| 1657 | { |
| 1658 | if (!shouldBreakAtLineToAvoidWidow()) |
| 1659 | return false; |
| 1660 | |
| 1661 | statePusher.pop(); |
| 1662 | setEverHadLayout(true); |
| 1663 | layoutBlock(false); |
| 1664 | return true; |
| 1665 | } |
| 1666 | |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1667 | bool RenderBlockFlow::hasNextPage(LayoutUnit logicalOffset, PageBoundaryRule pageBoundaryRule) const |
| 1668 | { |
| 1669 | ASSERT(view().layoutState() && view().layoutState()->isPaginated()); |
| 1670 | |
| 1671 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
| 1672 | if (!flowThread) |
| 1673 | return true; // Printing and multi-column both make new pages to accommodate content. |
| 1674 | |
| 1675 | // See if we're in the last region. |
| 1676 | LayoutUnit pageOffset = offsetFromLogicalTopOfFirstPage() + logicalOffset; |
stavila@adobe.com | 6cb976d | 2013-11-21 06:57:19 +0000 | [diff] [blame] | 1677 | RenderRegion* region = flowThread->regionAtBlockOffset(this, pageOffset, true); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1678 | if (!region) |
| 1679 | return false; |
| 1680 | if (region->isLastRegion()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1681 | return region->isRenderRegionSet() || region->style().regionFragment() == BreakRegionFragment |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1682 | || (pageBoundaryRule == IncludePageBoundary && pageOffset == region->logicalTopForFlowThreadContent()); |
stavila@adobe.com | 6cb976d | 2013-11-21 06:57:19 +0000 | [diff] [blame] | 1683 | |
| 1684 | RenderRegion* startRegion = 0; |
| 1685 | RenderRegion* endRegion = 0; |
| 1686 | flowThread->getRegionRangeForBox(this, startRegion, endRegion); |
| 1687 | |
| 1688 | if (region == endRegion) |
| 1689 | return false; |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1690 | return true; |
| 1691 | } |
| 1692 | |
| 1693 | LayoutUnit RenderBlockFlow::adjustForUnsplittableChild(RenderBox& child, LayoutUnit logicalOffset, bool includeMargins) |
| 1694 | { |
| 1695 | bool checkColumnBreaks = view().layoutState()->isPaginatingColumns(); |
| 1696 | bool checkPageBreaks = !checkColumnBreaks && view().layoutState()->m_pageLogicalHeight; |
| 1697 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
| 1698 | bool checkRegionBreaks = flowThread && flowThread->isRenderNamedFlowThread(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1699 | bool isUnsplittable = child.isUnsplittableForPagination() || (checkColumnBreaks && child.style().columnBreakInside() == PBAVOID) |
| 1700 | || (checkPageBreaks && child.style().pageBreakInside() == PBAVOID) |
| 1701 | || (checkRegionBreaks && child.style().regionBreakInside() == PBAVOID); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1702 | if (!isUnsplittable) |
| 1703 | return logicalOffset; |
| 1704 | LayoutUnit childLogicalHeight = logicalHeightForChild(child) + (includeMargins ? marginBeforeForChild(child) + marginAfterForChild(child) : LayoutUnit()); |
| 1705 | LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
| 1706 | bool hasUniformPageLogicalHeight = !flowThread || flowThread->regionsHaveUniformLogicalHeight(); |
| 1707 | updateMinimumPageHeight(logicalOffset, childLogicalHeight); |
| 1708 | if (!pageLogicalHeight || (hasUniformPageLogicalHeight && childLogicalHeight > pageLogicalHeight) |
| 1709 | || !hasNextPage(logicalOffset)) |
| 1710 | return logicalOffset; |
| 1711 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalOffset, ExcludePageBoundary); |
| 1712 | if (remainingLogicalHeight < childLogicalHeight) { |
| 1713 | if (!hasUniformPageLogicalHeight && !pushToNextPageWithMinimumLogicalHeight(remainingLogicalHeight, logicalOffset, childLogicalHeight)) |
| 1714 | return logicalOffset; |
| 1715 | return logicalOffset + remainingLogicalHeight; |
| 1716 | } |
| 1717 | return logicalOffset; |
| 1718 | } |
| 1719 | |
| 1720 | bool RenderBlockFlow::pushToNextPageWithMinimumLogicalHeight(LayoutUnit& adjustment, LayoutUnit logicalOffset, LayoutUnit minimumLogicalHeight) const |
| 1721 | { |
| 1722 | bool checkRegion = false; |
| 1723 | for (LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset + adjustment); pageLogicalHeight; |
| 1724 | pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset + adjustment)) { |
| 1725 | if (minimumLogicalHeight <= pageLogicalHeight) |
| 1726 | return true; |
| 1727 | if (!hasNextPage(logicalOffset + adjustment)) |
| 1728 | return false; |
| 1729 | adjustment += pageLogicalHeight; |
| 1730 | checkRegion = true; |
| 1731 | } |
| 1732 | return !checkRegion; |
| 1733 | } |
| 1734 | |
| 1735 | void RenderBlockFlow::setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) |
| 1736 | { |
| 1737 | if (RenderFlowThread* flowThread = flowThreadContainingBlock()) |
| 1738 | flowThread->setPageBreak(this, offsetFromLogicalTopOfFirstPage() + offset, spaceShortage); |
| 1739 | } |
| 1740 | |
| 1741 | void RenderBlockFlow::updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight) |
| 1742 | { |
| 1743 | if (RenderFlowThread* flowThread = flowThreadContainingBlock()) |
| 1744 | flowThread->updateMinimumPageHeight(this, offsetFromLogicalTopOfFirstPage() + offset, minHeight); |
| 1745 | else if (ColumnInfo* colInfo = view().layoutState()->m_columnInfo) |
| 1746 | colInfo->updateMinimumColumnHeight(minHeight); |
| 1747 | } |
| 1748 | |
| 1749 | LayoutUnit RenderBlockFlow::nextPageLogicalTop(LayoutUnit logicalOffset, PageBoundaryRule pageBoundaryRule) const |
| 1750 | { |
| 1751 | LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
| 1752 | if (!pageLogicalHeight) |
| 1753 | return logicalOffset; |
| 1754 | |
| 1755 | // The logicalOffset is in our coordinate space. We can add in our pushed offset. |
| 1756 | LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logicalOffset); |
| 1757 | if (pageBoundaryRule == ExcludePageBoundary) |
| 1758 | return logicalOffset + (remainingLogicalHeight ? remainingLogicalHeight : pageLogicalHeight); |
| 1759 | return logicalOffset + remainingLogicalHeight; |
| 1760 | } |
| 1761 | |
| 1762 | LayoutUnit RenderBlockFlow::pageLogicalTopForOffset(LayoutUnit offset) const |
| 1763 | { |
| 1764 | LayoutUnit firstPageLogicalTop = isHorizontalWritingMode() ? view().layoutState()->m_pageOffset.height() : view().layoutState()->m_pageOffset.width(); |
| 1765 | LayoutUnit blockLogicalTop = isHorizontalWritingMode() ? view().layoutState()->m_layoutOffset.height() : view().layoutState()->m_layoutOffset.width(); |
| 1766 | |
| 1767 | LayoutUnit cumulativeOffset = offset + blockLogicalTop; |
| 1768 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
| 1769 | if (!flowThread) { |
| 1770 | LayoutUnit pageLogicalHeight = view().layoutState()->pageLogicalHeight(); |
| 1771 | if (!pageLogicalHeight) |
| 1772 | return 0; |
| 1773 | return cumulativeOffset - roundToInt(cumulativeOffset - firstPageLogicalTop) % roundToInt(pageLogicalHeight); |
| 1774 | } |
hyatt@apple.com | 150e7f2 | 2014-02-11 16:51:45 +0000 | [diff] [blame^] | 1775 | return firstPageLogicalTop + flowThread->pageLogicalTopForOffset(cumulativeOffset - firstPageLogicalTop); |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | LayoutUnit RenderBlockFlow::pageLogicalHeightForOffset(LayoutUnit offset) const |
| 1779 | { |
| 1780 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
| 1781 | if (!flowThread) |
| 1782 | return view().layoutState()->m_pageLogicalHeight; |
| 1783 | return flowThread->pageLogicalHeightForOffset(offset + offsetFromLogicalTopOfFirstPage()); |
| 1784 | } |
| 1785 | |
| 1786 | LayoutUnit RenderBlockFlow::pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule pageBoundaryRule) const |
| 1787 | { |
| 1788 | offset += offsetFromLogicalTopOfFirstPage(); |
| 1789 | |
| 1790 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
| 1791 | if (!flowThread) { |
| 1792 | LayoutUnit pageLogicalHeight = view().layoutState()->m_pageLogicalHeight; |
| 1793 | LayoutUnit remainingHeight = pageLogicalHeight - intMod(offset, pageLogicalHeight); |
| 1794 | if (pageBoundaryRule == IncludePageBoundary) { |
| 1795 | // If includeBoundaryPoint is true the line exactly on the top edge of a |
| 1796 | // column will act as being part of the previous column. |
| 1797 | remainingHeight = intMod(remainingHeight, pageLogicalHeight); |
| 1798 | } |
| 1799 | return remainingHeight; |
| 1800 | } |
| 1801 | |
| 1802 | return flowThread->pageRemainingLogicalHeightForOffset(offset, pageBoundaryRule); |
| 1803 | } |
| 1804 | |
| 1805 | |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1806 | void RenderBlockFlow::layoutLineGridBox() |
| 1807 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1808 | if (style().lineGrid() == RenderStyle::initialLineGrid()) { |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1809 | setLineGridBox(0); |
| 1810 | return; |
| 1811 | } |
| 1812 | |
| 1813 | setLineGridBox(0); |
| 1814 | |
akling@apple.com | 1aa97b0 | 2013-10-31 21:59:49 +0000 | [diff] [blame] | 1815 | auto lineGridBox = std::make_unique<RootInlineBox>(*this); |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1816 | lineGridBox->setHasTextChildren(); // Needed to make the line ascent/descent actually be honored in quirks mode. |
| 1817 | lineGridBox->setConstructed(); |
| 1818 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1819 | VerticalPositionCache verticalPositionCache; |
| 1820 | lineGridBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache); |
| 1821 | |
akling@apple.com | 1aa97b0 | 2013-10-31 21:59:49 +0000 | [diff] [blame] | 1822 | setLineGridBox(std::move(lineGridBox)); |
| 1823 | |
hyatt@apple.com | 3cd5c77 | 2013-09-27 18:22:50 +0000 | [diff] [blame] | 1824 | // FIXME: If any of the characteristics of the box change compared to the old one, then we need to do a deep dirtying |
| 1825 | // (similar to what happens when the page height changes). Ideally, though, we only do this if someone is actually snapping |
| 1826 | // to this grid. |
| 1827 | } |
| 1828 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1829 | bool RenderBlockFlow::containsFloat(RenderBox& renderer) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1830 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1831 | return m_floatingObjects && m_floatingObjects->set().contains<RenderBox&, FloatingObjectHashTranslator>(renderer); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | void RenderBlockFlow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
| 1835 | { |
| 1836 | RenderBlock::styleDidChange(diff, oldStyle); |
| 1837 | |
| 1838 | // After our style changed, if we lose our ability to propagate floats into next sibling |
| 1839 | // blocks, then we need to find the top most parent containing that overhanging float and |
| 1840 | // then mark its descendants with floats for layout and clear all floats from its next |
| 1841 | // sibling blocks that exist in our floating objects list. See bug 56299 and 62875. |
| 1842 | bool canPropagateFloatIntoSibling = !isFloatingOrOutOfFlowPositioned() && !avoidsFloats(); |
| 1843 | if (diff == StyleDifferenceLayout && s_canPropagateFloatIntoSibling && !canPropagateFloatIntoSibling && hasOverhangingFloats()) { |
| 1844 | RenderBlockFlow* parentBlock = this; |
| 1845 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1846 | |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 1847 | for (auto& ancestor : ancestorsOfType<RenderBlockFlow>(*this)) { |
| 1848 | if (ancestor.isRenderView()) |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 1849 | break; |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 1850 | if (ancestor.hasOverhangingFloats()) { |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 1851 | for (auto it = floatingObjectSet.begin(), end = floatingObjectSet.end(); it != end; ++it) { |
| 1852 | RenderBox& renderer = (*it)->renderer(); |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 1853 | if (ancestor.hasOverhangingFloat(renderer)) { |
| 1854 | parentBlock = &ancestor; |
akling@apple.com | f302805 | 2013-11-04 08:46:06 +0000 | [diff] [blame] | 1855 | break; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1856 | } |
| 1857 | } |
| 1858 | } |
| 1859 | } |
| 1860 | |
| 1861 | parentBlock->markAllDescendantsWithFloatsForLayout(); |
| 1862 | parentBlock->markSiblingsWithFloatsForLayout(); |
| 1863 | } |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 1864 | |
akling@apple.com | 8f40c5b | 2013-10-27 22:54:07 +0000 | [diff] [blame] | 1865 | if (auto fragment = renderNamedFlowFragment()) |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1866 | fragment->setStyle(RenderNamedFlowFragment::createStyle(style())); |
antti@apple.com | 42fb53d | 2013-10-25 02:33:11 +0000 | [diff] [blame] | 1867 | |
| 1868 | if (diff >= StyleDifferenceRepaint) |
| 1869 | invalidateLineLayoutPath(); |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 1870 | |
| 1871 | if (multiColumnFlowThread()) { |
| 1872 | for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) |
| 1873 | child->setStyle(RenderStyle::createAnonymousStyleWithDisplay(&style(), BLOCK)); |
| 1874 | } |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
akling@apple.com | bdae4324 | 2013-10-25 12:00:20 +0000 | [diff] [blame] | 1877 | void RenderBlockFlow::styleWillChange(StyleDifference diff, const RenderStyle& newStyle) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1878 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 1879 | const RenderStyle* oldStyle = hasInitializedStyle() ? &style() : nullptr; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1880 | s_canPropagateFloatIntoSibling = oldStyle ? !isFloatingOrOutOfFlowPositioned() && !avoidsFloats() : false; |
| 1881 | |
akling@apple.com | bdae4324 | 2013-10-25 12:00:20 +0000 | [diff] [blame] | 1882 | if (oldStyle && parent() && diff == StyleDifferenceLayout && oldStyle->position() != newStyle.position()) { |
| 1883 | if (containsFloats() && !isFloating() && !isOutOfFlowPositioned() && newStyle.hasOutOfFlowPosition()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1884 | markAllDescendantsWithFloatsForLayout(); |
| 1885 | } |
| 1886 | |
| 1887 | RenderBlock::styleWillChange(diff, newStyle); |
| 1888 | } |
| 1889 | |
antti@apple.com | a2c7f24 | 2013-10-22 22:37:25 +0000 | [diff] [blame] | 1890 | void RenderBlockFlow::deleteLines() |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1891 | { |
| 1892 | if (containsFloats()) |
| 1893 | m_floatingObjects->clearLineBoxTreePointers(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 1894 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 1895 | if (m_simpleLineLayout) { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1896 | ASSERT(!m_lineBoxes.firstLineBox()); |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 1897 | m_simpleLineLayout = nullptr; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1898 | } else |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 1899 | m_lineBoxes.deleteLineBoxTree(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 1900 | |
antti@apple.com | a2c7f24 | 2013-10-22 22:37:25 +0000 | [diff] [blame] | 1901 | RenderBlock::deleteLines(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | void RenderBlockFlow::moveAllChildrenIncludingFloatsTo(RenderBlock* toBlock, bool fullRemoveInsert) |
| 1905 | { |
| 1906 | RenderBlockFlow* toBlockFlow = toRenderBlockFlow(toBlock); |
| 1907 | moveAllChildrenTo(toBlockFlow, fullRemoveInsert); |
| 1908 | |
| 1909 | // When a portion of the render tree is being detached, anonymous blocks |
| 1910 | // will be combined as their children are deleted. In this process, the |
| 1911 | // anonymous block later in the tree is merged into the one preceeding it. |
| 1912 | // It can happen that the later block (this) contains floats that the |
| 1913 | // previous block (toBlockFlow) did not contain, and thus are not in the |
| 1914 | // floating objects list for toBlockFlow. This can result in toBlockFlow |
| 1915 | // containing floats that are not in it's floating objects list, but are in |
| 1916 | // the floating objects lists of siblings and parents. This can cause |
| 1917 | // problems when the float itself is deleted, since the deletion code |
| 1918 | // assumes that if a float is not in it's containing block's floating |
| 1919 | // objects list, it isn't in any floating objects list. In order to |
| 1920 | // preserve this condition (removing it has serious performance |
| 1921 | // implications), we need to copy the floating objects from the old block |
| 1922 | // (this) to the new block (toBlockFlow). The float's metrics will likely |
| 1923 | // all be wrong, but since toBlockFlow is already marked for layout, this |
| 1924 | // will get fixed before anything gets displayed. |
| 1925 | // See bug https://bugs.webkit.org/show_bug.cgi?id=115566 |
| 1926 | if (m_floatingObjects) { |
| 1927 | if (!toBlockFlow->m_floatingObjects) |
| 1928 | toBlockFlow->createFloatingObjects(); |
| 1929 | |
| 1930 | const FloatingObjectSet& fromFloatingObjectSet = m_floatingObjects->set(); |
| 1931 | auto end = fromFloatingObjectSet.end(); |
| 1932 | |
| 1933 | for (auto it = fromFloatingObjectSet.begin(); it != end; ++it) { |
| 1934 | FloatingObject* floatingObject = it->get(); |
| 1935 | |
| 1936 | // Don't insert the object again if it's already in the list |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 1937 | if (toBlockFlow->containsFloat(floatingObject->renderer())) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1938 | continue; |
| 1939 | |
| 1940 | toBlockFlow->m_floatingObjects->add(floatingObject->unsafeClone()); |
| 1941 | } |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | void RenderBlockFlow::addOverflowFromFloats() |
| 1946 | { |
| 1947 | if (!m_floatingObjects) |
| 1948 | return; |
| 1949 | |
| 1950 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 1951 | auto end = floatingObjectSet.end(); |
| 1952 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 1953 | FloatingObject* r = it->get(); |
| 1954 | if (r->isDescendant()) |
| 1955 | addOverflowFromChild(&r->renderer(), IntSize(xPositionForFloatIncludingMargin(r), yPositionForFloatIncludingMargin(r))); |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | void RenderBlockFlow::computeOverflow(LayoutUnit oldClientAfterEdge, bool recomputeFloats) |
| 1960 | { |
| 1961 | RenderBlock::computeOverflow(oldClientAfterEdge, recomputeFloats); |
| 1962 | |
| 1963 | if (!hasColumns() && (recomputeFloats || isRoot() || expandsToEncloseOverhangingFloats() || hasSelfPaintingLayer())) |
| 1964 | addOverflowFromFloats(); |
| 1965 | } |
| 1966 | |
| 1967 | void RenderBlockFlow::repaintOverhangingFloats(bool paintAllDescendants) |
| 1968 | { |
| 1969 | // Repaint any overhanging floats (if we know we're the one to paint them). |
| 1970 | // Otherwise, bail out. |
| 1971 | if (!hasOverhangingFloats()) |
| 1972 | return; |
| 1973 | |
| 1974 | // FIXME: Avoid disabling LayoutState. At the very least, don't disable it for floats originating |
| 1975 | // in this block. Better yet would be to push extra state for the containers of other floats. |
| 1976 | LayoutStateDisabler layoutStateDisabler(&view()); |
| 1977 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 1978 | auto end = floatingObjectSet.end(); |
| 1979 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 1980 | FloatingObject* floatingObject = it->get(); |
| 1981 | // Only repaint the object if it is overhanging, is not in its own layer, and |
| 1982 | // is our responsibility to paint (m_shouldPaint is set). When paintAllDescendants is true, the latter |
| 1983 | // condition is replaced with being a descendant of us. |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 1984 | if (logicalBottomForFloat(floatingObject) > logicalHeight() |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 1985 | && !floatingObject->renderer().hasSelfPaintingLayer() |
| 1986 | && (floatingObject->shouldPaint() || (paintAllDescendants && floatingObject->renderer().isDescendantOf(this)))) { |
| 1987 | floatingObject->renderer().repaint(); |
| 1988 | floatingObject->renderer().repaintOverhangingFloats(false); |
| 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | void RenderBlockFlow::paintFloats(PaintInfo& paintInfo, const LayoutPoint& paintOffset, bool preservePhase) |
| 1994 | { |
| 1995 | if (!m_floatingObjects) |
| 1996 | return; |
| 1997 | |
| 1998 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 1999 | auto end = floatingObjectSet.end(); |
| 2000 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 2001 | FloatingObject* r = it->get(); |
| 2002 | // Only paint the object if our m_shouldPaint flag is set. |
| 2003 | if (r->shouldPaint() && !r->renderer().hasSelfPaintingLayer()) { |
| 2004 | PaintInfo currentPaintInfo(paintInfo); |
| 2005 | currentPaintInfo.phase = preservePhase ? paintInfo.phase : PaintPhaseBlockBackground; |
| 2006 | // FIXME: LayoutPoint version of xPositionForFloatIncludingMargin would make this much cleaner. |
| 2007 | LayoutPoint childPoint = flipFloatForWritingModeForChild(r, LayoutPoint(paintOffset.x() + xPositionForFloatIncludingMargin(r) - r->renderer().x(), paintOffset.y() + yPositionForFloatIncludingMargin(r) - r->renderer().y())); |
| 2008 | r->renderer().paint(currentPaintInfo, childPoint); |
| 2009 | if (!preservePhase) { |
| 2010 | currentPaintInfo.phase = PaintPhaseChildBlockBackgrounds; |
| 2011 | r->renderer().paint(currentPaintInfo, childPoint); |
| 2012 | currentPaintInfo.phase = PaintPhaseFloat; |
| 2013 | r->renderer().paint(currentPaintInfo, childPoint); |
| 2014 | currentPaintInfo.phase = PaintPhaseForeground; |
| 2015 | r->renderer().paint(currentPaintInfo, childPoint); |
| 2016 | currentPaintInfo.phase = PaintPhaseOutline; |
| 2017 | r->renderer().paint(currentPaintInfo, childPoint); |
| 2018 | } |
| 2019 | } |
| 2020 | } |
| 2021 | } |
| 2022 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2023 | 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] | 2024 | { |
| 2025 | if (m_floatingObjects) { |
| 2026 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2027 | auto end = floatingObjectSet.end(); |
| 2028 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 2029 | FloatingObject* floatingObject = it->get(); |
| 2030 | LayoutRect floatBox(offsetFromRootBlock.width() + xPositionForFloatIncludingMargin(floatingObject), |
| 2031 | offsetFromRootBlock.height() + yPositionForFloatIncludingMargin(floatingObject), |
| 2032 | floatingObject->renderer().width(), floatingObject->renderer().height()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2033 | rootBlock.flipForWritingMode(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2034 | floatBox.move(rootBlockPhysicalPosition.x(), rootBlockPhysicalPosition.y()); |
| 2035 | paintInfo->context->clipOut(pixelSnappedIntRect(floatBox)); |
| 2036 | } |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | void RenderBlockFlow::createFloatingObjects() |
| 2041 | { |
bjonesbe@adobe.com | 2e94fff | 2013-11-08 23:24:40 +0000 | [diff] [blame] | 2042 | m_floatingObjects = adoptPtr(new FloatingObjects(*this)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | void RenderBlockFlow::removeFloatingObjects() |
| 2046 | { |
| 2047 | if (!m_floatingObjects) |
| 2048 | return; |
| 2049 | |
| 2050 | m_floatingObjects->clear(); |
| 2051 | } |
| 2052 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2053 | FloatingObject* RenderBlockFlow::insertFloatingObject(RenderBox& floatBox) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2054 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2055 | ASSERT(floatBox.isFloating()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2056 | |
| 2057 | // Create the list of special objects if we don't aleady have one |
| 2058 | if (!m_floatingObjects) |
| 2059 | createFloatingObjects(); |
| 2060 | else { |
| 2061 | // Don't insert the floatingObject again if it's already in the list |
| 2062 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2063 | auto it = floatingObjectSet.find<RenderBox&, FloatingObjectHashTranslator>(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2064 | if (it != floatingObjectSet.end()) |
| 2065 | return it->get(); |
| 2066 | } |
| 2067 | |
| 2068 | // Create the special floatingObject entry & append it to the list |
| 2069 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2070 | std::unique_ptr<FloatingObject> floatingObject = FloatingObject::create(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2071 | |
| 2072 | // Our location is irrelevant if we're unsplittable or no pagination is in effect. |
| 2073 | // Just go ahead and lay out the float. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2074 | bool isChildRenderBlock = floatBox.isRenderBlock(); |
| 2075 | if (isChildRenderBlock && !floatBox.needsLayout() && view().layoutState()->pageLogicalHeightChanged()) |
| 2076 | floatBox.setChildNeedsLayout(MarkOnlyThis); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2077 | |
| 2078 | bool needsBlockDirectionLocationSetBeforeLayout = isChildRenderBlock && view().layoutState()->needsBlockDirectionLocationSetBeforeLayout(); |
| 2079 | if (!needsBlockDirectionLocationSetBeforeLayout || isWritingModeRoot()) // We are unsplittable if we're a block flow root. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2080 | floatBox.layoutIfNeeded(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2081 | else { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2082 | floatBox.updateLogicalWidth(); |
| 2083 | floatBox.computeAndSetBlockDirectionMargins(this); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2086 | setLogicalWidthForFloat(floatingObject.get(), logicalWidthForChild(floatBox) + marginStartForChild(floatBox) + marginEndForChild(floatBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2087 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2088 | return m_floatingObjects->add(std::move(floatingObject)); |
| 2089 | } |
| 2090 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2091 | void RenderBlockFlow::removeFloatingObject(RenderBox& floatBox) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2092 | { |
| 2093 | if (m_floatingObjects) { |
| 2094 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2095 | auto it = floatingObjectSet.find<RenderBox&, FloatingObjectHashTranslator>(floatBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2096 | if (it != floatingObjectSet.end()) { |
| 2097 | FloatingObject* floatingObject = it->get(); |
| 2098 | if (childrenInline()) { |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2099 | LayoutUnit logicalTop = logicalTopForFloat(floatingObject); |
| 2100 | LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2101 | |
| 2102 | // Fix for https://bugs.webkit.org/show_bug.cgi?id=54995. |
| 2103 | if (logicalBottom < 0 || logicalBottom < logicalTop || logicalTop == LayoutUnit::max()) |
| 2104 | logicalBottom = LayoutUnit::max(); |
| 2105 | else { |
| 2106 | // Special-case zero- and less-than-zero-height floats: those don't touch |
| 2107 | // the line that they're on, but it still needs to be dirtied. This is |
| 2108 | // accomplished by pretending they have a height of 1. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2109 | logicalBottom = std::max(logicalBottom, logicalTop + 1); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2110 | } |
| 2111 | if (floatingObject->originatingLine()) { |
| 2112 | if (!selfNeedsLayout()) { |
| 2113 | ASSERT(&floatingObject->originatingLine()->renderer() == this); |
| 2114 | floatingObject->originatingLine()->markDirty(); |
| 2115 | } |
| 2116 | #if !ASSERT_DISABLED |
| 2117 | floatingObject->setOriginatingLine(0); |
| 2118 | #endif |
| 2119 | } |
| 2120 | markLinesDirtyInBlockRange(0, logicalBottom); |
| 2121 | } |
| 2122 | m_floatingObjects->remove(floatingObject); |
| 2123 | } |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | void RenderBlockFlow::removeFloatingObjectsBelow(FloatingObject* lastFloat, int logicalOffset) |
| 2128 | { |
| 2129 | if (!containsFloats()) |
| 2130 | return; |
| 2131 | |
| 2132 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2133 | FloatingObject* curr = floatingObjectSet.last().get(); |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2134 | while (curr != lastFloat && (!curr->isPlaced() || logicalTopForFloat(curr) >= logicalOffset)) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2135 | m_floatingObjects->remove(curr); |
| 2136 | if (floatingObjectSet.isEmpty()) |
| 2137 | break; |
| 2138 | curr = floatingObjectSet.last().get(); |
| 2139 | } |
| 2140 | } |
| 2141 | |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2142 | LayoutUnit RenderBlockFlow::logicalLeftOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const |
| 2143 | { |
| 2144 | LayoutUnit offset = fixedOffset; |
| 2145 | if (m_floatingObjects && m_floatingObjects->hasLeftObjects()) |
| 2146 | offset = m_floatingObjects->logicalLeftOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining); |
| 2147 | return adjustLogicalLeftOffsetForLine(offset, applyTextIndent); |
| 2148 | } |
| 2149 | |
| 2150 | LayoutUnit RenderBlockFlow::logicalRightOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const |
| 2151 | { |
| 2152 | LayoutUnit offset = fixedOffset; |
| 2153 | if (m_floatingObjects && m_floatingObjects->hasRightObjects()) |
| 2154 | offset = m_floatingObjects->logicalRightOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining); |
| 2155 | return adjustLogicalRightOffsetForLine(offset, applyTextIndent); |
| 2156 | } |
| 2157 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2158 | LayoutPoint RenderBlockFlow::computeLogicalLocationForFloat(const FloatingObject* floatingObject, LayoutUnit logicalTopOffset) const |
| 2159 | { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2160 | RenderBox& childBox = floatingObject->renderer(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2161 | LayoutUnit logicalLeftOffset = logicalLeftOffsetForContent(logicalTopOffset); // Constant part of left offset. |
| 2162 | LayoutUnit logicalRightOffset; // Constant part of right offset. |
dino@apple.com | c133a8c | 2014-02-03 23:35:34 +0000 | [diff] [blame] | 2163 | #if ENABLE(CSS_SHAPES) && ENABLE(CSS_SHAPE_INSIDE) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2164 | // FIXME Bug 102948: This only works for shape outside directly set on this block. |
| 2165 | ShapeInsideInfo* shapeInsideInfo = this->layoutShapeInsideInfo(); |
| 2166 | // FIXME: Implement behavior for right floats. |
| 2167 | if (shapeInsideInfo) { |
zoltan@webkit.org | b64932a | 2013-10-11 21:01:40 +0000 | [diff] [blame] | 2168 | LayoutSize floatLogicalSize = logicalSizeForFloat(floatingObject); |
| 2169 | // floatingObject's logicalSize doesn't contain the actual height at this point, so we need to calculate it |
| 2170 | floatLogicalSize.setHeight(logicalHeightForChild(childBox) + marginBeforeForChild(childBox) + marginAfterForChild(childBox)); |
| 2171 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2172 | // FIXME: If the float doesn't fit in the shape we should push it under the content box |
| 2173 | logicalTopOffset = shapeInsideInfo->computeFirstFitPositionForFloat(floatLogicalSize); |
| 2174 | if (logicalHeight() > logicalTopOffset) |
| 2175 | logicalTopOffset = logicalHeight(); |
| 2176 | |
zoltan@webkit.org | b64932a | 2013-10-11 21:01:40 +0000 | [diff] [blame] | 2177 | SegmentList segments = shapeInsideInfo->computeSegmentsForLine(logicalTopOffset, floatLogicalSize.height()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2178 | // FIXME Bug 102949: Add support for shapes with multiple segments. |
| 2179 | if (segments.size() == 1) { |
| 2180 | // The segment offsets are relative to the content box. |
| 2181 | logicalRightOffset = logicalLeftOffset + segments[0].logicalRight; |
| 2182 | logicalLeftOffset += segments[0].logicalLeft; |
| 2183 | } |
| 2184 | } else |
| 2185 | #endif |
| 2186 | logicalRightOffset = logicalRightOffsetForContent(logicalTopOffset); |
| 2187 | |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2188 | 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] | 2189 | |
| 2190 | LayoutUnit floatLogicalLeft; |
| 2191 | |
| 2192 | bool insideFlowThread = flowThreadContainingBlock(); |
| 2193 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2194 | if (childBox.style().floating() == LeftFloat) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2195 | LayoutUnit heightRemainingLeft = 1; |
| 2196 | LayoutUnit heightRemainingRight = 1; |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2197 | floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft); |
| 2198 | while (logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight) - floatLogicalLeft < floatLogicalWidth) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2199 | logicalTopOffset += std::min(heightRemainingLeft, heightRemainingRight); |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2200 | floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2201 | if (insideFlowThread) { |
| 2202 | // Have to re-evaluate all of our offsets, since they may have changed. |
| 2203 | logicalRightOffset = logicalRightOffsetForContent(logicalTopOffset); // Constant part of right offset. |
| 2204 | logicalLeftOffset = logicalLeftOffsetForContent(logicalTopOffset); // Constant part of left offset. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2205 | floatLogicalWidth = std::min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2206 | } |
| 2207 | } |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2208 | floatLogicalLeft = std::max(logicalLeftOffset - borderAndPaddingLogicalLeft(), floatLogicalLeft); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2209 | } else { |
| 2210 | LayoutUnit heightRemainingLeft = 1; |
| 2211 | LayoutUnit heightRemainingRight = 1; |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2212 | floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight); |
| 2213 | while (floatLogicalLeft - logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft) < floatLogicalWidth) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2214 | logicalTopOffset += std::min(heightRemainingLeft, heightRemainingRight); |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2215 | floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2216 | if (insideFlowThread) { |
| 2217 | // Have to re-evaluate all of our offsets, since they may have changed. |
| 2218 | logicalRightOffset = logicalRightOffsetForContent(logicalTopOffset); // Constant part of right offset. |
| 2219 | logicalLeftOffset = logicalLeftOffsetForContent(logicalTopOffset); // Constant part of left offset. |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2220 | floatLogicalWidth = std::min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2221 | } |
| 2222 | } |
| 2223 | // Use the original width of the float here, since the local variable |
| 2224 | // |floatLogicalWidth| was capped to the available line width. See |
| 2225 | // fast/block/float/clamped-right-float.html. |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2226 | floatLogicalLeft -= logicalWidthForFloat(floatingObject); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | return LayoutPoint(floatLogicalLeft, logicalTopOffset); |
| 2230 | } |
| 2231 | |
| 2232 | bool RenderBlockFlow::positionNewFloats() |
| 2233 | { |
| 2234 | if (!m_floatingObjects) |
| 2235 | return false; |
| 2236 | |
| 2237 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2238 | if (floatingObjectSet.isEmpty()) |
| 2239 | return false; |
| 2240 | |
| 2241 | // If all floats have already been positioned, then we have no work to do. |
| 2242 | if (floatingObjectSet.last()->isPlaced()) |
| 2243 | return false; |
| 2244 | |
| 2245 | // Move backwards through our floating object list until we find a float that has |
| 2246 | // already been positioned. Then we'll be able to move forward, positioning all of |
| 2247 | // the new floats that need it. |
| 2248 | auto it = floatingObjectSet.end(); |
| 2249 | --it; // Go to last item. |
| 2250 | auto begin = floatingObjectSet.begin(); |
| 2251 | FloatingObject* lastPlacedFloatingObject = 0; |
| 2252 | while (it != begin) { |
| 2253 | --it; |
| 2254 | if ((*it)->isPlaced()) { |
| 2255 | lastPlacedFloatingObject = it->get(); |
| 2256 | ++it; |
| 2257 | break; |
| 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | LayoutUnit logicalTop = logicalHeight(); |
| 2262 | |
| 2263 | // The float cannot start above the top position of the last positioned float. |
| 2264 | if (lastPlacedFloatingObject) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2265 | logicalTop = std::max(logicalTopForFloat(lastPlacedFloatingObject), logicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2266 | |
| 2267 | auto end = floatingObjectSet.end(); |
| 2268 | // Now walk through the set of unpositioned floats and place them. |
| 2269 | for (; it != end; ++it) { |
| 2270 | FloatingObject* floatingObject = it->get(); |
| 2271 | // The containing block is responsible for positioning floats, so if we have floats in our |
| 2272 | // list that come from somewhere else, do not attempt to position them. |
| 2273 | if (floatingObject->renderer().containingBlock() != this) |
| 2274 | continue; |
| 2275 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2276 | RenderBox& childBox = floatingObject->renderer(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2277 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2278 | LayoutUnit childLogicalLeftMargin = style().isLeftToRightDirection() ? marginStartForChild(childBox) : marginEndForChild(childBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2279 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2280 | LayoutRect oldRect = childBox.frameRect(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2281 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2282 | if (childBox.style().clear() & CLEFT) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2283 | logicalTop = std::max(lowestFloatLogicalBottom(FloatingObject::FloatLeft), logicalTop); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2284 | if (childBox.style().clear() & CRIGHT) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2285 | logicalTop = std::max(lowestFloatLogicalBottom(FloatingObject::FloatRight), logicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2286 | |
| 2287 | LayoutPoint floatLogicalLocation = computeLogicalLocationForFloat(floatingObject, logicalTop); |
| 2288 | |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2289 | setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2290 | |
| 2291 | setLogicalLeftForChild(childBox, floatLogicalLocation.x() + childLogicalLeftMargin); |
| 2292 | setLogicalTopForChild(childBox, floatLogicalLocation.y() + marginBeforeForChild(childBox)); |
| 2293 | |
| 2294 | estimateRegionRangeForBoxChild(childBox); |
| 2295 | |
| 2296 | LayoutState* layoutState = view().layoutState(); |
| 2297 | bool isPaginated = layoutState->isPaginated(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2298 | if (isPaginated && !childBox.needsLayout()) |
| 2299 | childBox.markForPaginationRelayoutIfNeeded(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2300 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2301 | childBox.layoutIfNeeded(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2302 | |
| 2303 | if (isPaginated) { |
| 2304 | // If we are unsplittable and don't fit, then we need to move down. |
| 2305 | // We include our margins as part of the unsplittable area. |
| 2306 | LayoutUnit newLogicalTop = adjustForUnsplittableChild(childBox, floatLogicalLocation.y(), true); |
| 2307 | |
| 2308 | // See if we have a pagination strut that is making us move down further. |
| 2309 | // Note that an unsplittable child can't also have a pagination strut, so this is |
| 2310 | // exclusive with the case above. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2311 | RenderBlock* childBlock = childBox.isRenderBlock() ? toRenderBlock(&childBox) : nullptr; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2312 | if (childBlock && childBlock->paginationStrut()) { |
| 2313 | newLogicalTop += childBlock->paginationStrut(); |
| 2314 | childBlock->setPaginationStrut(0); |
| 2315 | } |
| 2316 | |
| 2317 | if (newLogicalTop != floatLogicalLocation.y()) { |
| 2318 | floatingObject->setPaginationStrut(newLogicalTop - floatLogicalLocation.y()); |
| 2319 | |
| 2320 | floatLogicalLocation = computeLogicalLocationForFloat(floatingObject, newLogicalTop); |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2321 | setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2322 | |
| 2323 | setLogicalLeftForChild(childBox, floatLogicalLocation.x() + childLogicalLeftMargin); |
| 2324 | setLogicalTopForChild(childBox, floatLogicalLocation.y() + marginBeforeForChild(childBox)); |
| 2325 | |
| 2326 | if (childBlock) |
| 2327 | childBlock->setChildNeedsLayout(MarkOnlyThis); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2328 | childBox.layoutIfNeeded(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | if (updateRegionRangeForBoxChild(childBox)) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2332 | childBox.setNeedsLayout(MarkOnlyThis); |
| 2333 | childBox.layoutIfNeeded(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2334 | } |
| 2335 | } |
| 2336 | |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2337 | setLogicalTopForFloat(floatingObject, floatLogicalLocation.y()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2338 | |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2339 | setLogicalHeightForFloat(floatingObject, logicalHeightForChild(childBox) + marginBeforeForChild(childBox) + marginAfterForChild(childBox)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2340 | |
| 2341 | m_floatingObjects->addPlacedObject(floatingObject); |
| 2342 | |
zoltan@webkit.org | 0faf572 | 2013-11-05 02:34:16 +0000 | [diff] [blame] | 2343 | #if ENABLE(CSS_SHAPES) |
| 2344 | if (ShapeOutsideInfo* shapeOutside = childBox.shapeOutsideInfo()) |
| 2345 | shapeOutside->setShapeSize(logicalWidthForChild(childBox), logicalHeightForChild(childBox)); |
| 2346 | #endif |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2347 | // If the child moved, we have to repaint it. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2348 | if (childBox.checkForRepaintDuringLayout()) |
| 2349 | childBox.repaintDuringLayoutIfMoved(oldRect); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2350 | } |
| 2351 | return true; |
| 2352 | } |
| 2353 | |
| 2354 | void RenderBlockFlow::newLine(EClear clear) |
| 2355 | { |
| 2356 | positionNewFloats(); |
| 2357 | // set y position |
| 2358 | LayoutUnit newY = 0; |
| 2359 | switch (clear) { |
| 2360 | case CLEFT: |
| 2361 | newY = lowestFloatLogicalBottom(FloatingObject::FloatLeft); |
| 2362 | break; |
| 2363 | case CRIGHT: |
| 2364 | newY = lowestFloatLogicalBottom(FloatingObject::FloatRight); |
| 2365 | break; |
| 2366 | case CBOTH: |
| 2367 | newY = lowestFloatLogicalBottom(); |
joepeck@webkit.org | aa676ee5 | 2014-01-28 04:04:52 +0000 | [diff] [blame] | 2368 | break; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2369 | default: |
| 2370 | break; |
| 2371 | } |
| 2372 | if (height() < newY) |
| 2373 | setLogicalHeight(newY); |
| 2374 | } |
| 2375 | |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2376 | LayoutUnit RenderBlockFlow::logicalLeftFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2377 | { |
| 2378 | if (m_floatingObjects && m_floatingObjects->hasLeftObjects()) |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2379 | return m_floatingObjects->logicalLeftOffset(fixedOffset, logicalTop, logicalHeight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2380 | |
| 2381 | return fixedOffset; |
| 2382 | } |
| 2383 | |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2384 | LayoutUnit RenderBlockFlow::logicalRightFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2385 | { |
| 2386 | if (m_floatingObjects && m_floatingObjects->hasRightObjects()) |
bjonesbe@adobe.com | 98b899b | 2013-11-07 18:11:43 +0000 | [diff] [blame] | 2387 | return m_floatingObjects->logicalRightOffset(fixedOffset, logicalTop, logicalHeight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2388 | |
| 2389 | return fixedOffset; |
| 2390 | } |
| 2391 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2392 | LayoutUnit RenderBlockFlow::nextFloatLogicalBottomBelow(LayoutUnit logicalHeight) const |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2393 | { |
| 2394 | if (!m_floatingObjects) |
| 2395 | return logicalHeight; |
| 2396 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2397 | return m_floatingObjects->findNextFloatLogicalBottomBelow(logicalHeight); |
| 2398 | } |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2399 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2400 | LayoutUnit RenderBlockFlow::nextFloatLogicalBottomBelowForBlock(LayoutUnit logicalHeight) const |
| 2401 | { |
| 2402 | if (!m_floatingObjects) |
| 2403 | return logicalHeight; |
| 2404 | |
| 2405 | return m_floatingObjects->findNextFloatLogicalBottomBelowForBlock(logicalHeight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | LayoutUnit RenderBlockFlow::lowestFloatLogicalBottom(FloatingObject::Type floatType) const |
| 2409 | { |
| 2410 | if (!m_floatingObjects) |
| 2411 | return 0; |
| 2412 | LayoutUnit lowestFloatBottom = 0; |
| 2413 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2414 | auto end = floatingObjectSet.end(); |
| 2415 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 2416 | FloatingObject* floatingObject = it->get(); |
| 2417 | if (floatingObject->isPlaced() && floatingObject->type() & floatType) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2418 | lowestFloatBottom = std::max(lowestFloatBottom, logicalBottomForFloat(floatingObject)); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2419 | } |
| 2420 | return lowestFloatBottom; |
| 2421 | } |
| 2422 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2423 | LayoutUnit RenderBlockFlow::addOverhangingFloats(RenderBlockFlow& child, bool makeChildPaintOtherFloats) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2424 | { |
| 2425 | // Prevent floats from being added to the canvas by the root element, e.g., <html>. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2426 | if (child.hasOverflowClip() || !child.containsFloats() || child.isRoot() || child.hasColumns() || child.isWritingModeRoot()) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2427 | return 0; |
| 2428 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2429 | LayoutUnit childLogicalTop = child.logicalTop(); |
| 2430 | LayoutUnit childLogicalLeft = child.logicalLeft(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2431 | LayoutUnit lowestFloatLogicalBottom = 0; |
| 2432 | |
| 2433 | // Floats that will remain the child's responsibility to paint should factor into its |
| 2434 | // overflow. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2435 | auto childEnd = child.m_floatingObjects->set().end(); |
| 2436 | for (auto childIt = child.m_floatingObjects->set().begin(); childIt != childEnd; ++childIt) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2437 | FloatingObject* floatingObject = childIt->get(); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2438 | LayoutUnit floatLogicalBottom = std::min(logicalBottomForFloat(floatingObject), LayoutUnit::max() - childLogicalTop); |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2439 | LayoutUnit logicalBottom = childLogicalTop + floatLogicalBottom; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2440 | lowestFloatLogicalBottom = std::max(lowestFloatLogicalBottom, logicalBottom); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2441 | |
| 2442 | if (logicalBottom > logicalHeight()) { |
| 2443 | // If the object is not in the list, we add it now. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2444 | if (!containsFloat(floatingObject->renderer())) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2445 | LayoutSize offset = isHorizontalWritingMode() ? LayoutSize(-childLogicalLeft, -childLogicalTop) : LayoutSize(-childLogicalTop, -childLogicalLeft); |
| 2446 | bool shouldPaint = false; |
| 2447 | |
| 2448 | // The nearest enclosing layer always paints the float (so that zindex and stacking |
| 2449 | // behaves properly). We always want to propagate the desire to paint the float as |
| 2450 | // far out as we can, to the outermost block that overlaps the float, stopping only |
| 2451 | // if we hit a self-painting layer boundary. |
| 2452 | if (floatingObject->renderer().enclosingFloatPaintingLayer() == enclosingFloatPaintingLayer()) { |
| 2453 | floatingObject->setShouldPaint(false); |
| 2454 | shouldPaint = true; |
| 2455 | } |
| 2456 | // We create the floating object list lazily. |
| 2457 | if (!m_floatingObjects) |
| 2458 | createFloatingObjects(); |
| 2459 | |
| 2460 | m_floatingObjects->add(floatingObject->copyToNewContainer(offset, shouldPaint, true)); |
| 2461 | } |
| 2462 | } else { |
| 2463 | if (makeChildPaintOtherFloats && !floatingObject->shouldPaint() && !floatingObject->renderer().hasSelfPaintingLayer() |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2464 | && floatingObject->renderer().isDescendantOf(&child) && floatingObject->renderer().enclosingFloatPaintingLayer() == child.enclosingFloatPaintingLayer()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2465 | // The float is not overhanging from this block, so if it is a descendant of the child, the child should |
| 2466 | // paint it (the other case is that it is intruding into the child), unless it has its own layer or enclosing |
| 2467 | // layer. |
| 2468 | // If makeChildPaintOtherFloats is false, it means that the child must already know about all the floats |
| 2469 | // it should paint. |
| 2470 | floatingObject->setShouldPaint(true); |
| 2471 | } |
| 2472 | |
| 2473 | // Since the float doesn't overhang, it didn't get put into our list. We need to go ahead and add its overflow in to the |
| 2474 | // child now. |
| 2475 | if (floatingObject->isDescendant()) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2476 | child.addOverflowFromChild(&floatingObject->renderer(), LayoutSize(xPositionForFloatIncludingMargin(floatingObject), yPositionForFloatIncludingMargin(floatingObject))); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | return lowestFloatLogicalBottom; |
| 2480 | } |
| 2481 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2482 | bool RenderBlockFlow::hasOverhangingFloat(RenderBox& renderer) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2483 | { |
| 2484 | if (!m_floatingObjects || hasColumns() || !parent()) |
| 2485 | return false; |
| 2486 | |
| 2487 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2488 | auto it = floatingObjectSet.find<RenderBox&, FloatingObjectHashTranslator>(renderer); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2489 | if (it == floatingObjectSet.end()) |
| 2490 | return false; |
| 2491 | |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2492 | return logicalBottomForFloat(it->get()) > logicalHeight(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | void RenderBlockFlow::addIntrudingFloats(RenderBlockFlow* prev, LayoutUnit logicalLeftOffset, LayoutUnit logicalTopOffset) |
| 2496 | { |
| 2497 | ASSERT(!avoidsFloats()); |
| 2498 | |
| 2499 | // If the parent or previous sibling doesn't have any floats to add, don't bother. |
| 2500 | if (!prev->m_floatingObjects) |
| 2501 | return; |
| 2502 | |
| 2503 | logicalLeftOffset += marginLogicalLeft(); |
| 2504 | |
| 2505 | const FloatingObjectSet& prevSet = prev->m_floatingObjects->set(); |
| 2506 | auto prevEnd = prevSet.end(); |
| 2507 | for (auto prevIt = prevSet.begin(); prevIt != prevEnd; ++prevIt) { |
| 2508 | FloatingObject* floatingObject = prevIt->get(); |
bjonesbe@adobe.com | 1ccd3a1 | 2013-10-10 00:35:38 +0000 | [diff] [blame] | 2509 | if (logicalBottomForFloat(floatingObject) > logicalTopOffset) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2510 | if (!m_floatingObjects || !m_floatingObjects->set().contains<FloatingObject&, FloatingObjectHashTranslator>(*floatingObject)) { |
| 2511 | // We create the floating object list lazily. |
| 2512 | if (!m_floatingObjects) |
| 2513 | createFloatingObjects(); |
| 2514 | |
| 2515 | // Applying the child's margin makes no sense in the case where the child was passed in. |
| 2516 | // since this margin was added already through the modification of the |logicalLeftOffset| variable |
| 2517 | // above. |logicalLeftOffset| will equal the margin in this case, so it's already been taken |
| 2518 | // into account. Only apply this code if prev is the parent, since otherwise the left margin |
| 2519 | // will get applied twice. |
| 2520 | LayoutSize offset = isHorizontalWritingMode() |
| 2521 | ? LayoutSize(logicalLeftOffset - (prev != parent() ? prev->marginLeft() : LayoutUnit()), logicalTopOffset) |
| 2522 | : LayoutSize(logicalTopOffset, logicalLeftOffset - (prev != parent() ? prev->marginTop() : LayoutUnit())); |
| 2523 | |
| 2524 | m_floatingObjects->add(floatingObject->copyToNewContainer(offset)); |
| 2525 | } |
| 2526 | } |
| 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | void RenderBlockFlow::markAllDescendantsWithFloatsForLayout(RenderBox* floatToRemove, bool inLayout) |
| 2531 | { |
| 2532 | if (!everHadLayout() && !containsFloats()) |
| 2533 | return; |
| 2534 | |
| 2535 | MarkingBehavior markParents = inLayout ? MarkOnlyThis : MarkContainingBlockChain; |
| 2536 | setChildNeedsLayout(markParents); |
| 2537 | |
| 2538 | if (floatToRemove) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2539 | removeFloatingObject(*floatToRemove); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2540 | |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2541 | if (childrenInline()) |
| 2542 | return; |
| 2543 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2544 | // Iterate over our children and mark them as needed. |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2545 | for (auto& block : childrenOfType<RenderBlock>(*this)) { |
| 2546 | if (!floatToRemove && block.isFloatingOrOutOfFlowPositioned()) |
| 2547 | continue; |
| 2548 | if (!block.isRenderBlockFlow()) { |
| 2549 | if (block.shrinkToAvoidFloats() && block.everHadLayout()) |
| 2550 | block.setChildNeedsLayout(markParents); |
| 2551 | continue; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2552 | } |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2553 | auto& blockFlow = toRenderBlockFlow(block); |
| 2554 | if ((floatToRemove ? blockFlow.containsFloat(*floatToRemove) : blockFlow.containsFloats()) || blockFlow.shrinkToAvoidFloats()) |
| 2555 | blockFlow.markAllDescendantsWithFloatsForLayout(floatToRemove, inLayout); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2556 | } |
| 2557 | } |
| 2558 | |
| 2559 | void RenderBlockFlow::markSiblingsWithFloatsForLayout(RenderBox* floatToRemove) |
| 2560 | { |
| 2561 | if (!m_floatingObjects) |
| 2562 | return; |
| 2563 | |
| 2564 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2565 | auto end = floatingObjectSet.end(); |
| 2566 | |
| 2567 | for (RenderObject* next = nextSibling(); next; next = next->nextSibling()) { |
| 2568 | if (!next->isRenderBlockFlow() || next->isFloatingOrOutOfFlowPositioned() || toRenderBlock(next)->avoidsFloats()) |
| 2569 | continue; |
| 2570 | |
| 2571 | RenderBlockFlow* nextBlock = toRenderBlockFlow(next); |
| 2572 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2573 | RenderBox& floatingBox = (*it)->renderer(); |
| 2574 | if (floatToRemove && &floatingBox != floatToRemove) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2575 | continue; |
| 2576 | if (nextBlock->containsFloat(floatingBox)) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2577 | nextBlock->markAllDescendantsWithFloatsForLayout(&floatingBox); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | } |
| 2581 | |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 2582 | LayoutPoint RenderBlockFlow::flipFloatForWritingModeForChild(const FloatingObject* child, const LayoutPoint& point) const |
| 2583 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2584 | if (!style().isFlippedBlocksWritingMode()) |
weinig@apple.com | 31324fd | 2013-10-28 19:22:51 +0000 | [diff] [blame] | 2585 | return point; |
| 2586 | |
| 2587 | // This is similar to RenderBox::flipForWritingModeForChild. We have to subtract out our left/top offsets twice, since |
| 2588 | // it's going to get added back in. We hide this complication here so that the calling code looks normal for the unflipped |
| 2589 | // case. |
| 2590 | if (isHorizontalWritingMode()) |
| 2591 | return LayoutPoint(point.x(), point.y() + height() - child->renderer().height() - 2 * yPositionForFloatIncludingMargin(child)); |
| 2592 | return LayoutPoint(point.x() + width() - child->renderer().width() - 2 * xPositionForFloatIncludingMargin(child), point.y()); |
| 2593 | } |
| 2594 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2595 | LayoutUnit RenderBlockFlow::getClearDelta(RenderBox& child, LayoutUnit logicalTop) |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2596 | { |
| 2597 | // There is no need to compute clearance if we have no floats. |
| 2598 | if (!containsFloats()) |
| 2599 | return 0; |
| 2600 | |
| 2601 | // 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] | 2602 | bool clearSet = child.style().clear() != CNONE; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2603 | LayoutUnit logicalBottom = 0; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2604 | switch (child.style().clear()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2605 | case CNONE: |
| 2606 | break; |
| 2607 | case CLEFT: |
| 2608 | logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatLeft); |
| 2609 | break; |
| 2610 | case CRIGHT: |
| 2611 | logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatRight); |
| 2612 | break; |
| 2613 | case CBOTH: |
| 2614 | logicalBottom = lowestFloatLogicalBottom(); |
| 2615 | break; |
| 2616 | } |
| 2617 | |
| 2618 | // 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] | 2619 | LayoutUnit result = clearSet ? std::max<LayoutUnit>(0, logicalBottom - logicalTop) : LayoutUnit(); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2620 | if (!result && child.avoidsFloats()) { |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2621 | LayoutUnit newLogicalTop = logicalTop; |
| 2622 | while (true) { |
| 2623 | LayoutUnit availableLogicalWidthAtNewLogicalTopOffset = availableLogicalWidthForLine(newLogicalTop, false, logicalHeightForChild(child)); |
| 2624 | if (availableLogicalWidthAtNewLogicalTopOffset == availableLogicalWidthForContent(newLogicalTop)) |
| 2625 | return newLogicalTop - logicalTop; |
| 2626 | |
| 2627 | RenderRegion* region = regionAtBlockOffset(logicalTopForChild(child)); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2628 | LayoutRect borderBox = child.borderBoxRectInRegion(region, DoNotCacheRenderBoxRegionInfo); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2629 | LayoutUnit childLogicalWidthAtOldLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height(); |
| 2630 | |
| 2631 | // FIXME: None of this is right for perpendicular writing-mode children. |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2632 | LayoutUnit childOldLogicalWidth = child.logicalWidth(); |
| 2633 | LayoutUnit childOldMarginLeft = child.marginLeft(); |
| 2634 | LayoutUnit childOldMarginRight = child.marginRight(); |
| 2635 | LayoutUnit childOldLogicalTop = child.logicalTop(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2636 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2637 | child.setLogicalTop(newLogicalTop); |
| 2638 | child.updateLogicalWidth(); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2639 | region = regionAtBlockOffset(logicalTopForChild(child)); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2640 | borderBox = child.borderBoxRectInRegion(region, DoNotCacheRenderBoxRegionInfo); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2641 | LayoutUnit childLogicalWidthAtNewLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height(); |
| 2642 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2643 | child.setLogicalTop(childOldLogicalTop); |
| 2644 | child.setLogicalWidth(childOldLogicalWidth); |
| 2645 | child.setMarginLeft(childOldMarginLeft); |
| 2646 | child.setMarginRight(childOldMarginRight); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2647 | |
| 2648 | if (childLogicalWidthAtNewLogicalTopOffset <= availableLogicalWidthAtNewLogicalTopOffset) { |
| 2649 | // Even though we may not be moving, if the logical width did shrink because of the presence of new floats, then |
| 2650 | // we need to force a relayout as though we shifted. This happens because of the dynamic addition of overhanging floats |
| 2651 | // from previous siblings when negative margins exist on a child (see the addOverhangingFloats call at the end of collapseMargins). |
| 2652 | if (childLogicalWidthAtOldLogicalTopOffset != childLogicalWidthAtNewLogicalTopOffset) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2653 | child.setChildNeedsLayout(MarkOnlyThis); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2654 | return newLogicalTop - logicalTop; |
| 2655 | } |
| 2656 | |
bjonesbe@adobe.com | edea342 | 2013-11-08 22:01:33 +0000 | [diff] [blame] | 2657 | newLogicalTop = nextFloatLogicalBottomBelowForBlock(newLogicalTop); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2658 | ASSERT(newLogicalTop >= logicalTop); |
| 2659 | if (newLogicalTop < logicalTop) |
| 2660 | break; |
| 2661 | } |
| 2662 | ASSERT_NOT_REACHED(); |
| 2663 | } |
| 2664 | return result; |
| 2665 | } |
| 2666 | |
| 2667 | bool RenderBlockFlow::hitTestFloats(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset) |
| 2668 | { |
| 2669 | if (!m_floatingObjects) |
| 2670 | return false; |
| 2671 | |
| 2672 | LayoutPoint adjustedLocation = accumulatedOffset; |
| 2673 | if (isRenderView()) |
| 2674 | adjustedLocation += toLayoutSize(toRenderView(*this).frameView().scrollPosition()); |
| 2675 | |
| 2676 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2677 | auto begin = floatingObjectSet.begin(); |
| 2678 | for (auto it = floatingObjectSet.end(); it != begin;) { |
| 2679 | --it; |
| 2680 | FloatingObject* floatingObject = it->get(); |
| 2681 | if (floatingObject->shouldPaint() && !floatingObject->renderer().hasSelfPaintingLayer()) { |
| 2682 | LayoutUnit xOffset = xPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer().x(); |
| 2683 | LayoutUnit yOffset = yPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer().y(); |
| 2684 | LayoutPoint childPoint = flipFloatForWritingModeForChild(floatingObject, adjustedLocation + LayoutSize(xOffset, yOffset)); |
| 2685 | if (floatingObject->renderer().hitTest(request, result, locationInContainer, childPoint)) { |
| 2686 | updateHitTestResult(result, locationInContainer.point() - toLayoutSize(childPoint)); |
| 2687 | return true; |
| 2688 | } |
| 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | return false; |
| 2693 | } |
| 2694 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2695 | bool RenderBlockFlow::hitTestInlineChildren(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction) |
| 2696 | { |
| 2697 | ASSERT(childrenInline()); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2698 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 2699 | if (m_simpleLineLayout) |
| 2700 | return SimpleLineLayout::hitTestFlow(*this, *m_simpleLineLayout, request, result, locationInContainer, accumulatedOffset, hitTestAction); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2701 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2702 | return m_lineBoxes.hitTest(this, request, result, locationInContainer, accumulatedOffset, hitTestAction); |
| 2703 | } |
| 2704 | |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2705 | void RenderBlockFlow::adjustForBorderFit(LayoutUnit x, LayoutUnit& left, LayoutUnit& right) const |
| 2706 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2707 | if (style().visibility() != VISIBLE) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2708 | return; |
| 2709 | |
| 2710 | // We don't deal with relative positioning. Our assumption is that you shrink to fit the lines without accounting |
| 2711 | // for either overflow or translations via relative positioning. |
| 2712 | if (childrenInline()) { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2713 | const_cast<RenderBlockFlow&>(*this).ensureLineBoxes(); |
| 2714 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2715 | for (auto box = firstRootBox(); box; box = box->nextRootBox()) { |
| 2716 | if (box->firstChild()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2717 | left = std::min(left, x + static_cast<LayoutUnit>(box->firstChild()->x())); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2718 | if (box->lastChild()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2719 | right = std::max(right, x + static_cast<LayoutUnit>(ceilf(box->lastChild()->logicalRight()))); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2720 | } |
| 2721 | } else { |
| 2722 | for (RenderBox* obj = firstChildBox(); obj; obj = obj->nextSiblingBox()) { |
| 2723 | if (!obj->isFloatingOrOutOfFlowPositioned()) { |
| 2724 | if (obj->isRenderBlockFlow() && !obj->hasOverflowClip()) |
| 2725 | toRenderBlockFlow(obj)->adjustForBorderFit(x + obj->x(), left, right); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2726 | else if (obj->style().visibility() == VISIBLE) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2727 | // 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] | 2728 | left = std::min(left, x + obj->x()); |
| 2729 | right = std::max(right, x + obj->x() + obj->width()); |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2730 | } |
| 2731 | } |
| 2732 | } |
| 2733 | } |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2734 | |
| 2735 | if (m_floatingObjects) { |
| 2736 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 2737 | auto end = floatingObjectSet.end(); |
| 2738 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 2739 | FloatingObject* r = it->get(); |
| 2740 | // Only examine the object if our m_shouldPaint flag is set. |
| 2741 | if (r->shouldPaint()) { |
| 2742 | LayoutUnit floatLeft = xPositionForFloatIncludingMargin(r) - r->renderer().x(); |
| 2743 | LayoutUnit floatRight = floatLeft + r->renderer().width(); |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2744 | left = std::min(left, floatLeft); |
| 2745 | right = std::max(right, floatRight); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2746 | } |
| 2747 | } |
| 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | void RenderBlockFlow::fitBorderToLinesIfNeeded() |
| 2752 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2753 | if (style().borderFit() == BorderFitBorder || hasOverrideWidth()) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2754 | return; |
| 2755 | |
| 2756 | // Walk any normal flow lines to snugly fit. |
| 2757 | LayoutUnit left = LayoutUnit::max(); |
| 2758 | LayoutUnit right = LayoutUnit::min(); |
| 2759 | LayoutUnit oldWidth = contentWidth(); |
| 2760 | adjustForBorderFit(0, left, right); |
| 2761 | |
| 2762 | // Clamp to our existing edges. We can never grow. We only shrink. |
| 2763 | LayoutUnit leftEdge = borderLeft() + paddingLeft(); |
| 2764 | LayoutUnit rightEdge = leftEdge + oldWidth; |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2765 | left = std::min(rightEdge, std::max(leftEdge, left)); |
| 2766 | right = std::max(leftEdge, std::min(rightEdge, right)); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2767 | |
| 2768 | LayoutUnit newContentWidth = right - left; |
| 2769 | if (newContentWidth == oldWidth) |
| 2770 | return; |
| 2771 | |
| 2772 | setOverrideLogicalContentWidth(newContentWidth); |
| 2773 | layoutBlock(false); |
| 2774 | clearOverrideLogicalContentWidth(); |
| 2775 | } |
| 2776 | |
| 2777 | void RenderBlockFlow::markLinesDirtyInBlockRange(LayoutUnit logicalTop, LayoutUnit logicalBottom, RootInlineBox* highest) |
| 2778 | { |
| 2779 | if (logicalTop >= logicalBottom) |
| 2780 | return; |
| 2781 | |
| 2782 | RootInlineBox* lowestDirtyLine = lastRootBox(); |
| 2783 | RootInlineBox* afterLowest = lowestDirtyLine; |
| 2784 | while (lowestDirtyLine && lowestDirtyLine->lineBottomWithLeading() >= logicalBottom && logicalBottom < LayoutUnit::max()) { |
| 2785 | afterLowest = lowestDirtyLine; |
| 2786 | lowestDirtyLine = lowestDirtyLine->prevRootBox(); |
| 2787 | } |
| 2788 | |
| 2789 | while (afterLowest && afterLowest != highest && (afterLowest->lineBottomWithLeading() >= logicalTop || afterLowest->lineBottomWithLeading() < 0)) { |
| 2790 | afterLowest->markDirty(); |
| 2791 | afterLowest = afterLowest->prevRootBox(); |
| 2792 | } |
| 2793 | } |
| 2794 | |
antti@apple.com | 0e632aa | 2013-10-22 21:03:38 +0000 | [diff] [blame] | 2795 | int RenderBlockFlow::firstLineBaseline() const |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2796 | { |
| 2797 | if (isWritingModeRoot() && !isRubyRun()) |
| 2798 | return -1; |
| 2799 | |
| 2800 | if (!childrenInline()) |
antti@apple.com | 0e632aa | 2013-10-22 21:03:38 +0000 | [diff] [blame] | 2801 | return RenderBlock::firstLineBaseline(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2802 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2803 | if (!hasLines()) |
| 2804 | return -1; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2805 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 2806 | if (m_simpleLineLayout) |
| 2807 | return SimpleLineLayout::computeFlowFirstLineBaseline(*this, *m_simpleLineLayout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2808 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 2809 | ASSERT(firstRootBox()); |
| 2810 | return firstRootBox()->logicalTop() + firstLineStyle().fontMetrics().ascent(firstRootBox()->baselineType()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | int RenderBlockFlow::inlineBlockBaseline(LineDirectionMode lineDirection) const |
| 2814 | { |
| 2815 | if (isWritingModeRoot() && !isRubyRun()) |
| 2816 | return -1; |
| 2817 | |
| 2818 | if (!childrenInline()) |
| 2819 | return RenderBlock::inlineBlockBaseline(lineDirection); |
| 2820 | |
antti@apple.com | 0e632aa | 2013-10-22 21:03:38 +0000 | [diff] [blame] | 2821 | if (!hasLines()) { |
| 2822 | if (!hasLineIfEmpty()) |
| 2823 | return -1; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2824 | const FontMetrics& fontMetrics = firstLineStyle().fontMetrics(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2825 | return fontMetrics.ascent() |
| 2826 | + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - fontMetrics.height()) / 2 |
| 2827 | + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : borderRight() + paddingRight()); |
| 2828 | } |
| 2829 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 2830 | if (m_simpleLineLayout) |
| 2831 | return SimpleLineLayout::computeFlowLastLineBaseline(*this, *m_simpleLineLayout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2832 | |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 2833 | bool isFirstLine = lastRootBox() == firstRootBox(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2834 | const RenderStyle& style = isFirstLine ? firstLineStyle() : this->style(); |
akling@apple.com | ee3c8df | 2013-11-06 08:09:44 +0000 | [diff] [blame] | 2835 | return lastRootBox()->logicalTop() + style.fontMetrics().ascent(lastRootBox()->baselineType()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2838 | GapRects RenderBlockFlow::inlineSelectionGaps(RenderBlock& rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2839 | LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const LogicalSelectionOffsetCaches& cache, const PaintInfo* paintInfo) |
| 2840 | { |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 2841 | ASSERT(!m_simpleLineLayout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 2842 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2843 | GapRects result; |
| 2844 | |
| 2845 | bool containsStart = selectionState() == SelectionStart || selectionState() == SelectionBoth; |
| 2846 | |
antti@apple.com | 0e632aa | 2013-10-22 21:03:38 +0000 | [diff] [blame] | 2847 | if (!hasLines()) { |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2848 | if (containsStart) { |
| 2849 | // Go ahead and update our lastLogicalTop to be the bottom of the block. <hr>s or empty blocks with height can trip this |
| 2850 | // case. |
| 2851 | lastLogicalTop = blockDirectionOffset(rootBlock, offsetFromRootBlock) + logicalHeight(); |
| 2852 | lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, logicalHeight(), cache); |
| 2853 | lastLogicalRight = logicalRightSelectionOffset(rootBlock, logicalHeight(), cache); |
| 2854 | } |
| 2855 | return result; |
| 2856 | } |
| 2857 | |
| 2858 | RootInlineBox* lastSelectedLine = 0; |
| 2859 | RootInlineBox* curr; |
| 2860 | for (curr = firstRootBox(); curr && !curr->hasSelectedChildren(); curr = curr->nextRootBox()) { } |
| 2861 | |
| 2862 | // Now paint the gaps for the lines. |
| 2863 | for (; curr && curr->hasSelectedChildren(); curr = curr->nextRootBox()) { |
| 2864 | LayoutUnit selTop = curr->selectionTopAdjustedForPrecedingBlock(); |
| 2865 | LayoutUnit selHeight = curr->selectionHeightAdjustedForPrecedingBlock(); |
| 2866 | |
| 2867 | if (!containsStart && !lastSelectedLine && |
| 2868 | selectionState() != SelectionStart && selectionState() != SelectionBoth) |
| 2869 | result.uniteCenter(blockSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, lastLogicalTop, lastLogicalLeft, lastLogicalRight, selTop, cache, paintInfo)); |
| 2870 | |
| 2871 | LayoutRect logicalRect(curr->logicalLeft(), selTop, curr->logicalWidth(), selTop + selHeight); |
| 2872 | logicalRect.move(isHorizontalWritingMode() ? offsetFromRootBlock : offsetFromRootBlock.transposedSize()); |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 2873 | LayoutRect physicalRect = rootBlock.logicalRectToPhysicalRect(rootBlockPhysicalPosition, logicalRect); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 2874 | if (!paintInfo || (isHorizontalWritingMode() && physicalRect.y() < paintInfo->rect.maxY() && physicalRect.maxY() > paintInfo->rect.y()) |
| 2875 | || (!isHorizontalWritingMode() && physicalRect.x() < paintInfo->rect.maxX() && physicalRect.maxX() > paintInfo->rect.x())) |
| 2876 | result.unite(curr->lineSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, selTop, selHeight, cache, paintInfo)); |
| 2877 | |
| 2878 | lastSelectedLine = curr; |
| 2879 | } |
| 2880 | |
| 2881 | if (containsStart && !lastSelectedLine) |
| 2882 | // VisibleSelection must start just after our last line. |
| 2883 | lastSelectedLine = lastRootBox(); |
| 2884 | |
| 2885 | if (lastSelectedLine && selectionState() != SelectionEnd && selectionState() != SelectionBoth) { |
| 2886 | // Go ahead and update our lastY to be the bottom of the last selected line. |
| 2887 | lastLogicalTop = blockDirectionOffset(rootBlock, offsetFromRootBlock) + lastSelectedLine->selectionBottom(); |
| 2888 | lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, lastSelectedLine->selectionBottom(), cache); |
| 2889 | lastLogicalRight = logicalRightSelectionOffset(rootBlock, lastSelectedLine->selectionBottom(), cache); |
| 2890 | } |
| 2891 | return result; |
bjonesbe@adobe.com | 2419975 | 2013-10-08 23:20:42 +0000 | [diff] [blame] | 2892 | } |
| 2893 | |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 2894 | void RenderBlockFlow::createRenderNamedFlowFragmentIfNeeded() |
| 2895 | { |
abucur@adobe.com | 0e81bc7 | 2013-10-22 14:50:37 +0000 | [diff] [blame] | 2896 | if (!document().cssRegionsEnabled() || renderNamedFlowFragment() || isRenderNamedFlowFragment()) |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 2897 | return; |
| 2898 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2899 | if (style().isDisplayRegionType() && style().hasFlowFrom()) { |
| 2900 | RenderNamedFlowFragment* flowFragment = new RenderNamedFlowFragment(document(), RenderNamedFlowFragment::createStyle(style())); |
akling@apple.com | 8f40c5b | 2013-10-27 22:54:07 +0000 | [diff] [blame] | 2901 | flowFragment->initializeStyle(); |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 2902 | setRenderNamedFlowFragment(flowFragment); |
| 2903 | addChild(renderNamedFlowFragment()); |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | bool RenderBlockFlow::canHaveChildren() const |
| 2908 | { |
| 2909 | return !renderNamedFlowFragment() ? RenderBlock::canHaveChildren() : renderNamedFlowFragment()->canHaveChildren(); |
| 2910 | } |
| 2911 | |
| 2912 | bool RenderBlockFlow::canHaveGeneratedChildren() const |
| 2913 | { |
| 2914 | return !renderNamedFlowFragment() ? RenderBlock::canHaveGeneratedChildren() : renderNamedFlowFragment()->canHaveGeneratedChildren(); |
| 2915 | } |
| 2916 | |
| 2917 | bool RenderBlockFlow::namedFlowFragmentNeedsUpdate() const |
| 2918 | { |
| 2919 | if (!isRenderNamedFlowFragmentContainer()) |
| 2920 | return false; |
| 2921 | |
| 2922 | return hasRelativeLogicalHeight() && !isRenderView(); |
| 2923 | } |
| 2924 | |
| 2925 | void RenderBlockFlow::updateLogicalHeight() |
| 2926 | { |
| 2927 | RenderBlock::updateLogicalHeight(); |
| 2928 | |
| 2929 | if (renderNamedFlowFragment()) |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 2930 | renderNamedFlowFragment()->setLogicalHeight(std::max<LayoutUnit>(0, logicalHeight() - borderAndPaddingLogicalHeight())); |
mihnea@adobe.com | be79cf1 | 2013-10-17 09:02:19 +0000 | [diff] [blame] | 2931 | } |
| 2932 | |
| 2933 | void RenderBlockFlow::setRenderNamedFlowFragment(RenderNamedFlowFragment* flowFragment) |
| 2934 | { |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 2935 | RenderBlockFlowRareData& rareData = ensureRareBlockFlowData(); |
abucur@adobe.com | 0e81bc7 | 2013-10-22 14:50:37 +0000 | [diff] [blame] | 2936 | if (rareData.m_renderNamedFlowFragment) |
| 2937 | rareData.m_renderNamedFlowFragment->destroy(); |
| 2938 | rareData.m_renderNamedFlowFragment = flowFragment; |
| 2939 | } |
| 2940 | |
hyatt@apple.com | e9fe3d3 | 2014-01-24 17:14:22 +0000 | [diff] [blame] | 2941 | void RenderBlockFlow::setMultiColumnFlowThread(RenderMultiColumnFlowThread* flowThread) |
| 2942 | { |
| 2943 | RenderBlockFlowRareData& rareData = ensureRareBlockFlowData(); |
| 2944 | rareData.m_multiColumnFlowThread = flowThread; |
| 2945 | } |
| 2946 | |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2947 | static bool shouldCheckLines(const RenderBlockFlow& blockFlow) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 2948 | { |
akling@apple.com | 38f0a65 | 2014-02-06 21:24:17 +0000 | [diff] [blame] | 2949 | return !blockFlow.isFloatingOrOutOfFlowPositioned() && blockFlow.style().height().isAuto(); |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | RootInlineBox* RenderBlockFlow::lineAtIndex(int i) const |
| 2953 | { |
| 2954 | ASSERT(i >= 0); |
| 2955 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2956 | if (style().visibility() != VISIBLE) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 2957 | return nullptr; |
| 2958 | |
| 2959 | if (childrenInline()) { |
| 2960 | for (auto box = firstRootBox(); box; box = box->nextRootBox()) { |
| 2961 | if (!i--) |
| 2962 | return box; |
| 2963 | } |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2964 | return nullptr; |
| 2965 | } |
| 2966 | |
| 2967 | for (auto& blockFlow : childrenOfType<RenderBlockFlow>(*this)) { |
| 2968 | if (!shouldCheckLines(blockFlow)) |
| 2969 | continue; |
| 2970 | if (RootInlineBox* box = blockFlow.lineAtIndex(i)) |
| 2971 | return box; |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | return nullptr; |
| 2975 | } |
| 2976 | |
| 2977 | int RenderBlockFlow::lineCount(const RootInlineBox* stopRootInlineBox, bool* found) const |
| 2978 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 2979 | if (style().visibility() != VISIBLE) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 2980 | return 0; |
| 2981 | |
| 2982 | int count = 0; |
| 2983 | |
| 2984 | if (childrenInline()) { |
| 2985 | for (auto box = firstRootBox(); box; box = box->nextRootBox()) { |
| 2986 | count++; |
| 2987 | if (box == stopRootInlineBox) { |
| 2988 | if (found) |
| 2989 | *found = true; |
| 2990 | break; |
| 2991 | } |
| 2992 | } |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 2993 | return count; |
| 2994 | } |
| 2995 | |
| 2996 | for (auto& blockFlow : childrenOfType<RenderBlockFlow>(*this)) { |
| 2997 | if (!shouldCheckLines(blockFlow)) |
| 2998 | continue; |
| 2999 | bool recursiveFound = false; |
| 3000 | count += blockFlow.lineCount(stopRootInlineBox, &recursiveFound); |
| 3001 | if (recursiveFound) { |
| 3002 | if (found) |
| 3003 | *found = true; |
| 3004 | break; |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | return count; |
| 3009 | } |
| 3010 | |
| 3011 | static int getHeightForLineCount(const RenderBlockFlow& block, int lineCount, bool includeBottom, int& count) |
| 3012 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 3013 | if (block.style().visibility() != VISIBLE) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3014 | return -1; |
| 3015 | |
| 3016 | if (block.childrenInline()) { |
| 3017 | for (auto box = block.firstRootBox(); box; box = box->nextRootBox()) { |
| 3018 | if (++count == lineCount) |
| 3019 | return box->lineBottom() + (includeBottom ? (block.borderBottom() + block.paddingBottom()) : LayoutUnit()); |
| 3020 | } |
| 3021 | } else { |
| 3022 | RenderBox* normalFlowChildWithoutLines = 0; |
| 3023 | for (auto obj = block.firstChildBox(); obj; obj = obj->nextSiblingBox()) { |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 3024 | if (obj->isRenderBlockFlow() && shouldCheckLines(toRenderBlockFlow(*obj))) { |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3025 | int result = getHeightForLineCount(toRenderBlockFlow(*obj), lineCount, false, count); |
| 3026 | if (result != -1) |
| 3027 | return result + obj->y() + (includeBottom ? (block.borderBottom() + block.paddingBottom()) : LayoutUnit()); |
akling@apple.com | 38f0a65 | 2014-02-06 21:24:17 +0000 | [diff] [blame] | 3028 | } else if (!obj->isFloatingOrOutOfFlowPositioned()) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3029 | normalFlowChildWithoutLines = obj; |
| 3030 | } |
| 3031 | if (normalFlowChildWithoutLines && !lineCount) |
| 3032 | return normalFlowChildWithoutLines->y() + normalFlowChildWithoutLines->height(); |
| 3033 | } |
| 3034 | |
| 3035 | return -1; |
| 3036 | } |
| 3037 | |
| 3038 | int RenderBlockFlow::heightForLineCount(int lineCount) |
| 3039 | { |
| 3040 | int count = 0; |
| 3041 | return getHeightForLineCount(*this, lineCount, true, count); |
| 3042 | } |
| 3043 | |
| 3044 | void RenderBlockFlow::clearTruncation() |
| 3045 | { |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 3046 | if (style().visibility() != VISIBLE) |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3047 | return; |
| 3048 | |
| 3049 | if (childrenInline() && hasMarkupTruncation()) { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3050 | ensureLineBoxes(); |
| 3051 | |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3052 | setHasMarkupTruncation(false); |
| 3053 | for (auto box = firstRootBox(); box; box = box->nextRootBox()) |
| 3054 | box->clearTruncation(); |
akling@apple.com | 525dae6 | 2014-01-03 20:22:09 +0000 | [diff] [blame] | 3055 | return; |
| 3056 | } |
| 3057 | |
| 3058 | for (auto& blockFlow : childrenOfType<RenderBlockFlow>(*this)) { |
| 3059 | if (shouldCheckLines(blockFlow)) |
| 3060 | blockFlow.clearTruncation(); |
weinig@apple.com | 1714091 | 2013-10-19 19:55:40 +0000 | [diff] [blame] | 3061 | } |
| 3062 | } |
| 3063 | |
weinig@apple.com | 3f23b38 | 2013-10-19 20:26:58 +0000 | [diff] [blame] | 3064 | bool RenderBlockFlow::containsNonZeroBidiLevel() const |
| 3065 | { |
| 3066 | for (auto root = firstRootBox(); root; root = root->nextRootBox()) { |
| 3067 | for (auto box = root->firstLeafChild(); box; box = box->nextLeafChild()) { |
| 3068 | if (box->bidiLevel()) |
| 3069 | return true; |
| 3070 | } |
| 3071 | } |
| 3072 | return false; |
| 3073 | } |
| 3074 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3075 | Position RenderBlockFlow::positionForBox(InlineBox *box, bool start) const |
| 3076 | { |
| 3077 | if (!box) |
| 3078 | return Position(); |
| 3079 | |
| 3080 | if (!box->renderer().nonPseudoNode()) |
| 3081 | return createLegacyEditingPosition(nonPseudoElement(), start ? caretMinOffset() : caretMaxOffset()); |
| 3082 | |
| 3083 | if (!box->isInlineTextBox()) |
| 3084 | return createLegacyEditingPosition(box->renderer().nonPseudoNode(), start ? box->renderer().caretMinOffset() : box->renderer().caretMaxOffset()); |
| 3085 | |
| 3086 | InlineTextBox* textBox = toInlineTextBox(box); |
| 3087 | return createLegacyEditingPosition(box->renderer().nonPseudoNode(), start ? textBox->start() : textBox->start() + textBox->len()); |
| 3088 | } |
| 3089 | |
| 3090 | VisiblePosition RenderBlockFlow::positionForPointWithInlineChildren(const LayoutPoint& pointInLogicalContents) |
| 3091 | { |
| 3092 | ASSERT(childrenInline()); |
| 3093 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3094 | ensureLineBoxes(); |
| 3095 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3096 | if (!firstRootBox()) |
| 3097 | return createVisiblePosition(0, DOWNSTREAM); |
| 3098 | |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 3099 | bool linesAreFlipped = style().isFlippedLinesWritingMode(); |
| 3100 | bool blocksAreFlipped = style().isFlippedBlocksWritingMode(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3101 | |
| 3102 | // look for the closest line box in the root box which is at the passed-in y coordinate |
| 3103 | InlineBox* closestBox = 0; |
| 3104 | RootInlineBox* firstRootBoxWithChildren = 0; |
| 3105 | RootInlineBox* lastRootBoxWithChildren = 0; |
| 3106 | for (RootInlineBox* root = firstRootBox(); root; root = root->nextRootBox()) { |
| 3107 | if (!root->firstLeafChild()) |
| 3108 | continue; |
| 3109 | if (!firstRootBoxWithChildren) |
| 3110 | firstRootBoxWithChildren = root; |
| 3111 | |
| 3112 | if (!linesAreFlipped && root->isFirstAfterPageBreak() && (pointInLogicalContents.y() < root->lineTopWithLeading() |
| 3113 | || (blocksAreFlipped && pointInLogicalContents.y() == root->lineTopWithLeading()))) |
| 3114 | break; |
| 3115 | |
| 3116 | lastRootBoxWithChildren = root; |
| 3117 | |
| 3118 | // check if this root line box is located at this y coordinate |
| 3119 | if (pointInLogicalContents.y() < root->selectionBottom() || (blocksAreFlipped && pointInLogicalContents.y() == root->selectionBottom())) { |
| 3120 | if (linesAreFlipped) { |
| 3121 | RootInlineBox* nextRootBoxWithChildren = root->nextRootBox(); |
| 3122 | while (nextRootBoxWithChildren && !nextRootBoxWithChildren->firstLeafChild()) |
| 3123 | nextRootBoxWithChildren = nextRootBoxWithChildren->nextRootBox(); |
| 3124 | |
| 3125 | if (nextRootBoxWithChildren && nextRootBoxWithChildren->isFirstAfterPageBreak() && (pointInLogicalContents.y() > nextRootBoxWithChildren->lineTopWithLeading() |
| 3126 | || (!blocksAreFlipped && pointInLogicalContents.y() == nextRootBoxWithChildren->lineTopWithLeading()))) |
| 3127 | continue; |
| 3128 | } |
| 3129 | closestBox = root->closestLeafChildForLogicalLeftPosition(pointInLogicalContents.x()); |
| 3130 | if (closestBox) |
| 3131 | break; |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | bool moveCaretToBoundary = frame().editor().behavior().shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom(); |
| 3136 | |
| 3137 | if (!moveCaretToBoundary && !closestBox && lastRootBoxWithChildren) { |
| 3138 | // y coordinate is below last root line box, pretend we hit it |
| 3139 | closestBox = lastRootBoxWithChildren->closestLeafChildForLogicalLeftPosition(pointInLogicalContents.x()); |
| 3140 | } |
| 3141 | |
| 3142 | if (closestBox) { |
| 3143 | if (moveCaretToBoundary) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 3144 | LayoutUnit firstRootBoxWithChildrenTop = std::min<LayoutUnit>(firstRootBoxWithChildren->selectionTop(), firstRootBoxWithChildren->logicalTop()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3145 | if (pointInLogicalContents.y() < firstRootBoxWithChildrenTop |
| 3146 | || (blocksAreFlipped && pointInLogicalContents.y() == firstRootBoxWithChildrenTop)) { |
| 3147 | InlineBox* box = firstRootBoxWithChildren->firstLeafChild(); |
| 3148 | if (box->isLineBreak()) { |
| 3149 | if (InlineBox* newBox = box->nextLeafChildIgnoringLineBreak()) |
| 3150 | box = newBox; |
| 3151 | } |
| 3152 | // y coordinate is above first root line box, so return the start of the first |
| 3153 | return VisiblePosition(positionForBox(box, true), DOWNSTREAM); |
| 3154 | } |
| 3155 | } |
| 3156 | |
| 3157 | // pass the box a top position that is inside it |
| 3158 | LayoutPoint point(pointInLogicalContents.x(), closestBox->root().blockDirectionPointInLine()); |
| 3159 | if (!isHorizontalWritingMode()) |
| 3160 | point = point.transposedPoint(); |
| 3161 | if (closestBox->renderer().isReplaced()) |
weinig@apple.com | 12840dc | 2013-10-22 23:59:08 +0000 | [diff] [blame] | 3162 | return positionForPointRespectingEditingBoundaries(*this, toRenderBox(closestBox->renderer()), point); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3163 | return closestBox->renderer().positionForPoint(point); |
| 3164 | } |
| 3165 | |
| 3166 | if (lastRootBoxWithChildren) { |
| 3167 | // We hit this case for Mac behavior when the Y coordinate is below the last box. |
| 3168 | ASSERT(moveCaretToBoundary); |
| 3169 | InlineBox* logicallyLastBox; |
| 3170 | if (lastRootBoxWithChildren->getLogicalEndBoxWithNode(logicallyLastBox)) |
| 3171 | return VisiblePosition(positionForBox(logicallyLastBox, false), DOWNSTREAM); |
| 3172 | } |
| 3173 | |
| 3174 | // Can't reach this. We have a root line box, but it has no kids. |
| 3175 | // FIXME: This should ASSERT_NOT_REACHED(), but clicking on placeholder text |
| 3176 | // seems to hit this code path. |
| 3177 | return createVisiblePosition(0, DOWNSTREAM); |
| 3178 | } |
| 3179 | |
commit-queue@webkit.org | 5ce6c90 | 2013-11-11 18:21:05 +0000 | [diff] [blame] | 3180 | VisiblePosition RenderBlockFlow::positionForPoint(const LayoutPoint& point) |
| 3181 | { |
| 3182 | if (auto fragment = renderNamedFlowFragment()) |
| 3183 | return fragment->positionForPoint(point); |
| 3184 | return RenderBlock::positionForPoint(point); |
| 3185 | } |
| 3186 | |
| 3187 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3188 | void RenderBlockFlow::addFocusRingRectsForInlineChildren(Vector<IntRect>& rects, const LayoutPoint& additionalOffset, const RenderLayerModelObject*) |
| 3189 | { |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3190 | ASSERT(childrenInline()); |
| 3191 | |
| 3192 | ensureLineBoxes(); |
| 3193 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3194 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 3195 | LayoutUnit top = std::max<LayoutUnit>(curr->lineTop(), curr->top()); |
| 3196 | LayoutUnit bottom = std::min<LayoutUnit>(curr->lineBottom(), curr->top() + curr->height()); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3197 | LayoutRect rect(additionalOffset.x() + curr->x(), additionalOffset.y() + top, curr->width(), bottom - top); |
| 3198 | if (!rect.isEmpty()) |
| 3199 | rects.append(pixelSnappedIntRect(rect)); |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | void RenderBlockFlow::paintInlineChildren(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| 3204 | { |
| 3205 | ASSERT(childrenInline()); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3206 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3207 | if (m_simpleLineLayout) { |
| 3208 | SimpleLineLayout::paintFlow(*this, *m_simpleLineLayout, paintInfo, paintOffset); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3209 | return; |
| 3210 | } |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3211 | m_lineBoxes.paint(this, paintInfo, paintOffset); |
| 3212 | } |
| 3213 | |
| 3214 | bool RenderBlockFlow::relayoutForPagination(bool hasSpecifiedPageLogicalHeight, LayoutUnit pageLogicalHeight, LayoutStateMaintainer& statePusher) |
| 3215 | { |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3216 | if (!hasColumns() && !multiColumnFlowThread()) |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3217 | return false; |
| 3218 | |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3219 | if (hasColumns()) { |
| 3220 | RefPtr<RenderOverflow> savedOverflow = m_overflow.release(); |
| 3221 | if (childrenInline()) |
| 3222 | addOverflowFromInlineChildren(); |
| 3223 | else |
| 3224 | addOverflowFromBlockChildren(); |
| 3225 | LayoutUnit layoutOverflowLogicalBottom = (isHorizontalWritingMode() ? layoutOverflowRect().maxY() : layoutOverflowRect().maxX()) - borderAndPaddingBefore(); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3226 | |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3227 | // FIXME: We don't balance properly at all in the presence of forced page breaks. We need to understand what |
| 3228 | // the distance between forced page breaks is so that we can avoid making the minimum column height too tall. |
| 3229 | ColumnInfo* colInfo = columnInfo(); |
| 3230 | if (!hasSpecifiedPageLogicalHeight) { |
| 3231 | LayoutUnit columnHeight = pageLogicalHeight; |
| 3232 | int minColumnCount = colInfo->forcedBreaks() + 1; |
| 3233 | int desiredColumnCount = colInfo->desiredColumnCount(); |
| 3234 | if (minColumnCount >= desiredColumnCount) { |
| 3235 | // The forced page breaks are in control of the balancing. Just set the column height to the |
| 3236 | // maximum page break distance. |
| 3237 | if (!pageLogicalHeight) { |
| 3238 | LayoutUnit distanceBetweenBreaks = std::max<LayoutUnit>(colInfo->maximumDistanceBetweenForcedBreaks(), |
| 3239 | view().layoutState()->pageLogicalOffset(this, borderAndPaddingBefore() + layoutOverflowLogicalBottom) - colInfo->forcedBreakOffset()); |
| 3240 | columnHeight = std::max(colInfo->minimumColumnHeight(), distanceBetweenBreaks); |
| 3241 | } |
| 3242 | } else if (layoutOverflowLogicalBottom > boundedMultiply(pageLogicalHeight, desiredColumnCount)) { |
| 3243 | // Now that we know the intrinsic height of the columns, we have to rebalance them. |
| 3244 | columnHeight = std::max<LayoutUnit>(colInfo->minimumColumnHeight(), ceilf((float)layoutOverflowLogicalBottom / desiredColumnCount)); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3245 | } |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3246 | |
| 3247 | if (columnHeight && columnHeight != pageLogicalHeight) { |
| 3248 | statePusher.pop(); |
| 3249 | setEverHadLayout(true); |
| 3250 | layoutBlock(false, columnHeight); |
| 3251 | return true; |
| 3252 | } |
| 3253 | } |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3254 | |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3255 | if (pageLogicalHeight) |
| 3256 | colInfo->setColumnCountAndHeight(ceilf((float)layoutOverflowLogicalBottom / pageLogicalHeight), pageLogicalHeight); |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3257 | |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3258 | if (columnCount(colInfo)) { |
| 3259 | setLogicalHeight(borderAndPaddingBefore() + colInfo->columnHeight() + borderAndPaddingAfter() + scrollbarLogicalHeight()); |
| 3260 | clearOverflow(); |
| 3261 | } else |
| 3262 | m_overflow = savedOverflow.release(); |
| 3263 | return false; |
| 3264 | } |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3265 | |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3266 | if (!multiColumnFlowThread()->shouldRelayoutForPagination()) |
| 3267 | return false; |
| 3268 | |
| 3269 | multiColumnFlowThread()->setNeedsRebalancing(false); |
| 3270 | multiColumnFlowThread()->setInBalancingPass(true); // Prevent re-entering this method (and recursion into layout). |
| 3271 | |
| 3272 | bool needsRelayout; |
| 3273 | bool neededRelayout = false; |
| 3274 | bool firstPass = true; |
| 3275 | do { |
| 3276 | // Column heights may change here because of balancing. We may have to do multiple layout |
| 3277 | // passes, depending on how the contents is fitted to the changed column heights. In most |
| 3278 | // cases, laying out again twice or even just once will suffice. Sometimes we need more |
| 3279 | // passes than that, though, but the number of retries should not exceed the number of |
| 3280 | // columns, unless we have a bug. |
| 3281 | needsRelayout = false; |
| 3282 | for (RenderBox* childBox = firstChildBox(); childBox; childBox = childBox->nextSiblingBox()) |
| 3283 | if (childBox != multiColumnFlowThread() && childBox->isRenderMultiColumnSet()) { |
| 3284 | RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(childBox); |
| 3285 | if (multicolSet->recalculateBalancedHeight(firstPass)) { |
| 3286 | multicolSet->setChildNeedsLayout(MarkOnlyThis); |
| 3287 | needsRelayout = true; |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | if (needsRelayout) { |
| 3292 | // Layout again. Column balancing resulted in a new height. |
| 3293 | neededRelayout = true; |
| 3294 | multiColumnFlowThread()->setChildNeedsLayout(MarkOnlyThis); |
| 3295 | setChildNeedsLayout(MarkOnlyThis); |
| 3296 | if (firstPass) |
| 3297 | statePusher.pop(); |
| 3298 | layoutBlock(false); |
| 3299 | } |
| 3300 | firstPass = false; |
| 3301 | } while (needsRelayout); |
| 3302 | |
| 3303 | multiColumnFlowThread()->setInBalancingPass(false); |
| 3304 | |
| 3305 | return neededRelayout; |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3306 | } |
| 3307 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3308 | bool RenderBlockFlow::hasLines() const |
| 3309 | { |
| 3310 | ASSERT(childrenInline()); |
| 3311 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3312 | if (m_simpleLineLayout) |
antti@apple.com | 09c8351 | 2013-10-30 14:12:32 +0000 | [diff] [blame] | 3313 | return m_simpleLineLayout->lineCount(); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3314 | |
| 3315 | return lineBoxes().firstLineBox(); |
| 3316 | } |
| 3317 | |
| 3318 | void RenderBlockFlow::layoutSimpleLines(LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
| 3319 | { |
| 3320 | ASSERT(!m_lineBoxes.firstLineBox()); |
| 3321 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3322 | m_simpleLineLayout = SimpleLineLayout::create(*this); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3323 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3324 | LayoutUnit lineLayoutHeight = SimpleLineLayout::computeFlowHeight(*this, *m_simpleLineLayout); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3325 | LayoutUnit lineLayoutTop = borderAndPaddingBefore(); |
| 3326 | |
| 3327 | repaintLogicalTop = lineLayoutTop; |
| 3328 | repaintLogicalBottom = lineLayoutTop + lineLayoutHeight; |
| 3329 | |
| 3330 | setLogicalHeight(lineLayoutTop + lineLayoutHeight + borderAndPaddingAfter()); |
| 3331 | } |
| 3332 | |
| 3333 | void RenderBlockFlow::deleteLineBoxesBeforeSimpleLineLayout() |
| 3334 | { |
antti@apple.com | 42fb53d | 2013-10-25 02:33:11 +0000 | [diff] [blame] | 3335 | ASSERT(m_lineLayoutPath == SimpleLinesPath); |
akling@apple.com | 31dd4f4 | 2013-10-30 22:27:59 +0000 | [diff] [blame] | 3336 | lineBoxes().deleteLineBoxes(); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3337 | toRenderText(firstChild())->deleteLineBoxesBeforeSimpleLineLayout(); |
| 3338 | } |
| 3339 | |
| 3340 | void RenderBlockFlow::ensureLineBoxes() |
| 3341 | { |
antti@apple.com | 42fb53d | 2013-10-25 02:33:11 +0000 | [diff] [blame] | 3342 | m_lineLayoutPath = ForceLineBoxesPath; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3343 | |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3344 | if (!m_simpleLineLayout) |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3345 | return; |
antti@apple.com | fea5199 | 2013-10-28 13:39:23 +0000 | [diff] [blame] | 3346 | m_simpleLineLayout = nullptr; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 3347 | |
| 3348 | #if !ASSERT_DISABLED |
| 3349 | LayoutUnit oldHeight = logicalHeight(); |
| 3350 | #endif |
| 3351 | bool didNeedLayout = needsLayout(); |
| 3352 | |
| 3353 | bool relayoutChildren = false; |
| 3354 | LayoutUnit repaintLogicalTop; |
| 3355 | LayoutUnit repaintLogicalBottom; |
| 3356 | layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); |
| 3357 | |
| 3358 | updateLogicalHeight(); |
| 3359 | ASSERT(didNeedLayout || logicalHeight() == oldHeight); |
| 3360 | |
| 3361 | if (!didNeedLayout) |
| 3362 | clearNeedsLayout(); |
| 3363 | } |
| 3364 | |
weinig@apple.com | 611b929 | 2013-10-20 22:57:54 +0000 | [diff] [blame] | 3365 | #ifndef NDEBUG |
| 3366 | void RenderBlockFlow::showLineTreeAndMark(const InlineBox* markedBox1, const char* markedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const RenderObject* obj) const |
| 3367 | { |
| 3368 | RenderBlock::showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLabel2, obj); |
| 3369 | for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRootBox()) |
| 3370 | root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLabel2, obj, 1); |
| 3371 | } |
| 3372 | #endif |
| 3373 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 3374 | RenderBlockFlow::RenderBlockFlowRareData& RenderBlockFlow::ensureRareBlockFlowData() |
| 3375 | { |
| 3376 | if (hasRareBlockFlowData()) |
| 3377 | return *m_rareBlockFlowData; |
| 3378 | materializeRareBlockFlowData(); |
| 3379 | return *m_rareBlockFlowData; |
| 3380 | } |
| 3381 | |
| 3382 | void RenderBlockFlow::materializeRareBlockFlowData() |
| 3383 | { |
| 3384 | ASSERT(!hasRareBlockFlowData()); |
| 3385 | m_rareBlockFlowData = std::make_unique<RenderBlockFlow::RenderBlockFlowRareData>(*this); |
| 3386 | } |
| 3387 | |
aestes@apple.com | 6751d84 | 2014-01-12 02:51:25 +0000 | [diff] [blame] | 3388 | #if ENABLE(IOS_TEXT_AUTOSIZING) |
| 3389 | inline static bool isVisibleRenderText(RenderObject* renderer) |
| 3390 | { |
| 3391 | if (!renderer->isText()) |
| 3392 | return false; |
| 3393 | RenderText* renderText = toRenderText(renderer); |
| 3394 | return !renderText->linesBoundingBox().isEmpty() && !renderText->text()->containsOnlyWhitespace(); |
| 3395 | } |
| 3396 | |
| 3397 | inline static bool resizeTextPermitted(RenderObject* render) |
| 3398 | { |
| 3399 | // We disallow resizing for text input fields and textarea to address <rdar://problem/5792987> and <rdar://problem/8021123> |
| 3400 | auto renderer = render->parent(); |
| 3401 | while (renderer) { |
| 3402 | // Get the first non-shadow HTMLElement and see if it's an input. |
| 3403 | if (renderer->element() && renderer->element()->isHTMLElement() && !renderer->element()->isInShadowTree()) { |
| 3404 | const HTMLElement& element = toHTMLElement(*renderer->element()); |
| 3405 | return !isHTMLInputElement(element) && !isHTMLTextAreaElement(element); |
| 3406 | } |
| 3407 | renderer = renderer->parent(); |
| 3408 | } |
| 3409 | return true; |
| 3410 | } |
| 3411 | |
| 3412 | int RenderBlockFlow::immediateLineCount() |
| 3413 | { |
| 3414 | // Copied and modified from RenderBlock::lineCount. |
| 3415 | // Only descend into list items. |
| 3416 | int count = 0; |
| 3417 | if (style().visibility() == VISIBLE) { |
| 3418 | if (childrenInline()) { |
| 3419 | for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox()) |
| 3420 | count++; |
| 3421 | } else { |
| 3422 | for (RenderObject* obj = firstChild(); obj; obj = obj->nextSibling()) { |
| 3423 | if (obj->isListItem()) |
| 3424 | count += toRenderBlockFlow(obj)->lineCount(); |
| 3425 | } |
| 3426 | } |
| 3427 | } |
| 3428 | return count; |
| 3429 | } |
| 3430 | |
| 3431 | static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject* render) |
| 3432 | { |
| 3433 | if (!render->isRenderBlock()) |
| 3434 | return true; |
| 3435 | if (render->isListItem()) |
| 3436 | return render->style().height().type() != Fixed; |
| 3437 | return false; |
| 3438 | } |
| 3439 | |
| 3440 | // For now, we auto size single lines of text the same as multiple lines. |
| 3441 | // We've been experimenting with low values for single lines of text. |
| 3442 | static inline float oneLineTextMultiplier(float specifiedSize) |
| 3443 | { |
| 3444 | return std::max((1.0f / log10f(specifiedSize) * 1.7f), 1.0f); |
| 3445 | } |
| 3446 | |
| 3447 | static inline float textMultiplier(float specifiedSize) |
| 3448 | { |
| 3449 | return std::max((1.0f / log10f(specifiedSize) * 1.95f), 1.0f); |
| 3450 | } |
| 3451 | |
| 3452 | void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth) |
| 3453 | { |
| 3454 | // Don't do any work if the block is smaller than the visible area. |
| 3455 | if (visibleWidth >= width()) |
| 3456 | return; |
| 3457 | |
| 3458 | unsigned lineCount; |
| 3459 | if (m_lineCountForTextAutosizing == NOT_SET) { |
| 3460 | int count = immediateLineCount(); |
| 3461 | if (!count) |
| 3462 | lineCount = NO_LINE; |
| 3463 | else if (count == 1) |
| 3464 | lineCount = ONE_LINE; |
| 3465 | else |
| 3466 | lineCount = MULTI_LINE; |
| 3467 | } else |
| 3468 | lineCount = m_lineCountForTextAutosizing; |
| 3469 | |
| 3470 | ASSERT(lineCount != NOT_SET); |
| 3471 | if (lineCount == NO_LINE) |
| 3472 | return; |
| 3473 | |
| 3474 | float actualWidth = m_widthForTextAutosizing != -1 ? static_cast<float>(m_widthForTextAutosizing) : static_cast<float>(width()); |
| 3475 | float scale = visibleWidth / actualWidth; |
| 3476 | float minFontSize = roundf(size / scale); |
| 3477 | |
| 3478 | for (RenderObject* descendent = traverseNext(this, isNonBlocksOrNonFixedHeightListItems); descendent; descendent = descendent->traverseNext(this, isNonBlocksOrNonFixedHeightListItems)) { |
| 3479 | if (isVisibleRenderText(descendent) && resizeTextPermitted(descendent)) { |
| 3480 | RenderText* text = toRenderText(descendent); |
| 3481 | RenderStyle& oldStyle = text->style(); |
| 3482 | FontDescription fontDescription = oldStyle.fontDescription(); |
| 3483 | float specifiedSize = fontDescription.specifiedSize(); |
| 3484 | float scaledSize = roundf(specifiedSize * scale); |
| 3485 | if (scaledSize > 0 && scaledSize < minFontSize) { |
| 3486 | // 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. |
| 3487 | // This makes text resizing consistent even if the block's width or line count changes (which can be caused by text resizing itself 5159915). |
| 3488 | if (m_lineCountForTextAutosizing == NOT_SET) |
| 3489 | m_lineCountForTextAutosizing = lineCount; |
| 3490 | if (m_widthForTextAutosizing == -1) |
| 3491 | m_widthForTextAutosizing = actualWidth; |
| 3492 | |
| 3493 | float candidateNewSize = 0; |
| 3494 | float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(specifiedSize) : textMultiplier(specifiedSize); |
| 3495 | candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier)); |
| 3496 | if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text->textNode() && oldStyle.textSizeAdjust().isAuto()) |
| 3497 | document().addAutoSizingNode(text->textNode(), candidateNewSize); |
| 3498 | } |
| 3499 | } |
| 3500 | } |
| 3501 | } |
| 3502 | #endif // ENABLE(IOS_TEXT_AUTOSIZING) |
| 3503 | |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3504 | RenderObject* RenderBlockFlow::layoutSpecialExcludedChild(bool relayoutChildren) |
| 3505 | { |
| 3506 | if (!multiColumnFlowThread()) |
| 3507 | return 0; |
| 3508 | |
| 3509 | // Update the dimensions of our regions before we lay out the flow thread. |
| 3510 | // FIXME: Eventually this is going to get way more complicated, and we will be destroying regions |
| 3511 | // instead of trying to keep them around. |
| 3512 | bool shouldInvalidateRegions = false; |
| 3513 | for (RenderBox* childBox = firstChildBox(); childBox; childBox = childBox->nextSiblingBox()) { |
| 3514 | if (childBox == multiColumnFlowThread()) |
| 3515 | continue; |
| 3516 | |
| 3517 | if (relayoutChildren || childBox->needsLayout()) { |
| 3518 | if (!multiColumnFlowThread()->inBalancingPass() && childBox->isRenderMultiColumnSet()) |
| 3519 | toRenderMultiColumnSet(childBox)->prepareForLayout(); |
| 3520 | shouldInvalidateRegions = true; |
| 3521 | } |
| 3522 | } |
| 3523 | |
| 3524 | if (shouldInvalidateRegions) |
| 3525 | multiColumnFlowThread()->invalidateRegions(); |
| 3526 | |
| 3527 | if (relayoutChildren) |
| 3528 | multiColumnFlowThread()->setChildNeedsLayout(MarkOnlyThis); |
| 3529 | |
| 3530 | if (multiColumnFlowThread()->requiresBalancing()) { |
| 3531 | // At the end of multicol layout, relayoutForPagination() is called unconditionally, but if |
| 3532 | // no children are to be laid out (e.g. fixed width with layout already being up-to-date), |
| 3533 | // we want to prevent it from doing any work, so that the column balancing machinery doesn't |
| 3534 | // kick in and trigger additional unnecessary layout passes. Actually, it's not just a good |
| 3535 | // idea in general to not waste time on balancing content that hasn't been re-laid out; we |
| 3536 | // are actually required to guarantee this. The calculation of implicit breaks needs to be |
| 3537 | // preceded by a proper layout pass, since it's layout that sets up content runs, and the |
| 3538 | // runs get deleted right after every pass. |
| 3539 | multiColumnFlowThread()->setNeedsRebalancing(shouldInvalidateRegions || multiColumnFlowThread()->needsLayout()); |
| 3540 | } |
| 3541 | |
| 3542 | setLogicalTopForChild(*multiColumnFlowThread(), borderAndPaddingBefore()); |
| 3543 | multiColumnFlowThread()->layoutIfNeeded(); |
| 3544 | determineLogicalLeftPositionForChild(*multiColumnFlowThread()); |
| 3545 | |
| 3546 | return multiColumnFlowThread(); |
| 3547 | } |
| 3548 | |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3549 | void RenderBlockFlow::addChild(RenderObject* newChild, RenderObject* beforeChild) |
| 3550 | { |
| 3551 | if (multiColumnFlowThread()) |
| 3552 | return multiColumnFlowThread()->addChild(newChild, beforeChild); |
| 3553 | RenderBlock::addChild(newChild, beforeChild); |
| 3554 | } |
| 3555 | |
hyatt@apple.com | d4be377 | 2014-01-24 19:55:33 +0000 | [diff] [blame] | 3556 | void RenderBlockFlow::checkForPaginationLogicalHeightChange(LayoutUnit& pageLogicalHeight, bool& pageLogicalHeightChanged, bool& hasSpecifiedPageLogicalHeight) |
| 3557 | { |
| 3558 | // If we don't use either of the two column implementations or a flow thread, then bail. |
| 3559 | if (!isRenderFlowThread() && !multiColumnFlowThread() && !hasColumns()) |
| 3560 | return; |
| 3561 | |
| 3562 | // We don't actually update any of the variables. We just subclassed to adjust our column height. |
| 3563 | if (multiColumnFlowThread()) { |
| 3564 | updateLogicalHeight(); |
| 3565 | multiColumnFlowThread()->setColumnHeightAvailable(std::max<LayoutUnit>(contentLogicalHeight(), 0)); |
| 3566 | setLogicalHeight(0); |
| 3567 | } else if (hasColumns()) { |
| 3568 | ColumnInfo* colInfo = columnInfo(); |
| 3569 | |
| 3570 | if (!pageLogicalHeight) { |
| 3571 | // We need to go ahead and set our explicit page height if one exists, so that we can |
| 3572 | // avoid doing two layout passes. |
| 3573 | updateLogicalHeight(); |
| 3574 | LayoutUnit columnHeight = isRenderView() ? view().pageOrViewLogicalHeight() : contentLogicalHeight(); |
| 3575 | if (columnHeight > 0) { |
| 3576 | pageLogicalHeight = columnHeight; |
| 3577 | hasSpecifiedPageLogicalHeight = true; |
| 3578 | } |
| 3579 | setLogicalHeight(0); |
| 3580 | } |
| 3581 | |
| 3582 | if (colInfo->columnHeight() != pageLogicalHeight && everHadLayout()) |
| 3583 | pageLogicalHeightChanged = true; |
| 3584 | |
| 3585 | colInfo->setColumnHeight(pageLogicalHeight); |
| 3586 | |
| 3587 | if (!hasSpecifiedPageLogicalHeight && !pageLogicalHeight) |
| 3588 | colInfo->clearForcedBreaks(); |
| 3589 | |
| 3590 | colInfo->setPaginationUnit(paginationUnit()); |
| 3591 | } else if (isRenderFlowThread()) { |
| 3592 | pageLogicalHeight = 1; // This is just a hack to always make sure we have a page logical height. |
| 3593 | pageLogicalHeightChanged = toRenderFlowThread(this)->pageLogicalSizeChanged(); |
| 3594 | } |
| 3595 | } |
| 3596 | |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3597 | void RenderBlockFlow::setComputedColumnCountAndWidth(int count, LayoutUnit width) |
| 3598 | { |
| 3599 | if (!document().regionBasedColumnsEnabled()) |
| 3600 | return RenderBlock::setComputedColumnCountAndWidth(count, width); |
| 3601 | |
| 3602 | bool destroyColumns = !requiresColumns(count); |
| 3603 | if (destroyColumns) { |
| 3604 | if (multiColumnFlowThread()) |
| 3605 | destroyMultiColumnFlowThread(); |
| 3606 | } else { |
| 3607 | if (!multiColumnFlowThread()) |
| 3608 | createMultiColumnFlowThread(); |
| 3609 | multiColumnFlowThread()->setColumnCountAndWidth(count, width); |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3610 | multiColumnFlowThread()->setProgressionIsInline(style().hasInlineColumnAxis()); |
| 3611 | multiColumnFlowThread()->setProgressionIsReversed(style().columnProgression() == ReverseColumnProgression); |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3612 | } |
| 3613 | } |
| 3614 | |
hyatt@apple.com | 8691986 | 2014-01-27 16:27:45 +0000 | [diff] [blame] | 3615 | void RenderBlockFlow::updateColumnProgressionFromStyle(RenderStyle* style) |
| 3616 | { |
| 3617 | if (!document().regionBasedColumnsEnabled()) |
| 3618 | return RenderBlock::updateColumnProgressionFromStyle(style); |
| 3619 | |
| 3620 | if (!multiColumnFlowThread()) |
| 3621 | return; |
| 3622 | |
| 3623 | bool needsLayout = false; |
| 3624 | bool oldProgressionIsInline = multiColumnFlowThread()->progressionIsInline(); |
| 3625 | bool newProgressionIsInline = style->hasInlineColumnAxis(); |
| 3626 | if (oldProgressionIsInline != newProgressionIsInline) { |
| 3627 | multiColumnFlowThread()->setProgressionIsInline(newProgressionIsInline); |
| 3628 | needsLayout = true; |
| 3629 | } |
| 3630 | |
| 3631 | bool oldProgressionIsReversed = multiColumnFlowThread()->progressionIsReversed(); |
| 3632 | bool newProgressionIsReversed = style->columnProgression() == ReverseColumnProgression; |
| 3633 | if (oldProgressionIsReversed != newProgressionIsReversed) { |
| 3634 | multiColumnFlowThread()->setProgressionIsReversed(newProgressionIsReversed); |
| 3635 | needsLayout = true; |
| 3636 | } |
| 3637 | |
| 3638 | if (needsLayout) |
| 3639 | setNeedsLayoutAndPrefWidthsRecalc(); |
| 3640 | } |
| 3641 | |
hyatt@apple.com | 39746fd | 2014-01-24 22:52:41 +0000 | [diff] [blame] | 3642 | LayoutUnit RenderBlockFlow::computedColumnWidth() const |
| 3643 | { |
| 3644 | if (!document().regionBasedColumnsEnabled()) |
| 3645 | return RenderBlock::computedColumnWidth(); |
| 3646 | |
| 3647 | if (multiColumnFlowThread()) |
| 3648 | return multiColumnFlowThread()->computedColumnWidth(); |
| 3649 | return contentLogicalWidth(); |
| 3650 | } |
| 3651 | |
| 3652 | unsigned RenderBlockFlow::computedColumnCount() const |
| 3653 | { |
| 3654 | if (!document().regionBasedColumnsEnabled()) |
| 3655 | return RenderBlock::computedColumnCount(); |
| 3656 | |
| 3657 | if (multiColumnFlowThread()) |
| 3658 | return multiColumnFlowThread()->computedColumnCount(); |
| 3659 | |
| 3660 | return 1; |
| 3661 | } |
| 3662 | |
hyatt@apple.com | 31a5daa | 2014-01-28 01:26:37 +0000 | [diff] [blame] | 3663 | bool RenderBlockFlow::isTopLayoutOverflowAllowed() const |
| 3664 | { |
| 3665 | bool hasTopOverflow = RenderBlock::isTopLayoutOverflowAllowed(); |
| 3666 | if (!multiColumnFlowThread() || style().columnProgression() == NormalColumnProgression) |
| 3667 | return hasTopOverflow; |
| 3668 | |
| 3669 | if (!(isHorizontalWritingMode() ^ !style().hasInlineColumnAxis())) |
| 3670 | hasTopOverflow = !hasTopOverflow; |
| 3671 | |
| 3672 | return hasTopOverflow; |
| 3673 | } |
| 3674 | |
| 3675 | bool RenderBlockFlow::isLeftLayoutOverflowAllowed() const |
| 3676 | { |
| 3677 | bool hasLeftOverflow = RenderBlock::isLeftLayoutOverflowAllowed(); |
| 3678 | if (!multiColumnFlowThread() || style().columnProgression() == NormalColumnProgression) |
| 3679 | return hasLeftOverflow; |
| 3680 | |
| 3681 | if (isHorizontalWritingMode() ^ !style().hasInlineColumnAxis()) |
| 3682 | hasLeftOverflow = !hasLeftOverflow; |
| 3683 | |
| 3684 | return hasLeftOverflow; |
| 3685 | } |
| 3686 | |
hyatt@apple.com | e96ebaf | 2013-11-12 22:51:12 +0000 | [diff] [blame] | 3687 | } |
| 3688 | // namespace WebCore |