1.1 --- a/tests/svg_events.py Fri Apr 06 21:45:01 2007 +0000
1.2 +++ b/tests/svg_events.py Fri Apr 06 21:45:35 2007 +0000
1.3 @@ -17,7 +17,9 @@
1.4 <svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"
1.5 xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 500 500">
1.6 <script type="application/x-python" xlink:href=""/>
1.7 - <rect xml:id="therect" x="0" y="0" width="100" height="100"/>
1.8 + <g xml:id="group1" fill="red">
1.9 + <rect xml:id="therect" x="0" y="0" width="100" height="100"/>
1.10 + </g>
1.11 </svg>
1.12 """
1.13
1.14 @@ -29,6 +31,8 @@
1.15 document = scriptElement.ownerDocument
1.16 rect = document.getElementById("therect")
1.17 rect.addEventListenerNS(libxml2dom.events.XML_EVENTS_NAMESPACE, "click", Handler(), 0, None)
1.18 + g = document.getElementById("group1")
1.19 + g.addEventListenerNS(libxml2dom.events.XML_EVENTS_NAMESPACE, "click", Handler(), 0, None)
1.20
1.21 class Impl(libxml2dom.svg.SVGImplementation):
1.22
1.23 @@ -42,23 +46,26 @@
1.24 "An event handler."
1.25
1.26 def handleEvent(self, event):
1.27 - print "Event handled with detail", event.detail
1.28 + print "Event handled in", event.currentTarget.localName, "in phase", event.eventPhase
1.29
1.30 d = libxml2dom.svg.parseString(s, impl=Impl())
1.31 rect = d.getElementById("therect")
1.32 event = d.createEvent("MouseEvent")
1.33 event.initEventNS(libxml2dom.events.XML_EVENTS_NAMESPACE, "click", 1, 1)
1.34 event.detail = "1"
1.35 -rect.dispatchEvent(event)
1.36 +d.sendEventToTarget(event, rect)
1.37
1.38 s2 = """\
1.39 <svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"
1.40 xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 500 500"
1.41 xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:exns="http://example.org/exNS">
1.42 <script xml:id="init" type="application/x-python" xlink:href=""/>
1.43 - <rect xml:id="therect" x="0" y="0" width="100" height="100">
1.44 - <handler type="application/x-python" ev:event="click" xlink:href="#init" exns:listenerClass="Handler"/>
1.45 - </rect>
1.46 + <g xml:id="group1" fill="red">
1.47 + <handler type="application/x-python" ev:event="click" ev:phase="capture" xlink:href="#init" exns:listenerClass="Handler"/>
1.48 + <rect xml:id="therect" x="0" y="0" width="100" height="100">
1.49 + <handler type="application/x-python" ev:event="click" xlink:href="#init" exns:listenerClass="Handler"/>
1.50 + </rect>
1.51 + </g>
1.52 </svg>
1.53 """
1.54
1.55 @@ -87,6 +94,6 @@
1.56 event2 = d2.createEvent("MouseEvent")
1.57 event2.initEventNS(None, "click", 1, 1)
1.58 event2.detail = "1"
1.59 -rect2.dispatchEvent(event2)
1.60 +d2.sendEventToTarget(event2, rect2)
1.61
1.62 # vim: tabstop=4 expandtab shiftwidth=4