summaryrefslogtreecommitdiff
path: root/Libraries/LibCore/CObject.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-01-21 21:37:49 +0100
committerAndreas Kling <kling@serenityos.org>2020-01-21 21:55:25 +0100
commit72d68b4025fcfba530023637952af655dd16873b (patch)
tree30b0e488aba46057327741344b9f6b02d6b98a30 /Libraries/LibCore/CObject.cpp
parenta5e482833d4646084bf2457cb8d7e1cf9fc9709b (diff)
downloadserenity-72d68b4025fcfba530023637952af655dd16873b.zip
LibCore: Fix broken "stay_within" mechanism in event dispatch
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 #1078.
Diffstat (limited to 'Libraries/LibCore/CObject.cpp')
-rw-r--r--Libraries/LibCore/CObject.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/Libraries/LibCore/CObject.cpp b/Libraries/LibCore/CObject.cpp
index efdd70ad1c..8e15383428 100644
--- a/Libraries/LibCore/CObject.cpp
+++ b/Libraries/LibCore/CObject.cpp
@@ -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());
}