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