Skip to content

Commit

Permalink
LibCore: Fix broken "stay_within" mechanism in event dispatch
Browse files Browse the repository at this point in the history
The "stay_within" parameter to CObject::dispatch_event() optionally
specifies a node in the CObject parent chain where event dispatch
should stop bubbling upwards.

Since event dispatch is done recursively, this was not working right,
as we would simply return from the innermost dispatch loop, leaving
the event un-accepted, which meant that the penultimately inner
dispatch loop would pick up the event and keep bubbling it anyway.

This made it possible for events to jump across window boundaries
within an application, in cases where one window was a CObject ancestor
of another window. This is typically the case with dialog windows.

Fix SerenityOS#1078.
  • Loading branch information
awesomekling committed Jan 21, 2020
1 parent a5e4828 commit 72d68b4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Libraries/LibCore/CObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ void CObject::dispatch_event(CEvent& e, CObject* stay_within)
do {
target->event(e);
target = target->parent();
if (target == stay_within) {
// Prevent the event from bubbling any further.
e.accept();
break;
}
} while (target && target != stay_within && !e.is_accepted());
}

Expand Down

0 comments on commit 72d68b4

Please sign in to comment.