[*][Scroller] merge from upstream revision 64051, but didn't accept data/theme/widget...
[framework/uifw/elementary.git] / src / lib / els_scroller.c
index ac4a62f..484efdb 100644 (file)
@@ -36,8 +36,12 @@ struct _Smart_Data
         Evas_Coord b2x, b2y;
         struct {
              Evas_Coord    x, y;
-             double        timestamp;
-        } history[20];
+             double        timestamp, localtimestamp;
+        } history[60];
+        struct {
+           double tadd, dxsum, dysum;
+           double est_timestamp_diff;
+        } hist;
       double anim_start;
       double anim_start2;
       double anim_start3;
@@ -103,10 +107,10 @@ struct _Smart_Data
    unsigned char bouncemey : 1;
    unsigned char bounce_horiz : 1;
    unsigned char bounce_vert : 1;
-   unsigned char momentum_animator_disabled :1;
-   unsigned char bounce_animator_disabled :1;
-   Eina_Bool is_mirrored : 1;
    unsigned char event_propagation :1;
+   Eina_Bool momentum_animator_disabled :1;
+   Eina_Bool bounce_animator_disabled :1;
+   Eina_Bool is_mirrored : 1;
    Eina_Bool wheel_disabled : 1;
 };
 
@@ -212,11 +216,8 @@ elm_smart_scroller_child_set(Evas_Object *obj, Evas_Object *child)
         sd->pan_obj = o;
         evas_object_smart_callback_add(o, "changed", _smart_pan_changed_hook, sd);
         evas_object_smart_callback_add(o, "pan_changed", _smart_pan_pan_changed_hook, sd);
-        _elm_smart_pan_child_set(o, child);
         edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", o);
      }
-   else
-     _elm_smart_pan_child_set(sd->pan_obj, child);
 
    sd->pan_func.set = _elm_smart_pan_set;
    sd->pan_func.get = _elm_smart_pan_get;
@@ -225,6 +226,7 @@ elm_smart_scroller_child_set(Evas_Object *obj, Evas_Object *child)
    sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
 
    evas_object_event_callback_add(child, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
+   _elm_smart_pan_child_set(sd->pan_obj, child);
    sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
    sd->child.w = w;
    sd->child.h = h;
@@ -470,6 +472,8 @@ _smart_momentum_end(Smart_Data *sd)
         sd->down.bounce_y_hold = 0;
         sd->down.ax = 0;
         sd->down.ay = 0;
+        sd->down.dx = 0;
+        sd->down.dy = 0;
         sd->down.pdx = 0;
         sd->down.pdy = 0;
      }
@@ -498,9 +502,9 @@ _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
    sd->scrollto.x.t_end = t + t_in;
    if (!sd->scrollto.x.animator)
      {
+        sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
         if (!sd->scrollto.y.animator)
           _smart_anim_start(sd->smart_obj);
-        sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
      }
    if (sd->down.bounce_x_animator)
      {
@@ -562,9 +566,9 @@ _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
    sd->scrollto.y.t_end = t + t_in;
    if (!sd->scrollto.y.animator)
      {
+        sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
         if (!sd->scrollto.x.animator)
           _smart_anim_start(sd->smart_obj);
-        sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
      }
    if (sd->down.bounce_y_animator)
      {
@@ -688,7 +692,7 @@ _smart_bounce_x_animator(void *data)
         if (sd->down.momentum_animator)
           {
              ed = abs(sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) - sd->down.b0x);
-             md = abs(15*w); // FIXME : 15 - probably should be config
+             md = abs(_elm_config->thumbscroll_friction*5*w);
              if (ed > md) r = (double)(md)/(double)ed;
           }
         x = sd->down.b2x + (int)((double)(dx - odx)*r);
@@ -742,7 +746,7 @@ _smart_bounce_y_animator(void *data)
         if (sd->down.momentum_animator)
           {
              ed = abs(sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) - sd->down.b0y);
-             md = abs(15*h); // FIXME : 15 - probably should be config
+             md = abs(_elm_config->thumbscroll_friction*5*h);
              if (ed > md) r = (double)(md)/(double)ed;
           }
         y = sd->down.b2y + (int)((double)(dy - ody)*r);
