Bug 1033114 Part 4: Make mStartTime a nullable TimeDuration r=birtles

This commit is contained in:
David Zbarsky 2014-08-30 02:11:57 -04:00
parent cbd65c781b
commit 13da8bae55
4 changed files with 32 additions and 50 deletions

View File

@ -30,27 +30,7 @@ AnimationPlayer::GetStartTime() const
Nullable<double>
AnimationPlayer::GetCurrentTime() const
{
Nullable<double> result;
Nullable<TimeDuration> currentTime = GetCurrentTimeDuration();
// The current time is currently only going to be null when don't have a
// refresh driver (e.g. because we are in a display:none iframe).
//
// Web Animations says that in this case we should use a timeline time of
// 0 (the "effective timeline time") and calculate the current time from that.
// Doing that, however, requires storing the start time as an offset rather
// than a timestamp so for now we just return 0.
//
// FIXME: Store player start time and pause start as offsets rather than
// timestamps and return the appropriate current time when the timeline time
// is null.
if (currentTime.IsNull()) {
result.SetValue(0.0);
} else {
result.SetValue(currentTime.Value().ToMilliseconds());
}
return result;
return AnimationUtils::TimeDurationToDouble(GetCurrentTimeDuration());
}
void
@ -90,5 +70,20 @@ AnimationPlayer::IsCurrent() const
return GetSource() && GetSource()->IsCurrent();
}
Nullable<TimeDuration>
AnimationPlayer::GetCurrentTimeDuration() const
{
Nullable<TimeDuration> result;
if (!mHoldTime.IsNull()) {
result = mHoldTime;
} else {
Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTimeDuration();
if (!timelineTime.IsNull() && !mStartTime.IsNull()) {
result.SetValue(timelineTime.Value() - mStartTime.Value());
}
}
return result;
}
} // namespace dom
} // namespace mozilla

View File

@ -67,23 +67,12 @@ public:
bool IsCurrent() const;
// Return the duration since the start time of the player, taking into
// account the pause state. May be negative.
// Returns a null value if the timeline associated with this object has a
// current timestamp that is null or if the start time of this object is
// null.
Nullable<TimeDuration> GetCurrentTimeDuration() const {
Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTimeDuration();
Nullable<TimeDuration> holdDuration = mTimeline->ToTimelineTime(mHoldTime);
Nullable<TimeDuration> result; // Initializes to null
if (!timelineTime.IsNull() && !mStartTime.IsNull()) {
result.SetValue((IsPaused() ? holdDuration.Value() : timelineTime.Value()) - mStartTime.Value());
}
return result;
}
// account the pause state. May be negative or null.
Nullable<TimeDuration> GetCurrentTimeDuration() const;
// The beginning of the delay period.
Nullable<TimeDuration> mStartTime;
TimeStamp mHoldTime;
Nullable<TimeDuration> mHoldTime;
uint8_t mPlayState;
bool mIsRunningOnCompositor;

View File

@ -41,9 +41,9 @@ public:
Nullable<TimeDuration> ToTimelineTime(const TimeStamp& aTimeStamp) const;
TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const;
protected:
TimeStamp GetCurrentTimeStamp() const;
protected:
virtual ~AnimationTimeline() { }
nsCOMPtr<nsIDocument> mDocument;

View File

@ -272,6 +272,9 @@ nsAnimationManager::CheckAnimationRule(nsStyleContext* aStyleContext,
// (or potentially optimize BuildAnimations to avoid rebuilding it
// in the first place).
if (!collection->mPlayers.IsEmpty()) {
Nullable<TimeDuration> now = timeline->GetCurrentTimeDuration();
for (size_t newIdx = newPlayers.Length(); newIdx-- != 0;) {
AnimationPlayer* newPlayer = newPlayers[newIdx];
@ -309,18 +312,15 @@ nsAnimationManager::CheckAnimationRule(nsStyleContext* aStyleContext,
// Handle changes in play state.
if (!oldPlayer->IsPaused() && newPlayer->IsPaused()) {
// Start pause at current time.
oldPlayer->mHoldTime = timeline->GetCurrentTimeStamp();
oldPlayer->mHoldTime = oldPlayer->GetCurrentTimeDuration();
} else if (oldPlayer->IsPaused() && !newPlayer->IsPaused()) {
const TimeStamp& now = timeline->GetCurrentTimeStamp();
if (!now.IsNull()) {
// FIXME: Once we store the start time and pause start as
// offsets (not timestamps) we should be able to update the
// start time to something more appropriate when now IsNull.
// Handle change in pause state by adjusting start time to
// unpause.
oldPlayer->mStartTime.SetValue(now + oldPlayer->mStartTime.Value() - oldPlayer->mHoldTime);
if (now.IsNull()) {
oldPlayer->mStartTime.SetNull();
} else {
oldPlayer->mStartTime.SetValue(now.Value() -
oldPlayer->mHoldTime.Value());
}
oldPlayer->mHoldTime = TimeStamp();
oldPlayer->mHoldTime.SetNull();
}
oldPlayer->mPlayState = newPlayer->mPlayState;
@ -419,7 +419,7 @@ nsAnimationManager::BuildAnimations(nsStyleContext* aStyleContext,
ResolvedStyleCache resolvedStyles;
const nsStyleDisplay *disp = aStyleContext->StyleDisplay();
TimeStamp now = aTimeline->GetCurrentTimeStamp();
Nullable<TimeDuration> now = aTimeline->GetCurrentTimeDuration();
for (size_t animIdx = 0, animEnd = disp->mAnimationNameCount;
animIdx != animEnd; ++animIdx) {
@ -454,12 +454,10 @@ nsAnimationManager::BuildAnimations(nsStyleContext* aStyleContext,
new Animation(mPresContext->Document(), timing, src.GetName());
dest->SetSource(destAnim);
dest->mStartTime = aTimeline->GetCurrentTimeDuration();
dest->mStartTime = now;
dest->mPlayState = src.GetPlayState();
if (dest->IsPaused()) {
dest->mHoldTime = now;
} else {
dest->mHoldTime = TimeStamp();
}
// While current drafts of css3-animations say that later keyframes