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/. */
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "SVGAnimatedEnumeration.h"
|
2018-12-28 05:47:10 +03:00
|
|
|
|
2019-01-02 21:24:11 +03:00
|
|
|
#include "mozilla/dom/SVGElement.h"
|
2019-01-23 16:48:08 +03:00
|
|
|
#include "mozilla/SMILValue.h"
|
2019-01-02 21:24:11 +03:00
|
|
|
#include "nsAtom.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2019-01-02 21:44:12 +03:00
|
|
|
#include "SMILEnumType.h"
|
2019-01-24 00:48:00 +03:00
|
|
|
#include "SVGAttrTearoffTable.h"
|
2010-01-23 21:59:03 +03:00
|
|
|
|
2013-07-01 11:02:46 +04:00
|
|
|
using namespace mozilla::dom;
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2019-01-02 21:24:11 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
static SVGAttrTearoffTable<SVGAnimatedEnumeration,
|
|
|
|
SVGAnimatedEnumeration::DOMAnimatedEnum>
|
2012-12-21 13:18:58 +04:00
|
|
|
sSVGAnimatedEnumTearoffTable;
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
const SVGEnumMapping* SVGAnimatedEnumeration::GetMapping(
|
|
|
|
SVGElement* aSVGElement) {
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::EnumAttributesInfo info = aSVGElement->GetEnumInfo();
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2007-08-28 03:11:14 +04:00
|
|
|
NS_ASSERTION(info.mEnumCount > 0 && mAttrEnum < info.mEnumCount,
|
|
|
|
"mapping request for a non-attrib enum");
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2007-08-28 03:11:14 +04:00
|
|
|
return info.mEnumInfo[mAttrEnum].mMapping;
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedEnumeration::SetBaseValueAtom(const nsAtom* aValue,
|
|
|
|
SVGElement* aSVGElement) {
|
2019-01-02 21:24:11 +03:00
|
|
|
const SVGEnumMapping* mapping = GetMapping(aSVGElement);
|
2010-01-23 21:59:03 +03:00
|
|
|
|
|
|
|
while (mapping && mapping->mKey) {
|
2018-03-29 12:45:28 +03:00
|
|
|
if (aValue == mapping->mKey) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsBaseSet = true;
|
2010-01-23 21:59:03 +03:00
|
|
|
if (mBaseVal != mapping->mVal) {
|
2010-02-11 22:41:48 +03:00
|
|
|
mBaseVal = mapping->mVal;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
} else {
|
2010-01-23 21:59:03 +03:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2010-02-11 22:41:48 +03:00
|
|
|
// We don't need to call DidChange* here - we're only called by
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement::ParseAttribute under Element::SetAttr,
|
2010-02-11 22:41:48 +03:00
|
|
|
// which takes care of notifying.
|
2010-01-23 21:59:03 +03:00
|
|
|
}
|
2004-10-15 03:02:53 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-01-23 21:59:03 +03:00
|
|
|
mapping++;
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2018-06-30 20:41:37 +03:00
|
|
|
return NS_ERROR_DOM_TYPE_ERR;
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsAtom* SVGAnimatedEnumeration::GetBaseValueAtom(SVGElement* aSVGElement) {
|
2019-01-02 21:24:11 +03:00
|
|
|
const SVGEnumMapping* mapping = GetMapping(aSVGElement);
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2010-01-23 21:59:03 +03:00
|
|
|
while (mapping && mapping->mKey) {
|
|
|
|
if (mBaseVal == mapping->mVal) {
|
2018-03-29 12:45:28 +03:00
|
|
|
return mapping->mKey;
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
2010-01-23 21:59:03 +03:00
|
|
|
mapping++;
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
NS_ERROR("unknown enumeration value");
|
2012-02-16 03:40:44 +04:00
|
|
|
return nsGkAtoms::_empty;
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedEnumeration::SetBaseValue(uint16_t aValue,
|
|
|
|
SVGElement* aSVGElement) {
|
2019-01-02 21:24:11 +03:00
|
|
|
const SVGEnumMapping* mapping = GetMapping(aSVGElement);
|
2010-01-23 21:59:03 +03:00
|
|
|
|
|
|
|
while (mapping && mapping->mKey) {
|
|
|
|
if (mapping->mVal == aValue) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsBaseSet = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
if (mBaseVal != uint8_t(aValue)) {
|
|
|
|
mBaseVal = uint8_t(aValue);
|
2010-02-11 22:41:48 +03:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
} else {
|
2010-01-23 21:59:03 +03:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2012-02-16 03:40:44 +04:00
|
|
|
aSVGElement->DidChangeEnum(mAttrEnum);
|
2010-01-23 21:59:03 +03:00
|
|
|
}
|
2007-09-25 13:40:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-01-23 21:59:03 +03:00
|
|
|
mapping++;
|
2007-09-25 13:40:52 +04:00
|
|
|
}
|
2018-06-30 20:41:37 +03:00
|
|
|
return NS_ERROR_DOM_TYPE_ERR;
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedEnumeration::SetAnimValue(uint16_t aValue,
|
|
|
|
SVGElement* aSVGElement) {
|
2012-06-02 03:53:06 +04:00
|
|
|
if (mIsAnimated && aValue == mAnimVal) {
|
|
|
|
return;
|
|
|
|
}
|
2010-01-23 21:59:03 +03:00
|
|
|
mAnimVal = aValue;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnimated = true;
|
2010-01-23 21:59:03 +03:00
|
|
|
aSVGElement->DidAnimateEnum(mAttrEnum);
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedEnumeration>
|
|
|
|
SVGAnimatedEnumeration::ToDOMAnimatedEnum(SVGElement* aSVGElement) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMAnimatedEnum> domAnimatedEnum =
|
2012-12-21 13:18:58 +04:00
|
|
|
sSVGAnimatedEnumTearoffTable.GetTearoff(this);
|
|
|
|
if (!domAnimatedEnum) {
|
|
|
|
domAnimatedEnum = new DOMAnimatedEnum(this, aSVGElement);
|
|
|
|
sSVGAnimatedEnumTearoffTable.AddTearoff(this, domAnimatedEnum);
|
|
|
|
}
|
2007-08-28 03:11:14 +04:00
|
|
|
|
2013-01-06 18:14:43 +04:00
|
|
|
return domAnimatedEnum.forget();
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
2010-01-23 21:59:03 +03:00
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedEnumeration::DOMAnimatedEnum::~DOMAnimatedEnum() {
|
2012-12-21 13:18:58 +04:00
|
|
|
sSVGAnimatedEnumTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
UniquePtr<SMILAttr> SVGAnimatedEnumeration::ToSMILAttr(
|
|
|
|
SVGElement* aSVGElement) {
|
2017-03-30 07:10:07 +03:00
|
|
|
return MakeUnique<SMILEnum>(this, aSVGElement);
|
2010-01-23 21:59:03 +03:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedEnumeration::SMILEnum::ValueFromString(
|
2019-01-02 21:24:11 +03:00
|
|
|
const nsAString& aStr, const SVGAnimationElement* /*aSrcElement*/,
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue& aValue, bool& aPreventCachingOfSandwich) const {
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* valAtom = NS_GetStaticAtom(aStr);
|
2012-08-24 11:29:09 +04:00
|
|
|
if (valAtom) {
|
2019-01-02 21:24:11 +03:00
|
|
|
const SVGEnumMapping* mapping = mVal->GetMapping(mSVGElement);
|
2012-08-24 11:29:09 +04:00
|
|
|
|
|
|
|
while (mapping && mapping->mKey) {
|
2018-03-29 12:45:28 +03:00
|
|
|
if (valAtom == mapping->mKey) {
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue val(SMILEnumType::Singleton());
|
2012-08-24 11:29:09 +04:00
|
|
|
val.mU.mUint = mapping->mVal;
|
|
|
|
aValue = val;
|
|
|
|
aPreventCachingOfSandwich = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mapping++;
|
2010-01-23 21:59:03 +03:00
|
|
|
}
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-01-23 21:59:03 +03:00
|
|
|
// only a warning since authors may mistype attribute values
|
|
|
|
NS_WARNING("unknown enumeration key");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
SMILValue SVGAnimatedEnumeration::SMILEnum::GetBaseValue() const {
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue val(SMILEnumType::Singleton());
|
2010-01-23 21:59:03 +03:00
|
|
|
val.mU.mUint = mVal->mBaseVal;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedEnumeration::SMILEnum::ClearAnimValue() {
|
2010-01-23 21:59:03 +03:00
|
|
|
if (mVal->mIsAnimated) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mVal->mIsAnimated = false;
|
2012-03-03 13:21:09 +04:00
|
|
|
mVal->mAnimVal = mVal->mBaseVal;
|
|
|
|
mSVGElement->DidAnimateEnum(mVal->mAttrEnum);
|
2010-01-23 21:59:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedEnumeration::SMILEnum::SetAnimValue(
|
|
|
|
const SMILValue& aValue) {
|
2013-05-31 02:34:53 +04:00
|
|
|
NS_ASSERTION(aValue.mType == SMILEnumType::Singleton(),
|
2010-01-23 21:59:03 +03:00
|
|
|
"Unexpected type to assign animated value");
|
2013-05-31 02:34:53 +04:00
|
|
|
if (aValue.mType == SMILEnumType::Singleton()) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aValue.mU.mUint <= USHRT_MAX,
|
|
|
|
"Very large enumerated value - too big for uint16_t");
|
2012-08-22 19:56:38 +04:00
|
|
|
mVal->SetAnimValue(uint16_t(aValue.mU.mUint), mSVGElement);
|
2010-01-23 21:59:03 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-01-02 21:24:11 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|