From 6f7c0c23d1aaec41e617a062086d7f4aeaa58824 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sun, 30 Jun 2013 21:27:03 +0200 Subject: [PATCH] Canvas: prevent bubbling of mouseenter and mouseleave. --- simgear/canvas/CanvasEventManager.cxx | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/simgear/canvas/CanvasEventManager.cxx b/simgear/canvas/CanvasEventManager.cxx index 6a6f7cf2..3e5c4028 100644 --- a/simgear/canvas/CanvasEventManager.cxx +++ b/simgear/canvas/CanvasEventManager.cxx @@ -251,6 +251,21 @@ namespace canvas // std::cout << it->element.lock()->getProps()->getPath() << std::endl; // } + // Check if event supports bubbling + const Event::Type types_no_bubbling[] = { + Event::MOUSE_ENTER, + Event::MOUSE_LEAVE, + }; + const size_t num_types_no_bubbling = sizeof(types_no_bubbling) + / sizeof(types_no_bubbling[0]); + bool do_bubble = true; + for( size_t i = 0; i < num_types_no_bubbling; ++i ) + if( event->type == types_no_bubbling[i] ) + { + do_bubble = false; + break; + } + // Bubbling phase for( EventPropagationPath::const_reverse_iterator it = path.rbegin(); @@ -260,9 +275,14 @@ namespace canvas ElementPtr el = it->element.lock(); if( !el ) + { // Ignore element if it has been destroyed while traversing the event // (eg. removed by another event handler) - continue; + if( do_bubble ) + continue; + else + break; + } // TODO provide functions to convert delta to local coordinates on demand. // Maybe also provide a clone method for events as local coordinates @@ -281,7 +301,7 @@ namespace canvas el->handleEvent(event); - if( event->propagation_stopped ) + if( event->propagation_stopped || !do_bubble ) return true; } -- 2.39.5