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
|
|
|
|
2019-01-08 10:55:14 +03:00
|
|
|
#include "SMILAnimationController.h"
|
2017-03-30 07:10:06 +03:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2017-03-30 07:10:06 +03:00
|
|
|
|
2013-02-01 03:11:49 +04:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2018-04-05 21:55:51 +03:00
|
|
|
#include "mozilla/RestyleManager.h"
|
2019-01-01 12:16:21 +03:00
|
|
|
#include "mozilla/SMILTimedElement.h"
|
2017-03-30 07:10:06 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/SVGAnimationElement.h"
|
2017-04-26 07:00:11 +03:00
|
|
|
#include "nsContentUtils.h"
|
2017-03-30 07:10:06 +03:00
|
|
|
#include "nsCSSProps.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2017-02-10 05:42:27 +03:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIPresShellInlines.h"
|
2017-03-30 07:10:06 +03:00
|
|
|
#include "nsITimer.h"
|
2019-01-01 12:16:21 +03:00
|
|
|
#include "SMILCompositor.h"
|
2019-01-08 10:55:14 +03:00
|
|
|
#include "SMILCSSProperty.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-05-14 21:04:51 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-28 14:47:58 +03:00
|
|
|
// SMILAnimationController implementation
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// ctors, dtors, factory methods
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
SMILAnimationController::SMILAnimationController(Document* aDoc)
|
2010-11-24 02:31:17 +03:00
|
|
|
: mAvgTimeBetweenSamples(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mResampleNeeded(false),
|
|
|
|
mDeferredStartSampling(false),
|
|
|
|
mRunningSample(false),
|
2014-05-20 16:34:26 +04:00
|
|
|
mRegisteredWithRefreshDriver(false),
|
2015-07-31 07:14:46 +03:00
|
|
|
mMightHavePendingStyleUpdates(false),
|
2011-04-28 23:02:20 +04:00
|
|
|
mDocument(aDoc) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aDoc, "need a non-null document");
|
2011-04-28 23:02:20 +04:00
|
|
|
|
2011-04-28 23:05:24 +04:00
|
|
|
nsRefreshDriver* refreshDriver = GetRefreshDriver();
|
2010-09-18 07:46:48 +04:00
|
|
|
if (refreshDriver) {
|
|
|
|
mStartTime = refreshDriver->MostRecentRefresh();
|
|
|
|
} else {
|
|
|
|
mStartTime = mozilla::TimeStamp::Now();
|
|
|
|
}
|
|
|
|
mCurrentSampleTime = mStartTime;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
Begin();
|
2011-04-28 23:02:20 +04:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
SMILAnimationController::~SMILAnimationController() {
|
2011-04-28 23:02:20 +04:00
|
|
|
NS_ASSERTION(mAnimationElementTable.Count() == 0,
|
|
|
|
"Animation controller shouldn't be tracking any animation"
|
|
|
|
" elements when it dies");
|
2014-05-20 16:34:26 +04:00
|
|
|
NS_ASSERTION(!mRegisteredWithRefreshDriver,
|
|
|
|
"Leaving stale entry in refresh driver's observer list");
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::Disconnect() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mDocument, "disconnecting when we weren't connected...?");
|
|
|
|
MOZ_ASSERT(mRefCnt.get() == 1,
|
|
|
|
"Expecting to disconnect when doc is sole remaining owner");
|
2019-01-02 10:21:13 +03:00
|
|
|
NS_ASSERTION(mPauseState & SMILTimeContainer::PAUSE_PAGEHIDE,
|
2011-08-03 03:12:32 +04:00
|
|
|
"Expecting to be paused for pagehide before disconnect");
|
2011-04-28 23:02:20 +04:00
|
|
|
|
2011-04-28 23:05:24 +04:00
|
|
|
StopSampling(GetRefreshDriver());
|
2011-04-28 23:02:20 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocument = nullptr; // (raw pointer)
|
2011-04-28 23:02:20 +04:00
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-02 10:21:13 +03:00
|
|
|
// SMILTimeContainer methods:
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::Pause(uint32_t aType) {
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer::Pause(aType);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
if (mPauseState) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mDeferredStartSampling = false;
|
2011-04-28 23:05:24 +04:00
|
|
|
StopSampling(GetRefreshDriver());
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::Resume(uint32_t aType) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool wasPaused = (mPauseState != 0);
|
2010-11-24 02:31:17 +03:00
|
|
|
// Update mCurrentSampleTime so that calls to GetParentTime--used for
|
|
|
|
// calculating parent offsets--are accurate
|
|
|
|
mCurrentSampleTime = mozilla::TimeStamp::Now();
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer::Resume(aType);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2009-01-22 04:00:27 +03:00
|
|
|
if (wasPaused && !mPauseState && mChildContainerTable.Count()) {
|
2011-04-28 23:05:24 +04:00
|
|
|
MaybeStartSampling(GetRefreshDriver());
|
2014-05-20 16:34:26 +04:00
|
|
|
Sample(); // Run the first sample manually
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
nsSMILTime SMILAnimationController::GetParentTime() const {
|
2010-09-18 07:46:48 +04:00
|
|
|
return (nsSMILTime)(mCurrentSampleTime - mStartTime).ToMilliseconds();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2010-03-19 07:14:40 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsARefreshObserver methods:
|
2018-12-28 14:47:58 +03:00
|
|
|
NS_IMPL_ADDREF(SMILAnimationController)
|
|
|
|
NS_IMPL_RELEASE(SMILAnimationController)
|
2010-03-19 07:14:40 +03:00
|
|
|
|
|
|
|
// nsRefreshDriver Callback function
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::WillRefresh(mozilla::TimeStamp aTime) {
|
2010-09-18 07:46:48 +04: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 16:22:03 +04:00
|
|
|
aTime = std::max(mCurrentSampleTime, aTime);
|
2010-11-24 02:31:17 +03: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-05 02:05:23 +04:00
|
|
|
// First sample.
|
2010-11-24 02:31:17 +03:00
|
|
|
mAvgTimeBetweenSamples = elapsedTime;
|
|
|
|
} else {
|
2013-03-05 02:05:23 +04: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-24 02:31:17 +03:00
|
|
|
mAvgTimeBetweenSamples =
|
|
|
|
(nsSMILTime)(elapsedTime * SAMPLE_DUR_WEIGHTING +
|
|
|
|
mAvgTimeBetweenSamples * (1.0 - SAMPLE_DUR_WEIGHTING));
|
|
|
|
}
|
|
|
|
mCurrentSampleTime = aTime;
|
|
|
|
|
2010-03-19 07:14:40 +03:00
|
|
|
Sample();
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Animation element registration methods:
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::RegisterAnimationElement(
|
2013-03-19 07:18:45 +04:00
|
|
|
SVGAnimationElement* aAnimationElement) {
|
2009-01-15 07:38:07 +03:00
|
|
|
mAnimationElementTable.PutEntry(aAnimationElement);
|
2010-03-21 22:22:36 +03:00
|
|
|
if (mDeferredStartSampling) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mDeferredStartSampling = false;
|
2010-11-06 22:13:01 +03:00
|
|
|
if (mChildContainerTable.Count()) {
|
|
|
|
// mAnimationElementTable was empty, but now we've added its 1st element
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mAnimationElementTable.Count() == 1,
|
|
|
|
"we shouldn't have deferred sampling if we already had "
|
|
|
|
"animations registered");
|
2011-04-28 23:05:24 +04:00
|
|
|
StartSampling(GetRefreshDriver());
|
2011-11-04 20:24:04 +04:00
|
|
|
Sample(); // Run the first sample manually
|
2010-11-06 22:13:01 +03:00
|
|
|
} // else, don't sample until a time container is registered (via AddChild)
|
2010-03-21 22:22:36 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::UnregisterAnimationElement(
|
2013-03-19 07:18:45 +04:00
|
|
|
SVGAnimationElement* aAnimationElement) {
|
2009-01-15 07:38:07 +03:00
|
|
|
mAnimationElementTable.RemoveEntry(aAnimationElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Page show/hide
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::OnPageShow() {
|
2019-01-02 10:21:13 +03:00
|
|
|
Resume(SMILTimeContainer::PAUSE_PAGEHIDE);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::OnPageHide() {
|
2019-01-02 10:21:13 +03:00
|
|
|
Pause(SMILTimeContainer::PAUSE_PAGEHIDE);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Cycle-collection support
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::Traverse(
|
2009-01-15 07:38:07 +03:00
|
|
|
nsCycleCollectionTraversalCallback* aCallback) {
|
|
|
|
// Traverse last compositor table
|
|
|
|
if (mLastCompositorTable) {
|
2015-07-22 10:13:49 +03:00
|
|
|
for (auto iter = mLastCompositorTable->Iter(); !iter.Done(); iter.Next()) {
|
2019-01-01 12:16:21 +03:00
|
|
|
SMILCompositor* compositor = iter.Get();
|
2015-07-22 10:13:49 +03:00
|
|
|
compositor->Traverse(aCallback);
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::Unlink() { mLastCompositorTable = nullptr; }
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-10-20 03:53:52 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Refresh driver lifecycle related methods
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::NotifyRefreshDriverCreated(
|
2010-10-20 03:53:52 +04:00
|
|
|
nsRefreshDriver* aRefreshDriver) {
|
2011-04-02 00:33:20 +04:00
|
|
|
if (!mPauseState) {
|
|
|
|
MaybeStartSampling(aRefreshDriver);
|
2010-10-20 03:53:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::NotifyRefreshDriverDestroying(
|
2010-10-20 03:53:52 +04:00
|
|
|
nsRefreshDriver* aRefreshDriver) {
|
|
|
|
if (!mPauseState && !mDeferredStartSampling) {
|
|
|
|
StopSampling(aRefreshDriver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Timer-related implementation helpers
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::StartSampling(nsRefreshDriver* aRefreshDriver) {
|
2010-03-22 09:42:53 +03:00
|
|
|
NS_ASSERTION(mPauseState == 0, "Starting sampling but controller is paused");
|
2010-10-20 03:52:49 +04:00
|
|
|
NS_ASSERTION(!mDeferredStartSampling,
|
|
|
|
"Started sampling but the deferred start flag is still set");
|
2010-03-22 09:42:53 +03:00
|
|
|
if (aRefreshDriver) {
|
2014-05-20 16:34:26 +04:00
|
|
|
MOZ_ASSERT(!mRegisteredWithRefreshDriver,
|
|
|
|
"Redundantly registering with refresh driver");
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!GetRefreshDriver() || aRefreshDriver == GetRefreshDriver(),
|
|
|
|
"Starting sampling with wrong refresh driver");
|
2010-11-24 02:31:17 +03: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();
|
2017-01-05 10:31:56 +03:00
|
|
|
aRefreshDriver->AddRefreshObserver(this, FlushType::Style);
|
2014-05-20 16:34:26 +04:00
|
|
|
mRegisteredWithRefreshDriver = true;
|
2010-03-22 09:42:53 +03:00
|
|
|
}
|
2010-03-18 17:58:09 +03:00
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::StopSampling(nsRefreshDriver* aRefreshDriver) {
|
2014-05-20 16:34:26 +04:00
|
|
|
if (aRefreshDriver && mRegisteredWithRefreshDriver) {
|
2010-03-22 09:42:53 +03:00
|
|
|
// NOTE: The document might already have been detached from its PresContext
|
2014-05-20 16:34:26 +04:00
|
|
|
// (and RefreshDriver), which would make GetRefreshDriver() return null.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!GetRefreshDriver() || aRefreshDriver == GetRefreshDriver(),
|
|
|
|
"Stopping sampling with wrong refresh driver");
|
2017-01-05 10:31:56 +03:00
|
|
|
aRefreshDriver->RemoveRefreshObserver(this, FlushType::Style);
|
2014-05-20 16:34:26 +04:00
|
|
|
mRegisteredWithRefreshDriver = false;
|
2010-03-22 09:42:53 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::MaybeStartSampling(
|
2011-04-02 00:33:20 +04:00
|
|
|
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 18:59:28 +04:00
|
|
|
mDeferredStartSampling = true;
|
2011-04-02 00:33:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Sample-related methods and callbacks
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::DoSample() {
|
2011-10-17 18:59:28 +04:00
|
|
|
DoSample(true); // Skip unchanged time containers
|
2009-01-22 04:00:27 +03:00
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::DoSample(bool aSkipUnchangedContainers) {
|
2011-04-28 23:02:20 +04:00
|
|
|
if (!mDocument) {
|
|
|
|
NS_ERROR("Shouldn't be sampling after document has disconnected");
|
|
|
|
return;
|
|
|
|
}
|
2012-08-29 09:32:56 +04:00
|
|
|
if (mRunningSample) {
|
|
|
|
NS_ERROR("Shouldn't be recursively sampling");
|
|
|
|
return;
|
|
|
|
}
|
2011-04-28 23:02:20 +04:00
|
|
|
|
2016-05-23 04:47:14 +03:00
|
|
|
bool isStyleFlushNeeded = mResampleNeeded;
|
2011-10-17 18:59:28 +04:00
|
|
|
mResampleNeeded = false;
|
2016-11-24 07:45:51 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> document(mDocument); // keeps 'this' alive too
|
2017-02-16 09:36:04 +03:00
|
|
|
|
2010-11-10 02:21:03 +03: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-12 01:12:47 +04:00
|
|
|
AutoRestore<bool> autoRestoreRunningSample(mRunningSample);
|
2011-10-17 18:59:28 +04:00
|
|
|
mRunningSample = true;
|
2016-05-23 04:47:14 +03:00
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
// STEP 1: Bring model up to date
|
2010-07-03 09:52:51 +04:00
|
|
|
// (i) Rewind elements where necessary
|
|
|
|
// (ii) Run milestone samples
|
|
|
|
RewindElements();
|
2010-01-12 23:00:49 +03:00
|
|
|
DoMilestoneSamples();
|
|
|
|
|
|
|
|
// STEP 2: Sample the child time containers
|
2009-01-15 07:38:07 +03:00
|
|
|
//
|
|
|
|
// When we sample the child time containers they will simply record the sample
|
|
|
|
// time in document time.
|
2013-09-02 12:41:57 +04:00
|
|
|
TimeContainerHashtable activeContainers(mChildContainerTable.Count());
|
2015-07-22 10:13:49 +03:00
|
|
|
for (auto iter = mChildContainerTable.Iter(); !iter.Done(); iter.Next()) {
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* container = iter.Get()->GetKey();
|
2015-07-22 10:13:49 +03:00
|
|
|
if (!container) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-01-02 10:21:13 +03:00
|
|
|
if (!container->IsPausedByType(SMILTimeContainer::PAUSE_BEGIN) &&
|
2015-07-22 10:13:49 +03:00
|
|
|
(container->NeedsSample() || !aSkipUnchangedContainers)) {
|
|
|
|
container->ClearMilestones();
|
|
|
|
container->Sample();
|
|
|
|
container->MarkSeekFinished();
|
|
|
|
activeContainers.PutEntry(container);
|
|
|
|
}
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
// STEP 3: (i) Sample the timed elements AND
|
2009-01-15 07:38:07 +03:00
|
|
|
// (ii) Create a table of compositors
|
2009-07-15 22:33:31 +04:00
|
|
|
//
|
2009-01-15 07:38:07 +03:00
|
|
|
// (i) Here we sample the timed elements (fetched from the
|
2013-03-19 07:18:45 +04:00
|
|
|
// SVGAnimationElements) which determine from the active time if the
|
2009-01-23 12:02:09 +03:00
|
|
|
// element is active and what its simple time etc. is. This information is
|
2018-12-31 14:54:22 +03:00
|
|
|
// then passed to its time client (SMILAnimationFunction).
|
2009-01-15 07:38:07 +03:00
|
|
|
//
|
|
|
|
// (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
|
2019-01-01 12:16:21 +03:00
|
|
|
nsAutoPtr<SMILCompositorTable> currentCompositorTable(
|
|
|
|
new SMILCompositorTable(0));
|
2017-03-21 02:47:46 +03:00
|
|
|
nsTArray<RefPtr<SVGAnimationElement>> animElems(
|
|
|
|
mAnimationElementTable.Count());
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2015-07-22 10:14:37 +03:00
|
|
|
for (auto iter = mAnimationElementTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
SVGAnimationElement* animElem = iter.Get()->GetKey();
|
|
|
|
SampleTimedElement(animElem, &activeContainers);
|
2016-05-23 04:47:14 +03:00
|
|
|
AddAnimationToCompositorTable(animElem, currentCompositorTable,
|
|
|
|
isStyleFlushNeeded);
|
2017-03-21 02:47:46 +03:00
|
|
|
animElems.AppendElement(animElem);
|
2015-07-22 10:14:37 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
activeContainers.Clear();
|
|
|
|
|
2010-02-21 00:13:11 +03:00
|
|
|
// STEP 4: Compare previous sample's compositors against this sample's.
|
2015-07-22 10:14:37 +03:00
|
|
|
// (Transfer cached base values across, & remove animation effects from
|
2010-02-21 00:13:11 +03:00
|
|
|
// no-longer-animated targets.)
|
2009-01-15 07:38:07 +03:00
|
|
|
if (mLastCompositorTable) {
|
2010-02-21 00:13:11 +03:00
|
|
|
// * Transfer over cached base values, from last sample's compositors
|
2015-07-22 10:14:37 +03:00
|
|
|
for (auto iter = currentCompositorTable->Iter(); !iter.Done();
|
|
|
|
iter.Next()) {
|
2019-01-01 12:16:21 +03:00
|
|
|
SMILCompositor* compositor = iter.Get();
|
|
|
|
SMILCompositor* lastCompositor =
|
2015-07-22 10:14:37 +03:00
|
|
|
mLastCompositorTable->GetEntry(compositor->GetKey());
|
|
|
|
|
|
|
|
if (lastCompositor) {
|
|
|
|
compositor->StealCachedBaseValue(lastCompositor);
|
|
|
|
}
|
|
|
|
}
|
2010-02-21 00:13:11 +03:00
|
|
|
|
2009-07-14 23:33:29 +04: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.
|
2015-07-22 10:14:37 +03:00
|
|
|
for (auto iter = currentCompositorTable->Iter(); !iter.Done();
|
|
|
|
iter.Next()) {
|
|
|
|
mLastCompositorTable->RemoveEntry(iter.Get()->GetKey());
|
|
|
|
}
|
2009-07-14 23:33:29 +04:00
|
|
|
|
|
|
|
// * For each entry that remains in prev sample's hash table (i.e. for
|
|
|
|
// every target that's no longer animated), clear animation effects.
|
2015-07-22 10:14:37 +03:00
|
|
|
for (auto iter = mLastCompositorTable->Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
iter.Get()->ClearAnimationEffects();
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2012-12-12 01:12:47 +04:00
|
|
|
// return early if there are no active animations to avoid a style flush
|
|
|
|
if (currentCompositorTable->Count() == 0) {
|
|
|
|
mLastCompositorTable = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-23 04:47:14 +03:00
|
|
|
if (isStyleFlushNeeded) {
|
2017-01-05 10:31:56 +03:00
|
|
|
document->FlushPendingNotifications(FlushType::Style);
|
2016-05-23 04:47:14 +03:00
|
|
|
}
|
2012-12-12 01:12:47 +04:00
|
|
|
|
2016-05-23 04:47:14 +03:00
|
|
|
// WARNING:
|
2012-12-12 01:12:47 +04:00
|
|
|
// WARNING: the above flush may have destroyed the pres shell and/or
|
|
|
|
// WARNING: frames and other layout related objects.
|
|
|
|
// WARNING:
|
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
// STEP 5: Compose currently-animated attributes.
|
2009-10-03 01:37:25 +04: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)
|
2016-05-23 04:47:14 +03:00
|
|
|
bool mightHavePendingStyleUpdates = false;
|
2015-07-22 10:14:37 +03:00
|
|
|
for (auto iter = currentCompositorTable->Iter(); !iter.Done(); iter.Next()) {
|
2016-05-23 04:47:14 +03:00
|
|
|
iter.Get()->ComposeAttribute(mightHavePendingStyleUpdates);
|
2015-07-22 10:14:37 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Update last compositor table
|
|
|
|
mLastCompositorTable = currentCompositorTable.forget();
|
2016-05-23 04:47:14 +03:00
|
|
|
mMightHavePendingStyleUpdates = mightHavePendingStyleUpdates;
|
2009-01-22 04:00:27 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(!mResampleNeeded, "Resample dirty flag set during sample!");
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::RewindElements() {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool rewindNeeded = false;
|
2015-07-22 10:19:36 +03:00
|
|
|
for (auto iter = mChildContainerTable.Iter(); !iter.Done(); iter.Next()) {
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* container = iter.Get()->GetKey();
|
2015-07-22 10:19:36 +03:00
|
|
|
if (container->NeedsRewind()) {
|
|
|
|
rewindNeeded = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-03 09:52:51 +04:00
|
|
|
if (!rewindNeeded) return;
|
|
|
|
|
2015-07-22 10:19:36 +03:00
|
|
|
for (auto iter = mAnimationElementTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
SVGAnimationElement* animElem = iter.Get()->GetKey();
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* timeContainer = animElem->GetTimeContainer();
|
2015-07-22 10:19:36 +03:00
|
|
|
if (timeContainer && timeContainer->NeedsRewind()) {
|
|
|
|
animElem->TimedElement().Rewind();
|
|
|
|
}
|
2010-07-03 09:52:51 +04:00
|
|
|
}
|
|
|
|
|
2015-07-22 10:19:36 +03:00
|
|
|
for (auto iter = mChildContainerTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
iter.Get()->GetKey()->ClearNeedsRewind();
|
2010-07-03 09:52:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::DoMilestoneSamples() {
|
2010-01-12 23:00:49 +03:00
|
|
|
// 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 23:55:23 +04:00
|
|
|
nsSMILTime sampleTime = INT64_MIN;
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
while (true) {
|
2010-01-12 23:00:49 +03: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.
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILMilestone nextMilestone(GetCurrentTimeAsSMILTime() + 1, true);
|
2015-07-22 10:26:48 +03:00
|
|
|
for (auto iter = mChildContainerTable.Iter(); !iter.Done(); iter.Next()) {
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* container = iter.Get()->GetKey();
|
|
|
|
if (container->IsPausedByType(SMILTimeContainer::PAUSE_BEGIN)) {
|
2015-07-22 10:26:48 +03:00
|
|
|
continue;
|
|
|
|
}
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILMilestone thisMilestone;
|
2015-07-22 10:26:48 +03:00
|
|
|
bool didGetMilestone =
|
|
|
|
container->GetNextMilestoneInParentTime(thisMilestone);
|
|
|
|
if (didGetMilestone && thisMilestone < nextMilestone) {
|
|
|
|
nextMilestone = thisMilestone;
|
|
|
|
}
|
|
|
|
}
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2018-12-21 08:37:58 +03:00
|
|
|
if (nextMilestone.mTime > GetCurrentTimeAsSMILTime()) {
|
2010-01-12 23:00:49 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<mozilla::dom::SVGAnimationElement>> elements;
|
2015-07-22 10:26:48 +03:00
|
|
|
for (auto iter = mChildContainerTable.Iter(); !iter.Done(); iter.Next()) {
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* container = iter.Get()->GetKey();
|
|
|
|
if (container->IsPausedByType(SMILTimeContainer::PAUSE_BEGIN)) {
|
2015-07-22 10:26:48 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
container->PopMilestoneElementsAtMilestone(nextMilestone, elements);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t length = elements.Length();
|
2010-01-12 23:00:49 +03: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 16:22:03 +04:00
|
|
|
sampleTime = std::max(nextMilestone.mTime, sampleTime);
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2015-07-22 10:26:48 +03:00
|
|
|
SVGAnimationElement* elem = elements[i].get();
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(elem, "nullptr animation element in list");
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* container = elem->GetTimeContainer();
|
2010-01-12 23:00:49 +03:00
|
|
|
if (!container)
|
2012-07-30 18:20:58 +04:00
|
|
|
// The container may be nullptr if the element has been detached from
|
2010-01-12 23:00:49 +03:00
|
|
|
// its parent since registering a milestone.
|
|
|
|
continue;
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
SMILTimeValue containerTimeValue =
|
2010-01-12 23:00:49 +03:00
|
|
|
container->ParentToContainerTime(sampleTime);
|
2011-09-07 04:20:40 +04:00
|
|
|
if (!containerTimeValue.IsDefinite()) continue;
|
2010-01-12 23:00:49 +03:00
|
|
|
|
|
|
|
// Clamp the converted container time to non-negative values.
|
2013-01-15 16:22:03 +04:00
|
|
|
nsSMILTime containerTime =
|
|
|
|
std::max<nsSMILTime>(0, containerTimeValue.GetMillis());
|
2010-01-12 23:00:49 +03:00
|
|
|
|
|
|
|
if (nextMilestone.mIsEnd) {
|
|
|
|
elem->TimedElement().SampleEndAt(containerTime);
|
|
|
|
} else {
|
|
|
|
elem->TimedElement().SampleAt(containerTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
/*static*/ void SMILAnimationController::SampleTimedElement(
|
2013-03-19 07:18:45 +04:00
|
|
|
SVGAnimationElement* aElement, TimeContainerHashtable* aActiveContainers) {
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* timeContainer = aElement->GetTimeContainer();
|
2009-01-15 07:38:07 +03:00
|
|
|
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-22 04:00:27 +03:00
|
|
|
// step (SampleTimeContainer) and then test here if the container for this
|
2009-01-15 07:38:07 +03:00
|
|
|
// timed element is in the list.
|
|
|
|
if (!aActiveContainers->GetEntry(timeContainer)) return;
|
|
|
|
|
2018-12-21 08:37:58 +03:00
|
|
|
nsSMILTime containerTime = timeContainer->GetCurrentTimeAsSMILTime();
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!timeContainer->IsSeeking(),
|
|
|
|
"Doing a regular sample but the time container is still seeking");
|
2009-01-15 07:38:07 +03:00
|
|
|
aElement->TimedElement().SampleAt(containerTime);
|
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
/*static*/ void SMILAnimationController::AddAnimationToCompositorTable(
|
2019-01-01 12:16:21 +03:00
|
|
|
SVGAnimationElement* aElement, SMILCompositorTable* aCompositorTable,
|
2016-05-23 04:47:14 +03:00
|
|
|
bool& aStyleFlushNeeded) {
|
2009-01-15 07:38:07 +03:00
|
|
|
// Add a compositor to the hash table if there's not already one there
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTargetIdentifier key;
|
2010-02-21 00:13:11 +03:00
|
|
|
if (!GetTargetIdentifierForAnimation(aElement, key))
|
2009-01-15 07:38:07 +03:00
|
|
|
// Something's wrong/missing about animation's target; skip this animation
|
|
|
|
return;
|
|
|
|
|
2018-12-31 14:54:22 +03:00
|
|
|
SMILAnimationFunction& func = aElement->AnimationFunction();
|
2009-07-15 22:33:31 +04:00
|
|
|
|
2009-08-25 23:02:28 +04:00
|
|
|
// Only add active animation functions. If there are no active animations
|
2010-02-21 00:13:11 +03:00
|
|
|
// targeting an attribute, no compositor will be created and any previously
|
2009-08-25 23:02:28 +04:00
|
|
|
// applied animations will be cleared.
|
|
|
|
if (func.IsActiveOrFrozen()) {
|
2010-02-21 00:13:11 +03:00
|
|
|
// Look up the compositor for our target, & add our animation function
|
|
|
|
// to its list of animation functions.
|
2019-01-01 12:16:21 +03:00
|
|
|
SMILCompositor* result = aCompositorTable->PutEntry(key);
|
2009-08-25 23:02:28 +04:00
|
|
|
result->AddAnimationFunction(&func);
|
2010-02-21 00:13:11 +03: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 18:59:28 +04:00
|
|
|
// it's got HasChanged() == true), so we need to make sure to recompose
|
2010-02-21 00:13:11 +03:00
|
|
|
// its target.
|
2019-01-01 12:16:21 +03:00
|
|
|
SMILCompositor* result = aCompositorTable->PutEntry(key);
|
2010-02-21 00:13:11 +03:00
|
|
|
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 23:02:28 +04:00
|
|
|
}
|
2016-05-23 04:47:14 +03:00
|
|
|
aStyleFlushNeeded |= func.ValueNeedsReparsingEverySample();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
static inline bool IsTransformAttribute(int32_t aNamespaceID,
|
|
|
|
nsAtom* aAttributeName) {
|
2013-01-28 01:34:14 +04:00
|
|
|
return aNamespaceID == kNameSpaceID_None &&
|
|
|
|
(aAttributeName == nsGkAtoms::transform ||
|
|
|
|
aAttributeName == nsGkAtoms::patternTransform ||
|
|
|
|
aAttributeName == nsGkAtoms::gradientTransform);
|
|
|
|
}
|
|
|
|
|
2013-03-19 07:18:45 +04:00
|
|
|
// Helper function that, given a SVGAnimationElement, looks up its target
|
2019-01-02 10:21:13 +03:00
|
|
|
// element & target attribute and populates a SMILTargetIdentifier
|
2009-01-15 07:38:07 +03:00
|
|
|
// for this target.
|
2018-12-28 14:47:58 +03:00
|
|
|
/*static*/ bool SMILAnimationController::GetTargetIdentifierForAnimation(
|
2019-01-02 10:21:13 +03:00
|
|
|
SVGAnimationElement* aAnimElem, SMILTargetIdentifier& aResult) {
|
2009-01-15 07:38:07 +03:00
|
|
|
// Look up target (animated) element
|
2010-05-14 21:04:51 +04:00
|
|
|
Element* targetElem = aAnimElem->GetTargetElementContent();
|
2009-01-15 07:38:07 +03:00
|
|
|
if (!targetElem)
|
|
|
|
// Animation has no target elem -- skip it.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Look up target (animated) attribute
|
2010-10-07 23:19:32 +04:00
|
|
|
// SMILANIM section 3.1, attributeName may
|
|
|
|
// have an XMLNS prefix to indicate the XML namespace.
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> attributeName;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t attributeNamespaceID;
|
2010-10-07 23:19:32 +04:00
|
|
|
if (!aAnimElem->GetTargetAttributeName(&attributeNamespaceID,
|
|
|
|
getter_AddRefs(attributeName)))
|
2009-01-15 07:38:07 +03:00
|
|
|
// Animation has no target attr -- skip it.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-28 01:34:14 +04:00
|
|
|
// animateTransform can only animate transforms, conversely transforms
|
|
|
|
// can only be animated by animateTransform
|
|
|
|
if (IsTransformAttribute(attributeNamespaceID, attributeName) !=
|
2015-03-03 14:09:00 +03:00
|
|
|
(aAnimElem->IsSVGElement(nsGkAtoms::animateTransform)))
|
2013-01-28 01:34:14 +04:00
|
|
|
return false;
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
// Construct the key
|
2017-03-21 09:42:17 +03:00
|
|
|
aResult.mElement = targetElem;
|
|
|
|
aResult.mAttributeName = attributeName;
|
2010-10-07 23:19:32 +04:00
|
|
|
aResult.mAttributeNamespaceID = attributeNamespaceID;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
bool SMILAnimationController::PreTraverse() {
|
2017-04-26 07:00:11 +03:00
|
|
|
return PreTraverseInSubtree(nullptr);
|
|
|
|
}
|
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
bool SMILAnimationController::PreTraverseInSubtree(Element* aRoot) {
|
2017-04-26 07:00:11 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mMightHavePendingStyleUpdates) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-21 01:00:10 +03:00
|
|
|
nsPresContext* context = mDocument->GetPresContext();
|
2017-04-26 07:00:11 +03:00
|
|
|
if (!context) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool foundElementsNeedingRestyle = false;
|
|
|
|
for (auto iter = mAnimationElementTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
SVGAnimationElement* animElement = iter.Get()->GetKey();
|
|
|
|
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTargetIdentifier key;
|
2017-04-26 07:00:11 +03:00
|
|
|
if (!GetTargetIdentifierForAnimation(animElement, key)) {
|
|
|
|
// Something's wrong/missing about animation's target; skip this animation
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore restyles that aren't in the flattened tree subtree rooted at
|
|
|
|
// aRoot.
|
|
|
|
if (aRoot && !nsContentUtils::ContentIsFlattenedTreeDescendantOf(
|
|
|
|
key.mElement, aRoot)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->RestyleManager()->PostRestyleEventForAnimations(
|
2017-06-08 04:22:25 +03:00
|
|
|
key.mElement, CSSPseudoElementType::NotPseudo,
|
2017-04-26 07:00:11 +03:00
|
|
|
eRestyle_StyleAttribute_Animations);
|
|
|
|
|
|
|
|
foundElementsNeedingRestyle = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only clear the mMightHavePendingStyleUpdates flag if we definitely posted
|
|
|
|
// all restyles.
|
|
|
|
if (!aRoot) {
|
|
|
|
mMightHavePendingStyleUpdates = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundElementsNeedingRestyle;
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Add/remove child time containers
|
|
|
|
|
2019-01-02 10:21:13 +03:00
|
|
|
nsresult SMILAnimationController::AddChild(SMILTimeContainer& aChild) {
|
2009-01-15 07:38:07 +03:00
|
|
|
TimeContainerPtrKey* key = mChildContainerTable.PutEntry(&aChild);
|
2011-04-02 00:33:20 +04:00
|
|
|
NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
if (!mPauseState && mChildContainerTable.Count() == 1) {
|
2011-04-28 23:05:24 +04:00
|
|
|
MaybeStartSampling(GetRefreshDriver());
|
2011-11-04 20:24:04 +04:00
|
|
|
Sample(); // Run the first sample manually
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2009-07-15 22:33:31 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-02 10:21:13 +03:00
|
|
|
void SMILAnimationController::RemoveChild(SMILTimeContainer& aChild) {
|
2009-01-15 07:38:07 +03:00
|
|
|
mChildContainerTable.RemoveEntry(&aChild);
|
|
|
|
|
|
|
|
if (!mPauseState && mChildContainerTable.Count() == 0) {
|
2011-04-28 23:05:24 +04:00
|
|
|
StopSampling(GetRefreshDriver());
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
}
|
2011-04-28 23:05:24 +04:00
|
|
|
|
|
|
|
// Helper method
|
2018-12-28 14:47:58 +03:00
|
|
|
nsRefreshDriver* SMILAnimationController::GetRefreshDriver() {
|
2011-04-28 23:05:24 +04:00
|
|
|
if (!mDocument) {
|
|
|
|
NS_ERROR("Requesting refresh driver after document has disconnected!");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-04-28 23:05:24 +04:00
|
|
|
}
|
|
|
|
|
2018-02-21 01:00:10 +03:00
|
|
|
nsPresContext* context = mDocument->GetPresContext();
|
2012-07-30 18:20:58 +04:00
|
|
|
return context ? context->RefreshDriver() : nullptr;
|
2011-04-28 23:05:24 +04:00
|
|
|
}
|
2011-12-15 08:42:15 +04:00
|
|
|
|
2018-12-28 14:47:58 +03:00
|
|
|
void SMILAnimationController::FlagDocumentNeedsFlush() {
|
2017-02-10 05:42:27 +03:00
|
|
|
if (nsIPresShell* shell = mDocument->GetShell()) {
|
|
|
|
shell->SetNeedStyleFlush();
|
|
|
|
}
|
2011-12-15 08:42:15 +04:00
|
|
|
}
|
2018-12-28 14:47:58 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|