2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-01 22:31:50 +03:00
|
|
|
|
2019-01-21 16:08:12 +03:00
|
|
|
#include "SMILInterval.h"
|
2010-03-01 22:31:50 +03:00
|
|
|
|
2019-01-21 16:08:12 +03:00
|
|
|
namespace mozilla {
|
2010-03-01 22:31:50 +03:00
|
|
|
|
2019-01-21 16:08:12 +03:00
|
|
|
SMILInterval::SMILInterval() : mBeginFixed(false), mEndFixed(false) {}
|
|
|
|
|
|
|
|
SMILInterval::SMILInterval(const SMILInterval& aOther)
|
2010-03-01 22:31:50 +03:00
|
|
|
: mBegin(aOther.mBegin),
|
|
|
|
mEnd(aOther.mEnd),
|
2011-10-17 18:59:28 +04:00
|
|
|
mBeginFixed(false),
|
|
|
|
mEndFixed(false) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aOther.mDependentTimes.IsEmpty(),
|
|
|
|
"Attempt 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.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!aOther.mBeginFixed && !aOther.mEndFixed,
|
|
|
|
"Attempt to copy-construct an interval with fixed endpoints");
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 16:08:12 +03:00
|
|
|
SMILInterval::~SMILInterval() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mDependentTimes.IsEmpty(),
|
|
|
|
"Destroying interval without disassociating dependent instance "
|
|
|
|
"times. Unlink was not called");
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 16:08:12 +03:00
|
|
|
void SMILInterval::Unlink(bool aFiltered) {
|
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
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
SMILInstanceTime* SMILInterval::Begin() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mBegin && mEnd, "Requesting Begin() on un-initialized interval.");
|
2010-03-01 22:31:50 +03:00
|
|
|
return mBegin;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
SMILInstanceTime* SMILInterval::End() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mBegin && mEnd, "Requesting End() on un-initialized interval.");
|
2010-03-01 22:31:50 +03:00
|
|
|
return mEnd;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
void SMILInterval::SetBegin(SMILInstanceTime& aBegin) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aBegin.Time().IsDefinite(),
|
|
|
|
"Attempt to set unresolved or indefinite begin time on interval");
|
|
|
|
MOZ_ASSERT(!mBeginFixed,
|
|
|
|
"Attempt 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.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mBegin || aBegin.GetBaseTime() != mBegin,
|
|
|
|
"Attempt to make self-dependent instance time");
|
2010-03-01 22:31:50 +03:00
|
|
|
|
|
|
|
mBegin = &aBegin;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
void SMILInterval::SetEnd(SMILInstanceTime& aEnd) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mEndFixed, "Attempt 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.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!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;
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:08:12 +03:00
|
|
|
void SMILInterval::FixBegin() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mBegin && mEnd, "Fixing begin point on un-initialized interval");
|
|
|
|
MOZ_ASSERT(!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();
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:08:12 +03:00
|
|
|
void SMILInterval::FixEnd() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mBegin && mEnd, "Fixing end point on un-initialized interval");
|
|
|
|
MOZ_ASSERT(mBeginFixed,
|
|
|
|
"Fixing the end of an interval without a fixed begin");
|
|
|
|
MOZ_ASSERT(!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();
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
void SMILInterval::AddDependentTime(SMILInstanceTime& aTime) {
|
|
|
|
RefPtr<SMILInstanceTime>* inserted =
|
2010-03-01 22:31:50 +03:00
|
|
|
mDependentTimes.InsertElementSorted(&aTime);
|
|
|
|
if (!inserted) {
|
|
|
|
NS_WARNING("Insufficient memory to insert instance time.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
void SMILInterval::RemoveDependentTime(const SMILInstanceTime& 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);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(found, "Couldn't find instance time to delete.");
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
2010-07-03 09:52:50 +04:00
|
|
|
|
2019-01-21 16:08:12 +03:00
|
|
|
void SMILInterval::GetDependentTimes(InstanceTimeList& aTimes) {
|
2011-06-15 04:16:57 +04:00
|
|
|
aTimes = mDependentTimes;
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:08:12 +03:00
|
|
|
bool SMILInterval::IsDependencyChainLink() const {
|
2010-07-03 09:52:50 +04:00
|
|
|
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
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
if (mDependentTimes.IsEmpty()) 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);
|
|
|
|
}
|
2019-01-21 16:08:12 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|