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