1/*
2 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "ewk_touch.h"
28
29#include "ewk_touch_private.h"
30#include <Ecore.h>
31#include <WebCore/AffineTransform.h>
32
33using namespace WebCore;
34
35WKTouchEvent* createWKTouchEvent(Ewk_Touch_Event_Type type, const Eina_List* points, const Evas_Modifier* modifiers, const AffineTransform& toDeviceScreen)
36{
37 EINA_SAFETY_ON_NULL_RETURN_VAL(points, 0);
38
39 WKTouchEvent* touchEvent = new WKTouchEvent;
40 touchEvent->type = static_cast<WKEventType>(type);
41 touchEvent->timestamp = ecore_time_get();
42 touchEvent->numTouchPoints = eina_list_count(points);
43 if (touchEvent->numTouchPoints > kWKMaximumTouchPointsPerTouchEvent)
44 touchEvent->numTouchPoints = eina_list_count(points);
45
46 touchEvent->modifiers = 0;
47 if (evas_key_modifier_is_set(modifiers, "Shift"))
48 touchEvent->modifiers |= kWKEventModifiersShiftKey;
49 if (evas_key_modifier_is_set(modifiers, "Control"))
50 touchEvent->modifiers |= kWKEventModifiersControlKey;
51 if (evas_key_modifier_is_set(modifiers, "Alt"))
52 touchEvent->modifiers |= kWKEventModifiersAltKey;
53 if (evas_key_modifier_is_set(modifiers, "Meta"))
54 touchEvent->modifiers |= kWKEventModifiersMetaKey;
55
56 const Eina_List* list;
57 unsigned index;
58 for (list = points, index = 0; list && index < touchEvent->numTouchPoints; list = eina_list_next(list), ++index) {
59 double x;
60 double y;
61 Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(eina_list_data_get(list));
62 WKTouchPoint& wkTouchPoint = touchEvent->touchPoints[index];
63
64 wkTouchPoint.id = point->id;
65 wkTouchPoint.position = WKPointMake(point->x, point->y);
66 toDeviceScreen.map(point->x, point->y, x, y);
67 wkTouchPoint.screenPosition = WKPointMake(x, y);
68 wkTouchPoint.radius = WKSizeMake(0, 0);
69 wkTouchPoint.rotationAngle = 0;
70 wkTouchPoint.force = 0;
71
72 switch (point->state) {
73 case EVAS_TOUCH_POINT_UP:
74 wkTouchPoint.state = kWKTouchPointStateTouchReleased;
75 break;
76 case EVAS_TOUCH_POINT_MOVE:
77 wkTouchPoint.state = kWKTouchPointStateTouchMoved;
78 break;
79 case EVAS_TOUCH_POINT_DOWN:
80 wkTouchPoint.state = kWKTouchPointStateTouchPressed;
81 break;
82 case EVAS_TOUCH_POINT_STILL:
83 wkTouchPoint.state = kWKTouchPointStateTouchStationary;
84 break;
85 case EVAS_TOUCH_POINT_CANCEL:
86 default:
87 wkTouchPoint.state = kWKTouchPointStateTouchCancelled;
88 break;
89 }
90 }
91
92 return touchEvent;
93}