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