Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687// Admitted candidate `model_0` (qwen3.8-flash-next, 105/105); provenance: containing_block.provenance.jsonuse crate::containing_block::{AncestorBox, ContainingBlockInputs, ContainingBlockOutputs, ContainingBlockRule, Rect};use dom::computed::Position;
pub fn resolve(inputs: &ContainingBlockInputs) -> ContainingBlockOutputs { // Rule 1: The root element's containing block is the initial containing block. // The root element has no ancestors. if inputs.ancestors.is_empty() { return ContainingBlockOutputs { rect: inputs.viewport, rule: ContainingBlockRule::RootElement, ancestor: None, }; }
match inputs.position { // Rule 3: A fixed box's containing block is the viewport. Position::Fixed => { ContainingBlockOutputs { rect: inputs.viewport, rule: ContainingBlockRule::Viewport, ancestor: None, } } // Rule 4: An absolute box's containing block is the padding edge of the nearest // ancestor whose position is not static. If there is no such ancestor, the initial // containing block. Position::Absolute => { // Find the nearest ancestor (nearest-first, so lowest index) with position != Static let found = inputs .ancestors .iter() .position(|a| a.position != Position::Static);
match found { Some(idx) => { ContainingBlockOutputs { rect: inputs.ancestors[idx].padding_box, rule: ContainingBlockRule::NearestPositionedAncestorPaddingEdge, ancestor: Some(idx), } } None => { // No positioned ancestor found: use the initial containing block (viewport) ContainingBlockOutputs { rect: inputs.viewport, rule: ContainingBlockRule::InitialContainingBlock, ancestor: None, } } } } // Rule 2: A static or relative box's containing block is the content edge of its // nearest block-container ancestor. Position::Static | Position::Relative => { // Find the nearest ancestor (nearest-first, so lowest index) that is a block container let found = inputs .ancestors .iter() .position(|a| a.is_block_container);
match found { Some(idx) => { ContainingBlockOutputs { rect: inputs.ancestors[idx].content_box, rule: ContainingBlockRule::NearestBlockContainerContentEdge, ancestor: Some(idx), } } None => { // Should not happen in practice if there's always a block container ancestor, // but fall back to the last ancestor's content box if none marked as block container. // Or if we truly have no block container ancestor, we might fall back to viewport? // The spec says "nearest block container ancestor". If none exists, behavior is undefined // in this simplified model, but typically the root is a block container. // Let's use the last ancestor if any, otherwise viewport. let last_idx = inputs.ancestors.len() - 1; ContainingBlockOutputs { rect: inputs.ancestors[last_idx].content_box, rule: ContainingBlockRule::NearestBlockContainerContentEdge, ancestor: Some(last_idx), } } } } }}