[els_scroller] merge the part of region_show, bring_in
authorJaehwan Kim <jae.hwan.kim@samsung.com>
Tue, 5 Jul 2011 09:04:08 +0000 (18:04 +0900)
committerJaehwan Kim <jae.hwan.kim@samsung.com>
Tue, 5 Jul 2011 09:04:08 +0000 (18:04 +0900)
Change-Id: I35c6cd1d9a8f920f9149fa7f5d69e57af2c1eaf6

src/lib/els_scroller.c

index b2b43dc..6cbf206 100644 (file)
@@ -1046,18 +1046,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;
@@ -1065,14 +1066,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))
@@ -1118,13 +1111,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
@@ -1133,7 +1131,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
@@ -1141,7 +1140,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
@@ -1351,77 +1356,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)
+   if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
      {
-        ecore_animator_del(sd->scrollto.x.animator);
-        sd->scrollto.x.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->scrollto.y.animator)
-     {
-        ecore_animator_del(sd->scrollto.y.animator);
-        sd->scrollto.y.animator = NULL;
-     }
-   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
@@ -2897,4 +2837,3 @@ _smart_init(void)
         _smart = evas_smart_class_new(&sc);
      }
 }
-