Bug 816778 Part 8: Convert SVGAnimatedBoolean to WebIDL r=bz
authorDavid Zbarsky <dzbarsky@gmail.com>
Sat, 22 Dec 2012 23:54:22 -0500
changeset 126025 6e64444d5f30425ec42d87b2456924c9c37ae55c
parent 126024 b4e40d2db9adc0ffce83d0fd1a99c9ac3e7abae7
child 126026 9b915ddf9d18066ef61e6bcb6fd33472718168a4
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 8: Convert SVGAnimatedBoolean to WebIDL r=bz
content/svg/content/src/Makefile.in
content/svg/content/src/SVGAnimatedBoolean.cpp
content/svg/content/src/SVGAnimatedBoolean.h
content/svg/content/src/nsSVGBoolean.cpp
content/svg/content/src/nsSVGBoolean.h
dom/webidl/SVGAnimatedBoolean.webidl
dom/webidl/WebIDL.mk
--- a/content/svg/content/src/Makefile.in
+++ b/content/svg/content/src/Makefile.in
@@ -87,16 +87,17 @@ CPPSRCS		= \
 		nsSVGTextElement.cpp \
 		nsSVGTextPathElement.cpp \
 		nsSVGTextPositioningElement.cpp \
 		nsSVGTitleElement.cpp \
 		nsSVGUnknownElement.cpp \
 		nsSVGUseElement.cpp \
 		nsSVGViewBox.cpp \
 		nsSVGViewElement.cpp \
+		SVGAnimatedBoolean.cpp \
 		SVGAnimatedLengthList.cpp \
 		SVGAnimatedNumberList.cpp \
 		SVGAnimatedPathSegList.cpp \
 		SVGAnimatedPointList.cpp \
 		SVGAnimatedPreserveAspectRatio.cpp \
 		SVGAnimatedTransformList.cpp \
 		SVGFragmentIdentifier.cpp \
 		SVGLength.cpp \
@@ -139,16 +140,22 @@ include $(topsrcdir)/config/config.mk
 FORCE_STATIC_LIB = 1
 
 EXPORTS =  			\
 	nsSVGFeatures.h            \
 	nsSVGRect.h                \
 	SVGAttrValueWrapper.h      \
 	$(NULL)
 
+EXPORTS_NAMESPACES = mozilla/dom
+
+EXPORTS_mozilla/dom = \
+	SVGAnimatedBoolean.h \
+	$(NULL)
+
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES += 	\
 		-I$(srcdir)/../../../xml/content/src \
 		-I$(srcdir)/../../../../dom \
 		-I$(srcdir)/../../../base/src \
 		-I$(srcdir)/../../../../layout/generic \
 		-I$(srcdir)/../../../../layout/xul/base/src \
