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
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_SVGANIMATEDLENGTH_H_
|
|
|
|
#define DOM_SVG_SVGANIMATEDLENGTH_H_
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2019-01-25 06:24:01 +03:00
|
|
|
#include "mozilla/SMILAttr.h"
|
2019-01-23 16:48:08 +03:00
|
|
|
#include "mozilla/SVGContentUtils.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"
|
2019-01-23 16:48:08 +03:00
|
|
|
#include "mozilla/dom/SVGElement.h"
|
|
|
|
#include "mozilla/gfx/Rect.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCoord.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsMathUtils.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2020-01-17 13:00:28 +03:00
|
|
|
class mozAutoDocUpdate;
|
2008-09-11 04:24:16 +04:00
|
|
|
class nsIFrame;
|
2013-01-10 03:02:45 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2019-01-23 16:48:08 +03:00
|
|
|
|
2020-08-03 12:32:36 +03:00
|
|
|
class AutoChangeLengthNotifier;
|
2019-01-23 16:48:08 +03:00
|
|
|
class SMILValue;
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
namespace dom {
|
2019-03-19 03:01:03 +03:00
|
|
|
class DOMSVGAnimatedLength;
|
2018-12-28 16:42:46 +03:00
|
|
|
class DOMSVGLength;
|
2013-03-19 07:18:45 +04:00
|
|
|
class SVGAnimationElement;
|
2017-08-21 11:19:31 +03:00
|
|
|
class SVGViewportElement;
|
2014-09-15 14:12:50 +04:00
|
|
|
|
|
|
|
class UserSpaceMetrics {
|
|
|
|
public:
|
2019-06-23 15:51:05 +03:00
|
|
|
static bool ResolveAbsoluteUnit(uint8_t aUnitType, float& aRes);
|
2019-04-10 07:34:35 +03:00
|
|
|
virtual ~UserSpaceMetrics() = default;
|
2014-09-15 14:12:50 +04:00
|
|
|
|
|
|
|
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
|
|
|
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
|
2014-09-15 14:12:50 +04:00
|
|
|
|
2019-04-09 23:04:33 +03:00
|
|
|
class SVGAnimatedLength {
|
2020-08-03 12:32:36 +03:00
|
|
|
friend class AutoChangeLengthNotifier;
|
2020-07-15 13:37:55 +03:00
|
|
|
friend class dom::DOMSVGAnimatedLength;
|
|
|
|
friend class dom::DOMSVGLength;
|
|
|
|
using DOMSVGLength = dom::DOMSVGLength;
|
|
|
|
using SVGElement = dom::SVGElement;
|
|
|
|
using SVGViewportElement = dom::SVGViewportElement;
|
|
|
|
using UserSpaceMetrics = dom::UserSpaceMetrics;
|
2017-08-21 11:19:31 +03:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
public:
|
2020-07-15 13:37:55 +03:00
|
|
|
void Init(uint8_t aCtxType = SVGContentUtils::XY, uint8_t aAttrEnum = 0xff,
|
|
|
|
float aValue = 0,
|
|
|
|
uint8_t aUnitType = 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
|
|
|
}
|
|
|
|
|
2019-04-09 23:04:33 +03:00
|
|
|
SVGAnimatedLength& operator=(const SVGAnimatedLength& aLength) {
|
2011-06-21 00:15:42 +04:00
|
|
|
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 ==
|
2020-07-15 13:37:55 +03:00
|
|
|
dom::SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE;
|
2018-06-26 00:20:54 +03:00
|
|
|
}
|
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
|
|
|
|
2020-07-15 13:37:55 +03:00
|
|
|
already_AddRefed<dom::DOMSVGAnimatedLength> ToDOMAnimatedLength(
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement);
|
2013-01-06 13:32:02 +04:00
|
|
|
|
2020-07-15 13:37:55 +03:00
|
|
|
UniquePtr<SMILAttr> 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,
|
2020-08-03 12:32:36 +03:00
|
|
|
bool aDoSetAttr);
|
2018-12-21 11:58:14 +03:00
|
|
|
nsresult SetAnimValue(float aValue, SVGElement* aSVGElement);
|
|
|
|
void SetAnimValueInSpecifiedUnits(float aValue, SVGElement* aSVGElement);
|
2019-04-27 10:57:50 +03:00
|
|
|
nsresult NewValueSpecifiedUnits(uint16_t aUnitType,
|
|
|
|
float aValueInSpecifiedUnits,
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement);
|
|
|
|
nsresult ConvertToSpecifiedUnits(uint16_t aUnitType, SVGElement* aSVGElement);
|
2019-01-09 23:40:21 +03:00
|
|
|
already_AddRefed<DOMSVGLength> ToDOMBaseVal(SVGElement* aSVGElement);
|
|
|
|
already_AddRefed<DOMSVGLength> ToDOMAnimVal(SVGElement* aSVGElement);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-23 10:24:43 +04:00
|
|
|
public:
|
2019-01-25 06:24:01 +03:00
|
|
|
struct SMILLength : public SMILAttr {
|
2009-01-15 07:38:07 +03:00
|
|
|
public:
|
2019-04-09 23:04:33 +03:00
|
|
|
SMILLength(SVGAnimatedLength* aVal, SVGElement* aSVGElement)
|
2009-01-15 07:38:07 +03:00
|
|
|
: mVal(aVal), mSVGElement(aSVGElement) {}
|
|
|
|
|
2019-01-25 06:24:01 +03:00
|
|
|
// These will stay alive because a SMILAttr only lives as long
|
2009-01-15 07:38:07 +03:00
|
|
|
// as the Compositing step, and DOM elements don't get a chance to
|
|
|
|
// die during that.
|
2019-04-09 23:04:33 +03:00
|
|
|
SVGAnimatedLength* mVal;
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* mSVGElement;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2019-01-25 06:24:01 +03:00
|
|
|
// SMILAttr methods
|
2009-01-15 07:38:07 +03:00
|
|
|
virtual nsresult ValueFromString(
|
2020-07-15 13:37:55 +03:00
|
|
|
const nsAString& aStr, const dom::SVGAnimationElement* aSrcElement,
|
|
|
|
SMILValue& aValue, bool& aPreventCachingOfSandwich) const override;
|
2019-01-23 16:48:08 +03:00
|
|
|
virtual SMILValue GetBaseValue() const override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ClearAnimValue() override;
|
2019-01-23 16:48:08 +03:00
|
|
|
virtual nsresult SetAnimValue(const SMILValue& aValue) override;
|
2009-01-15 07:38:07 +03:00
|
|
|
};
|
2006-04-14 19:09:39 +04:00
|
|
|
};
|
|
|
|
|
2019-04-09 23:04:33 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_SVGANIMATEDLENGTH_H_
|