Phase 9: Advanced Layout#
Implement overflow clipping so content that exceeds a box's dimensions is clipped according to the overflow property.
Current State#
Overflowenum (Visible, Hidden, Scroll, Auto) is parsed in computed styles- Layout and rendering ignore overflow entirely — content is never clipped
- No clip rect tracking in the layout tree
Requirements#
overflow: hidden: Content outside the box's padding edge is clipped and invisible. No scroll mechanism.overflow: visible(default): Content overflows freely — no clipping (current behavior).overflow: auto/overflow: scroll: For this issue, implement clipping only (scroll bars are a separate issue). Content that overflows is clipped.- Clip rect propagation: During rendering, establish a clip rect for boxes with
overflow!=visible. Nested clip rects intersect. - Overflow creates a new block formatting context: An element with
overflowother thanvisibleestablishes a new BFC (this prevents margin collapsing through it and contains floats).
Files to Modify#
crates/layout/src/lib.rs— StoreoverflowonLayoutBox, track content overflow dimensionscrates/render/src/lib.rs— Implement clip rect during painting; push/pop clip regions for nested overflow
Tests#
overflow: hiddenclips content that extends beyond the boxoverflow: visibledoes not clip (default behavior)- Nested overflow containers: inner clip intersects with outer clip
- Text content that overflows is clipped correctly
Acceptance Criteria#
overflow: hiddenclips overflowing content correctlyoverflow: auto/scrollclip content (scroll bars deferred)overflow: visiblecontinues to work as default- All tests pass, clippy clean, fmt clean