From c6681aa189094e5429572adcb3689466c02c057d Mon Sep 17 00:00:00 2001 From: EunMi Lee Date: Tue, 4 Oct 2011 07:30:22 +0000 Subject: [PATCH] From: EunMi Lee Subject: [E-devel] [Patch] Evas touch event patch. Nice to meet you. I'm Eunmi Lee, developing mobile web browser and working on WebKit EFL port. I need new type of event for touch, so I've made patch to add EVAS_CALLBACK_TOUCH event to the evas. I will explain history of this patch. Currently, many web applications and sites use TouchEvent and they can do everything(scrolling, zooming and so on) like native application using TouchEvent. So, I'm also want to provide TouchEvent for web in the WebKit EFL port, but I got a problem during making TouchEvent because EFL's touch event's structure (Mouse, Multi Event) is different from Web TouchEvent's one. Let me explain about Web TouchEvent firstly. Web TouchEvent is consist of type and touch points list simply. There are 3 kinds of type. TouchStart: Happens every time a finger is placed on the screen. TouchEnd: Happens every time a finger is removed from the screen. TouchMove: Happens as a finger already placed on the screen is moved across the screen. for example, we can make (1 finger starts to touch), (2 fingers are moving), (1 finger is released duirng 3 fingers are moving) and so on. You can see the detailed information in the following url: http://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone However, EFL's touch event is consist of six kinds of type : MOUSE_DOWN, MOUSE_UP, MOUSE_MOVE, MULTI_DOWN, MULTI_UP, MULTI_MOVE. So, I have to make a converter to make web touch event from EFL's touch event. You can reference attatched image file : evas_touch_event.png. To tell the truth, converting code is not a big one. But, I want to reduce this additional job and make code simple. In the WebKit QT port, they don't have to make converting code for TouchEvent, because they have QTouchEvent, it has type and touchPoints list and they can be mapped to Web TouchEvent one by one. I think iPhone and Android also have such kind of event. That's all why I want to add new touch event type to the evas. about my patch: - EVAS_CALLBACK_TOUCH event is added - touch_points Eina_List is added to the Evas structure to maintain current touch lists. - process MOUSE/MULTI UP, DOWN, MOVE to make TOUCH event. It is my first time to modify eves codes and actually I don't know too much about evas. So, I will be grateful if you send any feedback and comments. SVN revision: 63796 --- legacy/evas/AUTHORS | 1 + legacy/evas/src/lib/Evas.h | 41 ++++++ legacy/evas/src/lib/canvas/Makefile.am | 1 + legacy/evas/src/lib/canvas/evas_callbacks.c | 2 +- legacy/evas/src/lib/canvas/evas_events.c | 18 +++ legacy/evas/src/lib/canvas/evas_main.c | 4 + .../evas/src/lib/canvas/evas_touch_events.c | 127 ++++++++++++++++++ legacy/evas/src/lib/include/evas_private.h | 7 + 8 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 legacy/evas/src/lib/canvas/evas_touch_events.c diff --git a/legacy/evas/AUTHORS b/legacy/evas/AUTHORS index d29615f62c..ebae05f96c 100644 --- a/legacy/evas/AUTHORS +++ b/legacy/evas/AUTHORS @@ -30,3 +30,4 @@ Christopher 'devilhorns' Michael Seungsoo Woo Youness Alaoui Jim Kukunas +EunMi Lee diff --git a/legacy/evas/src/lib/Evas.h b/legacy/evas/src/lib/Evas.h index 5a0b0cab45..0a8706b262 100644 --- a/legacy/evas/src/lib/Evas.h +++ b/legacy/evas/src/lib/Evas.h @@ -430,6 +430,7 @@ typedef enum _Evas_Callback_Type * More Evas object event types - see evas_object_event_callback_add(): */ EVAS_CALLBACK_IMAGE_UNLOADED, /**< Image data has been unloaded (by some mechanims in Evas that throw out original image data) */ + EVAS_CALLBACK_TOUCH, /**< Touch Event */ EVAS_CALLBACK_LAST /**< kept as last element/sentinel -- not really an event */ } Evas_Callback_Type; /**< The types of events triggering a callback */ @@ -487,6 +488,29 @@ typedef enum _Evas_Event_Flags EVAS_EVENT_FLAG_ON_SCROLL = (1 << 1) /**< This event flag indicates the event occurs while scrolling; for exameple, DOWN event occurs during scrolling; the event should be used for informational purposes and maybe some indications visually, but not actually perform anything */ } Evas_Event_Flags; /**< Flags for Events */ +/** + * State of Evas_Coord_Touch_Point + */ +typedef enum _Evas_Touch_Point_State +{ + EVAS_TOUCH_POINT_DOWN, /**< Touch point is pressed down */ + EVAS_TOUCH_POINT_UP, /**< Touch point is released */ + EVAS_TOUCH_POINT_MOVE, /**< Touch point is moved */ + EVAS_TOUCH_POINT_STILL, /**< Touch point is not moved after pressed */ + EVAS_TOUCH_POINT_CANCEL /**< Touch point is calcelled */ +} Evas_Touch_Point_State; + +/** + * Types for Evas_Touch_Event + */ +typedef enum _Evas_Event_Touch_Type +{ + EVAS_EVENT_TOUCH_BEGIN, /**< Begin touch event with pressed new touch point */ + EVAS_EVENT_TOUCH_END, /**< End touch event with released touch point */ + EVAS_EVENT_TOUCH_MOVE, /**< Any touch point in the touch_points list is moved */ + EVAS_EVENT_TOUCH_CANCEL /**< Touch event is cancelled */ +} Evas_Event_Touch_Type; + /** * Flags for Font Hinting * @ingroup Evas_Font_Group @@ -534,6 +558,7 @@ typedef struct _Evas_Point Evas_Point; /**< integer point */ typedef struct _Evas_Coord_Point Evas_Coord_Point; /**< Evas_Coord point */ typedef struct _Evas_Coord_Precision_Point Evas_Coord_Precision_Point; /**< Evas_Coord point with sub-pixel precision */ +typedef struct _Evas_Coord_Touch_Point Evas_Coord_Touch_Point; /**< Evas_Coord point with touch type and id */ typedef struct _Evas_Position Evas_Position; /**< associates given point in Canvas and Output */ typedef struct _Evas_Precision_Position Evas_Precision_Position; /**< associates given point in Canvas and Output, with sub-pixel precision */ @@ -624,6 +649,13 @@ struct _Evas_Coord_Precision_Point double xsub, ysub; }; +struct _Evas_Coord_Touch_Point +{ + Evas_Coord x, y; + int id; /**< id in order to distinguish each point */ + Evas_Touch_Point_State state; +}; + struct _Evas_Position { Evas_Point output; @@ -660,6 +692,7 @@ typedef struct _Evas_Event_Multi_Move Evas_Event_Multi_Move; /**< Event structur typedef struct _Evas_Event_Key_Down Evas_Event_Key_Down; /**< Event structure for #EVAS_CALLBACK_KEY_DOWN event callbacks */ typedef struct _Evas_Event_Key_Up Evas_Event_Key_Up; /**< Event structure for #EVAS_CALLBACK_KEY_UP event callbacks */ typedef struct _Evas_Event_Hold Evas_Event_Hold; /**< Event structure for #EVAS_CALLBACK_HOLD event callbacks */ +typedef struct _Evas_Event_Touch Evas_Event_Touch; /**< Event structure for #EVAS_CALLBACK_TOUCH event callbacks */ typedef enum _Evas_Load_Error { @@ -1016,6 +1049,14 @@ struct _Evas_Event_Hold /** Hold change event */ Evas_Device *dev; }; +struct _Evas_Event_Touch /** Touch event */ +{ + Eina_List *points; /**< Evas_Coord_Touch_Point list */ + Evas_Modifier *modifiers; + unsigned int timestamp; + Evas_Event_Touch_Type type; /**< Type for Evas_Event_Touch */ +}; + /** * How the mouse pointer should be handled by Evas. * diff --git a/legacy/evas/src/lib/canvas/Makefile.am b/legacy/evas/src/lib/canvas/Makefile.am index 32dadc3219..fd32990e77 100644 --- a/legacy/evas/src/lib/canvas/Makefile.am +++ b/legacy/evas/src/lib/canvas/Makefile.am @@ -51,6 +51,7 @@ evas_smart.c \ evas_stack.c \ evas_async_events.c \ evas_stats.c \ +evas_touch_events.c \ evas_map.c \ evas_gl.c diff --git a/legacy/evas/src/lib/canvas/evas_callbacks.c b/legacy/evas/src/lib/canvas/evas_callbacks.c index 33b93bcbc6..f87adaa361 100644 --- a/legacy/evas/src/lib/canvas/evas_callbacks.c +++ b/legacy/evas/src/lib/canvas/evas_callbacks.c @@ -249,7 +249,7 @@ evas_object_event_callback_call(Evas_Object *obj, Evas_Callback_Type type, void if (!obj->no_propagate) { if ((obj->smart.parent) && (type != EVAS_CALLBACK_FREE) && - (type <= EVAS_CALLBACK_KEY_UP)) + ((type <= EVAS_CALLBACK_KEY_UP) || (type == EVAS_CALLBACK_TOUCH))) evas_object_event_callback_call(obj->smart.parent, type, event_info); } } diff --git a/legacy/evas/src/lib/canvas/evas_events.c b/legacy/evas/src/lib/canvas/evas_events.c index e7fb6b040b..33b5015ff2 100644 --- a/legacy/evas/src/lib/canvas/evas_events.c +++ b/legacy/evas/src/lib/canvas/evas_events.c @@ -270,6 +270,9 @@ evas_event_feed_mouse_down(Evas *e, int b, Evas_Button_Flags flags, unsigned int e->last_mouse_down_counter++; _evas_post_event_callback_call(e); _evas_unwalk(e); + + /* process mouse down for touch */ + _evas_event_touch_down(e, e->pointer.x, e->pointer.y, 0, timestamp); } static int @@ -455,6 +458,9 @@ evas_event_feed_mouse_up(Evas *e, int b, Evas_Button_Flags flags, unsigned int t } */ _evas_unwalk(e); + + /* process mouse up for touch */ + _evas_event_touch_up(e, e->pointer.x, e->pointer.y, 0, timestamp); } EAPI void @@ -771,6 +777,9 @@ evas_event_feed_mouse_move(Evas *e, int x, int y, unsigned int timestamp, const _evas_post_event_callback_call(e); } _evas_unwalk(e); + + /* process mouse move for touch */ + _evas_event_touch_move(e, e->pointer.x, e->pointer.y, 0, timestamp); } EAPI void @@ -960,6 +969,9 @@ evas_event_feed_multi_down(Evas *e, if (copy) eina_list_free(copy); _evas_post_event_callback_call(e); _evas_unwalk(e); + + /* process multi down for touch */ + _evas_event_touch_down(e, x, y, d, timestamp); } EAPI void @@ -1030,6 +1042,9 @@ evas_event_feed_multi_up(Evas *e, if ((e->pointer.mouse_grabbed == 0) && !_post_up_handle(e, timestamp, data)) _evas_post_event_callback_call(e); _evas_unwalk(e); + + /* process multi up for touch */ + _evas_event_touch_up(e, x, y, d, timestamp); } EAPI void @@ -1178,6 +1193,9 @@ evas_event_feed_multi_move(Evas *e, _evas_post_event_callback_call(e); } _evas_unwalk(e); + + /* process multi move for touch */ + _evas_event_touch_move(e, x, y, d, timestamp); } EAPI void diff --git a/legacy/evas/src/lib/canvas/evas_main.c b/legacy/evas/src/lib/canvas/evas_main.c index b52efe8e3b..d3e4c8c52d 100644 --- a/legacy/evas/src/lib/canvas/evas_main.c +++ b/legacy/evas/src/lib/canvas/evas_main.c @@ -143,6 +143,7 @@ EAPI void evas_free(Evas *e) { Eina_Rectangle *r; + Evas_Coord_Touch_Point *touch_point; Evas_Layer *lay; int i; int del; @@ -249,6 +250,9 @@ evas_free(Evas *e) eina_array_flush(&e->calculate_objects); eina_array_flush(&e->clip_changes); + EINA_LIST_FREE(e->touch_points, touch_point) + free(touch_point); + eina_list_free(e->calc_list); e->magic = 0; diff --git a/legacy/evas/src/lib/canvas/evas_touch_events.c b/legacy/evas/src/lib/canvas/evas_touch_events.c new file mode 100644 index 0000000000..456cd8b621 --- /dev/null +++ b/legacy/evas/src/lib/canvas/evas_touch_events.c @@ -0,0 +1,127 @@ +#include "evas_common.h" +#include "evas_private.h" + +static void +_evas_touch_point_append(Evas *e, int id, int x, int y) +{ + Evas_Coord_Touch_Point *point; + + /* create new Evas_Coord_Touch_Point */ + point = (Evas_Coord_Touch_Point *)calloc(1, sizeof(Evas_Coord_Touch_Point)); + point->x = x; + point->y = y; + point->id = id; + point->state = EVAS_TOUCH_POINT_DOWN; + + _evas_walk(e); + e->touch_points = eina_list_append(e->touch_points, point); + _evas_unwalk(e); +} + +static Evas_Coord_Touch_Point * +_evas_touch_point_update(Evas *e, int id, int x, int y, Evas_Touch_Point_State state) +{ + Eina_List *l; + Evas_Coord_Touch_Point *point = NULL; + + _evas_walk(e); + EINA_LIST_FOREACH(e->touch_points, l, point) + { + if (point->id == id) + { + point->x = x; + point->y = y; + point->state = state; + break; + } + } + _evas_unwalk(e); + + return point; +} + +static void +_evas_event_feed_touch(Evas *e, unsigned int timestamp, Evas_Event_Touch_Type type) +{ + Evas_Event_Touch ev; + Eina_List *l, *copy; + Evas_Coord_Touch_Point *point; + Evas_Object *obj; + const void *data; + + _evas_walk(e); + /* set Evas_Event_Touch's members */ + ev.points = NULL; + EINA_LIST_FOREACH(e->touch_points, l, point) + ev.points = eina_list_append(ev.points, point); + ev.modifiers = &(e->modifiers); + ev.timestamp = timestamp; + ev.type = type; + + /* make copy of object list */ + copy = NULL; + EINA_LIST_FOREACH(e->pointer.object.in, l, data) + copy = eina_list_append(copy, data); + + /* call all EVAS_CALLBACK_TOUCH's callbacks */ + EINA_LIST_FOREACH(copy, l, obj) + { + if (!obj->delete_me && (e->events_frozen <= 0)) + evas_object_event_callback_call(obj, EVAS_CALLBACK_TOUCH, &ev); + if (e->delete_me) break; + } + if (copy) eina_list_free(copy); + if (ev.points) eina_list_free(ev.points); + + /* if finger is released or pressed, reset all touch point's state */ + if (type != EVAS_EVENT_TOUCH_MOVE) + { + EINA_LIST_FOREACH(e->touch_points, l, point) + point->state = EVAS_TOUCH_POINT_STILL; + } + _evas_unwalk(e); +} + +void +_evas_event_touch_down(Evas *e, Evas_Coord x, Evas_Coord y, int id, unsigned int timestamp) +{ + _evas_touch_point_append(e, id, x, y); + _evas_event_feed_touch(e, timestamp, EVAS_EVENT_TOUCH_BEGIN); +} + +void +_evas_event_touch_up(Evas *e, Evas_Coord x, Evas_Coord y, int id, unsigned int timestamp) +{ + Evas_Coord_Touch_Point *point; + + /* update touch point in the touch_points list */ + point = _evas_touch_point_update(e, id, x, y, EVAS_TOUCH_POINT_UP); + if (!point) return; + + _evas_walk(e); + _evas_event_feed_touch(e, timestamp, EVAS_EVENT_TOUCH_END); + e->touch_points = eina_list_remove(e->touch_points, point); + _evas_unwalk(e); +} + +void +_evas_event_touch_move(Evas *e, Evas_Coord x, Evas_Coord y, int id, unsigned int timestamp) +{ + Eina_List *l; + Evas_Coord_Touch_Point *point; + + _evas_walk(e); + EINA_LIST_FOREACH(e->touch_points, l, point) + { + if (point->id == id) + { + /* update touch point */ + point->x = x; + point->y = y; + point->state = EVAS_TOUCH_POINT_MOVE; + + _evas_event_feed_touch(e, timestamp, EVAS_EVENT_TOUCH_MOVE); + } + } + _evas_unwalk(e); +} diff --git a/legacy/evas/src/lib/include/evas_private.h b/legacy/evas/src/lib/include/evas_private.h index c9ee526649..bb16f47530 100644 --- a/legacy/evas/src/lib/include/evas_private.h +++ b/legacy/evas/src/lib/include/evas_private.h @@ -378,6 +378,8 @@ struct _Evas unsigned char invalidate : 1; unsigned char cleanup : 1; unsigned char focus : 1; + + Eina_List *touch_points; }; struct _Evas_Layer @@ -1010,6 +1012,11 @@ Eina_Bool evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y, Eva Eina_List *evas_module_engine_list(void); +/* for touch event */ +void _evas_event_touch_down(Evas *e, Evas_Coord x, Evas_Coord y, int id, unsigned int timestamp); +void _evas_event_touch_up(Evas *e, Evas_Coord x, Evas_Coord y, int id, unsigned int timestamp); +void _evas_event_touch_move(Evas *e, Evas_Coord x, Evas_Coord y, int id, unsigned int timestamp); + /****************************************************************************/ /*****************************************/ /********************/