@@ -850,6 +854,7 @@ _smart_momentum_animator(void *data)
              y = py;
           }
         elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
+        _update_wanted_coordinates(sd, x, y);
         sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
         sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
         if (!sd->bounce_horiz)
@@ -867,7 +872,6 @@ _smart_momentum_animator(void *data)
             (no_bounce_x_end && no_bounce_y_end))
           {
              _smart_anim_stop(sd->smart_obj);
-             _update_wanted_coordinates(sd, px, py);
 
              sd->down.momentum_animator = NULL;
              sd->down.bounce_x_hold = 0;
@@ -914,7 +918,7 @@ bounce_eval(Smart_Data *sd)
    if ((!sd->widget) ||
        (!elm_widget_drag_child_locked_x_get(sd->widget)))
      {
-        if (!sd->down.bounce_x_animator && !sd->bounce_animator_disabled)
+        if ((!sd->down.bounce_x_animator) && (!sd->bounce_animator_disabled))
           {
              if (sd->bouncemex)
                {
@@ -936,7 +940,7 @@ bounce_eval(Smart_Data *sd)
    if ((!sd->widget) ||
        (!elm_widget_drag_child_locked_y_get(sd->widget)))
      {
-        if (!sd->down.bounce_y_animator && !sd->bounce_animator_disabled)
+        if ((!sd->down.bounce_y_animator) && (!sd->bounce_animator_disabled))
           {
              if (sd->bouncemey)
                {
@@ -1002,19 +1006,25 @@ elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
      edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
    if (!sd->down.bounce_x_animator)
      {
-        if ((x < minx) || (x > (mx + minx)))
+        if (((x < minx) && (0 <= sd->down.dx)) ||
+            ((x > (mx + minx)) && (0 >= sd->down.dx)))
           {
              sd->bouncemex = 1;
              bounce_eval(sd);
           }
+        else
+           sd->bouncemex = 0;
      }
    if (!sd->down.bounce_y_animator)
      {
-        if ((y < miny) || (y > my + miny))
+        if (((y < miny) && (0 <= sd->down.dy)) ||
+            ((y > (my + miny)) && (0 >= sd->down.dy)))
           {
              sd->bouncemey = 1;
              bounce_eval(sd);
           }
+        else
+           sd->bouncemey = 0;
      }
    if ((x != px) || (y != py))
      {
@@ -1043,18 +1053,19 @@ elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
    sd->pan_func.get(sd->pan_obj, x, y);
 }
 
-/* "internal_call" actually toggles whether we should save the coords and do
- * extra "speedup" checks, or not. */
-static void
-_elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, Eina_Bool internal_call)
+/* returns TRUE when we need to move the scroller, FALSE otherwise.
+ * Updates w and h either way, so save them if you need them. */
+static Eina_Bool
+_elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord *_x, Evas_Coord *_y, Evas_Coord w, Evas_Coord h)
 {
-   Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
+   Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0, pw = 0, ph = 0, x = *_x, y = *_y;
 
-   API_ENTRY return;
+   API_ENTRY return EINA_FALSE;
    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
    sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
    sd->pan_func.get(sd->pan_obj, &px, &py);
+   evas_object_geometry_get(sd->pan_obj, NULL, NULL, &pw, &ph);
 
    nx = px;
    if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
@@ -1062,14 +1073,6 @@ _elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord x, E
    ny = py;
    if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
    else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
-   if (!internal_call)
-     {
-        sd->wx = x;
-        sd->wy = y;
-        sd->ww = w;
-        sd->wh = h;
-        if ((nx == px) && (ny == py)) return;
-     }
 
    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
        (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
@@ -1115,13 +1118,18 @@ _elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord x, E
         sd->down.pdx = 0;
         sd->down.pdy = 0;
      }
+
    x = nx;
-   if ((x + w) > cw) x = cw - w;
+   if ((x + pw) > cw) x = cw - pw;
    if (x < minx) x = minx;
    y = ny;
-   if ((y + h) > ch) y = ch - h;
+   if ((y + ph) > ch) y = ch - ph;
    if (y < miny) y = miny;
-   elm_smart_scroller_child_pos_set(obj, x, y);
+
+   if ((x == px) && (y == py)) return EINA_FALSE;
+   *_x = x;
+   *_y = y;
+   return EINA_TRUE;
 }
 
 /* Set should be used for calculated positions, for example, when we move
@@ -1130,7 +1138,8 @@ _elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord x, E
 void
 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
 {
-   _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_TRUE);
+   if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
+      elm_smart_scroller_child_pos_set(obj, x, y);
 }
 
 /* Set should be used for setting the wanted position, for example a user scroll
@@ -1138,7 +1147,13 @@ elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y
 void
 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
 {
-   _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_FALSE);
+   API_ENTRY return;
+   sd->wx = x;
+   sd->wy = y;
+   sd->ww = w;
+   sd->wh = h;
+   if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
+      elm_smart_scroller_child_pos_set(obj, x, y);
 }
 
 void
@@ -1320,8 +1335,8 @@ void
 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
 {
    API_ENTRY return;
-   *horiz = sd->bounce_horiz;
-   *vert = sd->bounce_vert;
+   if (horiz) *horiz = sd->bounce_horiz;
+   if (vert) *vert = sd->bounce_vert;
 }
 
 void
@@ -1332,7 +1347,7 @@ elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel
    sd->pagerel_v = pagerel_v;
    sd->pagesize_h = pagesize_h;
    sd->pagesize_v = pagesize_v;
-   if (sd->child_obj) _smart_page_adjust(sd);
+   _smart_page_adjust(sd);
 }
 
 void
@@ -1348,77 +1363,12 @@ elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pager
 void
 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
 {
-   Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
-
    API_ENTRY return;
-   sd->pan_func.max_get(sd->pan_obj, &mx, &my);
-   sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
-   sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
-   sd->pan_func.get(sd->pan_obj, &px, &py);
-
-   nx = px;
-   if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
-   else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
-   ny = py;
-   if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
-   else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
-   sd->wx = x;
-   sd->wy = y;
-   sd->ww = w;
-   sd->wh = h;
-   if ((nx == px) && (ny == py)) return;
-   if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
-       (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
-     {
-        _smart_anim_stop(sd->smart_obj);
-     }
-   if (sd->scrollto.x.animator)
-     {
-        ecore_animator_del(sd->scrollto.x.animator);
-        sd->scrollto.x.animator = NULL;
-     }
-   if (sd->scrollto.y.animator)
+   if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
      {
-        ecore_animator_del(sd->scrollto.y.animator);
-        sd->scrollto.y.animator = NULL;
+        _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
+        _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
      }
-   if (sd->down.bounce_x_animator)
-     {
-        ecore_animator_del(sd->down.bounce_x_animator);
-        sd->down.bounce_x_animator = NULL;
-        sd->bouncemex = 0;
-     }
-   if (sd->down.bounce_y_animator)
-     {
-        ecore_animator_del(sd->down.bounce_y_animator);
-        sd->down.bounce_y_animator = NULL;
-        sd->bouncemey = 0;
-     }
-   if (sd->down.hold_animator)
-     {
-        ecore_animator_del(sd->down.hold_animator);
-        sd->down.hold_animator = NULL;
-        _smart_drag_stop(sd->smart_obj);
-     }
-   if (sd->down.momentum_animator)
-     {
-        ecore_animator_del(sd->down.momentum_animator);
-        sd->down.momentum_animator = NULL;
-        sd->down.bounce_x_hold = 0;
-        sd->down.bounce_y_hold = 0;
-        sd->down.ax = 0;
-        sd->down.ay = 0;
-        sd->down.pdx = 0;
-        sd->down.pdy = 0;
-     }
-   x = nx;
-   if ((x + w) > cw) x = cw - w;
-   if (x < minx) x = minx;
-   _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
-   y = ny;
-   if ((y + h) > ch) y = ch - h;
-   if (y < miny) y = miny;
-   _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
 }
 
 void
@@ -1434,6 +1384,10 @@ _elm_smart_scroller_wanted_region_set(Evas_Object *obj)
    INTERNAL_ENTRY;
    Evas_Coord ww, wh, wx = sd->wx;
 
+   if (sd->down.now || sd->down.momentum_animator ||
+       sd->down.bounce_x_animator || sd->down.bounce_y_animator ||
+       sd->down.hold_animator || sd->down.onhold_animator) return;
+
    /* Flip to RTL cords only if init in RTL mode */
    if(sd->is_mirrored)
      wx = _elm_smart_scroller_x_mirrored_get(obj, sd->wx);
@@ -1697,6 +1651,11 @@ _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSE
           }
         if (ev->button == 1)
           {
+             sd->down.hist.est_timestamp_diff =
+                ecore_loop_time_get() - ((double)ev->timestamp / 1000.0);
+             sd->down.hist.tadd = 0.0;
+             sd->down.hist.dxsum = 0.0;
+             sd->down.hist.dysum = 0.0;
              sd->down.now = 1;
              sd->down.dragged = 0;
              sd->down.dir_x = 0;
@@ -1707,9 +1666,10 @@ _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSE
              sd->down.sx = x;
              sd->down.sy = y;
              sd->down.locked = 0;
-             memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
+             memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 60);
 #ifdef EVTIME
              sd->down.history[0].timestamp = ev->timestamp / 1000.0;
+             sd->down.history[0].localtimestamp = ecore_loop_time_get();
 #else
              sd->down.history[0].timestamp = ecore_loop_time_get();
 #endif
@@ -1726,11 +1686,119 @@ _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSE
      }
 }
 
+static void
+_down_coord_eval(Smart_Data *sd, Evas_Coord *x, Evas_Coord *y)
+{
+   Evas_Coord minx, miny;
+
+   if (sd->down.dir_x) *x = sd->down.sx - (*x - sd->down.x);
+   else *x = sd->down.sx;
+   if (sd->down.dir_y) *y = sd->down.sy - (*y - sd->down.y);
+   else *y = sd->down.sy;
+
+   if ((sd->down.dir_x) || (sd->down.dir_y))
+     {
+        if (!((sd->down.dir_x) && (sd->down.dir_y)))
+          {
+             if (sd->down.dir_x) *y = sd->down.locked_y;
+             else *x = sd->down.locked_x;
+          }
+     }
+
+   sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
+
+   if (*x < minx)
+      *x += (minx - *x) * _elm_config->thumbscroll_border_friction;
+   else if (sd->child.w <= sd->w)
+      *x += (sd->down.sx - *x) * _elm_config->thumbscroll_border_friction;
+   else if ((sd->child.w - sd->w + minx) < *x)
+      *x += (sd->child.w - sd->w + minx - *x) *
+      _elm_config->thumbscroll_border_friction;
+
+   if (*y < miny)
+      *y += (miny - *y) * _elm_config->thumbscroll_border_friction;
+   else if (sd->child.h <= sd->h)
+      *y += (sd->down.sy - *y) * _elm_config->thumbscroll_border_friction;
+   else if ((sd->child.h - sd->h + miny) < *y)
+      *y += (sd->child.h - sd->h + miny - *y) *
+      _elm_config->thumbscroll_border_friction;
+}
+
 static Eina_Bool
 _smart_hold_animator(void *data)
 {
    Smart_Data *sd = data;
-   Evas_Coord ox, oy;
+   Evas_Coord ox = 0, oy = 0, fx = 0, fy= 0;
+
+   fx = sd->down.hold_x;
+   fy = sd->down.hold_y;
+
+   if ((!sd->hold) && (!sd->freeze) && (_elm_config->scroll_smooth_time_interval > 0.0))
+     {
+        int i, count = 0; //count for the real event number we have to deal with
+        int queue_size = 10; //for event queue size
+        int src_index = 0, dst_index = 0;
+        int xsum = 0, ysum=0;
+        Evas_Coord  x=0, y=0;
+
+        struct {
+             Evas_Coord x, y;
+             double t;
+        } pos[queue_size];
+
+        double tdiff, tnow;
+        double time_interval=_elm_config->scroll_smooth_time_interval;
+        // FIXME: assume server and client have the same "timezone"
+        // (0 timepoint) for now. this needs to be figured out in advance
+        // though.
+        tdiff = sd->down.hist.est_timestamp_diff;
+        tnow = ecore_time_get() - tdiff;
+
+        for(i = 0; i < queue_size; i++)
+          {
+             x = sd->down.history[i].x;
+             y = sd->down.history[i].y;
+
+             //if there is no history value , we don't deal with it
+             //if there is better wat to know existance of history value , I will modify this code to it
+             if ( (x == 0) && (y == 0) )
+               {
+                  break;
+               }
+             _down_coord_eval(sd, &x, &y);
+
+             pos[i].x = x;
+             pos[i].y = y;
+             pos[i].t = tnow - sd->down.history[i].timestamp;
+          }
+        count = --i;
+
+        // we only deal with smooth scroll there is enough history
+        for(i = 0; i < queue_size; i++)
+          {
+             if (src_index > count) break;
+             if (i == 0)
+               {
+                  xsum = pos[i].x;
+                  ysum = pos[i].y;
+                  dst_index++;
+                  continue;
+               }
+             while ((pos[src_index].t < time_interval *i) &&
+                     (src_index <= count))
+               {
+                  src_index++;
+               }
+             if (src_index <= count)
+               {
+                  xsum += pos[src_index].x;
+                  ysum += pos[src_index].y;
+                  dst_index++;
+               }
+          }
+        fx = xsum / dst_index;
+        fy = ysum / dst_index;
+     }
 
    elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
    if (sd->down.dir_x)
@@ -1738,7 +1806,7 @@ _smart_hold_animator(void *data)
         if ((!sd->widget) ||
             (!elm_widget_drag_child_locked_x_get(sd->widget)))
           {
-             ox = sd->down.hold_x;
+             ox = fx;
           }
      }
    if (sd->down.dir_y)
@@ -1746,7 +1814,7 @@ _smart_hold_animator(void *data)
         if ((!sd->widget) ||
             (!elm_widget_drag_child_locked_y_get(sd->widget)))
           {
-             oy = sd->down.hold_y;
+             oy = fy;
           }
      }
    elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
@@ -1774,10 +1842,13 @@ _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *ev
    Evas_Event_Mouse_Down *ev;
    Smart_Data *sd;
    Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
+   Evas_Coord vw, vh, aw, ah;
 
    sd = data;
    ev = event_info;
    sd->down.hold_parent = 0;
+   sd->down.dx = 0;
+   sd->down.dy = 0;
    //   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
    evas_post_event_callback_push(e, _smart_event_post_up, sd);
    // FIXME: respect elm_widget_scroll_hold_get of parent container
@@ -1813,7 +1884,7 @@ _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *ev
 #ifdef SCROLLDBG
                        printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
 #endif
-                       for (i = 0; i < 20; i++)
+                       for (i = 0; i < 60; i++)
                          {
                             dt = t - sd->down.history[i].timestamp;
                             if (dt > 0.2) break;
@@ -1829,7 +1900,7 @@ _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *ev
                        ax /= (i + 1);
                        ay /= (i + 1);
                        at /= (i + 1);
-                       at *= 4.0;
+                       at /= _elm_config->thumbscroll_sensitivity_friction;
                        dx = ev->canvas.x - ax;
                        dy = ev->canvas.y - ay;
                        if (at > 0)
@@ -1838,36 +1909,55 @@ _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *ev
                             if ((_elm_config->thumbscroll_friction > 0.0) &&
                                 (vel > _elm_config->thumbscroll_momentum_threshold))
                               {
+                                 int minx, miny, mx, my, px, py;
+                                 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
+                                 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
+                                 sd->pan_func.get(sd->pan_obj, &px, &py);
                                  sd->down.dx = ((double)dx / at);
                                  sd->down.dy = ((double)dy / at);
                                  if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
-                                     ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
-                                     ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
-                                     ((sd->down.dy < 0) && (sd->down.pdy < 0)))
-                                  {
-                                    double t = ecore_loop_time_get();
-                                    double dt = t - sd->down.anim_start;
-
-                                    if (dt < 0.0) dt = 0.0;
-                                    else if (dt > _elm_config->thumbscroll_friction)
-                                      dt = _elm_config->thumbscroll_friction;
-                                    sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
-                                  }
-                                 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
                                      ((sd->down.dx < 0) && (sd->down.pdx < 0)))
-                                   sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
+                                   if (px > minx && px < mx)
+                                     sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
                                  if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
                                      ((sd->down.dy < 0) && (sd->down.pdy < 0)))
