Skip to content

Commit cb045d2

Browse files
[css-flexbox] incorrect layout with max-height and flex-direction column and justify-content center
https://bugs.webkit.org/show_bug.cgi?id=282036 Reviewed by NOBODY (OOPS!). After calculation of the flex item size and adjusting it to min/max size of the flex item we should also check how the calculated size corresponds to specified max size of the whole container. In case the adjusted flex item size is bigger than the max size of the whole container we should use the flex item size calculated before adjusting to flex item min/max size. There is new layout test which tests the problem. * LayoutTests/css3/flexbox/nested-flexbox-max-height-expected.txt: Added. * LayoutTests/css3/flexbox/nested-flexbox-max-height.html: Added. * Source/WebCore/rendering/RenderFlexibleBox.cpp: (WebCore::RenderFlexibleBox::resolveFlexibleLengths):
1 parent 3e3b298 commit cb045d2

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Only red square should be visible
2+
3+
4+
PASS #container 1
5+
A
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<link href="resources/flexbox.css" rel="stylesheet">
3+
<script src="../../resources/testharness.js"></script>
4+
<script src="../../resources/testharnessreport.js"></script>
5+
<script src="../../resources/check-layout-th.js"></script>
6+
<script>
7+
function run() {
8+
checkLayout('#container');
9+
}
10+
</script>
11+
<body onload="run()">
12+
<p>Only red square should be visible</p>
13+
<div id="log"></div>
14+
<div id="container" class="flexbox column" style="max-height: 100px; height: 100px; width: 100px; background: green">
15+
<div class="flexbox column justify-content-center" style="height: 400px; background: red" data-expected-height="100">A</div>
16+
</div>

Source/WebCore/rendering/RenderFlexibleBox.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,21 @@ bool RenderFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, Vector<FlexIte
15871587
childSize += LayoutUnit::fromFloatRound(extraSpace);
15881588

15891589
LayoutUnit adjustedChildSize = flexItem.constrainSizeByMinMax(childSize);
1590+
1591+
// Adjust flex item size with the specified container max size.
1592+
auto maximumSize = isHorizontalFlow() ? style().maxWidth() : style().maxHeight();
1593+
const auto minimumSize = isHorizontalFlow() ? style().minWidth() : style().minHeight();
1594+
if (maximumSize.isFixed()) {
1595+
// The fixed min height/width should be considered as maximum size if it is bigger than fixed max height/width.
1596+
if (minimumSize.isFixed() && minimumSize.value() > maximumSize.value())
1597+
maximumSize = minimumSize;
1598+
1599+
// If the size of flex item adjusted to its min/max size is bigger than the maximum size of the container, then
1600+
// we use flext item size calculated before adjusting the min/max size of the flex item.
1601+
if (adjustedChildSize > LayoutUnit { maximumSize.value() })
1602+
adjustedChildSize = std::max(LayoutUnit { }, childSize);
1603+
}
1604+
15901605
ASSERT(adjustedChildSize >= 0);
15911606
flexItem.flexedContentSize = adjustedChildSize;
15921607
usedFreeSpace += adjustedChildSize - flexItem.flexBaseContentSize;

0 commit comments

Comments
 (0)