Re: Supporting Scoped Selectors in Selectors API 2

fantasai wrote:
> Lachlan Hunt wrote:
>> I removed the syntactic flag from the scoped selector string and
>> introduced scoped methods instead.
>>
>> When those methods are used, for each selector in the group, if the
>> first sequence of simple selectors contains :reference, then no
>> special processing is performed. Otherwise, if it begins with a
>> sequence of simple selectors that doesn't contain :reference, then
>> :reference followed by a descendant combinator is inserted. Otherwise,
>> if it begins with a combinator (>, + or ~), then :reference is inserted.
>>
>> For example,
>>
>> "div div" becomes ":reference div div"
>> "+p" becomes ":reference+p"
>> ":reference>p" is unchanged.
>>
>> This allows authors to be explicit if they don't like the shorthand
>> syntax, while still allowing the shorthand for those that do.
>
> This works for me, assuming the :reference detection is from a full
> selector parse and not from any kind of string matching.

Yes, it uses full selector parsing.

> I have a slight preference for
> a) :scope instead of :reference

This does seem to be the only name that people seem to be happy with, 
despite it being not entirely accurate for all use cases.  So far, all 
the names considered seem to have problems.  All the ones I can recall are:

:scope, :this, :self, :context, :context-node, :reference, :ref, 
:important, :root, and the emoticon-inspired :D, :s and :p

Does everyone really think :scope is best for this?  I've changed the 
draft to use :-x-scope for now, until a decision is made.

> b) Requiring :scope when there's an explicit combinator so as not
> to present incomplete selector fragments.

I think that's suboptimal because it will require JS libraries to 
perform selector parsing themselves to insert the pseudo-class before 
passing it to the API.  But since adjusting selector parsing for this 
seems to be unacceptable :-(, I've reluctantly changed the spec to 
require the explicit pseudo-class when a combinator other than the 
descendant combinator is needed, so "+p" is no longer allowed. Scripts 
have to use ":reference+p" instead.  I will now have to deal with the 
inevitable complaints from authors and JS library develpers for making 
their lives harder.

http://dev.w3.org/2006/webapi/selectors-api2/#parse-a-scoped-selector

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

Received on Wednesday, 30 September 2009 12:31:38 UTC