Bug 1273784 - Part 2: Overload ConstructKeyframeEffect for copy constructor.
The copy constructors of KeyframeEffectReadOnly and KeyframeEffect are
similar, so we overload ConstructKeyframeEffect<...>(...) for copy
constructors.
MozReview-Commit-ID: 37hClpn9ZUG
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -608,16 +608,52 @@ KeyframeEffectReadOnly::ConstructKeyfram
effect->SetKeyframes(aGlobal.Context(), aKeyframes, aRv);
if (aRv.Failed()) {
return nullptr;
}
return effect.forget();
}
+template<class KeyframeEffectType>
+/* static */ already_AddRefed<KeyframeEffectType>
+KeyframeEffectReadOnly::ConstructKeyframeEffect(const GlobalObject& aGlobal,
+ KeyframeEffectReadOnly& aSource,
+ ErrorResult& aRv)
+{
+ nsIDocument* doc = AnimationUtils::GetCurrentRealmDocument(aGlobal.Context());
+ if (!doc) {
+ aRv.Throw(NS_ERROR_FAILURE);
+ return nullptr;
+ }
+
+ // Create a new KeyframeEffectReadOnly object with aSource's target,
+ // iteration composite operation, composite operation, and spacing mode.
+ // The constructor creates a new AnimationEffect(ReadOnly) object by
+ // aSource's TimingParams.
+ // Note: we don't need to re-throw exceptions since the value specified on
+ // aSource's timing object can be assumed valid.
+ RefPtr<KeyframeEffectType> effect =
+ new KeyframeEffectType(doc,
+ aSource.mTarget,
+ aSource.SpecifiedTiming(),
+ aSource.mEffectOptions);
+ // Copy cumulative change hint. mCumulativeChangeHint should be the same as
+ // the source one because both of targets are the same.
+ effect->mCumulativeChangeHint = aSource.mCumulativeChangeHint;
+
+ // Clone aSource's keyframes and then move it into the new effect.
+ // FIXME: Bug 1314537: We have to make sure SharedKeyframeList is handled
+ // properly.
+ RefPtr<nsStyleContext> styleContext = effect->GetTargetStyleContext();
+ nsTArray<Keyframe> keyframes(aSource.mKeyframes);
+ effect->SetKeyframes(Move(keyframes), styleContext);
+ return effect.forget();
+}
+
void
KeyframeEffectReadOnly::UpdateTargetRegistration()
{
if (!mTarget) {
return;
}
bool isRelevant = mAnimation && mAnimation->IsRelevant();
--- a/dom/animation/KeyframeEffectReadOnly.h
+++ b/dom/animation/KeyframeEffectReadOnly.h
@@ -320,16 +320,22 @@ protected:
template<class KeyframeEffectType, class OptionsType>
static already_AddRefed<KeyframeEffectType>
ConstructKeyframeEffect(const GlobalObject& aGlobal,
const Nullable<ElementOrCSSPseudoElement>& aTarget,
JS::Handle<JSObject*> aKeyframes,
const OptionsType& aOptions,
ErrorResult& aRv);
+ template<class KeyframeEffectType>
+ static already_AddRefed<KeyframeEffectType>
+ ConstructKeyframeEffect(const GlobalObject& aGlobal,
+ KeyframeEffectReadOnly& aSource,
+ ErrorResult& aRv);
+
// This effect is registered with its target element so long as:
//
// (a) It has a target element, and
// (b) It is "relevant" (i.e. yet to finish but not idle, or finished but
// filling forwards)
//
// As a result, we need to make sure this gets called whenever anything
// changes with regards to this effects's timing including changes to the