2011-04-12 10:18:43 +04:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_css_AnimationCommon_h
|
|
|
|
#define mozilla_css_AnimationCommon_h
|
|
|
|
|
|
|
|
#include "nsIStyleRuleProcessor.h"
|
|
|
|
#include "nsIStyleRule.h"
|
|
|
|
#include "nsRefreshDriver.h"
|
2014-11-17 07:46:00 +03:00
|
|
|
#include "nsChangeHint.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsCSSProperty.h"
|
2014-11-17 07:46:00 +03:00
|
|
|
#include "nsDisplayList.h" // For nsDisplayItem::Type
|
2015-07-29 04:57:39 +03:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2015-08-18 07:13:14 +03:00
|
|
|
#include "mozilla/LinkedList.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-06-24 10:29:54 +04:00
|
|
|
#include "mozilla/StyleAnimationValue.h"
|
2015-04-21 04:22:09 +03:00
|
|
|
#include "mozilla/dom/Animation.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-07-16 04:02:32 +04:00
|
|
|
#include "mozilla/dom/Nullable.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsStyleStruct.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-10-17 09:14:02 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2014-06-11 09:19:07 +04:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2015-06-09 05:13:54 +03:00
|
|
|
#include "nsContentUtils.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2014-07-16 04:02:30 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2015-03-20 07:10:00 +03:00
|
|
|
#include "nsCSSPropertySet.h"
|
2013-10-23 00:55:14 +04:00
|
|
|
|
2013-10-22 14:30:45 +04:00
|
|
|
class nsIFrame;
|
2014-06-12 21:09:31 +04:00
|
|
|
class nsPresContext;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-06-24 10:29:54 +04:00
|
|
|
|
2014-08-07 09:58:44 +04:00
|
|
|
class RestyleTracker;
|
2015-04-21 04:22:10 +03:00
|
|
|
struct AnimationCollection;
|
2014-06-24 10:29:54 +04:00
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
bool IsGeometricProperty(nsCSSProperty aProperty);
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
class CommonAnimationManager : public nsIStyleRuleProcessor,
|
|
|
|
public nsARefreshObserver {
|
|
|
|
public:
|
2014-08-20 08:58:22 +04:00
|
|
|
explicit CommonAnimationManager(nsPresContext *aPresContext);
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
// nsIStyleRuleProcessor (parts)
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) override;
|
|
|
|
virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) override;
|
|
|
|
virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) override;
|
2011-04-12 10:18:43 +04:00
|
|
|
virtual nsRestyleHint
|
2015-08-05 15:42:21 +03:00
|
|
|
HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
|
|
|
|
RestyleHintData& aRestyleHintDataResult) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) override;
|
|
|
|
virtual void RulesMatching(ElementRuleProcessorData* aData) override;
|
|
|
|
virtual void RulesMatching(PseudoElementRuleProcessorData* aData) override;
|
|
|
|
virtual void RulesMatching(AnonBoxRuleProcessorData* aData) override;
|
2014-11-20 05:48:41 +03:00
|
|
|
#ifdef MOZ_XUL
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void RulesMatching(XULTreeRuleProcessorData* aData) override;
|
2014-11-20 05:48:41 +03:00
|
|
|
#endif
|
2015-07-29 04:57:39 +03:00
|
|
|
virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf)
|
2015-03-21 19:28:04 +03:00
|
|
|
const MOZ_MUST_OVERRIDE override;
|
2015-07-29 04:57:39 +03:00
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
|
2015-03-21 19:28:04 +03:00
|
|
|
const MOZ_MUST_OVERRIDE override;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2015-08-17 07:59:44 +03:00
|
|
|
// nsARefreshObserver
|
|
|
|
void WillRefresh(TimeStamp aTime) override;
|
|
|
|
|
2015-04-01 01:05:54 +03:00
|
|
|
// NOTE: This can return null after Disconnect().
|
|
|
|
nsPresContext* PresContext() const { return mPresContext; }
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
/**
|
|
|
|
* Notify the manager that the pres context is going away.
|
|
|
|
*/
|
|
|
|
void Disconnect();
|
|
|
|
|
2014-08-07 09:58:44 +04:00
|
|
|
// Tell the restyle tracker about all the styles that we're currently
|
|
|
|
// animating, so that it can update the animation rule for these
|
|
|
|
// elements.
|
2015-07-29 04:57:39 +03:00
|
|
|
void AddStyleUpdatesTo(RestyleTracker& aTracker);
|
2014-08-07 09:58:44 +04:00
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection*
|
2015-03-20 21:20:49 +03:00
|
|
|
GetAnimations(dom::Element *aElement,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
|
|
|
bool aCreateIfNeeded);
|
2014-11-17 07:45:59 +03:00
|
|
|
|
2014-11-20 05:48:42 +03:00
|
|
|
// Returns true if aContent or any of its ancestors has an animation
|
|
|
|
// or transition.
|
|
|
|
static bool ContentOrAncestorHasAnimation(nsIContent* aContent) {
|
|
|
|
do {
|
|
|
|
if (aContent->GetProperty(nsGkAtoms::animationsProperty) ||
|
|
|
|
aContent->GetProperty(nsGkAtoms::transitionsProperty)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} while ((aContent = aContent->GetParent()));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-31 10:21:55 +03:00
|
|
|
// Requests a standard restyle on each managed AnimationCollection that has
|
|
|
|
// an out-of-date mStyleRuleRefreshTime.
|
|
|
|
void FlushAnimations();
|
2012-12-12 01:12:43 +04:00
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
nsIStyleRule* GetAnimationRule(dom::Element* aElement,
|
2014-11-20 05:48:41 +03:00
|
|
|
nsCSSPseudoElements::Type aPseudoType);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ExtractComputedValueForTransition(
|
2011-04-12 10:18:43 +04:00
|
|
|
nsCSSProperty aProperty,
|
|
|
|
nsStyleContext* aStyleContext,
|
2015-07-29 04:57:39 +03:00
|
|
|
StyleAnimationValue& aComputedValue);
|
2014-11-17 07:45:56 +03:00
|
|
|
|
2014-11-17 07:46:00 +03:00
|
|
|
// For CSS properties that may be animated on a separate layer, represents
|
|
|
|
// a record of the corresponding layer type and change hint.
|
|
|
|
struct LayerAnimationRecord {
|
|
|
|
nsCSSProperty mProperty;
|
|
|
|
nsDisplayItem::Type mLayerType;
|
|
|
|
nsChangeHint mChangeHint;
|
|
|
|
};
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
protected:
|
2014-06-24 02:40:01 +04:00
|
|
|
virtual ~CommonAnimationManager();
|
|
|
|
|
2014-06-27 03:57:13 +04:00
|
|
|
// For ElementCollectionRemoved
|
2015-07-29 04:57:39 +03:00
|
|
|
friend struct AnimationCollection;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
void AddElementCollection(AnimationCollection* aCollection);
|
2015-03-24 03:06:06 +03:00
|
|
|
void ElementCollectionRemoved() { MaybeStartOrStopObservingRefreshDriver(); }
|
2014-06-27 03:57:13 +04:00
|
|
|
void RemoveAllElementCollections();
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2015-03-24 03:06:06 +03:00
|
|
|
// We should normally only call MaybeStartOrStopObservingRefreshDriver in
|
|
|
|
// situations where we will also queue events since otherwise we may stop
|
|
|
|
// getting refresh driver ticks before we queue the necessary events.
|
|
|
|
void MaybeStartObservingRefreshDriver();
|
|
|
|
void MaybeStartOrStopObservingRefreshDriver();
|
|
|
|
bool NeedsRefresh() const;
|
2014-11-17 07:45:56 +03:00
|
|
|
|
2014-11-20 05:48:41 +03:00
|
|
|
virtual nsIAtom* GetAnimationsAtom() = 0;
|
|
|
|
virtual nsIAtom* GetAnimationsBeforeAtom() = 0;
|
|
|
|
virtual nsIAtom* GetAnimationsAfterAtom() = 0;
|
|
|
|
|
|
|
|
virtual bool IsAnimationManager() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-01 18:55:51 +03:00
|
|
|
|
|
|
|
public:
|
2015-05-08 16:56:36 +03:00
|
|
|
// Return an AnimationCollection* if we have an animation for
|
2015-07-01 18:55:51 +03:00
|
|
|
// the frame aFrame that can be performed on the compositor thread (as
|
|
|
|
// defined by AnimationCollection::CanPerformOnCompositorThread).
|
2015-05-08 16:56:36 +03:00
|
|
|
//
|
2015-07-01 18:55:51 +03:00
|
|
|
// Note that this does not test whether the frame's layer uses
|
2015-05-08 16:56:36 +03:00
|
|
|
// off-main-thread compositing, although it does check whether
|
|
|
|
// off-main-thread compositing is enabled as a whole.
|
2015-07-01 18:55:51 +03:00
|
|
|
AnimationCollection*
|
|
|
|
GetAnimationsForCompositor(const nsIFrame* aFrame,
|
2015-04-07 04:13:48 +03:00
|
|
|
nsCSSProperty aProperty);
|
2014-06-20 07:39:25 +04:00
|
|
|
|
2015-07-01 21:43:13 +03:00
|
|
|
// Given the frame aFrame with possibly animated content, finds its
|
|
|
|
// associated collection of animations. If it is a generated content
|
|
|
|
// frame, it may examine the parent frame to search for such animations.
|
|
|
|
AnimationCollection*
|
|
|
|
GetAnimationCollection(const nsIFrame* aFrame);
|
|
|
|
|
2015-07-01 18:55:51 +03:00
|
|
|
protected:
|
2015-08-18 07:13:14 +03:00
|
|
|
LinkedList<AnimationCollection> mElementCollections;
|
2011-04-12 10:18:43 +04:00
|
|
|
nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect)
|
2014-11-17 07:45:56 +03:00
|
|
|
bool mIsObservingRefreshDriver;
|
2011-04-12 10:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-06-24 10:29:54 +04:00
|
|
|
* A style rule that maps property-StyleAnimationValue pairs.
|
2011-04-12 10:18:43 +04:00
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class AnimValuesStyleRule final : public nsIStyleRule
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports implementation
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIStyleRule implementation
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
|
2011-04-12 10:18:43 +04:00
|
|
|
#ifdef DEBUG
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
|
2011-04-12 10:18:43 +04:00
|
|
|
#endif
|
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
void AddValue(nsCSSProperty aProperty, StyleAnimationValue &aStartValue)
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
PropertyValuePair v = { aProperty, aStartValue };
|
|
|
|
mPropertyValuePairs.AppendElement(v);
|
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
// Caller must fill in returned value.
|
2015-07-29 04:57:39 +03:00
|
|
|
StyleAnimationValue* AddEmptyValue(nsCSSProperty aProperty)
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
PropertyValuePair *p = mPropertyValuePairs.AppendElement();
|
|
|
|
p->mProperty = aProperty;
|
|
|
|
return &p->mValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PropertyValuePair {
|
|
|
|
nsCSSProperty mProperty;
|
2015-07-29 04:57:39 +03:00
|
|
|
StyleAnimationValue mValue;
|
2011-04-12 10:18:43 +04:00
|
|
|
};
|
|
|
|
|
2015-03-20 07:10:00 +03:00
|
|
|
void AddPropertiesToSet(nsCSSPropertySet& aSet) const
|
|
|
|
{
|
|
|
|
for (size_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
|
|
|
|
const PropertyValuePair &cv = mPropertyValuePairs[i];
|
|
|
|
aSet.AddProperty(cv.mProperty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
private:
|
2014-06-24 02:40:01 +04:00
|
|
|
~AnimValuesStyleRule() {}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
InfallibleTArray<PropertyValuePair> mPropertyValuePairs;
|
2011-04-12 10:18:43 +04:00
|
|
|
};
|
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
typedef InfallibleTArray<nsRefPtr<dom::Animation>> AnimationPtrArray;
|
2014-05-15 03:38:37 +04:00
|
|
|
|
2015-08-18 07:13:14 +03:00
|
|
|
struct AnimationCollection : public LinkedListElement<AnimationCollection>
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection(dom::Element *aElement, nsIAtom *aElementProperty,
|
2015-07-29 04:57:39 +03:00
|
|
|
CommonAnimationManager *aManager)
|
2011-04-12 10:18:43 +04:00
|
|
|
: mElement(aElement)
|
|
|
|
, mElementProperty(aElementProperty)
|
|
|
|
, mManager(aManager)
|
2013-02-26 10:21:26 +04:00
|
|
|
, mAnimationGeneration(0)
|
2015-02-17 01:15:03 +03:00
|
|
|
, mCheckGeneration(0)
|
2014-06-20 07:39:24 +04:00
|
|
|
, mNeedsRefreshes(true)
|
2015-08-17 07:59:44 +03:00
|
|
|
, mHasPendingAnimationRestyle(false)
|
2011-05-01 02:16:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mCalledPropertyDtor(false)
|
|
|
|
#endif
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2015-04-21 04:22:10 +03:00
|
|
|
MOZ_COUNT_CTOR(AnimationCollection);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
2015-04-21 04:22:10 +03:00
|
|
|
~AnimationCollection()
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mCalledPropertyDtor,
|
|
|
|
"must call destructor through element property dtor");
|
2015-04-21 04:22:10 +03:00
|
|
|
MOZ_COUNT_DTOR(AnimationCollection);
|
2015-08-18 07:13:14 +03:00
|
|
|
remove();
|
2014-06-27 03:57:13 +04:00
|
|
|
mManager->ElementCollectionRemoved();
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Destroy()
|
|
|
|
{
|
|
|
|
// This will call our destructor.
|
|
|
|
mElement->DeleteProperty(mElementProperty);
|
|
|
|
}
|
|
|
|
|
2014-06-24 10:29:53 +04:00
|
|
|
static void PropertyDtor(void *aObject, nsIAtom *aPropertyName,
|
|
|
|
void *aPropertyValue, void *aData);
|
|
|
|
|
2014-08-10 11:06:48 +04:00
|
|
|
void Tick();
|
|
|
|
|
2015-08-18 10:11:55 +03:00
|
|
|
void EnsureStyleRuleFor(TimeStamp aRefreshTime);
|
2014-06-20 07:39:24 +04:00
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
enum CanAnimateFlags {
|
|
|
|
// Testing for width, height, top, right, bottom, or left.
|
|
|
|
CanAnimate_HasGeometricProperty = 1,
|
|
|
|
// Allow the case where OMTA is allowed in general, but not for the
|
|
|
|
// specified property.
|
|
|
|
CanAnimate_AllowPartial = 2
|
|
|
|
};
|
|
|
|
|
2015-08-17 07:59:44 +03:00
|
|
|
enum class RestyleType {
|
|
|
|
// Animation style has changed but the compositor is applying the same
|
|
|
|
// change so we might be able to defer updating the main thread until it
|
|
|
|
// becomes necessary.
|
|
|
|
Throttled,
|
|
|
|
// Animation style has changed and needs to be updated on the main thread.
|
2015-08-18 10:11:55 +03:00
|
|
|
Standard,
|
|
|
|
// Animation style has changed and needs to be updated on the main thread
|
|
|
|
// as well as forcing animations on layers to be updated.
|
|
|
|
// This is needed in cases such as when an animation becomes paused or has
|
|
|
|
// its playback rate changed. In such a case, although the computed style
|
|
|
|
// and refresh driver time might not change, we still need to ensure the
|
|
|
|
// corresponding animations on layers are updated to reflect the new
|
|
|
|
// configuration of the animation.
|
|
|
|
Layer
|
2015-08-17 07:59:44 +03:00
|
|
|
};
|
|
|
|
void RequestRestyle(RestyleType aRestyleType);
|
|
|
|
|
2015-05-08 16:56:36 +03:00
|
|
|
private:
|
2012-07-31 21:28:21 +04:00
|
|
|
static bool
|
|
|
|
CanAnimatePropertyOnCompositor(const dom::Element *aElement,
|
2012-08-22 05:48:47 +04:00
|
|
|
nsCSSProperty aProperty,
|
2012-12-12 01:12:43 +04:00
|
|
|
CanAnimateFlags aFlags);
|
|
|
|
|
2015-08-17 07:59:44 +03:00
|
|
|
bool CanThrottleAnimation(TimeStamp aTime);
|
|
|
|
bool CanThrottleTransformChanges(TimeStamp aTime);
|
|
|
|
|
2015-05-08 16:56:36 +03:00
|
|
|
public:
|
2013-10-22 14:30:45 +04:00
|
|
|
static bool IsCompositorAnimationDisabledForFrame(nsIFrame* aFrame);
|
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
// True if this animation can be performed on the compositor thread.
|
2014-06-20 07:39:25 +04:00
|
|
|
//
|
|
|
|
// If aFlags contains CanAnimate_AllowPartial, returns whether the
|
|
|
|
// state of this element's animations at the current refresh driver
|
|
|
|
// time contains animation data that can be done on the compositor
|
|
|
|
// thread. (This is useful for determining whether a layer should be
|
|
|
|
// active, or whether to send data to the layer.)
|
|
|
|
//
|
|
|
|
// If aFlags does not contain CanAnimate_AllowPartial, returns whether
|
|
|
|
// the state of this element's animations at the current refresh driver
|
|
|
|
// time can be fully represented by data sent to the compositor.
|
|
|
|
// (This is useful for determining whether throttle the animation
|
|
|
|
// (suppress main-thread style updates).)
|
2015-05-08 16:56:36 +03:00
|
|
|
//
|
|
|
|
// Note that this does not test whether the element's layer uses
|
|
|
|
// off-main-thread compositing, although it does check whether
|
|
|
|
// off-main-thread compositing is enabled as a whole.
|
2014-06-20 07:39:25 +04:00
|
|
|
bool CanPerformOnCompositorThread(CanAnimateFlags aFlags) const;
|
2015-04-01 01:05:54 +03:00
|
|
|
|
Bug 1181392 part 5 - Remove use of IsFinishedTransition from AnimationCollection::HasAnimationOfProperty; r=dbaron
AnimationCollection::HasAnimationOfProperty uses IsFinishedTransition to filter
out transitions that should otherwise be ignored. This is used in the following
places:
1. nsLayoutUtils::HasAnimations
The is only used by nsIFrame::BuildDisplayListForStackingContext to see if
there are any opacity animations
For this case, simply returning *current* animations would be sufficient
(since finished but filling animations should have already filled in the
display opacity)
2. CommonAnimationManager::GetAnimationsForCompositor
This should really only return *current* animations--that is, animations that
are running or scheduled to run. Finished animations never run on the
compositor. Indeed, only *playing* animations run on the compositor but, as
we will see in some of the cases below, it is sometimes useful to know that
an animation *will* run on the compositor in the near future (e.g. so we can
pre-render content).
The places where GetAnimationsForCompositor is used are:
- When building layers to add animations to layers in nsDisplayList--in this
case we skip any animations that aren't playing so if
GetAnimationsForCompositor only returned current animations that would be
more than sufficient.
- In nsLayoutUtils::HasAnimationsForCompositor. This in turn is used:
- In ChooseScaleAndSetTransform to see if the transform is being animated
on the compositor. If so, it calls
nsLayoutUtils::ComputeSuitableScaleForAnimation (which also calls
GetAnimationsForCompositor) and passes the result to
GetMinAndMaxScaleForAnimationProperty which we have already adjusted in
part 4 of this patch series to only deal with *relevant* animations
Relevant animations include both current animations and in effect
animations but we don't run forwards-filling animations on the compositor
so GetAnimationsForCompositor should NOT return them. Current animations
should be enough. In fact, playing animations should be enough but we
might want to pre-render layers at a suitable size during their delay
phase so returning current animations is probably ok.
- In nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay to add a fuzz
factor to the overflow rect for frames undergoing a transform animation
on the compositor. In this case too current animations should be
sufficient.
- In nsDisplayOpacity::NeedsActiveLayer to say "yes" if we are animating
opacity on the compositor. Presumably in this case it would be good to
say "yes" if the animation is in the delay phase too (as it currently
does). After the animation is finished, we should drop the layer, i.e.
current animations should be sufficient.
- In nsDisplayTransform::ShouldPrerenderTransformedContent. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to pre-render
transformed content for animations that are current.
- In nsDisplayTransform::GetLayerState. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to return active here
for current animations.
- In nsIFrame::IsTransformed. Here we test the display style to see if
there is a transform and also check if transform is being animated on the
compositor. As a result, we really only need HasAnimationsForCompositor
to return true for animations that are playing--otherwise the display
style will tell us if we're transformed or not. Returning true for all
current compositor animations (which is a superset of playing), however,
should not cause problems (we already return true for even more than
that).
- In nsIFrame::HasOpacityInternal which is much the same as
nsIFrame::IsTransformed and hence current should be fine.
3. AnimationCollection::CanThrottleAnimation
Here, HasAnimationOfProperty is used when looking for animations that would
disqualify us from throttling the animation by having an out-of-date layer
generation or being a transform animation that affects scroll and so requires
that we do the occasional main thread sample to update scrollbars.
It would seem like current animations are enough here too. One interesting
case is where we *had* a compositor animation but it has finished or been
cancelled. In that case, the animation won't be current and we should not
throttle the animation since we need to take it off its layer.
It turns out checking for current animations is still ok in this case too.
The reasoning is as follows:
- If the animation is newly-finished, we'll pick that up in
Animation::CanThrottle and return false then.
- If the animation is newly-idle then there are two cases:
If the cancelled animation was the only compositor animation then
AnimationCollection::CanPerformOnCompositorThread will notice that there
are no playing compositor animations and return false and
AnimationCollection::CanThrottleAnimation will never be called.
If there are other compositor animations running, then
AnimationCollection::CanThrottleAnimation will still return false because
whatever cancelled the animation will update the animation generation and
we'll notice the mismatch between the layer animation generation and the
animation generation on the collection.
Based on the above analysis it appears that making
AnimationCollection::HasAnimationOfProperty return only current animations (and
simulatneously renaming it to HasCurrentAnimationOfProperty) is safe. Indeed, in
effect, we already do this for transitions but not for animations. This patch
generalizes this behavior to all animations.
This patch also updates test_animations_omta.html since it was incorrectly
testing that a finished opacity animation was still running on the compositor.
Finished animations should not run on the compositor and the changes in this
patch cause that to happen. The reason we don't just update this test to check
for RunningOn.MainThread is that for opacity animations, unlike transform
animations, we can't detect if an opacity on a layer was set by animation or
not. As a result, for opacity animations we typically test the opacity on
either the main thread or compositor in order to allow for the case where an
animation-set opacity is still lingering on the compositor.
2015-08-07 06:29:36 +03:00
|
|
|
bool HasCurrentAnimationOfProperty(nsCSSProperty aProperty) const;
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2014-06-23 09:10:18 +04:00
|
|
|
bool IsForElement() const { // rather than for a pseudo-element
|
|
|
|
return mElementProperty == nsGkAtoms::animationsProperty ||
|
|
|
|
mElementProperty == nsGkAtoms::transitionsProperty;
|
|
|
|
}
|
|
|
|
|
2014-08-25 08:48:22 +04:00
|
|
|
bool IsForBeforePseudo() const {
|
|
|
|
return mElementProperty == nsGkAtoms::animationsOfBeforeProperty ||
|
|
|
|
mElementProperty == nsGkAtoms::transitionsOfBeforeProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsForAfterPseudo() const {
|
|
|
|
return mElementProperty == nsGkAtoms::animationsOfAfterProperty ||
|
|
|
|
mElementProperty == nsGkAtoms::transitionsOfAfterProperty;
|
|
|
|
}
|
|
|
|
|
2014-08-07 09:58:44 +04:00
|
|
|
bool IsForTransitions() const {
|
|
|
|
return mElementProperty == nsGkAtoms::transitionsProperty ||
|
|
|
|
mElementProperty == nsGkAtoms::transitionsOfBeforeProperty ||
|
|
|
|
mElementProperty == nsGkAtoms::transitionsOfAfterProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsForAnimations() const {
|
|
|
|
return mElementProperty == nsGkAtoms::animationsProperty ||
|
|
|
|
mElementProperty == nsGkAtoms::animationsOfBeforeProperty ||
|
|
|
|
mElementProperty == nsGkAtoms::animationsOfAfterProperty;
|
|
|
|
}
|
|
|
|
|
2015-03-20 07:10:00 +03:00
|
|
|
nsCSSPseudoElements::Type PseudoElementType() const
|
|
|
|
{
|
|
|
|
if (IsForElement()) {
|
|
|
|
return nsCSSPseudoElements::ePseudo_NotPseudoElement;
|
|
|
|
}
|
|
|
|
if (IsForBeforePseudo()) {
|
|
|
|
return nsCSSPseudoElements::ePseudo_before;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(IsForAfterPseudo(),
|
|
|
|
"::before & ::after should be the only pseudo-elements here");
|
|
|
|
return nsCSSPseudoElements::ePseudo_after;
|
|
|
|
}
|
|
|
|
|
2015-07-29 04:57:40 +03:00
|
|
|
static nsString PseudoTypeAsString(nsCSSPseudoElements::Type aPseudoType);
|
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
dom::Element* GetElementToRestyle() const;
|
2014-08-25 08:48:22 +04:00
|
|
|
|
2014-06-23 09:10:19 +04:00
|
|
|
void PostRestyleForAnimation(nsPresContext *aPresContext) {
|
2015-07-29 04:57:39 +03:00
|
|
|
dom::Element* element = GetElementToRestyle();
|
2014-08-25 08:48:22 +04:00
|
|
|
if (element) {
|
2014-11-17 22:39:14 +03:00
|
|
|
nsRestyleHint hint = IsForTransitions() ? eRestyle_CSSTransitions
|
|
|
|
: eRestyle_CSSAnimations;
|
|
|
|
aPresContext->PresShell()->RestyleForAnimation(element, hint);
|
2014-08-25 08:48:22 +04:00
|
|
|
}
|
2014-06-23 09:10:19 +04:00
|
|
|
}
|
|
|
|
|
2012-08-26 05:27:28 +04:00
|
|
|
static void LogAsyncAnimationFailure(nsCString& aMessage,
|
|
|
|
const nsIContent* aContent = nullptr);
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
dom::Element *mElement;
|
|
|
|
|
|
|
|
// the atom we use in mElement's prop table (must be a static atom,
|
|
|
|
// i.e., in an atom list)
|
|
|
|
nsIAtom *mElementProperty;
|
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
CommonAnimationManager *mManager;
|
2011-05-01 02:16:19 +04:00
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
AnimationPtrArray mAnimations;
|
2014-05-15 03:38:37 +04:00
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
// This style rule contains the style data for currently animating
|
|
|
|
// values. It only matches when styling with animation. When we
|
|
|
|
// style without animation, we need to not use it so that we can
|
|
|
|
// detect any new changes; if necessary we restyle immediately
|
|
|
|
// afterwards with animation.
|
|
|
|
// NOTE: If we don't need to apply any styles, mStyleRule will be
|
|
|
|
// null, but mStyleRuleRefreshTime will still be valid.
|
2015-07-29 04:57:39 +03:00
|
|
|
nsRefPtr<AnimValuesStyleRule> mStyleRule;
|
2012-12-12 01:12:43 +04:00
|
|
|
|
2014-04-03 09:57:28 +04:00
|
|
|
// RestyleManager keeps track of the number of animation
|
|
|
|
// 'mini-flushes' (see nsTransitionManager::UpdateAllThrottledStyles()).
|
|
|
|
// mAnimationGeneration is the sequence number of the last flush where a
|
|
|
|
// transition/animation changed. We keep a similar count on the
|
|
|
|
// corresponding layer so we can check that the layer is up to date with
|
|
|
|
// the animation manager.
|
2012-12-12 01:12:43 +04:00
|
|
|
uint64_t mAnimationGeneration;
|
2014-04-03 09:57:28 +04:00
|
|
|
// Update mAnimationGeneration to nsCSSFrameConstructor's count
|
2012-12-12 01:12:43 +04:00
|
|
|
void UpdateAnimationGeneration(nsPresContext* aPresContext);
|
|
|
|
|
2015-02-17 01:15:03 +03:00
|
|
|
// For CSS transitions only, we also record the most recent generation
|
|
|
|
// for which we've done the transition update, so that we avoid doing
|
|
|
|
// it more than once per style change. This should be greater than or
|
|
|
|
// equal to mAnimationGeneration, except when the generation counter
|
|
|
|
// cycles, or when animations are updated through the DOM Animation
|
|
|
|
// interfaces.
|
|
|
|
uint64_t mCheckGeneration;
|
|
|
|
// Update mAnimationGeneration to nsCSSFrameConstructor's count
|
|
|
|
void UpdateCheckGeneration(nsPresContext* aPresContext);
|
|
|
|
|
2014-10-02 10:14:13 +04:00
|
|
|
// Returns true if there is an animation that has yet to finish.
|
|
|
|
bool HasCurrentAnimations() const;
|
2015-04-06 05:53:51 +03:00
|
|
|
// Returns true if there is an animation of any of the specified properties
|
|
|
|
// that has yet to finish.
|
|
|
|
bool HasCurrentAnimationsForProperties(const nsCSSProperty* aProperties,
|
|
|
|
size_t aPropertyCount) const;
|
2014-06-16 22:43:04 +04:00
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
// The refresh time associated with mStyleRule.
|
|
|
|
TimeStamp mStyleRuleRefreshTime;
|
|
|
|
|
2014-06-20 07:39:24 +04:00
|
|
|
// False when we know that our current style rule is valid
|
|
|
|
// indefinitely into the future (because all of our animations are
|
|
|
|
// either completed or paused). May be invalidated by a style change.
|
|
|
|
bool mNeedsRefreshes;
|
|
|
|
|
2015-08-17 07:59:44 +03:00
|
|
|
private:
|
|
|
|
// Whether or not we have already posted for animation restyle.
|
|
|
|
// This is used to avoid making redundant requests and is reset each time
|
|
|
|
// the animation restyle is performed.
|
|
|
|
bool mHasPendingAnimationRestyle;
|
|
|
|
|
2011-05-01 02:16:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mCalledPropertyDtor;
|
|
|
|
#endif
|
2011-04-12 10:18:43 +04:00
|
|
|
};
|
|
|
|
|
2015-06-09 05:13:54 +03:00
|
|
|
/**
|
|
|
|
* Utility class for referencing the element that created a CSS animation or
|
|
|
|
* transition. It is non-owning (i.e. it uses a raw pointer) since it is only
|
|
|
|
* expected to be set by the owned animation while it actually being managed
|
|
|
|
* by the owning element.
|
|
|
|
*
|
|
|
|
* This class also abstracts the comparison of an element/pseudo-class pair
|
|
|
|
* for the sake of composite ordering since this logic is common to both CSS
|
|
|
|
* animations and transitions.
|
|
|
|
*
|
|
|
|
* (We call this OwningElementRef instead of just OwningElement so that we can
|
|
|
|
* call the getter on CSSAnimation/CSSTransition OwningElement() without
|
|
|
|
* clashing with this object's contructor.)
|
|
|
|
*/
|
|
|
|
class OwningElementRef final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OwningElementRef()
|
|
|
|
: mElement(nullptr)
|
|
|
|
, mPseudoType(nsCSSPseudoElements::ePseudo_NotPseudoElement)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
OwningElementRef(dom::Element& aElement,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType)
|
|
|
|
: mElement(&aElement)
|
|
|
|
, mPseudoType(aPseudoType)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
bool Equals(const OwningElementRef& aOther) const
|
|
|
|
{
|
|
|
|
return mElement == aOther.mElement &&
|
|
|
|
mPseudoType == aOther.mPseudoType;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LessThan(const OwningElementRef& aOther) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mElement && aOther.mElement,
|
|
|
|
"Elements to compare should not be null");
|
|
|
|
|
|
|
|
if (mElement != aOther.mElement) {
|
|
|
|
return nsContentUtils::PositionIsBefore(mElement, aOther.mElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
|
|
|
|
(mPseudoType == nsCSSPseudoElements::ePseudo_before &&
|
|
|
|
aOther.mPseudoType == nsCSSPseudoElements::ePseudo_after);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsSet() const { return !!mElement; }
|
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
void GetElement(dom::Element*& aElement,
|
|
|
|
nsCSSPseudoElements::Type& aPseudoType) const {
|
|
|
|
aElement = mElement;
|
|
|
|
aPseudoType = mPseudoType;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* GetRenderedPresContext() const;
|
|
|
|
|
2015-06-09 05:13:54 +03:00
|
|
|
private:
|
|
|
|
dom::Element* MOZ_NON_OWNING_REF mElement;
|
|
|
|
nsCSSPseudoElements::Type mPseudoType;
|
|
|
|
};
|
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
template <class EventInfo>
|
|
|
|
class DelayedEventDispatcher
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void QueueEvent(EventInfo&& aEventInfo)
|
|
|
|
{
|
|
|
|
mPendingEvents.AppendElement(mozilla::Forward<EventInfo>(aEventInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Takes a reference to the owning manager's pres context so it can
|
|
|
|
// detect if the pres context is destroyed while dispatching one of
|
|
|
|
// the events.
|
|
|
|
void DispatchEvents(nsPresContext* const & aPresContext)
|
|
|
|
{
|
|
|
|
if (!aPresContext || mPendingEvents.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventArray events;
|
|
|
|
mPendingEvents.SwapElements(events);
|
|
|
|
// FIXME: Sort events here in timeline order, then document order
|
|
|
|
for (EventInfo& info : events) {
|
|
|
|
EventDispatcher::Dispatch(info.mElement, aPresContext, &info.mEvent);
|
|
|
|
|
|
|
|
if (!aPresContext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearEventQueue() { mPendingEvents.Clear(); }
|
|
|
|
bool HasQueuedEvents() const { return !mPendingEvents.IsEmpty(); }
|
|
|
|
|
|
|
|
// Methods for supporting cycle-collection
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback* aCallback,
|
|
|
|
const char* aName)
|
|
|
|
{
|
|
|
|
for (EventInfo& info : mPendingEvents) {
|
|
|
|
ImplCycleCollectionTraverse(*aCallback, info.mElement, aName);
|
2015-09-15 08:05:44 +03:00
|
|
|
ImplCycleCollectionTraverse(*aCallback, info.mAnimation, aName);
|
2015-07-29 04:57:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void Unlink() { mPendingEvents.Clear(); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
typedef nsTArray<EventInfo> EventArray;
|
|
|
|
|
|
|
|
EventArray mPendingEvents;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class EventInfo>
|
|
|
|
inline void
|
|
|
|
ImplCycleCollectionUnlink(DelayedEventDispatcher<EventInfo>& aField)
|
|
|
|
{
|
|
|
|
aField.Unlink();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class EventInfo>
|
|
|
|
inline void
|
|
|
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
|
|
|
DelayedEventDispatcher<EventInfo>& aField,
|
|
|
|
const char* aName,
|
|
|
|
uint32_t aFlags = 0)
|
|
|
|
{
|
|
|
|
aField.Traverse(&aCallback, aName);
|
|
|
|
}
|
|
|
|
|
2015-06-09 05:13:54 +03:00
|
|
|
} // namespace mozilla
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
#endif /* !defined(mozilla_css_AnimationCommon_h) */
|