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