Skip to content

Commit 6b3259f

Browse files
noamrkhushalsagar
andauthored
[css-view-transitions-2] Editorial: refactor L2 concerns out of L1 (#9892)
* Move `onReady` to the correct place and rename See #9886 (comment) * Call proceed with navigation after capturing old doc * Move all cross-doc references to L2 * Update css-view-transitions-2/Overview.bs Co-authored-by: Khushal Sagar <63884798+khushalsagar@users.noreply.github.com> * Restructure new document steps and auto-skip * Add missing piece * Remove more references to L2 * Address PR nits * Address PR nits * Address PR nits * nits * Add rendering suppression * Move skip steps to monkey patch --------- Co-authored-by: Khushal Sagar <63884798+khushalsagar@users.noreply.github.com>
1 parent fbb66f7 commit 6b3259f

File tree

2 files changed

+122
-76
lines changed

2 files changed

+122
-76
lines changed

css-view-transitions-1/Overview.bs

+5-18
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
956956

957957
1. Let |document| be [=this's=] [=relevant global object's=] [=associated document=].
958958

959+
<<<<<<< HEAD
959960
1. If |document|'s [=Document/visibility state=] is "<code>hidden</code>",
960961
then [=skip the view transition|skip=] |transition| with an "{{InvalidStateError}}" {{DOMException}},
961962
and return.
@@ -964,6 +965,8 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
964965
then [=skip the view transition|skip=] |transition| with an "{{InvalidStateError}}" {{DOMException}},
965966
and return.
966967

968+
=======
969+
>>>>>>> 2b700bdce (Move all cross-doc references to L2)
967970
1. If |document|'s [=active view transition=] is not null,
968971
then [=skip the view transition|skip that view transition=]
969972
with an "{{AbortError}}" {{DOMException}} in [=this's=] [=relevant Realm=].
@@ -1095,19 +1098,8 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
10951098
Note: This is used to detect changes in the [=snapshot containing block size=],
10961099
which causes the transition to [=skip the view transition|skip=].
10971100
[Discussion of this behavior](https://github.com/w3c/csswg-drafts/issues/8045).
1098-
1099-
: <dfn export>process old state captured</dfn>
1100-
:: An algorithm accepting nothing, or null.
1101-
Initially null.
1102-
1103-
Note: this is used for cross-document view transitions.
11041101
</dl>
11051102

1106-
A {{ViewTransition}} must never have both an [=ViewTransition/update callback=] and a [=ViewTransition/process old state captured=].
1107-
1108-
Note: [=ViewTransition/update callback=] is optionally set for same-document view transitions,
1109-
and [=ViewTransition/process old state captured=] is set for cross-document view transitions.
1110-
11111103
The {{ViewTransition/finished}} [=getter steps=] are to return [=this's=] [=ViewTransition/finished promise=].
11121104

11131105
The {{ViewTransition/ready}} [=getter steps=] are to return [=this's=] [=ViewTransition/ready promise=].
@@ -1158,9 +1150,6 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
11581150
with [=this=]'s [=document element=] is its [=originating element=].
11591151

11601152
Note: The position of the [=ViewTransition/transition root pseudo-element=] within the [=document element=] does not matter, as the [=ViewTransition/transition root pseudo-element=]'s [=containing block=] is the [=snapshot containing block=].
1161-
1162-
: <dfn export>auto-skip view transitions</dfn>
1163-
:: A boolean. Initially false.
11641153
</dl>
11651154

11661155
### Additions to Elements ### {#elements-concept}
@@ -1259,8 +1248,6 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
12591248
If failure is returned, then [=skip the view transition=] for |transition| with an "{{InvalidStateError}}" {{DOMException}} in |transition|'s [=relevant Realm=],
12601249
and return.
12611250

1262-
1. If |transition|'s [=ViewTransition/process old state captured=] is not null, then call [=ViewTransition/process old state captured=] and return.
1263-
12641251
1. Set |document|'s [=document/rendering suppression for view transitions=] to true.
12651252

12661253
1. [=Queue a global task=] on the [=DOM manipulation task source=],
@@ -1680,8 +1667,6 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
16801667
Note: Since the rejection of |transition|'s [=ViewTransition/update callback done promise=] isn't explicitly handled here,
16811668
if |transition|'s [=ViewTransition/update callback done promise=] rejects,
16821669
then |transition|'s [=ViewTransition/finished promise=] will reject with the same reason.
1683-
1684-
1. If |transition|'s [=ViewTransition/process old state captured=] is not null, then call |transition|'s [=ViewTransition/process old state captured=].
16851670
</div>
16861671

16871672
## [=Capture the image=] ## {#capture-the-image-algorithm}
@@ -1960,6 +1945,8 @@ Changes from <a href="https://www.w3.org/TR/2023/WD-css-view-transitions-1-20230
19601945
* Refactor algorithm to clarify timing, especially of `updateCallbackDone. See <a href="https://github.com/w3c/csswg-drafts/issues/9762">issue 9762</a>.
19611946
* Add animation-delay inherit to UA stylesheet rules for (::view-transition) -image-pair, -old, and -new. See <a href="https://github.com/w3c/csswg-drafts/issues/9817">issue 9817</a>.
19621947
* Auto-skip animation when document is hidden. See <a href="https://github.com/w3c/csswg-drafts/issues/9543">issue 9543</a>.
1948+
* Remove references to cross-document view-transitions, to keep the L1 spec clean. See <a href="https://github.com/w3c/csswg-drafts/issues/9886">Issue 9886</a>.
1949+
19631950
<h3 id="changes-since-2022-05-25">
19641951
Changes from <a href="https://www.w3.org/TR/2023/WD-css-view-transitions-1-20230525/">2022-05-25 Working Draft</a>
19651952
</h3>

css-view-transitions-2/Overview.bs

+117-58
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ Markup Shorthands: css yes, markdown yes
1919
<pre class=link-defaults>
2020
spec:css-view-transitions-1;
2121
text: active view transition; type: dfn;
22+
text: capture the old state; type: dfn;
2223
text: clear view transition; type: dfn;
2324
text: activate view transition; type: dfn;
2425
text: skip the view transition; type: dfn;
2526
text: ViewTransition; type: interface;
2627
text: named elements; for: ViewTransition; type: dfn;
28+
text: finished promise; for: ViewTransition; type: dfn;
29+
text: ready promise; for: ViewTransition; type: dfn;
30+
text: update callback; for: ViewTransition; type: dfn;
2731
text: update callback done promise; for: ViewTransition; type: dfn;
2832
text: initial snapshot containing block size; for: ViewTransition; type: dfn;
2933
text: captured elements; type: dfn;
@@ -33,6 +37,7 @@ spec:css-view-transitions-1;
3337
text: perform pending transition operations; type: dfn;
3438
text: setup view transition; type: dfn;
3539
text: named view transition pseudo-element; type: dfn;
40+
text: rendering suppression for view transitions; type: dfn;
3641
spec:dom; type:dfn; text:document
3742
spec:css22; type:dfn; text:element
3843
spec:selectors-4; type:dfn;
@@ -446,13 +451,24 @@ Note: as per default behavior, the ''@view-transition'' rule can be nested insid
446451
<div algorithm="start-vt-with-options">
447452
The [=method steps=] for <dfn method for=Document>startViewTransition(|callbackOptions|)</dfn> are as follows:
448453

449-
1. If |callbackOptions| is not provided, then run the [=method steps=] for {{Document/startViewTransition()}} and return the result.
454+
1. Let |updateCallback| be null.
450455

451-
1. If |callbackOptions| is an {{UpdateCallback}}, then run the [=method steps=] for {{Document/startViewTransition(updateCallback)}} given |callbackOptions| and return the result.
456+
1. If |callbackOptions| is an an {{UpdateCallback}}, set |updateCallback| to |callbackOptions|.
452457

453-
1. Let |viewTransition| be the result of running [=method steps=] for {{Document/startViewTransition(updateCallback)}} given |callbackOptions|'s {{StartViewTransitionOptions/update}}.
458+
1. Otherwise, if |callbackOptions| is a {{StartViewTransitionOptions}}, then set |updateCallback| to |callbackOptions|'s {{StartViewTransitionOptions/update}}.
454459

455-
1. Set |viewTransition|'s [=ViewTransition/active types=] to |callbackOptions|'s {{StartViewTransitionOptions/type}}.
460+
1. If |this|'s [=active view transition=] is not null and its [=outbound post-capture steps=] is not null,
461+
then:
462+
463+
1. Let |preSkippedTransition| be a new {{ViewTransition}} in |this|'s [=relevant realm=] whose [=ViewTransition/update callback=] is |updateCallback|.
464+
465+
1. [=Skip the view transition|Skip=] |preSkippedTransition| with an "{{InvalidStateError}}" {{DOMException}}.
466+
467+
1. Return |preSkippedTransition|.
468+
469+
1. Let |viewTransition| be the result of running the [=method steps=] for {{Document/startViewTransition(updateCallback)}} given |updateCallback|.
470+
471+
1. If |callbackOptions| is a {{StartViewTransitionOptions}}, then set |viewTransition|'s [=ViewTransition/active types=] to |callbackOptions|'s {{StartViewTransitionOptions/type}}.
456472

457473
1. Return |viewTransition|.
458474
</div>
@@ -484,14 +500,34 @@ The {{CSSViewTransitionRule}} represents a ''@view-transition'' rule.
484500
# Algorithms # {#algorithms}
485501
## Data Structures ## {#concepts}
486502

503+
### Additions to {{Document}} ### {#additions-to-document}
504+
A {{Document}} additionaly has:
505+
506+
<dl dfn-for=document>
507+
: <dfn>inbound view transition params</dfn>
508+
:: a [=view transition params=], or null.
509+
Initially null.
510+
</dl>
511+
512+
### The View transition params struct ### {#view-transition-params-struct}
513+
514+
A <dfn>view transition params</dfn> is a [=struct=] whose purpose is to serialize view transition information across documents.
515+
It has the following [=struct/items=]:
516+
517+
<dl dfn-for="view transition params">
518+
: <dfn>named elements</dfn>
519+
:: a [=/map=], whose keys are strings and whose values are [=captured elements=].
520+
521+
: <dfn>initial snapshot containing block size</dfn>
522+
:: a [=tuple=] of two numbers (width and height).
523+
</dl>
524+
487525
### Additions to {{ViewTransition}} ### {#view-transitions-extension}
488526

489527
A {{ViewTransition}} additionally has:
490528
<dl dfn-for=ViewTransition>
491-
: <dfn>is inbound cross-document transition</dfn>
492-
:: a boolean, initially false.
493-
494-
Issue: should a cross-document transition take precedent? See [#9512](https://github.com/w3c/csswg-drafts/issues/9512)
529+
: <dfn>outbound post-capture steps</dfn>
530+
:: Null or a set of steps, initially null.
495531

496532
: <dfn>active types</dfn>
497533
:: Null or a [=list=] of strings, initially null.
@@ -506,7 +542,7 @@ The [=captured element=] struct should contain these fields, in addition to the
506542
:: a [=/list=] of strings, initially empty.
507543
</dl>
508544

509-
## Algorithms to capture 'view-transition-class': ## {#vt-class-algorithms}
545+
## Algorithm to capture 'view-transition-class': ## {#vt-class-algorithms}
510546
<div algorithm="additional capture steps">
511547
When capturing the old or new state for an element, perform the following steps given a [=captured element=] |capture| and an [=element=] |element|:
512548

@@ -515,6 +551,44 @@ When capturing the old or new state for an element, perform the following steps
515551
Note: This is written in a monkey-patch manner, and will be merged into the algorithm once the L1 spec graduates.
516552
</div>
517553

554+
## Additions to skip steps: ## {#additional-skip-steps}
555+
<div algorithm="additional skip steps">
556+
Append the following steps to [=skip the view transition=] given a {{ViewTransition}} |transition|:
557+
1. If |transition|'s [=outbound post-capture steps=] is not null, then run |transition|'s [=outbound post-capture steps=] with null.
558+
559+
Note: This is written in a monkey-patch manner, and will be merged into the algorithm once the L1 spec graduates.
560+
</div>
561+
562+
## Addition to pending transition operations ## {#additions-to-pending-transition-operation}
563+
564+
Prepend this to the [=Perform pending transition operations=] algorithm given a {{Document}} |document|:
565+
1. If |document|'s [=active view transition=] is not null and its [=outbound post-capture steps=] is not null, then:
566+
567+
1. Assert: |document|'s [=active view transition=]'s [=ViewTransition/phase=] is "`pending-capture`".
568+
569+
1. Let |viewTransitionParams| be null;
570+
571+
1. Set |document|'s [=document/rendering suppression for view transitions=] to true.
572+
573+
Issue: though [=capture the old state=] appears here as a synchronous step, it is in fact an asynchronous step
574+
as rendering an element into an image cannot be done synchronously. This should be more explicit in the L1 spec.
575+
576+
1. [=Capture the old state=] for |transition|.
577+
578+
1. Set |document|'s [=document/rendering suppression for view transitions=] to false.
579+
580+
1. If this succeeded, then set |viewTransitionParams| to a new [=view transition params=] whose
581+
[=view transition params/named elements=] is a [=map/clone=] of |transition|'s [=ViewTransition/named elements=],
582+
and whose [=view transition params/initial snapshot containing block size=] is |transition|'s [=ViewTransition/initial snapshot containing block size=].
583+
584+
1. [=Clear view transition=] |transition|.
585+
586+
Note: The ViewTransition object on the old Document should be destroyed after its state has been copied to the new Document below.
587+
We explicitly clear it here since the old Document may be cached by the UA.
588+
589+
1. Call |transition|'s [=outbound post-capture steps=] given |viewTransitionParams|.
590+
591+
518592
## Monkey patches to HTML ## {#monkey-patch-to-html}
519593

520594
<div algorithm="monkey patch to apply the history step">
@@ -558,7 +632,7 @@ When capturing the old or new state for an element, perform the following steps
558632

559633
<div algorithm>
560634
To check if a <dfn export>navigation can trigger a cross-document view-transition?</dfn> given
561-
an [=origin=] |oldOrigin|, an [=origin=] |newOrigin|, a boolean |navigationHasCrossOriginRedirects|, a {{NavigationType}} |navigationType|, and a boolean |isBrowserUINavigation|:
635+
an [=/origin=] |oldOrigin|, an [=/origin=] |newOrigin|, a boolean |navigationHasCrossOriginRedirects|, a {{NavigationType}} |navigationType|, and a boolean |isBrowserUINavigation|:
562636

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

@@ -577,7 +651,9 @@ When capturing the old or new state for an element, perform the following steps
577651
</div>
578652
<div algorithm>
579653
To <dfn export>setup cross-document view-transition</dfn> given a {{Document}} |oldDocument|,
580-
a {{Document}} |newDocument|, and |onReady|, which is an algorithm accepting nothing:
654+
a {{Document}} |newDocument|, and |proceedWithNavigation|, which is an algorithm accepting nothing:
655+
656+
1. [=Assert=]: These steps are running as part of a [=task=] queued on |oldDocument|.
581657

582658
1. Let |resolvedRule| be the result of [=Resolve @view-transition rule|resolving the @view-transition rule=] for |oldDocument|.
583659

@@ -593,54 +669,19 @@ When capturing the old or new state for an element, perform the following steps
593669
Note: this means that any running transition would be skipped when the document is ready
594670
to unload.
595671

596-
1. Set |oldDocument|'s [=auto-skip view transitions=] to true.
597-
598-
Note: this means that calling {{Document/startViewTransition()}} while capturing the old document for a cross-document view-transition would run the callback but skip the animation.
599-
600672
1. Let |outboundTransition| be a new {{ViewTransition}} object in |oldDocument|'s [=relevant Realm=],
601-
whose [=ViewTransition/active types=] is |resolvedRule|, and whose [=ViewTransition/process old state captured=] is set to the following steps:
602-
603-
Issue: should we check for the opt-in again, in case there was a CSSOM change in a requestAnimationFrame callback?
604-
605-
1. If |outboundTransition|'s [=ViewTransition/phase=] is "`done`", then call |onReady| and return.
606-
607-
1. Assert: |outboundTransition|'s [=ViewTransition/phase=] is "`pending-capture`".
608-
609-
1. [=Clear view transition=] |outboundTransition|.
610-
611-
Note: The ViewTransition object on the old Document should be destroyed after its state has been copied to the new Document below.
612-
We explicitly clear it here since the old Document may be cached by the UA.
613-
614-
1. Set |oldDocument|'s [=auto-skip view transitions=] to false.
615-
616-
1. [=Queue a global task=] on the [=DOM manipulation task source=] given |newDocument|'s [=relevant global object=],
617-
to perform the following steps:
673+
whose [=ViewTransition/active types=] is |resolvedRule|.
618674

619-
1. Let |inboundTransition| be a new {{ViewTransition}} in |newDocument|'s [=relevant Realm=],
620-
whose [=ViewTransition/named elements=] is |outboundTransition|'s [=ViewTransition/named elements=],
621-
[=ViewTransition/initial snapshot containing block size=] is |outboundTransition|'s [=ViewTransition/initial snapshot containing block size=],
622-
and whose [=ViewTransition/is inbound cross-document transition=] is true.
675+
1. Set |outboundTransition|'s [=outbound post-capture steps=] to the following steps given a [=view transition params=]-or-null |params|:
676+
1. Set |newDocument|'s [=inbound view transition params=] to |params|.
623677

624-
1. Set |newDocument|'s [=active view transition=] to |inboundTransition|.
678+
Note: The inbound transition is activated after the dispatch of {{Window/pagereveal}} to ensure mutations made in this event apply to the captured new state.
625679

626-
1. [=Resolve=] |inboundTransition|’s [=ViewTransition/update callback done promise=] with undefined.
627-
628-
1. Set |inboundTransition|’s [=ViewTransition/phase=] to "`update-callback-called`".
629-
630-
1. Call |onReady|.
631-
632-
Note: The |inboundTransition| is activated after the dispatch of {{Window/pagereveal}} to ensure mutations made in this event apply to the captured new state.
633-
634-
1. At any given time, the UA may decide to skip |inboundTransition|, e.g. after an [=implementation-defined=] timeout.
635-
To do so, the UA should [=queue a global task=] on the [=DOM manipulation task source=] given |newDocument|'s [=relevant global object=] to perform the following step:
636-
If |transition|'s [=ViewTransition/phase=] is not "`done`", then [=skip the view transition=] |transition| with a "{{TimeoutError}}" {{DOMException}}.
637-
638-
Note: |outboundTransition| is not exposed to JavaScript, it is used only for capturing
639-
the state of the old document.
680+
1. Call |proceedWithNavigation|.
640681

641682
1. Set |oldDocument|'s [=active view transition=] to |outboundTransition|.
642683

643-
Note: The process continues in [=setup view transition=], via [=perform pending transition operations=].
684+
Note: The process continues in [=perform pending transition operations=].
644685

645686
1. The user agent should display the currently displayed frame until either:
646687
* The {{Window/pagereveal}} event is fired.
@@ -656,20 +697,38 @@ When capturing the old or new state for an element, perform the following steps
656697
<div algorithm>
657698
To <dfn export>resolve cross-document view-transition</dfn> for {{Document}} |document|:
658699

659-
1. Let |transition| be |document|'s [=active view transition=].
700+
1. [=Assert=]: |document| is [=fully active=].
701+
702+
1. Let |inboundViewTransitionParams| be |document|'s [=inbound view transition params=].
703+
704+
1. If |inboundViewTransitionParams| is null, then return null.
705+
706+
1. Set |document|'s [=inbound view transition params=] to null.
660707

661-
1. If |transition| is null or |transition|'s [=ViewTransition/is inbound cross-document transition=] is false,
662-
then return null.
708+
1. If |document|'s [=active view transition=] is not null, then return null.
663709

664-
Note: |transition|'s [=ViewTransition/is inbound cross-document transition=] would be false if a same-document
665-
transition was started before the {{Window/pagereveal}} event was fired.
710+
Note: this means that starting a same-document transition before revealing the document would cancel a pending cross-document transition.
666711

667712
1. [=Resolve @view-transition rule=] for |document| and let |resolvedRule| be the result.
668713

669-
1. If |resolvedRule| is "<code>skip transition</code>", then [=skip the view transition|skip=] |transition| and return null.
714+
1. If |resolvedRule| is "<code>skip transition</code>", then return null.
715+
716+
1. Let |transition| be a new {{ViewTransition}} in |document|'s [=relevant Realm=],
717+
whose [=ViewTransition/named elements=] is |inboundViewTransitionParams|'s [=view transition params/named elements=],
718+
and [=ViewTransition/initial snapshot containing block size=] is |inboundViewTransitionParams|'s [=view transition params/initial snapshot containing block size=].
719+
720+
1. Set |document|'s [=active view transition=] to |transition|.
721+
722+
1. [=Resolve=] |transition|’s [=ViewTransition/update callback done promise=] with undefined.
723+
724+
1. Set |transition|’s [=ViewTransition/phase=] to "`update-callback-called`".
670725

671726
1. Set |transition|'s [=ViewTransition/active types=] to |resolvedRule|.
672727

728+
1. At any given time, the UA may decide to skip the inbound transition, e.g. after an [=implementation-defined=] timeout.
729+
To do so, the UA should [=queue a global task=] on the [=DOM manipulation task source=] given |document|'s [=relevant global object=] to perform the following step:
730+
If |transition|'s [=ViewTransition/phase=] is not "`done`", then [=skip the view transition=] |transition| with a "{{TimeoutError}}" {{DOMException}}.
731+
673732
1. Return |transition|.
674733
</div>
675734

0 commit comments

Comments
 (0)