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

View file

@ -84,9 +84,7 @@ pub(crate) enum BlockLevelBox {
OutOfFlowFloatBox(FloatBox), OutOfFlowFloatBox(FloatBox),
OutsideMarker(OutsideMarker), OutsideMarker(OutsideMarker),
SameFormattingContextBlock { SameFormattingContextBlock {
base_fragment_info: BaseFragmentInfo, base: LayoutBoxBase,
#[serde(skip_serializing)]
style: Arc<ComputedValues>,
contents: BlockContainer, contents: BlockContainer,
contains_floats: bool, contains_floats: bool,
}, },
@ -109,7 +107,7 @@ impl BlockLevelBox {
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
) -> bool { ) -> bool {
let style = match self { let style = match self {
BlockLevelBox::SameFormattingContextBlock { ref style, .. } => style, BlockLevelBox::SameFormattingContextBlock { base, .. } => &base.style,
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(_) | BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(_) |
BlockLevelBox::OutOfFlowFloatBox(_) => return true, BlockLevelBox::OutOfFlowFloatBox(_) => return true,
BlockLevelBox::OutsideMarker(_) => return false, BlockLevelBox::OutsideMarker(_) => return false,
@ -397,17 +395,17 @@ fn calculate_inline_content_size_for_block_level_boxes(
), ),
)) ))
}, },
BlockLevelBox::SameFormattingContextBlock { BlockLevelBox::SameFormattingContextBlock { base, contents, .. } => {
style, contents, ..
} => {
let inline_content_sizes_result = sizing::outer_inline( let inline_content_sizes_result = sizing::outer_inline(
style, &base.style,
containing_block, containing_block,
&LogicalVec2::zero(), &LogicalVec2::zero(),
false, /* auto_block_size_stretches_to_containing_block */ false, /* auto_block_size_stretches_to_containing_block */
|_| None, /* TODO: support preferred aspect ratios on non-replaced boxes */ |_| None, /* TODO: support preferred aspect ratios on non-replaced boxes */
|constraint_space| { |constraint_space| {
contents.inline_content_sizes(layout_context, 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, // 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>, collapsible_with_parent_start_margin: Option<CollapsibleWithParentStartMargin>,
) -> Fragment { ) -> Fragment {
match self { match self {
BlockLevelBox::SameFormattingContextBlock { BlockLevelBox::SameFormattingContextBlock { base, contents, .. } => {
base_fragment_info: tag, Fragment::Box(positioning_context.layout_maybe_position_relative_fragment(
style, layout_context,
contents, containing_block,
.. &base.style,
} => Fragment::Box(positioning_context.layout_maybe_position_relative_fragment( |positioning_context| {
layout_context, layout_in_flow_non_replaced_block_level_same_formatting_context(
containing_block, layout_context,
style, positioning_context,
|positioning_context| { containing_block,
layout_in_flow_non_replaced_block_level_same_formatting_context( base.base_fragment_info,
layout_context, &base.style,
positioning_context, contents,
containing_block, sequential_layout_state,
*tag, collapsible_with_parent_start_margin,
style, )
contents, },
sequential_layout_state, ))
collapsible_with_parent_start_margin, },
)
},
)),
BlockLevelBox::Independent(independent) => { BlockLevelBox::Independent(independent) => {
Fragment::Box(positioning_context.layout_maybe_position_relative_fragment( Fragment::Box(positioning_context.layout_maybe_position_relative_fragment(
layout_context, layout_context,