Bug 606160 - CSS updates for fx button after caption button padding changes. r=dao...
[mozilla-central.git] / content / smil / nsSMILInstanceTime.cpp
blobd108bf53acd7175317fd28be068a93347da98215
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
13 * License.
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.
21 * Contributor(s):
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 //----------------------------------------------------------------------
43 // Helper classes
45 namespace
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.
49 class AutoBoolSetter
51 public:
52 AutoBoolSetter(PRPackedBool& aValue)
53 : mValue(aValue)
55 mValue = PR_TRUE;
58 ~AutoBoolSetter()
60 mValue = PR_FALSE;
63 private:
64 PRPackedBool& mValue;
68 //----------------------------------------------------------------------
69 // Implementation
71 nsSMILInstanceTime::nsSMILInstanceTime(const nsSMILTimeValue& aTime,
72 nsSMILInstanceTimeSource aSource,
73 nsSMILTimeValueSpec* aCreator,
74 nsSMILInterval* aBaseInterval)
75 : mTime(aTime),
76 mFlags(0),
77 mVisited(PR_FALSE),
78 mFixedEndpointRefCnt(0),
79 mSerial(0),
80 mCreator(aCreator),
81 mBaseInterval(nsnull) // This will get set to aBaseInterval in a call to
82 // SetBaseInterval() at end of constructor
84 switch (aSource) {
85 case SOURCE_NONE:
86 // No special flags
87 break;
89 case SOURCE_DOM:
90 mFlags = kDynamic | kFromDOM;
91 break;
93 case SOURCE_SYNCBASE:
94 mFlags = kMayUpdate;
95 break;
97 case SOURCE_EVENT:
98 mFlags = kDynamic;
99 break;
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 "
111 "interval");
114 void
115 nsSMILInstanceTime::Unlink()
117 nsRefPtr<nsSMILInstanceTime> deathGrip(this);
118 if (mBaseInterval) {
119 mBaseInterval->RemoveDependentTime(*this);
120 mBaseInterval = nsnull;
122 mCreator = nsnull;
125 void
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.");
135 if (mVisited) {
136 // Break the cycle here
137 Unlink();
138 return;
141 PRBool objectChanged = mCreator->DependsOnBegin() ? aBeginObjectChanged :
142 aEndObjectChanged;
144 AutoBoolSetter setVisited(mVisited);
146 nsRefPtr<nsSMILInstanceTime> deathGrip(this);
147 mCreator->HandleChangedInstanceTime(*GetBaseTime(), aSrcContainer, *this,
148 objectChanged);
151 void
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);
163 mCreator = nsnull;
166 void
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
174 mCreator = nsnull;
177 PRBool
178 nsSMILInstanceTime::ShouldPreserve() const
180 return mFixedEndpointRefCnt > 0 || (mFlags & kWasDynamicEndpoint);
183 void
184 nsSMILInstanceTime::UnmarkShouldPreserve()
186 mFlags &= ~kWasDynamicEndpoint;
189 void
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
198 void
199 nsSMILInstanceTime::ReleaseFixedEndpoint()
201 NS_ABORT_IF_FALSE(mFixedEndpointRefCnt > 0, "Duplicate release");
202 --mFixedEndpointRefCnt;
203 if (mFixedEndpointRefCnt == 0 && IsDynamic()) {
204 mFlags |= kWasDynamicEndpoint;
208 PRBool
209 nsSMILInstanceTime::IsDependentOn(const nsSMILInstanceTime& aOther) const
211 if (mVisited)
212 return PR_FALSE;
214 const nsSMILInstanceTime* myBaseTime = GetBaseTime();
215 if (!myBaseTime)
216 return PR_FALSE;
218 if (myBaseTime == &aOther)
219 return PR_TRUE;
221 // mVisited is mutable
222 AutoBoolSetter setVisited(const_cast<nsSMILInstanceTime*>(this)->mVisited);
223 return myBaseTime->IsDependentOn(aOther);
226 void
227 nsSMILInstanceTime::SetBaseInterval(nsSMILInterval* aBaseInterval)
229 NS_ABORT_IF_FALSE(!mBaseInterval,
230 "Attempting to reassociate an instance time with a different interval.");
232 if (aBaseInterval) {
233 NS_ABORT_IF_FALSE(mCreator,
234 "Attempting to create a dependent instance time without reference "
235 "to the creating nsSMILTimeValueSpec object.");
236 if (!mCreator)
237 return;
239 aBaseInterval->AddDependentTime(*this);
242 mBaseInterval = aBaseInterval;
245 const nsSMILInstanceTime*
246 nsSMILInstanceTime::GetBaseTime() const
248 if (!mBaseInterval) {
249 return nsnull;
252 NS_ABORT_IF_FALSE(mCreator, "Base interval is set but there is no creator.");
253 if (!mCreator) {
254 return nsnull;
257 return mCreator->DependsOnBegin() ? mBaseInterval->Begin() :
258 mBaseInterval->End();