Bug 816778 Part 6: Convert SVGAnimatedPreserveAspectRatio to WebIDL r=bz

This commit is contained in:
David Zbarsky 2012-12-22 23:54:20 -05:00
parent 2e312948f9
commit a7787e2a78
6 changed files with 106 additions and 59 deletions

View File

@ -11,6 +11,7 @@
#include "nsSVGAttrTearoffTable.h"
#include "SMILEnumType.h"
#include "nsAttrValueInlines.h"
#include "mozilla/dom/SVGAnimatedPreserveAspectRatioBinding.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -18,24 +19,40 @@ using namespace mozilla::dom;
////////////////////////////////////////////////////////////////////////
// SVGAnimatedPreserveAspectRatio class
NS_SVG_VAL_IMPL_CYCLE_COLLECTION(
SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio, mSVGElement)
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGAnimatedPreserveAspectRatio)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGAnimatedPreserveAspectRatio)
// No unlinking mElement, we'd need to null out the value pointer (the object it
// points to is held by the element) and null-check it everywhere.
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(
SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio)
NS_IMPL_CYCLE_COLLECTING_RELEASE(
SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGAnimatedPreserveAspectRatio)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSVGElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
DOMCI_DATA(SVGAnimatedPreserveAspectRatio,
SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMSVGAnimatedPreserveAspectRatio)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio)
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGAnimatedPreserveAspectRatio)
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGAnimatedPreserveAspectRatio)
DOMCI_DATA(SVGAnimatedPreserveAspectRatio, DOMSVGAnimatedPreserveAspectRatio)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGAnimatedPreserveAspectRatio)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedPreserveAspectRatio)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedPreserveAspectRatio)
NS_INTERFACE_MAP_END
JSObject*
DOMSVGAnimatedPreserveAspectRatio::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
{
return SVGAnimatedPreserveAspectRatioBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
/* Implementation */
static const char *sAlignStrings[] =
@ -44,7 +61,7 @@ static const char *sAlignStrings[] =
static const char *sMeetOrSliceStrings[] = { "meet", "slice" };
static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio>
static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, DOMSVGAnimatedPreserveAspectRatio>
sSVGAnimatedPAspectRatioTearoffTable;
static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, DOMSVGPreserveAspectRatio>
sBaseSVGPAspectRatioTearoffTable;
@ -101,20 +118,17 @@ GetMeetOrSliceString(nsAString& aMeetOrSliceString, uint16_t aMeetOrSlice)
nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET]);
}
nsresult
SVGAnimatedPreserveAspectRatio::ToDOMBaseVal(
nsIDOMSVGPreserveAspectRatio **aResult,
nsSVGElement *aSVGElement)
already_AddRefed<DOMSVGPreserveAspectRatio>
DOMSVGAnimatedPreserveAspectRatio::BaseVal()
{
nsRefPtr<DOMSVGPreserveAspectRatio> domBaseVal =
sBaseSVGPAspectRatioTearoffTable.GetTearoff(this);
sBaseSVGPAspectRatioTearoffTable.GetTearoff(mVal);
if (!domBaseVal) {
domBaseVal = new DOMSVGPreserveAspectRatio(this, aSVGElement, true);
sBaseSVGPAspectRatioTearoffTable.AddTearoff(this, domBaseVal);
domBaseVal = new DOMSVGPreserveAspectRatio(mVal, mSVGElement, true);
sBaseSVGPAspectRatioTearoffTable.AddTearoff(mVal, domBaseVal);
}
domBaseVal.forget(aResult);
return NS_OK;
return domBaseVal.forget();
}
DOMSVGPreserveAspectRatio::~DOMSVGPreserveAspectRatio()
@ -126,20 +140,17 @@ DOMSVGPreserveAspectRatio::~DOMSVGPreserveAspectRatio()
}
}
nsresult
SVGAnimatedPreserveAspectRatio::ToDOMAnimVal(
nsIDOMSVGPreserveAspectRatio **aResult,
nsSVGElement *aSVGElement)
already_AddRefed<DOMSVGPreserveAspectRatio>
DOMSVGAnimatedPreserveAspectRatio::AnimVal()
{
nsRefPtr<DOMSVGPreserveAspectRatio> domAnimVal =
sAnimSVGPAspectRatioTearoffTable.GetTearoff(this);
sAnimSVGPAspectRatioTearoffTable.GetTearoff(mVal);
if (!domAnimVal) {
domAnimVal = new DOMSVGPreserveAspectRatio(this, aSVGElement, true);
sAnimSVGPAspectRatioTearoffTable.AddTearoff(this, domAnimVal);
domAnimVal = new DOMSVGPreserveAspectRatio(mVal, mSVGElement, false);
sAnimSVGPAspectRatioTearoffTable.AddTearoff(mVal, domAnimVal);
}
domAnimVal.forget(aResult);
return NS_OK;
return domAnimVal.forget();
}
static nsresult
@ -297,17 +308,17 @@ SVGAnimatedPreserveAspectRatio::ToDOMAnimatedPreserveAspectRatio(
nsIDOMSVGAnimatedPreserveAspectRatio **aResult,
nsSVGElement *aSVGElement)
{
nsRefPtr<DOMAnimPAspectRatio> domAnimatedPAspectRatio =
nsRefPtr<DOMSVGAnimatedPreserveAspectRatio> domAnimatedPAspectRatio =
sSVGAnimatedPAspectRatioTearoffTable.GetTearoff(this);
if (!domAnimatedPAspectRatio) {
domAnimatedPAspectRatio = new DOMAnimPAspectRatio(this, aSVGElement);
domAnimatedPAspectRatio = new DOMSVGAnimatedPreserveAspectRatio(this, aSVGElement);
sSVGAnimatedPAspectRatioTearoffTable.AddTearoff(this, domAnimatedPAspectRatio);
}
domAnimatedPAspectRatio.forget(aResult);
return NS_OK;
}
SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio::~DOMAnimPAspectRatio()
DOMSVGAnimatedPreserveAspectRatio::~DOMSVGAnimatedPreserveAspectRatio()
{
sSVGAnimatedPAspectRatioTearoffTable.RemoveTearoff(mVal);
}

