Refactored the motion_notify method
[hildon] / hildon / hildon-pannable-area.c
index c451b61..1f848d5 100644 (file)
@@ -57,6 +57,7 @@
 #define SCROLL_FADE_TIMEOUT 100
 #define MOTION_EVENTS_PER_SECOND 25
 #define CURSOR_STOPPED_TIMEOUT 80
+#define MAX_SPEED_THRESHOLD 250
 #define PANNABLE_MAX_WIDTH 788
 #define PANNABLE_MAX_HEIGHT 378
 
@@ -75,7 +76,7 @@ struct _HildonPannableAreaPrivate {
   gdouble ex;          /* Used to store mouse co-ordinates of the last */
   gdouble ey;          /* motion event in acceleration mode */
   gboolean enabled;
-  gboolean clicked;
+  gboolean button_pressed;
   guint32 last_time;   /* Last event time, to stop infinite loops */
   gint last_type;
   gboolean last_in;
@@ -133,6 +134,8 @@ struct _HildonPannableAreaPrivate {
 
   GtkAdjustment *hadjust;
   GtkAdjustment *vadjust;
+  gint x_offset;
+  gint y_offset;
 
   GtkPolicyType vscrollbar_policy;
   GtkPolicyType hscrollbar_policy;
@@ -264,6 +267,14 @@ static void hildon_pannable_area_calculate_velocity (gdouble *vel,
 static gboolean hildon_pannable_area_motion_event_scroll_timeout (HildonPannableArea *area);
 static void hildon_pannable_area_motion_event_scroll (HildonPannableArea *area,
                                                       gdouble x, gdouble y);
+static void hildon_pannable_area_check_move (HildonPannableArea *area,
+                                             GdkEventMotion * event,
+                                             gdouble *x,
+                                             gdouble *y);
+static void hildon_pannable_area_handle_move (HildonPannableArea *area,
+                                              GdkEventMotion * event,
+                                              gdouble *x,
+                                              gdouble *y);
 static gboolean hildon_pannable_area_motion_notify_cb (GtkWidget * widget,
                                                        GdkEventMotion * event);
 static gboolean hildon_pannable_leave_notify_event (GtkWidget *widget,
@@ -369,7 +380,7 @@ hildon_pannable_area_class_init (HildonPannableAreaClass * klass)
                                                        "Minimum scroll velocity",
                                                        "Minimum distance the child widget should scroll "
                                                        "per 'frame', in pixels per frame.",
-                                                       0, G_MAXDOUBLE, 20,
+                                                       0, G_MAXDOUBLE, 10,
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT));
 
@@ -440,7 +451,7 @@ hildon_pannable_area_class_init (HildonPannableAreaClass * klass)
                                                      "Threshold to consider a motion event an scroll",
                                                      "Amount of pixels to consider a motion event an scroll, if it is less"
                                                       "it is a click detected incorrectly by the touch screen.",
-                                                     0, G_MAXUINT, 6,
+                                                     0, G_MAXUINT, 25,
                                                      G_PARAM_READWRITE |
                                                      G_PARAM_CONSTRUCT));
 
@@ -470,7 +481,7 @@ hildon_pannable_area_class_init (HildonPannableAreaClass * klass)
                                                      "Multiplier of the calculated speed",
                                                      "Force applied to the movement, multiplies the calculated speed of the"
                                                       "user movement the cursor in the screen",
-                                                     0, G_MAXUINT, 120,
+                                                     0, G_MAXUINT, 50,
                                                      G_PARAM_READWRITE |
                                                      G_PARAM_CONSTRUCT));
 
@@ -630,7 +641,7 @@ hildon_pannable_area_init (HildonPannableArea * area)
   area->priv = priv;
 
   priv->moved = FALSE;
-  priv->clicked = FALSE;
+  priv->button_pressed = FALSE;
   priv->last_time = 0;
   priv->last_type = 0;
   priv->vscroll_visible = TRUE;
