Skip to content

Commit 3ec9eb1

Browse files
authored
[css-view-transitions-2] Update the algorithm to check opt-in on outbound transition (#10078)
* [css-view-transitions-2] Update the algorithm to check opt-in on outbound transition Instead of relying on the source snapshot params in HTML, we update a flag every time something relevant changes, and HTML can read that flag. * Refactor outbound algo into vt
1 parent 7b442a7 commit 3ec9eb1

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

css-view-transitions-2/Overview.bs

+37-10
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ Note: as per default behavior, the ''@view-transition'' rule can be nested insid
450450
Note: the [=@view-transition/type=] descriptor only applies to the {{Document}} in which it is defined.
451451
The author is responsible for using their chosen set of types in both documents.
452452

453+
## Responding to changes in the ''@view-transition'' rule ## {#respond-to-rule-changes}
454+
455+
When the ''@view-transition'' rule changes for {{Document}} |document|, [=update the opt-in state for outbound transitions=] given |document|.
456+
457+
453458
# API # {#api}
454459

455460
## Additions to {{Document}} ## {#additions-to-document-api}
@@ -527,6 +532,12 @@ The {{CSSViewTransitionRule}} represents a ''@view-transition'' rule.
527532
: <dfn>inbound view transition params</dfn>
528533
:: a [=view transition params=], or null.
529534
Initially null.
535+
536+
: <dfn>can initiate outbound view transition</dfn>
537+
:: a boolean.
538+
Initially false.
539+
540+
Note: this value can be read [=in parallel=] while navigating.
530541
</dl>
531542

532543
### The View transition params struct ### {#view-transition-params-struct}
@@ -660,20 +671,24 @@ Prepend this to the [=Perform pending transition operations=] algorithm given a
660671

661672
<div algorithm>
662673
To check if a <dfn export>navigation can trigger a cross-document view-transition?</dfn> given
663-
an [=/origin=] |oldOrigin|, an [=/origin=] |newOrigin|, a boolean |navigationHasCrossOriginRedirects|, a {{NavigationType}} |navigationType|, and a boolean |isBrowserUINavigation|:
674+
a {{Document}} |oldDocument|, a {{Document}} |newDocument|, a {{NavigationType}} |navigationType|, and a boolean |isBrowserUINavigation|:
664675

665-
Note: this is called during navigation, potentially [=in parallel=], for documents that have opted-in to view-transitions using the ''@view-transition'' rule.
676+
Note: this is called during navigation, potentially [=in parallel=].
666677

667678
1. If the user agent decides to display an [=implementation-defined=] navigation experience, e.g. a gesture-based transition for a back navigation,
668679
the user agent may ignore the author-defined view transition. If that is the case, return false.
669680

681+
1. If |oldDocument|'s [=can initiate outbound view transition=] is false, then return false.
682+
670683
1. If |navigationType| is {{NavigationType/reload}}, then return false.
671684

672-
1. If |isBrowserUINavigation| is true, and |navigationType| is {{NavigationType/push}} or {{NavigationType/replace}}, then return false.
685+
1. If |oldDocument|'s [=Document/origin=] is not [=same origin=] as |newDocument|'s [=Document/origin=], then return false.
673686

674-
1. If |oldOrigin| is not [=same origin=] as |newOrigin| then return false.
687+
1. If |navigationType| is {{NavigationType/traverse}}, then return true.
675688

676-
1. If |navigationHasCrossOriginRedirects| is true, then return false.
689+
1. If |isBrowserUINavigation| is true, then return false.
690+
691+
1. If |newDocument| [=was created via cross-origin redirects=], then return false.
677692

678693
1. Return true.
679694
</div>
@@ -683,11 +698,11 @@ Prepend this to the [=Perform pending transition operations=] algorithm given a
683698

684699
1. [=Assert=]: These steps are running as part of a [=task=] queued on |oldDocument|.
685700

686-
1. If |oldDocument|'s [=has been revealed=] is false, then return null.
701+
1. If |oldDocument|'s [=can initiate outbound view transition=] is false, then return null.
687702

688-
1. Let |resolvedRule| be the result of [=Resolve @view-transition rule|resolving the @view-transition rule=] for |oldDocument|.
703+
1. Let |transitionTypesFromRule| be the result of [=Resolve @view-transition rule|resolving the @view-transition rule=] for |oldDocument|.
689704

690-
1. If |resolvedRule| is "<code>skip transition</code>", then return null.
705+
1. [=Assert=]: |transitionTypesFromRule| is not "<code>skip transition</code>".
691706

692707
Note: We don't know yet if |newDocument| has opted in, as it might not be parsed yet.
693708
We check the opt-in for |newDocument| when we fire the {{Window/pagereveal}} event.
@@ -701,7 +716,7 @@ Prepend this to the [=Perform pending transition operations=] algorithm given a
701716

702717
1. Let |outboundTransition| be a new {{ViewTransition}} object in |oldDocument|'s [=relevant Realm=].
703718

704-
1. Set |outboundTransition|'s [=ViewTransition/active types=]'s [=DOMTokenList/token set=] to |resolvedRule|.
719+
1. Set |outboundTransition|'s [=ViewTransition/active types=]'s [=DOMTokenList/token set=] to |transitionTypesFromRule|.
705720

706721
Note: the [=ViewTransition/active types=] are not shared between documents.
707722
Manipulating the {{ViewTransition/typeList}} in the new document does not affect the types in the new document,
@@ -732,10 +747,14 @@ Prepend this to the [=Perform pending transition operations=] algorithm given a
732747
### Accessing the view-transition in the new {{Document}} ### {#access-view-transition-in-new-doc}
733748

734749
<div algorithm>
735-
To <dfn export>resolve cross-document view-transition</dfn> for {{Document}} |document|:
750+
To <dfn export>resolve inbound cross-document view-transition</dfn> for {{Document}} |document|:
736751

737752
1. [=Assert=]: |document| is [=fully active=].
738753

754+
1. [=Assert=]: |document| [=has been revealed=] is true.
755+
756+
1. [=Update the opt-in state for outbound transitions=] for |document|.
757+
739758
1. Let |inboundViewTransitionParams| be |document|'s [=inbound view transition params=].
740759

741760
1. If |inboundViewTransitionParams| is null, then return null.
@@ -769,6 +788,14 @@ Prepend this to the [=Perform pending transition operations=] algorithm given a
769788
1. Return |transition|.
770789
</div>
771790

791+
### Updating the opt-in state for outbound view transitions ### {#update-opt-in-state-for-outbound}
792+
793+
<div algorithm="update-opt-in-for-outbound">
794+
To <dfn>update the opt-in state for outbound transitions</dfn> for a {{Document}} |document|:
795+
1. If |document| [=has been revealed=], and the result of [=resolve @view-transition rule|resolving the @view-transition rule=] is not "<code>skip transition</code>",
796+
then set |document|'s [=can initiate outbound view transition=] to true.
797+
1. Otherwise, set |document|'s [=can initiate outbound view transition=] to false.
798+
772799

773800
<h2 id="priv" class="no-num">Privacy Considerations</h2>
774801

0 commit comments

Comments
 (0)