Bug 620295 - Give SVGAElement objects an href property in JS r=jwatt a=roc

This commit is contained in:
Cameron McCormack 2010-12-22 16:30:38 +13:00
parent 9ea103ff65
commit 198eef8656
9 changed files with 158 additions and 1 deletions

View File

@ -63,11 +63,12 @@ NS_IMPL_RELEASE_INHERITED(nsSVGAElement, nsSVGAElementBase)
DOMCI_NODE_DATA(SVGAElement, nsSVGAElement)
NS_INTERFACE_TABLE_HEAD(nsSVGAElement)
NS_NODE_INTERFACE_TABLE6(nsSVGAElement,
NS_NODE_INTERFACE_TABLE7(nsSVGAElement,
nsIDOMNode,
nsIDOMElement,
nsIDOMSVGElement,
nsIDOMSVGAElement,
nsIDOMSVGURIReference,
nsILink,
Link)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAElement)

View File

@ -83,6 +83,12 @@ _TEST_FILES = \
test_viewport.html \
zoom-helper.svg \
test_zoom.xhtml \
test_a_href_01.xhtml \
test_a_href_02.xhtml \
a_href_destination.svg \
a_href_helper_01.svg \
a_href_helper_02_03.svg \
a_href_helper_04.svg \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="green"/>
</svg>

After

Width:  |  Height:  |  Size: 98 B

View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<a id="a" xlink:href="a_href_destination.svg">
<rect width="100%" height="100%"/>
</a>
</svg>

After

Width:  |  Height:  |  Size: 186 B

View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<a id="a" xlink:href="initial.svg">
<rect width="100%" height="100%"/>
</a>
</svg>

After

Width:  |  Height:  |  Size: 175 B

View File

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<a id="a" xlink:href="initial.svg">
<set attributeName="xlink:href" to="a_href_destination.svg"/>
<rect width="100%" height="100%"/>
</a>
</svg>

After

Width:  |  Height:  |  Size: 241 B

View File

@ -0,0 +1,92 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=620295
-->
<head>
<title>Test that activating SVG 'a' elements navigate to their xlink:href</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=620295">Mozilla Bug 620295</a>
<p id="display"></p>
<div id="content" style="visibility: hidden">
<iframe id="iframe1" src="a_href_helper_01.svg" onload="frameLoaded()"></iframe>
<iframe id="iframe2" src="a_href_helper_02_03.svg" onload="frameLoaded()"></iframe>
<iframe id="iframe3" src="a_href_helper_02_03.svg" onload="frameLoaded()"></iframe>
<iframe id="iframe4" src="a_href_helper_04.svg" onload="frameLoaded()"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
var testCount = 4;
var didWindowLoad = false;
var frameLoadCount = 0;
var navigationCount = 0;
function endsWith(s1, s2) {
s1 = String(s1);
return s1.length >= s2.length && s1.substring(s1.length - s2.length) == s2;
}
function windowLoaded() {
didWindowLoad = true;
doNavigationIfReady();
}
function frameLoaded() {
frameLoadCount++;
doNavigationIfReady();
}
function doNavigationIfReady() {
if (didWindowLoad && frameLoadCount == testCount) {
doNavigation();
}
}
function doNavigation() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
// Test clicking on an unmodified <a>.
doNavigationTest(1, "a_href_helper_01.svg");
// Test clicking on an <a> whose xlink:href is modified by assigning to href.baseVal.
doNavigationTest(2, "a_href_helper_02_03.svg", function(a) { a.href.baseVal = "a_href_destination.svg"; });
// Test clicking on an <a> whose xlink:href is modified by a setAttributeNS call.
doNavigationTest(3, "a_href_helper_02_03.svg", function(a) { a.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "a_href_destination.svg"); });
// Test clicking on an <a> whose xlink:href is modified by animation.
doNavigationTest(4, "a_href_helper_04.svg");
}
function doNavigationTest(testNumber, initialHref, f) {
var iframe = document.getElementById("iframe" + testNumber);
var a = iframe.contentDocument.getElementById("a");
ok(endsWith(iframe.contentWindow.location, initialHref), "Initial href of test " + testNumber);
iframe.onload = function() {
ok(endsWith(iframe.contentWindow.location, "a_href_destination.svg"), "Final href of test " + testNumber);
if (++navigationCount == testCount) {
SimpleTest.finish();
}
};
if (f) {
f(a);
}
dispatchClickEvent(a);
}
function dispatchClickEvent(element) {
var event = element.ownerDocument.createEvent("MouseEvent");
event.initMouseEvent("click", true, true, element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false,
false, false, 0, null);
element.dispatchEvent(event);
}
window.onload = windowLoaded;
]]></script>
</pre>
</body>
</html>

View File

@ -0,0 +1,38 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=620295
-->
<head>
<title>Test that the href property reflects xlink:href="" on 'a' elements</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=620295">Mozilla Bug 620295</a>
<p id="display"></p>
<div id="content">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<a id="a" xlink:href="a"/>
</svg>
</div>
<pre id="test">
<script><![CDATA[
var a = document.getElementById("a");
// Initial attribute value should be reflected in the href property
is(a.href.baseVal, "a", "Initial property value");
// Updated attribute value should be reflected in the href property
a.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "b");
is(a.href.baseVal, "b", "Updated property value");
// Modifying the href property should cause the attribute to be updated
a.href.baseVal = "c";
is(a.getAttributeNS("http://www.w3.org/1999/xlink", "href"), "c", "Updated attribute value");
]]></script>
</pre>
</body>
</html>

View File

@ -3055,6 +3055,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(SVGAElement, nsIDOMSVGAElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGAElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGURIReference)
DOM_CLASSINFO_SVG_GRAPHIC_ELEMENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END