Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / event-handler-ecore-wl.cpp
index cfc5446..3033ba3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,9 @@
 #include <events/event-handler.h>
 
 // EXTERNAL INCLUDES
+// Ecore is littered with C style cast
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
 #include <Ecore.h>
 #include <Ecore_Input.h>
 #include <ecore-wl-render-surface.h>
@@ -88,6 +91,83 @@ const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
 
 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
 
+#ifdef DALI_ELDBUS_AVAILABLE
+// DBus gesture string matching lists.
+// TODO: This needs moving to its own module.
+const char * ElDBusAccessibilityFingerCountStrings[] =
+{
+  "OneFinger",
+  "TwoFingers",
+  "ThreeFingers"
+};
+const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
+enum GestureType
+{
+  GESTURE_TYPE_NONE,
+  GESTURE_TYPE_HOVER,
+  GESTURE_TYPE_SINGLE_TAP,
+  GESTURE_TYPE_DOUBLE_TAP,
+  GESTURE_TYPE_TRIPLE_TAP
+};
+struct GestureTypeTable
+{
+  const char* name;
+  const GestureType type;
+};
+GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
+{
+  { "Hover",     GESTURE_TYPE_HOVER      },
+  { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
+  { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
+  { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
+};
+const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
+enum SubGestureType
+{
+  SUB_GESTURE_TYPE_NONE,
+  SUB_GESTURE_TYPE_FLICK
+};
+struct SubGestureTypeTable
+{
+  const char* name;
+  const SubGestureType type;
+};
+SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
+{
+  { "Flick", SUB_GESTURE_TYPE_FLICK }
+};
+const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
+enum GestureDirection
+{
+  GESTURE_DIRECTION_NONE,
+  GESTURE_DIRECTION_UP,
+  GESTURE_DIRECTION_DOWN,
+  GESTURE_DIRECTION_LEFT,
+  GESTURE_DIRECTION_RIGHT,
+  GESTURE_DIRECTION_UP_RETURN,
+  GESTURE_DIRECTION_DOWN_RETURN,
+  GESTURE_DIRECTION_LEFT_RETURN,
+  GESTURE_DIRECTION_RIGHT_RETURN
+};
+struct GestureDirectionTable
+{
+    const char* name;
+    const GestureDirection direction;
+};
+GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
+{
+  { "Up",           GESTURE_DIRECTION_UP           },
+  { "Down",         GESTURE_DIRECTION_DOWN         },
+  { "Left",         GESTURE_DIRECTION_LEFT         },
+  { "Right",        GESTURE_DIRECTION_RIGHT        },
+  { "UpReturn",     GESTURE_DIRECTION_UP_RETURN    },
+  { "DownReturn",   GESTURE_DIRECTION_DOWN_RETURN  },
+  { "LeftReturn",   GESTURE_DIRECTION_LEFT_RETURN  },
+  { "RightReturn",  GESTURE_DIRECTION_RIGHT_RETURN }
+};
+const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
+#endif // DALI_ELDBUS_AVAILABLE
+
 /**
  * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
  * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
@@ -246,7 +326,10 @@ struct EventHandler::Impl
   Impl( EventHandler* handler, Ecore_Wl_Window* window )
   : mHandler( handler ),
     mEcoreEventHandler(),
-    mWindow( window )
+    mWindow( window ),
+    mRotationAngle( 0 ),
+    mWindowWidth( 0 ),
+    mWindowHeight( 0 )
 #ifdef DALI_ELDBUS_AVAILABLE
   , mSystemConnection( NULL )
 #endif // DALI_ELDBUS_AVAILABLE
@@ -1183,8 +1266,18 @@ struct EventHandler::Impl
     RotationEvent rotationEvent;
     rotationEvent.angle = ev->angle;
     rotationEvent.winResize = 0;
-    rotationEvent.width = ev->w;
-    rotationEvent.height = ev->h;
+
+    if( ev->angle == 0 || ev->angle == 180 )
+    {
+      rotationEvent.width = ev->w;
+      rotationEvent.height = ev->h;
+    }
+    else
+    {
+      rotationEvent.width = ev->h;
+      rotationEvent.height = ev->w;
+    }
+
     handler->SendRotationPrepareEvent( rotationEvent );
 
     return ECORE_CALLBACK_PASS_ON;
@@ -1227,10 +1320,48 @@ struct EventHandler::Impl
     handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
   }
 
+  void ConvertTouchPosition( Integration::Point& point )
+  {
+    Vector2 position = point.GetScreenPosition();
+    Vector2 convertedPosition;
+
+    switch( mRotationAngle )
+    {
+      case 90:
+      {
+        convertedPosition.x = mWindowWidth - position.y;
+        convertedPosition.y = position.x;
+        break;
+      }
+      case 180:
+      {
+        convertedPosition.x = mWindowWidth - position.x;
+        convertedPosition.y = mWindowHeight - position.y;
+        break;
+      }
+      case 270:
+      {
+        convertedPosition.x = position.y;
+        convertedPosition.y = mWindowHeight - position.x;
+        break;
+      }
+      default:
+      {
+        convertedPosition = position;
+        break;
+      }
+    }
+
+    point.SetScreenPosition( convertedPosition );
+  }
+
   // Data
   EventHandler* mHandler;
   std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
   Ecore_Wl_Window* mWindow;
+  int mRotationAngle;
+  int mWindowWidth;
+  int mWindowHeight;
 #ifdef DALI_ELDBUS_AVAILABLE
   Eldbus_Connection* mSystemConnection;
 #endif // DALI_ELDBUS_AVAILABLE
@@ -1278,12 +1409,14 @@ void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
     timeStamp = GetCurrentMilliSeconds();
   }
 
+  mImpl->ConvertTouchPosition( point );
+
   Integration::TouchEvent touchEvent;
   Integration::HoverEvent hoverEvent;
   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
   if(type != Integration::TouchEventCombiner::DispatchNone )
   {
-    DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetLocalPosition().x, point.GetLocalPosition().y);
+    DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetScreenPosition().x, point.GetScreenPosition().y);
 
     // First the touch and/or hover event & related gesture events are queued
     if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
@@ -1341,6 +1474,10 @@ void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
 {
   if( mRotationObserver != NULL )
   {
+    mImpl->mRotationAngle = event.angle;
+    mImpl->mWindowWidth = event.width;
+    mImpl->mWindowHeight = event.height;
+
     mRotationObserver->OnRotationPrepare( event );
     mRotationObserver->OnRotationRequest();
   }
@@ -1419,3 +1556,5 @@ void EventHandler::SetRotationObserver( RotationObserver* observer )
 } // namespace Internal
 
 } // namespace Dali
+
+#pragma GCC diagnostic pop