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
|
|
|
#ifndef mozilla_dom_KeyframeEffect_h
|
|
|
|
#define mozilla_dom_KeyframeEffect_h
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
#include "nsChangeHint.h"
|
|
|
|
#include "nsCSSPropertyID.h"
|
2016-12-04 02:07:40 +03:00
|
|
|
#include "nsCSSPropertyIDSet.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "nsCSSValue.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2017-04-06 04:34:50 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/AnimationPerformanceWarning.h"
|
2017-04-06 04:34:50 +03:00
|
|
|
#include "mozilla/AnimationPropertySegment.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "mozilla/AnimationTarget.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/ComputedTimingFunction.h"
|
|
|
|
#include "mozilla/EffectCompositor.h"
|
2017-01-29 06:58:23 +03:00
|
|
|
#include "mozilla/Keyframe.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "mozilla/KeyframeEffectParams.h"
|
2019-04-18 09:49:25 +03:00
|
|
|
#include "mozilla/PostRestyleMode.h"
|
2016-12-01 04:34:54 +03:00
|
|
|
// RawServoDeclarationBlock and associated RefPtrTraits
|
|
|
|
#include "mozilla/ServoBindingTypes.h"
|
2017-03-31 12:46:37 +03:00
|
|
|
#include "mozilla/StyleAnimationValue.h"
|
2018-05-07 05:15:16 +03:00
|
|
|
#include "mozilla/dom/AnimationEffect.h"
|
2016-12-07 12:47:23 +03:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
struct JSContext;
|
|
|
|
class JSObject;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIFrame;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class AnimValuesStyleRule;
|
|
|
|
class ErrorResult;
|
2017-01-24 10:19:18 +03:00
|
|
|
struct AnimationRule;
|
2016-09-04 10:34:21 +03:00
|
|
|
struct TimingParams;
|
2017-05-16 14:11:04 +03:00
|
|
|
class EffectSet;
|
2018-03-22 21:20:41 +03:00
|
|
|
class ComputedStyle;
|
2019-03-29 18:12:47 +03:00
|
|
|
class PresShell;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
namespace dom {
|
2020-11-23 19:08:40 +03:00
|
|
|
class Element;
|
2016-09-04 10:34:21 +03:00
|
|
|
class GlobalObject;
|
|
|
|
class UnrestrictedDoubleOrKeyframeAnimationOptions;
|
|
|
|
class UnrestrictedDoubleOrKeyframeEffectOptions;
|
2017-01-12 04:23:37 +03:00
|
|
|
enum class IterationCompositeOperation : uint8_t;
|
|
|
|
enum class CompositeOperation : uint8_t;
|
2016-09-04 10:34:21 +03:00
|
|
|
struct AnimationPropertyDetails;
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
struct AnimationProperty {
|
|
|
|
nsCSSPropertyID mProperty = eCSSProperty_UNKNOWN;
|
|
|
|
|
|
|
|
// If true, the propery is currently being animated on the compositor.
|
|
|
|
//
|
|
|
|
// Note that when the owning Animation requests a non-throttled restyle, in
|
|
|
|
// between calling RequestRestyle on its EffectCompositor and when the
|
|
|
|
// restyle is performed, this member may temporarily become false even if
|
|
|
|
// the animation remains on the layer after the restyle.
|
|
|
|
//
|
|
|
|
// **NOTE**: This member is not included when comparing AnimationProperty
|
|
|
|
// objects for equality.
|
|
|
|
bool mIsRunningOnCompositor = false;
|
|
|
|
|
|
|
|
Maybe<AnimationPerformanceWarning> mPerformanceWarning;
|
|
|
|
|
2019-07-10 06:25:03 +03:00
|
|
|
nsTArray<AnimationPropertySegment> mSegments;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2016-11-03 06:36:28 +03:00
|
|
|
// The copy constructor/assignment doesn't copy mIsRunningOnCompositor and
|
|
|
|
// mPerformanceWarning.
|
|
|
|
AnimationProperty() = default;
|
|
|
|
AnimationProperty(const AnimationProperty& aOther)
|
2020-05-05 13:42:23 +03:00
|
|
|
: mProperty(aOther.mProperty), mSegments(aOther.mSegments.Clone()) {}
|
2016-11-03 06:36:28 +03:00
|
|
|
AnimationProperty& operator=(const AnimationProperty& aOther) {
|
|
|
|
mProperty = aOther.mProperty;
|
2020-05-05 13:42:23 +03:00
|
|
|
mSegments = aOther.mSegments.Clone();
|
2016-11-03 06:36:28 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-10-05 08:48:05 +03:00
|
|
|
// NOTE: This operator does *not* compare the mIsRunningOnCompositor member.
|
2016-09-04 10:34:21 +03:00
|
|
|
// This is because AnimationProperty objects are compared when recreating
|
|
|
|
// CSS animations to determine if mutation observer change records need to
|
|
|
|
// be created or not. However, at the point when these objects are compared
|
2016-10-05 08:48:05 +03:00
|
|
|
// the mIsRunningOnCompositor will not have been set on the new objects so
|
|
|
|
// we ignore this member to avoid generating spurious change records.
|
2016-11-03 06:36:28 +03:00
|
|
|
bool operator==(const AnimationProperty& aOther) const {
|
2016-09-04 10:34:21 +03:00
|
|
|
return mProperty == aOther.mProperty && mSegments == aOther.mSegments;
|
|
|
|
}
|
2016-11-03 06:36:28 +03:00
|
|
|
bool operator!=(const AnimationProperty& aOther) const {
|
2016-09-04 10:34:21 +03:00
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
2019-03-21 20:40:11 +03:00
|
|
|
|
|
|
|
void SetPerformanceWarning(const AnimationPerformanceWarning& aWarning,
|
2019-11-29 23:39:36 +03:00
|
|
|
const dom::Element* aElement);
|
2016-09-04 10:34:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Animation;
|
2019-01-02 16:05:23 +03:00
|
|
|
class Document;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2018-05-07 05:15:16 +03:00
|
|
|
class KeyframeEffect : public AnimationEffect {
|
2016-09-04 10:34:21 +03:00
|
|
|
public:
|
2020-02-18 23:44:12 +03:00
|
|
|
KeyframeEffect(Document* aDocument, OwningAnimationTarget&& aTarget,
|
2018-05-07 05:08:59 +03:00
|
|
|
TimingParams&& aTiming, const KeyframeEffectParams& aOptions);
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2020-05-14 22:41:01 +03:00
|
|
|
KeyframeEffect(Document* aDocument, OwningAnimationTarget&& aTarget,
|
|
|
|
const KeyframeEffect& aOther);
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2018-05-07 05:08:59 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(KeyframeEffect,
|
2018-05-07 05:15:16 +03:00
|
|
|
AnimationEffect)
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
KeyframeEffect* AsKeyframeEffect() override { return this; }
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2021-02-24 19:35:17 +03:00
|
|
|
bool IsValidTransition() const {
|
|
|
|
return Properties().Length() == 1 &&
|
|
|
|
Properties()[0].mSegments.Length() == 1;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
// KeyframeEffect interface
|
|
|
|
static already_AddRefed<KeyframeEffect> Constructor(
|
2020-02-18 23:44:14 +03:00
|
|
|
const GlobalObject& aGlobal, Element* aTarget,
|
2016-09-04 10:34:21 +03:00
|
|
|
JS::Handle<JSObject*> aKeyframes,
|
|
|
|
const UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
static already_AddRefed<KeyframeEffect> Constructor(
|
2016-10-28 10:41:08 +03:00
|
|
|
const GlobalObject& aGlobal, KeyframeEffect& aSource, ErrorResult& aRv);
|
2018-05-07 05:08:59 +03:00
|
|
|
|
|
|
|
// Variant of Constructor that accepts a KeyframeAnimationOptions object
|
|
|
|
// for use with for Animatable.animate.
|
|
|
|
// Not exposed to content.
|
|
|
|
static already_AddRefed<KeyframeEffect> Constructor(
|
2020-02-18 23:44:14 +03:00
|
|
|
const GlobalObject& aGlobal, Element* aTarget,
|
2018-05-07 05:08:59 +03:00
|
|
|
JS::Handle<JSObject*> aKeyframes,
|
|
|
|
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
|
2016-10-28 10:41:08 +03:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2020-11-25 02:58:33 +03:00
|
|
|
Element* GetTarget() const { return mTarget.mElement.get(); }
|
2020-02-18 23:44:14 +03:00
|
|
|
NonOwningAnimationTarget GetAnimationTarget() const {
|
|
|
|
return NonOwningAnimationTarget(mTarget.mElement, mTarget.mPseudoType);
|
|
|
|
}
|
|
|
|
void GetPseudoElement(nsAString& aRetVal) const {
|
|
|
|
if (mTarget.mPseudoType == PseudoStyleType::NotPseudo) {
|
|
|
|
SetDOMStringToNull(aRetVal);
|
|
|
|
return;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
2020-02-18 23:44:14 +03:00
|
|
|
aRetVal = nsCSSPseudoElements::PseudoTypeAsString(mTarget.mPseudoType);
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
2020-02-18 23:44:14 +03:00
|
|
|
|
|
|
|
// These two setters call GetTargetComputedStyle which is not safe to use when
|
2018-05-07 04:48:48 +03:00
|
|
|
// we are in the middle of updating style. If we need to use this when
|
|
|
|
// updating style, we should pass the ComputedStyle into this method and use
|
|
|
|
// that to update the properties rather than calling
|
|
|
|
// GetComputedStyle.
|
2020-02-18 23:44:14 +03:00
|
|
|
void SetTarget(Element* aTarget) {
|
|
|
|
UpdateTarget(aTarget, mTarget.mPseudoType);
|
|
|
|
}
|
|
|
|
void SetPseudoElement(const nsAString& aPseudoElement, ErrorResult& aRv);
|
2018-05-07 04:48:48 +03:00
|
|
|
|
2020-03-07 02:05:15 +03:00
|
|
|
void 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
|
|
|
void GetProperties(nsTArray<AnimationPropertyDetails>& aProperties,
|
|
|
|
ErrorResult& aRv) const;
|
|
|
|
|
2018-07-14 03:23:03 +03:00
|
|
|
IterationCompositeOperation IterationComposite() const;
|
2018-05-07 04:48:48 +03:00
|
|
|
void SetIterationComposite(
|
2018-07-14 03:23:03 +03:00
|
|
|
const IterationCompositeOperation& aIterationComposite);
|
2018-05-07 04:48:48 +03:00
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
CompositeOperation Composite() const;
|
2018-05-07 04:48:48 +03:00
|
|
|
void SetComposite(const CompositeOperation& aComposite);
|
|
|
|
|
2018-05-07 05:02:12 +03:00
|
|
|
void NotifySpecifiedTimingUpdated();
|
2019-04-18 09:49:25 +03:00
|
|
|
void NotifyAnimationTimingUpdated(PostRestyleMode aPostRestyle);
|
2017-03-14 19:33:22 +03:00
|
|
|
void RequestRestyle(EffectCompositor::RestyleType aRestyleType);
|
2016-09-04 10:34:21 +03:00
|
|
|
void SetAnimation(Animation* aAnimation) override;
|
2020-03-04 03:35:52 +03:00
|
|
|
virtual void SetKeyframes(JSContext* aContext,
|
|
|
|
JS::Handle<JSObject*> aKeyframes, ErrorResult& aRv);
|
2017-02-23 03:52:44 +03:00
|
|
|
void SetKeyframes(nsTArray<Keyframe>&& aKeyframes,
|
2018-04-06 15:49:45 +03:00
|
|
|
const ComputedStyle* aStyle);
|
2016-10-13 10:54:25 +03:00
|
|
|
|
2020-03-02 09:38:36 +03:00
|
|
|
// Replace the start value of the transition. This is used for updating
|
|
|
|
// transitions running on the compositor.
|
|
|
|
void ReplaceTransitionStartValue(AnimationValue&& aStartValue);
|
|
|
|
|
2019-05-20 08:48:31 +03:00
|
|
|
// Returns the set of properties affected by this effect regardless of
|
|
|
|
// whether any of these properties is overridden by an !important rule.
|
|
|
|
nsCSSPropertyIDSet GetPropertySet() const;
|
|
|
|
|
2019-02-20 05:14:39 +03:00
|
|
|
// Returns true if the effect includes a property in |aPropertySet| regardless
|
2019-05-20 08:48:31 +03:00
|
|
|
// of whether any property in the set is overridden by an !important rule.
|
|
|
|
bool HasAnimationOfPropertySet(const nsCSSPropertyIDSet& aPropertySet) const {
|
|
|
|
return GetPropertySet().Intersects(aPropertySet);
|
|
|
|
}
|
2016-10-13 10:54:25 +03:00
|
|
|
|
|
|
|
// GetEffectiveAnimationOfProperty returns AnimationProperty corresponding
|
|
|
|
// to a given CSS property if the effect includes the property and the
|
|
|
|
// property is not overridden by !important rules.
|
|
|
|
// Also EffectiveAnimationOfProperty returns true under the same condition.
|
|
|
|
//
|
2018-11-13 13:17:44 +03:00
|
|
|
// |aEffect| should be the EffectSet containing this KeyframeEffect since
|
|
|
|
// this function is typically called for all KeyframeEffects on an element
|
|
|
|
// so that we can avoid multiple calls of EffectSet::GetEffect().
|
|
|
|
//
|
2019-06-28 21:18:08 +03:00
|
|
|
// Note that does not consider the interaction between related transform
|
|
|
|
// properties where an !important rule on another transform property may
|
|
|
|
// cause all transform properties to be run on the main thread. That check is
|
|
|
|
// performed by GetPropertiesForCompositor.
|
2018-11-13 13:17:44 +03:00
|
|
|
bool HasEffectiveAnimationOfProperty(nsCSSPropertyID aProperty,
|
|
|
|
const EffectSet& aEffect) const {
|
|
|
|
return GetEffectiveAnimationOfProperty(aProperty, aEffect) != nullptr;
|
2016-09-04 10:34:21 +03:00
|
|
|
}
|
2016-10-13 10:54:25 +03:00
|
|
|
const AnimationProperty* GetEffectiveAnimationOfProperty(
|
2018-11-13 13:17:44 +03:00
|
|
|
nsCSSPropertyID aProperty, const EffectSet& aEffect) const;
|
2016-10-13 10:54:25 +03:00
|
|
|
|
2019-03-18 07:10:10 +03:00
|
|
|
// Similar to HasEffectiveAnimationOfProperty, above, but for
|
|
|
|
// an nsCSSPropertyIDSet. Returns true if this keyframe effect has at least
|
|
|
|
// one property in |aPropertySet| that is not overridden by an !important
|
|
|
|
// rule.
|
|
|
|
//
|
2019-06-28 21:18:08 +03:00
|
|
|
// Note that does not consider the interaction between related transform
|
|
|
|
// properties where an !important rule on another transform property may
|
|
|
|
// cause all transform properties to be run on the main thread. That check is
|
|
|
|
// performed by GetPropertiesForCompositor.
|
2019-02-23 03:21:45 +03:00
|
|
|
bool HasEffectiveAnimationOfPropertySet(
|
2019-03-18 07:10:10 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertySet,
|
|
|
|
const EffectSet& aEffectSet) const;
|
2019-02-23 03:21:45 +03:00
|
|
|
|
2018-11-13 13:22:26 +03:00
|
|
|
// Returns all the effective animated CSS properties that can be animated on
|
|
|
|
// the compositor and are not overridden by a higher cascade level.
|
|
|
|
//
|
|
|
|
// NOTE: This function is basically called for all KeyframeEffects on an
|
|
|
|
// element thus it takes |aEffects| to avoid multiple calls of
|
|
|
|
// EffectSet::GetEffect().
|
2018-11-22 06:57:59 +03:00
|
|
|
//
|
|
|
|
// NOTE(2): This function does NOT check that animations are permitted on
|
|
|
|
// |aFrame|. It is the responsibility of the caller to first call
|
|
|
|
// EffectCompositor::AllowCompositorAnimationsOnFrame for |aFrame|, or use
|
|
|
|
// nsLayoutUtils::GetAnimationPropertiesForCompositor instead.
|
|
|
|
nsCSSPropertyIDSet GetPropertiesForCompositor(EffectSet& aEffects,
|
|
|
|
const nsIFrame* aFrame) const;
|
2018-11-13 13:22:26 +03:00
|
|
|
|
2019-07-10 06:25:03 +03:00
|
|
|
const nsTArray<AnimationProperty>& Properties() const { return mProperties; }
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
// Update |mProperties| by recalculating from |mKeyframes| using
|
2018-03-22 21:20:41 +03:00
|
|
|
// |aComputedStyle| to resolve specified values.
|
|
|
|
void UpdateProperties(const ComputedStyle* aComputedValues);
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
// Update various bits of state related to running ComposeStyle().
|
|
|
|
// We need to update this outside ComposeStyle() because we should avoid
|
|
|
|
// mutating any state in ComposeStyle() since it might be called during
|
|
|
|
// parallel traversal.
|
|
|
|
void WillComposeStyle();
|
|
|
|
|
2017-03-17 07:22:13 +03:00
|
|
|
// Updates |aComposeResult| with the animation values produced by this
|
2016-10-05 08:42:56 +03:00
|
|
|
// AnimationEffect for the current time except any properties contained
|
|
|
|
// in |aPropertiesToSkip|.
|
2018-04-09 14:15:59 +03:00
|
|
|
void ComposeStyle(RawServoAnimationValueMap& aComposeResult,
|
2016-10-05 08:42:56 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertiesToSkip);
|
2016-12-04 02:07:40 +03:00
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
// Returns true if at least one property is being animated on compositor.
|
|
|
|
bool IsRunningOnCompositor() const;
|
|
|
|
void SetIsRunningOnCompositor(nsCSSPropertyID aProperty, bool aIsRunning);
|
2019-03-02 00:13:01 +03:00
|
|
|
void SetIsRunningOnCompositor(const nsCSSPropertyIDSet& aPropertySet,
|
|
|
|
bool aIsRunning);
|
2016-09-04 10:34:21 +03:00
|
|
|
void ResetIsRunningOnCompositor();
|
|
|
|
|
2020-07-05 14:45:01 +03:00
|
|
|
void ResetPartialPrerendered();
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
// Returns true if this effect, applied to |aFrame|, contains properties
|
|
|
|
// that mean we shouldn't run transform compositor animations on this element.
|
|
|
|
//
|
|
|
|
// For example, if we have an animation of geometric properties like 'left'
|
|
|
|
// and 'top' on an element, we force all 'transform' animations running at
|
|
|
|
// the same time on the same element to run on the main thread.
|
|
|
|
//
|
|
|
|
// When returning true, |aPerformanceWarning| stores the reason why
|
|
|
|
// we shouldn't run the transform animations.
|
|
|
|
bool ShouldBlockAsyncTransformAnimations(
|
2019-06-28 21:18:08 +03:00
|
|
|
const nsIFrame* aFrame, const nsCSSPropertyIDSet& aPropertySet,
|
2018-11-22 07:01:10 +03:00
|
|
|
AnimationPerformanceWarning::Type& aPerformanceWarning /* out */) const;
|
2016-12-02 04:04:08 +03:00
|
|
|
bool HasGeometricProperties() const;
|
|
|
|
bool AffectsGeometry() const override {
|
2020-02-18 23:44:14 +03:00
|
|
|
return mTarget && HasGeometricProperties();
|
2016-12-02 04:04:08 +03:00
|
|
|
}
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* GetRenderedDocument() const;
|
2019-03-29 18:12:47 +03:00
|
|
|
PresShell* GetPresShell() const;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2019-03-21 20:40:11 +03:00
|
|
|
// Associates a warning with the animated property set on the specified frame
|
2016-09-04 10:34:21 +03:00
|
|
|
// indicating why, for example, the property could not be animated on the
|
|
|
|
// compositor. |aParams| and |aParamsLength| are optional parameters which
|
|
|
|
// will be used to generate a localized message for devtools.
|
2019-03-21 20:40:11 +03:00
|
|
|
void SetPerformanceWarning(const nsCSSPropertyIDSet& aPropertySet,
|
2016-09-04 10:34:21 +03:00
|
|
|
const AnimationPerformanceWarning& aWarning);
|
|
|
|
|
|
|
|
// Cumulative change hint on each segment for each property.
|
|
|
|
// This is used for deciding the animation is paint-only.
|
2018-04-06 15:49:45 +03:00
|
|
|
void CalculateCumulativeChangeHint(const ComputedStyle* aStyle);
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
// Returns true if all of animation properties' change hints
|
|
|
|
// can ignore painting if the animation is not visible.
|
|
|
|
// See nsChangeHint_Hints_CanIgnoreIfNotVisible in nsChangeHint.h
|
|
|
|
// in detail which change hint can be ignored.
|
|
|
|
bool CanIgnoreIfNotVisible() const;
|
|
|
|
|
2017-02-09 05:28:47 +03:00
|
|
|
// Returns true if the effect is current state and has scale animation.
|
|
|
|
// |aFrame| is used for calculation of scale values.
|
|
|
|
bool ContainsAnimatedScale(const nsIFrame* aFrame) const;
|
|
|
|
|
2017-05-10 06:06:19 +03:00
|
|
|
AnimationValue BaseStyle(nsCSSPropertyID aProperty) const {
|
|
|
|
AnimationValue result;
|
|
|
|
bool hasProperty = false;
|
2018-03-25 20:42:10 +03:00
|
|
|
// We cannot use getters_AddRefs on RawServoAnimationValue because it is
|
|
|
|
// an incomplete type, so Get() doesn't work. Instead, use GetWeak, and
|
|
|
|
// then assign the raw pointer to a RefPtr.
|
2018-12-06 23:57:12 +03:00
|
|
|
result.mServo = mBaseValues.GetWeak(aProperty, &hasProperty);
|
2017-02-11 13:11:45 +03:00
|
|
|
MOZ_ASSERT(hasProperty || result.IsNull());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-11-22 07:01:10 +03:00
|
|
|
enum class MatchForCompositor {
|
|
|
|
// This animation matches and should run on the compositor if possible.
|
|
|
|
Yes,
|
|
|
|
// This (not currently playing) animation matches and can be run on the
|
|
|
|
// compositor if there are other animations for this property that return
|
|
|
|
// 'Yes'.
|
|
|
|
IfNeeded,
|
|
|
|
// This animation does not match or can't be run on the compositor.
|
|
|
|
No,
|
|
|
|
// This animation does not match or can't be run on the compositor and,
|
|
|
|
// furthermore, its presence means we should not run any animations for this
|
|
|
|
// property on the compositor.
|
|
|
|
NoAndBlockThisProperty
|
|
|
|
};
|
|
|
|
|
|
|
|
MatchForCompositor 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;
|
|
|
|
|
2018-04-24 03:27:54 +03:00
|
|
|
static bool HasComputedTimingChanged(
|
|
|
|
const ComputedTiming& aComputedTiming,
|
|
|
|
IterationCompositeOperation aIterationComposite,
|
|
|
|
const Nullable<double>& aProgressOnLastCompose,
|
|
|
|
uint64_t aCurrentIterationOnLastCompose);
|
|
|
|
|
2020-02-27 04:36:14 +03:00
|
|
|
bool HasOpacityChange() const {
|
|
|
|
return mCumulativeChangeHint & nsChangeHint_UpdateOpacityLayer;
|
|
|
|
}
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
protected:
|
2018-05-07 05:08:59 +03:00
|
|
|
~KeyframeEffect() override = default;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2018-07-11 04:27:01 +03:00
|
|
|
template <class OptionsType>
|
|
|
|
static already_AddRefed<KeyframeEffect> ConstructKeyframeEffect(
|
2020-02-18 23:44:14 +03:00
|
|
|
const GlobalObject& aGlobal, Element* aTarget,
|
2016-09-04 10:34:21 +03:00
|
|
|
JS::Handle<JSObject*> aKeyframes, const OptionsType& aOptions,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Build properties by recalculating from |mKeyframes| using |aComputedStyle|
|
2016-11-07 12:01:39 +03:00
|
|
|
// to resolve specified values. This function also applies paced spacing if
|
|
|
|
// needed.
|
2018-04-09 14:15:59 +03:00
|
|
|
nsTArray<AnimationProperty> BuildProperties(const ComputedStyle* aStyle);
|
2016-11-07 12:01:39 +03:00
|
|
|
|
2020-02-18 23:44:14 +03:00
|
|
|
// Helper for SetTarget() and SetPseudoElement().
|
|
|
|
void UpdateTarget(Element* aElement, PseudoStyleType aPseudoType);
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
// This effect is registered with its target element so long as:
|
|
|
|
//
|
|
|
|
// (a) It has a target element, and
|
|
|
|
// (b) It is "relevant" (i.e. yet to finish but not idle, or finished but
|
|
|
|
// filling forwards)
|
|
|
|
//
|
|
|
|
// As a result, we need to make sure this gets called whenever anything
|
|
|
|
// changes with regards to this effects's timing including changes to the
|
|
|
|
// owning Animation's timing.
|
|
|
|
void UpdateTargetRegistration();
|
|
|
|
|
|
|
|
// Remove the current effect target from its EffectSet.
|
|
|
|
void UnregisterTarget();
|
|
|
|
|
2018-03-23 16:49:21 +03:00
|
|
|
// Looks up the ComputedStyle associated with the target element, if any.
|
2016-09-04 10:34:21 +03:00
|
|
|
// We need to be careful to *not* call this when we are updating the style
|
2018-03-22 21:20:41 +03:00
|
|
|
// context. That's because calling GetComputedStyle when we are in the process
|
2018-03-23 16:49:21 +03:00
|
|
|
// of building a ComputedStyle may trigger various forms of infinite
|
2017-04-05 08:39:23 +03:00
|
|
|
// recursion.
|
2019-02-15 09:08:05 +03:00
|
|
|
enum class Flush {
|
|
|
|
Style,
|
|
|
|
None,
|
|
|
|
};
|
2022-05-28 04:04:24 +03:00
|
|
|
already_AddRefed<const ComputedStyle> GetTargetComputedStyle(Flush) const;
|
2017-01-16 11:41:24 +03:00
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
// A wrapper for marking cascade update according to the current
|
|
|
|
// target and its effectSet.
|
|
|
|
void MarkCascadeNeedsUpdate();
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
void EnsureBaseStyles(const ComputedStyle* aComputedValues,
|
2018-12-06 23:59:50 +03:00
|
|
|
const nsTArray<AnimationProperty>& aProperties,
|
|
|
|
bool* aBaseStylesChanged);
|
2017-04-06 04:34:50 +03:00
|
|
|
void EnsureBaseStyle(const AnimationProperty& aProperty,
|
|
|
|
nsPresContext* aPresContext,
|
2018-03-22 21:20:41 +03:00
|
|
|
const ComputedStyle* aComputedValues,
|
2022-05-28 04:04:24 +03:00
|
|
|
RefPtr<const ComputedStyle>& aBaseComputedValues);
|
2017-02-11 13:11:45 +03:00
|
|
|
|
2020-02-18 23:44:12 +03:00
|
|
|
OwningAnimationTarget mTarget;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
KeyframeEffectParams mEffectOptions;
|
|
|
|
|
|
|
|
// The specified keyframes.
|
|
|
|
nsTArray<Keyframe> mKeyframes;
|
|
|
|
|
|
|
|
// A set of per-property value arrays, derived from |mKeyframes|.
|
|
|
|
nsTArray<AnimationProperty> mProperties;
|
|
|
|
|
|
|
|
// The computed progress last time we composed the style rule. This is
|
|
|
|
// used to detect when the progress is not changing (e.g. due to a step
|
|
|
|
// timing function) so we can avoid unnecessary style updates.
|
|
|
|
Nullable<double> mProgressOnLastCompose;
|
|
|
|
|
2016-09-13 05:48:45 +03:00
|
|
|
// The purpose of this value is the same as mProgressOnLastCompose but
|
|
|
|
// this is used to detect when the current iteration is not changing
|
|
|
|
// in the case when iterationComposite is accumulate.
|
|
|
|
uint64_t mCurrentIterationOnLastCompose = 0;
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
// We need to track when we go to or from being "in effect" since
|
|
|
|
// we need to re-evaluate the cascade of animations when that changes.
|
2019-01-08 09:43:52 +03:00
|
|
|
bool mInEffectOnLastAnimationTimingUpdate = false;
|
|
|
|
|
|
|
|
// True if this effect is in the EffectSet for its target element. This is
|
|
|
|
// used as an optimization to avoid unnecessary hashmap lookups on the
|
|
|
|
// EffectSet.
|
|
|
|
bool mInEffectSet = false;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2019-02-15 08:51:08 +03:00
|
|
|
// True if the last time we tried to update the cumulative change hint we
|
|
|
|
// didn't have style data to do so. We set this flag so that the next time
|
|
|
|
// our style context changes we know to update the cumulative change hint even
|
|
|
|
// if our properties haven't changed.
|
|
|
|
bool mNeedsStyleData = false;
|
|
|
|
|
2020-03-04 00:48:01 +03:00
|
|
|
// True if there is any current-color for background color in this keyframes.
|
|
|
|
bool mHasCurrentColor = false;
|
|
|
|
|
2017-02-11 13:11:45 +03:00
|
|
|
// The non-animated values for properties in this effect that contain at
|
|
|
|
// least one animation value that is composited with the underlying value
|
|
|
|
// (i.e. it uses the additive or accumulate composite mode).
|
2018-12-06 23:57:58 +03:00
|
|
|
using BaseValuesHashmap =
|
|
|
|
nsRefPtrHashtable<nsUint32HashKey, RawServoAnimationValue>;
|
|
|
|
BaseValuesHashmap mBaseValues;
|
2016-12-04 02:07:40 +03:00
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
private:
|
2020-05-14 22:41:01 +03:00
|
|
|
nsChangeHint mCumulativeChangeHint = nsChangeHint{0};
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2017-05-01 12:45:41 +03:00
|
|
|
void ComposeStyleRule(RawServoAnimationValueMap& aAnimationValues,
|
2017-03-17 06:48:56 +03:00
|
|
|
const AnimationProperty& aProperty,
|
|
|
|
const AnimationPropertySegment& aSegment,
|
|
|
|
const ComputedTiming& aComputedTiming);
|
|
|
|
|
2022-05-28 04:04:24 +03:00
|
|
|
already_AddRefed<const ComputedStyle> 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);
|
2017-10-12 11:12:54 +03:00
|
|
|
|
2018-05-08 23:53:47 +03:00
|
|
|
// Return the primary frame for the target (pseudo-)element.
|
|
|
|
nsIFrame* GetPrimaryFrame() const;
|
2018-05-08 23:53:46 +03:00
|
|
|
// Returns the frame which is used for styling.
|
|
|
|
nsIFrame* GetStyleFrame() const;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
|
|
|
bool CanThrottle() const;
|
2018-06-25 03:12:21 +03:00
|
|
|
bool CanThrottleOverflowChanges(const nsIFrame& aFrame) const;
|
|
|
|
bool CanThrottleOverflowChangesInScrollable(nsIFrame& aFrame) const;
|
2018-06-25 05:51:05 +03:00
|
|
|
bool CanThrottleIfNotVisible(nsIFrame& aFrame) const;
|
2016-09-04 10:34:21 +03:00
|
|
|
|
2016-09-13 05:48:45 +03:00
|
|
|
// Returns true if the computedTiming has changed since the last
|
|
|
|
// composition.
|
|
|
|
bool HasComputedTimingChanged() const;
|
|
|
|
|
2016-09-04 10:34:21 +03:00
|
|
|
// Returns true unless Gecko limitations prevent performing transform
|
|
|
|
// animations for |aFrame|. When returning true, the reason for the
|
|
|
|
// limitation is stored in |aOutPerformanceWarning|.
|
|
|
|
static bool CanAnimateTransformOnCompositor(
|
|
|
|
const nsIFrame* aFrame,
|
2018-11-22 07:01:10 +03:00
|
|
|
AnimationPerformanceWarning::Type& aPerformanceWarning /* out */);
|
2016-09-04 10:34:21 +03:00
|
|
|
static bool IsGeometricProperty(const nsCSSPropertyID aProperty);
|
|
|
|
|
|
|
|
static const TimeDuration OverflowRegionRefreshInterval();
|
2016-12-21 07:52:19 +03:00
|
|
|
|
2017-06-20 09:42:26 +03:00
|
|
|
void UpdateEffectSet(mozilla::EffectSet* aEffectSet = nullptr) const;
|
2017-05-16 14:11:04 +03:00
|
|
|
|
2018-06-25 03:12:21 +03:00
|
|
|
// Returns true if this effect has properties that might affect the overflow
|
|
|
|
// region.
|
2018-02-27 08:46:32 +03:00
|
|
|
// This function is used for updating scroll bars or notifying intersection
|
|
|
|
// observers reflected by the transform.
|
2018-06-25 03:12:21 +03:00
|
|
|
bool HasPropertiesThatMightAffectOverflow() const {
|
2018-06-25 05:50:56 +03:00
|
|
|
return mCumulativeChangeHint &
|
|
|
|
(nsChangeHint_AddOrRemoveTransform | nsChangeHint_UpdateOverflow |
|
|
|
|
nsChangeHint_UpdatePostTransformOverflow |
|
2018-02-27 08:46:32 +03:00
|
|
|
nsChangeHint_UpdateTransformLayer);
|
|
|
|
}
|
2018-05-03 08:14:11 +03:00
|
|
|
|
|
|
|
// Returns true if this effect causes visibility change.
|
|
|
|
// (i.e. 'visibility: hidden' -> 'visibility: visible' and vice versa.)
|
|
|
|
bool HasVisibilityChange() const {
|
|
|
|
return mCumulativeChangeHint & nsChangeHint_VisibilityChange;
|
|
|
|
}
|
2016-09-04 10:34:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-05-07 05:07:06 +03:00
|
|
|
#endif // mozilla_dom_KeyframeEffect_h
|