range: Have slider jump to the pointer coordinates on touch devices

This widget is too narrow to make touch interaction tricky enough, so
don't add the penalty of having the slider run farther from the touch
coordinates if it happens to miss the slider.
This commit is contained in:
Carlos Garnacho 2012-01-05 00:21:36 +01:00 committed by Matthias Clasen
parent 535b4150fd
commit 518a579838

View File

@ -2522,7 +2522,8 @@ gtk_range_button_press (GtkWidget *widget,
{ {
GtkRange *range = GTK_RANGE (widget); GtkRange *range = GTK_RANGE (widget);
GtkRangePrivate *priv = range->priv; GtkRangePrivate *priv = range->priv;
GdkDevice *device; GdkDevice *device, *source_device;
GdkInputSource source;
if (!gtk_widget_has_focus (widget)) if (!gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget); gtk_widget_grab_focus (widget);
@ -2532,6 +2533,9 @@ gtk_range_button_press (GtkWidget *widget,
return FALSE; return FALSE;
device = gdk_event_get_device ((GdkEvent *) event); device = gdk_event_get_device ((GdkEvent *) event);
source_device = gdk_event_get_source_device ((GdkEvent *) event);
source = gdk_device_get_source (source_device);
priv->mouse_x = event->x; priv->mouse_x = event->x;
priv->mouse_y = event->y; priv->mouse_y = event->y;
@ -2548,23 +2552,24 @@ gtk_range_button_press (GtkWidget *widget,
return TRUE; return TRUE;
} }
if (priv->mouse_location == MOUSE_TROUGH && if (source != GDK_SOURCE_TOUCHSCREEN &&
priv->mouse_location == MOUSE_TROUGH &&
event->button == GDK_BUTTON_PRIMARY) event->button == GDK_BUTTON_PRIMARY)
{ {
/* button 1 steps by page increment, as with button 2 on a stepper /* button 1 steps by page increment, as with button 2 on a stepper
*/ */
GtkScrollType scroll; GtkScrollType scroll;
gdouble click_value; gdouble click_value;
click_value = coord_to_value (range, click_value = coord_to_value (range,
priv->orientation == GTK_ORIENTATION_VERTICAL ? priv->orientation == GTK_ORIENTATION_VERTICAL ?
event->y : event->x); event->y : event->x);
priv->trough_click_forward = click_value > gtk_adjustment_get_value (priv->adjustment); priv->trough_click_forward = click_value > gtk_adjustment_get_value (priv->adjustment);
range_grab_add (range, device, MOUSE_TROUGH, event->button); range_grab_add (range, device, MOUSE_TROUGH, event->button);
scroll = range_get_scroll_for_grab (range); scroll = range_get_scroll_for_grab (range);
gtk_range_add_step_timer (range, scroll); gtk_range_add_step_timer (range, scroll);
return TRUE; return TRUE;
@ -2599,17 +2604,17 @@ gtk_range_button_press (GtkWidget *widget,
return TRUE; return TRUE;
} }
else if ((priv->mouse_location == MOUSE_TROUGH && else if ((priv->mouse_location == MOUSE_TROUGH &&
event->button == GDK_BUTTON_MIDDLE) || (source == GDK_SOURCE_TOUCHSCREEN || event->button == GDK_BUTTON_MIDDLE)) ||
priv->mouse_location == MOUSE_SLIDER) priv->mouse_location == MOUSE_SLIDER)
{ {
gboolean need_value_update = FALSE; gboolean need_value_update = FALSE;
/* Any button can be used to drag the slider, but you can start /* Any button can be used to drag the slider, but you can start
* dragging the slider with a trough click using button 2; * dragging the slider with a trough click using button 2;
* On button 2 press, we warp the slider to mouse position, * On button 2 press and touch devices, we warp the slider to
* then begin the slider drag. * mouse position, then begin the slider drag.
*/ */
if (event->button == GDK_BUTTON_MIDDLE) if (event->button == GDK_BUTTON_MIDDLE || source == GDK_SOURCE_TOUCHSCREEN)
{ {
gdouble slider_low_value, slider_high_value, new_value; gdouble slider_low_value, slider_high_value, new_value;