2009-01-14 20:38:07 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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-14 20:38:07 -08:00
|
|
|
|
|
|
|
#include "nsSMILAnimationController.h"
|
|
|
|
#include "nsSMILCompositor.h"
|
2009-10-02 14:37:25 -07:00
|
|
|
#include "nsSMILCSSProperty.h"
|
|
|
|
#include "nsCSSProps.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsITimer.h"
|
2010-05-14 10:04:51 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsIDocument.h"
|
2013-03-18 20:18:45 -07:00
|
|
|
#include "mozilla/dom/SVGAnimationElement.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsSMILTimedElement.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2013-01-31 15:11:49 -08:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2012-12-11 13:12:47 -08:00
|
|
|
using namespace mozilla;
|
2010-05-14 10:04:51 -07:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSMILAnimationController implementation
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// ctors, dtors, factory methods
|
|
|
|
|
2011-04-28 12:02:20 -07:00
|
|
|
nsSMILAnimationController::nsSMILAnimationController(nsIDocument* aDoc)
|
2010-11-23 15:31:17 -08:00
|
|
|
: mAvgTimeBetweenSamples(0),
|
2011-10-17 07:59:28 -07:00
|
|
|
mResampleNeeded(false),
|
|
|
|
mDeferredStartSampling(false),
|
|
|
|
mRunningSample(false),
|
2011-04-28 12:02:20 -07:00
|
|
|
mDocument(aDoc)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2011-04-28 12:02:20 -07:00
|
|
|
NS_ABORT_IF_FALSE(aDoc, "need a non-null document");
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
mAnimationElementTable.Init();
|
|
|
|
mChildContainerTable.Init();
|
|
|
|
|
2011-04-28 12:05:24 -07:00
|
|
|
nsRefreshDriver* refreshDriver = GetRefreshDriver();
|
2010-09-17 20:46:48 -07:00
|
|
|
if (refreshDriver) {
|
|
|
|
mStartTime = refreshDriver->MostRecentRefresh();
|
|
|
|
} else {
|
|
|
|
mStartTime = mozilla::TimeStamp::Now();
|
|
|
|
}
|
|
|
|
mCurrentSampleTime = mStartTime;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
Begin();
|
2011-04-28 12:02:20 -07:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2011-04-28 12:02:20 -07:00
|
|
|
nsSMILAnimationController::~nsSMILAnimationController()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mAnimationElementTable.Count() == 0,
|
|
|
|
"Animation controller shouldn't be tracking any animation"
|
|
|
|
" elements when it dies");
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2011-04-28 12:02:20 -07:00
|
|
|
void
|
|
|
|
nsSMILAnimationController::Disconnect()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mDocument, "disconnecting when we weren't connected...?");
|
|
|
|
NS_ABORT_IF_FALSE(mRefCnt.get() == 1,
|
|
|
|
"Expecting to disconnect when doc is sole remaining owner");
|
2011-08-02 16:12:32 -07:00
|
|
|
NS_ASSERTION(mPauseState & nsSMILTimeContainer::PAUSE_PAGEHIDE,
|
|
|
|
"Expecting to be paused for pagehide before disconnect");
|
2011-04-28 12:02:20 -07:00
|
|
|
|
2011-04-28 12:05:24 -07:00
|
|
|
StopSampling(GetRefreshDriver());
|
2011-04-28 12:02:20 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocument = nullptr; // (raw pointer)
|
2011-04-28 12:02:20 -07:00
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSMILTimeContainer methods:
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSMILAnimationController::Pause(uint32_t aType)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
nsSMILTimeContainer::Pause(aType);
|
|
|
|
|
|
|
|
if (mPauseState) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mDeferredStartSampling = false;
|
2011-04-28 12:05:24 -07:00
|
|
|
StopSampling(GetRefreshDriver());
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSMILAnimationController::Resume(uint32_t aType)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wasPaused = (mPauseState != 0);
|
2010-11-23 15:31:17 -08:00
|
|
|
// Update mCurrentSampleTime so that calls to GetParentTime--used for
|
|
|
|
// calculating parent offsets--are accurate
|
|
|
|
mCurrentSampleTime = mozilla::TimeStamp::Now();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
nsSMILTimeContainer::Resume(aType);
|
|
|
|
|
2009-01-21 17:00:27 -08:00
|
|
|
if (wasPaused && !mPauseState && mChildContainerTable.Count()) {
|
2010-03-18 21:14:40 -07:00
|
|
|
Sample(); // Run the first sample manually
|
2011-04-28 12:05:24 -07:00
|
|
|
MaybeStartSampling(GetRefreshDriver());
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTime
|
|
|
|
nsSMILAnimationController::GetParentTime() const
|
|
|
|
{
|
2010-09-17 20:46:48 -07:00
|
|
|
return (nsSMILTime)(mCurrentSampleTime - mStartTime).ToMilliseconds();
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-03-18 21:14:40 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsARefreshObserver methods:
|
|
|
|
NS_IMPL_ADDREF(nsSMILAnimationController)
|
|
|
|
NS_IMPL_RELEASE(nsSMILAnimationController)
|
|
|
|
|
|
|
|
// nsRefreshDriver Callback function
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::WillRefresh(mozilla::TimeStamp aTime)
|
|
|
|
{
|
2010-09-17 20:46:48 -07:00
|
|
|
// Although we never expect aTime to go backwards, when we initialise the
|
|
|
|
// animation controller, if we can't get hold of a refresh driver we
|
|
|
|
// initialise mCurrentSampleTime to Now(). It may be possible that after
|
|
|
|
// doing so we get sampled by a refresh driver whose most recent refresh time
|
|
|
|
// predates when we were initialised, so to be safe we make sure to take the
|
|
|
|
// most recent time here.
|
2013-01-15 04:22:03 -08:00
|
|
|
aTime = std::max(mCurrentSampleTime, aTime);
|
2010-11-23 15:31:17 -08:00
|
|
|
|
|
|
|
// Sleep detection: If the time between samples is a whole lot greater than we
|
|
|
|
// were expecting then we assume the computer went to sleep or someone's
|
|
|
|
// messing with the clock. In that case, fiddle our parent offset and use our
|
|
|
|
// average time between samples to calculate the new sample time. This
|
|
|
|
// prevents us from hanging while trying to catch up on all the missed time.
|
|
|
|
|
|
|
|
// Smoothing of coefficient for the average function. 0.2 should let us track
|
|
|
|
// the sample rate reasonably tightly without being overly affected by
|
|
|
|
// occasional delays.
|
|
|
|
static const double SAMPLE_DUR_WEIGHTING = 0.2;
|
|
|
|
// If the elapsed time exceeds our expectation by this number of times we'll
|
|
|
|
// initiate special behaviour to basically ignore the intervening time.
|
|
|
|
static const double SAMPLE_DEV_THRESHOLD = 200.0;
|
|
|
|
|
|
|
|
nsSMILTime elapsedTime =
|
|
|
|
(nsSMILTime)(aTime - mCurrentSampleTime).ToMilliseconds();
|
|
|
|
if (mAvgTimeBetweenSamples == 0) {
|
2013-03-04 14:05:23 -08:00
|
|
|
// First sample.
|
2010-11-23 15:31:17 -08:00
|
|
|
mAvgTimeBetweenSamples = elapsedTime;
|
|
|
|
} else {
|
2013-03-04 14:05:23 -08:00
|
|
|
if (elapsedTime > SAMPLE_DEV_THRESHOLD * mAvgTimeBetweenSamples) {
|
|
|
|
// Unexpectedly long delay between samples.
|
|
|
|
NS_WARNING("Detected really long delay between samples, continuing from "
|
|
|
|
"previous sample");
|
|
|
|
mParentOffset += elapsedTime - mAvgTimeBetweenSamples;
|
|
|
|
}
|
|
|
|
// Update the moving average. Due to truncation here the average will
|
|
|
|
// normally be a little less than it should be but that's probably ok.
|
2010-11-23 15:31:17 -08:00
|
|
|
mAvgTimeBetweenSamples =
|
|
|
|
(nsSMILTime)(elapsedTime * SAMPLE_DUR_WEIGHTING +
|
|
|
|
mAvgTimeBetweenSamples * (1.0 - SAMPLE_DUR_WEIGHTING));
|
|
|
|
}
|
|
|
|
mCurrentSampleTime = aTime;
|
|
|
|
|
2010-03-18 21:14:40 -07:00
|
|
|
Sample();
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Animation element registration methods:
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::RegisterAnimationElement(
|
2013-03-18 20:18:45 -07:00
|
|
|
SVGAnimationElement* aAnimationElement)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
mAnimationElementTable.PutEntry(aAnimationElement);
|
2010-03-21 12:22:36 -07:00
|
|
|
if (mDeferredStartSampling) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mDeferredStartSampling = false;
|
2010-11-06 12:13:01 -07:00
|
|
|
if (mChildContainerTable.Count()) {
|
|
|
|
// mAnimationElementTable was empty, but now we've added its 1st element
|
|
|
|
NS_ABORT_IF_FALSE(mAnimationElementTable.Count() == 1,
|
|
|
|
"we shouldn't have deferred sampling if we already had "
|
|
|
|
"animations registered");
|
2011-04-28 12:05:24 -07:00
|
|
|
StartSampling(GetRefreshDriver());
|
2011-11-04 09:24:04 -07:00
|
|
|
Sample(); // Run the first sample manually
|
2010-11-06 12:13:01 -07:00
|
|
|
} // else, don't sample until a time container is registered (via AddChild)
|
2010-03-21 12:22:36 -07:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::UnregisterAnimationElement(
|
2013-03-18 20:18:45 -07:00
|
|
|
SVGAnimationElement* aAnimationElement)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
mAnimationElementTable.RemoveEntry(aAnimationElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Page show/hide
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::OnPageShow()
|
|
|
|
{
|
|
|
|
Resume(nsSMILTimeContainer::PAUSE_PAGEHIDE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::OnPageHide()
|
|
|
|
{
|
|
|
|
Pause(nsSMILTimeContainer::PAUSE_PAGEHIDE);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Cycle-collection support
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::Traverse(
|
|
|
|
nsCycleCollectionTraversalCallback* aCallback)
|
|
|
|
{
|
|
|
|
// Traverse last compositor table
|
|
|
|
if (mLastCompositorTable) {
|
|
|
|
mLastCompositorTable->EnumerateEntries(CompositorTableEntryTraverse,
|
|
|
|
aCallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
/*static*/ PLDHashOperator
|
2009-01-14 20:38:07 -08:00
|
|
|
nsSMILAnimationController::CompositorTableEntryTraverse(
|
|
|
|
nsSMILCompositor* aCompositor,
|
|
|
|
void* aArg)
|
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback* cb =
|
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(aArg);
|
|
|
|
aCompositor->Traverse(cb);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::Unlink()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastCompositorTable = nullptr;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-10-19 16:53:52 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Refresh driver lifecycle related methods
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::NotifyRefreshDriverCreated(
|
|
|
|
nsRefreshDriver* aRefreshDriver)
|
|
|
|
{
|
2011-04-01 13:33:20 -07:00
|
|
|
if (!mPauseState) {
|
|
|
|
MaybeStartSampling(aRefreshDriver);
|
2010-10-19 16:53:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::NotifyRefreshDriverDestroying(
|
|
|
|
nsRefreshDriver* aRefreshDriver)
|
|
|
|
{
|
|
|
|
if (!mPauseState && !mDeferredStartSampling) {
|
|
|
|
StopSampling(aRefreshDriver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Timer-related implementation helpers
|
|
|
|
|
2010-03-21 23:42:53 -07:00
|
|
|
void
|
2010-03-18 21:14:40 -07:00
|
|
|
nsSMILAnimationController::StartSampling(nsRefreshDriver* aRefreshDriver)
|
2010-03-18 07:58:09 -07:00
|
|
|
{
|
2010-03-21 23:42:53 -07:00
|
|
|
NS_ASSERTION(mPauseState == 0, "Starting sampling but controller is paused");
|
2010-10-19 16:52:49 -07:00
|
|
|
NS_ASSERTION(!mDeferredStartSampling,
|
|
|
|
"Started sampling but the deferred start flag is still set");
|
2010-03-21 23:42:53 -07:00
|
|
|
if (aRefreshDriver) {
|
2011-04-28 12:05:24 -07:00
|
|
|
NS_ABORT_IF_FALSE(!GetRefreshDriver() ||
|
|
|
|
aRefreshDriver == GetRefreshDriver(),
|
2010-03-21 23:42:53 -07:00
|
|
|
"Starting sampling with wrong refresh driver");
|
2010-11-23 15:31:17 -08:00
|
|
|
// We're effectively resuming from a pause so update our current sample time
|
|
|
|
// or else it will confuse our "average time between samples" calculations.
|
|
|
|
mCurrentSampleTime = mozilla::TimeStamp::Now();
|
2010-03-21 23:42:53 -07:00
|
|
|
aRefreshDriver->AddRefreshObserver(this, Flush_Style);
|
|
|
|
}
|
2010-03-18 07:58:09 -07:00
|
|
|
}
|
|
|
|
|
2010-03-21 23:42:53 -07:00
|
|
|
void
|
2010-03-18 21:14:40 -07:00
|
|
|
nsSMILAnimationController::StopSampling(nsRefreshDriver* aRefreshDriver)
|
2010-03-18 07:58:09 -07:00
|
|
|
{
|
2010-03-21 23:42:53 -07:00
|
|
|
if (aRefreshDriver) {
|
|
|
|
// NOTE: The document might already have been detached from its PresContext
|
|
|
|
// (and RefreshDriver), which would make GetRefreshDriverForDoc return null.
|
2011-04-28 12:05:24 -07:00
|
|
|
NS_ABORT_IF_FALSE(!GetRefreshDriver() ||
|
|
|
|
aRefreshDriver == GetRefreshDriver(),
|
2010-03-21 23:42:53 -07:00
|
|
|
"Stopping sampling with wrong refresh driver");
|
|
|
|
aRefreshDriver->RemoveRefreshObserver(this, Flush_Style);
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2011-04-01 13:33:20 -07:00
|
|
|
void
|
|
|
|
nsSMILAnimationController::MaybeStartSampling(nsRefreshDriver* aRefreshDriver)
|
|
|
|
{
|
|
|
|
if (mDeferredStartSampling) {
|
|
|
|
// We've received earlier 'MaybeStartSampling' calls, and we're
|
|
|
|
// deferring until we get a registered animation.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAnimationElementTable.Count()) {
|
|
|
|
StartSampling(aRefreshDriver);
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mDeferredStartSampling = true;
|
2011-04-01 13:33:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Sample-related methods and callbacks
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
PLDHashOperator
|
2010-02-20 13:13:11 -08:00
|
|
|
TransferCachedBaseValue(nsSMILCompositor* aCompositor,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
nsSMILCompositorTable* lastCompositorTable =
|
|
|
|
static_cast<nsSMILCompositorTable*>(aData);
|
|
|
|
nsSMILCompositor* lastCompositor =
|
|
|
|
lastCompositorTable->GetEntry(aCompositor->GetKey());
|
|
|
|
|
|
|
|
if (lastCompositor) {
|
|
|
|
aCompositor->StealCachedBaseValue(lastCompositor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
PLDHashOperator
|
2009-07-14 12:33:29 -07:00
|
|
|
RemoveCompositorFromTable(nsSMILCompositor* aCompositor,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
nsSMILCompositorTable* lastCompositorTable =
|
2009-07-15 11:33:31 -07:00
|
|
|
static_cast<nsSMILCompositorTable*>(aData);
|
2009-07-14 12:33:29 -07:00
|
|
|
lastCompositorTable->RemoveEntry(aCompositor->GetKey());
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
PLDHashOperator
|
2009-07-14 12:33:29 -07:00
|
|
|
DoClearAnimationEffects(nsSMILCompositor* aCompositor,
|
|
|
|
void* /*aData*/)
|
|
|
|
{
|
|
|
|
aCompositor->ClearAnimationEffects();
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
PLDHashOperator
|
2009-07-14 12:33:29 -07:00
|
|
|
DoComposeAttribute(nsSMILCompositor* aCompositor,
|
|
|
|
void* /*aData*/)
|
|
|
|
{
|
|
|
|
aCompositor->ComposeAttribute();
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
void
|
|
|
|
nsSMILAnimationController::DoSample()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
DoSample(true); // Skip unchanged time containers
|
2009-01-21 17:00:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSMILAnimationController::DoSample(bool aSkipUnchangedContainers)
|
2009-01-21 17:00:27 -08:00
|
|
|
{
|
2011-04-28 12:02:20 -07:00
|
|
|
if (!mDocument) {
|
|
|
|
NS_ERROR("Shouldn't be sampling after document has disconnected");
|
|
|
|
return;
|
|
|
|
}
|
2012-08-28 22:32:56 -07:00
|
|
|
if (mRunningSample) {
|
|
|
|
NS_ERROR("Shouldn't be recursively sampling");
|
|
|
|
return;
|
|
|
|
}
|
2011-04-28 12:02:20 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mResampleNeeded = false;
|
2010-11-09 15:21:03 -08:00
|
|
|
// Set running sample flag -- do this before flushing styles so that when we
|
|
|
|
// flush styles we don't end up requesting extra samples
|
2012-12-11 13:12:47 -08:00
|
|
|
AutoRestore<bool> autoRestoreRunningSample(mRunningSample);
|
2011-10-17 07:59:28 -07:00
|
|
|
mRunningSample = true;
|
2012-03-20 11:02:38 -07:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
// STEP 1: Bring model up to date
|
2010-07-02 22:52:51 -07:00
|
|
|
// (i) Rewind elements where necessary
|
|
|
|
// (ii) Run milestone samples
|
|
|
|
RewindElements();
|
2010-01-12 12:00:49 -08:00
|
|
|
DoMilestoneSamples();
|
|
|
|
|
|
|
|
// STEP 2: Sample the child time containers
|
2009-01-14 20:38:07 -08:00
|
|
|
//
|
|
|
|
// When we sample the child time containers they will simply record the sample
|
|
|
|
// time in document time.
|
|
|
|
TimeContainerHashtable activeContainers;
|
|
|
|
activeContainers.Init(mChildContainerTable.Count());
|
2009-01-21 17:00:27 -08:00
|
|
|
SampleTimeContainerParams tcParams = { &activeContainers,
|
|
|
|
aSkipUnchangedContainers };
|
|
|
|
mChildContainerTable.EnumerateEntries(SampleTimeContainer, &tcParams);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
// STEP 3: (i) Sample the timed elements AND
|
2009-01-14 20:38:07 -08:00
|
|
|
// (ii) Create a table of compositors
|
2009-07-15 11:33:31 -07:00
|
|
|
//
|
2009-01-14 20:38:07 -08:00
|
|
|
// (i) Here we sample the timed elements (fetched from the
|
2013-03-18 20:18:45 -07:00
|
|
|
// SVGAnimationElements) which determine from the active time if the
|
2009-01-23 01:02:09 -08:00
|
|
|
// element is active and what its simple time etc. is. This information is
|
2009-01-14 20:38:07 -08:00
|
|
|
// then passed to its time client (nsSMILAnimationFunction).
|
|
|
|
//
|
|
|
|
// (ii) During the same loop we also build up a table that contains one
|
|
|
|
// compositor for each animated attribute and which maps animated elements to
|
|
|
|
// the corresponding compositor for their target attribute.
|
|
|
|
//
|
|
|
|
// Note that this compositor table needs to be allocated on the heap so we can
|
|
|
|
// store it until the next sample. This lets us find out which elements were
|
|
|
|
// animated in sample 'n-1' but not in sample 'n' (and hence need to have
|
|
|
|
// their animation effects removed in sample 'n').
|
|
|
|
//
|
|
|
|
// Parts (i) and (ii) are not functionally related but we combine them here to
|
|
|
|
// save iterating over the animation elements twice.
|
|
|
|
|
|
|
|
// Create the compositor table
|
2009-07-15 11:33:31 -07:00
|
|
|
nsAutoPtr<nsSMILCompositorTable>
|
2009-01-14 20:38:07 -08:00
|
|
|
currentCompositorTable(new nsSMILCompositorTable());
|
|
|
|
currentCompositorTable->Init(0);
|
|
|
|
|
2009-01-21 17:00:27 -08:00
|
|
|
SampleAnimationParams saParams = { &activeContainers,
|
|
|
|
currentCompositorTable };
|
2010-02-11 13:35:33 -08:00
|
|
|
mAnimationElementTable.EnumerateEntries(SampleAnimation,
|
|
|
|
&saParams);
|
2009-01-14 20:38:07 -08:00
|
|
|
activeContainers.Clear();
|
|
|
|
|
2010-02-20 13:13:11 -08:00
|
|
|
// STEP 4: Compare previous sample's compositors against this sample's.
|
|
|
|
// (Transfer cached base values across, & remove animation effects from
|
|
|
|
// no-longer-animated targets.)
|
2009-01-14 20:38:07 -08:00
|
|
|
if (mLastCompositorTable) {
|
2010-02-20 13:13:11 -08:00
|
|
|
// * Transfer over cached base values, from last sample's compositors
|
|
|
|
currentCompositorTable->EnumerateEntries(TransferCachedBaseValue,
|
|
|
|
mLastCompositorTable);
|
|
|
|
|
2009-07-14 12:33:29 -07:00
|
|
|
// * For each compositor in current sample's hash table, remove entry from
|
|
|
|
// prev sample's hash table -- we don't need to clear animation
|
|
|
|
// effects of those compositors, since they're still being animated.
|
|
|
|
currentCompositorTable->EnumerateEntries(RemoveCompositorFromTable,
|
|
|
|
mLastCompositorTable);
|
|
|
|
|
|
|
|
// * For each entry that remains in prev sample's hash table (i.e. for
|
|
|
|
// every target that's no longer animated), clear animation effects.
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastCompositorTable->EnumerateEntries(DoClearAnimationEffects, nullptr);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2012-12-11 13:12:47 -08:00
|
|
|
// return early if there are no active animations to avoid a style flush
|
|
|
|
if (currentCompositorTable->Count() == 0) {
|
|
|
|
mLastCompositorTable = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> kungFuDeathGrip(mDocument); // keeps 'this' alive too
|
|
|
|
mDocument->FlushPendingNotifications(Flush_Style);
|
|
|
|
|
|
|
|
// WARNING:
|
|
|
|
// WARNING: the above flush may have destroyed the pres shell and/or
|
|
|
|
// WARNING: frames and other layout related objects.
|
|
|
|
// WARNING:
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
// STEP 5: Compose currently-animated attributes.
|
2009-10-02 14:37:25 -07:00
|
|
|
// XXXdholbert: This step traverses our animation targets in an effectively
|
|
|
|
// random order. For animation from/to 'inherit' values to work correctly
|
|
|
|
// when the inherited value is *also* being animated, we really should be
|
|
|
|
// traversing our animated nodes in an ancestors-first order (bug 501183)
|
2012-07-30 07:20:58 -07:00
|
|
|
currentCompositorTable->EnumerateEntries(DoComposeAttribute, nullptr);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
// Update last compositor table
|
|
|
|
mLastCompositorTable = currentCompositorTable.forget();
|
2009-01-21 17:00:27 -08:00
|
|
|
|
|
|
|
NS_ASSERTION(!mResampleNeeded, "Resample dirty flag set during sample!");
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-07-02 22:52:51 -07:00
|
|
|
void
|
|
|
|
nsSMILAnimationController::RewindElements()
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool rewindNeeded = false;
|
2010-07-02 22:52:51 -07:00
|
|
|
mChildContainerTable.EnumerateEntries(RewindNeeded, &rewindNeeded);
|
|
|
|
if (!rewindNeeded)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mAnimationElementTable.EnumerateEntries(RewindAnimation, nullptr);
|
|
|
|
mChildContainerTable.EnumerateEntries(ClearRewindNeeded, nullptr);
|
2010-07-02 22:52:51 -07:00
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
/*static*/ PLDHashOperator
|
2010-07-02 22:52:51 -07:00
|
|
|
nsSMILAnimationController::RewindNeeded(TimeContainerPtrKey* aKey,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aData,
|
|
|
|
"Null data pointer during time container enumeration");
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* rewindNeeded = static_cast<bool*>(aData);
|
2010-07-02 22:52:51 -07:00
|
|
|
|
|
|
|
nsSMILTimeContainer* container = aKey->GetKey();
|
|
|
|
if (container->NeedsRewind()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*rewindNeeded = true;
|
2010-07-02 22:52:51 -07:00
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
/*static*/ PLDHashOperator
|
2010-07-02 22:52:51 -07:00
|
|
|
nsSMILAnimationController::RewindAnimation(AnimationElementPtrKey* aKey,
|
|
|
|
void* aData)
|
|
|
|
{
|
2013-03-18 20:18:45 -07:00
|
|
|
SVGAnimationElement* animElem = aKey->GetKey();
|
2010-07-02 22:52:51 -07:00
|
|
|
nsSMILTimeContainer* timeContainer = animElem->GetTimeContainer();
|
|
|
|
if (timeContainer && timeContainer->NeedsRewind()) {
|
|
|
|
animElem->TimedElement().Rewind();
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
/*static*/ PLDHashOperator
|
2010-07-02 22:52:51 -07:00
|
|
|
nsSMILAnimationController::ClearRewindNeeded(TimeContainerPtrKey* aKey,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
aKey->GetKey()->ClearNeedsRewind();
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
void
|
|
|
|
nsSMILAnimationController::DoMilestoneSamples()
|
|
|
|
{
|
|
|
|
// We need to sample the timing model but because SMIL operates independently
|
|
|
|
// of the frame-rate, we can get one sample at t=0s and the next at t=10min.
|
|
|
|
//
|
|
|
|
// In between those two sample times a whole string of significant events
|
|
|
|
// might be expected to take place: events firing, new interdependencies
|
|
|
|
// between animations resolved and dissolved, etc.
|
|
|
|
//
|
|
|
|
// Furthermore, at any given time, we want to sample all the intervals that
|
|
|
|
// end at that time BEFORE any that begin. This behaviour is implied by SMIL's
|
|
|
|
// endpoint-exclusive timing model.
|
|
|
|
//
|
|
|
|
// So we have the animations (specifically the timed elements) register the
|
|
|
|
// next significant moment (called a milestone) in their lifetime and then we
|
|
|
|
// step through the model at each of these moments and sample those animations
|
|
|
|
// registered for those times. This way events can fire in the correct order,
|
|
|
|
// dependencies can be resolved etc.
|
|
|
|
|
2012-09-28 12:55:23 -07:00
|
|
|
nsSMILTime sampleTime = INT64_MIN;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
while (true) {
|
2010-01-12 12:00:49 -08:00
|
|
|
// We want to find any milestones AT OR BEFORE the current sample time so we
|
|
|
|
// initialise the next milestone to the moment after (1ms after, to be
|
|
|
|
// precise) the current sample time and see if there are any milestones
|
|
|
|
// before that. Any other milestones will be dealt with in a subsequent
|
|
|
|
// sample.
|
2011-10-17 07:59:28 -07:00
|
|
|
nsSMILMilestone nextMilestone(GetCurrentTime() + 1, true);
|
2010-01-12 12:00:49 -08:00
|
|
|
mChildContainerTable.EnumerateEntries(GetNextMilestone, &nextMilestone);
|
|
|
|
|
|
|
|
if (nextMilestone.mTime > GetCurrentTime()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetMilestoneElementsParams params;
|
|
|
|
params.mMilestone = nextMilestone;
|
|
|
|
mChildContainerTable.EnumerateEntries(GetMilestoneElements, ¶ms);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length = params.mElements.Length();
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
// During the course of a sampling we don't want to actually go backwards.
|
|
|
|
// Due to negative offsets, early ends and the like, a timed element might
|
|
|
|
// register a milestone that is actually in the past. That's fine, but it's
|
|
|
|
// still only going to get *sampled* with whatever time we're up to and no
|
|
|
|
// earlier.
|
|
|
|
//
|
|
|
|
// Because we're only performing this clamping at the last moment, the
|
|
|
|
// animations will still all get sampled in the correct order and
|
|
|
|
// dependencies will be appropriately resolved.
|
2013-01-15 04:22:03 -08:00
|
|
|
sampleTime = std::max(nextMilestone.mTime, sampleTime);
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2013-03-18 20:18:45 -07:00
|
|
|
SVGAnimationElement* elem = params.mElements[i].get();
|
2010-01-12 12:00:49 -08:00
|
|
|
NS_ABORT_IF_FALSE(elem, "NULL animation element in list");
|
|
|
|
nsSMILTimeContainer* container = elem->GetTimeContainer();
|
|
|
|
if (!container)
|
2012-07-30 07:20:58 -07:00
|
|
|
// The container may be nullptr if the element has been detached from its
|
2010-01-12 12:00:49 -08:00
|
|
|
// parent since registering a milestone.
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsSMILTimeValue containerTimeValue =
|
|
|
|
container->ParentToContainerTime(sampleTime);
|
2011-09-06 17:20:40 -07:00
|
|
|
if (!containerTimeValue.IsDefinite())
|
2010-01-12 12:00:49 -08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Clamp the converted container time to non-negative values.
|
2013-01-15 04:22:03 -08:00
|
|
|
nsSMILTime containerTime = std::max<nsSMILTime>(0, containerTimeValue.GetMillis());
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
if (nextMilestone.mIsEnd) {
|
|
|
|
elem->TimedElement().SampleEndAt(containerTime);
|
|
|
|
} else {
|
|
|
|
elem->TimedElement().SampleAt(containerTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
/*static*/ PLDHashOperator
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILAnimationController::GetNextMilestone(TimeContainerPtrKey* aKey,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aKey, "Null hash key for time container hash table");
|
|
|
|
NS_ABORT_IF_FALSE(aKey->GetKey(), "Null time container key in hash table");
|
|
|
|
NS_ABORT_IF_FALSE(aData,
|
|
|
|
"Null data pointer during time container enumeration");
|
|
|
|
|
|
|
|
nsSMILMilestone* nextMilestone = static_cast<nsSMILMilestone*>(aData);
|
|
|
|
|
|
|
|
nsSMILTimeContainer* container = aKey->GetKey();
|
|
|
|
if (container->IsPausedByType(nsSMILTimeContainer::PAUSE_BEGIN))
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
|
|
|
|
nsSMILMilestone thisMilestone;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool didGetMilestone =
|
2010-01-12 12:00:49 -08:00
|
|
|
container->GetNextMilestoneInParentTime(thisMilestone);
|
|
|
|
if (didGetMilestone && thisMilestone < *nextMilestone) {
|
|
|
|
*nextMilestone = thisMilestone;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
/*static*/ PLDHashOperator
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILAnimationController::GetMilestoneElements(TimeContainerPtrKey* aKey,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aKey, "Null hash key for time container hash table");
|
|
|
|
NS_ABORT_IF_FALSE(aKey->GetKey(), "Null time container key in hash table");
|
|
|
|
NS_ABORT_IF_FALSE(aData,
|
|
|
|
"Null data pointer during time container enumeration");
|
|
|
|
|
|
|
|
GetMilestoneElementsParams* params =
|
|
|
|
static_cast<GetMilestoneElementsParams*>(aData);
|
|
|
|
|
|
|
|
nsSMILTimeContainer* container = aKey->GetKey();
|
|
|
|
if (container->IsPausedByType(nsSMILTimeContainer::PAUSE_BEGIN))
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
|
|
|
|
container->PopMilestoneElementsAtMilestone(params->mMilestone,
|
|
|
|
params->mElements);
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
/*static*/ PLDHashOperator
|
2009-01-21 17:00:27 -08:00
|
|
|
nsSMILAnimationController::SampleTimeContainer(TimeContainerPtrKey* aKey,
|
|
|
|
void* aData)
|
2009-07-15 11:33:31 -07:00
|
|
|
{
|
2009-01-14 20:38:07 -08:00
|
|
|
NS_ENSURE_TRUE(aKey, PL_DHASH_NEXT);
|
|
|
|
NS_ENSURE_TRUE(aKey->GetKey(), PL_DHASH_NEXT);
|
|
|
|
NS_ENSURE_TRUE(aData, PL_DHASH_NEXT);
|
|
|
|
|
2009-07-15 11:33:31 -07:00
|
|
|
SampleTimeContainerParams* params =
|
2009-01-21 17:00:27 -08:00
|
|
|
static_cast<SampleTimeContainerParams*>(aData);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
nsSMILTimeContainer* container = aKey->GetKey();
|
2010-01-12 12:00:49 -08:00
|
|
|
if (!container->IsPausedByType(nsSMILTimeContainer::PAUSE_BEGIN) &&
|
|
|
|
(container->NeedsSample() || !params->mSkipUnchangedContainers)) {
|
|
|
|
container->ClearMilestones();
|
2009-01-14 20:38:07 -08:00
|
|
|
container->Sample();
|
2010-07-02 22:52:51 -07:00
|
|
|
container->MarkSeekFinished();
|
2009-01-21 17:00:27 -08:00
|
|
|
params->mActiveContainers->PutEntry(container);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:18:38 -07:00
|
|
|
/*static*/ PLDHashOperator
|
2009-01-14 20:38:07 -08:00
|
|
|
nsSMILAnimationController::SampleAnimation(AnimationElementPtrKey* aKey,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aKey, PL_DHASH_NEXT);
|
|
|
|
NS_ENSURE_TRUE(aKey->GetKey(), PL_DHASH_NEXT);
|
|
|
|
NS_ENSURE_TRUE(aData, PL_DHASH_NEXT);
|
|
|
|
|
2013-03-18 20:18:45 -07:00
|
|
|
SVGAnimationElement* animElem = aKey->GetKey();
|
2012-02-05 15:17:23 -08:00
|
|
|
if (animElem->PassesConditionalProcessingTests()) {
|
|
|
|
SampleAnimationParams* params = static_cast<SampleAnimationParams*>(aData);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2012-02-05 15:17:23 -08:00
|
|
|
SampleTimedElement(animElem, params->mActiveContainers);
|
|
|
|
AddAnimationToCompositorTable(animElem, params->mCompositorTable);
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
nsSMILAnimationController::SampleTimedElement(
|
2013-03-18 20:18:45 -07:00
|
|
|
SVGAnimationElement* aElement, TimeContainerHashtable* aActiveContainers)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
nsSMILTimeContainer* timeContainer = aElement->GetTimeContainer();
|
|
|
|
if (!timeContainer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We'd like to call timeContainer->NeedsSample() here and skip all timed
|
|
|
|
// elements that belong to paused time containers that don't need a sample,
|
|
|
|
// but that doesn't work because we've already called Sample() on all the time
|
|
|
|
// containers so the paused ones don't need a sample any more and they'll
|
|
|
|
// return false.
|
|
|
|
//
|
|
|
|
// Instead we build up a hashmap of active time containers during the previous
|
2009-01-21 17:00:27 -08:00
|
|
|
// step (SampleTimeContainer) and then test here if the container for this
|
2009-01-14 20:38:07 -08:00
|
|
|
// timed element is in the list.
|
|
|
|
if (!aActiveContainers->GetEntry(timeContainer))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsSMILTime containerTime = timeContainer->GetCurrentTime();
|
|
|
|
|
2010-07-02 22:52:51 -07:00
|
|
|
NS_ABORT_IF_FALSE(!timeContainer->IsSeeking(),
|
|
|
|
"Doing a regular sample but the time container is still seeking");
|
2009-01-14 20:38:07 -08:00
|
|
|
aElement->TimedElement().SampleAt(containerTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
nsSMILAnimationController::AddAnimationToCompositorTable(
|
2013-03-18 20:18:45 -07:00
|
|
|
SVGAnimationElement* aElement, nsSMILCompositorTable* aCompositorTable)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
// Add a compositor to the hash table if there's not already one there
|
2010-02-20 13:13:11 -08:00
|
|
|
nsSMILTargetIdentifier key;
|
|
|
|
if (!GetTargetIdentifierForAnimation(aElement, key))
|
2009-01-14 20:38:07 -08:00
|
|
|
// Something's wrong/missing about animation's target; skip this animation
|
|
|
|
return;
|
|
|
|
|
2009-08-25 12:02:28 -07:00
|
|
|
nsSMILAnimationFunction& func = aElement->AnimationFunction();
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-08-25 12:02:28 -07:00
|
|
|
// Only add active animation functions. If there are no active animations
|
2010-02-20 13:13:11 -08:00
|
|
|
// targeting an attribute, no compositor will be created and any previously
|
2009-08-25 12:02:28 -07:00
|
|
|
// applied animations will be cleared.
|
|
|
|
if (func.IsActiveOrFrozen()) {
|
2010-02-20 13:13:11 -08:00
|
|
|
// Look up the compositor for our target, & add our animation function
|
|
|
|
// to its list of animation functions.
|
2009-08-25 12:02:28 -07:00
|
|
|
nsSMILCompositor* result = aCompositorTable->PutEntry(key);
|
|
|
|
result->AddAnimationFunction(&func);
|
2010-02-20 13:13:11 -08:00
|
|
|
|
|
|
|
} else if (func.HasChanged()) {
|
|
|
|
// Look up the compositor for our target, and force it to skip the
|
|
|
|
// "nothing's changed so don't bother compositing" optimization for this
|
|
|
|
// sample. |func| is inactive, but it's probably *newly* inactive (since
|
2011-10-17 07:59:28 -07:00
|
|
|
// it's got HasChanged() == true), so we need to make sure to recompose
|
2010-02-20 13:13:11 -08:00
|
|
|
// its target.
|
|
|
|
nsSMILCompositor* result = aCompositorTable->PutEntry(key);
|
|
|
|
result->ToggleForceCompositing();
|
|
|
|
|
|
|
|
// We've now made sure that |func|'s inactivity will be reflected as of
|
|
|
|
// this sample. We need to clear its HasChanged() flag so that it won't
|
|
|
|
// trigger this same clause in future samples (until it changes again).
|
|
|
|
func.ClearHasChanged();
|
2009-08-25 12:02:28 -07:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2013-01-27 13:34:14 -08:00
|
|
|
static inline bool
|
|
|
|
IsTransformAttribute(int32_t aNamespaceID, nsIAtom *aAttributeName)
|
|
|
|
{
|
|
|
|
return aNamespaceID == kNameSpaceID_None &&
|
|
|
|
(aAttributeName == nsGkAtoms::transform ||
|
|
|
|
aAttributeName == nsGkAtoms::patternTransform ||
|
|
|
|
aAttributeName == nsGkAtoms::gradientTransform);
|
|
|
|
}
|
|
|
|
|
2013-03-18 20:18:45 -07:00
|
|
|
// Helper function that, given a SVGAnimationElement, looks up its target
|
2010-02-20 13:13:11 -08:00
|
|
|
// element & target attribute and populates a nsSMILTargetIdentifier
|
2009-01-14 20:38:07 -08:00
|
|
|
// for this target.
|
2011-09-28 23:19:26 -07:00
|
|
|
/*static*/ bool
|
2010-02-20 13:13:11 -08:00
|
|
|
nsSMILAnimationController::GetTargetIdentifierForAnimation(
|
2013-03-18 20:18:45 -07:00
|
|
|
SVGAnimationElement* aAnimElem, nsSMILTargetIdentifier& aResult)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
// Look up target (animated) element
|
2010-05-14 10:04:51 -07:00
|
|
|
Element* targetElem = aAnimElem->GetTargetElementContent();
|
2009-01-14 20:38:07 -08:00
|
|
|
if (!targetElem)
|
|
|
|
// Animation has no target elem -- skip it.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
// Look up target (animated) attribute
|
2010-10-07 12:19:32 -07:00
|
|
|
// SMILANIM section 3.1, attributeName may
|
|
|
|
// have an XMLNS prefix to indicate the XML namespace.
|
|
|
|
nsCOMPtr<nsIAtom> attributeName;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t attributeNamespaceID;
|
2010-10-07 12:19:32 -07:00
|
|
|
if (!aAnimElem->GetTargetAttributeName(&attributeNamespaceID,
|
|
|
|
getter_AddRefs(attributeName)))
|
2009-01-14 20:38:07 -08:00
|
|
|
// Animation has no target attr -- skip it.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2013-01-27 13:34:14 -08:00
|
|
|
// animateTransform can only animate transforms, conversely transforms
|
|
|
|
// can only be animated by animateTransform
|
|
|
|
if (IsTransformAttribute(attributeNamespaceID, attributeName) !=
|
2013-03-18 20:18:45 -07:00
|
|
|
(aAnimElem->Tag() == nsGkAtoms::animateTransform))
|
2013-01-27 13:34:14 -08:00
|
|
|
return false;
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
// Look up target (animated) attribute-type
|
|
|
|
nsSMILTargetAttrType attributeType = aAnimElem->GetTargetAttributeType();
|
|
|
|
|
|
|
|
// Check if an 'auto' attributeType refers to a CSS property or XML attribute.
|
|
|
|
// Note that SMIL requires we search for CSS properties first. So if they
|
|
|
|
// overlap, 'auto' = 'CSS'. (SMILANIM 3.1)
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isCSS = false;
|
2009-01-14 20:38:07 -08:00
|
|
|
if (attributeType == eSMILTargetAttrType_auto) {
|
2010-10-07 12:19:32 -07:00
|
|
|
if (attributeNamespaceID == kNameSpaceID_None) {
|
2012-06-16 08:47:40 -07:00
|
|
|
// width/height are special as they may be attributes or for
|
|
|
|
// outer-<svg> elements, mapped into style.
|
|
|
|
if (attributeName == nsGkAtoms::width ||
|
|
|
|
attributeName == nsGkAtoms::height) {
|
|
|
|
isCSS = targetElem->GetNameSpaceID() != kNameSpaceID_SVG;
|
|
|
|
} else {
|
|
|
|
nsCSSProperty prop =
|
2012-07-13 16:59:05 -07:00
|
|
|
nsCSSProps::LookupProperty(nsDependentAtomString(attributeName),
|
|
|
|
nsCSSProps::eEnabled);
|
2012-06-16 08:47:40 -07:00
|
|
|
isCSS = nsSMILCSSProperty::IsPropertyAnimatable(prop);
|
|
|
|
}
|
2010-10-07 12:19:32 -07:00
|
|
|
}
|
2009-10-02 14:37:25 -07:00
|
|
|
} else {
|
|
|
|
isCSS = (attributeType == eSMILTargetAttrType_CSS);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Construct the key
|
|
|
|
aResult.mElement = targetElem;
|
|
|
|
aResult.mAttributeName = attributeName;
|
2010-10-07 12:19:32 -07:00
|
|
|
aResult.mAttributeNamespaceID = attributeNamespaceID;
|
2009-01-14 20:38:07 -08:00
|
|
|
aResult.mIsCSS = isCSS;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Add/remove child time containers
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILAnimationController::AddChild(nsSMILTimeContainer& aChild)
|
|
|
|
{
|
|
|
|
TimeContainerPtrKey* key = mChildContainerTable.PutEntry(&aChild);
|
2011-04-01 13:33:20 -07:00
|
|
|
NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
if (!mPauseState && mChildContainerTable.Count() == 1) {
|
2011-04-28 12:05:24 -07:00
|
|
|
MaybeStartSampling(GetRefreshDriver());
|
2011-11-04 09:24:04 -07:00
|
|
|
Sample(); // Run the first sample manually
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::RemoveChild(nsSMILTimeContainer& aChild)
|
|
|
|
{
|
|
|
|
mChildContainerTable.RemoveEntry(&aChild);
|
|
|
|
|
|
|
|
if (!mPauseState && mChildContainerTable.Count() == 0) {
|
2011-04-28 12:05:24 -07:00
|
|
|
StopSampling(GetRefreshDriver());
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
}
|
2011-04-28 12:05:24 -07:00
|
|
|
|
|
|
|
// Helper method
|
|
|
|
nsRefreshDriver*
|
|
|
|
nsSMILAnimationController::GetRefreshDriver()
|
|
|
|
{
|
|
|
|
if (!mDocument) {
|
|
|
|
NS_ERROR("Requesting refresh driver after document has disconnected!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-04-28 12:05:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* shell = mDocument->GetShell();
|
|
|
|
if (!shell) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-04-28 12:05:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* context = shell->GetPresContext();
|
2012-07-30 07:20:58 -07:00
|
|
|
return context ? context->RefreshDriver() : nullptr;
|
2011-04-28 12:05:24 -07:00
|
|
|
}
|
2011-12-14 20:42:15 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILAnimationController::FlagDocumentNeedsFlush()
|
|
|
|
{
|
|
|
|
mDocument->SetNeedStyleFlush();
|
|
|
|
}
|