Bug 1540408 Part 3 - Rename SVGViewBoxRect to SVGViewBox r=dholbert

This commit is contained in:
longsonr
2019-04-10 05:08:14 +01:00
parent 8eec04afdb
commit 632c5be54b
23 changed files with 140 additions and 130 deletions

View File

@@ -19,9 +19,9 @@ namespace mozilla {
#define NUM_VIEWBOX_COMPONENTS 4
/* Implementation of SVGViewBoxRect methods */
/* Implementation of SVGViewBox methods */
bool SVGViewBoxRect::operator==(const SVGViewBoxRect& aOther) const {
bool SVGViewBox::operator==(const SVGViewBox& aOther) const {
if (&aOther == this) return true;
return (none && aOther.none) ||
@@ -30,8 +30,7 @@ bool SVGViewBoxRect::operator==(const SVGViewBoxRect& aOther) const {
}
/* static */
nsresult SVGViewBoxRect::FromString(const nsAString& aStr,
SVGViewBoxRect* aViewBox) {
nsresult SVGViewBox::FromString(const nsAString& aStr, SVGViewBox* aViewBox) {
if (aStr.EqualsLiteral("none")) {
aViewBox->none = true;
return NS_OK;
@@ -107,7 +106,7 @@ void SVGAnimatedViewBox::Init() {
bool SVGAnimatedViewBox::HasRect() const {
// Check mAnimVal if we have one; otherwise, check mBaseVal if we have one;
// otherwise, just return false (we clearly do not have a rect).
const SVGViewBoxRect* rect = mAnimVal;
const SVGViewBox* rect = mAnimVal;
if (!rect) {
if (!mHasBaseVal) {
// no anim val, no base val --> no viewbox rect
@@ -119,11 +118,11 @@ bool SVGAnimatedViewBox::HasRect() const {
return !rect->none && rect->width >= 0 && rect->height >= 0;
}
void SVGAnimatedViewBox::SetAnimValue(const SVGViewBoxRect& aRect,
void SVGAnimatedViewBox::SetAnimValue(const SVGViewBox& aRect,
SVGElement* aSVGElement) {
if (!mAnimVal) {
// it's okay if allocation fails - and no point in reporting that
mAnimVal = new SVGViewBoxRect(aRect);
mAnimVal = new SVGViewBox(aRect);
} else {
if (aRect == *mAnimVal) {
return;
@@ -133,7 +132,7 @@ void SVGAnimatedViewBox::SetAnimValue(const SVGViewBoxRect& aRect,
aSVGElement->DidAnimateViewBox();
}
void SVGAnimatedViewBox::SetBaseValue(const SVGViewBoxRect& aRect,
void SVGAnimatedViewBox::SetBaseValue(const SVGViewBox& aRect,
SVGElement* aSVGElement) {
if (!mHasBaseVal || mBaseVal == aRect) {
// This method is used to set a single x, y, width
@@ -158,9 +157,9 @@ void SVGAnimatedViewBox::SetBaseValue(const SVGViewBoxRect& aRect,
nsresult SVGAnimatedViewBox::SetBaseValueString(const nsAString& aValue,
SVGElement* aSVGElement,
bool aDoSetAttr) {
SVGViewBoxRect viewBox;
SVGViewBox viewBox;
nsresult rv = SVGViewBoxRect::FromString(aValue, &viewBox);
nsresult rv = SVGViewBox::FromString(aValue, &viewBox);
if (NS_FAILED(rv)) {
return rv;
}
@@ -247,26 +246,26 @@ SVGAnimatedViewBox::DOMAnimVal::~DOMAnimVal() {
}
void SVGAnimatedViewBox::DOMBaseVal::SetX(float aX, ErrorResult& aRv) {
SVGViewBoxRect rect = mVal->GetBaseValue();
SVGViewBox rect = mVal->GetBaseValue();
rect.x = aX;
mVal->SetBaseValue(rect, mSVGElement);
}
void SVGAnimatedViewBox::DOMBaseVal::SetY(float aY, ErrorResult& aRv) {
SVGViewBoxRect rect = mVal->GetBaseValue();
SVGViewBox rect = mVal->GetBaseValue();
rect.y = aY;
mVal->SetBaseValue(rect, mSVGElement);
}
void SVGAnimatedViewBox::DOMBaseVal::SetWidth(float aWidth, ErrorResult& aRv) {
SVGViewBoxRect rect = mVal->GetBaseValue();
SVGViewBox rect = mVal->GetBaseValue();
rect.width = aWidth;
mVal->SetBaseValue(rect, mSVGElement);
}
void SVGAnimatedViewBox::DOMBaseVal::SetHeight(float aHeight,
ErrorResult& aRv) {
SVGViewBoxRect rect = mVal->GetBaseValue();
SVGViewBox rect = mVal->GetBaseValue();
rect.height = aHeight;
mVal->SetBaseValue(rect, mSVGElement);
}
@@ -278,13 +277,13 @@ UniquePtr<SMILAttr> SVGAnimatedViewBox::ToSMILAttr(SVGElement* aSVGElement) {
nsresult SVGAnimatedViewBox::SMILViewBox ::ValueFromString(
const nsAString& aStr, const SVGAnimationElement* /*aSrcElement*/,
SMILValue& aValue, bool& aPreventCachingOfSandwich) const {
SVGViewBoxRect viewBox;
nsresult res = SVGViewBoxRect::FromString(aStr, &viewBox);
SVGViewBox viewBox;
nsresult res = SVGViewBox::FromString(aStr, &viewBox);
if (NS_FAILED(res)) {
return res;
}
SMILValue val(&SVGViewBoxSMILType::sSingleton);
*static_cast<SVGViewBoxRect*>(val.mU.mPtr) = viewBox;
*static_cast<SVGViewBox*>(val.mU.mPtr) = viewBox;
aValue = std::move(val);
aPreventCachingOfSandwich = false;
@@ -293,7 +292,7 @@ nsresult SVGAnimatedViewBox::SMILViewBox ::ValueFromString(
SMILValue SVGAnimatedViewBox::SMILViewBox::GetBaseValue() const {
SMILValue val(&SVGViewBoxSMILType::sSingleton);
*static_cast<SVGViewBoxRect*>(val.mU.mPtr) = mVal->mBaseVal;
*static_cast<SVGViewBox*>(val.mU.mPtr) = mVal->mBaseVal;
return val;
}
@@ -309,7 +308,7 @@ nsresult SVGAnimatedViewBox::SMILViewBox::SetAnimValue(
NS_ASSERTION(aValue.mType == &SVGViewBoxSMILType::sSingleton,
"Unexpected type to assign animated value");
if (aValue.mType == &SVGViewBoxSMILType::sSingleton) {
SVGViewBoxRect& vb = *static_cast<SVGViewBoxRect*>(aValue.mU.mPtr);
SVGViewBox& vb = *static_cast<SVGViewBox*>(aValue.mU.mPtr);
mVal->SetAnimValue(vb, mSVGElement);
}
return NS_OK;

View File

@@ -26,23 +26,23 @@ class SVGAnimationElement;
class SVGElement;
} // namespace dom
struct SVGViewBoxRect {
struct SVGViewBox {
float x, y;
float width, height;
bool none;
SVGViewBoxRect() : x(0.0), y(0.0), width(0.0), height(0.0), none(true) {}
SVGViewBoxRect(float aX, float aY, float aWidth, float aHeight)
SVGViewBox() : x(0.0), y(0.0), width(0.0), height(0.0), none(true) {}
SVGViewBox(float aX, float aY, float aWidth, float aHeight)
: x(aX), y(aY), width(aWidth), height(aHeight), none(false) {}
SVGViewBoxRect(const SVGViewBoxRect& rhs)
SVGViewBox(const SVGViewBox& rhs)
: x(rhs.x),
y(rhs.y),
width(rhs.width),
height(rhs.height),
none(rhs.none) {}
bool operator==(const SVGViewBoxRect& aOther) const;
bool operator==(const SVGViewBox& aOther) const;
static nsresult FromString(const nsAString& aStr, SVGViewBoxRect* aViewBox);
static nsresult FromString(const nsAString& aStr, SVGViewBox* aViewBox);
};
class SVGAnimatedViewBox {
@@ -66,18 +66,18 @@ class SVGAnimatedViewBox {
*/
bool IsExplicitlySet() const {
if (mAnimVal || mHasBaseVal) {
const SVGViewBoxRect& rect = GetAnimValue();
const SVGViewBox& rect = GetAnimValue();
return rect.none || (rect.width >= 0 && rect.height >= 0);
}
return false;
}
const SVGViewBoxRect& GetBaseValue() const { return mBaseVal; }
void SetBaseValue(const SVGViewBoxRect& aRect, SVGElement* aSVGElement);
const SVGViewBoxRect& GetAnimValue() const {
const SVGViewBox& GetBaseValue() const { return mBaseVal; }
void SetBaseValue(const SVGViewBox& aRect, SVGElement* aSVGElement);
const SVGViewBox& GetAnimValue() const {
return mAnimVal ? *mAnimVal : mBaseVal;
}
void SetAnimValue(const SVGViewBoxRect& aRect, SVGElement* aSVGElement);
void SetAnimValue(const SVGViewBox& aRect, SVGElement* aSVGElement);
nsresult SetBaseValueString(const nsAString& aValue, SVGElement* aSVGElement,
bool aDoSetAttr);
@@ -95,8 +95,8 @@ class SVGAnimatedViewBox {
mozilla::UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement);
private:
SVGViewBoxRect mBaseVal;
nsAutoPtr<SVGViewBoxRect> mAnimVal;
SVGViewBox mBaseVal;
nsAutoPtr<SVGViewBox> mAnimVal;
bool mHasBaseVal;
public:

View File

@@ -173,20 +173,20 @@ nsresult SVGElement::Init() {
enumInfo.Reset(i);
}
SVGAnimatedOrient* orient = GetOrient();
SVGAnimatedOrient* orient = GetAnimatedOrient();
if (orient) {
orient->Init();
}
SVGAnimatedViewBox* viewBox = GetViewBox();
SVGAnimatedViewBox* viewBox = GetAnimatedViewBox();
if (viewBox) {
viewBox->Init();
}
SVGAnimatedPreserveAspectRatio* preserveAspectRatio =
GetPreserveAspectRatio();
GetAnimatedPreserveAspectRatio();
if (preserveAspectRatio) {
preserveAspectRatio->Init();
@@ -532,7 +532,7 @@ bool SVGElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
if (!foundMatch) {
// Check for orient attribute
if (aAttribute == nsGkAtoms::orient) {
SVGAnimatedOrient* orient = GetOrient();
SVGAnimatedOrient* orient = GetAnimatedOrient();
if (orient) {
rv = orient->SetBaseValueString(aValue, this, false);
if (NS_FAILED(rv)) {
@@ -545,7 +545,7 @@ bool SVGElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
}
// Check for viewBox attribute
} else if (aAttribute == nsGkAtoms::viewBox) {
SVGAnimatedViewBox* viewBox = GetViewBox();
SVGAnimatedViewBox* viewBox = GetAnimatedViewBox();
if (viewBox) {
rv = viewBox->SetBaseValueString(aValue, this, false);
if (NS_FAILED(rv)) {
@@ -559,7 +559,7 @@ bool SVGElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
// Check for preserveAspectRatio attribute
} else if (aAttribute == nsGkAtoms::preserveAspectRatio) {
SVGAnimatedPreserveAspectRatio* preserveAspectRatio =
GetPreserveAspectRatio();
GetAnimatedPreserveAspectRatio();
if (preserveAspectRatio) {
rv = preserveAspectRatio->SetBaseValueString(aValue, this, false);
if (NS_FAILED(rv)) {
@@ -768,7 +768,7 @@ void SVGElement::UnsetAttrInternal(int32_t aNamespaceID, nsAtom* aName,
// Check if this is an orient attribute going away
if (aName == nsGkAtoms::orient) {
SVGAnimatedOrient* orient = GetOrient();
SVGAnimatedOrient* orient = GetAnimatedOrient();
if (orient) {
MaybeSerializeAttrBeforeRemoval(aName, aNotify);
orient->Init();
@@ -778,7 +778,7 @@ void SVGElement::UnsetAttrInternal(int32_t aNamespaceID, nsAtom* aName,
// Check if this is a viewBox attribute going away
if (aName == nsGkAtoms::viewBox) {
SVGAnimatedViewBox* viewBox = GetViewBox();
SVGAnimatedViewBox* viewBox = GetAnimatedViewBox();
if (viewBox) {
MaybeSerializeAttrBeforeRemoval(aName, aNotify);
viewBox->Init();
@@ -789,7 +789,7 @@ void SVGElement::UnsetAttrInternal(int32_t aNamespaceID, nsAtom* aName,
// Check if this is a preserveAspectRatio attribute going away
if (aName == nsGkAtoms::preserveAspectRatio) {
SVGAnimatedPreserveAspectRatio* preserveAspectRatio =
GetPreserveAspectRatio();
GetAnimatedPreserveAspectRatio();
if (preserveAspectRatio) {
MaybeSerializeAttrBeforeRemoval(aName, aNotify);
preserveAspectRatio->Init();
@@ -1885,14 +1885,14 @@ void SVGElement::DidAnimateEnum(uint8_t aAttrEnum) {
}
}
SVGAnimatedOrient* SVGElement::GetOrient() { return nullptr; }
SVGAnimatedOrient* SVGElement::GetAnimatedOrient() { return nullptr; }
nsAttrValue SVGElement::WillChangeOrient() {
return WillChangeValue(nsGkAtoms::orient);
}
void SVGElement::DidChangeOrient(const nsAttrValue& aEmptyOrOldValue) {
SVGAnimatedOrient* orient = GetOrient();
SVGAnimatedOrient* orient = GetAnimatedOrient();
NS_ASSERTION(orient, "DidChangeOrient on element with no orient attrib");
@@ -1911,14 +1911,14 @@ void SVGElement::DidAnimateOrient() {
}
}
SVGAnimatedViewBox* SVGElement::GetViewBox() { return nullptr; }
SVGAnimatedViewBox* SVGElement::GetAnimatedViewBox() { return nullptr; }
nsAttrValue SVGElement::WillChangeViewBox() {
return WillChangeValue(nsGkAtoms::viewBox);
}
void SVGElement::DidChangeViewBox(const nsAttrValue& aEmptyOrOldValue) {
SVGAnimatedViewBox* viewBox = GetViewBox();
SVGAnimatedViewBox* viewBox = GetAnimatedViewBox();
NS_ASSERTION(viewBox, "DidChangeViewBox on element with no viewBox attrib");
@@ -1937,7 +1937,7 @@ void SVGElement::DidAnimateViewBox() {
}
}
SVGAnimatedPreserveAspectRatio* SVGElement::GetPreserveAspectRatio() {
SVGAnimatedPreserveAspectRatio* SVGElement::GetAnimatedPreserveAspectRatio() {
return nullptr;
}
@@ -1948,7 +1948,7 @@ nsAttrValue SVGElement::WillChangePreserveAspectRatio() {
void SVGElement::DidChangePreserveAspectRatio(
const nsAttrValue& aEmptyOrOldValue) {
SVGAnimatedPreserveAspectRatio* preserveAspectRatio =
GetPreserveAspectRatio();
GetAnimatedPreserveAspectRatio();
NS_ASSERTION(preserveAspectRatio,
"DidChangePreserveAspectRatio on element with no "
@@ -2222,20 +2222,20 @@ UniquePtr<SMILAttr> SVGElement::GetAnimatedAttr(int32_t aNamespaceID,
// orient:
if (aName == nsGkAtoms::orient) {
SVGAnimatedOrient* orient = GetOrient();
SVGAnimatedOrient* orient = GetAnimatedOrient();
return orient ? orient->ToSMILAttr(this) : nullptr;
}
// viewBox:
if (aName == nsGkAtoms::viewBox) {
SVGAnimatedViewBox* viewBox = GetViewBox();
SVGAnimatedViewBox* viewBox = GetAnimatedViewBox();
return viewBox ? viewBox->ToSMILAttr(this) : nullptr;
}
// preserveAspectRatio:
if (aName == nsGkAtoms::preserveAspectRatio) {
SVGAnimatedPreserveAspectRatio* preserveAspectRatio =
GetPreserveAspectRatio();
GetAnimatedPreserveAspectRatio();
return preserveAspectRatio ? preserveAspectRatio->ToSMILAttr(this)
: nullptr;
}

View File

@@ -567,9 +567,9 @@ class SVGElement : public SVGElementBase // nsIContent
virtual EnumAttributesInfo GetEnumInfo();
// We assume all orients, viewboxes and preserveAspectRatios are alike
// so we don't need to wrap the class
virtual SVGAnimatedOrient* GetOrient();
virtual SVGAnimatedPreserveAspectRatio* GetPreserveAspectRatio();
virtual SVGAnimatedViewBox* GetViewBox();
virtual SVGAnimatedOrient* GetAnimatedOrient();
virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio();
virtual SVGAnimatedViewBox* GetAnimatedViewBox();
virtual NumberListAttributesInfo GetNumberListInfo();
virtual LengthListAttributesInfo GetLengthListInfo();
virtual StringAttributesInfo GetStringInfo();

View File

@@ -284,7 +284,8 @@ SVGFEImageElement::PreserveAspectRatio() {
return mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(this);
}
SVGAnimatedPreserveAspectRatio* SVGFEImageElement::GetPreserveAspectRatio() {
SVGAnimatedPreserveAspectRatio*
SVGFEImageElement::GetAnimatedPreserveAspectRatio() {
return &mPreserveAspectRatio;
}

View File

@@ -88,7 +88,8 @@ class SVGFEImageElement final : public SVGFEImageElementBase,
protected:
virtual bool ProducesSRGB() override { return true; }
virtual SVGAnimatedPreserveAspectRatio* GetPreserveAspectRatio() override;
virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio()
override;
virtual StringAttributesInfo GetStringInfo() override;
// Override for nsImageLoadingContent.

View File

@@ -279,7 +279,8 @@ SVGElement::LengthAttributesInfo SVGImageElement::GetLengthInfo() {
ArrayLength(sLengthInfo));
}
SVGAnimatedPreserveAspectRatio* SVGImageElement::GetPreserveAspectRatio() {
SVGAnimatedPreserveAspectRatio*
SVGImageElement::GetAnimatedPreserveAspectRatio() {
return &mPreserveAspectRatio;
}

View File

@@ -99,7 +99,8 @@ class SVGImageElement : public SVGImageElementBase,
nsresult LoadSVGImage(bool aForce, bool aNotify);
virtual LengthAttributesInfo GetLengthInfo() override;
virtual SVGAnimatedPreserveAspectRatio* GetPreserveAspectRatio() override;
virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio()
override;
virtual StringAttributesInfo GetStringInfo() override;
// Override for nsImageLoadingContent.

View File

@@ -165,11 +165,12 @@ SVGElement::EnumAttributesInfo SVGMarkerElement::GetEnumInfo() {
return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
}
SVGAnimatedOrient* SVGMarkerElement::GetOrient() { return &mOrient; }
SVGAnimatedOrient* SVGMarkerElement::GetAnimatedOrient() { return &mOrient; }
SVGAnimatedViewBox* SVGMarkerElement::GetViewBox() { return &mViewBox; }
SVGAnimatedViewBox* SVGMarkerElement::GetAnimatedViewBox() { return &mViewBox; }
SVGAnimatedPreserveAspectRatio* SVGMarkerElement::GetPreserveAspectRatio() {
SVGAnimatedPreserveAspectRatio*
SVGMarkerElement::GetAnimatedPreserveAspectRatio() {
return &mPreserveAspectRatio;
}
@@ -200,12 +201,12 @@ gfx::Matrix SVGMarkerElement::GetMarkerTransform(float aStrokeWidth,
-sin(angle) * scale, cos(angle) * scale, aMark.x, aMark.y);
}
SVGViewBoxRect SVGMarkerElement::GetViewBoxRect() {
SVGViewBox SVGMarkerElement::GetViewBox() {
if (mViewBox.HasRect()) {
return mViewBox.GetAnimValue();
}
return SVGViewBoxRect(
0, 0, mLengthAttributes[MARKERWIDTH].GetAnimValue(mCoordCtx),
return SVGViewBox(0, 0,
mLengthAttributes[MARKERWIDTH].GetAnimValue(mCoordCtx),
mLengthAttributes[MARKERHEIGHT].GetAnimValue(mCoordCtx));
}
@@ -216,7 +217,7 @@ gfx::Matrix SVGMarkerElement::GetViewBoxTransform() {
float viewportHeight =
mLengthAttributes[MARKERHEIGHT].GetAnimValue(mCoordCtx);
SVGViewBoxRect viewbox = GetViewBoxRect();
SVGViewBox viewbox = GetViewBox();
MOZ_ASSERT(viewbox.width > 0.0f && viewbox.height > 0.0f,
"Rendering should be disabled");

View File

@@ -56,7 +56,7 @@ class SVGMarkerElement : public SVGMarkerElementBase {
// public helpers
gfx::Matrix GetMarkerTransform(float aStrokeWidth, const SVGMark& aMark);
SVGViewBoxRect GetViewBoxRect();
SVGViewBox GetViewBox();
gfx::Matrix GetViewBoxTransform();
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
@@ -79,9 +79,10 @@ class SVGMarkerElement : public SVGMarkerElementBase {
virtual LengthAttributesInfo GetLengthInfo() override;
virtual EnumAttributesInfo GetEnumInfo() override;
virtual SVGAnimatedOrient* GetOrient() override;
virtual SVGAnimatedPreserveAspectRatio* GetPreserveAspectRatio() override;
virtual SVGAnimatedViewBox* GetViewBox() override;
virtual SVGAnimatedOrient* GetAnimatedOrient() override;
virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio()
override;
virtual SVGAnimatedViewBox* GetAnimatedViewBox() override;
enum { REFX, REFY, MARKERWIDTH, MARKERHEIGHT };
SVGAnimatedLength mLengthAttributes[4];

View File

@@ -162,9 +162,12 @@ SVGElement::EnumAttributesInfo SVGPatternElement::GetEnumInfo() {
return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
}
SVGAnimatedViewBox* SVGPatternElement::GetViewBox() { return &mViewBox; }
SVGAnimatedViewBox* SVGPatternElement::GetAnimatedViewBox() {
return &mViewBox;
}
SVGAnimatedPreserveAspectRatio* SVGPatternElement::GetPreserveAspectRatio() {
SVGAnimatedPreserveAspectRatio*
SVGPatternElement::GetAnimatedPreserveAspectRatio() {
return &mPreserveAspectRatio;
}

View File

@@ -73,8 +73,9 @@ class SVGPatternElement final : public SVGPatternElementBase {
virtual LengthAttributesInfo GetLengthInfo() override;
virtual EnumAttributesInfo GetEnumInfo() override;
virtual StringAttributesInfo GetStringInfo() override;
virtual SVGAnimatedPreserveAspectRatio* GetPreserveAspectRatio() override;
virtual SVGAnimatedViewBox* GetViewBox() override;
virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio()
override;
virtual SVGAnimatedViewBox* GetAnimatedViewBox() override;
enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
SVGAnimatedLength mLengthAttributes[4];

View File

@@ -524,15 +524,15 @@ void SVGSVGElement::SetImageOverridePreserveAspectRatio(
MOZ_ASSERT(OwnerDoc()->IsBeingUsedAsImage(),
"should only override preserveAspectRatio in images");
bool hasViewBoxRect = HasViewBoxRect();
if (!hasViewBoxRect && ShouldSynthesizeViewBox()) {
bool hasViewBox = HasViewBox();
if (!hasViewBox && ShouldSynthesizeViewBox()) {
// My non-<svg:image> clients will have been painting me with a synthesized
// viewBox, but my <svg:image> client that's about to paint me now does NOT
// want that. Need to tell ourselves to flush our transform.
mImageNeedsTransformInvalidation = true;
}
if (!hasViewBoxRect) {
if (!hasViewBox) {
return; // preserveAspectRatio irrelevant (only matters if we have viewBox)
}
@@ -545,7 +545,7 @@ void SVGSVGElement::ClearImageOverridePreserveAspectRatio() {
MOZ_ASSERT(OwnerDoc()->IsBeingUsedAsImage(),
"should only override image preserveAspectRatio in images");
if (!HasViewBoxRect() && ShouldSynthesizeViewBox()) {
if (!HasViewBox() && ShouldSynthesizeViewBox()) {
// My non-<svg:image> clients will want to paint me with a synthesized
// viewBox, but my <svg:image> client that just painted me did NOT
// use that. Need to tell ourselves to flush our transform.
@@ -603,9 +603,9 @@ SVGPreserveAspectRatio SVGSVGElement::GetPreserveAspectRatioWithOverride()
SVGViewElement* viewElement = GetCurrentViewElement();
// This check is equivalent to "!HasViewBoxRect() &&
// This check is equivalent to "!HasViewBox() &&
// ShouldSynthesizeViewBox()". We're just holding onto the viewElement that
// HasViewBoxRect() would look up, so that we don't have to look it up again
// HasViewBox() would look up, so that we don't have to look it up again
// later.
if (!((viewElement && viewElement->mViewBox.HasRect()) ||
(mSVGView && mSVGView->mViewBox.HasRect()) || mViewBox.HasRect()) &&

View File

@@ -19,13 +19,13 @@ SVGViewBoxSMILType SVGViewBoxSMILType::sSingleton;
void SVGViewBoxSMILType::Init(SMILValue& aValue) const {
MOZ_ASSERT(aValue.IsNull(), "Unexpected value type");
aValue.mU.mPtr = new SVGViewBoxRect();
aValue.mU.mPtr = new SVGViewBox();
aValue.mType = this;
}
void SVGViewBoxSMILType::Destroy(SMILValue& aValue) const {
MOZ_ASSERT(aValue.mType == this, "Unexpected SMIL value");
delete static_cast<SVGViewBoxRect*>(aValue.mU.mPtr);
delete static_cast<SVGViewBox*>(aValue.mU.mPtr);
aValue.mU.mPtr = nullptr;
aValue.mType = SMILNullType::Singleton();
}
@@ -35,8 +35,8 @@ nsresult SVGViewBoxSMILType::Assign(SMILValue& aDest,
MOZ_ASSERT(aDest.mType == aSrc.mType, "Incompatible SMIL types");
MOZ_ASSERT(aDest.mType == this, "Unexpected SMIL value");
const SVGViewBoxRect* src = static_cast<const SVGViewBoxRect*>(aSrc.mU.mPtr);
SVGViewBoxRect* dst = static_cast<SVGViewBoxRect*>(aDest.mU.mPtr);
const SVGViewBox* src = static_cast<const SVGViewBox*>(aSrc.mU.mPtr);
SVGViewBox* dst = static_cast<SVGViewBox*>(aDest.mU.mPtr);
*dst = *src;
return NS_OK;
}
@@ -46,9 +46,8 @@ bool SVGViewBoxSMILType::IsEqual(const SMILValue& aLeft,
MOZ_ASSERT(aLeft.mType == aRight.mType, "Incompatible SMIL types");
MOZ_ASSERT(aLeft.mType == this, "Unexpected type for SMIL value");
const SVGViewBoxRect* leftBox =
static_cast<const SVGViewBoxRect*>(aLeft.mU.mPtr);
const SVGViewBoxRect* rightBox = static_cast<SVGViewBoxRect*>(aRight.mU.mPtr);
const SVGViewBox* leftBox = static_cast<const SVGViewBox*>(aLeft.mU.mPtr);
const SVGViewBox* rightBox = static_cast<SVGViewBox*>(aRight.mU.mPtr);
return *leftBox == *rightBox;
}
@@ -70,9 +69,8 @@ nsresult SVGViewBoxSMILType::ComputeDistance(const SMILValue& aFrom,
MOZ_ASSERT(aFrom.mType == aTo.mType, "Trying to compare different types");
MOZ_ASSERT(aFrom.mType == this, "Unexpected source type");
const SVGViewBoxRect* from =
static_cast<const SVGViewBoxRect*>(aFrom.mU.mPtr);
const SVGViewBoxRect* to = static_cast<const SVGViewBoxRect*>(aTo.mU.mPtr);
const SVGViewBox* from = static_cast<const SVGViewBox*>(aFrom.mU.mPtr);
const SVGViewBox* to = static_cast<const SVGViewBox*>(aTo.mU.mPtr);
if (from->none || to->none) {
return NS_ERROR_FAILURE;
@@ -104,16 +102,14 @@ nsresult SVGViewBoxSMILType::Interpolate(const SMILValue& aStartVal,
MOZ_ASSERT(aStartVal.mType == this, "Unexpected types for interpolation");
MOZ_ASSERT(aResult.mType == this, "Unexpected result type");
const SVGViewBoxRect* start =
static_cast<const SVGViewBoxRect*>(aStartVal.mU.mPtr);
const SVGViewBoxRect* end =
static_cast<const SVGViewBoxRect*>(aEndVal.mU.mPtr);
const SVGViewBox* start = static_cast<const SVGViewBox*>(aStartVal.mU.mPtr);
const SVGViewBox* end = static_cast<const SVGViewBox*>(aEndVal.mU.mPtr);
if (start->none || end->none) {
return NS_ERROR_FAILURE;
}
SVGViewBoxRect* current = static_cast<SVGViewBoxRect*>(aResult.mU.mPtr);
SVGViewBox* current = static_cast<SVGViewBox*>(aResult.mU.mPtr);
float x = (start->x + (end->x - start->x) * aUnitDistance);
float y = (start->y + (end->y - start->y) * aUnitDistance);
@@ -121,7 +117,7 @@ nsresult SVGViewBoxSMILType::Interpolate(const SMILValue& aStartVal,
float height =
(start->height + (end->height - start->height) * aUnitDistance);
*current = SVGViewBoxRect(x, y, width, height);
*current = SVGViewBox(x, y, width, height);
return NS_OK;
}

View File

@@ -67,9 +67,10 @@ SVGElement::EnumAttributesInfo SVGViewElement::GetEnumInfo() {
return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
}
SVGAnimatedViewBox* SVGViewElement::GetViewBox() { return &mViewBox; }
SVGAnimatedViewBox* SVGViewElement::GetAnimatedViewBox() { return &mViewBox; }
SVGAnimatedPreserveAspectRatio* SVGViewElement::GetPreserveAspectRatio() {
SVGAnimatedPreserveAspectRatio*
SVGViewElement::GetAnimatedPreserveAspectRatio() {
return &mPreserveAspectRatio;
}

View File

@@ -58,8 +58,9 @@ class SVGViewElement : public SVGViewElementBase {
static SVGEnumMapping sZoomAndPanMap[];
static EnumInfo sEnumInfo[1];
virtual SVGAnimatedViewBox* GetViewBox() override;
virtual SVGAnimatedPreserveAspectRatio* GetPreserveAspectRatio() override;
virtual SVGAnimatedViewBox* GetAnimatedViewBox() override;
virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio()
override;
SVGAnimatedViewBox mViewBox;
SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;

View File

@@ -185,8 +185,7 @@ gfx::Matrix SVGViewportElement::GetViewBoxTransform() const {
return gfx::Matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
}
SVGViewBoxRect viewBox =
GetViewBoxWithSynthesis(viewportWidth, viewportHeight);
SVGViewBox viewBox = GetViewBoxWithSynthesis(viewportWidth, viewportHeight);
if (viewBox.width <= 0.0f || viewBox.height <= 0.0f) {
return gfx::Matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
@@ -200,7 +199,7 @@ gfx::Matrix SVGViewportElement::GetViewBoxTransform() const {
// SVGViewportElement
float SVGViewportElement::GetLength(uint8_t aCtxType) {
const SVGViewBoxRect* viewbox = GetViewBoxInternal().HasRect()
const SVGViewBox* viewbox = GetViewBoxInternal().HasRect()
? &GetViewBoxInternal().GetAnimValue()
: nullptr;
@@ -310,14 +309,17 @@ bool SVGViewportElement::HasValidDimensions() const {
mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0));
}
SVGAnimatedViewBox* SVGViewportElement::GetViewBox() { return &mViewBox; }
SVGAnimatedViewBox* SVGViewportElement::GetAnimatedViewBox() {
return &mViewBox;
}
SVGAnimatedPreserveAspectRatio* SVGViewportElement::GetPreserveAspectRatio() {
SVGAnimatedPreserveAspectRatio*
SVGViewportElement::GetAnimatedPreserveAspectRatio() {
return &mPreserveAspectRatio;
}
bool SVGViewportElement::ShouldSynthesizeViewBox() const {
MOZ_ASSERT(!HasViewBoxRect(), "Should only be called if we lack a viewBox");
MOZ_ASSERT(!HasViewBox(), "Should only be called if we lack a viewBox");
return IsRoot() && OwnerDoc()->IsBeingUsedAsImage();
}
@@ -325,7 +327,7 @@ bool SVGViewportElement::ShouldSynthesizeViewBox() const {
//----------------------------------------------------------------------
// implementation helpers
SVGViewBoxRect SVGViewportElement::GetViewBoxWithSynthesis(
SVGViewBox SVGViewportElement::GetViewBoxWithSynthesis(
float aViewportWidth, float aViewportHeight) const {
if (GetViewBoxInternal().HasRect()) {
return GetViewBoxInternal().GetAnimValue();
@@ -334,7 +336,7 @@ SVGViewBoxRect SVGViewportElement::GetViewBoxWithSynthesis(
if (ShouldSynthesizeViewBox()) {
// Special case -- fake a viewBox, using height & width attrs.
// (Use |this| as context, since if we get here, we're outermost <svg>.)
return SVGViewBoxRect(
return SVGViewBox(
0, 0,
ComputeSynthesizedViewBoxDimension(mLengthAttributes[ATTR_WIDTH],
mViewportWidth, this),
@@ -344,7 +346,7 @@ SVGViewBoxRect SVGViewportElement::GetViewBoxWithSynthesis(
// No viewBox attribute, so we shouldn't auto-scale. This is equivalent
// to having a viewBox that exactly matches our viewport size.
return SVGViewBoxRect(0, 0, aViewportWidth, aViewportHeight);
return SVGViewBox(0, 0, aViewportWidth, aViewportHeight);
}
SVGElement::LengthAttributesInfo SVGViewportElement::GetLengthInfo() {

View File

@@ -79,19 +79,19 @@ class SVGViewportElement : public SVGGraphicsElement {
* Note also that this method does not pay attention to whether the width or
* height values of the viewBox rect are positive!
*/
bool HasViewBoxRect() const { return GetViewBoxInternal().HasRect(); }
bool HasViewBox() const { return GetViewBoxInternal().HasRect(); }
/**
* Returns true if we should synthesize a viewBox for ourselves (that is, if
* we're the root element in an image document, and we're not currently being
* painted for an <svg:image> element).
*
* Only call this method if HasViewBoxRect() returns false.
* Only call this method if HasViewBox() returns false.
*/
bool ShouldSynthesizeViewBox() const;
bool HasViewBoxOrSyntheticViewBox() const {
return HasViewBoxRect() || ShouldSynthesizeViewBox();
return HasViewBox() || ShouldSynthesizeViewBox();
}
bool HasChildrenOnlyTransform() const { return mHasChildrenOnlyTransform; }
@@ -126,7 +126,7 @@ class SVGViewportElement : public SVGGraphicsElement {
// WebIDL
already_AddRefed<SVGAnimatedRect> ViewBox();
already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
virtual SVGAnimatedViewBox* GetViewBox() override;
virtual SVGAnimatedViewBox* GetAnimatedViewBox() override;
protected:
// implementation helpers:
@@ -162,7 +162,7 @@ class SVGViewportElement : public SVGGraphicsElement {
* viewBox, if appropriate, or else a viewBox matching the dimensions of the
* SVG viewport.
*/
SVGViewBoxRect GetViewBoxWithSynthesis(float aViewportWidth,
SVGViewBox GetViewBoxWithSynthesis(float aViewportWidth,
float aViewportHeight) const;
/**
@@ -176,7 +176,8 @@ class SVGViewportElement : public SVGGraphicsElement {
static LengthInfo sLengthInfo[4];
virtual LengthAttributesInfo GetLengthInfo() override;
virtual SVGAnimatedPreserveAspectRatio* GetPreserveAspectRatio() override;
virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio()
override;
virtual const SVGAnimatedViewBox& GetViewBoxInternal() const {
return mViewBox;

View File

@@ -9589,14 +9589,15 @@ static nsRect ComputeSVGReferenceRect(nsIFrame* aFrame,
SVGViewportElement* svgElement = element->GetCtx();
MOZ_ASSERT(svgElement);
if (svgElement && svgElement->HasViewBoxRect()) {
if (svgElement && svgElement->HasViewBox()) {
// If a `viewBox` attribute is specified for the SVG viewport creating
// element:
// 1. The reference box is positioned at the origin of the coordinate
// system established by the `viewBox` attribute.
// 2. The dimension of the reference box is set to the width and height
// values of the `viewBox` attribute.
const SVGViewBoxRect& value = svgElement->GetViewBox()->GetAnimValue();
const SVGViewBox& value =
svgElement->GetAnimatedViewBox()->GetAnimValue();
r = nsRect(nsPresContext::CSSPixelsToAppUnits(value.x),
nsPresContext::CSSPixelsToAppUnits(value.y),
nsPresContext::CSSPixelsToAppUnits(value.width),

View File

@@ -105,7 +105,7 @@ void nsSVGMarkerFrame::PaintMark(gfxContext& aContext,
return;
}
const SVGViewBoxRect viewBox = marker->GetViewBoxRect();
const SVGViewBox viewBox = marker->GetViewBox();
if (viewBox.width <= 0.0f || viewBox.height <= 0.0f) {
// We must disable rendering if the viewBox width or height are zero.
@@ -154,7 +154,7 @@ SVGBBox nsSVGMarkerFrame::GetMarkBBoxContribution(
return bbox;
}
const SVGViewBoxRect viewBox = content->GetViewBoxRect();
const SVGViewBox viewBox = content->GetViewBox();
if (viewBox.width <= 0.0f || viewBox.height <= 0.0f) {
return bbox;

View File

@@ -257,7 +257,7 @@ nsSize nsSVGOuterSVGFrame::GetIntrinsicRatio() {
}
SVGViewElement* viewElement = content->GetCurrentViewElement();
const SVGViewBoxRect* viewbox = nullptr;
const SVGViewBox* viewbox = nullptr;
// The logic here should match HasViewBox().
if (viewElement && viewElement->mViewBox.HasRect()) {
@@ -781,7 +781,7 @@ void nsSVGOuterSVGFrame::NotifyViewportOrTransformChanged(uint32_t aFlags) {
SVGSVGElement* content = static_cast<SVGSVGElement*>(GetContent());
if (aFlags & COORD_CONTEXT_CHANGED) {
if (content->HasViewBoxRect()) {
if (content->HasViewBox()) {
// Percentage lengths on children resolve against the viewBox rect so we
// don't need to notify them of the viewport change, but the viewBox
// transform will have changed, so we need to notify them of that instead.

View File

@@ -636,9 +636,9 @@ gfxMatrix nsSVGPatternFrame::ConstructCTM(const SVGAnimatedViewBox &aViewBox,
if (!aViewBox.IsExplicitlySet()) {
return gfxMatrix(scaleX, 0.0, 0.0, scaleY, 0.0, 0.0);
}
const SVGViewBoxRect viewBoxRect = aViewBox.GetAnimValue();
const SVGViewBox viewBox = aViewBox.GetAnimValue();
if (viewBoxRect.height <= 0.0f || viewBoxRect.width <= 0.0f) {
if (viewBox.height <= 0.0f || viewBox.width <= 0.0f) {
return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
}
@@ -664,9 +664,8 @@ gfxMatrix nsSVGPatternFrame::ConstructCTM(const SVGAnimatedViewBox &aViewBox,
}
Matrix tm = SVGContentUtils::GetViewBoxTransform(
viewportWidth * scaleX, viewportHeight * scaleY, viewBoxRect.x,
viewBoxRect.y, viewBoxRect.width, viewBoxRect.height,
GetPreserveAspectRatio());
viewportWidth * scaleX, viewportHeight * scaleY, viewBox.x, viewBox.y,
viewBox.width, viewBox.height, GetPreserveAspectRatio());
return ThebesMatrix(tm);
}

View File

@@ -102,11 +102,11 @@ void nsSVGViewportFrame::NotifySVGChanged(uint32_t aFlags) {
if (!(aFlags & TRANSFORM_CHANGED) &&
(xOrYIsPercentage ||
(widthOrHeightIsPercentage && svg->HasViewBoxRect()))) {
(widthOrHeightIsPercentage && svg->HasViewBox()))) {
aFlags |= TRANSFORM_CHANGED;
}
if (svg->HasViewBoxRect() || !widthOrHeightIsPercentage) {
if (svg->HasViewBox() || !widthOrHeightIsPercentage) {
// Remove COORD_CONTEXT_CHANGED, since we establish the coordinate
// context for our descendants and this notification won't change its
// dimensions: