Skip to content

Commit 37d80bb

Browse files
committed
[selectors] Dfn 'evaluate a selector', make it take scoping into account, refine the 'Match a Selector' API hook.
1 parent 0263a12 commit 37d80bb

2 files changed

Lines changed: 66 additions & 76 deletions

File tree

selectors/Overview.html

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,15 +1373,36 @@ <h3 id=structure><span class=secno>3.1. </span> Structure and Terminology</h3>
13731373
<h3 id=evaluating-selectors><span class=secno>3.2. </span> Evaluating a
13741374
Selector</h3>
13751375

1376+
<p>This section describes how to <dfn data-export=data-export
1377+
id=evaluate-a-selector>evaluate a selector</dfn> against a set of
1378+
elements.
1379+
13761380
<p>A <a href="#selector"><i>selector</i></a> is evaluated against some
13771381
initial list of elements, as determined by the context that the selector
13781382
is evaluated in: the <dfn data-export=data-export
1379-
id=selector-match-list>selector match list</dfn>. The selector is
1380-
processed from left to right in order, with <a href="#simple"><i>simple
1383+
id=selector-match-list>selector match list</dfn>. If the selector is <a
1384+
href="#scope-contained"><i>scope-contained</i></a>, the <a
1385+
href="#selector-match-list"><i>selector match list</i></a> is immediately
1386+
filtered to contain only elements that are either the <a
1387+
href="#scoping-root"><i>scoping root</i></a> or descendants of the <a
1388+
href="#scoping-root"><i>scoping root</i></a>. The selector is processed
1389+
from left to right in order, with <a href="#simple"><i>simple
13811390
selectors</i></a> filtering the <i>selector match set</i>, and <a
13821391
href="#combinator0"><i>combinators</i></a> changing the <i>selector match
1383-
set</i> into something new. When this process is done, the elements in the
1384-
<i>selector match set</i> are the elements said to match the selector.
1392+
set</i> into something new. If the selector is <a
1393+
href="#scope-contained"><i>scope-contained</i></a> then after each <a
1394+
href="#combinator0"><i>combinator</i></a> the <a
1395+
href="#selector-match-list"><i>selector match list</i></a> must be
1396+
filtered to contain only elements that are either the <a
1397+
href="#scoping-root"><i>scoping root</i></a> or descendants of the <a
1398+
href="#scoping-root"><i>scoping root</i></a>. If the selector is <a
1399+
href="#scope-filtered"><i>scope-filtered</i></a>, then after the selector
1400+
is finished processing, the <a href="#selector-match-list"><i>selector
1401+
match list</i></a> must be filtered to contain only elements that are
1402+
either the <a href="#scoping-root"><i>scoping root</i></a> or descendants
1403+
of the <a href="#scoping-root"><i>scoping root</i></a>. When this process
1404+
is done, the elements in the <i>selector match set</i> are the elements
1405+
said to match the selector.
13851406

13861407
<p>For example, to evaluate the selector "div > i.name" against a document,
13871408
the <a href="#selector-match-list"><i>selector match list</i></a> is first
@@ -4383,48 +4404,25 @@ <h3 id=parse-a-relative-selector><span class=secno>17.2. </span> Parse A
43834404
<h3 id=match-a-selector><span class=secno>17.3. </span> Match A Selector</h3>
43844405

