Skip to content

Commit

Permalink
Bug 1551030 - Merge all SVGRect classes r=dholbert
Browse files Browse the repository at this point in the history
  • Loading branch information
longsonr committed Jun 20, 2019
1 parent 8ea522b commit 160c161
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 295 deletions.
4 changes: 0 additions & 4 deletions dom/bindings/Bindings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1005,10 +1005,6 @@ DOMInterfaces = {
'headerFile': 'mozilla/dom/SVGGradientElement.h',
},

'SVGRect': {
'nativeType': 'mozilla::dom::SVGIRect'
},

'SVGStringList': {
'nativeType': 'mozilla::DOMSVGStringList',
'headerFile': 'DOMSVGStringList.h',
Expand Down
6 changes: 3 additions & 3 deletions dom/svg/SVGAnimatedRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "SVGAnimatedRect.h"
#include "mozilla/dom/SVGAnimatedRectBinding.h"
#include "mozilla/dom/SVGElement.h"
#include "mozilla/dom/SVGRect.h"
#include "SVGAnimatedViewBox.h"
#include "SVGIRect.h"

namespace mozilla {
namespace dom {
Expand All @@ -26,11 +26,11 @@ SVGAnimatedRect::~SVGAnimatedRect() {
SVGAnimatedViewBox::sSVGAnimatedRectTearoffTable.RemoveTearoff(mVal);
}

already_AddRefed<SVGIRect> SVGAnimatedRect::GetBaseVal() {
already_AddRefed<SVGRect> SVGAnimatedRect::GetBaseVal() {
return mVal->ToDOMBaseVal(mSVGElement);
}

already_AddRefed<SVGIRect> SVGAnimatedRect::GetAnimVal() {
already_AddRefed<SVGRect> SVGAnimatedRect::GetAnimVal() {
return mVal->ToDOMAnimVal(mSVGElement);
}

Expand Down
12 changes: 9 additions & 3 deletions dom/svg/SVGAnimatedRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@

#include "nsCycleCollectionParticipant.h"
#include "mozilla/dom/SVGElement.h"
#include "mozilla/dom/SVGRectBinding.h"
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "nsWrapperCache.h"

namespace mozilla {

class SVGAnimatedViewBox;

namespace dom {

class SVGRect;

// Despite the name of this class appearing to be generic,
// SVGAnimatedRect is only used for viewBox attributes.

class SVGAnimatedRect final : public nsWrapperCache {
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(SVGAnimatedRect)
Expand All @@ -30,9 +36,9 @@ class SVGAnimatedRect final : public nsWrapperCache {
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;

already_AddRefed<SVGIRect> GetBaseVal();
already_AddRefed<SVGRect> GetBaseVal();

already_AddRefed<SVGIRect> GetAnimVal();
already_AddRefed<SVGRect> GetAnimVal();

private:
virtual ~SVGAnimatedRect();
Expand Down
77 changes: 15 additions & 62 deletions dom/svg/SVGAnimatedViewBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mozilla/Move.h"
#include "mozilla/SMILValue.h"
#include "mozilla/SVGContentUtils.h"
#include "mozilla/dom/SVGRect.h"
#include "nsCharSeparatedTokenizer.h"
#include "SVGViewBoxSMILType.h"
#include "nsTextFormatter.h"
Expand Down Expand Up @@ -61,32 +62,9 @@ nsresult SVGViewBox::FromString(const nsAString& aStr, SVGViewBox* aViewBox) {
return NS_OK;
}

/* Cycle collection macros for SVGAnimatedViewBox */

NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(SVGAnimatedViewBox::DOMBaseVal,
mSVGElement)
NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(SVGAnimatedViewBox::DOMAnimVal,
mSVGElement)

NS_IMPL_CYCLE_COLLECTING_ADDREF(SVGAnimatedViewBox::DOMBaseVal)
NS_IMPL_CYCLE_COLLECTING_RELEASE(SVGAnimatedViewBox::DOMBaseVal)

NS_IMPL_CYCLE_COLLECTING_ADDREF(SVGAnimatedViewBox::DOMAnimVal)
NS_IMPL_CYCLE_COLLECTING_RELEASE(SVGAnimatedViewBox::DOMAnimVal)

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGAnimatedViewBox::DOMBaseVal)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGAnimatedViewBox::DOMAnimVal)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END

static SVGAttrTearoffTable<SVGAnimatedViewBox, SVGAnimatedViewBox::DOMBaseVal>
static SVGAttrTearoffTable<SVGAnimatedViewBox, SVGRect>
sBaseSVGViewBoxTearoffTable;
static SVGAttrTearoffTable<SVGAnimatedViewBox, SVGAnimatedViewBox::DOMAnimVal>
static SVGAttrTearoffTable<SVGAnimatedViewBox, SVGRect>
sAnimSVGViewBoxTearoffTable;
SVGAttrTearoffTable<SVGAnimatedViewBox, SVGAnimatedRect>
SVGAnimatedViewBox::sSVGAnimatedRectTearoffTable;
Expand Down Expand Up @@ -206,70 +184,45 @@ already_AddRefed<SVGAnimatedRect> SVGAnimatedViewBox::ToSVGAnimatedRect(
return domAnimatedRect.forget();
}

already_AddRefed<SVGIRect> SVGAnimatedViewBox::ToDOMBaseVal(
already_AddRefed<SVGRect> SVGAnimatedViewBox::ToDOMBaseVal(
SVGElement* aSVGElement) {
if (!mHasBaseVal || mBaseVal.none) {
return nullptr;
}

RefPtr<DOMBaseVal> domBaseVal = sBaseSVGViewBoxTearoffTable.GetTearoff(this);
RefPtr<SVGRect> domBaseVal = sBaseSVGViewBoxTearoffTable.GetTearoff(this);
if (!domBaseVal) {
domBaseVal = new DOMBaseVal(this, aSVGElement);
domBaseVal = new SVGRect(this, aSVGElement, SVGRect::BaseValue);
sBaseSVGViewBoxTearoffTable.AddTearoff(this, domBaseVal);
}

return domBaseVal.forget();
}

SVGAnimatedViewBox::DOMBaseVal::~DOMBaseVal() {
sBaseSVGViewBoxTearoffTable.RemoveTearoff(mVal);
SVGRect::~SVGRect() {
if (mType == BaseValue) {
sBaseSVGViewBoxTearoffTable.RemoveTearoff(mVal);
} else if (mType == AnimValue) {
sAnimSVGViewBoxTearoffTable.RemoveTearoff(mVal);
}
}

already_AddRefed<SVGIRect> SVGAnimatedViewBox::ToDOMAnimVal(
already_AddRefed<SVGRect> SVGAnimatedViewBox::ToDOMAnimVal(
SVGElement* aSVGElement) {
if ((mAnimVal && mAnimVal->none) ||
(!mAnimVal && (!mHasBaseVal || mBaseVal.none))) {
return nullptr;
}

RefPtr<DOMAnimVal> domAnimVal = sAnimSVGViewBoxTearoffTable.GetTearoff(this);
RefPtr<SVGRect> domAnimVal = sAnimSVGViewBoxTearoffTable.GetTearoff(this);
if (!domAnimVal) {
domAnimVal = new DOMAnimVal(this, aSVGElement);
domAnimVal = new SVGRect(this, aSVGElement, SVGRect::AnimValue);
sAnimSVGViewBoxTearoffTable.AddTearoff(this, domAnimVal);
}

return domAnimVal.forget();
}

SVGAnimatedViewBox::DOMAnimVal::~DOMAnimVal() {
sAnimSVGViewBoxTearoffTable.RemoveTearoff(mVal);
}

void SVGAnimatedViewBox::DOMBaseVal::SetX(float aX, ErrorResult& aRv) {
SVGViewBox rect = mVal->GetBaseValue();
rect.x = aX;
mVal->SetBaseValue(rect, mSVGElement);
}

void SVGAnimatedViewBox::DOMBaseVal::SetY(float aY, ErrorResult& aRv) {
SVGViewBox rect = mVal->GetBaseValue();
rect.y = aY;
mVal->SetBaseValue(rect, mSVGElement);
}

void SVGAnimatedViewBox::DOMBaseVal::SetWidth(float aWidth, ErrorResult& aRv) {
SVGViewBox rect = mVal->GetBaseValue();
rect.width = aWidth;
mVal->SetBaseValue(rect, mSVGElement);
}

void SVGAnimatedViewBox::DOMBaseVal::SetHeight(float aHeight,
ErrorResult& aRv) {
SVGViewBox rect = mVal->GetBaseValue();
rect.height = aHeight;
mVal->SetBaseValue(rect, mSVGElement);
}

UniquePtr<SMILAttr> SVGAnimatedViewBox::ToSMILAttr(SVGElement* aSVGElement) {
return MakeUnique<SMILViewBox>(this, aSVGElement);
}
Expand Down
91 changes: 3 additions & 88 deletions dom/svg/SVGAnimatedViewBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
#include "mozilla/SMILAttr.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/SVGAnimatedRect.h"
#include "mozilla/dom/SVGIRect.h"

namespace mozilla {

class SMILValue;

namespace dom {
class SVGRect;
class SVGAnimationElement;
class SVGElement;
} // namespace dom
Expand Down Expand Up @@ -80,11 +80,9 @@ class SVGAnimatedViewBox {
already_AddRefed<mozilla::dom::SVGAnimatedRect> ToSVGAnimatedRect(
SVGElement* aSVGElement);

already_AddRefed<mozilla::dom::SVGIRect> ToDOMBaseVal(
SVGElement* aSVGElement);
already_AddRefed<dom::SVGRect> ToDOMBaseVal(SVGElement* aSVGElement);

already_AddRefed<mozilla::dom::SVGIRect> ToDOMAnimVal(
SVGElement* aSVGElement);
already_AddRefed<dom::SVGRect> ToDOMAnimVal(SVGElement* aSVGElement);

mozilla::UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement);

Expand All @@ -94,89 +92,6 @@ class SVGAnimatedViewBox {
bool mHasBaseVal;

public:
struct DOMBaseVal final : public mozilla::dom::SVGIRect {
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMBaseVal)

DOMBaseVal(SVGAnimatedViewBox* aVal, SVGElement* aSVGElement)
: mozilla::dom::SVGIRect(), mVal(aVal), mSVGElement(aSVGElement) {}

SVGAnimatedViewBox* mVal; // kept alive because it belongs to content
RefPtr<SVGElement> mSVGElement;

float X() const final { return mVal->GetBaseValue().x; }

float Y() const final { return mVal->GetBaseValue().y; }

float Width() const final { return mVal->GetBaseValue().width; }

float Height() const final { return mVal->GetBaseValue().height; }

void SetX(float aX, mozilla::ErrorResult& aRv) final;
void SetY(float aY, mozilla::ErrorResult& aRv) final;
void SetWidth(float aWidth, mozilla::ErrorResult& aRv) final;
void SetHeight(float aHeight, mozilla::ErrorResult& aRv) final;

virtual nsIContent* GetParentObject() const override { return mSVGElement; }

private:
virtual ~DOMBaseVal();
};

struct DOMAnimVal final : public mozilla::dom::SVGIRect {
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMAnimVal)

DOMAnimVal(SVGAnimatedViewBox* aVal, SVGElement* aSVGElement)
: mozilla::dom::SVGIRect(), mVal(aVal), mSVGElement(aSVGElement) {}

SVGAnimatedViewBox* mVal; // kept alive because it belongs to content
RefPtr<SVGElement> mSVGElement;

// Script may have modified animation parameters or timeline -- DOM getters
// need to flush any resample requests to reflect these modifications.
float X() const final {
mSVGElement->FlushAnimations();
return mVal->GetAnimValue().x;
}

float Y() const final {
mSVGElement->FlushAnimations();
return mVal->GetAnimValue().y;
}

float Width() const final {
mSVGElement->FlushAnimations();
return mVal->GetAnimValue().width;
}

float Height() const final {
mSVGElement->FlushAnimations();
return mVal->GetAnimValue().height;
}

void SetX(float aX, mozilla::ErrorResult& aRv) final {
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
}

void SetY(float aY, mozilla::ErrorResult& aRv) final {
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
}

void SetWidth(float aWidth, mozilla::ErrorResult& aRv) final {
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
}

void SetHeight(float aHeight, mozilla::ErrorResult& aRv) final {
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
}

virtual nsIContent* GetParentObject() const override { return mSVGElement; }

private:
virtual ~DOMAnimVal();
};

struct SMILViewBox : public SMILAttr {
public:
SMILViewBox(SVGAnimatedViewBox* aVal, SVGElement* aSVGElement)
Expand Down
52 changes: 0 additions & 52 deletions dom/svg/SVGIRect.h

This file was deleted.

Loading

0 comments on commit 160c161

Please sign in to comment.