зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1837093 - Make SVGAnimatedLength methods take const pointers to avoid casting away const later r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D180175
This commit is contained in:
Родитель
9e793bbe26
Коммит
056bb264bd
|
@ -104,8 +104,8 @@ static float FixAxisLength(float aLength) {
|
|||
return aLength;
|
||||
}
|
||||
|
||||
SVGElementMetrics::SVGElementMetrics(SVGElement* aSVGElement,
|
||||
SVGViewportElement* aCtx)
|
||||
SVGElementMetrics::SVGElementMetrics(const SVGElement* aSVGElement,
|
||||
const SVGViewportElement* aCtx)
|
||||
: mSVGElement(aSVGElement), mCtx(aCtx) {}
|
||||
|
||||
float SVGElementMetrics::GetEmLength() const {
|
||||
|
@ -128,7 +128,7 @@ bool SVGElementMetrics::EnsureCtx() const {
|
|||
if (!mCtx && mSVGElement) {
|
||||
mCtx = mSVGElement->GetCtx();
|
||||
if (!mCtx && mSVGElement->IsSVGElement(nsGkAtoms::svg)) {
|
||||
auto* e = static_cast<SVGViewportElement*>(mSVGElement);
|
||||
const auto* e = static_cast<const SVGViewportElement*>(mSVGElement);
|
||||
|
||||
if (!e->IsInner()) {
|
||||
// mSVGElement must be the outer svg element
|
||||
|
@ -176,13 +176,13 @@ float UserSpaceMetricsWithSize::GetAxisLength(uint8_t aCtxType) const {
|
|||
return FixAxisLength(length);
|
||||
}
|
||||
|
||||
float SVGAnimatedLength::GetPixelsPerUnit(SVGElement* aSVGElement,
|
||||
float SVGAnimatedLength::GetPixelsPerUnit(const SVGElement* aSVGElement,
|
||||
uint8_t aUnitType) const {
|
||||
return SVGLength::GetPixelsPerUnit(SVGElementMetrics(aSVGElement), aUnitType,
|
||||
mCtxType);
|
||||
}
|
||||
|
||||
float SVGAnimatedLength::GetPixelsPerUnit(SVGViewportElement* aCtx,
|
||||
float SVGAnimatedLength::GetPixelsPerUnit(const SVGViewportElement* aCtx,
|
||||
uint8_t aUnitType) const {
|
||||
return SVGLength::GetPixelsPerUnit(SVGElementMetrics(aCtx, aCtx), aUnitType,
|
||||
mCtxType);
|
||||
|
@ -190,11 +190,11 @@ float SVGAnimatedLength::GetPixelsPerUnit(SVGViewportElement* aCtx,
|
|||
|
||||
float SVGAnimatedLength::GetPixelsPerUnit(nsIFrame* aFrame,
|
||||
uint8_t aUnitType) const {
|
||||
nsIContent* content = aFrame->GetContent();
|
||||
const nsIContent* content = aFrame->GetContent();
|
||||
MOZ_ASSERT(!content->IsText(), "Not expecting text content");
|
||||
if (content->IsSVGElement()) {
|
||||
return SVGLength::GetPixelsPerUnit(
|
||||
SVGElementMetrics(static_cast<SVGElement*>(content)), aUnitType,
|
||||
SVGElementMetrics(static_cast<const SVGElement*>(content)), aUnitType,
|
||||
mCtxType);
|
||||
}
|
||||
return SVGLength::GetPixelsPerUnit(NonSVGFrameUserSpaceMetrics(aFrame),
|
||||
|
|
|
@ -50,8 +50,8 @@ class UserSpaceMetricsWithSize : public UserSpaceMetrics {
|
|||
|
||||
class SVGElementMetrics : public UserSpaceMetrics {
|
||||
public:
|
||||
explicit SVGElementMetrics(SVGElement* aSVGElement,
|
||||
SVGViewportElement* aCtx = nullptr);
|
||||
explicit SVGElementMetrics(const SVGElement* aSVGElement,
|
||||
const SVGViewportElement* aCtx = nullptr);
|
||||
|
||||
float GetEmLength() const override;
|
||||
float GetExLength() const override;
|
||||
|
@ -60,8 +60,8 @@ class SVGElementMetrics : public UserSpaceMetrics {
|
|||
private:
|
||||
bool EnsureCtx() const;
|
||||
|
||||
SVGElement* mSVGElement;
|
||||
mutable SVGViewportElement* mCtx;
|
||||
const SVGElement* mSVGElement;
|
||||
mutable const SVGViewportElement* mCtx;
|
||||
};
|
||||
|
||||
class NonSVGFrameUserSpaceMetrics : public UserSpaceMetricsWithSize {
|
||||
|
@ -113,17 +113,17 @@ class SVGAnimatedLength {
|
|||
void GetBaseValueString(nsAString& aValue) const;
|
||||
void GetAnimValueString(nsAString& aValue) const;
|
||||
|
||||
float GetBaseValue(SVGElement* aSVGElement) const {
|
||||
float GetBaseValue(const SVGElement* aSVGElement) const {
|
||||
return mBaseVal * GetPixelsPerUnit(aSVGElement, mSpecifiedUnitType);
|
||||
}
|
||||
|
||||
float GetAnimValue(SVGElement* aSVGElement) const {
|
||||
float GetAnimValue(const SVGElement* aSVGElement) const {
|
||||
return mAnimVal * GetPixelsPerUnit(aSVGElement, mSpecifiedUnitType);
|
||||
}
|
||||
float GetAnimValue(nsIFrame* aFrame) const {
|
||||
return mAnimVal * GetPixelsPerUnit(aFrame, mSpecifiedUnitType);
|
||||
}
|
||||
float GetAnimValue(SVGViewportElement* aCtx) const {
|
||||
float GetAnimValue(const SVGViewportElement* aCtx) const {
|
||||
return mAnimVal * GetPixelsPerUnit(aCtx, mSpecifiedUnitType);
|
||||
}
|
||||
float GetAnimValue(const UserSpaceMetrics& aMetrics) const {
|
||||
|
@ -139,7 +139,7 @@ class SVGAnimatedLength {
|
|||
float GetAnimValInSpecifiedUnits() const { return mAnimVal; }
|
||||
float GetBaseValInSpecifiedUnits() const { return mBaseVal; }
|
||||
|
||||
float GetBaseValue(SVGViewportElement* aCtx) const {
|
||||
float GetBaseValue(const SVGViewportElement* aCtx) const {
|
||||
return mBaseVal * GetPixelsPerUnit(aCtx, mSpecifiedUnitType);
|
||||
}
|
||||
|
||||
|
@ -172,8 +172,10 @@ class SVGAnimatedLength {
|
|||
float GetPixelsPerUnit(nsIFrame* aFrame, uint8_t aUnitType) const;
|
||||
float GetPixelsPerUnit(const UserSpaceMetrics& aMetrics,
|
||||
uint8_t aUnitType) const;
|
||||
float GetPixelsPerUnit(SVGElement* aSVGElement, uint8_t aUnitType) const;
|
||||
float GetPixelsPerUnit(SVGViewportElement* aCtx, uint8_t aUnitType) const;
|
||||
float GetPixelsPerUnit(const SVGElement* aSVGElement,
|
||||
uint8_t aUnitType) const;
|
||||
float GetPixelsPerUnit(const 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
|
||||
|
|
|
@ -1532,7 +1532,7 @@ void SVGElement::GetAnimatedLengthValues(float* aFirst, ...) {
|
|||
NS_ASSERTION(info.mCount > 0,
|
||||
"GetAnimatedLengthValues on element with no length attribs");
|
||||
|
||||
SVGViewportElement* ctx = nullptr;
|
||||
SVGElementMetrics metrics(this);
|
||||
|
||||
float* f = aFirst;
|
||||
uint32_t i = 0;
|
||||
|
@ -1541,15 +1541,7 @@ void SVGElement::GetAnimatedLengthValues(float* aFirst, ...) {
|
|||
va_start(args, aFirst);
|
||||
|
||||
while (f && i < info.mCount) {
|
||||
uint8_t type = info.mValues[i].GetSpecifiedUnitType();
|
||||
if (!ctx && !SVGLength::IsAbsoluteUnit(type)) {
|
||||
ctx = GetCtx();
|
||||
}
|
||||
if (type == SVGLength_Binding::SVG_LENGTHTYPE_EMS ||
|
||||
type == SVGLength_Binding::SVG_LENGTHTYPE_EXS)
|
||||
*f = info.mValues[i++].GetAnimValue(this);
|
||||
else
|
||||
*f = info.mValues[i++].GetAnimValue(ctx);
|
||||
*f = info.mValues[i++].GetAnimValue(metrics);
|
||||
f = va_arg(args, float*);
|
||||
}
|
||||
|
||||
|
|
|
@ -100,8 +100,8 @@ bool SVGForeignObjectElement::HasValidDimensions() const {
|
|||
float width, height;
|
||||
|
||||
DebugOnly<bool> ok =
|
||||
SVGGeometryProperty::ResolveAll<SVGT::Width, SVGT::Height>(
|
||||
const_cast<SVGForeignObjectElement*>(this), &width, &height);
|
||||
SVGGeometryProperty::ResolveAll<SVGT::Width, SVGT::Height>(this, &width,
|
||||
&height);
|
||||
MOZ_ASSERT(ok, "SVGGeometryProperty::ResolveAll failed");
|
||||
return width > 0 && height > 0;
|
||||
}
|
||||
|
|
|
@ -89,21 +89,21 @@ using dummy = int[];
|
|||
using CtxDirectionType = decltype(SVGContentUtils::X);
|
||||
|
||||
template <CtxDirectionType CTD>
|
||||
float ResolvePureLengthPercentage(SVGElement* aElement,
|
||||
float ResolvePureLengthPercentage(const SVGElement* aElement,
|
||||
const LengthPercentage& aLP) {
|
||||
return aLP.ResolveToCSSPixelsWith(
|
||||
[&] { return CSSCoord{SVGElementMetrics(aElement).GetAxisLength(CTD)}; });
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
float ResolveImpl(ComputedStyle const& aStyle, SVGElement* aElement,
|
||||
float ResolveImpl(ComputedStyle const& aStyle, const SVGElement* aElement,
|
||||
ResolverTypes::LengthPercentNoAuto) {
|
||||
auto const& value = aStyle.StyleSVGReset()->*Tag::Getter;
|
||||
return ResolvePureLengthPercentage<Tag::CtxDirection>(aElement, value);
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
float ResolveImpl(ComputedStyle const& aStyle, SVGElement* aElement,
|
||||
float ResolveImpl(ComputedStyle const& aStyle, const SVGElement* aElement,
|
||||
ResolverTypes::LengthPercentWidthHeight) {
|
||||
static_assert(
|
||||
std::is_same<Tag, Tags::Width>{} || std::is_same<Tag, Tags::Height>{},
|
||||
|
@ -193,7 +193,7 @@ float ResolveImpl(ComputedStyle const& aStyle, SVGElement* aElement,
|
|||
}
|
||||
|
||||
template <class Tag>
|
||||
float ResolveImpl(ComputedStyle const& aStyle, SVGElement* aElement,
|
||||
float ResolveImpl(ComputedStyle const& aStyle, const SVGElement* aElement,
|
||||
ResolverTypes::LengthPercentRXY) {
|
||||
static_assert(std::is_same<Tag, Tags::Rx>{} || std::is_same<Tag, Tags::Ry>{},
|
||||
"Wrong tag");
|
||||
|
@ -222,9 +222,7 @@ float ResolveImpl(ComputedStyle const& aStyle, SVGElement* aElement,
|
|||
|
||||
template <class Tag>
|
||||
float ResolveWith(const ComputedStyle& aStyle, const SVGElement* aElement) {
|
||||
// TODO: There are a lot of utilities lacking const-ness in dom/svg.
|
||||
// We should fix that problem and remove this `const_cast`.
|
||||
return details::ResolveImpl<Tag>(aStyle, const_cast<SVGElement*>(aElement),
|
||||
return details::ResolveImpl<Tag>(aStyle, aElement,
|
||||
typename Tag::ResolverType{});
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ float SVGLength::GetValueInSpecifiedUnit(uint8_t aUnit,
|
|||
// succeed if aElement is non-null (although that's not sufficient to
|
||||
// guarantee success).
|
||||
|
||||
auto userSpaceMetrics = SVGElementMetrics(const_cast<SVGElement*>(aElement));
|
||||
SVGElementMetrics userSpaceMetrics(aElement);
|
||||
|
||||
float userUnitsPerCurrentUnit = GetPixelsPerUnit(userSpaceMetrics, aAxis);
|
||||
float userUnitsPerNewUnit =
|
||||
|
|
|
@ -90,10 +90,7 @@ class SVGLength {
|
|||
*/
|
||||
|
||||
float GetValueInPixels(const dom::SVGElement* aElement, uint8_t aAxis) const {
|
||||
return mValue *
|
||||
GetPixelsPerUnit(
|
||||
dom::SVGElementMetrics(const_cast<dom::SVGElement*>(aElement)),
|
||||
aAxis);
|
||||
return mValue * GetPixelsPerUnit(dom::SVGElementMetrics(aElement), aAxis);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -304,7 +304,7 @@ class MOZ_STACK_CLASS SVGUserUnitList {
|
|||
public:
|
||||
SVGUserUnitList() : mList(nullptr), mElement(nullptr), mAxis(0) {}
|
||||
|
||||
void Init(const SVGLengthList* aList, dom::SVGElement* aElement,
|
||||
void Init(const SVGLengthList* aList, const dom::SVGElement* aElement,
|
||||
uint8_t aAxis) {
|
||||
mList = aList;
|
||||
mElement = aElement;
|
||||
|
@ -330,7 +330,7 @@ class MOZ_STACK_CLASS SVGUserUnitList {
|
|||
|
||||
private:
|
||||
const SVGLengthList* mList;
|
||||
dom::SVGElement* mElement;
|
||||
const dom::SVGElement* mElement;
|
||||
uint8_t mAxis;
|
||||
};
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ inline float ComputeSynthesizedViewBoxDimension(
|
|||
return aViewportLength * aLength.GetAnimValInSpecifiedUnits() / 100.0f;
|
||||
}
|
||||
|
||||
return aLength.GetAnimValue(const_cast<SVGViewportElement*>(aSelf));
|
||||
return aLength.GetAnimValue(aSelf);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -156,9 +156,9 @@ void SVGViewportElement::ChildrenOnlyTransformChanged(uint32_t aFlags) {
|
|||
gfx::Matrix SVGViewportElement::GetViewBoxTransform() const {
|
||||
float viewportWidth, viewportHeight;
|
||||
if (IsInner()) {
|
||||
SVGElement* self = const_cast<SVGViewportElement*>(this);
|
||||
viewportWidth = mLengthAttributes[ATTR_WIDTH].GetAnimValue(self);
|
||||
viewportHeight = mLengthAttributes[ATTR_HEIGHT].GetAnimValue(self);
|
||||
SVGElementMetrics metrics(this);
|
||||
viewportWidth = mLengthAttributes[ATTR_WIDTH].GetAnimValue(metrics);
|
||||
viewportHeight = mLengthAttributes[ATTR_HEIGHT].GetAnimValue(metrics);
|
||||
} else {
|
||||
viewportWidth = mViewportWidth;
|
||||
viewportHeight = mViewportHeight;
|
||||
|
@ -183,7 +183,7 @@ gfx::Matrix SVGViewportElement::GetViewBoxTransform() const {
|
|||
//----------------------------------------------------------------------
|
||||
// SVGViewportElement
|
||||
|
||||
float SVGViewportElement::GetLength(uint8_t aCtxType) {
|
||||
float SVGViewportElement::GetLength(uint8_t aCtxType) const {
|
||||
const SVGViewBox* viewbox = GetViewBoxInternal().HasRect()
|
||||
? &GetViewBoxInternal().GetAnimValue()
|
||||
: nullptr;
|
||||
|
@ -201,12 +201,12 @@ float SVGViewportElement::GetLength(uint8_t aCtxType) {
|
|||
// Resolving length for inner <svg> is exactly the same as other
|
||||
// ordinary element. We shouldn't use the SVGViewportElement overload
|
||||
// of GetAnimValue().
|
||||
SVGElement* self = this;
|
||||
SVGElementMetrics metrics(this);
|
||||
if (shouldComputeWidth) {
|
||||
w = mLengthAttributes[ATTR_WIDTH].GetAnimValue(self);
|
||||
w = mLengthAttributes[ATTR_WIDTH].GetAnimValue(metrics);
|
||||
}
|
||||
if (shouldComputeHeight) {
|
||||
h = mLengthAttributes[ATTR_HEIGHT].GetAnimValue(self);
|
||||
h = mLengthAttributes[ATTR_HEIGHT].GetAnimValue(metrics);
|
||||
}
|
||||
} else if (ShouldSynthesizeViewBox()) {
|
||||
if (shouldComputeWidth) {
|
||||
|
|
|
@ -63,7 +63,7 @@ class SVGViewportElement : public SVGGraphicsElement {
|
|||
|
||||
// SVGViewportElement methods:
|
||||
|
||||
float GetLength(uint8_t aCtxType);
|
||||
float GetLength(uint8_t aCtxType) const;
|
||||
|
||||
// public helpers:
|
||||
|
||||
|
|
|
@ -261,11 +261,6 @@ float SVGUtils::ObjectSpace(const gfxRect& aRect,
|
|||
axis;
|
||||
}
|
||||
|
||||
float SVGUtils::UserSpace(SVGElement* aSVGElement,
|
||||
const SVGAnimatedLength* aLength) {
|
||||
return aLength->GetAnimValue(aSVGElement);
|
||||
}
|
||||
|
||||
float SVGUtils::UserSpace(nsIFrame* aNonSVGContext,
|
||||
const SVGAnimatedLength* aLength) {
|
||||
MOZ_ASSERT(!aNonSVGContext->IsTextFrame(), "Not expecting text content");
|
||||
|
|
|
@ -222,8 +222,6 @@ class SVGUtils final {
|
|||
Input: content - object to be used for determining user space
|
||||
Input: length - length to be converted
|
||||
*/
|
||||
static float UserSpace(SVGElement* aSVGElement,
|
||||
const SVGAnimatedLength* aLength);
|
||||
static float UserSpace(nsIFrame* aNonSVGContext,
|
||||
const SVGAnimatedLength* aLength);
|
||||
static float UserSpace(const dom::UserSpaceMetrics& aMetrics,
|
||||
|
|
Загрузка…
Ссылка в новой задаче