Bug 1390088 - Part 1. Change the type of the parameter of nsSVGLength2::GetAnimValue from "SVGSVGElement*" to "SVGViewportElement*"
There are two overloads of nsSVGLength2::GetAnimValue:
1. float nsSVGLength2::GetAnimValue(nsSVGElement*) const;
2. float nsSVGLength2::GetAnimValue(SVGSVGElement*) const;
In
Bug 265894, I created SVGViewportElement as a base class of SVGSVGElement.
SVGSVGElement::GetViewBoxTransform was moved to SVGViewportElement in that
refactoring. The local variable 'ctx' in that function was changed from
SVGSVGElement to SVGViewportElement, which when passed to
nsSVGLength2::GetAnimValue caused us to switch from calling the overload that
takes a SVGSVGElement to the overload that takes a nsSVGElement, which is not
what we want.
This patch changes the argument type of the nsSVGLength2::GetAnimValue overload
that takes an SVGSVGElement to take an SVGViewportElement instead, which causes
the GetAnimValue(ctx) calls in SVGViewportElement::GetViewBoxTransform to call
the correct GetAnimValue overload again.
MozReview-Commit-ID: 2cmgIoltYfY
--- a/dom/svg/nsSVGLength2.cpp
+++ b/dom/svg/nsSVGLength2.cpp
@@ -3,17 +3,17 @@
/* 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/. */
#include "mozilla/ArrayUtils.h"
#include "nsSVGLength2.h"
#include "mozilla/dom/SVGAnimatedLength.h"
-#include "mozilla/dom/SVGSVGElement.h"
+#include "mozilla/dom/SVGViewportElement.h"
#include "nsContentUtils.h" // NS_ENSURE_FINITE
#include "nsIFrame.h"
#include "nsSMILFloatType.h"
#include "nsSMILValue.h"
#include "nsSVGAttrTearoffTable.h"
#include "nsSVGIntegrationUtils.h"
#include "nsTextFormatter.h"
#include "DOMSVGLength.h"
@@ -123,17 +123,17 @@ FixAxisLength(float aLength)
if (aLength == 0.0f) {
LAYOUT_WARNING("zero axis length");
return 1e-20f;
}
return aLength;
}
SVGElementMetrics::SVGElementMetrics(nsSVGElement* aSVGElement,
- SVGSVGElement* aCtx)
+ SVGViewportElement* aCtx)
: mSVGElement(aSVGElement)
, mCtx(aCtx)
{
}
float
SVGElementMetrics::GetEmLength() const
{
@@ -158,17 +158,17 @@ SVGElementMetrics::GetAxisLength(uint8_t
bool
SVGElementMetrics::EnsureCtx() const
{
if (!mCtx && mSVGElement) {
mCtx = mSVGElement->GetCtx();
if (!mCtx && mSVGElement->IsSVGElement(nsGkAtoms::svg)) {
// mSVGElement must be the outer svg element
- mCtx = static_cast<SVGSVGElement*>(mSVGElement);
+ mCtx = static_cast<SVGViewportElement*>(mSVGElement);
}
}
return mCtx != nullptr;
}
NonSVGFrameUserSpaceMetrics::NonSVGFrameUserSpaceMetrics(nsIFrame* aFrame)
: mFrame(aFrame)
{
@@ -211,30 +211,30 @@ UserSpaceMetricsWithSize::GetAxisLength(
NS_NOTREACHED("Unknown axis type");
length = 1;
break;
}
return FixAxisLength(length);
}
float
-nsSVGLength2::GetUnitScaleFactor(nsSVGElement *aSVGElement,
+nsSVGLength2::GetUnitScaleFactor(nsSVGElement* aSVGElement,
uint8_t aUnitType) const
{
return GetUnitScaleFactor(SVGElementMetrics(aSVGElement), aUnitType);
}
float
-nsSVGLength2::GetUnitScaleFactor(SVGSVGElement *aCtx, uint8_t aUnitType) const
+nsSVGLength2::GetUnitScaleFactor(SVGViewportElement* aCtx, uint8_t aUnitType) const
{
return GetUnitScaleFactor(SVGElementMetrics(aCtx, aCtx), aUnitType);
}
float
-nsSVGLength2::GetUnitScaleFactor(nsIFrame *aFrame, uint8_t aUnitType) const
+nsSVGLength2::GetUnitScaleFactor(nsIFrame* aFrame, uint8_t aUnitType) const
{
nsIContent* content = aFrame->GetContent();
if (content->IsSVGElement()) {
return GetUnitScaleFactor(SVGElementMetrics(static_cast<nsSVGElement*>(content)), aUnitType);
}
return GetUnitScaleFactor(NonSVGFrameUserSpaceMetrics(aFrame), aUnitType);
}
--- a/dom/svg/nsSVGLength2.h
+++ b/dom/svg/nsSVGLength2.h
@@ -22,17 +22,17 @@
class nsIFrame;
class nsSMILValue;
namespace mozilla {
class DOMSVGLength;
namespace dom {
class SVGAnimatedLength;
class SVGAnimationElement;
-class SVGSVGElement;
+class SVGViewportElement;
} // namespace dom
} // namespace mozilla
namespace mozilla {
namespace dom {
class UserSpaceMetrics
{
@@ -49,28 +49,30 @@ class UserSpaceMetricsWithSize : public
public:
virtual gfx::Size GetSize() const = 0;
virtual float GetAxisLength(uint8_t aCtxType) const override;
};
class SVGElementMetrics : public UserSpaceMetrics
{
public:
+ typedef mozilla::dom::SVGViewportElement SVGViewportElement;
+
explicit SVGElementMetrics(nsSVGElement* aSVGElement,
- mozilla::dom::SVGSVGElement* aCtx = nullptr);
+ SVGViewportElement* aCtx = nullptr);
virtual float GetEmLength() const override;
virtual float GetExLength() const override;
virtual float GetAxisLength(uint8_t aCtxType) const override;
private:
bool EnsureCtx() const;
nsSVGElement* mSVGElement;
- mutable mozilla::dom::SVGSVGElement* mCtx;
+ mutable SVGViewportElement* mCtx;
};
class NonSVGFrameUserSpaceMetrics : public UserSpaceMetricsWithSize
{
public:
explicit NonSVGFrameUserSpaceMetrics(nsIFrame* aFrame);
virtual float GetEmLength() const override;
@@ -84,16 +86,18 @@ private:
} // namespace dom
} // namespace mozilla
class nsSVGLength2
{
friend class mozilla::dom::SVGAnimatedLength;
friend class mozilla::DOMSVGLength;
typedef mozilla::dom::UserSpaceMetrics UserSpaceMetrics;
+ typedef mozilla::dom::SVGViewportElement SVGViewportElement;
+
public:
void Init(uint8_t aCtxType = SVGContentUtils::XY,
uint8_t aAttrEnum = 0xff,
float aValue = 0,
uint8_t aUnitType = nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER) {
mAnimVal = mBaseVal = aValue;
mSpecifiedUnitType = aUnitType;
mAttrEnum = aAttrEnum;
@@ -119,29 +123,29 @@ public:
float GetBaseValue(nsSVGElement* aSVGElement) const
{ return mBaseVal / GetUnitScaleFactor(aSVGElement, mSpecifiedUnitType); }
float GetAnimValue(nsSVGElement* aSVGElement) const
{ return mAnimVal / GetUnitScaleFactor(aSVGElement, mSpecifiedUnitType); }
float GetAnimValue(nsIFrame* aFrame) const
{ return mAnimVal / GetUnitScaleFactor(aFrame, mSpecifiedUnitType); }
- float GetAnimValue(mozilla::dom::SVGSVGElement* aCtx) const
+ float GetAnimValue(SVGViewportElement* aCtx) const
{ return mAnimVal / GetUnitScaleFactor(aCtx, mSpecifiedUnitType); }
float GetAnimValue(const UserSpaceMetrics& aMetrics) const
{ return mAnimVal / GetUnitScaleFactor(aMetrics, mSpecifiedUnitType); }
uint8_t GetCtxType() const { return mCtxType; }
uint8_t GetSpecifiedUnitType() const { return mSpecifiedUnitType; }
bool IsPercentage() const
{ return mSpecifiedUnitType == nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE; }
float GetAnimValInSpecifiedUnits() const { return mAnimVal; }
float GetBaseValInSpecifiedUnits() const { return mBaseVal; }
- float GetBaseValue(mozilla::dom::SVGSVGElement* aCtx) const
+ float GetBaseValue(SVGViewportElement* aCtx) const
{ return mBaseVal / GetUnitScaleFactor(aCtx, mSpecifiedUnitType); }
bool HasBaseVal() const {
return mIsBaseSet;
}
// Returns true if the animated value of this length has been explicitly
// set (either by animation, or by taking on the base value which has been
// explicitly set by markup or a DOM call), false otherwise.
@@ -159,20 +163,20 @@ private:
float mAnimVal;
float mBaseVal;
uint8_t mSpecifiedUnitType;
uint8_t mAttrEnum; // element specified tracking for attribute
uint8_t mCtxType; // X, Y or Unspecified
bool mIsAnimated:1;
bool mIsBaseSet:1;
- float GetUnitScaleFactor(nsIFrame *aFrame, uint8_t aUnitType) const;
+ float GetUnitScaleFactor(nsIFrame* aFrame, uint8_t aUnitType) const;
float GetUnitScaleFactor(const UserSpaceMetrics& aMetrics, uint8_t aUnitType) const;
- float GetUnitScaleFactor(nsSVGElement *aSVGElement, uint8_t aUnitType) const;
- float GetUnitScaleFactor(mozilla::dom::SVGSVGElement *aCtx, uint8_t aUnitType) const;
+ float GetUnitScaleFactor(nsSVGElement* aSVGElement, uint8_t aUnitType) const;
+ float GetUnitScaleFactor(SVGViewportElement* aCtx, uint8_t aUnitType) const;
// SetBaseValue and SetAnimValue set the value in user units
void SetBaseValue(float aValue, nsSVGElement *aSVGElement, bool aDoSetAttr);
void SetBaseValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement,
bool aDoSetAttr);
void SetAnimValue(float aValue, nsSVGElement *aSVGElement);
void SetAnimValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement);
nsresult NewValueSpecifiedUnits(uint16_t aUnitType, float aValue,
--- a/layout/svg/nsSVGGradientFrame.cpp
+++ b/layout/svg/nsSVGGradientFrame.cpp
@@ -469,17 +469,17 @@ nsSVGLinearGradientFrame::GetLengthValue
if (gradientUnits == SVG_UNIT_TYPE_USERSPACEONUSE) {
return nsSVGUtils::UserSpace(mSource, &length);
}
NS_ASSERTION(
gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX,
"Unknown gradientUnits type");
- return length.GetAnimValue(static_cast<SVGSVGElement*>(nullptr));
+ return length.GetAnimValue(static_cast<SVGViewportElement*>(nullptr));
}
dom::SVGLinearGradientElement*
nsSVGLinearGradientFrame::GetLinearGradientWithLength(uint32_t aIndex,
dom::SVGLinearGradientElement* aDefault)
{
dom::SVGLinearGradientElement* thisElement =
static_cast<dom::SVGLinearGradientElement*>(mContent);
@@ -589,17 +589,17 @@ nsSVGRadialGradientFrame::GetLengthValue
if (gradientUnits == SVG_UNIT_TYPE_USERSPACEONUSE) {
return nsSVGUtils::UserSpace(mSource, &length);
}
NS_ASSERTION(
gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX,
"Unknown gradientUnits type");
- return length.GetAnimValue(static_cast<SVGSVGElement*>(nullptr));
+ return length.GetAnimValue(static_cast<SVGViewportElement*>(nullptr));
}
dom::SVGRadialGradientElement*
nsSVGRadialGradientFrame::GetRadialGradientWithLength(uint32_t aIndex,
dom::SVGRadialGradientElement* aDefault)
{
dom::SVGRadialGradientElement* thisElement =
static_cast<dom::SVGRadialGradientElement*>(mContent);