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