struct-dom-15-f-isvalid.html (6021B)
1 <!DOCTYPE html> 2 <html lang='en'> 3 <head> 4 <title>struct-dom-15-f-manual.svg</title> 5 <meta charset='utf-8'> 6 </head> 7 <body> 8 <h1>Source SVG: struct-dom-15-f-manual.svg</h1> 9 <svg id="svg-root" width="100%" height="100%" 10 viewBox="0 0 480 360" xmlns="http://www.w3.org/2000/svg" 11 xmlns:xlink="http://www.w3.org/1999/xlink" onload="runTest()"> 12 <!--======================================================================--> 13 <!--= Copyright 2008 World Wide Web Consortium, (Massachusetts =--> 14 <!--= Institute of Technology, European Research Consortium for =--> 15 <!--= Informatics and Mathematics (ERCIM), Keio University). =--> 16 <!--= All Rights Reserved. =--> 17 <!--= See http://www.w3.org/Consortium/Legal/. =--> 18 <!--======================================================================--> 19 20 <title id="test-title">$RCSfile: struct-dom-15-f.svg,v $</title> 21 <defs> 22 <font-face 23 font-family="SVGFreeSansASCII" 24 unicode-range="U+0-7F"> 25 <font-face-src> 26 <font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/> 27 </font-face-src> 28 </font-face> 29 </defs> 30 <g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18"> 31 32 <defs> 33 <circle id="defscircle1" cx="240" cy="180" r="25" onclick="verifyDefs1(evt)" fill="red"/> 34 <circle id="defscircle2" cx="240" cy="180" r="25" onclick="verifyDefs2(evt)" fill="red"/> 35 36 <script><![CDATA[ 37 function verifyDefs1(e) 38 { 39 var dc = document.getElementById("defscircle1"); 40 if (e.target === e.currentTarget && // Assertion: the target and currentTarget are the same 41 e.target === dc) // Assertion: the target is the 'circle' element since we dispatched the event directly to it, not to an SVGElementInstance 42 { 43 dc.setAttribute("fill", "lime"); 44 } 45 } 46 47 // checks that event.target and event.currentTarget point to an SVGElementInstance (the instanceRoot) 48 function verifyDefs2(e) 49 { 50 var instance = document.getElementById("use2").instanceRoot; 51 if (e.target === e.currentTarget && // Assertion: the target and currentTarget are the same 52 e.target === instance) // Assertion: the target is SVGElementInstance corresponding to the 'circle' element with id="defscircle2", since we dispatched the event to that instance 53 { 54 instance.correspondingElement.setAttribute("fill", "lime"); 55 } 56 } 57 58 function verify(e) 59 { 60 var c = document.getElementById("circle"); 61 if (e.target === e.currentTarget && // Assertion: the target and currentTarget are the same 62 e.target === c) // Assertion: the target is the 'circle' element since we dispatched the event directly to it 63 { 64 c.setAttribute("fill", "lime"); 65 } 66 } 67 68 function dispatchMouseClick(target) 69 { 70 var mouseevent = document.createEvent("MouseEvents"); 71 mouseevent.initMouseEvent("click", 72 true, // canbubble 73 true, // cancellable 74 document.defaultView, // the AbstractView 75 1, // mouseclick count 76 0, // screen x coordinate 77 0, // screen y coordinate 78 0, // client x coordinate 79 0, // client y coordinate 80 false, // ctrlKey 81 false, // altKey 82 false, // shiftKey 83 false, // metaKey 84 0, // mousebutton 85 null); // related target 86 target.dispatchEvent(mouseevent); 87 } 88 89 function runTest() 90 { 91 // test simple circle inside <defs> 92 try { 93 var defsCircle = document.getElementById("defscircle1"); 94 dispatchMouseClick(defsCircle); 95 } catch(e) {} 96 97 // test SVGElementInstance 98 try { 99 var elementInstance2 = document.getElementById("use2").instanceRoot; 100 dispatchMouseClick(elementInstance2); 101 } catch(e) {} 102 103 // test simple circle outside of <defs> 104 try { 105 var circle = document.getElementById("circle"); 106 dispatchMouseClick(circle); 107 } catch(e) {} 108 } 109 ]]></script> 110 </defs> 111 112 <circle id="circle" cx="240" cy="180" r="25" onclick="verify(evt)" fill="red"/> 113 114 <use id="use1" xlink:href="#defscircle1" transform="translate(80,0)"/> 115 <use id="use2" xlink:href="#defscircle2" transform="translate(-80,0)"/> 116 <use id="use3" xlink:href="#defsg1"/> 117 </g> 118 <g font-family="SVGFreeSansASCII,sans-serif" font-size="32"> 119 <text id="revision" x="10" y="340" stroke="none" 120 fill="black">$Revision: 1.3 $</text> 121 </g> 122 <rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000"/> 123 <!-- comment out this watermark once the test is approved --> 124 <!--<g id="draft-watermark"> 125 <rect x="1" y="1" width="478" height="20" fill="red" stroke="black" stroke-width="1"/> 126 <text font-family="SVGFreeSansASCII,sans-serif" font-weight="bold" font-size="20" x="240" 127 text-anchor="middle" y="18" stroke-width="0.5" stroke="black" fill="white">DRAFT</text> 128 </g>--> 129 </svg> 130 </body> 131 </html>