Bug 589640 part 1. Add an SVGUnknownElement, like HTMLUnknownElement, so random elements in the SVG namespace create SVGElements (instead of XML Elements). r=bzbarsky
authorBrian O'Keefe <bokeefe@alum.wpi.edu>
Thu, 08 Dec 2011 01:32:11 -0500
changeset 82235 5c73dc22592e811649976319c2ec92a8ff2e1059
parent 82234 af91b8af10ddbaeef4666a1b007b85bdadf7d6d7
child 82236 6c1506a4b2010b2a2b1ad518e5d3af18693b6b70
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs589640
milestone11.0a1
Bug 589640 part 1. Add an SVGUnknownElement, like HTMLUnknownElement, so random elements in the SVG namespace create SVGElements (instead of XML Elements). r=bzbarsky
content/svg/content/src/Makefile.in
content/svg/content/src/nsSVGElementFactory.cpp
content/svg/content/src/nsSVGUnknownElement.cpp
content/svg/content/test/Makefile.in
content/svg/content/test/test_SVG_namespace_ids.html
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
--- a/content/svg/content/src/Makefile.in
+++ b/content/svg/content/src/Makefile.in
@@ -114,16 +114,17 @@ CPPSRCS		= \
 		nsSVGSwitchElement.cpp \
 		nsSVGSymbolElement.cpp \
 		nsSVGTSpanElement.cpp \
 		nsSVGTextContentElement.cpp \
 		nsSVGTextElement.cpp \
 		nsSVGTextPathElement.cpp \
 		nsSVGTextPositioningElement.cpp \
 		nsSVGTitleElement.cpp \
+		nsSVGUnknownElement.cpp \
 		nsSVGUseElement.cpp \
 		nsSVGViewBox.cpp \
 		SVGAnimatedLengthList.cpp \
 		SVGAnimatedNumberList.cpp \
 		SVGAnimatedPathSegList.cpp \
 		SVGAnimatedPointList.cpp \
 		SVGAnimatedPreserveAspectRatio.cpp \
 		SVGAnimatedTransformList.cpp \
--- a/content/svg/content/src/nsSVGElementFactory.cpp
+++ b/content/svg/content/src/nsSVGElementFactory.cpp
@@ -235,16 +235,20 @@ NS_NewSVGAnimateMotionElement(nsIContent
 nsresult
 NS_NewSVGMpathElement(nsIContent **aResult,
                       already_AddRefed<nsINodeInfo> aNodeInfo);
 nsresult
 NS_NewSVGSetElement(nsIContent **aResult,
                     already_AddRefed<nsINodeInfo> aNodeInfo);
 
 nsresult
+NS_NewSVGUnknownElement(nsIContent **aResult,
+                        already_AddRefed<nsINodeInfo> aNodeInfo);
+
+nsresult
 NS_NewSVGElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
                  FromParser aFromParser)
 {
   static const char kSVGStyleSheetURI[] = "resource://gre/res/svg.css";
 
   // this bit of code is to load svg.css on demand
   nsIDocument *doc = aNodeInfo.get()->GetDocument();
   if (doc)
@@ -374,12 +378,12 @@ NS_NewSVGElement(nsIContent** aResult, a
     if (name == nsGkAtoms::animateMotion)
       return NS_NewSVGAnimateMotionElement(aResult, aNodeInfo);
     if (name == nsGkAtoms::mpath)
       return NS_NewSVGMpathElement(aResult, aNodeInfo);
     if (name == nsGkAtoms::set)
       return NS_NewSVGSetElement(aResult, aNodeInfo);
   }
 
-  // if we don't know what to create, just create a standard xml element:
-  return NS_NewXMLElement(aResult, aNodeInfo);
+  // if we don't know what to create, just create a standard svg element:
+  return NS_NewSVGUnknownElement(aResult, aNodeInfo);
 }
 
