1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_ViewTransition_h
6 #define mozilla_dom_ViewTransition_h
9 #include "nsWrapperCache.h"
10 #include "nsTHashMap.h"
12 class nsIGlobalObject
;
24 class ViewTransitionUpdateCallback
;
26 enum class SkipTransitionReason
: uint8_t {
29 ClobberedActiveTransition
,
31 UpdateCallbackRejected
,
32 DuplicateTransitionNameCapturingOldState
,
33 DuplicateTransitionNameCapturingNewState
,
37 // https://drafts.csswg.org/css-view-transitions-1/#viewtransition-phase
38 enum class ViewTransitionPhase
: uint8_t {
45 class ViewTransition final
: public nsISupports
, public nsWrapperCache
{
47 using Phase
= ViewTransitionPhase
;
49 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
50 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(ViewTransition
)
52 ViewTransition(Document
&, ViewTransitionUpdateCallback
*);
54 Promise
* GetUpdateCallbackDone(ErrorResult
&);
55 Promise
* GetReady(ErrorResult
&);
56 Promise
* GetFinished(ErrorResult
&);
58 void SkipTransition(SkipTransitionReason
= SkipTransitionReason::JS
);
59 void PerformPendingOperations();
61 Element
* GetRoot() const { return mViewTransitionRoot
; }
63 nsIGlobalObject
* GetParentObject() const;
64 JSObject
* WrapObject(JSContext
*, JS::Handle
<JSObject
*> aGivenProto
) override
;
66 struct CapturedElement
;
69 enum class CallIfDone
: bool { No
, Yes
};
70 MOZ_CAN_RUN_SCRIPT
void CallUpdateCallbackIgnoringErrors(CallIfDone
);
71 MOZ_CAN_RUN_SCRIPT
void CallUpdateCallback(ErrorResult
&);
74 void ClearActiveTransition();
77 [[nodiscard
]] Maybe
<SkipTransitionReason
> CaptureOldState();
78 [[nodiscard
]] Maybe
<SkipTransitionReason
> CaptureNewState();
79 void SetupTransitionPseudoElements();
80 void ClearNamedElements();
82 void SkipTransition(SkipTransitionReason
, JS::Handle
<JS::Value
>);
83 void ClearTimeoutTimer();
85 nsRect
SnapshotContainingBlockRect() const;
89 // Stored for the whole lifetime of the object (until CC).
90 RefPtr
<Document
> mDocument
;
91 RefPtr
<ViewTransitionUpdateCallback
> mUpdateCallback
;
93 // https://drafts.csswg.org/css-view-transitions/#viewtransition-named-elements
94 using NamedElements
= nsTHashMap
<RefPtr
<nsAtom
>, UniquePtr
<CapturedElement
>>;
95 NamedElements mNamedElements
;
97 // https://drafts.csswg.org/css-view-transitions/#viewtransition-initial-snapshot-containing-block-size
98 nsSize mInitialSnapshotContainingBlockSize
;
100 // Allocated lazily, but same object once allocated (again until CC).
101 RefPtr
<Promise
> mUpdateCallbackDonePromise
;
102 RefPtr
<Promise
> mReadyPromise
;
103 RefPtr
<Promise
> mFinishedPromise
;
105 static void TimeoutCallback(nsITimer
*, void*);
106 RefPtr
<nsITimer
> mTimeoutTimer
;
108 Phase mPhase
= Phase::PendingCapture
;
109 RefPtr
<Element
> mViewTransitionRoot
;
113 } // namespace mozilla