From c343f64babc563096e155f315fb345e12122294f Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Wed, 26 Nov 2025 11:09:37 -0500 Subject: [PATCH] [css-navigation-1] Factor out current from/to URL definitions. This extracts the defintions of current from URL and current to URL from the definition of the @navigation rule, which both allows them to be used more formally in the definition of the ::link-to() pseudo-class and also makes the definitions a bit more readable. This also cleans up some whitespace in the spec. --- css-navigation-1/Overview.bs | 240 ++++++++++++++++++----------------- 1 file changed, 123 insertions(+), 117 deletions(-) diff --git a/css-navigation-1/Overview.bs b/css-navigation-1/Overview.bs index ef8f16040ea..1db4cf38929 100644 --- a/css-navigation-1/Overview.bs +++ b/css-navigation-1/Overview.bs @@ -68,12 +68,12 @@ The ''@route'' rule can be defined in one of two ways: : with the pattern descriptor :: in this case the URL pattern represented is the one represented by the <> function - given as the descriptor's value. + given as the descriptor's value. : with the other descriptors named by <> :: In this case the URL pattern represented is the result of invoking - [=URL pattern/create|create a URL pattern=] given + [=URL pattern/create|create a URL pattern=] given input as {{URLPatternInit}} - constructed from the descriptors and their values; + constructed from the descriptors and their values; if a baseURL descriptor is not given then one is created from the [=style resource base URL=] of the rule. @@ -185,14 +185,14 @@ The syntax of the ''@navigation'' rule is: with <> defined as:
-	<> = not <>
-	                     | <> [ and <> ]*
-	                     | <> [ or <> ]*
-	<> = ( <> ) | ( <> ) | <>
-	<> = <> | <> : <>
-	<> = at | from | to
-	<> = <> | <>
-	<> = <>
+<> = not <>
+                     | <> [ and <> ]*
+                     | <> [ or <> ]*
+<> = ( <> ) | ( <> ) | <>
+<> = <> | <> : <>
+<> = at | from | to
+<> = <> | <>
+<> = <>
 
