Supporting Scoped Selectors in Selectors API 2

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.

-- 
Lachlan Hunt - Opera Software
http://lachy.id.au/
http://www.opera.com/

Received on Monday, 28 September 2009 11:51:20 UTC