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
https://github.com/w3c/csswg-drafts/issues/10822

Differential Revision: https://phabricator.services.mozilla.com/D220843
This commit is contained in:
Emilio Cobos Álvarez
2024-09-04 11:12:47 +00:00
parent c60a536545
commit 4886de829b
79 changed files with 503 additions and 160 deletions

View File

@@ -243,6 +243,7 @@
#include "mozilla/dom/URL.h"
#include "mozilla/dom/UseCounterMetrics.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/ViewTransition.h"
#include "mozilla/dom/WakeLockJS.h"
#include "mozilla/dom/WakeLockSentinel.h"
#include "mozilla/dom/WindowBinding.h"
@@ -2586,6 +2587,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(Document)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrototypeDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMidasCommandManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAll)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mActiveViewTransition)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocGroup)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameRequestManager)
@@ -2715,6 +2717,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Document)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrototypeDocument)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMidasCommandManager)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAll)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mActiveViewTransition)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReferrerInfo)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPreloadReferrerInfo)
@@ -17782,10 +17785,49 @@ void Document::ClearStaleServoData() {
}
}
ViewTransition* Document::StartViewTransition(
const Optional<OwningNonNull<ViewTransitionUpdateCallback>>&) {
// TODO(emilio): Not yet implemented
return nullptr;
// https://drafts.csswg.org/css-view-transitions-1/#dom-document-startviewtransition
already_AddRefed<ViewTransition> Document::StartViewTransition(
const Optional<OwningNonNull<ViewTransitionUpdateCallback>>& aCallback) {
// Steps 1-3
RefPtr transition = new ViewTransition(
*this, aCallback.WasPassed() ? &aCallback.Value() : nullptr);
if (Hidden()) {
// Step 4:
//
// If document's visibility state is "hidden", then skip transition with an
// "InvalidStateError" DOMException, and return transition.
transition->SkipTransition(SkipTransitionReason::DocumentHidden);
return transition.forget();
}
if (mActiveViewTransition) {
// Step 5:
// If document's active view transition is not null, then skip that view
// transition with an "AbortError" DOMException in this's relevant Realm.
mActiveViewTransition->SkipTransition(
SkipTransitionReason::ClobberedActiveTransition);
}
// Step 6: Set document's active view transition to transition.
mActiveViewTransition = transition;
if (mPresShell) {
if (nsRefreshDriver* rd = mPresShell->GetRefreshDriver()) {
rd->EnsureViewTransitionOperationsHappen();
}
}
// Step 7: return transition
return transition.forget();
}
void Document::ClearActiveViewTransition() { mActiveViewTransition = nullptr; }
void Document::PerformPendingViewTransitionOperations() {
if (mActiveViewTransition) {
mActiveViewTransition->PerformPendingOperations();
}
EnumerateSubDocuments([](Document& aDoc) {
aDoc.PerformPendingViewTransitionOperations();
return CallState::Continue;
});
}
Selection* Document::GetSelection(ErrorResult& aRv) {