Including margins that collapse through nested and self-collapsing children.
Determine block-end adjacency after line reflow and fix up the affected
used margins, positions, overflow and collapsed-margin state.
Differential D319486
Bug 2051240 - Implement margin-trim for block containers r=#layout Authored by tlouw on Aug 18 2026, 3:05 PM. Tags None Referenced Files
Details
Including margins that collapse through nested and self-collapsing children. Determine block-end adjacency after line reflow and fix up the affected
Diff Detail
Event TimelineThere are a very large number of changes, so older changes are hidden. Show Older Changes Comment Actions Mostly questions... I'm a bit confused as to why do we need the prediction machinery and the retry stuff. It seems to me that we could apply margins unconditionally, then only if you don't find a non-empty line (and don't need to fragment etc) undo the block dir advance of the last margin(s), to "un-account" for those. Would that approach not work? Seems it would avoid needing retries / predictions / looking eagerly at lines to come up with an index / etc, but maybe I'm missing something?
Comment Actions Okay, it seems that the prediction stuff wasn't really needed after all. I was worried about the post reflow fix-ups, but it didn't turn out to be that complex. I removed it (as well as the retries) and its much simpler now. Thanks for the suggestion! Comment Actions Mostly coming to understanding, a few nits, but float overflow handling happening after scrolled content check + return in UpdateMarginTrimLineOverflow seems suspect?
Comment Actions I think the algorithm & its helpers are correct, but at least some of them can be merged? May be tricky, but I have concerns about procedures that seem mostly-the-same being done in different places, specifically for when re-computing line overflows & checking if the frame may be margin trimmed.
Comment Actions The overflow handling seems rather suspect, I'd rather not add a whole "recompute the whole overflow areas of the line out of band" without very good justification. Why don't we need to do that when doing margin collapsing? Can we use the same approach? If not, can't we reuse some of the other overflow handling somehow? It seems like margin trimming is, conceptually, basically margin-collapsing without any previous margin (i.e., collapsing into the void), right... What are the differences that make us not able to reuse more of that mechanism? The generational margin terminology really confused me, but that's of course not new... @jfkthame should probably double-check the interaction there. I think the rest looks in good shape, but... Would it be possible to maybe split this into separate patches so that this can land incrementally? Something like:
That would make it a bit easier to digest, but I guess no worries if it's too hard.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||