@@ -656,6 +667,8 @@ hildon_pannable_area_init (HildonPannableArea * area)
   priv->child_width = 0;
   priv->child_height = 0;
   priv->last_in = TRUE;
+  priv->x_offset = 0;
+  priv->y_offset = 0;
 
   gtk_widget_add_events (GTK_WIDGET (area), GDK_POINTER_MOTION_HINT_MASK);
 
@@ -824,7 +837,20 @@ hildon_pannable_area_set_property (GObject * object,
     priv->sps = g_value_get_uint (value);
     break;
   case PROP_PANNING_THRESHOLD:
-    priv->panning_threshold = g_value_get_uint (value);
+    {
+      GtkSettings *settings = gtk_settings_get_default ();
+      GtkSettingsValue svalue = { NULL, { 0, }, };
+
+      priv->panning_threshold = g_value_get_uint (value);
+
+      /* insure gtk dnd is the same we are using, not allowed
+         different thresholds in the same application */
+      svalue.origin = "panning_threshold";
+      g_value_init (&svalue.value, G_TYPE_LONG);
+      g_value_set_long (&svalue.value, priv->panning_threshold);
+      gtk_settings_set_property_value (settings, "gtk-dnd-drag-threshold", &svalue);
+      g_value_unset (&svalue.value);
+    }
     break;
   case PROP_SCROLLBAR_FADE_DELAY:
     /* convert to miliseconds */
@@ -1097,6 +1123,7 @@ hildon_pannable_area_size_allocate (GtkWidget * widget,
   HildonPannableAreaPrivate *priv;
   GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
   gint border_width;
+  gdouble hv, vv;
 
   border_width = GTK_CONTAINER (widget)->border_width;
 
@@ -1133,18 +1160,25 @@ hildon_pannable_area_size_allocate (GtkWidget * widget,
       gtk_widget_size_allocate (child, &child_allocation);
     }
 
+    hv = priv->hadjust->value;
+    vv = priv->vadjust->value;
+
     /* we have to do this after child size_allocate because page_size is
      * changed when we allocate the size of the children */
     if (priv->overshot_dist_y < 0) {
-      gtk_adjustment_set_value (priv->vadjust, priv->vadjust->upper -
-                                priv->vadjust->page_size);
+      priv->vadjust->value = priv->vadjust->upper - priv->vadjust->page_size;
     }
 
     if (priv->overshot_dist_x < 0) {
-      gtk_adjustment_set_value (priv->hadjust, priv->hadjust->upper -
-                                priv->hadjust->page_size);
+      priv->hadjust->value = priv->hadjust->upper - priv->hadjust->page_size;
     }
 
+    if (hv != priv->hadjust->value)
+      gtk_adjustment_value_changed (priv->hadjust);
+
+    if (vv != priv->vadjust->value)
+      gtk_adjustment_value_changed (priv->vadjust);
+
   } else {
     hildon_pannable_area_check_scrollbars (HILDON_PANNABLE_AREA (widget));
   }
@@ -1471,14 +1505,14 @@ hildon_pannable_area_initial_effect (GtkWidget * widget)
 {
   HildonPannableAreaPrivate *priv = HILDON_PANNABLE_AREA (widget)->priv;
 
-  if (priv->vscroll_visible || priv->hscroll_visible) {
-
-    priv->scroll_indicator_event_interrupt = 0;
-    priv->scroll_delay_counter = priv->scrollbar_fade_delay;
+  if (priv->initial_hint) {
+    if (priv->vscroll_visible || priv->hscroll_visible) {
 
-    hildon_pannable_area_launch_fade_timeout (HILDON_PANNABLE_AREA (widget), 1.0);
+      priv->scroll_indicator_event_interrupt = 0;
+      priv->scroll_delay_counter = priv->scrollbar_fade_delay;
 
-    priv->initial_effect = FALSE;
+      hildon_pannable_area_launch_fade_timeout (HILDON_PANNABLE_AREA (widget), 1.0);
+    }
   }
 }
 
@@ -1509,9 +1543,17 @@ static void
 hildon_pannable_area_adjust_value_changed (HildonPannableArea * area,
                                            gpointer data)
 {
-  if (GTK_WIDGET_REALIZED (area)) {
-    HildonPannableAreaPrivate *priv = HILDON_PANNABLE_AREA (area)->priv;
+  HildonPannableAreaPrivate *priv = HILDON_PANNABLE_AREA (area)->priv;
+  gint xdiff, ydiff;
+  gint x = priv->x_offset;
+  gint y = priv->y_offset;
+
+  priv->x_offset = priv->hadjust->value;
+  xdiff = x - priv->x_offset;
+  priv->y_offset = priv->vadjust->value;
+  ydiff = y - priv->y_offset;
 
+  if ((xdiff || ydiff) && GTK_WIDGET_DRAWABLE (area)) {
     hildon_pannable_area_redraw (area);
 
     if ((priv->vscroll_visible) || (priv->hscroll_visible)) {
@@ -1548,8 +1590,8 @@ hildon_pannable_area_scroll_indicator_fade(HildonPannableArea * area)
   HildonPannableAreaPrivate *priv = area->priv;
 
   /* if moving do not fade out */
-  if (((ABS (priv->vel_y)>1.0)||
-       (ABS (priv->vel_x)>1.0))&&(!priv->clicked)) {
+  if (((ABS (priv->vel_y)>priv->vmin)||
+       (ABS (priv->vel_x)>priv->vmin))&&(!priv->button_pressed)) {
 
     return TRUE;
   }
@@ -1608,8 +1650,10 @@ hildon_pannable_area_expose_event (GtkWidget * widget,
   GdkColor scroll_color = widget->style->fg[GTK_STATE_INSENSITIVE];
 #endif
 
-  if (G_UNLIKELY ((priv->initial_hint) && (priv->initial_effect))) {
+  if (G_UNLIKELY (priv->initial_effect)) {
     hildon_pannable_area_initial_effect (widget);
+
+    priv->initial_effect = FALSE;
   }
 
   if (gtk_bin_get_child (GTK_BIN (widget))) {
@@ -1817,7 +1861,7 @@ hildon_pannable_area_button_press_cb (GtkWidget * widget,
   priv->scroll_to_x = -1;
   priv->scroll_to_y = -1;
 
-  if (priv->clicked && priv->child) {
+  if (priv->button_pressed && priv->child) {
     /* Widget stole focus on last click, send crossing-out event */
     synth_crossing (priv->child, 0, 0, event->x_root, event->y_root,
                    event->time, FALSE);
@@ -1837,7 +1881,7 @@ hildon_pannable_area_button_press_cb (GtkWidget * widget,
   else
     priv->child = NULL;
 
-  priv->clicked = TRUE;
+  priv->button_pressed = TRUE;
 
   /* Stop scrolling on mouse-down (so you can flick, then hold to stop) */
   priv->vel_x = 0;
@@ -1937,7 +1981,16 @@ hildon_pannable_area_refresh (HildonPannableArea * area)
 {
   if (GTK_WIDGET_DRAWABLE (area) &&
       hildon_pannable_area_check_scrollbars (area)) {
+    HildonPannableAreaPrivate *priv = area->priv;
+
     gtk_widget_queue_resize (GTK_WIDGET (area));
+
+    if ((priv->vscroll_visible) || (priv->hscroll_visible)) {
+      priv->scroll_indicator_event_interrupt = 0;
+      priv->scroll_delay_counter = area->priv->scrollbar_fade_delay;
+
+      hildon_pannable_area_launch_fade_timeout (area, 1.0);
+    }
   } else {
     hildon_pannable_area_redraw (area);
   }
@@ -2010,9 +2063,9 @@ hildon_pannable_axis_scroll (HildonPannableArea *area,
       }
     }
 
-    gtk_adjustment_set_value (adjust, dist);
+    adjust->value = dist;
   } else {
-    if (!priv->clicked) {
+    if (!priv->button_pressed) {
 
       /* When the overshoot has started we continue for
        * PROP_BOUNCE_STEPS more steps into the overshoot before we
@@ -2068,7 +2121,10 @@ hildon_pannable_axis_scroll (HildonPannableArea *area,
         *overshot_dist = CLAMP ((*overshot_dist) + inc, -1 * overshoot_max, 0);
       } else {
         *overshooting = 0;
-        gtk_adjustment_set_value (adjust, dist);
+        adjust->value = CLAMP (dist,
+                               adjust->lower,
+                               adjust->upper -
+                               adjust->page_size);
       }
 
       if (*overshot_dist != overshot_dist_old)
@@ -2084,6 +2140,7 @@ hildon_pannable_area_scroll (HildonPannableArea *area,
   gboolean sx, sy;
   HildonPannableAreaPrivate *priv = area->priv;
   gboolean hscroll_visible, vscroll_visible;
+  gdouble hv, vv;
 
   if (gtk_bin_get_child (GTK_BIN (area)) == NULL)
     return;
@@ -2096,6 +2153,9 @@ hildon_pannable_area_scroll (HildonPannableArea *area,
   sx = TRUE;
   sy = TRUE;
 
+  hv = priv->hadjust->value;
+  vv = priv->vadjust->value;
+
   if (vscroll_visible) {
     hildon_pannable_axis_scroll (area, priv->vadjust, &priv->vel_y, y,
                                  &priv->overshooting_y, &priv->overshot_dist_y,
@@ -2112,6 +2172,12 @@ hildon_pannable_area_scroll (HildonPannableArea *area,
     priv->vel_x = 0;
   }
 
+  if (hv != priv->hadjust->value)
+    gtk_adjustment_value_changed (priv->hadjust);
+
+  if (vv != priv->vadjust->value)
+    gtk_adjustment_value_changed (priv->vadjust);
+
   /* If the scroll on a particular axis wasn't succesful, reset the
    * initial scroll position to the new mouse co-ordinate. This means
    * when you get to the top of the page, dragging down works immediately.
@@ -2138,7 +2204,7 @@ hildon_pannable_area_timeout (HildonPannableArea * area)
     return FALSE;
   }
 
-  if (!priv->clicked) {
+  if (!priv->button_pressed) {
     /* Decelerate gradually when pointer is raised */
     if ((!priv->overshot_dist_y) &&
         (!priv->overshot_dist_x)) {
@@ -2243,37 +2309,20 @@ hildon_pannable_area_motion_event_scroll (HildonPannableArea *area,
   }
 }
 
-static gboolean
-hildon_pannable_area_motion_notify_cb (GtkWidget * widget,
-                                      GdkEventMotion * event)
+static void
+hildon_pannable_area_check_move (HildonPannableArea *area,
+                                 GdkEventMotion * event,
+                                 gdouble *x,
+                                 gdouble *y)
 {
-  HildonPannableArea *area = HILDON_PANNABLE_AREA (widget);
   HildonPannableAreaPrivate *priv = area->priv;
-  gdouble x, y;
-  gdouble delta;
-
-  if (gtk_bin_get_child (GTK_BIN (widget)) == NULL)
-    return TRUE;
-
-  if ((!priv->enabled) || (!priv->clicked) ||
-      ((event->time == priv->last_time) && (priv->last_type == 2))) {
-    gdk_window_get_pointer (widget->window, NULL, NULL, 0);
-    return TRUE;
-  }
-
-  if (priv->last_type == 1) {
-    priv->first_drag = TRUE;
-  }
-
-  x = event->x - priv->x;
-  y = event->y - priv->y;
 
   if (priv->first_drag && (!priv->moved) &&
-      ((ABS (x) > (priv->panning_threshold))
-       || (ABS (y) > (priv->panning_threshold)))) {
+      ((ABS (*x) > (priv->panning_threshold))
+       || (ABS (*y) > (priv->panning_threshold)))) {
     priv->moved = TRUE;
-    x = 0;
-    y = 0;
+    *x = 0;
+    *y = 0;
 
     if (priv->first_drag) {
         gboolean vscroll_visible;
@@ -2357,76 +2406,116 @@ hildon_pannable_area_motion_notify_cb (GtkWidget * widget,
                                                  hildon_pannable_area_timeout, area);
     }
   }
+}
 
-  if (priv->moved) {
-    switch (priv->mode) {
-    case HILDON_PANNABLE_AREA_MODE_PUSH:
-      /* Scroll by the amount of pixels the cursor has moved
-       * since the last motion event.
-       */
-      hildon_pannable_area_motion_event_scroll (area, x, y);
+static void
+hildon_pannable_area_handle_move (HildonPannableArea *area,
+                                  GdkEventMotion * event,
+                                  gdouble *x,
+                                  gdouble *y)
+{
+  HildonPannableAreaPrivate *priv = area->priv;
+  gdouble delta;
+
+  switch (priv->mode) {
+  case HILDON_PANNABLE_AREA_MODE_PUSH:
+    /* Scroll by the amount of pixels the cursor has moved
+     * since the last motion event.
+     */
+    hildon_pannable_area_motion_event_scroll (area, *x, *y);
+    priv->x = event->x;
+    priv->y = event->y;
+    break;
+  case HILDON_PANNABLE_AREA_MODE_ACCEL:
+    /* Set acceleration relative to the initial click */
+    priv->ex = event->x;
+    priv->ey = event->y;
+    priv->vel_x = ((*x > 0) ? 1 : -1) *
+      (((ABS (*x) /
+         (gdouble) GTK_WIDGET (area)->allocation.width) *
+        (priv->vmax - priv->vmin)) + priv->vmin);
+    priv->vel_y = ((*y > 0) ? 1 : -1) *
+      (((ABS (*y) /
+         (gdouble) GTK_WIDGET (area)->allocation.height) *
+        (priv->vmax - priv->vmin)) + priv->vmin);
+    break;
+  case HILDON_PANNABLE_AREA_MODE_AUTO:
+
+    delta = event->time - priv->last_time;
+
+    if (priv->mov_mode&HILDON_MOVEMENT_MODE_VERT) {
+      gdouble dist = event->y - priv->y;
+
+      hildon_pannable_area_calculate_velocity (&priv->vel_y,
+                                               delta,
+                                               dist,
+                                               priv->vmax,
+                                               priv->drag_inertia,
+                                               priv->force,
+                                               priv->sps);
+    } else {
+      *y = 0;
+      priv->vel_y = 0;
+    }
+
+    if (priv->mov_mode&HILDON_MOVEMENT_MODE_HORIZ) {
+      gdouble dist = event->x - priv->x;
+
+      hildon_pannable_area_calculate_velocity (&priv->vel_x,
+                                               delta,
+                                               dist,
+                                               priv->vmax,
+                                               priv->drag_inertia,
+                                               priv->force,
+                                               priv->sps);
+    } else {
+      *x = 0;
+      priv->vel_x = 0;
+    }
+
+    hildon_pannable_area_motion_event_scroll (area, *x, *y);
+
+    if (priv->mov_mode&HILDON_MOVEMENT_MODE_HORIZ)
       priv->x = event->x;
+    if (priv->mov_mode&HILDON_MOVEMENT_MODE_VERT)
       priv->y = event->y;
-      break;
-    case HILDON_PANNABLE_AREA_MODE_ACCEL:
-      /* Set acceleration relative to the initial click */
-      priv->ex = event->x;
-      priv->ey = event->y;
-      priv->vel_x = ((x > 0) ? 1 : -1) *
-       (((ABS (x) /
-          (gdouble) widget->allocation.width) *
-         (priv->vmax - priv->vmin)) + priv->vmin);
-      priv->vel_y = ((y > 0) ? 1 : -1) *
-       (((ABS (y) /
-          (gdouble) widget->allocation.height) *
-         (priv->vmax - priv->vmin)) + priv->vmin);
-      break;
-    case HILDON_PANNABLE_AREA_MODE_AUTO:
 
-      delta = event->time - priv->last_time;
-
-      if (priv->mov_mode&HILDON_MOVEMENT_MODE_VERT) {
-        gdouble dist = event->y - priv->y;
+    break;
+  default:
+    break;
+  }
+}
 
-        hildon_pannable_area_calculate_velocity (&priv->vel_y,
-                                                 delta,
-                                                 dist,
-                                                 priv->vmax,
-                                                 priv->drag_inertia,
-                                                 priv->force,
-                                                 priv->sps);
-      } else {
-        y = 0;
-        priv->vel_y = 0;
-      }
+static gboolean
+hildon_pannable_area_motion_notify_cb (GtkWidget * widget,
+                                      GdkEventMotion * event)
+{
+  HildonPannableArea *area = HILDON_PANNABLE_AREA (widget);
+  HildonPannableAreaPrivate *priv = area->priv;
+  gdouble x, y;
 
-      if (priv->mov_mode&HILDON_MOVEMENT_MODE_HORIZ) {
-        gdouble dist = event->x - priv->x;
+  if (gtk_bin_get_child (GTK_BIN (widget)) == NULL)
+    return TRUE;
 
-        hildon_pannable_area_calculate_velocity (&priv->vel_x,
-                                                 delta,
-                                                 dist,
-                                                 priv->vmax,
-                                                 priv->drag_inertia,
-                                                 priv->force,
-                                                 priv->sps);
-      } else {
-        x = 0;
-        priv->vel_x = 0;
-      }
+  if ((!priv->enabled) || (!priv->button_pressed) ||
+      ((event->time == priv->last_time) && (priv->last_type == 2))) {
+    gdk_window_get_pointer (widget->window, NULL, NULL, 0);
+    return TRUE;
+  }
 
-      hildon_pannable_area_motion_event_scroll (area, x, y);
+  if (priv->last_type == 1) {
+    priv->first_drag = TRUE;
+  }
 
-      if (priv->mov_mode&HILDON_MOVEMENT_MODE_HORIZ)
-        priv->x = event->x;
-      if (priv->mov_mode&HILDON_MOVEMENT_MODE_VERT)
-        priv->y = event->y;
+  x = event->x - priv->x;
+  y = event->y - priv->y;
 
-      break;
+  if (!priv->moved) {
+    hildon_pannable_area_check_move (area, event, &x, &y);
+  }
 
-    default:
-      break;
-    }
+  if (priv->moved) {
+    hildon_pannable_area_handle_move (area, event, &x, &y);
   } else if (priv->child) {
     gboolean in;
     gint pos_x, pos_y;
@@ -2491,7 +2580,7 @@ hildon_pannable_area_button_release_cb (GtkWidget * widget,
 
   if  (((event->time == priv->last_time) && (priv->last_type == 3))
        || (gtk_bin_get_child (GTK_BIN (widget)) == NULL)
-       || (!priv->clicked) || (!priv->enabled) || (event->button != 1))
+       || (!priv->button_pressed) || (!priv->enabled) || (event->button != 1))
     return TRUE;
 
   priv->scroll_indicator_event_interrupt = 0;
@@ -2550,15 +2639,15 @@ hildon_pannable_area_button_release_cb (GtkWidget * widget,
     }
   }
 
-  if ((ABS (priv->vel_y) > 1.0)||
-      (ABS (priv->vel_x) > 1.0)) {
+  if ((ABS (priv->vel_y) > priv->vmin)||
+      (ABS (priv->vel_x) > priv->vmin)) {
     priv->scroll_indicator_alpha = 1.0;
   }
 
   hildon_pannable_area_launch_fade_timeout (HILDON_PANNABLE_AREA (widget),
                                             priv->scroll_indicator_alpha);
 
-  priv->clicked = FALSE;
+  priv->button_pressed = FALSE;
 
   if (priv->mode == HILDON_PANNABLE_AREA_MODE_AUTO ||
       priv->mode == HILDON_PANNABLE_AREA_MODE_ACCEL) {
@@ -2577,6 +2666,12 @@ hildon_pannable_area_button_release_cb (GtkWidget * widget,
     if ((ABS (priv->vel_y) >= priv->vmin) ||
         (ABS (priv->vel_x) >= priv->vmin)) {
 
+      if (ABS (priv->vel_x) > MAX_SPEED_THRESHOLD)
+        priv->vel_x = (priv->vel_x > 0) ? priv->vmax : -priv->vmax;
+
+      if (ABS (priv->vel_y) > MAX_SPEED_THRESHOLD)
+        priv->vel_y = (priv->vel_y > 0) ? priv->vmax : -priv->vmax;
+
       if (!priv->idle_id)
         priv->idle_id = gdk_threads_add_timeout ((gint) (1000.0 / (gdouble) priv->sps),
                                                  (GSourceFunc)
@@ -2734,7 +2829,7 @@ hildon_pannable_area_remove (GtkContainer *container, GtkWidget *child)
   GTK_CONTAINER_CLASS (hildon_pannable_area_parent_class)->remove (container, child);
 }
 
-/**
+/*
  * This method calculates a factor necessary to determine the initial distance
  * to jump in hildon_pannable_area_scroll_to(). For fixed time and frames per
  * second, we know in how many frames 'n' we need to reach the destination
@@ -2759,7 +2854,7 @@ hildon_pannable_area_remove (GtkContainer *container, GtkWidget *child)
  *   vel_factor = 1 + decel_factor + ... + decel_factor^(n-1).
  *
  * That's the gem we calculate in this method.
- **/
+ */
 static void
 hildon_pannable_calculate_vel_factor (HildonPannableArea * self)
 {
@@ -3002,6 +3097,7 @@ hildon_pannable_area_jump_to (HildonPannableArea *area,
 {
   HildonPannableAreaPrivate *priv;
   gint width, height;
+  gdouble hv, vv;
 
   g_return_if_fail (HILDON_IS_PANNABLE_AREA (area));
   g_return_if_fail (GTK_WIDGET_REALIZED (area));
@@ -3018,26 +3114,33 @@ hildon_pannable_area_jump_to (HildonPannableArea *area,
 
   g_return_if_fail (x < width || y < height);
 
+  hv = priv->hadjust->value;
+  vv = priv->vadjust->value;
+
   if (x != -1) {
     gdouble jump_to = x - priv->hadjust->page_size/2;
 
-    if (jump_to > priv->hadjust->upper - priv->hadjust->page_size) {
-      jump_to = priv->hadjust->upper - priv->hadjust->page_size;
-    }
-
-    gtk_adjustment_set_value (priv->hadjust, jump_to);
+    priv->hadjust->value = CLAMP (jump_to,
+                                  priv->hadjust->lower,
+                                  priv->hadjust->upper -
+                                  priv->hadjust->page_size);
   }
 
   if (y != -1) {
     gdouble jump_to =  y - priv->vadjust->page_size/2;
 
-    if (jump_to > priv->vadjust->upper - priv->vadjust->page_size) {
-      jump_to = priv->vadjust->upper - priv->vadjust->page_size;
-    }
-
-    gtk_adjustment_set_value (priv->vadjust, jump_to);
+    priv->vadjust->value = CLAMP (jump_to,
+                                  priv->vadjust->lower,
+                                  priv->vadjust->upper -
+                                  priv->vadjust->page_size);
   }
 
+  if (hv != priv->hadjust->value)
+    gtk_adjustment_value_changed (priv->hadjust);
+
+  if (vv != priv->vadjust->value)
+    gtk_adjustment_value_changed (priv->vadjust);
+
   priv->scroll_indicator_alpha = 1.0;
 
   if (priv->scroll_indicator_timeout) {