2009-01-14 20:38:07 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SMIL module.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Brian Birtles.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brian Birtles <birtles@gmail.com>
|
|
|
|
* Daniel Holbert <dholbert@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef NS_SMILANIMATIONCONTROLLER_H_
|
|
|
|
#define NS_SMILANIMATIONCONTROLLER_H_
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsSMILTimeContainer.h"
|
|
|
|
#include "nsSMILCompositorTable.h"
|
2010-01-12 12:00:49 -08:00
|
|
|
#include "nsSMILMilestone.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-02-20 13:13:11 -08:00
|
|
|
struct nsSMILTargetIdentifier;
|
2009-01-14 20:38:07 -08:00
|
|
|
class nsISMILAnimationElement;
|
|
|
|
class nsIDocument;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSMILAnimationController
|
2009-07-15 11:33:31 -07:00
|
|
|
//
|
2009-01-14 20:38:07 -08:00
|
|
|
// The animation controller maintains the animation timer and determines the
|
|
|
|
// sample times and sample rate for all SMIL animations in a document. There is
|
|
|
|
// at most one animation controller per nsDocument so that frame-rate tuning can
|
|
|
|
// be performed at a document-level.
|
|
|
|
//
|
|
|
|
// The animation controller can contain many child time containers (timed
|
|
|
|
// document root objects) which may correspond to SVG document fragments within
|
|
|
|
// a compound document. These time containers can be paused individually or
|
|
|
|
// here, at the document level.
|
|
|
|
//
|
|
|
|
class nsSMILAnimationController : public nsSMILTimeContainer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsSMILAnimationController();
|
|
|
|
~nsSMILAnimationController();
|
|
|
|
|
|
|
|
// nsSMILContainer
|
|
|
|
virtual void Pause(PRUint32 aType);
|
|
|
|
virtual void Resume(PRUint32 aType);
|
|
|
|
virtual nsSMILTime GetParentTime() const;
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
// Methods for registering and enumerating animation elements
|
|
|
|
void RegisterAnimationElement(nsISMILAnimationElement* aAnimationElement);
|
|
|
|
void UnregisterAnimationElement(nsISMILAnimationElement* aAnimationElement);
|
|
|
|
|
2009-01-21 17:00:27 -08:00
|
|
|
// Methods for resampling all animations
|
|
|
|
// (A resample performs the same operations as a sample but doesn't advance
|
|
|
|
// the current time and doesn't check if the container is paused)
|
2010-01-12 12:00:49 -08:00
|
|
|
void Resample() { DoSample(PR_FALSE); }
|
2009-01-21 17:00:27 -08:00
|
|
|
void SetResampleNeeded() { mResampleNeeded = PR_TRUE; }
|
|
|
|
void FlushResampleRequests()
|
|
|
|
{
|
|
|
|
if (!mResampleNeeded)
|
|
|
|
return;
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
Resample();
|
2009-01-21 17:00:27 -08:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
// Methods for handling page transitions
|
2009-01-21 17:00:27 -08:00
|
|
|
void OnPageShow();
|
|
|
|
void OnPageHide();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
// Methods for supporting cycle-collection
|
2009-01-21 17:00:27 -08:00
|
|
|
void Traverse(nsCycleCollectionTraversalCallback* aCallback);
|
|
|
|
void Unlink();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Typedefs
|
|
|
|
typedef nsPtrHashKey<nsSMILTimeContainer> TimeContainerPtrKey;
|
|
|
|
typedef nsTHashtable<TimeContainerPtrKey> TimeContainerHashtable;
|
|
|
|
typedef nsPtrHashKey<nsISMILAnimationElement> AnimationElementPtrKey;
|
|
|
|
typedef nsTHashtable<AnimationElementPtrKey> AnimationElementHashtable;
|
|
|
|
|
2009-01-21 17:00:27 -08:00
|
|
|
struct SampleTimeContainerParams
|
|
|
|
{
|
|
|
|
TimeContainerHashtable* mActiveContainers;
|
|
|
|
PRBool mSkipUnchangedContainers;
|
2009-01-14 20:38:07 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SampleAnimationParams
|
|
|
|
{
|
|
|
|
TimeContainerHashtable* mActiveContainers;
|
|
|
|
nsSMILCompositorTable* mCompositorTable;
|
|
|
|
};
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
struct GetMilestoneElementsParams
|
|
|
|
{
|
|
|
|
nsTArray<nsRefPtr<nsISMILAnimationElement> > mElements;
|
|
|
|
nsSMILMilestone mMilestone;
|
|
|
|
};
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
// Factory methods
|
|
|
|
friend nsSMILAnimationController*
|
|
|
|
NS_NewSMILAnimationController(nsIDocument* aDoc);
|
|
|
|
nsresult Init(nsIDocument* aDoc);
|
|
|
|
|
|
|
|
// Cycle-collection implementation helpers
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator) CompositorTableEntryTraverse(
|
|
|
|
nsSMILCompositor* aCompositor, void* aArg);
|
|
|
|
|
|
|
|
// Timer-related implementation helpers
|
|
|
|
static void Notify(nsITimer* aTimer, void* aClosure);
|
|
|
|
nsresult StartTimer();
|
|
|
|
nsresult StopTimer();
|
|
|
|
|
|
|
|
// Sample-related callbacks and implementation helpers
|
|
|
|
virtual void DoSample();
|
2009-01-21 17:00:27 -08:00
|
|
|
void DoSample(PRBool aSkipUnchangedContainers);
|
2010-01-12 12:00:49 -08:00
|
|
|
void DoMilestoneSamples();
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator) GetNextMilestone(
|
|
|
|
TimeContainerPtrKey* aKey, void* aData);
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator) GetMilestoneElements(
|
|
|
|
TimeContainerPtrKey* aKey, void* aData);
|
2009-01-21 17:00:27 -08:00
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator) SampleTimeContainer(
|
2009-01-14 20:38:07 -08:00
|
|
|
TimeContainerPtrKey* aKey, void* aData);
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator) SampleAnimation(
|
|
|
|
AnimationElementPtrKey* aKey, void* aData);
|
|
|
|
static void SampleTimedElement(nsISMILAnimationElement* aElement,
|
|
|
|
TimeContainerHashtable* aActiveContainers);
|
|
|
|
static void AddAnimationToCompositorTable(
|
|
|
|
nsISMILAnimationElement* aElement, nsSMILCompositorTable* aCompositorTable);
|
2010-02-20 13:13:11 -08:00
|
|
|
static PRBool GetTargetIdentifierForAnimation(
|
|
|
|
nsISMILAnimationElement* aAnimElem, nsSMILTargetIdentifier& aResult);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
// Methods for adding/removing time containers
|
|
|
|
virtual nsresult AddChild(nsSMILTimeContainer& aChild);
|
|
|
|
virtual void RemoveChild(nsSMILTimeContainer& aChild);
|
|
|
|
|
|
|
|
// Members
|
|
|
|
static const PRUint32 kTimerInterval;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
AnimationElementHashtable mAnimationElementTable;
|
|
|
|
TimeContainerHashtable mChildContainerTable;
|
2009-01-21 17:00:27 -08:00
|
|
|
PRPackedBool mResampleNeeded;
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
// Store raw ptr to mDocument. It owns the controller, so controller
|
|
|
|
// shouldn't outlive it
|
|
|
|
nsIDocument* mDocument;
|
|
|
|
|
|
|
|
// Contains compositors used in our last sample. We keep this around
|
|
|
|
// so we can detect when an element/attribute used to be animated,
|
2009-07-15 11:33:31 -07:00
|
|
|
// but isn't anymore for some reason. (e.g. if its <animate> element is
|
2009-01-14 20:38:07 -08:00
|
|
|
// removed or retargeted)
|
|
|
|
nsAutoPtr<nsSMILCompositorTable> mLastCompositorTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsSMILAnimationController* NS_NewSMILAnimationController(nsIDocument *doc);
|
|
|
|
|
|
|
|
#endif // NS_SMILANIMATIONCONTROLLER_H_
|