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/. */
|
2011-07-01 11:19:52 +04:00
|
|
|
|
|
|
|
#ifndef __NS_SVGNUMBERPAIR_H__
|
|
|
|
#define __NS_SVGNUMBERPAIR_H__
|
|
|
|
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsISMILAttr.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsMathUtils.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsSVGElement.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-07-01 11:03:04 +04:00
|
|
|
#include "mozilla/dom/SVGAnimatedNumber.h"
|
2014-10-01 13:26:00 +04:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
|
|
|
|
2011-07-01 11:19:52 +04:00
|
|
|
|
|
|
|
class nsSMILValue;
|
|
|
|
|
2013-03-19 07:18:45 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class SVGAnimationElement;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-03-19 07:18:45 +04:00
|
|
|
|
2011-07-01 11:19:52 +04:00
|
|
|
class nsSVGNumberPair
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum PairIndex {
|
|
|
|
eFirst,
|
|
|
|
eSecond
|
|
|
|
};
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void Init(uint8_t aAttrEnum = 0xff, float aValue1 = 0, float aValue2 = 0) {
|
2011-07-01 11:19:52 +04:00
|
|
|
mAnimVal[0] = mBaseVal[0] = aValue1;
|
|
|
|
mAnimVal[1] = mBaseVal[1] = aValue2;
|
|
|
|
mAttrEnum = aAttrEnum;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnimated = false;
|
|
|
|
mIsBaseSet = false;
|
2011-07-01 11:19:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult SetBaseValueString(const nsAString& aValue,
|
2011-10-09 19:25:07 +04:00
|
|
|
nsSVGElement *aSVGElement);
|
2012-02-16 03:40:45 +04:00
|
|
|
void GetBaseValueString(nsAString& aValue) const;
|
2011-07-01 11:19:52 +04:00
|
|
|
|
2011-10-09 19:25:07 +04:00
|
|
|
void SetBaseValue(float aValue, PairIndex aIndex, nsSVGElement *aSVGElement);
|
|
|
|
void SetBaseValues(float aValue1, float aValue2, nsSVGElement *aSVGElement);
|
2011-07-01 11:19:52 +04:00
|
|
|
float GetBaseValue(PairIndex aIndex) const
|
|
|
|
{ return mBaseVal[aIndex == eFirst ? 0 : 1]; }
|
|
|
|
void SetAnimValue(const float aValue[2], nsSVGElement *aSVGElement);
|
|
|
|
float GetAnimValue(PairIndex aIndex) const
|
|
|
|
{ return mAnimVal[aIndex == eFirst ? 0 : 1]; }
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
// Returns true if the animated value of this number has been explicitly
|
2011-07-01 11:19:52 +04:00
|
|
|
// set (either by animation, or by taking on the base value which has been
|
2011-10-17 18:59:28 +04:00
|
|
|
// explicitly set by markup or a DOM call), false otherwise.
|
|
|
|
// If this returns false, the animated value is still valid, that is,
|
2011-07-01 11:19:52 +04:00
|
|
|
// useable, and represents the default base value of the attribute.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsExplicitlySet() const
|
2011-07-01 11:19:52 +04:00
|
|
|
{ return mIsAnimated || mIsBaseSet; }
|
|
|
|
|
2013-07-01 11:03:04 +04:00
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedNumber>
|
2013-03-19 21:43:31 +04:00
|
|
|
ToDOMAnimatedNumber(PairIndex aIndex,
|
|
|
|
nsSVGElement* aSVGElement);
|
2011-07-01 11:19:52 +04:00
|
|
|
// Returns a new nsISMILAttr object that the caller must delete
|
|
|
|
nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
float mAnimVal[2];
|
|
|
|
float mBaseVal[2];
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mAttrEnum; // element specified tracking for attribute
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsAnimated;
|
|
|
|
bool mIsBaseSet;
|
2011-07-01 11:19:52 +04:00
|
|
|
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
struct DOMAnimatedNumber final : public mozilla::dom::SVGAnimatedNumber
|
2011-07-01 11:19:52 +04:00
|
|
|
{
|
2011-07-05 01:19:54 +04:00
|
|
|
DOMAnimatedNumber(nsSVGNumberPair* aVal, PairIndex aIndex, nsSVGElement *aSVGElement)
|
2013-07-01 11:03:04 +04:00
|
|
|
: mozilla::dom::SVGAnimatedNumber(aSVGElement)
|
|
|
|
, mVal(aVal)
|
|
|
|
, mIndex(aIndex)
|
|
|
|
{}
|
2012-12-21 13:18:58 +04:00
|
|
|
virtual ~DOMAnimatedNumber();
|
2011-07-01 11:19:52 +04:00
|
|
|
|
|
|
|
nsSVGNumberPair* mVal; // kept alive because it belongs to content
|
|
|
|
PairIndex mIndex; // are we the first or second number
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual float BaseVal() override
|
2013-07-01 11:03:04 +04:00
|
|
|
{
|
|
|
|
return mVal->GetBaseValue(mIndex);
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetBaseVal(float aValue) override
|
2013-07-01 11:03:04 +04:00
|
|
|
{
|
2014-10-01 13:26:00 +04:00
|
|
|
MOZ_ASSERT(mozilla::IsFinite(aValue));
|
2013-07-01 11:03:04 +04:00
|
|
|
mVal->SetBaseValue(aValue, mIndex, mSVGElement);
|
|
|
|
}
|
2011-07-01 11:19:52 +04:00
|
|
|
|
|
|
|
// Script may have modified animation parameters or timeline -- DOM getters
|
|
|
|
// need to flush any resample requests to reflect these modifications.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual float AnimVal() override
|
2011-07-01 11:19:52 +04:00
|
|
|
{
|
|
|
|
mSVGElement->FlushAnimations();
|
2013-07-01 11:03:04 +04:00
|
|
|
return mVal->GetAnimValue(mIndex);
|
2011-07-01 11:19:52 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SMILNumberPair : public nsISMILAttr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SMILNumberPair(nsSVGNumberPair* aVal, nsSVGElement* aSVGElement)
|
|
|
|
: mVal(aVal), mSVGElement(aSVGElement) {}
|
|
|
|
|
|
|
|
// These will stay alive because a nsISMILAttr only lives as long
|
|
|
|
// as the Compositing step, and DOM elements don't get a chance to
|
|
|
|
// die during that.
|
|
|
|
nsSVGNumberPair* mVal;
|
|
|
|
nsSVGElement* mSVGElement;
|
|
|
|
|
|
|
|
// nsISMILAttr methods
|
|
|
|
virtual nsresult ValueFromString(const nsAString& aStr,
|
2013-03-19 07:18:45 +04:00
|
|
|
const mozilla::dom::SVGAnimationElement* aSrcElement,
|
2011-07-01 11:19:52 +04:00
|
|
|
nsSMILValue& aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool& aPreventCachingOfSandwich) const override;
|
|
|
|
virtual nsSMILValue GetBaseValue() const override;
|
|
|
|
virtual void ClearAnimValue() override;
|
|
|
|
virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
|
2011-07-01 11:19:52 +04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //__NS_SVGNUMBERPAIR_H__
|