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
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "SVGAnimatedBoolean.h"
|
2018-12-28 05:47:10 +03:00
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
#include "DOMSVGAnimatedBoolean.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2010-01-24 19:42:08 +03:00
|
|
|
#include "SMILBoolType.h"
|
2019-01-24 00:48:00 +03:00
|
|
|
#include "SVGAttrTearoffTable.h"
|
2019-01-23 16:48:08 +03:00
|
|
|
#include "mozilla/SMILValue.h"
|
2010-01-24 19:42:08 +03:00
|
|
|
|
2012-12-23 08:54:22 +04:00
|
|
|
using namespace mozilla::dom;
|
2007-09-26 13:22:08 +04:00
|
|
|
|
2019-01-07 22:23:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2007-09-26 13:22:08 +04:00
|
|
|
/* Implementation */
|
|
|
|
|
2020-08-03 12:32:36 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangeBooleanNotifier
|
|
|
|
// Stack-based helper class to ensure DidChangeBoolean is called.
|
|
|
|
class MOZ_RAII AutoChangeBooleanNotifier {
|
|
|
|
public:
|
|
|
|
AutoChangeBooleanNotifier(SVGAnimatedBoolean* aBoolean,
|
|
|
|
SVGElement* aSVGElement, bool aDoSetAttr = true)
|
|
|
|
: mBoolean(aBoolean), mSVGElement(aSVGElement), mDoSetAttr(aDoSetAttr) {
|
|
|
|
MOZ_ASSERT(mBoolean, "Expecting non-null boolean");
|
|
|
|
MOZ_ASSERT(mSVGElement, "Expecting non-null element");
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangeBooleanNotifier() {
|
|
|
|
if (mDoSetAttr) {
|
|
|
|
mSVGElement->DidChangeBoolean(mBoolean->mAttrEnum);
|
|
|
|
}
|
|
|
|
if (mBoolean->mIsAnimated) {
|
|
|
|
mSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SVGAnimatedBoolean* const mBoolean;
|
|
|
|
SVGElement* const mSVGElement;
|
|
|
|
bool mDoSetAttr;
|
|
|
|
};
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
static inline SVGAttrTearoffTable<SVGAnimatedBoolean, DOMSVGAnimatedBoolean>&
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGAnimatedBooleanTearoffTable() {
|
2019-04-04 20:40:56 +03:00
|
|
|
static SVGAttrTearoffTable<SVGAnimatedBoolean, DOMSVGAnimatedBoolean>
|
2013-05-31 02:34:53 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
static nsresult GetValueFromAtom(const nsAtom* aValueAsAtom, bool* aValue) {
|
2012-02-16 03:40:45 +04: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 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedBoolean::SetBaseValueAtom(const nsAtom* aValue,
|
|
|
|
SVGElement* aSVGElement) {
|
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
|
|
|
|
2020-08-03 12:32:36 +03:00
|
|
|
// We don't need to call DidChange* here - we're only called by
|
|
|
|
// SVGElement::ParseAttribute under Element::SetAttr,
|
|
|
|
// which takes care of notifying.
|
|
|
|
AutoChangeBooleanNotifier notifier(this, aSVGElement, false);
|
|
|
|
|
2010-02-11 22:41:48 +03:00
|
|
|
mBaseVal = val;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
2010-01-24 19:42:08 +03:00
|
|
|
}
|
2010-02-11 22:41:48 +03:00
|
|
|
|
2007-09-26 13:22:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsAtom* SVGAnimatedBoolean::GetBaseValueAtom() const {
|
2012-02-16 03:40:45 +04:00
|
|
|
return mBaseVal ? nsGkAtoms::_true : nsGkAtoms::_false;
|
2007-09-26 13:22:08 +04:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedBoolean::SetBaseValue(bool aValue, SVGElement* aSVGElement) {
|
2012-02-16 03:40:45 +04:00
|
|
|
if (aValue == mBaseVal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-03 12:32:36 +03:00
|
|
|
AutoChangeBooleanNotifier notifier(this, aSVGElement);
|
|
|
|
|
2012-02-16 03:40:45 +04:00
|
|
|
mBaseVal = aValue;
|
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
2010-01-24 19:42:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedBoolean::SetAnimValue(bool aValue, SVGElement* aSVGElement) {
|
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
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedBoolean>
|
|
|
|
SVGAnimatedBoolean::ToDOMAnimatedBoolean(SVGElement* aSVGElement) {
|
2019-03-19 03:01:03 +03:00
|
|
|
RefPtr<DOMSVGAnimatedBoolean> domAnimatedBoolean =
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGAnimatedBooleanTearoffTable().GetTearoff(this);
|
2012-12-21 13:18:58 +04:00
|
|
|
if (!domAnimatedBoolean) {
|
2019-03-19 03:01:03 +03:00
|
|
|
domAnimatedBoolean = new DOMSVGAnimatedBoolean(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
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
DOMSVGAnimatedBoolean::~DOMSVGAnimatedBoolean() {
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGAnimatedBooleanTearoffTable().RemoveTearoff(mVal);
|
2012-12-21 13:18:58 +04:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
UniquePtr<SMILAttr> SVGAnimatedBoolean::ToSMILAttr(SVGElement* aSVGElement) {
|
2017-03-30 07:10:07 +03:00
|
|
|
return MakeUnique<SMILBool>(this, aSVGElement);
|
2010-01-24 19:42:08 +03:00
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedBoolean::SMILBool::ValueFromString(
|
2013-03-19 07:18:45 +04:00
|
|
|
const nsAString& aStr, const SVGAnimationElement* /*aSrcElement*/,
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue& aValue, bool& aPreventCachingOfSandwich) const {
|
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
|
|
|
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue 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;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
SMILValue SVGAnimatedBoolean::SMILBool::GetBaseValue() const {
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue val(SMILBoolType::Singleton());
|
2010-01-24 19:42:08 +03:00
|
|
|
val.mU.mBool = mVal->mBaseVal;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
void SVGAnimatedBoolean::SMILBool::ClearAnimValue() {
|
2010-01-24 19:42:08 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
nsresult SVGAnimatedBoolean::SMILBool::SetAnimValue(const SMILValue& 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;
|
|
|
|
}
|
2019-01-07 22:23:13 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|