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