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) 2005
|
|
|
|
* 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 "nsSMILInstanceTime.h"
|
2010-03-01 11:31:50 -08:00
|
|
|
#include "nsSMILInterval.h"
|
|
|
|
#include "nsSMILTimeValueSpec.h"
|
2011-07-19 03:04:55 -07:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2010-03-01 11:31:50 -08:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
nsSMILInstanceTime::nsSMILInstanceTime(const nsSMILTimeValue& aTime,
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILInstanceTimeSource aSource,
|
|
|
|
nsSMILTimeValueSpec* aCreator,
|
|
|
|
nsSMILInterval* aBaseInterval)
|
|
|
|
: mTime(aTime),
|
|
|
|
mFlags(0),
|
|
|
|
mVisited(PR_FALSE),
|
2010-07-02 22:52:50 -07:00
|
|
|
mFixedEndpointRefCnt(0),
|
|
|
|
mSerial(0),
|
2010-03-01 11:31:50 -08:00
|
|
|
mCreator(aCreator),
|
2010-03-01 11:31:52 -08:00
|
|
|
mBaseInterval(nsnull) // This will get set to aBaseInterval in a call to
|
|
|
|
// SetBaseInterval() at end of constructor
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
|
|
|
switch (aSource) {
|
|
|
|
case SOURCE_NONE:
|
|
|
|
// No special flags
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOURCE_DOM:
|
2010-07-02 22:52:50 -07:00
|
|
|
mFlags = kDynamic | kFromDOM;
|
2010-01-12 12:00:49 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SOURCE_SYNCBASE:
|
|
|
|
mFlags = kMayUpdate;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOURCE_EVENT:
|
2010-07-02 22:52:50 -07:00
|
|
|
mFlags = kDynamic;
|
2010-01-12 12:00:49 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
SetBaseInterval(aBaseInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILInstanceTime::~nsSMILInstanceTime()
|
|
|
|
{
|
2010-08-18 03:20:24 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mBaseInterval,
|
2010-03-01 11:31:50 -08:00
|
|
|
"Destroying instance time without first calling Unlink()");
|
2010-07-02 22:52:50 -07:00
|
|
|
NS_ABORT_IF_FALSE(mFixedEndpointRefCnt == 0,
|
|
|
|
"Destroying instance time that is still used as the fixed endpoint of an "
|
|
|
|
"interval");
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILInstanceTime::Unlink()
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
nsRefPtr<nsSMILInstanceTime> deathGrip(this);
|
|
|
|
if (mBaseInterval) {
|
|
|
|
mBaseInterval->RemoveDependentTime(*this);
|
|
|
|
mBaseInterval = nsnull;
|
|
|
|
}
|
|
|
|
mCreator = nsnull;
|
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
void
|
|
|
|
nsSMILInstanceTime::HandleChangedInterval(
|
|
|
|
const nsSMILTimeContainer* aSrcContainer,
|
|
|
|
PRBool aBeginObjectChanged,
|
|
|
|
PRBool aEndObjectChanged)
|
|
|
|
{
|
2011-06-14 17:16:57 -07:00
|
|
|
// It's possible a sequence of notifications might cause our base interval to
|
|
|
|
// be updated and then deleted. Furthermore, the delete might happen whilst
|
|
|
|
// we're still in the queue to be notified of the change. In any case, if we
|
|
|
|
// don't have a base interval, just ignore the change.
|
|
|
|
if (!mBaseInterval)
|
|
|
|
return;
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_ABORT_IF_FALSE(mCreator, "Base interval is set but creator is not.");
|
|
|
|
|
2010-07-02 22:52:50 -07:00
|
|
|
if (mVisited) {
|
|
|
|
// Break the cycle here
|
|
|
|
Unlink();
|
2010-03-01 11:31:50 -08:00
|
|
|
return;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
2010-03-01 11:31:52 -08:00
|
|
|
PRBool objectChanged = mCreator->DependsOnBegin() ? aBeginObjectChanged :
|
|
|
|
aEndObjectChanged;
|
|
|
|
|
2011-07-19 03:04:55 -07:00
|
|
|
mozilla::AutoRestore<PRPackedBool> setVisited(mVisited);
|
|
|
|
mVisited = PR_TRUE;
|
2010-03-01 11:31:50 -08:00
|
|
|
|
|
|
|
nsRefPtr<nsSMILInstanceTime> deathGrip(this);
|
|
|
|
mCreator->HandleChangedInstanceTime(*GetBaseTime(), aSrcContainer, *this,
|
|
|
|
objectChanged);
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILInstanceTime::HandleDeletedInterval()
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
NS_ABORT_IF_FALSE(mBaseInterval,
|
2010-07-02 22:52:50 -07:00
|
|
|
"Got call to HandleDeletedInterval on an independent instance time");
|
|
|
|
NS_ABORT_IF_FALSE(mCreator, "Base interval is set but creator is not");
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
mBaseInterval = nsnull;
|
2010-07-02 22:52:50 -07:00
|
|
|
mFlags &= ~kMayUpdate; // Can't update without a base interval
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
nsRefPtr<nsSMILInstanceTime> deathGrip(this);
|
|
|
|
mCreator->HandleDeletedInstanceTime(*this);
|
|
|
|
mCreator = nsnull;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-07-02 22:52:50 -07:00
|
|
|
void
|
|
|
|
nsSMILInstanceTime::HandleFilteredInterval()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mBaseInterval,
|
|
|
|
"Got call to HandleFilteredInterval on an independent instance time");
|
|
|
|
|
|
|
|
mBaseInterval = nsnull;
|
|
|
|
mFlags &= ~kMayUpdate; // Can't update without a base interval
|
|
|
|
mCreator = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-07-02 22:52:51 -07:00
|
|
|
PRBool
|
|
|
|
nsSMILInstanceTime::ShouldPreserve() const
|
|
|
|
{
|
|
|
|
return mFixedEndpointRefCnt > 0 || (mFlags & kWasDynamicEndpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILInstanceTime::UnmarkShouldPreserve()
|
|
|
|
{
|
|
|
|
mFlags &= ~kWasDynamicEndpoint;
|
|
|
|
}
|
|
|
|
|
2010-07-02 22:52:50 -07:00
|
|
|
void
|
|
|
|
nsSMILInstanceTime::AddRefFixedEndpoint()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mFixedEndpointRefCnt < PR_UINT16_MAX,
|
|
|
|
"Fixed endpoint reference count upper limit reached");
|
|
|
|
++mFixedEndpointRefCnt;
|
|
|
|
mFlags &= ~kMayUpdate; // Once fixed, always fixed
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILInstanceTime::ReleaseFixedEndpoint()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mFixedEndpointRefCnt > 0, "Duplicate release");
|
|
|
|
--mFixedEndpointRefCnt;
|
2010-07-02 22:52:51 -07:00
|
|
|
if (mFixedEndpointRefCnt == 0 && IsDynamic()) {
|
|
|
|
mFlags |= kWasDynamicEndpoint;
|
|
|
|
}
|
2010-07-02 22:52:50 -07:00
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
PRBool
|
2010-07-02 22:52:50 -07:00
|
|
|
nsSMILInstanceTime::IsDependentOn(const nsSMILInstanceTime& aOther) const
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-07-02 22:52:50 -07:00
|
|
|
if (mVisited)
|
2010-05-28 05:43:17 -07:00
|
|
|
return PR_FALSE;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
const nsSMILInstanceTime* myBaseTime = GetBaseTime();
|
|
|
|
if (!myBaseTime)
|
2010-01-12 12:00:49 -08:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
if (myBaseTime == &aOther)
|
2010-01-12 12:00:49 -08:00
|
|
|
return PR_TRUE;
|
|
|
|
|
2010-05-28 05:43:17 -07:00
|
|
|
// mVisited is mutable
|
2011-07-19 03:04:55 -07:00
|
|
|
mozilla::AutoRestore<PRPackedBool> setVisited(const_cast<nsSMILInstanceTime*>(this)->mVisited);
|
|
|
|
const_cast<nsSMILInstanceTime*>(this)->mVisited = PR_TRUE;
|
2010-07-02 22:52:50 -07:00
|
|
|
return myBaseTime->IsDependentOn(aOther);
|
2010-03-01 11:31:50 -08:00
|
|
|
}
|
|
|
|
|
2011-06-21 18:12:35 -07:00
|
|
|
const nsSMILInstanceTime*
|
|
|
|
nsSMILInstanceTime::GetBaseTime() const
|
|
|
|
{
|
|
|
|
if (!mBaseInterval) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(mCreator, "Base interval is set but there is no creator.");
|
|
|
|
if (!mCreator) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mCreator->DependsOnBegin() ? mBaseInterval->Begin() :
|
|
|
|
mBaseInterval->End();
|
|
|
|
}
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
void
|
|
|
|
nsSMILInstanceTime::SetBaseInterval(nsSMILInterval* aBaseInterval)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!mBaseInterval,
|
2010-05-20 17:18:29 -07:00
|
|
|
"Attempting to reassociate an instance time with a different interval.");
|
2010-03-01 11:31:50 -08:00
|
|
|
|
|
|
|
if (aBaseInterval) {
|
|
|
|
NS_ABORT_IF_FALSE(mCreator,
|
|
|
|
"Attempting to create a dependent instance time without reference "
|
|
|
|
"to the creating nsSMILTimeValueSpec object.");
|
|
|
|
if (!mCreator)
|
|
|
|
return;
|
|
|
|
|
|
|
|
aBaseInterval->AddDependentTime(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
mBaseInterval = aBaseInterval;
|
|
|
|
}
|