2009-01-15 04:38:07 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 04:38:07 +00:00
|
|
|
|
2012-12-14 23:58:45 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2013-09-25 11:21:22 +00:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2013-03-19 03:18:45 +00:00
|
|
|
#include "mozilla/dom/SVGAnimationElement.h"
|
2009-01-15 04:38:07 +00:00
|
|
|
#include "nsSMILTimedElement.h"
|
2012-09-30 16:40:24 +00:00
|
|
|
#include "nsAttrValueInlines.h"
|
2009-01-15 04:38:07 +00:00
|
|
|
#include "nsSMILAnimationFunction.h"
|
|
|
|
#include "nsSMILTimeValue.h"
|
|
|
|
#include "nsSMILTimeValueSpec.h"
|
|
|
|
#include "nsSMILInstanceTime.h"
|
|
|
|
#include "nsSMILParserUtils.h"
|
|
|
|
#include "nsSMILTimeContainer.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsMathUtils.h"
|
2010-07-31 07:02:52 +00:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsIPresShell.h"
|
2009-01-15 04:38:07 +00:00
|
|
|
#include "prdtoa.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "nsString.h"
|
2011-07-15 02:17:15 +00:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2012-02-24 00:45:40 +00:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2011-07-15 02:17:15 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-03-19 03:18:45 +00:00
|
|
|
using namespace mozilla::dom;
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
//----------------------------------------------------------------------
|
2010-07-31 07:02:52 +00:00
|
|
|
// Helper class: InstanceTimeComparator
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
// Upon inserting an instance time into one of our instance time lists we assign
|
|
|
|
// it a serial number. This allows us to sort the instance times in such a way
|
|
|
|
// that where we have several equal instance times, the ones added later will
|
|
|
|
// sort later. This means that when we call UpdateCurrentInterval during the
|
|
|
|
// waiting state we won't unnecessarily change the begin instance.
|
|
|
|
//
|
|
|
|
// The serial number also means that every instance time has an unambiguous
|
|
|
|
// position in the array so we can use RemoveElementSorted and the like.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::InstanceTimeComparator::Equals(
|
|
|
|
const nsSMILInstanceTime* aElem1,
|
|
|
|
const nsSMILInstanceTime* aElem2) const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aElem1 && aElem2,
|
|
|
|
"Trying to compare null instance time pointers");
|
|
|
|
NS_ABORT_IF_FALSE(aElem1->Serial() && aElem2->Serial(),
|
|
|
|
"Instance times have not been assigned serial numbers");
|
|
|
|
NS_ABORT_IF_FALSE(aElem1 == aElem2 || aElem1->Serial() != aElem2->Serial(),
|
|
|
|
"Serial numbers are not unique");
|
|
|
|
|
|
|
|
return aElem1->Serial() == aElem2->Serial();
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::InstanceTimeComparator::LessThan(
|
|
|
|
const nsSMILInstanceTime* aElem1,
|
|
|
|
const nsSMILInstanceTime* aElem2) const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aElem1 && aElem2,
|
|
|
|
"Trying to compare null instance time pointers");
|
|
|
|
NS_ABORT_IF_FALSE(aElem1->Serial() && aElem2->Serial(),
|
|
|
|
"Instance times have not been assigned serial numbers");
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int8_t cmp = aElem1->Time().CompareTo(aElem2->Time());
|
2010-01-12 20:00:49 +00:00
|
|
|
return cmp == 0 ? aElem1->Serial() < aElem2->Serial() : cmp < 0;
|
|
|
|
}
|
|
|
|
|
2010-07-31 07:02:52 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AsyncTimeEventRunner
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class AsyncTimeEventRunner : public nsRunnable
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
nsRefPtr<nsIContent> mTarget;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mMsg;
|
|
|
|
int32_t mDetail;
|
2010-07-31 07:02:52 +00:00
|
|
|
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
AsyncTimeEventRunner(nsIContent* aTarget, uint32_t aMsg, int32_t aDetail)
|
2010-07-31 07:02:52 +00:00
|
|
|
: mTarget(aTarget), mMsg(aMsg), mDetail(aDetail)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2014-02-15 01:06:06 +00:00
|
|
|
InternalUIEvent event(true, mMsg);
|
2010-07-31 07:02:52 +00:00
|
|
|
event.eventStructType = NS_SMIL_TIME_EVENT;
|
2014-02-15 01:06:06 +00:00
|
|
|
event.detail = mDetail;
|
2010-07-31 07:02:52 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
nsPresContext* context = nullptr;
|
2010-07-31 07:02:52 +00:00
|
|
|
nsIDocument* doc = mTarget->GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell = doc->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
context = shell->GetPresContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 04:48:21 +00:00
|
|
|
return EventDispatcher::Dispatch(mTarget, context, &event);
|
2010-07-31 07:02:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-07-02 03:37:10 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoIntervalUpdateBatcher
|
|
|
|
|
2013-12-13 04:41:56 +00:00
|
|
|
// Stack-based helper class to set the mDeferIntervalUpdates flag on an
|
|
|
|
// nsSMILTimedElement and perform the UpdateCurrentInterval when the object is
|
|
|
|
// destroyed.
|
2011-07-02 03:37:10 +00:00
|
|
|
//
|
|
|
|
// If several of these objects are allocated on the stack, the update will not
|
|
|
|
// be performed until the last object for a given nsSMILTimedElement is
|
|
|
|
// destroyed.
|
2013-04-12 03:20:09 +00:00
|
|
|
class MOZ_STACK_CLASS nsSMILTimedElement::AutoIntervalUpdateBatcher
|
2011-07-02 03:37:10 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoIntervalUpdateBatcher(nsSMILTimedElement& aTimedElement)
|
|
|
|
: mTimedElement(aTimedElement),
|
|
|
|
mDidSetFlag(!aTimedElement.mDeferIntervalUpdates)
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mTimedElement.mDeferIntervalUpdates = true;
|
2011-07-02 03:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~AutoIntervalUpdateBatcher()
|
|
|
|
{
|
|
|
|
if (!mDidSetFlag)
|
|
|
|
return;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mTimedElement.mDeferIntervalUpdates = false;
|
2011-07-02 03:37:10 +00:00
|
|
|
|
|
|
|
if (mTimedElement.mDoDeferredUpdate) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mTimedElement.mDoDeferredUpdate = false;
|
2011-07-02 03:37:10 +00:00
|
|
|
mTimedElement.UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsSMILTimedElement& mTimedElement;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mDidSetFlag;
|
2011-07-02 03:37:10 +00:00
|
|
|
};
|
|
|
|
|
2013-12-13 04:41:56 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoIntervalUpdater
|
|
|
|
|
|
|
|
// Stack-based helper class to call UpdateCurrentInterval when it is destroyed
|
|
|
|
// which helps avoid bugs where we forget to call UpdateCurrentInterval in the
|
|
|
|
// case of early returns (e.g. due to parse errors).
|
|
|
|
//
|
|
|
|
// This can be safely used in conjunction with AutoIntervalUpdateBatcher; any
|
|
|
|
// calls to UpdateCurrentInterval made by this class will simply be deferred if
|
|
|
|
// there is an AutoIntervalUpdateBatcher on the stack.
|
|
|
|
class MOZ_STACK_CLASS nsSMILTimedElement::AutoIntervalUpdater
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoIntervalUpdater(nsSMILTimedElement& aTimedElement)
|
|
|
|
: mTimedElement(aTimedElement) { }
|
|
|
|
|
|
|
|
~AutoIntervalUpdater()
|
|
|
|
{
|
|
|
|
mTimedElement.UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsSMILTimedElement& mTimedElement;
|
|
|
|
};
|
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Templated helper functions
|
|
|
|
|
|
|
|
// Selectively remove elements from an array of type
|
|
|
|
// nsTArray<nsRefPtr<nsSMILInstanceTime> > with O(n) performance.
|
|
|
|
template <class TestFunctor>
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::RemoveInstanceTimes(InstanceTimeList& aArray,
|
|
|
|
TestFunctor& aTest)
|
|
|
|
{
|
|
|
|
InstanceTimeList newArray;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < aArray.Length(); ++i) {
|
2010-07-03 05:52:50 +00:00
|
|
|
nsSMILInstanceTime* item = aArray[i].get();
|
|
|
|
if (aTest(item, i)) {
|
2011-07-25 17:44:58 +00:00
|
|
|
// As per bugs 665334 and 669225 we should be careful not to remove the
|
|
|
|
// instance time that corresponds to the previous interval's end time.
|
|
|
|
//
|
|
|
|
// Most functors supplied here fulfil this condition by checking if the
|
|
|
|
// instance time is marked as "ShouldPreserve" and if so, not deleting it.
|
|
|
|
//
|
|
|
|
// However, when filtering instance times, we sometimes need to drop even
|
|
|
|
// instance times marked as "ShouldPreserve". In that case we take special
|
|
|
|
// care not to delete the end instance time of the previous interval.
|
|
|
|
NS_ABORT_IF_FALSE(!GetPreviousInterval() ||
|
|
|
|
item != GetPreviousInterval()->End(),
|
|
|
|
"Removing end instance time of previous interval");
|
2010-07-03 05:52:50 +00:00
|
|
|
item->Unlink();
|
|
|
|
} else {
|
|
|
|
newArray.AppendElement(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aArray.Clear();
|
|
|
|
aArray.SwapElements(newArray);
|
|
|
|
}
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Static members
|
|
|
|
|
|
|
|
nsAttrValue::EnumTable nsSMILTimedElement::sFillModeTable[] = {
|
|
|
|
{"remove", FILL_REMOVE},
|
|
|
|
{"freeze", FILL_FREEZE},
|
2012-07-30 14:20:58 +00:00
|
|
|
{nullptr, 0}
|
2009-01-15 04:38:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nsAttrValue::EnumTable nsSMILTimedElement::sRestartModeTable[] = {
|
|
|
|
{"always", RESTART_ALWAYS},
|
|
|
|
{"whenNotActive", RESTART_WHENNOTACTIVE},
|
|
|
|
{"never", RESTART_NEVER},
|
2012-07-30 14:20:58 +00:00
|
|
|
{nullptr, 0}
|
2009-01-15 04:38:07 +00:00
|
|
|
};
|
|
|
|
|
2012-09-28 19:55:23 +00:00
|
|
|
const nsSMILMilestone nsSMILTimedElement::sMaxMilestone(INT64_MAX, false);
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
// The thresholds at which point we start filtering intervals and instance times
|
|
|
|
// indiscriminately.
|
|
|
|
// See FilterIntervals and FilterInstanceTimes.
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint8_t nsSMILTimedElement::sMaxNumIntervals = 20;
|
|
|
|
const uint8_t nsSMILTimedElement::sMaxNumInstanceTimes = 100;
|
2010-07-03 05:52:50 +00:00
|
|
|
|
2011-07-02 03:37:47 +00:00
|
|
|
// Detect if we arrive in some sort of undetected recursive syncbase dependency
|
|
|
|
// relationship
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint8_t nsSMILTimedElement::sMaxUpdateIntervalRecursionDepth = 20;
|
2011-07-02 03:37:47 +00:00
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Ctor, dtor
|
|
|
|
|
|
|
|
nsSMILTimedElement::nsSMILTimedElement()
|
|
|
|
:
|
2012-07-30 14:20:58 +00:00
|
|
|
mAnimationElement(nullptr),
|
2009-01-15 04:38:07 +00:00
|
|
|
mFillMode(FILL_REMOVE),
|
|
|
|
mRestartMode(RESTART_ALWAYS),
|
2010-01-12 20:00:49 +00:00
|
|
|
mInstanceSerialIndex(0),
|
2012-07-30 14:20:58 +00:00
|
|
|
mClient(nullptr),
|
|
|
|
mCurrentInterval(nullptr),
|
2010-07-31 07:02:52 +00:00
|
|
|
mCurrentRepeatIteration(0),
|
2010-01-12 20:00:49 +00:00
|
|
|
mPrevRegisteredMilestone(sMaxMilestone),
|
2010-07-03 05:52:51 +00:00
|
|
|
mElementState(STATE_STARTUP),
|
2011-07-02 03:37:10 +00:00
|
|
|
mSeekState(SEEK_NOT_SEEKING),
|
2011-10-17 14:59:28 +00:00
|
|
|
mDeferIntervalUpdates(false),
|
|
|
|
mDoDeferredUpdate(false),
|
2012-02-01 23:58:58 +00:00
|
|
|
mDeleteCount(0),
|
2011-07-02 03:37:47 +00:00
|
|
|
mUpdateIntervalRecursionDepth(0)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
|
|
|
mSimpleDur.SetIndefinite();
|
|
|
|
mMin.SetMillis(0L);
|
|
|
|
mMax.SetIndefinite();
|
|
|
|
}
|
|
|
|
|
2010-03-01 19:31:50 +00:00
|
|
|
nsSMILTimedElement::~nsSMILTimedElement()
|
|
|
|
{
|
|
|
|
// Unlink all instance times from dependent intervals
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mBeginInstances.Length(); ++i) {
|
2010-03-01 19:31:50 +00:00
|
|
|
mBeginInstances[i]->Unlink();
|
|
|
|
}
|
|
|
|
mBeginInstances.Clear();
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mEndInstances.Length(); ++i) {
|
2010-03-01 19:31:50 +00:00
|
|
|
mEndInstances[i]->Unlink();
|
|
|
|
}
|
|
|
|
mEndInstances.Clear();
|
|
|
|
|
|
|
|
// Notify anyone listening to our intervals that they're gone
|
|
|
|
// (We shouldn't get any callbacks from this because all our instance times
|
|
|
|
// are now disassociated with any intervals)
|
2011-07-25 17:45:49 +00:00
|
|
|
ClearIntervals();
|
2011-07-02 03:37:10 +00:00
|
|
|
|
|
|
|
// The following assertions are important in their own right (for checking
|
|
|
|
// correct behavior) but also because AutoIntervalUpdateBatcher holds pointers
|
|
|
|
// to class so if they fail there's the possibility we might have dangling
|
|
|
|
// pointers.
|
|
|
|
NS_ABORT_IF_FALSE(!mDeferIntervalUpdates,
|
|
|
|
"Interval updates should no longer be blocked when an nsSMILTimedElement "
|
|
|
|
"disappears");
|
|
|
|
NS_ABORT_IF_FALSE(!mDoDeferredUpdate,
|
|
|
|
"There should no longer be any pending updates when an "
|
|
|
|
"nsSMILTimedElement disappears");
|
2010-03-01 19:31:50 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
void
|
2013-03-19 03:18:45 +00:00
|
|
|
nsSMILTimedElement::SetAnimationElement(SVGAnimationElement* aElement)
|
2010-01-12 20:00:49 +00:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aElement, "NULL owner element");
|
|
|
|
NS_ABORT_IF_FALSE(!mAnimationElement, "Re-setting owner");
|
|
|
|
mAnimationElement = aElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimeContainer*
|
|
|
|
nsSMILTimedElement::GetTimeContainer()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return mAnimationElement ? mAnimationElement->GetTimeContainer() : nullptr;
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 03:18:45 +00:00
|
|
|
dom::Element*
|
|
|
|
nsSMILTimedElement::GetTargetElement()
|
|
|
|
{
|
|
|
|
return mAnimationElement ?
|
|
|
|
mAnimationElement->GetTargetElementContent() :
|
|
|
|
nullptr;
|
|
|
|
}
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMElementTimeControl methods
|
|
|
|
//
|
|
|
|
// The definition of the ElementTimeControl interface differs between SMIL
|
|
|
|
// Animation and SVG 1.1. In SMIL Animation all methods have a void return
|
|
|
|
// type and the new instance time is simply added to the list and restart
|
|
|
|
// semantics are applied as with any other instance time. In the SVG definition
|
2009-01-19 09:12:29 +00:00
|
|
|
// the methods return a bool depending on the restart mode.
|
2009-01-15 04:38:07 +00:00
|
|
|
//
|
2009-01-19 09:12:29 +00:00
|
|
|
// This inconsistency has now been addressed by an erratum in SVG 1.1:
|
2009-01-15 04:38:07 +00:00
|
|
|
//
|
2009-01-19 09:12:29 +00:00
|
|
|
// http://www.w3.org/2003/01/REC-SVG11-20030114-errata#elementtimecontrol-interface
|
2009-01-15 04:38:07 +00:00
|
|
|
//
|
2009-01-19 09:12:29 +00:00
|
|
|
// which favours the definition in SMIL, i.e. instance times are just added
|
|
|
|
// without first checking the restart mode.
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2009-01-19 09:12:29 +00:00
|
|
|
nsresult
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::BeginElementAt(double aOffsetSeconds)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimeContainer* container = GetTimeContainer();
|
|
|
|
if (!container)
|
2009-01-19 09:12:29 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-22 01:00:27 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTime currentTime = container->GetCurrentTime();
|
2011-10-17 14:59:28 +00:00
|
|
|
return AddInstanceTimeFromCurrentTime(currentTime, aOffsetSeconds, true);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 09:12:29 +00:00
|
|
|
nsresult
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::EndElementAt(double aOffsetSeconds)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimeContainer* container = GetTimeContainer();
|
|
|
|
if (!container)
|
2009-01-19 09:12:29 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-22 01:00:27 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTime currentTime = container->GetCurrentTime();
|
2011-10-17 14:59:28 +00:00
|
|
|
return AddInstanceTimeFromCurrentTime(currentTime, aOffsetSeconds, false);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 09:10:53 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGAnimationElement methods
|
|
|
|
|
|
|
|
nsSMILTimeValue
|
|
|
|
nsSMILTimedElement::GetStartTime() const
|
|
|
|
{
|
2009-10-12 23:14:08 +00:00
|
|
|
return mElementState == STATE_WAITING || mElementState == STATE_ACTIVE
|
2010-03-01 19:31:50 +00:00
|
|
|
? mCurrentInterval->Begin()->Time()
|
2009-10-12 23:14:08 +00:00
|
|
|
: nsSMILTimeValue();
|
2009-01-19 09:10:53 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 09:56:57 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Hyperlinking support
|
|
|
|
|
|
|
|
nsSMILTimeValue
|
|
|
|
nsSMILTimedElement::GetHyperlinkTime() const
|
|
|
|
{
|
|
|
|
nsSMILTimeValue hyperlinkTime; // Default ctor creates unresolved time
|
|
|
|
|
|
|
|
if (mElementState == STATE_ACTIVE) {
|
|
|
|
hyperlinkTime = mCurrentInterval->Begin()->Time();
|
|
|
|
} else if (!mBeginInstances.IsEmpty()) {
|
|
|
|
hyperlinkTime = mBeginInstances[0]->Time();
|
|
|
|
}
|
|
|
|
|
|
|
|
return hyperlinkTime;
|
|
|
|
}
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSMILTimedElement
|
|
|
|
|
|
|
|
void
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::AddInstanceTime(nsSMILInstanceTime* aInstanceTime,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIsBegin)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-01-12 20:00:49 +00:00
|
|
|
NS_ABORT_IF_FALSE(aInstanceTime, "Attempting to add null instance time");
|
|
|
|
|
2010-08-18 10:20:24 +00:00
|
|
|
// Event-sensitivity: If an element is not active (but the parent time
|
|
|
|
// container is), then events are only handled for begin specifications.
|
|
|
|
if (mElementState != STATE_ACTIVE && !aIsBegin &&
|
|
|
|
aInstanceTime->IsDynamic())
|
|
|
|
{
|
|
|
|
// No need to call Unlink here--dynamic instance times shouldn't be linked
|
|
|
|
// to anything that's going to miss them
|
|
|
|
NS_ABORT_IF_FALSE(!aInstanceTime->GetBaseInterval(),
|
|
|
|
"Dynamic instance time has a base interval--we probably need to unlink"
|
|
|
|
" it if we're not going to use it");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
aInstanceTime->SetSerial(++mInstanceSerialIndex);
|
|
|
|
InstanceTimeList& instanceList = aIsBegin ? mBeginInstances : mEndInstances;
|
|
|
|
nsRefPtr<nsSMILInstanceTime>* inserted =
|
|
|
|
instanceList.InsertElementSorted(aInstanceTime, InstanceTimeComparator());
|
|
|
|
if (!inserted) {
|
|
|
|
NS_WARNING("Insufficient memory to insert instance time");
|
|
|
|
return;
|
2009-01-19 09:12:29 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::UpdateInstanceTime(nsSMILInstanceTime* aInstanceTime,
|
|
|
|
nsSMILTimeValue& aUpdatedTime,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIsBegin)
|
2010-01-12 20:00:49 +00:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aInstanceTime, "Attempting to update null instance time");
|
|
|
|
|
|
|
|
// The reason we update the time here and not in the nsSMILTimeValueSpec is
|
|
|
|
// that it means we *could* re-sort more efficiently by doing a sorted remove
|
|
|
|
// and insert but currently this doesn't seem to be necessary given how
|
|
|
|
// infrequently we get these change notices.
|
|
|
|
aInstanceTime->DependentUpdate(aUpdatedTime);
|
|
|
|
InstanceTimeList& instanceList = aIsBegin ? mBeginInstances : mEndInstances;
|
|
|
|
instanceList.Sort(InstanceTimeComparator());
|
|
|
|
|
|
|
|
// Generally speaking, UpdateCurrentInterval makes changes to the current
|
|
|
|
// interval and sends changes notices itself. However, in this case because
|
|
|
|
// instance times are shared between the instance time list and the intervals
|
|
|
|
// we are effectively changing the current interval outside
|
|
|
|
// UpdateCurrentInterval so we need to explicitly signal that we've made
|
|
|
|
// a change.
|
|
|
|
//
|
|
|
|
// This wouldn't be necessary if we cloned instance times on adding them to
|
|
|
|
// the current interval but this introduces other complications (particularly
|
|
|
|
// detecting which instance time is being used to define the begin of the
|
|
|
|
// current interval when doing a Reset).
|
2011-09-29 06:19:26 +00:00
|
|
|
bool changedCurrentInterval = mCurrentInterval &&
|
2010-03-01 19:31:50 +00:00
|
|
|
(mCurrentInterval->Begin() == aInstanceTime ||
|
|
|
|
mCurrentInterval->End() == aInstanceTime);
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
UpdateCurrentInterval(changedCurrentInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::RemoveInstanceTime(nsSMILInstanceTime* aInstanceTime,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIsBegin)
|
2010-01-12 20:00:49 +00:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aInstanceTime, "Attempting to remove null instance time");
|
|
|
|
|
2011-07-25 17:44:54 +00:00
|
|
|
// If the instance time should be kept (because it is or was the fixed end
|
|
|
|
// point of an interval) then just disassociate it from the creator.
|
|
|
|
if (aInstanceTime->ShouldPreserve()) {
|
|
|
|
aInstanceTime->Unlink();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
InstanceTimeList& instanceList = aIsBegin ? mBeginInstances : mEndInstances;
|
2011-09-29 06:19:26 +00:00
|
|
|
mozilla::DebugOnly<bool> found =
|
2010-01-12 20:00:49 +00:00
|
|
|
instanceList.RemoveElementSorted(aInstanceTime, InstanceTimeComparator());
|
|
|
|
NS_ABORT_IF_FALSE(found, "Couldn't find instance time to delete");
|
|
|
|
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
namespace
|
|
|
|
{
|
2013-04-12 03:20:09 +00:00
|
|
|
class MOZ_STACK_CLASS RemoveByCreator
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
RemoveByCreator(const nsSMILTimeValueSpec* aCreator) : mCreator(aCreator)
|
|
|
|
{ }
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
bool operator()(nsSMILInstanceTime* aInstanceTime, uint32_t /*aIndex*/)
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
2011-07-02 03:37:56 +00:00
|
|
|
if (aInstanceTime->GetCreator() != mCreator)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-07-02 03:37:56 +00:00
|
|
|
|
|
|
|
// If the instance time should be kept (because it is or was the fixed end
|
|
|
|
// point of an interval) then just disassociate it from the creator.
|
|
|
|
if (aInstanceTime->ShouldPreserve()) {
|
|
|
|
aInstanceTime->Unlink();
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-07-02 03:37:56 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-07-03 05:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsSMILTimeValueSpec* mCreator;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-03-01 19:31:50 +00:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::RemoveInstanceTimesForCreator(
|
2011-09-29 06:19:26 +00:00
|
|
|
const nsSMILTimeValueSpec* aCreator, bool aIsBegin)
|
2010-03-01 19:31:50 +00:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aCreator, "Creator not set");
|
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
InstanceTimeList& instances = aIsBegin ? mBeginInstances : mEndInstances;
|
|
|
|
RemoveByCreator removeByCreator(aCreator);
|
|
|
|
RemoveInstanceTimes(instances, removeByCreator);
|
2010-03-01 19:31:50 +00:00
|
|
|
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::SetTimeClient(nsSMILAnimationFunction* aClient)
|
|
|
|
{
|
|
|
|
//
|
2013-04-03 01:14:24 +00:00
|
|
|
// No need to check for nullptr. A nullptr parameter simply means to remove the
|
|
|
|
// previous client which we do by setting to nullptr anyway.
|
2009-01-15 04:38:07 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
mClient = aClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::SampleAt(nsSMILTime aContainerTime)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-01-12 20:00:49 +00:00
|
|
|
// Milestones are cleared before a sample
|
|
|
|
mPrevRegisteredMilestone = sMaxMilestone;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
DoSampleAt(aContainerTime, false);
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::SampleEndAt(nsSMILTime aContainerTime)
|
|
|
|
{
|
|
|
|
// Milestones are cleared before a sample
|
|
|
|
mPrevRegisteredMilestone = sMaxMilestone;
|
|
|
|
|
|
|
|
// If the current interval changes, we don't bother trying to remove any old
|
|
|
|
// milestones we'd registered. So it's possible to get a call here to end an
|
|
|
|
// interval at a time that no longer reflects the end of the current interval.
|
|
|
|
//
|
|
|
|
// For now we just check that we're actually in an interval but note that the
|
|
|
|
// initial sample we use to initialise the model is an end sample. This is
|
|
|
|
// because we want to resolve all the instance times before committing to an
|
|
|
|
// initial interval. Therefore an end sample from the startup state is also
|
|
|
|
// acceptable.
|
|
|
|
if (mElementState == STATE_ACTIVE || mElementState == STATE_STARTUP) {
|
2011-10-17 14:59:28 +00:00
|
|
|
DoSampleAt(aContainerTime, true); // End sample
|
2010-01-12 20:00:49 +00:00
|
|
|
} else {
|
|
|
|
// Even if this was an unnecessary milestone sample we want to be sure that
|
|
|
|
// our next real milestone is registered.
|
|
|
|
RegisterMilestone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsSMILTimedElement::DoSampleAt(nsSMILTime aContainerTime, bool aEndOnly)
|
2010-01-12 20:00:49 +00:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mAnimationElement,
|
|
|
|
"Got sample before being registered with an animation element");
|
|
|
|
NS_ABORT_IF_FALSE(GetTimeContainer(),
|
|
|
|
"Got sample without being registered with a time container");
|
|
|
|
|
|
|
|
// This could probably happen if we later implement externalResourcesRequired
|
|
|
|
// (bug 277955) and whilst waiting for those resources (and the animation to
|
|
|
|
// start) we transfer a node from another document fragment that has already
|
|
|
|
// started. In such a case we might receive milestone samples registered with
|
|
|
|
// the already active container.
|
|
|
|
if (GetTimeContainer()->IsPausedByType(nsSMILTimeContainer::PAUSE_BEGIN))
|
|
|
|
return;
|
|
|
|
|
2010-12-14 00:38:14 +00:00
|
|
|
// We use an end-sample to start animation since an end-sample lets us
|
|
|
|
// tentatively create an interval without committing to it (by transitioning
|
|
|
|
// to the ACTIVE state) and this is necessary because we might have
|
|
|
|
// dependencies on other animations that are yet to start. After these
|
|
|
|
// other animations start, it may be necessary to revise our initial interval.
|
|
|
|
//
|
|
|
|
// However, sometimes instead of an end-sample we can get a regular sample
|
|
|
|
// during STARTUP state. This can happen, for example, if we register
|
|
|
|
// a milestone before time t=0 and are then re-bound to the tree (which sends
|
|
|
|
// us back to the STARTUP state). In such a case we should just ignore the
|
|
|
|
// sample and wait for our real initial sample which will be an end-sample.
|
|
|
|
if (mElementState == STATE_STARTUP && !aEndOnly)
|
|
|
|
return;
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool finishedSeek = false;
|
2010-07-03 05:52:51 +00:00
|
|
|
if (GetTimeContainer()->IsSeeking() && mSeekState == SEEK_NOT_SEEKING) {
|
|
|
|
mSeekState = mElementState == STATE_ACTIVE ?
|
|
|
|
SEEK_FORWARD_FROM_ACTIVE :
|
|
|
|
SEEK_FORWARD_FROM_INACTIVE;
|
|
|
|
} else if (mSeekState != SEEK_NOT_SEEKING &&
|
|
|
|
!GetTimeContainer()->IsSeeking()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
finishedSeek = true;
|
2010-07-03 05:52:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool stateChanged;
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimeValue sampleTime(aContainerTime);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
do {
|
2010-03-01 19:31:52 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Check invariant
|
|
|
|
if (mElementState == STATE_STARTUP || mElementState == STATE_POSTACTIVE) {
|
|
|
|
NS_ABORT_IF_FALSE(!mCurrentInterval,
|
|
|
|
"Shouldn't have current interval in startup or postactive states");
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(mCurrentInterval,
|
|
|
|
"Should have current interval in waiting and active states");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
stateChanged = false;
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
switch (mElementState)
|
|
|
|
{
|
|
|
|
case STATE_STARTUP:
|
|
|
|
{
|
2010-03-01 19:31:50 +00:00
|
|
|
nsSMILInterval firstInterval;
|
2012-07-30 14:20:58 +00:00
|
|
|
mElementState = GetNextInterval(nullptr, nullptr, nullptr, firstInterval)
|
2009-01-15 04:38:07 +00:00
|
|
|
? STATE_WAITING
|
|
|
|
: STATE_POSTACTIVE;
|
2011-10-17 14:59:28 +00:00
|
|
|
stateChanged = true;
|
2010-01-12 20:00:49 +00:00
|
|
|
if (mElementState == STATE_WAITING) {
|
2010-03-01 19:31:50 +00:00
|
|
|
mCurrentInterval = new nsSMILInterval(firstInterval);
|
2010-07-03 05:52:50 +00:00
|
|
|
NotifyNewInterval();
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_WAITING:
|
|
|
|
{
|
2010-03-01 19:31:50 +00:00
|
|
|
if (mCurrentInterval->Begin()->Time() <= sampleTime) {
|
2009-01-15 04:38:07 +00:00
|
|
|
mElementState = STATE_ACTIVE;
|
2010-07-03 05:52:50 +00:00
|
|
|
mCurrentInterval->FixBegin();
|
2009-01-15 04:38:07 +00:00
|
|
|
if (mClient) {
|
2010-03-01 19:31:50 +00:00
|
|
|
mClient->Activate(mCurrentInterval->Begin()->Time().GetMillis());
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2010-07-31 07:02:52 +00:00
|
|
|
if (mSeekState == SEEK_NOT_SEEKING) {
|
|
|
|
FireTimeEventAsync(NS_SMIL_BEGIN, 0);
|
|
|
|
}
|
2010-03-01 19:31:50 +00:00
|
|
|
if (HasPlayed()) {
|
2010-07-31 07:02:52 +00:00
|
|
|
Reset(); // Apply restart behaviour
|
2010-01-13 08:18:51 +00:00
|
|
|
// The call to Reset() may mean that the end point of our current
|
|
|
|
// interval should be changed and so we should update the interval
|
|
|
|
// now. However, calling UpdateCurrentInterval could result in the
|
|
|
|
// interval getting deleted (perhaps through some web of syncbase
|
|
|
|
// dependencies) therefore we make updating the interval the last
|
2010-07-31 07:02:52 +00:00
|
|
|
// thing we do. There is no guarantee that mCurrentInterval is set
|
|
|
|
// after this.
|
2010-01-13 08:18:51 +00:00
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
stateChanged = true;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_ACTIVE:
|
|
|
|
{
|
2011-06-15 00:16:57 +00:00
|
|
|
// Ending early will change the interval but we don't notify dependents
|
|
|
|
// of the change until we have closed off the current interval (since we
|
|
|
|
// don't want dependencies to un-end our early end).
|
2011-09-29 06:19:26 +00:00
|
|
|
bool didApplyEarlyEnd = ApplyEarlyEnd(sampleTime);
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2010-03-01 19:31:50 +00:00
|
|
|
if (mCurrentInterval->End()->Time() <= sampleTime) {
|
2009-01-15 04:38:07 +00:00
|
|
|
nsSMILInterval newInterval;
|
2011-06-22 01:12:35 +00:00
|
|
|
mElementState =
|
2012-07-30 14:20:58 +00:00
|
|
|
GetNextInterval(mCurrentInterval, nullptr, nullptr, newInterval)
|
2009-01-15 04:38:07 +00:00
|
|
|
? STATE_WAITING
|
|
|
|
: STATE_POSTACTIVE;
|
|
|
|
if (mClient) {
|
|
|
|
mClient->Inactivate(mFillMode == FILL_FREEZE);
|
|
|
|
}
|
2010-07-03 05:52:50 +00:00
|
|
|
mCurrentInterval->FixEnd();
|
2010-07-31 07:02:52 +00:00
|
|
|
if (mSeekState == SEEK_NOT_SEEKING) {
|
|
|
|
FireTimeEventAsync(NS_SMIL_END, 0);
|
|
|
|
}
|
|
|
|
mCurrentRepeatIteration = 0;
|
2010-03-01 19:31:50 +00:00
|
|
|
mOldIntervals.AppendElement(mCurrentInterval.forget());
|
2010-01-12 20:00:49 +00:00
|
|
|
SampleFillValue();
|
|
|
|
if (mElementState == STATE_WAITING) {
|
2010-03-01 19:31:50 +00:00
|
|
|
mCurrentInterval = new nsSMILInterval(newInterval);
|
2011-06-15 00:16:57 +00:00
|
|
|
}
|
|
|
|
// We are now in a consistent state to dispatch notifications
|
|
|
|
if (didApplyEarlyEnd) {
|
|
|
|
NotifyChangedInterval(
|
2011-10-17 14:59:28 +00:00
|
|
|
mOldIntervals[mOldIntervals.Length() - 1], false, true);
|
2011-06-15 00:16:57 +00:00
|
|
|
}
|
|
|
|
if (mElementState == STATE_WAITING) {
|
2010-07-03 05:52:50 +00:00
|
|
|
NotifyNewInterval();
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
2010-07-03 05:52:50 +00:00
|
|
|
FilterHistory();
|
2011-10-17 14:59:28 +00:00
|
|
|
stateChanged = true;
|
2009-01-15 04:38:07 +00:00
|
|
|
} else {
|
2011-06-15 00:16:57 +00:00
|
|
|
NS_ABORT_IF_FALSE(!didApplyEarlyEnd,
|
|
|
|
"We got an early end, but didn't end");
|
2010-03-01 19:31:50 +00:00
|
|
|
nsSMILTime beginTime = mCurrentInterval->Begin()->Time().GetMillis();
|
2010-07-03 05:52:51 +00:00
|
|
|
NS_ASSERTION(aContainerTime >= beginTime,
|
|
|
|
"Sample time should not precede current interval");
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTime activeTime = aContainerTime - beginTime;
|
2013-12-13 04:41:52 +00:00
|
|
|
|
|
|
|
// The 'min' attribute can cause the active interval to be longer than
|
|
|
|
// the 'repeating interval'.
|
|
|
|
// In that extended period we apply the fill mode.
|
|
|
|
if (GetRepeatDuration() <= nsSMILTimeValue(activeTime)) {
|
|
|
|
if (mClient && mClient->IsActive()) {
|
|
|
|
mClient->Inactivate(mFillMode == FILL_FREEZE);
|
|
|
|
}
|
|
|
|
SampleFillValue();
|
|
|
|
} else {
|
|
|
|
SampleSimpleTime(activeTime);
|
|
|
|
|
|
|
|
// We register our repeat times as milestones (except when we're
|
|
|
|
// seeking) so we should get a sample at exactly the time we repeat.
|
|
|
|
// (And even when we are seeking we want to update
|
|
|
|
// mCurrentRepeatIteration so we do that first before testing the
|
|
|
|
// seek state.)
|
|
|
|
uint32_t prevRepeatIteration = mCurrentRepeatIteration;
|
|
|
|
if (
|
|
|
|
ActiveTimeToSimpleTime(activeTime, mCurrentRepeatIteration)==0 &&
|
2010-07-31 07:02:52 +00:00
|
|
|
mCurrentRepeatIteration != prevRepeatIteration &&
|
|
|
|
mCurrentRepeatIteration &&
|
|
|
|
mSeekState == SEEK_NOT_SEEKING) {
|
2013-12-13 04:41:52 +00:00
|
|
|
FireTimeEventAsync(NS_SMIL_REPEAT,
|
|
|
|
static_cast<int32_t>(mCurrentRepeatIteration));
|
|
|
|
}
|
2010-07-31 07:02:52 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_POSTACTIVE:
|
|
|
|
break;
|
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
// Generally we continue driving the state machine so long as we have changed
|
|
|
|
// state. However, for end samples we only drive the state machine as far as
|
|
|
|
// the waiting or postactive state because we don't want to commit to any new
|
|
|
|
// interval (by transitioning to the active state) until all the end samples
|
|
|
|
// have finished and we then have complete information about the available
|
|
|
|
// instance times upon which to base our next interval.
|
|
|
|
} while (stateChanged && (!aEndOnly || (mElementState != STATE_WAITING &&
|
|
|
|
mElementState != STATE_POSTACTIVE)));
|
|
|
|
|
2010-07-03 05:52:51 +00:00
|
|
|
if (finishedSeek) {
|
|
|
|
DoPostSeek();
|
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
RegisterMilestone();
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::HandleContainerTimeChange()
|
|
|
|
{
|
|
|
|
// In future we could possibly introduce a separate change notice for time
|
|
|
|
// container changes and only notify those dependents who live in other time
|
|
|
|
// containers. For now we don't bother because when we re-resolve the time in
|
|
|
|
// the nsSMILTimeValueSpec we'll check if anything has changed and if not, we
|
|
|
|
// won't go any further.
|
|
|
|
if (mElementState == STATE_WAITING || mElementState == STATE_ACTIVE) {
|
2011-10-17 14:59:28 +00:00
|
|
|
NotifyChangedInterval(mCurrentInterval, false, false);
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-18 10:20:24 +00:00
|
|
|
namespace
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-08-18 10:20:24 +00:00
|
|
|
RemoveNonDynamic(nsSMILInstanceTime* aInstanceTime)
|
|
|
|
{
|
|
|
|
// Generally dynamically-generated instance times (DOM calls, event-based
|
|
|
|
// times) are not associated with their creator nsSMILTimeValueSpec since
|
|
|
|
// they may outlive them.
|
|
|
|
NS_ABORT_IF_FALSE(!aInstanceTime->IsDynamic() ||
|
|
|
|
!aInstanceTime->GetCreator(),
|
|
|
|
"Dynamic instance time should be unlinked from its creator");
|
2011-07-25 17:45:29 +00:00
|
|
|
return !aInstanceTime->IsDynamic() && !aInstanceTime->ShouldPreserve();
|
2010-08-18 10:20:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-03 05:52:51 +00:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::Rewind()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mAnimationElement,
|
|
|
|
"Got rewind request before being attached to an animation element");
|
|
|
|
|
2010-10-13 00:15:32 +00:00
|
|
|
// It's possible to get a rewind request whilst we're already in the middle of
|
|
|
|
// a backwards seek. This can happen when we're performing tree surgery and
|
|
|
|
// seeking containers at the same time because we can end up requesting
|
|
|
|
// a local rewind on an element after binding it to a new container and then
|
|
|
|
// performing a rewind on that container as a whole without sampling in
|
|
|
|
// between.
|
|
|
|
//
|
|
|
|
// However, it should currently be impossible to get a rewind in the middle of
|
|
|
|
// a forwards seek since forwards seeks are detected and processed within the
|
|
|
|
// same (re)sample.
|
|
|
|
if (mSeekState == SEEK_NOT_SEEKING) {
|
|
|
|
mSeekState = mElementState == STATE_ACTIVE ?
|
|
|
|
SEEK_BACKWARD_FROM_ACTIVE :
|
|
|
|
SEEK_BACKWARD_FROM_INACTIVE;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(mSeekState == SEEK_BACKWARD_FROM_INACTIVE ||
|
|
|
|
mSeekState == SEEK_BACKWARD_FROM_ACTIVE,
|
|
|
|
"Rewind in the middle of a forwards seek?");
|
2010-07-03 05:52:51 +00:00
|
|
|
|
2011-09-02 13:15:54 +00:00
|
|
|
// Putting us in the startup state will ensure we skip doing any interval
|
|
|
|
// updates
|
2011-09-02 13:03:08 +00:00
|
|
|
mElementState = STATE_STARTUP;
|
2011-09-02 13:15:54 +00:00
|
|
|
ClearIntervals();
|
2010-07-03 05:52:51 +00:00
|
|
|
|
2010-08-18 10:20:24 +00:00
|
|
|
UnsetBeginSpec(RemoveNonDynamic);
|
|
|
|
UnsetEndSpec(RemoveNonDynamic);
|
2010-07-03 05:52:51 +00:00
|
|
|
|
|
|
|
if (mClient) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mClient->Inactivate(false);
|
2010-07-03 05:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mAnimationElement->HasAnimAttr(nsGkAtoms::begin)) {
|
|
|
|
nsAutoString attValue;
|
|
|
|
mAnimationElement->GetAnimAttr(nsGkAtoms::begin, attValue);
|
2013-03-19 03:18:45 +00:00
|
|
|
SetBeginSpec(attValue, mAnimationElement, RemoveNonDynamic);
|
2010-07-03 05:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mAnimationElement->HasAnimAttr(nsGkAtoms::end)) {
|
|
|
|
nsAutoString attValue;
|
|
|
|
mAnimationElement->GetAnimAttr(nsGkAtoms::end, attValue);
|
2013-03-19 03:18:45 +00:00
|
|
|
SetEndSpec(attValue, mAnimationElement, RemoveNonDynamic);
|
2010-07-03 05:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mPrevRegisteredMilestone = sMaxMilestone;
|
|
|
|
RegisterMilestone();
|
2011-09-02 13:15:54 +00:00
|
|
|
NS_ABORT_IF_FALSE(!mCurrentInterval,
|
|
|
|
"Current interval is set at end of rewind");
|
2010-07-03 05:52:51 +00:00
|
|
|
}
|
|
|
|
|
2010-08-18 10:20:24 +00:00
|
|
|
namespace
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-08-18 10:20:24 +00:00
|
|
|
RemoveNonDOM(nsSMILInstanceTime* aInstanceTime)
|
|
|
|
{
|
2011-07-25 17:45:29 +00:00
|
|
|
return !aInstanceTime->FromDOM() && !aInstanceTime->ShouldPreserve();
|
2010-08-18 10:20:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-01-15 04:38:07 +00:00
|
|
|
nsSMILTimedElement::SetAttr(nsIAtom* aAttribute, const nsAString& aValue,
|
2010-08-18 10:20:24 +00:00
|
|
|
nsAttrValue& aResult,
|
|
|
|
Element* aContextNode,
|
2010-01-12 20:00:49 +00:00
|
|
|
nsresult* aParseResult)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool foundMatch = true;
|
2009-01-15 04:38:07 +00:00
|
|
|
nsresult parseResult = NS_OK;
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::begin) {
|
2010-08-18 10:20:24 +00:00
|
|
|
parseResult = SetBeginSpec(aValue, aContextNode, RemoveNonDOM);
|
2009-01-15 04:38:07 +00:00
|
|
|
} else if (aAttribute == nsGkAtoms::dur) {
|
|
|
|
parseResult = SetSimpleDuration(aValue);
|
|
|
|
} else if (aAttribute == nsGkAtoms::end) {
|
2010-08-18 10:20:24 +00:00
|
|
|
parseResult = SetEndSpec(aValue, aContextNode, RemoveNonDOM);
|
2009-01-15 04:38:07 +00:00
|
|
|
} else if (aAttribute == nsGkAtoms::fill) {
|
|
|
|
parseResult = SetFillMode(aValue);
|
|
|
|
} else if (aAttribute == nsGkAtoms::max) {
|
|
|
|
parseResult = SetMax(aValue);
|
|
|
|
} else if (aAttribute == nsGkAtoms::min) {
|
|
|
|
parseResult = SetMin(aValue);
|
|
|
|
} else if (aAttribute == nsGkAtoms::repeatCount) {
|
|
|
|
parseResult = SetRepeatCount(aValue);
|
|
|
|
} else if (aAttribute == nsGkAtoms::repeatDur) {
|
|
|
|
parseResult = SetRepeatDur(aValue);
|
|
|
|
} else if (aAttribute == nsGkAtoms::restart) {
|
|
|
|
parseResult = SetRestart(aValue);
|
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
foundMatch = false;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (foundMatch) {
|
|
|
|
aResult.SetTo(aValue);
|
|
|
|
if (aParseResult) {
|
|
|
|
*aParseResult = parseResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundMatch;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-01-15 04:38:07 +00:00
|
|
|
nsSMILTimedElement::UnsetAttr(nsIAtom* aAttribute)
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool foundMatch = true;
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::begin) {
|
2010-08-18 10:20:24 +00:00
|
|
|
UnsetBeginSpec(RemoveNonDOM);
|
2009-01-15 04:38:07 +00:00
|
|
|
} else if (aAttribute == nsGkAtoms::dur) {
|
|
|
|
UnsetSimpleDuration();
|
|
|
|
} else if (aAttribute == nsGkAtoms::end) {
|
2010-08-18 10:20:24 +00:00
|
|
|
UnsetEndSpec(RemoveNonDOM);
|
2009-01-15 04:38:07 +00:00
|
|
|
} else if (aAttribute == nsGkAtoms::fill) {
|
|
|
|
UnsetFillMode();
|
|
|
|
} else if (aAttribute == nsGkAtoms::max) {
|
|
|
|
UnsetMax();
|
|
|
|
} else if (aAttribute == nsGkAtoms::min) {
|
|
|
|
UnsetMin();
|
|
|
|
} else if (aAttribute == nsGkAtoms::repeatCount) {
|
|
|
|
UnsetRepeatCount();
|
|
|
|
} else if (aAttribute == nsGkAtoms::repeatDur) {
|
|
|
|
UnsetRepeatDur();
|
|
|
|
} else if (aAttribute == nsGkAtoms::restart) {
|
|
|
|
UnsetRestart();
|
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
foundMatch = false;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return foundMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Setters and unsetters
|
|
|
|
|
|
|
|
nsresult
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::SetBeginSpec(const nsAString& aBeginSpec,
|
2010-08-18 10:20:24 +00:00
|
|
|
Element* aContextNode,
|
2010-08-18 10:20:24 +00:00
|
|
|
RemovalTestFunction aRemove)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return SetBeginOrEndSpec(aBeginSpec, aContextNode, true /*isBegin*/,
|
2010-08-18 10:20:24 +00:00
|
|
|
aRemove);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-18 10:20:24 +00:00
|
|
|
nsSMILTimedElement::UnsetBeginSpec(RemovalTestFunction aRemove)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-08-18 10:20:24 +00:00
|
|
|
ClearSpecs(mBeginSpecs, mBeginInstances, aRemove);
|
2009-01-15 04:38:07 +00:00
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::SetEndSpec(const nsAString& aEndSpec,
|
2010-08-18 10:20:24 +00:00
|
|
|
Element* aContextNode,
|
2010-08-18 10:20:24 +00:00
|
|
|
RemovalTestFunction aRemove)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return SetBeginOrEndSpec(aEndSpec, aContextNode, false /*!isBegin*/,
|
2010-08-18 10:20:24 +00:00
|
|
|
aRemove);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-18 10:20:24 +00:00
|
|
|
nsSMILTimedElement::UnsetEndSpec(RemovalTestFunction aRemove)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-08-18 10:20:24 +00:00
|
|
|
ClearSpecs(mEndSpecs, mEndInstances, aRemove);
|
2009-01-15 04:38:07 +00:00
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetSimpleDuration(const nsAString& aDurSpec)
|
|
|
|
{
|
2013-12-13 04:41:56 +00:00
|
|
|
// Update the current interval before returning
|
|
|
|
AutoIntervalUpdater updater(*this);
|
2009-07-15 18:33:31 +00:00
|
|
|
|
2013-12-13 04:41:56 +00:00
|
|
|
nsSMILTimeValue duration;
|
2013-11-25 19:46:20 +00:00
|
|
|
const nsAString& dur = nsSMILParserUtils::TrimWhitespace(aDurSpec);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
// SVG-specific: "For SVG's animation elements, if "media" is specified, the
|
|
|
|
// attribute will be ignored." (SVG 1.1, section 19.2.6)
|
2013-11-25 19:46:20 +00:00
|
|
|
if (dur.EqualsLiteral("media") || dur.EqualsLiteral("indefinite")) {
|
2009-01-15 04:38:07 +00:00
|
|
|
duration.SetIndefinite();
|
2013-11-25 19:46:20 +00:00
|
|
|
} else {
|
|
|
|
if (!nsSMILParserUtils::ParseClockValue(dur, &duration) ||
|
|
|
|
duration.GetMillis() == 0L) {
|
|
|
|
mSimpleDur.SetIndefinite();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2009-01-19 09:10:53 +00:00
|
|
|
// mSimpleDur should never be unresolved. ParseClockValue will either set
|
2013-11-25 19:46:20 +00:00
|
|
|
// duration to resolved or will return false.
|
2011-09-07 00:20:40 +00:00
|
|
|
NS_ABORT_IF_FALSE(duration.IsResolved(),
|
2009-01-19 09:10:53 +00:00
|
|
|
"Setting unresolved simple duration");
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
mSimpleDur = duration;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetSimpleDuration()
|
|
|
|
{
|
|
|
|
mSimpleDur.SetIndefinite();
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetMin(const nsAString& aMinSpec)
|
|
|
|
{
|
2013-12-13 04:41:56 +00:00
|
|
|
// Update the current interval before returning
|
|
|
|
AutoIntervalUpdater updater(*this);
|
2009-07-15 18:33:31 +00:00
|
|
|
|
2013-12-13 04:41:56 +00:00
|
|
|
nsSMILTimeValue duration;
|
2013-11-25 19:46:20 +00:00
|
|
|
const nsAString& min = nsSMILParserUtils::TrimWhitespace(aMinSpec);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2013-11-25 19:46:20 +00:00
|
|
|
if (min.EqualsLiteral("media")) {
|
2009-01-15 04:38:07 +00:00
|
|
|
duration.SetMillis(0L);
|
2013-11-25 19:46:20 +00:00
|
|
|
} else {
|
|
|
|
if (!nsSMILParserUtils::ParseClockValue(min, &duration)) {
|
|
|
|
mMin.SetMillis(0L);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 19:46:20 +00:00
|
|
|
NS_ABORT_IF_FALSE(duration.GetMillis() >= 0L, "Invalid duration");
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
mMin = duration;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetMin()
|
|
|
|
{
|
|
|
|
mMin.SetMillis(0L);
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetMax(const nsAString& aMaxSpec)
|
|
|
|
{
|
2013-12-13 04:41:56 +00:00
|
|
|
// Update the current interval before returning
|
|
|
|
AutoIntervalUpdater updater(*this);
|
2009-07-15 18:33:31 +00:00
|
|
|
|
2013-12-13 04:41:56 +00:00
|
|
|
nsSMILTimeValue duration;
|
2013-11-25 19:46:20 +00:00
|
|
|
const nsAString& max = nsSMILParserUtils::TrimWhitespace(aMaxSpec);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2013-11-25 19:46:20 +00:00
|
|
|
if (max.EqualsLiteral("media") || max.EqualsLiteral("indefinite")) {
|
2009-01-15 04:38:07 +00:00
|
|
|
duration.SetIndefinite();
|
2013-11-25 19:46:20 +00:00
|
|
|
} else {
|
|
|
|
if (!nsSMILParserUtils::ParseClockValue(max, &duration) ||
|
|
|
|
duration.GetMillis() == 0L) {
|
|
|
|
mMax.SetIndefinite();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(duration.GetMillis() > 0L, "Invalid duration");
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mMax = duration;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetMax()
|
|
|
|
{
|
|
|
|
mMax.SetIndefinite();
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetRestart(const nsAString& aRestartSpec)
|
|
|
|
{
|
|
|
|
nsAttrValue temp;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool parseResult
|
2011-10-17 14:59:28 +00:00
|
|
|
= temp.ParseEnumValue(aRestartSpec, sRestartModeTable, true);
|
2009-01-15 04:38:07 +00:00
|
|
|
mRestartMode = parseResult
|
|
|
|
? nsSMILRestartMode(temp.GetEnumValue())
|
|
|
|
: RESTART_ALWAYS;
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
return parseResult ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetRestart()
|
|
|
|
{
|
|
|
|
mRestartMode = RESTART_ALWAYS;
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetRepeatCount(const nsAString& aRepeatCountSpec)
|
|
|
|
{
|
2013-12-13 04:41:56 +00:00
|
|
|
// Update the current interval before returning
|
|
|
|
AutoIntervalUpdater updater(*this);
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
nsSMILRepeatCount newRepeatCount;
|
|
|
|
|
2013-11-25 19:46:20 +00:00
|
|
|
if (nsSMILParserUtils::ParseRepeatCount(aRepeatCountSpec, newRepeatCount)) {
|
2009-01-15 04:38:07 +00:00
|
|
|
mRepeatCount = newRepeatCount;
|
2013-11-25 19:46:20 +00:00
|
|
|
return NS_OK;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2013-11-25 19:46:20 +00:00
|
|
|
mRepeatCount.Unset();
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetRepeatCount()
|
|
|
|
{
|
|
|
|
mRepeatCount.Unset();
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetRepeatDur(const nsAString& aRepeatDurSpec)
|
|
|
|
{
|
2013-12-13 04:41:56 +00:00
|
|
|
// Update the current interval before returning
|
|
|
|
AutoIntervalUpdater updater(*this);
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
nsSMILTimeValue duration;
|
|
|
|
|
2013-11-25 19:46:20 +00:00
|
|
|
const nsAString& repeatDur =
|
|
|
|
nsSMILParserUtils::TrimWhitespace(aRepeatDurSpec);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2013-11-25 19:46:20 +00:00
|
|
|
if (repeatDur.EqualsLiteral("indefinite")) {
|
|
|
|
duration.SetIndefinite();
|
|
|
|
} else {
|
|
|
|
if (!nsSMILParserUtils::ParseClockValue(repeatDur, &duration)) {
|
|
|
|
mRepeatDur.SetUnresolved();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-01-19 09:10:53 +00:00
|
|
|
}
|
2009-07-15 18:33:31 +00:00
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
mRepeatDur = duration;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetRepeatDur()
|
|
|
|
{
|
|
|
|
mRepeatDur.SetUnresolved();
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetFillMode(const nsAString& aFillModeSpec)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t previousFillMode = mFillMode;
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
nsAttrValue temp;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool parseResult =
|
2011-10-17 14:59:28 +00:00
|
|
|
temp.ParseEnumValue(aFillModeSpec, sFillModeTable, true);
|
2009-01-15 04:38:07 +00:00
|
|
|
mFillMode = parseResult
|
|
|
|
? nsSMILFillMode(temp.GetEnumValue())
|
|
|
|
: FILL_REMOVE;
|
|
|
|
|
2013-12-13 04:41:52 +00:00
|
|
|
// Update fill mode of client
|
|
|
|
if (mFillMode != previousFillMode && HasClientInFillRange()) {
|
2010-01-12 20:00:49 +00:00
|
|
|
mClient->Inactivate(mFillMode == FILL_FREEZE);
|
|
|
|
SampleFillValue();
|
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
return parseResult ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetFillMode()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t previousFillMode = mFillMode;
|
2009-01-15 04:38:07 +00:00
|
|
|
mFillMode = FILL_REMOVE;
|
2013-12-13 04:41:52 +00:00
|
|
|
if (previousFillMode == FILL_FREEZE && HasClientInFillRange()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mClient->Inactivate(false);
|
2013-12-13 04:41:52 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
void
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::AddDependent(nsSMILTimeValueSpec& aDependent)
|
|
|
|
{
|
|
|
|
// There's probably no harm in attempting to register a dependent
|
2010-01-12 20:00:49 +00:00
|
|
|
// nsSMILTimeValueSpec twice, but we're not expecting it to happen.
|
|
|
|
NS_ABORT_IF_FALSE(!mTimeDependents.GetEntry(&aDependent),
|
2010-01-12 20:00:49 +00:00
|
|
|
"nsSMILTimeValueSpec is already registered as a dependency");
|
2010-01-12 20:00:49 +00:00
|
|
|
mTimeDependents.PutEntry(&aDependent);
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
// Add current interval. We could add historical intervals too but that would
|
|
|
|
// cause unpredictable results since some intervals may have been filtered.
|
|
|
|
// SMIL doesn't say what to do here so for simplicity and consistency we
|
|
|
|
// simply add the current interval if there is one.
|
2010-03-01 19:31:50 +00:00
|
|
|
//
|
|
|
|
// It's not necessary to call SyncPauseTime since we're dealing with
|
|
|
|
// historical instance times not newly added ones.
|
|
|
|
if (mCurrentInterval) {
|
2010-07-03 05:52:50 +00:00
|
|
|
aDependent.HandleNewInterval(*mCurrentInterval, GetTimeContainer());
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::RemoveDependent(nsSMILTimeValueSpec& aDependent)
|
2010-01-12 20:00:49 +00:00
|
|
|
{
|
2010-01-12 20:00:49 +00:00
|
|
|
mTimeDependents.RemoveEntry(&aDependent);
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::IsTimeDependent(const nsSMILTimedElement& aOther) const
|
|
|
|
{
|
|
|
|
const nsSMILInstanceTime* thisBegin = GetEffectiveBeginInstance();
|
|
|
|
const nsSMILInstanceTime* otherBegin = aOther.GetEffectiveBeginInstance();
|
|
|
|
|
|
|
|
if (!thisBegin || !otherBegin)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
return thisBegin->IsDependentOn(*otherBegin);
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::BindToTree(nsIContent* aContextNode)
|
|
|
|
{
|
2010-11-09 23:22:02 +00:00
|
|
|
// Reset previously registered milestone since we may be registering with
|
|
|
|
// a different time container now.
|
|
|
|
mPrevRegisteredMilestone = sMaxMilestone;
|
|
|
|
|
2010-10-13 00:20:12 +00:00
|
|
|
// If we were already active then clear all our timing information and start
|
|
|
|
// afresh
|
|
|
|
if (mElementState != STATE_STARTUP) {
|
|
|
|
mSeekState = SEEK_NOT_SEEKING;
|
|
|
|
Rewind();
|
|
|
|
}
|
|
|
|
|
2011-07-02 03:37:10 +00:00
|
|
|
// Scope updateBatcher to last only for the ResolveReferences calls:
|
|
|
|
{
|
|
|
|
AutoIntervalUpdateBatcher updateBatcher(*this);
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2011-07-02 03:37:10 +00:00
|
|
|
// Resolve references to other parts of the tree
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mBeginSpecs.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2011-07-02 03:37:10 +00:00
|
|
|
mBeginSpecs[i]->ResolveReferences(aContextNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
count = mEndSpecs.Length();
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t j = 0; j < count; ++j) {
|
2011-07-02 03:37:10 +00:00
|
|
|
mEndSpecs[j]->ResolveReferences(aContextNode);
|
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2010-10-13 00:20:12 +00:00
|
|
|
RegisterMilestone();
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2010-08-18 10:20:24 +00:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::HandleTargetElementChange(Element* aNewTarget)
|
|
|
|
{
|
2011-07-02 03:37:10 +00:00
|
|
|
AutoIntervalUpdateBatcher updateBatcher(*this);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mBeginSpecs.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2010-08-18 10:20:24 +00:00
|
|
|
mBeginSpecs[i]->HandleTargetElementChange(aNewTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
count = mEndSpecs.Length();
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t j = 0; j < count; ++j) {
|
2010-08-18 10:20:24 +00:00
|
|
|
mEndSpecs[j]->HandleTargetElementChange(aNewTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::Traverse(nsCycleCollectionTraversalCallback* aCallback)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mBeginSpecs.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimeValueSpec* beginSpec = mBeginSpecs[i];
|
|
|
|
NS_ABORT_IF_FALSE(beginSpec,
|
|
|
|
"null nsSMILTimeValueSpec in list of begin specs");
|
|
|
|
beginSpec->Traverse(aCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
count = mEndSpecs.Length();
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t j = 0; j < count; ++j) {
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimeValueSpec* endSpec = mEndSpecs[j];
|
|
|
|
NS_ABORT_IF_FALSE(endSpec, "null nsSMILTimeValueSpec in list of end specs");
|
|
|
|
endSpec->Traverse(aCallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::Unlink()
|
|
|
|
{
|
2011-07-02 03:37:10 +00:00
|
|
|
AutoIntervalUpdateBatcher updateBatcher(*this);
|
|
|
|
|
2011-07-25 17:45:49 +00:00
|
|
|
// Remove dependencies on other elements
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mBeginSpecs.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimeValueSpec* beginSpec = mBeginSpecs[i];
|
|
|
|
NS_ABORT_IF_FALSE(beginSpec,
|
|
|
|
"null nsSMILTimeValueSpec in list of begin specs");
|
|
|
|
beginSpec->Unlink();
|
|
|
|
}
|
|
|
|
|
|
|
|
count = mEndSpecs.Length();
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t j = 0; j < count; ++j) {
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimeValueSpec* endSpec = mEndSpecs[j];
|
|
|
|
NS_ABORT_IF_FALSE(endSpec, "null nsSMILTimeValueSpec in list of end specs");
|
|
|
|
endSpec->Unlink();
|
|
|
|
}
|
2011-07-25 17:45:49 +00:00
|
|
|
|
|
|
|
ClearIntervals();
|
|
|
|
|
|
|
|
// Make sure we don't notify other elements of new intervals
|
|
|
|
mTimeDependents.Clear();
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetBeginOrEndSpec(const nsAString& aSpec,
|
2010-08-18 10:20:24 +00:00
|
|
|
Element* aContextNode,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIsBegin,
|
2010-08-18 10:20:24 +00:00
|
|
|
RemovalTestFunction aRemove)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-01-12 20:00:49 +00:00
|
|
|
TimeValueSpecList& timeSpecsList = aIsBegin ? mBeginSpecs : mEndSpecs;
|
2010-08-18 10:20:24 +00:00
|
|
|
InstanceTimeList& instances = aIsBegin ? mBeginInstances : mEndInstances;
|
|
|
|
|
|
|
|
ClearSpecs(timeSpecsList, instances, aRemove);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-07-02 03:37:10 +00:00
|
|
|
AutoIntervalUpdateBatcher updateBatcher(*this);
|
|
|
|
|
2012-02-24 00:45:40 +00:00
|
|
|
nsCharSeparatedTokenizer tokenizer(aSpec, ';');
|
|
|
|
if (!tokenizer.hasMoreTokens()) { // Empty list
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
while (tokenizer.hasMoreTokens() && NS_SUCCEEDED(rv)) {
|
2010-01-12 20:00:49 +00:00
|
|
|
nsAutoPtr<nsSMILTimeValueSpec>
|
|
|
|
spec(new nsSMILTimeValueSpec(*this, aIsBegin));
|
2012-02-24 00:45:40 +00:00
|
|
|
rv = spec->SetSpec(tokenizer.nextToken(), aContextNode);
|
2010-01-12 20:00:49 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
timeSpecsList.AppendElement(spec.forget());
|
|
|
|
}
|
2012-02-24 00:45:40 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2010-08-18 10:20:24 +00:00
|
|
|
ClearSpecs(timeSpecsList, instances, aRemove);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
namespace
|
|
|
|
{
|
2010-08-18 10:20:24 +00:00
|
|
|
// Adaptor functor for RemoveInstanceTimes that allows us to use function
|
|
|
|
// pointers instead.
|
|
|
|
// Without this we'd have to either templatize ClearSpecs and all its callers
|
|
|
|
// or pass bool flags around to specify which removal function to use here.
|
2013-04-12 03:20:09 +00:00
|
|
|
class MOZ_STACK_CLASS RemoveByFunction
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-08-18 10:20:24 +00:00
|
|
|
RemoveByFunction(nsSMILTimedElement::RemovalTestFunction aFunction)
|
|
|
|
: mFunction(aFunction) { }
|
2012-08-22 15:56:38 +00:00
|
|
|
bool operator()(nsSMILInstanceTime* aInstanceTime, uint32_t /*aIndex*/)
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
2010-08-18 10:20:24 +00:00
|
|
|
return mFunction(aInstanceTime);
|
2010-07-03 05:52:50 +00:00
|
|
|
}
|
2010-08-18 10:20:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsSMILTimedElement::RemovalTestFunction mFunction;
|
2010-07-03 05:52:50 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
void
|
2010-08-18 10:20:24 +00:00
|
|
|
nsSMILTimedElement::ClearSpecs(TimeValueSpecList& aSpecs,
|
|
|
|
InstanceTimeList& aInstances,
|
|
|
|
RemovalTestFunction aRemove)
|
2010-01-12 20:00:49 +00:00
|
|
|
{
|
2012-07-15 04:12:53 +00:00
|
|
|
AutoIntervalUpdateBatcher updateBatcher(*this);
|
2012-05-22 23:21:23 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < aSpecs.Length(); ++i) {
|
2012-05-22 23:21:23 +00:00
|
|
|
aSpecs[i]->Unlink();
|
|
|
|
}
|
2010-08-18 10:20:24 +00:00
|
|
|
aSpecs.Clear();
|
2012-05-22 23:21:23 +00:00
|
|
|
|
2010-08-18 10:20:24 +00:00
|
|
|
RemoveByFunction removeByFunction(aRemove);
|
|
|
|
RemoveInstanceTimes(aInstances, removeByFunction);
|
2010-07-03 05:52:50 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 05:52:51 +00:00
|
|
|
void
|
2011-07-25 17:45:49 +00:00
|
|
|
nsSMILTimedElement::ClearIntervals()
|
2010-07-03 05:52:51 +00:00
|
|
|
{
|
2011-09-02 13:15:54 +00:00
|
|
|
if (mElementState != STATE_STARTUP) {
|
|
|
|
mElementState = STATE_POSTACTIVE;
|
|
|
|
}
|
2010-10-13 00:20:12 +00:00
|
|
|
mCurrentRepeatIteration = 0;
|
|
|
|
ResetCurrentInterval();
|
2010-07-03 05:52:51 +00:00
|
|
|
|
2010-10-13 00:20:12 +00:00
|
|
|
// Remove old intervals
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = mOldIntervals.Length() - 1; i >= 0; --i) {
|
2010-07-03 05:52:51 +00:00
|
|
|
mOldIntervals[i]->Unlink();
|
|
|
|
}
|
|
|
|
mOldIntervals.Clear();
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-07-03 05:52:50 +00:00
|
|
|
nsSMILTimedElement::ApplyEarlyEnd(const nsSMILTimeValue& aSampleTime)
|
|
|
|
{
|
|
|
|
// This should only be called within DoSampleAt as a helper function
|
|
|
|
NS_ABORT_IF_FALSE(mElementState == STATE_ACTIVE,
|
|
|
|
"Unexpected state to try to apply an early end");
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool updated = false;
|
2011-06-15 00:16:57 +00:00
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
// Only apply an early end if we're not already ending.
|
|
|
|
if (mCurrentInterval->End()->Time() > aSampleTime) {
|
|
|
|
nsSMILInstanceTime* earlyEnd = CheckForEarlyEnd(aSampleTime);
|
|
|
|
if (earlyEnd) {
|
|
|
|
if (earlyEnd->IsDependent()) {
|
|
|
|
// Generate a new instance time for the early end since the
|
|
|
|
// existing instance time is part of some dependency chain that we
|
|
|
|
// don't want to participate in.
|
|
|
|
nsRefPtr<nsSMILInstanceTime> newEarlyEnd =
|
|
|
|
new nsSMILInstanceTime(earlyEnd->Time());
|
|
|
|
mCurrentInterval->SetEnd(*newEarlyEnd);
|
|
|
|
} else {
|
|
|
|
mCurrentInterval->SetEnd(*earlyEnd);
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
updated = true;
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 00:16:57 +00:00
|
|
|
return updated;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
namespace
|
|
|
|
{
|
2013-04-12 03:20:09 +00:00
|
|
|
class MOZ_STACK_CLASS RemoveReset
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
RemoveReset(const nsSMILInstanceTime* aCurrentIntervalBegin)
|
|
|
|
: mCurrentIntervalBegin(aCurrentIntervalBegin) { }
|
2012-08-22 15:56:38 +00:00
|
|
|
bool operator()(nsSMILInstanceTime* aInstanceTime, uint32_t /*aIndex*/)
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
|
|
|
// SMIL 3.0 section 5.4.3, 'Resetting element state':
|
|
|
|
// Any instance times associated with past Event-values, Repeat-values,
|
|
|
|
// Accesskey-values or added via DOM method calls are removed from the
|
|
|
|
// dependent begin and end instance times lists. In effect, all events
|
|
|
|
// and DOM methods calls in the past are cleared. This does not apply to
|
|
|
|
// an instance time that defines the begin of the current interval.
|
|
|
|
return aInstanceTime->IsDynamic() &&
|
2010-07-03 05:52:51 +00:00
|
|
|
!aInstanceTime->ShouldPreserve() &&
|
2010-07-03 05:52:50 +00:00
|
|
|
(!mCurrentIntervalBegin || aInstanceTime != mCurrentIntervalBegin);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsSMILInstanceTime* mCurrentIntervalBegin;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::Reset()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
RemoveReset resetBegin(mCurrentInterval ? mCurrentInterval->Begin() : nullptr);
|
2010-07-03 05:52:50 +00:00
|
|
|
RemoveInstanceTimes(mBeginInstances, resetBegin);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
RemoveReset resetEnd(nullptr);
|
2010-07-03 05:52:50 +00:00
|
|
|
RemoveInstanceTimes(mEndInstances, resetEnd);
|
|
|
|
}
|
|
|
|
|
2010-07-03 05:52:51 +00:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::DoPostSeek()
|
|
|
|
{
|
|
|
|
// Finish backwards seek
|
|
|
|
if (mSeekState == SEEK_BACKWARD_FROM_INACTIVE ||
|
|
|
|
mSeekState == SEEK_BACKWARD_FROM_ACTIVE) {
|
|
|
|
// Previously some dynamic instance times may have been marked to be
|
|
|
|
// preserved because they were endpoints of an historic interval (which may
|
|
|
|
// or may not have been filtered). Now that we've finished a seek we should
|
|
|
|
// clear that flag for those instance times whose intervals are no longer
|
|
|
|
// historic.
|
|
|
|
UnpreserveInstanceTimes(mBeginInstances);
|
|
|
|
UnpreserveInstanceTimes(mEndInstances);
|
|
|
|
|
|
|
|
// Now that the times have been unmarked perform a reset. This might seem
|
|
|
|
// counter-intuitive when we're only doing a seek within an interval but
|
|
|
|
// SMIL seems to require this. SMIL 3.0, 'Hyperlinks and timing':
|
|
|
|
// Resolved end times associated with events, Repeat-values,
|
|
|
|
// Accesskey-values or added via DOM method calls are cleared when seeking
|
|
|
|
// to time earlier than the resolved end time.
|
|
|
|
Reset();
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
2010-07-31 07:02:52 +00:00
|
|
|
switch (mSeekState)
|
|
|
|
{
|
|
|
|
case SEEK_FORWARD_FROM_ACTIVE:
|
|
|
|
case SEEK_BACKWARD_FROM_ACTIVE:
|
|
|
|
if (mElementState != STATE_ACTIVE) {
|
|
|
|
FireTimeEventAsync(NS_SMIL_END, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEEK_FORWARD_FROM_INACTIVE:
|
|
|
|
case SEEK_BACKWARD_FROM_INACTIVE:
|
|
|
|
if (mElementState == STATE_ACTIVE) {
|
|
|
|
FireTimeEventAsync(NS_SMIL_BEGIN, 0);
|
|
|
|
}
|
|
|
|
break;
|
2010-08-18 10:20:24 +00:00
|
|
|
|
|
|
|
case SEEK_NOT_SEEKING:
|
|
|
|
/* Do nothing */
|
|
|
|
break;
|
2010-07-31 07:02:52 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 05:52:51 +00:00
|
|
|
mSeekState = SEEK_NOT_SEEKING;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnpreserveInstanceTimes(InstanceTimeList& aList)
|
|
|
|
{
|
|
|
|
const nsSMILInterval* prevInterval = GetPreviousInterval();
|
|
|
|
const nsSMILInstanceTime* cutoff = mCurrentInterval ?
|
|
|
|
mCurrentInterval->Begin() :
|
2012-07-30 14:20:58 +00:00
|
|
|
prevInterval ? prevInterval->Begin() : nullptr;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = aList.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2010-07-03 05:52:51 +00:00
|
|
|
nsSMILInstanceTime* instance = aList[i].get();
|
2010-10-13 00:17:55 +00:00
|
|
|
if (!cutoff || cutoff->Time().CompareTo(instance->Time()) < 0) {
|
2010-07-03 05:52:51 +00:00
|
|
|
instance->UnmarkShouldPreserve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-03 05:52:50 +00:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::FilterHistory()
|
|
|
|
{
|
|
|
|
// We should filter the intervals first, since instance times still used in an
|
|
|
|
// interval won't be filtered.
|
|
|
|
FilterIntervals();
|
|
|
|
FilterInstanceTimes(mBeginInstances);
|
|
|
|
FilterInstanceTimes(mEndInstances);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::FilterIntervals()
|
|
|
|
{
|
|
|
|
// We can filter old intervals that:
|
|
|
|
//
|
|
|
|
// a) are not the previous interval; AND
|
2012-05-17 09:56:57 +00:00
|
|
|
// b) are not in the middle of a dependency chain; AND
|
|
|
|
// c) are not the first interval
|
2010-07-03 05:52:50 +00:00
|
|
|
//
|
|
|
|
// Condition (a) is necessary since the previous interval is used for applying
|
|
|
|
// fill effects and updating the current interval.
|
|
|
|
//
|
|
|
|
// Condition (b) is necessary since even if this interval itself is not
|
|
|
|
// active, it may be part of a dependency chain that includes active
|
|
|
|
// intervals. Such chains are used to establish priorities within the
|
|
|
|
// animation sandwich.
|
|
|
|
//
|
2012-05-17 09:56:57 +00:00
|
|
|
// Condition (c) is necessary to support hyperlinks that target animations
|
|
|
|
// since in some cases the defined behavior is to seek the document back to
|
|
|
|
// the first resolved begin time. Presumably the intention here is not
|
|
|
|
// actually to use the first resolved begin time, the
|
|
|
|
// _the_first_resolved_begin_time_that_produced_an_interval. That is,
|
|
|
|
// if we have begin="-5s; -3s; 1s; 3s" with a duration on 1s, we should seek
|
|
|
|
// to 1s. The spec doesn't say this but I'm pretty sure that is the intention.
|
|
|
|
// It seems negative times were simply not considered.
|
|
|
|
//
|
2010-07-03 05:52:50 +00:00
|
|
|
// Although the above conditions allow us to safely filter intervals for most
|
|
|
|
// scenarios they do not cover all cases and there will still be scenarios
|
|
|
|
// that generate intervals indefinitely. In such a case we simply set
|
|
|
|
// a maximum number of intervals and drop any intervals beyond that threshold.
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t threshold = mOldIntervals.Length() > sMaxNumIntervals ?
|
2010-07-03 05:52:50 +00:00
|
|
|
mOldIntervals.Length() - sMaxNumIntervals :
|
|
|
|
0;
|
|
|
|
IntervalList filteredList;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mOldIntervals.Length(); ++i)
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
|
|
|
nsSMILInterval* interval = mOldIntervals[i].get();
|
2012-05-17 09:56:57 +00:00
|
|
|
if (i != 0 && /*skip first interval*/
|
|
|
|
i + 1 < mOldIntervals.Length() && /*skip previous interval*/
|
2010-07-03 05:52:50 +00:00
|
|
|
(i < threshold || !interval->IsDependencyChainLink())) {
|
2011-10-17 14:59:28 +00:00
|
|
|
interval->Unlink(true /*filtered, not deleted*/);
|
2010-07-03 05:52:50 +00:00
|
|
|
} else {
|
|
|
|
filteredList.AppendElement(mOldIntervals[i].forget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mOldIntervals.Clear();
|
|
|
|
mOldIntervals.SwapElements(filteredList);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2013-04-12 03:20:09 +00:00
|
|
|
class MOZ_STACK_CLASS RemoveFiltered
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
RemoveFiltered(nsSMILTimeValue aCutoff) : mCutoff(aCutoff) { }
|
2012-08-22 15:56:38 +00:00
|
|
|
bool operator()(nsSMILInstanceTime* aInstanceTime, uint32_t /*aIndex*/)
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
|
|
|
// We can filter instance times that:
|
|
|
|
// a) Precede the end point of the previous interval; AND
|
|
|
|
// b) Are NOT syncbase times that might be updated to a time after the end
|
|
|
|
// point of the previous interval; AND
|
|
|
|
// c) Are NOT fixed end points in any remaining interval.
|
|
|
|
return aInstanceTime->Time() < mCutoff &&
|
|
|
|
aInstanceTime->IsFixedTime() &&
|
2010-07-03 05:52:51 +00:00
|
|
|
!aInstanceTime->ShouldPreserve();
|
2010-07-03 05:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsSMILTimeValue mCutoff;
|
|
|
|
};
|
|
|
|
|
2013-04-12 03:20:09 +00:00
|
|
|
class MOZ_STACK_CLASS RemoveBelowThreshold
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
RemoveBelowThreshold(uint32_t aThreshold,
|
2011-07-25 17:45:03 +00:00
|
|
|
nsTArray<const nsSMILInstanceTime *>& aTimesToKeep)
|
2010-07-03 05:52:50 +00:00
|
|
|
: mThreshold(aThreshold),
|
2011-07-25 17:45:03 +00:00
|
|
|
mTimesToKeep(aTimesToKeep) { }
|
2012-08-22 15:56:38 +00:00
|
|
|
bool operator()(nsSMILInstanceTime* aInstanceTime, uint32_t aIndex)
|
2010-07-03 05:52:50 +00:00
|
|
|
{
|
2011-07-25 17:45:03 +00:00
|
|
|
return aIndex < mThreshold && !mTimesToKeep.Contains(aInstanceTime);
|
2010-07-03 05:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mThreshold;
|
2011-07-25 17:45:03 +00:00
|
|
|
nsTArray<const nsSMILInstanceTime *>& mTimesToKeep;
|
2010-07-03 05:52:50 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::FilterInstanceTimes(InstanceTimeList& aList)
|
|
|
|
{
|
|
|
|
if (GetPreviousInterval()) {
|
|
|
|
RemoveFiltered removeFiltered(GetPreviousInterval()->End()->Time());
|
|
|
|
RemoveInstanceTimes(aList, removeFiltered);
|
|
|
|
}
|
|
|
|
|
|
|
|
// As with intervals it is possible to create a document that, even despite
|
|
|
|
// our most aggressive filtering, will generate instance times indefinitely
|
|
|
|
// (e.g. cyclic dependencies with TimeEvents---we can't filter such times as
|
|
|
|
// they're unpredictable due to the possibility of seeking the document which
|
|
|
|
// may prevent some events from being generated). Therefore we introduce
|
|
|
|
// a hard cutoff at which point we just drop the oldest instance times.
|
|
|
|
if (aList.Length() > sMaxNumInstanceTimes) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t threshold = aList.Length() - sMaxNumInstanceTimes;
|
2011-07-25 17:45:03 +00:00
|
|
|
// There are a few instance times we should keep though, notably:
|
|
|
|
// - the current interval begin time,
|
|
|
|
// - the previous interval end time (see note in RemoveInstanceTimes)
|
2012-05-17 09:56:57 +00:00
|
|
|
// - the first interval begin time (see note in FilterIntervals)
|
2011-07-25 17:45:03 +00:00
|
|
|
nsTArray<const nsSMILInstanceTime *> timesToKeep;
|
|
|
|
if (mCurrentInterval) {
|
|
|
|
timesToKeep.AppendElement(mCurrentInterval->Begin());
|
|
|
|
}
|
|
|
|
const nsSMILInterval* prevInterval = GetPreviousInterval();
|
|
|
|
if (prevInterval) {
|
|
|
|
timesToKeep.AppendElement(prevInterval->End());
|
|
|
|
}
|
2012-05-17 09:56:57 +00:00
|
|
|
if (!mOldIntervals.IsEmpty()) {
|
|
|
|
timesToKeep.AppendElement(mOldIntervals[0]->Begin());
|
|
|
|
}
|
2011-07-25 17:45:03 +00:00
|
|
|
RemoveBelowThreshold removeBelowThreshold(threshold, timesToKeep);
|
2010-07-03 05:52:50 +00:00
|
|
|
RemoveInstanceTimes(aList, removeBelowThreshold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
//
|
|
|
|
// This method is based on the pseudocode given in the SMILANIM spec.
|
|
|
|
//
|
|
|
|
// See:
|
|
|
|
// http://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-BeginEnd-LC-Start
|
|
|
|
//
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-08-05 02:39:04 +00:00
|
|
|
nsSMILTimedElement::GetNextInterval(const nsSMILInterval* aPrevInterval,
|
2011-06-22 01:12:35 +00:00
|
|
|
const nsSMILInterval* aReplacedInterval,
|
2010-01-12 20:00:49 +00:00
|
|
|
const nsSMILInstanceTime* aFixedBeginTime,
|
2010-03-01 19:31:52 +00:00
|
|
|
nsSMILInterval& aResult) const
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2011-09-07 00:20:40 +00:00
|
|
|
NS_ABORT_IF_FALSE(!aFixedBeginTime || aFixedBeginTime->Time().IsDefinite(),
|
2011-09-07 00:20:40 +00:00
|
|
|
"Unresolved or indefinite begin time specified for interval start");
|
2011-03-27 23:10:33 +00:00
|
|
|
static const nsSMILTimeValue zeroTime(0L);
|
2009-07-15 18:33:31 +00:00
|
|
|
|
2010-03-01 19:31:50 +00:00
|
|
|
if (mRestartMode == RESTART_NEVER && aPrevInterval)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2009-08-05 02:39:04 +00:00
|
|
|
// Calc starting point
|
|
|
|
nsSMILTimeValue beginAfter;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool prevIntervalWasZeroDur = false;
|
2010-03-01 19:31:50 +00:00
|
|
|
if (aPrevInterval) {
|
2010-01-12 20:00:49 +00:00
|
|
|
beginAfter = aPrevInterval->End()->Time();
|
|
|
|
prevIntervalWasZeroDur
|
|
|
|
= aPrevInterval->End()->Time() == aPrevInterval->Begin()->Time();
|
2009-08-05 02:39:04 +00:00
|
|
|
} else {
|
2012-09-28 19:55:23 +00:00
|
|
|
beginAfter.SetMillis(INT64_MIN);
|
2009-08-05 02:39:04 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
nsRefPtr<nsSMILInstanceTime> tempBegin;
|
|
|
|
nsRefPtr<nsSMILInstanceTime> tempEnd;
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
while (true) {
|
2010-01-13 08:18:51 +00:00
|
|
|
// Calculate begin time
|
2010-01-12 20:00:49 +00:00
|
|
|
if (aFixedBeginTime) {
|
2011-03-27 23:10:33 +00:00
|
|
|
if (aFixedBeginTime->Time() < beginAfter) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-03-27 23:10:33 +00:00
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
// our ref-counting is not const-correct
|
|
|
|
tempBegin = const_cast<nsSMILInstanceTime*>(aFixedBeginTime);
|
2010-08-18 10:20:24 +00:00
|
|
|
} else if ((!mAnimationElement ||
|
|
|
|
!mAnimationElement->HasAnimAttr(nsGkAtoms::begin)) &&
|
|
|
|
beginAfter <= zeroTime) {
|
2010-03-01 19:31:50 +00:00
|
|
|
tempBegin = new nsSMILInstanceTime(nsSMILTimeValue(0));
|
2009-01-15 04:38:07 +00:00
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t beginPos = 0;
|
2011-06-22 01:12:35 +00:00
|
|
|
do {
|
|
|
|
tempBegin =
|
|
|
|
GetNextGreaterOrEqual(mBeginInstances, beginAfter, beginPos);
|
2011-09-07 00:20:40 +00:00
|
|
|
if (!tempBegin || !tempBegin->Time().IsDefinite()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-06-22 01:12:35 +00:00
|
|
|
}
|
2011-11-14 03:58:30 +00:00
|
|
|
// If we're updating the current interval then skip any begin time that is
|
|
|
|
// dependent on the current interval's begin time. e.g.
|
|
|
|
// <animate id="a" begin="b.begin; a.begin+2s"...
|
|
|
|
// If b's interval disappears whilst 'a' is in the waiting state the begin
|
|
|
|
// time at "a.begin+2s" should be skipped since 'a' never begun.
|
2011-06-22 01:12:35 +00:00
|
|
|
} while (aReplacedInterval &&
|
|
|
|
tempBegin->GetBaseTime() == aReplacedInterval->Begin());
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2011-09-07 00:20:40 +00:00
|
|
|
NS_ABORT_IF_FALSE(tempBegin && tempBegin->Time().IsDefinite() &&
|
2010-05-21 00:18:29 +00:00
|
|
|
tempBegin->Time() >= beginAfter,
|
2010-01-12 20:00:49 +00:00
|
|
|
"Got a bad begin time while fetching next interval");
|
|
|
|
|
2010-01-13 08:18:51 +00:00
|
|
|
// Calculate end time
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t endPos = 0;
|
2011-06-22 01:12:35 +00:00
|
|
|
do {
|
|
|
|
tempEnd =
|
|
|
|
GetNextGreaterOrEqual(mEndInstances, tempBegin->Time(), endPos);
|
2011-11-14 03:58:30 +00:00
|
|
|
|
|
|
|
// SMIL doesn't allow for coincident zero-duration intervals, so if the
|
|
|
|
// previous interval was zero-duration, and tempEnd is going to give us
|
|
|
|
// another zero duration interval, then look for another end to use
|
|
|
|
// instead.
|
|
|
|
if (tempEnd && prevIntervalWasZeroDur &&
|
|
|
|
tempEnd->Time() == beginAfter) {
|
|
|
|
tempEnd = GetNextGreater(mEndInstances, tempBegin->Time(), endPos);
|
|
|
|
}
|
|
|
|
// As above with begin times, avoid creating self-referential loops
|
|
|
|
// between instance times by checking that the newly found end instance
|
|
|
|
// time is not already dependent on the end of the current interval.
|
2011-06-22 01:12:35 +00:00
|
|
|
} while (tempEnd && aReplacedInterval &&
|
|
|
|
tempEnd->GetBaseTime() == aReplacedInterval->End());
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-11-14 03:58:30 +00:00
|
|
|
if (!tempEnd) {
|
|
|
|
// If all the ends are before the beginning we have a bad interval
|
|
|
|
// UNLESS:
|
|
|
|
// a) We never had any end attribute to begin with (the SMIL pseudocode
|
|
|
|
// places this condition earlier in the flow but that fails to allow
|
|
|
|
// for DOM calls when no "indefinite" condition is given), OR
|
|
|
|
// b) We never had any end instance times to begin with, OR
|
|
|
|
// c) We have end events which leave the interval open-ended.
|
|
|
|
bool openEndedIntervalOk = mEndSpecs.IsEmpty() ||
|
|
|
|
mEndInstances.IsEmpty() ||
|
|
|
|
EndHasEventConditions();
|
|
|
|
|
|
|
|
// The above conditions correspond with the SMIL pseudocode but SMIL
|
|
|
|
// doesn't address self-dependent instance times which we choose to
|
|
|
|
// ignore.
|
|
|
|
//
|
|
|
|
// Therefore we add a qualification of (b) above that even if
|
|
|
|
// there are end instance times but they all depend on the end of the
|
|
|
|
// current interval we should act as if they didn't exist and allow the
|
|
|
|
// open-ended interval.
|
|
|
|
//
|
|
|
|
// In the following condition we don't use |= because it doesn't provide
|
|
|
|
// short-circuit behavior.
|
|
|
|
openEndedIntervalOk = openEndedIntervalOk ||
|
|
|
|
(aReplacedInterval &&
|
|
|
|
AreEndTimesDependentOn(aReplacedInterval->End()));
|
|
|
|
|
|
|
|
if (!openEndedIntervalOk) {
|
|
|
|
return false; // Bad interval
|
|
|
|
}
|
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
nsSMILTimeValue intervalEnd = tempEnd
|
|
|
|
? tempEnd->Time() : nsSMILTimeValue();
|
|
|
|
nsSMILTimeValue activeEnd = CalcActiveEnd(tempBegin->Time(), intervalEnd);
|
|
|
|
|
|
|
|
if (!tempEnd || intervalEnd != activeEnd) {
|
2010-03-01 19:31:50 +00:00
|
|
|
tempEnd = new nsSMILInstanceTime(activeEnd);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
NS_ABORT_IF_FALSE(tempEnd, "Failed to get end point for next interval");
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-11-14 03:58:30 +00:00
|
|
|
// When we choose the interval endpoints, we don't allow coincident
|
|
|
|
// zero-duration intervals, so if we arrive here and we have a zero-duration
|
|
|
|
// interval starting at the same point as a previous zero-duration interval,
|
|
|
|
// then it must be because we've applied constraints to the active duration.
|
|
|
|
// In that case, we will potentially run into an infinite loop, so we break
|
|
|
|
// it by searching for the next interval that starts AFTER our current
|
|
|
|
// zero-duration interval.
|
|
|
|
if (prevIntervalWasZeroDur && tempEnd->Time() == beginAfter) {
|
2009-08-05 02:39:04 +00:00
|
|
|
if (prevIntervalWasZeroDur) {
|
2011-11-14 03:58:30 +00:00
|
|
|
beginAfter.SetMillis(tempBegin->Time().GetMillis() + 1);
|
2011-10-17 14:59:28 +00:00
|
|
|
prevIntervalWasZeroDur = false;
|
2009-08-05 02:39:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-11-14 03:58:30 +00:00
|
|
|
prevIntervalWasZeroDur = tempBegin->Time() == tempEnd->Time();
|
2009-08-05 02:39:04 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
// Check for valid interval
|
|
|
|
if (tempEnd->Time() > zeroTime ||
|
|
|
|
(tempBegin->Time() == zeroTime && tempEnd->Time() == zeroTime)) {
|
|
|
|
aResult.Set(*tempBegin, *tempEnd);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
2010-01-28 09:51:03 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
if (mRestartMode == RESTART_NEVER) {
|
2009-08-05 02:39:04 +00:00
|
|
|
// tempEnd <= 0 so we're going to loop which effectively means restarting
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
beginAfter = tempEnd->Time();
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
NS_NOTREACHED("Hmm... we really shouldn't be here");
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILInstanceTime*
|
|
|
|
nsSMILTimedElement::GetNextGreater(const InstanceTimeList& aList,
|
|
|
|
const nsSMILTimeValue& aBase,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t& aPosition) const
|
2009-08-05 02:39:04 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
nsSMILInstanceTime* result = nullptr;
|
2010-01-12 20:00:49 +00:00
|
|
|
while ((result = GetNextGreaterOrEqual(aList, aBase, aPosition)) &&
|
2012-03-22 05:21:16 +00:00
|
|
|
result->Time() == aBase) { }
|
2010-01-12 20:00:49 +00:00
|
|
|
return result;
|
2009-08-05 02:39:04 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILInstanceTime*
|
|
|
|
nsSMILTimedElement::GetNextGreaterOrEqual(const InstanceTimeList& aList,
|
|
|
|
const nsSMILTimeValue& aBase,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t& aPosition) const
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
nsSMILInstanceTime* result = nullptr;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t count = aList.Length();
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
for (; aPosition < count && !result; ++aPosition) {
|
|
|
|
nsSMILInstanceTime* val = aList[aPosition].get();
|
|
|
|
NS_ABORT_IF_FALSE(val, "NULL instance time in list");
|
|
|
|
if (val->Time() >= aBase) {
|
|
|
|
result = val;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
return result;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see SMILANIM 3.3.4
|
|
|
|
*/
|
|
|
|
nsSMILTimeValue
|
|
|
|
nsSMILTimedElement::CalcActiveEnd(const nsSMILTimeValue& aBegin,
|
2010-01-12 20:00:49 +00:00
|
|
|
const nsSMILTimeValue& aEnd) const
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
|
|
|
nsSMILTimeValue result;
|
|
|
|
|
2011-09-07 00:20:40 +00:00
|
|
|
NS_ABORT_IF_FALSE(mSimpleDur.IsResolved(),
|
2010-01-28 09:50:30 +00:00
|
|
|
"Unresolved simple duration in CalcActiveEnd");
|
2011-09-07 00:20:40 +00:00
|
|
|
NS_ABORT_IF_FALSE(aBegin.IsDefinite(),
|
2011-09-07 00:20:40 +00:00
|
|
|
"Indefinite or unresolved begin time in CalcActiveEnd");
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2013-12-13 04:41:47 +00:00
|
|
|
result = GetRepeatDuration();
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-09-07 00:20:40 +00:00
|
|
|
if (aEnd.IsDefinite()) {
|
2009-01-15 04:38:07 +00:00
|
|
|
nsSMILTime activeDur = aEnd.GetMillis() - aBegin.GetMillis();
|
|
|
|
|
2011-09-07 00:20:40 +00:00
|
|
|
if (result.IsDefinite()) {
|
2013-01-15 12:22:03 +00:00
|
|
|
result.SetMillis(std::min(result.GetMillis(), activeDur));
|
2009-01-15 04:38:07 +00:00
|
|
|
} else {
|
|
|
|
result.SetMillis(activeDur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ApplyMinAndMax(result);
|
|
|
|
|
2011-09-07 00:20:40 +00:00
|
|
|
if (result.IsDefinite()) {
|
2009-01-15 04:38:07 +00:00
|
|
|
nsSMILTime activeEnd = result.GetMillis() + aBegin.GetMillis();
|
|
|
|
result.SetMillis(activeEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimeValue
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::GetRepeatDuration() const
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2013-12-13 04:41:47 +00:00
|
|
|
nsSMILTimeValue multipliedDuration;
|
|
|
|
if (mRepeatCount.IsDefinite() && mSimpleDur.IsDefinite()) {
|
|
|
|
multipliedDuration.SetMillis(
|
|
|
|
nsSMILTime(mRepeatCount * double(mSimpleDur.GetMillis())));
|
|
|
|
} else {
|
|
|
|
multipliedDuration.SetIndefinite();
|
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2013-12-13 04:41:47 +00:00
|
|
|
nsSMILTimeValue repeatDuration;
|
|
|
|
|
|
|
|
if (mRepeatDur.IsResolved()) {
|
|
|
|
repeatDuration = std::min(multipliedDuration, mRepeatDur);
|
|
|
|
} else if (mRepeatCount.IsSet()) {
|
|
|
|
repeatDuration = multipliedDuration;
|
2009-01-15 04:38:07 +00:00
|
|
|
} else {
|
2013-12-13 04:41:47 +00:00
|
|
|
repeatDuration = mSimpleDur;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 04:41:47 +00:00
|
|
|
return repeatDuration;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimeValue
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::ApplyMinAndMax(const nsSMILTimeValue& aDuration) const
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2011-09-07 00:20:40 +00:00
|
|
|
if (!aDuration.IsResolved()) {
|
2009-01-15 04:38:07 +00:00
|
|
|
return aDuration;
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
if (mMax < mMin) {
|
2009-01-15 04:38:07 +00:00
|
|
|
return aDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimeValue result;
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
if (aDuration > mMax) {
|
2009-01-15 04:38:07 +00:00
|
|
|
result = mMax;
|
2010-01-12 20:00:49 +00:00
|
|
|
} else if (aDuration < mMin) {
|
2013-12-13 04:41:52 +00:00
|
|
|
result = mMin;
|
2009-01-15 04:38:07 +00:00
|
|
|
} else {
|
|
|
|
result = aDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTime
|
|
|
|
nsSMILTimedElement::ActiveTimeToSimpleTime(nsSMILTime aActiveTime,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t& aRepeatIteration)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
|
|
|
nsSMILTime result;
|
|
|
|
|
2011-11-15 19:56:32 +00:00
|
|
|
NS_ABORT_IF_FALSE(mSimpleDur.IsResolved(),
|
2009-01-19 09:10:53 +00:00
|
|
|
"Unresolved simple duration in ActiveTimeToSimpleTime");
|
2011-11-15 19:56:32 +00:00
|
|
|
NS_ABORT_IF_FALSE(aActiveTime >= 0, "Expecting non-negative active time");
|
2010-07-03 05:52:51 +00:00
|
|
|
// Note that a negative aActiveTime will give us a negative value for
|
|
|
|
// aRepeatIteration, which is bad because aRepeatIteration is unsigned
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
if (mSimpleDur.IsIndefinite() || mSimpleDur.GetMillis() == 0L) {
|
|
|
|
aRepeatIteration = 0;
|
|
|
|
result = aActiveTime;
|
2009-07-15 18:33:31 +00:00
|
|
|
} else {
|
2009-01-15 04:38:07 +00:00
|
|
|
result = aActiveTime % mSimpleDur.GetMillis();
|
2012-08-22 15:56:38 +00:00
|
|
|
aRepeatIteration = (uint32_t)(aActiveTime / mSimpleDur.GetMillis());
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Although in many cases it would be possible to check for an early end and
|
|
|
|
// adjust the current interval well in advance the SMIL Animation spec seems to
|
|
|
|
// indicate that we should only apply an early end at the latest possible
|
|
|
|
// moment. In particular, this paragraph from section 3.6.8:
|
|
|
|
//
|
|
|
|
// 'If restart is set to "always", then the current interval will end early if
|
|
|
|
// there is an instance time in the begin list that is before (i.e. earlier
|
|
|
|
// than) the defined end for the current interval. Ending in this manner will
|
|
|
|
// also send a changed time notice to all time dependents for the current
|
|
|
|
// interval end.'
|
|
|
|
//
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILInstanceTime*
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::CheckForEarlyEnd(
|
|
|
|
const nsSMILTimeValue& aContainerTime) const
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-03-01 19:31:50 +00:00
|
|
|
NS_ABORT_IF_FALSE(mCurrentInterval,
|
2010-01-12 20:00:49 +00:00
|
|
|
"Checking for an early end but the current interval is not set");
|
2009-01-15 04:38:07 +00:00
|
|
|
if (mRestartMode != RESTART_ALWAYS)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t position = 0;
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILInstanceTime* nextBegin =
|
2010-03-01 19:31:50 +00:00
|
|
|
GetNextGreater(mBeginInstances, mCurrentInterval->Begin()->Time(),
|
|
|
|
position);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
if (nextBegin &&
|
2010-03-01 19:31:50 +00:00
|
|
|
nextBegin->Time() > mCurrentInterval->Begin()->Time() &&
|
|
|
|
nextBegin->Time() < mCurrentInterval->End()->Time() &&
|
2010-01-12 20:00:49 +00:00
|
|
|
nextBegin->Time() <= aContainerTime) {
|
2010-01-12 20:00:49 +00:00
|
|
|
return nextBegin;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsSMILTimedElement::UpdateCurrentInterval(bool aForceChangeNotice)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2011-07-02 03:37:10 +00:00
|
|
|
// Check if updates are currently blocked (batched)
|
|
|
|
if (mDeferIntervalUpdates) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mDoDeferredUpdate = true;
|
2011-07-02 03:37:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
// We adopt the convention of not resolving intervals until the first
|
|
|
|
// sample. Otherwise, every time each attribute is set we'll re-resolve the
|
|
|
|
// current interval and notify all our time dependents of the change.
|
2010-01-12 20:00:49 +00:00
|
|
|
//
|
|
|
|
// The disadvantage of deferring resolving the interval is that DOM calls to
|
|
|
|
// to getStartTime will throw an INVALID_STATE_ERR exception until the
|
2010-01-12 20:00:49 +00:00
|
|
|
// document timeline begins since the start time has not yet been resolved.
|
2010-01-12 20:00:49 +00:00
|
|
|
if (mElementState == STATE_STARTUP)
|
|
|
|
return;
|
|
|
|
|
2012-02-01 23:58:58 +00:00
|
|
|
// Although SMIL gives rules for detecting cycles in change notifications,
|
|
|
|
// some configurations can lead to create-delete-create-delete-etc. cycles
|
|
|
|
// which SMIL does not consider.
|
|
|
|
//
|
|
|
|
// In order to provide consistent behavior in such cases, we detect two
|
|
|
|
// deletes in a row and then refuse to create any further intervals. That is,
|
|
|
|
// we say the configuration is invalid.
|
|
|
|
if (mDeleteCount > 1) {
|
|
|
|
// When we update the delete count we also set the state to post active, so
|
|
|
|
// if we're not post active here then something other than
|
|
|
|
// UpdateCurrentInterval has updated the element state in between and all
|
|
|
|
// bets are off.
|
|
|
|
NS_ABORT_IF_FALSE(mElementState == STATE_POSTACTIVE,
|
|
|
|
"Expected to be in post-active state after performing double delete");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-02 03:37:47 +00:00
|
|
|
// Check that we aren't stuck in infinite recursion updating some syncbase
|
|
|
|
// dependencies. Generally such situations should be detected in advance and
|
|
|
|
// the chain broken in a sensible and predictable manner, so if we're hitting
|
|
|
|
// this assertion we need to work out how to detect the case that's causing
|
|
|
|
// it. In release builds, just bail out before we overflow the stack.
|
2012-08-22 15:56:38 +00:00
|
|
|
AutoRestore<uint8_t> depthRestorer(mUpdateIntervalRecursionDepth);
|
2011-07-02 03:37:47 +00:00
|
|
|
if (++mUpdateIntervalRecursionDepth > sMaxUpdateIntervalRecursionDepth) {
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ABORT_IF_FALSE(false,
|
2011-07-02 03:37:47 +00:00
|
|
|
"Update current interval recursion depth exceeded threshold");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
// If the interval is active the begin time is fixed.
|
|
|
|
const nsSMILInstanceTime* beginTime = mElementState == STATE_ACTIVE
|
2010-03-01 19:31:50 +00:00
|
|
|
? mCurrentInterval->Begin()
|
2012-07-30 14:20:58 +00:00
|
|
|
: nullptr;
|
2009-01-15 04:38:07 +00:00
|
|
|
nsSMILInterval updatedInterval;
|
2011-06-22 01:12:35 +00:00
|
|
|
if (GetNextInterval(GetPreviousInterval(), mCurrentInterval,
|
|
|
|
beginTime, updatedInterval)) {
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
if (mElementState == STATE_POSTACTIVE) {
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-03-01 19:31:50 +00:00
|
|
|
NS_ABORT_IF_FALSE(!mCurrentInterval,
|
2010-01-12 20:00:49 +00:00
|
|
|
"In postactive state but the interval has been set");
|
2010-03-01 19:31:50 +00:00
|
|
|
mCurrentInterval = new nsSMILInterval(updatedInterval);
|
2010-01-12 20:00:49 +00:00
|
|
|
mElementState = STATE_WAITING;
|
|
|
|
NotifyNewInterval();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool beginChanged = false;
|
|
|
|
bool endChanged = false;
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
if (mElementState != STATE_ACTIVE &&
|
2010-03-01 19:31:50 +00:00
|
|
|
!updatedInterval.Begin()->SameTimeAndBase(
|
|
|
|
*mCurrentInterval->Begin())) {
|
|
|
|
mCurrentInterval->SetBegin(*updatedInterval.Begin());
|
2011-10-17 14:59:28 +00:00
|
|
|
beginChanged = true;
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 19:31:50 +00:00
|
|
|
if (!updatedInterval.End()->SameTimeAndBase(*mCurrentInterval->End())) {
|
|
|
|
mCurrentInterval->SetEnd(*updatedInterval.End());
|
2011-10-17 14:59:28 +00:00
|
|
|
endChanged = true;
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 00:16:57 +00:00
|
|
|
if (beginChanged || endChanged || aForceChangeNotice) {
|
|
|
|
NotifyChangedInterval(mCurrentInterval, beginChanged, endChanged);
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
2010-10-19 23:55:09 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
// There's a chance our next milestone has now changed, so update the time
|
|
|
|
// container
|
|
|
|
RegisterMilestone();
|
2010-10-19 23:55:09 +00:00
|
|
|
} else { // GetNextInterval failed: Current interval is no longer valid
|
|
|
|
if (mElementState == STATE_ACTIVE) {
|
|
|
|
// The interval is active so we can't just delete it, instead trim it so
|
|
|
|
// that begin==end.
|
|
|
|
if (!mCurrentInterval->End()->SameTimeAndBase(*mCurrentInterval->Begin()))
|
|
|
|
{
|
|
|
|
mCurrentInterval->SetEnd(*mCurrentInterval->Begin());
|
2011-10-17 14:59:28 +00:00
|
|
|
NotifyChangedInterval(mCurrentInterval, false, true);
|
2010-10-19 23:55:09 +00:00
|
|
|
}
|
|
|
|
// The transition to the postactive state will take place on the next
|
|
|
|
// sample (along with firing end events, clearing intervals etc.)
|
|
|
|
RegisterMilestone();
|
|
|
|
} else if (mElementState == STATE_WAITING) {
|
2012-08-22 15:56:38 +00:00
|
|
|
AutoRestore<uint8_t> deleteCountRestorer(mDeleteCount);
|
2012-02-01 23:58:58 +00:00
|
|
|
++mDeleteCount;
|
2009-01-15 04:38:07 +00:00
|
|
|
mElementState = STATE_POSTACTIVE;
|
2010-10-13 00:20:12 +00:00
|
|
|
ResetCurrentInterval();
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::SampleSimpleTime(nsSMILTime aActiveTime)
|
|
|
|
{
|
|
|
|
if (mClient) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t repeatIteration;
|
2009-07-15 18:33:31 +00:00
|
|
|
nsSMILTime simpleTime =
|
2009-01-15 04:38:07 +00:00
|
|
|
ActiveTimeToSimpleTime(aActiveTime, repeatIteration);
|
|
|
|
mClient->SampleAt(simpleTime, mSimpleDur, repeatIteration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::SampleFillValue()
|
|
|
|
{
|
2010-03-01 19:31:50 +00:00
|
|
|
if (mFillMode != FILL_FREEZE || !mClient)
|
2009-01-15 04:38:07 +00:00
|
|
|
return;
|
|
|
|
|
2013-12-13 04:41:52 +00:00
|
|
|
nsSMILTime activeTime;
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2013-12-13 04:41:52 +00:00
|
|
|
if (mElementState == STATE_WAITING || mElementState == STATE_POSTACTIVE) {
|
|
|
|
const nsSMILInterval* prevInterval = GetPreviousInterval();
|
|
|
|
NS_ABORT_IF_FALSE(prevInterval,
|
|
|
|
"Attempting to sample fill value but there is no previous interval");
|
|
|
|
NS_ABORT_IF_FALSE(prevInterval->End()->Time().IsDefinite() &&
|
|
|
|
prevInterval->End()->IsFixedTime(),
|
|
|
|
"Attempting to sample fill value but the endpoint of the previous "
|
|
|
|
"interval is not resolved and fixed");
|
|
|
|
|
|
|
|
activeTime = prevInterval->End()->Time().GetMillis() -
|
|
|
|
prevInterval->Begin()->Time().GetMillis();
|
|
|
|
|
|
|
|
// If the interval's repeat duration was shorter than its active duration,
|
|
|
|
// use the end of the repeat duration to determine the frozen animation's
|
|
|
|
// state.
|
|
|
|
nsSMILTimeValue repeatDuration = GetRepeatDuration();
|
|
|
|
if (repeatDuration.IsDefinite()) {
|
|
|
|
activeTime = std::min(repeatDuration.GetMillis(), activeTime);
|
|
|
|
}
|
2013-12-19 05:08:03 +00:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mElementState == STATE_ACTIVE,
|
|
|
|
"Attempting to sample fill value when we're in an unexpected state "
|
|
|
|
"(probably STATE_STARTUP)");
|
|
|
|
|
2013-12-13 04:41:52 +00:00
|
|
|
// If we are being asked to sample the fill value while active we *must*
|
|
|
|
// have a repeat duration shorter than the active duration so use that.
|
|
|
|
MOZ_ASSERT(GetRepeatDuration().IsDefinite(),
|
|
|
|
"Attempting to sample fill value of an active animation with "
|
|
|
|
"an indefinite repeat duration");
|
|
|
|
activeTime = GetRepeatDuration().GetMillis();
|
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t repeatIteration;
|
2009-07-15 18:33:31 +00:00
|
|
|
nsSMILTime simpleTime =
|
2009-01-15 04:38:07 +00:00
|
|
|
ActiveTimeToSimpleTime(activeTime, repeatIteration);
|
|
|
|
|
2009-08-05 02:39:04 +00:00
|
|
|
if (simpleTime == 0L && repeatIteration) {
|
2009-01-15 04:38:07 +00:00
|
|
|
mClient->SampleLastValue(--repeatIteration);
|
|
|
|
} else {
|
|
|
|
mClient->SampleAt(simpleTime, mSimpleDur, repeatIteration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-25 17:46:08 +00:00
|
|
|
nsresult
|
2009-01-22 01:00:27 +00:00
|
|
|
nsSMILTimedElement::AddInstanceTimeFromCurrentTime(nsSMILTime aCurrentTime,
|
2011-09-29 06:19:26 +00:00
|
|
|
double aOffsetSeconds, bool aIsBegin)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
|
|
|
double offset = aOffsetSeconds * PR_MSEC_PER_SEC;
|
|
|
|
|
2011-07-25 17:46:08 +00:00
|
|
|
// Check we won't overflow the range of nsSMILTime
|
2012-09-28 19:55:23 +00:00
|
|
|
if (aCurrentTime + NS_round(offset) > INT64_MAX)
|
2011-07-25 17:46:08 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSMILTimeValue timeVal(aCurrentTime + int64_t(NS_round(offset)));
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
nsRefPtr<nsSMILInstanceTime> instanceTime =
|
2010-03-01 19:31:50 +00:00
|
|
|
new nsSMILInstanceTime(timeVal, nsSMILInstanceTime::SOURCE_DOM);
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
AddInstanceTime(instanceTime, aIsBegin);
|
2011-07-25 17:46:08 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::RegisterMilestone()
|
|
|
|
{
|
|
|
|
nsSMILTimeContainer* container = GetTimeContainer();
|
|
|
|
if (!container)
|
|
|
|
return;
|
|
|
|
NS_ABORT_IF_FALSE(mAnimationElement,
|
|
|
|
"Got a time container without an owning animation element");
|
|
|
|
|
|
|
|
nsSMILMilestone nextMilestone;
|
|
|
|
if (!GetNextMilestone(nextMilestone))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// This method is called every time we might possibly have updated our
|
|
|
|
// current interval, but since nsSMILTimeContainer makes no attempt to filter
|
|
|
|
// out redundant milestones we do some rudimentary filtering here. It's not
|
|
|
|
// perfect, but unnecessary samples are fairly cheap.
|
|
|
|
if (nextMilestone >= mPrevRegisteredMilestone)
|
|
|
|
return;
|
|
|
|
|
|
|
|
container->AddMilestone(nextMilestone, *mAnimationElement);
|
|
|
|
mPrevRegisteredMilestone = nextMilestone;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::GetNextMilestone(nsSMILMilestone& aNextMilestone) const
|
|
|
|
{
|
|
|
|
// Return the next key moment in our lifetime.
|
|
|
|
//
|
|
|
|
// XXX It may be possible in future to optimise this so that we only register
|
|
|
|
// for milestones if:
|
|
|
|
// a) We have time dependents, or
|
|
|
|
// b) We are dependent on events or syncbase relationships, or
|
|
|
|
// c) There are registered listeners for our events
|
|
|
|
//
|
|
|
|
// Then for the simple case where everything uses offset values we could
|
|
|
|
// ignore milestones altogether.
|
|
|
|
//
|
|
|
|
// We'd need to be careful, however, that if one of those conditions became
|
|
|
|
// true in between samples that we registered our next milestone at that
|
|
|
|
// point.
|
|
|
|
|
|
|
|
switch (mElementState)
|
|
|
|
{
|
|
|
|
case STATE_STARTUP:
|
|
|
|
// All elements register for an initial end sample at t=0 where we resolve
|
|
|
|
// our initial interval.
|
2011-10-17 14:59:28 +00:00
|
|
|
aNextMilestone.mIsEnd = true; // Initial sample should be an end sample
|
2010-01-12 20:00:49 +00:00
|
|
|
aNextMilestone.mTime = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
case STATE_WAITING:
|
2010-03-01 19:31:50 +00:00
|
|
|
NS_ABORT_IF_FALSE(mCurrentInterval,
|
2010-01-12 20:00:49 +00:00
|
|
|
"In waiting state but the current interval has not been set");
|
2011-10-17 14:59:28 +00:00
|
|
|
aNextMilestone.mIsEnd = false;
|
2010-03-01 19:31:50 +00:00
|
|
|
aNextMilestone.mTime = mCurrentInterval->Begin()->Time().GetMillis();
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
case STATE_ACTIVE:
|
|
|
|
{
|
2010-07-31 07:02:52 +00:00
|
|
|
// Work out what comes next: the interval end or the next repeat iteration
|
|
|
|
nsSMILTimeValue nextRepeat;
|
2011-09-07 00:20:40 +00:00
|
|
|
if (mSeekState == SEEK_NOT_SEEKING && mSimpleDur.IsDefinite()) {
|
2013-12-13 04:41:52 +00:00
|
|
|
nsSMILTime nextRepeatActiveTime =
|
|
|
|
(mCurrentRepeatIteration + 1) * mSimpleDur.GetMillis();
|
|
|
|
// Check that the repeat fits within the repeat duration
|
|
|
|
if (nsSMILTimeValue(nextRepeatActiveTime) < GetRepeatDuration()) {
|
|
|
|
nextRepeat.SetMillis(mCurrentInterval->Begin()->Time().GetMillis() +
|
|
|
|
nextRepeatActiveTime);
|
|
|
|
}
|
2010-07-31 07:02:52 +00:00
|
|
|
}
|
|
|
|
nsSMILTimeValue nextMilestone =
|
2013-01-15 12:22:03 +00:00
|
|
|
std::min(mCurrentInterval->End()->Time(), nextRepeat);
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2010-07-31 07:02:52 +00:00
|
|
|
// Check for an early end before that time
|
|
|
|
nsSMILInstanceTime* earlyEnd = CheckForEarlyEnd(nextMilestone);
|
2010-01-12 20:00:49 +00:00
|
|
|
if (earlyEnd) {
|
2011-10-17 14:59:28 +00:00
|
|
|
aNextMilestone.mIsEnd = true;
|
2010-01-12 20:00:49 +00:00
|
|
|
aNextMilestone.mTime = earlyEnd->Time().GetMillis();
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 07:02:52 +00:00
|
|
|
// Apply the previously calculated milestone
|
2011-09-07 00:20:40 +00:00
|
|
|
if (nextMilestone.IsDefinite()) {
|
2010-07-31 07:02:52 +00:00
|
|
|
aNextMilestone.mIsEnd = nextMilestone != nextRepeat;
|
|
|
|
aNextMilestone.mTime = nextMilestone.GetMillis();
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case STATE_POSTACTIVE:
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
2013-06-29 01:38:30 +00:00
|
|
|
MOZ_CRASH("Invalid element state");
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::NotifyNewInterval()
|
|
|
|
{
|
2010-03-01 19:31:50 +00:00
|
|
|
NS_ABORT_IF_FALSE(mCurrentInterval,
|
2010-01-12 20:00:49 +00:00
|
|
|
"Attempting to notify dependents of a new interval but the interval "
|
|
|
|
"is not set");
|
|
|
|
|
|
|
|
nsSMILTimeContainer* container = GetTimeContainer();
|
|
|
|
if (container) {
|
|
|
|
container->SyncPauseTime();
|
|
|
|
}
|
|
|
|
|
2012-01-31 00:54:10 +00:00
|
|
|
NotifyTimeDependentsParams params = { this, container };
|
2010-01-12 20:00:49 +00:00
|
|
|
mTimeDependents.EnumerateEntries(NotifyNewIntervalCallback, ¶ms);
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-15 00:16:57 +00:00
|
|
|
nsSMILTimedElement::NotifyChangedInterval(nsSMILInterval* aInterval,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aBeginObjectChanged,
|
|
|
|
bool aEndObjectChanged)
|
2010-01-12 20:00:49 +00:00
|
|
|
{
|
2011-06-15 00:16:57 +00:00
|
|
|
NS_ABORT_IF_FALSE(aInterval, "Null interval for change notification");
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
nsSMILTimeContainer* container = GetTimeContainer();
|
|
|
|
if (container) {
|
|
|
|
container->SyncPauseTime();
|
|
|
|
}
|
|
|
|
|
2011-06-15 00:16:57 +00:00
|
|
|
// Copy the instance times list since notifying the instance times can result
|
|
|
|
// in a chain reaction whereby our own interval gets deleted along with its
|
|
|
|
// instance times.
|
|
|
|
InstanceTimeList times;
|
|
|
|
aInterval->GetDependentTimes(times);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < times.Length(); ++i) {
|
2011-06-15 00:16:57 +00:00
|
|
|
times[i]->HandleChangedInterval(container, aBeginObjectChanged,
|
|
|
|
aEndObjectChanged);
|
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 07:02:52 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSMILTimedElement::FireTimeEventAsync(uint32_t aMsg, int32_t aDetail)
|
2010-07-31 07:02:52 +00:00
|
|
|
{
|
|
|
|
if (!mAnimationElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2013-03-19 03:18:45 +00:00
|
|
|
new AsyncTimeEventRunner(mAnimationElement, aMsg, aDetail);
|
2010-07-31 07:02:52 +00:00
|
|
|
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
const nsSMILInstanceTime*
|
|
|
|
nsSMILTimedElement::GetEffectiveBeginInstance() const
|
|
|
|
{
|
|
|
|
switch (mElementState)
|
|
|
|
{
|
|
|
|
case STATE_STARTUP:
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
case STATE_ACTIVE:
|
2010-03-01 19:31:50 +00:00
|
|
|
return mCurrentInterval->Begin();
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
case STATE_WAITING:
|
|
|
|
case STATE_POSTACTIVE:
|
2010-03-01 19:31:50 +00:00
|
|
|
{
|
|
|
|
const nsSMILInterval* prevInterval = GetPreviousInterval();
|
2012-07-30 14:20:58 +00:00
|
|
|
return prevInterval ? prevInterval->Begin() : nullptr;
|
2010-03-01 19:31:50 +00:00
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
2013-06-29 01:38:30 +00:00
|
|
|
MOZ_CRASH("Invalid element state");
|
2010-01-12 20:00:49 +00:00
|
|
|
}
|
2010-01-12 20:00:49 +00:00
|
|
|
|
2010-03-01 19:31:50 +00:00
|
|
|
const nsSMILInterval*
|
|
|
|
nsSMILTimedElement::GetPreviousInterval() const
|
|
|
|
{
|
|
|
|
return mOldIntervals.IsEmpty()
|
2012-07-30 14:20:58 +00:00
|
|
|
? nullptr
|
2010-03-01 19:31:50 +00:00
|
|
|
: mOldIntervals[mOldIntervals.Length()-1].get();
|
|
|
|
}
|
|
|
|
|
2013-12-13 04:41:52 +00:00
|
|
|
bool
|
|
|
|
nsSMILTimedElement::HasClientInFillRange() const
|
|
|
|
{
|
|
|
|
// Returns true if we have a client that is in the range where it will fill
|
|
|
|
return mClient &&
|
|
|
|
((mElementState != STATE_ACTIVE && HasPlayed()) ||
|
|
|
|
(mElementState == STATE_ACTIVE && !mClient->IsActive()));
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-08-18 10:20:24 +00:00
|
|
|
nsSMILTimedElement::EndHasEventConditions() const
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mEndSpecs.Length(); ++i) {
|
2010-08-18 10:20:24 +00:00
|
|
|
if (mEndSpecs[i]->IsEventBased())
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-08-18 10:20:24 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-08-18 10:20:24 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 03:58:30 +00:00
|
|
|
bool
|
|
|
|
nsSMILTimedElement::AreEndTimesDependentOn(
|
|
|
|
const nsSMILInstanceTime* aBase) const
|
|
|
|
{
|
|
|
|
if (mEndInstances.IsEmpty())
|
|
|
|
return false;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mEndInstances.Length(); ++i) {
|
2011-11-14 03:58:30 +00:00
|
|
|
if (mEndInstances[i]->GetBaseTime() != aBase) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Hashtable callback functions
|
|
|
|
|
2012-09-25 16:18:38 +00:00
|
|
|
/* static */ PLDHashOperator
|
2010-01-12 20:00:49 +00:00
|
|
|
nsSMILTimedElement::NotifyNewIntervalCallback(TimeValueSpecPtrKey* aKey,
|
|
|
|
void* aData)
|
|
|
|
{
|
2010-03-01 19:31:50 +00:00
|
|
|
NS_ABORT_IF_FALSE(aKey, "Null hash key for time container hash table");
|
|
|
|
NS_ABORT_IF_FALSE(aKey->GetKey(),
|
|
|
|
"null nsSMILTimeValueSpec in set of time dependents");
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
NotifyTimeDependentsParams* params =
|
|
|
|
static_cast<NotifyTimeDependentsParams*>(aData);
|
2010-03-01 19:31:50 +00:00
|
|
|
NS_ABORT_IF_FALSE(params, "null data ptr while enumerating hashtable");
|
2012-01-31 00:54:10 +00:00
|
|
|
nsSMILInterval* interval = params->mTimedElement->mCurrentInterval;
|
|
|
|
// It's possible that in notifying one new time dependent of a new interval
|
|
|
|
// that a chain reaction is triggered which results in the original interval
|
|
|
|
// disappearing. If that's the case we can skip sending further notifications.
|
|
|
|
if (!interval)
|
|
|
|
return PL_DHASH_STOP;
|
2010-01-12 20:00:49 +00:00
|
|
|
|
|
|
|
nsSMILTimeValueSpec* spec = aKey->GetKey();
|
2012-01-31 00:54:10 +00:00
|
|
|
spec->HandleNewInterval(*interval, params->mTimeContainer);
|
2010-01-12 20:00:49 +00:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|