2008-06-14 02:09:44 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2008-06-14 02:09:44 -07:00
|
|
|
|
|
|
|
#include "nsSVGString.h"
|
2012-12-21 01:18:58 -08:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2010-10-07 12:19:32 -07:00
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "SMILStringType.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-06-14 15:37:27 -07:00
|
|
|
using namespace mozilla::dom;
|
2008-06-14 02:09:44 -07:00
|
|
|
|
2013-06-14 15:37:27 -07:00
|
|
|
NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(nsSVGString::DOMAnimatedString, mSVGElement)
|
2008-06-14 02:09:44 -07:00
|
|
|
|
2008-12-30 08:32:22 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGString::DOMAnimatedString)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGString::DOMAnimatedString)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGString::DOMAnimatedString)
|
2013-06-14 15:37:27 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2008-06-14 02:09:44 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-05-30 15:34:53 -07:00
|
|
|
static inline
|
|
|
|
nsSVGAttrTearoffTable<nsSVGString, nsSVGString::DOMAnimatedString>&
|
|
|
|
SVGAnimatedStringTearoffTable()
|
|
|
|
{
|
|
|
|
static nsSVGAttrTearoffTable<nsSVGString, nsSVGString::DOMAnimatedString>
|
|
|
|
sSVGAnimatedStringTearoffTable;
|
|
|
|
return sSVGAnimatedStringTearoffTable;
|
|
|
|
}
|
2012-12-21 01:18:58 -08:00
|
|
|
|
2008-06-14 02:09:44 -07:00
|
|
|
/* Implementation */
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGString::SetBaseValue(const nsAString& aValue,
|
|
|
|
nsSVGElement *aSVGElement,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDoSetAttr)
|
2008-06-14 02:09:44 -07:00
|
|
|
{
|
2009-01-21 16:56:51 -08:00
|
|
|
NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue");
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsBaseSet = true;
|
2009-01-21 16:56:51 -08:00
|
|
|
if (aDoSetAttr) {
|
|
|
|
aSVGElement->SetStringBaseValue(mAttrEnum, aValue);
|
|
|
|
}
|
2010-10-07 12:19:32 -07:00
|
|
|
if (mAnimVal) {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2009-01-21 16:56:51 -08:00
|
|
|
|
|
|
|
aSVGElement->DidChangeString(mAttrEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-07 12:19:32 -07:00
|
|
|
nsSVGString::GetAnimValue(nsAString& aResult, const nsSVGElement *aSVGElement) const
|
2009-01-21 16:56:51 -08:00
|
|
|
{
|
2010-10-07 12:19:32 -07:00
|
|
|
if (mAnimVal) {
|
2009-01-21 16:56:51 -08:00
|
|
|
aResult = *mAnimVal;
|
2010-10-07 12:19:32 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-01-21 16:56:51 -08:00
|
|
|
|
|
|
|
aSVGElement->GetStringBaseValue(mAttrEnum, aResult);
|
2008-06-14 02:09:44 -07:00
|
|
|
}
|
|
|
|
|
2010-10-07 12:19:32 -07:00
|
|
|
void
|
|
|
|
nsSVGString::SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
if (aSVGElement->IsStringAnimatable(mAttrEnum)) {
|
2012-06-01 16:53:06 -07:00
|
|
|
if (mAnimVal && mAnimVal->Equals(aValue)) {
|
|
|
|
return;
|
|
|
|
}
|
2010-10-07 12:19:32 -07:00
|
|
|
if (!mAnimVal) {
|
|
|
|
mAnimVal = new nsString();
|
|
|
|
}
|
|
|
|
*mAnimVal = aValue;
|
|
|
|
aSVGElement->DidAnimateString(mAttrEnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-14 15:37:27 -07:00
|
|
|
already_AddRefed<SVGAnimatedString>
|
2013-02-07 00:08:56 -08:00
|
|
|
nsSVGString::ToDOMAnimatedString(nsSVGElement* aSVGElement)
|
2008-06-14 02:09:44 -07:00
|
|
|
{
|
2012-12-21 01:18:58 -08:00
|
|
|
nsRefPtr<DOMAnimatedString> domAnimatedString =
|
2013-05-30 15:34:53 -07:00
|
|
|
SVGAnimatedStringTearoffTable().GetTearoff(this);
|
2012-12-21 01:18:58 -08:00
|
|
|
if (!domAnimatedString) {
|
|
|
|
domAnimatedString = new DOMAnimatedString(this, aSVGElement);
|
2013-05-30 15:34:53 -07:00
|
|
|
SVGAnimatedStringTearoffTable().AddTearoff(this, domAnimatedString);
|
2012-12-21 01:18:58 -08:00
|
|
|
}
|
2008-06-14 02:09:44 -07:00
|
|
|
|
2013-02-07 00:08:56 -08:00
|
|
|
return domAnimatedString.forget();
|
2008-06-14 02:09:44 -07:00
|
|
|
}
|
2010-10-07 12:19:32 -07:00
|
|
|
|
2012-12-21 01:18:58 -08:00
|
|
|
nsSVGString::DOMAnimatedString::~DOMAnimatedString()
|
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
SVGAnimatedStringTearoffTable().RemoveTearoff(mVal);
|
2012-12-21 01:18:58 -08:00
|
|
|
}
|
|
|
|
|
2010-10-07 12:19:32 -07:00
|
|
|
nsISMILAttr*
|
|
|
|
nsSVGString::ToSMILAttr(nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
return new SMILString(this, aSVGElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGString::SMILString::ValueFromString(const nsAString& aStr,
|
2013-03-18 20:18:45 -07:00
|
|
|
const dom::SVGAnimationElement* /*aSrcElement*/,
|
2010-10-07 12:19:32 -07:00
|
|
|
nsSMILValue& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2010-10-07 12:19:32 -07:00
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
nsSMILValue val(SMILStringType::Singleton());
|
2010-10-07 12:19:32 -07:00
|
|
|
|
|
|
|
*static_cast<nsAString*>(val.mU.mPtr) = aStr;
|
|
|
|
aValue.Swap(val);
|
2011-10-17 07:59:28 -07:00
|
|
|
aPreventCachingOfSandwich = false;
|
2010-10-07 12:19:32 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSVGString::SMILString::GetBaseValue() const
|
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
nsSMILValue val(SMILStringType::Singleton());
|
2010-10-07 12:19:32 -07:00
|
|
|
mSVGElement->GetStringBaseValue(mVal->mAttrEnum, *static_cast<nsAString*>(val.mU.mPtr));
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGString::SMILString::ClearAnimValue()
|
|
|
|
{
|
|
|
|
if (mVal->mAnimVal) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mVal->mAnimVal = nullptr;
|
2010-10-07 12:19:32 -07:00
|
|
|
mSVGElement->DidAnimateString(mVal->mAttrEnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGString::SMILString::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
NS_ASSERTION(aValue.mType == SMILStringType::Singleton(),
|
2010-10-07 12:19:32 -07:00
|
|
|
"Unexpected type to assign animated value");
|
2013-05-30 15:34:53 -07:00
|
|
|
if (aValue.mType == SMILStringType::Singleton()) {
|
2010-10-07 12:19:32 -07:00
|
|
|
mVal->SetAnimValue(*static_cast<nsAString*>(aValue.mU.mPtr), mSVGElement);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|