new file mode 100644
--- /dev/null
+++ b/content/svg/content/src/SVGAnimatedBoolean.cpp
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; 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/. */
+
+#include "SVGAnimatedBoolean.h"
+#include "nsSVGBoolean.h"
+#include "mozilla/dom/SVGAnimatedBooleanBinding.h"
+
+using namespace mozilla;
+using namespace mozilla::dom;
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(SVGAnimatedBoolean)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(SVGAnimatedBoolean)
+
+NS_IMPL_CYCLE_COLLECTION_CLASS(SVGAnimatedBoolean)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(SVGAnimatedBoolean)
+// 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(SVGAnimatedBoolean)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSVGElement)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
+
+NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(SVGAnimatedBoolean)
+NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
+NS_IMPL_CYCLE_COLLECTION_TRACE_END
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGAnimatedBoolean)
+  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+  NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedBoolean)
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
+  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedBoolean)
+NS_INTERFACE_MAP_END
+
+DOMCI_DATA(SVGAnimatedBoolean, SVGAnimatedBoolean)
+
+JSObject*
+SVGAnimatedBoolean::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
+{
+  return SVGAnimatedBooleanBinding::Wrap(aCx, aScope, this, aTriedToWrap);
+}
+
new file mode 100644
--- /dev/null
+++ b/content/svg/content/src/SVGAnimatedBoolean.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; 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/. */
+
+#pragma once
+
+#include "nsIDOMSVGAnimatedBoolean.h"
+#include "nsWrapperCache.h"
+#include "nsSVGElement.h"
+#include "mozilla/Attributes.h"
+#include "nsSVGBoolean.h"
+
+namespace mozilla {
+namespace dom {
+
+class SVGAnimatedBoolean MOZ_FINAL : public nsIDOMSVGAnimatedBoolean,
+                                     public nsWrapperCache
+{
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(SVGAnimatedBoolean)
+
+  SVGAnimatedBoolean(nsSVGBoolean* aVal, nsSVGElement *aSVGElement)
+    : mVal(aVal), mSVGElement(aSVGElement)
+  {
+    SetIsDOMBinding();
+  }
+  ~SVGAnimatedBoolean();
+
+  NS_IMETHOD GetBaseVal(bool* aResult)
+    { *aResult = BaseVal(); return NS_OK; }
+  NS_IMETHOD SetBaseVal(bool aValue)
+    { mVal->SetBaseValue(aValue, mSVGElement); return NS_OK; }
+
+  // Script may have modified animation parameters or timeline -- DOM getters
+  // need to flush any resample requests to reflect these modifications.
+  NS_IMETHOD GetAnimVal(bool* aResult)
+  {
+    *aResult = AnimVal();
+    return NS_OK;
+  }
+
+  // WebIDL
+  nsSVGElement* GetParentObject() const { return mSVGElement; }
+  virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap);
+  bool BaseVal() const { return mVal->GetBaseValue(); }
+  bool AnimVal() const { mSVGElement->FlushAnimations(); return mVal->GetAnimValue(); }
+
+protected:
+  nsSVGBoolean* mVal; // kept alive because it belongs to content
+  nsRefPtr<nsSVGElement> mSVGElement;
+};
+
+} //namespace dom
+} //namespace mozilla
--- a/content/svg/content/src/nsSVGBoolean.cpp
+++ b/content/svg/content/src/nsSVGBoolean.cpp
@@ -3,35 +3,24 @@
  * 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/. */
 
 #include "nsError.h"
 #include "nsSVGAttrTearoffTable.h"
 #include "nsSVGBoolean.h"
 #include "nsSMILValue.h"
 #include "SMILBoolType.h"
+#include "SVGAnimatedBoolean.h"
 
 using namespace mozilla;
-
-NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGBoolean::DOMAnimatedBoolean, mSVGElement)
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGBoolean::DOMAnimatedBoolean)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGBoolean::DOMAnimatedBoolean)
-
-DOMCI_DATA(SVGAnimatedBoolean, nsSVGBoolean::DOMAnimatedBoolean)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGBoolean::DOMAnimatedBoolean)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedBoolean)
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedBoolean)
-NS_INTERFACE_MAP_END
+using namespace mozilla::dom;
 
 /* Implementation */
 
