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