2014-12-18 02:42:41 +03:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
#include "PendingAnimationTracker.h"
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2015-04-10 04:34:22 +03:00
|
|
|
#include "mozilla/dom/DocumentTimeline.h"
|
2014-12-22 03:35:41 +03:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIPresShell.h"
|
2014-12-22 03:35:41 +03:00
|
|
|
|
2014-12-18 02:42:41 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(PendingAnimationTracker,
|
2015-03-27 09:56:45 +03:00
|
|
|
mPlayPendingSet,
|
|
|
|
mPausePendingSet,
|
|
|
|
mDocument)
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PendingAnimationTracker, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PendingAnimationTracker, Release)
|
2014-12-18 02:42:41 +03:00
|
|
|
|
|
|
|
void
|
2015-04-21 04:22:09 +03:00
|
|
|
PendingAnimationTracker::AddPending(dom::Animation& aAnimation,
|
|
|
|
AnimationSet& aSet)
|
2014-12-18 02:42:41 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
aSet.PutEntry(&aAnimation);
|
2014-12-22 03:35:41 +03:00
|
|
|
|
|
|
|
// Schedule a paint. Otherwise animations that don't trigger a paint by
|
|
|
|
// themselves (e.g. CSS animations with an empty keyframes rule) won't
|
|
|
|
// start until something else paints.
|
|
|
|
EnsurePaintIsScheduled();
|
2014-12-18 02:42:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-21 04:22:09 +03:00
|
|
|
PendingAnimationTracker::RemovePending(dom::Animation& aAnimation,
|
|
|
|
AnimationSet& aSet)
|
2014-12-18 02:42:41 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
aSet.RemoveEntry(&aAnimation);
|
2014-12-18 02:42:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-04-21 04:22:09 +03:00
|
|
|
PendingAnimationTracker::IsWaiting(const dom::Animation& aAnimation,
|
|
|
|
const AnimationSet& aSet) const
|
2014-12-18 02:42:41 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
return aSet.Contains(const_cast<dom::Animation*>(&aAnimation));
|
2014-12-18 02:42:41 +03:00
|
|
|
}
|
|
|
|
|
2014-12-22 03:35:41 +03:00
|
|
|
PLDHashOperator
|
2015-04-21 04:22:09 +03:00
|
|
|
TriggerAnimationAtTime(nsRefPtrHashKey<dom::Animation>* aKey,
|
2015-03-27 09:56:45 +03:00
|
|
|
void* aReadyTime)
|
2014-12-22 03:35:41 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
dom::Animation* animation = aKey->GetKey();
|
|
|
|
dom::DocumentTimeline* timeline = animation->Timeline();
|
2014-12-22 03:35:41 +03:00
|
|
|
|
2015-01-09 01:57:58 +03:00
|
|
|
// When the timeline's refresh driver is under test control, its values
|
|
|
|
// have no correspondance to wallclock times so we shouldn't try to convert
|
|
|
|
// aReadyTime (which is a wallclock time) to a timeline value. Instead, the
|
2015-04-21 04:22:09 +03:00
|
|
|
// animation will be started/paused when the refresh driver is next
|
2015-04-21 04:22:09 +03:00
|
|
|
// advanced since this will trigger a call to TriggerPendingAnimationsNow.
|
2015-01-09 01:57:58 +03:00
|
|
|
if (timeline->IsUnderTestControl()) {
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Nullable<TimeDuration> readyTime =
|
|
|
|
timeline->ToTimelineTime(*static_cast<const TimeStamp*>(aReadyTime));
|
2015-04-21 04:22:09 +03:00
|
|
|
animation->TriggerOnNextTick(readyTime);
|
2014-12-22 03:35:41 +03:00
|
|
|
|
2015-01-09 01:57:58 +03:00
|
|
|
return PL_DHASH_REMOVE;
|
2014-12-22 03:35:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-21 04:22:09 +03:00
|
|
|
PendingAnimationTracker::TriggerPendingAnimationsOnNextTick(const TimeStamp&
|
2015-03-27 09:56:45 +03:00
|
|
|
aReadyTime)
|
2014-12-22 03:35:41 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
mPlayPendingSet.EnumerateEntries(TriggerAnimationAtTime,
|
2014-12-22 03:35:41 +03:00
|
|
|
const_cast<TimeStamp*>(&aReadyTime));
|
2015-04-21 04:22:09 +03:00
|
|
|
mPausePendingSet.EnumerateEntries(TriggerAnimationAtTime,
|
2015-03-27 09:56:45 +03:00
|
|
|
const_cast<TimeStamp*>(&aReadyTime));
|
2015-01-09 01:57:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
2015-04-21 04:22:09 +03:00
|
|
|
TriggerAnimationNow(nsRefPtrHashKey<dom::Animation>* aKey, void*)
|
2015-01-09 01:57:58 +03:00
|
|
|
{
|
2015-03-27 09:56:45 +03:00
|
|
|
aKey->GetKey()->TriggerNow();
|
2015-01-09 01:57:58 +03:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-21 04:22:09 +03:00
|
|
|
PendingAnimationTracker::TriggerPendingAnimationsNow()
|
2015-01-09 01:57:58 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
mPlayPendingSet.EnumerateEntries(TriggerAnimationNow, nullptr);
|
2014-12-22 03:35:41 +03:00
|
|
|
mPlayPendingSet.Clear();
|
2015-04-21 04:22:09 +03:00
|
|
|
mPausePendingSet.EnumerateEntries(TriggerAnimationNow, nullptr);
|
2015-03-27 09:56:45 +03:00
|
|
|
mPausePendingSet.Clear();
|
2014-12-22 03:35:41 +03:00
|
|
|
}
|
|
|
|
|
2014-12-22 03:35:41 +03:00
|
|
|
void
|
2015-04-21 04:22:09 +03:00
|
|
|
PendingAnimationTracker::EnsurePaintIsScheduled()
|
2014-12-22 03:35:41 +03:00
|
|
|
{
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* presShell = mDocument->GetShell();
|
|
|
|
if (!presShell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* rootFrame = presShell->GetRootFrame();
|
|
|
|
if (!rootFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rootFrame->SchedulePaint();
|
|
|
|
}
|
|
|
|
|
2014-12-18 02:42:41 +03:00
|
|
|
} // namespace mozilla
|