2011-07-01 07:19:52 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2011-07-01 07:19:52 +00:00
|
|
|
|
|
|
|
#include "nsSVGIntegerPair.h"
|
2012-12-21 09:18:58 +00:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2011-07-23 08:41:17 +00:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2011-08-01 17:43:23 +00:00
|
|
|
#include "nsMathUtils.h"
|
2011-07-01 07:19:52 +00:00
|
|
|
#include "nsSMILValue.h"
|
2012-09-22 19:26:05 +00:00
|
|
|
#include "SVGContentUtils.h"
|
2011-07-01 07:19:52 +00:00
|
|
|
#include "SVGIntegerPairSMILType.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-07-01 07:02:56 +00:00
|
|
|
using namespace mozilla::dom;
|
2011-07-01 07:19:52 +00:00
|
|
|
|
2012-12-21 09:18:58 +00:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGIntegerPair, nsSVGIntegerPair::DOMAnimatedInteger>
|
|
|
|
sSVGFirstAnimatedIntegerTearoffTable;
|
|
|
|
static nsSVGAttrTearoffTable<nsSVGIntegerPair, nsSVGIntegerPair::DOMAnimatedInteger>
|
|
|
|
sSVGSecondAnimatedIntegerTearoffTable;
|
|
|
|
|
2011-07-01 07:19:52 +00:00
|
|
|
/* Implementation */
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
ParseIntegerOptionalInteger(const nsAString& aValue,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aValues[2])
|
2011-07-01 07:19:52 +00:00
|
|
|
{
|
2011-07-23 08:41:17 +00:00
|
|
|
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
|
|
|
|
tokenizer(aValue, ',',
|
|
|
|
nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
|
2013-09-17 12:52:39 +00:00
|
|
|
if (tokenizer.whitespaceBeforeFirstToken()) {
|
2011-07-23 08:41:17 +00:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2011-07-01 07:19:52 +00:00
|
|
|
}
|
2011-07-23 08:41:17 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2011-07-23 08:41:17 +00:00
|
|
|
for (i = 0; i < 2 && tokenizer.hasMoreTokens(); ++i) {
|
2013-10-01 07:50:40 +00:00
|
|
|
if (!SVGContentUtils::ParseInteger(tokenizer.nextToken(), aValues[i])) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2011-07-01 07:19:52 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-23 08:41:17 +00:00
|
|
|
if (i == 1) {
|
|
|
|
aValues[1] = aValues[0];
|
|
|
|
}
|
2011-07-01 07:19:52 +00:00
|
|
|
|
2011-07-23 08:41:17 +00:00
|
|
|
if (i == 0 || // Too few values.
|
|
|
|
tokenizer.hasMoreTokens() || // Too many values.
|
2013-09-17 12:52:39 +00:00
|
|
|
tokenizer.whitespaceAfterCurrentToken() || // Trailing whitespace.
|
|
|
|
tokenizer.separatorAfterCurrentToken()) { // Trailing comma.
|
2011-07-23 08:41:17 +00:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
2011-07-01 07:19:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGIntegerPair::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 val[2];
|
2011-07-01 07:19:52 +00:00
|
|
|
|
|
|
|
nsresult rv = ParseIntegerOptionalInteger(aValueAsString, val);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBaseVal[0] = val[0];
|
|
|
|
mBaseVal[1] = val[1];
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsBaseSet = true;
|
2011-07-01 07:19:52 +00:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal[0] = mBaseVal[0];
|
|
|
|
mAnimVal[1] = mBaseVal[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't need to call DidChange* here - we're only called by
|
2012-11-14 22:10:08 +00:00
|
|
|
// nsSVGElement::ParseAttribute under Element::SetAttr,
|
2011-07-01 07:19:52 +00:00
|
|
|
// which takes care of notifying.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-15 23:40:45 +00:00
|
|
|
nsSVGIntegerPair::GetBaseValueString(nsAString &aValueAsString) const
|
2011-07-01 07:19:52 +00:00
|
|
|
{
|
|
|
|
aValueAsString.Truncate();
|
|
|
|
aValueAsString.AppendInt(mBaseVal[0]);
|
|
|
|
if (mBaseVal[0] != mBaseVal[1]) {
|
|
|
|
aValueAsString.AppendLiteral(", ");
|
|
|
|
aValueAsString.AppendInt(mBaseVal[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGIntegerPair::SetBaseValue(int32_t aValue, PairIndex aPairIndex,
|
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
|
|
|
uint32_t index = (aPairIndex == eFirst ? 0 : 1);
|
2012-02-15 23:40:45 +00:00
|
|
|
if (mIsBaseSet && mBaseVal[index] == aValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangeIntegerPair(mAttrEnum);
|
2011-07-01 07:19:52 +00:00
|
|
|
mBaseVal[index] = aValue;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsBaseSet = true;
|
2011-07-01 07:19:52 +00:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal[index] = aValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2012-02-15 23:40:45 +00:00
|
|
|
aSVGElement->DidChangeIntegerPair(mAttrEnum, emptyOrOldValue);
|
2011-07-01 07:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGIntegerPair::SetBaseValues(int32_t aValue1, int32_t aValue2,
|
2011-10-09 15:25:07 +00:00
|
|
|
nsSVGElement *aSVGElement)
|
2011-07-01 07:19:52 +00:00
|
|
|
{
|
2012-02-15 23:40:45 +00:00
|
|
|
if (mIsBaseSet && mBaseVal[0] == aValue1 && mBaseVal[1] == aValue2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangeIntegerPair(mAttrEnum);
|
2011-07-01 07:19:52 +00:00
|
|
|
mBaseVal[0] = aValue1;
|
|
|
|
mBaseVal[1] = aValue2;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsBaseSet = true;
|
2011-07-01 07:19:52 +00:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal[0] = aValue1;
|
|
|
|
mAnimVal[1] = aValue2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2012-02-15 23:40:45 +00:00
|
|
|
aSVGElement->DidChangeIntegerPair(mAttrEnum, emptyOrOldValue);
|
2011-07-01 07:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGIntegerPair::SetAnimValue(const int32_t aValue[2], nsSVGElement *aSVGElement)
|
2011-07-01 07:19:52 +00:00
|
|
|
{
|
2012-06-01 23:53:06 +00:00
|
|
|
if (mIsAnimated && mAnimVal[0] == aValue[0] && mAnimVal[1] == aValue[1]) {
|
|
|
|
return;
|
|
|
|
}
|
2011-07-01 07:19:52 +00:00
|
|
|
mAnimVal[0] = aValue[0];
|
|
|
|
mAnimVal[1] = aValue[1];
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsAnimated = true;
|
2011-07-01 07:19:52 +00:00
|
|
|
aSVGElement->DidAnimateIntegerPair(mAttrEnum);
|
|
|
|
}
|
|
|
|
|
2013-07-01 07:02:56 +00:00
|
|
|
already_AddRefed<SVGAnimatedInteger>
|
2013-02-18 02:14:02 +00:00
|
|
|
nsSVGIntegerPair::ToDOMAnimatedInteger(PairIndex aIndex,
|
|
|
|
nsSVGElement* aSVGElement)
|
2011-07-01 07:19:52 +00:00
|
|
|
{
|
2012-12-21 09:18:58 +00:00
|
|
|
nsRefPtr<DOMAnimatedInteger> domAnimatedInteger =
|
|
|
|
aIndex == eFirst ? sSVGFirstAnimatedIntegerTearoffTable.GetTearoff(this) :
|
|
|
|
sSVGSecondAnimatedIntegerTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimatedInteger) {
|
|
|
|
domAnimatedInteger = new DOMAnimatedInteger(this, aIndex, aSVGElement);
|
|
|
|
if (aIndex == eFirst) {
|
|
|
|
sSVGFirstAnimatedIntegerTearoffTable.AddTearoff(this, domAnimatedInteger);
|
|
|
|
} else {
|
|
|
|
sSVGSecondAnimatedIntegerTearoffTable.AddTearoff(this, domAnimatedInteger);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 02:14:02 +00:00
|
|
|
return domAnimatedInteger.forget();
|
2011-07-01 07:19:52 +00:00
|
|
|
}
|
|
|
|
|
2012-12-21 09:18:58 +00:00
|
|
|
nsSVGIntegerPair::DOMAnimatedInteger::~DOMAnimatedInteger()
|
|
|
|
{
|
|
|
|
if (mIndex == eFirst) {
|
|
|
|
sSVGFirstAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
|
|
|
|
} else {
|
|
|
|
sSVGSecondAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-01 07:19:52 +00:00
|
|
|
nsISMILAttr*
|
|
|
|
nsSVGIntegerPair::ToSMILAttr(nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
return new SMILIntegerPair(this, aSVGElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGIntegerPair::SMILIntegerPair::ValueFromString(const nsAString& aStr,
|
2013-03-19 03:18:45 +00:00
|
|
|
const dom::SVGAnimationElement* /*aSrcElement*/,
|
2011-07-01 07:19:52 +00:00
|
|
|
nsSMILValue& aValue,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2011-07-01 07:19:52 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t values[2];
|
2011-07-01 07:19:52 +00:00
|
|
|
|
|
|
|
nsresult rv = ParseIntegerOptionalInteger(aStr, values);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-05-30 22:34:53 +00:00
|
|
|
nsSMILValue val(SVGIntegerPairSMILType::Singleton());
|
2011-07-01 07:19:52 +00:00
|
|
|
val.mU.mIntPair[0] = values[0];
|
|
|
|
val.mU.mIntPair[1] = values[1];
|
|
|
|
aValue = val;
|
2011-10-17 14:59:28 +00:00
|
|
|
aPreventCachingOfSandwich = false;
|
2011-07-01 07:19:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSVGIntegerPair::SMILIntegerPair::GetBaseValue() const
|
|
|
|
{
|
2013-05-30 22:34:53 +00:00
|
|
|
nsSMILValue val(SVGIntegerPairSMILType::Singleton());
|
2011-07-01 07:19:52 +00:00
|
|
|
val.mU.mIntPair[0] = mVal->mBaseVal[0];
|
|
|
|
val.mU.mIntPair[1] = mVal->mBaseVal[1];
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGIntegerPair::SMILIntegerPair::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[0] = mVal->mBaseVal[0];
|
|
|
|
mVal->mAnimVal[1] = mVal->mBaseVal[1];
|
|
|
|
mSVGElement->DidAnimateIntegerPair(mVal->mAttrEnum);
|
2011-07-01 07:19:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGIntegerPair::SMILIntegerPair::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
2013-05-30 22:34:53 +00:00
|
|
|
NS_ASSERTION(aValue.mType == SVGIntegerPairSMILType::Singleton(),
|
2011-07-01 07:19:52 +00:00
|
|
|
"Unexpected type to assign animated value");
|
2013-05-30 22:34:53 +00:00
|
|
|
if (aValue.mType == SVGIntegerPairSMILType::Singleton()) {
|
2011-07-01 07:19:52 +00:00
|
|
|
mVal->SetAnimValue(aValue.mU.mIntPair, mSVGElement);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|