new file mode 100644
--- /dev/null
+++ b/content/svg/content/src/nsSVGUnknownElement.cpp
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla SVG project.
+ *
+ * The Initial Developer of the Original Code is Brian O'Keefe.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Brian O'Keefe <bokeefe@alum.wpi.edu>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsSVGElement.h"
+#include "nsIDOMSVGElement.h"
+
+using namespace mozilla;
+
+typedef nsSVGElement nsSVGUnknownElementBase;
+
+class nsSVGUnknownElement : public nsSVGUnknownElementBase,
+                            public nsIDOMSVGElement
+{
+protected:
+  friend nsresult NS_NewSVGUnknownElement(nsIContent **aResult,
+                                          already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsSVGUnknownElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+
+public:
+  // interfaces:
+  NS_DECL_ISUPPORTS_INHERITED
+  
+  // xxx I wish we could use virtual inheritance
+  NS_FORWARD_NSIDOMNODE(nsSVGUnknownElementBase::)
+  NS_FORWARD_NSIDOMELEMENT(nsSVGUnknownElementBase::)
+  NS_FORWARD_NSIDOMSVGELEMENT(nsSVGUnknownElementBase::)
+
+  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
+
+  virtual nsXPCClassInfo* GetClassInfo();
+};
+
+NS_IMPL_NS_NEW_SVG_ELEMENT(Unknown)
+
+//----------------------------------------------------------------------
+// nsISupports methods
+
+NS_IMPL_ADDREF_INHERITED(nsSVGUnknownElement, nsSVGUnknownElementBase)
+NS_IMPL_RELEASE_INHERITED(nsSVGUnknownElement, nsSVGUnknownElementBase)
+
+DOMCI_NODE_DATA(SVGUnknownElement, nsSVGUnknownElement)
+
+NS_INTERFACE_TABLE_HEAD(nsSVGUnknownElement)
+  NS_NODE_INTERFACE_TABLE3(nsSVGUnknownElement, nsIDOMNode, nsIDOMElement,
+                           nsIDOMSVGElement)
+NS_INTERFACE_MAP_END_INHERITING(nsSVGUnknownElementBase)
+//----------------------------------------------------------------------
+// Implementation
+
+nsSVGUnknownElement::nsSVGUnknownElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  : nsSVGUnknownElementBase(aNodeInfo)
+{
+}
+
+NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGUnknownElement)
--- a/content/svg/content/test/Makefile.in
+++ b/content/svg/content/test/Makefile.in
@@ -79,16 +79,17 @@ include $(topsrcdir)/config/rules.mk
 		test_pointer-events.xhtml \
 		test_pointer-events-2.xhtml \
 		test_scientific.html \
 		scientific-helper.svg \
 		test_SVGAnimatedImageSMILDisabled.html \
 		animated-svg-image-helper.html \
 		animated-svg-image-helper.svg \
 		test_stroke-linecap-hit-testing.xhtml \
+		test_SVG_namespace_ids.html \
 		test_SVGLengthList.xhtml \
 		test_SVGLengthList-2.xhtml \
 		test_SVGMatrix.xhtml \
 		test_SVGPathSegList.xhtml \
 		test_SVGStyleElement.xhtml \
 		test_SVGTransformList.xhtml \
 		test_SVGTransformListAddition.xhtml \
 		test_SVGxxxList.xhtml \
