Bug 44227 - Event of a Use element points to SVGElementInstance
Summary: Event of a Use element points to SVGElementInstance
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-18 19:19 PDT by Claus Colloseus
Modified: 2015-01-20 08:20 PST (History)
2 users (show)

See Also:


Attachments
Test case (1.37 KB, image/svg+xml)
2010-08-18 19:19 PDT, Claus Colloseus
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Claus Colloseus 2010-08-18 19:19:23 PDT
Created attachment 64802 [details]
Test case

(actually tested with Safari 5 on Windows and Epiphany 2.30 on Linux)

Set an event listener on a Use element, for example like this:
<use id="useElement" onclick="alert(evt.target.toString())"
  xlink:href="#sourceElement" />

The reported target object should be [object SVGUseElement]
That would result in evt.target.id="useElement"

Instead, you get [object SVGElementInstance]
As a consequence, evt.target.id=undefined and only evt.target.correspondingUseElement="useElement"

Comment: The SVG 1.1 spec states "If event attributes are assigned to referenced elements, then the actual target for the event will be the SVGElementInstance object within the "instance tree" corresponding to the given referenced element."
This could be misunderstood as if an event attribute on a _referencing_ <use> element should also point to the shadow tree, but what actually is said there only concerns the event attributes on the _referenced_ element.

The Attachment is a test file with several different constellations of <use> elements and event listener attachments. All of them end up with [object SVGElementInstance], even if the event attribute is on a parent element of the <use>.
Comment 1 Nikolas Zimmermann 2012-03-01 06:03:15 PST
(In reply to comment #0)
> Created an attachment (id=64802) [details]
> Test case
> 
> (actually tested with Safari 5 on Windows and Epiphany 2.30 on Linux)
> 
> Set an event listener on a Use element, for example like this:
> <use id="useElement" onclick="alert(evt.target.toString())"
>   xlink:href="#sourceElement" />
> 
> The reported target object should be [object SVGUseElement]
> That would result in evt.target.id="useElement"
An SVGUseElement is never clickable, it's the sourceElement it referenced, which gets clicked - so its SVGELementInstance receives the event.

Opera handles the testcase the same way, only SVGElementInstances receive events.

Quoting SVG 1.1:
If event attributes are assigned to referenced elements, then the actual target for the event will be the SVGElementInstance object within the "instance tree" corresponding to the given referenced element.

The event handling for the non-exposed tree works as if the referenced element had been textually included as a deeply cloned child of the ‘use’ element, except that events are dispatched to the SVGElementInstance objects. The event's target and currentTarget attributes are set to the SVGElementInstance that corresponds to the target and current target elements in the referenced subtree. An event propagates through the exposed and non-exposed portions of the tree in the same manner as it would in the regular document tree: first going from the root element to the ‘use’ element and then through non-exposed tree elements in the capture phase, followed by the target phase at the target of the event, then bubbling back through non-exposed tree to the use element and then back through regular tree to the root element in bubbling phase.
--

There's no way you could click a SVGUseElement, except sending such an event to the <use> element manually via dispatchEvent - in that case the target would be SVGUseElement.

> The Attachment is a test file with several different constellations of <use> elements and event listener attachments. All of them end up with [object SVGElementInstance], even if the event attribute is on a parent element of the <use>.
Try in Opera, it's the same there.

Do you agree that we can close this bug?
Comment 2 Darin Adler 2015-01-20 08:20:39 PST
I’m closing this, assuming that it’s correct behavior. Please comment if it’s not.