Closed Bug 523376 Opened 15 years ago Closed 4 years ago

Event Bubble and Capture phase are reversed on target (eventPhase=2)

Categories

(Core :: DOM: Events, defect, P5)

x86_64
Linux
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: the_djmaze, Unassigned)

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090909 Fedora/3.5.3-1.fc11 Firefox/3.5.3
Build Identifier: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090909 Fedora/3.5.3-1.fc11 Firefox/3.5.3

When registering an event listener in bubble phase and one in capture phase on the target itself the capture listener is executed before the bubble listener

Reproducible: Always

Steps to Reproduce:
<html>
<head>
	<title></title>
	<style>
	div { position:relative;}
	</style>
</head>
<body>
<div id="level1" style="background-color:#f00;height:300px;width:300px;float:left;">
	<div id="level2" style="background-color:#0f0;height:200px;width:200px;left:50px;top:50px">
		<div id="level3" style="background-color:#00f;height:100px;width:100px;left:50px;top:50px"></div>
	</div>
</div>

<textarea id="events" rows="20" cols="60"></textarea>

<script>
function $(id) { return document.getElementById(id); }
var d1 = $("level1"), d2 = $("level2"), d3 = $("level3"), txt = $("events");

d1.addEventListener("click", function(e){txt.value+="Level 1 Bubble\n"}, false);
d2.addEventListener("click", function(e){txt.value+="Level 2 Bubble\n"}, false);
d3.addEventListener("click", function(e){txt.value+="Level 3 Bubble\n"}, false);

d1.addEventListener("click", function(e){txt.value+="Level 1 Capture\n"}, true);
d2.addEventListener("click", function(e){txt.value+="Level 2 Capture\n"}, true);
d3.addEventListener("click", function(e){txt.value+="Level 3 Capture\n"}, true);
</script>
</body>
</html>

Actual Results:  
Level 1 Capture
Level 2 Capture
Level 3 Bubble
Level 3 Capture
Level 2 Bubble
Level 1 Bubble


Expected Results:  
Level 1 Capture
Level 2 Capture
Level 3 Capture
Level 3 Bubble
Level 2 Bubble
Level 1 Bubble
This does not happen when the capture listener is added before the bubble listener
Attached file modified testcase
I am fairly sure this is invalid.

...When the event reaches the target, any event listeners registered on the EventTarget are triggered. Although all EventListeners on the EventTarget are guaranteed to be triggered by any event which is received by that EventTarget, no specification is made as to the order in which they will receive the event with regards to the other EventListeners on the EventTarget...
Assignee: general → nobody
Component: JavaScript Engine → DOM: Events
QA Contact: general → events
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-capture
"A capturing EventListener will not be triggered by events dispatched directly to the EventTarget upon which it is registered."

My english is not that good but, doesn't that mean the capture listener shouldn't be called at all at level 3?
Just found another uri which says my findings in previous comment are correct.
http://cross-browser.com/cbe/docs/event_om.html

So the issue is not that the events are mixed but that they shouldn't be called at all.

Close this bug and open a new one regarding capture events getting called AT_TARGET?
(In reply to comment #3)
> My english is not that good but, doesn't that mean the capture listener
> shouldn't be called at all at level 3?
You're right, but because of backward compatibility it is very difficult to change
the current behavior.
See bug 235441.
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven't been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5

Per current DOM spec, capture listeners fire on the target.

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: