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
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "SVGAnimatedInteger.h"
|
2018-12-28 05:47:10 +03:00
|
|
|
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2019-01-24 00:48:00 +03:00
|
|
|
#include "SMILIntegerType.h"
|
|
|
|
#include "SVGAttrTearoffTable.h"
|
2019-01-23 16:48:08 +03:00
|
|
|
#include "mozilla/SMILValue.h"
|
|
|
|
#include "mozilla/SVGContentUtils.h"
|
2007-09-18 16:09:26 +04:00
|
|
|
|
2013-07-01 11:02:56 +04:00
|
|
|
using namespace mozilla::dom;
|
2007-09-18 16:09:26 +04:00
|
|
|
|
2019-01-07 22:23:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2007-09-18 16:09:26 +04:00
|
|
|
/* Implementation */
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
static SVGAttrTearoffTable<SVGAnimatedInteger,
|
|
|
|
SVGAnimatedInteger::DOMAnimatedInteger>
|
2012-12-21 13:18:58 +04:00
|
|
|
sSVGAnimatedIntegerTearoffTable;
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedInteger::SetBaseValueString(const nsAString& aValueAsString,
|
|
|
|
SVGElement* aSVGElement) {
|
2019-03-27 11:52:33 +03:00
|
|
|
bool success;
|
|
|
|
auto token = SVGContentUtils::GetAndEnsureOneToken(aValueAsString, success);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t value;
|
2011-07-01 11:19:52 +04:00
|
|
|
|
2019-03-27 11:52:33 +03:00
|
|
|
if (!SVGContentUtils::ParseInteger(token, value)) {
|
2013-10-01 11:50:40 +04:00
|
|
|
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;
|
2020-08-03 01:20:49 +03:00
|
|
|
} 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
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedInteger::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
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedInteger::SetBaseValue(int aValue, SVGElement* aSVGElement) {
|
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;
|
2020-08-03 01:20:49 +03:00
|
|
|
} else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
2010-02-19 00:51:00 +03:00
|
|
|
}
|
2020-08-03 01:20:49 +03:00
|
|
|
aSVGElement->DidChangeInteger(mAttrEnum);
|
2010-02-19 00:51:00 +03:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedInteger::SetAnimValue(int aValue, SVGElement* 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
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedInteger>
|
|
|
|
SVGAnimatedInteger::ToDOMAnimatedInteger(SVGElement* aSVGElement) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMAnimatedInteger> domAnimatedInteger =
|
2012-12-21 13:18:58 +04:00
|
|
|
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
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedInteger::DOMAnimatedInteger::~DOMAnimatedInteger() {
|
2012-12-21 13:18:58 +04:00
|
|
|
sSVGAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
UniquePtr<SMILAttr> SVGAnimatedInteger::ToSMILAttr(SVGElement* aSVGElement) {
|
2017-03-30 07:10:07 +03:00
|
|
|
return MakeUnique<SMILInteger>(this, aSVGElement);
|
2010-02-19 00:51:00 +03:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedInteger::SMILInteger::ValueFromString(
|
2013-03-19 07:18:45 +04:00
|
|
|
const nsAString& aStr, const dom::SVGAnimationElement* /*aSrcElement*/,
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue& aValue, bool& aPreventCachingOfSandwich) const {
|
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
|
|
|
}
|
|
|
|
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue 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;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
SMILValue SVGAnimatedInteger::SMILInteger::GetBaseValue() const {
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue val(SMILIntegerType::Singleton());
|
2010-02-19 00:51:00 +03:00
|
|
|
val.mU.mInt = mVal->mBaseVal;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedInteger::SMILInteger::ClearAnimValue() {
|
2010-02-19 00:51:00 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedInteger::SMILInteger::SetAnimValue(
|
|
|
|
const SMILValue& 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;
|
|
|
|
}
|
2019-01-07 22:23:13 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|