Skip to content

Commit

Permalink
Totally ignore abspos children for intrinsic sizing (#30010)
Browse files Browse the repository at this point in the history
calculate_inline_content_size_for_block_level_boxes was relying on
inline_content_sizes to get the size of each block-level box child.
For absolutely positioned boxes, this was 0x0.

That was no-op before #29887, but then it prevented adding the sizes
of a sequence of floats. Abspos should just be ignored instead of
treated as 0x0.

This patch removes inline_content_sizes, moves the logic into
calculate_inline_content_size_for_block_level_boxes (the only caller),
and handles abspos correctly.
  • Loading branch information
Loirooriol committed Jul 19, 2023
1 parent ae3f33b commit 9c333ab
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions components/layout_2020/flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,30 @@ fn calculate_inline_content_size_for_block_level_boxes(
writing_mode: WritingMode,
) -> ContentSizes {
let get_box_info = |box_: &ArcRefCell<BlockLevelBox>| {
let size = box_
.borrow_mut()
.inline_content_sizes(layout_context, writing_mode);
if let BlockLevelBox::OutOfFlowFloatBox(ref float_box) = *box_.borrow_mut() {
let style_box = &float_box.contents.style().get_box();
(size, style_box.float, style_box.clear)
} else {
// The element may in fact have clearance, but the logic below ignores it,
// so don't bother retrieving it from the style.
(size, Float::None, Clear::None)
match &mut *box_.borrow_mut() {
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(_) => None,
BlockLevelBox::OutOfFlowFloatBox(ref mut float_box) => {
let size = float_box
.contents
.outer_inline_content_sizes(layout_context, writing_mode);
let style_box = &float_box.contents.style().get_box();
Some((size, style_box.float, style_box.clear))
},
BlockLevelBox::SameFormattingContextBlock {
style, contents, ..
} => {
let size = sizing::outer_inline(&style, writing_mode, || {
contents.inline_content_sizes(layout_context, style.writing_mode)
});
// The element may in fact have clearance, but the logic below ignores it,
// so don't bother retrieving it from the style.
Some((size, Float::None, Clear::None))
},
BlockLevelBox::Independent(ref mut independent) => {
let size = independent.outer_inline_content_sizes(layout_context, writing_mode);
// TODO: do the right thing instead of copying SameFormattingContextBlock.
Some((size, Float::None, Clear::None))
},
}
};

Expand Down Expand Up @@ -295,12 +309,12 @@ fn calculate_inline_content_size_for_block_level_boxes(
let data = if layout_context.use_rayon {
boxes
.par_iter()
.map(get_box_info)
.filter_map(get_box_info)
.collect::<Vec<_>>()
.into_iter()
.fold(zero, accumulate)
} else {
boxes.iter().map(get_box_info).fold(zero, accumulate)
boxes.iter().filter_map(get_box_info).fold(zero, accumulate)
};
data.max_size_including_uncleared_floats()
}
Expand Down Expand Up @@ -552,26 +566,6 @@ impl BlockLevelBox {
)),
}
}

fn inline_content_sizes(
&mut self,
layout_context: &LayoutContext,
containing_block_writing_mode: WritingMode,
) -> ContentSizes {
match self {
Self::SameFormattingContextBlock {
style, contents, ..
} => sizing::outer_inline(style, containing_block_writing_mode, || {
contents.inline_content_sizes(layout_context, style.writing_mode)
}),
Self::Independent(independent) => independent
.outer_inline_content_sizes(layout_context, containing_block_writing_mode),
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(_) => ContentSizes::zero(),
BlockLevelBox::OutOfFlowFloatBox(float_box) => float_box
.contents
.outer_inline_content_sizes(layout_context, containing_block_writing_mode),
}
}
}

/// Lay out a normal flow non-replaced block that does not establish a new formatting
Expand Down

0 comments on commit 9c333ab

Please sign in to comment.