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