Re: Proposal: parent selectors

Boris Zbarsky wrote:
> On 1/21/10 3:26 PM, François REMY wrote:
>> The "cache" would contains every element matching "ul > li"
>> because every of those element could potentially match the
>> rule "ul:has(img) > li".
> 
> Ah, I see.  OK....
> 
> [...]
> 
> So you're assuming that we allow :has(img) but not, say :has(p img)?  Or
> that the latter is somehow scoped?

I'd hope that complex rules would be allowed.

How about following optimization strategy:

(1) Split any rule containing a :has() part into simpler pieces. E.g.
  div.message p:has(a img.thumbnail) span.nick
would be split into
  #1: div.message p a img.thumbnail
and
  #2: div.message p span.nick
behind the scenes. (If it possible to have multiple :has() parts in a
single selector, then all possible paths through the elements must
generate additional parts similar to #2.)
(2) Link the parts #1 and #2 to each other and to the original rule.
(3) After any DOM mutation, check if #2 matches (this should be fast
because the UA should already have a high performance implementation
today) and if #2 matches, then (4) follow the link to #1 and test all
elements matched by #1. The elements matched during the #2 check could
be cached because only those would need to be accessed while checking
the full :has() selector.

I'm aware that part (4) is not easy either because CSS is usually
targeted to problem "does *this element* match any rules" instead of
"what elements does *this rules* match"? Perhaps #1 needs to link to
list of elements that has been previously matched by #1? Is that enough?

-- 
Mikko

Received on Friday, 22 January 2010 12:58:43 UTC