43854406
<p> This section describes how to <dfn id=match-a-selector0>match a
4386-
selector</dfn> <var title="">selector</var> against a tree of nodes
4407+
selector</dfn> <var title="">selector</var>. Optionally, a tree of nodes
4408+
<var>nodes</var> to be matched against may be provided; if not, the
4409+
default <a href="#initial-selector-match-list"><i>initial selector match
4410+
list</i></a> for selectors in the given context is used as
43874411
<var>nodes</var>. Optionally, a <a href="#scoping-root"><i>scoping
4388-
root</i></a> and scoping method (<a
4412+
root</i></a> and <a href="#scoping-methods"><i>scoping method</i></a> (<a
43894413
href="#scope-contained"><i>scope-contained</i></a> or <a
43904414
href="#scope-filtered"><i>scope-filtered</i></a>) may be provided.
43914415
Optionally, an explicit <a href="#reference-element-set"><i>reference
43924416
element set</i></a> <var>element set</var> (which may be empty) may be
43934417
provided. It returns a list of zero or more elements.
43944418

4395-
<p> If an explicit <a href="#reference-element-set"><i>reference element
4396-
set</i></a> is given, this algorithm may be called without specifying a
4397-
tree of nodes. (The tree will be inferred from each element in the set;
4398-
this makes it easier to invoke the algorithm for a relative selector.)
4399-
4400-
<ol>
4401-
<li> If no explicit <a href="#reference-element-set"><i>reference element
4402-
set</i></a> was given, return the result of matching <var
4403-
title="">selector</var> against <var>nodes</var>, with the <a
4404-
href="#scoping-root"><i>scoping root</i></a> and scoping method if they
4405-
were provided.
4406-
4407-
<li> Otherwise, let <var>result</var> initially be the empty list.
4408-
4409-
<li> For each element <var>reference element</var> in <var>element
4410-
set</var>:
4411-
<ol>
4412-
<li> If <var>nodes</var> was not given, let <var>nodes</var> be all the
4413-
nodes in the same tree as <var>reference element</var>.
4414-
4415-
<li> Let <var>single result</var> be the result of matching <var
4416-
title="">selector</var> against <var>nodes</var>, with the <a
4417-
href="#scoping-root"><i>scoping root</i></a> and scoping method if they
4418-
were provided, and <var>reference element</var> as the <a
4419-
href="#reference-element-set"><i>reference element set</i></a>.
4420-
4421-
<li> Append each element in <var>single result</var> to
4422-
<var>result</var>, unless the element is already present in
4423-
<var>result</var>.
4424-
</ol>
4425-
4426-
<li> Return <var>result</var>.
4427-
</ol>
4419+
<p> <a href="#evaluate-a-selector"><i>Evaluate a selector</i></a> <var
4420+
title="">selector</var> against <var>nodes</var> with the <a
4421+
href="#scoping-root"><i>scoping root</i></a>, <a
4422+
href="#scoping-methods"><i>scoping method</i></a>, and <a
4423+
href="#reference-element-set"><i>reference element set</i></a> if they
4424+
were provided, and return the elements that match the selector. Return the
4425+
nodes matched by the selector.
44284426

44294427
<h2 id=changes><span class=secno>18. </span> Changes</h2>
44304428

selectors/Overview.src.html

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,30 @@ <h3 id="structure">
643643
<h3 id='evaluating-selectors'>
644644
Evaluating a Selector</h3>
645645

646+
<p>This section describes how to <dfn data-export>evaluate a selector</dfn> against a set of elements.
647+
646648
<p>A <i>selector</i> is evaluated against some initial list of elements,
647649
as determined by the context that the selector is evaluated in:
648650
the <dfn data-export>selector match list</dfn>.
651+
If the selector is <i>scope-contained</i>,
652+
the <i>selector match list</i> is immediately filtered
653+
to contain only elements that are either the <i>scoping root</i>
654+
or descendants of the <i>scoping root</i>.
655+
649656
The selector is processed from left to right in order,
650657
with <i>simple selectors</i> filtering the <i>selector match set</i>,
651658
and <i>combinators</i> changing the <i>selector match set</i> into something new.
659+
If the selector is <i>scope-contained</i>
660+
then after each <i>combinator</i>
661+
the <i>selector match list</i> must be filtered
662+
to contain only elements that are either the <i>scoping root</i>
663+
or descendants of the <i>scoping root</i>.
664+
If the selector is <i>scope-filtered</i>,
665+
then after the selector is finished processing,
666+
the <i>selector match list</i> must be filtered
667+
to contain only elements that are either the <i>scoping root</i>
668+
or descendants of the <i>scoping root</i>.
669+
652670
When this process is done, the elements in the <i>selector match set</i>
653671
are the elements said to match the selector.
654672

@@ -3208,48 +3226,22 @@ <h3 id='match-a-selector'>
32083226
Match A Selector</h3>
32093227

32103228
<p>
3211-
This section describes how to <dfn>match a selector</dfn> <var title=''>selector</var> against a tree of nodes <var>nodes</var>.
3212-
Optionally, a <i>scoping root</i> and scoping method (<i>scope-contained</i> or <i>scope-filtered</i>) may be provided.
3229+
This section describes how to <dfn>match a selector</dfn> <var title=''>selector</var>.
3230+
Optionally, a tree of nodes <var>nodes</var> to be matched against may be provided;
3231+
if not, the default <i>initial selector match list</i> for selectors in the given context is used as <var>nodes</var>.
3232+
Optionally, a <i>scoping root</i> and <i>scoping method</i> (<i>scope-contained</i> or <i>scope-filtered</i>) may be provided.
32133233
Optionally, an explicit <i>reference element set</i> <var>element set</var> (which may be empty) may be provided.
32143234
It returns a list of zero or more elements.
32153235

32163236
<p>
3217-
If an explicit <i>reference element set</i> is given,
3218-
this algorithm may be called without specifying a tree of nodes.
3219-
(The tree will be inferred from each element in the set;
3220-
this makes it easier to invoke the algorithm for a relative selector.)
3221-
3222-
<ol>
3223-
<li>
3224-
If no explicit <i>reference element set</i> was given,
3225-
return the result of matching <var title=''>selector</var> against <var>nodes</var>,
3226-
with the <i>scoping root</i> and scoping method if they were provided.
3227-
3228-
<li>
3229-
Otherwise,
3230-
let <var>result</var> initially be the empty list.
3231-
3232-
<li>
3233-
For each element <var>reference element</var> in <var>element set</var>:
3234-
3235-
<ol>
3236-
<li>
3237-
If <var>nodes</var> was not given,
3238-
let <var>nodes</var> be all the nodes in the same tree as <var>reference element</var>.
3237+
<i>Evaluate a selector</i> <var title=''>selector</var> against <var>nodes</var>
3238+
with the <i>scoping root</i>,
3239+
<i>scoping method</i>,
3240+
and <i>reference element set</i>
3241+
if they were provided,
3242+
and return the elements that match the selector.
3243+
Return the nodes matched by the selector.
32393244

3240-
<li>
3241-
Let <var>single result</var> be the result of matching <var title=''>selector</var> against <var>nodes</var>,
3242-
with the <i>scoping root</i> and scoping method if they were provided,
3243-
and <var>reference element</var> as the <i>reference element set</i>.
3244-
3245-
<li>
3246-
Append each element in <var>single result</var> to <var>result</var>,
3247-
unless the element is already present in <var>result</var>.
3248-
</ol>
3249-
3250-
<li>
3251-
Return <var>result</var>.
3252-
</ol>
32533245

32543246

32553247

0 commit comments

Comments
 (0)