1/*
2 * Copyright (C) 2012 Samsung Electronics
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 *  * Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 *  * 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 ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER 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
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27
28#if ENABLE(TOUCH_EVENTS)
29
30#include "PlatformTouchPoint.h"
31#include "ewk_touch_event_private.h"
32#include <Ecore_Input.h>
33#include <wtf/CurrentTime.h>
34
35class WebKitPlatformTouchPoint : public WebCore::PlatformTouchPoint {
36public:
37    WebKitPlatformTouchPoint(unsigned id, const WebCore::IntPoint& windowPos, WebCore::PlatformTouchPoint::State state)
38    {
39        m_id = id;
40        m_state = state;
41        m_screenPos = windowPos;
42        m_pos = windowPos;
43    }
44};
45
46class WebKitPlatformTouchEvent : public WebCore::PlatformTouchEvent {
47public:
48    WebKitPlatformTouchEvent(const Eina_List* points, const WebCore::IntPoint& pos, Ewk_Touch_Event_Type action, unsigned modifiers)
49    {
50        switch (action) {
51        case EWK_TOUCH_START:
52            m_type = WebCore::PlatformEvent::TouchStart;
53            break;
54        case EWK_TOUCH_MOVE:
55            m_type = WebCore::PlatformEvent::TouchMove;
56            break;
57        case EWK_TOUCH_END:
58            m_type = WebCore::PlatformEvent::TouchEnd;
59            break;
60        case EWK_TOUCH_CANCEL:
61            m_type = WebCore::PlatformEvent::TouchCancel;
62            break;
63        default:
64            ASSERT_NOT_REACHED();
65            break;
66        }
67
68        if (modifiers & ECORE_EVENT_MODIFIER_ALT)
69            m_modifiers |= WebCore::PlatformEvent::AltKey;
70        if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
71            m_modifiers |= WebCore::PlatformEvent::CtrlKey;
72        if (modifiers & ECORE_EVENT_MODIFIER_SHIFT)
73            m_modifiers |= WebCore::PlatformEvent::ShiftKey;
74        if (modifiers & ECORE_EVENT_MODIFIER_WIN)
75            m_modifiers |= WebCore::PlatformEvent::MetaKey;
76
77        m_timestamp = currentTime();
78
79        const Eina_List* list;
80        void* item;
81        EINA_LIST_FOREACH(points, list, item) {
82            Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(item);
83            WebCore::IntPoint pnt = WebCore::IntPoint(point->x - pos.x(), point->y - pos.y());
84            m_touchPoints.append(WebKitPlatformTouchPoint(point->id, pnt, static_cast<WebCore::PlatformTouchPoint::State>(point->state)));
85        }
86    }
87};
88
89namespace EWKPrivate {
90
91WebCore::PlatformTouchEvent platformTouchEvent(Evas_Coord x, Evas_Coord y, Eina_List* points, Ewk_Touch_Event_Type action, unsigned modifiers)
92{
93    return WebKitPlatformTouchEvent(points, WebCore::IntPoint(x, y), action, modifiers);
94}
95
96}
97
98#endif // ENABLE(TOUCH_EVENTS)
99