Hi Cameron, Thanks for the reply. I'd gone back to the SVG spec and tried to understand how the <use> element works with events. I'd gotten as far as the SVGOMUseShadowRoot object with a little toying, but couldn't figure out what to do with it from there. I was looking for the <g> element that the spec describes and thought it was odd I couldn't cast the SVGOMUseShadowRoot to an Element or anything like that. Your suggestion works just fine and I'm able to run my listeners on the DOM tree without any problem. Michael
________________________________ From: Cameron McCormack [mailto:[email protected]] Sent: Thu 5/21/2009 8:55 PM To: [email protected] Subject: Re: Clarification with pointer-events and use? Hi Michael. Bishop, Michael W. CTR USJFCOM JFL: > I think I've seen something like this before, but I haven't been able > to find it in the archives. Here's what's going on. I have some SVG > defined in <defs>. Elsewhere in the document, I have a <g> with the > attribute "pointer-events" set to visible. Within this <g>, I have > <use> elements that reference the SVG found in <defs>. The <use> > elements have further attributes on them. > > I'm registering a DOM "mouse-down" listener on the <g> tag. Pointer > events are being generated, but the event "target" is the SVG defined > in <defs> and I can't access the unique attributes found on my <use> > element. Is there anyway to discover information about the <use> > element instead of the SVG it "uses"? > > <defs> > <circle id="circle" ... /> > </defs> > > <g pointer-events="visible"> > <use xlink:href="#circle" id="12345"/> > </g> > > I want to discover the "id" attribute on the <use> element, but I'm > getting the <circle> as the event target. So according to the spec, event flow should go like this: SVGGElement CAPTURING SVGUseElement CAPTURING SVGElementInstance corresponding to the <circle> AT_TARGET SVGUseElement BUBBLING SVGGElement BUBBLING Batik doesn't implement the SVGElementInstance stuff; what it actually does is actually close the <use>d content into a hidden tree and dispatches events to those. So the <circle> that the event is dispatched to in the AT_TARGET phase is actually a copy of the <circle> element from your document. Per spec, if you wanted to find out which <use> element you're in, you'd do: event.target.correspondingUseElement since event.target would be the SVGElementInstance object. But that won't work at the moment. Batik creates a fake DOM node to be the root of the cloned shadow tree, and it has a pointer to the <use> element that it's the root of the shadow tree for. So you can do this: var n = event.target; while (n.parentNode) { n = n.parentNode; } // here, n will be an org.apache.batik.dom.svg.SVGOMUseShadowRoot n = n.getCSSParentNode(); // now n will be the <use> element This is non-standard of course, but it should suffice until the proper element instance tree is implemented. -- Cameron McCormack ? http://mcc.id.au/ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
<<winmail.dat>>
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
