This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 13684 - Event handler attributes should reregister each time they are changed (?)
Summary: Event handler attributes should reregister each time they are changed (?)
Status: RESOLVED FIXED
Alias: None
Product: HTML WG
Classification: Unclassified
Component: HTML5 spec (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
: 13683 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-08-05 10:10 UTC by Olli Pettay
Modified: 2011-10-07 21:45 UTC (History)
9 users (show)

See Also:


Attachments
testcase (646 bytes, text/html)
2011-08-05 10:10 UTC, Olli Pettay
Details

Description Olli Pettay 2011-08-05 10:10:46 UTC
Created attachment 1021 [details]
testcase

" Event handlers therefore always run before event listeners attached using addEventListener()" is wrong.
It is not what browsers (tested F, C, O) do.
Comment 1 Olli Pettay 2011-08-05 10:15:18 UTC
*** Bug 13683 has been marked as a duplicate of this bug. ***
Comment 2 Ian 'Hixie' Hickson 2011-08-06 06:10:30 UTC
EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Did Not Understand Request
Change Description: no spec change
Rationale: Removing the note is pointless, it's not normative.

If you want the normative requirements changed, that's a different matter. What would you like the behaviour to be?
Comment 3 Olli Pettay 2011-08-06 09:50:38 UTC
Event listeners are called in the order they are added to the event target.
Comment 4 Olli Pettay 2011-08-06 09:51:30 UTC
I couldn't figure out what in the spec leads to "therefore always".
Comment 5 Boris Zbarsky 2011-08-07 02:19:40 UTC
> I couldn't figure out what in the spec leads to "therefore always".

This bit:

  All event handlers on an object, whether an element or some other object, and
  whether set to null or to a Function object, must be registered as event
  listeners on the object when it is created

which means ipso facto that they're registered before any other event listeners (since those can't be registered before the object is created).
Comment 6 Olli Pettay 2011-08-07 08:08:09 UTC
Oh, I read that so that if elements have onfoo content attributes, they must be
registered as event listeners when element is basically parsed/created.
But ok, I misread that part.
But anyway, that is buggy, not something browser do, and there is no
need to special case onfoo listeners.
Comment 7 Olli Pettay 2011-08-07 08:10:36 UTC
And also, onfoo listeners have been discussed in WebApps WG, and
decided that they are no special, which is why D3E doesn't even try to
define them.
Comment 8 Ian 'Hixie' Hickson 2011-08-08 21:56:10 UTC
Will examine further.

Things to test:
 Order of handlers in  addEventListener(), set onhandler, addEventListener()
 Order of handlers in  set onhandler, addEventListener(), set onhandler
 Whether it matters if you're removing and resetting the attribute, vs changing the attribute.
 Whether the IDL attributes behaves differently.
Comment 9 Olli Pettay 2011-08-09 10:38:38 UTC
Gecko seems to keep the onfoo in its place in the event listener list
if one changes (not removes) the onfoo listener.
chrome and opera don't do that, but apparently remove the old listener
first and then add new.
I'm ok changing Gecko's behavior.
Comment 10 Anne 2011-09-21 16:47:14 UTC
Pretty sure this needs a hook in DOM4 (DOM Level 3 Events is wrong in that they are nothing special).

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1143

Using both addEventListener and on* you can register the same listener twice. And you cannot remove the listener added with addEventListener by setting on* to null, etc.

I think event listener needs an additional "event handler flag".

When you set on* it first removes any event listeners for type=type, listener=listener, event handler flag set, then it appends a new event listener for type=type, listener=listener, with the event handler flag set.

addEventListener meanwhile never has the event handler flag set and when doing equality checking it always checks for unset.
Comment 11 Jacob Rossi [MSFT] 2011-09-21 16:56:32 UTC
IE matches Firefox in that once on* is set, its position in the ordering is fixed. Changing on* changes the listener but not the order.
Comment 12 Anne 2011-09-21 17:03:04 UTC
If we want that behavior, instead of removing it should then simply change the original entry, if any, and append otherwise, when setting the event handler to a new value.

Hixie, do you agree that http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-listener needs a "event handler flag"? (I will also turn capture into a "capture flag" for consistency.)

(I realize we talked about moving event handlers into DOM4, but we should probably wait with that some more.)
Comment 13 Ian 'Hixie' Hickson 2011-09-21 17:28:04 UTC
Setting on* to a function foo does not register a listener for foo. The listener that is actually registered is an anonymous function that then calls foo. So there's no conflict with aEL() here.
Comment 14 Anne 2011-10-03 10:00:14 UTC
Hixie, where does HTML state that? I cannot find such a thing for event handler IDL attributes.
Comment 15 Ian 'Hixie' Hickson 2011-10-07 04:17:05 UTC
Search for the following text (also partly quoted in comment 5 above):

-----8<-----
All event handlers on an object, whether an element or some other object, and whether set to null or to a Function object, must be registered as event listeners on the object when it is created, as if the addEventListener() method on the object's EventTarget interface had been invoked, with the event type (type argument) equal to the type corresponding to the event handler (the event handler event type), the listener set to be a target and bubbling phase listener (useCapture argument set to false), and the event listener itself (listener argument) set to do nothing while the event handler's value is not a Function object, and set to invoke the call() callback of the Function object associated with the event handler otherwise.

Note: Event handlers therefore always run before event listeners attached using addEventListener().

Note: The listener argument is emphatically not the event handler itself.
-----8<-----

If I understand correctly, this bug is about changing this so that instead of this happening when the element is created, it happens when the event handler is first set to something other than null.
Comment 16 Ian 'Hixie' Hickson 2011-10-07 04:18:21 UTC
(Also I'll clarify the text so that it doesn't state by confusingly saying that the "event handlers [are] registered as event listeners" since that's not what the text goes on to actually require.)
Comment 17 Ian 'Hixie' Hickson 2011-10-07 21:21:25 UTC
EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Accepted
Change Description: see diff given below
Rationale: Concurred with reporter's comments.
Comment 18 contributor 2011-10-07 21:45:16 UTC
Checked in as WHATWG revision r6652.
Check-in comment: Define how event handler registration works to be compatible with IE and Firefox.
http://html5.org/tools/web-apps-tracker?from=6651&to=6652