Skip to content

Commit 42838d8

Browse files
committed
[selectors] Remove 'match a selector', by making 'evaluate a selector' a usable API entry point.
1 parent 33dd098 commit 42838d8

2 files changed

Lines changed: 79 additions & 43 deletions

File tree

selectors/Overview.bs

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,37 @@ Evaluating a Selector</h3>
568568

569569
This section describes how to <dfn export>evaluate a selector</dfn> against a set of elements.
570570

571+
APIs using this algorithm must provide a selector.
572+
They may optionally provide:
573+
574+
<ul>
575+
<li>
576+
a <a>selector match list</a> of elements to match against.
577+
If not specified, the <a>initial selector match list</a> for the selector's context is used.
578+
579+
<li>
580+
a <a>scoping method</a> and <a>scoping root</a>.
581+
If not specified, the selector defaults to being unscoped.
582+
583+
<li>
584+
a set of <a>:scope elements</a>,
585+
for resolving the '':scope'' pseudo-class against.
586+
If not specified,
587+
the set defaults to being empty.
588+
589+
If the selector is a <a>relative selector</a>,
590+
the set of <a>:scope elements</a> must not be empty.
591+
592+
Note: Note that if the selector is scoped,
593+
the scoping root is automatically taken as the <a>:scope element</a>,
594+
so it doesn't have to be provided explicitly
595+
unless a different result is desired.
596+
597+
<li>
598+
which <a>pseudo-elements</a> are allowed to show up in the match list, if any.
599+
If not specified, this defaults to allowing all pseudo-elements.
600+
</ul>
601+
571602
A <a>selector</a> is evaluated against some initial list of elements,
572603
as determined by the context that the selector is evaluated in:
573604
the <dfn export>selector match list</dfn>.
@@ -578,18 +609,24 @@ Evaluating a Selector</h3>
578609

579610
The selector is processed from left to right in order,
580611
with <a>simple selectors</a> filtering the <a>selector match list</a>,
581-
and <a>combinators</a> changing the <a>selector match list</a> into something new.
612+
and <a>combinators</a> and <a>pseudo-elements</a> changing the <a>selector match list</a> into something new.
582613
If the selector is <a>scope-contained</a>
583614
then after each <a>combinator</a>
584615
the <a>selector match list</a> must be filtered
585616
to contain only elements that are either the <a>scoping root</a>
586617
or descendants of the <a>scoping root</a>.
618+
587619
If the selector is <a>scope-filtered</a>,
588620
then after the selector is finished processing,
589621
the <a>selector match list</a> must be filtered
590622
to contain only elements that are either the <a>scoping root</a>
591623
or descendants of the <a>scoping root</a>.
592624

625+
After the selector is finished matching,
626+
the <a>selector match list</a> must be filtered
627+
to only contain elements and <a>pseudo-elements</a>
628+
allowed by the invoker of this algorithm.
629+
593630
When this process is done, the elements in the <a>selector match list</a>
594631
are the elements said to match the selector.
595632
If the order of elements matter,
@@ -3294,24 +3331,6 @@ Parse A Relative Selector</h3>
32943331
Return <var>selector</var>.
32953332
</ol>
32963333

3297-
<h3 id='match-a-selector'>
3298-
Match A Selector</h3>
3299-
3300-
This section describes how to <dfn export>match a selector</dfn> <var>selector</var>.
3301-
Optionally, a tree of nodes <var>nodes</var> to be matched against may be provided;
3302-
if not, the default <a>initial selector match list</a> for selectors in the given context is used as <var>nodes</var>.
3303-
Optionally, a <a>scoping root</a> and <a>scoping method</a> (<a>scope-contained</a> or <a>scope-filtered</a>) may be provided.
3304-
Optionally, an explicit <a>:scope elements</a> <var>element set</var> (which may be empty) may be provided.
3305-
It returns a list of zero or more elements.
3306-
3307-
<a>Evaluate a selector</a> <var>selector</var> against <var>nodes</var>
3308-
with the <a>scoping root</a>,
3309-
<a>scoping method</a>,
3310-
and <a>:scope elements</a>
3311-
if they were provided,
3312-
and return the elements that match the selector.
3313-
Return the nodes matched by the selector.
3314-
33153334

33163335
<h2 id="changes">
33173336
Changes</h2>

