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"
|
2018-12-21 11:58:14 +03:00
|
|
|
#include "SVGElement.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)
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
DOMAnimatedString(nsSVGClass* aVal, SVGElement* aSVGElement)
|
2013-06-15 02:37:27 +04:00
|
|
|
: 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(
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* 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 */
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
void nsSVGClass::SetBaseValue(const nsAString& aValue, SVGElement* aSVGElement,
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-23 12:22:22 +04:00
|
|
|
void nsSVGClass::GetBaseValue(nsAString& aValue,
|
2018-12-21 11:58:14 +03:00
|
|
|
const SVGElement* aSVGElement) const {
|
2011-10-18 16:43:57 +04:00
|
|
|
aSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aValue);
|
|
|
|
}
|
|
|
|
|
2012-12-23 12:22:22 +04:00
|
|
|
void nsSVGClass::GetAnimValue(nsAString& aResult,
|
2018-12-21 11:58:14 +03:00
|
|
|
const SVGElement* aSVGElement) const {
|
2011-01-23 20:08:17 +03:00
|
|
|
if (mAnimVal) {
|
|
|
|
aResult = *mAnimVal;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aResult);
|
|
|
|
}
|
|
|
|
|
2012-12-23 12:22:22 +04:00
|
|
|
void nsSVGClass::SetAnimValue(const nsAString& aValue,
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement) {
|
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);
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
UniquePtr<nsISMILAttr> nsSVGClass::ToSMILAttr(SVGElement* aSVGElement) {
|
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(
|
2013-03-19 07:18:45 +04:00
|
|
|
const nsAString& aStr, const dom::SVGAnimationElement* /*aSrcElement*/,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSMILValue& aValue, bool& aPreventCachingOfSandwich) const {
|
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;
|
|
|
|
}
|