Skip to content

Commit 131d277

Browse files
committed
[selectors] Add API hooks for matching selectors against trees and elements, and dedup some IDs.
1 parent cefbbf8 commit 131d277

2 files changed

Lines changed: 173 additions & 39 deletions

File tree

selectors/Overview.bs

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ Type selectors and namespaces</h4>
14101410
namespace has been defined.
14111411
</div>
14121412

1413-
<h3 id="universal-selector">
1413+
<h3 id="the-universal-selector">
14141414
Universal selector </h3>
14151415

14161416
The <dfn export>universal selector</dfn>, written as a
@@ -2227,7 +2227,7 @@ The drag-and-drop pseudo-class '':drop'' and '':drop()''</h3>
22272227
For example, in HTML the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#the-dropzone-attribute"><code>dropzone</code></a> attribute
22282228
specified that an element is a drop target.
22292229

2230-
The <dfn>:drop()</dfn> functional pseudo-class is identical to '':drop'',
2230+
The <dfn id="selectordef-drop-function">:drop()</dfn> functional pseudo-class is identical to '':drop'',
22312231
but allows additional filters to be specified that can exclude some drop targets.
22322232
Its syntax is:
22332233

@@ -3031,7 +3031,7 @@ Grid-Structural Selectors</h2>
30313031
are defined.
30323032
In a column-primary format, these pseudo-classes match against row associations instead.
30333033

3034-
<h3 id="column-combinator">
3034+
<h3 id="the-column-combinator">
30353035
Column combinator</h3>
30363036

30373037
The <dfn export>column combinator</dfn>, which consists of two pipes (''||'')
@@ -3306,7 +3306,7 @@ API Hooks</h2>
33063306
To aid in the writing of specs that use Selectors concepts,
33073307
this section defines several API hooks that can be invoked by other specifications.
33083308

3309-
<h3 id='parse-a-selector'>
3309+
<h3 id='parse-selector'>
33103310
Parse A Selector</h3>
33113311

33123312
This section defines how to <dfn export>parse a selector</dfn> from a string <var>source</var>.
@@ -3331,7 +3331,7 @@ Parse A Selector</h3>
33313331
return <var>selector</var>.
33323332
</ol>
33333333

3334-
<h3 id='parse-a-relative-selector'>
3334+
<h3 id='parse-relative-selector'>
33353335
Parse A Relative Selector</h3>
33363336

33373337
This section defines how to <dfn export>parse a relative selector</dfn> from a string <var>source</var>,
@@ -3360,6 +3360,71 @@ Parse A Relative Selector</h3>
33603360
Return <var>selector</var>.
33613361
</ol>
33623362

3363+
<h3 id='match-against-tree'>
3364+
Match a Selector Against A Tree</h3>
3365+
3366+
This section defines how to <dfn export>match a selector against a tree</dfn>.
3367+
3368+
APIs calling this algorithm must provide a <var>selector</var>,
3369+
and a set of <var>root elements</var> of the trees to be matched against.
3370+
They may optionally provide:
3371+
3372+
<ul>
3373+
<li>
3374+
A <a>scoping method</a> and <a>scoping root</a>.
3375+
If not specified,
3376+
the selector defaults to being unscoped.
3377+
3378+
<li>
3379+
A set of <a>:scope elements</a>,
3380+
which will match the '':scope'' pseudo-class.
3381+
If not specified,
3382+
then if the selector is a <a>scoped selector</a>,
3383+
the set of <a>:scope elements</a> default to the <a>scoping root</a>;
3384+
otherwise,
3385+
it defaults to the <var>root elements</var>.
3386+
3387+
<li>
3388+
Which <a>pseudo-elements</a> are allowed to show up in the match list.
3389+
If not specified, this defaults to allowing all pseudo-elements.
3390+
</ul>
3391+
3392+
This algorithm returns a (possible empty) list of elements.
3393+
3394+
<ol>
3395+
<li>
3396+
<a>Evaluate a selector</a> with the same arguments provided to this algorithm,
3397+
and return the result.
3398+
</ol>
3399+
3400+
<h3 id='match-against-element'>
3401+
Match a Selector Against an Element</h3>
3402+
3403+
This section defines how to <dfn export>match a selector against an element</dfn>.
3404+
3405+
APIs calling this algorithm must provide a <var>selector</var> and an <var>element</var>.
3406+
They may optionally provide the same optional arguments as described in the algorithm to <a>match a selector against a tree</a>.
3407+
3408+
This algorithm returns either success or failure.
3409+
3410+
<ol>
3411+
<li>
3412+
Let <var>root element</var> be the "root ancestor" of <var>element</var>:
3413+
the element found by traversing parent links from <var>element</var>
3414+
until an element without a parent is encountered.
3415+
3416+
<li>
3417+
<a>Evaluate a selector</a> with <var>selector</var> and <var>root element</var>,
3418+
and any optional arguments passed to this algorithm.
3419+
Let <var>matched elements</var> be the result.
3420+
3421+
<li>
3422+
If <var>element</var> is in <var>matched elements</var>,
3423+
return success.
3424+
Otherwise,
3425+
return failure.
3426+
</ol>
3427+
33633428

33643429
<h2 id="changes">
33653430
Changes</h2>

0 commit comments

Comments
 (0)