Canvas: prevent bubbling of mouseenter and mouseleave.

This commit is contained in:
Thomas Geymayer 2013-06-30 21:27:03 +02:00
parent 14eccc70da
commit 6f7c0c23d1

View File

@ -251,6 +251,21 @@ namespace canvas
// std::cout << it->element.lock()->getProps()->getPath() << std::endl; // 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 // Bubbling phase
for( EventPropagationPath::const_reverse_iterator for( EventPropagationPath::const_reverse_iterator
it = path.rbegin(); it = path.rbegin();
@ -260,9 +275,14 @@ namespace canvas
ElementPtr el = it->element.lock(); ElementPtr el = it->element.lock();
if( !el ) if( !el )
{
// Ignore element if it has been destroyed while traversing the event // Ignore element if it has been destroyed while traversing the event
// (eg. removed by another event handler) // (eg. removed by another event handler)
continue; if( do_bubble )
continue;
else
break;
}
// TODO provide functions to convert delta to local coordinates on demand. // TODO provide functions to convert delta to local coordinates on demand.
// Maybe also provide a clone method for events as local coordinates // Maybe also provide a clone method for events as local coordinates
@ -281,7 +301,7 @@ namespace canvas
el->handleEvent(event); el->handleEvent(event);
if( event->propagation_stopped ) if( event->propagation_stopped || !do_bubble )
return true; return true;
} }