scrollable: fix page snap behavior. 13/200213/2
authorHosang Kim <hosang12.kim@samsung.com>
Tue, 19 Feb 2019 02:11:52 +0000 (11:11 +0900)
committerkim hosang <hosang12.kim@samsung.com>
Wed, 6 Mar 2019 09:45:59 +0000 (09:45 +0000)
Sometimes page snap feature is not working.
Because there are two points to calculate the location of the current page.

@tizen_only
Change-Id: I5993d6c9d3b613fc095b6a1d4233d496d443f464

src/lib/elementary/elm_interface_scrollable.c
src/lib/elementary/elm_interface_scrollable.eo
src/lib/elementary/elm_interface_scrollable.h
src/lib/elementary/elm_scroller.c

index aff74d6..a963134 100644 (file)
@@ -1337,33 +1337,52 @@ _elm_scroll_scroll_bar_read_and_update(
    _elm_scroll_wanted_coordinates_update(sid, x, y);
 }
 
+//TIZEN_ONLY(20190219): fix page snap behavior.
 static void
-_elm_scroll_drag_start(Elm_Scrollable_Smart_Interface_Data *sid)
+_elm_scroll_scroll_start(Elm_Scrollable_Smart_Interface_Data *sid)
 {
    sid->current_page.x = _elm_scroll_page_x_get(sid, 0, EINA_FALSE);
    sid->current_page.y = _elm_scroll_page_y_get(sid, 0, EINA_FALSE);
 
-   if (sid->cb_func.drag_start)
-     sid->cb_func.drag_start(sid->obj, NULL);
+   sid->scrolling = EINA_TRUE;
+
+   if (sid->cb_func.scroll_start)
+     sid->cb_func.scroll_start(sid->obj, NULL);
 }
 
 static void
-_elm_scroll_drag_stop(Elm_Scrollable_Smart_Interface_Data *sid)
+_elm_scroll_scroll_stop(Elm_Scrollable_Smart_Interface_Data *sid)
 {
    Evas_Coord x, y;
+   sid->scrolling = EINA_FALSE;
+   x = _elm_scroll_page_x_get(sid, 0, EINA_FALSE);
+   y = _elm_scroll_page_y_get(sid, 0, EINA_FALSE);
+   if ((sid->cb_func.page_change) &&
+       ((x != sid->current_page.x) || (y != sid->current_page.y)))
+     sid->cb_func.page_change(sid->obj, NULL);
+   sid->current_page.x = x;
+   sid->current_page.y = y;
+
+   if (sid->cb_func.scroll_stop)
+     sid->cb_func.scroll_stop(sid->obj, NULL);
+}
+//
 
-   if (!(sid->down.bounce_x_animator) && !(sid->down.bounce_y_animator) &&
-       !(sid->scrollto.x.animator) && !(sid->scrollto.y.animator))
-     {
-        x = _elm_scroll_page_x_get(sid, 0, EINA_FALSE);
-        y = _elm_scroll_page_y_get(sid, 0, EINA_FALSE);
-        if (sid->cb_func.page_change &&
-            ((x != sid->current_page.x) || (y != sid->current_page.y)))
-          sid->cb_func.page_change(sid->obj, NULL);
-        sid->current_page.x = x;
-        sid->current_page.y = y;
-     }
+static void
+_elm_scroll_drag_start(Elm_Scrollable_Smart_Interface_Data *sid)
+{
+   if (sid->cb_func.drag_start)
+     sid->cb_func.drag_start(sid->obj, NULL);
 
+   //TIZEN_ONLY(20190219): fix page snap behavior.
+   if (!sid->scrolling)
+     _elm_scroll_scroll_start(sid);
+   //
+}
+
+static void
+_elm_scroll_drag_stop(Elm_Scrollable_Smart_Interface_Data *sid)
+{
    if (sid->cb_func.drag_stop)
      sid->cb_func.drag_stop(sid->obj, NULL);
 }
@@ -1371,11 +1390,13 @@ _elm_scroll_drag_stop(Elm_Scrollable_Smart_Interface_Data *sid)
 static void
 _elm_scroll_anim_start(Elm_Scrollable_Smart_Interface_Data *sid)
 {
-   sid->current_page.x = _elm_scroll_page_x_get(sid, 0, EINA_FALSE);
-   sid->current_page.y = _elm_scroll_page_y_get(sid, 0, EINA_FALSE);
-
    if (sid->cb_func.animate_start)
      sid->cb_func.animate_start(sid->obj, NULL);
+
+   //TIZEN_ONLY(20190219): fix page snap behavior.
+   if (!sid->scrolling)
+     _elm_scroll_scroll_start(sid);
+   //
 }
 
 static void
@@ -1383,18 +1404,13 @@ _elm_scroll_anim_stop(Elm_Scrollable_Smart_Interface_Data *sid)
 {
    Evas_Coord x, y;
 
-   if (sid->cb_func.page_change)
-     {
-        x = _elm_scroll_page_x_get(sid, 0, EINA_FALSE);
-        y = _elm_scroll_page_y_get(sid, 0, EINA_FALSE);
-        if ((x != sid->current_page.x) || (y != sid->current_page.y))
-           sid->cb_func.page_change(sid->obj, NULL);
-        sid->current_page.x = x;
-        sid->current_page.y = y;
-     }
-
    if (sid->cb_func.animate_stop)
      sid->cb_func.animate_stop(sid->obj, NULL);
+
+   //TIZEN_ONLY(20190219): fix page snap behavior.
+   if (sid->scrolling)
+     _elm_scroll_scroll_stop(sid);
+   //
 }
 
 static void
@@ -3431,6 +3447,13 @@ _elm_scroll_mouse_up_event_cb(void *data,
 
         if (!_paging_is_enabled(sid))
           _elm_scroll_bounce_eval(sid);
+
+        //TIZEN_ONLY(20190219): fix page snap behavior.
+        if (sid->scrolling && !sid->down.momentum_animator &&
+            !sid->down.bounce_x_animator && !sid->down.bounce_y_animator &&
+            !sid->scrollto.x.animator && !sid->scrollto.y.animator)
+          _elm_scroll_scroll_stop(sid);
+        //
      }
 }
 
@@ -4875,6 +4898,20 @@ _elm_interface_scrollable_animate_stop_cb_set(Eo *obj EINA_UNUSED, Elm_Scrollabl
    sid->cb_func.animate_stop = animate_stop_cb;
 }
 
+//TIZEN_ONLY(20190219): fix page snap behavior.
+EOLIAN static void
+_elm_interface_scrollable_scroll_start_cb_set(Eo *obj EINA_UNUSED, Elm_Scrollable_Smart_Interface_Data *sid, Elm_Interface_Scrollable_Cb scroll_start_cb)
+{
+   sid->cb_func.scroll_start = scroll_start_cb;
+}
+
+EOLIAN static void
+_elm_interface_scrollable_scroll_stop_cb_set(Eo *obj EINA_UNUSED, Elm_Scrollable_Smart_Interface_Data *sid, Elm_Interface_Scrollable_Cb scroll_stop_cb)
+{
+   sid->cb_func.scroll_stop = scroll_stop_cb;
+}
+//
+
 EOLIAN static void
 _elm_interface_scrollable_page_change_cb_set(Eo *obj EINA_UNUSED, Elm_Scrollable_Smart_Interface_Data *sid, Elm_Interface_Scrollable_Cb page_change_cb EINA_UNUSED)
 {
@@ -5457,6 +5494,9 @@ _elm_interface_scrollable_efl_canvas_group_group_add(Eo *obj, Elm_Scrollable_Sma
    sid->momentum_animator_disabled = EINA_FALSE;
    sid->bounce_animator_disabled = EINA_FALSE;
    sid->block = EFL_UI_SCROLL_BLOCK_NONE;
+   //TIZEN_ONLY(20190219): fix page snap behavior.
+   sid->scrolling = EINA_FALSE;
+   //
 
    _elm_scroll_scroll_bar_reset(sid);
 
index 034c80f..a56f3ef 100644 (file)
@@ -309,6 +309,16 @@ mixin Elm.Interface_Scrollable requires Efl.Ui.Widget extends Efl.Ui.Scrollable,
             drag_start_cb: Elm_Interface_Scrollable_Cb @nullable; [[The callback]]
          }
       }
