use super::*;
pub(in crate::layout) fn style_is_in_normal_flow(style: &ComputedStyle) -> bool {
!style.display.is_none()
&& style.position.is_normal_flow()
&& style.float == Float::None
&& !style.position.is_running()
}
pub(in crate::layout) fn style_establishes_multicol_formatting_context(
style: &ComputedStyle,
) -> bool {
matches!(style.column_count, css::ColumnCount::Count(_))
|| matches!(style.column_width, css::ComputedColumnWidth::Length(_))
|| matches!(style.column_height, css::ComputedColumnHeight::Length(_))
}
pub(in crate::layout) fn style_establishes_line_clamp_formatting_context(
style: &ComputedStyle,
) -> bool {
!style_establishes_multicol_formatting_context(style)
&& matches!(
style.used_continuation(),
css::UsedContinuation::LineClamp(_) | css::UsedContinuation::Discard(_)
)
}
pub(in crate::layout) fn used_line_clamp_for_style(
style: &ComputedStyle,
) -> Option<css::InlineLineClamp<'_>> {
style
.line_limit_traversal
.as_ref()
.map(css::InlineLineClamp::Used)
.or_else(|| {
(!style_establishes_multicol_formatting_context(style))
.then(|| {
style
.line_clamp_container()
.map(css::InlineLineClamp::Computed)
})
.flatten()
})
}
pub(in crate::layout) fn is_normal_block_flow_child(
_element: &Element,
style: &ComputedStyle,
) -> bool {
style.position.is_normal_flow() && style.float == Float::None && style.display.is_block_level()
}
pub(in crate::layout) fn is_collapsible_block_child(
element: &Element,
style: &ComputedStyle,
) -> bool {
is_normal_block_flow_child(element, style) && !is_replaced_element(element)
}
pub(in crate::layout) fn outer_margins_adjoin_block_siblings(
element: &Element,
style: &ComputedStyle,
) -> bool {
is_normal_block_flow_child(element, style) && !is_replaced_element(element)
}
pub(in crate::layout) fn has_later_normal_block_flow_child_with_font_metrics(
element: &Element,
start_element_index: usize,
sibling_tags: &ElementSiblingSignatureList,
parent_style: &ComputedStyle,
stylesheets: &Stylesheets<'_>,
ancestors: &[ElementSignature],
font_system: &mut FontSystem,
) -> bool {
let mut resolver = DomStyleResolver::with_font_system(font_system);
has_later_normal_block_flow_child_with_resolver(
element,
start_element_index,
sibling_tags,
parent_style,
stylesheets,
ancestors,
&mut resolver,
)
}
pub(in crate::layout) fn has_later_normal_block_flow_child_with_resolver(
element: &Element,
start_element_index: usize,
sibling_tags: &ElementSiblingSignatureList,
parent_style: &ComputedStyle,
stylesheets: &Stylesheets<'_>,
ancestors: &[ElementSignature],
resolver: &mut DomStyleResolver<'_>,
) -> bool {
let mut element_index = 0usize;
for child in &element.children {
let NodeKind::Element(child_element) = &child.kind else {
continue;
};
let current_index = element_index;
element_index += 1;
if current_index < start_element_index {
continue;
}
let signature = ElementSignature::with_sibling_list(
child_element.tag.clone(),
child_element.attrs.clone(),
current_index,
sibling_tags.clone(),
);
let style = resolver.structural_style_for_element(
child_element,
signature,
stylesheets,
Some(parent_style),
ancestors,
);
if is_normal_block_flow_child(child_element, &style) || is_replaced_element(child_element) {
return true;
}
}
false
}
pub(in crate::layout) fn has_later_normal_block_flow_box_child(
child_boxes: &[box_tree::FormattingBox<'_>],
start_index: usize,
parent: &Element,
document_canvas: DocumentCanvasResolution,
) -> bool {
child_boxes
.iter()
.skip(start_index)
.any(|child| formatting_box_is_normal_block_flow_sibling(child, parent, document_canvas))
}
pub(in crate::layout) fn formatting_box_is_normal_block_flow_sibling(
child: &box_tree::FormattingBox<'_>,
parent: &Element,
document_canvas: DocumentCanvasResolution,
) -> bool {
match child {
box_tree::FormattingBox::AnonymousBlock(box_) => {
style_is_in_normal_flow(&box_.style)
&& !formatting_box_can_only_create_phantom_line_boxes(child)
}
_ => child
.element_parts()
.is_some_and(|(child_element, _, child_style, _)| {
style_is_in_normal_flow(child_style)
&& (is_normal_block_flow_child(child_element, child_style)
|| document_canvas.is_document_canvas_flow_element(parent)
|| is_replaced_element(child_element))
}),
}
}