View File

@ -84,34 +84,7 @@ private:
bool mIsAnimated;
bool mIsBaseSet;
nsresult ToDOMBaseVal(nsIDOMSVGPreserveAspectRatio **aResult,
nsSVGElement* aSVGElement);
nsresult ToDOMAnimVal(nsIDOMSVGPreserveAspectRatio **aResult,
nsSVGElement* aSVGElement);
public:
struct DOMAnimPAspectRatio MOZ_FINAL : public nsIDOMSVGAnimatedPreserveAspectRatio
{
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimPAspectRatio)
DOMAnimPAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
nsSVGElement *aSVGElement)
: mVal(aVal), mSVGElement(aSVGElement) {}
virtual ~DOMAnimPAspectRatio();
// kept alive because it belongs to content:
SVGAnimatedPreserveAspectRatio* mVal;
nsRefPtr<nsSVGElement> mSVGElement;
NS_IMETHOD GetBaseVal(nsIDOMSVGPreserveAspectRatio **aBaseVal)
{ return mVal->ToDOMBaseVal(aBaseVal, mSVGElement); }
NS_IMETHOD GetAnimVal(nsIDOMSVGPreserveAspectRatio **aAnimVal)
{ return mVal->ToDOMAnimVal(aAnimVal, mSVGElement); }
};
struct SMILPreserveAspectRatio MOZ_FINAL : public nsISMILAttr
{
public:
@ -136,6 +109,42 @@ public:
};
};
namespace dom {
class DOMSVGAnimatedPreserveAspectRatio MOZ_FINAL : public nsIDOMSVGAnimatedPreserveAspectRatio,
public nsWrapperCache
{
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGAnimatedPreserveAspectRatio)
DOMSVGAnimatedPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
nsSVGElement *aSVGElement)
: mVal(aVal), mSVGElement(aSVGElement)
{
SetIsDOMBinding();
}
~DOMSVGAnimatedPreserveAspectRatio();
NS_IMETHOD GetBaseVal(nsIDOMSVGPreserveAspectRatio **aBaseVal)
{ *aBaseVal = BaseVal().get(); return NS_OK; }
NS_IMETHOD GetAnimVal(nsIDOMSVGPreserveAspectRatio **aAnimVal)
{ *aAnimVal = AnimVal().get(); return NS_OK; }
// WebIDL
nsSVGElement* GetParentObject() const { return mSVGElement; }
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap);
// These aren't weak refs because new objects are returned each time
already_AddRefed<DOMSVGPreserveAspectRatio> BaseVal();
already_AddRefed<DOMSVGPreserveAspectRatio> AnimVal();
protected:
// kept alive because it belongs to content:
SVGAnimatedPreserveAspectRatio* mVal;
nsRefPtr<nsSVGElement> mSVGElement;
};
} // namespace dom
} // namespace mozilla
#endif // MOZILLA_SVGANIMATEDPRESERVEASPECTRATIO_H__

View File

@ -12,6 +12,8 @@ using namespace dom;
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGPreserveAspectRatio)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGPreserveAspectRatio)
// No unlinking mElement, we'd need to null out the value pointer (the object it
// points to is held by the element) and null-check it everywhere.
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

View File

@ -441,6 +441,11 @@ DOMInterfaces = {
'prefable': True,
},
'SVGAnimatedPreserveAspectRatio': {
'nativeType': 'mozilla::dom::DOMSVGAnimatedPreserveAspectRatio',
'headerFile': 'SVGAnimatedPreserveAspectRatio.h'
},
'SVGAnimatedTransformList': {
'nativeType': 'mozilla::DOMSVGAnimatedTransformList',
'headerFile': 'DOMSVGAnimatedTransformList.h'

View File

@ -0,0 +1,19 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://www.w3.org/TR/SVG2/
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
interface SVGAnimatedPreserveAspectRatio {
[Constant]
readonly attribute SVGPreserveAspectRatio baseVal;
[Constant]
readonly attribute SVGPreserveAspectRatio animVal;
};

View File

@ -68,6 +68,7 @@ webidl_files = \
PerformanceTiming.webidl \
RGBColor.webidl \
Screen.webidl \
SVGAnimatedPreserveAspectRatio.webidl \
SVGAnimatedTransformList.webidl \
SVGLengthList.webidl \
SVGMatrix.webidl \