Re: [csswg-drafts] [css-grid][css-contain] Clarify that `contain:size` affects track sizing (#4931)

> > The "_including_ when computing its intrinsic size" (my emphasis) seems to imply that it affects more size calculations than just the intrinsic size of the box itself.
> 
> No, it means that it's both the size of the box in actual layout, and the intrinsic size of the box if requested by its parent, that are calculated as if the box were empty. Not that other unspecified operations (such as track sizing) also treat it as empty.

This is a fundamental misunderstanding of how Grid layout works. Track sizing isn't "other unspecified operations" unrelated to a grid container's size. It's literally the way you calculate its content-box size, [per spec](https://drafts.csswg.org/css-grid/#intrinsic-sizes): "_The max-content size (min-content size) of a grid container is the sum of the grid container’s track sizes (including gutters) in the appropriate axis, when the grid is sized under a max-content constraint (min-content constraint)._" So suggesting that size-containment doesn't affect track sizing makes no sense because if it doesn't then it can't affect the grid container's size either.

To be concrete, [here's](https://searchfox.org/mozilla-central/rev/9120151ddb35f2d4c37bfe613a54a4f10a9a3dc5/layout/generic/nsGridContainerFrame.cpp#8012,8038,8053-8054,8059,8061) how Gecko reports "the intrinsic size of the box if requested by its parent". I've highlighted the three salient steps there:
1. place items into the grid
2. run the Track Sizing Algorithm (TSA) in the relevant axis
3. return the sum of the track sizes + gaps

> The spec tries to be explicit that once you've done this sizing step, everything else runs normally, with the following statement:
> 
> > Then, its contents must then be laid out into the containing box's resolved size.

OK, so it seems what you're trying to say then is that `contain:size` only has an effect when the grid container is sized under a min-/max-content constraint, and has no effect otherwise?

> > [...] I read "taken into account" there as "run the TSA pretending that the grid container has no items", which is what I suggested in the OP. I don't think there is a way to take the grid properties into account in any other way.
> 
> For the purpose of finding how big the grid is, yes. Hence the grid in your example being sized to `width:0; height:0;` But then we do actual layout of the grid, and at that point everything behaves as usual, and so it's track aren't empty.

I'm guessing "how big the grid is" means "what the content-box size of the grid container is". (please try to use precise terms that are defined in specs or we're going to talk past each other).

>  doing what you suggest instead doesn't seem necessary to allow the kind of optimizations that size-containment is trying to enable.

Doing what you suggest means that we have to run the TSA twice: once _without_ items to determine the grid container's content-box size and once _with_ items to determine the track sizes to use for layout of the children. Always running the TSA without items, as I suggested in the OP, is an optimization (and a lot simpler to implement since running it once is what we're currently doing).

> Yeah, in that case, Chromium is right and Firefox is wrong. That is exactly what the note in the spec is about:
> 
> > Even when the element’s sizing properties are auto this does not necessarily make the element zero-sized: properties set on the element itself, such as the columns property or the grid property, continue to be taken into account.

Right, but the way you "take the grid property into account" is to run the TSA. So again, there is no other way to implement this but **to run the TSA without items** (at least under a min-/max-content constraint) and use the track sizes that falls out. If you're thinking of something else then please point to spec text that defines that alternative algorithm.

I can live with doing it twice I guess, if you all think it's important that intrinsic track sizes should be sized normally before laying out the children.

-- 
GitHub Notification of comment by MatsPalmgren
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4931#issuecomment-611866864 using your GitHub account

Received on Friday, 10 April 2020 04:00:45 UTC