Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / view-transitions / ViewTransition.h
bloba41b06968d46dcadaf1ccd0c410ac065dd46e773
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
8 #include "nsRect.h"
9 #include "nsWrapperCache.h"
10 #include "nsTHashMap.h"
12 class nsIGlobalObject;
13 class nsITimer;
15 namespace mozilla {
17 class ErrorResult;
19 namespace dom {
21 class Document;
22 class Element;
23 class Promise;
24 class ViewTransitionUpdateCallback;
26 enum class SkipTransitionReason : uint8_t {
27 JS,
28 DocumentHidden,
29 ClobberedActiveTransition,
30 Timeout,
31 UpdateCallbackRejected,
32 DuplicateTransitionNameCapturingOldState,
33 DuplicateTransitionNameCapturingNewState,
34 Resize,
37 // https://drafts.csswg.org/css-view-transitions-1/#viewtransition-phase
38 enum class ViewTransitionPhase : uint8_t {
39 PendingCapture = 0,
40 UpdateCallbackCalled,
41 Animating,
42 Done,
45 class ViewTransition final : public nsISupports, public nsWrapperCache {
46 public:
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;
68 private:
69 enum class CallIfDone : bool { No, Yes };
70 MOZ_CAN_RUN_SCRIPT void CallUpdateCallbackIgnoringErrors(CallIfDone);
71 MOZ_CAN_RUN_SCRIPT void CallUpdateCallback(ErrorResult&);
72 void Activate();
74 void ClearActiveTransition();
75 void Timeout();
76 void Setup();
77 [[nodiscard]] Maybe<SkipTransitionReason> CaptureOldState();
78 [[nodiscard]] Maybe<SkipTransitionReason> CaptureNewState();
79 void SetupTransitionPseudoElements();
80 void ClearNamedElements();
81 void HandleFrame();
82 void SkipTransition(SkipTransitionReason, JS::Handle<JS::Value>);
83 void ClearTimeoutTimer();
85 nsRect SnapshotContainingBlockRect() const;
87 ~ViewTransition();
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;
112 } // namespace dom
113 } // namespace mozilla
115 #endif