2009-01-14 20:38:07 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SMIL module.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Brian Birtles.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brian Birtles <birtles@gmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsSMILTimedElement.h"
|
|
|
|
#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"
|
|
|
|
#include "prdtoa.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper classes -- InstanceTimeComparator
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
PRBool
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
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");
|
|
|
|
|
|
|
|
PRInt8 cmp = aElem1->Time().CompareTo(aElem2->Time());
|
|
|
|
return cmp == 0 ? aElem1->Serial() < aElem2->Serial() : cmp < 0;
|
|
|
|
}
|
|
|
|
|
2010-07-02 22:52:50 -07: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;
|
|
|
|
for (PRUint32 i = 0; i < aArray.Length(); ++i) {
|
|
|
|
nsSMILInstanceTime* item = aArray[i].get();
|
|
|
|
if (aTest(item, i)) {
|
|
|
|
item->Unlink();
|
|
|
|
} else {
|
|
|
|
newArray.AppendElement(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aArray.Clear();
|
|
|
|
aArray.SwapElements(newArray);
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Static members
|
|
|
|
|
|
|
|
nsAttrValue::EnumTable nsSMILTimedElement::sFillModeTable[] = {
|
|
|
|
{"remove", FILL_REMOVE},
|
|
|
|
{"freeze", FILL_FREEZE},
|
|
|
|
{nsnull, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
nsAttrValue::EnumTable nsSMILTimedElement::sRestartModeTable[] = {
|
|
|
|
{"always", RESTART_ALWAYS},
|
|
|
|
{"whenNotActive", RESTART_WHENNOTACTIVE},
|
|
|
|
{"never", RESTART_NEVER},
|
|
|
|
{nsnull, 0}
|
|
|
|
};
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
const nsSMILMilestone nsSMILTimedElement::sMaxMilestone(LL_MAXINT, PR_FALSE);
|
|
|
|
|
2010-07-02 22:52:50 -07:00
|
|
|
// The thresholds at which point we start filtering intervals and instance times
|
|
|
|
// indiscriminately.
|
|
|
|
// See FilterIntervals and FilterInstanceTimes.
|
|
|
|
const PRUint8 nsSMILTimedElement::sMaxNumIntervals = 20;
|
|
|
|
const PRUint8 nsSMILTimedElement::sMaxNumInstanceTimes = 100;
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Ctor, dtor
|
|
|
|
|
|
|
|
nsSMILTimedElement::nsSMILTimedElement()
|
|
|
|
:
|
2010-01-12 12:00:49 -08:00
|
|
|
mAnimationElement(nsnull),
|
2009-01-14 20:38:07 -08:00
|
|
|
mFillMode(FILL_REMOVE),
|
|
|
|
mRestartMode(RESTART_ALWAYS),
|
|
|
|
mBeginSpecSet(PR_FALSE),
|
|
|
|
mEndHasEventConditions(PR_FALSE),
|
2010-01-12 12:00:49 -08:00
|
|
|
mInstanceSerialIndex(0),
|
2009-01-14 20:38:07 -08:00
|
|
|
mClient(nsnull),
|
2010-03-01 11:31:50 -08:00
|
|
|
mCurrentInterval(nsnull),
|
2010-01-12 12:00:49 -08:00
|
|
|
mPrevRegisteredMilestone(sMaxMilestone),
|
2009-01-14 20:38:07 -08:00
|
|
|
mElementState(STATE_STARTUP)
|
|
|
|
{
|
|
|
|
mSimpleDur.SetIndefinite();
|
|
|
|
mMin.SetMillis(0L);
|
|
|
|
mMax.SetIndefinite();
|
2010-01-12 12:00:49 -08:00
|
|
|
mTimeDependents.Init();
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILTimedElement::~nsSMILTimedElement()
|
|
|
|
{
|
|
|
|
// Put us in a consistent state in case we get any callbacks
|
|
|
|
mElementState = STATE_POSTACTIVE;
|
|
|
|
|
|
|
|
// Unlink all instance times from dependent intervals
|
|
|
|
for (PRUint32 i = 0; i < mBeginInstances.Length(); ++i) {
|
|
|
|
mBeginInstances[i]->Unlink();
|
|
|
|
}
|
|
|
|
mBeginInstances.Clear();
|
|
|
|
for (PRUint32 i = 0; i < mEndInstances.Length(); ++i) {
|
|
|
|
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)
|
|
|
|
if (mCurrentInterval) {
|
2010-07-02 22:52:50 -07:00
|
|
|
mCurrentInterval->Unlink();
|
2010-03-01 11:31:50 -08:00
|
|
|
mCurrentInterval = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRInt32 i = mOldIntervals.Length() - 1; i >= 0; --i) {
|
2010-07-02 22:52:50 -07:00
|
|
|
mOldIntervals[i]->Unlink();
|
2010-03-01 11:31:50 -08:00
|
|
|
}
|
|
|
|
mOldIntervals.Clear();
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::SetAnimationElement(nsISMILAnimationElement* aElement)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aElement, "NULL owner element");
|
|
|
|
NS_ABORT_IF_FALSE(!mAnimationElement, "Re-setting owner");
|
|
|
|
mAnimationElement = aElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimeContainer*
|
|
|
|
nsSMILTimedElement::GetTimeContainer()
|
|
|
|
{
|
|
|
|
return mAnimationElement ? mAnimationElement->GetTimeContainer() : nsnull;
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08: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 01:12:29 -08:00
|
|
|
// the methods return a bool depending on the restart mode.
|
2009-01-14 20:38:07 -08:00
|
|
|
//
|
2009-01-19 01:12:29 -08:00
|
|
|
// This inconsistency has now been addressed by an erratum in SVG 1.1:
|
2009-01-14 20:38:07 -08:00
|
|
|
//
|
2009-01-19 01:12:29 -08:00
|
|
|
// http://www.w3.org/2003/01/REC-SVG11-20030114-errata#elementtimecontrol-interface
|
2009-01-14 20:38:07 -08:00
|
|
|
//
|
2009-01-19 01:12:29 -08:00
|
|
|
// which favours the definition in SMIL, i.e. instance times are just added
|
|
|
|
// without first checking the restart mode.
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2009-01-19 01:12:29 -08:00
|
|
|
nsresult
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::BeginElementAt(double aOffsetSeconds)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimeContainer* container = GetTimeContainer();
|
|
|
|
if (!container)
|
2009-01-19 01:12:29 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-21 17:00:27 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTime currentTime = container->GetCurrentTime();
|
2009-01-21 17:00:27 -08:00
|
|
|
AddInstanceTimeFromCurrentTime(currentTime, aOffsetSeconds, PR_TRUE);
|
|
|
|
|
|
|
|
// After we've added the instance time we must do a local resample.
|
|
|
|
//
|
|
|
|
// The reason for this can be explained by considering the following sequence
|
|
|
|
// of calls in a script block
|
|
|
|
//
|
|
|
|
// BeginElementAt(0)
|
|
|
|
// BeginElementAt(-1)
|
|
|
|
// GetStartTime() <-- should return the time from the first call to
|
|
|
|
// BeginElementAt
|
|
|
|
//
|
|
|
|
// After BeginElementAt(0) is called a new begin instance time is added to the
|
|
|
|
// list. Depending on the restart mode this may generate a new interval,
|
|
|
|
// possiblying ending the current interval early.
|
|
|
|
//
|
|
|
|
// Intuitively this change should take effect before the subsequent call to
|
|
|
|
// BeginElementAt however to get this to take effect we need to drive the
|
2009-01-23 01:02:09 -08:00
|
|
|
// state engine through its sequence active-waiting-active by calling Sample.
|
2009-01-21 17:00:27 -08:00
|
|
|
//
|
|
|
|
// When we get the second call to BeginElementAt the element should be in the
|
|
|
|
// active state and hence the new begin instance time will be ignored because
|
|
|
|
// it is before the beginning of the (new) current interval. SMIL says we do
|
|
|
|
// not change the begin of a current interval once it is active.
|
|
|
|
//
|
|
|
|
// See also:
|
|
|
|
// http://www.w3.org/TR/SMIL3/smil-timing.html#Timing-BeginEnd-Restart
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
// If we haven't started yet, then there's no point in trying to force the
|
|
|
|
// sample. A series of calls to BeginElementAt before the document starts
|
|
|
|
// should probably just add a series of instance times.
|
|
|
|
if (mElementState != STATE_STARTUP) {
|
|
|
|
DoSampleAt(currentTime, PR_FALSE); // Regular sample, not end sample
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2009-01-19 01:12:29 -08:00
|
|
|
return NS_OK;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2009-01-19 01:12:29 -08:00
|
|
|
nsresult
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::EndElementAt(double aOffsetSeconds)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimeContainer* container = GetTimeContainer();
|
|
|
|
if (!container)
|
2009-01-19 01:12:29 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-21 17:00:27 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTime currentTime = container->GetCurrentTime();
|
2009-01-21 17:00:27 -08:00
|
|
|
AddInstanceTimeFromCurrentTime(currentTime, aOffsetSeconds, PR_FALSE);
|
2010-01-12 12:00:49 -08:00
|
|
|
if (mElementState != STATE_STARTUP) {
|
|
|
|
DoSampleAt(currentTime, PR_FALSE); // Regular sample, not end sample
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2009-01-19 01:12:29 -08:00
|
|
|
return NS_OK;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2009-01-19 01:10:53 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGAnimationElement methods
|
|
|
|
|
|
|
|
nsSMILTimeValue
|
|
|
|
nsSMILTimedElement::GetStartTime() const
|
|
|
|
{
|
2009-10-12 16:14:08 -07:00
|
|
|
return mElementState == STATE_WAITING || mElementState == STATE_ACTIVE
|
2010-03-01 11:31:50 -08:00
|
|
|
? mCurrentInterval->Begin()->Time()
|
2009-10-12 16:14:08 -07:00
|
|
|
: nsSMILTimeValue();
|
2009-01-19 01:10:53 -08:00
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSMILTimedElement
|
|
|
|
|
|
|
|
void
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::AddInstanceTime(nsSMILInstanceTime* aInstanceTime,
|
2009-01-14 20:38:07 -08:00
|
|
|
PRBool aIsBegin)
|
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
NS_ABORT_IF_FALSE(aInstanceTime, "Attempting to add null instance time");
|
|
|
|
|
|
|
|
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 01:12:29 -08:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::UpdateInstanceTime(nsSMILInstanceTime* aInstanceTime,
|
|
|
|
nsSMILTimeValue& aUpdatedTime,
|
|
|
|
PRBool aIsBegin)
|
|
|
|
{
|
|
|
|
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).
|
2010-03-01 11:31:50 -08:00
|
|
|
PRBool changedCurrentInterval = mCurrentInterval &&
|
|
|
|
(mCurrentInterval->Begin() == aInstanceTime ||
|
|
|
|
mCurrentInterval->End() == aInstanceTime);
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
UpdateCurrentInterval(changedCurrentInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::RemoveInstanceTime(nsSMILInstanceTime* aInstanceTime,
|
|
|
|
PRBool aIsBegin)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aInstanceTime, "Attempting to remove null instance time");
|
|
|
|
|
|
|
|
InstanceTimeList& instanceList = aIsBegin ? mBeginInstances : mEndInstances;
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool found =
|
|
|
|
#endif
|
|
|
|
instanceList.RemoveElementSorted(aInstanceTime, InstanceTimeComparator());
|
|
|
|
NS_ABORT_IF_FALSE(found, "Couldn't find instance time to delete");
|
|
|
|
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
2010-07-02 22:52:50 -07:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class RemoveByCreator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RemoveByCreator(const nsSMILTimeValueSpec* aCreator) : mCreator(aCreator)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
PRBool operator()(nsSMILInstanceTime* aInstanceTime, PRUint32 /*aIndex*/)
|
|
|
|
{
|
|
|
|
return aInstanceTime->GetCreator() == mCreator;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsSMILTimeValueSpec* mCreator;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::RemoveInstanceTimesForCreator(
|
|
|
|
const nsSMILTimeValueSpec* aCreator, PRBool aIsBegin)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aCreator, "Creator not set");
|
|
|
|
|
2010-07-02 22:52:50 -07:00
|
|
|
InstanceTimeList& instances = aIsBegin ? mBeginInstances : mEndInstances;
|
|
|
|
RemoveByCreator removeByCreator(aCreator);
|
|
|
|
RemoveInstanceTimes(instances, removeByCreator);
|
2010-03-01 11:31:50 -08:00
|
|
|
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::SetTimeClient(nsSMILAnimationFunction* aClient)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// No need to check for NULL. A NULL parameter simply means to remove the
|
|
|
|
// previous client which we do by setting to NULL anyway.
|
|
|
|
//
|
|
|
|
|
|
|
|
mClient = aClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::SampleAt(nsSMILTime aContainerTime)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
// Milestones are cleared before a sample
|
|
|
|
mPrevRegisteredMilestone = sMaxMilestone;
|
|
|
|
|
|
|
|
DoSampleAt(aContainerTime, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
DoSampleAt(aContainerTime, PR_TRUE); // End sample
|
|
|
|
} else {
|
|
|
|
// Even if this was an unnecessary milestone sample we want to be sure that
|
|
|
|
// our next real milestone is registered.
|
|
|
|
RegisterMilestone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::DoSampleAt(nsSMILTime aContainerTime, PRBool aEndOnly)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(mElementState != STATE_STARTUP || aEndOnly,
|
|
|
|
"Got a regular sample during startup state, expected an end sample"
|
|
|
|
" instead");
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
PRBool stateChanged;
|
|
|
|
nsSMILTimeValue sampleTime(aContainerTime);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
do {
|
2010-03-01 11:31:52 -08: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
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
stateChanged = PR_FALSE;
|
|
|
|
|
|
|
|
switch (mElementState)
|
|
|
|
{
|
|
|
|
case STATE_STARTUP:
|
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILInterval firstInterval;
|
2009-07-15 11:33:31 -07:00
|
|
|
mElementState =
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_SUCCEEDED(GetNextInterval(nsnull, nsnull, firstInterval))
|
2009-01-14 20:38:07 -08:00
|
|
|
? STATE_WAITING
|
|
|
|
: STATE_POSTACTIVE;
|
|
|
|
stateChanged = PR_TRUE;
|
2010-01-12 12:00:49 -08:00
|
|
|
if (mElementState == STATE_WAITING) {
|
2010-03-01 11:31:50 -08:00
|
|
|
mCurrentInterval = new nsSMILInterval(firstInterval);
|
2010-07-02 22:52:50 -07:00
|
|
|
NotifyNewInterval();
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_WAITING:
|
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
if (mCurrentInterval->Begin()->Time() <= sampleTime) {
|
2009-01-14 20:38:07 -08:00
|
|
|
mElementState = STATE_ACTIVE;
|
2010-07-02 22:52:50 -07:00
|
|
|
mCurrentInterval->FixBegin();
|
2010-03-01 11:31:50 -08:00
|
|
|
if (HasPlayed()) {
|
2010-01-13 00:18:51 -08:00
|
|
|
Reset(); // Apply restart behaviour
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
if (mClient) {
|
2010-03-01 11:31:50 -08:00
|
|
|
mClient->Activate(mCurrentInterval->Begin()->Time().GetMillis());
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
2010-03-01 11:31:50 -08:00
|
|
|
if (HasPlayed()) {
|
2010-01-13 00:18:51 -08: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
|
|
|
|
// thing we do. There is no guarantee that mCurrentInterval.IsSet()
|
|
|
|
// is true after this.
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
stateChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_ACTIVE:
|
|
|
|
{
|
2010-07-02 22:52:50 -07:00
|
|
|
ApplyEarlyEnd(sampleTime);
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
if (mCurrentInterval->End()->Time() <= sampleTime) {
|
2009-01-14 20:38:07 -08:00
|
|
|
nsSMILInterval newInterval;
|
2009-07-15 11:33:31 -07:00
|
|
|
mElementState =
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_SUCCEEDED(GetNextInterval(mCurrentInterval, nsnull, newInterval))
|
2009-01-14 20:38:07 -08:00
|
|
|
? STATE_WAITING
|
|
|
|
: STATE_POSTACTIVE;
|
|
|
|
if (mClient) {
|
|
|
|
mClient->Inactivate(mFillMode == FILL_FREEZE);
|
|
|
|
}
|
2010-07-02 22:52:50 -07:00
|
|
|
mCurrentInterval->FixEnd();
|
2010-03-01 11:31:50 -08:00
|
|
|
mOldIntervals.AppendElement(mCurrentInterval.forget());
|
|
|
|
// We must update mOldIntervals before calling SampleFillValue
|
2010-01-12 12:00:49 -08:00
|
|
|
SampleFillValue();
|
|
|
|
if (mElementState == STATE_WAITING) {
|
2010-03-01 11:31:50 -08:00
|
|
|
mCurrentInterval = new nsSMILInterval(newInterval);
|
2010-07-02 22:52:50 -07:00
|
|
|
NotifyNewInterval();
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
2010-07-02 22:52:50 -07:00
|
|
|
FilterHistory();
|
2009-01-14 20:38:07 -08:00
|
|
|
stateChanged = PR_TRUE;
|
|
|
|
} else {
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILTime beginTime = mCurrentInterval->Begin()->Time().GetMillis();
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTime activeTime = aContainerTime - beginTime;
|
2009-01-14 20:38:07 -08:00
|
|
|
SampleSimpleTime(activeTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_POSTACTIVE:
|
|
|
|
break;
|
|
|
|
}
|
2010-01-12 12:00:49 -08: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)));
|
|
|
|
|
|
|
|
RegisterMilestone();
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08: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) {
|
|
|
|
NotifyChangedInterval();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
PRBool
|
|
|
|
nsSMILTimedElement::SetAttr(nsIAtom* aAttribute, const nsAString& aValue,
|
2010-01-12 12:00:49 -08:00
|
|
|
nsAttrValue& aResult, nsIContent* aContextNode,
|
|
|
|
nsresult* aParseResult)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
PRBool foundMatch = PR_TRUE;
|
|
|
|
nsresult parseResult = NS_OK;
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::begin) {
|
2010-01-12 12:00:49 -08:00
|
|
|
parseResult = SetBeginSpec(aValue, aContextNode);
|
2009-01-14 20:38:07 -08:00
|
|
|
} else if (aAttribute == nsGkAtoms::dur) {
|
|
|
|
parseResult = SetSimpleDuration(aValue);
|
|
|
|
} else if (aAttribute == nsGkAtoms::end) {
|
2010-01-12 12:00:49 -08:00
|
|
|
parseResult = SetEndSpec(aValue, aContextNode);
|
2009-01-14 20:38:07 -08: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 {
|
|
|
|
foundMatch = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundMatch) {
|
|
|
|
aResult.SetTo(aValue);
|
|
|
|
if (aParseResult) {
|
|
|
|
*aParseResult = parseResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILTimedElement::UnsetAttr(nsIAtom* aAttribute)
|
|
|
|
{
|
|
|
|
PRBool foundMatch = PR_TRUE;
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::begin) {
|
|
|
|
UnsetBeginSpec();
|
|
|
|
} else if (aAttribute == nsGkAtoms::dur) {
|
|
|
|
UnsetSimpleDuration();
|
|
|
|
} else if (aAttribute == nsGkAtoms::end) {
|
|
|
|
UnsetEndSpec();
|
|
|
|
} 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 {
|
|
|
|
foundMatch = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Setters and unsetters
|
|
|
|
|
|
|
|
nsresult
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::SetBeginSpec(const nsAString& aBeginSpec,
|
|
|
|
nsIContent* aContextNode)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
mBeginSpecSet = PR_TRUE;
|
2010-01-12 12:00:49 -08:00
|
|
|
return SetBeginOrEndSpec(aBeginSpec, aContextNode, PR_TRUE);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetBeginSpec()
|
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
ClearBeginOrEndSpecs(PR_TRUE);
|
2009-01-14 20:38:07 -08:00
|
|
|
mBeginSpecSet = PR_FALSE;
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::SetEndSpec(const nsAString& aEndSpec,
|
|
|
|
nsIContent* aContextNode)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
// XXX When implementing events etc., don't forget to ensure
|
2009-01-14 20:38:07 -08:00
|
|
|
// mEndHasEventConditions is set if the specification contains conditions that
|
|
|
|
// describe event-values, repeat-values or accessKey-values.
|
2010-01-12 12:00:49 -08:00
|
|
|
return SetBeginOrEndSpec(aEndSpec, aContextNode, PR_FALSE);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetEndSpec()
|
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
ClearBeginOrEndSpecs(PR_FALSE);
|
2009-01-14 20:38:07 -08:00
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetSimpleDuration(const nsAString& aDurSpec)
|
|
|
|
{
|
|
|
|
nsSMILTimeValue duration;
|
|
|
|
PRBool isMedia;
|
|
|
|
nsresult rv;
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
rv = nsSMILParserUtils::ParseClockValue(aDurSpec, &duration,
|
|
|
|
nsSMILParserUtils::kClockValueAllowIndefinite, &isMedia);
|
|
|
|
|
2009-01-21 20:17:12 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
2009-01-19 01:10:53 -08:00
|
|
|
mSimpleDur.SetIndefinite();
|
2009-01-14 20:38:07 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-19 01:10:53 -08:00
|
|
|
}
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-19 01:10:53 -08:00
|
|
|
if (duration.IsResolved() && duration.GetMillis() == 0L) {
|
|
|
|
mSimpleDur.SetIndefinite();
|
2009-01-14 20:38:07 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-19 01:10:53 -08:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
//
|
|
|
|
// SVG-specific: "For SVG's animation elements, if "media" is specified, the
|
|
|
|
// attribute will be ignored." (SVG 1.1, section 19.2.6)
|
|
|
|
//
|
|
|
|
if (isMedia)
|
|
|
|
duration.SetIndefinite();
|
|
|
|
|
2009-01-19 01:10:53 -08:00
|
|
|
// mSimpleDur should never be unresolved. ParseClockValue will either set
|
|
|
|
// duration to resolved/indefinite/media or will return a failure code.
|
|
|
|
NS_ASSERTION(duration.IsResolved() || duration.IsIndefinite(),
|
|
|
|
"Setting unresolved simple duration");
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
mSimpleDur = duration;
|
2009-01-21 17:00:27 -08:00
|
|
|
UpdateCurrentInterval();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetSimpleDuration()
|
|
|
|
{
|
|
|
|
mSimpleDur.SetIndefinite();
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetMin(const nsAString& aMinSpec)
|
|
|
|
{
|
|
|
|
nsSMILTimeValue duration;
|
|
|
|
PRBool isMedia;
|
|
|
|
nsresult rv;
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
rv = nsSMILParserUtils::ParseClockValue(aMinSpec, &duration, 0, &isMedia);
|
|
|
|
|
|
|
|
if (isMedia) {
|
|
|
|
duration.SetMillis(0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || !duration.IsResolved()) {
|
|
|
|
mMin.SetMillis(0L);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
if (duration.GetMillis() < 0L) {
|
|
|
|
mMin.SetMillis(0L);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMin = duration;
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetMin()
|
|
|
|
{
|
|
|
|
mMin.SetMillis(0L);
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetMax(const nsAString& aMaxSpec)
|
|
|
|
{
|
|
|
|
nsSMILTimeValue duration;
|
|
|
|
PRBool isMedia;
|
|
|
|
nsresult rv;
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
rv = nsSMILParserUtils::ParseClockValue(aMaxSpec, &duration,
|
|
|
|
nsSMILParserUtils::kClockValueAllowIndefinite, &isMedia);
|
|
|
|
|
|
|
|
if (isMedia)
|
|
|
|
duration.SetIndefinite();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || (!duration.IsResolved() && !duration.IsIndefinite())) {
|
|
|
|
mMax.SetIndefinite();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
if (duration.IsResolved() && duration.GetMillis() <= 0L) {
|
|
|
|
mMax.SetIndefinite();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMax = duration;
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetMax()
|
|
|
|
{
|
|
|
|
mMax.SetIndefinite();
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetRestart(const nsAString& aRestartSpec)
|
|
|
|
{
|
|
|
|
nsAttrValue temp;
|
2009-07-15 11:33:31 -07:00
|
|
|
PRBool parseResult
|
2009-01-14 20:38:07 -08:00
|
|
|
= temp.ParseEnumValue(aRestartSpec, sRestartModeTable, PR_TRUE);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
nsSMILRepeatCount newRepeatCount;
|
2009-07-15 11:33:31 -07:00
|
|
|
nsresult rv =
|
2009-01-14 20:38:07 -08:00
|
|
|
nsSMILParserUtils::ParseRepeatCount(aRepeatCountSpec, newRepeatCount);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mRepeatCount = newRepeatCount;
|
|
|
|
} else {
|
|
|
|
mRepeatCount.Unset();
|
|
|
|
}
|
2009-01-21 17:00:27 -08:00
|
|
|
|
|
|
|
UpdateCurrentInterval();
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetRepeatCount()
|
|
|
|
{
|
|
|
|
mRepeatCount.Unset();
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetRepeatDur(const nsAString& aRepeatDurSpec)
|
|
|
|
{
|
2009-01-19 01:10:53 -08:00
|
|
|
nsresult rv;
|
2009-01-14 20:38:07 -08:00
|
|
|
nsSMILTimeValue duration;
|
|
|
|
|
|
|
|
rv = nsSMILParserUtils::ParseClockValue(aRepeatDurSpec, &duration,
|
|
|
|
nsSMILParserUtils::kClockValueAllowIndefinite);
|
|
|
|
|
2009-01-19 01:10:53 -08:00
|
|
|
if (NS_FAILED(rv) || (!duration.IsResolved() && !duration.IsIndefinite())) {
|
|
|
|
mRepeatDur.SetUnresolved();
|
2009-01-14 20:38:07 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-19 01:10:53 -08:00
|
|
|
}
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
mRepeatDur = duration;
|
2009-01-21 17:00:27 -08:00
|
|
|
UpdateCurrentInterval();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetRepeatDur()
|
|
|
|
{
|
|
|
|
mRepeatDur.SetUnresolved();
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetFillMode(const nsAString& aFillModeSpec)
|
|
|
|
{
|
|
|
|
PRUint16 previousFillMode = mFillMode;
|
|
|
|
|
|
|
|
nsAttrValue temp;
|
2009-07-15 11:33:31 -07:00
|
|
|
PRBool parseResult =
|
2009-01-14 20:38:07 -08:00
|
|
|
temp.ParseEnumValue(aFillModeSpec, sFillModeTable, PR_TRUE);
|
|
|
|
mFillMode = parseResult
|
|
|
|
? nsSMILFillMode(temp.GetEnumValue())
|
|
|
|
: FILL_REMOVE;
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
// Check if we're in a fill-able state: i.e. we've played at least one
|
|
|
|
// interval and are now between intervals or at the end of all intervals
|
|
|
|
PRBool isFillable = HasPlayed() &&
|
2010-01-12 12:00:49 -08:00
|
|
|
(mElementState == STATE_WAITING || mElementState == STATE_POSTACTIVE);
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
if (mClient && mFillMode != previousFillMode && isFillable) {
|
2010-01-12 12:00:49 -08:00
|
|
|
mClient->Inactivate(mFillMode == FILL_FREEZE);
|
|
|
|
SampleFillValue();
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
return parseResult ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::UnsetFillMode()
|
|
|
|
{
|
|
|
|
PRUint16 previousFillMode = mFillMode;
|
|
|
|
mFillMode = FILL_REMOVE;
|
|
|
|
if ((mElementState == STATE_WAITING || mElementState == STATE_POSTACTIVE) &&
|
2010-03-01 11:31:50 -08:00
|
|
|
previousFillMode == FILL_FREEZE && mClient && HasPlayed())
|
2009-01-14 20:38:07 -08:00
|
|
|
mClient->Inactivate(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
void
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::AddDependent(nsSMILTimeValueSpec& aDependent)
|
|
|
|
{
|
|
|
|
// There's probably no harm in attempting to register a dependent
|
2010-01-12 12:00:49 -08:00
|
|
|
// nsSMILTimeValueSpec twice, but we're not expecting it to happen.
|
|
|
|
NS_ABORT_IF_FALSE(!mTimeDependents.GetEntry(&aDependent),
|
2010-01-12 12:00:49 -08:00
|
|
|
"nsSMILTimeValueSpec is already registered as a dependency");
|
2010-01-12 12:00:49 -08:00
|
|
|
mTimeDependents.PutEntry(&aDependent);
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-07-02 22:52:50 -07: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 11:31:50 -08:00
|
|
|
//
|
|
|
|
// It's not necessary to call SyncPauseTime since we're dealing with
|
|
|
|
// historical instance times not newly added ones.
|
|
|
|
if (mCurrentInterval) {
|
2010-07-02 22:52:50 -07:00
|
|
|
aDependent.HandleNewInterval(*mCurrentInterval, GetTimeContainer());
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::RemoveDependent(nsSMILTimeValueSpec& aDependent)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
mTimeDependents.RemoveEntry(&aDependent);
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILTimedElement::IsTimeDependent(const nsSMILTimedElement& aOther) const
|
|
|
|
{
|
|
|
|
const nsSMILInstanceTime* thisBegin = GetEffectiveBeginInstance();
|
|
|
|
const nsSMILInstanceTime* otherBegin = aOther.GetEffectiveBeginInstance();
|
|
|
|
|
|
|
|
if (!thisBegin || !otherBegin)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-07-02 22:52:50 -07:00
|
|
|
return thisBegin->IsDependentOn(*otherBegin);
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::BindToTree(nsIContent* aContextNode)
|
|
|
|
{
|
|
|
|
// Resolve references to other parts of the tree
|
|
|
|
PRUint32 count = mBeginSpecs.Length();
|
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
|
|
|
nsSMILTimeValueSpec* beginSpec = mBeginSpecs[i];
|
|
|
|
NS_ABORT_IF_FALSE(beginSpec,
|
|
|
|
"null nsSMILTimeValueSpec in list of begin specs");
|
|
|
|
beginSpec->ResolveReferences(aContextNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
count = mEndSpecs.Length();
|
|
|
|
for (PRUint32 j = 0; j < count; ++j) {
|
|
|
|
nsSMILTimeValueSpec* endSpec = mEndSpecs[j];
|
|
|
|
NS_ABORT_IF_FALSE(endSpec, "null nsSMILTimeValueSpec in list of end specs");
|
|
|
|
endSpec->ResolveReferences(aContextNode);
|
|
|
|
}
|
|
|
|
|
2010-05-24 17:38:25 -07:00
|
|
|
// Clear any previous milestone since it might be been processed whilst we
|
|
|
|
// were not bound to the tree.
|
|
|
|
mPrevRegisteredMilestone = sMaxMilestone;
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
RegisterMilestone();
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::Traverse(nsCycleCollectionTraversalCallback* aCallback)
|
|
|
|
{
|
|
|
|
PRUint32 count = mBeginSpecs.Length();
|
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
|
|
|
nsSMILTimeValueSpec* beginSpec = mBeginSpecs[i];
|
|
|
|
NS_ABORT_IF_FALSE(beginSpec,
|
|
|
|
"null nsSMILTimeValueSpec in list of begin specs");
|
|
|
|
beginSpec->Traverse(aCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
count = mEndSpecs.Length();
|
|
|
|
for (PRUint32 j = 0; j < count; ++j) {
|
|
|
|
nsSMILTimeValueSpec* endSpec = mEndSpecs[j];
|
|
|
|
NS_ABORT_IF_FALSE(endSpec, "null nsSMILTimeValueSpec in list of end specs");
|
|
|
|
endSpec->Traverse(aCallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::Unlink()
|
|
|
|
{
|
|
|
|
PRUint32 count = mBeginSpecs.Length();
|
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
|
|
|
nsSMILTimeValueSpec* beginSpec = mBeginSpecs[i];
|
|
|
|
NS_ABORT_IF_FALSE(beginSpec,
|
|
|
|
"null nsSMILTimeValueSpec in list of begin specs");
|
|
|
|
beginSpec->Unlink();
|
|
|
|
}
|
|
|
|
|
|
|
|
count = mEndSpecs.Length();
|
|
|
|
for (PRUint32 j = 0; j < count; ++j) {
|
|
|
|
nsSMILTimeValueSpec* endSpec = mEndSpecs[j];
|
|
|
|
NS_ABORT_IF_FALSE(endSpec, "null nsSMILTimeValueSpec in list of end specs");
|
|
|
|
endSpec->Unlink();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILTimedElement::SetBeginOrEndSpec(const nsAString& aSpec,
|
2010-01-12 12:00:49 -08:00
|
|
|
nsIContent* aContextNode,
|
2009-01-14 20:38:07 -08:00
|
|
|
PRBool aIsBegin)
|
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
ClearBeginOrEndSpecs(aIsBegin);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
PRInt32 start;
|
|
|
|
PRInt32 end = -1;
|
|
|
|
PRInt32 length;
|
2010-01-12 12:00:49 -08:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
TimeValueSpecList& timeSpecsList = aIsBegin ? mBeginSpecs : mEndSpecs;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
do {
|
|
|
|
start = end + 1;
|
|
|
|
end = aSpec.FindChar(';', start);
|
|
|
|
length = (end == -1) ? -1 : end - start;
|
2010-01-12 12:00:49 -08:00
|
|
|
nsAutoPtr<nsSMILTimeValueSpec>
|
|
|
|
spec(new nsSMILTimeValueSpec(*this, aIsBegin));
|
|
|
|
rv = spec->SetSpec(Substring(aSpec, start, length), aContextNode);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
timeSpecsList.AppendElement(spec.forget());
|
|
|
|
}
|
|
|
|
} while (end != -1 && NS_SUCCEEDED(rv));
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
ClearBeginOrEndSpecs(aIsBegin);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateCurrentInterval();
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-07-02 22:52:50 -07:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class RemoveNonDOM
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PRBool operator()(nsSMILInstanceTime* aInstanceTime, PRUint32 /*aIndex*/)
|
|
|
|
{
|
|
|
|
return !aInstanceTime->FromDOM();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::ClearBeginOrEndSpecs(PRBool aIsBegin)
|
|
|
|
{
|
|
|
|
TimeValueSpecList& specs = aIsBegin ? mBeginSpecs : mEndSpecs;
|
|
|
|
specs.Clear();
|
|
|
|
|
|
|
|
// Remove only those instance times generated by the attribute, not those from
|
|
|
|
// DOM calls.
|
|
|
|
InstanceTimeList& instances = aIsBegin ? mBeginInstances : mEndInstances;
|
2010-07-02 22:52:50 -07:00
|
|
|
RemoveNonDOM removeNonDOM;
|
|
|
|
RemoveInstanceTimes(instances, removeNonDOM);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
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");
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
NotifyChangedInterval();
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-07-02 22:52:50 -07:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class RemoveReset
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RemoveReset(const nsSMILInstanceTime* aCurrentIntervalBegin)
|
|
|
|
: mCurrentIntervalBegin(aCurrentIntervalBegin) { }
|
|
|
|
PRBool operator()(nsSMILInstanceTime* aInstanceTime, PRUint32 /*aIndex*/)
|
|
|
|
{
|
|
|
|
// 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() &&
|
|
|
|
!aInstanceTime->IsUsedAsFixedEndpoint() &&
|
|
|
|
(!mCurrentIntervalBegin || aInstanceTime != mCurrentIntervalBegin);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsSMILInstanceTime* mCurrentIntervalBegin;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::Reset()
|
|
|
|
{
|
|
|
|
RemoveReset resetBegin(mCurrentInterval ? mCurrentInterval->Begin() : nsnull);
|
|
|
|
RemoveInstanceTimes(mBeginInstances, resetBegin);
|
|
|
|
|
|
|
|
RemoveReset resetEnd(nsnull);
|
|
|
|
RemoveInstanceTimes(mEndInstances, resetEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
// b) are not in the middle of a dependency chain
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
PRUint32 threshold = mOldIntervals.Length() > sMaxNumIntervals ?
|
|
|
|
mOldIntervals.Length() - sMaxNumIntervals :
|
|
|
|
0;
|
|
|
|
IntervalList filteredList;
|
|
|
|
for (PRUint32 i = 0; i < mOldIntervals.Length(); ++i)
|
|
|
|
{
|
|
|
|
nsSMILInterval* interval = mOldIntervals[i].get();
|
|
|
|
if (i + 1 < mOldIntervals.Length() /*skip previous interval*/ &&
|
|
|
|
(i < threshold || !interval->IsDependencyChainLink())) {
|
|
|
|
interval->Unlink(PR_TRUE /*filtered, not deleted*/);
|
|
|
|
} else {
|
|
|
|
filteredList.AppendElement(mOldIntervals[i].forget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mOldIntervals.Clear();
|
|
|
|
mOldIntervals.SwapElements(filteredList);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class RemoveFiltered
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RemoveFiltered(nsSMILTimeValue aCutoff) : mCutoff(aCutoff) { }
|
|
|
|
PRBool operator()(nsSMILInstanceTime* aInstanceTime, PRUint32 /*aIndex*/)
|
|
|
|
{
|
|
|
|
// 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() &&
|
|
|
|
!aInstanceTime->IsUsedAsFixedEndpoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsSMILTimeValue mCutoff;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RemoveBelowThreshold
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RemoveBelowThreshold(PRUint32 aThreshold,
|
|
|
|
const nsSMILInstanceTime* aCurrentIntervalBegin)
|
|
|
|
: mThreshold(aThreshold),
|
|
|
|
mCurrentIntervalBegin(aCurrentIntervalBegin) { }
|
|
|
|
PRBool operator()(nsSMILInstanceTime* aInstanceTime, PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
return aInstanceTime != mCurrentIntervalBegin && aIndex < mThreshold;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRUint32 mThreshold;
|
|
|
|
const nsSMILInstanceTime* mCurrentIntervalBegin;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
PRUint32 threshold = aList.Length() - sMaxNumInstanceTimes;
|
|
|
|
// We should still preserve the current interval begin time however
|
|
|
|
const nsSMILInstanceTime* currentIntervalBegin = mCurrentInterval ?
|
|
|
|
mCurrentInterval->Begin() : nsnull;
|
|
|
|
RemoveBelowThreshold removeBelowThreshold(threshold, currentIntervalBegin);
|
|
|
|
RemoveInstanceTimes(aList, removeBelowThreshold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08: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
|
|
|
|
//
|
|
|
|
nsresult
|
2009-08-04 19:39:04 -07:00
|
|
|
nsSMILTimedElement::GetNextInterval(const nsSMILInterval* aPrevInterval,
|
2010-01-12 12:00:49 -08:00
|
|
|
const nsSMILInstanceTime* aFixedBeginTime,
|
2010-03-01 11:31:52 -08:00
|
|
|
nsSMILInterval& aResult) const
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
NS_ABORT_IF_FALSE(!aFixedBeginTime || aFixedBeginTime->Time().IsResolved(),
|
|
|
|
"Unresolved begin time specified for interval start");
|
2010-01-12 12:00:49 -08:00
|
|
|
static nsSMILTimeValue zeroTime(0L);
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
if (mRestartMode == RESTART_NEVER && aPrevInterval)
|
2009-08-04 19:39:04 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2009-08-04 19:39:04 -07:00
|
|
|
// Calc starting point
|
|
|
|
nsSMILTimeValue beginAfter;
|
|
|
|
PRBool prevIntervalWasZeroDur = PR_FALSE;
|
2010-03-01 11:31:50 -08:00
|
|
|
if (aPrevInterval) {
|
2010-01-12 12:00:49 -08:00
|
|
|
beginAfter = aPrevInterval->End()->Time();
|
|
|
|
prevIntervalWasZeroDur
|
|
|
|
= aPrevInterval->End()->Time() == aPrevInterval->Begin()->Time();
|
2010-01-13 00:18:51 -08:00
|
|
|
if (aFixedBeginTime) {
|
2010-01-28 01:51:03 -08:00
|
|
|
prevIntervalWasZeroDur &=
|
2010-01-13 00:18:51 -08:00
|
|
|
aPrevInterval->Begin()->Time() == aFixedBeginTime->Time();
|
|
|
|
}
|
2009-08-04 19:39:04 -07:00
|
|
|
} else {
|
|
|
|
beginAfter.SetMillis(LL_MININT);
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsRefPtr<nsSMILInstanceTime> tempBegin;
|
|
|
|
nsRefPtr<nsSMILInstanceTime> tempEnd;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
while (PR_TRUE) {
|
2010-01-13 00:18:51 -08:00
|
|
|
// Calculate begin time
|
2010-01-12 12:00:49 -08:00
|
|
|
if (aFixedBeginTime) {
|
|
|
|
if (aFixedBeginTime->Time() < beginAfter)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
// our ref-counting is not const-correct
|
|
|
|
tempBegin = const_cast<nsSMILInstanceTime*>(aFixedBeginTime);
|
|
|
|
} else if (!mBeginSpecSet && beginAfter <= zeroTime) {
|
2010-03-01 11:31:50 -08:00
|
|
|
tempBegin = new nsSMILInstanceTime(nsSMILTimeValue(0));
|
2009-01-14 20:38:07 -08:00
|
|
|
} else {
|
2009-08-04 19:39:04 -07:00
|
|
|
PRInt32 beginPos = 0;
|
2010-01-12 12:00:49 -08:00
|
|
|
tempBegin = GetNextGreaterOrEqual(mBeginInstances, beginAfter, beginPos);
|
2010-05-20 17:18:29 -07:00
|
|
|
if (!tempBegin || !tempBegin->Time().IsResolved())
|
2009-01-14 20:38:07 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-05-20 17:18:29 -07:00
|
|
|
NS_ABORT_IF_FALSE(tempBegin && tempBegin->Time().IsResolved() &&
|
|
|
|
tempBegin->Time() >= beginAfter,
|
2010-01-12 12:00:49 -08:00
|
|
|
"Got a bad begin time while fetching next interval");
|
|
|
|
|
2010-01-13 00:18:51 -08:00
|
|
|
// Calculate end time
|
|
|
|
{
|
2009-08-04 19:39:04 -07:00
|
|
|
PRInt32 endPos = 0;
|
2010-01-12 12:00:49 -08:00
|
|
|
tempEnd = GetNextGreaterOrEqual(mEndInstances, tempBegin->Time(), endPos);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2009-08-04 19:39:04 -07:00
|
|
|
// If the last interval ended at the same point and was zero-duration and
|
|
|
|
// this one is too, look for another end to use instead
|
2010-01-12 12:00:49 -08:00
|
|
|
if (tempEnd && tempEnd->Time() == tempBegin->Time() &&
|
|
|
|
prevIntervalWasZeroDur) {
|
|
|
|
tempEnd = GetNextGreater(mEndInstances, tempBegin->Time(), endPos);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-01-13 00:18:51 -08:00
|
|
|
// If all the ends are before the beginning we have a bad interval UNLESS:
|
|
|
|
// a) We have end events which leave the interval open-ended, OR
|
|
|
|
// b) We never had any end attribute to begin with (and hence we should
|
|
|
|
// just use the active duration after allowing for the possibility of
|
|
|
|
// an end instance provided by a DOM call)
|
|
|
|
// c) We have an end attribute but no end instances--this is a special
|
|
|
|
// case that is needed for syncbase timing so that animations of the
|
|
|
|
// following sort: <animate id="a" end="a.begin+1s" ... /> can be
|
|
|
|
// resolved (see SVGT 1.2 Test Suite animate-elem-221-t.svg) by first
|
|
|
|
// establishing an interval of unresolved duration.
|
|
|
|
PRBool openEndedIntervalOk = mEndHasEventConditions ||
|
|
|
|
mEndSpecs.IsEmpty() ||
|
|
|
|
mEndInstances.IsEmpty();
|
|
|
|
if (!tempEnd && !openEndedIntervalOk)
|
|
|
|
return NS_ERROR_FAILURE; // Bad interval
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
nsSMILTimeValue intervalEnd = tempEnd
|
|
|
|
? tempEnd->Time() : nsSMILTimeValue();
|
|
|
|
nsSMILTimeValue activeEnd = CalcActiveEnd(tempBegin->Time(), intervalEnd);
|
|
|
|
|
|
|
|
if (!tempEnd || intervalEnd != activeEnd) {
|
2010-03-01 11:31:50 -08:00
|
|
|
tempEnd = new nsSMILInstanceTime(activeEnd);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
NS_ABORT_IF_FALSE(tempEnd, "Failed to get end point for next interval");
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2009-08-04 19:39:04 -07:00
|
|
|
// If we get two zero-length intervals in a row we will potentially have an
|
|
|
|
// infinite loop so we break it here by searching for the next begin time
|
|
|
|
// greater than tempEnd on the next time around.
|
2010-01-12 12:00:49 -08:00
|
|
|
if (tempEnd->Time().IsResolved() && tempBegin->Time() == tempEnd->Time()) {
|
2009-08-04 19:39:04 -07:00
|
|
|
if (prevIntervalWasZeroDur) {
|
2010-01-12 12:00:49 -08:00
|
|
|
beginAfter.SetMillis(tempEnd->Time().GetMillis() + 1);
|
2009-08-04 19:39:04 -07:00
|
|
|
prevIntervalWasZeroDur = PR_FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prevIntervalWasZeroDur = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
// Check for valid interval
|
|
|
|
if (tempEnd->Time() > zeroTime ||
|
|
|
|
(tempBegin->Time() == zeroTime && tempEnd->Time() == zeroTime)) {
|
|
|
|
aResult.Set(*tempBegin, *tempEnd);
|
2009-01-14 20:38:07 -08:00
|
|
|
return NS_OK;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
2010-01-28 01:51:03 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (mRestartMode == RESTART_NEVER) {
|
2009-08-04 19:39:04 -07:00
|
|
|
// tempEnd <= 0 so we're going to loop which effectively means restarting
|
2009-01-14 20:38:07 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
beginAfter = tempEnd->Time();
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
NS_NOTREACHED("Hmm... we really shouldn't be here");
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILInstanceTime*
|
|
|
|
nsSMILTimedElement::GetNextGreater(const InstanceTimeList& aList,
|
|
|
|
const nsSMILTimeValue& aBase,
|
|
|
|
PRInt32& aPosition) const
|
2009-08-04 19:39:04 -07:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILInstanceTime* result = nsnull;
|
|
|
|
while ((result = GetNextGreaterOrEqual(aList, aBase, aPosition)) &&
|
|
|
|
result->Time() == aBase);
|
|
|
|
return result;
|
2009-08-04 19:39:04 -07:00
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILInstanceTime*
|
|
|
|
nsSMILTimedElement::GetNextGreaterOrEqual(const InstanceTimeList& aList,
|
|
|
|
const nsSMILTimeValue& aBase,
|
|
|
|
PRInt32& aPosition) const
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILInstanceTime* result = nsnull;
|
2009-01-14 20:38:07 -08:00
|
|
|
PRInt32 count = aList.Length();
|
|
|
|
|
2010-01-12 12:00:49 -08: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-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
return result;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see SMILANIM 3.3.4
|
|
|
|
*/
|
|
|
|
nsSMILTimeValue
|
|
|
|
nsSMILTimedElement::CalcActiveEnd(const nsSMILTimeValue& aBegin,
|
2010-01-12 12:00:49 -08:00
|
|
|
const nsSMILTimeValue& aEnd) const
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
nsSMILTimeValue result;
|
|
|
|
|
2010-05-20 17:18:29 -07:00
|
|
|
NS_ABORT_IF_FALSE(mSimpleDur.IsResolved() || mSimpleDur.IsIndefinite(),
|
2010-01-28 01:50:30 -08:00
|
|
|
"Unresolved simple duration in CalcActiveEnd");
|
2010-05-20 17:18:29 -07:00
|
|
|
NS_ABORT_IF_FALSE(aBegin.IsResolved(),
|
|
|
|
"Unresolved begin time in CalcActiveEnd");
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-05-20 17:18:29 -07:00
|
|
|
if (mRepeatDur.IsIndefinite()) {
|
2009-01-14 20:38:07 -08:00
|
|
|
result.SetIndefinite();
|
|
|
|
} else {
|
|
|
|
result = GetRepeatDuration();
|
|
|
|
}
|
|
|
|
|
2010-05-20 17:18:29 -07:00
|
|
|
if (aEnd.IsResolved()) {
|
2009-01-14 20:38:07 -08:00
|
|
|
nsSMILTime activeDur = aEnd.GetMillis() - aBegin.GetMillis();
|
|
|
|
|
|
|
|
if (result.IsResolved()) {
|
2009-12-30 15:25:44 -08:00
|
|
|
result.SetMillis(NS_MIN(result.GetMillis(), activeDur));
|
2009-01-14 20:38:07 -08:00
|
|
|
} else {
|
|
|
|
result.SetMillis(activeDur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ApplyMinAndMax(result);
|
|
|
|
|
|
|
|
if (result.IsResolved()) {
|
|
|
|
nsSMILTime activeEnd = result.GetMillis() + aBegin.GetMillis();
|
|
|
|
result.SetMillis(activeEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimeValue
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::GetRepeatDuration() const
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
nsSMILTimeValue result;
|
|
|
|
|
|
|
|
if (mRepeatCount.IsDefinite() && mRepeatDur.IsResolved()) {
|
|
|
|
if (mSimpleDur.IsResolved()) {
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTime activeDur =
|
|
|
|
nsSMILTime(mRepeatCount * double(mSimpleDur.GetMillis()));
|
2009-12-30 15:25:44 -08:00
|
|
|
result.SetMillis(NS_MIN(activeDur, mRepeatDur.GetMillis()));
|
2009-01-14 20:38:07 -08:00
|
|
|
} else {
|
|
|
|
result = mRepeatDur;
|
|
|
|
}
|
|
|
|
} else if (mRepeatCount.IsDefinite() && mSimpleDur.IsResolved()) {
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTime activeDur =
|
|
|
|
nsSMILTime(mRepeatCount * double(mSimpleDur.GetMillis()));
|
2009-01-14 20:38:07 -08:00
|
|
|
result.SetMillis(activeDur);
|
|
|
|
} else if (mRepeatDur.IsResolved()) {
|
|
|
|
result = mRepeatDur;
|
|
|
|
} else if (mRepeatCount.IsIndefinite()) {
|
|
|
|
result.SetIndefinite();
|
|
|
|
} else {
|
|
|
|
result = mSimpleDur;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimeValue
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::ApplyMinAndMax(const nsSMILTimeValue& aDuration) const
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
if (!aDuration.IsResolved() && !aDuration.IsIndefinite()) {
|
|
|
|
return aDuration;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (mMax < mMin) {
|
2009-01-14 20:38:07 -08:00
|
|
|
return aDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimeValue result;
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (aDuration > mMax) {
|
2009-01-14 20:38:07 -08:00
|
|
|
result = mMax;
|
2010-01-12 12:00:49 -08:00
|
|
|
} else if (aDuration < mMin) {
|
2009-01-14 20:38:07 -08:00
|
|
|
nsSMILTimeValue repeatDur = GetRepeatDuration();
|
2010-01-12 12:00:49 -08:00
|
|
|
result = mMin > repeatDur ? repeatDur : mMin;
|
2009-01-14 20:38:07 -08:00
|
|
|
} else {
|
|
|
|
result = aDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTime
|
|
|
|
nsSMILTimedElement::ActiveTimeToSimpleTime(nsSMILTime aActiveTime,
|
|
|
|
PRUint32& aRepeatIteration)
|
|
|
|
{
|
|
|
|
nsSMILTime result;
|
|
|
|
|
|
|
|
NS_ASSERTION(mSimpleDur.IsResolved() || mSimpleDur.IsIndefinite(),
|
2009-01-19 01:10:53 -08:00
|
|
|
"Unresolved simple duration in ActiveTimeToSimpleTime");
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
if (mSimpleDur.IsIndefinite() || mSimpleDur.GetMillis() == 0L) {
|
|
|
|
aRepeatIteration = 0;
|
|
|
|
result = aActiveTime;
|
2009-07-15 11:33:31 -07:00
|
|
|
} else {
|
2009-01-14 20:38:07 -08:00
|
|
|
result = aActiveTime % mSimpleDur.GetMillis();
|
|
|
|
aRepeatIteration = (PRUint32)(aActiveTime / mSimpleDur.GetMillis());
|
|
|
|
}
|
|
|
|
|
|
|
|
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 12:00:49 -08:00
|
|
|
nsSMILInstanceTime*
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::CheckForEarlyEnd(
|
|
|
|
const nsSMILTimeValue& aContainerTime) const
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_ABORT_IF_FALSE(mCurrentInterval,
|
2010-01-12 12:00:49 -08:00
|
|
|
"Checking for an early end but the current interval is not set");
|
2009-01-14 20:38:07 -08:00
|
|
|
if (mRestartMode != RESTART_ALWAYS)
|
2010-01-12 12:00:49 -08:00
|
|
|
return nsnull;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
PRInt32 position = 0;
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILInstanceTime* nextBegin =
|
2010-03-01 11:31:50 -08:00
|
|
|
GetNextGreater(mBeginInstances, mCurrentInterval->Begin()->Time(),
|
|
|
|
position);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (nextBegin &&
|
2010-03-01 11:31:50 -08:00
|
|
|
nextBegin->Time() > mCurrentInterval->Begin()->Time() &&
|
|
|
|
nextBegin->Time() < mCurrentInterval->End()->Time() &&
|
2010-01-12 12:00:49 -08:00
|
|
|
nextBegin->Time() <= aContainerTime) {
|
2010-01-12 12:00:49 -08:00
|
|
|
return nextBegin;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
return nsnull;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimedElement::UpdateCurrentInterval(PRBool aForceChangeNotice)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08: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 12:00:49 -08: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 12:00:49 -08:00
|
|
|
// document timeline begins since the start time has not yet been resolved.
|
2010-01-12 12:00:49 -08:00
|
|
|
if (mElementState == STATE_STARTUP)
|
|
|
|
return;
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
// If the interval is active the begin time is fixed.
|
|
|
|
const nsSMILInstanceTime* beginTime = mElementState == STATE_ACTIVE
|
2010-03-01 11:31:50 -08:00
|
|
|
? mCurrentInterval->Begin()
|
2010-01-12 12:00:49 -08:00
|
|
|
: nsnull;
|
2009-01-14 20:38:07 -08:00
|
|
|
nsSMILInterval updatedInterval;
|
2010-03-01 11:31:50 -08:00
|
|
|
nsresult rv =
|
|
|
|
GetNextInterval(GetPreviousInterval(), beginTime, updatedInterval);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (mElementState == STATE_POSTACTIVE) {
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_ABORT_IF_FALSE(!mCurrentInterval,
|
2010-01-12 12:00:49 -08:00
|
|
|
"In postactive state but the interval has been set");
|
2010-03-01 11:31:50 -08:00
|
|
|
mCurrentInterval = new nsSMILInterval(updatedInterval);
|
2010-01-12 12:00:49 -08:00
|
|
|
mElementState = STATE_WAITING;
|
|
|
|
NotifyNewInterval();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
PRBool changed = PR_FALSE;
|
|
|
|
|
|
|
|
if (mElementState != STATE_ACTIVE &&
|
2010-03-01 11:31:50 -08:00
|
|
|
!updatedInterval.Begin()->SameTimeAndBase(
|
|
|
|
*mCurrentInterval->Begin())) {
|
|
|
|
mCurrentInterval->SetBegin(*updatedInterval.Begin());
|
2010-01-12 12:00:49 -08:00
|
|
|
changed = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
if (!updatedInterval.End()->SameTimeAndBase(*mCurrentInterval->End())) {
|
|
|
|
mCurrentInterval->SetEnd(*updatedInterval.End());
|
2010-01-12 12:00:49 -08:00
|
|
|
changed = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed || aForceChangeNotice) {
|
|
|
|
NotifyChangedInterval();
|
|
|
|
}
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
// There's a chance our next milestone has now changed, so update the time
|
|
|
|
// container
|
|
|
|
RegisterMilestone();
|
2009-01-14 20:38:07 -08:00
|
|
|
} else {
|
2010-01-12 12:00:49 -08:00
|
|
|
if (mElementState == STATE_ACTIVE && mClient) {
|
2010-01-13 00:18:51 -08:00
|
|
|
// Only apply a fill if it was already being applied before the (now
|
|
|
|
// deleted) interval was created
|
2010-03-01 11:31:50 -08:00
|
|
|
PRBool applyFill = HasPlayed() && mFillMode == FILL_FREEZE;
|
2010-01-13 00:18:51 -08:00
|
|
|
mClient->Inactivate(applyFill);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (mElementState == STATE_ACTIVE || mElementState == STATE_WAITING) {
|
2009-01-14 20:38:07 -08:00
|
|
|
mElementState = STATE_POSTACTIVE;
|
2010-07-02 22:52:50 -07:00
|
|
|
mCurrentInterval->Unlink();
|
2010-03-01 11:31:50 -08:00
|
|
|
mCurrentInterval = nsnull;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::SampleSimpleTime(nsSMILTime aActiveTime)
|
|
|
|
{
|
|
|
|
if (mClient) {
|
|
|
|
PRUint32 repeatIteration;
|
2009-07-15 11:33:31 -07:00
|
|
|
nsSMILTime simpleTime =
|
2009-01-14 20:38:07 -08:00
|
|
|
ActiveTimeToSimpleTime(aActiveTime, repeatIteration);
|
|
|
|
mClient->SampleAt(simpleTime, mSimpleDur, repeatIteration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::SampleFillValue()
|
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
if (mFillMode != FILL_FREEZE || !mClient)
|
2009-01-14 20:38:07 -08:00
|
|
|
return;
|
|
|
|
|
2010-03-01 11:31:52 -08:00
|
|
|
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().IsResolved() &&
|
2010-07-02 22:52:50 -07:00
|
|
|
prevInterval->End()->IsFixedTime(),
|
2010-01-12 12:00:49 -08:00
|
|
|
"Attempting to sample fill value but the endpoint of the previous "
|
2010-07-02 22:52:50 -07:00
|
|
|
"interval is not resolved and fixed");
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-03-01 11:31:52 -08:00
|
|
|
nsSMILTime activeTime = prevInterval->End()->Time().GetMillis() -
|
|
|
|
prevInterval->Begin()->Time().GetMillis();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
PRUint32 repeatIteration;
|
2009-07-15 11:33:31 -07:00
|
|
|
nsSMILTime simpleTime =
|
2009-01-14 20:38:07 -08:00
|
|
|
ActiveTimeToSimpleTime(activeTime, repeatIteration);
|
|
|
|
|
2009-08-04 19:39:04 -07:00
|
|
|
if (simpleTime == 0L && repeatIteration) {
|
2009-01-14 20:38:07 -08:00
|
|
|
mClient->SampleLastValue(--repeatIteration);
|
|
|
|
} else {
|
|
|
|
mClient->SampleAt(simpleTime, mSimpleDur, repeatIteration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-21 17:00:27 -08:00
|
|
|
void
|
|
|
|
nsSMILTimedElement::AddInstanceTimeFromCurrentTime(nsSMILTime aCurrentTime,
|
|
|
|
double aOffsetSeconds, PRBool aIsBegin)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
double offset = aOffsetSeconds * PR_MSEC_PER_SEC;
|
2009-01-21 17:00:27 -08:00
|
|
|
nsSMILTime timeWithOffset = aCurrentTime + PRInt64(NS_round(offset));
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimeValue timeVal(timeWithOffset);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
// XXX If we re-use this method for event-based timing we'll need to change it
|
|
|
|
// so we don't end up setting SOURCE_DOM for event-based times.
|
|
|
|
nsRefPtr<nsSMILInstanceTime> instanceTime =
|
2010-03-01 11:31:50 -08:00
|
|
|
new nsSMILInstanceTime(timeVal, nsSMILInstanceTime::SOURCE_DOM);
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
AddInstanceTime(instanceTime, aIsBegin);
|
|
|
|
}
|
2010-01-12 12:00:49 -08: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSMILTimedElement::GetNextMilestone(nsSMILMilestone& aNextMilestone) const
|
|
|
|
{
|
|
|
|
// Return the next key moment in our lifetime.
|
|
|
|
//
|
|
|
|
// XXX Once we implement TimeEvents and event based timing we might need to
|
|
|
|
// include repeat times too, particularly if it's important to get them in
|
|
|
|
// order.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
aNextMilestone.mIsEnd = PR_TRUE; // Initial sample should be an end sample
|
|
|
|
aNextMilestone.mTime = 0;
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
case STATE_WAITING:
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_ABORT_IF_FALSE(mCurrentInterval,
|
2010-01-12 12:00:49 -08:00
|
|
|
"In waiting state but the current interval has not been set");
|
2010-01-12 12:00:49 -08:00
|
|
|
aNextMilestone.mIsEnd = PR_FALSE;
|
2010-03-01 11:31:50 -08:00
|
|
|
aNextMilestone.mTime = mCurrentInterval->Begin()->Time().GetMillis();
|
2010-01-12 12:00:49 -08:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
case STATE_ACTIVE:
|
|
|
|
{
|
|
|
|
// XXX When we implement TimeEvents, we may need to consider what comes
|
|
|
|
// next: the interval end or an interval repeat.
|
|
|
|
|
|
|
|
// Check for an early end
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILInstanceTime* earlyEnd =
|
2010-03-01 11:31:50 -08:00
|
|
|
CheckForEarlyEnd(mCurrentInterval->End()->Time());
|
2010-01-12 12:00:49 -08:00
|
|
|
if (earlyEnd) {
|
2010-01-12 12:00:49 -08:00
|
|
|
aNextMilestone.mIsEnd = PR_TRUE;
|
2010-01-12 12:00:49 -08:00
|
|
|
aNextMilestone.mTime = earlyEnd->Time().GetMillis();
|
2010-01-12 12:00:49 -08:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise it's just the next interval end
|
2010-03-01 11:31:50 -08:00
|
|
|
if (mCurrentInterval->End()->Time().IsResolved()) {
|
2010-01-12 12:00:49 -08:00
|
|
|
aNextMilestone.mIsEnd = PR_TRUE;
|
2010-03-01 11:31:50 -08:00
|
|
|
aNextMilestone.mTime = mCurrentInterval->End()->Time().GetMillis();
|
2010-01-12 12:00:49 -08:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case STATE_POSTACTIVE:
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ABORT_IF_FALSE(PR_FALSE, "Invalid element state");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::NotifyNewInterval()
|
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_ABORT_IF_FALSE(mCurrentInterval,
|
2010-01-12 12:00:49 -08:00
|
|
|
"Attempting to notify dependents of a new interval but the interval "
|
|
|
|
"is not set");
|
|
|
|
|
|
|
|
nsSMILTimeContainer* container = GetTimeContainer();
|
|
|
|
if (container) {
|
|
|
|
container->SyncPauseTime();
|
|
|
|
}
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
NotifyTimeDependentsParams params = { mCurrentInterval, container };
|
2010-01-12 12:00:49 -08:00
|
|
|
mTimeDependents.EnumerateEntries(NotifyNewIntervalCallback, ¶ms);
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimedElement::NotifyChangedInterval()
|
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_ABORT_IF_FALSE(mCurrentInterval,
|
2010-01-12 12:00:49 -08:00
|
|
|
"Attempting to notify dependents of a changed interval but the interval "
|
|
|
|
"is not set--perhaps we should be deleting the interval instead?");
|
|
|
|
|
|
|
|
nsSMILTimeContainer* container = GetTimeContainer();
|
|
|
|
if (container) {
|
|
|
|
container->SyncPauseTime();
|
|
|
|
}
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
mCurrentInterval->NotifyChanged(container);
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsSMILInstanceTime*
|
|
|
|
nsSMILTimedElement::GetEffectiveBeginInstance() const
|
|
|
|
{
|
|
|
|
switch (mElementState)
|
|
|
|
{
|
|
|
|
case STATE_STARTUP:
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
case STATE_ACTIVE:
|
2010-03-01 11:31:50 -08:00
|
|
|
return mCurrentInterval->Begin();
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
case STATE_WAITING:
|
|
|
|
case STATE_POSTACTIVE:
|
2010-03-01 11:31:50 -08:00
|
|
|
{
|
|
|
|
const nsSMILInterval* prevInterval = GetPreviousInterval();
|
|
|
|
return prevInterval ? prevInterval->Begin() : nsnull;
|
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Invalid element state");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
const nsSMILInterval*
|
|
|
|
nsSMILTimedElement::GetPreviousInterval() const
|
|
|
|
{
|
|
|
|
return mOldIntervals.IsEmpty()
|
|
|
|
? nsnull
|
|
|
|
: mOldIntervals[mOldIntervals.Length()-1].get();
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Hashtable callback functions
|
|
|
|
|
|
|
|
/* static */ PR_CALLBACK PLDHashOperator
|
|
|
|
nsSMILTimedElement::NotifyNewIntervalCallback(TimeValueSpecPtrKey* aKey,
|
|
|
|
void* aData)
|
|
|
|
{
|
2010-03-01 11:31:50 -08: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 12:00:49 -08:00
|
|
|
|
|
|
|
NotifyTimeDependentsParams* params =
|
|
|
|
static_cast<NotifyTimeDependentsParams*>(aData);
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_ABORT_IF_FALSE(params, "null data ptr while enumerating hashtable");
|
|
|
|
NS_ABORT_IF_FALSE(params->mCurrentInterval, "null current-interval ptr");
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
nsSMILTimeValueSpec* spec = aKey->GetKey();
|
2010-03-01 11:31:50 -08:00
|
|
|
spec->HandleNewInterval(*params->mCurrentInterval, params->mTimeContainer);
|
2010-01-12 12:00:49 -08:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|