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"
|
2019-01-08 09:45:18 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2018-11-01 03:15:45 +03:00
|
|
|
#include "mozilla/TypedEnumBits.h"
|
2014-12-18 02:42:41 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
|
2014-12-22 03:35:41 +03:00
|
|
|
class nsIFrame;
|
|
|
|
|
2014-12-18 02:42:41 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
namespace dom {
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
class PendingAnimationTracker final {
|
2014-12-18 02:42:41 +03:00
|
|
|
public:
|
2019-01-02 16:05:23 +03:00
|
|
|
explicit PendingAnimationTracker(dom::Document* 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) {
|
2017-10-13 08:37:51 +03:00
|
|
|
// We'd like to assert here that IsWaitingToPause(aAnimation) is false but
|
|
|
|
// if |aAnimation| was tracked here as a pause-pending animation when it was
|
|
|
|
// removed from |mDocument|, then re-attached to |mDocument|, and then
|
|
|
|
// played again, we could end up here with IsWaitingToPause returning true.
|
|
|
|
//
|
|
|
|
// However, that should be harmless since all it means is that we'll call
|
|
|
|
// Animation::TriggerOnNextTick or Animation::TriggerNow twice, both of
|
|
|
|
// which will handle the redundant call gracefully.
|
2015-04-21 04:22:09 +03:00
|
|
|
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) {
|
|
|
|
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 {
|
|
|
|
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) {
|
2017-10-13 08:37:51 +03:00
|
|
|
// As with AddPausePending, we'd like to assert that
|
|
|
|
// IsWaitingToPlay(aAnimation) is false but there are some circumstances
|
|
|
|
// where this can be true. Fortunately adding the animation to both pending
|
|
|
|
// sets should be harmless.
|
2015-04-21 04:22:09 +03:00
|
|
|
AddPending(aAnimation, mPausePendingSet);
|
2015-03-27 09:56:45 +03:00
|
|
|
}
|
2015-04-21 04:22:09 +03:00
|
|
|
void RemovePausePending(dom::Animation& aAnimation) {
|
|
|
|
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 {
|
|
|
|
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
|
|
|
|
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;
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<dom::Document> mDocument;
|
2016-12-02 04:10:44 +03:00
|
|
|
|
2018-11-01 03:15:45 +03:00
|
|
|
public:
|
2016-12-02 04:10:44 +03:00
|
|
|
enum class CheckState {
|
2018-11-01 03:15:45 +03:00
|
|
|
Indeterminate = 0,
|
|
|
|
Absent = 1 << 0,
|
|
|
|
AnimationsPresent = 1 << 1,
|
|
|
|
TransitionsPresent = 1 << 2,
|
2016-12-02 04:10:44 +03:00
|
|
|
};
|
2018-11-01 03:15:45 +03:00
|
|
|
|
|
|
|
private:
|
2016-12-02 04:10:44 +03:00
|
|
|
CheckState mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
|
2014-12-18 02:42:41 +03:00
|
|
|
};
|
|
|
|
|
2018-11-01 03:15:45 +03:00
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(PendingAnimationTracker::CheckState)
|
|
|
|
|
2014-12-18 02:42:41 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
#endif // mozilla_dom_PendingAnimationTracker_h
|