Bug 1564128 part 1 - Add clone function for Animation and constructor for KeyframeEffect to copy properties but not the target. r=hiro

This is needed for copying animations from an original document to a static
clone during printing/print preview.

Differential Revision: https://phabricator.services.mozilla.com/D73139
This commit is contained in:
Emily McDonough
2020-05-14 19:41:01 +00:00
parent e971984db0
commit a6dea63c4c
4 changed files with 61 additions and 16 deletions

View File

@@ -83,6 +83,37 @@ class MOZ_RAII AutoMutationBatchForAnimation {
//
// ---------------------------------------------------------------------------
/* static */
already_AddRefed<Animation> Animation::ClonePausedAnimation(
nsIGlobalObject* aGlobal, const Animation& aOther, AnimationEffect& aEffect,
AnimationTimeline& aTimeline) {
RefPtr<Animation> animation = new Animation(aGlobal);
// Setup the timing.
animation->mTimeline = &aTimeline;
const Nullable<TimeDuration> timelineTime =
aTimeline.GetCurrentTimeAsDuration();
MOZ_ASSERT(!timelineTime.IsNull(), "Timeline not yet set");
const Nullable<TimeDuration> currentTime = aOther.GetCurrentTimeAsDuration();
animation->mHoldTime = currentTime;
if (!currentTime.IsNull()) {
animation->mPreviousCurrentTime = timelineTime;
}
animation->mPlaybackRate = aOther.mPlaybackRate;
// Setup the effect's link to this.
animation->mEffect = &aEffect;
animation->mEffect->SetAnimation(animation);
// We expect our relevance to be the same as the orginal.
animation->mIsRelevant = aOther.mIsRelevant;
animation->PostUpdate();
animation->mTimeline->NotifyAnimationUpdated(*animation);
return animation.forget();
}
NonOwningAnimationTarget Animation::GetTargetForAnimation() const {
AnimationEffect* effect = GetEffect();
NonOwningAnimationTarget target;