mod box_kind;
mod cursor;
pub mod generation;
pub mod geometry;
mod inline;
mod inline_run;
mod outer_display;
mod paint_style;
mod position;
mod rect;
mod wrap;
pub mod inner_formatting_context;
pub use box_kind::{BoxKind, ReplacedContent};
pub use cursor::Cursor;
pub use generation::{
GeneratedBox, GeneratedBoxKind, GeneratedPayload, flatten_contents_children, generate_box_tree,
generate_node, visible_children,
};
pub use geometry::{layout_generated_box, layout_generated_tree};
pub use inline::collect_runs;
pub(crate) use inline::{inline_tree_has_forced_break, q_quote_pair, text_node_run};
pub use inline_run::InlineRun;
pub use inner_formatting_context::FormattingContext;
pub use outer_display::OuterDisplay;
pub use paint_style::{ColumnLayout, PaintStyle, ScrollbarLayout};
pub(crate) use position::translate_subtree;
pub use position::{
apply_relative_offset, pin_fixed_boxes, pin_sticky_boxes, resolve_positioned_rects,
};
pub use rect::Rect;
pub use wrap::{apply_ellipsis, is_cjk_break_opportunity, wrap_runs, wrapped_size};
use crate::html::css_parse::Positioning;
use crate::tdom::node::NodeId;
#[derive(Debug, Clone)]
pub struct LayoutBox {
pub node_id: NodeId,
pub rect: Rect,
pub paint_style: PaintStyle,
pub kind: BoxKind,
pub outer_display: OuterDisplay,
pub inner_formatting_context: FormattingContext,
pub positioning: Positioning,
pub sticky_flow_y: Option<usize>,
pub children: Vec<LayoutBox>,
}
impl LayoutBox {
pub fn new_normal(
node_id: NodeId,
rect: Rect,
paint_style: PaintStyle,
outer_display: OuterDisplay,
children: Vec<LayoutBox>,
) -> Self {
Self::new_normal_with_context(
node_id,
rect,
paint_style,
outer_display,
FormattingContext::Flow,
children,
)
}
pub fn new_normal_with_context(
node_id: NodeId,
rect: Rect,
paint_style: PaintStyle,
outer_display: OuterDisplay,
inner_formatting_context: FormattingContext,
children: Vec<LayoutBox>,
) -> Self {
Self {
node_id,
rect,
paint_style,
kind: BoxKind::Normal,
outer_display,
inner_formatting_context,
positioning: Positioning::default(),
sticky_flow_y: None,
children,
}
}
pub fn new_flex_container(
node_id: NodeId,
rect: Rect,
paint_style: PaintStyle,
outer_display: OuterDisplay,
children: Vec<LayoutBox>,
) -> Self {
Self::new_normal_with_context(
node_id,
rect,
paint_style,
outer_display,
FormattingContext::Flex,
children,
)
}
pub fn new_replaced(
node_id: NodeId,
rect: Rect,
content: ReplacedContent,
paint_style: PaintStyle,
) -> Self {
Self {
node_id,
rect,
paint_style,
kind: BoxKind::Replaced(content),
outer_display: OuterDisplay::BlockLevel { container: false },
inner_formatting_context: FormattingContext::Flow,
positioning: Positioning::default(),
sticky_flow_y: None,
children: Vec::new(),
}
}
pub fn new_anonymous(
node_id: NodeId,
rect: Rect,
paint_style: PaintStyle,
children: Vec<LayoutBox>,
) -> Self {
Self {
node_id,
rect,
paint_style,
kind: BoxKind::Anonymous,
outer_display: OuterDisplay::BlockLevel { container: true },
inner_formatting_context: FormattingContext::Flow,
positioning: Positioning::default(),
sticky_flow_y: None,
children,
}
}
}