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"
|
|
|
|
#include "prclist.h"
|
|
|
|
#include "nsCSSProperty.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"
|
2014-07-16 04:02:30 +04:00
|
|
|
#include "mozilla/dom/AnimationTimeline.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "nsSMILKeySpline.h"
|
|
|
|
#include "nsStyleStruct.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-06-11 09:19:07 +04:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2014-07-16 04:02:30 +04:00
|
|
|
#include "nsCycleCollectionParticipant.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;
|
|
|
|
class nsStyleChangeList;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2014-07-16 04:02:31 +04:00
|
|
|
// X11 has a #define for CurrentTime.
|
|
|
|
#ifdef CurrentTime
|
|
|
|
#undef CurrentTime
|
|
|
|
#endif
|
2012-08-22 05:48:47 +04:00
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
namespace mozilla {
|
2014-06-24 10:29:54 +04:00
|
|
|
|
|
|
|
class StyleAnimationValue;
|
2014-06-27 03:57:12 +04:00
|
|
|
struct ElementPropertyTransition;
|
2014-06-27 03:57:12 +04:00
|
|
|
struct ElementAnimationCollection;
|
2014-06-24 10:29:54 +04:00
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
namespace css {
|
|
|
|
|
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:
|
|
|
|
CommonAnimationManager(nsPresContext *aPresContext);
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIStyleRuleProcessor (parts)
|
2013-05-14 20:33:23 +04:00
|
|
|
virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE;
|
2013-11-28 10:46:39 +04:00
|
|
|
virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) MOZ_OVERRIDE;
|
2012-09-14 20:10:08 +04:00
|
|
|
virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE;
|
2011-04-12 10:18:43 +04:00
|
|
|
virtual nsRestyleHint
|
2012-09-14 20:10:08 +04:00
|
|
|
HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE;
|
|
|
|
virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE;
|
2013-06-23 16:03:39 +04:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2013-03-24 06:14:43 +04:00
|
|
|
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
2013-06-23 16:03:39 +04:00
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2013-03-24 06:14:43 +04:00
|
|
|
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify the manager that the pres context is going away.
|
|
|
|
*/
|
|
|
|
void Disconnect();
|
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
enum FlushFlags {
|
|
|
|
Can_Throttle,
|
|
|
|
Cannot_Throttle
|
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ExtractComputedValueForTransition(
|
2011-04-12 10:18:43 +04:00
|
|
|
nsCSSProperty aProperty,
|
|
|
|
nsStyleContext* aStyleContext,
|
2014-06-24 10:29:54 +04:00
|
|
|
mozilla::StyleAnimationValue& aComputedValue);
|
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
|
|
|
|
friend struct mozilla::ElementAnimationCollection;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2014-06-27 03:57:13 +04:00
|
|
|
virtual void
|
|
|
|
AddElementCollection(ElementAnimationCollection* aCollection) = 0;
|
|
|
|
virtual void ElementCollectionRemoved() = 0;
|
|
|
|
void RemoveAllElementCollections();
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2014-06-20 07:39:26 +04:00
|
|
|
// When this returns a value other than nullptr, it also,
|
|
|
|
// as a side-effect, notifies the ActiveLayerTracker.
|
2014-06-27 03:57:12 +04:00
|
|
|
static ElementAnimationCollection*
|
2014-06-20 07:39:25 +04:00
|
|
|
GetAnimationsForCompositor(nsIContent* aContent,
|
|
|
|
nsIAtom* aElementProperty,
|
|
|
|
nsCSSProperty aProperty);
|
|
|
|
|
2013-10-22 16:14:41 +04:00
|
|
|
// Update the style on aElement from the transition stored in this manager and
|
|
|
|
// the new parent style - aParentStyle. aElement must be transitioning or
|
|
|
|
// animated. Returns the updated style.
|
|
|
|
nsStyleContext* UpdateThrottledStyle(mozilla::dom::Element* aElement,
|
|
|
|
nsStyleContext* aParentStyle,
|
|
|
|
nsStyleChangeList &aChangeList);
|
|
|
|
// Reparent the style of aContent and any :before and :after pseudo-elements.
|
|
|
|
already_AddRefed<nsStyleContext> ReparentContent(nsIContent* aContent,
|
|
|
|
nsStyleContext* aParentStyle);
|
|
|
|
// reparent :before and :after pseudo elements of aElement
|
|
|
|
static void ReparentBeforeAndAfter(dom::Element* aElement,
|
|
|
|
nsIFrame* aPrimaryFrame,
|
|
|
|
nsStyleContext* aNewStyle,
|
|
|
|
nsStyleSet* aStyleSet);
|
|
|
|
|
2014-06-27 03:57:13 +04:00
|
|
|
PRCList mElementCollections;
|
2011-04-12 10:18:43 +04:00
|
|
|
nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect)
|
|
|
|
};
|
|
|
|
|
2013-10-22 16:14:41 +04:00
|
|
|
// The internals of UpdateAllThrottledStyles, used by nsAnimationManager and
|
|
|
|
// nsTransitionManager, see the comments in the declaration of the latter.
|
|
|
|
#define IMPL_UPDATE_ALL_THROTTLED_STYLES_INTERNAL(class_, animations_getter_) \
|
|
|
|
void \
|
|
|
|
class_::UpdateAllThrottledStylesInternal() \
|
|
|
|
{ \
|
|
|
|
TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh(); \
|
|
|
|
\
|
|
|
|
nsStyleChangeList changeList; \
|
|
|
|
\
|
|
|
|
/* update each transitioning element by finding its root-most ancestor
|
|
|
|
with a transition, and flushing the style on that ancestor and all
|
|
|
|
its descendants*/ \
|
2014-06-27 03:57:13 +04:00
|
|
|
PRCList *next = PR_LIST_HEAD(&mElementCollections); \
|
|
|
|
while (next != &mElementCollections) { \
|
2014-06-27 03:57:13 +04:00
|
|
|
ElementAnimationCollection* collection = \
|
2014-06-27 03:57:12 +04:00
|
|
|
static_cast<ElementAnimationCollection*>(next); \
|
2013-10-22 16:14:41 +04:00
|
|
|
next = PR_NEXT_LINK(next); \
|
|
|
|
\
|
2014-06-27 03:57:13 +04:00
|
|
|
if (collection->mFlushGeneration == now) { \
|
2013-10-22 16:14:41 +04:00
|
|
|
/* this element has been ticked already */ \
|
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
/* element is initialised to the starting element (i.e., one we know has
|
|
|
|
an animation) and ends up with the root-most animated ancestor,
|
|
|
|
that is, the element where we begin updates. */ \
|
2014-06-27 03:57:13 +04:00
|
|
|
dom::Element* element = collection->mElement; \
|
2013-10-22 16:14:41 +04:00
|
|
|
/* make a list of ancestors */ \
|
|
|
|
nsTArray<dom::Element*> ancestors; \
|
|
|
|
do { \
|
|
|
|
ancestors.AppendElement(element); \
|
|
|
|
} while ((element = element->GetParentElement())); \
|
|
|
|
\
|
|
|
|
/* walk down the ancestors until we find one with a throttled transition */\
|
|
|
|
for (int32_t i = ancestors.Length() - 1; i >= 0; --i) { \
|
|
|
|
if (animations_getter_(ancestors[i], \
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement, \
|
|
|
|
false)) { \
|
|
|
|
element = ancestors[i]; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
nsIFrame* primaryFrame; \
|
|
|
|
if (element && \
|
|
|
|
(primaryFrame = nsLayoutUtils::GetStyleFrame(element))) { \
|
|
|
|
UpdateThrottledStylesForSubtree(element, \
|
|
|
|
primaryFrame->StyleContext()->GetParent(), changeList); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
RestyleManager* restyleManager = mPresContext->RestyleManager(); \
|
|
|
|
restyleManager->ProcessRestyledFrames(changeList); \
|
|
|
|
restyleManager->FlushOverflowChangedTracker(); \
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2012-06-19 06:30:09 +04:00
|
|
|
class AnimValuesStyleRule MOZ_FINAL : public nsIStyleRule
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports implementation
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIStyleRule implementation
|
2013-05-14 20:33:23 +04:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE;
|
2011-04-12 10:18:43 +04:00
|
|
|
#ifdef DEBUG
|
2012-09-14 20:10:08 +04:00
|
|
|
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
|
2011-04-12 10:18:43 +04:00
|
|
|
#endif
|
|
|
|
|
2014-06-24 10:29:54 +04:00
|
|
|
void AddValue(nsCSSProperty aProperty,
|
|
|
|
mozilla::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.
|
2014-06-24 10:29:54 +04:00
|
|
|
mozilla::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;
|
2014-06-24 10:29:54 +04:00
|
|
|
mozilla::StyleAnimationValue mValue;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
class ComputedTimingFunction {
|
|
|
|
public:
|
|
|
|
typedef nsTimingFunction::Type Type;
|
|
|
|
void Init(const nsTimingFunction &aFunction);
|
|
|
|
double GetValue(double aPortion) const;
|
2012-07-31 21:28:21 +04:00
|
|
|
const nsSMILKeySpline* GetFunction() const {
|
|
|
|
NS_ASSERTION(mType == nsTimingFunction::Function, "Type mismatch");
|
|
|
|
return &mTimingFunction;
|
|
|
|
}
|
|
|
|
Type GetType() const { return mType; }
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetSteps() const { return mSteps; }
|
2011-04-12 10:18:43 +04:00
|
|
|
private:
|
|
|
|
Type mType;
|
|
|
|
nsSMILKeySpline mTimingFunction;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSteps;
|
2011-04-12 10:18:43 +04:00
|
|
|
};
|
|
|
|
|
2014-04-03 09:57:28 +04:00
|
|
|
} /* end css sub-namespace */
|
|
|
|
|
2014-04-03 09:57:28 +04:00
|
|
|
struct AnimationPropertySegment
|
|
|
|
{
|
|
|
|
float mFromKey, mToKey;
|
2014-06-24 10:29:54 +04:00
|
|
|
mozilla::StyleAnimationValue mFromValue, mToValue;
|
2014-04-03 09:57:28 +04:00
|
|
|
mozilla::css::ComputedTimingFunction mTimingFunction;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AnimationProperty
|
|
|
|
{
|
|
|
|
nsCSSProperty mProperty;
|
|
|
|
InfallibleTArray<AnimationPropertySegment> mSegments;
|
|
|
|
};
|
|
|
|
|
2014-05-28 11:51:49 +04:00
|
|
|
/**
|
|
|
|
* Input timing parameters.
|
|
|
|
*
|
|
|
|
* Eventually this will represent all the input timing parameters specified
|
|
|
|
* by content but for now it encapsulates just the subset of those
|
|
|
|
* parameters passed to GetPositionInIteration.
|
|
|
|
*/
|
|
|
|
struct AnimationTiming
|
|
|
|
{
|
|
|
|
mozilla::TimeDuration mIterationDuration;
|
2014-06-20 07:39:23 +04:00
|
|
|
mozilla::TimeDuration mDelay;
|
2014-06-11 09:19:07 +04:00
|
|
|
float mIterationCount; // mozilla::PositiveInfinity<float>() means infinite
|
2014-05-28 11:51:49 +04:00
|
|
|
uint8_t mDirection;
|
|
|
|
uint8_t mFillMode;
|
2014-05-28 11:51:49 +04:00
|
|
|
|
|
|
|
bool FillsForwards() const {
|
|
|
|
return mFillMode == NS_STYLE_ANIMATION_FILL_MODE_BOTH ||
|
|
|
|
mFillMode == NS_STYLE_ANIMATION_FILL_MODE_FORWARDS;
|
|
|
|
}
|
|
|
|
bool FillsBackwards() const {
|
|
|
|
return mFillMode == NS_STYLE_ANIMATION_FILL_MODE_BOTH ||
|
|
|
|
mFillMode == NS_STYLE_ANIMATION_FILL_MODE_BACKWARDS;
|
|
|
|
}
|
2014-05-28 11:51:49 +04:00
|
|
|
};
|
|
|
|
|
2014-05-28 11:51:49 +04:00
|
|
|
/**
|
|
|
|
* Stores the results of calculating the timing properties of an animation
|
|
|
|
* at a given sample time.
|
2014-06-25 04:42:19 +04:00
|
|
|
*
|
|
|
|
* The members of a default-constructed object of this type are not meaningful.
|
|
|
|
* Rather, this object is intended to be used as the return value of
|
|
|
|
* ElementAnimation::GetComputedTimingAt which ensures all members are set
|
|
|
|
* correctly.
|
2014-05-28 11:51:49 +04:00
|
|
|
*/
|
|
|
|
struct ComputedTiming
|
|
|
|
{
|
|
|
|
ComputedTiming()
|
|
|
|
: mTimeFraction(kNullTimeFraction),
|
|
|
|
mCurrentIteration(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
static const double kNullTimeFraction;
|
|
|
|
|
2014-06-25 04:42:19 +04:00
|
|
|
// The total duration of the animation including all iterations.
|
|
|
|
// Will equal TimeDuration::Forever() if the animation repeats indefinitely.
|
|
|
|
TimeDuration mActiveDuration;
|
|
|
|
|
2014-05-28 11:51:49 +04:00
|
|
|
// Will be kNullTimeFraction if the animation is neither animating nor
|
|
|
|
// filling at the sampled time.
|
|
|
|
double mTimeFraction;
|
|
|
|
|
|
|
|
// Zero-based iteration index (meaningless if mTimeFraction is
|
|
|
|
// kNullTimeFraction).
|
|
|
|
uint64_t mCurrentIteration;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
// Sampled prior to the start of the active interval
|
|
|
|
AnimationPhase_Before,
|
|
|
|
// Sampled within the active interval
|
|
|
|
AnimationPhase_Active,
|
|
|
|
// Sampled after (or at) the end of the active interval
|
|
|
|
AnimationPhase_After
|
|
|
|
} mPhase;
|
|
|
|
};
|
|
|
|
|
2014-04-03 09:57:28 +04:00
|
|
|
/**
|
|
|
|
* Data about one animation (i.e., one of the values of
|
|
|
|
* 'animation-name') running on an element.
|
|
|
|
*/
|
2014-07-16 04:02:31 +04:00
|
|
|
class ElementAnimation : public nsWrapperCache
|
2014-04-03 09:57:28 +04:00
|
|
|
{
|
2014-06-19 06:28:59 +04:00
|
|
|
protected:
|
|
|
|
virtual ~ElementAnimation() { }
|
|
|
|
|
|
|
|
public:
|
2014-07-16 04:02:30 +04:00
|
|
|
explicit ElementAnimation(dom::AnimationTimeline* aTimeline)
|
2014-04-03 09:57:28 +04:00
|
|
|
: mIsRunningOnCompositor(false)
|
2014-07-16 04:02:29 +04:00
|
|
|
, mIsFinishedTransition(false)
|
2014-04-03 09:57:28 +04:00
|
|
|
, mLastNotification(LAST_NOTIFICATION_NONE)
|
2014-07-16 04:02:30 +04:00
|
|
|
, mTimeline(aTimeline)
|
2014-04-03 09:57:28 +04:00
|
|
|
{
|
2014-07-16 04:02:31 +04:00
|
|
|
SetIsDOMBinding();
|
2014-04-03 09:57:28 +04:00
|
|
|
}
|
|
|
|
|
2014-07-16 04:02:30 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ElementAnimation)
|
2014-07-16 04:02:31 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(ElementAnimation)
|
|
|
|
|
|
|
|
mozilla::dom::AnimationTimeline* GetParentObject() const { return mTimeline; }
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
// AnimationPlayer methods
|
|
|
|
double StartTime() const;
|
|
|
|
double CurrentTime() const;
|
2014-07-16 04:02:30 +04:00
|
|
|
|
2014-05-15 03:38:37 +04:00
|
|
|
// FIXME: If we succeed in moving transition-specific code to a type of
|
|
|
|
// AnimationEffect (as per the Web Animations API) we should remove these
|
|
|
|
// virtual methods.
|
|
|
|
virtual ElementPropertyTransition* AsTransition() { return nullptr; }
|
|
|
|
virtual const ElementPropertyTransition* AsTransition() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-04-03 09:57:28 +04:00
|
|
|
bool IsPaused() const {
|
|
|
|
return mPlayState == NS_STYLE_ANIMATION_PLAY_STATE_PAUSED;
|
|
|
|
}
|
|
|
|
|
2014-06-20 07:39:24 +04:00
|
|
|
// After transitions finish they need to be retained for one throttle-able
|
|
|
|
// cycle (for reasons see explanation in nsTransitionManager.cpp). In the
|
|
|
|
// meantime, however, they should be ignored.
|
|
|
|
bool IsFinishedTransition() const {
|
2014-07-16 04:02:29 +04:00
|
|
|
return mIsFinishedTransition;
|
2014-06-20 07:39:24 +04:00
|
|
|
}
|
|
|
|
void SetFinishedTransition() {
|
|
|
|
MOZ_ASSERT(AsTransition(),
|
|
|
|
"Calling SetFinishedTransition but it's not a transition");
|
2014-07-16 04:02:29 +04:00
|
|
|
mIsFinishedTransition = true;
|
2014-06-20 07:39:24 +04:00
|
|
|
}
|
|
|
|
|
2014-04-03 09:57:28 +04:00
|
|
|
bool HasAnimationOfProperty(nsCSSProperty aProperty) const;
|
|
|
|
bool IsRunningAt(mozilla::TimeStamp aTime) const;
|
2014-06-16 22:43:04 +04:00
|
|
|
bool IsCurrentAt(mozilla::TimeStamp aTime) const;
|
2014-04-03 09:57:28 +04:00
|
|
|
|
2014-06-20 07:39:24 +04:00
|
|
|
// Return the duration at aTime (or, if paused, mPauseStart) since
|
|
|
|
// the start of the delay period. May be negative.
|
|
|
|
mozilla::TimeDuration GetLocalTimeAt(mozilla::TimeStamp aTime) const {
|
|
|
|
MOZ_ASSERT(!IsPaused() || aTime >= mPauseStart,
|
|
|
|
"if paused, aTime must be at least mPauseStart");
|
|
|
|
return (IsPaused() ? mPauseStart : aTime) - mStartTime;
|
2014-04-03 09:57:28 +04:00
|
|
|
}
|
|
|
|
|
2014-05-30 04:45:39 +04:00
|
|
|
// Return the duration from the start the active interval to the point where
|
|
|
|
// the animation begins playback. This is zero unless the animation has
|
|
|
|
// a negative delay in which case it is the absolute value of the delay.
|
|
|
|
// This is used for setting the elapsedTime member of AnimationEvents.
|
|
|
|
mozilla::TimeDuration InitialAdvance() const {
|
2014-06-20 07:39:23 +04:00
|
|
|
return std::max(TimeDuration(), mTiming.mDelay * -1);
|
2014-05-30 04:45:39 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 11:51:50 +04:00
|
|
|
// This function takes as input the timing parameters of an animation and
|
|
|
|
// returns the computed timing at the specified moment.
|
|
|
|
//
|
|
|
|
// This function returns ComputedTiming::kNullTimeFraction for the
|
|
|
|
// mTimeFraction member of the return value if the animation should not be
|
|
|
|
// run (because it is not currently active and is not filling at this time).
|
2014-06-20 07:39:24 +04:00
|
|
|
static ComputedTiming GetComputedTimingAt(TimeDuration aLocalTime,
|
2014-05-28 11:51:50 +04:00
|
|
|
const AnimationTiming& aTiming);
|
|
|
|
|
2014-06-25 04:42:19 +04:00
|
|
|
// Return the duration of the active interval for the given timing parameters.
|
|
|
|
static mozilla::TimeDuration ActiveDuration(const AnimationTiming& aTiming);
|
|
|
|
|
2014-07-03 04:04:16 +04:00
|
|
|
nsString mName;
|
2014-05-28 11:51:50 +04:00
|
|
|
AnimationTiming mTiming;
|
2014-07-16 04:02:29 +04:00
|
|
|
// The beginning of the delay period.
|
2014-04-03 09:57:28 +04:00
|
|
|
mozilla::TimeStamp mStartTime;
|
|
|
|
mozilla::TimeStamp mPauseStart;
|
2014-05-28 11:51:50 +04:00
|
|
|
uint8_t mPlayState;
|
2014-04-03 09:57:28 +04:00
|
|
|
bool mIsRunningOnCompositor;
|
2014-07-16 04:02:29 +04:00
|
|
|
// A flag to mark transitions that have finished and are due to
|
|
|
|
// be removed on the next throttle-able cycle.
|
|
|
|
bool mIsFinishedTransition;
|
2014-04-03 09:57:28 +04:00
|
|
|
|
|
|
|
enum {
|
2014-05-28 11:51:49 +04:00
|
|
|
LAST_NOTIFICATION_NONE = uint64_t(-1),
|
|
|
|
LAST_NOTIFICATION_END = uint64_t(-2)
|
2014-04-03 09:57:28 +04:00
|
|
|
};
|
|
|
|
// One of the above constants, or an integer for the iteration
|
|
|
|
// whose start we last notified on.
|
2014-05-28 11:51:49 +04:00
|
|
|
uint64_t mLastNotification;
|
2014-04-03 09:57:28 +04:00
|
|
|
|
|
|
|
InfallibleTArray<AnimationProperty> mProperties;
|
2014-05-15 03:38:37 +04:00
|
|
|
|
2014-07-16 04:02:30 +04:00
|
|
|
nsRefPtr<dom::AnimationTimeline> mTimeline;
|
2014-04-03 09:57:28 +04:00
|
|
|
};
|
|
|
|
|
2014-05-15 03:38:37 +04:00
|
|
|
typedef InfallibleTArray<nsRefPtr<ElementAnimation> > ElementAnimationPtrArray;
|
2014-05-15 03:38:37 +04:00
|
|
|
|
2014-06-20 07:39:25 +04:00
|
|
|
enum EnsureStyleRuleFlags {
|
|
|
|
EnsureStyleRule_IsThrottled,
|
|
|
|
EnsureStyleRule_IsNotThrottled
|
|
|
|
};
|
|
|
|
|
2014-06-27 03:57:12 +04:00
|
|
|
struct ElementAnimationCollection : public PRCList
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2014-06-27 03:57:12 +04:00
|
|
|
ElementAnimationCollection(dom::Element *aElement, nsIAtom *aElementProperty,
|
|
|
|
mozilla::css::CommonAnimationManager *aManager,
|
|
|
|
TimeStamp aNow)
|
2011-04-12 10:18:43 +04:00
|
|
|
: mElement(aElement)
|
|
|
|
, mElementProperty(aElementProperty)
|
|
|
|
, mManager(aManager)
|
2013-02-26 10:21:26 +04:00
|
|
|
, mAnimationGeneration(0)
|
2013-10-22 16:14:41 +04:00
|
|
|
, mFlushGeneration(aNow)
|
2014-06-20 07:39:24 +04:00
|
|
|
, mNeedsRefreshes(true)
|
2011-05-01 02:16:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mCalledPropertyDtor(false)
|
|
|
|
#endif
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2014-06-27 03:57:12 +04:00
|
|
|
MOZ_COUNT_CTOR(ElementAnimationCollection);
|
2011-04-12 10:18:43 +04:00
|
|
|
PR_INIT_CLIST(this);
|
|
|
|
}
|
2014-06-27 03:57:12 +04:00
|
|
|
~ElementAnimationCollection()
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2011-05-01 02:16:19 +04:00
|
|
|
NS_ABORT_IF_FALSE(mCalledPropertyDtor,
|
|
|
|
"must call destructor through element property dtor");
|
2014-06-27 03:57:12 +04:00
|
|
|
MOZ_COUNT_DTOR(ElementAnimationCollection);
|
2011-04-12 10:18:43 +04:00
|
|
|
PR_REMOVE_LINK(this);
|
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-06-20 07:39:24 +04:00
|
|
|
// This updates mNeedsRefreshes so the caller may need to check
|
|
|
|
// for changes to values (for example, nsAnimationManager provides
|
|
|
|
// CheckNeedsRefresh to register or unregister from observing the refresh
|
|
|
|
// driver when this value changes).
|
2014-06-20 07:39:25 +04:00
|
|
|
void EnsureStyleRuleFor(TimeStamp aRefreshTime, EnsureStyleRuleFlags aFlags);
|
2014-06-20 07:39:24 +04:00
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
bool CanThrottleTransformChanges(mozilla::TimeStamp aTime);
|
|
|
|
|
|
|
|
bool CanThrottleAnimation(mozilla::TimeStamp aTime);
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
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).)
|
|
|
|
bool CanPerformOnCompositorThread(CanAnimateFlags aFlags) const;
|
2014-06-20 07:39:25 +04:00
|
|
|
bool HasAnimationOfProperty(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString PseudoElement()
|
|
|
|
{
|
|
|
|
if (IsForElement()) {
|
|
|
|
return EmptyString();
|
|
|
|
} else if (mElementProperty == nsGkAtoms::animationsOfBeforeProperty ||
|
|
|
|
mElementProperty == nsGkAtoms::transitionsOfBeforeProperty) {
|
|
|
|
return NS_LITERAL_STRING("::before");
|
|
|
|
} else {
|
|
|
|
return NS_LITERAL_STRING("::after");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 09:10:19 +04:00
|
|
|
void PostRestyleForAnimation(nsPresContext *aPresContext) {
|
|
|
|
nsRestyleHint styleHint = IsForElement() ? eRestyle_Self : eRestyle_Subtree;
|
|
|
|
aPresContext->PresShell()->RestyleForAnimation(mElement, styleHint);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2014-06-27 03:57:12 +04:00
|
|
|
mozilla::css::CommonAnimationManager *mManager;
|
2011-05-01 02:16:19 +04:00
|
|
|
|
2014-05-15 03:38:37 +04:00
|
|
|
mozilla::ElementAnimationPtrArray mAnimations;
|
|
|
|
|
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.
|
|
|
|
nsRefPtr<mozilla::css::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);
|
|
|
|
|
2014-06-16 22:43:04 +04:00
|
|
|
// Returns true if there is an animation in the before or active phase at
|
|
|
|
// the given time.
|
|
|
|
bool HasCurrentAnimationsAt(mozilla::TimeStamp aTime);
|
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
// The refresh time associated with mStyleRule.
|
|
|
|
TimeStamp mStyleRuleRefreshTime;
|
|
|
|
|
2013-10-22 16:14:41 +04:00
|
|
|
// Generation counter for flushes of throttled animations.
|
|
|
|
// Used to prevent updating the styles twice for a given element during
|
|
|
|
// UpdateAllThrottledStyles.
|
|
|
|
TimeStamp mFlushGeneration;
|
|
|
|
|
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;
|
|
|
|
|
2011-05-01 02:16:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mCalledPropertyDtor;
|
|
|
|
#endif
|
2011-04-12 10:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !defined(mozilla_css_AnimationCommon_h) */
|