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
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SMIL_SMILANIMATIONCONTROLLER_H_
|
|
|
|
#define DOM_SMIL_SMILANIMATIONCONTROLLER_H_
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2019-01-01 12:16:21 +03:00
|
|
|
#include "mozilla/SMILCompositorTable.h"
|
2019-01-02 10:21:13 +03:00
|
|
|
#include "mozilla/SMILMilestone.h"
|
|
|
|
#include "mozilla/SMILTimeContainer.h"
|
2020-02-25 23:03:26 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2020-08-05 00:17:50 +03:00
|
|
|
#include "nsRefreshObservers.h"
|
|
|
|
|
|
|
|
class nsRefreshDriver;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-03-19 07:18:45 +04:00
|
|
|
namespace mozilla {
|
2019-01-02 10:21:13 +03:00
|
|
|
struct SMILTargetIdentifier;
|
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
|
2013-03-19 07:18:45 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-28 14:47:58 +03:00
|
|
|
// SMILAnimationController
|
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
|
2018-12-31 17:10:19 +03:00
|
|
|
// at most one animation controller per document so that frame-rate tuning can
|
2009-01-15 07:38:07 +03:00
|
|
|
// 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.
|
|
|
|
//
|
2019-01-02 10:21:13 +03:00
|
|
|
class SMILAnimationController final : public SMILTimeContainer,
|
|
|
|
public nsARefreshObserver {
|
2010-09-18 07:46:48 +04:00
|
|
|
public:
|
2019-01-02 16:05:23 +03:00
|
|
|
explicit SMILAnimationController(mozilla::dom::Document* aDoc);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
// Clears mDocument pointer. (Called by our mozilla::dom::Document when it's
|
|
|
|
// going away)
|
2011-04-28 23:02:20 +04:00
|
|
|
void Disconnect();
|
|
|
|
|
2019-01-25 06:24:01 +03:00
|
|
|
// SMILContainer
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Pause(uint32_t aType) override;
|
|
|
|
virtual void Resume(uint32_t aType) override;
|
2019-01-25 06:24:01 +03:00
|
|
|
virtual SMILTime 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-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:
|
2018-12-28 14:47:58 +03:00
|
|
|
~SMILAnimationController();
|
2014-06-23 23:56:07 +04:00
|
|
|
|
2020-07-15 13:37:55 +03:00
|
|
|
// alias declarations
|
|
|
|
using TimeContainerPtrKey = nsPtrHashKey<SMILTimeContainer>;
|
|
|
|
using TimeContainerHashtable = nsTHashtable<TimeContainerPtrKey>;
|
|
|
|
using AnimationElementPtrKey = nsPtrHashKey<dom::SVGAnimationElement>;
|
|
|
|
using AnimationElementHashtable = nsTHashtable<AnimationElementPtrKey>;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
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,
|
2019-01-01 12:16:21 +03:00
|
|
|
SMILCompositorTable* aCompositorTable, bool& aStyleFlushNeeded);
|
2016-05-23 04:47:14 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool GetTargetIdentifierForAnimation(
|
2013-03-19 07:18:45 +04:00
|
|
|
mozilla::dom::SVGAnimationElement* aAnimElem,
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTargetIdentifier& aResult);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Methods for adding/removing time containers
|
2019-01-02 10:21:13 +03:00
|
|
|
virtual nsresult AddChild(SMILTimeContainer& aChild) override;
|
|
|
|
virtual void RemoveChild(SMILTimeContainer& 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).
|
2019-01-25 06:24:01 +03:00
|
|
|
SMILTime mAvgTimeBetweenSamples;
|
2010-11-24 02:31:17 +03:00
|
|
|
|
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
|
2019-01-02 16:05:23 +03:00
|
|
|
mozilla::dom::Document* mDocument;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// 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)
|
2020-02-25 23:03:26 +03:00
|
|
|
UniquePtr<SMILCompositorTable> mLastCompositorTable;
|
2009-01-15 07:38:07 +03:00
|
|
|
};
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SMIL_SMILANIMATIONCONTROLLER_H_
|