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

My understanding is the same as @bfgeek and @Loirooriol here. The "inculding intrinsic size" bit means that if the layout of any parent of the size-contained element depends in some way on the intrinsic size of that size-contained element, then that input to its layout is the same as if that size-contained element was empty.

For instance, the size of a grid row depends on the intrinsic sizes of the elements in that row. Say you have a column which is sized to min-content, we look at the intrinsic min content size of the elements in the column, pick the largest, size the column that way, and then do the actual layout of the grid items in that column at that width. During that phase, if any of the grid items have size containment, they'll be treated as empty for the purpose of figuring out their min-content size.

However, setting size-containment on the grid itself would not affect the intrinsic size calculation of the grid items.

> 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. 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.

----

> Anyway, the Containment spec already says that "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.". 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.

At least:
* that's what I meant when I phrased the spec that way
* doing what you suggest instead doesn't seem necessary to allow the kind of optimizations that size-containment is trying to enable. (to be fair, I don't think it would disable them either.)

That said, if it is not clear (which seems to be the case), the spec should certainly at least be clarified. If we have agreement that the behavior suggested here would be more useful, I suspect we could switch to that, but it's not clear to me that it is.

----

> Chromium and Firefox are not interoperable in these cases:
> 
> ```html
> <div style="display: inline-grid; grid-auto-columns: 50px; height: 50px; contain: size; border: > 5px solid">
>   <div style="background: yellow"></div>
> </div>
> ```
>
> In Chromium, the content area of the grid container is 50px wide, in Firefox it's 0px.

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.

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

Received on Friday, 10 April 2020 00:17:24 UTC