ISSUE-50 - Public View

Should capturing EventListeners registered on the target fire?

State:
CLOSED
Product:
DOM 3 Events
Raised by:
Jonas Sicking
Opened on:
2006-03-23
Description:
Right now mozilla will fire capturing EventListeners registered on the target
node of an element. So for something like

myImg.addEventListener("click", gotClicked, true);

if a click event is dispatched against myImg the gotClicked handler will be 
fired.

It is not entierly clear in DOM Level 2 Events if this is how things should be.
The relevant section [1] in the spec on one hand says:

  When the event reaches the target, any event listeners registered on the
  EventTarget are triggered.

But then later in the section specifically on the capturing phase says:

  Event capture is the process by which an EventListener registered on an
  ancestor of the event's target can intercept events of a given type before
  they are received by the event's target.

The section describing the "useCapture" argument to addEventListener says:

  Events which are bubbling upward through the tree will not trigger an
  EventListener designated to use capture.


There is currently a bug [2] filed on mozilla where it is debated what the spec
really calls for. (I don't see a reason why mozilla wouldn't change its
behaviour if that is really what the spec says).

One interpretation (A) is that capturing listeners will not fire during the
bubbling phase, but that that phase is only the duration from after the event
has fired against the target to after when it has fired against the document (or
other toplevel node). Under this interpretation mozilla does the right thing.

Another interpretation (B) is that capturing listeners are only fired during the
capturing phase, which is the duration from before the event has fired on the
document to after it has fired on the last ancestor (i.e. the parent) of the
target. Under this interpretation mozilla should be changed.


One advantage of interpretation A is that it lets you see non-bubbling events
for an entire subtree by just registing one EventListener. For example if you
are interested in if any node in a subtree is focused you just register a
capturing listener on the root of that subtree. Under interpretation B you would
not notice if the root got focused. Instead you would have to register both a
capturing and a non-capturing EventListener.

I can't offhand think of an advantage with B, but I don't think we want to break
compatibility with DOM Level 2 Events if that is indeed what it says.


In any event, this needs to be clarified in DOM Level 3 Events.

/ Jonas

[1] http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=235441

Note: Some of these links may be accessible only to W3C Members.

Related emails:
  1. ISSUE-50: Should capturing EventListeners registered on the target fire? (from dean+cgi@w3.org on 2006-03-23)
  2. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from derhoermi@gmx.net on 2006-03-23)
  3. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from derhoermi@gmx.net on 2006-03-23)
  4. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from annevk@opera.com on 2006-03-23)
  5. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from sergey@backbase.com on 2006-03-23)
  6. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from pettay@mappi.helsinki.fi on 2006-03-23)
  7. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from derhoermi@gmx.net on 2006-03-24)
  8. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from jonas@sicking.cc on 2006-03-23)
  9. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from ian@hixie.ch on 2006-03-24)
  10. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from derhoermi@gmx.net on 2006-03-24)
  11. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from ian@hixie.ch on 2006-03-24)
  12. Minutes 2006-03-27 (from chaals@opera.com on 2006-04-09)
  13. Re: ISSUE-50: Should capturing EventListeners registered on the target fire? (from ian@hixie.ch on 2006-05-18)

Related notes:

No additional notes.