Backed out changeset 58dbd2146e24 (bug 944961) for bustage.
[gecko.git] / content / smil / nsSMILInterval.cpp
bloba2324c1f21b31cdd01341070beeec4012d7d9d39
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsSMILInterval.h"
8 nsSMILInterval::nsSMILInterval()
10 mBeginFixed(false),
11 mEndFixed(false)
15 nsSMILInterval::nsSMILInterval(const nsSMILInterval& aOther)
17 mBegin(aOther.mBegin),
18 mEnd(aOther.mEnd),
19 mBeginFixed(false),
20 mEndFixed(false)
22 NS_ABORT_IF_FALSE(aOther.mDependentTimes.IsEmpty(),
23 "Attempting to copy-construct an interval with dependent times, "
24 "this will lead to instance times being shared between intervals.");
26 // For the time being we don't allow intervals with fixed endpoints to be
27 // copied since we only ever copy-construct to establish a new current
28 // interval. If we ever need to copy historical intervals we may need to move
29 // the ReleaseFixedEndpoint calls from Unlink to the dtor.
30 NS_ABORT_IF_FALSE(!aOther.mBeginFixed && !aOther.mEndFixed,
31 "Attempting to copy-construct an interval with fixed endpoints");
34 nsSMILInterval::~nsSMILInterval()
36 NS_ABORT_IF_FALSE(mDependentTimes.IsEmpty(),
37 "Destroying interval without disassociating dependent instance times. "
38 "Unlink was not called");
41 void
42 nsSMILInterval::Unlink(bool aFiltered)
44 for (int32_t i = mDependentTimes.Length() - 1; i >= 0; --i) {
45 if (aFiltered) {
46 mDependentTimes[i]->HandleFilteredInterval();
47 } else {
48 mDependentTimes[i]->HandleDeletedInterval();
51 mDependentTimes.Clear();
52 if (mBegin && mBeginFixed) {
53 mBegin->ReleaseFixedEndpoint();
55 mBegin = nullptr;
56 if (mEnd && mEndFixed) {
57 mEnd->ReleaseFixedEndpoint();
59 mEnd = nullptr;
62 nsSMILInstanceTime*
63 nsSMILInterval::Begin()
65 NS_ABORT_IF_FALSE(mBegin && mEnd,
66 "Requesting Begin() on un-initialized interval.");
67 return mBegin;
70 nsSMILInstanceTime*
71 nsSMILInterval::End()
73 NS_ABORT_IF_FALSE(mBegin && mEnd,
74 "Requesting End() on un-initialized interval.");
75 return mEnd;
78 void
79 nsSMILInterval::SetBegin(nsSMILInstanceTime& aBegin)
81 NS_ABORT_IF_FALSE(aBegin.Time().IsDefinite(),
82 "Attempting to set unresolved or indefinite begin time on interval");
83 NS_ABORT_IF_FALSE(!mBeginFixed,
84 "Attempting to set begin time but the begin point is fixed");
85 // Check that we're not making an instance time dependent on itself. Such an
86 // arrangement does not make intuitive sense and should be detected when
87 // creating or updating intervals.
88 NS_ABORT_IF_FALSE(!mBegin || aBegin.GetBaseTime() != mBegin,
89 "Attempting to make self-dependent instance time");
91 mBegin = &aBegin;
94 void
95 nsSMILInterval::SetEnd(nsSMILInstanceTime& aEnd)
97 NS_ABORT_IF_FALSE(!mEndFixed,
98 "Attempting to set end time but the end point is fixed");
99 // As with SetBegin, check we're not making an instance time dependent on
100 // itself.
101 NS_ABORT_IF_FALSE(!mEnd || aEnd.GetBaseTime() != mEnd,
102 "Attempting to make self-dependent instance time");
104 mEnd = &aEnd;
107 void
108 nsSMILInterval::FixBegin()
110 NS_ABORT_IF_FALSE(mBegin && mEnd,
111 "Fixing begin point on un-initialized interval");
112 NS_ABORT_IF_FALSE(!mBeginFixed, "Duplicate calls to FixBegin()");
113 mBeginFixed = true;
114 mBegin->AddRefFixedEndpoint();
117 void
118 nsSMILInterval::FixEnd()
120 NS_ABORT_IF_FALSE(mBegin && mEnd,
121 "Fixing end point on un-initialized interval");
122 NS_ABORT_IF_FALSE(mBeginFixed,
123 "Fixing the end of an interval without a fixed begin");
124 NS_ABORT_IF_FALSE(!mEndFixed, "Duplicate calls to FixEnd()");
125 mEndFixed = true;
126 mEnd->AddRefFixedEndpoint();
129 void
130 nsSMILInterval::AddDependentTime(nsSMILInstanceTime& aTime)
132 nsRefPtr<nsSMILInstanceTime>* inserted =
133 mDependentTimes.InsertElementSorted(&aTime);
134 if (!inserted) {
135 NS_WARNING("Insufficient memory to insert instance time.");
139 void
140 nsSMILInterval::RemoveDependentTime(const nsSMILInstanceTime& aTime)
142 #ifdef DEBUG
143 bool found =
144 #endif
145 mDependentTimes.RemoveElementSorted(&aTime);
146 NS_ABORT_IF_FALSE(found, "Couldn't find instance time to delete.");
149 void
150 nsSMILInterval::GetDependentTimes(InstanceTimeList& aTimes)
152 aTimes = mDependentTimes;
155 bool
156 nsSMILInterval::IsDependencyChainLink() const
158 if (!mBegin || !mEnd)
159 return false; // Not yet initialised so it can't be part of a chain
161 if (mDependentTimes.IsEmpty())
162 return false; // No dependents, chain end
164 // So we have dependents, but we're still only a link in the chain (as opposed
165 // to the end of the chain) if one of our endpoints is dependent on an
166 // interval other than ourselves.
167 return (mBegin->IsDependent() && mBegin->GetBaseInterval() != this) ||
168 (mEnd->IsDependent() && mEnd->GetBaseInterval() != this);