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