gecko-dev/dom/svg/SVGAnimatedInteger.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

144 строки
4.1 KiB
C++
Исходник Обычный вид История

/* -*- 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/. */
#include "SVGAnimatedInteger.h"
#include "nsError.h"
#include "SMILIntegerType.h"
#include "SVGAttrTearoffTable.h"
#include "mozilla/SMILValue.h"
#include "mozilla/SVGContentUtils.h"
using namespace mozilla::dom;
namespace mozilla {
/* Implementation */
static SVGAttrTearoffTable<SVGAnimatedInteger,
SVGAnimatedInteger::DOMAnimatedInteger>
sSVGAnimatedIntegerTearoffTable;
nsresult SVGAnimatedInteger::SetBaseValueString(const nsAString& aValueAsString,
SVGElement* aSVGElement) {
bool success;
auto token = SVGContentUtils::GetAndEnsureOneToken(aValueAsString, success);
if (!success) {
return NS_ERROR_DOM_SYNTAX_ERR;
}
int32_t value;
if (!SVGContentUtils::ParseInteger(token, value)) {
return NS_ERROR_DOM_SYNTAX_ERR;
}
mIsBaseSet = true;
mBaseVal = value;
if (!mIsAnimated) {
mAnimVal = mBaseVal;
} else {
aSVGElement->AnimationNeedsResample();
}
return NS_OK;
}
void SVGAnimatedInteger::GetBaseValueString(nsAString& aValueAsString) {
aValueAsString.Truncate();
aValueAsString.AppendInt(mBaseVal);
}
void SVGAnimatedInteger::SetBaseValue(int aValue, SVGElement* aSVGElement) {
// 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;
}
mBaseVal = aValue;
mIsBaseSet = true;
if (!mIsAnimated) {
mAnimVal = mBaseVal;
} else {
aSVGElement->AnimationNeedsResample();
}
aSVGElement->DidChangeInteger(mAttrEnum);
}
void SVGAnimatedInteger::SetAnimValue(int aValue, SVGElement* aSVGElement) {
if (mIsAnimated && aValue == mAnimVal) {
return;
}
mAnimVal = aValue;
mIsAnimated = true;
aSVGElement->DidAnimateInteger(mAttrEnum);
}
already_AddRefed<DOMSVGAnimatedInteger>
SVGAnimatedInteger::ToDOMAnimatedInteger(SVGElement* aSVGElement) {
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<DOMAnimatedInteger> domAnimatedInteger =
sSVGAnimatedIntegerTearoffTable.GetTearoff(this);
if (!domAnimatedInteger) {
domAnimatedInteger = new DOMAnimatedInteger(this, aSVGElement);
sSVGAnimatedIntegerTearoffTable.AddTearoff(this, domAnimatedInteger);
}
return domAnimatedInteger.forget();
}
SVGAnimatedInteger::DOMAnimatedInteger::~DOMAnimatedInteger() {
sSVGAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
}
UniquePtr<SMILAttr> SVGAnimatedInteger::ToSMILAttr(SVGElement* aSVGElement) {
return MakeUnique<SMILInteger>(this, aSVGElement);
}
nsresult SVGAnimatedInteger::SMILInteger::ValueFromString(
const nsAString& aStr, const dom::SVGAnimationElement* /*aSrcElement*/,
SMILValue& aValue, bool& aPreventCachingOfSandwich) const {
int32_t val;
if (!SVGContentUtils::ParseInteger(aStr, val)) {
return NS_ERROR_DOM_SYNTAX_ERR;
}
SMILValue smilVal(SMILIntegerType::Singleton());
smilVal.mU.mInt = val;
aValue = smilVal;
aPreventCachingOfSandwich = false;
return NS_OK;
}
SMILValue SVGAnimatedInteger::SMILInteger::GetBaseValue() const {
SMILValue val(SMILIntegerType::Singleton());
val.mU.mInt = mVal->mBaseVal;
return val;
}
void SVGAnimatedInteger::SMILInteger::ClearAnimValue() {
if (mVal->mIsAnimated) {
mVal->mIsAnimated = false;
mVal->mAnimVal = mVal->mBaseVal;
mSVGElement->DidAnimateInteger(mVal->mAttrEnum);
}
}
nsresult SVGAnimatedInteger::SMILInteger::SetAnimValue(
const SMILValue& aValue) {
NS_ASSERTION(aValue.mType == SMILIntegerType::Singleton(),
"Unexpected type to assign animated value");
if (aValue.mType == SMILIntegerType::Singleton()) {
mVal->SetAnimValue(int(aValue.mU.mInt), mSVGElement);
}
return NS_OK;
}
} // namespace mozilla