2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-12-18 02:42:41 +03:00
|
|
|
/* 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
|
|
|
#ifndef mozilla_dom_PendingAnimationTracker_h
|
|
|
|
#define mozilla_dom_PendingAnimationTracker_h
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
#include "mozilla/dom/Animation.h"
|
2014-12-18 02:42:41 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-12-22 03:35:41 +03:00
|
|
|
#include "nsIDocument.h"
|
2014-12-18 02:42:41 +03:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
|
2014-12-22 03:35:41 +03:00
|
|
|
class nsIFrame;
|
|
|
|
|
2014-12-18 02:42:41 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
class PendingAnimationTracker final
|
2014-12-18 02:42:41 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-04-21 04:22:09 +03:00
|
|
|
explicit PendingAnimationTracker(nsIDocument* aDocument)
|
2014-12-22 03:35:41 +03:00
|
|
|
: mDocument(aDocument)
|
|
|
|
{ }
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PendingAnimationTracker)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(PendingAnimationTracker)
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void AddPlayPending(dom::Animation& aAnimation)
|
2015-03-27 09:56:45 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
MOZ_ASSERT(!IsWaitingToPause(aAnimation),
|
|
|
|
"Animation is already waiting to pause");
|
|
|
|
AddPending(aAnimation, mPlayPendingSet);
|
2016-12-02 04:10:44 +03:00
|
|
|
mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
2015-04-21 04:22:09 +03:00
|
|
|
void RemovePlayPending(dom::Animation& aAnimation)
|
2015-03-27 09:56:45 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
RemovePending(aAnimation, mPlayPendingSet);
|
2016-12-02 04:10:44 +03:00
|
|
|
mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
2015-04-21 04:22:09 +03:00
|
|
|
bool IsWaitingToPlay(const dom::Animation& aAnimation) const
|
2015-03-27 09:56:45 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
return IsWaiting(aAnimation, mPlayPendingSet);
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void AddPausePending(dom::Animation& aAnimation)
|
2015-03-27 09:56:45 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
MOZ_ASSERT(!IsWaitingToPlay(aAnimation),
|
|
|
|
"Animation is already waiting to play");
|
|
|
|
AddPending(aAnimation, mPausePendingSet);
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
2015-04-21 04:22:09 +03:00
|
|
|
void RemovePausePending(dom::Animation& aAnimation)
|
2015-03-27 09:56:45 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
RemovePending(aAnimation, mPausePendingSet);
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
2015-04-21 04:22:09 +03:00
|
|
|
bool IsWaitingToPause(const dom::Animation& aAnimation) const
|
2015-03-27 09:56:45 +03:00
|
|
|
{
|
2015-04-21 04:22:09 +03:00
|
|
|
return IsWaiting(aAnimation, mPausePendingSet);
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void TriggerPendingAnimationsOnNextTick(const TimeStamp& aReadyTime);
|
|
|
|
void TriggerPendingAnimationsNow();
|
|
|
|
bool HasPendingAnimations() const {
|
2015-03-27 09:56:45 +03:00
|
|
|
return mPlayPendingSet.Count() > 0 || mPausePendingSet.Count() > 0;
|
|
|
|
}
|
2014-12-22 03:35:41 +03:00
|
|
|
|
2016-12-02 04:10:44 +03:00
|
|
|
/**
|
|
|
|
* Looks amongst the set of play-pending animations, and, if there are
|
|
|
|
* animations that affect geometric properties, notifies all play-pending
|
|
|
|
* animations so that they can be synchronized, if needed.
|
|
|
|
*/
|
|
|
|
void MarkAnimationsThatMightNeedSynchronization();
|
|
|
|
|
2014-12-18 02:42:41 +03:00
|
|
|
private:
|
2015-04-21 04:22:09 +03:00
|
|
|
~PendingAnimationTracker() { }
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2016-12-02 04:10:44 +03:00
|
|
|
bool HasPlayPendingGeometricAnimations();
|
2014-12-22 03:35:41 +03:00
|
|
|
void EnsurePaintIsScheduled();
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
typedef nsTHashtable<nsRefPtrHashKey<dom::Animation>> AnimationSet;
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
void AddPending(dom::Animation& aAnimation, AnimationSet& aSet);
|
|
|
|
void RemovePending(dom::Animation& aAnimation, AnimationSet& aSet);
|
|
|
|
bool IsWaiting(const dom::Animation& aAnimation,
|
|
|
|
const AnimationSet& aSet) const;
|
2015-03-27 09:56:45 +03:00
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
AnimationSet mPlayPendingSet;
|
|
|
|
AnimationSet mPausePendingSet;
|
2014-12-22 03:35:41 +03:00
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
2016-12-02 04:10:44 +03:00
|
|
|
|
|
|
|
enum class CheckState {
|
|
|
|
Indeterminate,
|
|
|
|
Absent,
|
|
|
|
Present
|
|
|
|
};
|
|
|
|
CheckState mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
|
2014-12-18 02:42:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
#endif // mozilla_dom_PendingAnimationTracker_h
|