Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp

Issue 2531953002: Detect floats to avoid or clear due to negative margin top (Closed)
Patch Set: bug 666487 Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/block/float/avoid-floats-when-negative-margin-top-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b82580923a4d97eb71c95b9c80834c131fd0b734 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) : 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-
@@ -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,24 @@ 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)
+ // 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) {
+ auto lowestFloat = previousBlockFlow->logicalTop() +
+ previousBlockFlow->lowestFloatLogicalBottom();
+ if (lowestFloat > logicalTop)
addOverhangingFloats(previousBlockFlow, false);
- setLogicalHeight(oldLogicalHeight);
+ 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/block/float/avoid-floats-when-negative-margin-top-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698