[csswg-drafts] [css-gcpm-3] string-set with counter(page), when is value resolved? (#4740)

faceless2 has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-gcpm-3] string-set with counter(page), when is value resolved? ==
Take the following CSS and HTML:

```css
:root {
  counter-reset: page 0; /* UA rule */
}
@page {
  counter-increment: page 1; /* UA rule */
  @top-center {
    content: "page " string(x, first);
  }
}
body {
  string-set: x counter(page, decimal);
}
```
```html
<body>
  ... multi page content ...
</body>
```
What is displayed at the top of each page? There are two conceivable options:

1. The value is "page 1" on all pages, which is the result you would get it you set the value of "x" to the value of the _page_ counter when the string was first created.

2. The value is "page _n_", where page is the current page number. This is the result you would get if you evaluate the value of the _page_ counter when the string "x" is displayed, not when its set.

Prince chooses option 2, at least for the page counter - this exact approach is used in their "essay.html" example available at https://css4.pub. I am fairly convinced this is wrong, but have realised that this is not explicit in the specification (which is [here](https://drafts.csswg.org/css-gcpm/#setting-named-strings-the-string-set-pro), for reference).

Why do I think this is wrong? Because it is inconsistent with the way other counter values are used. Take an almost identical example:

```css
:root {
  counter-reset: section 0;
}
@page {
  @top-center {
    content: "section " string(x, first);
  }
}
h1 {
  counter-increment: section 1;
  string-set: x counter(section, decimal);
}
```
```html
<body>
  <h1>Header</h1>
  <h1>Header</h1>
  <h1>Header</h1>
</body>
```
The only difference here is that the counter is being incremented on the `<h1>`, not in the page rule. The intention of this is clear, and examples showing this type of approach exist in the spec and in various testcases. All agree that the value at the top of the page is "section 1".

But the only way you can get "section 1" is by evaluating the _section_ counter __when the string is set__. If you evaluate it when the string is displayed, you will get the current value of the counter, which - in this example - would result in "section 3".

The page counter is not magic - it is a normal counter as described in https://drafts.csswg.org/css-page-3/#page-based-counters, and the rules marked "UA rule" in the first example would be in the UA stylesheet, or equivalent structure.

I'm prepared to concede that there is a third way to conceive of this beyond the reach of my feeble mind. Whatever the solution, I think this needs clarification in the specification.

I'll prepare a proper (tentative) testcase and would be interested to hear the results from other paged media renderers.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4740 using your GitHub account

Received on Tuesday, 4 February 2020 18:20:00 UTC