2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2012-12-21 01:18:58 -08:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2007-09-18 05:09:26 -07:00
|
|
|
#include "nsSVGInteger.h"
|
2010-02-18 13:51:00 -08:00
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "SMILIntegerType.h"
|
2013-09-17 05:52:39 -07:00
|
|
|
#include "SVGContentUtils.h"
|
2007-09-18 05:09:26 -07:00
|
|
|
|
2010-02-18 13:51:00 -08:00
|
|
|
using namespace mozilla;
|
2013-07-01 00:02:56 -07:00
|
|
|
using namespace mozilla::dom;
|
2007-09-18 05:09:26 -07:00
|
|
|
|
|
|
|
/* Implementation */
|
|
|
|
|
2012-12-21 01:18:58 -08:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGInteger, nsSVGInteger::DOMAnimatedInteger>
|
|
|
|
sSVGAnimatedIntegerTearoffTable;
|
|
|
|
|
2011-07-01 00:19:52 -07:00
|
|
|
nsresult
|
|
|
|
nsSVGInteger::SetBaseValueString(const nsAString &aValueAsString,
|
2011-10-09 08:25:07 -07:00
|
|
|
nsSVGElement *aSVGElement)
|
2011-07-01 00:19:52 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t value;
|
2011-07-01 00:19:52 -07:00
|
|
|
|
2013-10-01 00:50:40 -07:00
|
|
|
if (!SVGContentUtils::ParseInteger(aValueAsString, value)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2011-07-01 00:19:52 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsBaseSet = true;
|
2011-07-01 00:19:52 -07:00
|
|
|
mBaseVal = value;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
2010-02-18 13:51:00 -08:00
|
|
|
}
|
2007-09-18 05:09:26 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-18 05:09:26 -07:00
|
|
|
void
|
|
|
|
nsSVGInteger::GetBaseValueString(nsAString & aValueAsString)
|
|
|
|
{
|
2011-07-01 00:19:52 -07:00
|
|
|
aValueAsString.Truncate();
|
|
|
|
aValueAsString.AppendInt(mBaseVal);
|
2007-09-18 05:09:26 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-18 05:09:26 -07:00
|
|
|
void
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGInteger::SetBaseValue(int aValue, nsSVGElement *aSVGElement)
|
2007-09-18 05:09:26 -07:00
|
|
|
{
|
2012-02-15 15:40:45 -08:00
|
|
|
// We can't just rely on SetParsedAttrValue (as called by DidChangeInteger)
|
|
|
|
// detecting redundant changes since it will compare false if the existing
|
|
|
|
// attribute value has an associated serialized version (a string value) even
|
|
|
|
// if the integers match due to the way integers are stored in nsAttrValue.
|
|
|
|
if (aValue == mBaseVal && mIsBaseSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-01 00:19:52 -07:00
|
|
|
mBaseVal = aValue;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsBaseSet = true;
|
2011-07-01 00:19:52 -07:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
2010-02-18 13:51:00 -08:00
|
|
|
}
|
2012-02-15 15:40:45 -08:00
|
|
|
aSVGElement->DidChangeInteger(mAttrEnum);
|
2010-02-18 13:51:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGInteger::SetAnimValue(int aValue, nsSVGElement *aSVGElement)
|
|
|
|
{
|
2012-06-01 16:53:06 -07:00
|
|
|
if (mIsAnimated && aValue == mAnimVal) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-18 13:51:00 -08:00
|
|
|
mAnimVal = aValue;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAnimated = true;
|
2010-02-18 13:51:00 -08:00
|
|
|
aSVGElement->DidAnimateInteger(mAttrEnum);
|
2007-09-18 05:09:26 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-01 00:02:56 -07:00
|
|
|
already_AddRefed<SVGAnimatedInteger>
|
2013-03-24 23:26:06 -07:00
|
|
|
nsSVGInteger::ToDOMAnimatedInteger(nsSVGElement *aSVGElement)
|
2007-09-18 05:09:26 -07:00
|
|
|
{
|
2012-12-21 01:18:58 -08:00
|
|
|
nsRefPtr<DOMAnimatedInteger> domAnimatedInteger =
|
|
|
|
sSVGAnimatedIntegerTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimatedInteger) {
|
|
|
|
domAnimatedInteger = new DOMAnimatedInteger(this, aSVGElement);
|
|
|
|
sSVGAnimatedIntegerTearoffTable.AddTearoff(this, domAnimatedInteger);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-24 23:26:06 -07:00
|
|
|
return domAnimatedInteger.forget();
|
2007-09-18 05:09:26 -07:00
|
|
|
}
|
2010-02-18 13:51:00 -08:00
|
|
|
|
2012-12-21 01:18:58 -08:00
|
|
|
nsSVGInteger::DOMAnimatedInteger::~DOMAnimatedInteger()
|
|
|
|
{
|
|
|
|
sSVGAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2010-02-18 13:51:00 -08:00
|
|
|
nsISMILAttr*
|
|
|
|
nsSVGInteger::ToSMILAttr(nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
return new SMILInteger(this, aSVGElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGInteger::SMILInteger::ValueFromString(const nsAString& aStr,
|
2013-03-18 20:18:45 -07:00
|
|
|
const dom::SVGAnimationElement* /*aSrcElement*/,
|
2010-02-20 13:13:11 -08:00
|
|
|
nsSMILValue& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2010-02-18 13:51:00 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t val;
|
2010-02-18 13:51:00 -08:00
|
|
|
|
2013-10-01 00:50:40 -07:00
|
|
|
if (!SVGContentUtils::ParseInteger(aStr, val)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2010-02-18 13:51:00 -08:00
|
|
|
}
|
|
|
|
|
2013-05-30 15:34:53 -07:00
|
|
|
nsSMILValue smilVal(SMILIntegerType::Singleton());
|
2010-02-18 13:51:00 -08:00
|
|
|
smilVal.mU.mInt = val;
|
|
|
|
aValue = smilVal;
|
2011-10-17 07:59:28 -07:00
|
|
|
aPreventCachingOfSandwich = false;
|
2010-02-18 13:51:00 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSVGInteger::SMILInteger::GetBaseValue() const
|
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
nsSMILValue val(SMILIntegerType::Singleton());
|
2010-02-18 13:51:00 -08:00
|
|
|
val.mU.mInt = mVal->mBaseVal;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGInteger::SMILInteger::ClearAnimValue()
|
|
|
|
{
|
|
|
|
if (mVal->mIsAnimated) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mVal->mIsAnimated = false;
|
2012-03-03 01:21:09 -08:00
|
|
|
mVal->mAnimVal = mVal->mBaseVal;
|
|
|
|
mSVGElement->DidAnimateInteger(mVal->mAttrEnum);
|
2010-02-18 13:51:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGInteger::SMILInteger::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
NS_ASSERTION(aValue.mType == SMILIntegerType::Singleton(),
|
2010-02-18 13:51:00 -08:00
|
|
|
"Unexpected type to assign animated value");
|
2013-05-30 15:34:53 -07:00
|
|
|
if (aValue.mType == SMILIntegerType::Singleton()) {
|
2010-02-18 13:51:00 -08:00
|
|
|
mVal->SetAnimValue(int(aValue.mU.mInt), mSVGElement);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|