Bug 830230 - Convert SVGPatternElement to WebIDL r=bz
authorDavid Zbarsky <dzbarsky@gmail.com>
Wed, 16 Jan 2013 15:51:00 -0500
changeset 119066 3e149de4b63871eb66b4555be097f4c348e19618
parent 119065 69eec5e8a4777df33957a05b4c3d88c4626871b8
child 119067 f719315ea4121c192a8c9f5c0f65fc114472e351
push id24189
push useremorley@mozilla.com
push dateThu, 17 Jan 2013 10:42:06 +0000
treeherdermozilla-central@712eca11a04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs830230
milestone21.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 830230 - Convert SVGPatternElement to WebIDL r=bz
content/svg/content/src/SVGPatternElement.cpp
content/svg/content/src/SVGPatternElement.h
dom/webidl/SVGPatternElement.webidl
dom/webidl/WebIDL.mk
layout/svg/nsSVGPatternFrame.cpp
--- a/content/svg/content/src/SVGPatternElement.cpp
+++ b/content/svg/content/src/SVGPatternElement.cpp
@@ -5,24 +5,31 @@
 
 #include "mozilla/Util.h"
 
 #include "DOMSVGAnimatedTransformList.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsCOMPtr.h"
 #include "nsGkAtoms.h"
 #include "mozilla/dom/SVGPatternElement.h"
