mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 04:45:45 +00:00
Bug 994117, add method to check if an element has current animations, r=bbirtles
This commit is contained in:
parent
ef66038dae
commit
5504409f46
@ -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)
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user