layout: Unify logic for laying out replaced and non-replaced in a BFC (#37864)

The logic for laying out block-level replaced elements wasn't taking
floats into account when resolving a `stretch` inline size. By handling
them with the same logic as non-replaced elements, we fix that problem,
and reduce the amount of code.

Testing: Adding new tests
Fixes: #37861

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-07-04 19:47:40 +02:00 committed by GitHub
parent 72b1331949
commit 4ee7a34f32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 257 additions and 252 deletions

View file

@ -265,6 +265,48 @@ impl IndependentFormattingContext {
IndependentFormattingContextContents::Replaced(..) => {},
}
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn layout(
&self,
layout_context: &LayoutContext,
positioning_context: &mut PositioningContext,
containing_block_for_children: &ContainingBlock,
containing_block: &ContainingBlock,
preferred_aspect_ratio: Option<AspectRatio>,
depends_on_block_constraints: bool,
lazy_block_size: &LazySize,
) -> CacheableLayoutResult {
match &self.contents {
IndependentFormattingContextContents::NonReplaced(content) => content.layout(
layout_context,
positioning_context,
containing_block_for_children,
containing_block,
&self.base,
depends_on_block_constraints,
lazy_block_size,
),
IndependentFormattingContextContents::Replaced(content) => content.layout(
layout_context,
containing_block_for_children,
preferred_aspect_ratio,
&self.base,
depends_on_block_constraints,
lazy_block_size,
),
}
}
#[inline]
pub(crate) fn is_table(&self) -> bool {
matches!(
&self.contents,
IndependentFormattingContextContents::NonReplaced(
IndependentNonReplacedContents::Table(_)
)
)
}
}
impl IndependentNonReplacedContents {
@ -312,7 +354,7 @@ impl IndependentNonReplacedContents {
skip_all
)]
#[allow(clippy::too_many_arguments)]
pub fn layout(
pub(crate) fn layout(
&self,
layout_context: &LayoutContext,
positioning_context: &mut PositioningContext,
@ -378,11 +420,6 @@ impl IndependentNonReplacedContents {
None
}
#[inline]
pub(crate) fn is_table(&self) -> bool {
matches!(self, Self::Table(_))
}
fn repair_style(
&mut self,
context: &SharedStyleContext,