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