summaryrefslogtreecommitdiff
path: root/src/lib/evas/gesture/efl_canvas_gesture_manager.c
blob: 38071d40e8d80b9eeab41d14b34f7c359de24451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
#define EFL_CANVAS_GESTURE_PROTECTED
#define EFL_CANVAS_GESTURE_CUSTOM_PROTECTED
#include "efl_canvas_gesture_private.h"

#define MY_CLASS EFL_CANVAS_GESTURE_MANAGER_CLASS

typedef struct _Object_Gesture
{
   Eo                            *object;
   const Efl_Event_Description   *type;
   Efl_Canvas_Gesture            *gesture;
   Efl_Canvas_Gesture_Recognizer *recognizer;
} Object_Gesture;

typedef struct _Efl_Canvas_Gesture_Manager_Data
{
   //Keeps track of all the gesture request for a particular target
   Eina_Hash *m_gesture_contex;     // (*target, Eina_Hash(type, int))
   //Keeps all the event directed to this particular object from touch_begin till touch_end
   Eina_Hash *m_object_events;     // (*recognizer, *efl_gesture_touch)
   //Keeps all the recognizer registered to gesture manager
   Eina_Hash *m_recognizers;    // (*gesture_type, *recognizer)
   Eina_List *custom_recognizers;
   //Keeps track of all current object gestures.
   Eina_List *m_object_gestures;    //(List of *object_gesture)
   //Lazy deletion of gestures
   Eina_Array *m_gestures_to_delete;
   //Kepps config values for gesture recognize
   Eina_Bool processing : 1;
} Efl_Canvas_Gesture_Manager_Data;

static void _cleanup_cached_gestures(Efl_Canvas_Gesture_Manager_Data *pd,
                                      const Eo *target, const Efl_Event_Description *type, const Efl_Canvas_Gesture_Recognizer *recognizer);
static Efl_Canvas_Gesture *
            _get_state(Efl_Canvas_Gesture_Manager_Data *pd, Eo *target,
           Efl_Canvas_Gesture_Recognizer *recognizer, const Efl_Event_Description *type);

static const Efl_Event_Description *
_gesture_recognizer_event_type_get(const Efl_Canvas_Gesture_Recognizer *recognizer)
{
   const Efl_Class *type = efl_gesture_recognizer_type_get(recognizer);

   if (type == EFL_CANVAS_GESTURE_TAP_CLASS)
     return EFL_EVENT_GESTURE_TAP;
   if (type == EFL_CANVAS_GESTURE_DOUBLE_TAP_CLASS)
     return EFL_EVENT_GESTURE_DOUBLE_TAP;
   if (type == EFL_CANVAS_GESTURE_TRIPLE_TAP_CLASS)
     return EFL_EVENT_GESTURE_TRIPLE_TAP;
   if (type == EFL_CANVAS_GESTURE_LONG_PRESS_CLASS)
     return EFL_EVENT_GESTURE_LONG_PRESS;
   if (type == EFL_CANVAS_GESTURE_MOMENTUM_CLASS)
     return EFL_EVENT_GESTURE_MOMENTUM;
   if (type == EFL_CANVAS_GESTURE_FLICK_CLASS)
     return EFL_EVENT_GESTURE_FLICK;
   if (type == EFL_CANVAS_GESTURE_ROTATE_CLASS)
     return EFL_EVENT_GESTURE_ROTATE;
   if (type == EFL_CANVAS_GESTURE_ZOOM_CLASS)
     return EFL_EVENT_GESTURE_ZOOM;
   return EFL_EVENT_GESTURE_CUSTOM;
}

static void
_cleanup_object(Eina_Array *arr)
{
   Eo *obj;

   if (!eina_array_count(arr)) return;

   while ((obj = eina_array_pop(arr)))
     efl_del(obj);
}

static void
_hash_unref_cb(Eo *obj)
{
   efl_unref(obj);
}

