2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
#include "nsSMILInstanceTime.h"
|
2010-03-01 22:31:50 +03:00
|
|
|
#include "nsSMILInterval.h"
|
|
|
|
#include "nsSMILTimeValueSpec.h"
|
2011-07-19 14:04:55 +04:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2010-03-01 22:31:50 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
nsSMILInstanceTime::nsSMILInstanceTime(const nsSMILTimeValue& aTime,
|
2010-03-01 22:31:50 +03:00
|
|
|
nsSMILInstanceTimeSource aSource,
|
|
|
|
nsSMILTimeValueSpec* aCreator,
|
|
|
|
nsSMILInterval* aBaseInterval)
|
|
|
|
: mTime(aTime),
|
|
|
|
mFlags(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mVisited(false),
|
2010-07-03 09:52:50 +04:00
|
|
|
mFixedEndpointRefCnt(0),
|
|
|
|
mSerial(0),
|
2010-03-01 22:31:50 +03:00
|
|
|
mCreator(aCreator),
|
2012-07-30 18:20:58 +04:00
|
|
|
mBaseInterval(nullptr) // This will get set to aBaseInterval in a call to
|
2010-03-01 22:31:52 +03:00
|
|
|
// SetBaseInterval() at end of constructor
|
2010-01-12 23:00:49 +03:00
|
|
|
{
|
|
|
|
switch (aSource) {
|
|
|
|
case SOURCE_NONE:
|
|
|
|
// No special flags
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOURCE_DOM:
|
2010-07-03 09:52:50 +04:00
|
|
|
mFlags = kDynamic | kFromDOM;
|
2010-01-12 23:00:49 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SOURCE_SYNCBASE:
|
|
|
|
mFlags = kMayUpdate;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOURCE_EVENT:
|
2010-07-03 09:52:50 +04:00
|
|
|
mFlags = kDynamic;
|
2010-01-12 23:00:49 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-01 22:31:50 +03:00
|
|
|
SetBaseInterval(aBaseInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILInstanceTime::~nsSMILInstanceTime()
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mBaseInterval,
|
|
|
|
"Destroying instance time without first calling Unlink()");
|
|
|
|
MOZ_ASSERT(mFixedEndpointRefCnt == 0,
|
|
|
|
"Destroying instance time that is still used as the fixed "
|
|
|
|
"endpoint of an interval");
|
2010-01-12 23:00:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-01 22:31:50 +03:00
|
|
|
nsSMILInstanceTime::Unlink()
|
2010-01-12 23:00:49 +03:00
|
|
|
{
|
2010-03-01 22:31:50 +03:00
|
|
|
nsRefPtr<nsSMILInstanceTime> deathGrip(this);
|
|
|
|
if (mBaseInterval) {
|
|
|
|
mBaseInterval->RemoveDependentTime(*this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mBaseInterval = nullptr;
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mCreator = nullptr;
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2010-03-01 22:31:50 +03:00
|
|
|
void
|
|
|
|
nsSMILInstanceTime::HandleChangedInterval(
|
|
|
|
const nsSMILTimeContainer* aSrcContainer,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aBeginObjectChanged,
|
|
|
|
bool aEndObjectChanged)
|
2010-03-01 22:31:50 +03:00
|
|
|
{
|
2011-06-15 04:16:57 +04:00
|
|
|
// It's possible a sequence of notifications might cause our base interval to
|
|
|
|
// be updated and then deleted. Furthermore, the delete might happen whilst
|
|
|
|
// we're still in the queue to be notified of the change. In any case, if we
|
|
|
|
// don't have a base interval, just ignore the change.
|
|
|
|
if (!mBaseInterval)
|
|
|
|
return;
|
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mCreator, "Base interval is set but creator is not.");
|
2010-03-01 22:31:50 +03:00
|
|
|
|
2010-07-03 09:52:50 +04:00
|
|
|
if (mVisited) {
|
|
|
|
// Break the cycle here
|
|
|
|
Unlink();
|
2010-03-01 22:31:50 +03:00
|
|
|
return;
|
2010-01-12 23:00:49 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool objectChanged = mCreator->DependsOnBegin() ? aBeginObjectChanged :
|
2010-03-01 22:31:52 +03:00
|
|
|
aEndObjectChanged;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
mozilla::AutoRestore<bool> setVisited(mVisited);
|
2011-10-17 18:59:28 +04:00
|
|
|
mVisited = true;
|
2010-03-01 22:31:50 +03:00
|
|
|
|
|
|
|
nsRefPtr<nsSMILInstanceTime> deathGrip(this);
|
|
|
|
mCreator->HandleChangedInstanceTime(*GetBaseTime(), aSrcContainer, *this,
|
|
|
|
objectChanged);
|
2010-01-12 23:00:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-01 22:31:50 +03:00
|
|
|
nsSMILInstanceTime::HandleDeletedInterval()
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mBaseInterval,
|
|
|
|
"Got call to HandleDeletedInterval on an independent instance "
|
|
|
|
"time");
|
|
|
|
MOZ_ASSERT(mCreator, "Base interval is set but creator is not");
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mBaseInterval = nullptr;
|
2010-07-03 09:52:50 +04:00
|
|
|
mFlags &= ~kMayUpdate; // Can't update without a base interval
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2010-03-01 22:31:50 +03:00
|
|
|
nsRefPtr<nsSMILInstanceTime> deathGrip(this);
|
|
|
|
mCreator->HandleDeletedInstanceTime(*this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mCreator = nullptr;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2010-07-03 09:52:50 +04:00
|
|
|
void
|
|
|
|
nsSMILInstanceTime::HandleFilteredInterval()
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mBaseInterval,
|
|
|
|
"Got call to HandleFilteredInterval on an independent instance "
|
|
|
|
"time");
|
2010-07-03 09:52:50 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mBaseInterval = nullptr;
|
2010-07-03 09:52:50 +04:00
|
|
|
mFlags &= ~kMayUpdate; // Can't update without a base interval
|
2012-07-30 18:20:58 +04:00
|
|
|
mCreator = nullptr;
|
2010-07-03 09:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-07-03 09:52:51 +04:00
|
|
|
nsSMILInstanceTime::ShouldPreserve() const
|
|
|
|
{
|
|
|
|
return mFixedEndpointRefCnt > 0 || (mFlags & kWasDynamicEndpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILInstanceTime::UnmarkShouldPreserve()
|
|
|
|
{
|
|
|
|
mFlags &= ~kWasDynamicEndpoint;
|
|
|
|
}
|
|
|
|
|
2010-07-03 09:52:50 +04:00
|
|
|
void
|
|
|
|
nsSMILInstanceTime::AddRefFixedEndpoint()
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mFixedEndpointRefCnt < UINT16_MAX,
|
|
|
|
"Fixed endpoint reference count upper limit reached");
|
2010-07-03 09:52:50 +04:00
|
|
|
++mFixedEndpointRefCnt;
|
|
|
|
mFlags &= ~kMayUpdate; // Once fixed, always fixed
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILInstanceTime::ReleaseFixedEndpoint()
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mFixedEndpointRefCnt > 0, "Duplicate release");
|
2010-07-03 09:52:50 +04:00
|
|
|
--mFixedEndpointRefCnt;
|
2010-07-03 09:52:51 +04:00
|
|
|
if (mFixedEndpointRefCnt == 0 && IsDynamic()) {
|
|
|
|
mFlags |= kWasDynamicEndpoint;
|
|
|
|
}
|
2010-07-03 09:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-07-03 09:52:50 +04:00
|
|
|
nsSMILInstanceTime::IsDependentOn(const nsSMILInstanceTime& aOther) const
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2010-07-03 09:52:50 +04:00
|
|
|
if (mVisited)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2010-03-01 22:31:50 +03:00
|
|
|
const nsSMILInstanceTime* myBaseTime = GetBaseTime();
|
|
|
|
if (!myBaseTime)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2010-03-01 22:31:50 +03:00
|
|
|
if (myBaseTime == &aOther)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2012-08-29 09:27:53 +04:00
|
|
|
mozilla::AutoRestore<bool> setVisited(mVisited);
|
|
|
|
mVisited = true;
|
2010-07-03 09:52:50 +04:00
|
|
|
return myBaseTime->IsDependentOn(aOther);
|
2010-03-01 22:31:50 +03:00
|
|
|
}
|
|
|
|
|
2011-06-22 05:12:35 +04:00
|
|
|
const nsSMILInstanceTime*
|
|
|
|
nsSMILInstanceTime::GetBaseTime() const
|
|
|
|
{
|
|
|
|
if (!mBaseInterval) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-06-22 05:12:35 +04:00
|
|
|
}
|
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mCreator, "Base interval is set but there is no creator.");
|
2011-06-22 05:12:35 +04:00
|
|
|
if (!mCreator) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-06-22 05:12:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mCreator->DependsOnBegin() ? mBaseInterval->Begin() :
|
|
|
|
mBaseInterval->End();
|
|
|
|
}
|
|
|
|
|
2010-03-01 22:31:50 +03:00
|
|
|
void
|
|
|
|
nsSMILInstanceTime::SetBaseInterval(nsSMILInterval* aBaseInterval)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mBaseInterval,
|
|
|
|
"Attempting to reassociate an instance time with a different "
|
|
|
|
"interval.");
|
2010-03-01 22:31:50 +03:00
|
|
|
|
|
|
|
if (aBaseInterval) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mCreator,
|
|
|
|
"Attempting to create a dependent instance time without "
|
|
|
|
"reference to the creating nsSMILTimeValueSpec object.");
|
2010-03-01 22:31:50 +03:00
|
|
|
if (!mCreator)
|
|
|
|
return;
|
|
|
|
|
|
|
|
aBaseInterval->AddDependentTime(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
mBaseInterval = aBaseInterval;
|
|
|
|
}
|