Commit f9d77f77 authored by glebl's avatar glebl Committed by Commit bot

Check if fragment's block size fits into a layout opportunity.

Since we started using LayoutOpportunity iterator for positioning BFC
fragments, we can't longer rely on the assumption that
FindLayoutOpportunityForFragment will be used for floats only.

List of changes:
- Change FindLayoutOpportunityForFragment to check if fragment's block
  size fits into a layout opportunity.
- Change NGInlineLayoutAlgorithm to avoid adding font's descent to
  line_bottom if the text only includes object replacement characters
  I need it to fix floats-wrap-top-below-002l-ref.xht.

BUG=635619

Review-Url: https://codereview.chromium.org/2840883002
Cr-Commit-Position: refs/heads/master@{#467875}
parent b68f0949
......@@ -49,6 +49,11 @@ NGLogicalOffset GetOriginPointForFloats(const NGConstraintSpace& space,
origin_point.block_offset += content_size;
return origin_point;
}
inline bool IsObjectReplacementCharacter(UChar character) {
return character == kObjectReplacementCharacter;
}
} // namespace
NGInlineLayoutAlgorithm::NGInlineLayoutAlgorithm(
......@@ -474,7 +479,12 @@ bool NGInlineLayoutAlgorithm::PlaceItems(
baseline = LayoutUnit(baseline.Round());
// Check if the line fits into the constraint space in block direction.
LayoutUnit line_bottom = baseline + line_box.Metrics().descent;
LayoutUnit line_bottom = baseline;
// See http://crrev.com/2840883002
if (!Node()->Text().IsAllSpecialCharacters<IsObjectReplacementCharacter>())
line_bottom += line_box.Metrics().descent;
if (!container_builder_.Children().IsEmpty() &&
ConstraintSpace().AvailableSize().block_size != NGSizeIndefinite &&
line_bottom > ConstraintSpace().AvailableSize().block_size) {
......
......@@ -416,10 +416,13 @@ NGLogicalOffset NGBlockLayoutAlgorithm::PositionNewFc(
PositionFloats(curr_bfc_offset_.block_offset, curr_bfc_offset_.block_offset,
container_builder_.UnpositionedFloats(), tmp_space.Get());
NGLogicalOffset origin_offset = curr_bfc_offset_;
origin_offset.inline_offset += border_and_padding_.inline_start;
// 2. Find an estimated layout opportunity for our fragment.
NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment(
tmp_space->Exclusions().get(), child_space.AvailableSize(),
curr_bfc_offset_, curr_child_margins_, fragment);
tmp_space->Exclusions().get(), child_space.AvailableSize(), origin_offset,
curr_child_margins_, fragment);
// 3. If the found opportunity lies on the same line with our estimated
// child's BFC offset then merge fragment's margins with the current
......@@ -435,11 +438,14 @@ NGLogicalOffset NGBlockLayoutAlgorithm::PositionNewFc(
PositionPendingFloats(curr_bfc_offset_.block_offset, &container_builder_,
MutableConstraintSpace());
origin_offset = curr_bfc_offset_;
origin_offset.inline_offset += border_and_padding_.inline_start;
// 5. Find the final layout opportunity for the fragment after all pending
// floats are positioned at the correct BFC block's offset.
opportunity = FindLayoutOpportunityForFragment(
MutableConstraintSpace()->Exclusions().get(), child_space.AvailableSize(),
curr_bfc_offset_, curr_child_margins_, fragment);
origin_offset, curr_child_margins_, fragment);
curr_bfc_offset_ = opportunity.offset;
return curr_bfc_offset_;
......
......@@ -271,10 +271,10 @@ NGLayoutOpportunity FindLayoutOpportunityForFragment(
NGLayoutOpportunity opportunity_candidate = opportunity_iter.Next();
while (!opportunity_candidate.IsEmpty()) {
opportunity = opportunity_candidate;
// Checking opportunity's block size is not necessary as a float cannot be
// positioned on top of another float inside of the same constraint space.
auto fragment_inline_size = fragment.InlineSize() + margins.InlineSum();
if (opportunity.size.inline_size >= fragment_inline_size)
auto fragment_block_size = fragment.BlockSize() + margins.BlockSum();
if (opportunity.size.inline_size >= fragment_inline_size &&
opportunity.size.block_size >= fragment_block_size)
break;
opportunity_candidate = opportunity_iter.Next();
}
......
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