Bug 541588 subpatch 1: Change method signatures in nsSMILAnimationController, and subclass nsRefreshObserver. r=roc

This commit is contained in:
Daniel Holbert 2010-03-18 21:14:40 -07:00
Родитель 33500804db
Коммит 3fa0080345
3 изменённых файлов: 57 добавлений и 17 удалений

Просмотреть файл

@ -1360,7 +1360,7 @@ protected:
#ifdef MOZ_SMIL
// SMIL Animation Controller, lazily-initialized in GetAnimationController
nsAutoPtr<nsSMILAnimationController> mAnimationController;
nsRefPtr<nsSMILAnimationController> mAnimationController;
#endif // MOZ_SMIL
// Table of element properties for this document.

Просмотреть файл

@ -62,6 +62,20 @@
//
const PRUint32 nsSMILAnimationController::kTimerInterval = 22;
// Helper method
static nsRefreshDriver*
GetRefreshDriverForDoc(nsIDocument* aDoc)
{
nsIPresShell* shell = aDoc->GetPrimaryShell();
if (!shell) {
return nsnull;
}
nsPresContext* context = shell->GetPresContext();
return context ? context->RefreshDriver() : nsnull;
}
//----------------------------------------------------------------------
// ctors, dtors, factory methods
@ -75,10 +89,8 @@ nsSMILAnimationController::nsSMILAnimationController()
nsSMILAnimationController::~nsSMILAnimationController()
{
if (mTimer) {
mTimer->Cancel();
mTimer = nsnull;
}
StopSampling(GetRefreshDriverForDoc(mDocument));
mTimer = nsnull;
NS_ASSERTION(mAnimationElementTable.Count() == 0,
"Animation controller shouldn't be tracking any animation"
@ -125,7 +137,7 @@ nsSMILAnimationController::Pause(PRUint32 aType)
nsSMILTimeContainer::Pause(aType);
if (mPauseState) {
StopTimer();
StopSampling(GetRefreshDriverForDoc(mDocument));
}
}
@ -137,7 +149,8 @@ nsSMILAnimationController::Resume(PRUint32 aType)
nsSMILTimeContainer::Resume(aType);
if (wasPaused && !mPauseState && mChildContainerTable.Count()) {
StartTimer();
Sample(); // Run the first sample manually
StartSampling(GetRefreshDriverForDoc(mDocument));
}
}
@ -148,6 +161,22 @@ nsSMILAnimationController::GetParentTime() const
return PR_Now() / PR_USEC_PER_MSEC;
}
//----------------------------------------------------------------------
// nsARefreshObserver methods:
NS_IMPL_ADDREF(nsSMILAnimationController)
NS_IMPL_RELEASE(nsSMILAnimationController)
// nsRefreshDriver Callback function
// XXXdholbert NOTE: This function isn't used yet
void
nsSMILAnimationController::WillRefresh(mozilla::TimeStamp aTime)
{
// XXXdholbert Eventually we should be sampling based on aTime. For now,
// though, we keep track of the time on our own, and we just use
// nsRefreshDriver for scheduling samples.
Sample();
}
//----------------------------------------------------------------------
// Animation element registration methods:
@ -226,14 +255,11 @@ nsSMILAnimationController::Notify(nsITimer* timer, void* aClosure)
}
nsresult
nsSMILAnimationController::StartTimer()
nsSMILAnimationController::StartSampling(nsRefreshDriver* aRefreshDriver)
{
NS_ENSURE_TRUE(mTimer, NS_ERROR_FAILURE);
NS_ASSERTION(mPauseState == 0, "Starting timer but controller is paused");
// Run the first sample manually
Sample();
//
// XXX Make this self-tuning. Sounds like control theory to me and not
// something I'm familiar with.
@ -245,7 +271,7 @@ nsSMILAnimationController::StartTimer()
}
nsresult
nsSMILAnimationController::StopTimer()
nsSMILAnimationController::StopSampling(nsRefreshDriver* aRefreshDriver)
{
NS_ENSURE_TRUE(mTimer, NS_ERROR_FAILURE);
@ -668,7 +694,8 @@ nsSMILAnimationController::AddChild(nsSMILTimeContainer& aChild)
NS_ENSURE_TRUE(key,NS_ERROR_OUT_OF_MEMORY);
if (!mPauseState && mChildContainerTable.Count() == 1) {
StartTimer();
Sample(); // Run the first sample manually
StartSampling(GetRefreshDriverForDoc(mDocument));
}
return NS_OK;
@ -680,6 +707,6 @@ nsSMILAnimationController::RemoveChild(nsSMILTimeContainer& aChild)
mChildContainerTable.RemoveEntry(&aChild);
if (!mPauseState && mChildContainerTable.Count() == 0) {
StopTimer();
StopSampling(GetRefreshDriverForDoc(mDocument));
}
}

Просмотреть файл

@ -48,6 +48,7 @@
#include "nsSMILTimeContainer.h"
#include "nsSMILCompositorTable.h"
#include "nsSMILMilestone.h"
#include "nsRefreshDriver.h"
struct nsSMILTargetIdentifier;
class nsISMILAnimationElement;
@ -66,7 +67,8 @@ class nsIDocument;
// a compound document. These time containers can be paused individually or
// here, at the document level.
//
class nsSMILAnimationController : public nsSMILTimeContainer
class nsSMILAnimationController : public nsSMILTimeContainer,
public nsARefreshObserver
{
public:
nsSMILAnimationController();
@ -77,6 +79,12 @@ public:
virtual void Resume(PRUint32 aType);
virtual nsSMILTime GetParentTime() const;
// nsARefreshObserver
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
virtual void WillRefresh(mozilla::TimeStamp aTime);
// Methods for registering and enumerating animation elements
void RegisterAnimationElement(nsISMILAnimationElement* aAnimationElement);
void UnregisterAnimationElement(nsISMILAnimationElement* aAnimationElement);
@ -102,6 +110,10 @@ public:
void Traverse(nsCycleCollectionTraversalCallback* aCallback);
void Unlink();
// Methods for controlling whether we're sampling
nsresult StartSampling(nsRefreshDriver* aRefreshDriver);
nsresult StopSampling(nsRefreshDriver* aRefreshDriver);
protected:
// Typedefs
typedef nsPtrHashKey<nsSMILTimeContainer> TimeContainerPtrKey;
@ -138,8 +150,6 @@ protected:
// Timer-related implementation helpers
static void Notify(nsITimer* aTimer, void* aClosure);
nsresult StartTimer();
nsresult StopTimer();
// Sample-related callbacks and implementation helpers
virtual void DoSample();
@ -165,6 +175,9 @@ protected:
virtual void RemoveChild(nsSMILTimeContainer& aChild);
// Members
nsAutoRefCnt mRefCnt;
NS_DECL_OWNINGTHREAD
static const PRUint32 kTimerInterval;
nsCOMPtr<nsITimer> mTimer;
AnimationElementHashtable mAnimationElementTable;