2007-09-26 02:22:08 -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-09-26 02:22:08 -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-09-26 02:22:08 -07:00
|
|
|
#include "nsSVGBoolean.h"
|
2010-01-24 08:42:08 -08:00
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "SMILBoolType.h"
|
2012-12-22 20:54:22 -08:00
|
|
|
#include "SVGAnimatedBoolean.h"
|
2010-01-24 08:42:08 -08:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-12-22 20:54:22 -08:00
|
|
|
using namespace mozilla::dom;
|
2007-09-26 02:22:08 -07:00
|
|
|
|
|
|
|
/* Implementation */
|
|
|
|
|
2013-05-30 15:34:53 -07:00
|
|
|
static inline
|
|
|
|
nsSVGAttrTearoffTable<nsSVGBoolean, SVGAnimatedBoolean>&
|
|
|
|
SVGAnimatedBooleanTearoffTable()
|
|
|
|
{
|
|
|
|
static nsSVGAttrTearoffTable<nsSVGBoolean, SVGAnimatedBoolean>
|
|
|
|
sSVGAnimatedBooleanTearoffTable;
|
|
|
|
return sSVGAnimatedBooleanTearoffTable;
|
|
|
|
}
|
2012-12-21 01:18:58 -08:00
|
|
|
|
2013-10-01 00:50:40 -07:00
|
|
|
static bool
|
|
|
|
GetValueFromString(const nsAString& aValueAsString,
|
|
|
|
bool& aValue)
|
2011-07-01 14:15:04 -07:00
|
|
|
{
|
|
|
|
if (aValueAsString.EqualsLiteral("true")) {
|
2013-10-01 00:50:40 -07:00
|
|
|
aValue = true;
|
|
|
|
return true;
|
2011-07-01 14:15:04 -07:00
|
|
|
}
|
|
|
|
if (aValueAsString.EqualsLiteral("false")) {
|
2013-10-01 00:50:40 -07:00
|
|
|
aValue = false;
|
|
|
|
return true;
|
2011-07-01 14:15:04 -07:00
|
|
|
}
|
2013-10-01 00:50:40 -07:00
|
|
|
return false;
|
2011-07-01 14:15:04 -07:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:40:45 -08:00
|
|
|
static nsresult
|
|
|
|
GetValueFromAtom(const nsIAtom* aValueAsAtom, bool *aValue)
|
|
|
|
{
|
|
|
|
if (aValueAsAtom == nsGkAtoms::_true) {
|
|
|
|
*aValue = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aValueAsAtom == nsGkAtoms::_false) {
|
|
|
|
*aValue = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
2007-09-26 02:22:08 -07:00
|
|
|
nsresult
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGBoolean::SetBaseValueAtom(const nsIAtom* aValue, nsSVGElement *aSVGElement)
|
2007-09-26 02:22:08 -07:00
|
|
|
{
|
2015-01-08 13:52:19 -08:00
|
|
|
bool val = false;
|
2007-09-26 02:22:08 -07:00
|
|
|
|
2012-02-15 15:40:45 -08:00
|
|
|
nsresult rv = GetValueFromAtom(aValue, &val);
|
2011-07-01 14:15:04 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-09-26 02:22:08 -07:00
|
|
|
|
2010-02-11 11:41:48 -08:00
|
|
|
mBaseVal = val;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
2010-01-24 08:42:08 -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.
|
2007-09-26 02:22:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-15 15:40:45 -08:00
|
|
|
nsIAtom*
|
|
|
|
nsSVGBoolean::GetBaseValueAtom() const
|
2007-09-26 02:22:08 -07:00
|
|
|
{
|
2012-02-15 15:40:45 -08:00
|
|
|
return mBaseVal ? nsGkAtoms::_true : nsGkAtoms::_false;
|
2007-09-26 02:22:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-15 15:40:45 -08:00
|
|
|
nsSVGBoolean::SetBaseValue(bool aValue, nsSVGElement *aSVGElement)
|
2007-09-26 02:22:08 -07:00
|
|
|
{
|
2012-02-15 15:40:45 -08:00
|
|
|
if (aValue == mBaseVal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBaseVal = aValue;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
} else {
|
|
|
|
aSVGElement->AnimationNeedsResample();
|
2010-01-24 08:42:08 -08:00
|
|
|
}
|
2012-02-15 15:40:45 -08:00
|
|
|
aSVGElement->DidChangeBoolean(mAttrEnum);
|
2010-01-24 08:42:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSVGBoolean::SetAnimValue(bool aValue, nsSVGElement *aSVGElement)
|
2010-01-24 08:42:08 -08:00
|
|
|
{
|
2012-06-01 16:53:06 -07:00
|
|
|
if (mIsAnimated && mAnimVal == aValue) {
|
|
|
|
return;
|
|
|
|
}
|
2010-01-24 08:42:08 -08:00
|
|
|
mAnimVal = aValue;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAnimated = true;
|
2010-01-24 08:42:08 -08:00
|
|
|
aSVGElement->DidAnimateBoolean(mAttrEnum);
|
2007-09-26 02:22:08 -07:00
|
|
|
}
|
|
|
|
|
2013-03-24 23:26:06 -07:00
|
|
|
already_AddRefed<SVGAnimatedBoolean>
|
|
|
|
nsSVGBoolean::ToDOMAnimatedBoolean(nsSVGElement* aSVGElement)
|
2007-09-26 02:22:08 -07:00
|
|
|
{
|
2012-12-22 20:54:22 -08:00
|
|
|
nsRefPtr<SVGAnimatedBoolean> domAnimatedBoolean =
|
2013-05-30 15:34:53 -07:00
|
|
|
SVGAnimatedBooleanTearoffTable().GetTearoff(this);
|
2012-12-21 01:18:58 -08:00
|
|
|
if (!domAnimatedBoolean) {
|
2012-12-22 20:54:22 -08:00
|
|
|
domAnimatedBoolean = new SVGAnimatedBoolean(this, aSVGElement);
|
2013-05-30 15:34:53 -07:00
|
|
|
SVGAnimatedBooleanTearoffTable().AddTearoff(this, domAnimatedBoolean);
|
2012-12-21 01:18:58 -08:00
|
|
|
}
|
2007-09-26 02:22:08 -07:00
|
|
|
|
2013-03-24 23:26:06 -07:00
|
|
|
return domAnimatedBoolean.forget();
|
2007-09-26 02:22:08 -07:00
|
|
|
}
|
2010-01-24 08:42:08 -08:00
|
|
|
|
2012-12-22 20:54:22 -08:00
|
|
|
SVGAnimatedBoolean::~SVGAnimatedBoolean()
|
2012-12-21 01:18:58 -08:00
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
SVGAnimatedBooleanTearoffTable().RemoveTearoff(mVal);
|
2012-12-21 01:18:58 -08:00
|
|
|
}
|
|
|
|
|
2010-01-24 08:42:08 -08:00
|
|
|
nsISMILAttr*
|
|
|
|
nsSVGBoolean::ToSMILAttr(nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
return new SMILBool(this, aSVGElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGBoolean::SMILBool::ValueFromString(const nsAString& aStr,
|
2013-03-18 20:18:45 -07:00
|
|
|
const 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-24 08:42:08 -08:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool value;
|
2013-10-01 00:50:40 -07:00
|
|
|
if (!GetValueFromString(aStr, value)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2011-07-01 14:15:04 -07:00
|
|
|
}
|
2010-01-24 08:42:08 -08:00
|
|
|
|
2013-05-30 15:34:53 -07:00
|
|
|
nsSMILValue val(SMILBoolType::Singleton());
|
2011-07-01 14:15:04 -07:00
|
|
|
val.mU.mBool = value;
|
2010-01-24 08:42:08 -08:00
|
|
|
aValue = val;
|
2011-10-17 07:59:28 -07:00
|
|
|
aPreventCachingOfSandwich = false;
|
2011-07-01 14:15:04 -07:00
|
|
|
|
2010-01-24 08:42:08 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSVGBoolean::SMILBool::GetBaseValue() const
|
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
nsSMILValue val(SMILBoolType::Singleton());
|
2010-01-24 08:42:08 -08:00
|
|
|
val.mU.mBool = mVal->mBaseVal;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGBoolean::SMILBool::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->DidAnimateBoolean(mVal->mAttrEnum);
|
2010-01-24 08:42:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGBoolean::SMILBool::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
2013-05-30 15:34:53 -07:00
|
|
|
NS_ASSERTION(aValue.mType == SMILBoolType::Singleton(),
|
2010-01-24 08:42:08 -08:00
|
|
|
"Unexpected type to assign animated value");
|
2013-05-30 15:34:53 -07:00
|
|
|
if (aValue.mType == SMILBoolType::Singleton()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
mVal->SetAnimValue(uint16_t(aValue.mU.mBool), mSVGElement);
|
2010-01-24 08:42:08 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|