-                                   sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
+                                   if (py > miny && py < my)
+                                     sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
+                                 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
+                                     ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
+                                     ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
+                                     ((sd->down.dy < 0) && (sd->down.pdy < 0)))
+                                   {
+                                      double t = ecore_loop_time_get();
+                                      double dt = t - sd->down.anim_start;
+
+                                      if (dt < 0.0) dt = 0.0;
+                                      else if (dt > _elm_config->thumbscroll_friction)
+                                        dt = _elm_config->thumbscroll_friction;
+                                      sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
+                                   }
                                  else
                                    sd->down.extra_time = 0.0;
+                                 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &vw, &vh);
+                                 aw = abs(sd->down.dx);
+                                 if (aw  > vw*3)
+                                   {
+                                      if (sd->down.dx > 0) sd->down.dx = vw*3;
+                                      else sd->down.dx = -(vw*3);
+                                   }
+                                 ah = abs(sd->down.dy);
+                                 if (ah  > vh*3)
+                                   {
+                                      if (sd->down.dy > 0) sd->down.dy = vh*3;
+                                      else sd->down.dy = -(vh*3);
+                                   }
                                  sd->down.pdx = sd->down.dx;
                                  sd->down.pdy = sd->down.dy;
                                  ox = -sd->down.dx;
                                  oy = -sd->down.dy;
                                  if (!_smart_do_page(sd))
                                    {
-                                      if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
+                                      if ((!sd->down.momentum_animator) && (!sd->momentum_animator_disabled))
                                         {
                                            sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
                                            ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
@@ -1882,11 +1972,6 @@ _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *ev
                                    }
                               }
                          }
