Bug 824229 Part 5: Implement SVGGraphicsElement r=longsonr
authorDavid Zbarsky <dzbarsky@gmail.com>
Thu, 03 Jan 2013 01:17:02 -0500
changeset 126878 7cfc54a3465bf14fc23bf431890f42a367f240b1
parent 126877 9c9681d775952ab2a7d7182e02bc116f00b4e6f7
child 126879 3b08c0ff70b190de871a852401d51ca74d04b0ff
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)
reviewerslongsonr
bugs824229
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 824229 Part 5: Implement SVGGraphicsElement r=longsonr
content/svg/content/src/DOMSVGTests.cpp
content/svg/content/src/DOMSVGTests.h
content/svg/content/src/nsSVGFilterElement.cpp
content/svg/content/src/nsSVGGraphicElement.cpp
content/svg/content/src/nsSVGGraphicElement.h
dom/bindings/Bindings.conf
dom/webidl/SVGGraphicsElement.webidl
dom/webidl/SVGTests.webidl
dom/webidl/WebIDL.mk
--- a/content/svg/content/src/DOMSVGTests.cpp
+++ b/content/svg/content/src/DOMSVGTests.cpp
@@ -26,51 +26,75 @@ DOMSVGTests::DOMSVGTests()
 {
   mStringListAttributes[LANGUAGE].SetIsCommaSeparated(true);
 }
 
 /* readonly attribute nsIDOMSVGStringList requiredFeatures; */
 NS_IMETHODIMP
 DOMSVGTests::GetRequiredFeatures(nsIDOMSVGStringList * *aRequiredFeatures)
 {
+  *aRequiredFeatures = RequiredFeatures().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGStringList>
+DOMSVGTests::RequiredFeatures()
+{
   nsCOMPtr<nsSVGElement> element = do_QueryInterface(this);
-  *aRequiredFeatures = DOMSVGStringList::GetDOMWrapper(
-                         &mStringListAttributes[FEATURES], element, true, FEATURES).get();
-  return NS_OK;
+  return DOMSVGStringList::GetDOMWrapper(
+           &mStringListAttributes[FEATURES], element, true, FEATURES).get();
 }
 
 /* readonly attribute nsIDOMSVGStringList requiredExtensions; */
 NS_IMETHODIMP
 DOMSVGTests::GetRequiredExtensions(nsIDOMSVGStringList * *aRequiredExtensions)
 {
+  *aRequiredExtensions = RequiredExtensions().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGStringList>
+DOMSVGTests::RequiredExtensions()
+{
   nsCOMPtr<nsSVGElement> element = do_QueryInterface(this);
-  *aRequiredExtensions = DOMSVGStringList::GetDOMWrapper(
-                           &mStringListAttributes[EXTENSIONS], element, true, EXTENSIONS).get();
-  return NS_OK;
+  return DOMSVGStringList::GetDOMWrapper(
+           &mStringListAttributes[EXTENSIONS], element, true, EXTENSIONS).get();
 }
 
 /* readonly attribute nsIDOMSVGStringList systemLanguage; */
 NS_IMETHODIMP
 DOMSVGTests::GetSystemLanguage(nsIDOMSVGStringList * *aSystemLanguage)
 {
+  *aSystemLanguage = SystemLanguage().get();
+  return NS_OK;
+}
+
+already_AddRefed<nsIDOMSVGStringList>
+DOMSVGTests::SystemLanguage()
+{
   nsCOMPtr<nsSVGElement> element = do_QueryInterface(this);
-  *aSystemLanguage = DOMSVGStringList::GetDOMWrapper(
-                       &mStringListAttributes[LANGUAGE], element, true, LANGUAGE).get();
-  return NS_OK;
+  return DOMSVGStringList::GetDOMWrapper(
+           &mStringListAttributes[LANGUAGE], element, true, LANGUAGE).get();
 }
 
 /* boolean hasExtension (in DOMString extension); */
 NS_IMETHODIMP
 DOMSVGTests::HasExtension(const nsAString & extension, bool *_retval)
 {
-  *_retval = nsSVGFeatures::HasExtension(extension);
+  *_retval = HasExtension(extension);
   return NS_OK;
 }
 
 bool
+DOMSVGTests::HasExtension(const nsAString& aExtension)
+{
+  return nsSVGFeatures::HasExtension(aExtension);
+}
+
+bool
 DOMSVGTests::IsConditionalProcessingAttribute(const nsIAtom* aAttribute) const
 {
   for (uint32_t i = 0; i < ArrayLength(sStringListNames); i++) {
     if (aAttribute == *sStringListNames[i]) {
       return true;
     }
   }
   return false;
--- a/content/svg/content/src/DOMSVGTests.h
+++ b/content/svg/content/src/DOMSVGTests.h
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_DOMSVGTESTS_H__
 #define MOZILLA_DOMSVGTESTS_H__
 
 #include "nsIDOMSVGTests.h"
 #include "nsStringFwd.h"
 #include "SVGStringList.h"
+#include "nsCOMPtr.h"
 
 class nsAttrValue;
 class nsIAtom;
 class nsString;
 
 namespace mozilla {
 class DOMSVGStringList;
 }
@@ -79,15 +80,21 @@ public:
    */
   void UnsetAttr(const nsIAtom* aAttribute);
 
   nsIAtom* GetAttrName(uint8_t aAttrEnum) const;
   void GetAttrValue(uint8_t aAttrEnum, nsAttrValue &aValue) const;
 
   void MaybeInvalidate();
 
+  // WebIDL
+  already_AddRefed<nsIDOMSVGStringList> RequiredFeatures();
+  already_AddRefed<nsIDOMSVGStringList> RequiredExtensions();
+  already_AddRefed<nsIDOMSVGStringList> SystemLanguage();
+  bool HasExtension(const nsAString& aExtension);
+
 private:
   enum { FEATURES, EXTENSIONS, LANGUAGE };
   SVGStringList mStringListAttributes[3];
   static nsIAtom** sStringListNames[3];
 };
 
 #endif // MOZILLA_DOMSVGTESTS_H__
--- a/content/svg/content/src/nsSVGFilterElement.cpp
+++ b/content/svg/content/src/nsSVGFilterElement.cpp
@@ -161,17 +161,17 @@ nsSVGFilterElement::IsAttributeMapped(co
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
   return FindAttributeDependence(name, map) ||
-    nsSVGGraphicElementBase::IsAttributeMapped(name);
+    nsSVGFilterElementBase::IsAttributeMapped(name);
 }
 
 void
 nsSVGFilterElement::Invalidate()
 {
   nsTObserverArray<nsIMutationObserver*> *observers = GetMutationObservers();
 
   if (observers && !observers->IsEmpty()) {
--- a/content/svg/content/src/nsSVGGraphicElement.cpp
+++ b/content/svg/content/src/nsSVGGraphicElement.cpp
@@ -13,130 +13,46 @@
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsIFrame.h"
 #include "nsISVGChildFrame.h"
 #include "nsSVGUtils.h"
 #include "nsError.h"
 #include "nsSVGRect.h"
 #include "nsContentUtils.h"
+#include "mozilla/dom/SVGGraphicsElementBinding.h"
 
 using namespace mozilla;
+using namespace mozilla::dom;
+
+JSObject*
+nsSVGGraphicElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
+{
+  return SVGGraphicsElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
+}
 
 //----------------------------------------------------------------------
 // nsISupports methods
 
 NS_IMPL_ADDREF_INHERITED(nsSVGGraphicElement, nsSVGGraphicElementBase)
 NS_IMPL_RELEASE_INHERITED(nsSVGGraphicElement, nsSVGGraphicElementBase)
 
 NS_INTERFACE_MAP_BEGIN(nsSVGGraphicElement)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMSVGLocatable)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMSVGTransformable)
   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGTests)
 NS_INTERFACE_MAP_END_INHERITING(nsSVGGraphicElementBase)
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsSVGGraphicElement::nsSVGGraphicElement(already_AddRefed<nsINodeInfo> aNodeInfo)
   : nsSVGGraphicElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
-// nsIDOMSVGLocatable methods
-
-/* readonly attribute nsIDOMSVGElement nearestViewportElement; */
-NS_IMETHODIMP nsSVGGraphicElement::GetNearestViewportElement(nsIDOMSVGElement * *aNearestViewportElement)
-{
-  *aNearestViewportElement = SVGContentUtils::GetNearestViewportElement(this).get();
-  return NS_OK;
-}
-
-/* readonly attribute nsIDOMSVGElement farthestViewportElement; */
-NS_IMETHODIMP nsSVGGraphicElement::GetFarthestViewportElement(nsIDOMSVGElement * *aFarthestViewportElement)
-{
-  NS_IF_ADDREF(*aFarthestViewportElement = SVGContentUtils::GetOuterSVGElement(this));
-  return NS_OK;
-}
-
-/* nsIDOMSVGRect getBBox (); */
-NS_IMETHODIMP nsSVGGraphicElement::GetBBox(nsIDOMSVGRect **_retval)
-{
-  *_retval = nullptr;
-
-  nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
-
-  if (!frame || (frame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD))
-    return NS_ERROR_FAILURE;
-
-  nsISVGChildFrame* svgframe = do_QueryFrame(frame);
-  if (svgframe) {
-    return NS_NewSVGRect(_retval, nsSVGUtils::GetBBox(frame));
-  }
-  return NS_ERROR_FAILURE;
-}
-
-/* DOMSVGMatrix getCTM (); */
-NS_IMETHODIMP nsSVGGraphicElement::GetCTM(nsISupports * *aCTM)
-{
-  gfxMatrix m = SVGContentUtils::GetCTM(this, false);
-  *aCTM = m.IsSingular() ? nullptr : new DOMSVGMatrix(m);
-  NS_IF_ADDREF(*aCTM);
-  return NS_OK;
-}
-
-/* DOMSVGMatrix getScreenCTM (); */
-NS_IMETHODIMP nsSVGGraphicElement::GetScreenCTM(nsISupports * *aCTM)
-{
-  gfxMatrix m = SVGContentUtils::GetCTM(this, true);
-  *aCTM = m.IsSingular() ? nullptr : new DOMSVGMatrix(m);
-  NS_IF_ADDREF(*aCTM);
-  return NS_OK;
-}
-
-/* DOMSVGMatrix getTransformToElement (in nsIDOMSVGElement element); */
-NS_IMETHODIMP nsSVGGraphicElement::GetTransformToElement(nsIDOMSVGElement *element, nsISupports **_retval)
-{
-  if (!element)
-    return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
-
-  nsresult rv;
-  *_retval = nullptr;
-  nsCOMPtr<DOMSVGMatrix> ourScreenCTM;
-  nsCOMPtr<DOMSVGMatrix> targetScreenCTM;
-  nsCOMPtr<nsIDOMSVGLocatable> target = do_QueryInterface(element, &rv);
-  if (NS_FAILED(rv)) return rv;
-
-  // the easiest way to do this (if likely to increase rounding error):
-  GetScreenCTM(getter_AddRefs(ourScreenCTM));
-  if (!ourScreenCTM) return NS_ERROR_DOM_SVG_MATRIX_NOT_INVERTABLE;
-  target->GetScreenCTM(getter_AddRefs(targetScreenCTM));
-  if (!targetScreenCTM) return NS_ERROR_DOM_SVG_MATRIX_NOT_INVERTABLE;
-  ErrorResult result;
-  nsCOMPtr<DOMSVGMatrix> tmp = targetScreenCTM->Inverse(result);
-  if (result.Failed()) return result.ErrorCode();
-  *_retval = tmp->Multiply(*ourScreenCTM).get(); // addrefs, so we don't
-  return NS_OK;
-}
-
-//----------------------------------------------------------------------
-// nsIDOMSVGTransformable methods
-/* readonly attribute nsISupports transform; */
-
-NS_IMETHODIMP nsSVGGraphicElement::GetTransform(nsISupports **aTransform)
-{
-  // We're creating a DOM wrapper, so we must tell GetAnimatedTransformList
-  // to allocate the SVGAnimatedTransformList if it hasn't already done so:
-  *aTransform = DOMSVGAnimatedTransformList::GetDOMWrapper(
-                  GetAnimatedTransformList(DO_ALLOCATE), this).get();
-  return NS_OK;
-}
-
-//----------------------------------------------------------------------
 // nsIContent methods
 
 NS_IMETHODIMP_(bool)
 nsSVGGraphicElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sColorMap,
     sFillStrokeMap,
--- a/content/svg/content/src/nsSVGGraphicElement.h
+++ b/content/svg/content/src/nsSVGGraphicElement.h
@@ -2,36 +2,38 @@
 /* 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/. */
 
 #ifndef __NS_SVGGRAPHICELEMENT_H__
 #define __NS_SVGGRAPHICELEMENT_H__
 
 #include "gfxMatrix.h"
-#include "nsIDOMSVGLocatable.h"
-#include "nsIDOMSVGTransformable.h"
-#include "nsSVGElement.h"
+#include "SVGTransformableElement.h"
 #include "SVGAnimatedTransformList.h"
 #include "DOMSVGTests.h"
 
-typedef nsSVGElement nsSVGGraphicElementBase;
+typedef mozilla::dom::SVGTransformableElement nsSVGGraphicElementBase;
+
+#define MOZILLA_SVGGRAPHICSELEMENT_IID \
+  { 0xe57b8fe5, 0x9088, 0x446e, \
+    {0xa1, 0x87, 0xd1, 0xdb, 0xbb, 0x58, 0xce, 0xdc}}
 
 class nsSVGGraphicElement : public nsSVGGraphicElementBase,
-                            public DOMSVGTests,
-                            public nsIDOMSVGTransformable // : nsIDOMSVGLocatable
+                            public DOMSVGTests
 {
 protected:
   nsSVGGraphicElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   
 public:
   // interfaces:  
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_NSIDOMSVGLOCATABLE
-  NS_DECL_NSIDOMSVGTRANSFORMABLE
+  NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_SVGGRAPHICSELEMENT_IID)
+  NS_FORWARD_NSIDOMSVGLOCATABLE(mozilla::dom::SVGLocatableElement::)
+  NS_FORWARD_NSIDOMSVGTRANSFORMABLE(mozilla::dom::SVGTransformableElement::)
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
                                       int32_t aModType) const;
 
 
