1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Mozilla SMIL module.
17 * The Initial Developer of the Original Code is Brian Birtles.
18 * Portions created by the Initial Developer are Copyright (C) 2005
19 * the Initial Developer. All Rights Reserved.
22 * Brian Birtles <birtles@gmail.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsSMILInstanceTime.h"
39 #include "nsSMILInterval.h"
40 #include "nsSMILTimeValueSpec.h"
42 //----------------------------------------------------------------------
47 // Utility class to set a PRPackedBool value to PR_TRUE whilst it is in scope.
48 // Saves us having to remember to clear the flag at every possible return.
52 AutoBoolSetter(PRPackedBool
& aValue
)
68 //----------------------------------------------------------------------
71 nsSMILInstanceTime::nsSMILInstanceTime(const nsSMILTimeValue
& aTime
,
72 nsSMILInstanceTimeSource aSource
,
73 nsSMILTimeValueSpec
* aCreator
,
74 nsSMILInterval
* aBaseInterval
)
78 mFixedEndpointRefCnt(0),
81 mBaseInterval(nsnull
) // This will get set to aBaseInterval in a call to
82 // SetBaseInterval() at end of constructor
90 mFlags
= kDynamic
| kFromDOM
;
102 SetBaseInterval(aBaseInterval
);
105 nsSMILInstanceTime::~nsSMILInstanceTime()
107 NS_ABORT_IF_FALSE(!mBaseInterval
,
108 "Destroying instance time without first calling Unlink()");
109 NS_ABORT_IF_FALSE(mFixedEndpointRefCnt
== 0,
110 "Destroying instance time that is still used as the fixed endpoint of an "
115 nsSMILInstanceTime::Unlink()
117 nsRefPtr
<nsSMILInstanceTime
> deathGrip(this);
119 mBaseInterval
->RemoveDependentTime(*this);
120 mBaseInterval
= nsnull
;
126 nsSMILInstanceTime::HandleChangedInterval(
127 const nsSMILTimeContainer
* aSrcContainer
,
128 PRBool aBeginObjectChanged
,
129 PRBool aEndObjectChanged
)
131 NS_ABORT_IF_FALSE(mBaseInterval
,
132 "Got call to HandleChangedInterval on an independent instance time.");
133 NS_ABORT_IF_FALSE(mCreator
, "Base interval is set but creator is not.");
136 // Break the cycle here
141 PRBool objectChanged
= mCreator
->DependsOnBegin() ? aBeginObjectChanged
:
144 AutoBoolSetter
setVisited(mVisited
);
146 nsRefPtr
<nsSMILInstanceTime
> deathGrip(this);
147 mCreator
->HandleChangedInstanceTime(*GetBaseTime(), aSrcContainer
, *this,
152 nsSMILInstanceTime::HandleDeletedInterval()
154 NS_ABORT_IF_FALSE(mBaseInterval
,
155 "Got call to HandleDeletedInterval on an independent instance time");
156 NS_ABORT_IF_FALSE(mCreator
, "Base interval is set but creator is not");
158 mBaseInterval
= nsnull
;
159 mFlags
&= ~kMayUpdate
; // Can't update without a base interval
161 nsRefPtr
<nsSMILInstanceTime
> deathGrip(this);
162 mCreator
->HandleDeletedInstanceTime(*this);
167 nsSMILInstanceTime::HandleFilteredInterval()
169 NS_ABORT_IF_FALSE(mBaseInterval
,
170 "Got call to HandleFilteredInterval on an independent instance time");
172 mBaseInterval
= nsnull
;
173 mFlags
&= ~kMayUpdate
; // Can't update without a base interval
178 nsSMILInstanceTime::ShouldPreserve() const
180 return mFixedEndpointRefCnt
> 0 || (mFlags
& kWasDynamicEndpoint
);
184 nsSMILInstanceTime::UnmarkShouldPreserve()
186 mFlags
&= ~kWasDynamicEndpoint
;
190 nsSMILInstanceTime::AddRefFixedEndpoint()
192 NS_ABORT_IF_FALSE(mFixedEndpointRefCnt
< PR_UINT16_MAX
,
193 "Fixed endpoint reference count upper limit reached");
194 ++mFixedEndpointRefCnt
;
195 mFlags
&= ~kMayUpdate
; // Once fixed, always fixed
199 nsSMILInstanceTime::ReleaseFixedEndpoint()
201 NS_ABORT_IF_FALSE(mFixedEndpointRefCnt
> 0, "Duplicate release");
202 --mFixedEndpointRefCnt
;
203 if (mFixedEndpointRefCnt
== 0 && IsDynamic()) {
204 mFlags
|= kWasDynamicEndpoint
;
209 nsSMILInstanceTime::IsDependentOn(const nsSMILInstanceTime
& aOther
) const
214 const nsSMILInstanceTime
* myBaseTime
= GetBaseTime();
218 if (myBaseTime
== &aOther
)
221 // mVisited is mutable
222 AutoBoolSetter
setVisited(const_cast<nsSMILInstanceTime
*>(this)->mVisited
);
223 return myBaseTime
->IsDependentOn(aOther
);
227 nsSMILInstanceTime::SetBaseInterval(nsSMILInterval
* aBaseInterval
)
229 NS_ABORT_IF_FALSE(!mBaseInterval
,
230 "Attempting to reassociate an instance time with a different interval.");
233 NS_ABORT_IF_FALSE(mCreator
,
234 "Attempting to create a dependent instance time without reference "
235 "to the creating nsSMILTimeValueSpec object.");
239 aBaseInterval
->AddDependentTime(*this);
242 mBaseInterval
= aBaseInterval
;
245 const nsSMILInstanceTime
*
246 nsSMILInstanceTime::GetBaseTime() const
248 if (!mBaseInterval
) {
252 NS_ABORT_IF_FALSE(mCreator
, "Base interval is set but there is no creator.");
257 return mCreator
->DependsOnBegin() ? mBaseInterval
->Begin() :
258 mBaseInterval
->End();