2016-09-04 10:34:21 +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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2018-05-07 05:07:06 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffect.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2017-10-26 13:55:28 +03:00
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "mozilla/dom/Animation.h"
|
2016-09-08 23:38:53 +03:00
|
|
|
#include "mozilla/dom/KeyframeAnimationOptionsBinding.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
// For UnrestrictedDoubleOrKeyframeAnimationOptions;
|
|
|
|
#include "mozilla/dom/CSSPseudoElement.h"
|
|
|
|
#include "mozilla/dom/KeyframeEffectBinding.h"
|
|
|
|
#include "mozilla/AnimationUtils.h"
|
2016-12-21 07:52:19 +03:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2018-03-22 21:20:41 +03:00
|
|
|
#include "mozilla/ComputedStyleInlines.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "mozilla/EffectSet.h"
|
|
|
|
#include "mozilla/FloatingPoint.h" // For IsFinite
|
2017-10-26 13:55:28 +03:00
|
|
|
#include "mozilla/LayerAnimationInfo.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "mozilla/LookAndFeel.h" // For LookAndFeel::GetInt
|
|
|
|
#include "mozilla/KeyframeUtils.h"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2019-04-30 04:52:53 +03:00
|
|
|
#include "mozilla/PresShellInlines.h"
|
2016-10-24 12:16:46 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2018-07-14 03:23:03 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2017-02-23 03:52:44 +03:00
|
|
|
#include "mozilla/TypeTraits.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "Layers.h" // For Layer
|
2018-03-22 21:20:41 +03:00
|
|
|
#include "nsComputedDOMStyle.h" // nsComputedDOMStyle::GetComputedStyle
|
2017-10-26 13:55:28 +03:00
|
|
|
#include "nsContentUtils.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "nsCSSPropertyIDSet.h"
|
2019-02-15 09:05:06 +03:00
|
|
|
#include "nsCSSProps.h" // For nsCSSProps::PropHasFlags
|
2019-02-19 16:44:33 +03:00
|
|
|
#include "nsCSSPseudoElements.h" // For PseudoStyleType
|
2019-02-15 09:05:06 +03:00
|
|
|
#include "nsDOMMutationObserver.h" // For nsAutoAnimationMutationBatch
|
2017-10-26 13:55:28 +03:00
|
|
|
#include "nsIFrame.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "nsIScriptError.h"
|
2019-03-29 18:11:22 +03:00
|
|
|
#include "nsPresContextInlines.h"
|
2017-10-26 13:55:28 +03:00
|
|
|
#include "nsRefreshDriver.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
2016-10-24 12:16:46 +03:00
|
|
|
|
2019-03-21 20:40:11 +03:00
|
|
|
void AnimationProperty::SetPerformanceWarning(
|
|
|
|
const AnimationPerformanceWarning& aWarning, const Element* aElement) {
|
|
|
|
if (mPerformanceWarning && *mPerformanceWarning == aWarning) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPerformanceWarning = Some(aWarning);
|
|
|
|
|
|
|
|
nsAutoString localizedString;
|
|
|
|
if (nsLayoutUtils::IsAnimationLoggingEnabled() &&
|
|
|
|
mPerformanceWarning->ToLocalizedString(localizedString)) {
|
|
|
|
nsAutoCString logMessage = NS_ConvertUTF16toUTF8(localizedString);
|
|
|
|
AnimationUtils::LogAsyncAnimationFailure(logMessage, aElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-24 12:16:46 +03:00
|
|
|
bool PropertyValuePair::operator==(const PropertyValuePair& aOther) const {
|
2018-03-26 08:15:56 +03:00
|
|
|
if (mProperty != aOther.mProperty) {
|
2016-10-24 12:16:46 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mServoDeclarationBlock == aOther.mServoDeclarationBlock) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!mServoDeclarationBlock || !aOther.mServoDeclarationBlock) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Servo_DeclarationBlock_Equals(mServoDeclarationBlock,
|
|
|
|
aOther.mServoDeclarationBlock);
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
namespace dom {
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(KeyframeEffect, AnimationEffect, mTarget)
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(KeyframeEffect, AnimationEffect)
|
2016-09-04 10:34:21 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(KeyframeEffect)
|
2018-05-07 05:15:16 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(AnimationEffect)
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2018-05-07 05:15:16 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(KeyframeEffect, AnimationEffect)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(KeyframeEffect, AnimationEffect)
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
KeyframeEffect::KeyframeEffect(Document* aDocument,
|
2016-09-04 10:34:21 +03:00
|
|
|
const Maybe<OwningAnimationTarget>& aTarget,
|
2018-10-16 00:38:00 +03:00
|
|
|
TimingParams&& aTiming,
|
2016-09-04 10:34:21 +03:00
|
|
|
const KeyframeEffectParams& aOptions)
|
2018-10-16 00:38:00 +03:00
|
|
|
: AnimationEffect(aDocument, std::move(aTiming)),
|
2016-09-04 10:34:21 +03:00
|
|
|
mTarget(aTarget),
|
|
|
|
mEffectOptions(aOptions),
|
|
|
|
mCumulativeChangeHint(nsChangeHint(0)) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
JSObject* KeyframeEffect::WrapObject(JSContext* aCx,
|
2016-09-04 10:34:21 +03:00
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return KeyframeEffect_Binding::Wrap(aCx, this, aGivenProto);
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2018-07-14 03:23:03 +03:00
|
|
|
IterationCompositeOperation KeyframeEffect::IterationComposite() const {
|
2016-09-13 05:48:44 +03:00
|
|
|
return mEffectOptions.mIterationComposite;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::SetIterationComposite(
|
2018-07-14 03:23:03 +03:00
|
|
|
const IterationCompositeOperation& aIterationComposite) {
|
2018-05-07 04:48:48 +03:00
|
|
|
if (mEffectOptions.mIterationComposite == aIterationComposite) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAnimation && mAnimation->IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(mAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffectOptions.mIterationComposite = aIterationComposite;
|
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
CompositeOperation KeyframeEffect::Composite() const {
|
2016-12-04 02:07:41 +03:00
|
|
|
return mEffectOptions.mComposite;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::SetComposite(const CompositeOperation& aComposite) {
|
2018-05-07 04:48:48 +03:00
|
|
|
if (mEffectOptions.mComposite == aComposite) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffectOptions.mComposite = aComposite;
|
|
|
|
|
|
|
|
if (mAnimation && mAnimation->IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(mAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTarget) {
|
2019-02-15 09:08:05 +03:00
|
|
|
RefPtr<ComputedStyle> computedStyle = GetTargetComputedStyle(Flush::None);
|
2018-05-07 04:48:48 +03:00
|
|
|
if (computedStyle) {
|
|
|
|
UpdateProperties(computedStyle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::NotifySpecifiedTimingUpdated() {
|
2018-05-07 05:02:12 +03:00
|
|
|
// Use the same document for a pseudo element and its parent element.
|
|
|
|
// Use nullptr if we don't have mTarget, so disable the mutation batch.
|
|
|
|
nsAutoAnimationMutationBatch mb(mTarget ? mTarget->mElement->OwnerDoc()
|
|
|
|
: nullptr);
|
|
|
|
|
|
|
|
if (mAnimation) {
|
|
|
|
mAnimation->NotifyEffectTimingUpdated();
|
|
|
|
|
|
|
|
if (mAnimation->IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(mAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:49:25 +03:00
|
|
|
void KeyframeEffect::NotifyAnimationTimingUpdated(
|
|
|
|
PostRestyleMode aPostRestyle) {
|
2016-09-04 10:34:21 +03:00
|
|
|
UpdateTargetRegistration();
|
|
|
|
|
|
|
|
// If the effect is not relevant it will be removed from the target
|
|
|
|
// element's effect set. However, effects not in the effect set
|
|
|
|
// will not be included in the set of candidate effects for running on
|
|
|
|
// the compositor and hence they won't have their compositor status
|
|
|
|
// updated. As a result, we need to make sure we clear their compositor
|
|
|
|
// status here.
|
|
|
|
bool isRelevant = mAnimation && mAnimation->IsRelevant();
|
|
|
|
if (!isRelevant) {
|
|
|
|
ResetIsRunningOnCompositor();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request restyle if necessary.
|
2019-04-18 09:49:25 +03:00
|
|
|
if (aPostRestyle == PostRestyleMode::IfNeeded && mAnimation &&
|
|
|
|
!mProperties.IsEmpty() && HasComputedTimingChanged()) {
|
2016-09-04 10:34:21 +03:00
|
|
|
EffectCompositor::RestyleType restyleType =
|
|
|
|
CanThrottle() ? EffectCompositor::RestyleType::Throttled
|
|
|
|
: EffectCompositor::RestyleType::Standard;
|
|
|
|
RequestRestyle(restyleType);
|
|
|
|
}
|
|
|
|
|
2017-10-20 12:23:44 +03:00
|
|
|
// Detect changes to "in effect" status since we need to recalculate the
|
|
|
|
// animation cascade for this element whenever that changes.
|
|
|
|
// Note that updating mInEffectOnLastAnimationTimingUpdate has to be done
|
|
|
|
// after above CanThrottle() call since the function uses the flag inside it.
|
|
|
|
bool inEffect = IsInEffect();
|
|
|
|
if (inEffect != mInEffectOnLastAnimationTimingUpdate) {
|
|
|
|
MarkCascadeNeedsUpdate();
|
|
|
|
mInEffectOnLastAnimationTimingUpdate = inEffect;
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
// If we're no longer "in effect", our ComposeStyle method will never be
|
2016-09-13 05:48:45 +03:00
|
|
|
// called and we will never have a chance to update mProgressOnLastCompose
|
|
|
|
// and mCurrentIterationOnLastCompose.
|
|
|
|
// We clear them here to ensure that if we later become "in effect" we will
|
|
|
|
// request a restyle (above).
|
2016-09-04 10:34:21 +03:00
|
|
|
if (!inEffect) {
|
|
|
|
mProgressOnLastCompose.SetNull();
|
2016-09-13 05:48:45 +03:00
|
|
|
mCurrentIterationOnLastCompose = 0;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool KeyframesEqualIgnoringComputedOffsets(
|
|
|
|
const nsTArray<Keyframe>& aLhs, const nsTArray<Keyframe>& aRhs) {
|
|
|
|
if (aLhs.Length() != aRhs.Length()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0, len = aLhs.Length(); i < len; ++i) {
|
|
|
|
const Keyframe& a = aLhs[i];
|
|
|
|
const Keyframe& b = aRhs[i];
|
|
|
|
if (a.mOffset != b.mOffset || a.mTimingFunction != b.mTimingFunction ||
|
|
|
|
a.mPropertyValues != b.mPropertyValues) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#dom-keyframeeffect-setkeyframes
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::SetKeyframes(JSContext* aContext,
|
|
|
|
JS::Handle<JSObject*> aKeyframes,
|
|
|
|
ErrorResult& aRv) {
|
2016-09-04 10:34:21 +03:00
|
|
|
nsTArray<Keyframe> keyframes = KeyframeUtils::GetKeyframesFromObject(
|
|
|
|
aContext, mDocument, aKeyframes, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-15 09:08:05 +03:00
|
|
|
RefPtr<ComputedStyle> style = GetTargetComputedStyle(Flush::None);
|
2018-05-30 22:15:35 +03:00
|
|
|
SetKeyframes(std::move(keyframes), style);
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2017-02-23 03:52:44 +03:00
|
|
|
void KeyframeEffect::SetKeyframes(nsTArray<Keyframe>&& aKeyframes,
|
2018-04-06 15:49:45 +03:00
|
|
|
const ComputedStyle* aStyle) {
|
2016-09-04 10:34:21 +03:00
|
|
|
if (KeyframesEqualIgnoringComputedOffsets(aKeyframes, mKeyframes)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
mKeyframes = std::move(aKeyframes);
|
2017-06-15 05:47:32 +03:00
|
|
|
KeyframeUtils::DistributeKeyframes(mKeyframes);
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
if (mAnimation && mAnimation->IsRelevant()) {
|
|
|
|
nsNodeUtils::AnimationChanged(mAnimation);
|
|
|
|
}
|
|
|
|
|
2018-04-09 14:15:59 +03:00
|
|
|
// We need to call UpdateProperties() unless the target element doesn't have
|
|
|
|
// style (e.g. the target element is not associated with any document).
|
2017-06-02 03:38:54 +03:00
|
|
|
if (aStyle) {
|
2017-02-23 03:52:44 +03:00
|
|
|
UpdateProperties(aStyle);
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:18:09 +03:00
|
|
|
static bool IsEffectiveProperty(const EffectSet& aEffects,
|
|
|
|
nsCSSPropertyID aProperty) {
|
|
|
|
return !aEffects.PropertiesWithImportantRules().HasProperty(aProperty) ||
|
|
|
|
!aEffects.PropertiesForAnimationsLevel().HasProperty(aProperty);
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:17:44 +03:00
|
|
|
const AnimationProperty* KeyframeEffect::GetEffectiveAnimationOfProperty(
|
|
|
|
nsCSSPropertyID aProperty, const EffectSet& aEffects) const {
|
|
|
|
MOZ_ASSERT(&aEffects ==
|
|
|
|
EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType));
|
|
|
|
|
2018-11-13 13:17:56 +03:00
|
|
|
for (const AnimationProperty& property : mProperties) {
|
|
|
|
if (aProperty != property.mProperty) {
|
|
|
|
continue;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
2018-11-13 13:17:56 +03:00
|
|
|
|
|
|
|
const AnimationProperty* result = nullptr;
|
|
|
|
// Only include the property if it is not overridden by !important rules in
|
|
|
|
// the transitions level.
|
2018-11-13 13:18:09 +03:00
|
|
|
if (IsEffectiveProperty(aEffects, property.mProperty)) {
|
2018-11-13 13:17:56 +03:00
|
|
|
result = &property;
|
|
|
|
}
|
|
|
|
return result;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-23 03:21:45 +03:00
|
|
|
bool KeyframeEffect::HasEffectiveAnimationOfPropertySet(
|
2019-03-18 07:10:10 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertySet, const EffectSet& aEffectSet) const {
|
|
|
|
// The various transform properties ('transform', 'scale' etc.) get combined
|
|
|
|
// on the compositor.
|
|
|
|
//
|
|
|
|
// As a result, if we have an animation of 'scale' and 'translate', but the
|
|
|
|
// 'translate' property is covered by an !important rule, we will not be
|
|
|
|
// able to combine the result on the compositor since we won't have the
|
|
|
|
// !important rule to incorporate. In that case we should run all the
|
|
|
|
// transform-related animations on the main thread (where we have the
|
|
|
|
// !important rule).
|
|
|
|
//
|
|
|
|
// Bug 1534884: Move this check to ShouldBlockAsyncTransformAnimations (or
|
|
|
|
// similar) and add a performance warning for this case.
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
|
2019-02-23 03:21:45 +03:00
|
|
|
for (const AnimationProperty& property : mProperties) {
|
|
|
|
if (!aPropertySet.HasProperty(property.mProperty)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-18 07:10:10 +03:00
|
|
|
if (IsEffectiveProperty(aEffectSet, property.mProperty)) {
|
|
|
|
result = true;
|
|
|
|
} else if (nsCSSPropertyIDSet::TransformLikeProperties().HasProperty(
|
|
|
|
property.mProperty)) {
|
2019-02-23 03:21:45 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-03-18 07:10:10 +03:00
|
|
|
|
|
|
|
return result;
|
2019-02-23 03:21:45 +03:00
|
|
|
}
|
|
|
|
|
2018-11-22 06:57:59 +03:00
|
|
|
nsCSSPropertyIDSet KeyframeEffect::GetPropertiesForCompositor(
|
|
|
|
EffectSet& aEffects, const nsIFrame* aFrame) const {
|
2018-11-13 13:22:26 +03:00
|
|
|
MOZ_ASSERT(&aEffects ==
|
|
|
|
EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType));
|
|
|
|
|
|
|
|
nsCSSPropertyIDSet properties;
|
|
|
|
|
2019-05-20 08:55:52 +03:00
|
|
|
if (!mAnimation || !mAnimation->IsRelevant()) {
|
2018-11-13 13:22:26 +03:00
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr nsCSSPropertyIDSet compositorAnimatables =
|
|
|
|
nsCSSPropertyIDSet::CompositorAnimatables();
|
|
|
|
for (const AnimationProperty& property : mProperties) {
|
|
|
|
if (!compositorAnimatables.HasProperty(property.mProperty)) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-22 06:57:59 +03:00
|
|
|
|
|
|
|
AnimationPerformanceWarning::Type warning;
|
2019-03-02 00:13:03 +03:00
|
|
|
KeyframeEffect::MatchForCompositor matchResult = IsMatchForCompositor(
|
|
|
|
nsCSSPropertyIDSet{property.mProperty}, aFrame, aEffects, warning);
|
2018-11-22 06:57:59 +03:00
|
|
|
if (matchResult ==
|
|
|
|
KeyframeEffect::MatchForCompositor::NoAndBlockThisProperty ||
|
|
|
|
matchResult == KeyframeEffect::MatchForCompositor::No) {
|
|
|
|
continue;
|
2018-11-13 13:22:26 +03:00
|
|
|
}
|
2018-11-22 06:57:59 +03:00
|
|
|
|
|
|
|
properties.AddProperty(property.mProperty);
|
2018-11-13 13:22:26 +03:00
|
|
|
}
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
2019-05-20 08:48:31 +03:00
|
|
|
nsCSSPropertyIDSet KeyframeEffect::GetPropertySet() const {
|
|
|
|
nsCSSPropertyIDSet result;
|
|
|
|
|
2016-10-13 10:54:25 +03:00
|
|
|
for (const AnimationProperty& property : mProperties) {
|
2019-05-20 08:48:31 +03:00
|
|
|
result.AddProperty(property.mProperty);
|
2016-10-13 10:54:25 +03:00
|
|
|
}
|
2019-05-20 08:48:31 +03:00
|
|
|
|
|
|
|
return result;
|
2016-10-13 10:54:25 +03:00
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool SpecifiedKeyframeArraysAreEqual(const nsTArray<Keyframe>& aA,
|
|
|
|
const nsTArray<Keyframe>& aB) {
|
|
|
|
if (aA.Length() != aB.Length()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < aA.Length(); i++) {
|
|
|
|
const Keyframe& a = aA[i];
|
|
|
|
const Keyframe& b = aB[i];
|
|
|
|
if (a.mOffset != b.mOffset || a.mTimingFunction != b.mTimingFunction ||
|
|
|
|
a.mPropertyValues != b.mPropertyValues) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::UpdateProperties(const ComputedStyle* aStyle) {
|
2017-06-02 03:38:54 +03:00
|
|
|
MOZ_ASSERT(aStyle);
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2017-06-02 03:38:54 +03:00
|
|
|
nsTArray<AnimationProperty> properties = BuildProperties(aStyle);
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2018-12-06 23:59:50 +03:00
|
|
|
bool propertiesChanged = mProperties != properties;
|
|
|
|
|
2017-02-11 13:11:45 +03:00
|
|
|
// We need to update base styles even if any properties are not changed at all
|
|
|
|
// since base styles might have been changed due to parent style changes, etc.
|
2018-12-06 23:59:50 +03:00
|
|
|
bool baseStylesChanged = false;
|
|
|
|
EnsureBaseStyles(aStyle, properties,
|
|
|
|
!propertiesChanged ? &baseStylesChanged : nullptr);
|
2017-02-11 13:11:45 +03:00
|
|
|
|
2018-12-06 23:59:50 +03:00
|
|
|
if (!propertiesChanged) {
|
|
|
|
if (baseStylesChanged) {
|
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
|
|
|
}
|
2019-02-15 08:51:08 +03:00
|
|
|
// Check if we need to update the cumulative change hint because we now have
|
|
|
|
// style data.
|
|
|
|
if (mNeedsStyleData && mTarget && mTarget->mElement->HasServoData()) {
|
|
|
|
CalculateCumulativeChangeHint(aStyle);
|
|
|
|
}
|
2016-09-04 10:34:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-05 08:48:05 +03:00
|
|
|
// Preserve the state of the mIsRunningOnCompositor flag.
|
2016-09-04 10:34:21 +03:00
|
|
|
nsCSSPropertyIDSet runningOnCompositorProperties;
|
|
|
|
|
|
|
|
for (const AnimationProperty& property : mProperties) {
|
|
|
|
if (property.mIsRunningOnCompositor) {
|
|
|
|
runningOnCompositorProperties.AddProperty(property.mProperty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
mProperties = std::move(properties);
|
2017-06-20 09:42:26 +03:00
|
|
|
UpdateEffectSet();
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
for (AnimationProperty& property : mProperties) {
|
|
|
|
property.mIsRunningOnCompositor =
|
|
|
|
runningOnCompositorProperties.HasProperty(property.mProperty);
|
|
|
|
}
|
|
|
|
|
2017-02-23 03:52:44 +03:00
|
|
|
CalculateCumulativeChangeHint(aStyle);
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
MarkCascadeNeedsUpdate();
|
|
|
|
|
2019-05-20 08:48:29 +03:00
|
|
|
if (mAnimation) {
|
|
|
|
mAnimation->NotifyEffectPropertiesUpdated();
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::EnsureBaseStyles(
|
2018-03-22 21:20:41 +03:00
|
|
|
const ComputedStyle* aComputedValues,
|
2018-12-06 23:59:50 +03:00
|
|
|
const nsTArray<AnimationProperty>& aProperties, bool* aBaseStylesChanged) {
|
|
|
|
if (aBaseStylesChanged != nullptr) {
|
|
|
|
*aBaseStylesChanged = false;
|
|
|
|
}
|
|
|
|
|
2017-04-06 04:34:50 +03:00
|
|
|
if (!mTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-07 20:28:29 +03:00
|
|
|
BaseValuesHashmap previousBaseStyles;
|
2018-12-06 23:59:50 +03:00
|
|
|
if (aBaseStylesChanged != nullptr) {
|
2018-12-07 20:28:29 +03:00
|
|
|
previousBaseStyles = std::move(mBaseValues);
|
2018-12-06 23:59:50 +03:00
|
|
|
}
|
|
|
|
|
2018-12-06 23:57:12 +03:00
|
|
|
mBaseValues.Clear();
|
2017-04-06 04:34:50 +03:00
|
|
|
|
|
|
|
nsPresContext* presContext =
|
|
|
|
nsContentUtils::GetContextForContent(mTarget->mElement);
|
2017-12-20 11:34:57 +03:00
|
|
|
// If |aProperties| is empty we're not going to dereference |presContext| so
|
|
|
|
// we don't care if it is nullptr.
|
|
|
|
//
|
|
|
|
// We could just return early when |aProperties| is empty and save looking up
|
|
|
|
// the pres context, but that won't save any effort normally since we don't
|
|
|
|
// call this function if we have no keyframes to begin with. Furthermore, the
|
|
|
|
// case where |presContext| is nullptr is so rare (we've only ever seen in
|
|
|
|
// fuzzing, and even then we've never been able to reproduce it reliably)
|
|
|
|
// it's not worth the runtime cost of an extra branch.
|
|
|
|
MOZ_ASSERT(presContext || aProperties.IsEmpty(),
|
|
|
|
"Typically presContext should not be nullptr but if it is"
|
|
|
|
" we should have also failed to calculate the computed values"
|
|
|
|
" passed-in as aProperties");
|
2017-04-06 04:34:50 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
RefPtr<ComputedStyle> baseComputedStyle;
|
2017-04-06 04:34:50 +03:00
|
|
|
for (const AnimationProperty& property : aProperties) {
|
|
|
|
EnsureBaseStyle(property, presContext, aComputedValues, baseComputedStyle);
|
|
|
|
}
|
2018-12-06 23:59:50 +03:00
|
|
|
|
|
|
|
if (aBaseStylesChanged != nullptr) {
|
|
|
|
for (auto iter = mBaseValues.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
if (AnimationValue(iter.Data()) !=
|
2018-12-07 20:28:29 +03:00
|
|
|
AnimationValue(previousBaseStyles.Get(iter.Key()))) {
|
2018-12-06 23:59:50 +03:00
|
|
|
*aBaseStylesChanged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-06 04:34:50 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::EnsureBaseStyle(
|
2017-04-06 04:34:50 +03:00
|
|
|
const AnimationProperty& aProperty, nsPresContext* aPresContext,
|
2018-03-22 21:20:41 +03:00
|
|
|
const ComputedStyle* aComputedStyle,
|
|
|
|
RefPtr<ComputedStyle>& aBaseComputedStyle) {
|
2017-04-06 04:34:50 +03:00
|
|
|
bool hasAdditiveValues = false;
|
|
|
|
|
|
|
|
for (const AnimationPropertySegment& segment : aProperty.mSegments) {
|
|
|
|
if (!segment.HasReplaceableValues()) {
|
|
|
|
hasAdditiveValues = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasAdditiveValues) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
if (!aBaseComputedStyle) {
|
2017-11-22 05:03:40 +03:00
|
|
|
Element* animatingElement = EffectCompositor::GetElementToRestyle(
|
|
|
|
mTarget->mElement, mTarget->mPseudoType);
|
2019-02-15 08:54:10 +03:00
|
|
|
if (!animatingElement) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-29 14:15:46 +03:00
|
|
|
aBaseComputedStyle = aPresContext->StyleSet()->GetBaseContextForElement(
|
|
|
|
animatingElement, aComputedStyle);
|
2017-04-06 04:34:50 +03:00
|
|
|
}
|
|
|
|
RefPtr<RawServoAnimationValue> baseValue =
|
2018-03-22 21:20:41 +03:00
|
|
|
Servo_ComputedValues_ExtractAnimationValue(aBaseComputedStyle,
|
2017-04-06 04:34:50 +03:00
|
|
|
aProperty.mProperty)
|
|
|
|
.Consume();
|
2018-12-06 23:57:12 +03:00
|
|
|
mBaseValues.Put(aProperty.mProperty, baseValue);
|
2017-04-06 04:34:50 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::WillComposeStyle() {
|
2017-03-08 23:20:17 +03:00
|
|
|
ComputedTiming computedTiming = GetComputedTiming();
|
|
|
|
mProgressOnLastCompose = computedTiming.mProgress;
|
|
|
|
mCurrentIterationOnLastCompose = computedTiming.mCurrentIteration;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::ComposeStyleRule(
|
2017-05-01 12:45:41 +03:00
|
|
|
RawServoAnimationValueMap& aAnimationValues,
|
2017-03-17 06:48:56 +03:00
|
|
|
const AnimationProperty& aProperty,
|
|
|
|
const AnimationPropertySegment& aSegment,
|
|
|
|
const ComputedTiming& aComputedTiming) {
|
2019-03-21 20:00:27 +03:00
|
|
|
auto* opaqueTable =
|
|
|
|
reinterpret_cast<RawServoAnimationValueTable*>(&mBaseValues);
|
|
|
|
Servo_AnimationCompose(&aAnimationValues, opaqueTable, aProperty.mProperty,
|
2018-12-06 23:57:12 +03:00
|
|
|
&aSegment, &aProperty.mSegments.LastElement(),
|
|
|
|
&aComputedTiming, mEffectOptions.mIterationComposite);
|
2017-03-17 06:48:56 +03:00
|
|
|
}
|
|
|
|
|
2018-04-09 14:15:59 +03:00
|
|
|
void KeyframeEffect::ComposeStyle(RawServoAnimationValueMap& aComposeResult,
|
2016-10-05 08:42:56 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertiesToSkip) {
|
2016-09-04 10:34:21 +03:00
|
|
|
ComputedTiming computedTiming = GetComputedTiming();
|
|
|
|
|
|
|
|
// If the progress is null, we don't have fill data for the current
|
|
|
|
// time so we shouldn't animate.
|
|
|
|
if (computedTiming.mProgress.IsNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t propIdx = 0, propEnd = mProperties.Length(); propIdx != propEnd;
|
|
|
|
++propIdx) {
|
|
|
|
const AnimationProperty& prop = mProperties[propIdx];
|
|
|
|
|
|
|
|
MOZ_ASSERT(prop.mSegments[0].mFromKey == 0.0, "incorrect first from key");
|
|
|
|
MOZ_ASSERT(prop.mSegments[prop.mSegments.Length() - 1].mToKey == 1.0,
|
|
|
|
"incorrect last to key");
|
|
|
|
|
2016-10-05 08:42:56 +03:00
|
|
|
if (aPropertiesToSkip.HasProperty(prop.mProperty)) {
|
2016-09-04 10:34:21 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(prop.mSegments.Length() > 0,
|
|
|
|
"property should not be in animations if it has no segments");
|
|
|
|
|
|
|
|
// FIXME: Maybe cache the current segment?
|
|
|
|
const AnimationPropertySegment *segment = prop.mSegments.Elements(),
|
|
|
|
*segmentEnd =
|
|
|
|
segment + prop.mSegments.Length();
|
|
|
|
while (segment->mToKey <= computedTiming.mProgress.Value()) {
|
|
|
|
MOZ_ASSERT(segment->mFromKey <= segment->mToKey, "incorrect keys");
|
|
|
|
if ((segment + 1) == segmentEnd) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++segment;
|
|
|
|
MOZ_ASSERT(segment->mFromKey == (segment - 1)->mToKey, "incorrect keys");
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(segment->mFromKey <= segment->mToKey, "incorrect keys");
|
|
|
|
MOZ_ASSERT(segment >= prop.mSegments.Elements() &&
|
|
|
|
size_t(segment - prop.mSegments.Elements()) <
|
|
|
|
prop.mSegments.Length(),
|
|
|
|
"out of array bounds");
|
|
|
|
|
2018-04-09 14:15:59 +03:00
|
|
|
ComposeStyleRule(aComposeResult, prop, *segment, computedTiming);
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
2017-10-31 03:45:41 +03:00
|
|
|
|
2018-06-25 03:12:21 +03:00
|
|
|
// If the animation produces a change hint that affects the overflow region,
|
|
|
|
// we need to record the current time to unthrottle the animation
|
2018-02-27 08:46:32 +03:00
|
|
|
// periodically when the animation is being throttled because it's scrolled
|
|
|
|
// out of view.
|
2018-06-25 03:12:21 +03:00
|
|
|
if (HasPropertiesThatMightAffectOverflow()) {
|
2017-10-31 03:45:41 +03:00
|
|
|
nsPresContext* presContext =
|
|
|
|
nsContentUtils::GetContextForContent(mTarget->mElement);
|
|
|
|
if (presContext) {
|
|
|
|
TimeStamp now = presContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
EffectSet* effectSet =
|
|
|
|
EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType);
|
|
|
|
MOZ_ASSERT(effectSet,
|
|
|
|
"ComposeStyle should only be called on an effect "
|
|
|
|
"that is part of an effect set");
|
2018-06-25 03:12:21 +03:00
|
|
|
effectSet->UpdateLastOverflowAnimationSyncTime(now);
|
2017-10-31 03:45:41 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
bool KeyframeEffect::IsRunningOnCompositor() const {
|
2016-09-04 10:34:21 +03:00
|
|
|
// We consider animation is running on compositor if there is at least
|
|
|
|
// one property running on compositor.
|
|
|
|
// Animation.IsRunningOnCompotitor will return more fine grained
|
|
|
|
// information in bug 1196114.
|
|
|
|
for (const AnimationProperty& property : mProperties) {
|
|
|
|
if (property.mIsRunningOnCompositor) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::SetIsRunningOnCompositor(nsCSSPropertyID aProperty,
|
|
|
|
bool aIsRunning) {
|
2016-09-04 10:34:21 +03:00
|
|
|
MOZ_ASSERT(
|
2018-04-26 08:00:50 +03:00
|
|
|
nsCSSProps::PropHasFlags(aProperty, CSSPropFlags::CanAnimateOnCompositor),
|
2016-09-04 10:34:21 +03:00
|
|
|
"Property being animated on compositor is a recognized "
|
|
|
|
"compositor-animatable property");
|
|
|
|
for (AnimationProperty& property : mProperties) {
|
|
|
|
if (property.mProperty == aProperty) {
|
|
|
|
property.mIsRunningOnCompositor = aIsRunning;
|
|
|
|
// We currently only set a performance warning message when animations
|
|
|
|
// cannot be run on the compositor, so if this animation is running
|
|
|
|
// on the compositor we don't need a message.
|
|
|
|
if (aIsRunning) {
|
|
|
|
property.mPerformanceWarning.reset();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 00:13:01 +03:00
|
|
|
void KeyframeEffect::SetIsRunningOnCompositor(
|
|
|
|
const nsCSSPropertyIDSet& aPropertySet, bool aIsRunning) {
|
|
|
|
for (AnimationProperty& property : mProperties) {
|
|
|
|
if (aPropertySet.HasProperty(property.mProperty)) {
|
|
|
|
MOZ_ASSERT(nsCSSProps::PropHasFlags(property.mProperty,
|
|
|
|
CSSPropFlags::CanAnimateOnCompositor),
|
|
|
|
"Property being animated on compositor is a recognized "
|
|
|
|
"compositor-animatable property");
|
|
|
|
property.mIsRunningOnCompositor = aIsRunning;
|
|
|
|
// We currently only set a performance warning message when animations
|
|
|
|
// cannot be run on the compositor, so if this animation is running
|
|
|
|
// on the compositor we don't need a message.
|
|
|
|
if (aIsRunning) {
|
|
|
|
property.mPerformanceWarning.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::ResetIsRunningOnCompositor() {
|
2016-09-04 10:34:21 +03:00
|
|
|
for (AnimationProperty& property : mProperties) {
|
|
|
|
property.mIsRunningOnCompositor = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const KeyframeEffectOptions& KeyframeEffectOptionsFromUnion(
|
|
|
|
const UnrestrictedDoubleOrKeyframeEffectOptions& aOptions) {
|
|
|
|
MOZ_ASSERT(aOptions.IsKeyframeEffectOptions());
|
|
|
|
return aOptions.GetAsKeyframeEffectOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const KeyframeEffectOptions& KeyframeEffectOptionsFromUnion(
|
|
|
|
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions) {
|
|
|
|
MOZ_ASSERT(aOptions.IsKeyframeAnimationOptions());
|
|
|
|
return aOptions.GetAsKeyframeAnimationOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class OptionsType>
|
|
|
|
static KeyframeEffectParams KeyframeEffectParamsFromUnion(
|
|
|
|
const OptionsType& aOptions, CallerType aCallerType) {
|
|
|
|
KeyframeEffectParams result;
|
2017-06-13 10:09:19 +03:00
|
|
|
if (aOptions.IsUnrestrictedDouble() ||
|
2018-07-14 03:23:03 +03:00
|
|
|
// Ignore iterationComposite and composite if the corresponding pref is
|
|
|
|
// not set. The default value 'Replace' will be used instead.
|
|
|
|
!StaticPrefs::dom_animations_api_compositing_enabled()) {
|
2017-06-13 10:09:19 +03:00
|
|
|
return result;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
2017-06-13 10:09:19 +03:00
|
|
|
|
|
|
|
const KeyframeEffectOptions& options =
|
|
|
|
KeyframeEffectOptionsFromUnion(aOptions);
|
|
|
|
result.mIterationComposite = options.mIterationComposite;
|
|
|
|
result.mComposite = options.mComposite;
|
2016-09-04 10:34:21 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
Maybe<OwningAnimationTarget> KeyframeEffect::ConvertTarget(
|
2016-09-04 10:34:21 +03:00
|
|
|
const Nullable<ElementOrCSSPseudoElement>& aTarget) {
|
|
|
|
// Return value optimization.
|
|
|
|
Maybe<OwningAnimationTarget> result;
|
|
|
|
|
|
|
|
if (aTarget.IsNull()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ElementOrCSSPseudoElement& target = aTarget.Value();
|
|
|
|
MOZ_ASSERT(target.IsElement() || target.IsCSSPseudoElement(),
|
|
|
|
"Uninitialized target");
|
|
|
|
|
|
|
|
if (target.IsElement()) {
|
|
|
|
result.emplace(&target.GetAsElement());
|
|
|
|
} else {
|
2019-02-22 06:12:19 +03:00
|
|
|
RefPtr<Element> elem = target.GetAsCSSPseudoElement().Element();
|
2016-09-04 10:34:21 +03:00
|
|
|
result.emplace(elem, target.GetAsCSSPseudoElement().GetType());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-07-11 04:27:01 +03:00
|
|
|
template <class OptionsType>
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<KeyframeEffect> KeyframeEffect::ConstructKeyframeEffect(
|
2016-09-04 10:34:21 +03:00
|
|
|
const GlobalObject& aGlobal,
|
|
|
|
const Nullable<ElementOrCSSPseudoElement>& aTarget,
|
|
|
|
JS::Handle<JSObject*> aKeyframes, const OptionsType& aOptions,
|
|
|
|
ErrorResult& aRv) {
|
Bug 1414674 - Do not enter the compartment of the target window when calling KeyframeEffect and KeyframeEffectReadOnly constructor via Xray. r=bz,birtles
KeyframeEffect and KeyframeEffectReadOnly constructors can run in the caller
compartment, which is okay because the current compartment is used in the
following places and all of them are safe:
1. GlobalObject::CallerType(), that is ultimately passed to
nsDocument::IsWebAnimationsEnabled in KeyframeEffectParamsFromUnion,
to decide whether to copy mIterationComposite/mComposite to
KeyframeEffectParams.
GlobalObject::CallerType() can now be different than the target window's one,
if the caller has the system principal and the target is web content, and
in that case nsDocument::IsWebAnimationsEnabled there always returns true
while Web Animations can be disabled on web content.
honoring the mIterationComposite/mComposite properties is OK, since it just
changes the animation behavior, and this is disabled by default until
remaining spec issues are resolved.
2. GlobalObject::Context(), that is ultimately passed to
KeyframeUtils::GetKeyframesFromObject and used while extracting information
from passed-in keyframe object, with iterable/iterator protocols.
Performing that operation in the caller side is okay, since the same thing
can be done on caller, and the operation doesn't perform any GCThing
allocation on the target window global.
2018-02-17 11:21:13 +03:00
|
|
|
// We should get the document from `aGlobal` instead of the current Realm
|
|
|
|
// to make this works in Xray case.
|
|
|
|
//
|
|
|
|
// In all non-Xray cases, `aGlobal` matches the current Realm, so this
|
|
|
|
// matches the spec behavior.
|
|
|
|
//
|
|
|
|
// In Xray case, the new objects should be created using the document of
|
2018-05-07 05:08:59 +03:00
|
|
|
// the target global, but the KeyframeEffect constructors are called in the
|
|
|
|
// caller's compartment to access `aKeyframes` object.
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = AnimationUtils::GetDocumentFromGlobal(aGlobal.Get());
|
2016-09-04 10:34:21 +03:00
|
|
|
if (!doc) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimingParams timingParams =
|
|
|
|
TimingParams::FromOptionsUnion(aOptions, doc, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyframeEffectParams effectOptions =
|
2017-06-13 10:09:19 +03:00
|
|
|
KeyframeEffectParamsFromUnion(aOptions, aGlobal.CallerType());
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
Maybe<OwningAnimationTarget> target = ConvertTarget(aTarget);
|
2018-07-11 04:27:01 +03:00
|
|
|
RefPtr<KeyframeEffect> effect =
|
2018-10-16 00:38:00 +03:00
|
|
|
new KeyframeEffect(doc, target, std::move(timingParams), effectOptions);
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
effect->SetKeyframes(aGlobal.Context(), aKeyframes, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return effect.forget();
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
nsTArray<AnimationProperty> KeyframeEffect::BuildProperties(
|
|
|
|
const ComputedStyle* aStyle) {
|
2017-02-23 03:52:44 +03:00
|
|
|
MOZ_ASSERT(aStyle);
|
2016-11-07 12:01:39 +03:00
|
|
|
|
|
|
|
nsTArray<AnimationProperty> result;
|
|
|
|
// If mTarget is null, return an empty property array.
|
|
|
|
if (!mTarget) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When GetComputedKeyframeValues or GetAnimationPropertiesFromKeyframes
|
|
|
|
// calculate computed values from |mKeyframes|, they could possibly
|
|
|
|
// trigger a subsequent restyle in which we rebuild animations. If that
|
|
|
|
// happens we could find that |mKeyframes| is overwritten while it is
|
|
|
|
// being iterated over. Normally that shouldn't happen but just in case we
|
|
|
|
// make a copy of |mKeyframes| first and iterate over that instead.
|
|
|
|
auto keyframesCopy(mKeyframes);
|
|
|
|
|
2017-02-23 03:52:43 +03:00
|
|
|
result = KeyframeUtils::GetAnimationPropertiesFromKeyframes(
|
|
|
|
keyframesCopy, mTarget->mElement, aStyle, mEffectOptions.mComposite);
|
2016-11-07 12:01:39 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(SpecifiedKeyframeArraysAreEqual(mKeyframes, keyframesCopy),
|
|
|
|
"Apart from the computed offset members, the keyframes array"
|
|
|
|
" should not be modified");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mKeyframes.SwapElements(keyframesCopy);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:15:12 +03:00
|
|
|
template <typename FrameEnumFunc>
|
|
|
|
static void EnumerateContinuationsOrIBSplitSiblings(nsIFrame* aFrame,
|
|
|
|
FrameEnumFunc&& aFunc) {
|
|
|
|
while (aFrame) {
|
|
|
|
aFunc(aFrame);
|
|
|
|
aFrame = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::UpdateTargetRegistration() {
|
2016-09-04 10:34:21 +03:00
|
|
|
if (!mTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isRelevant = mAnimation && mAnimation->IsRelevant();
|
|
|
|
|
|
|
|
// Animation::IsRelevant() returns a cached value. It only updates when
|
|
|
|
// something calls Animation::UpdateRelevance. Whenever our timing changes,
|
|
|
|
// we should be notifying our Animation before calling this, so
|
|
|
|
// Animation::IsRelevant() should be up-to-date by the time we get here.
|
2019-05-20 08:55:52 +03:00
|
|
|
MOZ_ASSERT(isRelevant ==
|
|
|
|
((IsCurrent() || IsInEffect()) && mAnimation &&
|
|
|
|
mAnimation->ReplaceState() != AnimationReplaceState::Removed),
|
2016-09-04 10:34:21 +03:00
|
|
|
"Out of date Animation::IsRelevant value");
|
|
|
|
|
2017-07-05 04:29:58 +03:00
|
|
|
if (isRelevant && !mInEffectSet) {
|
2016-09-04 10:34:21 +03:00
|
|
|
EffectSet* effectSet = EffectSet::GetOrCreateEffectSet(
|
|
|
|
mTarget->mElement, mTarget->mPseudoType);
|
|
|
|
effectSet->AddEffect(*this);
|
2017-07-05 04:29:58 +03:00
|
|
|
mInEffectSet = true;
|
2017-06-20 09:42:26 +03:00
|
|
|
UpdateEffectSet(effectSet);
|
2018-05-23 12:15:12 +03:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
EnumerateContinuationsOrIBSplitSiblings(
|
|
|
|
frame, [](nsIFrame* aFrame) { aFrame->MarkNeedsDisplayItemRebuild(); });
|
2017-07-05 04:29:58 +03:00
|
|
|
} else if (!isRelevant && mInEffectSet) {
|
2016-09-04 10:34:21 +03:00
|
|
|
UnregisterTarget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::UnregisterTarget() {
|
2017-07-05 04:29:58 +03:00
|
|
|
if (!mInEffectSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
EffectSet* effectSet =
|
|
|
|
EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType);
|
2017-07-05 04:29:58 +03:00
|
|
|
MOZ_ASSERT(effectSet,
|
|
|
|
"If mInEffectSet is true, there must be an EffectSet"
|
|
|
|
" on the target element");
|
|
|
|
mInEffectSet = false;
|
2016-09-04 10:34:21 +03:00
|
|
|
if (effectSet) {
|
|
|
|
effectSet->RemoveEffect(*this);
|
2017-05-16 14:11:04 +03:00
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
if (effectSet->IsEmpty()) {
|
|
|
|
EffectSet::DestroyEffectSet(mTarget->mElement, mTarget->mPseudoType);
|
|
|
|
}
|
|
|
|
}
|
2018-05-23 12:15:12 +03:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
EnumerateContinuationsOrIBSplitSiblings(
|
|
|
|
frame, [](nsIFrame* aFrame) { aFrame->MarkNeedsDisplayItemRebuild(); });
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::RequestRestyle(
|
|
|
|
EffectCompositor::RestyleType aRestyleType) {
|
2017-03-13 18:09:49 +03:00
|
|
|
if (!mTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsPresContext* presContext =
|
|
|
|
nsContentUtils::GetContextForContent(mTarget->mElement);
|
|
|
|
if (presContext && mAnimation) {
|
2016-09-04 10:34:21 +03:00
|
|
|
presContext->EffectCompositor()->RequestRestyle(
|
|
|
|
mTarget->mElement, mTarget->mPseudoType, aRestyleType,
|
|
|
|
mAnimation->CascadeLevel());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 09:08:05 +03:00
|
|
|
already_AddRefed<ComputedStyle> KeyframeEffect::GetTargetComputedStyle(
|
|
|
|
Flush aFlushType) const {
|
2018-01-23 17:49:00 +03:00
|
|
|
if (!GetRenderedDocument()) {
|
2016-09-04 10:34:21 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mTarget,
|
2018-01-23 17:49:00 +03:00
|
|
|
"Should only have a document when we have a target element");
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* pseudo =
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyle::IsPseudoElement(mTarget->mPseudoType)
|
2016-09-04 10:34:21 +03:00
|
|
|
? nsCSSPseudoElements::GetPseudoAtom(mTarget->mPseudoType)
|
|
|
|
: nullptr;
|
2017-01-16 11:41:24 +03:00
|
|
|
|
2018-05-02 00:17:41 +03:00
|
|
|
OwningAnimationTarget kungfuDeathGrip(mTarget->mElement,
|
|
|
|
mTarget->mPseudoType);
|
|
|
|
|
2019-02-15 09:08:05 +03:00
|
|
|
return aFlushType == Flush::Style
|
|
|
|
? nsComputedDOMStyle::GetComputedStyle(mTarget->mElement, pseudo)
|
|
|
|
: nsComputedDOMStyle::GetComputedStyleNoFlush(mTarget->mElement,
|
|
|
|
pseudo);
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void DumpAnimationProperties(
|
|
|
|
nsTArray<AnimationProperty>& aAnimationProperties) {
|
|
|
|
for (auto& p : aAnimationProperties) {
|
2018-07-30 19:04:05 +03:00
|
|
|
printf("%s\n", nsCString(nsCSSProps::GetStringValue(p.mProperty)).get());
|
2016-09-04 10:34:21 +03:00
|
|
|
for (auto& s : p.mSegments) {
|
|
|
|
nsString fromValue, toValue;
|
2017-02-09 06:33:17 +03:00
|
|
|
s.mFromValue.SerializeSpecifiedValue(p.mProperty, fromValue);
|
|
|
|
s.mToValue.SerializeSpecifiedValue(p.mProperty, toValue);
|
2016-09-04 10:34:21 +03:00
|
|
|
printf(" %f..%f: %s..%s\n", s.mFromKey, s.mToKey,
|
|
|
|
NS_ConvertUTF16toUTF8(fromValue).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(toValue).get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<KeyframeEffect> KeyframeEffect::Constructor(
|
2016-09-04 10:34:21 +03:00
|
|
|
const GlobalObject& aGlobal,
|
|
|
|
const Nullable<ElementOrCSSPseudoElement>& aTarget,
|
|
|
|
JS::Handle<JSObject*> aKeyframes,
|
|
|
|
const UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
|
|
|
|
ErrorResult& aRv) {
|
2018-07-11 04:27:01 +03:00
|
|
|
return ConstructKeyframeEffect(aGlobal, aTarget, aKeyframes, aOptions, aRv);
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<KeyframeEffect> KeyframeEffect::Constructor(
|
2018-05-07 05:08:59 +03:00
|
|
|
const GlobalObject& aGlobal,
|
|
|
|
const Nullable<ElementOrCSSPseudoElement>& aTarget,
|
|
|
|
JS::Handle<JSObject*> aKeyframes,
|
|
|
|
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
|
|
|
|
ErrorResult& aRv) {
|
2018-07-11 04:27:01 +03:00
|
|
|
return ConstructKeyframeEffect(aGlobal, aTarget, aKeyframes, aOptions, aRv);
|
2016-10-28 10:41:08 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<KeyframeEffect> KeyframeEffect::Constructor(
|
2018-07-11 04:27:56 +03:00
|
|
|
const GlobalObject& aGlobal, KeyframeEffect& aSource, ErrorResult& aRv) {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = AnimationUtils::GetCurrentRealmDocument(aGlobal.Context());
|
2018-07-11 04:27:56 +03:00
|
|
|
if (!doc) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new KeyframeEffect object with aSource's target,
|
|
|
|
// iteration composite operation, composite operation, and spacing mode.
|
|
|
|
// The constructor creates a new AnimationEffect 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<KeyframeEffect> effect = new KeyframeEffect(
|
2018-10-16 00:38:00 +03:00
|
|
|
doc, aSource.mTarget, TimingParams(aSource.SpecifiedTiming()),
|
2018-07-11 04:27:56 +03:00
|
|
|
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;
|
|
|
|
|
|
|
|
// Copy aSource's keyframes and animation properties.
|
|
|
|
// Note: We don't call SetKeyframes directly, which might revise the
|
|
|
|
// computed offsets and rebuild the animation properties.
|
|
|
|
effect->mKeyframes = aSource.mKeyframes;
|
|
|
|
effect->mProperties = aSource.mProperties;
|
|
|
|
return effect.forget();
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::GetTarget(
|
|
|
|
Nullable<OwningElementOrCSSPseudoElement>& aRv) const {
|
2016-09-04 10:34:21 +03:00
|
|
|
if (!mTarget) {
|
|
|
|
aRv.SetNull();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mTarget->mPseudoType) {
|
2019-02-19 16:44:33 +03:00
|
|
|
case PseudoStyleType::before:
|
|
|
|
case PseudoStyleType::after:
|
2019-03-26 07:48:26 +03:00
|
|
|
case PseudoStyleType::marker:
|
2016-09-04 10:34:21 +03:00
|
|
|
aRv.SetValue().SetAsCSSPseudoElement() =
|
|
|
|
CSSPseudoElement::GetCSSPseudoElement(mTarget->mElement,
|
|
|
|
mTarget->mPseudoType);
|
|
|
|
break;
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
case PseudoStyleType::NotPseudo:
|
2016-09-04 10:34:21 +03:00
|
|
|
aRv.SetValue().SetAsElement() = mTarget->mElement;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Animation of unsupported pseudo-type");
|
2016-09-04 10:34:21 +03:00
|
|
|
aRv.SetNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::SetTarget(
|
|
|
|
const Nullable<ElementOrCSSPseudoElement>& aTarget) {
|
2018-05-07 04:48:48 +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);
|
|
|
|
|
|
|
|
nsAutoAnimationMutationBatch mb(mTarget->mElement->OwnerDoc());
|
|
|
|
if (mAnimation) {
|
|
|
|
nsNodeUtils::AnimationRemoved(mAnimation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mTarget = newTarget;
|
|
|
|
|
|
|
|
if (mTarget) {
|
|
|
|
UpdateTargetRegistration();
|
2019-02-15 09:08:05 +03:00
|
|
|
RefPtr<ComputedStyle> computedStyle = GetTargetComputedStyle(Flush::None);
|
2018-05-07 04:48:48 +03:00
|
|
|
if (computedStyle) {
|
|
|
|
UpdateProperties(computedStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
|
|
|
|
|
|
|
nsAutoAnimationMutationBatch mb(mTarget->mElement->OwnerDoc());
|
|
|
|
if (mAnimation) {
|
|
|
|
nsNodeUtils::AnimationAdded(mAnimation);
|
2018-07-12 11:05:50 +03:00
|
|
|
mAnimation->ReschedulePendingTasks();
|
2018-05-07 04:48:48 +03:00
|
|
|
}
|
|
|
|
}
|
2019-05-20 08:48:29 +03:00
|
|
|
|
|
|
|
if (mAnimation) {
|
|
|
|
mAnimation->NotifyEffectTargetUpdated();
|
|
|
|
}
|
2018-05-07 04:48:48 +03:00
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
static void CreatePropertyValue(
|
|
|
|
nsCSSPropertyID aProperty, float aOffset,
|
|
|
|
const Maybe<ComputedTimingFunction>& aTimingFunction,
|
2016-12-04 02:07:40 +03:00
|
|
|
const AnimationValue& aValue, dom::CompositeOperation aComposite,
|
2016-09-04 10:34:21 +03:00
|
|
|
AnimationPropertyValueDetails& aResult) {
|
|
|
|
aResult.mOffset = aOffset;
|
|
|
|
|
2016-12-04 02:07:39 +03:00
|
|
|
if (!aValue.IsNull()) {
|
|
|
|
nsString stringValue;
|
2017-02-09 06:33:17 +03:00
|
|
|
aValue.SerializeSpecifiedValue(aProperty, stringValue);
|
2016-12-04 02:07:39 +03:00
|
|
|
aResult.mValue.Construct(stringValue);
|
|
|
|
}
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
if (aTimingFunction) {
|
|
|
|
aResult.mEasing.Construct();
|
|
|
|
aTimingFunction->AppendToString(aResult.mEasing.Value());
|
|
|
|
} else {
|
|
|
|
aResult.mEasing.Construct(NS_LITERAL_STRING("linear"));
|
|
|
|
}
|
|
|
|
|
2016-12-04 02:07:40 +03:00
|
|
|
aResult.mComposite = aComposite;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::GetProperties(
|
2016-09-04 10:34:21 +03:00
|
|
|
nsTArray<AnimationPropertyDetails>& aProperties, ErrorResult& aRv) const {
|
|
|
|
for (const AnimationProperty& property : mProperties) {
|
|
|
|
AnimationPropertyDetails propertyDetails;
|
|
|
|
propertyDetails.mProperty =
|
|
|
|
NS_ConvertASCIItoUTF16(nsCSSProps::GetStringValue(property.mProperty));
|
|
|
|
propertyDetails.mRunningOnCompositor = property.mIsRunningOnCompositor;
|
|
|
|
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAutoString localizedString;
|
2016-09-04 10:34:21 +03:00
|
|
|
if (property.mPerformanceWarning &&
|
|
|
|
property.mPerformanceWarning->ToLocalizedString(localizedString)) {
|
|
|
|
propertyDetails.mWarning.Construct(localizedString);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!propertyDetails.mValues.SetCapacity(property.mSegments.Length(),
|
|
|
|
mozilla::fallible)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t segmentIdx = 0, segmentLen = property.mSegments.Length();
|
|
|
|
segmentIdx < segmentLen; segmentIdx++) {
|
|
|
|
const AnimationPropertySegment& segment = property.mSegments[segmentIdx];
|
|
|
|
|
|
|
|
binding_detail::FastAnimationPropertyValueDetails fromValue;
|
|
|
|
CreatePropertyValue(property.mProperty, segment.mFromKey,
|
2017-02-08 11:15:18 +03:00
|
|
|
segment.mTimingFunction, segment.mFromValue,
|
2016-12-04 02:07:40 +03:00
|
|
|
segment.mFromComposite, fromValue);
|
2016-09-04 10:34:21 +03:00
|
|
|
// We don't apply timing functions for zero-length segments, so
|
|
|
|
// don't return one here.
|
|
|
|
if (segment.mFromKey == segment.mToKey) {
|
|
|
|
fromValue.mEasing.Reset();
|
|
|
|
}
|
|
|
|
// The following won't fail since we have already allocated the capacity
|
|
|
|
// above.
|
|
|
|
propertyDetails.mValues.AppendElement(fromValue, mozilla::fallible);
|
|
|
|
|
|
|
|
// Normally we can ignore the to-value for this segment since it is
|
|
|
|
// identical to the from-value from the next segment. However, we need
|
|
|
|
// to add it if either:
|
|
|
|
// a) this is the last segment, or
|
|
|
|
// b) the next segment's from-value differs.
|
|
|
|
if (segmentIdx == segmentLen - 1 ||
|
2017-07-24 04:25:13 +03:00
|
|
|
property.mSegments[segmentIdx + 1].mFromValue != segment.mToValue) {
|
2016-09-04 10:34:21 +03:00
|
|
|
binding_detail::FastAnimationPropertyValueDetails toValue;
|
|
|
|
CreatePropertyValue(property.mProperty, segment.mToKey, Nothing(),
|
2016-12-04 02:07:40 +03:00
|
|
|
segment.mToValue, segment.mToComposite, toValue);
|
2016-09-04 10:34:21 +03:00
|
|
|
// It doesn't really make sense to have a timing function on the
|
|
|
|
// last property value or before a sudden jump so we just drop the
|
|
|
|
// easing property altogether.
|
|
|
|
toValue.mEasing.Reset();
|
|
|
|
propertyDetails.mValues.AppendElement(toValue, mozilla::fallible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aProperties.AppendElement(propertyDetails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::GetKeyframes(JSContext*& aCx, nsTArray<JSObject*>& aResult,
|
2019-01-08 09:42:17 +03:00
|
|
|
ErrorResult& aRv) const {
|
2016-09-04 10:34:21 +03:00
|
|
|
MOZ_ASSERT(aResult.IsEmpty());
|
|
|
|
MOZ_ASSERT(!aRv.Failed());
|
|
|
|
|
|
|
|
if (!aResult.SetCapacity(mKeyframes.Length(), mozilla::fallible)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-21 06:35:35 +03:00
|
|
|
bool isCSSAnimation = mAnimation && mAnimation->AsCSSAnimation();
|
|
|
|
|
|
|
|
// For Servo, when we have CSS Animation @keyframes with variables, we convert
|
|
|
|
// shorthands to longhands if needed, and store a reference to the unparsed
|
|
|
|
// value. When it comes time to serialize, however, what do you serialize for
|
|
|
|
// a longhand that comes from a variable reference in a shorthand? Servo says,
|
|
|
|
// "an empty string" which is not particularly helpful.
|
|
|
|
//
|
|
|
|
// We should just store shorthands as-is (bug 1391537) and then return the
|
|
|
|
// variable references, but for now, since we don't do that, and in order to
|
|
|
|
// be consistent with Gecko, we just expand the variables (assuming we have
|
2018-03-23 16:49:21 +03:00
|
|
|
// enough context to do so). For that we need to grab the ComputedStyle so we
|
2017-08-21 06:35:35 +03:00
|
|
|
// know what custom property values to provide.
|
2018-03-22 16:49:21 +03:00
|
|
|
RefPtr<ComputedStyle> computedStyle;
|
2018-03-25 20:42:10 +03:00
|
|
|
if (isCSSAnimation) {
|
2017-08-21 06:35:35 +03:00
|
|
|
// The following will flush style but that's ok since if you update
|
|
|
|
// a variable's computed value, you expect to see that updated value in the
|
|
|
|
// result of getKeyframes().
|
|
|
|
//
|
|
|
|
// If we don't have a target, the following will return null. In that case
|
|
|
|
// we might end up returning variables as-is or empty string. That should be
|
|
|
|
// acceptable however, since such a case is rare and this is only
|
|
|
|
// short-term (and unshipped) behavior until bug 1391537 is fixed.
|
2019-02-15 09:08:05 +03:00
|
|
|
computedStyle = GetTargetComputedStyle(Flush::Style);
|
2017-08-21 06:35:35 +03:00
|
|
|
}
|
2017-04-06 04:34:51 +03:00
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
for (const Keyframe& keyframe : mKeyframes) {
|
|
|
|
// Set up a dictionary object for the explicit members
|
|
|
|
BaseComputedKeyframe keyframeDict;
|
|
|
|
if (keyframe.mOffset) {
|
|
|
|
keyframeDict.mOffset.SetValue(keyframe.mOffset.value());
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(keyframe.mComputedOffset != Keyframe::kComputedOffsetNotSet,
|
|
|
|
"Invalid computed offset");
|
|
|
|
keyframeDict.mComputedOffset.Construct(keyframe.mComputedOffset);
|
|
|
|
if (keyframe.mTimingFunction) {
|
|
|
|
keyframeDict.mEasing.Truncate();
|
|
|
|
keyframe.mTimingFunction.ref().AppendToString(keyframeDict.mEasing);
|
|
|
|
} // else if null, leave easing as its default "linear".
|
|
|
|
|
2018-08-16 19:24:52 +03:00
|
|
|
keyframeDict.mComposite = keyframe.mComposite;
|
2016-12-04 02:07:41 +03:00
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
JS::Rooted<JS::Value> keyframeJSValue(aCx);
|
|
|
|
if (!ToJSValue(aCx, keyframeDict, &keyframeJSValue)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-27 10:49:21 +03:00
|
|
|
RefPtr<RawServoDeclarationBlock> customProperties;
|
|
|
|
// A workaround for CSS Animations in servo backend, custom properties in
|
|
|
|
// keyframe are stored in a servo's declaration block. Find the declaration
|
|
|
|
// block to resolve CSS variables in the keyframe.
|
|
|
|
// This workaround will be solved by bug 1391537.
|
2018-03-25 20:42:10 +03:00
|
|
|
if (isCSSAnimation) {
|
2017-09-27 10:49:21 +03:00
|
|
|
for (const PropertyValuePair& propertyValue : keyframe.mPropertyValues) {
|
|
|
|
if (propertyValue.mProperty ==
|
|
|
|
nsCSSPropertyID::eCSSPropertyExtra_variable) {
|
|
|
|
customProperties = propertyValue.mServoDeclarationBlock;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
JS::Rooted<JSObject*> keyframeObject(aCx, &keyframeJSValue.toObject());
|
|
|
|
for (const PropertyValuePair& propertyValue : keyframe.mPropertyValues) {
|
|
|
|
nsAutoString stringValue;
|
2018-03-25 20:42:10 +03:00
|
|
|
// Don't serialize the custom properties for this keyframe.
|
|
|
|
if (propertyValue.mProperty ==
|
|
|
|
nsCSSPropertyID::eCSSPropertyExtra_variable) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (propertyValue.mServoDeclarationBlock) {
|
|
|
|
Servo_DeclarationBlock_SerializeOneValue(
|
|
|
|
propertyValue.mServoDeclarationBlock, propertyValue.mProperty,
|
|
|
|
&stringValue, computedStyle, customProperties);
|
2016-09-16 03:26:48 +03:00
|
|
|
} else {
|
2018-03-25 20:42:10 +03:00
|
|
|
RawServoAnimationValue* value =
|
2018-12-06 23:57:12 +03:00
|
|
|
mBaseValues.GetWeak(propertyValue.mProperty);
|
2018-03-25 20:42:10 +03:00
|
|
|
|
|
|
|
if (value) {
|
|
|
|
Servo_AnimationValue_Serialize(value, propertyValue.mProperty,
|
|
|
|
&stringValue);
|
|
|
|
}
|
2016-09-16 03:26:48 +03:00
|
|
|
}
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2016-11-22 14:18:18 +03:00
|
|
|
const char* name = nsCSSProps::PropertyIDLName(propertyValue.mProperty);
|
2016-09-04 10:34:21 +03:00
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
if (!ToJSValue(aCx, stringValue, &value) ||
|
|
|
|
!JS_DefineProperty(aCx, keyframeObject, name, value,
|
|
|
|
JSPROP_ENUMERATE)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.AppendElement(keyframeObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ const TimeDuration
|
2018-05-07 05:08:59 +03:00
|
|
|
KeyframeEffect::OverflowRegionRefreshInterval() {
|
2016-09-04 10:34:21 +03:00
|
|
|
// The amount of time we can wait between updating throttled animations
|
|
|
|
// on the main thread that influence the overflow region.
|
|
|
|
static const TimeDuration kOverflowRegionRefreshInterval =
|
|
|
|
TimeDuration::FromMilliseconds(200);
|
|
|
|
|
|
|
|
return kOverflowRegionRefreshInterval;
|
|
|
|
}
|
|
|
|
|
2018-06-25 05:51:05 +03:00
|
|
|
bool KeyframeEffect::CanThrottleIfNotVisible(nsIFrame& aFrame) const {
|
2018-06-25 12:23:59 +03:00
|
|
|
// Unless we are newly in-effect, we can throttle the animation if the
|
|
|
|
// animation is paint only and the target frame is out of view or the document
|
|
|
|
// is in background tabs.
|
2018-06-25 05:51:05 +03:00
|
|
|
if (!mInEffectOnLastAnimationTimingUpdate || !CanIgnoreIfNotVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-25 12:23:59 +03:00
|
|
|
|
2019-03-29 18:12:47 +03:00
|
|
|
PresShell* presShell = GetPresShell();
|
2018-06-25 05:51:05 +03:00
|
|
|
if (presShell && !presShell->IsActive()) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-06-25 12:23:59 +03:00
|
|
|
|
2018-06-25 05:51:05 +03:00
|
|
|
const bool isVisibilityHidden =
|
|
|
|
!aFrame.IsVisibleOrMayHaveVisibleDescendants();
|
|
|
|
if ((!isVisibilityHidden || HasVisibilityChange()) &&
|
|
|
|
!aFrame.IsScrolledOutOfView()) {
|
|
|
|
return false;
|
2018-06-25 05:51:05 +03:00
|
|
|
}
|
2018-06-25 05:51:05 +03:00
|
|
|
|
|
|
|
// If there are no overflow change hints, we don't need to worry about
|
|
|
|
// unthrottling the animation periodically to update scrollbar positions for
|
|
|
|
// the overflow region.
|
|
|
|
if (!HasPropertiesThatMightAffectOverflow()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't throttle finite animations since the animation might suddenly
|
|
|
|
// come into view and if it was throttled it will be out-of-sync.
|
|
|
|
if (HasFiniteActiveDuration()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isVisibilityHidden ? CanThrottleOverflowChangesInScrollable(aFrame)
|
|
|
|
: CanThrottleOverflowChanges(aFrame);
|
2018-06-25 05:51:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool KeyframeEffect::CanThrottle() const {
|
|
|
|
// Unthrottle if we are not in effect or current. This will be the case when
|
|
|
|
// our owning animation has finished, is idle, or when we are in the delay
|
|
|
|
// phase (but without a backwards fill). In each case the computed progress
|
|
|
|
// value produced on each tick will be the same so we will skip requesting
|
|
|
|
// unnecessary restyles in NotifyAnimationTimingUpdated. Any calls we *do* get
|
|
|
|
// here will be because of a change in state (e.g. we are newly finished or
|
|
|
|
// newly no longer in effect) in which case we shouldn't throttle the sample.
|
|
|
|
if (!IsInEffect() || !IsCurrent()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame = GetStyleFrame();
|
|
|
|
if (!frame) {
|
|
|
|
// There are two possible cases here.
|
|
|
|
// a) No target element
|
|
|
|
// b) The target element has no frame, e.g. because it is in a display:none
|
|
|
|
// subtree.
|
|
|
|
// In either case we can throttle the animation because there is no
|
|
|
|
// need to update on the main thread.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CanThrottleIfNotVisible(*frame)) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2018-11-07 00:02:18 +03:00
|
|
|
EffectSet* effectSet = nullptr;
|
2018-11-07 00:01:50 +03:00
|
|
|
for (const AnimationProperty& property : mProperties) {
|
|
|
|
if (!property.mIsRunningOnCompositor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-07 00:02:18 +03:00
|
|
|
MOZ_ASSERT(nsCSSPropertyIDSet::CompositorAnimatables().HasProperty(
|
|
|
|
property.mProperty),
|
|
|
|
"The property should be able to run on the compositor");
|
2018-11-07 00:02:06 +03:00
|
|
|
if (!effectSet) {
|
|
|
|
effectSet =
|
|
|
|
EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType);
|
|
|
|
MOZ_ASSERT(effectSet,
|
|
|
|
"CanThrottle should be called on an effect "
|
|
|
|
"associated with a target element");
|
|
|
|
}
|
2018-11-13 13:17:44 +03:00
|
|
|
MOZ_ASSERT(HasEffectiveAnimationOfProperty(property.mProperty, *effectSet),
|
|
|
|
"There should be an effective animation of the property while "
|
|
|
|
"it is marked as being run on the compositor");
|
|
|
|
|
2018-11-07 00:02:18 +03:00
|
|
|
DisplayItemType displayItemType =
|
|
|
|
LayerAnimationInfo::GetDisplayItemTypeForProperty(property.mProperty);
|
|
|
|
|
2018-05-08 23:53:47 +03:00
|
|
|
// Note that AnimationInfo::GetGenarationFromFrame() is supposed to work
|
|
|
|
// with the primary frame instead of the style frame.
|
2018-04-06 17:06:54 +03:00
|
|
|
Maybe<uint64_t> generation = layers::AnimationInfo::GetGenerationFromFrame(
|
2018-11-07 00:02:18 +03:00
|
|
|
GetPrimaryFrame(), displayItemType);
|
2018-04-06 17:06:54 +03:00
|
|
|
// Unthrottle if the animation needs to be brought up to date
|
|
|
|
if (!generation || effectSet->GetAnimationGeneration() != *generation) {
|
2016-09-04 10:34:21 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is a transform animation that affects the overflow region,
|
|
|
|
// we should unthrottle the animation periodically.
|
2018-06-25 03:12:21 +03:00
|
|
|
if (HasPropertiesThatMightAffectOverflow() &&
|
|
|
|
!CanThrottleOverflowChangesInScrollable(*frame)) {
|
2016-09-04 10:34:21 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-25 03:12:21 +03:00
|
|
|
bool KeyframeEffect::CanThrottleOverflowChanges(const nsIFrame& aFrame) const {
|
2017-02-27 05:34:48 +03:00
|
|
|
TimeStamp now = aFrame.PresContext()->RefreshDriver()->MostRecentRefresh();
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
EffectSet* effectSet =
|
|
|
|
EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType);
|
2018-06-25 03:12:21 +03:00
|
|
|
MOZ_ASSERT(effectSet,
|
|
|
|
"CanOverflowTransformChanges is expected to be called"
|
2016-09-04 10:34:21 +03:00
|
|
|
" on an effect in an effect set");
|
2018-06-25 03:12:21 +03:00
|
|
|
MOZ_ASSERT(mAnimation,
|
|
|
|
"CanOverflowTransformChanges is expected to be called"
|
2016-09-04 10:34:21 +03:00
|
|
|
" on an effect with a parent animation");
|
2018-06-25 03:12:21 +03:00
|
|
|
TimeStamp lastSyncTime = effectSet->LastOverflowAnimationSyncTime();
|
2016-09-04 10:34:21 +03:00
|
|
|
// If this animation can cause overflow, we can throttle some of the ticks.
|
2018-01-17 23:44:00 +03:00
|
|
|
return (!lastSyncTime.IsNull() &&
|
|
|
|
(now - lastSyncTime) < OverflowRegionRefreshInterval());
|
|
|
|
}
|
|
|
|
|
2018-06-25 03:12:21 +03:00
|
|
|
bool KeyframeEffect::CanThrottleOverflowChangesInScrollable(
|
|
|
|
nsIFrame& aFrame) const {
|
2018-02-07 04:46:15 +03:00
|
|
|
// If the target element is not associated with any documents, we don't care
|
|
|
|
// it.
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = GetRenderedDocument();
|
2018-02-07 04:46:15 +03:00
|
|
|
if (!doc) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasIntersectionObservers = doc->HasIntersectionObservers();
|
|
|
|
|
2018-01-17 23:44:00 +03:00
|
|
|
// If we know that the animation cannot cause overflow,
|
|
|
|
// we can just disable flushes for this animation.
|
|
|
|
|
2018-02-07 04:46:15 +03:00
|
|
|
// If we don't show scrollbars and have no intersection observers, we don't
|
|
|
|
// care about overflow.
|
|
|
|
if (LookAndFeel::GetInt(LookAndFeel::eIntID_ShowHideScrollbars) == 0 &&
|
|
|
|
!hasIntersectionObservers) {
|
2018-01-17 23:44:00 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-25 03:12:21 +03:00
|
|
|
if (CanThrottleOverflowChanges(aFrame)) {
|
2016-09-04 10:34:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-07 04:46:15 +03:00
|
|
|
// If we have any intersection observers, we unthrottle this transform
|
|
|
|
// animation periodically.
|
|
|
|
if (hasIntersectionObservers) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
// If the nearest scrollable ancestor has overflow:hidden,
|
|
|
|
// we don't care about overflow.
|
|
|
|
nsIScrollableFrame* scrollable =
|
|
|
|
nsLayoutUtils::GetNearestScrollableFrame(&aFrame);
|
|
|
|
if (!scrollable) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-01 09:14:26 +03:00
|
|
|
ScrollStyles ss = scrollable->GetScrollStyles();
|
2018-12-11 03:50:32 +03:00
|
|
|
if (ss.mVertical == StyleOverflow::Hidden &&
|
|
|
|
ss.mHorizontal == StyleOverflow::Hidden &&
|
2016-09-04 10:34:21 +03:00
|
|
|
scrollable->GetLogicalScrollPosition() == nsPoint(0, 0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
nsIFrame* KeyframeEffect::GetStyleFrame() const {
|
2018-05-08 23:53:47 +03:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
if (!frame) {
|
2016-09-04 10:34:21 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-08 23:53:47 +03:00
|
|
|
return nsLayoutUtils::GetStyleFrame(frame);
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
nsIFrame* KeyframeEffect::GetPrimaryFrame() const {
|
2018-05-08 23:53:47 +03:00
|
|
|
nsIFrame* frame = nullptr;
|
|
|
|
if (!mTarget) {
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
if (mTarget->mPseudoType == PseudoStyleType::before) {
|
2017-04-19 13:53:57 +03:00
|
|
|
frame = nsLayoutUtils::GetBeforeFrame(mTarget->mElement);
|
2019-02-19 16:44:33 +03:00
|
|
|
} else if (mTarget->mPseudoType == PseudoStyleType::after) {
|
2017-04-19 13:53:57 +03:00
|
|
|
frame = nsLayoutUtils::GetAfterFrame(mTarget->mElement);
|
2019-03-26 07:48:26 +03:00
|
|
|
} else if (mTarget->mPseudoType == PseudoStyleType::marker) {
|
|
|
|
frame = nsLayoutUtils::GetMarkerFrame(mTarget->mElement);
|
2016-09-04 10:34:21 +03:00
|
|
|
} else {
|
2017-04-19 13:53:57 +03:00
|
|
|
frame = mTarget->mElement->GetPrimaryFrame();
|
2019-02-19 16:44:33 +03:00
|
|
|
MOZ_ASSERT(mTarget->mPseudoType == PseudoStyleType::NotPseudo,
|
2016-09-04 10:34:21 +03:00
|
|
|
"unknown mTarget->mPseudoType");
|
|
|
|
}
|
2017-04-19 13:53:57 +03:00
|
|
|
|
2018-05-08 23:53:47 +03:00
|
|
|
return frame;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* KeyframeEffect::GetRenderedDocument() const {
|
2016-09-04 10:34:21 +03:00
|
|
|
if (!mTarget) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mTarget->mElement->GetComposedDoc();
|
|
|
|
}
|
|
|
|
|
2019-03-29 18:12:47 +03:00
|
|
|
PresShell* KeyframeEffect::GetPresShell() const {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = GetRenderedDocument();
|
2016-09-04 10:34:21 +03:00
|
|
|
if (!doc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-03-29 18:12:47 +03:00
|
|
|
return doc->GetPresShell();
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
bool KeyframeEffect::IsGeometricProperty(const nsCSSPropertyID aProperty) {
|
2016-12-02 03:00:05 +03:00
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"Property should be a longhand property");
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
switch (aProperty) {
|
|
|
|
case eCSSProperty_bottom:
|
|
|
|
case eCSSProperty_height:
|
|
|
|
case eCSSProperty_left:
|
2016-12-02 03:00:05 +03:00
|
|
|
case eCSSProperty_margin_bottom:
|
|
|
|
case eCSSProperty_margin_left:
|
|
|
|
case eCSSProperty_margin_right:
|
|
|
|
case eCSSProperty_margin_top:
|
|
|
|
case eCSSProperty_padding_bottom:
|
|
|
|
case eCSSProperty_padding_left:
|
|
|
|
case eCSSProperty_padding_right:
|
|
|
|
case eCSSProperty_padding_top:
|
2016-09-04 10:34:21 +03:00
|
|
|
case eCSSProperty_right:
|
|
|
|
case eCSSProperty_top:
|
|
|
|
case eCSSProperty_width:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
bool KeyframeEffect::CanAnimateTransformOnCompositor(
|
2016-09-04 10:34:21 +03:00
|
|
|
const nsIFrame* aFrame,
|
2018-11-22 07:01:10 +03:00
|
|
|
AnimationPerformanceWarning::Type& aPerformanceWarning /* out */) {
|
2019-03-18 07:10:49 +03:00
|
|
|
// In some cases, such as when we are simply collecting all the compositor
|
|
|
|
// animations regardless of the frame on which they run in order to calculate
|
|
|
|
// change hints, |aFrame| will be the style frame. However, even in that case
|
|
|
|
// we should look at the primary frame since that is where the transform will
|
|
|
|
// be applied.
|
|
|
|
const nsIFrame* primaryFrame =
|
|
|
|
nsLayoutUtils::GetPrimaryFrameFromStyleFrame(aFrame);
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
// Disallow OMTA for preserve-3d transform. Note that we check the style
|
|
|
|
// property rather than Extend3DContext() since that can recurse back into
|
|
|
|
// this function via HasOpacity(). See bug 779598.
|
2019-03-18 07:10:49 +03:00
|
|
|
if (primaryFrame->Combines3DTransformWithAncestors() ||
|
|
|
|
primaryFrame->StyleDisplay()->mTransformStyle ==
|
2016-09-04 10:34:21 +03:00
|
|
|
NS_STYLE_TRANSFORM_STYLE_PRESERVE_3D) {
|
|
|
|
aPerformanceWarning =
|
|
|
|
AnimationPerformanceWarning::Type::TransformPreserve3D;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Note that testing BackfaceIsHidden() is not a sufficient test for
|
|
|
|
// what we need for animating backface-visibility correctly if we
|
|
|
|
// remove the above test for Extend3DContext(); that would require
|
|
|
|
// looking at backface-visibility on descendants as well. See bug 1186204.
|
2019-03-18 07:10:49 +03:00
|
|
|
if (primaryFrame->BackfaceIsHidden()) {
|
2016-09-04 10:34:21 +03:00
|
|
|
aPerformanceWarning =
|
|
|
|
AnimationPerformanceWarning::Type::TransformBackfaceVisibilityHidden;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Async 'transform' animations of aFrames with SVG transforms is not
|
|
|
|
// supported. See bug 779599.
|
2019-03-18 07:10:49 +03:00
|
|
|
if (primaryFrame->IsSVGTransformed()) {
|
2016-09-04 10:34:21 +03:00
|
|
|
aPerformanceWarning = AnimationPerformanceWarning::Type::TransformSVG;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
bool KeyframeEffect::ShouldBlockAsyncTransformAnimations(
|
2016-09-04 10:34:21 +03:00
|
|
|
const nsIFrame* aFrame,
|
2018-11-22 07:01:10 +03:00
|
|
|
AnimationPerformanceWarning::Type& aPerformanceWarning /* out */) const {
|
2016-10-05 08:42:56 +03:00
|
|
|
EffectSet* effectSet =
|
|
|
|
EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType);
|
2016-09-04 10:34:21 +03:00
|
|
|
for (const AnimationProperty& property : mProperties) {
|
2016-10-05 08:42:56 +03:00
|
|
|
// If there is a property for animations level that is overridden by
|
|
|
|
// !important rules, it should not block other animations from running
|
|
|
|
// on the compositor.
|
|
|
|
// NOTE: We don't currently check for !important rules for properties that
|
|
|
|
// don't run on the compositor. As result such properties (e.g. margin-left)
|
|
|
|
// can still block async animations even if they are overridden by
|
|
|
|
// !important rules.
|
|
|
|
if (effectSet &&
|
|
|
|
effectSet->PropertiesWithImportantRules().HasProperty(
|
|
|
|
property.mProperty) &&
|
|
|
|
effectSet->PropertiesForAnimationsLevel().HasProperty(
|
|
|
|
property.mProperty)) {
|
2016-09-04 10:34:21 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Check for geometric properties
|
|
|
|
if (IsGeometricProperty(property.mProperty)) {
|
|
|
|
aPerformanceWarning =
|
|
|
|
AnimationPerformanceWarning::Type::TransformWithGeometricProperties;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for unsupported transform animations
|
2019-03-02 00:13:03 +03:00
|
|
|
if (LayerAnimationInfo::GetCSSPropertiesFor(DisplayItemType::TYPE_TRANSFORM)
|
|
|
|
.HasProperty(property.mProperty)) {
|
2018-11-22 07:01:10 +03:00
|
|
|
if (!CanAnimateTransformOnCompositor(aFrame, aPerformanceWarning)) {
|
2016-09-04 10:34:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
bool KeyframeEffect::HasGeometricProperties() const {
|
2016-12-02 04:04:08 +03:00
|
|
|
for (const AnimationProperty& property : mProperties) {
|
|
|
|
if (IsGeometricProperty(property.mProperty)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::SetPerformanceWarning(
|
2019-03-21 20:40:11 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertySet,
|
|
|
|
const AnimationPerformanceWarning& aWarning) {
|
|
|
|
nsCSSPropertyIDSet curr = aPropertySet;
|
2016-09-04 10:34:21 +03:00
|
|
|
for (AnimationProperty& property : mProperties) {
|
2019-03-21 20:40:11 +03:00
|
|
|
if (!curr.HasProperty(property.mProperty)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
property.SetPerformanceWarning(aWarning, mTarget->mElement);
|
|
|
|
curr.RemoveProperty(property.mProperty);
|
|
|
|
if (curr.IsEmpty()) {
|
2016-09-04 10:34:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
2018-05-07 05:08:59 +03:00
|
|
|
KeyframeEffect::CreateComputedStyleForAnimationValue(
|
2017-10-12 11:12:54 +03:00
|
|
|
nsCSSPropertyID aProperty, const AnimationValue& aValue,
|
2018-03-22 21:20:41 +03:00
|
|
|
nsPresContext* aPresContext, const ComputedStyle* aBaseComputedStyle) {
|
|
|
|
MOZ_ASSERT(aBaseComputedStyle,
|
|
|
|
"CreateComputedStyleForAnimationValue needs to be called "
|
|
|
|
"with a valid ComputedStyle");
|
2017-10-12 11:12:54 +03:00
|
|
|
|
|
|
|
Element* elementForResolve = EffectCompositor::GetElementToRestyle(
|
|
|
|
mTarget->mElement, mTarget->mPseudoType);
|
2019-02-15 08:54:10 +03:00
|
|
|
// The element may be null if, for example, we target a pseudo-element that no
|
|
|
|
// longer exists.
|
|
|
|
if (!elementForResolve) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServoStyleSet* styleSet = aPresContext->StyleSet();
|
2017-10-12 11:12:54 +03:00
|
|
|
return styleSet->ResolveServoStyleByAddingAnimation(
|
2018-03-22 21:20:41 +03:00
|
|
|
elementForResolve, aBaseComputedStyle, aValue.mServo);
|
2017-10-12 11:12:54 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::CalculateCumulativeChangeHint(
|
|
|
|
const ComputedStyle* aComputedStyle) {
|
2016-09-04 10:34:21 +03:00
|
|
|
mCumulativeChangeHint = nsChangeHint(0);
|
2019-02-15 08:51:08 +03:00
|
|
|
mNeedsStyleData = false;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2018-04-06 15:49:45 +03:00
|
|
|
nsPresContext* presContext =
|
|
|
|
nsContentUtils::GetContextForContent(mTarget->mElement);
|
|
|
|
if (!presContext) {
|
|
|
|
// Change hints make no sense if we're not rendered.
|
|
|
|
//
|
|
|
|
// Actually, we cannot even post them anywhere.
|
2019-02-15 08:51:08 +03:00
|
|
|
mNeedsStyleData = true;
|
2018-04-06 15:49:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
for (const AnimationProperty& property : mProperties) {
|
2018-01-17 05:48:20 +03:00
|
|
|
// For opacity property we don't produce any change hints that are not
|
|
|
|
// included in nsChangeHint_Hints_CanIgnoreIfNotVisible so we can throttle
|
|
|
|
// opacity animations regardless of the change they produce. This
|
|
|
|
// optimization is particularly important since it allows us to throttle
|
|
|
|
// opacity animations with missing 0%/100% keyframes.
|
|
|
|
if (property.mProperty == eCSSProperty_opacity) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
for (const AnimationPropertySegment& segment : property.mSegments) {
|
2017-03-08 04:07:08 +03:00
|
|
|
// In case composite operation is not 'replace' or value is null,
|
|
|
|
// we can't throttle animations which will not cause any layout changes
|
|
|
|
// on invisible elements because we can't calculate the change hint for
|
|
|
|
// such properties until we compose it.
|
2017-03-27 03:15:26 +03:00
|
|
|
if (!segment.HasReplaceableValues()) {
|
2019-03-18 21:05:06 +03:00
|
|
|
if (!nsCSSPropertyIDSet::TransformLikeProperties().HasProperty(
|
|
|
|
property.mProperty)) {
|
2018-06-25 12:29:28 +03:00
|
|
|
mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// We try a little harder to optimize transform animations simply
|
|
|
|
// because they are so common (the second-most commonly animated
|
|
|
|
// property at the time of writing). So if we encounter a transform
|
|
|
|
// segment that needs composing with the underlying value, we just add
|
|
|
|
// all the change hints a transform animation is known to be able to
|
|
|
|
// generate.
|
2018-07-30 04:51:18 +03:00
|
|
|
mCumulativeChangeHint |=
|
|
|
|
nsChangeHint_ComprehensiveAddOrRemoveTransform |
|
|
|
|
nsChangeHint_UpdatePostTransformOverflow |
|
|
|
|
nsChangeHint_UpdateTransformLayer;
|
2018-06-25 12:29:28 +03:00
|
|
|
continue;
|
2016-12-04 02:07:40 +03:00
|
|
|
}
|
2018-06-25 12:29:28 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
RefPtr<ComputedStyle> fromContext = CreateComputedStyleForAnimationValue(
|
|
|
|
property.mProperty, segment.mFromValue, presContext, aComputedStyle);
|
2017-10-12 11:12:54 +03:00
|
|
|
if (!fromContext) {
|
|
|
|
mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
|
2019-02-15 08:51:08 +03:00
|
|
|
mNeedsStyleData = true;
|
2017-10-12 11:12:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
RefPtr<ComputedStyle> toContext = CreateComputedStyleForAnimationValue(
|
|
|
|
property.mProperty, segment.mToValue, presContext, aComputedStyle);
|
2017-10-12 11:12:54 +03:00
|
|
|
if (!toContext) {
|
|
|
|
mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
|
2019-02-15 08:51:08 +03:00
|
|
|
mNeedsStyleData = true;
|
2017-10-12 11:12:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
uint32_t equalStructs = 0;
|
|
|
|
nsChangeHint changeHint =
|
2019-02-05 22:47:29 +03:00
|
|
|
fromContext->CalcStyleDifference(*toContext, &equalStructs);
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
mCumulativeChangeHint |= changeHint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::SetAnimation(Animation* aAnimation) {
|
2016-09-04 10:34:21 +03:00
|
|
|
if (mAnimation == aAnimation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restyle for the old animation.
|
|
|
|
RequestRestyle(EffectCompositor::RestyleType::Layer);
|
|
|
|
|
|
|
|
mAnimation = aAnimation;
|
|
|
|
|
|
|
|
// The order of these function calls is important:
|
|
|
|
// NotifyAnimationTimingUpdated() need the updated mIsRelevant flag to check
|
|
|
|
// if it should create the effectSet or not, and MarkCascadeNeedsUpdate()
|
|
|
|
// needs a valid effectSet, so we should call them in this order.
|
|
|
|
if (mAnimation) {
|
|
|
|
mAnimation->UpdateRelevance();
|
|
|
|
}
|
2019-04-18 09:49:25 +03:00
|
|
|
NotifyAnimationTimingUpdated(PostRestyleMode::IfNeeded);
|
2016-09-04 10:34:21 +03:00
|
|
|
if (mAnimation) {
|
|
|
|
MarkCascadeNeedsUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
bool KeyframeEffect::CanIgnoreIfNotVisible() const {
|
2016-09-04 10:34:21 +03:00
|
|
|
if (!AnimationUtils::IsOffscreenThrottlingEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: For further sophisticated optimization we need to check
|
|
|
|
// change hint on the segment corresponding to computedTiming.progress.
|
|
|
|
return NS_IsHintSubset(mCumulativeChangeHint,
|
|
|
|
nsChangeHint_Hints_CanIgnoreIfNotVisible);
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::MarkCascadeNeedsUpdate() {
|
2016-09-04 10:34:21 +03:00
|
|
|
if (!mTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EffectSet* effectSet =
|
|
|
|
EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType);
|
|
|
|
if (!effectSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
effectSet->MarkCascadeNeedsUpdate();
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
bool KeyframeEffect::HasComputedTimingChanged(
|
2018-04-24 03:27:54 +03:00
|
|
|
const ComputedTiming& aComputedTiming,
|
|
|
|
IterationCompositeOperation aIterationComposite,
|
|
|
|
const Nullable<double>& aProgressOnLastCompose,
|
|
|
|
uint64_t aCurrentIterationOnLastCompose) {
|
2016-09-13 05:48:45 +03:00
|
|
|
// Typically we don't need to request a restyle if the progress hasn't
|
|
|
|
// changed since the last call to ComposeStyle. The one exception is if the
|
|
|
|
// iteration composite mode is 'accumulate' and the current iteration has
|
|
|
|
// changed, since that will often produce a different result.
|
2018-04-24 03:27:54 +03:00
|
|
|
return aComputedTiming.mProgress != aProgressOnLastCompose ||
|
|
|
|
(aIterationComposite == IterationCompositeOperation::Accumulate &&
|
|
|
|
aComputedTiming.mCurrentIteration != aCurrentIterationOnLastCompose);
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
bool KeyframeEffect::HasComputedTimingChanged() const {
|
2016-09-13 05:48:45 +03:00
|
|
|
ComputedTiming computedTiming = GetComputedTiming();
|
2018-04-24 03:27:54 +03:00
|
|
|
return HasComputedTimingChanged(
|
|
|
|
computedTiming, mEffectOptions.mIterationComposite,
|
|
|
|
mProgressOnLastCompose, mCurrentIterationOnLastCompose);
|
2016-09-13 05:48:45 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
bool KeyframeEffect::ContainsAnimatedScale(const nsIFrame* aFrame) const {
|
2019-03-18 07:12:10 +03:00
|
|
|
// For display:table content, transform animations run on the table wrapper
|
|
|
|
// frame. If we are being passed a frame that doesn't support transforms
|
|
|
|
// (i.e. the inner table frame) we could just return false, but it possibly
|
|
|
|
// means we looked up the wrong EffectSet so for now we just assert instead.
|
|
|
|
MOZ_ASSERT(aFrame && aFrame->IsFrameOfType(nsIFrame::eSupportsCSSTransforms),
|
|
|
|
"We should be passed a frame that supports transforms");
|
|
|
|
|
2017-02-09 05:28:47 +03:00
|
|
|
if (!IsCurrent()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-20 08:55:52 +03:00
|
|
|
if (!mAnimation ||
|
|
|
|
mAnimation->ReplaceState() == AnimationReplaceState::Removed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-09 05:28:47 +03:00
|
|
|
for (const AnimationProperty& prop : mProperties) {
|
2019-02-24 06:27:51 +03:00
|
|
|
if (prop.mProperty != eCSSProperty_transform &&
|
|
|
|
prop.mProperty != eCSSProperty_scale &&
|
|
|
|
prop.mProperty != eCSSProperty_rotate) {
|
2017-02-09 05:28:47 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-05-10 06:06:19 +03:00
|
|
|
AnimationValue baseStyle = BaseStyle(prop.mProperty);
|
2017-02-11 13:11:45 +03:00
|
|
|
if (baseStyle.IsNull()) {
|
|
|
|
// If we failed to get the base style, we consider it has scale value
|
|
|
|
// here just to be safe.
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-13 02:37:33 +03:00
|
|
|
gfx::Size size = baseStyle.GetScaleValue(aFrame);
|
|
|
|
if (size != gfx::Size(1.0f, 1.0f)) {
|
2017-02-11 13:11:45 +03:00
|
|
|
return true;
|
2017-02-09 05:28:47 +03:00
|
|
|
}
|
2017-02-09 05:28:47 +03:00
|
|
|
|
|
|
|
// This is actually overestimate because there are some cases that combining
|
|
|
|
// the base value and from/to value produces 1:1 scale. But it doesn't
|
|
|
|
// really matter.
|
|
|
|
for (const AnimationPropertySegment& segment : prop.mSegments) {
|
|
|
|
if (!segment.mFromValue.IsNull()) {
|
2017-11-13 02:37:33 +03:00
|
|
|
gfx::Size from = segment.mFromValue.GetScaleValue(aFrame);
|
|
|
|
if (from != gfx::Size(1.0f, 1.0f)) {
|
2017-02-09 05:28:47 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!segment.mToValue.IsNull()) {
|
2017-11-13 02:37:33 +03:00
|
|
|
gfx::Size to = segment.mToValue.GetScaleValue(aFrame);
|
|
|
|
if (to != gfx::Size(1.0f, 1.0f)) {
|
2017-02-09 05:28:47 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-09 05:28:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void KeyframeEffect::UpdateEffectSet(EffectSet* aEffectSet) const {
|
2017-07-05 04:29:58 +03:00
|
|
|
if (!mInEffectSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-16 14:11:04 +03:00
|
|
|
EffectSet* effectSet =
|
|
|
|
aEffectSet
|
|
|
|
? aEffectSet
|
|
|
|
: EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType);
|
|
|
|
if (!effectSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-18 07:12:23 +03:00
|
|
|
nsIFrame* styleFrame = GetStyleFrame();
|
2019-02-20 05:14:39 +03:00
|
|
|
if (HasAnimationOfPropertySet(nsCSSPropertyIDSet::OpacityProperties())) {
|
2017-05-16 14:11:04 +03:00
|
|
|
effectSet->SetMayHaveOpacityAnimation();
|
2019-03-18 07:12:23 +03:00
|
|
|
EnumerateContinuationsOrIBSplitSiblings(styleFrame, [](nsIFrame* aFrame) {
|
|
|
|
aFrame->SetMayHaveOpacityAnimation();
|
|
|
|
});
|
2017-05-16 14:11:04 +03:00
|
|
|
}
|
2019-03-18 07:12:23 +03:00
|
|
|
|
|
|
|
nsIFrame* primaryFrame = GetPrimaryFrame();
|
2019-02-20 05:14:39 +03:00
|
|
|
if (HasAnimationOfPropertySet(
|
|
|
|
nsCSSPropertyIDSet::TransformLikeProperties())) {
|
2017-05-16 14:11:04 +03:00
|
|
|
effectSet->SetMayHaveTransformAnimation();
|
2019-03-18 07:12:23 +03:00
|
|
|
// For table frames, it's not clear if we should iterate over the
|
|
|
|
// continuations of the table wrapper or the inner table frame.
|
|
|
|
//
|
|
|
|
// Fortunately, this is not currently an issue because we only split tables
|
|
|
|
// when printing (page breaks) where we don't run animations.
|
|
|
|
EnumerateContinuationsOrIBSplitSiblings(primaryFrame, [](nsIFrame* aFrame) {
|
2018-05-23 12:15:12 +03:00
|
|
|
aFrame->SetMayHaveTransformAnimation();
|
|
|
|
});
|
2017-05-16 14:11:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-22 07:01:10 +03:00
|
|
|
KeyframeEffect::MatchForCompositor KeyframeEffect::IsMatchForCompositor(
|
2019-03-02 00:13:03 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertySet, const nsIFrame* aFrame,
|
2018-11-22 07:01:10 +03:00
|
|
|
const EffectSet& aEffects,
|
|
|
|
AnimationPerformanceWarning::Type& aPerformanceWarning /* out */) const {
|
|
|
|
MOZ_ASSERT(mAnimation);
|
|
|
|
|
|
|
|
if (!mAnimation->IsRelevant()) {
|
|
|
|
return KeyframeEffect::MatchForCompositor::No;
|
|
|
|
}
|
|
|
|
|
2019-03-02 00:13:03 +03:00
|
|
|
if (mAnimation->ShouldBeSynchronizedWithMainThread(aPropertySet, aFrame,
|
2018-11-22 07:01:10 +03:00
|
|
|
aPerformanceWarning)) {
|
|
|
|
// For a given |aFrame|, we don't want some animations of |aProperty| to
|
|
|
|
// run on the compositor and others to run on the main thread, so if any
|
|
|
|
// need to be synchronized with the main thread, run them all there.
|
|
|
|
return KeyframeEffect::MatchForCompositor::NoAndBlockThisProperty;
|
|
|
|
}
|
|
|
|
|
2019-03-02 00:13:03 +03:00
|
|
|
if (!HasEffectiveAnimationOfPropertySet(aPropertySet, aEffects)) {
|
2018-11-22 07:01:10 +03:00
|
|
|
return KeyframeEffect::MatchForCompositor::No;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we know that the animation is not visible, we don't need to send the
|
|
|
|
// animation to the compositor.
|
|
|
|
if (!aFrame->IsVisibleOrMayHaveVisibleDescendants() ||
|
|
|
|
aFrame->IsScrolledOutOfView()) {
|
|
|
|
return KeyframeEffect::MatchForCompositor::NoAndBlockThisProperty;
|
|
|
|
}
|
|
|
|
|
2019-03-02 00:13:03 +03:00
|
|
|
if (aPropertySet.HasProperty(eCSSProperty_background_color)) {
|
2018-11-28 03:58:46 +03:00
|
|
|
if (!StaticPrefs::gfx_omta_background_color()) {
|
|
|
|
return KeyframeEffect::MatchForCompositor::No;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsIContent* content = aFrame->GetContent()) {
|
|
|
|
RefPtr<layers::LayerManager> layerManager =
|
|
|
|
nsContentUtils::LayerManagerForContent(content);
|
|
|
|
if (layerManager &&
|
|
|
|
layerManager->GetBackendType() == layers::LayersBackend::LAYERS_WR) {
|
|
|
|
// Bug 1510030: We don't yet support background-color animations on the
|
|
|
|
// compositor for WebRender.
|
|
|
|
return KeyframeEffect::MatchForCompositor::No;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-22 07:01:10 +03:00
|
|
|
return mAnimation->IsPlaying() ? KeyframeEffect::MatchForCompositor::Yes
|
|
|
|
: KeyframeEffect::MatchForCompositor::IfNeeded;
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|