/* updates the data for in-tree recognizers without needing to watch events */
static void
_update_finger_sizes(Efl_Canvas_Gesture_Manager_Data *pd, int finger_size)
{
   Efl_Canvas_Gesture_Recognizer *r;
   Efl_Canvas_Gesture_Recognizer_Tap_Data *td;
   Efl_Canvas_Gesture_Recognizer_Double_Tap_Data *dtd;
   Efl_Canvas_Gesture_Recognizer_Triple_Tap_Data *ttd;
   Efl_Canvas_Gesture_Recognizer_Long_Press_Data *ltd;
   Efl_Canvas_Gesture_Recognizer_Flick_Data *fd;
   Efl_Canvas_Gesture_Recognizer_Rotate_Data *rd;
   Efl_Canvas_Gesture_Recognizer_Zoom_Data *zd;
   const Efl_Event_Description *type;

   type = EFL_EVENT_GESTURE_TAP;
   r = eina_hash_find(pd->m_recognizers, &type);
   td = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_TAP_CLASS);
   td->finger_size = finger_size;

   type = EFL_EVENT_GESTURE_DOUBLE_TAP;
   r = eina_hash_find(pd->m_recognizers, &type);
   dtd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_DOUBLE_TAP_CLASS);
   dtd->finger_size = finger_size;

   type = EFL_EVENT_GESTURE_TRIPLE_TAP;
   r = eina_hash_find(pd->m_recognizers, &type);
   ttd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_TRIPLE_TAP_CLASS);
   ttd->finger_size = finger_size;

   type = EFL_EVENT_GESTURE_LONG_PRESS;
   r = eina_hash_find(pd->m_recognizers, &type);
   ltd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_LONG_PRESS_CLASS);
   ltd->finger_size = finger_size;

   type = EFL_EVENT_GESTURE_FLICK;
   r = eina_hash_find(pd->m_recognizers, &type);
   fd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_FLICK_CLASS);
   fd->finger_size = finger_size;

   type = EFL_EVENT_GESTURE_ROTATE;
   r = eina_hash_find(pd->m_recognizers, &type);
   rd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_ROTATE_CLASS);
   rd->finger_size = finger_size;

   type = EFL_EVENT_GESTURE_ZOOM;
   r = eina_hash_find(pd->m_recognizers, &type);
   zd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_ZOOM_CLASS);
   zd->finger_size = finger_size;
}

static void
_gesture_manager_config_changed(void *data, const Efl_Event *ev)
{
   Efl_Canvas_Gesture_Manager_Data *pd = data;

   if ((!ev->info) || eina_streq(ev->info, "glayer_tap_finger_size"))
     _update_finger_sizes(pd, efl_config_int_get(ev->object, "glayer_tap_finger_size"));
}

EOLIAN static Efl_Object *
_efl_canvas_gesture_manager_efl_object_constructor(Eo *obj, Efl_Canvas_Gesture_Manager_Data *pd)
{
   Eo *config;
   int finger_size = 0;
   obj = efl_constructor(efl_super(obj, MY_CLASS));

   pd->m_recognizers = eina_hash_pointer_new(EINA_FREE_CB(_hash_unref_cb));
   pd->m_gesture_contex = eina_hash_pointer_new(EINA_FREE_CB(eina_hash_free));
   pd->m_object_events = eina_hash_pointer_new(EINA_FREE_CB(_hash_unref_cb));
   pd->m_object_gestures = NULL;
   pd->m_gestures_to_delete = eina_array_new(1);;

   /* this needs to always be present */
   config = efl_provider_find(efl_main_loop_get(), EFL_CONFIG_INTERFACE);
   efl_event_callback_add(config, EFL_CONFIG_EVENT_CONFIG_CHANGED, _gesture_manager_config_changed, pd);

   //Register all types of recognizers at very first time.
   efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_TAP_CLASS, obj));
   efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_LONG_PRESS_CLASS, obj));
   efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_DOUBLE_TAP_CLASS, obj));
   efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_TRIPLE_TAP_CLASS, obj));
   efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_MOMENTUM_CLASS, obj));
   efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_FLICK_CLASS, obj));
   efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_ROTATE_CLASS, obj));
   efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_ZOOM_CLASS, obj));
   /* realistically this will never fail, but the whole gesture layer breaks if this is 0 */
   if (!getenv("EFL_RUN_IN_TREE"))
     finger_size = efl_config_int_get(config, "glayer_tap_finger_size");
   if (finger_size < 1) finger_size = 10;
   _update_finger_sizes(pd, finger_size);

   return obj;
}

