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