selectors/Overview.html

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</p>
6060
<h1 class="p-name no-ref" id=title>Selectors Level 4</h1>
6161
<h2 class="no-num no-toc no-ref heading settled heading" id=subtitle><span class=content>Editor’s Draft,
62-
<span class=dt-updated><span class=value-title title=20140328>28 March 2014</span></span></span></h2>
62+
<span class=dt-updated><span class=value-title title=20140329>29 March 2014</span></span></span></h2>
6363
<div data-fill-with=spec-metadata><dl><dt>This version:<dd><a class=u-url href=http://dev.w3.org/csswg/selectors>http://dev.w3.org/csswg/selectors</a><dt>Latest version:<dd><a href=http://www.w3.org/TR/selectors/>http://www.w3.org/TR/selectors/</a><dt>Editor’s Draft:<dd><a href=http://dev.w3.org/csswg/selectors>http://dev.w3.org/csswg/selectors</a><dt>Previous Versions:<dd><a href=http://www.w3.org/TR/2013/WD-selectors4-20130502/ rel=previous>http://www.w3.org/TR/2013/WD-selectors4-20130502/</a><dd><a href=http://www.w3.org/TR/2012/WD-selectors4-20120823/ rel=previous>http://www.w3.org/TR/2012/WD-selectors4-20120823/</a><dd><a href=http://www.w3.org/TR/2011/WD-selectors4-20110929/ rel=previous>http://www.w3.org/TR/2011/WD-selectors4-20110929/</a>
6464
<dt>Feedback:</dt>
6565
<dd><a href="mailto:www-style@w3.org?subject=%5Bselectors%5D%20feedback">www-style@w3.org</a>
@@ -237,8 +237,7 @@ <h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class
237237
<li><a href=#api-hooks><span class=secno>17</span> API Hooks</a>
238238
<ul class=toc>
239239
<li><a href=#parse-a-selector><span class=secno>17.1</span> Parse A Selector</a>
240-
<li><a href=#parse-a-relative-selector><span class=secno>17.2</span> Parse A Relative Selector</a>
241-
<li><a href=#match-a-selector><span class=secno>17.3</span> Match A Selector</a></ul>
240+
<li><a href=#parse-a-relative-selector><span class=secno>17.2</span> Parse A Relative Selector</a></ul>
242241
<li><a href=#changes><span class=secno>18</span> Changes</a>
243242
<li><a href=#acknowledgements><span class=secno>19</span> Acknowledgements</a>
244243
<li><a href=#conformance><span class=secno></span> Conformance</a>
@@ -797,6 +796,37 @@ <h3 class="heading settled heading" data-level=3.2 id=evaluating-selectors><span
797796

798797
<p> This section describes how to <dfn data-dfn-type=dfn data-export="" id=evaluate-a-selector>evaluate a selector<a class=self-link href=#evaluate-a-selector></a></dfn> against a set of elements.
799798

799+
<p> APIs using this algorithm must provide a selector.
800+
They may optionally provide:
801+
802+
<p> <ul>
803+
<li>
804+
a <a data-link-type=dfn href=#selector-match-list title="selector match list">selector match list</a> of elements to match against.
805+
If not specified, the <a data-link-type=dfn href=#initial-selector-match-list title="initial selector match list">initial selector match list</a> for the selector’s context is used.
806+
807+
<li>
808+
a <a data-link-type=dfn href=#scoping-method- title="scoping method">scoping method</a> and <a data-link-type=dfn href=#scoping-root title="scoping root">scoping root</a>.
809+
If not specified, the selector defaults to being unscoped.
810+
811+
<li>
812+
a set of <a data-link-type=dfn href=#scope-element title=":scope elements">:scope elements</a>,
813+
for resolving the <a class=css data-link-type=maybe href=#scope-pseudo title=:scope>:scope</a> pseudo-class against.
814+
If not specified,
815+
the set defaults to being empty.
816+
817+
<p> If the selector is a <a data-link-type=dfn href=#relative-selector- title="relative selector">relative selector</a>,
818+
the set of <a data-link-type=dfn href=#scope-element title=":scope elements">:scope elements</a> must not be empty.
819+
820+
<p class=note> Note: Note that if the selector is scoped,
821+
the scoping root is automatically taken as the <a data-link-type=dfn href=#scope-element title=":scope element">:scope element</a>,
822+
so it doesn’t have to be provided explicitly
823+
unless a different result is desired.
824+
825+
<li>
826+
which <a data-link-type=dfn href=#pseudo-element title=pseudo-elements>pseudo-elements</a> are allowed to show up in the match list, if any.
827+
If not specified, this defaults to allowing all pseudo-elements.
828+
</ul>
829+
800830
<p> A <a data-link-type=dfn href=#selector title=selector>selector</a> is evaluated against some initial list of elements,
801831
as determined by the context that the selector is evaluated in:
802832
the <dfn data-dfn-type=dfn data-export="" id=selector-match-list>selector match list<a class=self-link href=#selector-match-list></a></dfn>.
@@ -807,18 +837,24 @@ <h3 class="heading settled heading" data-level=3.2 id=evaluating-selectors><span
807837

