layout: Have SameFormattingContextBlock be a LayoutBoxBase (#34530)

This allows `SameFormattingContextBlock` to cache inline content sizes
and will eventually allow it to participate in incremental layout.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-12-09 07:57:15 +01:00 committed by GitHub
parent af8f35f5ef
commit f5fdbd70d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 33 deletions

View file

@ -26,6 +26,7 @@ use crate::dom_traversal::{
use crate::flow::float::FloatBox;
use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox};
use crate::formatting_contexts::IndependentFormattingContext;
use crate::layout_box_base::LayoutBoxBase;
use crate::positioned::AbsolutelyPositionedBox;
use crate::style_ext::{ComputedValuesExt, DisplayGeneratingBox, DisplayInside, DisplayOutside};
use crate::table::{AnonymousTableContent, Table};
@ -654,9 +655,8 @@ where
let contents = intermediate_block_container.finish(context, info);
let contains_floats = contents.contains_floats();
ArcRefCell::new(BlockLevelBox::SameFormattingContextBlock {
base_fragment_info: info.into(),
base: LayoutBoxBase::new(info.into(), info.style.clone()),
contents,
style: Arc::clone(&info.style),
contains_floats,
})
},

View file

@ -84,9 +84,7 @@ pub(crate) enum BlockLevelBox {
OutOfFlowFloatBox(FloatBox),
OutsideMarker(OutsideMarker),
SameFormattingContextBlock {
base_fragment_info: BaseFragmentInfo,
#[serde(skip_serializing)]
style: Arc<ComputedValues>,
base: LayoutBoxBase,
contents: BlockContainer,
contains_floats: bool,
},
@ -109,7 +107,7 @@ impl BlockLevelBox {
containing_block: &ContainingBlock,
) -> bool {
let style = match self {
BlockLevelBox::SameFormattingContextBlock { ref style, .. } => style,
BlockLevelBox::SameFormattingContextBlock { base, .. } => &base.style,
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(_) |
BlockLevelBox::OutOfFlowFloatBox(_) => return true,
BlockLevelBox::OutsideMarker(_) => return false,
@ -397,17 +395,17 @@ fn calculate_inline_content_size_for_block_level_boxes(
),
))
},
BlockLevelBox::SameFormattingContextBlock {
style, contents, ..
} => {
BlockLevelBox::SameFormattingContextBlock { base, contents, .. } => {
let inline_content_sizes_result = sizing::outer_inline(
style,
&base.style,
containing_block,
&LogicalVec2::zero(),
false, /* auto_block_size_stretches_to_containing_block */
|_| None, /* TODO: support preferred aspect ratios on non-replaced boxes */
|constraint_space| {
base.inline_content_sizes(constraint_space, || {
contents.inline_content_sizes(layout_context, constraint_space)
})
},
);
// A block in the same BFC can overlap floats, it's not moved next to them,
@ -693,28 +691,25 @@ impl BlockLevelBox {
collapsible_with_parent_start_margin: Option<CollapsibleWithParentStartMargin>,
) -> Fragment {
match self {
BlockLevelBox::SameFormattingContextBlock {
base_fragment_info: tag,
style,
contents,
..
} => Fragment::Box(positioning_context.layout_maybe_position_relative_fragment(
BlockLevelBox::SameFormattingContextBlock { base, contents, .. } => {
Fragment::Box(positioning_context.layout_maybe_position_relative_fragment(
layout_context,
containing_block,
style,
&base.style,
|positioning_context| {
layout_in_flow_non_replaced_block_level_same_formatting_context(
layout_context,
positioning_context,
containing_block,
*tag,
style,
base.base_fragment_info,
&base.style,
contents,
sequential_layout_state,
collapsible_with_parent_start_margin,
)
},
)),
))
},
BlockLevelBox::Independent(independent) => {
Fragment::Box(positioning_context.layout_maybe_position_relative_fragment(
layout_context,