Chromium Code Reviews| 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 dd29fed7bae60dbf585a4a6250e217eff5ff7fa2..fbaee4f358a811116bced1438149bcebd54ee072 100644 |
| --- a/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp |
| +++ b/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp |
| @@ -1721,10 +1721,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) : 0; |
|
pdr.
2016/11/30 21:45:32
nit: nullptr instead of 0?
|
| + 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- |
| @@ -1732,7 +1732,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() - |
| @@ -1816,18 +1817,22 @@ 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. |
| - LayoutUnit oldLogicalHeight = logicalHeight(); |
| - setLogicalHeight(logicalTop); |
| - if (!previousBlockFlow->avoidsFloats() && |
| - (previousBlockFlow->logicalTop() + |
| - previousBlockFlow->lowestFloatLogicalBottom()) > logicalTop) |
| - addOverhangingFloats(previousBlockFlow, false); |
| - setLogicalHeight(oldLogicalHeight); |
| + // If |child| has moved up into previous siblings it needs to avoid or clear |
| + // any floats they contain. |
| + LayoutUnit oldLogicalHeight = logicalHeight(); |
| + setLogicalHeight(logicalTop); |
| + while (previousBlockFlow && |
|
pdr.
2016/11/30 21:45:32
This is pretty hard to read. Do you think we could
|
| + previousBlockFlow->logicalTop() + |
| + previousBlockFlow->lowestFloatLogicalBottom() > |
| + logicalTop) { |
| + addOverhangingFloats(previousBlockFlow, false); |
| + LayoutObject* prev = previousBlockFlow->previousSibling(); |
| + previousBlockFlow = |
| + prev && prev->isLayoutBlockFlow() ? toLayoutBlockFlow(prev) : 0; |
| + } |
| + 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 |