1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/nsSMILInterval.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,169 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsSMILInterval.h" 1.10 + 1.11 +nsSMILInterval::nsSMILInterval() 1.12 +: 1.13 + mBeginFixed(false), 1.14 + mEndFixed(false) 1.15 +{ 1.16 +} 1.17 + 1.18 +nsSMILInterval::nsSMILInterval(const nsSMILInterval& aOther) 1.19 +: 1.20 + mBegin(aOther.mBegin), 1.21 + mEnd(aOther.mEnd), 1.22 + mBeginFixed(false), 1.23 + mEndFixed(false) 1.24 +{ 1.25 + NS_ABORT_IF_FALSE(aOther.mDependentTimes.IsEmpty(), 1.26 + "Attempting to copy-construct an interval with dependent times, " 1.27 + "this will lead to instance times being shared between intervals."); 1.28 + 1.29 + // For the time being we don't allow intervals with fixed endpoints to be 1.30 + // copied since we only ever copy-construct to establish a new current 1.31 + // interval. If we ever need to copy historical intervals we may need to move 1.32 + // the ReleaseFixedEndpoint calls from Unlink to the dtor. 1.33 + NS_ABORT_IF_FALSE(!aOther.mBeginFixed && !aOther.mEndFixed, 1.34 + "Attempting to copy-construct an interval with fixed endpoints"); 1.35 +} 1.36 + 1.37 +nsSMILInterval::~nsSMILInterval() 1.38 +{ 1.39 + NS_ABORT_IF_FALSE(mDependentTimes.IsEmpty(), 1.40 + "Destroying interval without disassociating dependent instance times. " 1.41 + "Unlink was not called"); 1.42 +} 1.43 + 1.44 +void 1.45 +nsSMILInterval::Unlink(bool aFiltered) 1.46 +{ 1.47 + for (int32_t i = mDependentTimes.Length() - 1; i >= 0; --i) { 1.48 + if (aFiltered) { 1.49 + mDependentTimes[i]->HandleFilteredInterval(); 1.50 + } else { 1.51 + mDependentTimes[i]->HandleDeletedInterval(); 1.52 + } 1.53 + } 1.54 + mDependentTimes.Clear(); 1.55 + if (mBegin && mBeginFixed) { 1.56 + mBegin->ReleaseFixedEndpoint(); 1.57 + } 1.58 + mBegin = nullptr; 1.59 + if (mEnd && mEndFixed) { 1.60 + mEnd->ReleaseFixedEndpoint(); 1.61 + } 1.62 + mEnd = nullptr; 1.63 +} 1.64 + 1.65 +nsSMILInstanceTime* 1.66 +nsSMILInterval::Begin() 1.67 +{ 1.68 + NS_ABORT_IF_FALSE(mBegin && mEnd, 1.69 + "Requesting Begin() on un-initialized interval."); 1.70 + return mBegin; 1.71 +} 1.72 + 1.73 +nsSMILInstanceTime* 1.74 +nsSMILInterval::End() 1.75 +{ 1.76 + NS_ABORT_IF_FALSE(mBegin && mEnd, 1.77 + "Requesting End() on un-initialized interval."); 1.78 + return mEnd; 1.79 +} 1.80 + 1.81 +void 1.82 +nsSMILInterval::SetBegin(nsSMILInstanceTime& aBegin) 1.83 +{ 1.84 + NS_ABORT_IF_FALSE(aBegin.Time().IsDefinite(), 1.85 + "Attempting to set unresolved or indefinite begin time on interval"); 1.86 + NS_ABORT_IF_FALSE(!mBeginFixed, 1.87 + "Attempting to set begin time but the begin point is fixed"); 1.88 + // Check that we're not making an instance time dependent on itself. Such an 1.89 + // arrangement does not make intuitive sense and should be detected when 1.90 + // creating or updating intervals. 1.91 + NS_ABORT_IF_FALSE(!mBegin || aBegin.GetBaseTime() != mBegin, 1.92 + "Attempting to make self-dependent instance time"); 1.93 + 1.94 + mBegin = &aBegin; 1.95 +} 1.96 + 1.97 +void 1.98 +nsSMILInterval::SetEnd(nsSMILInstanceTime& aEnd) 1.99 +{ 1.100 + NS_ABORT_IF_FALSE(!mEndFixed, 1.101 + "Attempting to set end time but the end point is fixed"); 1.102 + // As with SetBegin, check we're not making an instance time dependent on 1.103 + // itself. 1.104 + NS_ABORT_IF_FALSE(!mEnd || aEnd.GetBaseTime() != mEnd, 1.105 + "Attempting to make self-dependent instance time"); 1.106 + 1.107 + mEnd = &aEnd; 1.108 +} 1.109 + 1.110 +void 1.111 +nsSMILInterval::FixBegin() 1.112 +{ 1.113 + NS_ABORT_IF_FALSE(mBegin && mEnd, 1.114 + "Fixing begin point on un-initialized interval"); 1.115 + NS_ABORT_IF_FALSE(!mBeginFixed, "Duplicate calls to FixBegin()"); 1.116 + mBeginFixed = true; 1.117 + mBegin->AddRefFixedEndpoint(); 1.118 +} 1.119 + 1.120 +void 1.121 +nsSMILInterval::FixEnd() 1.122 +{ 1.123 + NS_ABORT_IF_FALSE(mBegin && mEnd, 1.124 + "Fixing end point on un-initialized interval"); 1.125 + NS_ABORT_IF_FALSE(mBeginFixed, 1.126 + "Fixing the end of an interval without a fixed begin"); 1.127 + NS_ABORT_IF_FALSE(!mEndFixed, "Duplicate calls to FixEnd()"); 1.128 + mEndFixed = true; 1.129 + mEnd->AddRefFixedEndpoint(); 1.130 +} 1.131 + 1.132 +void 1.133 +nsSMILInterval::AddDependentTime(nsSMILInstanceTime& aTime) 1.134 +{ 1.135 + nsRefPtr<nsSMILInstanceTime>* inserted = 1.136 + mDependentTimes.InsertElementSorted(&aTime); 1.137 + if (!inserted) { 1.138 + NS_WARNING("Insufficient memory to insert instance time."); 1.139 + } 1.140 +} 1.141 + 1.142 +void 1.143 +nsSMILInterval::RemoveDependentTime(const nsSMILInstanceTime& aTime) 1.144 +{ 1.145 +#ifdef DEBUG 1.146 + bool found = 1.147 +#endif 1.148 + mDependentTimes.RemoveElementSorted(&aTime); 1.149 + NS_ABORT_IF_FALSE(found, "Couldn't find instance time to delete."); 1.150 +} 1.151 + 1.152 +void 1.153 +nsSMILInterval::GetDependentTimes(InstanceTimeList& aTimes) 1.154 +{ 1.155 + aTimes = mDependentTimes; 1.156 +} 1.157 + 1.158 +bool 1.159 +nsSMILInterval::IsDependencyChainLink() const 1.160 +{ 1.161 + if (!mBegin || !mEnd) 1.162 + return false; // Not yet initialised so it can't be part of a chain 1.163 + 1.164 + if (mDependentTimes.IsEmpty()) 1.165 + return false; // No dependents, chain end 1.166 + 1.167 + // So we have dependents, but we're still only a link in the chain (as opposed 1.168 + // to the end of the chain) if one of our endpoints is dependent on an 1.169 + // interval other than ourselves. 1.170 + return (mBegin->IsDependent() && mBegin->GetBaseInterval() != this) || 1.171 + (mEnd->IsDependent() && mEnd->GetBaseInterval() != this); 1.172 +}