Skip to content

Commit

Permalink
Fix dispatch event for capturing/bubbling phases for own target
Browse files Browse the repository at this point in the history
The standard is not very clear about that.

On the general description of
events (https://dom.spec.whatwg.org/#events) it says "all the object’s
inclusive ancestor event listeners whose capture is true are invoked"
for capturing and bubbling phases. So the target itself *should be included*.

But later when describing the
phases (https://dom.spec.whatwg.org/#dom-event-eventphase) it says
that capturing phase is _before_ the target and bubbling phase is
_after_ the target. So the target itself *should not be included*.

The behavior of modern web browsers (Chrome/Firefox) do not include
the target in capturing/bubbling phase so let's follow that.

Signed-off-by: Francis Bouvier <[email protected]>
  • Loading branch information
francisbouvier committed Jan 18, 2024
1 parent fa989c7 commit 9327625
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/events/event_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,15 @@ dom_exception _dom_event_target_dispatch(dom_event_target *et,
if (dom_string_isequal(le->type, evt->type)) {
assert(le->listener->handler != NULL);

bool ancestor = evt->current != evt->target;

if ((le->capture &&
phase == DOM_CAPTURING_PHASE) ||
phase == DOM_CAPTURING_PHASE &&
ancestor) ||
(le->capture == false &&
evt->bubble &&
phase == DOM_BUBBLING_PHASE) ||
phase == DOM_BUBBLING_PHASE &&
ancestor) ||
(evt->target == evt->current &&
phase == DOM_AT_TARGET)) {
le->listener->handler(evt,
Expand Down

0 comments on commit 9327625

Please sign in to comment.