EOLIAN static void
_efl_canvas_gesture_manager_efl_object_destructor(Eo *obj, Efl_Canvas_Gesture_Manager_Data *pd)
{
   Efl_Canvas_Gesture_Recognizer *recognizer;
   void *ptr;
   Eo *config = efl_provider_find(efl_main_loop_get(), EFL_CONFIG_INTERFACE);
   if (config)
     efl_event_callback_del(config, EFL_CONFIG_EVENT_CONFIG_CHANGED, _gesture_manager_config_changed, pd);

   eina_hash_free(pd->m_recognizers);
   EINA_LIST_FREE(pd->custom_recognizers, recognizer)
     efl_unref(recognizer);
   eina_hash_free(pd->m_gesture_contex);
   eina_hash_free(pd->m_object_events);
   _cleanup_object(pd->m_gestures_to_delete);
   eina_array_free(pd->m_gestures_to_delete);
   EINA_LIST_FREE(pd->m_object_gestures, ptr)
     free(ptr);
   efl_destructor(efl_super(obj, MY_CLASS));
}

void
_efl_canvas_gesture_manager_callback_add_hook(void *data, Eo *target, const Efl_Event_Description *type)
{
   Efl_Canvas_Gesture_Manager_Data *pd = data;
   //If there is a recognizer registered for that event then add it to the gesture context
   Efl_Canvas_Gesture_Recognizer *recognizer;

   if (type == EFL_EVENT_GESTURE_CUSTOM)
     recognizer = eina_list_data_get(pd->custom_recognizers);
   else
     recognizer = eina_hash_find(pd->m_recognizers, &type);
   if (recognizer)
     {
        //Add it to the gesture context.
        Eina_Hash *thisisreallystupid = eina_hash_find(pd->m_gesture_contex, &target);
        intptr_t count = 0;
        /* already present */
        if (thisisreallystupid)
          count = (intptr_t)eina_hash_find(thisisreallystupid, &type);
        else
          {
             thisisreallystupid = eina_hash_pointer_new(NULL);
             eina_hash_set(pd->m_gesture_contex, &target, thisisreallystupid);
          }
        count++;
        eina_hash_set(thisisreallystupid, &type, (intptr_t*)count);
     }
}

void
_efl_canvas_gesture_manager_callback_del_hook(void *data, Eo *target, const Efl_Event_Description *type)
{
   Efl_Canvas_Gesture_Manager_Data *pd = data;
   //If there is a recognizer registered for that event then add it to the gesture context
   Efl_Canvas_Gesture_Recognizer *recognizer;

   if (type == EFL_EVENT_GESTURE_CUSTOM)
     recognizer = eina_list_data_get(pd->custom_recognizers);
   else
     recognizer = eina_hash_find(pd->m_recognizers, &type);
   if (recognizer)
     {
        Eina_Hash *thisisreallystupid = eina_hash_find(pd->m_gesture_contex, &target);
        intptr_t count;

        if (!thisisreallystupid) return;
        count = (intptr_t)eina_hash_find(thisisreallystupid, &type);
        if (!count) return;
        count--;
        eina_hash_set(thisisreallystupid, &type, (intptr_t*)count);
        if (count) return;
        eina_hash_del_by_key(thisisreallystupid, &type);
        if (eina_hash_population(thisisreallystupid)) return;
        eina_hash_del_by_key(pd->m_gesture_contex, &target);
        _cleanup_cached_gestures(pd, target, type, NULL);
     }
}

