// (scoped via BfcState) +spec:floats:2fa329 - Float positioning (left/right shift), content flow
// +spec:floats:148fcd - floating boxes reduce available line box width between containing block
// +spec:floats:054a1e - Clearance computation: positions border edge below bottom outer edge of
// +spec:block-formatting-context:b04653 - dispatches layout by formatting context type (BFC, IFC,
#[allow(clippy::implicit_hasher)] // internal helper; only ever called with the default-hasher HashMap/HashSet
// [g147b az-web-lift DIAG] per-node FormattingContext discriminant at layout_formatting_context
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
let width_adjustment = bp.border.left + bp.border.right + bp.padding.left + bp.padding.right;
let height_adjustment = bp.border.top + bp.border.bottom + bp.padding.top + bp.padding.bottom;
// placement constraints +spec:floats:6a1769 - Float shortens line boxes, margins never collapse,
// stacking order +spec:floats:15bfd9 - float:right positions element at line-right edge within BFC
// containment, earlier-float stacking, outer-top constraints, and "move down" when insufficient
// +spec:box-model:db0f02 - Float positioning: line boxes shortened by floats, floats shift down if
// no space, BFC elements must not overlap float margin boxes +spec:containing-block:136e45 - Float
// +spec:floats:45fce7 - Float positioning: pulled out of flow, line boxes shortened around float
// non-collapsing +spec:width-calculation:761677 - float positioning: content flows around floats,
/// 1. **Sizing Pass:** It first iterates through its children and triggers their layout recursively
/// by calling `calculate_layout_for_subtree`. This ensures that the `used_size` property of each
/// 2. **Positioning Pass:** It then iterates through the children again. Now that each child has a
// +spec:display-property:f38f52 - BFC handles normal flow, relative positioning offsets, and float
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose
// +spec:containing-block:42b75f - Block element establishes containing block for inline content
// - When calculate_layout_for_subtree recurses into children after layout_bfc returns, it hits
// +spec:display-property:9f6e18 - BFC dispatches normal flow, floats, and relative positioning
let child_escaped_bottom = if has_margin_collapse_blocker(&child_bp, writing_mode, false) {
let child_has_bottom_blocker = has_margin_collapse_blocker(&child_bp, writing_mode, false);
// 10.6.3: block-level non-replaced auto height = distance from top content edge to last in-flow
// +spec:inline-formatting-context:2227a4 - atomic inline baseline for inline-block/inline-table
/// 1. **Collect Content**: Traverse the direct children of the IFC root and convert them into a
/// - Recursively laying out `inline-block` children to determine their final size and baseline,
/// 2. **Translate Constraints**: Convert the `LayoutConstraints` (available space, floats) from
/// 3. **Invoke Text Layout**: Call the `text3` cache's `layout_flow` method to perform the complex
/// +spec:display-property:e96c82 - inline formatting context: flow of elements/text wrapped into
/// - Store the rich layout result on the IFC root `LayoutNode` for the display list generation
// +spec:display-property:574e7b - text-box-trim for inline boxes trims block-end to content edge
// (TODO: implement trimming per text-box-edge metric) +spec:display-property:da284a - IFC: flow
// inline-level boxes into line boxes, size/position each fragment +spec:inline-formatting-context:
// 275f64 - IFC: boxes laid out horizontally into line boxes, respecting margins/borders/padding
#[allow(clippy::field_reassign_with_default)] // struct built incrementally / test setup; a struct literal is not clearer here
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
let ifc_node_state = &styled_dom.styled_nodes.as_container()[ifc_root_dom_id].styled_node_state;
// [g147 az-web-lift DIAG] CALLER-side tree validity at layout_ifc entry, indexed by node_index
// Compare vs _impl's CALLEE-side (0x60940+/0x60960+): ptr differs ⇒ &mut tree mis-passes across
// +spec:display-property:a469a6 - line boxes created as needed for inline-level content in IFC
pub const fn convert_font_style(style: StyleFontStyle) -> crate::font_traits::FontStyle {
// +spec:block-formatting-context:40e03e - BFC root: block container establishing new BFC (contains
// parent's, based on overflow/position/float/display +spec:block-formatting-context:9fe441 - BFC
// establishment based on position, float, overflow, and display properties +spec:display-property:
// 3c7369 - block boxes establishing independent FC create new BFC; flex containers already do;
// +spec:overflow:f6a186 - overflow:clip does NOT establish BFC; use display:flow-root for that
// NOTE: align-content != normal should also establish BFC per CSS-DISPLAY-3, but align-content
// +spec:display-property:5e5420 - replaced element identification (glossary: replaced elements have
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose
let overflow_behaviour = get_overflow_x(styled_dom, id, node_state).unwrap_or_default();
// +spec:display-property:21f728 - vertical-align shorthand resolves inline-level box alignment
let text_orientation = match get_text_orientation_property(styled_dom, id, node_state) {
// +spec:display-contents:5f95ac - text-indent: percentage=0 for intrinsic sizing, each-line and
let explicit_column_count = declared_prop!(DOM_HAS_COLUMN_COUNT, get_column_count).copied();
// +spec:block-formatting-context:fd60a8 - initial letter box is in-flow in its BFC, originating
// +spec:display-property:b5e149 - initial letters are in-flow inline-level content, not floats
// +spec:line-height:306d87 - initial-letter sizing must use containing block's line-height, not
// +spec:floats:c5e23f - floats in subsequent lines adjacent to a sunk initial letter must clear
// +spec:line-breaking:9f150a - text-combine-upright:all composes glyphs horizontally, ignoring
// (§17.4-17.5) +spec:positioning:930891 - Table formatting context implementation (CSS 2.2 § 17
// row-group, row, cell (bottom to top) +spec:table-layout:dcdf1b - Collapsing border model: border
// conflict resolution uses layer priority (cell > row > row-group > column > column-group > table)
pub const fn new(width: f32, style: BorderStyle, color: ColorU, source: BorderSource) -> Self {
// +spec:box-model:2255c2 - Collapsing border conflict resolution (hidden wins, then none loses,
// conflict resolution per CSS 2.2 §17.6.2.1 (hidden wins, then wider, then style priority, then
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
// +spec:box-model:547563 - visibility:collapse removes table rows/columns; elsewhere same as hidden
// +spec:table-layout:dcdf1b - empty-cells property controls rendering of borders/backgrounds around
// row/column/cell/caption structure +spec:table-layout:a6422d - CSS table model: table structure
#[allow(clippy::cast_precision_loss)] // bounded graphics/coord/font/fixed-point/debug-marker cast
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
// +spec:width-calculation:431d60 - fixed vs auto table layout column width algorithms (CSS 2.2
let mut cell_positions = position_table_cells(&table_ctx, tree, ctx, node_index, constraints)?;
// +spec:display-property:7f167c - Table grid cell placement: rows fill table top-to-bottom, cells
// content +spec:positioning:46070a - Fixed table layout (17.5.2.1) and auto table layout (17.5.2.2)
// column width algorithms +spec:table-layout:875401 - Fixed table layout algorithm (17.5.2.1):
// +spec:table-layout:c5e446 - Fixed table layout algorithm: column widths from col elements or
/// +spec:width-calculation:8c958a - Fixed table layout: column widths from col elements, first-row
#[allow(clippy::cast_precision_loss)] // bounded graphics/coord/font/fixed-point/debug-marker cast
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
// +spec:display-property:05c8e8 - CSS 2.2 §17.5.2.2 automatic table layout: column min/max widths,
/// +spec:overflow:29edde - CSS 2.2 §17.5.2.2 automatic table layout: MCW/max-content per cell,
// +spec:table-layout:23a215 - automatic table layout: MCW/max cell widths, column min/max, colspan
// distribution, table width from MAX/MIN/CAPMIN +spec:table-layout:5e1145 - Automatic table layout:
// +spec:width-calculation:42dfca - CSS 2.2 §17.5.2.2 automatic table layout: MCW/max-content per
#[allow(clippy::suboptimal_flops)] // mul_add not guaranteed faster/available without target +fma; keep explicit a*b+c
#[allow(clippy::cast_precision_loss)] // bounded graphics/coord/font/fixed-point/debug-marker cast
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
#[allow(clippy::cast_precision_loss)] // bounded graphics/coord/font/fixed-point/debug-marker cast
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
// +spec:overflow:3fa86f - Table cell baseline: first in-flow line box or bottom of content edge;
// scrolling boxes treated as at origin +spec:inline-formatting-context:c4a20d - cell baseline:
// +spec:inline-formatting-context:27be38 - cell baseline is first in-flow line box or bottom of
/// +spec:box-model:72b495 - Table row height = max of computed height and MIN required by cells;
// +spec:display-property:728144 - Table height algorithm: row heights from cell content, rowspan
// computation, and horizontal alignment via text-align +spec:positioning:3eaadd - Table height
// height, cell heights, MIN); vertical-align in cells (baseline/top/middle/bottom, sub/super/etc.
#[allow(clippy::cast_precision_loss)] // bounded graphics/coord/font/fixed-point/debug-marker cast
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose
#[allow(clippy::suboptimal_flops)] // mul_add not guaranteed faster/available without target +fma; keep explicit a*b+c
#[allow(clippy::cast_precision_loss)] // bounded graphics/coord/font/fixed-point/debug-marker cast
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose
let (h_spacing, v_spacing) = if table_ctx.border_collapse == StyleBorderCollapse::Separate {
/// we can find its parent IFC's `inline_layout_result` via `ifc_membership.ifc_root_layout_index`.
// +spec:display-property:63a38b - inline box boundaries and out-of-flow elements are ignored for
/// * `content_box_top` — padding + border on the box's top edge, i.e. the offset from its border
#[allow(clippy::cast_possible_truncation)] // bounded graphics/coord/font/fixed-point/debug-marker cast
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose
// [g134/g135 az-web-lift DIAG] out-param pointer + tree validity at _impl entry. The early Err
// get_node_type() calls above. Those calls were corrupting the `dom_children` Vec's stack-slot
// +spec:display-property:c05c53 - inlinifying boxes can't contain block-level boxes; children are
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
// +spec:box-model:b7428d - empty inline boxes still have margins, padding, borders, line-height
// +spec:box-model:cc79a4 - empty inline elements still have margins, padding, borders and line
// vertical +spec:box-model:63d6f2 - scrollable overflow extends beyond padding edge, needs scroll
// mechanism +spec:box-model:45b5fb - scrollbar space subtracted from content area, inserted between
// inner border edge and outer padding edge +spec:box-model:70a0a4 - UAs must start assuming no
// scrollbars needed, recalculate if they are +spec:box-model:c1b0b2 - scrollbar gutter is space
// between inner border edge and outer padding edge +spec:overflow:4f5b99 - scrollable overflow
// +spec:overflow:e983f4 - overflow:auto/scroll boxes must allow user to access overflowed content
// via scrollbars +spec:overflow:97c257 - relative positioning causing overflow in auto/scroll boxes
OverflowBehavior::Visible | OverflowBehavior::Hidden | OverflowBehavior::Clip => false,
OverflowBehavior::Visible | OverflowBehavior::Hidden | OverflowBehavior::Clip => false,
// +spec:box-model:c3d73f - scrollbar presence affects available content area; padding preserved
/// Used for white-space modes that preserve segment breaks (pre, pre-wrap, pre-line, break-spaces).
// +spec:white-space-processing:af4e3f - each newline/segment break in text is treated as a segment
/// +spec:white-space-processing:159dbf - segment breaks converted to spaces (default transform)
// +spec:white-space-processing:7e9529 - Segment break transformation rules (§4.1.3): collapse
// +spec:white-space-processing:b64e38 - parser may normalize/collapse whitespace before CSS; CSS
// +spec:display-property:1389e3 - bidi control characters per UAX #9 for Unicode bidirectional
// algorithm +spec:display-property:aad99b - inline boxes can be split into fragments due to bidi
// text processing Bidi_Control property (UAX #9). These characters are ignored during white-space
/// +spec:white-space-processing:1188f6 - only spaces, tabs, and segment breaks are document white
/// space Returns true if `c` is a CSS "document white space character" per CSS Text Level 3 §4.1.
// +spec:white-space-processing:efbece - white-space property controls collapsing/preserving of
// formatting characters for rendering +spec:writing-modes:b87688 - inlines laid out with bidi
// reordering and white-space wrapping +spec:writing-modes:cdd4f1 - white space trimming before bidi
// reordering preserves end-of-line spaces per UAX9 L1 white space characters are processed prior to
// line breaking and bidi reordering +spec:inline-block:381c0c - white-space property: collapsing,
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
// +spec:white-space-processing:bd11da - white-space property: new lines, spaces/tabs, wrapping
} else if had_trailing && had_leading && collapsed.is_empty() { /* already have one space */
// +spec:white-space-processing:5e3f70 - text-transform applied after Phase I collapsing, before
/// (cap-height-to-advance-width ~0.7 for Latin text). A proper implementation would measure the
/// 4. The `sink` value determines how many lines the letter drops below the first baseline. When
/// `sink == size`, this is a classic drop cap. When `sink < size`, the letter rises above the
// +spec:width-calculation:7f4f68 - initial-letter-wrap exclusion area (none behavior; first/grid
#[allow(clippy::cast_precision_loss)] // bounded graphics/coord/font/fixed-point/debug-marker cast
fn hot(parent: Option<usize>, used_size: Option<LogicalSize>, bp: &BoxProps) -> LayoutNodeHot {