Bug 927349 part 1 - Add PendingPlayerTracker; r=jwatt

This patch adds a hashtable to nsDocument that stores all the animation players
that are currently waiting to start. In the future it may also be used to store
players that are waiting to pause which is why the methods are called
AddPlayPending/RemovePlayPending instead of just AddPlayer/RemovePlayer.
This commit is contained in:
Brian Birtles 2014-12-18 08:42:41 +09:00
parent 11e4d27c81
commit 1c721ff76d
6 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,35 @@
/* 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/. */
#include "PendingPlayerTracker.h"
using namespace mozilla;
namespace mozilla {
NS_IMPL_CYCLE_COLLECTION(PendingPlayerTracker, mPlayPendingSet)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PendingPlayerTracker, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PendingPlayerTracker, Release)
void
PendingPlayerTracker::AddPlayPending(dom::AnimationPlayer& aPlayer)
{
mPlayPendingSet.PutEntry(&aPlayer);
}
void
PendingPlayerTracker::RemovePlayPending(dom::AnimationPlayer& aPlayer)
{
mPlayPendingSet.RemoveEntry(&aPlayer);
}
bool
PendingPlayerTracker::IsWaitingToPlay(dom::AnimationPlayer const& aPlayer) const
{
return mPlayPendingSet.Contains(const_cast<dom::AnimationPlayer*>(&aPlayer));
}
} // namespace mozilla

View File

@ -0,0 +1,36 @@
/* 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/. */
#ifndef mozilla_dom_PendingPlayerTracker_h
#define mozilla_dom_PendingPlayerTracker_h
#include "mozilla/dom/AnimationPlayer.h"
#include "nsCycleCollectionParticipant.h"
#include "nsTHashtable.h"
namespace mozilla {
class PendingPlayerTracker MOZ_FINAL
{
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PendingPlayerTracker)
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(PendingPlayerTracker)
void AddPlayPending(dom::AnimationPlayer& aPlayer);
void RemovePlayPending(dom::AnimationPlayer& aPlayer);
bool IsWaitingToPlay(dom::AnimationPlayer const& aPlayer) const;
private:
~PendingPlayerTracker() { }
typedef nsTHashtable<nsRefPtrHashKey<dom::AnimationPlayer>>
AnimationPlayerSet;
AnimationPlayerSet mPlayPendingSet;
};
} // namespace mozilla
#endif // mozilla_dom_PendingPlayerTracker_h

View File

@ -14,11 +14,16 @@ EXPORTS.mozilla.dom += [
'AnimationTimeline.h',
]
EXPORTS.mozilla += [
'PendingPlayerTracker.h',
]
UNIFIED_SOURCES += [
'Animation.cpp',
'AnimationEffect.cpp',
'AnimationPlayer.cpp',
'AnimationTimeline.cpp',
'PendingPlayerTracker.cpp',
]
FAIL_ON_WARNINGS = True

View File

@ -1995,6 +1995,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStateObjectCached)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mUndoManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnimationTimeline)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingPlayerTracker)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTemplateContentsOwner)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChildrenCollection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRegistry)
@ -2078,6 +2079,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedEncoder)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mUndoManager)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnimationTimeline)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingPlayerTracker)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTemplateContentsOwner)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChildrenCollection)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRegistry)
@ -7391,6 +7393,16 @@ nsDocument::GetAnimationController()
return mAnimationController;
}
PendingPlayerTracker*
nsDocument::GetOrCreatePendingPlayerTracker()
{
if (!mPendingPlayerTracker) {
mPendingPlayerTracker = new PendingPlayerTracker();
}
return mPendingPlayerTracker;
}
/**
* Retrieve the "direction" property of the document.
*

View File

@ -59,6 +59,7 @@
#include "mozilla/EventListenerManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/PendingPlayerTracker.h"
#include "mozilla/dom/DOMImplementation.h"
#include "mozilla/dom/StyleSheetList.h"
#include "nsDataHashtable.h"
@ -1047,6 +1048,15 @@ public:
// If HasAnimationController is true, this is guaranteed to return non-null.
nsSMILAnimationController* GetAnimationController() MOZ_OVERRIDE;
virtual mozilla::PendingPlayerTracker*
GetPendingPlayerTracker() MOZ_FINAL
{
return mPendingPlayerTracker;
}
virtual mozilla::PendingPlayerTracker*
GetOrCreatePendingPlayerTracker() MOZ_OVERRIDE;
void SetImagesNeedAnimating(bool aAnimating) MOZ_OVERRIDE;
virtual void SuppressEventHandling(SuppressionType aWhat,
@ -1511,6 +1521,10 @@ protected:
// Array of observers
nsTObserverArray<nsIDocumentObserver*> mObservers;
// Tracker for animation players that are waiting to start.
// nullptr until GetOrCreatePendingPlayerTracker is called.
nsRefPtr<mozilla::PendingPlayerTracker> mPendingPlayerTracker;
// Weak reference to the scope object (aka the script global object)
// that, unlike mScriptGlobalObject, is never unset once set. This
// is a weak reference to avoid leaks due to circular references.

View File

@ -86,6 +86,7 @@ namespace mozilla {
class CSSStyleSheet;
class ErrorResult;
class EventStates;
class PendingPlayerTracker;
class SVGAttrAnimationRuleProcessor;
namespace css {
@ -1822,6 +1823,17 @@ public:
// mAnimationController isn't yet initialized.
virtual nsSMILAnimationController* GetAnimationController() = 0;
// Gets the tracker for animation players that are waiting to start.
// Returns nullptr if there is no pending player tracker for this document
// which will be the case if there have never been any CSS animations or
// transitions on elements in the document.
virtual mozilla::PendingPlayerTracker* GetPendingPlayerTracker() = 0;
// Gets the tracker for animation players that are waiting to start and
// creates it if it doesn't already exist. As a result, the return value
// will never be nullptr.
virtual mozilla::PendingPlayerTracker* GetOrCreatePendingPlayerTracker() = 0;
// Makes the images on this document capable of having their animation
// active or suspended. An Image will animate as long as at least one of its
// owning Documents needs it to animate; otherwise it can suspend.