2007-03-22 10:30:00 -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-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef __NS_SVGLENGTH2_H__
|
|
|
|
#define __NS_SVGLENGTH2_H__
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-01-26 01:57:21 -08:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCoord.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsIDOMSVGLength.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsISMILAttr.h"
|
2012-01-26 01:57:21 -08:00
|
|
|
#include "nsMathUtils.h"
|
|
|
|
#include "nsSVGElement.h"
|
2012-09-22 12:26:05 -07:00
|
|
|
#include "SVGContentUtils.h"
|
2014-09-15 03:12:50 -07:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
class nsIFrame;
|
2012-01-26 01:57:21 -08:00
|
|
|
class nsSMILValue;
|
2013-01-09 15:02:45 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-04-11 14:26:29 -07:00
|
|
|
class DOMSVGLength;
|
2013-01-09 15:02:45 -08:00
|
|
|
namespace dom {
|
2013-01-19 12:56:00 -08:00
|
|
|
class SVGAnimatedLength;
|
2013-03-18 20:18:45 -07:00
|
|
|
class SVGAnimationElement;
|
2013-01-09 15:02:45 -08:00
|
|
|
class SVGSVGElement;
|
|
|
|
}
|
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2014-09-15 03:12:50 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class UserSpaceMetrics
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~UserSpaceMetrics() {}
|
|
|
|
|
|
|
|
virtual float GetEmLength() const = 0;
|
|
|
|
virtual float GetExLength() const = 0;
|
|
|
|
virtual float GetAxisLength(uint8_t aCtxType) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class UserSpaceMetricsWithSize : public UserSpaceMetrics
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual gfx::Size GetSize() const = 0;
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual float GetAxisLength(uint8_t aCtxType) const override;
|
2014-09-15 03:12:50 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class SVGElementMetrics : public UserSpaceMetrics
|
|
|
|
{
|
|
|
|
public:
|
2014-09-17 14:53:42 -07:00
|
|
|
explicit SVGElementMetrics(nsSVGElement* aSVGElement,
|
|
|
|
mozilla::dom::SVGSVGElement* aCtx = nullptr);
|
2014-09-15 03:12:50 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual float GetEmLength() const override;
|
|
|
|
virtual float GetExLength() const override;
|
|
|
|
virtual float GetAxisLength(uint8_t aCtxType) const override;
|
2014-09-15 03:12:50 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool EnsureCtx() const;
|
|
|
|
|
|
|
|
nsSVGElement* mSVGElement;
|
|
|
|
mutable mozilla::dom::SVGSVGElement* mCtx;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NonSVGFrameUserSpaceMetrics : public UserSpaceMetricsWithSize
|
|
|
|
{
|
|
|
|
public:
|
2014-09-17 14:53:42 -07:00
|
|
|
explicit NonSVGFrameUserSpaceMetrics(nsIFrame* aFrame);
|
2014-09-15 03:12:50 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual float GetEmLength() const override;
|
|
|
|
virtual float GetExLength() const override;
|
|
|
|
virtual gfx::Size GetSize() const override;
|
2014-09-15 03:12:50 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsSVGLength2
|
|
|
|
{
|
2013-01-19 12:56:00 -08:00
|
|
|
friend class mozilla::dom::SVGAnimatedLength;
|
2014-04-11 14:26:29 -07:00
|
|
|
friend class mozilla::DOMSVGLength;
|
2014-09-15 03:12:50 -07:00
|
|
|
typedef mozilla::dom::UserSpaceMetrics UserSpaceMetrics;
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2012-09-22 12:26:05 -07:00
|
|
|
void Init(uint8_t aCtxType = SVGContentUtils::XY,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aAttrEnum = 0xff,
|
2007-03-22 10:30:00 -07:00
|
|
|
float aValue = 0,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aUnitType = nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mAnimVal = mBaseVal = aValue;
|
|
|
|
mSpecifiedUnitType = aUnitType;
|
|
|
|
mAttrEnum = aAttrEnum;
|
|
|
|
mCtxType = aCtxType;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAnimated = false;
|
|
|
|
mIsBaseSet = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-06-20 13:15:42 -07:00
|
|
|
nsSVGLength2& operator=(const nsSVGLength2& aLength) {
|
|
|
|
mBaseVal = aLength.mBaseVal;
|
|
|
|
mAnimVal = aLength.mAnimVal;
|
|
|
|
mSpecifiedUnitType = aLength.mSpecifiedUnitType;
|
|
|
|
mIsAnimated = aLength.mIsAnimated;
|
|
|
|
mIsBaseSet = aLength.mIsBaseSet;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult SetBaseValueString(const nsAString& aValue,
|
|
|
|
nsSVGElement *aSVGElement,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDoSetAttr);
|
2012-02-15 15:40:45 -08:00
|
|
|
void GetBaseValueString(nsAString& aValue) const;
|
|
|
|
void GetAnimValueString(nsAString& aValue) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
float GetBaseValue(nsSVGElement* aSVGElement) const
|
2009-01-21 17:00:27 -08:00
|
|
|
{ return mBaseVal / GetUnitScaleFactor(aSVGElement, mSpecifiedUnitType); }
|
2014-09-15 03:12:50 -07:00
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
float GetAnimValue(nsSVGElement* aSVGElement) const
|
2010-02-25 10:20:43 -08:00
|
|
|
{ return mAnimVal / GetUnitScaleFactor(aSVGElement, mSpecifiedUnitType); }
|
2008-09-10 17:24:16 -07:00
|
|
|
float GetAnimValue(nsIFrame* aFrame) const
|
2009-01-21 17:00:27 -08:00
|
|
|
{ return mAnimVal / GetUnitScaleFactor(aFrame, mSpecifiedUnitType); }
|
2014-09-15 03:12:50 -07:00
|
|
|
float GetAnimValue(mozilla::dom::SVGSVGElement* aCtx) const
|
|
|
|
{ return mAnimVal / GetUnitScaleFactor(aCtx, mSpecifiedUnitType); }
|
|
|
|
float GetAnimValue(const UserSpaceMetrics& aMetrics) const
|
|
|
|
{ return mAnimVal / GetUnitScaleFactor(aMetrics, mSpecifiedUnitType); }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t GetCtxType() const { return mCtxType; }
|
|
|
|
uint8_t GetSpecifiedUnitType() const { return mSpecifiedUnitType; }
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsPercentage() const
|
2008-01-25 01:27:03 -08:00
|
|
|
{ return mSpecifiedUnitType == nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE; }
|
2007-10-03 02:02:19 -07:00
|
|
|
float GetAnimValInSpecifiedUnits() const { return mAnimVal; }
|
|
|
|
float GetBaseValInSpecifiedUnits() const { return mBaseVal; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-09 15:02:45 -08:00
|
|
|
float GetBaseValue(mozilla::dom::SVGSVGElement* aCtx) const
|
2009-01-21 17:00:27 -08:00
|
|
|
{ return mBaseVal / GetUnitScaleFactor(aCtx, mSpecifiedUnitType); }
|
2010-11-16 15:24:11 -08:00
|
|
|
|
2011-12-27 02:27:42 -08:00
|
|
|
bool HasBaseVal() const {
|
|
|
|
return mIsBaseSet;
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
// Returns true if the animated value of this length has been explicitly
|
2010-11-16 15:24:11 -08:00
|
|
|
// set (either by animation, or by taking on the base value which has been
|
2011-10-17 07:59:28 -07:00
|
|
|
// explicitly set by markup or a DOM call), false otherwise.
|
|
|
|
// If this returns false, the animated value is still valid, that is,
|
2010-11-16 15:24:11 -08:00
|
|
|
// useable, and represents the default base value of the attribute.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsExplicitlySet() const
|
2010-11-16 15:24:11 -08:00
|
|
|
{ return mIsAnimated || mIsBaseSet; }
|
2013-01-06 01:32:02 -08:00
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedLength>
|
2013-01-06 01:32:02 -08:00
|
|
|
ToDOMAnimatedLength(nsSVGElement* aSVGElement);
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
// Returns a new nsISMILAttr object that the caller must delete
|
|
|
|
nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
float mAnimVal;
|
|
|
|
float mBaseVal;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mSpecifiedUnitType;
|
|
|
|
uint8_t mAttrEnum; // element specified tracking for attribute
|
|
|
|
uint8_t mCtxType; // X, Y or Unspecified
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsAnimated:1;
|
|
|
|
bool mIsBaseSet:1;
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2014-09-15 03:12:50 -07:00
|
|
|
float GetUnitScaleFactor(nsIFrame *aFrame, uint8_t aUnitType) const;
|
|
|
|
float GetUnitScaleFactor(const UserSpaceMetrics& aMetrics, uint8_t aUnitType) const;
|
2012-08-22 08:56:38 -07:00
|
|
|
float GetUnitScaleFactor(nsSVGElement *aSVGElement, uint8_t aUnitType) const;
|
2013-01-09 15:02:45 -08:00
|
|
|
float GetUnitScaleFactor(mozilla::dom::SVGSVGElement *aCtx, uint8_t aUnitType) const;
|
2009-01-21 17:00:27 -08:00
|
|
|
|
2011-03-31 12:29:44 -07:00
|
|
|
// SetBaseValue and SetAnimValue set the value in user units
|
2012-02-15 15:40:45 -08:00
|
|
|
void SetBaseValue(float aValue, nsSVGElement *aSVGElement, bool aDoSetAttr);
|
|
|
|
void SetBaseValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement,
|
|
|
|
bool aDoSetAttr);
|
2009-01-14 20:38:07 -08:00
|
|
|
void SetAnimValue(float aValue, nsSVGElement *aSVGElement);
|
2011-03-31 12:29:44 -07:00
|
|
|
void SetAnimValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult NewValueSpecifiedUnits(uint16_t aUnitType, float aValue,
|
2010-01-20 12:22:40 -08:00
|
|
|
nsSVGElement *aSVGElement);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult ConvertToSpecifiedUnits(uint16_t aUnitType, nsSVGElement *aSVGElement);
|
2014-04-11 14:26:29 -07:00
|
|
|
nsresult ToDOMBaseVal(mozilla::DOMSVGLength **aResult, nsSVGElement* aSVGElement);
|
|
|
|
nsresult ToDOMAnimVal(mozilla::DOMSVGLength **aResult, nsSVGElement* aSVGElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 23:24:43 -07:00
|
|
|
public:
|
2009-01-14 20:38:07 -08:00
|
|
|
struct SMILLength : public nsISMILAttr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SMILLength(nsSVGLength2* 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.
|
|
|
|
nsSVGLength2* mVal;
|
|
|
|
nsSVGElement* mSVGElement;
|
|
|
|
|
|
|
|
// nsISMILAttr methods
|
|
|
|
virtual nsresult ValueFromString(const nsAString& aStr,
|
2013-03-18 20:18:45 -07:00
|
|
|
const mozilla::dom::SVGAnimationElement* aSrcElement,
|
2010-02-20 13:13:11 -08:00
|
|
|
nsSMILValue &aValue,
|
2015-03-21 09:28:04 -07:00
|
|
|
bool& aPreventCachingOfSandwich) const override;
|
|
|
|
virtual nsSMILValue GetBaseValue() const override;
|
|
|
|
virtual void ClearAnimValue() override;
|
|
|
|
virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
|
2009-01-14 20:38:07 -08:00
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
#endif // __NS_SVGLENGTH2_H__
|