motion controller: Match focus event propagation

Make the crossing event generation for pointer events
match what we do for focus now.
This commit is contained in:
Matthias Clasen 2020-02-20 23:20:58 -05:00
parent 77aed615e8
commit e062137b2c
4 changed files with 85 additions and 26 deletions

View File

@ -41,9 +41,6 @@ struct _GtkEventControllerMotion
{
GtkEventController parent_instance;
GdkEvent *current_event;
const GtkCrossingData *current_crossing;
guint is_pointer : 1;
guint contains_pointer : 1;
};
@ -105,18 +102,28 @@ update_pointer_focus (GtkEventController *controller,
if (crossing->direction == GTK_CROSSING_IN)
{
if (crossing->new_descendent != NULL)
{
contains_pointer = TRUE;
}
if (crossing->new_target == widget)
is_pointer = TRUE;
if (crossing->new_target != NULL)
{
contains_pointer = TRUE;
is_pointer = TRUE;
}
}
else
{
if (crossing->new_descendent != NULL ||
crossing->new_target == widget)
contains_pointer = TRUE;
is_pointer = FALSE;
}
if (motion->contains_pointer != contains_pointer)
{
if (contains_pointer)
enter = TRUE;
else
leave = TRUE;
enter = contains_pointer;
leave = !contains_pointer;
}
if (leave)
@ -145,16 +152,8 @@ gtk_event_controller_motion_handle_crossing (GtkEventController *controller,
double x,
double y)
{
GtkEventControllerMotion *motion = GTK_EVENT_CONTROLLER_MOTION (controller);
if (crossing->type != GTK_CROSSING_POINTER)
return;
motion->current_crossing = crossing;
update_pointer_focus (controller, crossing, x, y);
motion->current_crossing = NULL;
if (crossing->type == GTK_CROSSING_POINTER)
update_pointer_focus (controller, crossing, x, y);
}
static void

View File

@ -1312,20 +1312,52 @@ gtk_synthesize_crossing_events (GtkRoot *toplevel,
GdkCrossingMode mode)
{
GtkCrossingData crossing;
GtkWidget *ancestor;
GtkWidget *widget;
GList *list, *l;
double x, y;
GtkWidget *prev;
gboolean seen_ancestor;
if (old_target && new_target)
ancestor = gtk_widget_common_ancestor (old_target, new_target);
else
ancestor = NULL;
crossing.type = GTK_CROSSING_POINTER;
crossing.mode = mode;
crossing.old_target = old_target;
crossing.old_descendent = NULL;
crossing.new_target = new_target;
crossing.new_descendent = NULL;
crossing.direction = GTK_CROSSING_OUT;
prev = NULL;
seen_ancestor = FALSE;
widget = old_target;
while (widget)
{
crossing.old_descendent = prev;
if (seen_ancestor)
{
crossing.new_descendent = new_target ? prev : NULL;
}
else if (widget == ancestor)
{
GtkWidget *w;
crossing.new_descendent = NULL;
for (w = new_target; w != ancestor; w = gtk_widget_get_parent (w))
crossing.new_descendent = w;
seen_ancestor = TRUE;
}
else
{
crossing.new_descendent = NULL;
}
check_crossing_invariants (widget, &crossing);
translate_event_coordinates (event, &x, &y, widget);
gtk_widget_handle_crossing (widget, &crossing, x, y);
gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_PRELIGHT);
@ -1333,18 +1365,38 @@ gtk_synthesize_crossing_events (GtkRoot *toplevel,
}
list = NULL;
widget = new_target;
while (widget)
{
list = g_list_prepend (list, widget);
widget = gtk_widget_get_parent (widget);
}
for (widget = new_target; widget; widget = gtk_widget_get_parent (widget))
list = g_list_prepend (list, widget);
crossing.direction = GTK_CROSSING_IN;
seen_ancestor = FALSE;
for (l = list; l; l = l->next)
{
widget = l->data;
if (l->next)
crossing.new_descendent = l->next->data;
else
crossing.new_descendent = NULL;
if (seen_ancestor)
{
crossing.old_descendent = NULL;
}
else if (widget == ancestor)
{
GtkWidget *w;
crossing.old_descendent = NULL;
for (w = old_target; w != ancestor; w = gtk_widget_get_parent (w))
crossing.old_descendent = w;
seen_ancestor = TRUE;
}
else
{
crossing.old_descendent = old_target ? crossing.new_descendent : NULL;
}
translate_event_coordinates (event, &x, &y, widget);
gtk_widget_handle_crossing (widget, &crossing, x, y);
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_PRELIGHT, FALSE);

View File

@ -31,6 +31,7 @@
#include "gtkcsstypesprivate.h"
#include "gtktexthandleprivate.h"
#include "gtkeventcontrollerprivate.h"
G_BEGIN_DECLS
@ -97,6 +98,11 @@ gboolean gtk_propagate_event (GtkWidget *widget,
GdkEvent *event);
void gtk_main_do_event (GdkEvent *event);
GtkWidget *gtk_get_event_widget (GdkEvent *event);
void check_crossing_invariants (GtkWidget *widget,
GtkCrossingData *crossing);
gdouble _gtk_get_slowdown (void);
void _gtk_set_slowdown (gdouble slowdown_factor);

View File

@ -6352,10 +6352,11 @@ gtk_window_move_focus (GtkWidget *widget,
gtk_window_set_focus (GTK_WINDOW (widget), NULL);
}
static void
void
check_crossing_invariants (GtkWidget *widget,
GtkCrossingData *crossing)
{
#ifdef G_ENBABLE_DEBUG
if (crossing->old_target == NULL)
g_assert (crossing->old_descendent == NULL);
else if (crossing->old_descendent == NULL)
@ -6376,6 +6377,7 @@ check_crossing_invariants (GtkWidget *widget,
g_assert (gtk_widget_is_ancestor (crossing->new_descendent, widget));
g_assert (crossing->new_target == crossing->new_descendent || gtk_widget_is_ancestor (crossing->new_target, crossing->new_descendent));
}
#endif
}
static void