new file mode 100644
--- /dev/null
+++ b/content/svg/content/test/test_SVG_namespace_ids.html
@@ -0,0 +1,116 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=589640
+-->
+<head>
+  <title>Test for Bug 589640</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script class="testbody" type="application/javascript">
+    SimpleTest.waitForExplicitFinish();
+
+    function debug(message) {
+      document.getElementById('debug').appendChild(document.createTextNode(message + "\n"));
+    }
+
+    function runTests()
+    {
+      var svg = document.getElementById('svg1');
+      for (var el = 0; el < svg.children.length; el++) {
+        is(svg.children[el].id, svg.children[el].localName, svg.children[el].localName + " in the SVG namespace has a valid ID");
+        debug(svg.children[el].localName + '.id = ' + svg.children[el].id);
+      }
+
+      SimpleTest.finish();
+    }
+  </script>
+</head>
+<body onload="runTests()">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=589640">Mozilla Bug 589640</a>
+<pre id="debug"></pre>
+<!-- NOTE: This test relies on the ids being the same as the element names -->
+<svg id="svg1">
+  <a id="a" />
+  <altGlyph id="altGlyph" />
+  <altGlyphDef id="altGlyphDef" />
+  <altGlyphItem id="altGlyphItem" />
+  <animate id="animate" />
+  <animateColor id="animateColor" />
+  <animateMotion id="animateMotion" />
+  <animateTransform id="animateTransform" />
+  <circle id="circle" />
+  <clipPath id="clipPath" />
+  <color-profile id="color-profile" />
+  <cursor id="cursor" />
+  <defs id="defs" />
+  <desc id="desc" />
+  <ellipse id="ellipse" />
+  <feBlend id="feBlend" />
+  <feColorMatrix id="feColorMatrix" />
+  <feComponentTransfer id="feComponentTransfer" />
+  <feComposite id="feComposite" />
+  <feConvolveMatrix id="feConvolveMatrix" />
+  <feDiffuseLighting id="feDiffuseLighting" />
+  <feDisplacementMap id="feDisplacementMap" />
+  <feDistantLight id="feDistantLight" />
+  <feFlood id="feFlood" />
+  <feFuncA id="feFuncA" />
+  <feFuncB id="feFuncB" />
+  <feFuncG id="feFuncG" />
+  <feFuncR id="feFuncR" />
+  <feGaussianBlur id="feGaussianBlur" />
+  <feImage id="feImage" />
+  <feMerge id="feMerge" />
+  <feMergeNode id="feMergeNode" />
+  <feMorphology id="feMorphology" />
+  <feOffset id="feOffset" />
+  <fePointLight id="fePointLight" />
+  <feSpecularLighting id="feSpecularLighting" />
+  <feSpotLight id="feSpotLight" />
+  <feTile id="feTile" />
+  <feTurbulence id="feTurbulence" />
+  <filter id="filter" />
+  <font id="font" />
+  <font-face id="font-face" />
+  <font-face-format id="font-face-format" />
+  <font-face-name id="font-face-name" />
+  <font-face-src id="font-face-src" />
+  <font-face-uri id="font-face-uri" />
+  <foreignObject id="foreignObject" />
+  <g id="g" />
+  <glyph id="glyph" />
+  <glyphRef id="glyphRef" />
+  <hkern id="hkern" />
+  <image id="image" />
+  <line id="line" />
+  <linearGradient id="linearGradient" />
+  <marker id="marker" />
+  <mask id="mask" />
+  <metadata id="metadata" />
+  <missing-glyph id="missing-glyph" />
+  <mpath id="mpath" />
+  <path id="path" />
+  <pattern id="pattern" />
+  <polygon id="polygon" />
+  <polyline id="polyline" />
+  <radialGradient id="radialGradient" />
+  <rect id="rect" />
+  <script id="script" />
+  <set id="set" />
+  <stop id="stop" />
+  <style id="style" />
+  <svg id="svg" />
+  <switch id="switch" />
+  <symbol id="symbol" />
+  <text id="text" />
+  <textPath id="textPath" />
+  <title id="title" />
+  <tref id="tref" />
+  <tspan id="tspan" />
+  <use id="use" />
+  <view id="view" />
+  <vkern id="vkern" />
+</svg>
+</body>
+</html>
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -1146,16 +1146,18 @@ static nsDOMClassInfoData sClassInfoData
   NS_DEFINE_CLASSINFO_DATA(SVGTextElement, nsElementSH,
                            ELEMENT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(SVGTextPathElement, nsElementSH,
                            ELEMENT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(SVGTitleElement, nsElementSH,
                            ELEMENT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(SVGTSpanElement, nsElementSH,
                            ELEMENT_SCRIPTABLE_FLAGS)
+  NS_DEFINE_CLASSINFO_DATA_WITH_NAME(SVGUnknownElement, SVGElement, nsElementSH,
+                                     ELEMENT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(SVGUseElement, nsElementSH,
                            ELEMENT_SCRIPTABLE_FLAGS)
 
   // other SVG classes
   NS_DEFINE_CLASSINFO_DATA(SVGAngle, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(SVGAnimatedAngle, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
@@ -3455,16 +3457,20 @@ nsDOMClassInfo::Init()
   DOM_CLASSINFO_MAP_BEGIN(SVGTSpanElement, nsIDOMSVGTSpanElement)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGTextPositioningElement)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGTextContentElement)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGStylable)
     DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
 
+  DOM_CLASSINFO_MAP_BEGIN(SVGUnknownElement, nsIDOMSVGElement)
+    DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
+  DOM_CLASSINFO_MAP_END
+
   DOM_CLASSINFO_MAP_BEGIN(SVGUseElement, nsIDOMSVGUseElement)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGUseElement)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGURIReference)
     DOM_CLASSINFO_SVG_GRAPHIC_ELEMENT_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
 
   // other SVG classes
 
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -288,16 +288,17 @@ DOMCI_CLASS(SVGStopElement)
 DOMCI_CLASS(SVGStyleElement)
 DOMCI_CLASS(SVGSVGElement)
 DOMCI_CLASS(SVGSwitchElement)
 DOMCI_CLASS(SVGSymbolElement)
 DOMCI_CLASS(SVGTextElement)
 DOMCI_CLASS(SVGTextPathElement)
 DOMCI_CLASS(SVGTitleElement)
 DOMCI_CLASS(SVGTSpanElement)
+DOMCI_CLASS(SVGUnknownElement)
 DOMCI_CLASS(SVGUseElement)
 
 // other SVG classes
 DOMCI_CLASS(SVGAngle)
 DOMCI_CLASS(SVGAnimatedAngle)
 DOMCI_CLASS(SVGAnimatedBoolean)
 DOMCI_CLASS(SVGAnimatedEnumeration)
 DOMCI_CLASS(SVGAnimatedInteger)