Closed Bug 1519958 Opened 1 year ago Closed 1 year ago

The computed value of grid-template-{columns|rows} should not expand repeat()


(Core :: CSS Parsing and Computation, defect, P3)




Tracking Status
firefox66 --- affected


(Reporter: boris, Assigned: emilio)


(Blocks 2 open bugs, )



(2 files, 1 obsolete file)

Based on the spec [1][2], it seems the repeat() notation is resolved in resolved values, instead of computed track list. The current Gecko expands repeat() (with numeric repeat count) in ToComputedValue [3]. This is incorrect, and will have impact on interpolation between repeat()s.


BTW, there is a discussion about interpolating repeat():

Priority: -- → P3

The spec issue,, is resolved by a more restrictive rule for now:

Define repeat interpolation using the more restrictive rule in

It could be loosen, but for now we should follow the restrictive rule: require that the first arg is a number, and identical between start/end; different values, or keyword values, both go discrete

That means we have to fix this bug to match the updated spec and fix the wpts [1]/[2], which uses a loosen way if the first arg is a number (because Gecko uses an incorrect computed value of repeat()).


Assignee: nobody → boris.chiou

It seems the biggest problem is: nsStyleCoord doesn't support general function type (i.e. only calc() is acceptable), and we use m{Max|Min}TrackSizingFunctions to represent all the different types of <track-size>, but not <track-repeat> (i.e. repeat() notation). In order to make sure we keep repeat() notation in the computed value, we have to

  1. Do not expand repeat() in ToComputedValue
  2. Redesign nsStyleGridTemplate so it could represent <track-size>|<track-repeat>_
  3. Update the conversion code in, and then update all the layout code to use the new type. (And maybe need to resolve it by adding an utility function)

Looks like we have a lot of things to do.

Blocks: 1341507

I have a wip patch that removes nsStyleGridTemplate and does this while at it. Still needs a bunch of work, but if you're not actively working on this mind if I take it?

Flags: needinfo?(boris.chiou)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #4)

I have a wip patch that removes nsStyleGridTemplate and does this while at it. Still needs a bunch of work, but if you're not actively working on this mind if I take it?

Sure. Please feel free to take this. (It’s better to fix this together with using cbindgen.)

Flags: needinfo?(boris.chiou)

Cool, thanks!

Flags: needinfo?(emilio)

While we're at it we may as well do this.

Depends on D36349

Comment on attachment 9074825 [details]
Bug 1519958 - Drive by, remove unused CSS keywords. r=#style,boris

Revision D36350 was moved to bug 1562269. Setting attachment 9074825 [details] to obsolete.

Attachment #9074825 - Attachment is obsolete: true
Pushed by
Drive by, remove unused CSS keywords. r=boris

Ouch, landed with the wrong bug # :(

Keywords: leave-open
Assignee: boris.chiou → emilio
Depends on: 1562789

I'm really sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.

This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:

  • Make us preserve repeat() at computed-value time. This is per spec since
    interpolation needs to know about repeat(). Except for subgrid, which did the
    repeat expansion at parse-time and was a bit more annoying (plus it doesn't
    really animate yet so we don't need it to comply with the spec).

  • Tweaks the WPT tests for interpolation to adopt the resolution at:

Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.

Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.

This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.

In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around

This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.

Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.

This re-enables the assertion which was disabled on the previous patch by doing
a bit of boxing around.

Depends on D36598

Flags: needinfo?(emilio)
Pushed by
Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
Improve stack size of grid templates and re-enable style struct size assertions disabled in the previous patch. r=boris
Created web-platform-tests PR for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.
Pushed by
followup: Fix bustage in 32-bit builds and rust unit tests. r=me
Upstream PR merged
Keywords: leave-open
Closed: 1 year ago
Resolution: --- → FIXED
No longer blocks: 1578717
Regressions: 1581106
You need to log in before you can comment on or make changes to this bug.