2015-05-03 19:32:37 +00: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 11:12:37 +00: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/. */
|
2005-09-06 22:30:40 +00:00
|
|
|
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2012-12-21 09:18:58 +00:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2007-09-18 12:09:26 +00:00
|
|
|
#include "nsSVGInteger.h"
|
2010-02-18 21:51:00 +00:00
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "SMILIntegerType.h"
|
2013-09-17 12:52:39 +00:00
|
|
|
#include "SVGContentUtils.h"
|
2007-09-18 12:09:26 +00:00
|
|
|
|
2010-02-18 21:51:00 +00:00
|
|
|
using namespace mozilla;
|
2013-07-01 07:02:56 +00:00
|
|
|
using namespace mozilla::dom;
|
2007-09-18 12:09:26 +00:00
|
|
|
|
|
|
|
/* Implementation */
|
|
|
|
|
2012-12-21 09:18:58 +00:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGInteger, nsSVGInteger::DOMAnimatedInteger>
|
|
|
|
sSVGAnimatedIntegerTearoffTable;
|
|
|
|
|
2011-07-01 07:19:52 +00:00
|
|
|
nsresult
|
|
|
|
nsSVGInteger::SetBaseValueString(const nsAString &aValueAsString,
|
2011-10-09 15:25:07 +00:00
|
|
|
nsSVGElement *aSVGElement)
|
2011-07-01 07:19:52 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t value;
|
2011-07-01 07:19:52 +00:00
|
|
|
|
2013-10-01 07:50:40 +00:00
|
|
|
if (!SVGContentUtils::ParseInteger(aValueAsString, value)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2011-07-01 07:19:52 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsBaseSet = true;
|
2011-07-01 07:19:52 +00:00
|
|
|
mBaseVal = value;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
2010-02-18 21:51:00 +00:00
|
|
|
}
|
2007-09-18 12:09:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-09-06 22:30:40 +00:00
|
|
|
|
2007-09-18 12:09:26 +00:00
|
|
|
void
|
|
|
|
nsSVGInteger::GetBaseValueString(nsAString & aValueAsString)
|
|
|
|
{
|
2011-07-01 07:19:52 +00:00
|
|
|
aValueAsString.Truncate();
|
|
|
|
aValueAsString.AppendInt(mBaseVal);
|
2007-09-18 12:09:26 +00:00
|
|
|
}
|
2005-09-06 22:30:40 +00:00
|
|
|
|
2007-09-18 12:09:26 +00:00
|
|
|
void
|
2012-02-15 23:40:45 +00:00
|
|
|
nsSVGInteger::SetBaseValue(int aValue, nsSVGElement *aSVGElement)
|
2007-09-18 12:09:26 +00:00
|
|
|
{
|
2012-02-15 23:40:45 +00: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 07:19:52 +00:00
|
|
|
mBaseVal = aValue;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsBaseSet = true;
|
2011-07-01 07:19:52 +00:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
2010-02-18 21:51:00 +00:00
|
|
|
}
|
2012-02-15 23:40:45 +00:00
|
|
|
aSVGElement->DidChangeInteger(mAttrEnum);
|
2010-02-18 21:51:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGInteger::SetAnimValue(int aValue, nsSVGElement *aSVGElement)
|
|
|
|
{
|
2012-06-01 23:53:06 +00:00
|
|
|
if (mIsAnimated && aValue == mAnimVal) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-18 21:51:00 +00:00
|
|
|
mAnimVal = aValue;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsAnimated = true;
|
2010-02-18 21:51:00 +00:00
|
|
|
aSVGElement->DidAnimateInteger(mAttrEnum);
|
2007-09-18 12:09:26 +00:00
|
|
|
}
|
2005-09-06 22:30:40 +00:00
|
|
|
|
2013-07-01 07:02:56 +00:00
|
|
|
already_AddRefed<SVGAnimatedInteger>
|
2013-03-25 06:26:06 +00:00
|
|
|
nsSVGInteger::ToDOMAnimatedInteger(nsSVGElement *aSVGElement)
|
2007-09-18 12:09:26 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMAnimatedInteger> domAnimatedInteger =
|
2012-12-21 09:18:58 +00:00
|
|
|
sSVGAnimatedIntegerTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimatedInteger) {
|
|
|
|
domAnimatedInteger = new DOMAnimatedInteger(this, aSVGElement);
|
|
|
|
sSVGAnimatedIntegerTearoffTable.AddTearoff(this, domAnimatedInteger);
|
|
|
|
}
|
2005-09-06 22:30:40 +00:00
|
|
|
|
2013-03-25 06:26:06 +00:00
|
|
|
return domAnimatedInteger.forget();
|
2007-09-18 12:09:26 +00:00
|
|
|
}
|
2010-02-18 21:51:00 +00:00
|
|
|
|
2012-12-21 09:18:58 +00:00
|
|
|
nsSVGInteger::DOMAnimatedInteger::~DOMAnimatedInteger()
|
|
|
|
{
|
|
|
|
sSVGAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2010-02-18 21:51:00 +00:00
|
|
|
nsISMILAttr*
|
|
|
|
nsSVGInteger::ToSMILAttr(nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
return new SMILInteger(this, aSVGElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGInteger::SMILInteger::ValueFromString(const nsAString& aStr,
|
2013-03-19 03:18:45 +00:00
|
|
|
const dom::SVGAnimationElement* /*aSrcElement*/,
|
2010-02-20 21:13:11 +00:00
|
|
|
nsSMILValue& aValue,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2010-02-18 21:51:00 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t val;
|
2010-02-18 21:51:00 +00:00
|
|
|
|
2013-10-01 07:50:40 +00:00
|
|
|
if (!SVGContentUtils::ParseInteger(aStr, val)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2010-02-18 21:51:00 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 22:34:53 +00:00
|
|
|
nsSMILValue smilVal(SMILIntegerType::Singleton());
|
2010-02-18 21:51:00 +00:00
|
|
|
smilVal.mU.mInt = val;
|
|
|
|
aValue = smilVal;
|
2011-10-17 14:59:28 +00:00
|
|
|
aPreventCachingOfSandwich = false;
|
2010-02-18 21:51:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSVGInteger::SMILInteger::GetBaseValue() const
|
|
|
|
{
|
2013-05-30 22:34:53 +00:00
|
|
|
nsSMILValue val(SMILIntegerType::Singleton());
|
2010-02-18 21:51:00 +00:00
|
|
|
val.mU.mInt = mVal->mBaseVal;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGInteger::SMILInteger::ClearAnimValue()
|
|
|
|
{
|
|
|
|
if (mVal->mIsAnimated) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mVal->mIsAnimated = false;
|
2012-03-03 09:21:09 +00:00
|
|
|
mVal->mAnimVal = mVal->mBaseVal;
|
|
|
|
mSVGElement->DidAnimateInteger(mVal->mAttrEnum);
|
2010-02-18 21:51:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGInteger::SMILInteger::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
2013-05-30 22:34:53 +00:00
|
|
|
NS_ASSERTION(aValue.mType == SMILIntegerType::Singleton(),
|
2010-02-18 21:51:00 +00:00
|
|
|
"Unexpected type to assign animated value");
|
2013-05-30 22:34:53 +00:00
|
|
|
if (aValue.mType == SMILIntegerType::Singleton()) {
|
2010-02-18 21:51:00 +00:00
|
|
|
mVal->SetAnimValue(int(aValue.mU.mInt), mSVGElement);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|