2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-08-10 11:06:46 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-04-15 02:48:21 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffect.h"
|
2015-11-20 08:12:00 +03:00
|
|
|
|
2016-09-08 23:38:53 +03:00
|
|
|
#include "mozilla/dom/KeyframeAnimationOptionsBinding.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
// For UnrestrictedDoubleOrKeyframeAnimationOptions
|
2016-09-04 10:33:38 +03:00
|
|
|
#include "mozilla/dom/AnimationEffectTiming.h"
|
2015-04-15 02:48:21 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffectBinding.h"
|
2016-02-27 00:39:49 +03:00
|
|
|
#include "nsDOMMutationObserver.h" // For nsAutoAnimationMutationBatch
|
2017-10-26 13:55:28 +03:00
|
|
|
#include "nsStyleContext.h"
|
2014-08-10 11:06:46 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2016-02-15 03:34:47 +03:00
|
|
|
KeyframeEffect::KeyframeEffect(nsIDocument* aDocument,
|
2016-04-28 18:22:44 +03:00
|
|
|
const Maybe<OwningAnimationTarget>& aTarget,
|
2016-05-05 10:41:03 +03:00
|
|
|
const TimingParams& aTiming,
|
|
|
|
const KeyframeEffectParams& aOptions)
|
2016-04-28 18:22:44 +03:00
|
|
|
: KeyframeEffectReadOnly(aDocument, aTarget,
|
2016-05-05 10:41:03 +03:00
|
|
|
new AnimationEffectTiming(aDocument, aTiming, this),
|
|
|
|
aOptions)
|
2016-02-15 03:34:47 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-15 03:34:47 +03:00
|
|
|
JSObject*
|
|
|
|
KeyframeEffect::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto)
|
|
|
|
{
|
|
|
|
return KeyframeEffectBinding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
2016-03-11 11:27:16 +03:00
|
|
|
/* static */ already_AddRefed<KeyframeEffect>
|
|
|
|
KeyframeEffect::Constructor(
|
|
|
|
const GlobalObject& aGlobal,
|
|
|
|
const Nullable<ElementOrCSSPseudoElement>& aTarget,
|
2016-05-13 03:40:52 +03:00
|
|
|
JS::Handle<JSObject*> aKeyframes,
|
2016-03-11 11:27:16 +03:00
|
|
|
const UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2016-05-13 03:40:52 +03:00
|
|
|
return ConstructKeyframeEffect<KeyframeEffect>(aGlobal, aTarget, aKeyframes,
|
2016-03-11 11:27:16 +03:00
|
|
|
aOptions, aRv);
|
|
|
|
}
|
|
|
|
|
2016-10-28 10:41:08 +03:00
|
|
|
/* static */ already_AddRefed<KeyframeEffect>
|
|
|
|
KeyframeEffect::Constructor(const GlobalObject& aGlobal,
|
|
|
|
KeyframeEffectReadOnly& aSource,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2016-11-01 13:39:06 +03:00
|
|
|
return ConstructKeyframeEffect<KeyframeEffect>(aGlobal, aSource, aRv);
|
2016-10-28 10:41:08 +03:00
|
|
|
}
|
|
|
|
|
2016-03-11 11:27:16 +03:00
|
|
|
/* static */ already_AddRefed<KeyframeEffect>
|
|
|
|
KeyframeEffect::Constructor(
|
|
|
|
const GlobalObject& aGlobal,
|
|
|
|
const Nullable<ElementOrCSSPseudoElement>& aTarget,
|
2016-05-13 03:40:52 +03:00
|
|
|
JS::Handle<JSObject*> aKeyframes,
|
2016-03-12 16:14:10 +03:00
|
|
|
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
|
2016-03-11 11:27:16 +03:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2016-05-13 03:40:52 +03:00
|
|
|
return ConstructKeyframeEffect<KeyframeEffect>(aGlobal, aTarget, aKeyframes,
|
2016-03-12 16:14:10 +03:00
|
|
|
aOptions, aRv);
|
2016-03-11 11:27:16 +03:00
|
|
|
}
|
|
|
|
|
2016-04-28 18:22:43 +03:00
|
|
|
void
|
|
|
|
KeyframeEffect::NotifySpecifiedTimingUpdated()
|
2016-02-27 00:39:49 +03:00
|
|
|
{
|
2016-03-21 11:49:50 +03:00
|
|
|
// Use the same document for a pseudo element and its parent element.
|
2016-04-28 18:22:42 +03:00
|
|
|
// Use nullptr if we don't have mTarget, so disable the mutation batch.
|
2016-04-28 18:22:43 +03:00
|
|
|
nsAutoAnimationMutationBatch mb(mTarget ? mTarget->mElement->OwnerDoc()
|
|
|
|
: nullptr);
|
2016-02-27 00:39:49 +03:00
|
|
|
|
|
|
|
if (mAnimation) {
|
|
|
|
mAnimation->NotifyEffectTimingUpdated();
|
|
|
|
|
|
|
|
if (mAnimation->IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(mAnimation);
|
|
|
|
}
|
|
|
|
|
2016-04-28 18:22:43 +03:00
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
2016-02-27 00:39:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 18:22:43 +03:00
|
|
|
void
|
|
|
|
KeyframeEffect::SetTarget(const Nullable<ElementOrCSSPseudoElement>& aTarget)
|
|
|
|
{
|
2016-04-28 18:22:43 +03:00
|
|
|
Maybe<OwningAnimationTarget> newTarget = ConvertTarget(aTarget);
|
|
|
|
if (mTarget == newTarget) {
|
|
|
|
// Assign the same target, skip it.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTarget) {
|
|
|
|
UnregisterTarget();
|
|
|
|
ResetIsRunningOnCompositor();
|
|
|
|
|
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
2016-04-28 18:22:43 +03:00
|
|
|
|
|
|
|
nsAutoAnimationMutationBatch mb(mTarget->mElement->OwnerDoc());
|
|
|
|
if (mAnimation) {
|
|
|
|
nsNodeUtils::AnimationRemoved(mAnimation);
|
|
|
|
}
|
2016-04-28 18:22:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mTarget = newTarget;
|
|
|
|
|
|
|
|
if (mTarget) {
|
|
|
|
UpdateTargetRegistration();
|
2016-05-11 06:41:20 +03:00
|
|
|
RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
|
|
|
|
if (styleContext) {
|
|
|
|
UpdateProperties(styleContext);
|
|
|
|
}
|
2016-04-28 18:22:43 +03:00
|
|
|
|
2016-07-11 02:29:14 +03:00
|
|
|
MaybeUpdateFrameForCompositor();
|
|
|
|
|
2016-04-28 18:22:43 +03:00
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
2016-04-28 18:22:43 +03:00
|
|
|
|
|
|
|
nsAutoAnimationMutationBatch mb(mTarget->mElement->OwnerDoc());
|
|
|
|
if (mAnimation) {
|
|
|
|
nsNodeUtils::AnimationAdded(mAnimation);
|
|
|
|
}
|
2016-04-28 18:22:43 +03:00
|
|
|
}
|
2017-03-24 10:53:54 +03:00
|
|
|
|
|
|
|
// If the new target frame is also oversized we should probably record that
|
|
|
|
// too so we have a more complete picture of the type of frame sizes we
|
|
|
|
// encounter, hence we reset the telemetry flag here.
|
|
|
|
mRecordedContentTooLarge = false;
|
2017-05-04 04:39:42 +03:00
|
|
|
mRecordedFrameSize = false;
|
2016-04-28 18:22:43 +03:00
|
|
|
}
|
|
|
|
|
2016-09-13 05:48:44 +03:00
|
|
|
void
|
|
|
|
KeyframeEffect::SetIterationComposite(
|
2016-12-07 12:47:23 +03:00
|
|
|
const IterationCompositeOperation& aIterationComposite,
|
|
|
|
CallerType aCallerType)
|
2016-09-13 05:48:44 +03:00
|
|
|
{
|
2016-09-21 13:17:18 +03:00
|
|
|
// Ignore iterationComposite if the Web Animations API is not enabled,
|
|
|
|
// then the default value 'Replace' will be used.
|
2016-12-07 12:47:23 +03:00
|
|
|
if (!AnimationUtils::IsCoreAPIEnabledForCaller(aCallerType)) {
|
2016-09-21 13:17:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-13 05:48:44 +03:00
|
|
|
if (mEffectOptions.mIterationComposite == aIterationComposite) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAnimation && mAnimation->IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(mAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffectOptions.mIterationComposite = aIterationComposite;
|
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
|
|
|
}
|
|
|
|
|
2016-12-14 02:51:44 +03:00
|
|
|
void
|
|
|
|
KeyframeEffect::SetComposite(const CompositeOperation& aComposite)
|
|
|
|
{
|
|
|
|
if (mEffectOptions.mComposite == aComposite) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffectOptions.mComposite = aComposite;
|
|
|
|
|
|
|
|
if (mAnimation && mAnimation->IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(mAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTarget) {
|
|
|
|
RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
|
|
|
|
if (styleContext) {
|
|
|
|
UpdateProperties(styleContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:46 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|