From: Shinwoo Kim Date: Tue, 26 Jun 2012 22:48:55 +0000 (+0900) Subject: [gesture_layer] opensource merge (r71200) X-Git-Tag: 1.0.0+svn.70492slp2+build19~40^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c28f3e6960438ede0b1d7e1a3b22c3c8bcbe796;p=framework%2Fuifw%2Felementary.git [gesture_layer] opensource merge (r71200) Change-Id: I4fcc0b006e7c50e39f527aa6079b2fd6c295a0e2 --- diff --git a/src/lib/elm_gesture_layer.c b/src/lib/elm_gesture_layer.c index af36efe..68b7758 100644 --- a/src/lib/elm_gesture_layer.c +++ b/src/lib/elm_gesture_layer.c @@ -11,6 +11,8 @@ #define ELM_GESTURE_MULTI_TIMEOUT 50 #define ELM_GESTURE_MINIMUM_MOMENTUM 0.001 +#define ELM_GESTURE_TAP_TIMEOUT 0.2 + /* Some Trigo values */ #define RAD_90DEG M_PI_2 #define RAD_180DEG M_PI @@ -411,7 +413,9 @@ consume_event(Widget_Data *wd, void *event_info, if (!event_info) return; /* This happens when restarting gestures */ - if ((ev_flags) || (!wd->repeat_events)) + if (!wd->repeat_events) ev_flags |= EVAS_EVENT_FLAG_ON_HOLD; + + if (ev_flags) { switch(event_type) { @@ -1183,6 +1187,7 @@ _tap_gesture_check_finish(Gesture_Info *gesture) Taps_Type *st = gesture->data; Eina_List *l; Eina_List *pe_list; + if (!st || !st->l) return EINA_FALSE; EINA_LIST_FOREACH(st->l, l, pe_list) { if (eina_list_count(pe_list) != st->n_taps_needed) @@ -1206,12 +1211,14 @@ _tap_gesture_check_finish(Gesture_Info *gesture) static void _tap_gesture_finish(void *data) { /* This function will test each tap gesture when timer expires */ - Elm_Gesture_State s = ELM_GESTURE_STATE_END; + Elm_Gesture_State s = ELM_GESTURE_STATE_ABORT; Gesture_Info *gesture = data; Taps_Type *st = gesture->data; - if (!_tap_gesture_check_finish(data)) - s = ELM_GESTURE_STATE_ABORT; + if (_tap_gesture_check_finish(gesture)) + { + s = ELM_GESTURE_STATE_END; + } st->info.n = eina_list_count(st->l); _set_state(gesture, s, gesture->info, EINA_FALSE); @@ -1275,7 +1282,7 @@ _long_tap_timeout(void *data) /** * @internal * - * This function checks if a tap gesture should start + * This function checks the state of a tap gesture. * * @param wd Gesture Layer Widget Data. * @param pe The recent input event as stored in pe struct. @@ -1284,15 +1291,16 @@ _long_tap_timeout(void *data) * @param gesture what gesture is tested * @param how many taps for this gesture (1, 2 or 3) * - * @return Flag to determine if we need to set a timer for finish - * * @ingroup Elm_Gesture_Layer */ -static Eina_Bool -_tap_gesture_start(Widget_Data *wd, Pointer_Event *pe, +static void +_tap_gesture_test(Widget_Data *wd, Pointer_Event *pe, void *event_info, Evas_Callback_Type event_type, Gesture_Info *gesture, int taps) { /* Here we fill Tap struct */ + if (!pe) + return; + Taps_Type *st = gesture->data; if (!st) { /* Allocated once on first time */ @@ -1318,10 +1326,20 @@ _tap_gesture_start(Widget_Data *wd, Pointer_Event *pe, &st->info, EINA_FALSE); consume_event(wd, event_info, event_type, ev_flag); - return EINA_FALSE; + return; } pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type); + if (!wd->dbl_timeout) + { + wd->dbl_timeout = ecore_timer_add(ELM_GESTURE_TAP_TIMEOUT, + _multi_tap_timeout, gesture->obj); + } + else + { + ecore_timer_reset(wd->dbl_timeout); + } + if ((pe->device == 0) && (eina_list_count(pe_list) == 1)) { /* This is the first mouse down we got */ ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START, @@ -1330,7 +1348,13 @@ _tap_gesture_start(Widget_Data *wd, Pointer_Event *pe, st->n_taps_needed = taps * 2; /* count DOWN and UP */ - return EINA_TRUE; + return; + } + else if (eina_list_count(pe_list) > st->n_taps_needed) + { + /* If we arleady got too many touches for this gesture. */ + ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, + &st->info, EINA_FALSE); } break; @@ -1339,7 +1363,7 @@ _tap_gesture_start(Widget_Data *wd, Pointer_Event *pe, case EVAS_CALLBACK_MOUSE_UP: pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe); if (!pe_list) - return EINA_FALSE; + return; pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type); @@ -1352,7 +1376,7 @@ _tap_gesture_start(Widget_Data *wd, Pointer_Event *pe, if (_tap_gesture_check_finish(gesture)) { _tap_gesture_finish(gesture); - return EINA_FALSE; + return; } } @@ -1376,52 +1400,7 @@ _tap_gesture_start(Widget_Data *wd, Pointer_Event *pe, break; default: - return EINA_FALSE; - } - - return EINA_FALSE; -} - - -/** - * @internal - * - * This function checks all click/tap and double/triple taps - * - * @param obj The gesture-layer object. - * @param pe The recent input event as stored in pe struct. - * @param event_info Original input event pointer. - * @param event_type Type of original input event. - * - * @ingroup Elm_Gesture_Layer - */ -static void -_tap_gestures_test(Evas_Object *obj, Pointer_Event *pe, - void *event_info, Evas_Callback_Type event_type) -{ /* Here we fill Recent_Taps struct and fire-up click/tap timers */ - Eina_Bool need_timer = EINA_FALSE; - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return; - - if (!pe) /* this happens when unhandled event arrived */ - return; /* see _make_pointer_event function */ - - if (IS_TESTED(ELM_GESTURE_N_TAPS)) - need_timer |= _tap_gesture_start(wd, pe, event_info, event_type, - wd->gesture[ELM_GESTURE_N_TAPS], 1); - - if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS)) - need_timer |= _tap_gesture_start(wd, pe, event_info, event_type, - wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS], 2); - - if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS)) - need_timer |= _tap_gesture_start(wd, pe, event_info, event_type, - wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS], 3); - - if ((need_timer) && (!wd->dbl_timeout)) - { /* Set a timer to finish these gestures */ - wd->dbl_timeout = ecore_timer_add(0.4, _multi_tap_timeout, - obj); + return ; } } @@ -3237,8 +3216,17 @@ _event_process(void *data, Evas_Object *obj __UNUSED__, _n_long_tap_test(data, pe, event_info, event_type, ELM_GESTURE_N_LONG_TAPS); - /* This takes care of single, double and tripple tap */ - _tap_gestures_test(data, pe, event_info, event_type); + if (IS_TESTED(ELM_GESTURE_N_TAPS)) + _tap_gesture_test(wd, pe, event_info, event_type, + wd->gesture[ELM_GESTURE_N_TAPS], 1); + + if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS)) + _tap_gesture_test(wd, pe, event_info, event_type, + wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS], 2); + + if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS)) + _tap_gesture_test(wd, pe, event_info, event_type, + wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS], 3); if (IS_TESTED(ELM_GESTURE_MOMENTUM)) _momentum_test(data, pe, event_info, event_type, @@ -3261,16 +3249,6 @@ _event_process(void *data, Evas_Object *obj __UNUSED__, if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD) _event_history_add(data, event_info, event_type); - else if ((event_type == EVAS_CALLBACK_MOUSE_UP) || - (event_type == EVAS_CALLBACK_MULTI_UP)) - { - Eina_List *pending = _device_is_pending(wd->pending, event_info, event_type); - if (pending) - { - consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_ON_HOLD); - _event_history_add(data, event_info, event_type); - } - } /* we maintain list of touched devices */ /* We also use move to track current device x.y pos */ diff --git a/src/lib/elm_gesture_layer.h b/src/lib/elm_gesture_layer.h index b24babb..0b57238 100644 --- a/src/lib/elm_gesture_layer.h +++ b/src/lib/elm_gesture_layer.h @@ -28,7 +28,7 @@ * (again with @ref elm_gesture_layer_cb_set) * * The information reported by gesture layer to your callback is depending - * on @ref Elm_Gesture_Type: + * on @ref Elm_Gesture_Type : * @ref Elm_Gesture_Taps_Info is the info reported for tap gestures: * @ref ELM_GESTURE_N_TAPS, @ref ELM_GESTURE_N_LONG_TAPS, * @ref ELM_GESTURE_N_DOUBLE_TAPS, @ref ELM_GESTURE_N_TRIPLE_TAPS. @@ -60,13 +60,15 @@ * @li @ref elm_object_disabled_set * @li @ref elm_object_disabled_get * + * @{ + * */ /** + * @enum _Elm_Gesture_Type * Enum of supported gesture types. - * @ingroup Elm_Gesture_Layer */ -typedef enum +enum _Elm_Gesture_Type { ELM_GESTURE_FIRST = 0, @@ -84,26 +86,36 @@ typedef enum ELM_GESTURE_ROTATE, /**< Rotate */ ELM_GESTURE_LAST -} Elm_Gesture_Type; +}; + +/** + * @typedef Elm_Gesture_Type + * Convenient macro around #_Elm_Gesture_Type + */ +typedef enum _Elm_Gesture_Type Elm_Gesture_Type; /** * @enum _Elm_Gesture_State * Enum of gesture states. - * @ingroup Elm_Gesture_Layer */ -typedef enum +enum _Elm_Gesture_State { ELM_GESTURE_STATE_UNDEFINED = -1, /**< Gesture not STARTed */ ELM_GESTURE_STATE_START, /**< Gesture STARTed */ ELM_GESTURE_STATE_MOVE, /**< Gesture is ongoing */ ELM_GESTURE_STATE_END, /**< Gesture completed */ ELM_GESTURE_STATE_ABORT /**< Ongoing gesture was ABORTed */ -} Elm_Gesture_State; +}; + +/** + * @typedef Elm_Gesture_State + * Convenient macro around #_Elm_Gesture_State + */ +typedef enum _Elm_Gesture_State Elm_Gesture_State; /** * @struct _Elm_Gesture_Taps_Info * Struct holds taps info for user - * @ingroup Elm_Gesture_Layer */ struct _Elm_Gesture_Taps_Info { @@ -115,7 +127,6 @@ struct _Elm_Gesture_Taps_Info /** * @typedef Elm_Gesture_Taps_Info * holds taps info for user - * @ingroup Elm_Gesture_Layer */ typedef struct _Elm_Gesture_Taps_Info Elm_Gesture_Taps_Info; @@ -126,7 +137,6 @@ typedef struct _Elm_Gesture_Taps_Info Elm_Gesture_Taps_Info; * x1 holds x value of x direction starting point * and same holds for y1. * This is noticeable when doing V-shape movement - * @ingroup Elm_Gesture_Layer */ struct _Elm_Gesture_Momentum_Info /* Report line ends, timestamps, and momentum computed */ {Evas_Coord x1; /**< Final-swipe direction starting point on X */ @@ -146,14 +156,12 @@ struct _Elm_Gesture_Momentum_Info /* Report line ends, timestamps, and momentum /** * @typedef Elm_Gesture_Momentum_Info * holds momentum info for user - * @ingroup Elm_Gesture_Layer */ typedef struct _Elm_Gesture_Momentum_Info Elm_Gesture_Momentum_Info; /** * @struct _Elm_Gesture_Line_Info * Struct holds line info for user - * @ingroup Elm_Gesture_Layer */ struct _Elm_Gesture_Line_Info /* Report line ends, timestamps, and momentum computed */ {Elm_Gesture_Momentum_Info momentum; /**< Line momentum info */ @@ -163,14 +171,12 @@ struct _Elm_Gesture_Line_Info /* Report line ends, timestamps, and momentum co /** * @typedef Elm_Gesture_Line_Info * Holds line info for user - * @ingroup Elm_Gesture_Layer */ typedef struct _Elm_Gesture_Line_Info Elm_Gesture_Line_Info; /** * @struct _Elm_Gesture_Zoom_Info * Struct holds zoom info for user - * @ingroup Elm_Gesture_Layer */ struct _Elm_Gesture_Zoom_Info { @@ -183,14 +189,12 @@ struct _Elm_Gesture_Zoom_Info /** * @typedef Elm_Gesture_Zoom_Info * Holds zoom info for user - * @ingroup Elm_Gesture_Layer */ typedef struct _Elm_Gesture_Zoom_Info Elm_Gesture_Zoom_Info; /** * @struct _Elm_Gesture_Rotate_Info * Struct holds rotation info for user - * @ingroup Elm_Gesture_Layer */ struct _Elm_Gesture_Rotate_Info { @@ -204,7 +208,6 @@ struct _Elm_Gesture_Rotate_Info /** * @typedef Elm_Gesture_Rotate_Info * Holds rotation info for user - * @ingroup Elm_Gesture_Layer */ typedef struct _Elm_Gesture_Rotate_Info Elm_Gesture_Rotate_Info; @@ -217,7 +220,6 @@ typedef struct _Elm_Gesture_Rotate_Info Elm_Gesture_Rotate_Info; * You should probably return EVAS_EVENT_FLAG_ON_HOLD if your widget acted * upon the event, in an irreversible way. * - * @ingroup Elm_Gesture_Layer */ typedef Evas_Event_Flags (*Elm_Gesture_Event_Cb)(void *data, void *event_info); @@ -237,7 +239,6 @@ typedef Evas_Event_Flags (*Elm_Gesture_Event_Cb)(void *data, void *event_info); * @param cb_type what event this callback tracks: START, MOVE, END, ABORT. * @param data user info to be sent to callback (usually, Smart Data) * - * @ingroup Elm_Gesture_Layer */ EAPI void elm_gesture_layer_cb_set(Evas_Object *obj, Elm_Gesture_Type idx, Elm_Gesture_State cb_type, Elm_Gesture_Event_Cb cb, void *data); @@ -248,7 +249,6 @@ EAPI void elm_gesture_layer_cb_set(Evas_Object *obj, Elm_Gesture_Type id * * @return repeat events settings. * @see elm_gesture_layer_hold_events_set() - * @ingroup Elm_Gesture_Layer */ EAPI Eina_Bool elm_gesture_layer_hold_events_get(const Evas_Object *obj); @@ -261,7 +261,6 @@ EAPI Eina_Bool elm_gesture_layer_hold_events_get(const Evas_Object *obj); * @param obj gesture layer. * @param hold_events hold events or not. * - * @ingroup Elm_Gesture_Layer */ EAPI void elm_gesture_layer_hold_events_set(Evas_Object *obj, Eina_Bool hold_events); @@ -274,7 +273,6 @@ EAPI void elm_gesture_layer_hold_events_set(Evas_Object *obj, Eina_Bool * @param step new zoom step value. * * @see elm_gesture_layer_zoom_step_get() - * @ingroup Elm_Gesture_Layer */ EAPI void elm_gesture_layer_zoom_step_set(Evas_Object *obj, double step); @@ -285,7 +283,6 @@ EAPI void elm_gesture_layer_zoom_step_set(Evas_Object *obj, double step) * @return zoom step value. * * @see elm_gesture_layer_zoom_step_set() - * @ingroup Elm_Gesture_Layer */ EAPI double elm_gesture_layer_zoom_step_get(const Evas_Object *obj); @@ -297,7 +294,6 @@ EAPI double elm_gesture_layer_zoom_step_get(const Evas_Object *obj); * @param obj gesture-layer. * @param step new rotate step value. * - * @ingroup Elm_Gesture_Layer */ EAPI void elm_gesture_layer_rotate_step_set(Evas_Object *obj, double step); @@ -307,7 +303,6 @@ EAPI void elm_gesture_layer_rotate_step_set(Evas_Object *obj, double ste * @param obj gesture-layer. * @return rotate step value. * - * @ingroup Elm_Gesture_Layer */ EAPI double elm_gesture_layer_rotate_step_get(const Evas_Object *obj); @@ -318,7 +313,6 @@ EAPI double elm_gesture_layer_rotate_step_get(const Evas_Object *obj); * * @return TRUE, FALSE on success, failure. * - * @ingroup Elm_Gesture_Layer */ EAPI Eina_Bool elm_gesture_layer_attach(Evas_Object *obj, Evas_Object *target); @@ -331,6 +325,9 @@ EAPI Eina_Bool elm_gesture_layer_attach(Evas_Object *obj, Evas_Object *target * * @return new gesture-layer object. * - * @ingroup Elm_Gesture_Layer */ EAPI Evas_Object *elm_gesture_layer_add(Evas_Object *parent); + +/** + * @} + */