Bug 1040543 part 5 - Pass down time from AnimationPlayer to Animation; r=bz

This patch makes AnimationPlayers pass their current time down to the Animation
they are playing.

Since all Animations need from their players is their time, this avoids adding
a pointer back to their AnimationPlayer.
This commit is contained in:
Brian Birtles 2014-08-10 17:06:48 +10:00
Родитель 8f9311bf63
Коммит 249039905a
8 изменённых файлов: 40 добавлений и 0 удалений

Просмотреть файл

@ -20,5 +20,11 @@ Animation::WrapObject(JSContext* aCx)
return AnimationBinding::Wrap(aCx, this); return AnimationBinding::Wrap(aCx, this);
} }
void
Animation::SetParentTime(Nullable<TimeDuration> aParentTime)
{
mParentTime = aParentTime;
}
} // namespace dom } // namespace dom
} // namespace mozilla } // namespace mozilla

Просмотреть файл

@ -11,6 +11,8 @@
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsWrapperCache.h" #include "nsWrapperCache.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/Nullable.h"
struct JSContext; struct JSContext;
@ -32,12 +34,15 @@ public:
nsIDocument* GetParentObject() const { return mDocument; } nsIDocument* GetParentObject() const { return mDocument; }
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
void SetParentTime(Nullable<TimeDuration> aParentTime);
protected: protected:
virtual ~Animation() { } virtual ~Animation() { }
// We use a document for a parent object since the other likely candidate, // We use a document for a parent object since the other likely candidate,
// the target element, can be empty. // the target element, can be empty.
nsRefPtr<nsIDocument> mDocument; nsRefPtr<nsIDocument> mDocument;
Nullable<TimeDuration> mParentTime;
}; };
} // namespace dom } // namespace dom

Просмотреть файл

@ -104,7 +104,21 @@ AnimationPlayer::CurrentTime() const
void void
AnimationPlayer::SetSource(Animation* aSource) AnimationPlayer::SetSource(Animation* aSource)
{ {
if (mSource) {
mSource->SetParentTime(Nullable<TimeDuration>());
}
mSource = aSource; mSource = aSource;
if (mSource) {
mSource->SetParentTime(GetLocalTime());
}
}
void
AnimationPlayer::Tick()
{
if (mSource) {
mSource->SetParentTime(GetLocalTime());
}
} }
bool bool

Просмотреть файл

@ -152,6 +152,7 @@ public:
double CurrentTime() const; double CurrentTime() const;
void SetSource(Animation* aSource); void SetSource(Animation* aSource);
void Tick();
// FIXME: If we succeed in moving transition-specific code to a type of // FIXME: If we succeed in moving transition-specific code to a type of
// AnimationEffect (as per the Web Animations API) we should remove these // AnimationEffect (as per the Web Animations API) we should remove these

Просмотреть файл

@ -442,6 +442,15 @@ AnimationPlayerCollection::PropertyDtor(void *aObject, nsIAtom *aPropertyName,
delete collection; delete collection;
} }
void
AnimationPlayerCollection::Tick()
{
for (size_t animIdx = 0, animEnd = mAnimations.Length();
animIdx != animEnd; animIdx++) {
mAnimations[animIdx]->Tick();
}
}
void void
AnimationPlayerCollection::EnsureStyleRuleFor(TimeStamp aRefreshTime, AnimationPlayerCollection::EnsureStyleRuleFor(TimeStamp aRefreshTime,
EnsureStyleRuleFlags aFlags) EnsureStyleRuleFlags aFlags)

Просмотреть файл

@ -182,6 +182,8 @@ struct AnimationPlayerCollection : public PRCList
static void PropertyDtor(void *aObject, nsIAtom *aPropertyName, static void PropertyDtor(void *aObject, nsIAtom *aPropertyName,
void *aPropertyValue, void *aData); void *aPropertyValue, void *aData);
void Tick();
// This updates mNeedsRefreshes so the caller may need to check // This updates mNeedsRefreshes so the caller may need to check
// for changes to values (for example, nsAnimationManager provides // for changes to values (for example, nsAnimationManager provides
// CheckNeedsRefresh to register or unregister from observing the refresh // CheckNeedsRefresh to register or unregister from observing the refresh

Просмотреть файл

@ -335,6 +335,7 @@ nsAnimationManager::CheckAnimationRule(nsStyleContext* aStyleContext,
} }
collection->mAnimations.SwapElements(newAnimations); collection->mAnimations.SwapElements(newAnimations);
collection->mNeedsRefreshes = true; collection->mNeedsRefreshes = true;
collection->Tick();
TimeStamp refreshTime = mPresContext->RefreshDriver()->MostRecentRefresh(); TimeStamp refreshTime = mPresContext->RefreshDriver()->MostRecentRefresh();
UpdateStyleAndEvents(collection, refreshTime, UpdateStyleAndEvents(collection, refreshTime,
@ -745,6 +746,7 @@ nsAnimationManager::FlushAnimations(FlushFlags aFlags)
l = PR_NEXT_LINK(l)) { l = PR_NEXT_LINK(l)) {
AnimationPlayerCollection* collection = AnimationPlayerCollection* collection =
static_cast<AnimationPlayerCollection*>(l); static_cast<AnimationPlayerCollection*>(l);
collection->Tick();
bool canThrottleTick = aFlags == Can_Throttle && bool canThrottleTick = aFlags == Can_Throttle &&
collection->CanPerformOnCompositorThread( collection->CanPerformOnCompositorThread(
AnimationPlayerCollection::CanAnimateFlags(0)) && AnimationPlayerCollection::CanAnimateFlags(0)) &&

Просмотреть файл

@ -746,6 +746,7 @@ nsTransitionManager::FlushTransitions(FlushFlags aFlags)
static_cast<AnimationPlayerCollection*>(next); static_cast<AnimationPlayerCollection*>(next);
next = PR_NEXT_LINK(next); next = PR_NEXT_LINK(next);
collection->Tick();
bool canThrottleTick = aFlags == Can_Throttle && bool canThrottleTick = aFlags == Can_Throttle &&
collection->CanPerformOnCompositorThread( collection->CanPerformOnCompositorThread(
AnimationPlayerCollection::CanAnimateFlags(0)) && AnimationPlayerCollection::CanAnimateFlags(0)) &&