Re: [css-counters] Counters not in scope scope

On Thursday 2012-08-16 11:49 -0700, Elliott Sprehn wrote:
> I'm trying to fix and clean up the counter implementation in WebKit
> and came across some confusion in the spec:
> 
> http://www.w3.org/TR/CSS21/generate.html#scope
> """
> If 'counter-increment' or 'content' on an element or pseudo-element
> refers to a counter that is not in the scope of any 'counter-reset',
> implementations should behave as though a 'counter-reset' had reset
> the counter to 0 on that element or pseudo-element.
> """
> 
> To me this reads that every counter-increment or content: counter(x);
> when there's no scope should reset to 0 so given this example
> http://jsfiddle.net/mLUyP/ you should output all (1)'s since there's
> no counter-reset in the document. Instead WebKit and Gecko output
> (1)(2)(3) twice like the first counter-increment implies a
> counter-reset to 0 *and* establishes a new scope.

This is because a scope includes not just descendants but also all
later siblings and their descendants, at least up to (but not
including) a later sibling that also resets the same counter.

> Opera's behavior here is totally different:
> http://test.csswg.org/suites/css2.1/20110323/html4/counters-scope-implied-002.htm
> 
> Is there a reason for the implied scopes? Why not just reset every
> counter to 0 at the document root?

I think the reason to avoid a reset to zero on the root is to avoid
creepy action-at-a-distance.  In particular, if something is using
the counters() function (i.e., to produce output like "1.2" rather
than just "2"), then in a document like this (using elements with
silly names to imply what properties they have):

  <div>
    <reset-counter>
      <!-- without the second increment-and-use-counter this is "1".
           But if the element below creates an implicit reset on the
           root element then this becomes "1.1" -- which is also
           very strange in terms of incremental loading -->
      <increment-and-use-counter />
    </reset-counter>
  </div>
  <increment-and-use-counter />

-David

-- 
𝄞   L. David Baron                         http://dbaron.org/   𝄂
𝄢   Mozilla                           http://www.mozilla.org/   𝄂

Received on Thursday, 16 August 2012 19:07:20 UTC