808838
<p> The selector is processed from left to right in order,
809839
with <a data-link-type=dfn href=#simple title="simple selectors">simple selectors</a> filtering the <a data-link-type=dfn href=#selector-match-list title="selector match list">selector match list</a>,
810-
and <a data-link-type=dfn href=#combinator title=combinators>combinators</a> changing the <a data-link-type=dfn href=#selector-match-list title="selector match list">selector match list</a> into something new.
840+
and <a data-link-type=dfn href=#combinator title=combinators>combinators</a> and <a data-link-type=dfn href=#pseudo-element title=pseudo-elements>pseudo-elements</a> changing the <a data-link-type=dfn href=#selector-match-list title="selector match list">selector match list</a> into something new.
811841
If the selector is <a data-link-type=dfn href=#scope-contained- title=scope-contained>scope-contained</a>
812842
then after each <a data-link-type=dfn href=#combinator title=combinator>combinator</a>
813843
the <a data-link-type=dfn href=#selector-match-list title="selector match list">selector match list</a> must be filtered
814844
to contain only elements that are either the <a data-link-type=dfn href=#scoping-root title="scoping root">scoping root</a>
815845
or descendants of the <a data-link-type=dfn href=#scoping-root title="scoping root">scoping root</a>.
816-
If the selector is <a data-link-type=dfn href=#scope-filtered- title=scope-filtered>scope-filtered</a>,
846+
847+
<p> If the selector is <a data-link-type=dfn href=#scope-filtered- title=scope-filtered>scope-filtered</a>,
817848
then after the selector is finished processing,
818849
the <a data-link-type=dfn href=#selector-match-list title="selector match list">selector match list</a> must be filtered
819850
to contain only elements that are either the <a data-link-type=dfn href=#scoping-root title="scoping root">scoping root</a>
820851
or descendants of the <a data-link-type=dfn href=#scoping-root title="scoping root">scoping root</a>.
821852

853+
<p> After the selector is finished matching,
854+
the <a data-link-type=dfn href=#selector-match-list title="selector match list">selector match list</a> must be filtered
855+
to only contain elements and <a data-link-type=dfn href=#pseudo-element title=pseudo-elements>pseudo-elements</a>
856+
allowed by the invoker of this algorithm.
857+
822858
<p> When this process is done, the elements in the <a data-link-type=dfn href=#selector-match-list title="selector match list">selector match list</a>
823859
are the elements said to match the selector.
824860
If the order of elements matter,
@@ -3401,24 +3437,6 @@ <h3 class="heading settled heading" data-level=17.2 id=parse-a-relative-selector
34013437
Return <var>selector</var>.
34023438
</ol>
34033439

3404-
<h3 class="heading settled heading" data-level=17.3 id=match-a-selector><span class=secno>17.3 </span><span class=content>
3405-
Match A Selector</span><a class=self-link href=#match-a-selector></a></h3>
3406-
3407-
<p> This section describes how to <dfn data-dfn-type=dfn data-export="" id=match-a-selector0>match a selector<a class=self-link href=#match-a-selector0></a></dfn> <var>selector</var>.
3408-
Optionally, a tree of nodes <var>nodes</var> to be matched against may be provided;
3409-
if not, the default <a data-link-type=dfn href=#initial-selector-match-list title="initial selector match list">initial selector match list</a> for selectors in the given context is used as <var>nodes</var>.
3410-
Optionally, a <a data-link-type=dfn href=#scoping-root title="scoping root">scoping root</a> and <a data-link-type=dfn href=#scoping-method- title="scoping method">scoping method</a> (<a data-link-type=dfn href=#scope-contained- title=scope-contained>scope-contained</a> or <a data-link-type=dfn href=#scope-filtered- title=scope-filtered>scope-filtered</a>) may be provided.
3411-
Optionally, an explicit <a data-link-type=dfn href=#scope-element title=":scope elements">:scope elements</a> <var>element set</var> (which may be empty) may be provided.
3412-
It returns a list of zero or more elements.
3413-
3414-
<p> <a data-link-type=dfn href=#evaluate-a-selector title="evaluate a selector">Evaluate a selector</a> <var>selector</var> against <var>nodes</var>
3415-
with the <a data-link-type=dfn href=#scoping-root title="scoping root">scoping root</a>,
3416-
<a data-link-type=dfn href=#scoping-method- title="scoping method">scoping method</a>,
3417-
and <a data-link-type=dfn href=#scope-element title=":scope elements">:scope elements</a>
3418-
if they were provided,
3419-
and return the elements that match the selector.
3420-
Return the nodes matched by the selector.
3421-
34223440

34233441
<h2 class="heading settled heading" data-level=18 id=changes><span class=secno>18 </span><span class=content>
34243442
Changes</span><a class=self-link href=#changes></a></h2>
@@ -3636,7 +3654,6 @@ <h2 class="no-num no-ref heading settled heading" id=index><span class=content>
36363654
<li>:last-of-type, <a href=#last-of-type-pseudo title="section 12.5.4">12.5.4</a>
36373655
<li>:link, <a href=#link-pseudo title="section 8.2">8.2</a>
36383656
<li>:local-link, <a href=#local-link-pseudo title="section 8.3">8.3</a>
3639-
<li>match a selector, <a href=#match-a-selector0 title="section 17.3">17.3</a>
36403657
<li>:matches(), <a href=#matches-pseudo title="section 4.2">4.2</a>
36413658
<li>next-sibling combinator, <a href=#next-sibling-combinator title="section 13.3">13.3</a>
36423659
<li>:not(), <a href=#negation-pseudo title="section 4.3">4.3</a>

0 commit comments

Comments
 (0)