[gtk+] widget: Change GtkCapturePhase behavior in event controllers' handling



commit 505efbb3f3ae76ffdd4f7e9871cedd84c41cb673
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue May 27 12:14:52 2014 +0200

    widget: Change GtkCapturePhase behavior in event controllers' handling
    
    Previously, there would be globally just a capture and a bubble phase,
    with the event just going down the hierarchy once, and the up once.
    GTK_PHASE_TARGET actually meaning "run within event handlers", so in
    a hierarchy of 3 widgets, emission would be:
    
      Capture(C)
      Capture(B)
      Capture(A)
      Target(A) (if event handlers allow)
      Bubble(A)
      Target(B) (if event handlers allow)
      Bubble(B)
      Target(C) (if event handlers allow)
      Bubble(C)
    
    This commit changes this behavior and uses GTK_PHASE_TARGET in a less
    misleading way, running only on the widget that was meant to receive
    the event. And GTK_PHASE_BUBBLE has taken over the execution place of
    GTK_PHASE_TARGET, so the emission remains:
    
      Capture(C)
      Capture(B)
      Capture(A)
      Target(A)
      Bubble(A) (if event handlers allow)
      Bubble(B) (...)
      Bubble(C) (...)
    
    As it was, GTK_PHASE_BUBBLE was useful for running event controllers
    paralelly to event handlers, without modifying a single line in those.
    For those mixed scenarios, Any of the other phases will have to be
    used at discretion, or the event handlers eventually changed to chain
    up and let the default event handlers in GtkWidget to be run.

 gtk/gtkwidget.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 5895f49..cf0505f 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -7130,7 +7130,7 @@ gtk_widget_real_button_event (GtkWidget      *widget,
                               GdkEventButton *event)
 {
   return _gtk_widget_run_controllers (widget, (GdkEvent *) event,
-                                      GTK_PHASE_TARGET);
+                                      GTK_PHASE_BUBBLE);
 }
 
 static gboolean
@@ -7138,7 +7138,7 @@ gtk_widget_real_motion_event (GtkWidget      *widget,
                               GdkEventMotion *event)
 {
   return _gtk_widget_run_controllers (widget, (GdkEvent *) event,
-                                      GTK_PHASE_TARGET);
+                                      GTK_PHASE_BUBBLE);
 }
 
 static gboolean
@@ -7183,7 +7183,7 @@ gtk_widget_real_touch_event (GtkWidget     *widget,
 
   if (!event->emulating_pointer)
     return _gtk_widget_run_controllers (widget, (GdkEvent*) event,
-                                        GTK_PHASE_TARGET);
+                                        GTK_PHASE_BUBBLE);
 
   if (event->type == GDK_TOUCH_BEGIN ||
       event->type == GDK_TOUCH_END)
@@ -7248,7 +7248,7 @@ gtk_widget_real_grab_broken_event (GtkWidget          *widget,
                                    GdkEventGrabBroken *event)
 {
   return _gtk_widget_run_controllers (widget, (GdkEvent*) event,
-                                      GTK_PHASE_TARGET);
+                                      GTK_PHASE_BUBBLE);
 }
 
 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
@@ -7586,6 +7586,9 @@ gtk_widget_event_internal (GtkWidget *widget,
 
   g_object_ref (widget);
 
+  if (widget == gtk_get_event_widget (event))
+    return_val |= _gtk_widget_run_controllers (widget, event, GTK_PHASE_TARGET);
+
   g_signal_emit (widget, widget_signals[EVENT], 0, event, &handled);
   return_val |= handled | !WIDGET_REALIZED_FOR_EVENT (widget, event);
   if (!return_val)
@@ -7699,8 +7702,6 @@ gtk_widget_event_internal (GtkWidget *widget,
   else
     return_val = TRUE;
 
-  return_val |= _gtk_widget_run_controllers (widget, event, GTK_PHASE_BUBBLE);
-
   g_object_unref (widget);
 
   return return_val;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]