Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 "nsSMILInstanceTime.h" |
michael@0 | 7 | #include "nsSMILInterval.h" |
michael@0 | 8 | #include "nsSMILTimeValueSpec.h" |
michael@0 | 9 | #include "mozilla/AutoRestore.h" |
michael@0 | 10 | |
michael@0 | 11 | //---------------------------------------------------------------------- |
michael@0 | 12 | // Implementation |
michael@0 | 13 | |
michael@0 | 14 | nsSMILInstanceTime::nsSMILInstanceTime(const nsSMILTimeValue& aTime, |
michael@0 | 15 | nsSMILInstanceTimeSource aSource, |
michael@0 | 16 | nsSMILTimeValueSpec* aCreator, |
michael@0 | 17 | nsSMILInterval* aBaseInterval) |
michael@0 | 18 | : mTime(aTime), |
michael@0 | 19 | mFlags(0), |
michael@0 | 20 | mVisited(false), |
michael@0 | 21 | mFixedEndpointRefCnt(0), |
michael@0 | 22 | mSerial(0), |
michael@0 | 23 | mCreator(aCreator), |
michael@0 | 24 | mBaseInterval(nullptr) // This will get set to aBaseInterval in a call to |
michael@0 | 25 | // SetBaseInterval() at end of constructor |
michael@0 | 26 | { |
michael@0 | 27 | switch (aSource) { |
michael@0 | 28 | case SOURCE_NONE: |
michael@0 | 29 | // No special flags |
michael@0 | 30 | break; |
michael@0 | 31 | |
michael@0 | 32 | case SOURCE_DOM: |
michael@0 | 33 | mFlags = kDynamic | kFromDOM; |
michael@0 | 34 | break; |
michael@0 | 35 | |
michael@0 | 36 | case SOURCE_SYNCBASE: |
michael@0 | 37 | mFlags = kMayUpdate; |
michael@0 | 38 | break; |
michael@0 | 39 | |
michael@0 | 40 | case SOURCE_EVENT: |
michael@0 | 41 | mFlags = kDynamic; |
michael@0 | 42 | break; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | SetBaseInterval(aBaseInterval); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | nsSMILInstanceTime::~nsSMILInstanceTime() |
michael@0 | 49 | { |
michael@0 | 50 | NS_ABORT_IF_FALSE(!mBaseInterval, |
michael@0 | 51 | "Destroying instance time without first calling Unlink()"); |
michael@0 | 52 | NS_ABORT_IF_FALSE(mFixedEndpointRefCnt == 0, |
michael@0 | 53 | "Destroying instance time that is still used as the fixed endpoint of an " |
michael@0 | 54 | "interval"); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | void |
michael@0 | 58 | nsSMILInstanceTime::Unlink() |
michael@0 | 59 | { |
michael@0 | 60 | nsRefPtr<nsSMILInstanceTime> deathGrip(this); |
michael@0 | 61 | if (mBaseInterval) { |
michael@0 | 62 | mBaseInterval->RemoveDependentTime(*this); |
michael@0 | 63 | mBaseInterval = nullptr; |
michael@0 | 64 | } |
michael@0 | 65 | mCreator = nullptr; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | void |
michael@0 | 69 | nsSMILInstanceTime::HandleChangedInterval( |
michael@0 | 70 | const nsSMILTimeContainer* aSrcContainer, |
michael@0 | 71 | bool aBeginObjectChanged, |
michael@0 | 72 | bool aEndObjectChanged) |
michael@0 | 73 | { |
michael@0 | 74 | // It's possible a sequence of notifications might cause our base interval to |
michael@0 | 75 | // be updated and then deleted. Furthermore, the delete might happen whilst |
michael@0 | 76 | // we're still in the queue to be notified of the change. In any case, if we |
michael@0 | 77 | // don't have a base interval, just ignore the change. |
michael@0 | 78 | if (!mBaseInterval) |
michael@0 | 79 | return; |
michael@0 | 80 | |
michael@0 | 81 | NS_ABORT_IF_FALSE(mCreator, "Base interval is set but creator is not."); |
michael@0 | 82 | |
michael@0 | 83 | if (mVisited) { |
michael@0 | 84 | // Break the cycle here |
michael@0 | 85 | Unlink(); |
michael@0 | 86 | return; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | bool objectChanged = mCreator->DependsOnBegin() ? aBeginObjectChanged : |
michael@0 | 90 | aEndObjectChanged; |
michael@0 | 91 | |
michael@0 | 92 | mozilla::AutoRestore<bool> setVisited(mVisited); |
michael@0 | 93 | mVisited = true; |
michael@0 | 94 | |
michael@0 | 95 | nsRefPtr<nsSMILInstanceTime> deathGrip(this); |
michael@0 | 96 | mCreator->HandleChangedInstanceTime(*GetBaseTime(), aSrcContainer, *this, |
michael@0 | 97 | objectChanged); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | void |
michael@0 | 101 | nsSMILInstanceTime::HandleDeletedInterval() |
michael@0 | 102 | { |
michael@0 | 103 | NS_ABORT_IF_FALSE(mBaseInterval, |
michael@0 | 104 | "Got call to HandleDeletedInterval on an independent instance time"); |
michael@0 | 105 | NS_ABORT_IF_FALSE(mCreator, "Base interval is set but creator is not"); |
michael@0 | 106 | |
michael@0 | 107 | mBaseInterval = nullptr; |
michael@0 | 108 | mFlags &= ~kMayUpdate; // Can't update without a base interval |
michael@0 | 109 | |
michael@0 | 110 | nsRefPtr<nsSMILInstanceTime> deathGrip(this); |
michael@0 | 111 | mCreator->HandleDeletedInstanceTime(*this); |
michael@0 | 112 | mCreator = nullptr; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | void |
michael@0 | 116 | nsSMILInstanceTime::HandleFilteredInterval() |
michael@0 | 117 | { |
michael@0 | 118 | NS_ABORT_IF_FALSE(mBaseInterval, |
michael@0 | 119 | "Got call to HandleFilteredInterval on an independent instance time"); |
michael@0 | 120 | |
michael@0 | 121 | mBaseInterval = nullptr; |
michael@0 | 122 | mFlags &= ~kMayUpdate; // Can't update without a base interval |
michael@0 | 123 | mCreator = nullptr; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | bool |
michael@0 | 127 | nsSMILInstanceTime::ShouldPreserve() const |
michael@0 | 128 | { |
michael@0 | 129 | return mFixedEndpointRefCnt > 0 || (mFlags & kWasDynamicEndpoint); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | void |
michael@0 | 133 | nsSMILInstanceTime::UnmarkShouldPreserve() |
michael@0 | 134 | { |
michael@0 | 135 | mFlags &= ~kWasDynamicEndpoint; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | void |
michael@0 | 139 | nsSMILInstanceTime::AddRefFixedEndpoint() |
michael@0 | 140 | { |
michael@0 | 141 | NS_ABORT_IF_FALSE(mFixedEndpointRefCnt < UINT16_MAX, |
michael@0 | 142 | "Fixed endpoint reference count upper limit reached"); |
michael@0 | 143 | ++mFixedEndpointRefCnt; |
michael@0 | 144 | mFlags &= ~kMayUpdate; // Once fixed, always fixed |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | void |
michael@0 | 148 | nsSMILInstanceTime::ReleaseFixedEndpoint() |
michael@0 | 149 | { |
michael@0 | 150 | NS_ABORT_IF_FALSE(mFixedEndpointRefCnt > 0, "Duplicate release"); |
michael@0 | 151 | --mFixedEndpointRefCnt; |
michael@0 | 152 | if (mFixedEndpointRefCnt == 0 && IsDynamic()) { |
michael@0 | 153 | mFlags |= kWasDynamicEndpoint; |
michael@0 | 154 | } |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | bool |
michael@0 | 158 | nsSMILInstanceTime::IsDependentOn(const nsSMILInstanceTime& aOther) const |
michael@0 | 159 | { |
michael@0 | 160 | if (mVisited) |
michael@0 | 161 | return false; |
michael@0 | 162 | |
michael@0 | 163 | const nsSMILInstanceTime* myBaseTime = GetBaseTime(); |
michael@0 | 164 | if (!myBaseTime) |
michael@0 | 165 | return false; |
michael@0 | 166 | |
michael@0 | 167 | if (myBaseTime == &aOther) |
michael@0 | 168 | return true; |
michael@0 | 169 | |
michael@0 | 170 | mozilla::AutoRestore<bool> setVisited(mVisited); |
michael@0 | 171 | mVisited = true; |
michael@0 | 172 | return myBaseTime->IsDependentOn(aOther); |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | const nsSMILInstanceTime* |
michael@0 | 176 | nsSMILInstanceTime::GetBaseTime() const |
michael@0 | 177 | { |
michael@0 | 178 | if (!mBaseInterval) { |
michael@0 | 179 | return nullptr; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | NS_ABORT_IF_FALSE(mCreator, "Base interval is set but there is no creator."); |
michael@0 | 183 | if (!mCreator) { |
michael@0 | 184 | return nullptr; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | return mCreator->DependsOnBegin() ? mBaseInterval->Begin() : |
michael@0 | 188 | mBaseInterval->End(); |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | void |
michael@0 | 192 | nsSMILInstanceTime::SetBaseInterval(nsSMILInterval* aBaseInterval) |
michael@0 | 193 | { |
michael@0 | 194 | NS_ABORT_IF_FALSE(!mBaseInterval, |
michael@0 | 195 | "Attempting to reassociate an instance time with a different interval."); |
michael@0 | 196 | |
michael@0 | 197 | if (aBaseInterval) { |
michael@0 | 198 | NS_ABORT_IF_FALSE(mCreator, |
michael@0 | 199 | "Attempting to create a dependent instance time without reference " |
michael@0 | 200 | "to the creating nsSMILTimeValueSpec object."); |
michael@0 | 201 | if (!mCreator) |
michael@0 | 202 | return; |
michael@0 | 203 | |
michael@0 | 204 | aBaseInterval->AddDependentTime(*this); |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | mBaseInterval = aBaseInterval; |
michael@0 | 208 | } |