Bug 994117, add method to check if an element has current animations, r=bbirtles

This commit is contained in:
Neil Deakin 2014-06-16 14:43:04 -04:00
parent ef66038dae
commit 5504409f46
4 changed files with 57 additions and 0 deletions

View File

@ -330,6 +330,21 @@ nsLayoutUtils::HasAnimations(nsIContent* aContent,
(aContent, nsGkAtoms::transitionsProperty, aProperty);
}
bool
nsLayoutUtils::HasCurrentAnimations(nsIContent* aContent,
nsIAtom* aAnimationProperty,
nsPresContext* aPresContext)
{
if (!aContent->MayHaveAnimations())
return false;
TimeStamp now = aPresContext->RefreshDriver()->MostRecentRefresh();
CommonElementAnimationData* animations =
static_cast<CommonElementAnimationData*>(aContent->GetProperty(aAnimationProperty));
return (animations && animations->HasCurrentAnimationsAt(now));
}
static gfxSize
GetScaleForValue(const nsStyleAnimation::Value& aValue,
nsIFrame* aFrame)

View File

@ -1877,6 +1877,15 @@ public:
*/
static bool HasAnimations(nsIContent* aContent, nsCSSProperty aProperty);
/**
* Returns true if the content node has any current animations or transitions.
* A current animation is any animation that has not yet finished playing
* including paused animations.
*/
static bool HasCurrentAnimations(nsIContent* aContent,
nsIAtom* aAnimationProperty,
nsPresContext* aPresContext);
/**
* Checks if off-main-thread animations are enabled.
*/

View File

@ -381,6 +381,22 @@ ElementAnimation::IsRunningAt(TimeStamp aTime) const
iterationsElapsed < mTiming.mIterationCount;
}
bool
ElementAnimation::IsCurrentAt(TimeStamp aTime) const
{
if (!mStartTime.IsNull()) {
TimeDuration elapsedDuration = ElapsedDurationAt(aTime);
ComputedTiming computedTiming =
ElementAnimation::GetComputedTimingAt(elapsedDuration, mTiming);
if (computedTiming.mPhase == ComputedTiming::AnimationPhase_Before ||
computedTiming.mPhase == ComputedTiming::AnimationPhase_Active) {
return true;
}
}
return false;
}
bool
ElementAnimation::HasAnimationOfProperty(nsCSSProperty aProperty) const
{
@ -675,5 +691,17 @@ CommonElementAnimationData::UpdateAnimationGeneration(nsPresContext* aPresContex
aPresContext->RestyleManager()->GetAnimationGeneration();
}
bool
CommonElementAnimationData::HasCurrentAnimationsAt(TimeStamp aTime)
{
for (uint32_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
if (mAnimations[animIdx]->IsCurrentAt(aTime)) {
return true;
}
}
return false;
}
}
}

View File

@ -303,6 +303,7 @@ struct ElementAnimation
bool HasAnimationOfProperty(nsCSSProperty aProperty) const;
bool IsRunningAt(mozilla::TimeStamp aTime) const;
bool IsCurrentAt(mozilla::TimeStamp aTime) const;
// Return the duration, at aTime (or, if paused, mPauseStart), since
// the *end* of the delay period. May be negative.
@ -459,6 +460,10 @@ struct CommonElementAnimationData : public PRCList
// Update mAnimationGeneration to nsCSSFrameConstructor's count
void UpdateAnimationGeneration(nsPresContext* aPresContext);
// Returns true if there is an animation in the before or active phase at
// the given time.
bool HasCurrentAnimationsAt(mozilla::TimeStamp aTime);
// The refresh time associated with mStyleRule.
TimeStamp mStyleRuleRefreshTime;