[Tizen] Support custom fonts registration
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / event-handler-ecore-wl.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/window-system/common/event-handler.h>
20
21 // EXTERNAL INCLUDES
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
25 #include <Ecore.h>
26 #include <Ecore_Input.h>
27 #include <Ecore_IMF.h>
28 #include <cstring>
29
30 #include <sys/time.h>
31
32 #ifndef DALI_PROFILE_UBUNTU
33 #include <vconf.h>
34 #include <vconf-keys.h>
35 #endif // DALI_PROFILE_UBUNTU
36
37 #ifdef DALI_ELDBUS_AVAILABLE
38 #include <Eldbus.h>
39 #endif // DALI_ELDBUS_AVAILABLE
40
41 #include <dali/public-api/common/vector-wrapper.h>
42 #include <dali/public-api/events/device.h>
43 #include <dali/public-api/events/touch-point.h>
44 #include <dali/public-api/events/key-event.h>
45 #include <dali/public-api/events/wheel-event.h>
46 #include <dali/integration-api/debug.h>
47 #include <dali/integration-api/events/key-event-integ.h>
48 #include <dali/integration-api/events/touch-event-integ.h>
49 #include <dali/integration-api/events/hover-event-integ.h>
50 #include <dali/integration-api/events/wheel-event-integ.h>
51
52 // INTERNAL INCLUDES
53 #include <dali/internal/input/common/gesture-manager.h>
54 #include <dali/internal/window-system/tizen-wayland/window-render-surface-ecore-wl.h>
55 #include <dali/internal/clipboard/common/clipboard-impl.h>
56 #include <dali/internal/input/common/key-impl.h>
57 #include <dali/internal/input/common/physical-keyboard-impl.h>
58 #include <dali/internal/styling/common/style-monitor-impl.h>
59 #include <dali/internal/system/common/core-event-interface.h>
60 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
61
62 namespace Dali
63 {
64
65 namespace Internal
66 {
67
68 namespace Adaptor
69 {
70
71 #if defined(DEBUG_ENABLED)
72 namespace
73 {
74 Integration::Log::Filter* gTouchEventLogFilter  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
75 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
76 Integration::Log::Filter* gImfLogging  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
77 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
78 } // unnamed namespace
79 #endif
80
81
82 namespace
83 {
84
85 // DBUS accessibility
86 const char* BUS = "org.enlightenment.wm-screen-reader";
87 const char* INTERFACE = "org.tizen.GestureNavigation";
88 const char* PATH = "/org/tizen/GestureNavigation";
89
90 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
91
92 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
93
94 #ifdef DALI_ELDBUS_AVAILABLE
95 // DBus gesture string matching lists.
96 // TODO: This needs moving to its own module.
97 const char * ElDBusAccessibilityFingerCountStrings[] =
98 {
99   "OneFinger",
100   "TwoFingers",
101   "ThreeFingers"
102 };
103 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
104 enum GestureType
105 {
106   GESTURE_TYPE_NONE,
107   GESTURE_TYPE_HOVER,
108   GESTURE_TYPE_SINGLE_TAP,
109   GESTURE_TYPE_DOUBLE_TAP,
110   GESTURE_TYPE_TRIPLE_TAP
111 };
112 struct GestureTypeTable
113 {
114   const char* name;
115   const GestureType type;
116 };
117 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
118 {
119   { "Hover",     GESTURE_TYPE_HOVER      },
120   { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
121   { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
122   { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
123 };
124 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
125 enum SubGestureType
126 {
127   SUB_GESTURE_TYPE_NONE,
128   SUB_GESTURE_TYPE_FLICK
129 };
130 struct SubGestureTypeTable
131 {
132   const char* name;
133   const SubGestureType type;
134 };
135 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
136 {
137   { "Flick", SUB_GESTURE_TYPE_FLICK }
138 };
139 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
140 enum GestureDirection
141 {
142   GESTURE_DIRECTION_NONE,
143   GESTURE_DIRECTION_UP,
144   GESTURE_DIRECTION_DOWN,
145   GESTURE_DIRECTION_LEFT,
146   GESTURE_DIRECTION_RIGHT,
147   GESTURE_DIRECTION_UP_RETURN,
148   GESTURE_DIRECTION_DOWN_RETURN,
149   GESTURE_DIRECTION_LEFT_RETURN,
150   GESTURE_DIRECTION_RIGHT_RETURN
151 };
152 struct GestureDirectionTable
153 {
154     const char* name;
155     const GestureDirection direction;
156 };
157 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
158 {
159   { "Up",           GESTURE_DIRECTION_UP           },
160   { "Down",         GESTURE_DIRECTION_DOWN         },
161   { "Left",         GESTURE_DIRECTION_LEFT         },
162   { "Right",        GESTURE_DIRECTION_RIGHT        },
163   { "UpReturn",     GESTURE_DIRECTION_UP_RETURN    },
164   { "DownReturn",   GESTURE_DIRECTION_DOWN_RETURN  },
165   { "LeftReturn",   GESTURE_DIRECTION_LEFT_RETURN  },
166   { "RightReturn",  GESTURE_DIRECTION_RIGHT_RETURN }
167 };
168 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
169 #endif // DALI_ELDBUS_AVAILABLE
170
171 // Copied from x server
172 static unsigned int GetCurrentMilliSeconds(void)
173 {
174   struct timeval tv;
175
176   struct timespec tp;
177   static clockid_t clockid;
178
179   if (!clockid)
180   {
181 #ifdef CLOCK_MONOTONIC_COARSE
182     if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
183       (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
184     {
185       clockid = CLOCK_MONOTONIC_COARSE;
186     }
187     else
188 #endif
189     if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
190     {
191       clockid = CLOCK_MONOTONIC;
192     }
193     else
194     {
195       clockid = ~0L;
196     }
197   }
198   if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
199   {
200     return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
201   }
202
203   gettimeofday(&tv, NULL);
204   return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
205 }
206
207 #ifndef DALI_PROFILE_UBUNTU
208 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name";  // It will be update at vconf-key.h and replaced.
209 #endif // DALI_PROFILE_UBUNTU
210
211 /**
212  * Get the device name from the provided ecore key event
213  */
214 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
215 {
216   const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
217
218   if ( ecoreDeviceName )
219   {
220     result = ecoreDeviceName;
221   }
222 }
223
224 /**
225  * Get the device class from the provided ecore event
226  */
227 void GetDeviceClass( Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass )
228 {
229   switch( ecoreDeviceClass )
230   {
231     case ECORE_DEVICE_CLASS_SEAT:
232     {
233       deviceClass = Device::Class::USER;
234       break;
235     }
236     case ECORE_DEVICE_CLASS_KEYBOARD:
237     {
238       deviceClass = Device::Class::KEYBOARD;
239       break;
240     }
241     case ECORE_DEVICE_CLASS_MOUSE:
242     {
243       deviceClass = Device::Class::MOUSE;
244       break;
245     }
246     case ECORE_DEVICE_CLASS_TOUCH:
247     {
248       deviceClass = Device::Class::TOUCH;
249       break;
250     }
251     case ECORE_DEVICE_CLASS_PEN:
252     {
253       deviceClass = Device::Class::PEN;
254       break;
255     }
256     case ECORE_DEVICE_CLASS_POINTER:
257     {
258       deviceClass = Device::Class::POINTER;
259       break;
260     }
261     case ECORE_DEVICE_CLASS_GAMEPAD:
262     {
263       deviceClass = Device::Class::GAMEPAD;
264       break;
265     }
266     default:
267     {
268       deviceClass = Device::Class::NONE;
269       break;
270     }
271   }
272 }
273
274 void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass )
275 {
276   switch( ecoreDeviceSubclass )
277   {
278     case ECORE_DEVICE_SUBCLASS_FINGER:
279     {
280       deviceSubclass = Device::Subclass::FINGER;
281       break;
282     }
283     case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
284     {
285       deviceSubclass = Device::Subclass::FINGERNAIL;
286       break;
287     }
288     case ECORE_DEVICE_SUBCLASS_KNUCKLE:
289     {
290       deviceSubclass = Device::Subclass::KNUCKLE;
291       break;
292     }
293     case ECORE_DEVICE_SUBCLASS_PALM:
294     {
295       deviceSubclass = Device::Subclass::PALM;
296       break;
297     }
298     case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
299     {
300       deviceSubclass = Device::Subclass::HAND_SIDE;
301       break;
302     }
303     case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
304     {
305       deviceSubclass = Device::Subclass::HAND_FLAT;
306       break;
307     }
308     case ECORE_DEVICE_SUBCLASS_PEN_TIP:
309     {
310       deviceSubclass = Device::Subclass::PEN_TIP;
311       break;
312     }
313     case ECORE_DEVICE_SUBCLASS_TRACKPAD:
314     {
315       deviceSubclass = Device::Subclass::TRACKPAD;
316       break;
317     }
318     case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
319     {
320       deviceSubclass = Device::Subclass::TRACKPOINT;
321       break;
322     }
323     case ECORE_DEVICE_SUBCLASS_TRACKBALL:
324     {
325       deviceSubclass = Device::Subclass::TRACKBALL;
326       break;
327     }
328 #ifdef OVER_TIZEN_VERSION_4
329     case ECORE_DEVICE_SUBCLASS_REMOCON:
330     {
331       deviceSubclass = Device::Subclass::REMOCON;
332       break;
333     }
334     case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
335     {
336       deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
337       break;
338     }
339 #endif
340     default:
341     {
342       deviceSubclass = Device::Subclass::NONE;
343       break;
344     }
345   }
346 }
347
348 } // unnamed namespace
349
350 // Impl to hide EFL implementation.
351 struct EventHandler::Impl
352 {
353   // Construction & Destruction
354
355   /**
356    * Constructor
357    */
358   Impl( EventHandler* handler, Ecore_Wl_Window* window )
359   : mHandler( handler ),
360     mEcoreEventHandler(),
361     mWindow( window ),
362     mRotationAngle( 0 ),
363     mWindowWidth( 0 ),
364     mWindowHeight( 0 )
365 #ifdef DALI_ELDBUS_AVAILABLE
366   , mSystemConnection( NULL )
367 #endif // DALI_ELDBUS_AVAILABLE
368   {
369     // Only register for touch and key events if we have a window
370     if ( window != 0 )
371     {
372       // Register Touch events
373       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN,   EcoreEventMouseButtonDown,   handler ) );
374       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP,     EcoreEventMouseButtonUp,     handler ) );
375       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE,          EcoreEventMouseButtonMove,   handler ) );
376       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
377
378       // Register Mouse wheel events
379       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL,        EcoreEventMouseWheel,      handler ) );
380
381       // Register Focus events
382       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN,  EcoreEventWindowFocusIn,   handler ) );
383       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut,  handler ) );
384
385       // Register Key events
386       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN,           EcoreEventKeyDown,         handler ) );
387       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP,             EcoreEventKeyUp,           handler ) );
388
389       // Register Selection event - clipboard selection
390       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
391       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
392
393       // Register Rotate event
394       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
395
396       // Register Detent event
397       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
398
399 #ifndef DALI_PROFILE_UBUNTU
400       // Register Vconf notify - font name and size
401       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
402       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
403 #endif // DALI_PROFILE_UBUNTU
404
405 #ifdef DALI_ELDBUS_AVAILABLE
406       // Initialize ElDBus.
407       DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
408
409       // Pass in handler.
410       EcoreElDBusInitialisation( handler );
411
412       DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
413 #endif // DALI_ELDBUS_AVAILABLE
414     }
415   }
416
417   /**
418    * Destructor
419    */
420   ~Impl()
421   {
422 #ifndef DALI_PROFILE_UBUNTU
423     vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
424     vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
425 #endif // DALI_PROFILE_UBUNTU
426
427     for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
428     {
429       ecore_event_handler_del( *iter );
430     }
431
432 #ifdef DALI_ELDBUS_AVAILABLE
433     // Close down ElDBus connections.
434     if( mSystemConnection )
435     {
436       eldbus_connection_unref( mSystemConnection );
437     }
438 #endif // DALI_ELDBUS_AVAILABLE
439   }
440
441   // Static methods
442
443   /////////////////////////////////////////////////////////////////////////////////////////////////
444   // Touch Callbacks
445   /////////////////////////////////////////////////////////////////////////////////////////////////
446
447   /**
448    * Called when a touch down is received.
449    */
450   static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
451   {
452     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
453     EventHandler* handler( (EventHandler*)data );
454
455     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
456     {
457       PointState::Type state ( PointState::DOWN );
458
459       // Check if the buttons field is set and ensure it's the primary touch button.
460       // If this event was triggered by buttons other than the primary button (used for touch), then
461       // just send an interrupted event to Core.
462       if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
463       {
464         state = PointState::INTERRUPTED;
465       }
466
467       Device::Class::Type deviceClass;
468       Device::Subclass::Type deviceSubclass;
469
470       GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
471       GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
472
473       Integration::Point point;
474       point.SetDeviceId( touchEvent->multi.device );
475       point.SetState( state );
476       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
477       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
478       point.SetPressure( touchEvent->multi.pressure );
479       point.SetAngle( Degree( touchEvent->multi.angle ) );
480       point.SetDeviceClass( deviceClass );
481       point.SetDeviceSubclass( deviceSubclass );
482
483       handler->SendEvent( point, touchEvent->timestamp );
484     }
485
486     return ECORE_CALLBACK_PASS_ON;
487   }
488
489   /**
490    * Called when a touch up is received.
491    */
492   static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
493   {
494     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
495     EventHandler* handler( (EventHandler*)data );
496
497     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
498     {
499       Device::Class::Type deviceClass;
500       Device::Subclass::Type deviceSubclass;
501
502       GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
503       GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
504
505       Integration::Point point;
506       point.SetDeviceId( touchEvent->multi.device );
507       point.SetState( PointState::UP );
508       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
509       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
510       point.SetPressure( touchEvent->multi.pressure );
511       point.SetAngle( Degree( touchEvent->multi.angle ) );
512       point.SetDeviceClass( deviceClass );
513       point.SetDeviceSubclass( deviceSubclass );
514
515       handler->SendEvent( point, touchEvent->timestamp );
516     }
517
518     return ECORE_CALLBACK_PASS_ON;
519   }
520
521   /**
522    * Called when a touch motion is received.
523    */
524   static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
525   {
526     Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
527     EventHandler* handler( (EventHandler*)data );
528
529     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
530     {
531       Device::Class::Type deviceClass;
532       Device::Subclass::Type deviceSubclass;
533
534       GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
535       GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
536
537       Integration::Point point;
538       point.SetDeviceId( touchEvent->multi.device );
539       point.SetState( PointState::MOTION );
540       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
541       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
542       point.SetPressure( touchEvent->multi.pressure );
543       point.SetAngle( Degree( touchEvent->multi.angle ) );
544       point.SetDeviceClass( deviceClass );
545       point.SetDeviceSubclass( deviceSubclass );
546
547       handler->SendEvent( point, touchEvent->timestamp );
548     }
549
550     return ECORE_CALLBACK_PASS_ON;
551   }
552
553   /**
554    * Called when a touch is canceled.
555    */
556   static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
557   {
558     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
559     EventHandler* handler( (EventHandler*)data );
560
561     if( touchEvent->window == (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
562     {
563       Integration::Point point;
564       point.SetDeviceId( touchEvent->multi.device );
565       point.SetState( PointState::INTERRUPTED );
566       point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
567       handler->SendEvent( point, touchEvent->timestamp );
568
569       DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
570     }
571
572     return ECORE_CALLBACK_PASS_ON;
573   }
574
575   /**
576    * Called when a mouse wheel is received.
577    */
578   static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
579   {
580     Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
581
582     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT Ecore_Event_Mouse_Wheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent->direction, mouseWheelEvent->modifiers, mouseWheelEvent->x, mouseWheelEvent->y, mouseWheelEvent->z);
583
584     EventHandler* handler( (EventHandler*)data );
585     if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
586     {
587       WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
588       handler->SendWheelEvent( wheelEvent );
589     }
590     return ECORE_CALLBACK_PASS_ON;
591   }
592
593   /////////////////////////////////////////////////////////////////////////////////////////////////
594   // Key Callbacks
595   /////////////////////////////////////////////////////////////////////////////////////////////////
596
597   /**
598    * Called when a key down is received.
599    */
600   static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
601   {
602     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
603
604     EventHandler* handler( (EventHandler*)data );
605     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
606     bool eventHandled( false );
607
608     // If the event wasn't handled then we should send a key event.
609     if ( !eventHandled )
610     {
611       if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
612       {
613         std::string keyName( keyEvent->keyname );
614         std::string keyString( "" );
615         std::string compose( "" );
616
617         // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
618         if ( keyEvent->compose )
619         {
620           compose = keyEvent->compose;
621         }
622
623         int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
624         keyCode = (keyCode == -1) ? 0 : keyCode;
625         int modifier( keyEvent->modifiers );
626         unsigned long time = keyEvent->timestamp;
627         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
628           keyCode = atoi(keyEvent->keyname + 8);
629
630         // Ensure key event string is not NULL as keys like SHIFT have a null string.
631         if ( keyEvent->string )
632         {
633           keyString = keyEvent->string;
634         }
635
636         std::string deviceName;
637         Device::Class::Type deviceClass;
638         Device::Subclass::Type deviceSubclass;
639
640         GetDeviceName( keyEvent, deviceName );
641         GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
642         GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
643
644         DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
645
646         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, compose, deviceName, deviceClass, deviceSubclass );
647         handler->SendEvent( keyEvent );
648       }
649     }
650
651     return ECORE_CALLBACK_PASS_ON;
652   }
653
654   /**
655    * Called when a key up is received.
656    */
657   static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
658   {
659     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
660
661     EventHandler* handler( (EventHandler*)data );
662     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
663     bool eventHandled( false );
664
665     // If the event wasn't handled then we should send a key event.
666     if ( !eventHandled )
667     {
668       if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
669       {
670         std::string keyName( keyEvent->keyname );
671         std::string keyString( "" );
672         std::string compose( "" );
673
674         // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
675         if ( keyEvent->compose )
676         {
677           compose = keyEvent->compose;
678         }
679
680         int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
681         keyCode = (keyCode == -1) ? 0 : keyCode;
682         int modifier( keyEvent->modifiers );
683         unsigned long time = keyEvent->timestamp;
684         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
685           keyCode = atoi(keyEvent->keyname + 8);
686
687         // Ensure key event string is not NULL as keys like SHIFT have a null string.
688         if ( keyEvent->string )
689         {
690           keyString = keyEvent->string;
691         }
692
693         std::string deviceName;
694         Device::Class::Type deviceClass;
695         Device::Subclass::Type deviceSubclass;
696
697         GetDeviceName( keyEvent, deviceName );
698         GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
699         GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
700
701         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, compose, deviceName, deviceClass, deviceSubclass );
702         handler->SendEvent( keyEvent );
703       }
704     }
705
706     return ECORE_CALLBACK_PASS_ON;
707   }
708
709   /////////////////////////////////////////////////////////////////////////////////////////////////
710   // Window Callbacks
711   /////////////////////////////////////////////////////////////////////////////////////////////////
712
713   /**
714    * Called when the window gains focus.
715    */
716   static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
717   {
718     Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
719     EventHandler* handler( (EventHandler*)data );
720
721     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
722
723     // If the window gains focus and we hid the keyboard then show it again.
724     if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
725     {
726       DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
727
728       Dali::Clipboard clipboard = Clipboard::Get();
729       clipboard.HideClipboard();
730     }
731
732     return ECORE_CALLBACK_PASS_ON;
733   }
734
735   /**
736    * Called when the window loses focus.
737    */
738   static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
739   {
740     Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
741     EventHandler* handler( (EventHandler*)data );
742
743     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
744
745     // If the window loses focus then hide the keyboard.
746     if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
747     {
748       // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
749       Dali::Clipboard clipboard = Clipboard::Get();
750       if ( clipboard )
751       {
752         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
753         clipBoardImpl.HideClipboard(true);
754       }
755     }
756
757     return ECORE_CALLBACK_PASS_ON;
758   }
759
760   /**
761    * Called when the window is damaged.
762    */
763   static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
764   {
765     return ECORE_CALLBACK_PASS_ON;
766   }
767
768   /**
769    * Called when the window properties are changed.
770    * We are only interested in the font change.
771    */
772
773
774   /////////////////////////////////////////////////////////////////////////////////////////////////
775   // Drag & Drop Callbacks
776   /////////////////////////////////////////////////////////////////////////////////////////////////
777
778   /**
779    * Called when a dragged item enters our window's bounds.
780    * This is when items are dragged INTO our window.
781    */
782   static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
783   {
784     DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
785
786     return ECORE_CALLBACK_PASS_ON;
787   }
788
789   /**
790    * Called when a dragged item is moved within our window.
791    * This is when items are dragged INTO our window.
792    */
793   static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
794   {
795     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
796
797     return ECORE_CALLBACK_PASS_ON;
798   }
799
800   /**
801    * Called when a dragged item leaves our window's bounds.
802    * This is when items are dragged INTO our window.
803    */
804   static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
805   {
806     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
807
808     return ECORE_CALLBACK_PASS_ON;
809   }
810
811   /**
812    * Called when the dragged item is dropped within our window's bounds.
813    * This is when items are dragged INTO our window.
814    */
815   static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
816   {
817     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
818
819     return ECORE_CALLBACK_PASS_ON;
820   }
821
822   /**
823    * Called when a dragged item is moved from our window and the target window has done processing it.
824    * This is when items are dragged FROM our window.
825    */
826   static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
827   {
828     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
829     return ECORE_CALLBACK_PASS_ON;
830   }
831
832   /**
833    * Called when a dragged item is moved from our window and the target window has sent us a status.
834    * This is when items are dragged FROM our window.
835    */
836   static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
837   {
838     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
839     return ECORE_CALLBACK_PASS_ON;
840   }
841
842   /**
843    * Called when the client messages (i.e. the accessibility events) are received.
844    */
845   static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
846   {
847     return ECORE_CALLBACK_PASS_ON;
848   }
849
850
851   /////////////////////////////////////////////////////////////////////////////////////////////////
852   // ElDBus Accessibility Callbacks
853   /////////////////////////////////////////////////////////////////////////////////////////////////
854
855 #ifdef DALI_ELDBUS_AVAILABLE
856   // Callback for Ecore ElDBus accessibility events.
857   static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
858   {
859     EventHandler* handler = static_cast< EventHandler* >( context );
860     // Ignore any accessibility events when paused.
861     if( handler->mPaused )
862     {
863       return;
864     }
865
866     if( !handler->mAccessibilityAdaptor )
867     {
868       DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
869       return;
870     }
871
872     AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
873     if( !accessibilityAdaptor )
874     {
875       DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
876       return;
877     }
878
879     int gestureValue;
880     int xS, yS, xE, yE;
881     int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
882     int eventTime;
883
884     // The string defines the arg-list's respective types.
885     if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
886     {
887       DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
888     }
889
890     DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d  Args: %d,%d,%d,%d  State: %d\n", gestureValue, xS, yS, xE, yE );
891
892     // Create a touch point object.
893     TouchPoint::State touchPointState( TouchPoint::Down );
894     if( state == 0 )
895     {
896       touchPointState = TouchPoint::Down; // Mouse down.
897     }
898     else if( state == 1 )
899     {
900       touchPointState = TouchPoint::Motion; // Mouse move.
901     }
902     else if( state == 2 )
903     {
904       touchPointState = TouchPoint::Up; // Mouse up.
905     }
906     else
907     {
908       touchPointState = TouchPoint::Interrupted; // Error.
909     }
910
911     // Send touch event to accessibility adaptor.
912     TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
913
914     // Perform actions based on received gestures.
915     // Note: This is seperated from the reading so we can have other input readers without changing the below code.
916     switch( gestureValue )
917     {
918       case 0: // OneFingerHover
919       {
920         // Focus, read out.
921         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
922         break;
923       }
924       case 1: // TwoFingersHover
925       {
926         // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
927         accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
928         break;
929       }
930       case 2: // ThreeFingersHover
931       {
932         // Read from top item on screen continuously.
933         accessibilityAdaptor->HandleActionReadFromTopEvent();
934         break;
935       }
936       case 3: // OneFingerFlickLeft
937       {
938         // Move to previous item.
939         accessibilityAdaptor->HandleActionReadPreviousEvent();
940         break;
941       }
942       case 4: // OneFingerFlickRight
943       {
944         // Move to next item.
945         accessibilityAdaptor->HandleActionReadNextEvent();
946         break;
947       }
948       case 5: // OneFingerFlickUp
949       {
950         // Move to previous item.
951         accessibilityAdaptor->HandleActionPreviousEvent();
952         break;
953       }
954       case 6: // OneFingerFlickDown
955       {
956         // Move to next item.
957         accessibilityAdaptor->HandleActionNextEvent();
958         break;
959       }
960       case 7: // TwoFingersFlickUp
961       {
962         // Scroll up the list.
963         accessibilityAdaptor->HandleActionScrollUpEvent();
964         break;
965       }
966       case 8: // TwoFingersFlickDown
967       {
968         // Scroll down the list.
969         accessibilityAdaptor->HandleActionScrollDownEvent();
970         break;
971       }
972       case 9: // TwoFingersFlickLeft
973       {
974         // Scroll left to the previous page
975         accessibilityAdaptor->HandleActionPageLeftEvent();
976         break;
977       }
978       case 10: // TwoFingersFlickRight
979       {
980         // Scroll right to the next page
981         accessibilityAdaptor->HandleActionPageRightEvent();
982         break;
983       }
984       case 11: // ThreeFingersFlickLeft
985       {
986         // Not exist yet
987         break;
988       }
989       case 12: // ThreeFingersFlickRight
990       {
991         // Not exist yet
992         break;
993       }
994       case 13: // ThreeFingersFlickUp
995       {
996         // Not exist yet
997         break;
998       }
999       case 14: // ThreeFingersFlickDown
1000       {
1001         // Not exist yet
1002         break;
1003       }
1004       case 15: // OneFingerSingleTap
1005       {
1006         // Focus, read out.
1007         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1008         break;
1009       }
1010       case 16: // OneFingerDoubleTap
1011       {
1012         // Activate selected item / active edit mode.
1013         accessibilityAdaptor->HandleActionActivateEvent();
1014         break;
1015       }
1016       case 17: // OneFingerTripleTap
1017       {
1018         // Zoom
1019         accessibilityAdaptor->HandleActionZoomEvent();
1020         break;
1021       }
1022       case 18: // TwoFingersSingleTap
1023       {
1024         // Pause/Resume current speech
1025         accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1026         break;
1027       }
1028       case 19: // TwoFingersDoubleTap
1029       {
1030         // Start/Stop current action
1031         accessibilityAdaptor->HandleActionStartStopEvent();
1032         break;
1033       }
1034       case 20: // TwoFingersTripleTap
1035       {
1036         // Read information from indicator
1037         accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1038         break;
1039       }
1040       case 21: // ThreeFingersSingleTap
1041       {
1042         // Read from top item on screen continuously.
1043         accessibilityAdaptor->HandleActionReadFromTopEvent();
1044         break;
1045       }
1046       case 22: // ThreeFingersDoubleTap
1047       {
1048         // Read from next item continuously.
1049         accessibilityAdaptor->HandleActionReadFromNextEvent();
1050         break;
1051       }
1052       case 23: // ThreeFingersTripleTap
1053       {
1054         // Not exist yet
1055         break;
1056       }
1057       case 24: // OneFingerFlickLeftReturn
1058       {
1059         // Scroll up to the previous page
1060         accessibilityAdaptor->HandleActionPageUpEvent();
1061         break;
1062       }
1063       case 25: // OneFingerFlickRightReturn
1064       {
1065         // Scroll down to the next page
1066         accessibilityAdaptor->HandleActionPageDownEvent();
1067         break;
1068       }
1069       case 26: // OneFingerFlickUpReturn
1070       {
1071         // Move to the first item on screen
1072         accessibilityAdaptor->HandleActionMoveToFirstEvent();
1073         break;
1074       }
1075       case 27: // OneFingerFlickDownReturn
1076       {
1077         // Move to the last item on screen
1078         accessibilityAdaptor->HandleActionMoveToLastEvent();
1079         break;
1080       }
1081       case 28: // TwoFingersFlickLeftReturn
1082       {
1083         // Not exist yet
1084         break;
1085       }
1086       case 29: // TwoFingersFlickRightReturn
1087       {
1088         // Not exist yet
1089         break;
1090       }
1091       case 30: // TwoFingersFlickUpReturn
1092       {
1093         // Not exist yet
1094         break;
1095       }
1096       case 31: // TwoFingersFlickDownReturn
1097       {
1098         // Not exist yet
1099         break;
1100       }
1101       case 32: // ThreeFingersFlickLeftReturn
1102       {
1103         // Not exist yet
1104         break;
1105       }
1106       case 33: // ThreeFingersFlickRightReturn
1107       {
1108         // Not exist yet
1109         break;
1110       }
1111       case 34: // ThreeFingersFlickUpReturn
1112       {
1113         // Not exist yet
1114         break;
1115       }
1116       case 35: // ThreeFingersFlickDownReturn
1117       {
1118         // Not exist yet
1119         break;
1120       }
1121     }
1122   }
1123
1124   void EcoreElDBusInitialisation( void *handle )
1125   {
1126     Eldbus_Object *object;
1127     Eldbus_Proxy *manager;
1128
1129     if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1130     {
1131       DALI_LOG_ERROR( "Unable to get system bus\n" );
1132     }
1133
1134     object = eldbus_object_get( mSystemConnection, BUS, PATH );
1135     if( !object )
1136     {
1137       DALI_LOG_ERROR( "Getting object failed\n" );
1138       return;
1139     }
1140
1141     manager = eldbus_proxy_get( object, INTERFACE );
1142     if( !manager )
1143     {
1144       DALI_LOG_ERROR( "Getting proxy failed\n" );
1145       return;
1146     }
1147
1148     if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1149     {
1150       DALI_LOG_ERROR( "No signal handler returned\n" );
1151     }
1152   }
1153 #endif // DALI_ELDBUS_AVAILABLE
1154
1155   /**
1156    * Called when the source window notifies us the content in clipboard is selected.
1157    */
1158   static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1159   {
1160     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1161     return ECORE_CALLBACK_PASS_ON;
1162   }
1163
1164   /**
1165    * Called when the source window sends us about the selected content.
1166    * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1167    */
1168   static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1169   {
1170     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1171     return ECORE_CALLBACK_PASS_ON;
1172   }
1173
1174   /**
1175   * Called when the source window notifies us the content in clipboard is selected.
1176   */
1177   static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1178   {
1179     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1180
1181     Dali::Clipboard clipboard = Clipboard::Get();
1182     if ( clipboard )
1183     {
1184       Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1185       clipBoardImpl.ExcuteBuffered( true, event );
1186     }
1187     return ECORE_CALLBACK_PASS_ON;
1188   }
1189
1190    /**
1191     * Called when the source window sends us about the selected content.
1192     * For example, when item is selected in the clipboard.
1193     */
1194    static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1195    {
1196      DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1197
1198      EventHandler* handler( (EventHandler*)data );
1199       Dali::Clipboard clipboard = Clipboard::Get();
1200       char *selectionData = NULL;
1201       if ( clipboard )
1202       {
1203         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1204         selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1205       }
1206       if ( selectionData && handler->mClipboardEventNotifier )
1207       {
1208         ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1209         std::string content( selectionData, strlen(selectionData) );
1210
1211         clipboardEventNotifier.SetContent( content );
1212         clipboardEventNotifier.EmitContentSelectedSignal();
1213       }
1214      return ECORE_CALLBACK_PASS_ON;
1215    }
1216
1217   /*
1218   * Called when rotate event is recevied
1219   */
1220   static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1221   {
1222     DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1223
1224     EventHandler* handler( (EventHandler*)data );
1225     Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1226
1227     if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1228     {
1229       return ECORE_CALLBACK_PASS_ON;
1230     }
1231
1232     RotationEvent rotationEvent;
1233     rotationEvent.angle = ev->angle;
1234     rotationEvent.winResize = 0;
1235
1236     if( ev->angle == 0 || ev->angle == 180 )
1237     {
1238       rotationEvent.width = ev->w;
1239       rotationEvent.height = ev->h;
1240     }
1241     else
1242     {
1243       rotationEvent.width = ev->h;
1244       rotationEvent.height = ev->w;
1245     }
1246
1247     handler->SendRotationPrepareEvent( rotationEvent );
1248
1249     return ECORE_CALLBACK_PASS_ON;
1250   }
1251
1252   /*
1253   * Called when detent event is recevied
1254   */
1255   static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1256   {
1257     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1258     EventHandler* handler( (EventHandler*)data );
1259     Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1260     int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1261     int timeStamp = e->timestamp;
1262
1263     WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1264     handler->SendWheelEvent( wheelEvent );
1265     return ECORE_CALLBACK_PASS_ON;
1266   }
1267
1268   /////////////////////////////////////////////////////////////////////////////////////////////////
1269   // Font Callbacks
1270   /////////////////////////////////////////////////////////////////////////////////////////////////
1271   /**
1272    * Called when a font name is changed.
1273    */
1274   static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1275   {
1276     EventHandler* handler = static_cast<EventHandler*>( data );
1277     handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1278   }
1279
1280   /**
1281    * Called when a font size is changed.
1282    */
1283   static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1284   {
1285     EventHandler* handler = static_cast<EventHandler*>( data );
1286     handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1287   }
1288
1289   void ConvertTouchPosition( Integration::Point& point )
1290   {
1291     Vector2 position = point.GetScreenPosition();
1292     Vector2 convertedPosition;
1293
1294     switch( mRotationAngle )
1295     {
1296       case 90:
1297       {
1298         convertedPosition.x = mWindowWidth - position.y;
1299         convertedPosition.y = position.x;
1300         break;
1301       }
1302       case 180:
1303       {
1304         convertedPosition.x = mWindowWidth - position.x;
1305         convertedPosition.y = mWindowHeight - position.y;
1306         break;
1307       }
1308       case 270:
1309       {
1310         convertedPosition.x = position.y;
1311         convertedPosition.y = mWindowHeight - position.x;
1312         break;
1313       }
1314       default:
1315       {
1316         convertedPosition = position;
1317         break;
1318       }
1319     }
1320
1321     point.SetScreenPosition( convertedPosition );
1322   }
1323
1324   // Data
1325   EventHandler* mHandler;
1326   std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1327   Ecore_Wl_Window* mWindow;
1328   int mRotationAngle;
1329   int mWindowWidth;
1330   int mWindowHeight;
1331 #ifdef DALI_ELDBUS_AVAILABLE
1332   Eldbus_Connection* mSystemConnection;
1333 #endif // DALI_ELDBUS_AVAILABLE
1334 };
1335
1336 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1337 : mCoreEventInterface( coreEventInterface ),
1338   mGestureManager( gestureManager ),
1339   mStyleMonitor( StyleMonitor::Get() ),
1340   mDamageObserver( damageObserver ),
1341   mRotationObserver( NULL ),
1342   mDragAndDropDetector( dndDetector ),
1343   mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1344   mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1345   mClipboard( Clipboard::Get() ),
1346   mImpl( NULL ),
1347   mPaused( false )
1348 {
1349   Ecore_Wl_Window* window = 0;
1350
1351   // this code only works with the WindowRenderSurface so need to downcast
1352   WindowRenderSurfaceEcoreWl* ecoreSurface = static_cast< WindowRenderSurfaceEcoreWl* >( surface );
1353   if( ecoreSurface )
1354   {
1355     window = ecoreSurface->GetWlWindow();
1356   }
1357
1358   mImpl = new Impl(this, window);
1359 }
1360
1361 EventHandler::~EventHandler()
1362 {
1363   if(mImpl)
1364   {
1365     delete mImpl;
1366   }
1367
1368   mGestureManager.Stop();
1369 }
1370
1371 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1372 {
1373   if(timeStamp < 1)
1374   {
1375     timeStamp = GetCurrentMilliSeconds();
1376   }
1377
1378   mImpl->ConvertTouchPosition( point );
1379
1380   Integration::TouchEvent touchEvent;
1381   Integration::HoverEvent hoverEvent;
1382   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1383   if(type != Integration::TouchEventCombiner::DispatchNone )
1384   {
1385     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);
1386
1387     // First the touch and/or hover event & related gesture events are queued
1388     if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1389     {
1390       mCoreEventInterface.QueueCoreEvent( touchEvent );
1391       mGestureManager.SendEvent(touchEvent);
1392     }
1393
1394     if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1395     {
1396       mCoreEventInterface.QueueCoreEvent( hoverEvent );
1397     }
1398
1399     // Next the events are processed with a single call into Core
1400     mCoreEventInterface.ProcessCoreEvents();
1401   }
1402 }
1403
1404 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1405 {
1406   Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1407   if ( physicalKeyboard )
1408   {
1409     if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1410     {
1411       GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1412     }
1413   }
1414
1415   // Create send KeyEvent to Core.
1416   mCoreEventInterface.QueueCoreEvent( keyEvent );
1417   mCoreEventInterface.ProcessCoreEvents();
1418 }
1419
1420 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1421 {
1422   // Create WheelEvent and send to Core.
1423   Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1424   mCoreEventInterface.QueueCoreEvent( event );
1425   mCoreEventInterface.ProcessCoreEvents();
1426 }
1427
1428 void EventHandler::SendEvent( StyleChange::Type styleChange )
1429 {
1430   DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1431   GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1432 }
1433
1434 void EventHandler::SendEvent( const DamageArea& area )
1435 {
1436   mDamageObserver.OnDamaged( area );
1437 }
1438
1439 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1440 {
1441   if( mRotationObserver != NULL )
1442   {
1443     mImpl->mRotationAngle = event.angle;
1444     mImpl->mWindowWidth = event.width;
1445     mImpl->mWindowHeight = event.height;
1446
1447     mRotationObserver->OnRotationPrepare( event );
1448     mRotationObserver->OnRotationRequest();
1449   }
1450 }
1451
1452 void EventHandler::SendRotationRequestEvent( )
1453 {
1454   // No need to separate event into prepare and request in wayland
1455 }
1456
1457 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1458 {
1459   Integration::Point convertedPoint( point );
1460   SendEvent(convertedPoint, timeStamp);
1461 }
1462
1463 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1464 {
1465   SendWheelEvent( wheelEvent );
1466 }
1467
1468 void EventHandler::FeedKeyEvent( KeyEvent& event )
1469 {
1470   Integration::KeyEvent convertedEvent( event );
1471   SendEvent( convertedEvent );
1472 }
1473
1474 void EventHandler::FeedEvent( Integration::Event& event )
1475 {
1476   mCoreEventInterface.QueueCoreEvent( event );
1477   mCoreEventInterface.ProcessCoreEvents();
1478 }
1479
1480 void EventHandler::Reset()
1481 {
1482   mCombiner.Reset();
1483
1484   // Any touch listeners should be told of the interruption.
1485   Integration::TouchEvent event;
1486   Integration::Point point;
1487   point.SetState( PointState::INTERRUPTED );
1488   event.AddPoint( point );
1489
1490   // First the touch event & related gesture events are queued
1491   mCoreEventInterface.QueueCoreEvent( event );
1492   mGestureManager.SendEvent( event );
1493
1494   // Next the events are processed with a single call into Core
1495   mCoreEventInterface.ProcessCoreEvents();
1496 }
1497
1498 void EventHandler::Pause()
1499 {
1500   mPaused = true;
1501   Reset();
1502 }
1503
1504 void EventHandler::Resume()
1505 {
1506   mPaused = false;
1507   Reset();
1508 }
1509
1510 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1511 {
1512   mDragAndDropDetector = detector;
1513 }
1514
1515 void EventHandler::SetRotationObserver( RotationObserver* observer )
1516 {
1517   mRotationObserver = observer;
1518 }
1519
1520 } // namespace Adaptor
1521
1522 } // namespace Internal
1523
1524 } // namespace Dali
1525
1526 #pragma GCC diagnostic pop