DnD: Make the accepted callback of elm_drag_start working correctly 49/250249/2
authorTaehyub Kim <taehyub.kim@samsung.com>
Tue, 22 Dec 2020 09:09:22 +0000 (18:09 +0900)
committerTaehyub Kim <taehyub.kim@samsung.com>
Tue, 22 Dec 2020 09:27:07 +0000 (18:27 +0900)
problem: The accepted callback of elm_drag_start always returns 0
solved: The accepted callback will be return 1 when drag and drop is finished successfully.
        (When the drag data is sent)

Change-Id: Id877b3f39b1634128fa453d99cde20bd6e44806a

src/lib/ecore_evas/Ecore_Evas.h
src/lib/ecore_evas/ecore_evas.c
src/lib/ecore_evas/ecore_evas_private.h
src/lib/elementary/efl_ui_dnd.c
src/lib/elementary/efl_ui_dnd.eo
src/lib/elementary/elm_dnd.c

index 886b29d..8afc2bd 100755 (executable)
@@ -4081,6 +4081,15 @@ EAPI Eina_Future* ecore_evas_selection_get(Ecore_Evas *ee, unsigned int seat, Ec
 typedef void (*Ecore_Evas_Drag_Finished_Cb)(Ecore_Evas *ee, unsigned int seat, void *data, Eina_Bool accepted);
 
 /**
+ * @brief This method is called when the drag object is accepted while performing a drag operation.
+ *
+ * @param[in] ee The Ecore Evas the drag operation started on.
+ * @param[in] data The Drag and Drop data.
+ * @param[in] accepted @c EINA_TRUE if drag and drop is accepted. @c EINA_FALSE if drag and drop is not accepted.
+ */
+typedef void (*Ecore_Evas_Drag_Accepted_Cb)(Ecore_Evas *ee, unsigned int seat, void *data, Eina_Bool accepted);
+
+/**
  * @brief Starts a new drag operation.
  *
  * @param[in] ee The Ecore Evas the drag operation started on.
@@ -4101,7 +4110,7 @@ typedef void (*Ecore_Evas_Drag_Finished_Cb)(Ecore_Evas *ee, unsigned int seat, v
  * @since 1.24
  */
 EAPI Eina_Bool ecore_evas_drag_start(Ecore_Evas *ee, unsigned int seat, Eina_Content *content, Ecore_Evas *drag_rep,
-                                     const char* action, Ecore_Evas_Drag_Finished_Cb terminate_cb, void *data);
+                                     const char* action, Ecore_Evas_Drag_Finished_Cb terminate_cb, Ecore_Evas_Drag_Accepted_Cb accepted_cb,  void *data);
 
 /**
  * @brief Cancels an ongoing drag operation.
index 3128bbe..3f04850 100644 (file)
@@ -6298,6 +6298,11 @@ _deliver_cb(Ecore_Evas *ee, unsigned int seat, Ecore_Evas_Selection_Buffer buffe
    if (buffer == ECORE_EVAS_SELECTION_BUFFER_DRAG_AND_DROP_BUFFER)
      {
         ee->drag.accepted = EINA_TRUE;
+
+        //TIZEN_ONLY(20201222): fix accepted callback working
+        if (ee->drag.acceptedcb)
+          ee->drag.acceptedcb(ee, seat, ee->drag.data, ee->drag.accepted);
+        //
      }
 
 free_everything:
@@ -6431,7 +6436,10 @@ ecore_evas_selection_get(Ecore_Evas *ee, unsigned int seat, Ecore_Evas_Selection
 }
 
 EAPI Eina_Bool
-ecore_evas_drag_start(Ecore_Evas *ee, unsigned int seat, Eina_Content *content, Ecore_Evas *drag_rep, const char* action, Ecore_Evas_Drag_Finished_Cb terminate_cb, void *data)
+//TIZEN_ONLY(20201222): fix accepted callback working
+//ecore_evas_drag_start(Ecore_Evas *ee, unsigned int seat, Eina_Content *content, Ecore_Evas *drag_rep, const char* action, Ecore_Evas_Drag_Finished_Cb terminate_cb, void *data)
+//
+ecore_evas_drag_start(Ecore_Evas *ee, unsigned int seat, Eina_Content *content, Ecore_Evas *drag_rep, const char* action, Ecore_Evas_Drag_Finished_Cb terminate_cb, Ecore_Evas_Drag_Accepted_Cb accepted_cb,  void *data)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(content, EINA_FALSE);
@@ -6450,6 +6458,9 @@ ecore_evas_drag_start(Ecore_Evas *ee, unsigned int seat, Eina_Content *content,
    ee->drag.rep = drag_rep;
    ee->drag.free = terminate_cb;
    ee->drag.data = data;
+   //TIZEN_ONLY(20201222): fix accepted callback working
+   ee->drag.acceptedcb = accepted_cb;
+   //
    ee->drag.accepted = EINA_FALSE;
 
    return success;
index 9e447a8..fb4f1b1 100644 (file)
@@ -421,6 +421,9 @@ struct _Ecore_Evas
         Ecore_Evas *rep;
         void *data;
         Ecore_Evas_Drag_Finished_Cb free;
+        //TIZEN_ONLY(20201222): fix accepted callback working
+        Ecore_Evas_Drag_Accepted_Cb acceptedcb;
+        //
         Eina_Bool accepted;
      } drag;
 
index da075bf..1d0dd50 100644 (file)
@@ -22,6 +22,10 @@ typedef struct {
    Efl_Ui_Dnd *obj;
 } Efl_Ui_Drag_Start;
 
+//TIZEN_ONLY(20201222): fix accepted callback working
+static Eo *recent_drag_object = NULL;
+//
+
 static void
 _ecore_evas_drag_terminated(Ecore_Evas *ee EINA_UNUSED, unsigned int seat, void *data, Eina_Bool accepted)
 {
@@ -29,9 +33,20 @@ _ecore_evas_drag_terminated(Ecore_Evas *ee EINA_UNUSED, unsigned int seat, void
    Efl_Ui_Drag_Finished_Event ev = {seat, accepted};
    efl_event_callback_call(start->obj, EFL_UI_DND_EVENT_DRAG_FINISHED, &ev);
    efl_del(start->win);
+   recent_drag_object = start->obj;
    free(start);
 }
 
+//TIZEN_ONLY(20201222): fix accepted callback working
+static void
+_ecore_evas_drag_accepted(Ecore_Evas *ee EINA_UNUSED, unsigned int seat, void *data, Eina_Bool accepted)
+{
+   Efl_Ui_Drag_Accepted_Event ev = {seat, accepted};
+   efl_event_callback_call(recent_drag_object, EFL_UI_DND_EVENT_DRAG_ACCEPTED, &ev);
+   recent_drag_object = NULL;
+}
+//
+
 EOLIAN static Efl_Content*
 _efl_ui_dnd_drag_start(Eo *obj, Efl_Ui_Dnd_Data *pd, Eina_Content *content, const char* action, unsigned int seat)
 {
@@ -53,7 +68,10 @@ _efl_ui_dnd_drag_start(Eo *obj, Efl_Ui_Dnd_Data *pd, Eina_Content *content, cons
    elm_win_borderless_set(drag_win, EINA_TRUE);
    drag_ee = ecore_evas_ecore_evas_get(evas_object_evas_get(drag_win));
 
-   if (!ecore_evas_drag_start(pd->ee, seat, content, drag_ee, action, _ecore_evas_drag_terminated, start))
+     //TIZEN_ONLY(20201222): fix accepted callback working
+     //if (!ecore_evas_drag_start(pd->ee, seat, content, drag_ee, action, _ecore_evas_drag_terminated, start))
+     if (!ecore_evas_drag_start(pd->ee, seat, content, drag_ee, action, _ecore_evas_drag_terminated, _ecore_evas_drag_accepted, start))
+     //
      {
         efl_del(drag_win);
         free(start);
index 49ef148..f84d20d 100644 (file)
@@ -29,6 +29,12 @@ struct @beta Efl.Ui.Drag_Finished_Event {
    accepted : bool; [[$true if the operation completed with a Drop, or $false if it was cancelled.]]
 }
 
+struct @beta Efl.Ui.Drag_Accepted_Event {
+   [[Information sent along with @Efl.Ui.Drag_Accepted_Event events.]]
+   seat : uint; [[Which seat triggered the event.]]
+   accepted : bool; [[$true if the operation completed with a Drop, or $false if it was cancelled.]]
+}
+
 mixin @beta Efl.Ui.Dnd requires Efl.Object {
    [[This mixin provides the ability to interact with the system's Drag & Drop facilities.
 
@@ -84,6 +90,7 @@ mixin @beta Efl.Ui.Dnd requires Efl.Object {
       drop,dropped : Efl.Ui.Drop_Dropped_Event;  [[Dragged content was dropped over the window.]]
       drag,started : Efl.Ui.Drag_Started_Event;  [[A Drag operation started.]]
       drag,finished : Efl.Ui.Drag_Finished_Event;[[A Drag operation finished.]]
+      drag,accepted : Efl.Ui.Drag_Accepted_Event;[[A Drag operation accepted.]]
    }
    implements {
       Efl.Object.constructor;
index 2f2ad00..fa8031f 100644 (file)
@@ -740,7 +740,9 @@ elm_drop_item_container_del(Evas_Object *obj)
 typedef struct {
   void *dragdata, *acceptdata, *donecbdata;
   Elm_Drag_Pos dragposcb;
-  Elm_Drag_Accept acceptcb;
+  //TIZEN_ONLY(20201222): fix accepted callback working
+  //Elm_Drag_Accept acceptcb;
+  //
   Elm_Drag_State dragdonecb;
 } Elm_Drag_Data;
 
@@ -750,8 +752,10 @@ _drag_finished_cb(void *data, const Efl_Event *ev)
    Elm_Drag_Data *dd = data;
    Eina_Bool *accepted = ev->info;
 
-   if (dd->acceptcb)
-     dd->acceptcb(dd->acceptdata, ev->object, *accepted);
+   //TIZEN_ONLY(20201222): fix accepted callback working
+   //if (dd->acceptcb)
+   //  dd->acceptcb(dd->acceptdata, ev->object, *accepted);
+   //
 
    if (dd->dragdonecb)
      dd->dragdonecb(dd->donecbdata, ev->object);
@@ -760,6 +764,20 @@ _drag_finished_cb(void *data, const Efl_Event *ev)
    free(dd);
 }
 
+//TIZEN_ONLY(20201222): fix accepted callback working
+static void
+_drag_accepted_cb(void *data, const Efl_Event *ev)
+{
+   Elm_Drag_Accept acceptcb = data;
+   Efl_Ui_Drag_Accepted_Event *accepted_event = ev->info;
+
+   if (acceptcb)
+     acceptcb(NULL, ev->object, accepted_event->accepted);
+
+   efl_event_callback_del(ev->object, EFL_UI_DND_EVENT_DRAG_ACCEPTED, _drag_accepted_cb, acceptcb);
+}
+//
+
 EAPI Eina_Bool
 elm_drag_start(Evas_Object *obj, Elm_Sel_Format format,
                const char *data, Elm_Xdnd_Action action,
@@ -787,7 +805,9 @@ elm_drag_start(Evas_Object *obj, Elm_Sel_Format format,
    dd = calloc(1, sizeof(Elm_Drag_Data));
    dd->dragposcb = dragpos;
    dd->dragdata = dragdata;
-   dd->acceptcb = acceptcb;
+   //TIZEN_ONLY(20201222): fix accepted callback working
+   //dd->acceptcb = acceptcb;
+   //
    dd->acceptdata = acceptdata;
    dd->dragdonecb = dragdone;
    dd->donecbdata = donecbdata;
@@ -806,6 +826,9 @@ elm_drag_start(Evas_Object *obj, Elm_Sel_Format format,
    eina_array_free(mime_types);
 
    efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_FINISHED, _drag_finished_cb, dd);
+   //TIZEN_ONLY(20201222): fix accepted callback working
+   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_ACCEPTED, _drag_accepted_cb, acceptcb);
+   //
 
    return EINA_TRUE;
 }