-                       if (sd->down.hold_animator)
-                         {
-                            ecore_animator_del(sd->down.hold_animator);
-                            sd->down.hold_animator = NULL;
-                         }
                     }
                   else
                     {
@@ -1943,11 +2028,11 @@ _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *ev
                             if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
                          }
                     }
-                  if (sd->down.hold_animator)
-                    {
-                       ecore_animator_del(sd->down.hold_animator);
-                       sd->down.hold_animator = NULL;
-                    }
+               }
+             if (sd->down.hold_animator)
+               {
+                  ecore_animator_del(sd->down.hold_animator);
+                  sd->down.hold_animator = NULL;
                }
              if (sd->down.scroll)
                {
@@ -2106,9 +2191,10 @@ _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *
              printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
 #endif
              memmove(&(sd->down.history[1]), &(sd->down.history[0]),
-                     sizeof(sd->down.history[0]) * 19);
+                     sizeof(sd->down.history[0]) * (60 - 1));
 #ifdef EVTIME
              sd->down.history[0].timestamp = ev->timestamp / 1000.0;
+             sd->down.history[0].localtimestamp = ecore_loop_time_get();
 #else
              sd->down.history[0].timestamp = ecore_loop_time_get();
 #endif
@@ -2217,7 +2303,6 @@ _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *
                                  else x = sd->down.locked_x;
                               }
                          }