+      //TIZEN_ONLY(20190219): fix page snap behavior.
+      @property scroll_start_cb {
+         set {
+            [[Set the callback to run when scrolling of the contents has started.]]
+         }
+         values {
+            scroll_start_cb: Elm_Interface_Scrollable_Cb @nullable; [[The callback]]
+         }
+      }
+      //
       @property freeze {
           [[Freeze property]]
          set {
@@ -365,6 +375,16 @@ mixin Elm.Interface_Scrollable requires Efl.Ui.Widget extends Efl.Ui.Scrollable,
             drag_stop_cb: Elm_Interface_Scrollable_Cb @nullable; [[The callback]]
          }
       }
+      //TIZEN_ONLY(20190219): fix page snap behavior.
+      @property scroll_stop_cb {
+         set {
+            [[Set the callback to run when scrolling of the contents has stopped.]]
+         }
+         values {
+            scroll_stop_cb: Elm_Interface_Scrollable_Cb @nullable; [[The callback]]
+         }
+      }
+      //
       @property extern_pan {
           [[Extern pan]]
          set {
index 894b892..1771a18 100644 (file)
@@ -180,6 +180,10 @@ struct _Elm_Scrollable_Smart_Interface_Data
       Elm_Interface_Scrollable_Cb hbar_press;
       Elm_Interface_Scrollable_Cb hbar_unpress;
       Elm_Interface_Scrollable_Cb page_change;
+      //TIZEN_ONLY(20190219): fix page snap behavior.
+      Elm_Interface_Scrollable_Cb scroll_start;
+      Elm_Interface_Scrollable_Cb scroll_stop;
+      //
 
       Elm_Interface_Scrollable_Min_Limit_Cb content_min_limit;
       Elm_Interface_Scrollable_Resize_Cb content_viewport_resize;
@@ -236,6 +240,9 @@ struct _Elm_Scrollable_Smart_Interface_Data
    Eina_Bool  go_down : 1;
    Eina_Bool  loop_h : 1;
    Eina_Bool  loop_v : 1;
+   //TIZEN_ONLY(20190219): fix page snap behavior.
+   Eina_Bool  scrolling : 1;
+   //
 
    Efl_Ui_Focus_Manager *manager;
 
index 60b8c58..fb6ef04 100644 (file)
@@ -798,6 +798,24 @@ _scroll_drag_stop_cb(Evas_Object *obj,
      (obj, EFL_UI_EVENT_SCROLL_DRAG_STOP, NULL);
 }
 
+//TIZEN_ONLY(20190219): fix page snap behavior.
+static void
+_scroll_start_cb(Evas_Object *obj,
+                      void *data EINA_UNUSED)
+{
+   efl_event_callback_legacy_call
+     (obj, EFL_UI_EVENT_SCROLL_START, NULL);
+}
+
+static void
+_scroll_stop_cb(Evas_Object *obj,
+                     void *data EINA_UNUSED)
+{
+   efl_event_callback_legacy_call
+     (obj, EFL_UI_EVENT_SCROLL_STOP, NULL);
+}
+//
+
 static void
 _vbar_drag_cb(Evas_Object *obj,
                 void *data EINA_UNUSED)
@@ -1058,6 +1076,10 @@ _elm_scroller_efl_canvas_group_group_add(Eo *obj, Elm_Scroller_Data *priv)
    elm_interface_scrollable_scroll_right_cb_set(obj, _scroll_right_cb);
    elm_interface_scrollable_scroll_up_cb_set(obj, _scroll_up_cb);
    elm_interface_scrollable_scroll_down_cb_set(obj, _scroll_down_cb);
+   //TIZEN_ONLY(20190219): fix page snap behavior.
+   elm_interface_scrollable_scroll_start_cb_set(obj, _scroll_start_cb);
+   elm_interface_scrollable_scroll_stop_cb_set(obj, _scroll_stop_cb);
+   //
    elm_interface_scrollable_animate_start_cb_set(obj, _scroll_anim_start_cb);
    elm_interface_scrollable_animate_stop_cb_set(obj, _scroll_anim_stop_cb);
    elm_interface_scrollable_drag_start_cb_set(obj, _scroll_drag_start_cb);