W3C home > Mailing lists > Public > www-style@w3.org > September 2009

Re: Supporting Scoped Selectors in Selectors API 2

From: fantasai <fantasai.lists@inkedblade.net>
Date: Mon, 28 Sep 2009 11:16:17 -0700
Message-ID: <4AC0FD71.2070203@inkedblade.net>
To: Lachlan Hunt <lachlan.hunt@lachy.id.au>
CC: www-style <www-style@w3.org>
Lachlan Hunt wrote:
> Hi,
>   I would like to get feedback from the CSSWG regarding the approach 
> I've taken to support scoped selectors in Selectors API Level 2.
> The editor's draft for this spec can be found here.
> http://dev.w3.org/2006/webapi/selectors-api2/
> The two specific sections I would like to discuss are the use of *scoped 
> selector strings*, which are custom selector-like syntax which need 
> special pre-processing to be interpreted as a proper selector, and the 
> :reference pseudo class.
> The :reference pseudo-class was previously discussed with the CSS WG, 
> though it was known as :scope or :context at the time.  The original 
> proposal and discussion for which can be found here.
> http://lists.w3.org/Archives/Public/www-style/2008Jul/0193.html
> http://lists.w3.org/Archives/Public/www-archive/2008Jul/att-0025/Overview.html 
> The definition has changed slightly since then, but the basic concept is 
> still the same.
> Scoped selector strings are selectors that begin with either a 
> combinator like '>', '+' or '~', or, because the descendant combinator 
> can't work due to the need to strip whitespace, an exclamation point.
> e.g.
> var elm = document.getElementById("foo");
> elm.querySelector(">em, >strong");
> ems.querySelector("+p");
> ems.querySelector("~p");
> These are pre-processed and interpreted as being equivalent to 
> ":reference>em, :reference>strong", ":reference+p" and ":reference~p", 
> respectively, where :reference matches the element elm.  This is 
> designed to be more compatible with how JavaScript libraries operate.
> Because the descendant combinator can't work in the same way, I've used 
> the exclamation point character as an indicator that it is intended to 
> be a scoped selector.
> e.g.
> elm.querySelector("!div div, div p");
> That is interpreted as being equivalent to:
>   ":reference div div, :reference div p".
> This character was chosen because it currently can't appear at the 
> beginning of a conforming group of selectors.  But it also makes the 
> assumption that future selector syntax will never allow a selector to 
> begin with an exclamation point, or at least not in a way that would 
> clash with its use here.
> I would like to find out if the CSSWG finds this acceptable, or if I 
> should try to find an alternative solution.

I agree with Tab here, the use of ! is a strange way of handling special
cases like this. Its exceptional use is confusing, and its scoping is
inconsistent with the way selectors work. I'd rather see something like

   elm.scopeSelector("div div, div p")

I think it's much clearer how that works and it avoids screwing around
with the Selectors syntax. An API like that is how I would have expected
querySelector to work; that it doesn't is weird imho.

I will also note that the use of ! has been proposed for other things,
and I would strongly prefer if your API did not introduce any new
punctuation into the Selectors syntax.

Received on Monday, 28 September 2009 18:17:06 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:38:29 UTC