ewk_touch_event.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #include "config.h"
  26. #if ENABLE(TOUCH_EVENTS)
  27. #include "PlatformTouchPoint.h"
  28. #include "ewk_touch_event_private.h"
  29. #include <Ecore_Input.h>
  30. #include <wtf/CurrentTime.h>
  31. class WebKitPlatformTouchPoint : public WebCore::PlatformTouchPoint {
  32. public:
  33. WebKitPlatformTouchPoint(unsigned id, const WebCore::IntPoint& windowPos, WebCore::PlatformTouchPoint::State state)
  34. {
  35. m_id = id;
  36. m_state = state;
  37. m_screenPos = windowPos;
  38. m_pos = windowPos;
  39. }
  40. };
  41. class WebKitPlatformTouchEvent : public WebCore::PlatformTouchEvent {
  42. public:
  43. WebKitPlatformTouchEvent(const Eina_List* points, const WebCore::IntPoint& pos, Ewk_Touch_Event_Type action, unsigned modifiers)
  44. {
  45. switch (action) {
  46. case EWK_TOUCH_START:
  47. m_type = WebCore::PlatformEvent::TouchStart;
  48. break;
  49. case EWK_TOUCH_MOVE:
  50. m_type = WebCore::PlatformEvent::TouchMove;
  51. break;
  52. case EWK_TOUCH_END:
  53. m_type = WebCore::PlatformEvent::TouchEnd;
  54. break;
  55. case EWK_TOUCH_CANCEL:
  56. m_type = WebCore::PlatformEvent::TouchCancel;
  57. break;
  58. default:
  59. ASSERT_NOT_REACHED();
  60. break;
  61. }
  62. if (modifiers & ECORE_EVENT_MODIFIER_ALT)
  63. m_modifiers |= WebCore::PlatformEvent::AltKey;
  64. if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
  65. m_modifiers |= WebCore::PlatformEvent::CtrlKey;
  66. if (modifiers & ECORE_EVENT_MODIFIER_SHIFT)
  67. m_modifiers |= WebCore::PlatformEvent::ShiftKey;
  68. if (modifiers & ECORE_EVENT_MODIFIER_WIN)
  69. m_modifiers |= WebCore::PlatformEvent::MetaKey;
  70. m_timestamp = currentTime();
  71. const Eina_List* list;
  72. void* item;
  73. EINA_LIST_FOREACH(points, list, item) {
  74. Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(item);
  75. WebCore::IntPoint pnt = WebCore::IntPoint(point->x - pos.x(), point->y - pos.y());
  76. m_touchPoints.append(WebKitPlatformTouchPoint(point->id, pnt, static_cast<WebCore::PlatformTouchPoint::State>(point->state)));
  77. }
  78. }
  79. };
  80. namespace EWKPrivate {
  81. WebCore::PlatformTouchEvent platformTouchEvent(Evas_Coord x, Evas_Coord y, Eina_List* points, Ewk_Touch_Event_Type action, unsigned modifiers)
  82. {
  83. return WebKitPlatformTouchEvent(points, WebCore::IntPoint(x, y), action, modifiers);
  84. }
  85. }
  86. #endif // ENABLE(TOUCH_EVENTS)