liorean wrote:
In this traversal scheme, querying the selector is still done from the
document node, just excluding all subtrees except for the subtree of
the element we're querying on.
Another alternative is of course to do the matching backwards,
beginning with trying to match the last simple selector in the
selectors on each of the elements of the subtree in question, then
traversing the tree in upwards direction.
Indeed. I believe the backwards approach is what UAs actually do, and
what makes the most sense to do. That is, the real question is whether
there is a subset of the maximal connected subtree containing the given
node (the one on which querySelector is being called) such that this
subset consists of nodes which match the various sequences of simple
selectors involved, and are positioned as required by the combinators,
with the element matching the rightmost sequence of simple selectors a
descendant of the given node. If so, that element matches the selector.
If Selectors does not define this sort of thing (and as I recall it
actually doesn't), then selectors api might need to. It would make the
most sense to define this in Selectors, however.
-Boris