Skip to content

Commit eb57419

Browse files
committed
Bug 1916311 - [css-view-transitions] Initial pass at DOM API internals. r=boris,webidl,smaug
This is still fairly incomplete (i.e. no capturing, etc), but it allows a transition to "start", and then finish (on the next frame always, for now) or timeout, appropriately. I think it's in a reviewable shape, given that. There's one known divergence from the spec, which is described in w3c/csswg-drafts#10822 Differential Revision: https://phabricator.services.mozilla.com/D220843
1 parent e5aa13a commit eb57419

File tree

79 files changed

+503
-160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+503
-160
lines changed

dom/base/Document.cpp

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
#include "mozilla/dom/URL.h"
244244
#include "mozilla/dom/UseCounterMetrics.h"
245245
#include "mozilla/dom/UserActivation.h"
246+
#include "mozilla/dom/ViewTransition.h"
246247
#include "mozilla/dom/WakeLockJS.h"
247248
#include "mozilla/dom/WakeLockSentinel.h"
248249
#include "mozilla/dom/WindowBinding.h"
@@ -2586,6 +2587,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(Document)
25862587
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrototypeDocument)
25872588
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMidasCommandManager)
25882589
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAll)
2590+
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mActiveViewTransition)
25892591
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocGroup)
25902592
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameRequestManager)
25912593

@@ -2715,6 +2717,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Document)
27152717
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrototypeDocument)
27162718
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMidasCommandManager)
27172719
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAll)
2720+
NS_IMPL_CYCLE_COLLECTION_UNLINK(mActiveViewTransition)
27182721
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReferrerInfo)
27192722
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPreloadReferrerInfo)
27202723

@@ -17782,10 +17785,49 @@ void Document::ClearStaleServoData() {
1778217785
}
1778317786
}
1778417787

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+
});
1778917831
}
1779017832

1779117833
Selection* Document::GetSelection(ErrorResult& aRv) {

dom/base/Document.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3818,8 +3818,13 @@ class Document : public nsINode,
38183818
MOZ_CAN_RUN_SCRIPT void
38193819
DetermineProximityToViewportAndNotifyResizeObservers();
38203820

3821-
ViewTransition* StartViewTransition(
3821+
already_AddRefed<ViewTransition> StartViewTransition(
38223822
const Optional<OwningNonNull<ViewTransitionUpdateCallback>>&);
3823+
ViewTransition* GetActiveViewTransition() const {
3824+
return mActiveViewTransition;
3825+
}
3826+
void ClearActiveViewTransition();
3827+
void PerformPendingViewTransitionOperations();
38233828

38243829
// Getter for PermissionDelegateHandler. Performs lazy initialization.
38253830
PermissionDelegateHandler* GetPermissionDelegateHandler();
@@ -5359,6 +5364,9 @@ class Document : public nsINode,
53595364

53605365
RefPtr<HTMLAllCollection> mAll;
53615366

5367+
// https://drafts.csswg.org/css-view-transitions-1/#document-active-view-transition
5368+
RefPtr<ViewTransition> mActiveViewTransition;
5369+
53625370
nsTHashSet<RefPtr<WorkerDocumentListener>> mWorkerListeners;
53635371

53645372
// Pres shell resolution saved before entering fullscreen mode.

0 commit comments

Comments
 (0)