-static nsSVGAttrTearoffTable<nsSVGBoolean, nsSVGBoolean::DOMAnimatedBoolean>
+static nsSVGAttrTearoffTable<nsSVGBoolean, SVGAnimatedBoolean>
   sSVGAnimatedBooleanTearoffTable;
 
 static nsresult
 GetValueFromString(const nsAString &aValueAsString,
                    bool *aValue)
 {
   if (aValueAsString.EqualsLiteral("true")) {
     *aValue = true;
@@ -116,28 +105,28 @@ nsSVGBoolean::SetAnimValue(bool aValue, 
   mIsAnimated = true;
   aSVGElement->DidAnimateBoolean(mAttrEnum);
 }
 
 nsresult
 nsSVGBoolean::ToDOMAnimatedBoolean(nsIDOMSVGAnimatedBoolean **aResult,
                                    nsSVGElement *aSVGElement)
 {
-  nsRefPtr<DOMAnimatedBoolean> domAnimatedBoolean =
+  nsRefPtr<SVGAnimatedBoolean> domAnimatedBoolean =
     sSVGAnimatedBooleanTearoffTable.GetTearoff(this);
   if (!domAnimatedBoolean) {
-    domAnimatedBoolean = new DOMAnimatedBoolean(this, aSVGElement);
+    domAnimatedBoolean = new SVGAnimatedBoolean(this, aSVGElement);
     sSVGAnimatedBooleanTearoffTable.AddTearoff(this, domAnimatedBoolean);
   }
 
   domAnimatedBoolean.forget(aResult);
   return NS_OK;
 }
 
-nsSVGBoolean::DOMAnimatedBoolean::~DOMAnimatedBoolean()
+SVGAnimatedBoolean::~SVGAnimatedBoolean()
 {
   sSVGAnimatedBooleanTearoffTable.RemoveTearoff(mVal);
 }
 
 nsISMILAttr*
 nsSVGBoolean::ToSMILAttr(nsSVGElement *aSVGElement)
 {
   return new SMILBool(this, aSVGElement);
--- a/content/svg/content/src/nsSVGBoolean.h
+++ b/content/svg/content/src/nsSVGBoolean.h
@@ -47,55 +47,28 @@ public:
 private:
 
   bool mAnimVal;
   bool mBaseVal;
   bool mIsAnimated;
   uint8_t mAttrEnum; // element specified tracking for attribute
 
 public:
-  struct DOMAnimatedBoolean MOZ_FINAL : public nsIDOMSVGAnimatedBoolean
-  {
-    NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-    NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedBoolean)
-
-    DOMAnimatedBoolean(nsSVGBoolean* aVal, nsSVGElement *aSVGElement)
-      : mVal(aVal), mSVGElement(aSVGElement) {}
-    virtual ~DOMAnimatedBoolean();
-
-    nsSVGBoolean* mVal; // kept alive because it belongs to content
-    nsRefPtr<nsSVGElement> mSVGElement;
-
-    NS_IMETHOD GetBaseVal(bool* aResult)
-      { *aResult = mVal->GetBaseValue(); return NS_OK; }
-    NS_IMETHOD SetBaseVal(bool aValue)
-      { mVal->SetBaseValue(aValue, mSVGElement); return NS_OK; }
-
-    // Script may have modified animation parameters or timeline -- DOM getters
-    // need to flush any resample requests to reflect these modifications.
-    NS_IMETHOD GetAnimVal(bool* aResult)
-    {
-      mSVGElement->FlushAnimations();
-      *aResult = mVal->GetAnimValue();
-      return NS_OK;
-    }
-  };
-
   struct SMILBool : public nsISMILAttr
   {
   public:
     SMILBool(nsSVGBoolean* aVal, nsSVGElement* aSVGElement)
       : mVal(aVal), mSVGElement(aSVGElement) {}
-    
+
     // These will stay alive because a nsISMILAttr only lives as long
     // as the Compositing step, and DOM elements don't get a chance to
     // die during that.
     nsSVGBoolean* mVal;
     nsSVGElement* mSVGElement;
-    
+
     // nsISMILAttr methods
     virtual nsresult ValueFromString(const nsAString& aStr,
                                      const nsISMILAnimationElement* aSrcElement,
                                      nsSMILValue& aValue,
                                      bool& aPreventCachingOfSandwich) const;
     virtual nsSMILValue GetBaseValue() const;
     virtual void ClearAnimValue();
     virtual nsresult SetAnimValue(const nsSMILValue& aValue);
new file mode 100644
--- /dev/null
+++ b/dom/webidl/SVGAnimatedBoolean.webidl
@@ -0,0 +1,17 @@
+/* -*- 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 SVGAnimatedBoolean {
+           attribute boolean baseVal;
+  readonly attribute boolean 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 \
+  SVGAnimatedBoolean.webidl \
   SVGAnimatedNumberList.webidl \
   SVGAnimatedPreserveAspectRatio.webidl \
   SVGAnimatedTransformList.webidl \
   SVGLengthList.webidl \
   SVGMatrix.webidl \
   SVGNumberList.webidl \
   SVGPathSegList.webidl \
   SVGPoint.webidl \