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/. */
|
2006-04-14 19:09:39 +04:00
|
|
|
|
|
|
|
#ifndef __NS_SVGLENGTH2_H__
|
|
|
|
#define __NS_SVGLENGTH2_H__
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-03-30 07:10:07 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2018-02-02 16:21:33 +03:00
|
|
|
#include "mozilla/dom/SVGLengthBinding.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCoord.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsError.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
#include "nsISMILAttr.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsMathUtils.h"
|
2018-12-21 11:58:14 +03:00
|
|
|
#include "SVGElement.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "SVGContentUtils.h"
|
2014-09-15 14:12:50 +04:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
class nsIFrame;
|
2012-01-26 13:57:21 +04:00
|
|
|
class nsSMILValue;
|
2013-01-10 03:02:45 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2018-12-28 16:42:46 +03:00
|
|
|
class DOMSVGLength;
|
2013-01-20 00:56:00 +04:00
|
|
|
class SVGAnimatedLength;
|
2013-03-19 07:18:45 +04:00
|
|
|
class SVGAnimationElement;
|
2017-08-21 11:19:31 +03:00
|
|
|
class SVGViewportElement;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2014-09-15 14:12:50 +04: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 19:28:04 +03:00
|
|
|
virtual float GetAxisLength(uint8_t aCtxType) const override;
|
2014-09-15 14:12:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class SVGElementMetrics : public UserSpaceMetrics {
|
|
|
|
public:
|
2018-12-21 11:58:14 +03:00
|
|
|
typedef mozilla::dom::SVGElement SVGElement;
|
2017-08-21 11:19:31 +03:00
|
|
|
typedef mozilla::dom::SVGViewportElement SVGViewportElement;
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
explicit SVGElementMetrics(SVGElement* aSVGElement,
|
2017-08-21 11:19:31 +03:00
|
|
|
SVGViewportElement* aCtx = nullptr);
|
2014-09-15 14:12:50 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual float GetEmLength() const override;
|
|
|
|
virtual float GetExLength() const override;
|
|
|
|
virtual float GetAxisLength(uint8_t aCtxType) const override;
|
2014-09-15 14:12:50 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool EnsureCtx() const;
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* mSVGElement;
|
2017-08-21 11:19:31 +03:00
|
|
|
mutable SVGViewportElement* mCtx;
|
2014-09-15 14:12:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class NonSVGFrameUserSpaceMetrics : public UserSpaceMetricsWithSize {
|
|
|
|
public:
|
2014-09-18 01:53:42 +04:00
|
|
|
explicit NonSVGFrameUserSpaceMetrics(nsIFrame* aFrame);
|
2014-09-15 14:12:50 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual float GetEmLength() const override;
|
|
|
|
virtual float GetExLength() const override;
|
|
|
|
virtual gfx::Size GetSize() const override;
|
2014-09-15 14:12:50 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2014-09-15 14:12:50 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
class nsSVGLength2 {
|
2013-01-20 00:56:00 +04:00
|
|
|
friend class mozilla::dom::SVGAnimatedLength;
|
2018-12-28 16:42:46 +03:00
|
|
|
friend class mozilla::dom::DOMSVGLength;
|
2014-09-15 14:12:50 +04:00
|
|
|
typedef mozilla::dom::UserSpaceMetrics UserSpaceMetrics;
|
2018-12-21 11:58:14 +03:00
|
|
|
typedef mozilla::dom::SVGElement SVGElement;
|
2017-08-21 11:19:31 +03:00
|
|
|
typedef mozilla::dom::SVGViewportElement SVGViewportElement;
|
2018-12-21 11:58:14 +03:00
|
|
|
typedef mozilla::SVGContentUtils SVGContentUtils;
|
2017-08-21 11:19:31 +03:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
public:
|
2018-12-20 10:58:08 +03:00
|
|
|
void Init(uint8_t aCtxType = mozilla::SVGContentUtils::XY,
|
|
|
|
uint8_t aAttrEnum = 0xff, float aValue = 0,
|
2018-02-02 16:21:33 +03:00
|
|
|
uint8_t aUnitType =
|
2018-06-26 00:20:54 +03:00
|
|
|
mozilla::dom::SVGLength_Binding::SVG_LENGTHTYPE_NUMBER) {
|
2006-04-14 19:09:39 +04:00
|
|
|
mAnimVal = mBaseVal = aValue;
|
|
|
|
mSpecifiedUnitType = aUnitType;
|
|
|
|
mAttrEnum = aAttrEnum;
|
|
|
|
mCtxType = aCtxType;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnimated = false;
|
|
|
|
mIsBaseSet = false;
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
|
|
|
|
2011-06-21 00:15:42 +04:00
|
|
|
nsSVGLength2& operator=(const nsSVGLength2& aLength) {
|
|
|
|
mBaseVal = aLength.mBaseVal;
|
|
|
|
mAnimVal = aLength.mAnimVal;
|
|
|
|
mSpecifiedUnitType = aLength.mSpecifiedUnitType;
|
|
|
|
mIsAnimated = aLength.mIsAnimated;
|
|
|
|
mIsBaseSet = aLength.mIsBaseSet;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
nsresult SetBaseValueString(const nsAString& aValue, SVGElement* aSVGElement,
|
|
|
|
bool aDoSetAttr);
|
2012-02-16 03:40:45 +04:00
|
|
|
void GetBaseValueString(nsAString& aValue) const;
|
|
|
|
void GetAnimValueString(nsAString& aValue) const;
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
float GetBaseValue(SVGElement* aSVGElement) const {
|
2017-12-30 20:07:27 +03:00
|
|
|
return mBaseVal * GetPixelsPerUnit(aSVGElement, mSpecifiedUnitType);
|
|
|
|
}
|
2014-09-15 14:12:50 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
float GetAnimValue(SVGElement* aSVGElement) const {
|
2017-12-30 20:07:27 +03:00
|
|
|
return mAnimVal * GetPixelsPerUnit(aSVGElement, mSpecifiedUnitType);
|
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
float GetAnimValue(nsIFrame* aFrame) const {
|
2017-12-30 20:07:27 +03:00
|
|
|
return mAnimVal * GetPixelsPerUnit(aFrame, mSpecifiedUnitType);
|
|
|
|
}
|
2017-08-21 11:19:31 +03:00
|
|
|
float GetAnimValue(SVGViewportElement* aCtx) const {
|
2017-12-30 20:07:27 +03:00
|
|
|
return mAnimVal * GetPixelsPerUnit(aCtx, mSpecifiedUnitType);
|
|
|
|
}
|
2014-09-15 14:12:50 +04:00
|
|
|
float GetAnimValue(const UserSpaceMetrics& aMetrics) const {
|
2017-12-30 20:07:27 +03:00
|
|
|
return mAnimVal * GetPixelsPerUnit(aMetrics, mSpecifiedUnitType);
|
|
|
|
}
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t GetCtxType() const { return mCtxType; }
|
|
|
|
uint8_t GetSpecifiedUnitType() const { return mSpecifiedUnitType; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsPercentage() const {
|
2018-02-02 16:21:33 +03:00
|
|
|
return mSpecifiedUnitType ==
|
2018-06-26 00:20:54 +03:00
|
|
|
mozilla::dom::SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE;
|
|
|
|
}
|
2007-10-03 13:02:19 +04:00
|
|
|
float GetAnimValInSpecifiedUnits() const { return mAnimVal; }
|
|
|
|
float GetBaseValInSpecifiedUnits() const { return mBaseVal; }
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2017-08-21 11:19:31 +03:00
|
|
|
float GetBaseValue(SVGViewportElement* aCtx) const {
|
2017-12-30 20:07:27 +03:00
|
|
|
return mBaseVal * GetPixelsPerUnit(aCtx, mSpecifiedUnitType);
|
2011-12-27 14:27:42 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-10-03 13:02:19 +04:00
|
|
|
bool HasBaseVal() const { return mIsBaseSet; }
|
2011-10-17 18:59:28 +04:00
|
|
|
// Returns true if the animated value of this length has been explicitly
|
2010-11-17 02:24:11 +03: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,
|
2018-03-18 21:09:51 +03:00
|
|
|
// usable, and represents the default base value of the attribute.
|
2010-11-17 02:24:11 +03:00
|
|
|
bool IsExplicitlySet() const { return mIsAnimated || mIsBaseSet; }
|
2013-01-06 13:32:02 +04:00
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedLength> ToDOMAnimatedLength(
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement);
|
2013-01-06 13:32:02 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(SVGElement* aSVGElement);
|
2006-04-14 19:09:39 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
float mAnimVal;
|
|
|
|
float mBaseVal;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mSpecifiedUnitType;
|
|
|
|
uint8_t mAttrEnum; // element specified tracking for attribute
|
|
|
|
uint8_t mCtxType; // X, Y or Unspecified
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsAnimated : 1;
|
|
|
|
bool mIsBaseSet : 1;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2017-12-30 20:07:27 +03:00
|
|
|
// These APIs returns the number of user-unit pixels per unit of the
|
|
|
|
// given type, in a given context (frame/element/etc).
|
|
|
|
float GetPixelsPerUnit(nsIFrame* aFrame, uint8_t aUnitType) const;
|
|
|
|
float GetPixelsPerUnit(const UserSpaceMetrics& aMetrics,
|
|
|
|
uint8_t aUnitType) const;
|
2018-12-21 11:58:14 +03:00
|
|
|
float GetPixelsPerUnit(SVGElement* aSVGElement, uint8_t aUnitType) const;
|
2017-12-30 20:07:27 +03:00
|
|
|
float GetPixelsPerUnit(SVGViewportElement* aCtx, uint8_t aUnitType) const;
|
|
|
|
|
|
|
|
// SetBaseValue and SetAnimValue set the value in user units. This may fail
|
|
|
|
// if unit conversion fails e.g. conversion to ex or em units where the
|
|
|
|
// font-size is 0.
|
|
|
|
// SetBaseValueInSpecifiedUnits and SetAnimValueInSpecifiedUnits do not
|
|
|
|
// perform unit conversion and are therefore infallible.
|
2018-12-21 11:58:14 +03:00
|
|
|
nsresult SetBaseValue(float aValue, SVGElement* aSVGElement, bool aDoSetAttr);
|
|
|
|
void SetBaseValueInSpecifiedUnits(float aValue, SVGElement* aSVGElement,
|
2012-02-16 03:40:45 +04:00
|
|
|
bool aDoSetAttr);
|
2018-12-21 11:58:14 +03:00
|
|
|
nsresult SetAnimValue(float aValue, SVGElement* aSVGElement);
|
|
|
|
void SetAnimValueInSpecifiedUnits(float aValue, SVGElement* aSVGElement);
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult NewValueSpecifiedUnits(uint16_t aUnitType, float aValue,
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement);
|
|
|
|
nsresult ConvertToSpecifiedUnits(uint16_t aUnitType, SVGElement* aSVGElement);
|
2018-12-28 16:42:46 +03:00
|
|
|
nsresult ToDOMBaseVal(mozilla::dom::DOMSVGLength** aResult,
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement);
|
2018-12-28 16:42:46 +03:00
|
|
|
nsresult ToDOMAnimVal(mozilla::dom::DOMSVGLength** aResult,
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-23 10:24:43 +04:00
|
|
|
public:
|
2009-01-15 07:38:07 +03:00
|
|
|
struct SMILLength : public nsISMILAttr {
|
|
|
|
public:
|
2018-12-21 11:58:14 +03:00
|
|
|
SMILLength(nsSVGLength2* aVal, SVGElement* aSVGElement)
|
2009-01-15 07:38:07 +03:00
|
|
|
: 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;
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* mSVGElement;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// nsISMILAttr methods
|
|
|
|
virtual nsresult ValueFromString(
|
|
|
|
const nsAString& aStr,
|
2013-03-19 07:18:45 +04:00
|
|
|
const mozilla::dom::SVGAnimationElement* aSrcElement,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsSMILValue& aValue, bool& aPreventCachingOfSandwich) const override;
|
|
|
|
virtual nsSMILValue GetBaseValue() const override;
|
|
|
|
virtual void ClearAnimValue() override;
|
|
|
|
virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
|
2009-01-15 07:38:07 +03:00
|
|
|
};
|
2006-04-14 19:09:39 +04:00
|
|
|
};
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
#endif // __NS_SVGLENGTH2_H__
|