static void
_recognizer_cleanup_internal(Efl_Canvas_Gesture_Manager_Data *pd, const Efl_Canvas_Gesture_Recognizer *recognizer, const Eo *target, const Efl_Event_Description *type)
{
   _cleanup_cached_gestures(pd, target, type, recognizer);
   eina_hash_del(pd->m_object_events, &recognizer, NULL);
   //FIXME: delete it by object not list.
   _cleanup_object(pd->m_gestures_to_delete);
}

static void
_gesture_recognizer_process_internal(Efl_Canvas_Gesture_Manager_Data *pd, Efl_Canvas_Gesture_Recognizer *recognizer,
                                     Eo *target, const Efl_Event_Description *gesture_type, void *event)
{
   Efl_Canvas_Gesture_Recognizer_Result recog_result;
   Efl_Canvas_Gesture_Recognizer_Result recog_state = EFL_GESTURE_RECOGNIZER_RESULT_FINISH;
   Efl_Canvas_Gesture_Touch *touch_event;
   Efl_Canvas_Gesture_Recognizer_Data *rd = efl_data_scope_get(recognizer, EFL_CANVAS_GESTURE_RECOGNIZER_CLASS);
   //If the gesture canceled or already finished by recognizer.
   Efl_Canvas_Gesture *gesture = _get_state(pd, target, recognizer, gesture_type);
   if (!gesture) return;

   //Check there is already created event exist or not.
   touch_event = eina_hash_find(pd->m_object_events, &recognizer);

   if (!touch_event)
     {
        touch_event = efl_add_ref(EFL_CANVAS_GESTURE_TOUCH_CLASS, NULL);
        eina_hash_add(pd->m_object_events, &recognizer, touch_event);
     }

   efl_gesture_touch_point_record(touch_event, event);

   //This is for handling the case that mouse event pairs dont match.
   //Such as the case of canceling gesture recognition after a mouse down.
   if (efl_gesture_touch_state_get(touch_event) == EFL_GESTURE_TOUCH_STATE_UNKNOWN)
     return;
   if ((!rd->continues) && ((efl_gesture_state_get(gesture) == EFL_GESTURE_STATE_CANCELED) ||
       (efl_gesture_state_get(gesture) == EFL_GESTURE_STATE_FINISHED)))
     goto post_event;

   /* this is the "default" value for the event, recognizers may modify it if necessary */
   efl_gesture_touch_count_set(gesture, efl_gesture_touch_points_count_get(touch_event));

   //Gesture detecting.
   recog_result = efl_gesture_recognizer_recognize(recognizer, gesture, target, touch_event);
   recog_state = recog_result & EFL_GESTURE_RECOGNIZER_RESULT_RESULT_MASK;

   if (recog_state == EFL_GESTURE_RECOGNIZER_RESULT_TRIGGER)
     {
        if (efl_gesture_state_get(gesture) == EFL_GESTURE_STATE_NONE)
          efl_gesture_state_set(gesture, EFL_GESTURE_STATE_STARTED);
        else
          efl_gesture_state_set(gesture, EFL_GESTURE_STATE_UPDATED);
     }
   else if (recog_state == EFL_GESTURE_RECOGNIZER_RESULT_FINISH)
     {
        efl_gesture_state_set(gesture, EFL_GESTURE_STATE_FINISHED);
     }
   else if (recog_state == EFL_GESTURE_RECOGNIZER_RESULT_MAYBE)
     {
        return;
     }
   else if (recog_state == EFL_GESTURE_RECOGNIZER_RESULT_CANCEL)
     {
        if (efl_gesture_state_get(gesture) != EFL_GESTURE_STATE_NONE)
          efl_gesture_state_set(gesture, EFL_GESTURE_STATE_CANCELED);
        else
          {
             if (rd->continues)
               return;
             goto post_event;
          }
     }
   else if (recog_state == EFL_GESTURE_RECOGNIZER_RESULT_IGNORE)
     {
        return;
     }

   efl_gesture_timestamp_set(gesture, efl_gesture_touch_current_timestamp_get(touch_event));
   efl_event_callback_call(target, gesture_type, gesture);
post_event:
   /* avoid destroying touch tracking before gesture has ended */
   if ((!rd->continues) &&
        ((efl_gesture_touch_state_get(touch_event) != EFL_GESTURE_TOUCH_STATE_END) || efl_gesture_touch_points_count_get(touch_event)))
     return;
   //If the current event recognizes the gesture continuously, dont delete gesture.
   if (((recog_state == EFL_GESTURE_RECOGNIZER_RESULT_FINISH) || (recog_state == EFL_GESTURE_RECOGNIZER_RESULT_CANCEL)) &&
       !rd->continues)
     _recognizer_cleanup_internal(pd, recognizer, target, gesture_type);
}