-                       if (_elm_config->thumbscroll_border_friction > 0.0)
                          {
                             Evas_Coord minx, miny;
                             sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
@@ -2581,14 +2666,11 @@ _smart_scrollbar_size_adjust(Smart_Data *sd)
      {
         Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
 
-       edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
-       edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
-        if (sd->pan_obj)
-          {
-             sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
-             sd->pan_func.get(sd->pan_obj, &px, &py);
-             sd->pan_func.set(sd->pan_obj, minx, miny);
-          }
+        edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
+        edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
+        sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
+        sd->pan_func.get(sd->pan_obj, &px, &py);
+        sd->pan_func.set(sd->pan_obj, minx, miny);
         if ((px != minx) || (py != miny))
           edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
      }
@@ -2633,8 +2715,8 @@ _smart_add(Evas_Object *obj)
    sd->bounce_vert = 1;
 
    sd->one_dir_at_a_time = 1;
-   sd->momentum_animator_disabled = 0;
-   sd->bounce_animator_disabled = 0;
+   sd->momentum_animator_disabled = EINA_FALSE;
+   sd->bounce_animator_disabled = EINA_FALSE;
 
    o = edje_object_add(evas_object_evas_get(obj));
    evas_object_propagate_events_set(o, 0);
@@ -2779,4 +2861,3 @@ _smart_init(void)
         _smart = evas_smart_class_new(&sc);
      }
 }
-