The above grammar is purposely very loose for forwards-compatibility reasons, @@ -231,106 +231,24 @@ as follows: :: The result is whether the result of [=URL pattern/match|match a URL pattern=] is non-null given urlPattern as - the [=navigation location URL pattern=] of <>, - input as the document's [=Document/URL=]. + the [=navigation location URL pattern=] of <> + and input as the document's [=Document/URL=]. : from: <> :: The result is true if - the [=document's navigation API=] of the document - is non-null, and either: - - * its [=transition=] is non-null, - its [=from entry=]'s {{NavigationHistoryEntry/url}} - is non-null and - [=URL pattern/match|match a URL pattern=] is non-null when - given urlPattern as - the [=navigation location URL pattern=] of <>, - input as that - [=from entry=]'s {{NavigationHistoryEntry/url}}. - - NOTE: This part handles from: when it matches in the old page. - - * its [=activation=] is non-null, - the document's [=has been revealed=] is false or - was false at the start of the current [=task=], - and the activation's {{NavigationActivation/from}}'s - {{NavigationHistoryEntry/url}} - is non-null and - [=URL pattern/match|match a URL pattern=] is non-null when - given urlPattern as - the [=navigation location URL pattern=] of <>, - input as that - activation's {{NavigationActivation/from}}'s - {{NavigationHistoryEntry/url}}. - - NOTE: This part handles from: when it matches in the new page. + the [=current from URL=] from of the document is non-null and + [=URL pattern/match|match a URL pattern=] is non-null when + given urlPattern as + the [=navigation location URL pattern=] of <> + and input as from. : to: <> :: The result is true if - the [=document's navigation API=] of the document - is non-null, and either: - - * its [=ongoing navigate event=] is non-null, - [=URL pattern/match|match a URL pattern=] is non-null - given urlPattern as - the [=navigation location URL pattern=] of <>, - input as the [=current to url=], - where the current to url is defined as: - - * if the {{pageswap}} event has fired since that navigation began, - and its {{PageSwapEvent/activation}} was non-null, - and that {{PageSwapEvent/activation}}'s - {{NavigationActivation/entry}}'s - {{NavigationHistoryEntry/url}} is non-null, - then that - {{NavigationHistoryEntry/url}}. - - NOTE: This part does expose the result of redirects. - - ISSUE: Is the final "non-null" check needed? - - * otherwise, the [=ongoing navigate event=]'s - {{NavigateEvent/destination}}'s - {{NavigationDestination/url}} - - NOTE: This part does not expose the result of redirects. - - ISSUE: This assumes that the [=ongoing navigate event=] - and the [=transition=] have the same lifetime, - but this isn't really - true if the event is intercepted. - After - whatwg/html#11690 / - whatwg/html#11692. - we could probably define this more like "from" above. - But which lifetime is the one we want? - - NOTE: This part handles to: when it matches in the old page. - - * its [=activation=] is non-null, - the document's [=has been revealed=] is false or - was false at the start of the current [=task=], - and the activation's {{NavigationActivation/entry}}'s - {{NavigationHistoryEntry/url}} - is non-null and - [=URL pattern/match|match a URL pattern=] is non-null - given urlPattern as - the [=navigation location URL pattern=] of <>, - input as that - activation's {{NavigationActivation/entry}}'s - {{NavigationHistoryEntry/url}}. - - NOTE: This part handles to: when it matches in the new page. - - ISSUE: The above definitions of from and to apparently don't work right - if you start a same-document navigation (e.g., with {{History/pushState}}) - in the middle of a cross-document navigation. - - ISSUE: Generally improve integration with the HTML spec for these definitions, - instead of monkeypatching. - This includes the interaction with [=has been revealed=] - and the interaction with the {{pageswap}} event, - and other things where this section links to non-exported definitions. + the [=current to URL=] to of the document is non-null and + [=URL pattern/match|match a URL pattern=] is non-null when + given urlPattern as + the [=navigation location URL pattern=] of <> + and input as to. : <> :: @@ -539,11 +457,8 @@ if the following steps return true: 1. If <> is a <>, and entry's [=map/key=] is the function's <>, then for each navigationUrl of the - current to URL - and current from URL - extract "current to URL" and - "current from URL" from ''@navigation'' - definitions above and link to them: + [=current to URL=] + and [=current from URL=]: 1. Let navigationMatchResult be the result of [=URL pattern/match|match a URL pattern=] given urlPattern and navigationUrl. @@ -554,20 +469,111 @@ if the following steps return true: whose [=map/key=] is the same as entry's key and whose [=map/value=] is the same as entry's value. - NOTE: This step makes the ''navigation-param()'' function - perform what is essentially a three-way match, - between the target of the link, - the provided URL pattern, - and the from or to URL of the current navigation. + NOTE: This step makes the ''navigation-param()'' function + perform what is essentially a three-way match, + between the target of the link, + the provided URL pattern, + and the from or to URL of the current navigation. ISSUE: A <> should also be able to be a named route once those are added back to the spec. +

Current navigation URLs

+ +Both the ''@navigation'' rule and the '':link-to()'' pseudo-class +rely on the following definitions of +the [=current from URL=] and [=current to URL=]. + +The current from URL of a [=/document=] is a URL or null. +It is defined as follows: + +1. If the [=document's navigation API=] of the document is non-null and + its [=transition=] is non-null, + its [=from entry=]'s {{NavigationHistoryEntry/url}}. + + NOTE: This part is for when the old document in the navigation + is still the current document. + +1. If the [=document's navigation API=] of the document is non-null and + its [=activation=] is non-null, + the document's [=has been revealed=] is false or + was false at the start of the current [=task=], + the activation's {{NavigationActivation/from}}'s + {{NavigationHistoryEntry/url}}. + + NOTE: This part is for when the new document in the navigation + has become the current document. + +1. Otherwise, null. + + NOTE: The previous two branches can also produce null results. + +The current to URL of a [=/document=] is a URL or null. +It is defined as follows: + +1. If the [=document's navigation API=] of the document is non-null and + its [=ongoing navigate event=] is non-null: + + 1. if the {{pageswap}} event has fired since that navigation began, + and its {{PageSwapEvent/activation}} was non-null, + and that {{PageSwapEvent/activation}}'s + {{NavigationActivation/entry}}'s + {{NavigationHistoryEntry/url}} is non-null, + then that + {{NavigationHistoryEntry/url}}. + + NOTE: This part does expose the result of redirects. + + ISSUE: Is the final "non-null" check needed? + + 1. otherwise, the [=ongoing navigate event=]'s + {{NavigateEvent/destination}}'s + {{NavigationDestination/url}} + + NOTE: This part does not expose the result of redirects. + + ISSUE: This assumes that the [=ongoing navigate event=] + and the [=transition=] have the same lifetime, + but this isn't really + true if the event is intercepted. + After + whatwg/html#11690 / + whatwg/html#11692. + we could probably define this more like "from" above. + But which lifetime is the one we want? + + NOTE: This part is for when the old document in the navigation + is still the current document. + +1. If the [=document's navigation API=] of the document is non-null and + its [=activation=] is non-null, + the document's [=has been revealed=] is false or + was false at the start of the current [=task=], + and the activation's {{NavigationActivation/entry}}'s + {{NavigationHistoryEntry/url}}. + + NOTE: This part is for when the new document in the navigation + has become the current document. + +1. Otherwise, null. + + NOTE: The previous two branches can also produce null results. + +ISSUE: The above definitions of from and to apparently don't work right +if you start a same-document navigation (e.g., with {{History/pushState}}) +in the middle of a cross-document navigation. + +ISSUE: Generally improve integration with the HTML spec for these definitions, +instead of monkeypatching. +This includes the interaction with [=has been revealed=] +and the interaction with the {{pageswap}} event, +and other things where this section links to non-exported definitions. +

The ''url-pattern()'' function