Commit 38dde6d6 authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[LayoutNG] Add CalculateChildPercentageSize utility function.

Fixes percentage sized floats which were previously not using the
correct percentage resolution size.

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Ie57909b7f452f5d59b8dfe2f899bedf253ab90ac
Reviewed-on: https://chromium-review.googlesource.com/1205200
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588959}
parent 087f227d
<title>In quirks mode a float should resolve its percentage height against its first ancestor with a defined height.</title>
<link rel="help" href="https://www.w3.org/TR/CSS22/visudet.html#Computing_widths_and_margins">
<link rel="match" href="../../reference/ref-filled-green-100px-square-only.html">
<p style="margin-top: 1em;">Test passes if there is a filled green square.</p>
<div style="width:100px; height:100px; background:red;">
<div>
<div></div>
<div style="float:left; width:100%; height:100%; background:green;"></div>
</div>
</div>
......@@ -364,23 +364,10 @@ scoped_refptr<NGLayoutResult> NGBlockLayoutAlgorithm::Layout() {
NGLogicalSize border_box_size = CalculateBorderBoxSize(
ConstraintSpace(), Node(), CalculateDefaultBlockSize(), border_padding_);
// Our calculated block-axis size may be indefinite at this point.
// If so, just leave the size as NGSizeIndefinite instead of subtracting
// borders and padding.
NGLogicalSize adjusted_size =
child_available_size_ =
CalculateContentBoxSize(border_box_size, border_scrollbar_padding_);
child_available_size_ = adjusted_size;
// Anonymous constraint spaces are auto-sized. Don't let that affect
// block-axis percentage resolution.
if (ConstraintSpace().IsAnonymous() || Node().IsAnonymousBlock())
child_percentage_size_ = ConstraintSpace().PercentageResolutionSize();
else
child_percentage_size_ = adjusted_size;
if (ConstraintSpace().IsFixedSizeBlock() &&
!ConstraintSpace().FixedSizeBlockIsDefinite())
child_percentage_size_.block_size = NGSizeIndefinite;
child_percentage_size_ = CalculateChildPercentageSize(
ConstraintSpace(), Node(), child_available_size_);
container_builder_.SetInlineSize(border_box_size.inline_size);
container_builder_.SetBfcLineOffset(
......@@ -1815,19 +1802,8 @@ NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild(
const base::Optional<LayoutUnit> floats_bfc_block_offset) {
NGConstraintSpaceBuilder space_builder(ConstraintSpace());
NGLogicalSize available_size(child_available_size);
NGLogicalSize percentage_size(child_percentage_size_);
if (percentage_size.block_size == NGSizeIndefinite &&
Node().GetDocument().InQuirksMode()) {
// Implement percentage height calculation quirk
// https://quirks.spec.whatwg.org/#the-percentage-height-calculation-quirk
if (!Style().IsDisplayTableType() && !Style().HasOutOfFlowPosition()) {
percentage_size.block_size =
constraint_space_.PercentageResolutionSize().block_size;
}
}
space_builder.SetAvailableSize(available_size)
.SetPercentageResolutionSize(percentage_size);
space_builder.SetAvailableSize(child_available_size)
.SetPercentageResolutionSize(child_percentage_size_);
if (NGBaseline::ShouldPropagateBaselines(child))
space_builder.AddBaselineRequests(ConstraintSpace().BaselineRequests());
......
......@@ -939,4 +939,30 @@ NGLogicalSize CalculateContentBoxSize(
return size;
}
NGLogicalSize CalculateChildPercentageSize(
const NGConstraintSpace& space,
const NGBlockNode node,
const NGLogicalSize& child_available_size) {
// Anonymous block or spaces should pass the percent size straight through.
if (space.IsAnonymous() || node.IsAnonymousBlock())
return space.PercentageResolutionSize();
NGLogicalSize child_percentage_size = child_available_size;
if (space.IsFixedSizeBlock() && !space.FixedSizeBlockIsDefinite())
child_percentage_size.block_size = NGSizeIndefinite;
// In quirks mode the percentage resolution height is passed from parent to
// child.
// https://quirks.spec.whatwg.org/#the-percentage-height-calculation-quirk
if (child_percentage_size.block_size == NGSizeIndefinite &&
node.GetDocument().InQuirksMode() && !node.Style().IsDisplayTableType() &&
!node.Style().HasOutOfFlowPosition()) {
child_percentage_size.block_size =
space.PercentageResolutionSize().block_size;
}
return child_percentage_size;
}
} // namespace blink
......@@ -249,6 +249,12 @@ NGLogicalSize CalculateContentBoxSize(
const NGLogicalSize border_box_size,
const NGBoxStrut& border_scrollbar_padding);
// Calculates the percentage resolution size children of node should use.
NGLogicalSize CalculateChildPercentageSize(
const NGConstraintSpace&,
const NGBlockNode node,
const NGLogicalSize& child_available_size);
} // namespace blink
#endif // NGLengthUtils_h
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