Bug 816778 Part 6: Convert SVGAnimatedPreserveAspectRatio to WebIDL r=bz
authorDavid Zbarsky <dzbarsky@gmail.com>
Sat, 22 Dec 2012 23:54:20 -0500
changeset 126021 00c8e8d5fe04c1d1a29d2d04e06f61064eedaae5
parent 126020 1945ceaff5faca696a3fa0853750b6c13cc170ab
child 126022 94ed53f03fd1374934534e3e4a2855e3732564f4
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs816778
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 816778 Part 6: Convert SVGAnimatedPreserveAspectRatio to WebIDL r=bz
content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp
content/svg/content/src/SVGAnimatedPreserveAspectRatio.h
content/svg/content/src/SVGPreserveAspectRatio.cpp
dom/bindings/Bindings.conf
dom/webidl/SVGAnimatedPreserveAspectRatio.webidl
dom/webidl/WebIDL.mk
--- a/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp
+++ b/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp
@@ -6,50 +6,67 @@
 #include "mozilla/Util.h"
 
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "nsWhitespaceTokenizer.h"
 #include "nsSMILValue.h"
 #include "nsSVGAttrTearoffTable.h"
 #include "SMILEnumType.h"
 #include "nsAttrValueInlines.h"
+#include "mozilla/dom/SVGAnimatedPreserveAspectRatioBinding.h"
 
 using namespace mozilla;
 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_COLLECTION_TRAVERSE_BEGIN(DOMSVGAnimatedPreserveAspectRatio)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSVGElement)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-NS_IMPL_CYCLE_COLLECTING_ADDREF(
-  SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(
-  SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio)
+NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMSVGAnimatedPreserveAspectRatio)
+NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
+NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
-DOMCI_DATA(SVGAnimatedPreserveAspectRatio,
-           SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGAnimatedPreserveAspectRatio)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGAnimatedPreserveAspectRatio)
 
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
-  SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio)
+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[] =
   { "none", "xMinYMin", "xMidYMin", "xMaxYMin", "xMinYMid", "xMidYMid",
     "xMaxYMid", "xMinYMax", "xMidYMax", "xMaxYMax" };
 
 static const char *sMeetOrSliceStrings[] = { "meet", "slice" };
 
-static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, SVGAnimatedPreserveAspectRatio::DOMAnimPAspectRatio>
+static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, DOMSVGAnimatedPreserveAspectRatio>
   sSVGAnimatedPAspectRatioTearoffTable;
 static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, DOMSVGPreserveAspectRatio>
   sBaseSVGPAspectRatioTearoffTable;
 static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, DOMSVGPreserveAspectRatio>
   sAnimSVGPAspectRatioTearoffTable;
 
 static uint16_t
 GetAlignForString(const nsAString &aAlignString)
@@ -96,55 +113,49 @@ GetMeetOrSliceString(nsAString& aMeetOrS
     aMeetOrSlice <= nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE,
     "Unknown meetOrSlice");
 
   aMeetOrSliceString.AssignASCII(
     sMeetOrSliceStrings[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()
 {
   if (mIsBaseValue) {
     sBaseSVGPAspectRatioTearoffTable.RemoveTearoff(mVal);
   } else {
     sAnimSVGPAspectRatioTearoffTable.RemoveTearoff(mVal);
   }
 }
 
-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
 ToPreserveAspectRatio(const nsAString &aString,
                       SVGPreserveAspectRatio *aValue)
 {
   if (aString.IsEmpty() || NS_IsAsciiWhitespace(aString[0])) {
     return NS_ERROR_DOM_SYNTAX_ERR;
@@ -292,27 +303,27 @@ SVGAnimatedPreserveAspectRatio::SetAnimV
   aSVGElement->DidAnimatePreserveAspectRatio();
 }
 
 nsresult
 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);
 }
 
 nsISMILAttr*
 SVGAnimatedPreserveAspectRatio::ToSMILAttr(nsSVGElement *aSVGElement)
 {
   return new SMILPreserveAspectRatio(this, aSVGElement);
--- a/content/svg/content/src/SVGAnimatedPreserveAspectRatio.h
+++ b/content/svg/content/src/SVGAnimatedPreserveAspectRatio.h
@@ -79,44 +79,17 @@ public:
 
 private:
 
   SVGPreserveAspectRatio mAnimVal;
   SVGPreserveAspectRatio mBaseVal;
   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:
     SMILPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
                             nsSVGElement* aSVGElement)
       : mVal(aVal), mSVGElement(aSVGElement) {}
 
     // These will stay alive because a nsISMILAttr only lives as long
@@ -131,11 +104,47 @@ public:
                                      nsSMILValue& aValue,
                                      bool& aPreventCachingOfSandwich) const;
     virtual nsSMILValue GetBaseValue() const;
     virtual void ClearAnimValue();
     virtual nsresult SetAnimValue(const nsSMILValue& aValue);
   };
 };
 
+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__
--- a/content/svg/content/src/SVGPreserveAspectRatio.cpp
+++ b/content/svg/content/src/SVGPreserveAspectRatio.cpp
@@ -7,16 +7,18 @@
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "mozilla/dom/SVGPreserveAspectRatioBinding.h"
 
 using namespace mozilla;
 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
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGPreserveAspectRatio)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSVGElement)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -436,16 +436,21 @@ DOMInterfaces = {
     'resultNotAddRefed': [ "alpha", "blue", "green", "red" ]
 },
 
 'Screen': {
     'nativeType': 'nsScreen',
     'prefable': True,
 },
 
+'SVGAnimatedPreserveAspectRatio': {
+    'nativeType': 'mozilla::dom::DOMSVGAnimatedPreserveAspectRatio',
+    'headerFile': 'SVGAnimatedPreserveAspectRatio.h'
+},
+
 'SVGAnimatedTransformList': {
     'nativeType': 'mozilla::DOMSVGAnimatedTransformList',
     'headerFile': 'DOMSVGAnimatedTransformList.h'
 },
 
 'SVGLengthList': {
     'nativeType': 'mozilla::DOMSVGLengthList',
     'headerFile': 'DOMSVGLengthList.h',
new file mode 100644
--- /dev/null
+++ b/dom/webidl/SVGAnimatedPreserveAspectRatio.webidl
@@ -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;
+};
+
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -63,16 +63,17 @@ webidl_files = \
   PaintRequest.webidl \
   PaintRequestList.webidl \
   PannerNode.webidl \
   Performance.webidl \
   PerformanceNavigation.webidl \
   PerformanceTiming.webidl \
   RGBColor.webidl \
   Screen.webidl \
+  SVGAnimatedPreserveAspectRatio.webidl \
   SVGAnimatedTransformList.webidl \
   SVGLengthList.webidl \
   SVGMatrix.webidl \
   SVGNumberList.webidl \
   SVGPathSegList.webidl \
   SVGPoint.webidl \
   SVGPointList.webidl \
   SVGPreserveAspectRatio.webidl \