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: */
|
2012-05-21 15:12:37 +04: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/. */
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
#ifndef NS_SMILANIMATIONCONTROLLER_H_
|
|
|
|
#define NS_SMILANIMATIONCONTROLLER_H_
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
#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 23:00:49 +03:00
|
|
|
#include "nsSMILMilestone.h"
|
2010-03-19 07:14:40 +03:00
|
|
|
#include "nsRefreshDriver.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-02-21 00:13:11 +03:00
|
|
|
struct nsSMILTargetIdentifier;
|
2009-01-15 07:38:07 +03:00
|
|
|
class nsIDocument;
|
|
|
|
|
2013-03-19 07:18:45 +04:00
|
|
|
namespace mozilla {
|
2015-02-17 01:15:02 +03:00
|
|
|
class RestyleTracker;
|
2013-03-19 07:18:45 +04:00
|
|
|
namespace dom {
|
2017-04-26 07:00:11 +03:00
|
|
|
class Element;
|
2013-03-19 07:18:45 +04:00
|
|
|
class SVGAnimationElement;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-03-19 07:18:45 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSMILAnimationController
|
2009-07-15 22:33:31 +04:00
|
|
|
//
|
2009-01-15 07:38:07 +03: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.
|
|
|
|
//
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsSMILAnimationController final : public nsSMILTimeContainer,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsARefreshObserver
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2010-09-18 07:46:48 +04:00
|
|
|
public:
|
2014-08-08 17:49:39 +04:00
|
|
|
explicit nsSMILAnimationController(nsIDocument* aDoc);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2011-04-28 23:02:20 +04:00
|
|
|
// Clears mDocument pointer. (Called by our nsIDocument when it's going away)
|
|
|
|
void Disconnect();
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
// nsSMILContainer
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Pause(uint32_t aType) override;
|
|
|
|
virtual void Resume(uint32_t aType) override;
|
|
|
|
virtual nsSMILTime GetParentTime() const override;
|
2009-07-15 22:33:31 +04:00
|
|
|
|
2010-03-19 07:14:40 +03:00
|
|
|
// nsARefreshObserver
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef() override;
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release() override;
|
2010-03-19 07:14:40 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) override;
|
2010-03-19 07:14:40 +03:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
// Methods for registering and enumerating animation elements
|
2013-03-19 07:18:45 +04:00
|
|
|
void RegisterAnimationElement(mozilla::dom::SVGAnimationElement* aAnimationElement);
|
|
|
|
void UnregisterAnimationElement(mozilla::dom::SVGAnimationElement* aAnimationElement);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2009-01-22 04:00:27 +03: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)
|
2012-03-20 22:02:38 +04:00
|
|
|
// This will flush pending style changes for the document.
|
2011-10-17 18:59:28 +04:00
|
|
|
void Resample() { DoSample(false); }
|
2011-12-15 08:42:15 +04:00
|
|
|
|
2010-11-10 02:21:03 +03:00
|
|
|
void SetResampleNeeded()
|
|
|
|
{
|
2015-07-31 07:14:46 +03:00
|
|
|
if (!mRunningSample && !mResampleNeeded) {
|
|
|
|
FlagDocumentNeedsFlush();
|
2011-10-17 18:59:28 +04:00
|
|
|
mResampleNeeded = true;
|
2010-11-10 02:21:03 +03:00
|
|
|
}
|
|
|
|
}
|
2012-03-20 22:02:38 +04:00
|
|
|
|
|
|
|
// This will flush pending style changes for the document.
|
2009-01-22 04:00:27 +03:00
|
|
|
void FlushResampleRequests()
|
|
|
|
{
|
|
|
|
if (!mResampleNeeded)
|
|
|
|
return;
|
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
Resample();
|
2009-01-22 04:00:27 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Methods for handling page transitions
|
2009-01-22 04:00:27 +03:00
|
|
|
void OnPageShow();
|
|
|
|
void OnPageHide();
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Methods for supporting cycle-collection
|
2009-01-22 04:00:27 +03:00
|
|
|
void Traverse(nsCycleCollectionTraversalCallback* aCallback);
|
|
|
|
void Unlink();
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-10-20 03:53:52 +04:00
|
|
|
// Methods for relaying the availability of the refresh driver
|
|
|
|
void NotifyRefreshDriverCreated(nsRefreshDriver* aRefreshDriver);
|
|
|
|
void NotifyRefreshDriverDestroying(nsRefreshDriver* aRefreshDriver);
|
2010-03-19 07:14:40 +03:00
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
// Helper to check if we have any animation elements at all
|
2015-07-31 07:14:46 +03:00
|
|
|
bool HasRegisteredAnimations() const
|
|
|
|
{
|
|
|
|
return mAnimationElementTable.Count() != 0;
|
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2015-02-17 01:15:02 +03:00
|
|
|
void AddStyleUpdatesTo(mozilla::RestyleTracker& aTracker);
|
2015-07-31 07:14:46 +03:00
|
|
|
bool MightHavePendingStyleUpdates() const
|
|
|
|
{
|
|
|
|
return mMightHavePendingStyleUpdates;
|
|
|
|
}
|
2015-02-17 01:15:02 +03:00
|
|
|
|
2017-04-26 07:00:11 +03:00
|
|
|
bool PreTraverse();
|
|
|
|
bool PreTraverseInSubtree(mozilla::dom::Element* aRoot);
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
protected:
|
2014-06-23 23:56:07 +04:00
|
|
|
~nsSMILAnimationController();
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
// Typedefs
|
|
|
|
typedef nsPtrHashKey<nsSMILTimeContainer> TimeContainerPtrKey;
|
|
|
|
typedef nsTHashtable<TimeContainerPtrKey> TimeContainerHashtable;
|
2013-03-19 07:18:45 +04:00
|
|
|
typedef nsPtrHashKey<mozilla::dom::SVGAnimationElement> AnimationElementPtrKey;
|
2009-01-15 07:38:07 +03:00
|
|
|
typedef nsTHashtable<AnimationElementPtrKey> AnimationElementHashtable;
|
|
|
|
|
2011-04-28 23:05:24 +04:00
|
|
|
// Returns mDocument's refresh driver, if it's got one.
|
|
|
|
nsRefreshDriver* GetRefreshDriver();
|
|
|
|
|
2010-10-20 03:53:52 +04:00
|
|
|
// Methods for controlling whether we're sampling
|
|
|
|
void StartSampling(nsRefreshDriver* aRefreshDriver);
|
|
|
|
void StopSampling(nsRefreshDriver* aRefreshDriver);
|
|
|
|
|
2011-04-02 00:33:20 +04:00
|
|
|
// Wrapper for StartSampling that defers if no animations are registered.
|
|
|
|
void MaybeStartSampling(nsRefreshDriver* aRefreshDriver);
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
// Sample-related callbacks and implementation helpers
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DoSample() override;
|
2011-09-29 10:19:26 +04:00
|
|
|
void DoSample(bool aSkipUnchangedContainers);
|
2010-07-03 09:52:51 +04:00
|
|
|
|
|
|
|
void RewindElements();
|
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
void DoMilestoneSamples();
|
2010-07-03 09:52:51 +04:00
|
|
|
|
2013-03-19 07:18:45 +04:00
|
|
|
static void SampleTimedElement(mozilla::dom::SVGAnimationElement* aElement,
|
2009-01-15 07:38:07 +03:00
|
|
|
TimeContainerHashtable* aActiveContainers);
|
2016-05-23 04:47:14 +03:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
static void AddAnimationToCompositorTable(
|
2016-05-23 04:47:14 +03:00
|
|
|
mozilla::dom::SVGAnimationElement* aElement,
|
|
|
|
nsSMILCompositorTable* aCompositorTable,
|
|
|
|
bool& aStyleFlushNeeded);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool GetTargetIdentifierForAnimation(
|
2013-03-19 07:18:45 +04:00
|
|
|
mozilla::dom::SVGAnimationElement* aAnimElem, nsSMILTargetIdentifier& aResult);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Methods for adding/removing time containers
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult AddChild(nsSMILTimeContainer& aChild) override;
|
|
|
|
virtual void RemoveChild(nsSMILTimeContainer& aChild) override;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2011-12-15 08:42:15 +04:00
|
|
|
void FlagDocumentNeedsFlush();
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
// Members
|
2010-03-19 07:14:40 +03:00
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
AnimationElementHashtable mAnimationElementTable;
|
|
|
|
TimeContainerHashtable mChildContainerTable;
|
2010-09-18 07:46:48 +04:00
|
|
|
mozilla::TimeStamp mCurrentSampleTime;
|
|
|
|
mozilla::TimeStamp mStartTime;
|
2010-11-24 02:31:17 +03:00
|
|
|
|
|
|
|
// Average time between samples from the refresh driver. This is used to
|
|
|
|
// detect large unexpected gaps between samples such as can occur when the
|
|
|
|
// computer sleeps. The nature of the SMIL model means that catching up these
|
|
|
|
// large gaps can be expensive as, for example, many events may need to be
|
|
|
|
// dispatched for the intervening time when no samples were received.
|
|
|
|
//
|
|
|
|
// In such cases, we ignore the intervening gap and continue sampling from
|
|
|
|
// when we were expecting the next sample to arrive.
|
|
|
|
//
|
|
|
|
// Note that we only do this for SMIL and not CSS transitions (which doesn't
|
|
|
|
// have so much work to do to catch up) nor scripted animations (which expect
|
|
|
|
// animation time to follow real time).
|
|
|
|
//
|
|
|
|
// This behaviour does not affect pausing (since we're not *expecting* any
|
|
|
|
// samples then) nor seeking (where the SMIL model behaves somewhat
|
|
|
|
// differently such as not dispatching events).
|
|
|
|
nsSMILTime mAvgTimeBetweenSamples;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mResampleNeeded;
|
2010-10-20 03:52:49 +04:00
|
|
|
// If we're told to start sampling but there are no animation elements we just
|
|
|
|
// record the time, set the following flag, and then wait until we have an
|
|
|
|
// animation element. Then we'll reset this flag and actually start sampling.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDeferredStartSampling;
|
|
|
|
bool mRunningSample;
|
2009-07-15 22:33:31 +04:00
|
|
|
|
2014-05-20 16:34:26 +04:00
|
|
|
// Are we registered with our document's refresh driver?
|
|
|
|
bool mRegisteredWithRefreshDriver;
|
|
|
|
|
2015-07-31 07:14:46 +03:00
|
|
|
// Have we updated animated values without adding them to the restyle tracker?
|
|
|
|
bool mMightHavePendingStyleUpdates;
|
|
|
|
|
2009-01-15 07:38:07 +03: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 22:33:31 +04:00
|
|
|
// but isn't anymore for some reason. (e.g. if its <animate> element is
|
2009-01-15 07:38:07 +03:00
|
|
|
// removed or retargeted)
|
|
|
|
nsAutoPtr<nsSMILCompositorTable> mLastCompositorTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NS_SMILANIMATIONCONTROLLER_H_
|