+#include "mozilla/dom/SVGPatternElementBinding.h"
 
 NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Pattern)
 
 DOMCI_NODE_DATA(SVGPatternElement, mozilla::dom::SVGPatternElement)
 
 namespace mozilla {
 namespace dom {
 
+JSObject*
+SVGPatternElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
+{
+  return SVGPatternElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
+}
+
 //--------------------- Patterns ------------------------
 
 nsSVGElement::LengthInfo SVGPatternElement::sLengthInfo[4] =
 {
   { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
   { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
   { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
   { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
@@ -60,101 +67,172 @@ NS_INTERFACE_TABLE_HEAD(SVGPatternElemen
 NS_INTERFACE_MAP_END_INHERITING(SVGPatternElementBase)
 
 //----------------------------------------------------------------------
 // Implementation
 
 SVGPatternElement::SVGPatternElement(already_AddRefed<nsINodeInfo> aNodeInfo)
   : SVGPatternElementBase(aNodeInfo)
 {
+  SetIsDOMBinding();
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode method
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPatternElement)
 
 //----------------------------------------------------------------------
 // nsIDOMSVGFitToViewBox methods
 
 /* readonly attribute nsIDOMSVGAnimatedRect viewBox; */
 NS_IMETHODIMP SVGPatternElement::GetViewBox(nsIDOMSVGAnimatedRect * *aViewBox)
 {
-  return mViewBox.ToDOMAnimatedRect(aViewBox, this);
+  *aViewBox = ViewBox().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGAnimatedRect>
+SVGPatternElement::ViewBox()
+{
+  nsCOMPtr<nsIDOMSVGAnimatedRect> rect;
+  mViewBox.ToDOMAnimatedRect(getter_AddRefs(rect), this);
+  return rect.forget();
 }
 
 /* readonly attribute SVGPreserveAspectRatio preserveAspectRatio; */
 NS_IMETHODIMP
-SVGPatternElement::GetPreserveAspectRatio(nsISupports
-                                          **aPreserveAspectRatio)
+SVGPatternElement::GetPreserveAspectRatio(nsISupports **aPreserveAspectRatio)
+{
+  *aPreserveAspectRatio = PreserveAspectRatio().get();
+  return NS_OK;
+}
+
+already_AddRefed<DOMSVGAnimatedPreserveAspectRatio>
+SVGPatternElement::PreserveAspectRatio()
 {
   nsRefPtr<DOMSVGAnimatedPreserveAspectRatio> ratio;
   mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(getter_AddRefs(ratio), this);
-  ratio.forget(aPreserveAspectRatio);
-  return NS_OK;
+  return ratio.forget();
 }
 
 //----------------------------------------------------------------------
 // nsIDOMSVGPatternElement methods
 
 /* readonly attribute nsIDOMSVGAnimatedEnumeration patternUnits; */
 NS_IMETHODIMP SVGPatternElement::GetPatternUnits(nsIDOMSVGAnimatedEnumeration * *aPatternUnits)
 {
-  return mEnumAttributes[PATTERNUNITS].ToDOMAnimatedEnum(aPatternUnits, this);
+  *aPatternUnits = PatternUnits().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGAnimatedEnumeration>
+SVGPatternElement::PatternUnits()
+{
+  return mEnumAttributes[PATTERNUNITS].ToDOMAnimatedEnum(this);
 }
 
 /* readonly attribute nsIDOMSVGAnimatedEnumeration patternContentUnits; */
 NS_IMETHODIMP SVGPatternElement::GetPatternContentUnits(nsIDOMSVGAnimatedEnumeration * *aPatternUnits)
 {
-  return mEnumAttributes[PATTERNCONTENTUNITS].ToDOMAnimatedEnum(aPatternUnits, this);
+  *aPatternUnits = PatternContentUnits().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGAnimatedEnumeration>
+SVGPatternElement::PatternContentUnits()
+{
+  return mEnumAttributes[PATTERNCONTENTUNITS].ToDOMAnimatedEnum(this);
 }
 
 /* readonly attribute nsISupports patternTransform; */
 NS_IMETHODIMP SVGPatternElement::GetPatternTransform(nsISupports * *aPatternTransform)
 {
+  *aPatternTransform = PatternTransform().get();
+  return NS_OK;
+}
+
+already_AddRefed<DOMSVGAnimatedTransformList>
+SVGPatternElement::PatternTransform()
+{
   // We're creating a DOM wrapper, so we must tell GetAnimatedTransformList
   // to allocate the SVGAnimatedTransformList if it hasn't already done so:
-  *aPatternTransform = DOMSVGAnimatedTransformList::GetDOMWrapper(
-                         GetAnimatedTransformList(DO_ALLOCATE), this).get();
-  return NS_OK;
+  return DOMSVGAnimatedTransformList::GetDOMWrapper(
+           GetAnimatedTransformList(DO_ALLOCATE), this);
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLength x; */
 NS_IMETHODIMP SVGPatternElement::GetX(nsIDOMSVGAnimatedLength * *aX)
 {
-  return mLengthAttributes[X].ToDOMAnimatedLength(aX, this);
+  *aX = X().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGAnimatedLength>
+SVGPatternElement::X()
+{
+  return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLength y; */
 NS_IMETHODIMP SVGPatternElement::GetY(nsIDOMSVGAnimatedLength * *aY)
 {
-  return mLengthAttributes[Y].ToDOMAnimatedLength(aY, this);
+  *aY = Y().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGAnimatedLength>
+SVGPatternElement::Y()
+{
+  return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLength width; */
 NS_IMETHODIMP SVGPatternElement::GetWidth(nsIDOMSVGAnimatedLength * *aWidth)
 {
-  return mLengthAttributes[WIDTH].ToDOMAnimatedLength(aWidth, this);
+  *aWidth = Width().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGAnimatedLength>
+SVGPatternElement::Width()
+{
+  return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
 }
 
 /* readonly attribute nsIDOMSVGAnimatedLength height; */
 NS_IMETHODIMP SVGPatternElement::GetHeight(nsIDOMSVGAnimatedLength * *aHeight)
 {
-  return mLengthAttributes[HEIGHT].ToDOMAnimatedLength(aHeight, this);
+  *aHeight = Height().get();
+  return NS_OK;
 }
 
+already_AddRefed<nsIDOMSVGAnimatedLength>
+SVGPatternElement::Height()
+{
+  return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
+}
 
 //----------------------------------------------------------------------
 // nsIDOMSVGURIReference methods:
 
 /* readonly attribute nsIDOMSVGAnimatedString href; */
 NS_IMETHODIMP
 SVGPatternElement::GetHref(nsIDOMSVGAnimatedString * *aHref)
 {
-  return mStringAttributes[HREF].ToDOMAnimatedString(aHref, this);
+  *aHref = Href().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGAnimatedString>
+SVGPatternElement::Href()
+{
+  nsCOMPtr<nsIDOMSVGAnimatedString> href;
+  mStringAttributes[HREF].ToDOMAnimatedString(getter_AddRefs(href), this);
+  return href.forget();
 }
 
 //----------------------------------------------------------------------
 // nsIContent methods
 
 NS_IMETHODIMP_(bool)
 SVGPatternElement::IsAttributeMapped(const nsIAtom* name) const
 {
@@ -183,20 +261,20 @@ SVGPatternElement::GetAnimatedTransformL
     mPatternTransform = new SVGAnimatedTransformList();
   }
   return mPatternTransform;
 }
 
 /* virtual */ bool
 SVGPatternElement::HasValidDimensions() const
 {
-  return mLengthAttributes[WIDTH].IsExplicitlySet() &&
-         mLengthAttributes[WIDTH].GetAnimValInSpecifiedUnits() > 0 &&
-         mLengthAttributes[HEIGHT].IsExplicitlySet() &&
-         mLengthAttributes[HEIGHT].GetAnimValInSpecifiedUnits() > 0;
+  return mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() &&
+         mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0 &&
+         mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() &&
+         mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0;
 }
 
 nsSVGElement::LengthAttributesInfo
 SVGPatternElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
                               ArrayLength(sLengthInfo));
 }
--- a/content/svg/content/src/SVGPatternElement.h
+++ b/content/svg/content/src/SVGPatternElement.h
@@ -19,32 +19,35 @@
 #include "SVGAnimatedTransformList.h"
 
 class nsSVGPatternFrame;
 
 nsresult NS_NewSVGPatternElement(nsIContent **aResult,
                                  already_AddRefed<nsINodeInfo> aNodeInfo);
 
 namespace mozilla {
+class DOMSVGAnimatedTransformList;
+
 namespace dom {
 
 typedef nsSVGElement SVGPatternElementBase;
 
 class SVGPatternElement MOZ_FINAL : public SVGPatternElementBase,
                                     public nsIDOMSVGPatternElement,
                                     public nsIDOMSVGURIReference,
                                     public nsIDOMSVGFitToViewBox,
                                     public nsIDOMSVGUnitTypes
 {
   friend class ::nsSVGPatternFrame;
 
 protected:
   friend nsresult (::NS_NewSVGPatternElement(nsIContent **aResult,
                                              already_AddRefed<nsINodeInfo> aNodeInfo));
   SVGPatternElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap) MOZ_OVERRIDE;
 
 public:
   typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
 
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
 
   // Pattern Element
@@ -72,26 +75,39 @@ public:
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const;
 
   virtual mozilla::SVGAnimatedTransformList*
     GetAnimatedTransformList(uint32_t aFlags = 0);
   virtual nsIAtom* GetTransformListAttrName() const {
     return nsGkAtoms::patternTransform;
   }
+
+  // WebIDL
+  already_AddRefed<nsIDOMSVGAnimatedRect> ViewBox();
+  already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
+  already_AddRefed<nsIDOMSVGAnimatedEnumeration> PatternUnits();
+  already_AddRefed<nsIDOMSVGAnimatedEnumeration> PatternContentUnits();
+  already_AddRefed<DOMSVGAnimatedTransformList> PatternTransform();
+  already_AddRefed<nsIDOMSVGAnimatedLength> X();
+  already_AddRefed<nsIDOMSVGAnimatedLength> Y();
+  already_AddRefed<nsIDOMSVGAnimatedLength> Width();
+  already_AddRefed<nsIDOMSVGAnimatedLength> Height();
+  already_AddRefed<nsIDOMSVGAnimatedString> Href();
+
 protected:
 
   virtual LengthAttributesInfo GetLengthInfo();
   virtual EnumAttributesInfo GetEnumInfo();
   virtual nsSVGViewBox *GetViewBox();
   virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio();
   virtual StringAttributesInfo GetStringInfo();
 
   // nsIDOMSVGPatternElement values
-  enum { X, Y, WIDTH, HEIGHT };
+  enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
   nsSVGLength2 mLengthAttributes[4];
   static LengthInfo sLengthInfo[4];
 
   enum { PATTERNUNITS, PATTERNCONTENTUNITS };
   nsSVGEnum mEnumAttributes[2];
   static EnumInfo sEnumInfo[2];
 
   nsAutoPtr<mozilla::SVGAnimatedTransformList> mPatternTransform;
new file mode 100644
--- /dev/null
+++ b/dom/webidl/SVGPatternElement.webidl
@@ -0,0 +1,35 @@
+/* -*- 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/pservers.html#InterfaceSVGPatternElement
+ *
+ * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+
+interface SVGAnimatedEnumeration;
+interface SVGAnimatedLength;
+
+interface SVGPatternElement : SVGElement {
+  [Constant]
+  readonly attribute SVGAnimatedEnumeration patternUnits;
+  [Constant]
+  readonly attribute SVGAnimatedEnumeration patternContentUnits;
+  [Constant]
+  readonly attribute SVGAnimatedTransformList patternTransform;
+  [Constant]
+  readonly attribute SVGAnimatedLength x;
+  [Constant]
+  readonly attribute SVGAnimatedLength y;
+  [Constant]
+  readonly attribute SVGAnimatedLength width;
+  [Constant]
+  readonly attribute SVGAnimatedLength height;
+};
+
+SVGPatternElement implements SVGFitToViewBox;
+SVGPatternElement implements SVGURIReference;
+SVGPatternElement implements SVGUnitTypes;
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -130,16 +130,17 @@ webidl_files = \
   SVGLocatableElement.webidl \
   SVGMatrix.webidl \
   SVGMetadataElement.webidl \
   SVGMPathElement.webidl \
   SVGNumberList.webidl \
   SVGPathElement.webidl \
   SVGPathSeg.webidl \
   SVGPathSegList.webidl \
+  SVGPatternElement.webidl \
   SVGPoint.webidl \
   SVGPointList.webidl \
   SVGPolygonElement.webidl \
   SVGPolylineElement.webidl \
   SVGPreserveAspectRatio.webidl \
   SVGRadialGradientElement.webidl \
   SVGRectElement.webidl \
   SVGScriptElement.webidl \
--- a/layout/svg/nsSVGPatternFrame.cpp
+++ b/layout/svg/nsSVGPatternFrame.cpp
@@ -583,20 +583,20 @@ nsSVGPatternFrame::GetPatternRect(uint16
                                   const gfxMatrix &aTargetCTM,
                                   nsIFrame *aTarget)
 {
   // We need to initialize our box
   float x,y,width,height;
 
   // Get the pattern x,y,width, and height
   const nsSVGLength2 *tmpX, *tmpY, *tmpHeight, *tmpWidth;
-  tmpX = GetLengthValue(SVGPatternElement::X);
-  tmpY = GetLengthValue(SVGPatternElement::Y);
-  tmpHeight = GetLengthValue(SVGPatternElement::HEIGHT);
-  tmpWidth = GetLengthValue(SVGPatternElement::WIDTH);
+  tmpX = GetLengthValue(SVGPatternElement::ATTR_X);
+  tmpY = GetLengthValue(SVGPatternElement::ATTR_Y);
+  tmpHeight = GetLengthValue(SVGPatternElement::ATTR_HEIGHT);
+  tmpWidth = GetLengthValue(SVGPatternElement::ATTR_WIDTH);
 
   if (aPatternUnits == nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
     x = nsSVGUtils::ObjectSpace(aTargetBBox, tmpX);
     y = nsSVGUtils::ObjectSpace(aTargetBBox, tmpY);
     width = nsSVGUtils::ObjectSpace(aTargetBBox, tmpWidth);
     height = nsSVGUtils::ObjectSpace(aTargetBBox, tmpHeight);
   } else {
     float scale = nsSVGUtils::MaxExpansion(aTargetCTM);
@@ -642,25 +642,25 @@ nsSVGPatternFrame::ConstructCTM(const ns
   }
 
   float viewportWidth, viewportHeight;
   if (targetContent->IsSVG()) {
     // If we're dealing with an SVG target only retrieve the context once.
     // Calling the nsIFrame* variant of GetAnimValue would look it up on
     // every call.
     viewportWidth =
-      GetLengthValue(SVGPatternElement::WIDTH)->GetAnimValue(ctx);
+      GetLengthValue(SVGPatternElement::ATTR_WIDTH)->GetAnimValue(ctx);
     viewportHeight =
-      GetLengthValue(SVGPatternElement::HEIGHT)->GetAnimValue(ctx);
+      GetLengthValue(SVGPatternElement::ATTR_HEIGHT)->GetAnimValue(ctx);
   } else {
     // No SVG target, call the nsIFrame* variant of GetAnimValue.
     viewportWidth =
-      GetLengthValue(SVGPatternElement::WIDTH)->GetAnimValue(aTarget);
+      GetLengthValue(SVGPatternElement::ATTR_WIDTH)->GetAnimValue(aTarget);
     viewportHeight =
-      GetLengthValue(SVGPatternElement::HEIGHT)->GetAnimValue(aTarget);
+      GetLengthValue(SVGPatternElement::ATTR_HEIGHT)->GetAnimValue(aTarget);
   }
 
   if (viewportWidth <= 0.0f || viewportHeight <= 0.0f) {
     return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
   }
 
   gfxMatrix tm = SVGContentUtils::GetViewBoxTransform(
     static_cast<SVGPatternElement*>(mContent),