void
_efl_canvas_gesture_manager_filter_event(void *data, Eo *target, void *event)
{
   Efl_Canvas_Gesture_Manager_Data *pd = data;
   Eina_Hash *thisisreallystupid;
   Eina_Iterator *it;
   Eina_Hash_Tuple *tup;
   Efl_Canvas_Gesture_Recognizer *recognizer;

   thisisreallystupid = eina_hash_find(pd->m_gesture_contex, &target);
   if (!thisisreallystupid) return;
   pd->processing = EINA_TRUE;
   it = eina_hash_iterator_tuple_new(thisisreallystupid);
   EINA_ITERATOR_FOREACH(it, tup)
     {
        const Efl_Event_Description *gesture_type = *(void**)tup->key;

        if (gesture_type == EFL_EVENT_GESTURE_CUSTOM)
          {
             Eina_List *l;
             EINA_LIST_FOREACH(pd->custom_recognizers, l, recognizer)
               _gesture_recognizer_process_internal(pd, recognizer, target, gesture_type, event);
          }
        else
          {
             recognizer = eina_hash_find(pd->m_recognizers, &gesture_type);
             _gesture_recognizer_process_internal(pd, recognizer, target, gesture_type, event);
          }
     }
   eina_iterator_free(it);
   pd->processing = EINA_FALSE;
}

EOLIAN static void
_efl_canvas_gesture_manager_recognizer_register(Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Manager_Data *pd,
                                                Efl_Canvas_Gesture_Recognizer *recognizer)
{
   const Efl_Event_Description *type = _gesture_recognizer_event_type_get(recognizer);
   //Add the recognizer to the m_recognizers
   if (type == EFL_EVENT_GESTURE_CUSTOM)
     {
        EINA_SAFETY_ON_TRUE_RETURN(pd->custom_recognizers && eina_list_data_find(pd->custom_recognizers, recognizer));
        pd->custom_recognizers = eina_list_append(pd->custom_recognizers, efl_ref(recognizer));
     }
   else
     {
        EINA_SAFETY_ON_TRUE_RETURN(!!eina_hash_find(pd->m_recognizers, &type));
        eina_hash_add(pd->m_recognizers, &type, efl_ref(recognizer));
     }

}

EOLIAN static void
_efl_canvas_gesture_manager_recognizer_unregister(Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Manager_Data *pd,
                                                  Efl_Canvas_Gesture_Recognizer *recognizer)
{
   Eina_List *l, *l_next;
   Object_Gesture *object_gesture;
   const Efl_Event_Description *type;

   if (!recognizer) return;

   //Find the type of the recognizer
   type = _gesture_recognizer_event_type_get(recognizer);
   //Check if its already registered
   if (type == EFL_EVENT_GESTURE_CUSTOM)
     {
        EINA_SAFETY_ON_TRUE_RETURN((!pd->custom_recognizers) || (!eina_list_data_find(pd->custom_recognizers, recognizer)));
        pd->custom_recognizers = eina_list_remove(pd->custom_recognizers, recognizer);
        eina_hash_del_by_key(pd->m_object_events, &recognizer);
        efl_unref(recognizer);
     }
   else
     {
        EINA_SAFETY_ON_TRUE_RETURN(!eina_hash_find(pd->m_recognizers, &type));
        eina_hash_del_by_key(pd->m_object_events, &recognizer);
        eina_hash_del_by_key(pd->m_recognizers, &type);
     }

   //Remove that gesture from the list of object gestures
   EINA_LIST_FOREACH_SAFE(pd->m_object_gestures, l, l_next, object_gesture)
     {
        if ((object_gesture->type == type) && (object_gesture->recognizer == recognizer))
          {
             eina_array_push(pd->m_gestures_to_delete, object_gesture->gesture);
             free(object_gesture);
             pd->m_object_gestures = eina_list_remove_list(pd->m_object_gestures, l);
          }
     }
   if (pd->processing) return;
   _cleanup_object(pd->m_gestures_to_delete);
}

