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