| Index: third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp
|
| diff --git a/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp b/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp
|
| index 03b3619bcb05640d829fae89ddf392d4b41d6b2c..da28bc8f7e1384f71d14d1c1a7b08ca477e52315 100644
|
| --- a/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp
|
| +++ b/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp
|
| @@ -1709,10 +1709,10 @@ LayoutUnit LayoutBlockFlow::collapseMargins(LayoutBox& child,
|
|
|
| LayoutObject* prev = child.previousSibling();
|
| LayoutBlockFlow* previousBlockFlow =
|
| - prev && prev->isLayoutBlockFlow() &&
|
| - !prev->isFloatingOrOutOfFlowPositioned()
|
| - ? toLayoutBlockFlow(prev)
|
| - : 0;
|
| + prev && prev->isLayoutBlockFlow() ? toLayoutBlockFlow(prev) : nullptr;
|
| + bool previousBlockFlowCanSelfCollapse =
|
| + previousBlockFlow &&
|
| + !previousBlockFlow->isFloatingOrOutOfFlowPositioned();
|
| // 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 of
|
| // the float. Since we want to collapse the child's top margin with the self-
|
| @@ -1720,7 +1720,8 @@ LayoutUnit LayoutBlockFlow::collapseMargins(LayoutBox& child,
|
| // height to match the 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.
|
| - if (!marginInfo.canCollapseWithMarginBefore() && previousBlockFlow &&
|
| + if (!marginInfo.canCollapseWithMarginBefore() &&
|
| + previousBlockFlowCanSelfCollapse &&
|
| marginInfo.lastChildIsSelfCollapsingBlockWithClearance())
|
| setLogicalHeight(
|
| logicalHeight() -
|
| @@ -1801,18 +1802,28 @@ LayoutUnit LayoutBlockFlow::collapseMargins(LayoutBox& child,
|
| setLogicalHeight(logicalHeight() + (logicalTop - oldLogicalTop));
|
| }
|
|
|
| - if (previousBlockFlow) {
|
| - // 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 any floats from the parent will now overhang.
|
| + // If |child| has moved up into previous siblings it needs to avoid or clear
|
| + // any floats they contain.
|
| + if (logicalTop < beforeCollapseLogicalTop) {
|
| LayoutUnit oldLogicalHeight = logicalHeight();
|
| setLogicalHeight(logicalTop);
|
| - if (!previousBlockFlow->avoidsFloats() &&
|
| - (previousBlockFlow->logicalTop() +
|
| - previousBlockFlow->lowestFloatLogicalBottom()) > logicalTop)
|
| - addOverhangingFloats(previousBlockFlow, false);
|
| + while (previousBlockFlow) {
|
| + auto lowestFloat = previousBlockFlow->logicalTop() +
|
| + previousBlockFlow->lowestFloatLogicalBottom();
|
| + if (lowestFloat > logicalTop)
|
| + addOverhangingFloats(previousBlockFlow, false);
|
| + else
|
| + break;
|
| + LayoutObject* prev = previousBlockFlow->previousSibling();
|
| + if (prev && prev->isLayoutBlockFlow())
|
| + previousBlockFlow = toLayoutBlockFlow(prev);
|
| + else
|
| + previousBlockFlow = nullptr;
|
| + }
|
| setLogicalHeight(oldLogicalHeight);
|
| + }
|
|
|
| + if (previousBlockFlowCanSelfCollapse) {
|
| // If |child|'s previous sibling is or contains a self-collapsing block that
|
| // cleared a float and margin collapsing resulted in |child| moving up
|
| // into the margin area of the self-collapsing block then the float it
|
|
|