W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2005

Re: Query regarding canTrigger() method of EventTarget Interface

From: Philippe Le Hegaret <plh@w3.org>
Date: Tue, 12 Apr 2005 11:44:16 -0400
To: Sarika Garg <sagarg@quark.com>
Cc: www-dom@w3.org
Message-Id: <1113320656.7864.122.camel@localhost>
On Mon, 2005-04-11 at 20:11 +0530, Sarika Garg wrote:
> Does it mean that we need to check if there are any event listeners of
> the event type passed as parameter registered on the eventTarget or
> its ancestors? 

Yes.

> If there are any listeners of the particular event type registered,
> canTrigger() will return true else false. I mean what is the basis of
> determining that an event will be triggered?


An event triggers some event listeners (and not the reverse), on the
basis defined in section 1.2.2.3 [1]. For the case of willTriggerNS, it
return true if the event listener was registered for the type of event
and the appropriate phase (see also your next question).

>  Secondly, are we talking about the capture phase when we say dispatch
> of the event to the event target or one of its descendants.

This also include the target and bubbling phases, in the following way:

Consider the tree [2],
tbodyElement.willTrigger("http://www.w3.org/2001/xml-events",
"DOMActivate") will return true if:
- an event listener of the same type was registered for the capture
phase or bubbling phase on Document, html, body, and table elements
- an event listener of the same type was registered for the capture,
target, and bubbling phases on the tbody element.

If the event type doesn't "bubble", e.g. "DOMNodeInsertedIntoDocument",
you don't consider event listener of the same type registered for the
bubbling phase on Document, html, body, table, and tbody elements.

You will note that the returned list cannot be 100% accurate in any case
and may contain more event listeners than what would effectively be
triggered, for two reasons:
- there is no way to know if an event may be stopped before reaching the
event listener;
- you include all event listeners of the same type from the event target
for the capture, target, and bubbling phases since the returned list
must contain all listeners "triggered by the specified event type during
the dispatch of the event to this event target or one of its
descendants". If the event is effectively targeted towards that node,
only the event listeners in the target phase will be triggered. If the
event is effectively targeted towards one of its descendants, only the
event listeners in the capture and bubbling phase will be triggered.

We may need to add those reasons as notes in the specification, or
change "will be triggered" into "could be triggered"...

Philippe

[1]
http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-listeners-activation
[2]
http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/images/eventflow.png


Received on Tuesday, 12 April 2005 15:44:19 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:58 GMT