@@ -45,17 +47,22 @@ public:
 
   virtual mozilla::SVGAnimatedTransformList*
     GetAnimatedTransformList(uint32_t aFlags = 0);
   virtual nsIAtom* GetTransformListAttrName() const {
     return nsGkAtoms::transform;
   }
 
 protected:
+  virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap) MOZ_OVERRIDE;
+
   // nsSVGElement overrides
 
   nsAutoPtr<mozilla::SVGAnimatedTransformList> mTransforms;
 
   // XXX maybe move this to property table, to save space on un-animated elems?
   nsAutoPtr<gfxMatrix> mAnimateMotionTransform;
 };
 
+NS_DEFINE_STATIC_IID_ACCESSOR(nsSVGGraphicElement,
+                              MOZILLA_SVGGRAPHICSELEMENT_IID)
+
 #endif // __NS_SVGGRAPHICELEMENT_H__
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -604,16 +604,21 @@ DOMInterfaces = {
 
 'SVGElement': {
     'nativeType': 'nsSVGElement',
     'hasXPConnectImpls': True,
     'hasInstanceInterface': 'nsIDOMSVGElement',
     'resultNotAddRefed': ['ownerSVGElement', 'style']
 },
 
+'SVGGraphicsElement': {
+    'hasXPConnectImpls': True,
+    'nativeType': 'nsSVGGraphicElement'
+},
+
 'SVGLocatableElement': {
     'hasXPConnectImpls': True,
     'concrete': False
 },
 
 'SVGLengthList': {
     'nativeType': 'mozilla::DOMSVGLengthList',
     'headerFile': 'DOMSVGLengthList.h',
new file mode 100644
--- /dev/null
+++ b/dom/webidl/SVGGraphicsElement.webidl
@@ -0,0 +1,16 @@
+/* -*- 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 SVGGraphicsElement : SVGTransformableElement {
+};
+
+SVGGraphicsElement implements SVGTests;
new file mode 100644
--- /dev/null
+++ b/dom/webidl/SVGTests.webidl
@@ -0,0 +1,24 @@
+/* -*- 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 SVGStringList;
+
+[NoInterfaceObject]
+interface SVGTests {
+
+  readonly attribute SVGStringList requiredFeatures;
+  readonly attribute SVGStringList requiredExtensions;
+  readonly attribute SVGStringList systemLanguage;
+
+  boolean hasExtension(DOMString extension);
+};
+
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -100,30 +100,32 @@ webidl_files = \
   SVGAnimatedAngle.webidl \
   SVGAnimatedBoolean.webidl \
   SVGAnimatedLengthList.webidl \
   SVGAnimatedNumberList.webidl \
   SVGAnimatedPreserveAspectRatio.webidl \
   SVGAnimatedTransformList.webidl \
   SVGDescElement.webidl \
   SVGElement.webidl \
+  SVGGraphicsElement.webidl \
   SVGLengthList.webidl \
   SVGLocatableElement.webidl \
   SVGMatrix.webidl \
   SVGMetadataElement.webidl \
   SVGMPathElement.webidl \
   SVGNumberList.webidl \
   SVGPathSeg.webidl \
   SVGPathSegList.webidl \
   SVGPoint.webidl \
   SVGPointList.webidl \
   SVGPreserveAspectRatio.webidl \
   SVGScriptElement.webidl \
   SVGStopElement.webidl \
   SVGStyleElement.webidl \
+  SVGTests.webidl \
   SVGTitleElement.webidl \
   SVGTransform.webidl \
   SVGTransformableElement.webidl \
   SVGTransformList.webidl \
   SVGURIReference.webidl \
   Text.webidl \
   TextDecoder.webidl \
   TextEncoder.webidl \