Commit 8835f44a authored by robhogan@gmail.com's avatar robhogan@gmail.com

Margins should expand/shrink an element's width if no float constrains it

This is a regression from https://src.chromium.org/viewvc/blink?revision=175325&view=revision.
I didn't consider the case where there are floats in the same formatting
context but they don't actually overlap with the element so have no effect
on its width.

BUG=413202

Review URL: https://codereview.chromium.org/570933002

git-svn-id: svn://svn.chromium.org/blink/trunk@181998 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 030eedc2
crbug.com/413202: Margins can expand/shrink the width of an element if a float does not constrain it.
PASS
PASS
<!doctype html>
<style>
body {
margin-left: 200px;
width: 35em;
}
div.floater {
float: right;
width: 20em;
margin-right: -23em;
margin-bottom: 1em;
}
table {
background-color: green;
}
#expands {
margin-left: -200px;
margin-right: -200px;
}
#shrinks {
margin-left: 200px;
margin-right: 200px;
}
td {
width: 1500px;
}
</style>
<div style="position: absolute">crbug.com/413202: Margins can expand/shrink the width of an element if a float does not constrain it.</div>
<div class="floater"></div>
<table id="expands" data-expected-client-width="960">
<tr>
<td></td>
</tr>
</table>
<table id="shrinks" data-expected-client-width="160">
<tr>
<td></td>
</tr>
</table>
<script src="../../resources/check-layout.js"></script>
<script>
document.body.offsetLeft;
checkLayout("#expands");
checkLayout("#shrinks");
</script>
...@@ -1469,15 +1469,23 @@ static LayoutUnit portionOfMarginNotConsumedByFloat(LayoutUnit childMargin, Layo ...@@ -1469,15 +1469,23 @@ static LayoutUnit portionOfMarginNotConsumedByFloat(LayoutUnit childMargin, Layo
LayoutUnit RenderBox::shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const LayoutUnit RenderBox::shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const
{ {
LayoutUnit logicalTopPosition = logicalTop(); LayoutUnit logicalTopPosition = logicalTop();
LayoutUnit width = cb->availableLogicalWidthForLine(logicalTopPosition, false) - std::max<LayoutUnit>(0, childMarginStart) - std::max<LayoutUnit>(0, childMarginEnd); LayoutUnit startOffsetForContent = cb->startOffsetForContent();
LayoutUnit endOffsetForContent = cb->endOffsetForContent();
LayoutUnit startOffsetForLine = cb->startOffsetForLine(logicalTopPosition, false);
LayoutUnit endOffsetForLine = cb->endOffsetForLine(logicalTopPosition, false);
// If there aren't any floats constraining us then allow the margins to shrink/expand the width as much as they want.
if (startOffsetForContent == startOffsetForLine && endOffsetForContent == endOffsetForLine)
return cb->availableLogicalWidthForLine(logicalTopPosition, false) - childMarginStart - childMarginEnd;
LayoutUnit width = cb->availableLogicalWidthForLine(logicalTopPosition, false) - std::max<LayoutUnit>(0, childMarginStart) - std::max<LayoutUnit>(0, childMarginEnd);
// We need to see if margins on either the start side or the end side can contain the floats in question. If they can, // We need to see if margins on either the start side or the end side can contain the floats in question. If they can,
// then just using the line width is inaccurate. In the case where a float completely fits, we don't need to use the line // then just using the line width is inaccurate. In the case where a float completely fits, we don't need to use the line
// offset at all, but can instead push all the way to the content edge of the containing block. In the case where the float // offset at all, but can instead push all the way to the content edge of the containing block. In the case where the float
// doesn't fit, we can use the line offset, but we need to grow it by the margin to reflect the fact that the margin was // doesn't fit, we can use the line offset, but we need to grow it by the margin to reflect the fact that the margin was
// "consumed" by the float. Negative margins aren't consumed by the float, and so we ignore them. // "consumed" by the float. Negative margins aren't consumed by the float, and so we ignore them.
width += portionOfMarginNotConsumedByFloat(childMarginStart, cb->startOffsetForContent(), cb->startOffsetForLine(logicalTopPosition, false)); width += portionOfMarginNotConsumedByFloat(childMarginStart, startOffsetForContent, startOffsetForLine);
width += portionOfMarginNotConsumedByFloat(childMarginEnd, cb->endOffsetForContent(), cb->endOffsetForLine(logicalTopPosition, false)); width += portionOfMarginNotConsumedByFloat(childMarginEnd, endOffsetForContent, endOffsetForLine);
return width; return width;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment