Skip to content

Commit 2cfa965

Browse files
authored
[css-navigation-1] Add :link-to() pseudo-class (with navigation-param() function). (w3c#13134)
This adds an initial proposal for the :link-to() pseudo-class and a navigation-param() function that goes inside of it. This also refactors some of the invocations of the URL pattern "match" algorithm to structure the parameters the way the algorithm expects (and be a little bit clearer that a base URL doesn't need to be provided).
1 parent 3605ce8 commit 2cfa965

File tree

1 file changed

+119
-14
lines changed

1 file changed

+119
-14
lines changed

css-navigation-1/Overview.bs

Lines changed: 119 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ as follows:
115115
: <<navigation-test>>
116116
:: : <<navigation-location>>
117117
: at: <<navigation-location>>
118-
:: The result is true if
119-
the document's [=Document/URL=] [=URL pattern/match|matches=]
120-
the [=navigation location URL pattern=] of <<navigation-location>>.
118+
:: The result is whether the result of
119+
[=URL pattern/match|match a URL pattern=] is non-null
120+
given <var>urlPattern</var> as
121+
the [=navigation location URL pattern=] of <<navigation-location>>,
122+
<var>input</var> as the document's [=Document/URL=].
121123

122124
: from: <<navigation-location>>
123125
:: The result is true if
@@ -127,19 +129,26 @@ as follows:
127129
* its [=transition=] is non-null,
128130
its [=from entry=]'s {{NavigationHistoryEntry/url}}
129131
is non-null and
130-
[=URL pattern/match|matches=]
131-
the [=navigation location URL pattern=] of <<navigation-location>>.
132+
[=URL pattern/match|match a URL pattern=] is non-null when
133+
given <var>urlPattern</var> as
134+
the [=navigation location URL pattern=] of <<navigation-location>>,
135+
<var>input</var> as that
136+
[=from entry=]'s {{NavigationHistoryEntry/url}}.
132137

133138
NOTE: This part handles <code>from:</code> when it matches in the old page.
134139

135140
* its [=activation=] is non-null,
136141
the document's [=has been revealed=] is false or
137142
was false at the start of the current [=task=],
138143
and the activation's {{NavigationActivation/from}}'s
139-
{{NavigationHistoryEntry/url}}'s
144+
{{NavigationHistoryEntry/url}}
140145
is non-null and
141-
[=URL pattern/match|matches=]
142-
the [=navigation location URL pattern=] of <<navigation-location>>.
146+
[=URL pattern/match|match a URL pattern=] is non-null when
147+
given <var>urlPattern</var> as
148+
the [=navigation location URL pattern=] of <<navigation-location>>,
149+
<var>input</var> as that
150+
activation's {{NavigationActivation/from}}'s
151+
{{NavigationHistoryEntry/url}}.
143152

144153
NOTE: This part handles <code>from:</code> when it matches in the new page.
145154

@@ -149,9 +158,10 @@ as follows:
149158
is non-null, and either:
150159

151160
* its [=ongoing navigate event=] is non-null,
152-
and the [=current to url=]
153-
[=URL pattern/match|matches=]
161+
[=URL pattern/match|match a URL pattern=] is non-null
162+
given <var>urlPattern</var> as
154163
the [=navigation location URL pattern=] of <<navigation-location>>,
164+
<var>input</var> as the [=current to url=],
155165
where the <dfn>current to url</dfn> is defined as:
156166

157167
* if the {{pageswap}} event has fired since that navigation began,
@@ -188,10 +198,14 @@ as follows:
188198
the document's [=has been revealed=] is false or
189199
was false at the start of the current [=task=],
190200
and the activation's {{NavigationActivation/entry}}'s
191-
{{NavigationHistoryEntry/url}}'s
201+
{{NavigationHistoryEntry/url}}
192202
is non-null and
193-
[=URL pattern/match|matches=]
194-
the [=navigation location URL pattern=] of <<navigation-location>>.
203+
[=URL pattern/match|match a URL pattern=] is non-null
204+
given <var>urlPattern</var> as
205+
the [=navigation location URL pattern=] of <<navigation-location>>,
206+
<var>input</var> as that
207+
activation's {{NavigationActivation/entry}}'s
208+
{{NavigationHistoryEntry/url}}.
195209

196210
NOTE: This part handles <code>to:</code> when it matches in the new page.
197211

@@ -266,7 +280,98 @@ to model it after.
266280

267281
<h2 id="link-navigation-pseudo-classes">Pseudo-classes for navigation-related links</h2>
268282

269-
TODO: To be written.
283+
This specification defines a new '':link-to()'' functional pseudo-class
284+
that matches link elements that link to a certain URL.
285+
286+
The '':link-to()'' pseudo-class takes a single argument, a <<link-condition>>,
287+
and the pseudo-class matches any element where:
288+
* the element matches '':any-link''
289+
* the target of link matches the <<link-condition>>, as defined below.
290+
291+
<pre class="prod def" dfn-type="type" nohighlight>
292+
<dfn><<link-condition>></dfn> = <<link-condition-base>> [ with <<navigation-param-expression>> ]?
293+
<dfn><<link-condition-base>></dfn> = <<url-pattern()>>
294+
<dfn><<navigation-param-expression>></dfn> = ( [ <<navigation-param-and>> |
295+
<<navigation-param-or>> |
296+
<<navigation-param>> ] )
297+
<dfn><<navigation-param-and>></dfn> = <<navigation-param-expression>>
298+
[ "and" <<navigation-param-expression>> ]*
299+
<dfn><<navigation-param-or>></dfn> = <<navigation-param-expression>>
300+
[ "or" <<navigation-param-expression>> ]*
301+
<dfn><<navigation-param>></dfn> = <<navigation-param-key-value>> | <<navigation-param-function>>
302+
<dfn><<navigation-param-key-value>></dfn> = <<ident>> : <<string>>
303+
<dfn><<navigation-param-function>></dfn> = navigation-param( <<ident>> )
304+
</pre>
305+
306+
A <<link-condition>> matches the target of the link when both:
307+
* the <<link-condition-base>> matches the target of the link, and
308+
* the <<navigation-param-expression>> matches the target of the link,
309+
with the [=URL pattern=] represented by the <<link-condition-base>> as context
310+
311+
A <<link-condition-base>> represents a [=URL pattern=].
312+
If the <<link-condition-base>> is a <<url-pattern()>>,
313+
then it represents the URL pattern
314+
represented by the <<url-pattern()>> function
315+
(see [=create a URL pattern for url-pattern()=]).
316+
317+
A <<link-condition-base>> matches a URL
318+
when [=URL pattern/match|match a URL pattern=] is non-null
319+
given <var>urlPattern</var> as
320+
the [=URL pattern=] that it represents and
321+
<var>input</var> as the given URL.
322+
323+
A <<navigation-param-expression>> matches a URL
324+
(with a [=URL Pattern=] as context)
325+
based on standard boolean logic for <code>and</code> and <code>or</code>,
326+
and based on whether each <<navigation-param>> matches the URL
327+
(with the URL Pattern as context).
328+
329+
A <<navigation-param>> matches the URL <var>input</var> (with a URL Pattern <var>urlPattern</var> as context)
330+
if the following steps return true:
331+
1. Let <var>matchResult</var> be the result of
332+
[=URL pattern/match|match a URL pattern=]
333+
given <var>urlPattern</var> and <var>input</var>.
334+
the [=URL pattern=]
335+
represented by the <<url-pattern()>> function in the <<link-condition-base>>
336+
(see [=create a URL pattern for url-pattern()=])
337+
1. If <var>matchResult</var> is null, return false.
338+
339+
NOTE: This doesn't really matter because
340+
in this case the <<link-condition-base>> also doesn't match.
341+
1. For each property <var>prop</var> of <var>matchResult</var> (a {{URLPatternResult}})
342+
that is a {{URLPatternComponentResult}}:
343+
1. For each [=map/entry=] <var>entry</var> in its {{URLPatternComponentResult/groups}},
344+
then:
345+
1. If <<navigation-param>> is a <<navigation-param-key-value>>,
346+
return true if
347+
<var>entry</var>'s [=map/key=] is the <<ident>>
348+
and <var>entry</var>'s [=map/value=] is the <<string>>.
349+
1. If <<navigation-param>> is a <<navigation-param-function>>,
350+
and <var>entry</var>'s [=map/key=] is the function's <<ident>>,
351+
then for each <var>navigationUrl</var> of the
352+
current to URL
353+
and current from URL
354+
<span class="issue">extract "current to URL" and
355+
"current from URL" from ''@navigation''
356+
definitions above and link to them</span>:
357+
1. Let <var>navigationMatchResult</var> be the result of
358+
[=URL pattern/match|match a URL pattern=]
359+
given <var>urlPattern</var> and <var>navigationUrl</var>.
360+
1. If <var>navigationMatchResult</var> is null, [=continue=].
361+
1. Return true if <var>navigationMatchResult</var>'s
362+
property <var>prop</var>
363+
has an [=map/entry=]
364+
whose [=map/key=] is the same as <var>entry</var>'s key
365+
and whose [=map/value=] is the same as <var>entry</var>'s value.
366+
367+
NOTE: This step makes the ''navigation-param()'' function
368+
perform what is essentially a three-way match,
369+
between the target of the link,
370+
the provided URL pattern,
371+
and the from or to URL of the current navigation.
372+
373+
ISSUE: A <<link-condition>> should also be able to be a named route
374+
once those are added back to the spec.
270375

271376
<h2 id="url-pattern-function">The ''url-pattern()'' function</h2>
272377

0 commit comments

Comments
 (0)