Commit ed2f02d8 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Fix inline out-of-flow container computation

The out-of-flow code assumed that all fragments for a
LayoutInline has the same height, but the change for
crbug.com/903578 (WIP CL:1251142) breaks the assumption.

This patch fixes by computing the rect and uniting them,
instead of taking the max of heights.

No behavior changes until the WIP CL lands.

Change-Id: I9fe6b35d25836fde10dd88dd90ca2a810f5c9863
Bug: 636993, 903578
Reviewed-on: https://chromium-review.googlesource.com/c/1351189Reviewed-by: default avatarAleks Totic <atotic@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610994}
parent 3e019656
...@@ -219,6 +219,10 @@ void NGBoxFragmentBuilder::ComputeInlineContainerFragments( ...@@ -219,6 +219,10 @@ void NGBoxFragmentBuilder::ComputeInlineContainerFragments(
if (children_[i]->IsLineBox()) { if (children_[i]->IsLineBox()) {
const NGPhysicalLineBoxFragment* linebox = const NGPhysicalLineBoxFragment* linebox =
ToNGPhysicalLineBoxFragment(children_[i].get()); ToNGPhysicalLineBoxFragment(children_[i].get());
const NGPhysicalOffset linebox_offset = offsets_[i].ConvertToPhysical(
GetWritingMode(), Direction(),
ToNGPhysicalSize(Size(), GetWritingMode()), linebox->Size());
for (auto& descendant : for (auto& descendant :
NGInlineFragmentTraversal::DescendantsOf(*linebox)) { NGInlineFragmentTraversal::DescendantsOf(*linebox)) {
LayoutObject* key = {}; LayoutObject* key = {};
...@@ -230,54 +234,31 @@ void NGBoxFragmentBuilder::ComputeInlineContainerFragments( ...@@ -230,54 +234,31 @@ void NGBoxFragmentBuilder::ComputeInlineContainerFragments(
} else if (descendant.fragment->IsBox()) { } else if (descendant.fragment->IsBox()) {
key = descendant.fragment->GetLayoutObject(); key = descendant.fragment->GetLayoutObject();
} }
if (key && inline_container_fragments->Contains(key)) { if (!key)
NGBoxFragmentBuilder::FragmentPair value = continue;
inline_container_fragments->at(key); auto it = inline_container_fragments->find(key);
if (!value.start_fragment) { if (it != inline_container_fragments->end()) {
NGBoxFragmentBuilder::FragmentPair& value = it->value;
// |DescendantsOf| returns the offset from the given fragment. Since
// we give it the line box, need to add the |linebox_offset|.
NGPhysicalOffsetRect fragment_rect(
linebox_offset + descendant.offset_to_container_box,
descendant.fragment->Size());
if (value.start_linebox_fragment == linebox) {
value.start_fragment_union_rect.Unite(fragment_rect);
} else if (!value.start_fragment) {
value.start_fragment = descendant.fragment.get(); value.start_fragment = descendant.fragment.get();
value.start_fragment_union_rect.offset = value.start_fragment_union_rect = fragment_rect;
descendant.offset_to_container_box;
value.start_fragment_union_rect =
NGPhysicalOffsetRect(descendant.offset_to_container_box,
value.start_fragment->Size());
value.start_linebox_fragment = linebox; value.start_linebox_fragment = linebox;
value.start_linebox_offset = offsets_.at(i);
} }
if (!value.end_fragment || value.end_linebox_fragment != linebox) { // Skip fragments within an empty line boxes for the end fragment.
if (value.end_linebox_fragment == linebox) {
value.end_fragment_union_rect.Unite(fragment_rect);
} else if (!value.end_fragment || !linebox->IsEmptyLineBox()) {
value.end_fragment = descendant.fragment.get(); value.end_fragment = descendant.fragment.get();
value.end_fragment_union_rect = NGPhysicalOffsetRect( value.end_fragment_union_rect = fragment_rect;
descendant.offset_to_container_box, value.end_fragment->Size());
value.end_linebox_fragment = linebox; value.end_linebox_fragment = linebox;
value.end_linebox_offset = offsets_.at(i);
}
// Extend the union size
if (value.start_linebox_fragment == linebox) {
// std::max because initial box might have larger extent than its
// descendants.
value.start_fragment_union_rect.size.width =
std::max(descendant.offset_to_container_box.left +
descendant.fragment->Size().width -
value.start_fragment_union_rect.offset.left,
value.start_fragment_union_rect.size.width);
value.start_fragment_union_rect.size.height =
std::max(descendant.offset_to_container_box.top +
descendant.fragment->Size().height -
value.start_fragment_union_rect.offset.top,
value.start_fragment_union_rect.size.height);
}
if (value.end_linebox_fragment == linebox) {
value.end_fragment_union_rect.size.width =
std::max(descendant.offset_to_container_box.left +
descendant.fragment->Size().width -
value.start_fragment_union_rect.offset.left,
value.end_fragment_union_rect.size.width);
value.end_fragment_union_rect.size.height =
std::max(descendant.offset_to_container_box.top +
descendant.fragment->Size().height -
value.start_fragment_union_rect.offset.top,
value.end_fragment_union_rect.size.height);
} }
inline_container_fragments->Set(key, value);
} }
} }
} }
......
...@@ -213,8 +213,6 @@ class CORE_EXPORT NGBoxFragmentBuilder final ...@@ -213,8 +213,6 @@ class CORE_EXPORT NGBoxFragmentBuilder final
DISALLOW_NEW(); DISALLOW_NEW();
// Linebox that contains start_fragment. // Linebox that contains start_fragment.
const NGPhysicalLineBoxFragment* start_linebox_fragment; const NGPhysicalLineBoxFragment* start_linebox_fragment;
// Offset of start_linebox from containing block.
NGLogicalOffset start_linebox_offset;
// Start fragment of inline containing block. // Start fragment of inline containing block.
const NGPhysicalFragment* start_fragment; const NGPhysicalFragment* start_fragment;
// Start fragment rect combined with rectangles of all fragments // Start fragment rect combined with rectangles of all fragments
...@@ -222,7 +220,6 @@ class CORE_EXPORT NGBoxFragmentBuilder final ...@@ -222,7 +220,6 @@ class CORE_EXPORT NGBoxFragmentBuilder final
NGPhysicalOffsetRect start_fragment_union_rect; NGPhysicalOffsetRect start_fragment_union_rect;
// end_** variables are end fragment counterparts to start fragment. // end_** variables are end fragment counterparts to start fragment.
const NGPhysicalLineBoxFragment* end_linebox_fragment; const NGPhysicalLineBoxFragment* end_linebox_fragment;
NGLogicalOffset end_linebox_offset;
const NGPhysicalFragment* end_fragment; const NGPhysicalFragment* end_fragment;
NGPhysicalOffsetRect end_fragment_union_rect; NGPhysicalOffsetRect end_fragment_union_rect;
}; };
......
...@@ -199,11 +199,6 @@ void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks( ...@@ -199,11 +199,6 @@ void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks(
start_fragment_logical_offset.ConvertToPhysical( start_fragment_logical_offset.ConvertToPhysical(
container_writing_mode, container_direction, container_writing_mode, container_direction,
start_linebox_fragment->Size(), NGPhysicalSize()); start_linebox_fragment->Size(), NGPhysicalSize());
NGPhysicalOffset start_linebox_physical_offset =
block_info.value.start_linebox_offset.ConvertToPhysical(
container_writing_mode, container_direction,
container_builder_physical_size, start_linebox_fragment->Size());
start_fragment_physical_offset += start_linebox_physical_offset;
// Step 2 // Step 2
const NGPhysicalLineBoxFragment* end_linebox_fragment = const NGPhysicalLineBoxFragment* end_linebox_fragment =
block_info.value.end_linebox_fragment; block_info.value.end_linebox_fragment;
...@@ -228,11 +223,6 @@ void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks( ...@@ -228,11 +223,6 @@ void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks(
end_fragment_bottom_right.ConvertToPhysical( end_fragment_bottom_right.ConvertToPhysical(
container_writing_mode, container_direction, container_writing_mode, container_direction,
end_linebox_fragment->Size(), NGPhysicalSize()); end_linebox_fragment->Size(), NGPhysicalSize());
NGPhysicalOffset end_linebox_physical_offset =
block_info.value.end_linebox_offset.ConvertToPhysical(
container_writing_mode, container_direction,
container_builder_physical_size, end_linebox_fragment->Size());
end_fragment_physical_offset += end_linebox_physical_offset;
// Step 3 // Step 3
NGLogicalOffset start_fragment_logical_offset_wrt_box = NGLogicalOffset start_fragment_logical_offset_wrt_box =
start_fragment_physical_offset.ConvertToLogical( start_fragment_physical_offset.ConvertToLogical(
......
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