2010-03-01 22:31:50 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-01 22:31:50 +03:00
|
|
|
|
|
|
|
#include "nsSMILInterval.h"
|
|
|
|
|
|
|
|
nsSMILInterval::nsSMILInterval()
|
|
|
|
:
|
2011-10-17 18:59:28 +04:00
|
|
|
mBeginFixed(false),
|
|
|
|
mEndFixed(false)
|
2010-03-01 22:31:50 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILInterval::nsSMILInterval(const nsSMILInterval& aOther)
|
|
|
|
:
|
|
|
|
mBegin(aOther.mBegin),
|
|
|
|
mEnd(aOther.mEnd),
|
2011-10-17 18:59:28 +04:00
|
|
|
mBeginFixed(false),
|
|
|
|
mEndFixed(false)
|
2010-03-01 22:31:50 +03:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aOther.mDependentTimes.IsEmpty(),
|
|
|
|
"Attempting to copy-construct an interval with dependent times, "
|
|
|
|
"this will lead to instance times being shared between intervals.");
|
2010-07-03 09:52:50 +04:00
|
|
|
|
|
|
|
// For the time being we don't allow intervals with fixed endpoints to be
|
|
|
|
// copied since we only ever copy-construct to establish a new current
|
|
|
|
// interval. If we ever need to copy historical intervals we may need to move
|
|
|
|
// the ReleaseFixedEndpoint calls from Unlink to the dtor.
|
|
|
|
NS_ABORT_IF_FALSE(!aOther.mBeginFixed && !aOther.mEndFixed,
|
|
|
|
"Attempting to copy-construct an interval with fixed endpoints");
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILInterval::~nsSMILInterval()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mDependentTimes.IsEmpty(),
|
|
|
|
"Destroying interval without disassociating dependent instance times. "
|
2010-07-03 09:52:50 +04:00
|
|
|
"Unlink was not called");
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSMILInterval::Unlink(bool aFiltered)
|
2010-03-01 22:31:50 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = mDependentTimes.Length() - 1; i >= 0; --i) {
|
2010-07-03 09:52:50 +04:00
|
|
|
if (aFiltered) {
|
|
|
|
mDependentTimes[i]->HandleFilteredInterval();
|
|
|
|
} else {
|
|
|
|
mDependentTimes[i]->HandleDeletedInterval();
|
|
|
|
}
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
|
|
|
mDependentTimes.Clear();
|
2010-07-03 09:52:50 +04:00
|
|
|
if (mBegin && mBeginFixed) {
|
|
|
|
mBegin->ReleaseFixedEndpoint();
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mBegin = nullptr;
|
2010-07-03 09:52:50 +04:00
|
|
|
if (mEnd && mEndFixed) {
|
|
|
|
mEnd->ReleaseFixedEndpoint();
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mEnd = nullptr;
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILInstanceTime*
|
|
|
|
nsSMILInterval::Begin()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mBegin && mEnd,
|
2010-05-21 04:18:29 +04:00
|
|
|
"Requesting Begin() on un-initialized interval.");
|
2010-03-01 22:31:50 +03:00
|
|
|
return mBegin;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILInstanceTime*
|
|
|
|
nsSMILInterval::End()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mBegin && mEnd,
|
2010-05-21 04:18:29 +04:00
|
|
|
"Requesting End() on un-initialized interval.");
|
2010-03-01 22:31:50 +03:00
|
|
|
return mEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILInterval::SetBegin(nsSMILInstanceTime& aBegin)
|
|
|
|
{
|
2011-09-07 04:20:40 +04:00
|
|
|
NS_ABORT_IF_FALSE(aBegin.Time().IsDefinite(),
|
2011-09-07 04:20:40 +04:00
|
|
|
"Attempting to set unresolved or indefinite begin time on interval");
|
2010-07-03 09:52:50 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mBeginFixed,
|
|
|
|
"Attempting to set begin time but the begin point is fixed");
|
2011-06-22 05:12:35 +04:00
|
|
|
// Check that we're not making an instance time dependent on itself. Such an
|
|
|
|
// arrangement does not make intuitive sense and should be detected when
|
|
|
|
// creating or updating intervals.
|
|
|
|
NS_ABORT_IF_FALSE(!mBegin || aBegin.GetBaseTime() != mBegin,
|
|
|
|
"Attempting to make self-dependent instance time");
|
2010-03-01 22:31:50 +03:00
|
|
|
|
|
|
|
mBegin = &aBegin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILInterval::SetEnd(nsSMILInstanceTime& aEnd)
|
|
|
|
{
|
2010-07-03 09:52:50 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mEndFixed,
|
|
|
|
"Attempting to set end time but the end point is fixed");
|
2011-06-22 05:12:35 +04:00
|
|
|
// As with SetBegin, check we're not making an instance time dependent on
|
|
|
|
// itself.
|
|
|
|
NS_ABORT_IF_FALSE(!mEnd || aEnd.GetBaseTime() != mEnd,
|
|
|
|
"Attempting to make self-dependent instance time");
|
2010-07-03 09:52:50 +04:00
|
|
|
|
2010-03-01 22:31:50 +03:00
|
|
|
mEnd = &aEnd;
|
|
|
|
}
|
|
|
|
|
2010-07-03 09:52:50 +04:00
|
|
|
void
|
|
|
|
nsSMILInterval::FixBegin()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mBegin && mEnd,
|
|
|
|
"Fixing begin point on un-initialized interval");
|
|
|
|
NS_ABORT_IF_FALSE(!mBeginFixed, "Duplicate calls to FixBegin()");
|
2011-10-17 18:59:28 +04:00
|
|
|
mBeginFixed = true;
|
2010-07-03 09:52:50 +04:00
|
|
|
mBegin->AddRefFixedEndpoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILInterval::FixEnd()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mBegin && mEnd,
|
|
|
|
"Fixing end point on un-initialized interval");
|
|
|
|
NS_ABORT_IF_FALSE(mBeginFixed,
|
|
|
|
"Fixing the end of an interval without a fixed begin");
|
|
|
|
NS_ABORT_IF_FALSE(!mEndFixed, "Duplicate calls to FixEnd()");
|
2011-10-17 18:59:28 +04:00
|
|
|
mEndFixed = true;
|
2010-07-03 09:52:50 +04:00
|
|
|
mEnd->AddRefFixedEndpoint();
|
|
|
|
}
|
|
|
|
|
2010-03-01 22:31:50 +03:00
|
|
|
void
|
|
|
|
nsSMILInterval::AddDependentTime(nsSMILInstanceTime& aTime)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsSMILInstanceTime>* inserted =
|
|
|
|
mDependentTimes.InsertElementSorted(&aTime);
|
|
|
|
if (!inserted) {
|
|
|
|
NS_WARNING("Insufficient memory to insert instance time.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILInterval::RemoveDependentTime(const nsSMILInstanceTime& aTime)
|
|
|
|
{
|
2010-03-01 22:31:52 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found =
|
2010-03-01 22:31:52 +03:00
|
|
|
#endif
|
|
|
|
mDependentTimes.RemoveElementSorted(&aTime);
|
2010-03-01 22:31:50 +03:00
|
|
|
NS_ABORT_IF_FALSE(found, "Couldn't find instance time to delete.");
|
|
|
|
}
|
2010-07-03 09:52:50 +04:00
|
|
|
|
2011-06-15 04:16:57 +04:00
|
|
|
void
|
|
|
|
nsSMILInterval::GetDependentTimes(InstanceTimeList& aTimes)
|
|
|
|
{
|
|
|
|
aTimes = mDependentTimes;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-07-03 09:52:50 +04:00
|
|
|
nsSMILInterval::IsDependencyChainLink() const
|
|
|
|
{
|
|
|
|
if (!mBegin || !mEnd)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // Not yet initialised so it can't be part of a chain
|
2010-07-03 09:52:50 +04:00
|
|
|
|
|
|
|
if (mDependentTimes.IsEmpty())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // No dependents, chain end
|
2010-07-03 09:52:50 +04:00
|
|
|
|
|
|
|
// So we have dependents, but we're still only a link in the chain (as opposed
|
|
|
|
// to the end of the chain) if one of our endpoints is dependent on an
|
|
|
|
// interval other than ourselves.
|
|
|
|
return (mBegin->IsDependent() && mBegin->GetBaseInterval() != this) ||
|
|
|
|
(mEnd->IsDependent() && mEnd->GetBaseInterval() != this);
|
|
|
|
}
|