use super::*;
pub(in crate::layout) fn can_collapse_block_start_margin(
element: &Element,
style: &ComputedStyle,
border_edges: UsedEdges,
has_direct_inline_content: bool,
used_overflow: css::Overflow,
) -> bool {
style.display.is_flow()
&& !style.display.establishes_block_formatting_context()
&& !style_establishes_multicol_formatting_context(style)
&& !style_establishes_line_clamp_formatting_context(style)
&& !property_containment_establishes_independent_formatting_context(element, style)
&& style.float == Float::None
&& !has_direct_inline_content
&& used_overflow == css::Overflow::Visible
&& style.padding.top == 0.0
&& border_edges.top == layout_pt(0.0)
}
pub(in crate::layout) fn can_collapse_block_end_margin(
element: &Element,
style: &ComputedStyle,
containing_block_height_basis: BlockSizePercentageBasis,
border_edges: UsedEdges,
has_direct_inline_content: bool,
used_overflow: css::Overflow,
) -> bool {
style.display.is_flow()
&& !style.display.establishes_block_formatting_context()
&& !style_establishes_multicol_formatting_context(style)
&& !style_establishes_line_clamp_formatting_context(style)
&& !property_containment_establishes_independent_formatting_context(element, style)
&& style.float == Float::None
&& !has_direct_inline_content
&& used_overflow == css::Overflow::Visible
&& style.padding.bottom == 0.0
&& border_edges.bottom == layout_pt(0.0)
&& height_behaves_as_auto_for_margin_collapse(style, containing_block_height_basis)
}
pub(in crate::layout) fn height_behaves_as_auto_for_margin_collapse(
style: &ComputedStyle,
containing_block_height_basis: BlockSizePercentageBasis,
) -> bool {
match &*style.box_values.height {
css::ComputedLengthPercentageOrAuto::Auto
| css::ComputedLengthPercentageOrAuto::MinContent
| css::ComputedLengthPercentageOrAuto::MaxContent
| css::ComputedLengthPercentageOrAuto::FitContent(_) => true,
css::ComputedLengthPercentageOrAuto::Stretch => {
matches!(containing_block_height_basis, PercentageBasis::Indefinite)
}
css::ComputedLengthPercentageOrAuto::LengthPercentage(value) => {
matches!(containing_block_height_basis, PercentageBasis::Indefinite)
&& value.needs_percentage_basis()
}
css::ComputedLengthPercentageOrAuto::CalcSize(value) => {
matches!(&value.basis, css::CalcSizeBasis::Auto)
}
}
}
pub(in crate::layout) fn can_collapse_own_block_margins(
element: &Element,
style: &ComputedStyle,
border_widths: css::Edges,
has_direct_inline_content: bool,
used_overflow: css::Overflow,
) -> bool {
style.display.is_flow()
&& style.float == Float::None
&& !style_establishes_multicol_formatting_context(style)
&& !used_property_containment(element, style).establishes_independent_formatting_context()
&& !has_direct_inline_content
&& used_overflow == css::Overflow::Visible
&& style.padding.top == 0.0
&& style.padding.bottom == 0.0
&& border_widths.top == 0.0
&& border_widths.bottom == 0.0
&& height_is_auto_or_zero(style)
&& style.box_values.min_height.is_auto()
}
pub(in crate::layout) fn height_is_auto_or_zero(style: &ComputedStyle) -> bool {
style.box_values.height.is_auto()
|| style
.box_values
.height
.length_if_no_percent()
.is_some_and(|height| height == 0.0)
}