Bug 589640 part 1. Add an SVGUnknownElement, like HTMLUnknownElement, so random elements in the SVG namespace create SVGElements (instead of XML Elements). r=bzbarsky

This commit is contained in:
Brian O'Keefe 2011-12-08 01:32:11 -05:00
parent e7ad553215
commit 77aa894da7
7 changed files with 220 additions and 2 deletions

View File

@ -119,6 +119,7 @@ CPPSRCS = \
nsSVGTextPathElement.cpp \
nsSVGTextPositioningElement.cpp \
nsSVGTitleElement.cpp \
nsSVGUnknownElement.cpp \
nsSVGUseElement.cpp \
nsSVGViewBox.cpp \
SVGAnimatedLengthList.cpp \

View File

@ -239,6 +239,10 @@ 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)
@ -379,7 +383,7 @@ NS_NewSVGElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
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);
}

View File

@ -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)

View File

@ -84,6 +84,7 @@ _TEST_FILES = \
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 \

View File

@ -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>

View File

@ -1151,6 +1151,8 @@ static nsDOMClassInfoData sClassInfoData[] = {
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)
@ -3460,6 +3462,10 @@ nsDOMClassInfo::Init()
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)

View File

@ -293,6 +293,7 @@ DOMCI_CLASS(SVGTextElement)
DOMCI_CLASS(SVGTextPathElement)
DOMCI_CLASS(SVGTitleElement)
DOMCI_CLASS(SVGTSpanElement)
DOMCI_CLASS(SVGUnknownElement)
DOMCI_CLASS(SVGUseElement)
// other SVG classes