gesture: Consume the event triggering ::begin if reset within the handler

If the event triggers GtkGesture::begin, and the handler ends up resetting
the gesture (say, due to taking a grab somewhere else within the handler),
still take the event as "managed", as it actually triggered recognition,
even if just to end abruptly.

https://bugzilla.gnome.org/show_bug.cgi?id=731711
This commit is contained in:
Carlos Garnacho 2014-06-24 19:08:51 +02:00
parent fa4301c63e
commit 80d6735ffc

View File

@ -287,21 +287,29 @@ _gtk_gesture_do_check (GtkGesture *gesture)
} }
static gboolean static gboolean
_gtk_gesture_check_recognized (GtkGesture *gesture, _gtk_gesture_has_matching_touchpoints (GtkGesture *gesture)
GdkEventSequence *sequence)
{ {
GtkGesturePrivate *priv = gtk_gesture_get_instance_private (gesture); GtkGesturePrivate *priv = gtk_gesture_get_instance_private (gesture);
guint current_n_points; guint current_n_points;
current_n_points = _gtk_gesture_effective_n_points (gesture); current_n_points = _gtk_gesture_effective_n_points (gesture);
if (priv->recognized && return (current_n_points == priv->n_points &&
(current_n_points != priv->n_points || g_hash_table_size (priv->points) == priv->n_points);
g_hash_table_size (priv->points) != priv->n_points)) }
static gboolean
_gtk_gesture_check_recognized (GtkGesture *gesture,
GdkEventSequence *sequence)
{
GtkGesturePrivate *priv = gtk_gesture_get_instance_private (gesture);
gboolean has_matching_touchpoints;
has_matching_touchpoints = _gtk_gesture_has_matching_touchpoints (gesture);
if (priv->recognized && !has_matching_touchpoints)
_gtk_gesture_set_recognized (gesture, FALSE, sequence); _gtk_gesture_set_recognized (gesture, FALSE, sequence);
else if (!priv->recognized && else if (!priv->recognized && has_matching_touchpoints &&
current_n_points == priv->n_points &&
g_hash_table_size (priv->points) == priv->n_points &&
_gtk_gesture_do_check (gesture)) _gtk_gesture_do_check (gesture))
_gtk_gesture_set_recognized (gesture, TRUE, sequence); _gtk_gesture_set_recognized (gesture, TRUE, sequence);
@ -576,8 +584,14 @@ gtk_gesture_handle_event (GtkEventController *controller,
{ {
case GDK_BUTTON_PRESS: case GDK_BUTTON_PRESS:
case GDK_TOUCH_BEGIN: case GDK_TOUCH_BEGIN:
if (_gtk_gesture_update_point (gesture, event, TRUE) && if (_gtk_gesture_update_point (gesture, event, TRUE))
_gtk_gesture_check_recognized (gesture, sequence)) {
gboolean triggered_recognition;
triggered_recognition =
!was_recognized && _gtk_gesture_has_matching_touchpoints (gesture);
if (_gtk_gesture_check_recognized (gesture, sequence))
{ {
PointData *data; PointData *data;
@ -587,6 +601,15 @@ gtk_gesture_handle_event (GtkEventController *controller,
if (gtk_gesture_get_sequence_state (gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED) if (gtk_gesture_get_sequence_state (gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED)
data->press_handled = TRUE; data->press_handled = TRUE;
} }
else if (triggered_recognition && g_hash_table_size (priv->points) == 0)
{
/* Recognition was triggered, but the gesture reset during
* ::begin emission. Still, recognition was strictly triggered,
* so the event should be consumed.
*/
return TRUE;
}
}
break; break;
case GDK_BUTTON_RELEASE: case GDK_BUTTON_RELEASE: