2011-01-23 09:08:17 -08: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/. */
|
2011-01-23 09:08:17 -08:00
|
|
|
|
|
|
|
#include "nsSVGClass.h"
|
2012-12-23 00:22:22 -08:00
|
|
|
#include "nsSVGElement.h"
|
2011-01-23 09:08:17 -08:00
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "SMILStringType.h"
|
2013-06-14 15:37:27 -07:00
|
|
|
#include "mozilla/dom/SVGAnimatedString.h"
|
2011-01-23 09:08:17 -08:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-06-14 15:37:27 -07:00
|
|
|
using namespace mozilla::dom;
|
2011-01-23 09:08:17 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
struct DOMAnimatedString final : public SVGAnimatedString
|
2013-06-14 15:37:27 -07:00
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMAnimatedString)
|
|
|
|
|
|
|
|
DOMAnimatedString(nsSVGClass* aVal, nsSVGElement* aSVGElement)
|
|
|
|
: SVGAnimatedString(aSVGElement)
|
|
|
|
, mVal(aVal)
|
|
|
|
{}
|
|
|
|
|
|
|
|
nsSVGClass* mVal; // kept alive because it belongs to content
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
void GetBaseVal(nsAString& aResult) override
|
2013-06-14 15:37:27 -07:00
|
|
|
{
|
|
|
|
mVal->GetBaseValue(aResult, mSVGElement);
|
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
void SetBaseVal(const nsAString& aValue) override
|
2013-06-14 15:37:27 -07:00
|
|
|
{
|
|
|
|
mVal->SetBaseValue(aValue, mSVGElement, true);
|
|
|
|
}
|
2011-01-23 09:08:17 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
void GetAnimVal(nsAString& aResult) override;
|
2014-06-24 09:36:45 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
~DOMAnimatedString() {}
|
2013-06-14 15:37:27 -07:00
|
|
|
};
|
2011-01-23 09:08:17 -08:00
|
|
|
|
2013-06-14 15:37:27 -07:00
|
|
|
NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMAnimatedString, mSVGElement)
|
2011-01-23 09:08:17 -08:00
|
|
|
|
2013-06-14 15:37:27 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMAnimatedString)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMAnimatedString)
|
|
|
|
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMAnimatedString)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-01-23 09:08:17 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-06-14 15:37:27 -07:00
|
|
|
already_AddRefed<SVGAnimatedString>
|
|
|
|
nsSVGClass::ToDOMAnimatedString(nsSVGElement* aSVGElement)
|
|
|
|
{
|
|
|
|
nsRefPtr<DOMAnimatedString> result = new DOMAnimatedString(this, aSVGElement);
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2011-01-23 09:08:17 -08:00
|
|
|
/* Implementation */
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGClass::SetBaseValue(const nsAString& aValue,
|
2012-12-23 00:22:22 -08:00
|
|
|
nsSVGElement *aSVGElement,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDoSetAttr)
|
2011-01-23 09:08:17 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue");
|
|
|
|
|
|
|
|
aSVGElement->SetFlags(NODE_MAY_HAVE_CLASS);
|
|
|
|
if (aDoSetAttr) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aSVGElement->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, aValue, true);
|
2011-01-23 09:08:17 -08:00
|
|
|
}
|
|
|
|
if (mAnimVal) {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-23 00:22:22 -08:00
|
|
|
nsSVGClass::GetBaseValue(nsAString& aValue, const nsSVGElement *aSVGElement) const
|
2011-10-18 05:43:57 -07:00
|
|
|
{
|
|
|
|
aSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-23 00:22:22 -08:00
|
|
|
nsSVGClass::GetAnimValue(nsAString& aResult, const nsSVGElement *aSVGElement) const
|
2011-01-23 09:08:17 -08:00
|
|
|
{
|
|
|
|
if (mAnimVal) {
|
|
|
|
aResult = *mAnimVal;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-23 00:22:22 -08:00
|
|
|
nsSVGClass::SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement)
|
2011-01-23 09:08:17 -08:00
|
|
|
{
|
2012-06-01 16:53:06 -07:00
|
|
|
if (mAnimVal && mAnimVal->Equals(aValue)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-23 09:08:17 -08:00
|
|
|
if (!mAnimVal) {
|
|
|
|
mAnimVal = new nsString();
|
|
|
|
}
|
|
|
|
*mAnimVal = aValue;
|
|
|
|
aSVGElement->SetFlags(NODE_MAY_HAVE_CLASS);
|
|
|
|
aSVGElement->DidAnimateClass();
|
|
|
|
}
|
|
|
|
|
2013-06-14 15:37:27 -07:00
|
|
|
void
|
|
|
|
DOMAnimatedString::GetAnimVal(nsAString& aResult)
|
|
|
|
{
|
2011-10-18 05:43:57 -07:00
|
|
|
mSVGElement->FlushAnimations();
|
|
|
|
mVal->GetAnimValue(aResult, mSVGElement);
|
|
|
|
}
|
|
|
|
|
2011-11-01 12:22:30 -07:00
|
|
|
nsISMILAttr*
|
2012-12-23 00:22:22 -08:00
|
|
|
nsSVGClass::ToSMILAttr(nsSVGElement *aSVGElement)
|
2011-11-01 12:22:30 -07:00
|
|
|
{
|
|
|
|
return new SMILString(this, aSVGElement);
|
|
|
|
}
|
|
|
|
|
2011-01-23 09:08:17 -08:00
|
|
|
nsresult
|
|
|
|
nsSVGClass::SMILString::ValueFromString(const nsAString& aStr,
|
2013-03-18 20:18:45 -07:00
|
|
|
const dom::SVGAnimationElement* /*aSrcElement*/,
|
2011-01-23 09:08:17 -08:00
|
|
|
nsSMILValue& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2011-01-23 09:08:17 -08:00
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
nsSMILValue val(SMILStringType::Singleton());
|
2011-01-23 09:08:17 -08:00
|
|
|
|
|
|
|
*static_cast<nsAString*>(val.mU.mPtr) = aStr;
|
|
|
|
aValue.Swap(val);
|
2011-10-17 07:59:28 -07:00
|
|
|
aPreventCachingOfSandwich = false;
|
2011-01-23 09:08:17 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSVGClass::SMILString::GetBaseValue() const
|
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
nsSMILValue val(SMILStringType::Singleton());
|
2011-01-23 09:08:17 -08:00
|
|
|
mSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class,
|
|
|
|
*static_cast<nsAString*>(val.mU.mPtr));
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGClass::SMILString::ClearAnimValue()
|
|
|
|
{
|
|
|
|
if (mVal->mAnimVal) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mVal->mAnimVal = nullptr;
|
2011-01-23 09:08:17 -08:00
|
|
|
mSVGElement->DidAnimateClass();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGClass::SMILString::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
NS_ASSERTION(aValue.mType == SMILStringType::Singleton(),
|
2011-01-23 09:08:17 -08:00
|
|
|
"Unexpected type to assign animated value");
|
2013-05-30 15:34:53 -07:00
|
|
|
if (aValue.mType == SMILStringType::Singleton()) {
|
2011-01-23 09:08:17 -08:00
|
|
|
mVal->SetAnimValue(*static_cast<nsAString*>(aValue.mU.mPtr), mSVGElement);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|