// EOLIAN static void
// _efl_canvas_gesture_manager_ungrab_all(Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Manager_Data *pd,
//                                    Eo *target)
// {
//    const Efl_Event_Description *type;
//    Eina_List *l;

//    Eina_List *gesture_type_list = eina_hash_find(pd->m_gesture_contex, &target);

//    if (!gesture_type_list) return;

//    EINA_LIST_FOREACH(gesture_type_list, l, type)
//      {
//         _cleanup_cached_gestures(obj, pd, target, type);
//      }
//    eina_hash_del(pd->m_gesture_contex, &target, NULL);
// }

//Get or create a gesture object that will represent the state for a given object, used by the recognizer
Efl_Canvas_Gesture *
_get_state(Efl_Canvas_Gesture_Manager_Data *pd,
           Eo *target, Efl_Canvas_Gesture_Recognizer *recognizer, const Efl_Event_Description *type)
{
   Eina_List *l;
   Object_Gesture *object_gesture;
   Efl_Canvas_Gesture *gesture;

   //If the widget is being deleted we should be careful not to
   //Create a new state.
   if (efl_destructed_is(target))
     return 0;

   //TODO find a optimized way of looking for gesture
   EINA_LIST_FOREACH(pd->m_object_gestures, l, object_gesture)
     {
        if (object_gesture->object == target &&
            object_gesture->recognizer == recognizer &&
            object_gesture->type == type)
          {
             return object_gesture->gesture;
          }
     }

   gesture = efl_add(efl_gesture_recognizer_type_get(recognizer), recognizer);
   if (!gesture)
     return 0;

   object_gesture = calloc(1, sizeof(Object_Gesture));
   object_gesture->object = target;
   object_gesture->recognizer = recognizer;
   object_gesture->type = type;
   object_gesture->gesture = gesture;
   if (type == EFL_EVENT_GESTURE_CUSTOM)
     efl_gesture_custom_gesture_name_set(gesture, efl_gesture_recognizer_custom_gesture_name_get(recognizer));

   pd->m_object_gestures = eina_list_append(pd->m_object_gestures, object_gesture);

   return gesture;
}

static void
_cleanup_cached_gestures(Efl_Canvas_Gesture_Manager_Data *pd,
                         const Eo *target, const Efl_Event_Description *type, const Efl_Canvas_Gesture_Recognizer *recognizer)
{
   Eina_List *l, *l_next;
   Object_Gesture *object_gesture;

   EINA_LIST_FOREACH_SAFE(pd->m_object_gestures, l, l_next, object_gesture)
     {
        if ((object_gesture->type == type) && (target == object_gesture->object) &&
            ((!recognizer) || (object_gesture->recognizer == recognizer)))
          {
             eina_array_push(pd->m_gestures_to_delete, object_gesture->gesture);
             free(object_gesture);
             pd->m_object_gestures = eina_list_remove_list(pd->m_object_gestures, l);
          }
     }
}

EOLIAN static void
_efl_canvas_gesture_manager_recognizer_cleanup(Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Manager_Data *pd, const Efl_Canvas_Gesture_Recognizer *recognizer, const Eo *target)
{
   const Efl_Event_Description *type;

   EINA_SAFETY_ON_NULL_RETURN(recognizer);

   //Find the type of the recognizer
   type = _gesture_recognizer_event_type_get(recognizer);
   _recognizer_cleanup_internal(pd, recognizer, target, type);
}

#include "efl_canvas_gesture_manager.eo.c"