//! 1. The `layout_document` function takes the `viewport` as an argument. The `LayoutCache` stores
//! percentage-based sizes and repositions all elements according to the new viewport dimensions.
//! 4. The intrinsic size calculation (bottom-up) can often be skipped, as it's independent of the
pub fn get_size(&self, slot: usize, known_dims: LogicalSize) -> Option<&SizingCacheEntry> {
#[allow(clippy::match_same_arms)] // enum/value mapping/dispatch table: one arm per input variant
pub(crate) fn to_overflow_behavior(overflow: MultiValue<LayoutOverflow>) -> fc::OverflowBehavior {
pub fn collect_children_dom_ids(styled_dom: &StyledDom, parent_dom_id: NodeId) -> Vec<NodeId> {
let writing_mode = get_writing_mode(styled_dom, dom_id, &styled_node_state).unwrap_or_default();
/// - In table structural contexts (table, row-group, row) whitespace text nodes are skipped (CSS
/// - Whitespace-only inline runs that sit between block siblings collapse to zero boxes (CSS 2.2
let parent_state = &styled_dom.styled_nodes.as_container()[parent_dom_id].styled_node_state;
let white_space = match get_white_space_property(styled_dom, parent_dom_id, parent_state) {
/// Recursively traverses the new DOM and old tree, building a new tree and marking dirty nodes.
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
let mut new_children_dom_ids: Vec<_> = collect_children_dom_ids(styled_dom, new_dom_id);
.filter(|&&cidx| t.warm(LayoutNodeId::new(cidx)).is_none_or(|w| w.pseudo_element.is_none()))
.filter_map(|&cidx| t.get(LayoutNodeId::new(cidx)).and_then(|n| n.dom_node_id).map(|did| (did, cidx)))
let mut children_are_different = new_layout_relevant_count != old_layout_relevant_count;
// +spec:overflow:08b60d - non-interactive media: UA may show scroll indicators but we skip them
// +spec:overflow:3a6966 - classic scrollbar gutter width == scrollbar width; overlay scrollbars
let scrollbar_gutter = get_scrollbar_gutter_property(ctx.styled_dom, dom_id, styled_node_state)
/// * `display_list::paint_scrollbars`, which cannot read a post-layout write-back: the display list
/// is built inside the very layout pass that recomputes `warm.scrollbar_info` from scratch; and
/// * `shell2::common::layout::register_scroll_nodes`, which stores the amended value back into
compute_scrollbar_info_core(ctx, dom_id, styled_node_state, content_size, container_size)
// self_content_box_pos is [CoordinateSpace::Window] - absolute position of parent's content-box
/// - **`ComputeSize`** (BFC Pass 1 — sizing): Computes only the node's border-box size. On cache
/// hit from measurement slots, sets `used_size` and returns immediately — no child positioning.
/// - **`PerformLayout`** (BFC Pass 2 — positioning): Computes size AND positions all children. On
/// cache hit from layout slot, applies cached child positions recursively. When Pass 2 provides
/// the same constraints as Pass 1, the "result matches request" optimization triggers automatic
#[allow(clippy::implicit_hasher)] // internal helper; only ever called with the default-hasher HashMap/HashSet
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
// [g147b az-web-lift DIAG] per-node calculate_layout_for_subtree entry (0x60980+slot): records
// Positions in layout_result.output.positions are [CoordinateSpace::Parent] - relative to this
#[allow(clippy::match_same_arms)] // enum/value mapping/dispatch table: one arm per input variant
_ => node_props.padding.main_sum(writing_mode) + node_props.border.main_sum(writing_mode),
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
matches!(cache.pending_patch_damage(seq - 1), PendingPatchDamage::Rects(ref v) if v.len() == 1)