Commit 8d47cb35 authored by Morten Stenshorne's avatar Morten Stenshorne Committed by Commit Bot

[LayoutNG] Skip "optimistic" float placement if inline-size is known.

If we already know the inline-size of the float before placing it, we
don't need to make a guess at its position before laying it out. We can
just set it right away.

This is just an optimization. No behavior changes intended.

Bug: 915929
Change-Id: I72ce406ef6b32ff5755522e3375dd93c407ee834
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2278050Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786440}
parent e7412d01
......@@ -232,19 +232,29 @@ NGPositionedFloat PositionFloat(NGUnpositionedFloat* unpositioned_float,
// laying it out. This is a float, and in order to calculate its offset, we
// first need to know its inline-size.
// TODO(crbug.com/915929): In some cases the inline-size of the float is
// already known at this point, and then we should be able to set the
// correct layout opportunity right away, i.e. no need for optimistic
// placement. However, this only happens in inline formatting contexts, and
// we don't support fragmenting floats in inline formatting contexts yet.
bool optimistically_placed = true;
// We'll estimate the offset to be the one we'd get if the float isn't
// affected by any other floats in the block formatting context. If this
// turns out to be wrong, we'll need to lay out again.
LayoutUnit fragmentainer_delta =
unpositioned_float->origin_bfc_offset.block_offset +
fragment_margins.block_start;
LayoutUnit fragmentainer_delta;
bool optimistically_placed = false;
if (unpositioned_float->layout_result) {
// We have already laid out the float to find its inline-size.
NGFragment float_fragment(
parent_space.GetWritingMode(),
unpositioned_float->layout_result->PhysicalFragment());
// We can find a layout opportunity and set the fragmentainer offset right
// away.
opportunity = FindLayoutOpportunityForFloat(
*unpositioned_float, *exclusion_space, fragment_margins,
float_fragment.InlineSize());
fragmentainer_delta = opportunity.rect.start_offset.block_offset +
fragment_margins.block_start;
} else {
// If we don't know the inline-size yet, we'll estimate the offset to be
// the one we'd get if the float isn't affected by any other floats in the
// block formatting context. If this turns out to be wrong, we'll need to
// lay out again.
fragmentainer_delta = unpositioned_float->origin_bfc_offset.block_offset +
fragment_margins.block_start;
optimistically_placed = true;
}
do {
NGConstraintSpace space = CreateConstraintSpaceForFloat(
......
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