Skip to content

Implement the layout-affecting parts of CSS layout and paint containment - #1128

Merged
nicoburns merged 3 commits into
mainfrom
devin/1787098726-contain-layout-paint
Aug 19, 2026
Merged

Implement the layout-affecting parts of CSS layout and paint containment#1128
nicoburns merged 3 commits into
mainfrom
devin/1787098726-contain-layout-paint

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Objective

Add a contain style to Taffy with layout and paint flags, and implement their layout effects. Based on the previously-reverted #1106, but with all size / inline-size containment stripped out.

New style API:

pub struct Contain(u8); // bitflags: NONE, LAYOUT, PAINT, CONTENT (= LAYOUT | PAINT)

pub struct Style { pub contain: Contain, ... }

pub trait CoreStyle {
    fn contain(&self) -> Contain { Contain::NONE } // defaulted
}

Implemented effects (both layout and paint, since both force an independent formatting context):

  • Block: a contained box establishes a new BFC — margins don't collapse with its children, it contains its own floats, and it avoids external floats
  • Overflow: a contained box's overflowing content no longer contributes to its ancestors' scrollable overflow regions (layout containment treats it as ink overflow; paint containment clips it). The box's own scrollable_overflow_rect still includes it
  • layout only: the box's baseline is suppressed for baseline-alignment purposes in block, flexbox and grid containers (a synthesized border-box baseline is used where one is required)

CSS parsing (parse feature) accepts none | content | [ layout || style || paint ]; style is accepted and ignored (no layout effect); strict / size / inline-size are rejected as size containment is not implemented.

Also fixes a preexisting block/float bug this work surfaced: overflowing in-flow content of a nested block no longer contributes to the height of its BFC root as if it were floated content (float_content_contribution now starts at NEG_INFINITY instead of the content edge).

CHANGELOG.md is updated under Added/Fixed.

Context

  • Inspiration commit (reverted): 20f04b9 / Implement the layout-affecting parts of the CSS contain property #1106
  • Gentest support added (contain attribute in fixtures/helper/xml runner) with new generated fixtures under test_fixtures/contain/ covering margin collapsing, float containment/avoidance, contain: content, and flex baseline suppression for both layout and paint
  • A companion Blitz PR wires up contain: layout / contain: paint from Stylo (link to follow)

Feedback wanted

  • Whether Contain as a minimal hand-rolled bitflags type (rather than a bitflags! dependency or an enum) is the preferred representation
  • The scrollable-overflow semantics: both containment types stop propagation to ancestors but keep the box's own scrollable_overflow_rect unclipped — for paint a consumer may additionally want to clip when painting

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/c903534a83f54a6daf2f68f4cc38cf72
Requested by: @nicoburns

Adds a Contain style type with LAYOUT and PAINT flags, a Style::contain
field and a defaulted CoreStyle::contain() accessor, plus CSS parsing
support for the contain property (none | content | [ layout || style || paint ]).

Layout and paint containment make the box establish an independent
formatting context (margins do not collapse with children, floats are
contained/avoided) and prevent the box's overflowing content from
contributing to its ancestors' scrollable overflow regions. Layout
containment additionally suppresses the box's baseline.

Also fixes a preexisting bug where the overflowing in-flow content of a
nested block contributed to the height of its BFC root as if it were
floated content.
@staging-devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@nicoburns
nicoburns merged commit 4ae4219 into main Aug 19, 2026
28 checks passed
@nicoburns
nicoburns deleted the devin/1787098726-contain-layout-paint branch August 19, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant