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

Re: Behavior of matches() and closest() with :scope()

From: Sean Hogan <shogun70@westnet.com.au>
Date: Mon, 22 Sep 2014 19:54:41 +1000
Message-ID: <541FF1E1.9040703@westnet.com.au>
To: Boris Zbarsky <bzbarsky@mit.edu>, Anne van Kesteren <annevk@annevk.nl>
CC: "Tab Atkins Jr." <jackalmage@gmail.com>, "www-style@w3.org" <www-style@w3.org>, "www-dom@w3.org" <www-dom@w3.org>, David Håsäther <hasather@gmail.com>
On 22/09/14 6:07 AM, Boris Zbarsky wrote:
> On 9/21/14, 8:02 AM, Sean Hogan wrote:
>> If no explicit scoping root is passed then EITHER:
>>      the selector must be an absolute selector
>
> :matches and :closest only allow absolute selectors right now, right? 
> So this is basically proposing an extension to the current spec to 
> allow relative selectors if an explicit scoping root is passed in?
>

No. I am also saying that if there is no explicit scope reference node 
passed in then the implied scope reference node is document (or some 
equivalent for elements not in document). I believe that currently the 
implied scope reference node is the element itself.

Currently:
     E.matches(':scope') -> true
     E.matches(':scope ul li') -> false

Should be:
     E.matches(':scope') -> false
     E.matches(':scope ul li') -> true if E.matches('ul li') is true

Not that anyone would want to write these. They are purely for 
illustration.

I am also saying that the behavior of closest() involves upwards 
traversal of the DOM *only as far as* the scope reference node. If there 
is no explicit scope reference node then the implied scope reference 
node is document (or equivalent) which results in expected behavior.

So:
     E.closest(selector, A) -> halts at A
     E.closest(selector) -> halts at document (or equivalent)

Imagine if closest() always traversed upwards until there were no more 
elements.
Then E.closest(selector, A) could be testing elements that were 
ancestors of A.

Or imagine closest() only traversed upwards to the scope reference node, 
but there was no explicit scope reference node and the implied scope 
reference node was the element itself.
Then E.closest(selector) would only test E.

>>      the implied scoping root is assumed to be the **document** or
>> fragment or virtual fragment of E.
>
> What is a "virtual fragment"?
>

If E is not in a document or a fragment, then it is part of a tree which 
has an element at its root (this root element may even be E). A virtual 
fragment is a virtual parent of this root element.

>> E.closest(selector, scope) attempts to find a matching element by
>> testing E against the selector, and if that fails then testing E's
>> parent, and-so-on until the scoping root is reached. The scoping root is
>> NOT tested, even if it is an element.
>
> OK.  But the scoping root is supposed to match :scope, even in 
> absolute selectors?

Is scoping root the wrong term? How about scoping reference node?

>
>> If the scoping root is assumed to be E then you can only have absolute
>> selectors.
>
> Right now this API only supports absolute selectors.
>

Conceptually you could allow all the following to be valid and 
equivalent (assuming E in document)
     E.matches('html #id')
     E.matches('html #id', document)
     E.matches(':scope > html #id')
     E.matches(':scope > html #id', document)
     E.matches('> html #id')
     E.matches('> html #id', document)
Received on Monday, 22 September 2014 09:55:20 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:46 UTC