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.
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/evas@63796
7cbeb6ba-43b4-40fd-8cce-
4c39aea84d33
Seungsoo Woo <om101.woo@samsung.com>
Youness Alaoui <kakaroto@kakaroto.homelinux.net>
Jim Kukunas <james.t.kukunas@linux.intel.com>
+EunMi Lee <eunmi15.lee@samsung.com>
* 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 */
} 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
*/
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 */
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;
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
{
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.
*
evas_stack.c \
evas_async_events.c \
evas_stats.c \
+evas_touch_events.c \
evas_map.c \
evas_gl.c
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);
}
}
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
}
*/
_evas_unwalk(e);
+
+ /* process mouse up for touch */
+ _evas_event_touch_up(e, e->pointer.x, e->pointer.y, 0, timestamp);
}
EAPI void
_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
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
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
_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
evas_free(Evas *e)
{
Eina_Rectangle *r;
+ Evas_Coord_Touch_Point *touch_point;
Evas_Layer *lay;
int i;
int del;
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;
--- /dev/null
+#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);
+}
unsigned char invalidate : 1;
unsigned char cleanup : 1;
unsigned char focus : 1;
+
+ Eina_List *touch_points;
};
struct _Evas_Layer
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);
+
/****************************************************************************/
/*****************************************/
/********************/