|
243 | 243 | #include "mozilla/dom/URL.h"
|
244 | 244 | #include "mozilla/dom/UseCounterMetrics.h"
|
245 | 245 | #include "mozilla/dom/UserActivation.h"
|
| 246 | +#include "mozilla/dom/ViewTransition.h" |
246 | 247 | #include "mozilla/dom/WakeLockJS.h"
|
247 | 248 | #include "mozilla/dom/WakeLockSentinel.h"
|
248 | 249 | #include "mozilla/dom/WindowBinding.h"
|
@@ -2586,6 +2587,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(Document)
|
2586 | 2587 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrototypeDocument)
|
2587 | 2588 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMidasCommandManager)
|
2588 | 2589 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAll)
|
| 2590 | + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mActiveViewTransition) |
2589 | 2591 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocGroup)
|
2590 | 2592 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameRequestManager)
|
2591 | 2593 |
|
@@ -2715,6 +2717,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Document)
|
2715 | 2717 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrototypeDocument)
|
2716 | 2718 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mMidasCommandManager)
|
2717 | 2719 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mAll)
|
| 2720 | + NS_IMPL_CYCLE_COLLECTION_UNLINK(mActiveViewTransition) |
2718 | 2721 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mReferrerInfo)
|
2719 | 2722 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mPreloadReferrerInfo)
|
2720 | 2723 |
|
@@ -17782,10 +17785,49 @@ void Document::ClearStaleServoData() {
|
17782 | 17785 | }
|
17783 | 17786 | }
|
17784 | 17787 |
|
17785 |
| -ViewTransition* Document::StartViewTransition( |
17786 |
| - const Optional<OwningNonNull<ViewTransitionUpdateCallback>>&) { |
17787 |
| - // TODO(emilio): Not yet implemented |
17788 |
| - return nullptr; |
| 17788 | +// https://drafts.csswg.org/css-view-transitions-1/#dom-document-startviewtransition |
| 17789 | +already_AddRefed<ViewTransition> Document::StartViewTransition( |
| 17790 | + const Optional<OwningNonNull<ViewTransitionUpdateCallback>>& aCallback) { |
| 17791 | + // Steps 1-3 |
| 17792 | + RefPtr transition = new ViewTransition( |
| 17793 | + *this, aCallback.WasPassed() ? &aCallback.Value() : nullptr); |
| 17794 | + if (Hidden()) { |
| 17795 | + // Step 4: |
| 17796 | + // |
| 17797 | + // If document's visibility state is "hidden", then skip transition with an |
| 17798 | + // "InvalidStateError" DOMException, and return transition. |
| 17799 | + transition->SkipTransition(SkipTransitionReason::DocumentHidden); |
| 17800 | + return transition.forget(); |
| 17801 | + } |
| 17802 | + if (mActiveViewTransition) { |
| 17803 | + // Step 5: |
| 17804 | + // If document's active view transition is not null, then skip that view |
| 17805 | + // transition with an "AbortError" DOMException in this's relevant Realm. |
| 17806 | + mActiveViewTransition->SkipTransition( |
| 17807 | + SkipTransitionReason::ClobberedActiveTransition); |
| 17808 | + } |
| 17809 | + // Step 6: Set document's active view transition to transition. |
| 17810 | + mActiveViewTransition = transition; |
| 17811 | + |
| 17812 | + if (mPresShell) { |
| 17813 | + if (nsRefreshDriver* rd = mPresShell->GetRefreshDriver()) { |
| 17814 | + rd->EnsureViewTransitionOperationsHappen(); |
| 17815 | + } |
| 17816 | + } |
| 17817 | + // Step 7: return transition |
| 17818 | + return transition.forget(); |
| 17819 | +} |
| 17820 | + |
| 17821 | +void Document::ClearActiveViewTransition() { mActiveViewTransition = nullptr; } |
| 17822 | + |
| 17823 | +void Document::PerformPendingViewTransitionOperations() { |
| 17824 | + if (mActiveViewTransition) { |
| 17825 | + mActiveViewTransition->PerformPendingOperations(); |
| 17826 | + } |
| 17827 | + EnumerateSubDocuments([](Document& aDoc) { |
| 17828 | + aDoc.PerformPendingViewTransitionOperations(); |
| 17829 | + return CallState::Continue; |
| 17830 | + }); |
17789 | 17831 | }
|
17790 | 17832 |
|
17791 | 17833 | Selection* Document::GetSelection(ErrorResult& aRv) {
|
|
0 commit comments